wacom: Split off notebook switching for detected stylus

This will reduce code duplication for mocking styli.
This commit is contained in:
Bastien Nocera 2021-11-16 17:18:15 +01:00 committed by Georges Basile Stavracas Neto
parent d47b9be08a
commit a93a023229

View file

@ -330,6 +330,26 @@ update_test_button (CcWacomPanel *self)
}
}
static void
update_stylus_notebook (CcWacomPanel *panel,
CcWacomTool *stylus)
{
if (panel->stylus_notebook ==
gtk_stack_get_visible_child (GTK_STACK (panel->stack))) {
GtkWidget *widget;
gint page;
widget = g_hash_table_lookup (panel->stylus_pages, stylus);
page = gtk_notebook_page_num (GTK_NOTEBOOK (panel->stylus_notebook), widget);
gtk_notebook_set_current_page (GTK_NOTEBOOK (panel->stylus_notebook), page);
} else {
gtk_container_child_set (GTK_CONTAINER (panel->stack),
panel->stylus_notebook,
"needs-attention", TRUE,
NULL);
}
}
static void
update_current_tool (CcWacomPanel *panel,
GdkDevice *device,
@ -392,22 +412,8 @@ update_current_tool (CcWacomPanel *panel,
added = add_stylus (panel, stylus);
if (added) {
if (panel->stylus_notebook ==
gtk_stack_get_visible_child (GTK_STACK (panel->stack))) {
GtkWidget *widget;
gint page;
widget = g_hash_table_lookup (panel->stylus_pages, stylus);
page = gtk_notebook_page_num (GTK_NOTEBOOK (panel->stylus_notebook), widget);
gtk_notebook_set_current_page (GTK_NOTEBOOK (panel->stylus_notebook), page);
} else {
gtk_container_child_set (GTK_CONTAINER (panel->stack),
panel->stylus_notebook,
"needs-attention", TRUE,
NULL);
}
}
if (added)
update_stylus_notebook (panel, stylus);
cc_tablet_tool_map_add_relation (panel->tablet_tool_map,
wacom_device, stylus);