diff --git a/capplets/common/ChangeLog b/capplets/common/ChangeLog index ed696f659..bee1ea977 100644 --- a/capplets/common/ChangeLog +++ b/capplets/common/ChangeLog @@ -1,3 +1,9 @@ +2002-06-21 Stephen Browne + + * wm-common.[ch] : added new files to expose + wm_common_get_current_window_manager and + wm_common_register_window_manager_change + 2002-06-13 Jody Goldberg * capplet-util.c (capplet_help) : Use the new utility. diff --git a/capplets/common/Makefile.am b/capplets/common/Makefile.am index 6cdc0191e..0ae16f431 100644 --- a/capplets/common/Makefile.am +++ b/capplets/common/Makefile.am @@ -17,6 +17,7 @@ libcommon_la_SOURCES = \ gconf-property-editor.c gconf-property-editor.h \ gconf-property-editor-marshal.c gconf-property-editor-marshal.h \ file-transfer-dialog.c file-transfer-dialog.h \ - theme-common.c theme-common.h + theme-common.c theme-common.h \ + wm-common.c wm-common.h libcommon_la_LIBADD = $(top_builddir)/libbackground/libbackground.la diff --git a/capplets/common/wm-common.c b/capplets/common/wm-common.c new file mode 100644 index 000000000..c8ddf462d --- /dev/null +++ b/capplets/common/wm-common.c @@ -0,0 +1,149 @@ +#include +#include +#include +#include +#include +#include +#include "wm-common.h" + +typedef struct _WMCallbackData +{ + GFunc func; + gpointer data; +} WMCallbackData; + +/* Our WM Window */ +static Window wm_window = None; + +char* +wm_common_get_current_window_manager (void) +{ + Atom utf8_string, atom, type; + int result; + char *retval; + int format; + gulong nitems; + gulong bytes_after; + guchar *val; + + if (wm_window == None) + return WM_COMMON_UNKNOWN; + + utf8_string = XInternAtom (GDK_DISPLAY (), "UTF8_STRING", False); + atom = XInternAtom (GDK_DISPLAY (), "_NET_WM_NAME", False); + + gdk_error_trap_push (); + + result = XGetWindowProperty (GDK_DISPLAY (), + wm_window, + atom, + 0, G_MAXLONG, + False, utf8_string, + &type, &format, &nitems, + &bytes_after, (guchar **)&val); + + if (gdk_error_trap_pop () || result != Success) + return WM_COMMON_UNKNOWN; + + if (type != utf8_string || + format !=8 || + nitems == 0) + { + if (val) + XFree (val); + return WM_COMMON_UNKNOWN; + } + + if (!g_utf8_validate (val, nitems, NULL)) + { + XFree (val); + return WM_COMMON_UNKNOWN; + } + + retval = g_strndup (val, nitems); + + XFree (val); + + return retval; +} + +static void +update_wm_window (void) +{ + Window *xwindow; + Atom type; + gint format; + gulong nitems; + gulong bytes_after; + + XGetWindowProperty (GDK_DISPLAY (), GDK_ROOT_WINDOW (), + XInternAtom (GDK_DISPLAY (), "_NET_SUPPORTING_WM_CHECK", False), + 0, G_MAXLONG, False, XA_WINDOW, &type, &format, + &nitems, &bytes_after, (guchar **) &xwindow); + + if (type != XA_WINDOW) + { + wm_window = None; + return; + } + + gdk_error_trap_push (); + XSelectInput (GDK_DISPLAY (), *xwindow, StructureNotifyMask | PropertyChangeMask); + XSync (GDK_DISPLAY (), False); + + if (gdk_error_trap_pop ()) + { + XFree (xwindow); + wm_window = None; + return; + } + + wm_window = *xwindow; + XFree (xwindow); +} + +static GdkFilterReturn +wm_window_event_filter (GdkXEvent *xev, + GdkEvent *event, + gpointer data) +{ + WMCallbackData *ncb_data = (WMCallbackData*) data; + XEvent *xevent = (XEvent *)xev; + + if ((xevent->type == DestroyNotify && + wm_window != None && xevent->xany.window == wm_window) || + (xevent->type == PropertyNotify && + xevent->xany.window == GDK_ROOT_WINDOW () && + xevent->xproperty.atom == (XInternAtom (GDK_DISPLAY (), "_NET_SUPPORTING_WM_CHECK", False))) || + (xevent->type == PropertyNotify && + wm_window != None && xevent->xany.window == wm_window && + xevent->xproperty.atom == (XInternAtom (GDK_DISPLAY (), "_NET_WM_NAME", False)))) + { + update_wm_window (); + (* ncb_data->func) ((gpointer)wm_common_get_current_window_manager(), + ncb_data->data); + } + + return GDK_FILTER_CONTINUE; +} + +void +wm_common_register_window_manager_change (GFunc func, + gpointer data) +{ + WMCallbackData *ncb_data; + + ncb_data = g_new0 (WMCallbackData, 1); + + ncb_data->func = func; + ncb_data->data = data; + + gdk_window_add_filter (NULL, wm_window_event_filter, ncb_data); + + update_wm_window (); + + XSelectInput (GDK_DISPLAY (), GDK_ROOT_WINDOW (), PropertyChangeMask); + XSync (GDK_DISPLAY (), False); +} + + diff --git a/capplets/common/wm-common.h b/capplets/common/wm-common.h new file mode 100644 index 000000000..08c7145d0 --- /dev/null +++ b/capplets/common/wm-common.h @@ -0,0 +1,13 @@ +#ifndef WM_COMMON_H +#define WM_COMMON_H + +#define WM_COMMON_METACITY "Metacity" +#define WM_COMMON_SAWFISH "Sawfish" +#define WM_COMMON_UNKNOWN "Unknown" + +gchar *wm_common_get_current_window_manager (void); +void wm_common_register_window_manager_change (GFunc func, + gpointer data); + +#endif /* WM_COMMON_H */ + diff --git a/capplets/keybindings/ChangeLog b/capplets/keybindings/ChangeLog index 05589b12a..f3d9b47b9 100644 --- a/capplets/keybindings/ChangeLog +++ b/capplets/keybindings/ChangeLog @@ -1,3 +1,9 @@ +2002-06-21 Stephen Browne + + * gnome-keybinding-properties.c : moved metacity detection + out of here and into a more generic API in capplets/common/wm-common.c + + 2002-06-17 Jody Goldberg * Release 2.0.0 diff --git a/capplets/keybindings/gnome-keybinding-properties.c b/capplets/keybindings/gnome-keybinding-properties.c index 01ebebddd..085f1be23 100644 --- a/capplets/keybindings/gnome-keybinding-properties.c +++ b/capplets/keybindings/gnome-keybinding-properties.c @@ -12,6 +12,7 @@ #include #include "theme-common.h" +#include "wm-common.h" #include "capplet-util.h" #include "eggcellrendererkeys.h" #include "activate-settings-daemon.h" @@ -107,149 +108,7 @@ typedef struct guint gconf_cnxn; } KeyEntry; -static void reload_key_entries (GladeXML *dialog); - -/* Our WM Window */ -static Window wm_window = None; - -static char * -get_wm_name (void) -{ - Atom utf8_string, atom, type; - int result; - char *retval; - int format; - gulong nitems; - gulong bytes_after; - guchar *val; - - if (wm_window == None) - return NULL; - - utf8_string = XInternAtom (GDK_DISPLAY (), "UTF8_STRING", False); - atom = XInternAtom (GDK_DISPLAY (), "_NET_WM_NAME", False); - - gdk_error_trap_push (); - - result = XGetWindowProperty (GDK_DISPLAY (), - wm_window, - atom, - 0, G_MAXLONG, - False, utf8_string, - &type, &format, &nitems, - &bytes_after, (guchar **)&val); - - if (gdk_error_trap_pop () || result != Success) - return NULL; - - if (type != utf8_string || - format != 8 || - nitems == 0) - { - if (val) - XFree (val); - return NULL; - } - - if (!g_utf8_validate (val, nitems, NULL)) - { - XFree (val); - return NULL; - } - - retval = g_strndup (val, nitems); - - XFree (val); - - return retval; -} - -static gboolean -is_metacity_running (void) -{ - char *wm_name; - - wm_name = get_wm_name (); - - if (wm_name && - strcmp (wm_name, "Metacity") == 0) - { - g_free (wm_name); - return TRUE; - } - - g_free (wm_name); - return FALSE; -} - -static void -update_wm_window (void) -{ - Window *xwindow; - Atom type; - gint format; - gulong nitems; - gulong bytes_after; - - XGetWindowProperty (GDK_DISPLAY (), GDK_ROOT_WINDOW (), - XInternAtom (GDK_DISPLAY (), "_NET_SUPPORTING_WM_CHECK", False), - 0, G_MAXLONG, False, XA_WINDOW, &type, &format, - &nitems, &bytes_after, (guchar **) &xwindow); - - if (type != XA_WINDOW) - { - wm_window = None; - return; - } - - gdk_error_trap_push (); - XSelectInput (GDK_DISPLAY (), *xwindow, StructureNotifyMask | PropertyChangeMask); - XSync (GDK_DISPLAY (), False); - - if (gdk_error_trap_pop ()) - { - XFree (xwindow); - wm_window = None; - return; - } - - wm_window = *xwindow; - XFree (xwindow); -} - -static GdkFilterReturn -wm_window_event_filter (GdkXEvent *xev, - GdkEvent *event, - gpointer data) -{ - XEvent *xevent = (XEvent *)xev; - - if ((xevent->type == DestroyNotify && - wm_window != None && xevent->xany.window == wm_window) || - (xevent->type == PropertyNotify && - xevent->xany.window == GDK_ROOT_WINDOW () && - xevent->xproperty.atom == (XInternAtom (GDK_DISPLAY (), "_NET_SUPPORTING_WM_CHECK", False))) || - (xevent->type == PropertyNotify && - wm_window != None && xevent->xany.window == wm_window && - xevent->xproperty.atom == (XInternAtom (GDK_DISPLAY (), "_NET_WM_NAME", False)))) - { - update_wm_window (); - reload_key_entries (data); - } - - return GDK_FILTER_CONTINUE; -} - -static void -initialize_wm_handling (GladeXML *dialog) -{ - gdk_window_add_filter (NULL, wm_window_event_filter, dialog); - - update_wm_window (); - - XSelectInput (GDK_DISPLAY (), GDK_ROOT_WINDOW (), PropertyChangeMask); - XSync (GDK_DISPLAY (), False); -} +static void reload_key_entries (gpointer wm_name, GladeXML *dialog); static void menu_item_activate (GtkWidget *menu_item, @@ -591,13 +450,13 @@ append_keys_to_tree (GladeXML *dialog, } static void -reload_key_entries (GladeXML *dialog) +reload_key_entries (gpointer wm_name, GladeXML *dialog) { clear_old_model (dialog, WID ("shortcut_treeview")); append_keys_to_tree (dialog, _("Desktop"), desktop_key_list); - if (is_metacity_running ()) + if (strcmp((char *) wm_name, WM_COMMON_METACITY) == 0) { append_keys_to_tree (dialog, _("Window Management"), metacity_key_list); } @@ -609,7 +468,7 @@ key_entry_controlling_key_changed (GConfClient *client, GConfEntry *entry, gpointer user_data) { - reload_key_entries (user_data); + reload_key_entries (wm_common_get_current_window_manager(), user_data); } static void @@ -896,7 +755,7 @@ setup_dialog (GladeXML *dialog) dialog, NULL, NULL); /* set up the dialog */ - reload_key_entries (dialog); + reload_key_entries (wm_common_get_current_window_manager(), dialog); widget = WID ("gnome-keybinding-dialog"); filename = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_APP_PIXMAP, "keyboard-shortcut.png", TRUE, NULL); @@ -929,7 +788,7 @@ main (int argc, char *argv[]) activate_settings_daemon (); dialog = create_dialog (); - initialize_wm_handling (dialog); + wm_common_register_window_manager_change ((GFunc)(reload_key_entries), dialog); setup_dialog (dialog); gtk_main ();