ecore-x - add xresource set/get/load etc.

new ecore-x calls to support the things xrdb does

@feat
This commit is contained in:
Carsten Haitzler 2020-11-22 20:30:04 +00:00
parent 5f8e4dabea
commit 148aec9d9c
5 changed files with 125 additions and 0 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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

View File

@ -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);
}

View File

@ -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'
])