From ced8c1cb998b905a4494f6f8d675d376165f0c28 Mon Sep 17 00:00:00 2001 From: Christopher Davis Date: Sat, 12 Feb 2022 17:16:00 -0800 Subject: [PATCH] keyboard: Use GAction and GMenuModel for input row popovers Gives these menus proper styling without having to roll our own widgets. Also removes the Remove button when the action is disabled. --- panels/keyboard/cc-input-row.c | 52 +++++++------ panels/keyboard/cc-input-row.ui | 134 ++++++++------------------------ 2 files changed, 61 insertions(+), 125 deletions(-) diff --git a/panels/keyboard/cc-input-row.c b/panels/keyboard/cc-input-row.c index 60e1cec21..966882451 100644 --- a/panels/keyboard/cc-input-row.c +++ b/panels/keyboard/cc-input-row.c @@ -25,10 +25,6 @@ struct _CcInputRow CcInputSource *source; - GtkButton *remove_button; - GtkButton *settings_button; - GtkSeparator *settings_separator; - GtkListBox *drag_widget; GtkDragSource *drag_source; @@ -107,9 +103,11 @@ drop_cb (GtkDropTarget *drop_target, } static void -move_up_button_clicked_cb (CcInputRow *self, - GtkButton *button) +move_up_cb (GtkWidget *widget, + const char *action_name, + GVariant *parameter) { + CcInputRow *self = CC_INPUT_ROW (widget); GtkListBox *list_box = GTK_LIST_BOX (gtk_widget_get_parent (GTK_WIDGET (self))); gint previous_idx = gtk_list_box_row_get_index (GTK_LIST_BOX_ROW (self)) - 1; GtkListBoxRow *previous_row = gtk_list_box_get_row_at_index (list_box, previous_idx); @@ -124,9 +122,11 @@ move_up_button_clicked_cb (CcInputRow *self, } static void -move_down_button_clicked_cb (CcInputRow *self, - GtkButton *button) +move_down_cb (GtkWidget *widget, + const char *action_name, + GVariant *parameter) { + CcInputRow *self = CC_INPUT_ROW (widget); GtkListBox *list_box = GTK_LIST_BOX (gtk_widget_get_parent (GTK_WIDGET (self))); gint next_idx = gtk_list_box_row_get_index (GTK_LIST_BOX_ROW (self)) + 1; GtkListBoxRow *next_row = gtk_list_box_get_row_at_index (list_box, next_idx); @@ -141,24 +141,33 @@ move_down_button_clicked_cb (CcInputRow *self, } static void -settings_button_clicked_cb (CcInputRow *self) +show_settings_cb (GtkWidget *widget, + const char *action_name, + GVariant *parameter) { + CcInputRow *self = CC_INPUT_ROW (widget); g_signal_emit (self, signals[SIGNAL_SHOW_SETTINGS], 0); } static void -layout_button_clicked_cb (CcInputRow *self) +show_layout_cb (GtkWidget *widget, + const char *action_name, + GVariant *parameter) { + CcInputRow *self = CC_INPUT_ROW (widget); g_signal_emit (self, signals[SIGNAL_SHOW_LAYOUT], 0); } static void -remove_button_clicked_cb (CcInputRow *self) +remove_cb (GtkWidget *widget, + const char *action_name, + GVariant *parameter) { + CcInputRow *self = CC_INPUT_ROW (widget); g_signal_emit (self, signals[SIGNAL_REMOVE_ROW], 0); @@ -184,16 +193,6 @@ cc_input_row_class_init (CcInputRowClass *klass) gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/control-center/keyboard/cc-input-row.ui"); - gtk_widget_class_bind_template_child (widget_class, CcInputRow, remove_button); - gtk_widget_class_bind_template_child (widget_class, CcInputRow, settings_button); - gtk_widget_class_bind_template_child (widget_class, CcInputRow, settings_separator); - - gtk_widget_class_bind_template_callback (widget_class, layout_button_clicked_cb); - gtk_widget_class_bind_template_callback (widget_class, move_down_button_clicked_cb); - gtk_widget_class_bind_template_callback (widget_class, move_up_button_clicked_cb); - gtk_widget_class_bind_template_callback (widget_class, remove_button_clicked_cb); - gtk_widget_class_bind_template_callback (widget_class, settings_button_clicked_cb); - signals[SIGNAL_SHOW_SETTINGS] = g_signal_new ("show-settings", G_TYPE_FROM_CLASS (object_class), @@ -233,6 +232,12 @@ cc_input_row_class_init (CcInputRowClass *klass) NULL, G_TYPE_NONE, 0); + + gtk_widget_class_install_action (widget_class, "row.move-up", NULL, move_up_cb); + gtk_widget_class_install_action (widget_class, "row.move-down", NULL, move_down_cb); + gtk_widget_class_install_action (widget_class, "row.show-layout", NULL, show_layout_cb); + gtk_widget_class_install_action (widget_class, "row.show-settings", NULL, show_settings_cb); + gtk_widget_class_install_action (widget_class, "row.remove", NULL, remove_cb); } void @@ -272,8 +277,7 @@ cc_input_row_new (CcInputSource *source) g_signal_connect_object (source, "label-changed", G_CALLBACK (label_changed_cb), self, G_CONNECT_SWAPPED); label_changed_cb (self); - gtk_widget_set_visible (GTK_WIDGET (self->settings_button), CC_IS_INPUT_SOURCE_IBUS (source)); - gtk_widget_set_visible (GTK_WIDGET (self->settings_separator), CC_IS_INPUT_SOURCE_IBUS (source)); + gtk_widget_action_set_enabled (GTK_WIDGET (self), "row.show-settings", CC_IS_INPUT_SOURCE_IBUS (source)); return self; } @@ -290,7 +294,7 @@ cc_input_row_set_removable (CcInputRow *self, gboolean removable) { g_return_if_fail (CC_IS_INPUT_ROW (self)); - gtk_widget_set_sensitive (GTK_WIDGET (self->remove_button), removable); + gtk_widget_action_set_enabled (GTK_WIDGET (self), "row.remove", removable); } void diff --git a/panels/keyboard/cc-input-row.ui b/panels/keyboard/cc-input-row.ui index 79d73137b..e3a28d718 100644 --- a/panels/keyboard/cc-input-row.ui +++ b/panels/keyboard/cc-input-row.ui @@ -15,111 +15,43 @@ center view-more-symbolic - popover_menu + popover_menu - - - - - 6 - 6 - 6 - 6 - vertical - - - - - - - Move up - 0.0 - - - - - - - - - - - Move down - 0.0 - - - - - - - horizontal - - - - - False - - - - Preferences - 0.0 - - - - - - - - horizontal - - - - - - - - - View Keyboard Layout - 0.0 - - - - - - - horizontal - - - - - - - - - Remove - 0.0 - - - - - - - + +
+ + Move Up + row.move-up + + + Move Down + row.move-down + +
+
+ + Preferences + row.show-settings + action-disabled + +
+
+ + View Keyboard Layout + row.show-layout + +
+
+ + Remove + row.remove + action-disabled + +
+