raster pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=148aec9d9c79bd1eff54c7f82d404456a2fcd9d8

commit 148aec9d9c79bd1eff54c7f82d404456a2fcd9d8
Author: Carsten Haitzler (Rasterman) <ras...@rasterman.com>
Date:   Sun Nov 22 20:30:04 2020 +0000

    ecore-x - add xresource set/get/load etc.
    
    new ecore-x calls to support the things xrdb does
    
    @feat
---
 src/lib/ecore_x/Ecore_X.h          |   5 ++
 src/lib/ecore_x/ecore_x.c          |   1 +
 src/lib/ecore_x/ecore_x_private.h  |   2 +
 src/lib/ecore_x/ecore_x_resource.c | 116 +++++++++++++++++++++++++++++++++++++
 src/lib/ecore_x/meson.build        |   1 +
 5 files changed, 125 insertions(+)

diff --git a/src/lib/ecore_x/Ecore_X.h b/src/lib/ecore_x/Ecore_X.h
index 4a1ab61472..ae82a549ce 100644
--- a/src/lib/ecore_x/Ecore_X.h
+++ b/src/lib/ecore_x/Ecore_X.h
@@ -2802,6 +2802,11 @@ EAPI Eina_Bool                             
ecore_x_window_keygrab_unset(Ecore_X_
 EAPI void                                  
ecore_x_e_keyrouter_set(Ecore_X_Window root, Eina_Bool on); /**< @since 1.15 */ 
//Key router set keyrouter flag using this
 EAPI Eina_Bool                             
ecore_x_e_keyrouter_get(Ecore_X_Window root); /**< @since 1.15 */ //Client 
check the existence of keyrouter using this
 
+EAPI void                                  ecore_x_rersource_load(const char 
*file); /** @since 1.26 */
+EAPI void                                  
ecore_x_resource_db_string_set(const char *key, const char *val); /** @since 
1.26 */
+EAPI const char                           
*ecore_x_resource_db_string_get(const char *key); /** @since 1.26 */
+EAPI void                                  ecore_x_resource_db_flush(void); 
/** @since 1.26 */
+
 #ifdef EFL_BETA_API_SUPPORT
 // XXX: FIXME: re-evaluate this after looking at xdg foreign in wayland
 EAPI void                                  
ecore_x_e_stack_type_set(Ecore_X_Window win, Ecore_X_Stack_Type stack_type);
diff --git a/src/lib/ecore_x/ecore_x.c b/src/lib/ecore_x/ecore_x.c
index 0ad3befd22..c78e6adbb1 100644
--- a/src/lib/ecore_x/ecore_x.c
+++ b/src/lib/ecore_x/ecore_x.c
@@ -836,6 +836,7 @@ _ecore_x_shutdown(void)
    _ecore_x_input_shutdown();
    _ecore_x_selection_shutdown();
    _ecore_x_dnd_shutdown();
+   _ecore_x_resource_shutdown();
    ecore_x_netwm_shutdown();
 
    return 0;
diff --git a/src/lib/ecore_x/ecore_x_private.h 
b/src/lib/ecore_x/ecore_x_private.h
index d0d6a9c168..ec14111b70 100644
--- a/src/lib/ecore_x/ecore_x_private.h
+++ b/src/lib/ecore_x/ecore_x_private.h
@@ -383,6 +383,8 @@ Ecore_Event_Mouse_Button *_ecore_mouse_button(int event,
 void _ecore_x_modifiers_get(void);
 KeySym _ecore_x_XKeycodeToKeysym(Display *display, KeyCode keycode, int index);
 
+void _ecore_x_resource_shutdown(void);
+
 int _ecore_x_shutdown(void);
 //#define LOGFNS 1
 
diff --git a/src/lib/ecore_x/ecore_x_resource.c 
b/src/lib/ecore_x/ecore_x_resource.c
new file mode 100644
index 0000000000..c4b7eed3b1
--- /dev/null
+++ b/src/lib/ecore_x/ecore_x_resource.c
@@ -0,0 +1,116 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif /* ifdef HAVE_CONFIG_H */
+
+#include "ecore_x_private.h"
+
+static Eina_Bool _ecore_x_resource_initted = EINA_FALSE;
+static XrmDatabase _ecore_x_resource_db = NULL;
+
+static void
+_ecore_x_resource_init(void)
+{
+   if (_ecore_x_resource_initted) return;
+   XrmInitialize();
+   _ecore_x_resource_initted = EINA_TRUE;
+}
+
+void
+_ecore_x_resource_shutdown(void)
+{
+   if (!_ecore_x_disp) return;
+   if (!_ecore_x_resource_initted) return;
+   if (_ecore_x_resource_db) _ecore_x_resource_db = NULL;
+   _ecore_x_resource_initted = EINA_FALSE;
+}
+
+EAPI void
+ecore_x_rersource_load(const char *file)
+{
+   XrmDatabase db;
+
+   if (!_ecore_x_disp) return;
+   _ecore_x_resource_init();
+   db = XrmGetFileDatabase(file);
+   if (!db) return;
+   if (_ecore_x_resource_db) XrmDestroyDatabase(_ecore_x_resource_db);
+   _ecore_x_resource_db = db;
+   XrmSetDatabase(_ecore_x_disp, db);
+}
+
+EAPI void
+ecore_x_resource_db_string_set(const char *key, const char *val)
+{
+   if (!_ecore_x_disp) return;
+   _ecore_x_resource_init();
+   if ((!key) || (!val)) return;
+   if (!_ecore_x_resource_db)
+     _ecore_x_resource_db = XrmGetDatabase(_ecore_x_disp);
+   XrmPutStringResource(&_ecore_x_resource_db, key, val);
+}
+
+EAPI const char *
+ecore_x_resource_db_string_get(const char *key)
+{
+   char *type = NULL;
+   XrmValue xval = { 0, NULL };
+
+   if (!_ecore_x_disp) return NULL;
+   _ecore_x_resource_init();
+   if (!_ecore_x_resource_db)
+     _ecore_x_resource_db = XrmGetDatabase(_ecore_x_disp);
+   if (XrmGetResource(_ecore_x_resource_db, key, "String", &type, &xval))
+     {
+        if (xval.addr && (!strcmp(type, "String")))
+          {
+             if (xval.size > 0) return xval.addr;
+          }
+     }
+   return NULL;
+}
+
+EAPI void
+ecore_x_resource_db_flush(void)
+{
+   Ecore_X_Atom atom, type;
+   Ecore_X_Window *roots;
+   int i, num, fd;
+   char *str;
+   Eina_Tmpstr *path = NULL;
+   off_t offset;
+
+   if (!_ecore_x_disp) return;
+   _ecore_x_resource_init();
+   if (!_ecore_x_resource_db) return;
+   fd = eina_file_mkstemp("ecore-x-resource-XXXXXX", &path);
+   if (fd < 0) return;
+   XrmPutFileDatabase(_ecore_x_resource_db, path);
+   offset = lseek(fd, 0, SEEK_END);
+   if (offset > 0)
+     {
+        lseek(fd, 0, SEEK_SET);
+        str = malloc(offset + 1);
+        if (str)
+          {
+             if (read(fd, str, offset) == offset)
+               {
+                  str[offset] = 0;
+                  atom = XInternAtom(_ecore_x_disp, "RESOURCE_MANAGER", False);
+                  type = ECORE_X_ATOM_STRING;
+                  roots = ecore_x_window_root_list(&num);
+                  if (roots)
+                    {
+                       for (i = 0; i < num; i++)
+                         ecore_x_window_prop_property_set(roots[i],
+                                                          atom, type,
+                                                          8, str, offset);
+                       free(roots);
+                    }
+               }
+             free(str);
+          }
+     }
+   eina_tmpstr_del(path);
+   close(fd);
+   unlink(path);
+}
diff --git a/src/lib/ecore_x/meson.build b/src/lib/ecore_x/meson.build
index 608d3cda22..c62ec4df99 100644
--- a/src/lib/ecore_x/meson.build
+++ b/src/lib/ecore_x/meson.build
@@ -43,6 +43,7 @@ ecore_x_src = files([
   'ecore_x_xi2.c',
   'ecore_x_vsync.c',
   'ecore_x_gesture.c',
+  'ecore_x_resource.c',
   'ecore_x_private.h'
 ])
 

-- 


Reply via email to