1
#include "gpesettings_store.h"
3
XSettingsClient *client;
5
static GdkFilterReturn xsettings_event_filter (GdkXEvent *xevp, GdkEvent *ev, gpointer p)
7
if (xsettings_client_process_event (client, (XEvent *)xevp))
8
return GDK_FILTER_REMOVE;
10
return GDK_FILTER_CONTINUE;
13
static void notify_func (const char *name, XSettingsAction action,
14
XSettingsSetting *setting, void *cb_data)
18
if (strncmp(name,"dasher/",7)==0) {
19
length = strlen(name);
20
settingname = (char *)malloc(length*sizeof(char));
21
for (size_t i=0; i<length; i++) {
22
settingname[i]=name[i+7];
29
watch_func (Window window,
36
gdkwin = gdk_window_lookup (window);
41
gdkwin = gdk_window_foreign_new (window);
43
g_object_ref (gdkwin);
45
gdk_window_add_filter (gdkwin, xsettings_event_filter, NULL);
49
g_object_unref (gdkwin);
50
gdk_window_remove_filter (gdkwin, xsettings_event_filter, NULL);
57
client=xsettings_client_new(GDK_DISPLAY(),DefaultScreen(GDK_DISPLAY()), notify_func, watch_func, NULL);
60
bool get_long_option_callback(const std::string& Key, long *value)
64
snprintf( keypath, 1024, "dasher/%s", Key.c_str() );
66
XSettingsSetting *setting;
68
if (xsettings_client_get_setting (client,keypath, &setting) != XSETTINGS_SUCCESS) {
72
if (setting->type==XSETTINGS_TYPE_INT) {
73
*value=setting->data.v_int;
79
bool get_bool_option_callback(const std::string& Key, bool *value)
82
if(get_long_option_callback(Key,&tmp)==false) {
93
bool get_string_option_callback(const std::string& Key, std::string *value)
97
snprintf( keypath, 1024, "dasher/%s", Key.c_str() );
99
XSettingsSetting *setting;
101
if (xsettings_client_get_setting (client,keypath, &setting) != XSETTINGS_SUCCESS) {
105
if (setting->type==XSETTINGS_TYPE_STRING) {
106
*value=setting->data.v_string;
112
void set_long_option_callback(const std::string& Key, long Value)
116
Atom gpe_settings_update_atom = XInternAtom (GDK_DISPLAY(), "_GPE_SETTINGS_UPDATE", 0);
117
Window manager = XGetSelectionOwner (GDK_DISPLAY(), gpe_settings_update_atom);
119
size_t length, name_len;
121
XClientMessageEvent ev;
122
gboolean done = FALSE;
126
get_long_option_callback(Key,¤tvalue);
128
if (currentvalue==Value)
131
snprintf( keypath, 1024, "dasher/%s", Key.c_str() );
133
if (manager == None) {
134
fprintf (stderr, "gpe-confd not running.\n");
137
win = XCreateSimpleWindow (GDK_DISPLAY(), DefaultRootWindow (GDK_DISPLAY()), 1, 1, 1, 1, 0, 0, 0);
139
type = XSETTINGS_TYPE_INT;
142
name_len = strlen(keypath);
143
// This crack rounds up to the nearest 4
144
name_len = (name_len +3) & ~3;
145
buffer = (gchar *)g_malloc(length + 4 + name_len);
148
buffer[2] = name_len & 0xff;
149
buffer[3] = (name_len >> 8) & 0xff;
150
memcpy (buffer + 4, keypath, name_len);
151
*((unsigned long *)(buffer + 4 + name_len)) = realvalue;
153
XChangeProperty (GDK_DISPLAY(), win, gpe_settings_update_atom,
154
gpe_settings_update_atom, 8, PropModeReplace, (const unsigned char*)buffer,
155
length + 4 + name_len);
157
XSelectInput (GDK_DISPLAY(), win, PropertyChangeMask);
158
ev.type = ClientMessage;
160
ev.message_type = gpe_settings_update_atom;
162
ev.data.l[0] = gpe_settings_update_atom;
163
XSendEvent (GDK_DISPLAY(), manager, FALSE, 0, (XEvent *)&ev);
168
XNextEvent (GDK_DISPLAY(), &ev);
169
switch (ev.xany.type)
172
if (ev.xproperty.window == win
173
&& ev.xproperty.atom == gpe_settings_update_atom)
180
void set_bool_option_callback(const std::string& Key, bool Value)
182
set_long_option_callback(Key, long(Value));
185
void set_string_option_callback(const std::string& Key, const std::string& Value)
187
Atom gpe_settings_update_atom = XInternAtom (GDK_DISPLAY(), "_GPE_SETTINGS_UPDATE", 0);
188
Window manager = XGetSelectionOwner (GDK_DISPLAY(), gpe_settings_update_atom);
190
std::string currentvalue;
191
size_t length, name_len;
193
XClientMessageEvent ev;
194
gboolean done = FALSE;
198
get_string_option_callback(Key,¤tvalue);
199
if (currentvalue==Value)
202
snprintf( keypath, 1024, "dasher/%s", Key.c_str() );
204
if (manager == None) {
205
fprintf (stderr, "gpe-confd not running.\n");
208
win = XCreateSimpleWindow (GDK_DISPLAY(), DefaultRootWindow (GDK_DISPLAY()), 1, 1, 1, 1, 0, 0, 0);
210
type = XSETTINGS_TYPE_STRING;
211
length = 4+(strlen(Value.c_str()) +3) & ~3;
213
name_len = strlen(keypath);
214
// As does this crack
215
name_len = (name_len+3) & ~3;
216
buffer = (gchar *)g_malloc(length + 4 + name_len);
219
buffer[2] = name_len & 0xff;
220
buffer[3] = (name_len >> 8) & 0xff;
221
memcpy (buffer + 4, keypath, name_len);
222
*((unsigned long *)(buffer + 4 + name_len)) = strlen(Value.c_str());
223
memcpy (buffer + 8 + name_len, Value.c_str(), strlen (Value.c_str()));
224
XChangeProperty (GDK_DISPLAY(), win, gpe_settings_update_atom,
225
gpe_settings_update_atom, 8, PropModeReplace, (const unsigned char*)buffer,
226
length + 4 + name_len);
228
XSelectInput (GDK_DISPLAY(), win, PropertyChangeMask);
229
ev.type = ClientMessage;
231
ev.message_type = gpe_settings_update_atom;
233
ev.data.l[0] = gpe_settings_update_atom;
234
XSendEvent (GDK_DISPLAY(), manager, FALSE, 0, (XEvent *)&ev);
238
XNextEvent (GDK_DISPLAY(), &ev);
240
switch (ev.xany.type)
243
if (ev.xproperty.window == win
244
&& ev.xproperty.atom == gpe_settings_update_atom)