monitor-config-manager: Keep short history of configurations
In order to go back in monitor configurations, save them to a history. The history is implemented as a max 3 element long queue, where newly set configurations are pushed to the head, and old are popped from the tail. The difference between using a single previous config reference and a queue is that we can now remember the configuration used prior to a D-Bus triggered configuration when the user discarded the configuration. This will later be used to restore a previous configuration when a laptop lid is opened. https://bugzilla.gnome.org/show_bug.cgi?id=777732
This commit is contained in:
parent
6c0f107db0
commit
b140e7fbeb
@ -28,6 +28,8 @@
|
||||
#include "backends/meta-monitor-manager-private.h"
|
||||
#include "core/boxes-private.h"
|
||||
|
||||
#define CONFIG_HISTORY_MAX_SIZE 3
|
||||
|
||||
struct _MetaMonitorConfigManager
|
||||
{
|
||||
GObject parent;
|
||||
@ -37,7 +39,7 @@ struct _MetaMonitorConfigManager
|
||||
MetaMonitorConfigStore *config_store;
|
||||
|
||||
MetaMonitorsConfig *current_config;
|
||||
MetaMonitorsConfig *previous_config;
|
||||
GQueue config_history;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (MetaMonitorConfigManager, meta_monitor_config_manager,
|
||||
@ -988,8 +990,15 @@ void
|
||||
meta_monitor_config_manager_set_current (MetaMonitorConfigManager *config_manager,
|
||||
MetaMonitorsConfig *config)
|
||||
{
|
||||
g_set_object (&config_manager->previous_config,
|
||||
config_manager->current_config);
|
||||
if (config_manager->current_config)
|
||||
{
|
||||
g_queue_push_head (&config_manager->config_history,
|
||||
g_object_ref (config_manager->current_config));
|
||||
if (g_queue_get_length (&config_manager->config_history) >
|
||||
CONFIG_HISTORY_MAX_SIZE)
|
||||
g_object_unref (g_queue_pop_tail (&config_manager->config_history));
|
||||
}
|
||||
|
||||
g_set_object (&config_manager->current_config, config);
|
||||
}
|
||||
|
||||
@ -1008,10 +1017,23 @@ meta_monitor_config_manager_get_current (MetaMonitorConfigManager *config_manage
|
||||
return config_manager->current_config;
|
||||
}
|
||||
|
||||
MetaMonitorsConfig *
|
||||
meta_monitor_config_manager_pop_previous (MetaMonitorConfigManager *config_manager)
|
||||
{
|
||||
return g_queue_pop_head (&config_manager->config_history);
|
||||
}
|
||||
|
||||
MetaMonitorsConfig *
|
||||
meta_monitor_config_manager_get_previous (MetaMonitorConfigManager *config_manager)
|
||||
{
|
||||
return config_manager->previous_config;
|
||||
return g_queue_peek_head (&config_manager->config_history);
|
||||
}
|
||||
|
||||
void
|
||||
meta_monitor_config_manager_clear_history (MetaMonitorConfigManager *config_manager)
|
||||
{
|
||||
g_queue_foreach (&config_manager->config_history, (GFunc) g_object_unref, NULL);
|
||||
g_queue_clear (&config_manager->config_history);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1021,7 +1043,7 @@ meta_monitor_config_manager_dispose (GObject *object)
|
||||
META_MONITOR_CONFIG_MANAGER (object);
|
||||
|
||||
g_clear_object (&config_manager->current_config);
|
||||
g_clear_object (&config_manager->previous_config);
|
||||
meta_monitor_config_manager_clear_history (config_manager);
|
||||
|
||||
G_OBJECT_CLASS (meta_monitor_config_manager_parent_class)->dispose (object);
|
||||
}
|
||||
@ -1029,6 +1051,7 @@ meta_monitor_config_manager_dispose (GObject *object)
|
||||
static void
|
||||
meta_monitor_config_manager_init (MetaMonitorConfigManager *config_manager)
|
||||
{
|
||||
g_queue_init (&config_manager->config_history);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -104,8 +104,12 @@ void meta_monitor_config_manager_set_current (MetaMonitorConfigManager *config_m
|
||||
|
||||
MetaMonitorsConfig * meta_monitor_config_manager_get_current (MetaMonitorConfigManager *config_manager);
|
||||
|
||||
MetaMonitorsConfig * meta_monitor_config_manager_pop_previous (MetaMonitorConfigManager *config_manager);
|
||||
|
||||
MetaMonitorsConfig * meta_monitor_config_manager_get_previous (MetaMonitorConfigManager *config_manager);
|
||||
|
||||
void meta_monitor_config_manager_clear_history (MetaMonitorConfigManager *config_manager);
|
||||
|
||||
void meta_monitor_config_manager_save_current (MetaMonitorConfigManager *config_manager);
|
||||
|
||||
MetaMonitorsConfig * meta_monitors_config_new (GList *logical_monitor_configs,
|
||||
|
@ -1111,14 +1111,13 @@ restore_previous_config (MetaMonitorManager *manager)
|
||||
GError *error = NULL;
|
||||
|
||||
previous_config =
|
||||
meta_monitor_config_manager_get_previous (manager->config_manager);
|
||||
meta_monitor_config_manager_pop_previous (manager->config_manager);
|
||||
|
||||
if (previous_config)
|
||||
{
|
||||
MetaMonitorsConfigMethod method;
|
||||
|
||||
method = META_MONITORS_CONFIG_METHOD_TEMPORARY;
|
||||
g_object_ref (previous_config);
|
||||
if (meta_monitor_manager_apply_monitors_config (manager,
|
||||
previous_config,
|
||||
method,
|
||||
|
Loading…
Reference in New Issue
Block a user