diff options
author | Bastien Nocera <hadess@hadess.net> | 2018-05-30 11:54:09 +0200 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2018-06-20 08:59:43 +0000 |
commit | 2f0f24ef8918cfb7848c104a1640167ad91de344 (patch) | |
tree | 2f93ea6bdd8efdf8a43373a98b7b8f4a2ffead4a | |
parent | 67d39e497a4090d2a06935c2b1a1b9c286115429 (diff) | |
download | gnome-control-center-2f0f24ef8918cfb7848c104a1640167ad91de344.tar.gz |
wacom: Hide Wacom panel when there are no tablets
-rw-r--r-- | panels/wacom/cc-wacom-panel.c | 37 | ||||
-rw-r--r-- | panels/wacom/cc-wacom-panel.h | 2 | ||||
-rw-r--r-- | shell/cc-panel-loader.c | 5 |
3 files changed, 43 insertions, 1 deletions
diff --git a/panels/wacom/cc-wacom-panel.c b/panels/wacom/cc-wacom-panel.c index 77a1e261f..82caf9ab0 100644 --- a/panels/wacom/cc-wacom-panel.c +++ b/panels/wacom/cc-wacom-panel.c @@ -25,6 +25,8 @@ #include <gtk/gtk.h> #include <glib/gi18n-lib.h> +#include "shell/cc-application.h" +#include "shell/cc-debug.h" #include "cc-wacom-panel.h" #include "cc-wacom-page.h" #include "cc-wacom-stylus-page.h" @@ -83,6 +85,41 @@ enum { PROP_PARAMETERS }; +/* Static init function */ +static void +update_visibility (GsdDeviceManager *manager, + GsdDevice *device, + gpointer user_data) +{ + CcApplication *application; + g_autoptr(GList) devices = NULL; + guint i; + + devices = gsd_device_manager_list_devices (manager, GSD_DEVICE_TYPE_TABLET); + i = g_list_length (devices); + + /* Set the new visibility */ + application = CC_APPLICATION (g_application_get_default ()); + cc_shell_model_set_panel_visibility (cc_application_get_model (application), + "wacom", + i > 0 ? CC_PANEL_VISIBLE : CC_PANEL_VISIBLE_IN_SEARCH); + + g_debug ("Wacom panel visible: %s", i > 0 ? "yes" : "no"); +} + +void +cc_wacom_panel_static_init_func (void) +{ + GsdDeviceManager *manager; + + manager = gsd_device_manager_get (); + g_signal_connect (G_OBJECT (manager), "device-added", + G_CALLBACK (update_visibility), NULL); + g_signal_connect (G_OBJECT (manager), "device-removed", + G_CALLBACK (update_visibility), NULL); + update_visibility (manager, NULL, NULL); +} + static CcWacomPage * set_device_page (CcWacomPanel *self, const gchar *device_name) { diff --git a/panels/wacom/cc-wacom-panel.h b/panels/wacom/cc-wacom-panel.h index 430c94381..a5b1e758b 100644 --- a/panels/wacom/cc-wacom-panel.h +++ b/panels/wacom/cc-wacom-panel.h @@ -64,6 +64,8 @@ struct _CcWacomPanelClass CcPanelClass parent_class; }; +void cc_wacom_panel_static_init_func (void); + GType cc_wacom_panel_get_type (void) G_GNUC_CONST; void cc_wacom_panel_switch_to_panel (CcWacomPanel *self, diff --git a/shell/cc-panel-loader.c b/shell/cc-panel-loader.c index 3beba0bfd..6b5c6e3d0 100644 --- a/shell/cc-panel-loader.c +++ b/shell/cc-panel-loader.c @@ -68,6 +68,9 @@ extern GType cc_wacom_panel_get_type (void); #ifdef BUILD_NETWORK extern void cc_wifi_panel_static_init_func (void); #endif /* BUILD_NETWORK */ +#ifdef BUILD_WACOM +extern void cc_wacom_panel_static_init_func (void); +#endif /* BUILD_WACOM */ #define PANEL_TYPE(name, get_type, init_func) { name, get_type, init_func } @@ -115,7 +118,7 @@ static struct { PANEL_TYPE("universal-access", cc_ua_panel_get_type, NULL), PANEL_TYPE("user-accounts", cc_user_panel_get_type, NULL), #ifdef BUILD_WACOM - PANEL_TYPE("wacom", cc_wacom_panel_get_type, NULL), + PANEL_TYPE("wacom", cc_wacom_panel_get_type, cc_wacom_panel_static_init_func), #endif }; |