[gnome-flashback] monitor-manager: move lid-is-closed handling to GfBackend
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-flashback] monitor-manager: move lid-is-closed handling to GfBackend
- Date: Sat, 23 Oct 2021 18:48:44 +0000 (UTC)
commit b053b4185bca0459fbc50446b26c25b382c5e108
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Sun Sep 12 21:12:46 2021 +0300
monitor-manager: move lid-is-closed handling to GfBackend
Based on mutter commit:
https://gitlab.gnome.org/GNOME/mutter/-/commit/951219650f8d
backends/gf-backend-private.h | 7 +++
backends/gf-backend.c | 89 +++++++++++++++++++++++++++++++++++
backends/gf-monitor-config-manager.c | 16 +++++--
backends/gf-monitor-manager-private.h | 7 ---
backends/gf-monitor-manager.c | 67 ++++++++------------------
backends/gf-monitors-config.c | 12 ++++-
6 files changed, 139 insertions(+), 59 deletions(-)
---
diff --git a/backends/gf-backend-private.h b/backends/gf-backend-private.h
index 427085e..e5ac27a 100644
--- a/backends/gf-backend-private.h
+++ b/backends/gf-backend-private.h
@@ -26,6 +26,8 @@
#ifndef GF_BACKEND_PRIVATE_H
#define GF_BACKEND_PRIVATE_H
+#include <libupower-glib/upower.h>
+
#include "gf-backend.h"
#include "gf-monitor-manager-private.h"
#include "gf-monitor-manager-types-private.h"
@@ -42,6 +44,9 @@ struct _GfBackendClass
GfMonitorManager * (* create_monitor_manager) (GfBackend *backend,
GError **error);
+
+ gboolean (* is_lid_closed) (GfBackend *self);
+
};
GfOrientationManager *gf_backend_get_orientation_manager (GfBackend *backend);
@@ -50,6 +55,8 @@ GfSettings *gf_backend_get_settings (GfBackend *backend);
void gf_backend_monitors_changed (GfBackend *backend);
+gboolean gf_backend_is_lid_closed (GfBackend *self);
+
void gf_backend_add_gpu (GfBackend *self,
GfGpu *gpu);
diff --git a/backends/gf-backend.c b/backends/gf-backend.c
index 639d430..190226f 100644
--- a/backends/gf-backend.c
+++ b/backends/gf-backend.c
@@ -39,11 +39,15 @@ typedef struct
GfMonitorManager *monitor_manager;
+ UpClient *up_client;
+ gboolean lid_is_closed;
+
GList *gpus;
} GfBackendPrivate;
enum
{
+ LID_IS_CLOSED_CHANGED,
GPU_ADDED,
LAST_SIGNAL
@@ -66,6 +70,29 @@ create_monitor_manager (GfBackend *backend,
return GF_BACKEND_GET_CLASS (backend)->create_monitor_manager (backend, error);
}
+static void
+lid_is_closed_changed_cb (UpClient *client,
+ GParamSpec *pspec,
+ GfBackend *self)
+{
+ GfBackendPrivate *priv;
+ gboolean lid_is_closed;
+
+ priv = gf_backend_get_instance_private (self);
+
+ lid_is_closed = up_client_get_lid_is_closed (priv->up_client);
+
+ if (priv->lid_is_closed == lid_is_closed)
+ return;
+
+ priv->lid_is_closed = lid_is_closed;
+
+ g_signal_emit (self,
+ backend_signals[LID_IS_CLOSED_CHANGED],
+ 0,
+ priv->lid_is_closed);
+}
+
static gboolean
gf_backend_initable_init (GInitable *initable,
GCancellable *cancellable,
@@ -93,6 +120,46 @@ initable_iface_init (GInitableIface *initable_iface)
initable_iface->init = gf_backend_initable_init;
}
+static gboolean
+gf_backend_real_is_lid_closed (GfBackend *self)
+{
+ GfBackendPrivate *priv;
+
+ priv = gf_backend_get_instance_private (self);
+
+ if (priv->up_client == NULL)
+ return FALSE;
+
+ return priv->lid_is_closed;
+}
+
+static void
+gf_backend_constructed (GObject *object)
+{
+ GfBackend *self;
+ GfBackendClass *self_class;
+ GfBackendPrivate *priv;
+
+ self = GF_BACKEND (object);
+ self_class = GF_BACKEND_GET_CLASS (self);
+ priv = gf_backend_get_instance_private (self);
+
+ if (self_class->is_lid_closed != gf_backend_real_is_lid_closed)
+ return;
+
+ priv->up_client = up_client_new ();
+
+ if (priv->up_client != NULL)
+ {
+ g_signal_connect (priv->up_client,
+ "notify::lid-is-closed",
+ G_CALLBACK (lid_is_closed_changed_cb),
+ self);
+
+ priv->lid_is_closed = up_client_get_lid_is_closed (priv->up_client);
+ }
+}
+
static void
gf_backend_dispose (GObject *object)
{
@@ -118,6 +185,8 @@ gf_backend_finalize (GObject *object)
self = GF_BACKEND (object);
priv = gf_backend_get_instance_private (self);
+ g_clear_object (&priv->up_client);
+
g_list_free_full (priv->gpus, g_object_unref);
G_OBJECT_CLASS (gf_backend_parent_class)->finalize (object);
@@ -140,10 +209,24 @@ gf_backend_class_init (GfBackendClass *backend_class)
object_class = G_OBJECT_CLASS (backend_class);
+ object_class->constructed = gf_backend_constructed;
object_class->dispose = gf_backend_dispose;
object_class->finalize = gf_backend_finalize;
backend_class->post_init = gf_backend_real_post_init;
+ backend_class->is_lid_closed = gf_backend_real_is_lid_closed;
+
+ backend_signals[LID_IS_CLOSED_CHANGED] =
+ g_signal_new ("lid-is-closed-changed",
+ G_TYPE_FROM_CLASS (backend_class),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL,
+ NULL,
+ NULL,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_BOOLEAN);
backend_signals[GPU_ADDED] =
g_signal_new ("gpu-added",
@@ -237,6 +320,12 @@ gf_backend_monitors_changed (GfBackend *backend)
{
}
+gboolean
+gf_backend_is_lid_closed (GfBackend *self)
+{
+ return GF_BACKEND_GET_CLASS (self)->is_lid_closed (self);
+}
+
void
gf_backend_add_gpu (GfBackend *self,
GfGpu *gpu)
diff --git a/backends/gf-monitor-config-manager.c b/backends/gf-monitor-config-manager.c
index 5b9079f..89c0d79 100644
--- a/backends/gf-monitor-config-manager.c
+++ b/backends/gf-monitor-config-manager.c
@@ -109,6 +109,16 @@ find_monitor_with_highest_preferred_resolution (GfMonitorManager *monitor_manage
return largest_monitor;
}
+static gboolean
+is_lid_closed (GfMonitorManager *monitor_manager)
+{
+ GfBackend *backend;
+
+ backend = gf_monitor_manager_get_backend (monitor_manager);
+
+ return gf_backend_is_lid_closed (backend);
+}
+
/*
* Try to find the primary monitor. The priority of classification is:
*
@@ -124,7 +134,7 @@ find_primary_monitor (GfMonitorManager *monitor_manager)
{
GfMonitor *monitor;
- if (gf_monitor_manager_is_lid_closed (monitor_manager))
+ if (is_lid_closed (monitor_manager))
{
monitor = gf_monitor_manager_get_primary_monitor (monitor_manager);
if (monitor && !gf_monitor_is_laptop_panel (monitor))
@@ -922,7 +932,7 @@ gf_create_monitors_config_key_for_current_state (GfMonitorManager *monitor_manag
{
laptop_monitor_spec = gf_monitor_get_spec (monitor);
- if (gf_monitor_manager_is_lid_closed (monitor_manager))
+ if (is_lid_closed (monitor_manager))
continue;
}
@@ -1153,7 +1163,7 @@ gf_monitor_config_manager_create_linear (GfMonitorConfigManager *config_manager)
continue;
if (gf_monitor_is_laptop_panel (monitor) &&
- gf_monitor_manager_is_lid_closed (monitor_manager))
+ is_lid_closed (monitor_manager))
continue;
logical_monitor_config = create_preferred_logical_monitor_config (monitor_manager,
diff --git a/backends/gf-monitor-manager-private.h b/backends/gf-monitor-manager-private.h
index e3a48da..f5d4f5a 100644
--- a/backends/gf-monitor-manager-private.h
+++ b/backends/gf-monitor-manager-private.h
@@ -26,7 +26,6 @@
#define GF_MONITOR_MANAGER_PRIVATE_H
#include <libgnome-desktop/gnome-pnp-ids.h>
-#include <libupower-glib/upower.h>
#include "gf-backend-private.h"
#include "gf-dbus-display-config.h"
@@ -70,8 +69,6 @@ struct _GfMonitorManager
GfMonitorConfigManager *config_manager;
GnomePnpIds *pnp_ids;
- UpClient *up_client;
- gboolean lid_is_closed;
GfMonitorSwitchConfigType current_switch_config;
};
@@ -83,8 +80,6 @@ typedef struct
GBytes * (* read_edid) (GfMonitorManager *manager,
GfOutput *output);
- gboolean (* is_lid_closed) (GfMonitorManager *manager);
-
void (* read_current_state) (GfMonitorManager *manager);
void (* ensure_initial_config) (GfMonitorManager *manager);
@@ -191,8 +186,6 @@ GfMonitorsConfig *gf_monitor_manager_ensure_configured (GfM
void gf_monitor_manager_update_logical_state_derived (GfMonitorManager
*manager,
GfMonitorsConfig
*config);
-gboolean gf_monitor_manager_is_lid_closed (GfMonitorManager
*manager);
-
gfloat gf_monitor_manager_calculate_monitor_mode_scale (GfMonitorManager
*manager,
GfMonitor
*monitor,
GfMonitorMode
*monitor_mode);
diff --git a/backends/gf-monitor-manager.c b/backends/gf-monitor-manager.c
index 7ef020f..074eddc 100644
--- a/backends/gf-monitor-manager.c
+++ b/backends/gf-monitor-manager.c
@@ -219,8 +219,11 @@ gf_monitor_manager_is_config_applicable (GfMonitorManager *manager,
GfMonitorsConfig *config,
GError **error)
{
+ GfMonitorManagerPrivate *priv;
GList *l;
+ priv = gf_monitor_manager_get_instance_private (manager);
+
for (l = config->logical_monitor_configs; l; l = l->next)
{
GfLogicalMonitorConfig *logical_monitor_config = l->data;
@@ -263,7 +266,7 @@ gf_monitor_manager_is_config_applicable (GfMonitorManager *manager,
}
if (gf_monitor_is_laptop_panel (monitor) &&
- gf_monitor_manager_is_lid_closed (manager))
+ gf_backend_is_lid_closed (priv->backend))
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Refusing to activate a closed laptop panel");
@@ -2008,15 +2011,6 @@ gf_monitor_manager_real_read_edid (GfMonitorManager *manager,
return NULL;
}
-static gboolean
-gf_monitor_manager_real_is_lid_closed (GfMonitorManager *manager)
-{
- if (!manager->up_client)
- return FALSE;
-
- return manager->lid_is_closed;
-}
-
static void
gf_monitor_manager_real_read_current_state (GfMonitorManager *manager)
{
@@ -2043,33 +2037,21 @@ gf_monitor_manager_real_read_current_state (GfMonitorManager *manager)
}
static void
-lid_is_closed_changed (UpClient *client,
- GParamSpec *pspec,
- gpointer user_data)
+lid_is_closed_changed_cb (GfBackend *backend,
+ GParamSpec *pspec,
+ GfMonitorManager *self)
{
- GfMonitorManager *manager;
- gboolean lid_is_closed;
-
- manager = user_data;
- lid_is_closed = up_client_get_lid_is_closed (manager->up_client);
-
- if (lid_is_closed == manager->lid_is_closed)
- return;
-
- manager->lid_is_closed = lid_is_closed;
- gf_monitor_manager_ensure_configured (manager);
+ gf_monitor_manager_ensure_configured (self);
}
static void
gf_monitor_manager_constructed (GObject *object)
{
GfMonitorManager *manager;
- GfMonitorManagerClass *manager_class;
GfMonitorManagerPrivate *priv;
GfOrientationManager *orientation_manager;
manager = GF_MONITOR_MANAGER (object);
- manager_class = GF_MONITOR_MANAGER_GET_CLASS (manager);
priv = gf_monitor_manager_get_instance_private (manager);
G_OBJECT_CLASS (gf_monitor_manager_parent_class)->constructed (object);
@@ -2077,19 +2059,6 @@ gf_monitor_manager_constructed (GObject *object)
manager->display_config = gf_dbus_display_config_skeleton_new ();
monitor_manager_setup_dbus_config_handlers (manager);
- if (manager_class->is_lid_closed == gf_monitor_manager_real_is_lid_closed)
- {
- manager->up_client = up_client_new ();
-
- if (manager->up_client)
- {
- g_signal_connect_object (manager->up_client, "notify::lid-is-closed",
- G_CALLBACK (lid_is_closed_changed), manager, 0);
-
- manager->lid_is_closed = up_client_get_lid_is_closed (manager->up_client);
- }
- }
-
g_signal_connect_object (manager->display_config, "notify::power-save-mode",
G_CALLBACK (power_save_mode_changed), manager,
G_CONNECT_SWAPPED);
@@ -2104,6 +2073,12 @@ gf_monitor_manager_constructed (GObject *object)
manager,
G_CONNECT_SWAPPED);
+ g_signal_connect_object (priv->backend,
+ "lid-is-closed-changed",
+ G_CALLBACK (lid_is_closed_changed_cb),
+ manager,
+ 0);
+
manager->current_switch_config = GF_MONITOR_SWITCH_CONFIG_UNKNOWN;
priv->bus_name_id = g_bus_own_name (G_BUS_TYPE_SESSION,
@@ -2134,7 +2109,6 @@ gf_monitor_manager_dispose (GObject *object)
g_clear_object (&manager->display_config);
g_clear_object (&manager->config_manager);
- g_clear_object (&manager->up_client);
priv->backend = NULL;
@@ -2274,7 +2248,6 @@ gf_monitor_manager_class_init (GfMonitorManagerClass *manager_class)
object_class->set_property = gf_monitor_manager_set_property;
manager_class->read_edid = gf_monitor_manager_real_read_edid;
- manager_class->is_lid_closed = gf_monitor_manager_real_is_lid_closed;
manager_class->read_current_state = gf_monitor_manager_real_read_current_state;
gf_monitor_manager_install_properties (object_class);
@@ -2624,12 +2597,6 @@ gf_monitor_manager_update_logical_state_derived (GfMonitorManager *manager,
gf_monitor_manager_rebuild_logical_monitors_derived (manager, config);
}
-gboolean
-gf_monitor_manager_is_lid_closed (GfMonitorManager *manager)
-{
- return GF_MONITOR_MANAGER_GET_CLASS (manager)->is_lid_closed (manager);
-}
-
gfloat
gf_monitor_manager_calculate_monitor_mode_scale (GfMonitorManager *manager,
GfMonitor *monitor,
@@ -2800,7 +2767,11 @@ gf_monitor_manager_get_switch_config (GfMonitorManager *manager)
gboolean
gf_monitor_manager_can_switch_config (GfMonitorManager *manager)
{
- return (!gf_monitor_manager_is_lid_closed (manager) &&
+ GfMonitorManagerPrivate *priv;
+
+ priv = gf_monitor_manager_get_instance_private (manager);
+
+ return (!gf_backend_is_lid_closed (priv->backend) &&
g_list_length (manager->monitors) > 1);
}
diff --git a/backends/gf-monitors-config.c b/backends/gf-monitors-config.c
index 0ea8bcb..7e668ca 100644
--- a/backends/gf-monitors-config.c
+++ b/backends/gf-monitors-config.c
@@ -28,6 +28,16 @@
G_DEFINE_TYPE (GfMonitorsConfig, gf_monitors_config, G_TYPE_OBJECT)
+static gboolean
+is_lid_closed (GfMonitorManager *monitor_manager)
+{
+ GfBackend *backend;
+
+ backend = gf_monitor_manager_get_backend (monitor_manager);
+
+ return gf_backend_is_lid_closed (backend);
+}
+
static gboolean
has_adjacent_neighbour (GfMonitorsConfig *config,
GfLogicalMonitorConfig *logical_monitor_config)
@@ -170,7 +180,7 @@ gf_monitors_config_new (GfMonitorManager *monitor_manager,
GfMonitor *monitor = l->data;
GfMonitorSpec *monitor_spec;
- if (gf_monitor_manager_is_lid_closed (monitor_manager) &&
+ if (is_lid_closed (monitor_manager) &&
gf_monitor_is_laptop_panel (monitor))
continue;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]