[gnome-flashback] backends: clean up DPMS state tracking
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-flashback] backends: clean up DPMS state tracking
- Date: Tue, 18 Feb 2020 19:48:02 +0000 (UTC)
commit 25c874be87c21de535a6ef379424c912e0700457
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Tue Feb 18 20:52:17 2020 +0200
backends: clean up DPMS state tracking
Based on mutter commits:
https://gitlab.gnome.org/GNOME/mutter/commit/4cae9b5b1132a61cbff7c
https://gitlab.gnome.org/GNOME/mutter/commit/4a184d74d565f819b1317
backends/gf-gpu-xrandr.c | 34 --------------
backends/gf-monitor-manager-private.h | 9 +++-
backends/gf-monitor-manager-xrandr.c | 50 +++++++++++++++++++++
backends/gf-monitor-manager.c | 84 ++++++++++++++++++++++++-----------
4 files changed, 116 insertions(+), 61 deletions(-)
---
diff --git a/backends/gf-gpu-xrandr.c b/backends/gf-gpu-xrandr.c
index ea6b3fd..341d556 100644
--- a/backends/gf-gpu-xrandr.c
+++ b/backends/gf-gpu-xrandr.c
@@ -84,8 +84,6 @@ gf_gpu_xrandr_read_current (GfGpu *gpu,
GfMonitorManagerXrandr *monitor_manager_xrandr;
Display *xdisplay;
XRRScreenResources *resources;
- CARD16 dpms_state;
- BOOL dpms_enabled;
gint min_width;
gint min_height;
Screen *screen;
@@ -103,38 +101,6 @@ gf_gpu_xrandr_read_current (GfGpu *gpu,
g_clear_pointer (&gpu_xrandr->resources, XRRFreeScreenResources);
- if (DPMSCapable (xdisplay) &&
- DPMSInfo (xdisplay, &dpms_state, &dpms_enabled) &&
- dpms_enabled)
- {
- switch (dpms_state)
- {
- case DPMSModeOn:
- monitor_manager->power_save_mode = GF_POWER_SAVE_ON;
- break;
-
- case DPMSModeStandby:
- monitor_manager->power_save_mode = GF_POWER_SAVE_STANDBY;
- break;
-
- case DPMSModeSuspend:
- monitor_manager->power_save_mode = GF_POWER_SAVE_SUSPEND;
- break;
-
- case DPMSModeOff:
- monitor_manager->power_save_mode = GF_POWER_SAVE_OFF;
- break;
-
- default:
- monitor_manager->power_save_mode = GF_POWER_SAVE_UNSUPPORTED;
- break;
- }
- }
- else
- {
- monitor_manager->power_save_mode = GF_POWER_SAVE_UNSUPPORTED;
- }
-
XRRGetScreenSizeRange (xdisplay, DefaultRootWindow (xdisplay),
&min_width, &min_height,
&gpu_xrandr->max_screen_width,
diff --git a/backends/gf-monitor-manager-private.h b/backends/gf-monitor-manager-private.h
index 50d36bf..9108405 100644
--- a/backends/gf-monitor-manager-private.h
+++ b/backends/gf-monitor-manager-private.h
@@ -54,8 +54,6 @@ struct _GfMonitorManager
guint serial;
- GfPowerSave power_save_mode;
-
GfLogicalMonitorLayoutMode layout_mode;
gint screen_width;
@@ -86,6 +84,8 @@ typedef struct
gboolean (* is_lid_closed) (GfMonitorManager *manager);
+ void (* read_current_state) (GfMonitorManager *manager);
+
void (* ensure_initial_config) (GfMonitorManager *manager);
gboolean (* apply_monitors_config) (GfMonitorManager *manager,
@@ -226,6 +226,11 @@ GfMonitorConfigManager *gf_monitor_manager_get_config_manager (GfM
char *gf_monitor_manager_get_vendor_name (GfMonitorManager
*manager,
const char
*vendor);
+GfPowerSave gf_monitor_manager_get_power_save_mode (GfMonitorManager
*manager);
+
+void gf_monitor_manager_power_save_mode_changed (GfMonitorManager
*manager,
+ GfPowerSave
mode);
+
static inline gboolean
gf_monitor_transform_is_rotated (GfMonitorTransform transform)
{
diff --git a/backends/gf-monitor-manager-xrandr.c b/backends/gf-monitor-manager-xrandr.c
index 1038424..b3609ef 100644
--- a/backends/gf-monitor-manager-xrandr.c
+++ b/backends/gf-monitor-manager-xrandr.c
@@ -776,6 +776,55 @@ gf_monitor_manager_xrandr_read_edid (GfMonitorManager *manager,
return gf_output_xrandr_read_edid (output);
}
+static void
+gf_monitor_manager_xrandr_read_current_state (GfMonitorManager *manager)
+{
+ GfMonitorManagerXrandr *self;
+ CARD16 dpms_state;
+ BOOL dpms_enabled;
+ GfPowerSave power_save_mode;
+ GfMonitorManagerClass *parent_class;
+
+ self = GF_MONITOR_MANAGER_XRANDR (manager);
+
+ if (DPMSCapable (self->xdisplay) &&
+ DPMSInfo (self->xdisplay, &dpms_state, &dpms_enabled) &&
+ dpms_enabled)
+ {
+ switch (dpms_state)
+ {
+ case DPMSModeOn:
+ power_save_mode = GF_POWER_SAVE_ON;
+ break;
+
+ case DPMSModeStandby:
+ power_save_mode = GF_POWER_SAVE_STANDBY;
+ break;
+
+ case DPMSModeSuspend:
+ power_save_mode = GF_POWER_SAVE_SUSPEND;
+ break;
+
+ case DPMSModeOff:
+ power_save_mode = GF_POWER_SAVE_OFF;
+ break;
+
+ default:
+ power_save_mode = GF_POWER_SAVE_UNSUPPORTED;
+ break;
+ }
+ }
+ else
+ {
+ power_save_mode = GF_POWER_SAVE_UNSUPPORTED;
+ }
+
+ gf_monitor_manager_power_save_mode_changed (manager, power_save_mode);
+
+ parent_class = GF_MONITOR_MANAGER_CLASS (gf_monitor_manager_xrandr_parent_class);
+ parent_class->read_current_state (manager);
+}
+
static void
gf_monitor_manager_xrandr_ensure_initial_config (GfMonitorManager *manager)
{
@@ -1101,6 +1150,7 @@ gf_monitor_manager_xrandr_class_init (GfMonitorManagerXrandrClass *xrandr_class)
object_class->finalize = gf_monitor_manager_xrandr_finalize;
manager_class->read_edid = gf_monitor_manager_xrandr_read_edid;
+ manager_class->read_current_state = gf_monitor_manager_xrandr_read_current_state;
manager_class->ensure_initial_config = gf_monitor_manager_xrandr_ensure_initial_config;
manager_class->apply_monitors_config = gf_monitor_manager_xrandr_apply_monitors_config;
manager_class->set_power_save_mode = gf_monitor_manager_xrandr_set_power_save_mode;
diff --git a/backends/gf-monitor-manager.c b/backends/gf-monitor-manager.c
index 347986e..cad4aea 100644
--- a/backends/gf-monitor-manager.c
+++ b/backends/gf-monitor-manager.c
@@ -45,13 +45,15 @@
typedef struct
{
- GfBackend *backend;
+ GfBackend *backend;
- gboolean in_init;
+ gboolean in_init;
- guint bus_name_id;
+ guint bus_name_id;
- guint persistent_timeout_id;
+ guint persistent_timeout_id;
+
+ GfPowerSave power_save_mode;
} GfMonitorManagerPrivate;
typedef gboolean (* MonitorMatchFunc) (GfMonitor *monitor);
@@ -133,9 +135,11 @@ power_save_mode_changed (GfMonitorManager *manager,
GParamSpec *pspec,
gpointer user_data)
{
+ GfMonitorManagerPrivate *priv;
GfMonitorManagerClass *manager_class;
gint mode;
+ priv = gf_monitor_manager_get_instance_private (manager);
manager_class = GF_MONITOR_MANAGER_GET_CLASS (manager);
mode = gf_dbus_display_config_get_power_save_mode (manager->display_config);
@@ -143,7 +147,7 @@ power_save_mode_changed (GfMonitorManager *manager,
return;
/* If DPMS is unsupported, force the property back. */
- if (manager->power_save_mode == GF_POWER_SAVE_UNSUPPORTED)
+ if (priv->power_save_mode == GF_POWER_SAVE_UNSUPPORTED)
{
gf_dbus_display_config_set_power_save_mode (manager->display_config,
GF_POWER_SAVE_UNSUPPORTED);
@@ -153,9 +157,7 @@ power_save_mode_changed (GfMonitorManager *manager,
if (manager_class->set_power_save_mode)
manager_class->set_power_save_mode (manager, mode);
- manager->power_save_mode = mode;
-
- g_signal_emit (manager, manager_signals[POWER_SAVE_MODE_CHANGED], 0);
+ gf_monitor_manager_power_save_mode_changed (manager, mode);
}
static void
@@ -1907,6 +1909,28 @@ gf_monitor_manager_real_is_lid_closed (GfMonitorManager *manager)
return manager->lid_is_closed;
}
+static void
+gf_monitor_manager_real_read_current_state (GfMonitorManager *manager)
+{
+ GList *l;
+
+ manager->serial++;
+
+ for (l = manager->gpus; l; l = l->next)
+ {
+ GfGpu *gpu = l->data;
+ GError *error = NULL;
+
+ if (!gf_gpu_read_current (gpu, &error))
+ {
+ g_warning ("Failed to read current KMS state: %s", error->message);
+ g_clear_error (&error);
+ }
+ }
+
+ rebuild_monitors (manager);
+}
+
static void
lid_is_closed_changed (UpClient *client,
GParamSpec *pspec,
@@ -2119,6 +2143,7 @@ gf_monitor_manager_class_init (GfMonitorManagerClass *manager_class)
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);
gf_monitor_manager_install_signals (object_class);
@@ -2259,23 +2284,7 @@ gf_monitor_manager_has_hotplug_mode_update (GfMonitorManager *manager)
void
gf_monitor_manager_read_current_state (GfMonitorManager *manager)
{
- GList *l;
-
- manager->serial++;
-
- for (l = manager->gpus; l; l = l->next)
- {
- GfGpu *gpu = l->data;
- GError *error = NULL;
-
- if (!gf_gpu_read_current (gpu, &error))
- {
- g_warning ("Failed to read current KMS state: %s", error->message);
- g_clear_error (&error);
- }
- }
-
- rebuild_monitors (manager);
+ return GF_MONITOR_MANAGER_GET_CLASS (manager)->read_current_state (manager);
}
void
@@ -2595,6 +2604,31 @@ gf_monitor_manager_get_vendor_name (GfMonitorManager *manager,
return gnome_pnp_ids_get_pnp_id (manager->pnp_ids, vendor);
}
+GfPowerSave
+gf_monitor_manager_get_power_save_mode (GfMonitorManager *manager)
+{
+ GfMonitorManagerPrivate *priv;
+
+ priv = gf_monitor_manager_get_instance_private (manager);
+
+ return priv->power_save_mode;
+}
+
+void
+gf_monitor_manager_power_save_mode_changed (GfMonitorManager *manager,
+ GfPowerSave mode)
+{
+ GfMonitorManagerPrivate *priv;
+
+ priv = gf_monitor_manager_get_instance_private (manager);
+
+ if (priv->power_save_mode == mode)
+ return;
+
+ priv->power_save_mode = mode;
+ g_signal_emit (manager, manager_signals[POWER_SAVE_MODE_CHANGED], 0);
+}
+
gint
gf_monitor_manager_get_monitor_for_connector (GfMonitorManager *manager,
const gchar *connector)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]