[gnome-settings-daemon/wip/hadess/lid-is-closed-removal] power: Use logind to get lid status
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon/wip/hadess/lid-is-closed-removal] power: Use logind to get lid status
- Date: Thu, 22 Apr 2021 13:59:47 +0000 (UTC)
commit f1c4b5f26d81c71b475f8a2b82d304ad6561d4a2
Author: Bastien Nocera <hadess hadess net>
Date: Thu Apr 22 15:56:50 2021 +0200
power: Use logind to get lid status
Rather than upower, where the lid status functions have been obsolete
for some time.
plugins/power/gsd-power-manager.c | 55 +++++++++++++++++++++++++--------------
1 file changed, 36 insertions(+), 19 deletions(-)
---
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c
index 95cec9c3..54dffd2f 100644
--- a/plugins/power/gsd-power-manager.c
+++ b/plugins/power/gsd-power-manager.c
@@ -150,7 +150,6 @@ struct _GsdPowerManager
gboolean screensaver_active;
/* State */
- gboolean lid_is_present;
gboolean lid_is_closed;
gboolean session_is_active;
UpClient *up_client;
@@ -1429,19 +1428,40 @@ do_lid_closed_action (GsdPowerManager *manager)
}
}
+static gboolean
+is_lid_closed (GsdPowerManager *manager)
+{
+ GVariant *variant;
+ gboolean is_lid_closed = FALSE;
+
+ variant = g_dbus_proxy_get_cached_property (manager->logind_proxy,
+ "LidClosed");
+ if (variant) {
+ is_lid_closed = g_variant_get_boolean (variant);
+ g_variant_unref (variant);
+ }
+
+ return is_lid_closed;
+}
+
static void
-lid_state_changed_cb (UpClient *client, GParamSpec *pspec, GsdPowerManager *manager)
+logind_proxy_changed_cb (GDBusProxy *proxy,
+ GVariant *changed_properties,
+ GStrv invalidated_properties,
+ gpointer user_data)
{
+ GsdPowerManager *manager = user_data;
+ g_autoptr(GVariant) lid_closed = NULL;
gboolean tmp;
- if (!manager->lid_is_present)
+ lid_closed = g_dbus_proxy_get_cached_property (proxy, "LidClosed");
+ if (lid_closed == NULL)
return;
-
- /* same lid state */
- tmp = up_client_get_lid_is_closed (manager->up_client);
- if (manager->lid_is_closed == tmp)
+ tmp = g_variant_get_boolean (lid_closed);
+ if (tmp == manager->lid_is_closed)
return;
- manager->lid_is_closed = tmp;
+
+ manager->lid_is_closed = tmp;
g_debug ("up changed: lid is now %s", tmp ? "closed" : "open");
if (manager->lid_is_closed)
@@ -2572,11 +2592,9 @@ on_rr_screen_acquired (GObject *object,
manager->session_is_active = is_session_active (manager);
/* set up the screens */
- if (manager->lid_is_present) {
- g_signal_connect (manager->rr_screen, "changed", G_CALLBACK (on_randr_event), manager);
- watch_external_monitor (manager->rr_screen);
- on_randr_event (manager->rr_screen, manager);
- }
+ g_signal_connect (manager->rr_screen, "changed", G_CALLBACK (on_randr_event), manager);
+ watch_external_monitor (manager->rr_screen);
+ on_randr_event (manager->rr_screen, manager);
manager->screensaver_proxy = gnome_settings_bus_get_screen_saver_proxy ();
@@ -2594,8 +2612,6 @@ on_rr_screen_acquired (GObject *object,
G_CALLBACK (engine_device_added_cb), manager);
g_signal_connect (manager->up_client, "device-removed",
G_CALLBACK (engine_device_removed_cb), manager);
- g_signal_connect_after (manager->up_client, "notify::lid-is-closed",
- G_CALLBACK (lid_state_changed_cb), manager);
g_signal_connect (manager->up_client, "notify::on-battery",
G_CALLBACK (up_client_on_battery_cb), manager);
@@ -2765,11 +2781,7 @@ gsd_power_manager_start (GsdPowerManager *manager,
g_debug ("Starting power manager");
gnome_settings_profile_start (NULL);
- /* Check whether we have a lid first */
manager->up_client = up_client_new ();
- manager->lid_is_present = up_client_get_lid_is_present (manager->up_client);
- if (manager->lid_is_present)
- manager->lid_is_closed = up_client_get_lid_is_closed (manager->up_client);
/* Set up the logind proxy */
manager->logind_proxy =
@@ -2786,6 +2798,11 @@ gsd_power_manager_start (GsdPowerManager *manager,
return FALSE;
}
+ /* Check whether the lid is closed */
+ manager->lid_is_closed = is_lid_closed (manager);
+ g_signal_connect (manager->logind_proxy, "g-properties-changed",
+ G_CALLBACK (logind_proxy_changed_cb), manager);
+
/* coldplug the list of screens */
gnome_rr_screen_new_async (gdk_screen_get_default (),
on_rr_screen_acquired, manager);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]