summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Borges <felipeborges@gnome.org>2022-12-15 12:36:54 +0100
committerFelipe Borges <felipeborges@gnome.org>2022-12-15 14:02:02 +0100
commit22b5686943ff31e04a9cd07843c89171212e44ce (patch)
tree05902c44b40cb73e554b59e8759bf9a5edf30d2c
parente46dd4c5d365ed47eacce5431c23a5f8d56cf581 (diff)
downloadgnome-control-center-22b5686943ff31e04a9cd07843c89171212e44ce.tar.gz
thunderbolt: Hide panel if there's no thunderbolt hardware
Same logic as the Wacom tablet panel. Fixes #612
-rw-r--r--panels/thunderbolt/cc-bolt-panel.c58
-rw-r--r--panels/thunderbolt/cc-bolt-panel.h2
-rw-r--r--shell/cc-panel-loader.c5
3 files changed, 64 insertions, 1 deletions
diff --git a/panels/thunderbolt/cc-bolt-panel.c b/panels/thunderbolt/cc-bolt-panel.c
index fc9986200..dac08f356 100644
--- a/panels/thunderbolt/cc-bolt-panel.c
+++ b/panels/thunderbolt/cc-bolt-panel.c
@@ -24,6 +24,7 @@
#include <glib/gi18n.h>
#include <polkit/polkit.h>
+#include "shell/cc-application.h"
#include "cc-bolt-device-dialog.h"
#include "cc-bolt-device-entry.h"
@@ -144,6 +145,63 @@ static void on_permission_notify_cb (GPermission *permission,
CC_PANEL_REGISTER (CcBoltPanel, cc_bolt_panel);
+/* Static init function */
+static void
+set_panel_visibility (gboolean visible)
+{
+ CcApplication *application;
+
+ application = CC_APPLICATION (g_application_get_default ());
+ cc_shell_model_set_panel_visibility (cc_application_get_model (application),
+ "thunderbolt",
+ visible ? CC_PANEL_VISIBLE : CC_PANEL_VISIBLE_IN_SEARCH);
+ g_debug ("Thunderbolt panel visible: %s", visible ? "yes" : "no");
+}
+
+static void
+update_visibility (BoltClient *client,
+ const char *path,
+ gpointer user_data)
+{
+ g_autoptr(GPtrArray) devices = NULL;
+
+ devices = bolt_client_list_devices (client, NULL, NULL);
+ set_panel_visibility (devices->len > 0);
+}
+
+static void
+on_visibility_client_ready (GObject *source,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ BoltClient *client;
+
+ client = bolt_client_new_finish (res, NULL);
+ if (client == NULL)
+ {
+ set_panel_visibility (FALSE);
+ return;
+ }
+
+ g_signal_connect_object (client,
+ "device-added",
+ G_CALLBACK (update_visibility),
+ NULL,
+ 0);
+ g_signal_connect_object (client,
+ "device-removed",
+ G_CALLBACK (update_visibility),
+ NULL,
+ 0);
+ update_visibility (client, NULL, NULL);
+}
+
+void
+cc_thunderbolt_panel_static_init_func (void)
+{
+ bolt_client_new_async (NULL, on_visibility_client_ready, NULL);
+}
+
static void
bolt_client_ready (GObject *source,
GAsyncResult *res,
diff --git a/panels/thunderbolt/cc-bolt-panel.h b/panels/thunderbolt/cc-bolt-panel.h
index 5901044e8..60ff0ac48 100644
--- a/panels/thunderbolt/cc-bolt-panel.h
+++ b/panels/thunderbolt/cc-bolt-panel.h
@@ -27,4 +27,6 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (CcBoltPanel, cc_bolt_panel, CC, BOLT_PANEL, CcPanel);
+void cc_thunderbolt_panel_static_init_func (void);
+
G_END_DECLS
diff --git a/shell/cc-panel-loader.c b/shell/cc-panel-loader.c
index 17f96017f..7a8673edf 100644
--- a/shell/cc-panel-loader.c
+++ b/shell/cc-panel-loader.c
@@ -78,6 +78,9 @@ extern GType cc_diagnostics_panel_get_type (void);
/* Static init functions */
extern void cc_diagnostics_panel_static_init_func (void);
+#ifdef BUILD_THUNDERBOLT
+extern void cc_thunderbolt_panel_static_init_func (void);
+#endif /* BUILD_THUNDERBOLT */
#ifdef BUILD_NETWORK
extern void cc_wifi_panel_static_init_func (void);
#endif /* BUILD_NETWORK */
@@ -132,7 +135,7 @@ static CcPanelLoaderVtable default_panels[] =
PANEL_TYPE("sharing", cc_sharing_panel_get_type, NULL),
PANEL_TYPE("sound", cc_sound_panel_get_type, NULL),
#ifdef BUILD_THUNDERBOLT
- PANEL_TYPE("thunderbolt", cc_bolt_panel_get_type, NULL),
+ PANEL_TYPE("thunderbolt", cc_bolt_panel_get_type, cc_thunderbolt_panel_static_init_func),
#endif
PANEL_TYPE("universal-access", cc_ua_panel_get_type, NULL),
PANEL_TYPE("usage", cc_usage_panel_get_type, NULL),