diff options
author | Anders Carlsson <andersca@gnu.org> | 2002-05-05 23:04:45 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@src.gnome.org> | 2002-05-05 23:04:45 +0000 |
commit | 0f67005a9c6df61aa43419f2f514ec717f719b00 (patch) | |
tree | ad8a1cc7e6811229d1c2df77b4e225c81330fa10 /capplets/keybindings | |
parent | 0ea4906ae94b4d75bce37cf341f2293cda45af6e (diff) | |
download | gnome-control-center-0f67005a9c6df61aa43419f2f514ec717f719b00.tar.gz |
Update to latest eggcellrendererkeys.
2002-05-06 Anders Carlsson <andersca@gnu.org>
* eggcellrendererkeys.c: (grab_key_callback), (ungrab_stuff),
(pointless_eventbox_start_editing),
(egg_cell_renderer_keys_start_editing):
* eggcellrendererkeys.h:
Update to latest eggcellrendererkeys.
* gnome-keybinding-properties.c: (get_wm_name),
(is_metacity_running), (update_wm_window),
(wm_window_event_filter), (initialize_wm_handling),
(binding_from_string), (accel_set_func), (keybinding_key_changed),
(clear_old_model), (count_rows_foreach), (should_show_key),
(append_keys_to_tree), (reload_key_entries),
(key_entry_controlling_key_changed), (disable_collapsing_cb),
(setup_dialog), (main):
* gnome-keybinding-properties.glade:
Hard-code the list of keybindings. Add Metacity keybindings
and code for handling WM changes.
Diffstat (limited to 'capplets/keybindings')
-rw-r--r-- | capplets/keybindings/ChangeLog | 20 | ||||
-rw-r--r-- | capplets/keybindings/eggcellrendererkeys.c | 80 | ||||
-rw-r--r-- | capplets/keybindings/eggcellrendererkeys.h | 2 | ||||
-rw-r--r-- | capplets/keybindings/gnome-keybinding-properties.c | 443 | ||||
-rw-r--r-- | capplets/keybindings/gnome-keybinding-properties.glade | 27 |
5 files changed, 411 insertions, 161 deletions
diff --git a/capplets/keybindings/ChangeLog b/capplets/keybindings/ChangeLog index 7793ad6d4..93e96cf5c 100644 --- a/capplets/keybindings/ChangeLog +++ b/capplets/keybindings/ChangeLog @@ -1,3 +1,23 @@ +2002-05-06 Anders Carlsson <andersca@gnu.org> + + * eggcellrendererkeys.c: (grab_key_callback), (ungrab_stuff), + (pointless_eventbox_start_editing), + (egg_cell_renderer_keys_start_editing): + * eggcellrendererkeys.h: + Update to latest eggcellrendererkeys. + + * gnome-keybinding-properties.c: (get_wm_name), + (is_metacity_running), (update_wm_window), + (wm_window_event_filter), (initialize_wm_handling), + (binding_from_string), (accel_set_func), (keybinding_key_changed), + (clear_old_model), (count_rows_foreach), (should_show_key), + (append_keys_to_tree), (reload_key_entries), + (key_entry_controlling_key_changed), (disable_collapsing_cb), + (setup_dialog), (main): + * gnome-keybinding-properties.glade: + Hard-code the list of keybindings. Add Metacity keybindings + and code for handling WM changes. + 2002-04-26 Havoc Pennington <hp@pobox.com> * gnome-keybinding-properties.c (append_keys_to_tree): fix diff --git a/capplets/keybindings/eggcellrendererkeys.c b/capplets/keybindings/eggcellrendererkeys.c index 410dfaff9..1ddbe7704 100644 --- a/capplets/keybindings/eggcellrendererkeys.c +++ b/capplets/keybindings/eggcellrendererkeys.c @@ -5,13 +5,17 @@ #include <gdk/gdkkeysyms.h> #include "eggcellrendererkeys.h" +#ifndef EGG_COMPILATION #ifndef _ #define _(x) dgettext (GETTEXT_PACKAGE, x) #define N_(x) x #endif +#else +#define _(x) x +#define N_(x) x +#endif #define EGG_CELL_RENDERER_TEXT_PATH "egg-cell-renderer-text" -#define USED_MODS (GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK) static void egg_cell_renderer_keys_finalize (GObject *object); static void egg_cell_renderer_keys_init (EggCellRendererKeys *cell_keys); @@ -311,63 +315,71 @@ egg_cell_renderer_keys_get_size (GtkCellRenderer *cell, } -static GdkFilterReturn -grab_key_filter (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data) +static gboolean +grab_key_callback (GtkWidget *widget, + GdkEventKey *event, + void *data) { - XEvent *xevent = (XEvent *)gdk_xevent; - guint keycode, state; - char buf[10]; - KeySym keysym; + GdkModifierType accel_mods; + guint accel_keyval; EggCellRendererKeys *keys; char *path; gboolean edited; - - if (xevent->type != KeyPress) - return GDK_FILTER_CONTINUE; + GdkModifierType consumed_modifiers; keys = EGG_CELL_RENDERER_KEYS (data); - - keycode = xevent->xkey.keycode; - if (is_modifier (keycode)) - return GDK_FILTER_CONTINUE; + if (is_modifier (event->hardware_keycode)) + return FALSE; edited = FALSE; + + consumed_modifiers = 0; + gdk_keymap_translate_keyboard_state (gdk_keymap_get_default (), + event->hardware_keycode, + event->state, + event->group, + NULL, NULL, NULL, &consumed_modifiers); + + accel_keyval = gdk_keyval_to_lower (event->keyval); + accel_mods = event->state & gtk_accelerator_get_default_mod_mask () & ~consumed_modifiers; - state = xevent->xkey.state & USED_MODS; - - XLookupString ((XKeyEvent*)xevent, buf, sizeof (buf), &keysym, NULL); - - if (state == 0 && keysym == GDK_Escape) + if (accel_mods == 0 && accel_keyval == GDK_Escape) goto out; /* cancel */ /* clear the accelerator on Backspace */ if (keys->edit_key != 0 && - state == 0 && - keysym == GDK_BackSpace) - keysym = 0; + accel_mods == 0 && + accel_keyval == GDK_BackSpace) + accel_keyval = 0; + if (!gtk_accelerator_valid (accel_keyval, accel_mods)) + { + accel_keyval = 0; + accel_mods = 0; + } + edited = TRUE; out: path = g_strdup (g_object_get_data (G_OBJECT (keys->edit_widget), EGG_CELL_RENDERER_TEXT_PATH)); - gdk_keyboard_ungrab (xevent->xkey.time); - gdk_pointer_ungrab (xevent->xkey.time); + gdk_keyboard_ungrab (event->time); + gdk_pointer_ungrab (event->time); gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (keys->edit_widget)); gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (keys->edit_widget)); keys->edit_widget = NULL; - keys->filter_window = NULL; + keys->grab_widget = NULL; if (edited) g_signal_emit_by_name (G_OBJECT (keys), "keys_edited", path, - keysym, state); + accel_keyval, accel_mods); g_free (path); - return GDK_FILTER_REMOVE; + return FALSE; } static void @@ -378,13 +390,13 @@ ungrab_stuff (GtkWidget *widget, gpointer data) gdk_keyboard_ungrab (GDK_CURRENT_TIME); gdk_pointer_ungrab (GDK_CURRENT_TIME); - gdk_window_remove_filter (keys->filter_window, - grab_key_filter, data); + g_signal_handlers_disconnect_by_func (G_OBJECT (keys->grab_widget), + G_CALLBACK (grab_key_callback), data); } static void pointless_eventbox_start_editing (GtkCellEditable *cell_editable, - GdkEvent *event) + GdkEvent *event) { /* do nothing, because we are pointless */ } @@ -465,9 +477,11 @@ egg_cell_renderer_keys_start_editing (GtkCellRenderer *cell, return NULL; } - keys->filter_window = widget->window; - - gdk_window_add_filter (keys->filter_window, grab_key_filter, keys); + keys->grab_widget = widget; + + g_signal_connect (G_OBJECT (widget), "key_press_event", + G_CALLBACK (grab_key_callback), + keys); eventbox = g_object_new (pointless_eventbox_subclass_get_type (), NULL); diff --git a/capplets/keybindings/eggcellrendererkeys.h b/capplets/keybindings/eggcellrendererkeys.h index 1d3550d5e..0f413edb7 100644 --- a/capplets/keybindings/eggcellrendererkeys.h +++ b/capplets/keybindings/eggcellrendererkeys.h @@ -40,7 +40,7 @@ struct _EggCellRendererKeys guint accel_key; GdkModifierType accel_mask; GtkWidget *edit_widget; - GdkWindow *filter_window; + GtkWidget *grab_widget; guint edit_key; GdkModifierType edit_mask; GtkWidget *sizing_label; diff --git a/capplets/keybindings/gnome-keybinding-properties.c b/capplets/keybindings/gnome-keybinding-properties.c index f52d572a0..ef342d147 100644 --- a/capplets/keybindings/gnome-keybinding-properties.c +++ b/capplets/keybindings/gnome-keybinding-properties.c @@ -7,7 +7,9 @@ #include <string.h> #include <gtk/gtk.h> #include <gconf/gconf-client.h> +#include <gdk/gdkx.h> #include <glade/glade.h> +#include <X11/Xatom.h> #include "theme-common.h" #include "capplet-util.h" @@ -16,10 +18,78 @@ #define LABEL_DATA "gnome-keybinding-properties-label" #define KEY_THEME_KEY "/desktop/gnome/interface/gtk_key_theme" -#define KEY_LIST_KEY "/apps/gnome_keybinding_properties/keybinding_key_list" -#define METACITY_KEY_LIST_KEY "/apps/metacity/general/configurable_keybinding_key_list" #define MAX_ELEMENTS_BEFORE_SCROLLING 8 +typedef enum { + ALWAYS_VISIBLE, + N_WORKSPACES_GT +} KeyListEntryVisibility; + +typedef struct +{ + const char *name; + KeyListEntryVisibility visibility; + gint data; +} KeyListEntry; + +const KeyListEntry desktop_key_list[] = +{ + { "/apps/panel/global/run_key", ALWAYS_VISIBLE, 0 }, + { "/apps/panel/global/menu_key", ALWAYS_VISIBLE, 0 }, + { "/apps/panel/global/screenshot_key", ALWAYS_VISIBLE, 0 }, + { "/apps/panel/global/window_screenshot_key", ALWAYS_VISIBLE, 0 }, + { NULL } +}; + +const KeyListEntry metacity_key_list[] = +{ + { "/apps/metacity/window_keybindings/activate_window_menu", ALWAYS_VISIBLE, 0 }, + { "/apps/metacity/window_keybindings/toggle_fullscreen", ALWAYS_VISIBLE, 0 }, + { "/apps/metacity/window_keybindings/toggle_maximized", ALWAYS_VISIBLE, 0 }, + { "/apps/metacity/window_keybindings/toggle_shaded", ALWAYS_VISIBLE, 0 }, + { "/apps/metacity/window_keybindings/close", ALWAYS_VISIBLE, 0 }, + { "/apps/metacity/window_keybindings/begin_move", ALWAYS_VISIBLE, 0 }, + { "/apps/metacity/window_keybindings/begin_resize", ALWAYS_VISIBLE, 0 }, + { "/apps/metacity/window_keybindings/toggle_on_all_workspaces", N_WORKSPACES_GT, 1 }, + { "/apps/metacity/window_keybindings/move_to_workspace_1", N_WORKSPACES_GT, 1 }, + { "/apps/metacity/window_keybindings/move_to_workspace_2", N_WORKSPACES_GT, 1 }, + { "/apps/metacity/window_keybindings/move_to_workspace_3", N_WORKSPACES_GT, 2 }, + { "/apps/metacity/window_keybindings/move_to_workspace_4", N_WORKSPACES_GT, 3 }, + { "/apps/metacity/window_keybindings/move_to_workspace_5", N_WORKSPACES_GT, 4 }, + { "/apps/metacity/window_keybindings/move_to_workspace_6", N_WORKSPACES_GT, 5 }, + { "/apps/metacity/window_keybindings/move_to_workspace_7", N_WORKSPACES_GT, 6 }, + { "/apps/metacity/window_keybindings/move_to_workspace_8", N_WORKSPACES_GT, 7 }, + { "/apps/metacity/window_keybindings/move_to_workspace_9", N_WORKSPACES_GT, 8 }, + { "/apps/metacity/window_keybindings/move_to_workspace_10", N_WORKSPACES_GT, 9 }, + { "/apps/metacity/window_keybindings/move_to_workspace_11", N_WORKSPACES_GT, 10 }, + { "/apps/metacity/window_keybindings/move_to_workspace_12", N_WORKSPACES_GT, 11 }, + { "/apps/metacity/window_keybindings/move_to_workspace_left", N_WORKSPACES_GT, 1 }, + { "/apps/metacity/window_keybindings/move_to_workspace_right", N_WORKSPACES_GT, 1 }, + { "/apps/metacity/window_keybindings/move_to_workspace_up", N_WORKSPACES_GT, 1 }, + { "/apps/metacity/window_keybindings/move_to_workspace_down", N_WORKSPACES_GT, 1 }, + { "/apps/metacity/global_keybindings/switch_windows", ALWAYS_VISIBLE, 0 }, + { "/apps/metacity/global_keybindings/switch_panels", ALWAYS_VISIBLE, 0 }, + { "/apps/metacity/global_keybindings/focus_previous_window", ALWAYS_VISIBLE, 0 }, + { "/apps/metacity/global_keybindings/show_desktop", ALWAYS_VISIBLE, 0 }, + { "/apps/metacity/global_keybindings/switch_to_workspace_1", N_WORKSPACES_GT, 1 }, + { "/apps/metacity/global_keybindings/switch_to_workspace_2", N_WORKSPACES_GT, 1 }, + { "/apps/metacity/global_keybindings/switch_to_workspace_3", N_WORKSPACES_GT, 2 }, + { "/apps/metacity/global_keybindings/switch_to_workspace_4", N_WORKSPACES_GT, 3 }, + { "/apps/metacity/global_keybindings/switch_to_workspace_5", N_WORKSPACES_GT, 4 }, + { "/apps/metacity/global_keybindings/switch_to_workspace_6", N_WORKSPACES_GT, 5 }, + { "/apps/metacity/global_keybindings/switch_to_workspace_7", N_WORKSPACES_GT, 6 }, + { "/apps/metacity/global_keybindings/switch_to_workspace_8", N_WORKSPACES_GT, 7 }, + { "/apps/metacity/global_keybindings/switch_to_workspace_9", N_WORKSPACES_GT, 8 }, + { "/apps/metacity/global_keybindings/switch_to_workspace_10", N_WORKSPACES_GT, 9 }, + { "/apps/metacity/global_keybindings/switch_to_workspace_11", N_WORKSPACES_GT, 10 }, + { "/apps/metacity/global_keybindings/switch_to_workspace_12", N_WORKSPACES_GT, 11 }, + { "/apps/metacity/global_keybindings/switch_to_workspace_left", N_WORKSPACES_GT, 1 }, + { "/apps/metacity/global_keybindings/switch_to_workspace_right", N_WORKSPACES_GT, 1 }, + { "/apps/metacity/global_keybindings/switch_to_workspace_up", N_WORKSPACES_GT, 1 }, + { "/apps/metacity/global_keybindings/switch_to_workspace_down", N_WORKSPACES_GT, 1 }, + { NULL } +}; + enum { DESCRIPTION_COLUMN, @@ -37,16 +107,151 @@ typedef struct guint gconf_cnxn; } KeyEntry; -GList *signals = NULL; +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 menu_item_activate (GtkWidget *menu_item, gpointer unused) { @@ -101,6 +306,28 @@ binding_name (guint keyval, return translate ? g_strdup (_("Disabled")) : g_strdup ("disabled"); } +static gboolean +binding_from_string (const char *str, + guint *accelerator_key, + GdkModifierType *accelerator_mods) +{ + g_return_val_if_fail (accelerator_key != NULL, FALSE); + + if (str == NULL || (str && strcmp (str, "disabled") == 0)) + { + *accelerator_key = 0; + *accelerator_mods = 0; + return TRUE; + } + + gtk_accelerator_parse (str, accelerator_key, accelerator_mods); + + if (*accelerator_key == 0) + return FALSE; + else + return TRUE; +} + static void accel_set_func (GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, @@ -113,7 +340,7 @@ accel_set_func (GtkTreeViewColumn *tree_column, gtk_tree_model_get (model, iter, KEYENTRY_COLUMN, &key_entry, -1); - + if (key_entry == NULL) g_object_set (G_OBJECT (cell), "visible", FALSE, @@ -151,15 +378,7 @@ keybinding_key_changed (GConfClient *client, key_entry = (KeyEntry *)user_data; key_value = gconf_value_get_string (entry->value); - if (key_value != NULL) - { - gtk_accelerator_parse (key_value, &key_entry->keyval, &key_entry->mask); - } - else - { - key_entry->keyval = 0; - key_entry->mask = 0; - } + binding_from_string (key_value, &key_entry->keyval, &key_entry->mask); key_entry->editable = gconf_entry_get_is_writable (entry); path = gtk_tree_path_new_first (); @@ -206,46 +425,90 @@ clear_old_model (GladeXML *dialog, gtk_tree_model_get (model, &iter, KEYENTRY_COLUMN, &key_entry, -1); - gconf_client_notify_remove (client, key_entry->gconf_cnxn); - g_free (key_entry->gconf_key); - g_free (key_entry); + if (key_entry != NULL) + { + gconf_client_notify_remove (client, key_entry->gconf_cnxn); + g_free (key_entry->gconf_key); + g_free (key_entry); + } } g_object_unref (model); } - model = (GtkTreeModel *) gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_POINTER); + model = (GtkTreeModel *) gtk_tree_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_POINTER); gtk_tree_view_set_model (GTK_TREE_VIEW (tree_view), model); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (WID ("actions_swindow")), GTK_POLICY_NEVER, GTK_POLICY_NEVER); gtk_widget_set_usize (WID ("actions_swindow"), -1, -1); } +static gboolean +count_rows_foreach (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) +{ + gint *rows = data; + + (*rows)++; + + return FALSE; +} + +static gboolean +should_show_key (const KeyListEntry *entry) +{ + gint workspaces; + + switch (entry->visibility) { + case ALWAYS_VISIBLE: + return TRUE; + case N_WORKSPACES_GT: + workspaces = gconf_client_get_int (gconf_client_get_default (), + "/apps/metacity/general/num_workspaces", NULL); + if (workspaces > entry->data) + return TRUE; + else + return FALSE; + break; + } + + return FALSE; +} + static void -append_keys_to_tree (GladeXML *dialog, - GSList *keys_list) +append_keys_to_tree (GladeXML *dialog, + const gchar *title, + const KeyListEntry *keys_list) { GConfClient *client; + GtkTreeIter parent_iter; GtkTreeModel *model; - GSList *list; - gint i; + gint i, j; client = gconf_client_get_default (); model = gtk_tree_view_get_model (GTK_TREE_VIEW (WID ("shortcut_treeview"))); - i = gtk_tree_model_iter_n_children (model, NULL); + i = 0; + gtk_tree_model_foreach (model, count_rows_foreach, &i); + gtk_tree_store_append (GTK_TREE_STORE (model), &parent_iter, NULL); + gtk_tree_store_set (GTK_TREE_STORE (model), &parent_iter, + DESCRIPTION_COLUMN, title, + -1); - for (list = keys_list; list; list = list->next) + for (j = 0; keys_list[j].name != NULL; j++) { GConfEntry *entry; GConfSchema *schema = NULL; KeyEntry *key_entry; GError *error = NULL; GtkTreeIter iter; - gchar *key_string; + const gchar *key_string; gchar *key_value; - key_string = g_strdup ((gchar *) list->data); + if (!should_show_key (&keys_list[j])) + continue; + + key_string = keys_list[j].name; + entry = gconf_client_get_entry (client, key_string, NULL, @@ -254,7 +517,6 @@ append_keys_to_tree (GladeXML *dialog, if (error || entry == NULL) { /* We don't actually want to popup a dialog - just skip this one */ - g_free (key_string); if (error) g_error_free (error); continue; @@ -266,7 +528,6 @@ append_keys_to_tree (GladeXML *dialog, if (error || schema == NULL) { /* We don't actually want to popup a dialog - just skip this one */ - g_free (key_string); if (error) g_error_free (error); continue; @@ -275,7 +536,7 @@ append_keys_to_tree (GladeXML *dialog, key_value = gconf_client_get_string (client, key_string, &error); key_entry = g_new0 (KeyEntry, 1); - key_entry->gconf_key = key_string; + key_entry->gconf_key = g_strdup (key_string); key_entry->editable = gconf_entry_get_is_writable (entry); key_entry->model = model; gconf_client_add_dir (client, key_string, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); @@ -283,15 +544,7 @@ append_keys_to_tree (GladeXML *dialog, key_string, (GConfClientNotifyFunc) &keybinding_key_changed, key_entry, NULL, NULL); - if (key_value) - { - gtk_accelerator_parse (key_value, &key_entry->keyval, &key_entry->mask); - } - else - { - key_entry->keyval = 0; - key_entry->mask = 0; - } + binding_from_string (key_value, &key_entry->keyval, &key_entry->mask); g_free (key_value); if (i == MAX_ELEMENTS_BEFORE_SCROLLING) @@ -299,23 +552,24 @@ append_keys_to_tree (GladeXML *dialog, GtkRequisition rectangle; gtk_widget_ensure_style (WID ("shortcut_treeview")); gtk_widget_size_request (WID ("shortcut_treeview"), &rectangle); - gtk_widget_set_usize (WID ("actions_swindow"), -1, rectangle.height); + gtk_widget_set_size_request (WID ("actions_swindow"), -1, rectangle.height); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (WID ("actions_swindow")), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); } i++; - gtk_list_store_append (GTK_LIST_STORE (model), &iter); + gtk_tree_store_append (GTK_TREE_STORE (model), &iter, &parent_iter); if (gconf_schema_get_short_desc (schema)) - gtk_list_store_set (GTK_LIST_STORE (model), &iter, + gtk_tree_store_set (GTK_TREE_STORE (model), &iter, DESCRIPTION_COLUMN, gconf_schema_get_short_desc (schema), KEYENTRY_COLUMN, key_entry, -1); else - gtk_list_store_set (GTK_LIST_STORE (model), &iter, + gtk_tree_store_set (GTK_TREE_STORE (model), &iter, DESCRIPTION_COLUMN, _("<Unknown Action>"), KEYENTRY_COLUMN, key_entry, -1); + gtk_tree_view_expand_all (GTK_TREE_VIEW (WID ("shortcut_treeview"))); gconf_entry_free (entry); gconf_schema_free (schema); } @@ -331,75 +585,25 @@ append_keys_to_tree (GladeXML *dialog, } static void -keybinding_key_list_changed (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - gpointer user_data) +reload_key_entries (GladeXML *dialog) { - GladeXML *dialog; - GSList *value_list, *list; - GSList *keys_list = NULL; - - dialog = user_data; - - if (strcmp (entry->key, KEY_LIST_KEY)) - return; - - value_list = gconf_value_get_list (entry->value); - for (list = value_list; list; list = list->next) - { - GConfValue *value = list->data; - keys_list = g_slist_append (keys_list, (char *) gconf_value_get_string (value)); - } - clear_old_model (dialog, WID ("shortcut_treeview")); - append_keys_to_tree (dialog, keys_list); - g_slist_free (keys_list); + + append_keys_to_tree (dialog, _("Desktop"), desktop_key_list); + if (is_metacity_running ()) { - GSList *keys_list; - - keys_list = gconf_client_get_list (client, METACITY_KEY_LIST_KEY, GCONF_VALUE_STRING, NULL); - append_keys_to_tree (dialog, keys_list); + append_keys_to_tree (dialog, _("Window Management"), metacity_key_list); } } static void -metacity_key_list_changed (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - gpointer user_data) +key_entry_controlling_key_changed (GConfClient *client, + guint cnxn_id, + GConfEntry *entry, + gpointer user_data) { - GladeXML *dialog; - GSList *value_list, *list; - GSList *keys_list; - - if (strcmp (entry->key, METACITY_KEY_LIST_KEY)) - return; - if (! is_metacity_running ()) - return; - - dialog = user_data; - clear_old_model (dialog, WID ("shortcut_treeview")); - - keys_list = gconf_client_get_list (client, KEY_LIST_KEY, GCONF_VALUE_STRING, NULL); - append_keys_to_tree (dialog, keys_list); - g_slist_foreach (keys_list, (GFunc) g_free, NULL); - g_slist_free (keys_list); - keys_list = NULL; - - value_list = gconf_value_get_list (entry->value); - for (list = value_list; list; list = list->next) - { - GConfValue *value; - - value = list->data; - keys_list = g_slist_append (keys_list, (char *)gconf_value_get_string (value)); - } - - append_keys_to_tree (dialog, keys_list); - g_slist_free (keys_list); - + reload_key_entries (user_data); } static void @@ -541,13 +745,18 @@ theme_changed_func (gpointer uri, key_theme_changed (client, 0, entry, omenu); } +static gboolean +disable_collapsing_cb (GtkTreeView *tree_view, GtkTreeIter *iter, GtkTreePath *path) +{ + return TRUE; +} + static void setup_dialog (GladeXML *dialog) { GConfClient *client; GList *key_theme_list; GtkCellRenderer *renderer; - GSList *keys_list; GtkWidget *widget; gboolean found_keys = FALSE; GList *list; @@ -590,6 +799,9 @@ setup_dialog (GladeXML *dialog) } + g_signal_connect (WID ("shortcut_treeview"), "test_collapse_row", + G_CALLBACK (disable_collapsing_cb), NULL), + gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (WID ("shortcut_treeview")), -1, _("_Action"), @@ -608,30 +820,14 @@ setup_dialog (GladeXML *dialog) renderer, accel_set_func, NULL, NULL); gconf_client_add_dir (client, "/apps/gnome_keybinding_properties", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); - gconf_client_notify_add (client, - KEY_LIST_KEY, - (GConfClientNotifyFunc) &keybinding_key_list_changed, - dialog, NULL, NULL); gconf_client_add_dir (client, "/apps/metacity/general", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); gconf_client_notify_add (client, - METACITY_KEY_LIST_KEY, - (GConfClientNotifyFunc) &metacity_key_list_changed, + "/apps/metacity/general/num_workspaces", + (GConfClientNotifyFunc) &key_entry_controlling_key_changed, dialog, NULL, NULL); - + /* set up the dialog */ - clear_old_model (dialog, WID ("shortcut_treeview")); - keys_list = gconf_client_get_list (client, KEY_LIST_KEY, GCONF_VALUE_STRING, NULL); - append_keys_to_tree (dialog, keys_list); - g_slist_foreach (keys_list, (GFunc) g_free, NULL); - g_slist_free (keys_list); - - if (is_metacity_running ()) - { - keys_list = gconf_client_get_list (client, METACITY_KEY_LIST_KEY, GCONF_VALUE_STRING, NULL); - append_keys_to_tree (dialog, keys_list); - g_slist_foreach (keys_list, (GFunc) g_free, NULL); - g_slist_free (keys_list); - } + reload_key_entries (dialog); widget = WID ("gnome-keybinding-dialog"); gtk_widget_show (widget); @@ -658,8 +854,9 @@ main (int argc, char *argv[]) activate_settings_daemon (); dialog = create_dialog (); + initialize_wm_handling (dialog); setup_dialog (dialog); - + gtk_main (); return 0; diff --git a/capplets/keybindings/gnome-keybinding-properties.glade b/capplets/keybindings/gnome-keybinding-properties.glade index 6118d8ad2..071ac2999 100644 --- a/capplets/keybindings/gnome-keybinding-properties.glade +++ b/capplets/keybindings/gnome-keybinding-properties.glade @@ -104,8 +104,8 @@ <child> <widget class="GtkFrame" id="shortcuts_frame"> <property name="visible">True</property> - <property name="label" translatable="yes">Desktop Shortcuts:</property> <property name="label_xalign">0</property> + <property name="label_yalign">0.5</property> <property name="shadow_type">GTK_SHADOW_ETCHED_IN</property> <child> @@ -129,7 +129,7 @@ <property name="visible">True</property> <property name="can_focus">True</property> <property name="headers_visible">True</property> - <property name="rules_hint">True</property> + <property name="rules_hint">False</property> <property name="reorderable">False</property> <property name="enable_search">True</property> </widget> @@ -188,12 +188,31 @@ </widget> <packing> <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> + <property name="expand">False</property> + <property name="fill">False</property> </packing> </child> </widget> </child> + + <child> + <widget class="GtkLabel" id="label9"> + <property name="visible">True</property> + <property name="label" translatable="yes">Desktop Shortcuts:</property> + <property name="use_underline">False</property> + <property name="use_markup">False</property> + <property name="justify">GTK_JUSTIFY_LEFT</property> + <property name="wrap">False</property> + <property name="selectable">False</property> + <property name="xalign">0.5</property> + <property name="yalign">0.5</property> + <property name="xpad">0</property> + <property name="ypad">0</property> + </widget> + <packing> + <property name="type">label_item</property> + </packing> + </child> </widget> <packing> <property name="padding">0</property> |