From: devilhorns Date: Thu, 8 Sep 2011 21:51:08 +0000 (+0000) Subject: Ecore_X(cb): Add simple .Xdefaults file parser for getting dpi, cursor X-Git-Tag: build/2012-07-04.173327~863 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ddfb0463f1e7998a5f68fba6d08539303813547f;p=profile%2Fivi%2Fecore.git 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). git-svn-id: http://svn.enlightenment.org/svn/e/trunk/ecore@63299 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- diff --git a/src/lib/ecore_x/xcb/Makefile.am b/src/lib/ecore_x/xcb/Makefile.am index 0dcdad4..b5ca362 100644 --- a/src/lib/ecore_x/xcb/Makefile.am +++ b/src/lib/ecore_x/xcb/Makefile.am @@ -67,7 +67,8 @@ libecore_x_xcb_la_SOURCES = \ ecore_xcb_xinerama.c \ ecore_xcb_error.c \ ecore_xcb_xtest.c \ - ecore_xcb_vsync.c + ecore_xcb_vsync.c \ + ecore_xcb_xdefaults.c libecore_x_xcb_la_LIBADD = \ @XCB_DAMAGE_LIBS@ \ diff --git a/src/lib/ecore_x/xcb/ecore_xcb.c b/src/lib/ecore_x/xcb/ecore_xcb.c index 2b4330d..ff50b6b 100644 --- a/src/lib/ecore_x/xcb/ecore_xcb.c +++ b/src/lib/ecore_x/xcb/ecore_xcb.c @@ -1376,6 +1376,9 @@ _ecore_xcb_fd_handle(void *data, Ecore_Fd_Handler *hdlr __UNUSED__) while ((ev = xcb_poll_for_event(conn))) { + /* NB: Ecore Xlib uses filterevent for xim, but xcb does not support + * xim, so no need for it here */ + /* check for errors first */ if (xcb_connection_has_error(conn)) { diff --git a/src/lib/ecore_x/xcb/ecore_xcb_composite.c b/src/lib/ecore_x/xcb/ecore_xcb_composite.c index 8a88da9..aef9b6a 100644 --- a/src/lib/ecore_x/xcb/ecore_xcb_composite.c +++ b/src/lib/ecore_x/xcb/ecore_xcb_composite.c @@ -76,6 +76,7 @@ _ecore_xcb_composite_finalize(void) EAPI Eina_Bool ecore_x_composite_query(void) { + LOGFN(__FILE__, __LINE__, __FUNCTION__); return _composite_avail; } diff --git a/src/lib/ecore_x/xcb/ecore_xcb_cursor.c b/src/lib/ecore_x/xcb/ecore_xcb_cursor.c index 2714832..a22dddb 100644 --- a/src/lib/ecore_x/xcb/ecore_xcb_cursor.c +++ b/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 Ecore_X_Cursor cursor = 0; xcb_image_t *img; - LOGFN(__FILE__, __LINE__, __FUNCTION__); +// LOGFN(__FILE__, __LINE__, __FUNCTION__); #ifdef ECORE_XCB_CURSOR 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 EAPI void ecore_x_cursor_free(Ecore_X_Cursor c) { - LOGFN(__FILE__, __LINE__, __FUNCTION__); +// LOGFN(__FILE__, __LINE__, __FUNCTION__); xcb_free_cursor(_ecore_xcb_conn, c); } @@ -295,25 +295,34 @@ _ecore_xcb_cursor_format_get(void) static void _ecore_xcb_cursor_default_size_get(void) { - LOGFN(__FILE__, __LINE__, __FUNCTION__); + char *s = NULL; + int v = 0; - /* char *v = NULL; */ + LOGFN(__FILE__, __LINE__, __FUNCTION__); - /* v = getenv("XCURSOR_SIZE"); */ - /* if (!v) */ - /* v = _ecore_xcb_resource_get_string("Xcursor", "size"); */ - /* if (v) _ecore_xcb_cursor_size = ((atoi(v) * 16) / 72); */ + s = getenv("XCURSOR_SIZE"); + if (!s) + { + _ecore_xcb_xdefaults_init(); + v = _ecore_xcb_xdefaults_int_get("Xcursor", "size"); + _ecore_xcb_xdefaults_shutdown(); + } + else + v = atoi(s); + if (v) _ecore_xcb_cursor_size = ((v * 16) / 72); } static void _ecore_xcb_cursor_dpi_size_get(void) { - LOGFN(__FILE__, __LINE__, __FUNCTION__); + int v = 0; - /* int v = 0; */ + LOGFN(__FILE__, __LINE__, __FUNCTION__); - /* v = _ecore_xcb_resource_get_int("Xft", "dpi"); */ - /* if (v) _ecore_xcb_cursor_size = ((v * 16) / 72); */ + _ecore_xcb_xdefaults_init(); + v = _ecore_xcb_xdefaults_int_get("Xft", "dpi"); + if (v) _ecore_xcb_cursor_size = ((v * 16) / 72); + _ecore_xcb_xdefaults_shutdown(); } static void diff --git a/src/lib/ecore_x/xcb/ecore_xcb_private.h b/src/lib/ecore_x/xcb/ecore_xcb_private.h index 95824ca..21decbd 100644 --- a/src/lib/ecore_x/xcb/ecore_xcb_private.h +++ b/src/lib/ecore_x/xcb/ecore_xcb_private.h @@ -337,4 +337,9 @@ int _ecore_xcb_io_error_handle(xcb_generic_error_t *err); xcb_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); +void _ecore_xcb_xdefaults_init(void); +void _ecore_xcb_xdefaults_shutdown(void); +char *_ecore_xcb_xdefaults_string_get(const char *prog, const char *param); +int _ecore_xcb_xdefaults_int_get(const char *prog, const char *param); + #endif diff --git a/src/lib/ecore_x/xcb/ecore_xcb_xdefaults.c b/src/lib/ecore_x/xcb/ecore_xcb_xdefaults.c new file mode 100644 index 0000000..ba41e91 --- /dev/null +++ b/src/lib/ecore_x/xcb/ecore_xcb_xdefaults.c @@ -0,0 +1,111 @@ +#include "ecore_xcb_private.h" +#include + +/* local function prototypes */ +static Eina_Bool _ecore_xcb_xdefaults_glob_match(const char *str, const char *glob); + +/* local variables */ +static Eina_File *_ecore_xcb_xdefaults_file = NULL; +static char *_ecore_xcb_xdefaults_data = NULL; + +void +_ecore_xcb_xdefaults_init(void) +{ + char buff[PATH_MAX]; + + LOGFN(__FILE__, __LINE__, __FUNCTION__); + + snprintf(buff, sizeof(buff), "%s/.Xdefaults", getenv("HOME")); + if ((_ecore_xcb_xdefaults_file = eina_file_open(buff, EINA_FALSE))) + { + eina_mmap_safety_enabled_set(EINA_TRUE); + + _ecore_xcb_xdefaults_data = + eina_file_map_all(_ecore_xcb_xdefaults_file, EINA_FILE_SEQUENTIAL); + } +} + +void +_ecore_xcb_xdefaults_shutdown(void) +{ + LOGFN(__FILE__, __LINE__, __FUNCTION__); + + if (!_ecore_xcb_xdefaults_file) return; + if (_ecore_xcb_xdefaults_data) + eina_file_map_free(_ecore_xcb_xdefaults_file, _ecore_xcb_xdefaults_data); + if (_ecore_xcb_xdefaults_file) eina_file_close(_ecore_xcb_xdefaults_file); +} + +char * +_ecore_xcb_xdefaults_string_get(const char *prog, const char *param) +{ + char buff[1024], ret[1024]; + char *str = NULL; + char **ea = NULL; + unsigned int count = 0, i = 0; + + if ((!_ecore_xcb_xdefaults_data) || (!_ecore_xcb_xdefaults_file)) + return NULL; + + snprintf(buff, sizeof(buff), "*%s*.*%s*", prog, param); + + str = _ecore_xcb_xdefaults_data; + ea = eina_str_split_full(str, "\n", -1, &count); + for (i = 0; i < count; i++) + { + if (_ecore_xcb_xdefaults_glob_match(ea[i], buff)) + sscanf(ea[i], "%*[^:]:%*[ ]%s", ret); + } + if ((ea) && (ea[0])) + { + free(ea[0]); + free(ea); + } + + return strdup(ret); +} + +int +_ecore_xcb_xdefaults_int_get(const char *prog, const char *param) +{ + char buff[1024]; + char *str = NULL; + char **ea = NULL; + unsigned int count = 0, i = 0; + int ret = -1; + + if ((!_ecore_xcb_xdefaults_data) || (!_ecore_xcb_xdefaults_file)) + return 0; + + snprintf(buff, sizeof(buff), "*%s*.*%s*", prog, param); + + str = _ecore_xcb_xdefaults_data; + ea = eina_str_split_full(str, "\n", -1, &count); + for (i = 0; i < count; i++) + { + if (_ecore_xcb_xdefaults_glob_match(ea[i], buff)) + sscanf(ea[i], "%*[^:]:%*[ ]%d", &ret); + } + if ((ea) && (ea[0])) + { + free(ea[0]); + free(ea); + } + + return ret; +} + +/* local functions */ +static Eina_Bool +_ecore_xcb_xdefaults_glob_match(const char *str, const char *glob) +{ + if ((!str) || (!glob)) return EINA_FALSE; + if (glob[0] == 0) + { + if (str[0] == 0) return EINA_TRUE; + return EINA_FALSE; + } + if (!strcmp(glob, "*")) return EINA_TRUE; + if (!fnmatch(glob, str, 0)) return EINA_TRUE; + return EINA_FALSE; +}