Merge branch 'fix-focus' into 'main'

malcontent-control: Focus controls rather than user selector

See merge request pwithnall/malcontent!126
This commit is contained in:
Philip Withnall 2021-10-12 14:08:58 +00:00
commit dcf7265f55
3 changed files with 35 additions and 2 deletions

View File

@ -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 dont 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 */ /* GObject overrides */
static void 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_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_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_application_usage_permissions_listbox_activated_cb);
gtk_widget_class_bind_template_callback (widget_class, on_keynav_failed);
} }
static void static void

View File

@ -39,6 +39,7 @@
<property name="selection_mode">none</property> <property name="selection_mode">none</property>
<property name="activate-on-single-click">True</property> <property name="activate-on-single-click">True</property>
<signal name="row-activated" handler="on_application_usage_permissions_listbox_activated_cb" object="MctUserControls" swapped="no" /> <signal name="row-activated" handler="on_application_usage_permissions_listbox_activated_cb" object="MctUserControls" swapped="no" />
<signal name="keynav-failed" handler="on_keynav_failed" object="MctUserControls" swapped="no" />
<child> <child>
<object class="GtkListBoxRow"> <object class="GtkListBoxRow">
<property name="visible">True</property> <property name="visible">True</property>
@ -252,6 +253,7 @@
<property name="hexpand">True</property> <property name="hexpand">True</property>
<property name="selection_mode">none</property> <property name="selection_mode">none</property>
<property name="activate_on_single_click">False</property> <property name="activate_on_single_click">False</property>
<signal name="keynav-failed" handler="on_keynav_failed" object="MctUserControls" swapped="no" />
<child> <child>
<object class="GtkListBoxRow"> <object class="GtkListBoxRow">
<property name="visible" bind-source="restrict_software_installation_switch" bind-property="visible" bind-flags="default|sync-create" /> <property name="visible" bind-source="restrict_software_installation_switch" bind-property="visible" bind-flags="default|sync-create" />

View File

@ -415,7 +415,7 @@ update_main_stack (MctApplication *self)
mct_user_controls_set_user (self->user_controls, selected_user); mct_user_controls_set_user (self->user_controls, selected_user);
new_page_name = "controls"; new_page_name = "controls";
new_focus_widget = GTK_WIDGET (self->user_selector); new_focus_widget = GTK_WIDGET (self->user_controls);
} }
else else
{ {
@ -427,7 +427,12 @@ update_main_stack (MctApplication *self)
gtk_stack_set_visible_child_name (self->main_stack, new_page_name); 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)) 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 static void