[gnome-control-center/wip/hadess/wacom-mock: 1/3] wacom: Split off notebook switching for detected stylus




commit e5e0750a8e6dd89c24fbea46357f07ca194a0b70
Author: Bastien Nocera <hadess hadess net>
Date:   Tue Nov 16 17:18:15 2021 +0100

    wacom: Split off notebook switching for detected stylus
    
    This will reduce code duplication for mocking styli.

 panels/wacom/cc-wacom-panel.c | 38 ++++++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 16 deletions(-)
---
diff --git a/panels/wacom/cc-wacom-panel.c b/panels/wacom/cc-wacom-panel.c
index 17404c1bd..643955c3a 100644
--- a/panels/wacom/cc-wacom-panel.c
+++ b/panels/wacom/cc-wacom-panel.c
@@ -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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]