diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2012-04-12 15:29:36 +0200 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2012-04-12 14:43:34 +0100 |
commit | ff31b771bbff300de4da4b4860d4ebdcd09acb6b (patch) | |
tree | 3490c463e70f59a83f0dfce090a58a5b316480f5 | |
parent | 0463ba862220ceb14433dbf1ab90043357bfeac7 (diff) | |
download | gnome-control-center-ff31b771bbff300de4da4b4860d4ebdcd09acb6b.tar.gz |
wacom: update the UI if a new tool comes in
The device_added_cb is called once for each tool added. The wacom driver
hotplugs tools in the order stylus, eraser, cursor, pad.
update_current_page will add a new page once a tablet has stylus and
eraser, before cursor and pad exist. priv->pad is thus always NULL,
causing, cc_wacom_page's update_tablet_ui to remove the "Map Buttons..."
button for any device.
Change the code to update the tool list for every new tool we get,
merely triggering the visibility of the button instead of destroying it
completely.
https://bugzilla.gnome.org/show_bug.cgi?id=672691
-rw-r--r-- | panels/wacom/cc-wacom-page.c | 83 | ||||
-rw-r--r-- | panels/wacom/cc-wacom-page.h | 5 | ||||
-rw-r--r-- | panels/wacom/cc-wacom-panel.c | 11 |
3 files changed, 71 insertions, 28 deletions
diff --git a/panels/wacom/cc-wacom-page.c b/panels/wacom/cc-wacom-page.c index 857cd01ce..3a3128a9d 100644 --- a/panels/wacom/cc-wacom-page.c +++ b/panels/wacom/cc-wacom-page.c @@ -95,6 +95,32 @@ enum { MODE_RELATIVE, /* stylus + eraser relative */ }; +/* Different types of layout for the tablet config */ +enum { + LAYOUT_NORMAL, /* tracking mode, button mapping */ + LAYOUT_REVERSIBLE, /* tracking mode, button mapping, left-hand orientation */ + LAYOUT_SCREEN /* button mapping, calibration, display resolution */ +}; + +static void +update_tablet_ui (CcWacomPage *page, + int layout); + +static int +get_layout_type (GsdWacomDevice *device) +{ + int layout; + + if (gsd_wacom_device_is_screen_tablet (device)) + layout = LAYOUT_SCREEN; + else if (gsd_wacom_device_reversible (device)) + layout = LAYOUT_REVERSIBLE; + else + layout = LAYOUT_NORMAL; + + return layout; +} + static void set_calibration (gint *cal, gsize ncal, @@ -661,11 +687,14 @@ display_mapping_dialog_closed (GtkDialog *dialog, CcWacomPage *page) { CcWacomPagePrivate *priv; + int layout; priv = page->priv; gtk_widget_destroy (priv->dialog); priv->dialog = NULL; priv->mapping = NULL; + layout = get_layout_type (priv->stylus); + update_tablet_ui (page, layout); } static void @@ -981,13 +1010,6 @@ stylus_changed (GsdWacomDevice *device, gsd_wacom_stylus_get_name (stylus)); } -/* Different types of layout for the tablet config */ -enum { - LAYOUT_NORMAL, /* tracking mode, button mapping */ - LAYOUT_REVERSIBLE, /* tracking mode, button mapping, left-hand orientation */ - LAYOUT_SCREEN /* button mapping, calibration, display resolution */ -}; - static void remove_left_handed (CcWacomPagePrivate *priv) { @@ -1013,7 +1035,8 @@ update_tablet_ui (CcWacomPage *page, priv = page->priv; - /* FIXME Handle ->pad being NULL and hide the pad buttons */ + /* Hide the pad buttons if no pad is present */ + gtk_widget_set_visible (WID ("map-buttons-button"), priv->pad != NULL); switch (layout) { case LAYOUT_NORMAL: @@ -1045,6 +1068,33 @@ update_tablet_ui (CcWacomPage *page, } } +gboolean +cc_wacom_page_update_tools (CcWacomPage *page, + GsdWacomDevice *stylus, + GsdWacomDevice *eraser, + GsdWacomDevice *pad) +{ + CcWacomPagePrivate *priv; + int layout; + gboolean changed; + + /* Type of layout */ + layout = get_layout_type (stylus); + + priv = page->priv; + changed = (priv->stylus != stylus || priv->eraser != eraser || priv->pad != pad); + if (!changed) + return FALSE; + + priv->stylus = stylus; + priv->eraser = eraser; + priv->pad = pad; + + update_tablet_ui (CC_WACOM_PAGE (page), layout); + + return TRUE; +} + GtkWidget * cc_wacom_page_new (CcWacomPanel *panel, GsdWacomDevice *stylus, @@ -1053,7 +1103,6 @@ cc_wacom_page_new (CcWacomPanel *panel, { CcWacomPage *page; CcWacomPagePrivate *priv; - int layout; g_return_val_if_fail (GSD_IS_WACOM_DEVICE (stylus), NULL); g_return_val_if_fail (gsd_wacom_device_get_device_type (stylus) == WACOM_TYPE_STYLUS, NULL); @@ -1067,10 +1116,8 @@ cc_wacom_page_new (CcWacomPanel *panel, page = g_object_new (CC_TYPE_WACOM_PAGE, NULL); priv = page->priv; - priv->panel = panel; - priv->stylus = stylus; - priv->eraser = eraser; - priv->pad = pad; + + cc_wacom_page_update_tools (page, stylus, eraser, pad); /* FIXME move this to construct */ priv->wacom_settings = gsd_wacom_device_get_settings (stylus); @@ -1079,16 +1126,6 @@ cc_wacom_page_new (CcWacomPanel *panel, /* Tablet name */ gtk_label_set_text (GTK_LABEL (WID ("label-tabletmodel")), gsd_wacom_device_get_name (stylus)); - /* Type of layout */ - if (gsd_wacom_device_is_screen_tablet (stylus)) - layout = LAYOUT_SCREEN; - else if (gsd_wacom_device_reversible (stylus)) - layout = LAYOUT_REVERSIBLE; - else - layout = LAYOUT_NORMAL; - - update_tablet_ui (page, layout); - /* Left-handedness */ if (gsd_wacom_device_reversible (stylus)) set_left_handed_from_gsettings (page); diff --git a/panels/wacom/cc-wacom-page.h b/panels/wacom/cc-wacom-page.h index 7b8fc2dcb..12c520e6c 100644 --- a/panels/wacom/cc-wacom-page.h +++ b/panels/wacom/cc-wacom-page.h @@ -74,6 +74,11 @@ GtkWidget * cc_wacom_page_new (CcWacomPanel *panel, GsdWacomDevice *eraser, GsdWacomDevice *pad); +gboolean cc_wacom_page_update_tools (CcWacomPage *page, + GsdWacomDevice *stylus, + GsdWacomDevice *eraser, + GsdWacomDevice *pad); + void cc_wacom_page_set_navigation (CcWacomPage *page, GtkNotebook *notebook, gboolean ignore_first_page); diff --git a/panels/wacom/cc-wacom-panel.c b/panels/wacom/cc-wacom-panel.c index 1cfdd5a69..087d1b6e6 100644 --- a/panels/wacom/cc-wacom-panel.c +++ b/panels/wacom/cc-wacom-panel.c @@ -200,12 +200,11 @@ update_current_page (CcWacomPanel *self) tablets = g_hash_table_get_values (ht); for (l = tablets; l; l = l->next) { Tablet *tablet; + GtkWidget *page; tablet = l->data; if (tablet->stylus == NULL || tablet->eraser == NULL) { - GtkWidget *page; - page = g_hash_table_lookup (priv->pages, tablet->name); if (page != NULL) { remove_page (GTK_NOTEBOOK (priv->notebook), page); @@ -215,9 +214,9 @@ update_current_page (CcWacomPanel *self) } continue; } - - if (g_hash_table_lookup (priv->pages, tablet->name) == NULL) { - GtkWidget *page; + /* this code is called once the stylus + eraser were set up, but the pad does not exist yet */ + page = g_hash_table_lookup (priv->pages, tablet->name); + if (page == NULL) { page = cc_wacom_page_new (self, tablet->stylus, tablet->eraser, tablet->pad); cc_wacom_page_set_navigation (CC_WACOM_PAGE (page), GTK_NOTEBOOK (priv->notebook), TRUE); gtk_widget_show (page); @@ -225,6 +224,8 @@ update_current_page (CcWacomPanel *self) g_hash_table_insert (priv->pages, g_strdup (tablet->name), page); changed = TRUE; + } else { + cc_wacom_page_update_tools (CC_WACOM_PAGE (page), tablet->stylus, tablet->eraser, tablet->pad); } } g_list_free (tablets); |