From 37fc3c54a4311e01789672e7cffaf09612e4057a Mon Sep 17 00:00:00 2001 From: "Sergey V. Udaltsov" Date: Thu, 15 Oct 2009 23:18:59 +0100 Subject: [PATCH] Serious changes in the keyboard capplet UI Following the discussion at http://live.gnome.org/UsabilityProject/Whiteboard/KeyboardPreferences --- .../gnome-keyboard-properties-dialog.ui | 205 ++++++++++------ .../keyboard/gnome-keyboard-properties-xkb.c | 44 +++- .../keyboard/gnome-keyboard-properties-xkb.h | 10 +- .../gnome-keyboard-properties-xkblt.c | 218 +++++++----------- 4 files changed, 257 insertions(+), 220 deletions(-) diff --git a/capplets/keyboard/gnome-keyboard-properties-dialog.ui b/capplets/keyboard/gnome-keyboard-properties-dialog.ui index b09d11c62..46b941ffb 100644 --- a/capplets/keyboard/gnome-keyboard-properties-dialog.ui +++ b/capplets/keyboard/gnome-keyboard-properties-dialog.ui @@ -207,7 +207,7 @@ Short - + @@ -222,7 +222,7 @@ Slow - + @@ -285,7 +285,7 @@ Long - + @@ -299,7 +299,7 @@ Fast - + @@ -420,7 +420,7 @@ Slow - + @@ -453,7 +453,7 @@ Fast - + @@ -547,21 +547,6 @@ True vertical 6 - - - Separate _layout for each window - True - True - False - True - True - - - False - False - 0 - - True @@ -571,7 +556,7 @@ True 0 - _Selected layouts: + Selected _layouts: True xkb_layouts_selected @@ -610,25 +595,37 @@ - 1 + 0 - + True - GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK - 6 - + True - 6 - start + vertical + 3 + + + _Add... + True + True + True + True + + + False + False + 0 + + gtk-remove True True - False + True True @@ -637,61 +634,111 @@ 1 + + + 0 + + + + + True + vertical - - gtk-print + + Move _Up True True - False - True - - - False - False - 2 - - - - - _Add... - True - True - False + True True False False - 3 + 0 + + + + + Move _Down + True + True + True + True + + + False + False + 1 - False - 0 + 1 - - Reset to De_faults + True - True - False - True + vertical + start + + + gtk-print + True + True + True + True + + + False + False + 0 + + + + + - False - False - end - 4 + 2 False + 1 + + + + + _Separate layout for each window + True + True + False + True + True + + + False + False 2 + + + New windows get layout "foobar" + True + True + False + True + True + + + False + False + 3 + + 1 @@ -701,6 +748,7 @@ True GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 6 end @@ -717,6 +765,21 @@ 0 + + + Reset to De_faults + True + True + True + True + + + False + False + end + 1 + + False @@ -964,7 +1027,7 @@ Short - + @@ -997,7 +1060,7 @@ Long - + @@ -1118,7 +1181,7 @@ Short - + @@ -1151,7 +1214,7 @@ Long - + @@ -1290,7 +1353,7 @@ center - + @@ -1310,7 +1373,7 @@ center - + @@ -1360,7 +1423,7 @@ center - + @@ -1380,7 +1443,7 @@ center - + @@ -1444,7 +1507,7 @@ center - + @@ -1481,7 +1544,7 @@ center - + @@ -1843,8 +1906,8 @@ - helpbutton1 - button4 + helpbutton1 + button4 diff --git a/capplets/keyboard/gnome-keyboard-properties-xkb.c b/capplets/keyboard/gnome-keyboard-properties-xkb.c index ba3165988..160524f6a 100644 --- a/capplets/keyboard/gnome-keyboard-properties-xkb.c +++ b/capplets/keyboard/gnome-keyboard-properties-xkb.c @@ -135,8 +135,7 @@ reset_to_defaults (GtkWidget * button, GtkBuilder * dialog) gkbd_keyboard_config_term (&empty_kbd_config); gconf_client_unset (xkb_gconf_client, - GKBD_DESKTOP_CONFIG_KEY_DEFAULT_GROUP, - NULL); + GKBD_DESKTOP_CONFIG_KEY_DEFAULT_GROUP, NULL); /* all the rest is g-s-d's business */ } @@ -147,21 +146,35 @@ chk_separate_group_per_window_toggled (GConfPropertyEditor * peditor, const GConfValue * value, GtkBuilder * dialog) { - xkb_layouts_enable_disable_default (dialog, value - && - gconf_value_get_bool (value)); + gtk_widget_set_sensitive (WID ("chk_new_windows_get_first_layout"), + gconf_value_get_bool (value)); +} + +static void +chk_new_windows_get_first_layout_toggled (GtkWidget * + chk_new_windows_get_first_layout, + GtkBuilder * dialog) +{ + xkb_save_default_group (gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON + (chk_new_windows_get_first_layout)) ? 0 : + -1); } void setup_xkb_tabs (GtkBuilder * dialog, GConfChangeSet * changeset) { GObject *peditor; + GtkWidget *chk_new_windows_get_first_layout = + WID ("chk_new_windows_get_first_layout"); + xkb_gconf_client = gconf_client_get_default (); engine = xkl_engine_get_instance (GDK_DISPLAY ()); config_registry = xkl_config_registry_get_instance (engine); - gkbd_desktop_config_init (&desktop_config, xkb_gconf_client, engine); + gkbd_desktop_config_init (&desktop_config, xkb_gconf_client, + engine); gkbd_desktop_config_load_from_gconf (&desktop_config); xkl_config_registry_load (config_registry, @@ -188,11 +201,25 @@ setup_xkb_tabs (GtkBuilder * dialog, GConfChangeSet * changeset) xkb_layouts_prepare_selected_tree (dialog, changeset); xkb_layouts_fill_selected_tree (dialog); + gtk_widget_set_sensitive (chk_new_windows_get_first_layout, + gtk_toggle_button_get_active + (GTK_TOGGLE_BUTTON + (WID + ("chk_separate_group_per_window")))); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON + (chk_new_windows_get_first_layout), + xkb_get_default_group () == 0); + xkb_layouts_register_buttons_handlers (dialog); g_signal_connect (G_OBJECT (WID ("xkb_reset_to_defaults")), "clicked", G_CALLBACK (reset_to_defaults), dialog); + g_signal_connect (G_OBJECT (chk_new_windows_get_first_layout), + "toggled", (GCallback) + chk_new_windows_get_first_layout_toggled, + dialog); + g_signal_connect_swapped (G_OBJECT (WID ("xkb_layout_options")), "clicked", G_CALLBACK (xkb_options_popup_dialog), @@ -210,11 +237,6 @@ setup_xkb_tabs (GtkBuilder * dialog, GConfChangeSet * changeset) dialog); enable_disable_restoring (dialog); - xkb_layouts_enable_disable_default (dialog, - gconf_client_get_bool - (xkb_gconf_client, - GKBD_DESKTOP_CONFIG_KEY_GROUP_PER_WINDOW, - NULL)); } void diff --git a/capplets/keyboard/gnome-keyboard-properties-xkb.h b/capplets/keyboard/gnome-keyboard-properties-xkb.h index cf2244738..d9c387850 100644 --- a/capplets/keyboard/gnome-keyboard-properties-xkb.h +++ b/capplets/keyboard/gnome-keyboard-properties-xkb.h @@ -35,7 +35,8 @@ extern XklConfigRegistry *config_registry; extern GConfClient *xkb_gconf_client; extern GkbdKeyboardConfig initial_config; -extern void setup_xkb_tabs (GtkBuilder * dialog, GConfChangeSet * changeset); +extern void setup_xkb_tabs (GtkBuilder * dialog, + GConfChangeSet * changeset); extern void xkb_layouts_fill_selected_tree (GtkBuilder * dialog); @@ -66,9 +67,6 @@ extern void choose_model (GtkBuilder * dialog); extern void xkb_layout_choose (GtkBuilder * dialog); -extern void xkb_layouts_enable_disable_default (GtkBuilder * dialog, - gboolean enable); - extern GSList *xkb_layouts_get_selected_list (void); extern GSList *xkb_options_get_selected_list (void); @@ -94,5 +92,9 @@ extern void xkb_layout_preview_set_drawing_layout (GtkWidget * kbdraw, extern gchar *xkb_layout_chooser_get_selected_id (GtkBuilder * chooser_dialog); +extern void xkb_save_default_group (gint group_no); + +extern gint xkb_get_default_group (void); + G_END_DECLS #endif /* __GNOME_KEYBOARD_PROPERTY_XKB_H */ diff --git a/capplets/keyboard/gnome-keyboard-properties-xkblt.c b/capplets/keyboard/gnome-keyboard-properties-xkblt.c index 21b72f8bf..c7d2fc129 100644 --- a/capplets/keyboard/gnome-keyboard-properties-xkblt.c +++ b/capplets/keyboard/gnome-keyboard-properties-xkblt.c @@ -36,15 +36,13 @@ #define SEL_LAYOUT_TREE_COL_DESCRIPTION 0 -#define SEL_LAYOUT_TREE_COL_DEFAULT 1 -#define SEL_LAYOUT_TREE_COL_ID 2 +#define SEL_LAYOUT_TREE_COL_ID 1 static int idx2select = -1; static int max_selected_layouts = -1; static int default_group = -1; static GtkCellRenderer *text_renderer; -static GtkCellRenderer *toggle_renderer; static gboolean disable_buttons_sensibility_update = FALSE; @@ -108,73 +106,23 @@ xkb_layouts_get_selected_list (void) return retval; } -static void -save_default_group (int default_group) +gint +xkb_get_default_group () { - if (default_group != gconf_client_get_int (xkb_gconf_client, - GKBD_DESKTOP_CONFIG_KEY_DEFAULT_GROUP, - NULL)) + return gconf_client_get_int (xkb_gconf_client, + GKBD_DESKTOP_CONFIG_KEY_DEFAULT_GROUP, + NULL); +} + +void +xkb_save_default_group (gint default_group) +{ + if (default_group != xkb_get_default_group ()) gconf_client_set_int (xkb_gconf_client, GKBD_DESKTOP_CONFIG_KEY_DEFAULT_GROUP, default_group, NULL); } -static void -def_group_in_ui_changed (GtkCellRendererToggle * cell_renderer, - gchar * path, GtkBuilder * dialog) -{ - GtkTreePath *chpath = gtk_tree_path_new_from_string (path); - int new_default_group = -1; - gboolean previously_selected = - gtk_cell_renderer_toggle_get_active (cell_renderer); - - if (!previously_selected) { /* prev state - non-selected! */ - int *indices = gtk_tree_path_get_indices (chpath); - new_default_group = indices[0]; - } - - save_default_group (new_default_group); - gtk_tree_path_free (chpath); -} - -static void -def_group_in_gconf_changed (GConfClient * client, - guint cnxn_id, - GConfEntry * entry, GtkBuilder * dialog) -{ - GConfValue *value = gconf_entry_get_value (entry); - - if (!value) - return; - - if (value->type == GCONF_VALUE_INT) { - GtkWidget *tree_view = WID ("xkb_layouts_selected"); - GtkTreeModel *model = - GTK_TREE_MODEL (gtk_tree_view_get_model - (GTK_TREE_VIEW (tree_view))); - GtkTreeIter iter; - int counter = 0; - default_group = MAX(0, gconf_value_get_int (value)); - if (gtk_tree_model_get_iter_first (model, &iter)) { - do { - gboolean cur_val; - gtk_tree_model_get (model, &iter, - SEL_LAYOUT_TREE_COL_DEFAULT, - &cur_val, -1); - if (cur_val != (counter == default_group)) - gtk_list_store_set (GTK_LIST_STORE - (model), &iter, - SEL_LAYOUT_TREE_COL_DEFAULT, - counter == - default_group, - -1); - counter++; - } - while (gtk_tree_model_iter_next (model, &iter)); - } - } -} - static void xkb_layouts_enable_disable_buttons (GtkBuilder * dialog) { @@ -182,6 +130,8 @@ xkb_layouts_enable_disable_buttons (GtkBuilder * dialog) GtkWidget *print_layout_btn = WID ("xkb_layouts_print"); GtkWidget *del_layout_btn = WID ("xkb_layouts_remove"); GtkWidget *selected_layouts_tree = WID ("xkb_layouts_selected"); + GtkWidget *move_up_layout_btn = WID ("xkb_layouts_move_up"); + GtkWidget *move_down_layout_btn = WID ("xkb_layouts_move_down"); GtkTreeSelection *s_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW @@ -193,6 +143,7 @@ xkb_layouts_enable_disable_buttons (GtkBuilder * dialog) const int n_selected_layouts = gtk_tree_model_iter_n_children (selected_layouts_model, NULL); + gint sidx = find_selected_layout_idx (dialog); if (disable_buttons_sensibility_update) return; @@ -205,47 +156,9 @@ xkb_layouts_enable_disable_buttons (GtkBuilder * dialog) && (n_selected_selected_layouts > 0)); gtk_widget_set_sensitive (print_layout_btn, (n_selected_selected_layouts > 0)); -} - -static GtkTreeViewColumn * -xkb_layouts_create_default_layout_column () -{ - GtkTreeViewColumn *def_column = - gtk_tree_view_column_new_with_attributes (_("Default"), - toggle_renderer, - "active", - SEL_LAYOUT_TREE_COL_DEFAULT, - NULL); - gtk_tree_view_column_set_sizing (def_column, - GTK_TREE_VIEW_COLUMN_AUTOSIZE); - gtk_tree_view_column_set_resizable (def_column, TRUE); - gtk_tree_view_column_set_expand (def_column, FALSE); - return def_column; -} - -void -xkb_layouts_enable_disable_default (GtkBuilder * dialog, gboolean enable) -{ - GtkWidget *tree_view = WID ("xkb_layouts_selected"); - - if (enable) { - gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), - xkb_layouts_create_default_layout_column - ()); - g_object_unref (toggle_renderer); - } else { - GtkTreeViewColumn *col = - gtk_tree_view_get_column (GTK_TREE_VIEW (tree_view), - 1); - if (col != NULL) { - g_object_ref (toggle_renderer); - gtk_tree_view_column_clear (col); - gtk_tree_view_remove_column (GTK_TREE_VIEW - (tree_view), col); - } - } - - gtk_widget_queue_draw (tree_view); + gtk_widget_set_sensitive (move_up_layout_btn, sidx > 0); + gtk_widget_set_sensitive (move_down_layout_btn, sidx >= 0 + && sidx < (n_selected_layouts - 1)); } static void @@ -322,11 +235,6 @@ xkb_layouts_prepare_selected_tree (GtkBuilder * dialog, GtkTreeViewColumn *desc_column; text_renderer = GTK_CELL_RENDERER (gtk_cell_renderer_text_new ()); - toggle_renderer = - GTK_CELL_RENDERER (gtk_cell_renderer_toggle_new ()); - gtk_cell_renderer_toggle_set_radio (GTK_CELL_RENDERER_TOGGLE - (toggle_renderer), TRUE); - g_object_ref (toggle_renderer); desc_column = gtk_tree_view_column_new_with_attributes (_("Layout"), @@ -354,14 +262,6 @@ xkb_layouts_prepare_selected_tree (GtkBuilder * dialog, dialog); max_selected_layouts = xkl_engine_get_max_num_groups (engine); - gconf_client_notify_add (xkb_gconf_client, - GKBD_DESKTOP_CONFIG_KEY_DEFAULT_GROUP, - (GConfClientNotifyFunc) - def_group_in_gconf_changed, dialog, NULL, - NULL); - g_signal_connect (G_OBJECT (toggle_renderer), "toggled", - G_CALLBACK (def_group_in_ui_changed), dialog); - /* Setting up DnD */ gtk_drag_source_set (tree_view, GDK_BUTTON1_MASK, &self_drag_target, 1, GDK_ACTION_MOVE); @@ -389,14 +289,15 @@ xkb_layout_description_utf8 (const gchar * visible) void xkb_layouts_fill_selected_tree (GtkBuilder * dialog) { - GConfEntry *gce; - GError *err = NULL; GSList *layouts = xkb_layouts_get_selected_list (); GSList *cur_layout; GtkListStore *list_store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (WID ("xkb_layouts_selected")))); + GtkWidget *chk_new_windows_get_first_layout = + WID ("chk_new_windows_get_first_layout"); + int counter = 0; /* temporarily disable the buttons' status update */ disable_buttons_sensibility_update = TRUE; @@ -404,7 +305,7 @@ xkb_layouts_fill_selected_tree (GtkBuilder * dialog) gtk_list_store_clear (list_store); for (cur_layout = layouts; cur_layout != NULL; - cur_layout = cur_layout->next) { + cur_layout = cur_layout->next, counter++) { GtkTreeIter iter; const char *visible = (char *) cur_layout->data; gchar *utf_visible = xkb_layout_description_utf8 (visible); @@ -412,9 +313,18 @@ xkb_layouts_fill_selected_tree (GtkBuilder * dialog) gtk_list_store_set (list_store, &iter, SEL_LAYOUT_TREE_COL_DESCRIPTION, utf_visible, - SEL_LAYOUT_TREE_COL_DEFAULT, FALSE, SEL_LAYOUT_TREE_COL_ID, cur_layout->data, -1); + if (!counter) { + gchar *chklbl = + g_strdup_printf (_ + ("New windows get layout \"%s\""), +utf_visible); + gtk_button_set_label (GTK_BUTTON + (chk_new_windows_get_first_layout), + chklbl); + g_free (chklbl); + } g_free (utf_visible); } @@ -438,16 +348,6 @@ xkb_layouts_fill_selected_tree (GtkBuilder * dialog) otherwise it would be done by the selection change */ xkb_layouts_enable_disable_buttons (dialog); } - - gce = gconf_client_get_entry (xkb_gconf_client, - GKBD_DESKTOP_CONFIG_KEY_DEFAULT_GROUP, - NULL, TRUE, &err); - if (err == NULL) { - def_group_in_gconf_changed (xkb_gconf_client, -1, gce, - dialog); - } else { - g_error_free (err); - } } static void @@ -500,15 +400,59 @@ remove_selected_layout (GtkWidget * button, GtkBuilder * dialog) g_free (id); if (default_group > idx) - save_default_group (default_group - 1); + xkb_save_default_group (default_group - 1); else if (default_group == idx) - save_default_group (-1); + xkb_save_default_group (-1); xkb_layouts_set_selected_list (layouts_list); clear_xkb_elements_list (layouts_list); } } +static void +move_up_selected_layout (GtkWidget * button, GtkBuilder * dialog) +{ + gint idx = find_selected_layout_idx (dialog); + + if (idx != -1) { + GSList *layouts_list = xkb_layouts_get_selected_list (); + GSList *node2Remove = g_slist_nth (layouts_list, idx); + + layouts_list = + g_slist_remove_link (layouts_list, node2Remove); + layouts_list = + g_slist_insert (layouts_list, node2Remove->data, + idx - 1); + g_slist_free_1 (node2Remove); + + idx2select = idx - 1; + xkb_layouts_set_selected_list (layouts_list); + clear_xkb_elements_list (layouts_list); + } +} + +static void +move_down_selected_layout (GtkWidget * button, GtkBuilder * dialog) +{ + gint idx = find_selected_layout_idx (dialog); + + if (idx != -1) { + GSList *layouts_list = xkb_layouts_get_selected_list (); + GSList *node2Remove = g_slist_nth (layouts_list, idx); + + layouts_list = + g_slist_remove_link (layouts_list, node2Remove); + layouts_list = + g_slist_insert (layouts_list, node2Remove->data, + idx + 1); + g_slist_free_1 (node2Remove); + + idx2select = idx + 1; + xkb_layouts_set_selected_list (layouts_list); + clear_xkb_elements_list (layouts_list); + } +} + void xkb_layouts_register_buttons_handlers (GtkBuilder * dialog) { @@ -518,6 +462,12 @@ xkb_layouts_register_buttons_handlers (GtkBuilder * dialog) G_CALLBACK (print_selected_layout), dialog); g_signal_connect (G_OBJECT (WID ("xkb_layouts_remove")), "clicked", G_CALLBACK (remove_selected_layout), dialog); + g_signal_connect (G_OBJECT (WID ("xkb_layouts_move_up")), + "clicked", G_CALLBACK (move_up_selected_layout), + dialog); + g_signal_connect (G_OBJECT (WID ("xkb_layouts_move_down")), + "clicked", + G_CALLBACK (move_down_selected_layout), dialog); } static void