update boilerplate
[apps/home/starter.git] / boot-mgr / x11.c
1 /*
2  * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved 
3  *
4  * This file is part of <starter>
5  * Written by <Seungtaek Chung> <seungtaek.chung@samsung.com>, <Mi-Ju Lee> <miju52.lee@samsung.com>, <Xi Zhichan> <zhichan.xi@samsung.com>
6  *
7  * PROPRIETARY/CONFIDENTIAL
8  *
9  * This software is the confidential and proprietary information of SAMSUNG ELECTRONICS ("Confidential Information").
10  * You shall not disclose such Confidential Information and shall use it only in accordance
11  * with the terms of the license agreement you entered into with SAMSUNG ELECTRONICS.
12  * SAMSUNG make no representations or warranties about the suitability of the software,
13  * either express or implied, including but not limited to the implied warranties of merchantability,
14  * fitness for a particular purpose, or non-infringement.
15  * SAMSUNG shall not be liable for any damages suffered by licensee as a result of using,
16  * modifying or distributing this software or its derivatives.
17  *
18  */
19
20 #include <string.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23
24 #include <X11/Xlib.h>
25 #include <X11/Xatom.h>
26 #include <X11/Xutil.h>
27
28 #define DEFAULT_WINDOW_H 1280
29
30 void prop_string_set(const char *name, const char *value)
31 {
32         Display *d;
33         Atom a_name;
34         Atom a_UTF8;
35         XTextProperty xtp;
36
37         if (name == NULL || value == NULL || value[0] == '\0')
38                 return;
39
40         d = XOpenDisplay(NULL);
41         if (d == NULL)
42                 return;
43
44         a_name = XInternAtom(d, name, False);
45         if (a_name == None)
46                 goto exit;
47
48         a_UTF8 = XInternAtom(d, "UTF8_STRING", False);
49         if (a_UTF8 == None)
50                 goto exit;
51
52         xtp.value = (unsigned char *)value;
53         xtp.format = 8;
54         xtp.encoding = a_UTF8;
55         xtp.nitems = strlen(value);
56
57         XSetTextProperty(d, DefaultRootWindow(d), &xtp, a_name);
58
59  exit:
60         XCloseDisplay(d);
61 }
62
63 void prop_int_set(const char *name, unsigned int val)
64 {
65         Display *d;
66         Atom a_name;
67
68         if (name == NULL)
69                 return;
70
71         d = XOpenDisplay(NULL);
72         if (d == NULL)
73                 return;
74
75         a_name = XInternAtom(d, name, False);
76         if (a_name == None)
77                 goto exit;
78
79         XChangeProperty(d, DefaultRootWindow(d), a_name, XA_CARDINAL, 32,
80                         PropModeReplace, (unsigned char *)&val, 1);
81
82  exit:
83         XCloseDisplay(d);
84 }
85
86 void set_window_scale(void)
87 {
88         double root_width = 0.0, root_height = 0.0;
89         char buf[128] = { 0, };
90         Display *disp;
91         int screen_num;
92
93         disp = XOpenDisplay(NULL);
94         if (disp == NULL)
95                 return;
96
97         screen_num = DefaultScreen(disp);
98
99         root_width = DisplayWidth(disp, screen_num);
100         root_height = DisplayHeight(disp, screen_num);
101
102         XCloseDisplay(disp);
103
104         snprintf(buf, sizeof(buf), "%lf", root_height / DEFAULT_WINDOW_H);
105
106         if (root_width == 800 && root_height == 1280) {
107                 snprintf(buf, sizeof(buf), "0.71");
108         }
109
110         setenv("ELM_SCALE", buf, 1);
111         setenv("SCALE_FACTOR", buf, 1);
112 }