[gnome-control-center/wip/hadess/wacom-visibility: 49/50] wacom: Hide Wacom panel when there are no tablets
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/hadess/wacom-visibility: 49/50] wacom: Hide Wacom panel when there are no tablets
- Date: Wed, 20 Jun 2018 09:00:40 +0000 (UTC)
commit 2f0f24ef8918cfb7848c104a1640167ad91de344
Author: Bastien Nocera <hadess hadess net>
Date: Wed May 30 11:54:09 2018 +0200
wacom: Hide Wacom panel when there are no tablets
panels/wacom/cc-wacom-panel.c | 37 +++++++++++++++++++++++++++++++++++++
panels/wacom/cc-wacom-panel.h | 2 ++
shell/cc-panel-loader.c | 5 ++++-
3 files changed, 43 insertions(+), 1 deletion(-)
---
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
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]