From b2e928dc0788f856bcb1e67450a2a0b28962a415 Mon Sep 17 00:00:00 2001 From: Owen Taylor Date: Fri, 27 Feb 2004 01:00:08 +0000 Subject: Thu Feb 26 19:55:29 2004 Owen Taylor * xsettings-client.[ch]: Add xsettings_client_set_grab_func(), xsettings_client_set_ungrab_func() to allow users to control exactly how server grabs are done. (In case the user has a refcounted grab facility, for instance.) (Patch by Soeren Sandmann) * xsettings-client.c: Use XInternAtoms() to reduce roundtrips. * xsettings-client.c: Fix a memory leak for XGetWindowProperty() on type mismatch. --- xsettings/ChangeLog | 15 ++++++++ xsettings/xsettings-client.c | 85 ++++++++++++++++++++++++++++++++------------ xsettings/xsettings-client.h | 28 ++++++++------- 3 files changed, 94 insertions(+), 34 deletions(-) diff --git a/xsettings/ChangeLog b/xsettings/ChangeLog index aa08127..fe8d039 100644 --- a/xsettings/ChangeLog +++ b/xsettings/ChangeLog @@ -1,3 +1,18 @@ +Thu Feb 26 19:55:29 2004 Owen Taylor + + * xsettings-client.[ch]: Add + xsettings_client_set_grab_func(), + xsettings_client_set_ungrab_func() to allow users to + control exactly how server grabs are done. (In case + the user has a refcounted grab facility, for instance.) + (Patch by Soeren Sandmann) + + * xsettings-client.c: Use XInternAtoms() to reduce + roundtrips. + + * xsettings-client.c: Fix a memory leak for + XGetWindowProperty() on type mismatch. + Mon Dec 2 20:24:02 2002 Owen Taylor * xsettings.xml: Fix ordering of color components. diff --git a/xsettings/xsettings-client.c b/xsettings/xsettings-client.c index 7be2dd1..8b81b45 100644 --- a/xsettings/xsettings-client.c +++ b/xsettings/xsettings-client.c @@ -38,6 +38,9 @@ struct _XSettingsClient XSettingsWatchFunc watch; void *cb_data; + XSettingsGrabFunc grab; + XSettingsGrabFunc ungrab; + Window manager_window; Atom manager_atom; Atom selection_atom; @@ -370,24 +373,31 @@ read_settings (XSettingsClient *client) XSettingsList *old_list = client->settings; client->settings = NULL; - - old_handler = XSetErrorHandler (ignore_errors); - result = XGetWindowProperty (client->display, client->manager_window, - client->xsettings_atom, 0, LONG_MAX, - False, client->xsettings_atom, - &type, &format, &n_items, &bytes_after, &data); - XSetErrorHandler (old_handler); - - if (result == Success && type == client->xsettings_atom) + + if (client->manager_window) { - if (format != 8) + old_handler = XSetErrorHandler (ignore_errors); + result = XGetWindowProperty (client->display, client->manager_window, + client->xsettings_atom, 0, LONG_MAX, + False, client->xsettings_atom, + &type, &format, &n_items, &bytes_after, &data); + XSetErrorHandler (old_handler); + + if (result == Success && type != None) { - fprintf (stderr, "Invalid format for XSETTINGS property %d", format); + if (type != client->xsettings_atom) + { + fprintf (stderr, "Invalid type for XSETTINGS property"); + } + eles if (format != 8) + { + fprintf (stderr, "Invalid format for XSETTINGS property %d", format); + } + else + client->settings = parse_settings (data, n_items); + + XFree (data); } - else - client->settings = parse_settings (data, n_items); - - XFree (data); } notify_changes (client, old_list); @@ -410,8 +420,11 @@ check_manager_window (XSettingsClient *client) { if (client->manager_window && client->watch) client->watch (client->manager_window, False, 0, client->cb_data); - - XGrabServer (client->display); + + if (client->grab) + client->grab (client->display); + else + XGrabServer (client->display); client->manager_window = XGetSelectionOwner (client->display, client->selection_atom); @@ -419,7 +432,11 @@ check_manager_window (XSettingsClient *client) XSelectInput (client->display, client->manager_window, PropertyChangeMask | StructureNotifyMask); - XUngrabServer (client->display); + if (client->ungrab) + client->ungrab (client->display); + else + XUngrabServer (client->display); + XFlush (client->display); if (client->manager_window && client->watch) @@ -439,7 +456,9 @@ xsettings_client_new (Display *display, { XSettingsClient *client; char buffer[256]; - + char *atom_names[3]; + Atom atoms[3]; + client = malloc (sizeof *client); if (!client) return NULL; @@ -449,14 +468,22 @@ xsettings_client_new (Display *display, client->notify = notify; client->watch = watch; client->cb_data = cb_data; + client->grab = NULL; + client->ungrab = NULL; client->manager_window = None; client->settings = NULL; sprintf(buffer, "_XSETTINGS_S%d", screen); - client->selection_atom = XInternAtom (display, buffer, False); - client->xsettings_atom = XInternAtom (display, "_XSETTINGS_SETTINGS", False); - client->manager_atom = XInternAtom (display, "MANAGER", False); + atom_names[0] = buffer; + atom_names[1] = "_XSETTINGS_SETTINGS"; + atom_names[2] = "MANAGER"; + + XInternAtoms (display, atom_names, 3, False, atoms); + + client->selection_atom = atoms[0]; + client->xsettings_atom = atoms[1]; + client->manager_atom = atoms[2]; /* Select on StructureNotify so we get MANAGER events */ @@ -471,6 +498,20 @@ xsettings_client_new (Display *display, 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) { diff --git a/xsettings/xsettings-client.h b/xsettings/xsettings-client.h index 1b13fe3..b916eba 100644 --- a/xsettings/xsettings-client.h +++ b/xsettings/xsettings-client.h @@ -47,19 +47,23 @@ typedef void (*XSettingsWatchFunc) (Window window, Bool is_start, long mask, void *cb_data); +typedef void (*XSettingsGrabFunc) (Display *display); -XSettingsClient *xsettings_client_new (Display *display, - int screen, - XSettingsNotifyFunc notify, - XSettingsWatchFunc watch, - void *cb_data); -void xsettings_client_destroy (XSettingsClient *client); -Bool xsettings_client_process_event (XSettingsClient *client, - XEvent *xev); - -XSettingsResult xsettings_client_get_setting (XSettingsClient *client, - const char *name, - XSettingsSetting **setting); +XSettingsClient *xsettings_client_new (Display *display, + int screen, + XSettingsNotifyFunc notify, + XSettingsWatchFunc watch, + void *cb_data); +void xsettings_client_set_grab_func (XSettingsClient *client, + XSettingsGrabFunc grab); +void xsettings_client_set_ungrab_func (XSettingsClient *client, + XSettingsGrabFunc ungrab); +void xsettings_client_destroy (XSettingsClient *client); +Bool xsettings_client_process_event (XSettingsClient *client, + XEvent *xev); +XSettingsResult xsettings_client_get_setting (XSettingsClient *client, + const char *name, + XSettingsSetting **setting); #ifdef __cplusplus } -- cgit v1.2.3-70-g09d2