diff options
author | Bastien Nocera <hadess@hadess.net> | 2022-01-20 12:20:33 +0100 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2022-01-20 12:20:33 +0100 |
commit | a43e1689e3e32253e2203d28df8ffcd917d1ce00 (patch) | |
tree | 1f76568ac43303cb26ffbd44933297bcdb0fb26f /lib | |
parent | f5fae22865a781204d56d6c6adfcbac3867bae9b (diff) | |
download | gnome-bluetooth-a43e1689e3e32253e2203d28df8ffcd917d1ce00.tar.gz |
lib: Add API to check whether input devices are connected
This will figure out whether there are any connected input devices, so
that gnome-shell (or gnome-control-center) can show a confirmation
dialogue before really turning things off.
Closes: #101
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bluetooth-client.c | 29 | ||||
-rw-r--r-- | lib/bluetooth-client.h | 2 | ||||
-rw-r--r-- | lib/gnome-bluetooth.map | 1 |
3 files changed, 32 insertions, 0 deletions
diff --git a/lib/bluetooth-client.c b/lib/bluetooth-client.c index cf7ae67c..652d6777 100644 --- a/lib/bluetooth-client.c +++ b/lib/bluetooth-client.c @@ -1518,3 +1518,32 @@ bluetooth_client_connect_service_finish (BluetoothClient *client, return g_task_propagate_boolean (task, error); } + +gboolean +bluetooth_client_has_connected_input_devices (BluetoothClient *client) +{ + guint i, n_items; + guint n_connected = 0; + + n_items = g_list_model_get_n_items (G_LIST_MODEL (client->list_store)); + for (i = 0; i < n_items; i++) { + g_autoptr(BluetoothDevice) device = NULL; + g_auto(GStrv) uuids = NULL; + gboolean connected = FALSE; + + device = g_list_model_get_item (G_LIST_MODEL (client->list_store), i); + g_object_get (device, + "connected", &connected, + "uuids", &uuids, NULL); + if (!connected) + continue; + if (!uuids) + continue; + if (g_strv_contains ((const gchar * const *) uuids, "Human Interface Device") || + g_strv_contains ((const gchar * const *) uuids, "HumanInterfaceDeviceService")) + n_connected++; + } + g_debug ("Found %i input devices connected", n_connected); + + return n_connected > 0; +} diff --git a/lib/bluetooth-client.h b/lib/bluetooth-client.h index 26effcaf..c79c460d 100644 --- a/lib/bluetooth-client.h +++ b/lib/bluetooth-client.h @@ -44,3 +44,5 @@ void bluetooth_client_connect_service (BluetoothClient *client, gboolean bluetooth_client_connect_service_finish (BluetoothClient *client, GAsyncResult *res, GError **error); + +gboolean bluetooth_client_has_connected_input_devices (BluetoothClient *client); diff --git a/lib/gnome-bluetooth.map b/lib/gnome-bluetooth.map index 02e00cb2..d9a88dda 100644 --- a/lib/gnome-bluetooth.map +++ b/lib/gnome-bluetooth.map @@ -7,6 +7,7 @@ global: bluetooth_client_get_type; bluetooth_client_new; bluetooth_client_get_devices; + bluetooth_client_has_connected_input_devices; bluetooth_client_connect_service; bluetooth_client_connect_service_finish; bluetooth_client_set_trusted; |