From 98ebfaa20e225cc958d2d2d9fb13a7e66cb7acd8 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 7 Oct 2021 16:18:00 +0100 Subject: [PATCH 1/2] malcontent-control: Focus controls rather than user selector When showing the controls, focus them first rather than the user selector. The correct user is probably already selected. This has the added benefit of not drawing attention to the ugly focus rectangle on the user selector. Signed-off-by: Philip Withnall --- malcontent-control/application.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/malcontent-control/application.c b/malcontent-control/application.c index 0ba20be..6ef2452 100644 --- a/malcontent-control/application.c +++ b/malcontent-control/application.c @@ -414,7 +414,7 @@ update_main_stack (MctApplication *self) mct_user_controls_set_user (self->user_controls, selected_user); new_page_name = "controls"; - new_focus_widget = GTK_WIDGET (self->user_selector); + new_focus_widget = GTK_WIDGET (self->user_controls); } else { @@ -426,7 +426,12 @@ update_main_stack (MctApplication *self) gtk_stack_set_visible_child_name (self->main_stack, new_page_name); if (new_focus_widget != NULL && !g_str_equal (old_page_name, new_page_name)) - gtk_widget_grab_focus (new_focus_widget); + { + if (gtk_widget_get_can_focus (new_focus_widget)) + gtk_widget_grab_focus (new_focus_widget); + else + gtk_widget_child_focus (new_focus_widget, GTK_DIR_TAB_FORWARD); + } } static void From ec7fa2529ba1c396b2afc780af60124384984ee5 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Thu, 7 Oct 2021 16:21:21 +0100 Subject: [PATCH 2/2] libmalcontent-ui: Improve keynav between listboxes Fix using the up and down keys to change the keyboard focus between rows between the listboxes. Previously, keynav would fail at the bottom of the first listbox, and at the top of the second. Signed-off-by: Philip Withnall --- libmalcontent-ui/user-controls.c | 26 ++++++++++++++++++++++++++ libmalcontent-ui/user-controls.ui | 2 ++ 2 files changed, 28 insertions(+) diff --git a/libmalcontent-ui/user-controls.c b/libmalcontent-ui/user-controls.c index ffeebcc..ad6a3a8 100644 --- a/libmalcontent-ui/user-controls.c +++ b/libmalcontent-ui/user-controls.c @@ -711,6 +711,31 @@ list_box_header_func (GtkListBoxRow *row, } } +static gboolean +on_keynav_failed (GtkWidget *listbox, + GtkDirectionType direction, + gpointer user_data) +{ + MctUserControls *self = MCT_USER_CONTROLS (user_data); + GtkWidget *new_widget = NULL; + + /* There are currently two listboxes, so don’t over-complicate this function. */ + if (listbox == GTK_WIDGET (self->application_usage_permissions_listbox) && + direction == GTK_DIR_DOWN) + new_widget = GTK_WIDGET (self->software_installation_permissions_listbox); + else if (listbox == GTK_WIDGET (self->software_installation_permissions_listbox) && + direction == GTK_DIR_UP) + new_widget = GTK_WIDGET (self->application_usage_permissions_listbox); + + if (new_widget != NULL) + { + gtk_widget_child_focus (new_widget, direction); + return TRUE; + } + + return FALSE; +} + /* GObject overrides */ static void @@ -1031,6 +1056,7 @@ mct_user_controls_class_init (MctUserControlsClass *klass) gtk_widget_class_bind_template_callback (widget_class, on_restrict_applications_dialog_delete_event_cb); gtk_widget_class_bind_template_callback (widget_class, on_restrict_applications_dialog_response_cb); gtk_widget_class_bind_template_callback (widget_class, on_application_usage_permissions_listbox_activated_cb); + gtk_widget_class_bind_template_callback (widget_class, on_keynav_failed); } static void diff --git a/libmalcontent-ui/user-controls.ui b/libmalcontent-ui/user-controls.ui index 2155777..b699871 100644 --- a/libmalcontent-ui/user-controls.ui +++ b/libmalcontent-ui/user-controls.ui @@ -39,6 +39,7 @@ none True + True @@ -252,6 +253,7 @@ True none False +