summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Michael <cpmichael1@comcast.net>2011-09-08 21:51:08 +0000
committerChristopher Michael <cpmichael1@comcast.net>2011-09-08 21:51:08 +0000
commit67a369fee37185ac8c224973dcb7e4fc09200b73 (patch)
tree77d5c06813f267e40ed8ef2059aade47a37d4835
parent1a1248b689bcc85995acfed08b1804ff5d1f90dd (diff)
Ecore_X(cb): Add simple .Xdefaults file parser for getting dpi, cursor
size, etc. NB: Xcb has no support for xrdb (yet), so parse dpi, etc from .Xdefaults (if exists). SVN revision: 63299
-rw-r--r--legacy/ecore/src/lib/ecore_x/xcb/Makefile.am3
-rw-r--r--legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb.c3
-rw-r--r--legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_composite.c1
-rw-r--r--legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_cursor.c33
-rw-r--r--legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_private.h5
-rw-r--r--legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_xdefaults.c111
6 files changed, 143 insertions, 13 deletions
diff --git a/legacy/ecore/src/lib/ecore_x/xcb/Makefile.am b/legacy/ecore/src/lib/ecore_x/xcb/Makefile.am
index 0dcdad476d..b5ca362f59 100644
--- a/legacy/ecore/src/lib/ecore_x/xcb/Makefile.am
+++ b/legacy/ecore/src/lib/ecore_x/xcb/Makefile.am
@@ -67,7 +67,8 @@ libecore_x_xcb_la_SOURCES = \
67 ecore_xcb_xinerama.c \ 67 ecore_xcb_xinerama.c \
68 ecore_xcb_error.c \ 68 ecore_xcb_error.c \
69 ecore_xcb_xtest.c \ 69 ecore_xcb_xtest.c \
70 ecore_xcb_vsync.c 70 ecore_xcb_vsync.c \
71 ecore_xcb_xdefaults.c
71 72
72libecore_x_xcb_la_LIBADD = \ 73libecore_x_xcb_la_LIBADD = \
73 @XCB_DAMAGE_LIBS@ \ 74 @XCB_DAMAGE_LIBS@ \
diff --git a/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb.c b/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb.c
index 2b4330df45..ff50b6b4a1 100644
--- a/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb.c
+++ b/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb.c
@@ -1376,6 +1376,9 @@ _ecore_xcb_fd_handle(void *data, Ecore_Fd_Handler *hdlr __UNUSED__)
1376 1376
1377 while ((ev = xcb_poll_for_event(conn))) 1377 while ((ev = xcb_poll_for_event(conn)))
1378 { 1378 {
1379 /* NB: Ecore Xlib uses filterevent for xim, but xcb does not support
1380 * xim, so no need for it here */
1381
1379 /* check for errors first */ 1382 /* check for errors first */
1380 if (xcb_connection_has_error(conn)) 1383 if (xcb_connection_has_error(conn))
1381 { 1384 {
diff --git a/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_composite.c b/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_composite.c
index 8a88da9177..aef9b6acc0 100644
--- a/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_composite.c
+++ b/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_composite.c
@@ -76,6 +76,7 @@ _ecore_xcb_composite_finalize(void)
76EAPI Eina_Bool 76EAPI Eina_Bool
77ecore_x_composite_query(void) 77ecore_x_composite_query(void)
78{ 78{
79 LOGFN(__FILE__, __LINE__, __FUNCTION__);
79 return _composite_avail; 80 return _composite_avail;
80} 81}
81 82
diff --git a/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_cursor.c b/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_cursor.c
index 27148322d9..a22dddb387 100644
--- a/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_cursor.c
+++ b/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_cursor.c
@@ -72,7 +72,7 @@ ecore_x_cursor_new(Ecore_X_Window win, int *pixels, int w, int h, int hot_x, int
72 Ecore_X_Cursor cursor = 0; 72 Ecore_X_Cursor cursor = 0;
73 xcb_image_t *img; 73 xcb_image_t *img;
74 74
75 LOGFN(__FILE__, __LINE__, __FUNCTION__); 75// LOGFN(__FILE__, __LINE__, __FUNCTION__);
76 76
77#ifdef ECORE_XCB_CURSOR 77#ifdef ECORE_XCB_CURSOR
78 if (_ecore_xcb_cursor) 78 if (_ecore_xcb_cursor)
@@ -228,7 +228,7 @@ ecore_x_cursor_new(Ecore_X_Window win, int *pixels, int w, int h, int hot_x, int
228EAPI void 228EAPI void
229ecore_x_cursor_free(Ecore_X_Cursor c) 229ecore_x_cursor_free(Ecore_X_Cursor c)
230{ 230{
231 LOGFN(__FILE__, __LINE__, __FUNCTION__); 231// LOGFN(__FILE__, __LINE__, __FUNCTION__);
232 232
233 xcb_free_cursor(_ecore_xcb_conn, c); 233 xcb_free_cursor(_ecore_xcb_conn, c);
234} 234}
@@ -295,25 +295,34 @@ _ecore_xcb_cursor_format_get(void)
295static void 295static void
296_ecore_xcb_cursor_default_size_get(void) 296_ecore_xcb_cursor_default_size_get(void)
297{ 297{
298 LOGFN(__FILE__, __LINE__, __FUNCTION__); 298 char *s = NULL;
299 int v = 0;
299 300
300 /* char *v = NULL; */ 301 LOGFN(__FILE__, __LINE__, __FUNCTION__);
301 302
302 /* v = getenv("XCURSOR_SIZE"); */ 303 s = getenv("XCURSOR_SIZE");
303 /* if (!v) */ 304 if (!s)
304 /* v = _ecore_xcb_resource_get_string("Xcursor", "size"); */ 305 {
305 /* if (v) _ecore_xcb_cursor_size = ((atoi(v) * 16) / 72); */ 306 _ecore_xcb_xdefaults_init();
307 v = _ecore_xcb_xdefaults_int_get("Xcursor", "size");
308 _ecore_xcb_xdefaults_shutdown();
309 }
310 else
311 v = atoi(s);
312 if (v) _ecore_xcb_cursor_size = ((v * 16) / 72);
306} 313}
307 314
308static void 315static void
309_ecore_xcb_cursor_dpi_size_get(void) 316_ecore_xcb_cursor_dpi_size_get(void)
310{ 317{
311 LOGFN(__FILE__, __LINE__, __FUNCTION__); 318 int v = 0;
312 319
313 /* int v = 0; */ 320 LOGFN(__FILE__, __LINE__, __FUNCTION__);
314 321
315 /* v = _ecore_xcb_resource_get_int("Xft", "dpi"); */ 322 _ecore_xcb_xdefaults_init();
316 /* if (v) _ecore_xcb_cursor_size = ((v * 16) / 72); */ 323 v = _ecore_xcb_xdefaults_int_get("Xft", "dpi");
324 if (v) _ecore_xcb_cursor_size = ((v * 16) / 72);
325 _ecore_xcb_xdefaults_shutdown();
317} 326}
318 327
319static void 328static void
diff --git a/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_private.h b/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_private.h
index 95824cabeb..21decbd35f 100644
--- a/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_private.h
+++ b/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_private.h
@@ -337,4 +337,9 @@ int _ecore_xcb_io_error_handle(xcb_generic_error_t *err);
337 337
338xcb_image_t *_ecore_xcb_image_create_native(int w, int h, xcb_image_format_t format, uint8_t depth, void *base, uint32_t bytes, uint8_t *data); 338xcb_image_t *_ecore_xcb_image_create_native(int w, int h, xcb_image_format_t format, uint8_t depth, void *base, uint32_t bytes, uint8_t *data);
339 339
340void _ecore_xcb_xdefaults_init(void);
341void _ecore_xcb_xdefaults_shutdown(void);
342char *_ecore_xcb_xdefaults_string_get(const char *prog, const char *param);
343int _ecore_xcb_xdefaults_int_get(const char *prog, const char *param);
344
340#endif 345#endif
diff --git a/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_xdefaults.c b/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_xdefaults.c
new file mode 100644
index 0000000000..ba41e9135e
--- /dev/null
+++ b/legacy/ecore/src/lib/ecore_x/xcb/ecore_xcb_xdefaults.c
@@ -0,0 +1,111 @@
1#include "ecore_xcb_private.h"
2#include <fnmatch.h>
3
4/* local function prototypes */
5static Eina_Bool _ecore_xcb_xdefaults_glob_match(const char *str, const char *glob);
6
7/* local variables */
8static Eina_File *_ecore_xcb_xdefaults_file = NULL;
9static char *_ecore_xcb_xdefaults_data = NULL;
10
11void
12_ecore_xcb_xdefaults_init(void)
13{
14 char buff[PATH_MAX];
15
16 LOGFN(__FILE__, __LINE__, __FUNCTION__);
17
18 snprintf(buff, sizeof(buff), "%s/.Xdefaults", getenv("HOME"));
19 if ((_ecore_xcb_xdefaults_file = eina_file_open(buff, EINA_FALSE)))
20 {
21 eina_mmap_safety_enabled_set(EINA_TRUE);
22
23 _ecore_xcb_xdefaults_data =
24 eina_file_map_all(_ecore_xcb_xdefaults_file, EINA_FILE_SEQUENTIAL);
25 }
26}
27
28void
29_ecore_xcb_xdefaults_shutdown(void)
30{
31 LOGFN(__FILE__, __LINE__, __FUNCTION__);
32
33 if (!_ecore_xcb_xdefaults_file) return;
34 if (_ecore_xcb_xdefaults_data)
35 eina_file_map_free(_ecore_xcb_xdefaults_file, _ecore_xcb_xdefaults_data);
36 if (_ecore_xcb_xdefaults_file) eina_file_close(_ecore_xcb_xdefaults_file);
37}
38
39char *
40_ecore_xcb_xdefaults_string_get(const char *prog, const char *param)
41{
42 char buff[1024], ret[1024];
43 char *str = NULL;
44 char **ea = NULL;
45 unsigned int count = 0, i = 0;
46
47 if ((!_ecore_xcb_xdefaults_data) || (!_ecore_xcb_xdefaults_file))
48 return NULL;
49
50 snprintf(buff, sizeof(buff), "*%s*.*%s*", prog, param);
51
52 str = _ecore_xcb_xdefaults_data;
53 ea = eina_str_split_full(str, "\n", -1, &count);
54 for (i = 0; i < count; i++)
55 {
56 if (_ecore_xcb_xdefaults_glob_match(ea[i], buff))
57 sscanf(ea[i], "%*[^:]:%*[ ]%s", ret);
58 }
59 if ((ea) && (ea[0]))
60 {
61 free(ea[0]);
62 free(ea);
63 }
64
65 return strdup(ret);
66}
67
68int
69_ecore_xcb_xdefaults_int_get(const char *prog, const char *param)
70{
71 char buff[1024];
72 char *str = NULL;
73 char **ea = NULL;
74 unsigned int count = 0, i = 0;
75 int ret = -1;
76
77 if ((!_ecore_xcb_xdefaults_data) || (!_ecore_xcb_xdefaults_file))
78 return 0;
79
80 snprintf(buff, sizeof(buff), "*%s*.*%s*", prog, param);
81
82 str = _ecore_xcb_xdefaults_data;
83 ea = eina_str_split_full(str, "\n", -1, &count);
84 for (i = 0; i < count; i++)
85 {
86 if (_ecore_xcb_xdefaults_glob_match(ea[i], buff))
87 sscanf(ea[i], "%*[^:]:%*[ ]%d", &ret);
88 }
89 if ((ea) && (ea[0]))
90 {
91 free(ea[0]);
92 free(ea);
93 }
94
95 return ret;
96}
97
98/* local functions */
99static Eina_Bool
100_ecore_xcb_xdefaults_glob_match(const char *str, const char *glob)
101{
102 if ((!str) || (!glob)) return EINA_FALSE;
103 if (glob[0] == 0)
104 {
105 if (str[0] == 0) return EINA_TRUE;
106 return EINA_FALSE;
107 }
108 if (!strcmp(glob, "*")) return EINA_TRUE;
109 if (!fnmatch(glob, str, 0)) return EINA_TRUE;
110 return EINA_FALSE;
111}