Evas: Add simple .Xdefaults files parsing to get DPI.
authordevilhorns <devilhorns@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 8 Sep 2011 21:49:45 +0000 (21:49 +0000)
committerdevilhorns <devilhorns@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 8 Sep 2011 21:49:45 +0000 (21:49 +0000)
NB: Xcb has no support (yet) for dealing with xrdb (Xresource
database), so add a simple parser to read an .Xdefaults file and get
things like xft.dpi.

git-svn-id: http://svn.enlightenment.org/svn/e/trunk/evas@63297 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/modules/engines/software_x11/Makefile.am
src/modules/engines/software_x11/evas_engine.c
src/modules/engines/software_x11/evas_xcb_xdefaults.c [new file with mode: 0644]
src/modules/engines/software_x11/evas_xcb_xdefaults.h [new file with mode: 0644]

index 9163fbe..5a2e345 100644 (file)
@@ -40,6 +40,7 @@ AM_CPPFLAGS = \
 @evas_engine_software_xcb_cflags@
 
 SOFTWARE_X11_SOURCES += \
+evas_xcb_xdefaults.c \
 evas_xcb_outbuf.c \
 evas_xcb_buffer.c \
 evas_xcb_color.c \
@@ -79,4 +80,6 @@ evas_xlib_buffer.h \
 evas_xlib_color.h \
 evas_xcb_outbuf.h \
 evas_xcb_buffer.h \
-evas_xcb_color.h
+evas_xcb_color.h \
+evas_xcb_xdefaults.h
+
index 908a84d..cb07032 100644 (file)
@@ -12,6 +12,7 @@
 #ifdef BUILD_ENGINE_SOFTWARE_XCB
 # include "evas_xcb_outbuf.h"
 # include "evas_xcb_color.h"
+# include "evas_xcb_xdefaults.h"
 #endif
 
 int _evas_engine_soft_x11_log_dom = -1;
@@ -242,6 +243,7 @@ _output_xcb_setup(int w, int h, int rot, xcb_connection_t *conn,
                   int shape_dither, int destination_alpha)
 {
    Render_Engine *re;
+   int v = 0;
 
    if (!(re = calloc(1, sizeof(Render_Engine)))) return NULL;
 
@@ -250,7 +252,12 @@ _output_xcb_setup(int w, int h, int rot, xcb_connection_t *conn,
    evas_software_xcb_outbuf_init();
 
    // FIXME: re->xrdb
-   re->xr.dpi = 75000; // dpy * 1000
+   _evas_xcb_xdefaults_init();
+   v = _evas_xcb_xdefaults_int_get("Xft", "dpi");
+   _evas_xcb_xdefaults_shutdown();
+   if (v) re->xr.dpi = (v * 1000);
+   else re->xr.dpi = 75000; // dpy * 1000
+
    evas_common_font_dpi_set(re->xr.dpi / 1000);
 
    re->ob = 
diff --git a/src/modules/engines/software_x11/evas_xcb_xdefaults.c b/src/modules/engines/software_x11/evas_xcb_xdefaults.c
new file mode 100644 (file)
index 0000000..3a0bda5
--- /dev/null
@@ -0,0 +1,108 @@
+#include "evas_common.h"
+#include "evas_xcb_xdefaults.h"
+#include <fnmatch.h>
+
+/* local function prototypes */
+static Eina_Bool _evas_xcb_xdefaults_glob_match(const char *str, const char *glob);
+
+/* local variables */
+static Eina_File *_evas_xcb_xdefaults_file = NULL;
+static char *_evas_xcb_xdefaults_data = NULL;
+
+void 
+_evas_xcb_xdefaults_init(void) 
+{
+   char buff[PATH_MAX];
+
+   snprintf(buff, sizeof(buff), "%s/.Xdefaults", getenv("HOME"));
+   if ((_evas_xcb_xdefaults_file = eina_file_open(buff, EINA_FALSE)))
+     {
+        eina_mmap_safety_enabled_set(EINA_TRUE);
+
+        _evas_xcb_xdefaults_data = 
+          eina_file_map_all(_evas_xcb_xdefaults_file, EINA_FILE_SEQUENTIAL);
+     }
+}
+
+void 
+_evas_xcb_xdefaults_shutdown(void) 
+{
+   if (!_evas_xcb_xdefaults_file) return;
+   if (_evas_xcb_xdefaults_data) 
+     eina_file_map_free(_evas_xcb_xdefaults_file, _evas_xcb_xdefaults_data);
+   if (_evas_xcb_xdefaults_file) eina_file_close(_evas_xcb_xdefaults_file);
+}
+
+char *
+_evas_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 ((!_evas_xcb_xdefaults_data) || (!_evas_xcb_xdefaults_file))
+     return NULL;
+
+   snprintf(buff, sizeof(buff), "*%s*.*%s*", prog, param);
+
+   str = _evas_xcb_xdefaults_data;
+   ea = eina_str_split_full(str, "\n", -1, &count);
+   for (i = 0; i < count; i++) 
+     {
+        if (_evas_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 
+_evas_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 ((!_evas_xcb_xdefaults_data) || (!_evas_xcb_xdefaults_file))
+     return 0;
+
+   snprintf(buff, sizeof(buff), "*%s*.*%s*", prog, param);
+
+   str = _evas_xcb_xdefaults_data;
+   ea = eina_str_split_full(str, "\n", -1, &count);
+   for (i = 0; i < count; i++) 
+     {
+        if (_evas_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 
+_evas_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;
+}
diff --git a/src/modules/engines/software_x11/evas_xcb_xdefaults.h b/src/modules/engines/software_x11/evas_xcb_xdefaults.h
new file mode 100644 (file)
index 0000000..c5f4ab8
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef EVAS_XCB_XDEFAULTS_H
+# define EVAS_XCB_XDEFAULTS_H
+
+# include "evas_engine.h"
+
+void _evas_xcb_xdefaults_init(void);
+void _evas_xcb_xdefaults_shutdown(void);
+char *_evas_xcb_xdefaults_string_get(const char *prog, const char *param);
+int _evas_xcb_xdefaults_int_get(const char *prog, const char *param);
+
+#endif