summaryrefslogtreecommitdiff
path: root/src/x11.c
blob: 01119ec4aff252dfa715eec59865e8c8ccf04dad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
 /*
  * Copyright 2012  Samsung Electronics Co., Ltd
  *
  * Licensed under the Flora License, Version 1.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *     http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */



#include <string.h>
#include <stdio.h>
#include <stdlib.h>

#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>

#define DEFAULT_WINDOW_H 1280

void prop_string_set(const char *name, const char *value)
{
	Display *d;
	Atom a_name;
	Atom a_UTF8;
	XTextProperty xtp;

	if (name == NULL || value == NULL || value[0] == '\0')
		return;

	d = XOpenDisplay(NULL);
	if (d == NULL)
		return;

	a_name = XInternAtom(d, name, False);
	if (a_name == None)
		goto exit;

	a_UTF8 = XInternAtom(d, "UTF8_STRING", False);
	if (a_UTF8 == None)
		goto exit;

	xtp.value = (unsigned char *)value;
	xtp.format = 8;
	xtp.encoding = a_UTF8;
	xtp.nitems = strlen(value);

	XSetTextProperty(d, DefaultRootWindow(d), &xtp, a_name);

 exit:
	XCloseDisplay(d);
}

void prop_int_set(const char *name, unsigned int val)
{
	Display *d;
	Atom a_name;

	if (name == NULL)
		return;

	d = XOpenDisplay(NULL);
	if (d == NULL)
		return;

	a_name = XInternAtom(d, name, False);
	if (a_name == None)
		goto exit;

	XChangeProperty(d, DefaultRootWindow(d), a_name, XA_CARDINAL, 32,
			PropModeReplace, (unsigned char *)&val, 1);

 exit:
	XCloseDisplay(d);
}

void set_window_scale(void)
{
	double root_width = 0.0, root_height = 0.0;
	char buf[128] = { 0, };
	Display *disp;
	int screen_num;

	disp = XOpenDisplay(NULL);
	if (disp == NULL)
		return;

	screen_num = DefaultScreen(disp);

	root_width = DisplayWidth(disp, screen_num);
	root_height = DisplayHeight(disp, screen_num);

	XCloseDisplay(disp);

	snprintf(buf, sizeof(buf), "%lf", root_height / DEFAULT_WINDOW_H);

	if (root_width == 800 && root_height == 1280) {
		snprintf(buf, sizeof(buf), "0.71");
	}

	setenv("ELM_SCALE", buf, 1);
	setenv("SCALE_FACTOR", buf, 1);
}