monitor-manager: Add 'reason' argument to 'power-save-changed' signal

We can change power save mode for two reasons: gsd-power told us to, or
we saw a hotplug event. Sometimes it's useful to be able to make the
distinction to why a power save mode changed, so add a reason to the
signal.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3233>
This commit is contained in:
Jonas Ådahl 2023-09-01 22:20:16 +02:00 committed by Marge Bot
parent a7231ab2be
commit 96d4ae5ac8
8 changed files with 42 additions and 16 deletions

View File

@ -656,8 +656,9 @@ input_mapper_monitors_changed_cb (MetaMonitorManager *monitor_manager,
}
static void
input_mapper_power_save_mode_changed_cb (MetaMonitorManager *monitor_manager,
MetaInputMapper *mapper)
input_mapper_power_save_mode_changed_cb (MetaMonitorManager *monitor_manager,
MetaPowerSaveChangeReason reason,
MetaInputMapper *mapper)
{
ClutterInputDevice *device;
MetaLogicalMonitor *logical_monitor;

View File

@ -319,8 +319,9 @@ void meta_monitor_manager_get_screen_size (MetaMonitorManager *
MetaPowerSave meta_monitor_manager_get_power_save_mode (MetaMonitorManager *manager);
void meta_monitor_manager_power_save_mode_changed (MetaMonitorManager *manager,
MetaPowerSave mode);
void meta_monitor_manager_power_save_mode_changed (MetaMonitorManager *manager,
MetaPowerSave mode,
MetaPowerSaveChangeReason reason);
void meta_monitor_manager_confirm_configuration (MetaMonitorManager *manager,
gboolean ok);

View File

@ -59,6 +59,7 @@
#include "clutter/clutter.h"
#include "core/util-private.h"
#include "meta/main.h"
#include "meta/meta-enum-types.h"
#include "meta/meta-x11-errors.h"
#include "meta-dbus-display-config.h"
@ -416,8 +417,9 @@ meta_monitor_manager_rebuild_logical_monitors_derived (MetaMonitorManager *manag
}
void
meta_monitor_manager_power_save_mode_changed (MetaMonitorManager *manager,
MetaPowerSave mode)
meta_monitor_manager_power_save_mode_changed (MetaMonitorManager *manager,
MetaPowerSave mode,
MetaPowerSaveChangeReason reason)
{
MetaMonitorManagerPrivate *priv =
meta_monitor_manager_get_instance_private (manager);
@ -426,7 +428,7 @@ meta_monitor_manager_power_save_mode_changed (MetaMonitorManager *manager,
return;
priv->power_save_mode = mode;
g_signal_emit (manager, signals[POWER_SAVE_MODE_CHANGED], 0);
g_signal_emit (manager, signals[POWER_SAVE_MODE_CHANGED], 0, reason);
}
static void
@ -438,6 +440,7 @@ power_save_mode_changed (MetaMonitorManager *manager,
meta_monitor_manager_get_instance_private (manager);
MetaMonitorManagerClass *klass;
int mode = meta_dbus_display_config_get_power_save_mode (manager->display_config);
MetaPowerSaveChangeReason reason;
if (mode == META_POWER_SAVE_UNSUPPORTED)
return;
@ -453,7 +456,8 @@ power_save_mode_changed (MetaMonitorManager *manager,
if (klass->set_power_save_mode)
klass->set_power_save_mode (manager, mode);
meta_monitor_manager_power_save_mode_changed (manager, mode);
reason = META_POWER_SAVE_CHANGE_REASON_MODE_CHANGE;
meta_monitor_manager_power_save_mode_changed (manager, mode, reason);
}
void
@ -1474,7 +1478,8 @@ meta_monitor_manager_class_init (MetaMonitorManagerClass *klass)
G_SIGNAL_RUN_LAST,
0,
NULL, NULL, NULL,
G_TYPE_NONE, 0);
G_TYPE_NONE, 1,
META_TYPE_POWER_SAVE_CHANGE_REASON);
signals[CONFIRM_DISPLAY_CHANGE] =
g_signal_new ("confirm-display-change",

View File

@ -292,8 +292,9 @@ meta_stage_deactivate (ClutterStage *actor)
}
static void
on_power_save_changed (MetaMonitorManager *monitor_manager,
MetaStage *stage)
on_power_save_changed (MetaMonitorManager *monitor_manager,
MetaPowerSaveChangeReason reason,
MetaStage *stage)
{
if (meta_monitor_manager_get_power_save_mode (monitor_manager) ==
META_POWER_SAVE_ON)

View File

@ -114,8 +114,14 @@ meta_monitor_manager_native_read_current_state (MetaMonitorManager *manager)
power_save_mode = meta_monitor_manager_get_power_save_mode (manager);
if (power_save_mode != META_POWER_SAVE_ON)
meta_monitor_manager_power_save_mode_changed (manager,
META_POWER_SAVE_ON);
{
MetaPowerSaveChangeReason reason;
reason = META_POWER_SAVE_CHANGE_REASON_HOTPLUG;
meta_monitor_manager_power_save_mode_changed (manager,
META_POWER_SAVE_ON,
reason);
}
parent_class->read_current_state (manager);
}

View File

@ -2011,8 +2011,9 @@ on_gpu_added (MetaBackendNative *backend_native,
}
static void
on_power_save_mode_changed (MetaMonitorManager *monitor_manager,
MetaRendererNative *renderer_native)
on_power_save_mode_changed (MetaMonitorManager *monitor_manager,
MetaPowerSaveChangeReason reason,
MetaRendererNative *renderer_native)
{
MetaRenderer *renderer = META_RENDERER (renderer_native);
MetaBackend *backend = meta_renderer_get_backend (renderer);

View File

@ -141,6 +141,7 @@ meta_monitor_manager_xrandr_read_current_state (MetaMonitorManager *manager)
BOOL dpms_capable, dpms_enabled;
CARD16 dpms_state;
MetaPowerSave power_save_mode;
MetaPowerSaveChangeReason reason;
dpms_capable = DPMSCapable (xdisplay);
@ -151,7 +152,11 @@ meta_monitor_manager_xrandr_read_current_state (MetaMonitorManager *manager)
else
power_save_mode = META_POWER_SAVE_UNSUPPORTED;
meta_monitor_manager_power_save_mode_changed (manager, power_save_mode);
reason = META_POWER_SAVE_CHANGE_REASON_HOTPLUG;
meta_monitor_manager_power_save_mode_changed (manager,
power_save_mode,
reason);
parent_class->read_current_state (manager);
}

View File

@ -30,6 +30,12 @@ typedef enum
META_MONITOR_SWITCH_CONFIG_UNKNOWN,
} MetaMonitorSwitchConfigType;
typedef enum _MetaPowerSaveChangeReason
{
META_POWER_SAVE_CHANGE_REASON_MODE_CHANGE,
META_POWER_SAVE_CHANGE_REASON_HOTPLUG,
} MetaPowerSaveChangeReason;
typedef struct _MetaMonitorManagerClass MetaMonitorManagerClass;
typedef struct _MetaMonitorManager MetaMonitorManager;