#include "xsettings-client.h"
+#include <gdk/x11/gdkx11display.h>
+#include <gdk/x11/gdkx11screen.h>
+#include <gdk/x11/gdkx11window.h>
+
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
struct _XSettingsClient
{
+ GdkScreen *screen;
Display *display;
- int screen;
XSettingsNotifyFunc notify;
XSettingsWatchFunc watch;
void *cb_data;
- XSettingsGrabFunc grab;
- XSettingsGrabFunc ungrab;
-
Window manager_window;
Atom manager_atom;
Atom selection_atom;
Atom xsettings_atom;
- XSettingsList *settings;
+ GHashTable *settings; /* string => XSettingsSetting */
};
static void
notify_changes (XSettingsClient *client,
- XSettingsList *old_list)
+ GHashTable *old_list)
{
GHashTableIter iter;
XSettingsSetting *setting, *old_setting;
g_hash_table_iter_init (&iter, client->settings);
while (g_hash_table_iter_next (&iter, NULL, (gpointer*) &setting))
{
- old_setting = xsettings_list_lookup (old_list, setting->name);
+ old_setting = old_list ? g_hash_table_lookup (old_list, setting->name) : NULL;
if (old_setting == NULL)
client->notify (setting->name, XSETTINGS_ACTION_NEW, setting, client->cb_data);
#define XSETTINGS_PAD(n,m) ((n + m - 1) & (~(m-1)))
-static XSettingsList *
+static GHashTable *
parse_settings (unsigned char *data,
size_t len)
{
XSettingsBuffer buffer;
XSettingsResult result = XSETTINGS_SUCCESS;
- XSettingsList *settings = NULL;
+ GHashTable *settings = NULL;
CARD32 serial;
CARD32 n_entries;
CARD32 i;
setting->name[name_len] = '\0';
buffer.pos += pad_len;
+ /* last change serial (we ignore it) */
result = fetch_card32 (&buffer, &v_int);
if (result != XSETTINGS_SUCCESS)
goto out;
- setting->last_change_serial = v_int;
switch (type)
{
setting->type = type;
- result = xsettings_list_insert (&settings, setting);
- if (result != XSETTINGS_SUCCESS)
- goto out;
+ if (settings == NULL)
+ settings = g_hash_table_new_full (g_str_hash, g_str_equal,
+ NULL,
+ (GDestroyNotify) xsettings_setting_free);
+
+ if (g_hash_table_lookup (settings, setting->name) != NULL)
+ {
+ result = XSETTINGS_DUPLICATE_ENTRY;
+ goto out;
+ }
+ g_hash_table_insert (settings, setting->name, setting);
setting = NULL;
}
if (setting)
xsettings_setting_free (setting);
- xsettings_list_free (settings);
+ if (settings)
+ g_hash_table_unref (settings);
settings = NULL;
-
}
return settings;
int (*old_handler) (Display *, XErrorEvent *);
- XSettingsList *old_list = client->settings;
+ GHashTable *old_list = client->settings;
client->settings = NULL;
}
notify_changes (client, old_list);
- xsettings_list_free (old_list);
+ if (old_list)
+ g_hash_table_unref (old_list);
}
static void
if (client->manager_window && client->watch)
client->watch (client->manager_window, False, 0, client->cb_data);
- if (client->grab)
- client->grab (client->display);
- else
- XGrabServer (client->display);
+ gdk_x11_display_grab (gdk_screen_get_display (client->screen));
client->manager_window = XGetSelectionOwner (client->display,
client->selection_atom);
XSelectInput (client->display, client->manager_window,
PropertyChangeMask | StructureNotifyMask);
- if (client->ungrab)
- client->ungrab (client->display);
- else
- XUngrabServer (client->display);
+ gdk_x11_display_ungrab (gdk_screen_get_display (client->screen));
XFlush (client->display);
}
XSettingsClient *
-xsettings_client_new (Display *display,
- int screen,
+xsettings_client_new (GdkScreen *screen,
XSettingsNotifyFunc notify,
XSettingsWatchFunc watch,
- void *cb_data,
- XSettingsGrabFunc grab,
- XSettingsGrabFunc ungrab)
+ void *cb_data)
{
XSettingsClient *client;
char buffer[256];
if (!client)
return NULL;
- client->display = display;
client->screen = screen;
+ client->display = gdk_x11_display_get_xdisplay (gdk_screen_get_display (screen));
client->notify = notify;
client->watch = watch;
client->cb_data = cb_data;
- client->grab = grab;
- client->ungrab = ungrab;
client->manager_window = None;
client->settings = NULL;
- sprintf(buffer, "_XSETTINGS_S%d", screen);
+ sprintf(buffer, "_XSETTINGS_S%d", gdk_x11_screen_get_screen_number (screen));
atom_names[0] = buffer;
atom_names[1] = "_XSETTINGS_SETTINGS";
atom_names[2] = "MANAGER";
- XInternAtoms (display, atom_names, 3, False, atoms);
+ XInternAtoms (client->display, atom_names, 3, False, atoms);
client->selection_atom = atoms[0];
client->xsettings_atom = atoms[1];
/* Select on StructureNotify so we get MANAGER events
*/
- add_events (display, RootWindow (display, screen), StructureNotifyMask);
+ add_events (client->display, gdk_x11_window_get_xid (gdk_screen_get_root_window (screen)), StructureNotifyMask);
if (client->watch)
- client->watch (RootWindow (display, screen), True, StructureNotifyMask,
+ client->watch (gdk_x11_window_get_xid (gdk_screen_get_root_window (screen)), True, StructureNotifyMask,
client->cb_data);
check_manager_window (client);
return client;
}
-
-void
-xsettings_client_set_grab_func (XSettingsClient *client,
- XSettingsGrabFunc grab)
-{
- client->grab = grab;
-}
-
-void
-xsettings_client_set_ungrab_func (XSettingsClient *client,
- XSettingsGrabFunc ungrab)
-{
- client->ungrab = ungrab;
-}
-
void
xsettings_client_destroy (XSettingsClient *client)
{
if (client->watch)
- client->watch (RootWindow (client->display, client->screen),
+ client->watch (gdk_x11_window_get_xid (gdk_screen_get_root_window (client->screen)),
False, 0, client->cb_data);
if (client->manager_window && client->watch)
client->watch (client->manager_window, False, 0, client->cb_data);
- xsettings_list_free (client->settings);
+ if (client->settings)
+ g_hash_table_unref (client->settings);
free (client);
}
-XSettingsResult
+const XSettingsSetting *
xsettings_client_get_setting (XSettingsClient *client,
- const char *name,
- XSettingsSetting **setting)
+ const char *name)
{
- XSettingsSetting *search = xsettings_list_lookup (client->settings, name);
- if (search)
- {
- *setting = xsettings_setting_copy (search);
- return *setting ? XSETTINGS_SUCCESS : XSETTINGS_NO_MEM;
- }
- else
- return XSETTINGS_NO_ENTRY;
+ return g_hash_table_lookup (client->settings, name);
}
Bool
* times when the manager changes from A->B. But manager changes
* are going to be pretty rare.
*/
- if (xev->xany.window == RootWindow (client->display, client->screen))
+ if (xev->xany.window == gdk_x11_window_get_xid (gdk_screen_get_root_window (client->screen)))
{
if (xev->xany.type == ClientMessage &&
xev->xclient.message_type == client->manager_atom &&
return False;
}
+
+int
+xsettings_setting_equal (XSettingsSetting *setting_a,
+ XSettingsSetting *setting_b)
+{
+ if (setting_a->type != setting_b->type)
+ return 0;
+
+ if (strcmp (setting_a->name, setting_b->name) != 0)
+ return 0;
+
+ switch (setting_a->type)
+ {
+ case XSETTINGS_TYPE_INT:
+ return setting_a->data.v_int == setting_b->data.v_int;
+ case XSETTINGS_TYPE_COLOR:
+ return (setting_a->data.v_color.red == setting_b->data.v_color.red &&
+ setting_a->data.v_color.green == setting_b->data.v_color.green &&
+ setting_a->data.v_color.blue == setting_b->data.v_color.blue &&
+ setting_a->data.v_color.alpha == setting_b->data.v_color.alpha);
+ case XSETTINGS_TYPE_STRING:
+ return strcmp (setting_a->data.v_string, setting_b->data.v_string) == 0;
+ }
+
+ return 0;
+}
+
+void
+xsettings_setting_free (XSettingsSetting *setting)
+{
+ if (setting->type == XSETTINGS_TYPE_STRING)
+ free (setting->data.v_string);
+
+ if (setting->name)
+ free (setting->name);
+
+ free (setting);
+}
+