[gnome-flashback] monitor-manager: show confirm display change dialog
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-flashback] monitor-manager: show confirm display change dialog
- Date: Thu, 28 Sep 2017 12:03:54 +0000 (UTC)
commit 1ce7ac0ae633ecb510d4b7dcaed407379da98cdd
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Thu Sep 28 14:59:08 2017 +0300
monitor-manager: show confirm display change dialog
backends/gf-monitor-manager.c | 107 ++++++++++++++++++++++++++++++++++++++
backends/gf-monitor-manager.h | 15 ++++--
gnome-flashback/gf-application.c | 40 ++++++++++++++
3 files changed, 157 insertions(+), 5 deletions(-)
---
diff --git a/backends/gf-monitor-manager.c b/backends/gf-monitor-manager.c
index 0d95dc9..0b5d7c0 100644
--- a/backends/gf-monitor-manager.c
+++ b/backends/gf-monitor-manager.c
@@ -42,6 +42,8 @@
#include "gf-monitors-config-private.h"
#include "gf-output-private.h"
+#define DEFAULT_DISPLAY_CONFIGURATION_TIMEOUT 10
+
typedef struct
{
GfBackend *backend;
@@ -49,6 +51,8 @@ typedef struct
gboolean in_init;
guint bus_name_id;
+
+ guint persistent_timeout_id;
} GfMonitorManagerPrivate;
typedef gboolean (* MonitorMatchFunc) (GfMonitor *monitor);
@@ -485,13 +489,92 @@ orientation_changed (GfOrientationManager *orientation_manager,
}
static void
+restore_previous_config (GfMonitorManager *manager)
+{
+ GfMonitorsConfig *previous_config;
+
+ previous_config = gf_monitor_config_manager_pop_previous (manager->config_manager);
+
+ if (previous_config)
+ {
+ GfMonitorsConfigMethod method;
+ GError *error;
+
+ method = GF_MONITORS_CONFIG_METHOD_TEMPORARY;
+ error = NULL;
+
+ if (gf_monitor_manager_apply_monitors_config (manager, previous_config,
+ method, &error))
+ {
+ g_object_unref (previous_config);
+ return;
+ }
+ else
+ {
+ g_object_unref (previous_config);
+ g_warning ("Failed to restore previous configuration: %s", error->message);
+ g_error_free (error);
+ }
+ }
+
+ gf_monitor_manager_ensure_configured (manager);
+}
+
+static gboolean
+save_config_timeout (gpointer user_data)
+{
+ GfMonitorManager *manager = user_data;
+ GfMonitorManagerPrivate *priv;
+
+ priv = gf_monitor_manager_get_instance_private (manager);
+
+ restore_previous_config (manager);
+ priv->persistent_timeout_id = 0;
+
+ return G_SOURCE_REMOVE;
+}
+
+static void
cancel_persistent_confirmation (GfMonitorManager *manager)
{
+ GfMonitorManagerPrivate *priv;
+
+ priv = gf_monitor_manager_get_instance_private (manager);
+
+ if (priv->persistent_timeout_id != 0)
+ {
+ g_source_remove (priv->persistent_timeout_id);
+ priv->persistent_timeout_id = 0;
+ }
+}
+
+static void
+confirm_configuration (GfMonitorManager *manager,
+ gboolean confirmed)
+{
+ if (confirmed)
+ gf_monitor_config_manager_save_current (manager->config_manager);
+ else
+ restore_previous_config (manager);
}
static void
request_persistent_confirmation (GfMonitorManager *manager)
{
+ GfMonitorManagerPrivate *priv;
+ gint timeout;
+
+ priv = gf_monitor_manager_get_instance_private (manager);
+ timeout = gf_monitor_manager_get_display_configuration_timeout ();
+
+ priv->persistent_timeout_id = g_timeout_add_seconds (timeout,
+ save_config_timeout,
+ manager);
+
+ g_source_set_name_by_id (priv->persistent_timeout_id,
+ "[gnome-flashback] save_config_timeout");
+
+ g_signal_emit (manager, manager_signals[CONFIRM_DISPLAY_CHANGE], 0);
}
static gboolean
@@ -2492,3 +2575,27 @@ gf_monitor_manager_switch_config (GfMonitorManager *manager,
g_object_unref (config);
}
+
+gint
+gf_monitor_manager_get_display_configuration_timeout (void)
+{
+ return DEFAULT_DISPLAY_CONFIGURATION_TIMEOUT;
+}
+
+void
+gf_monitor_manager_confirm_configuration (GfMonitorManager *manager,
+ gboolean ok)
+{
+ GfMonitorManagerPrivate *priv;
+
+ priv = gf_monitor_manager_get_instance_private (manager);
+
+ if (!priv->persistent_timeout_id)
+ {
+ /* too late */
+ return;
+ }
+
+ cancel_persistent_confirmation (manager);
+ confirm_configuration (manager, ok);
+}
diff --git a/backends/gf-monitor-manager.h b/backends/gf-monitor-manager.h
index 68a217a..2518dac 100644
--- a/backends/gf-monitor-manager.h
+++ b/backends/gf-monitor-manager.h
@@ -37,14 +37,19 @@ typedef enum
typedef struct _GfMonitorManager GfMonitorManager;
-gboolean gf_monitor_manager_get_is_builtin_display_on (GfMonitorManager *manager);
+gboolean gf_monitor_manager_get_is_builtin_display_on (GfMonitorManager
*manager);
-GfMonitorSwitchConfigType gf_monitor_manager_get_switch_config (GfMonitorManager *manager);
+GfMonitorSwitchConfigType gf_monitor_manager_get_switch_config (GfMonitorManager
*manager);
-gboolean gf_monitor_manager_can_switch_config (GfMonitorManager *manager);
+gboolean gf_monitor_manager_can_switch_config (GfMonitorManager
*manager);
-void gf_monitor_manager_switch_config (GfMonitorManager *manager,
- GfMonitorSwitchConfigType
config_type);
+void gf_monitor_manager_switch_config (GfMonitorManager
*manager,
+ GfMonitorSwitchConfigType
config_type);
+
+gint gf_monitor_manager_get_display_configuration_timeout (void);
+
+void gf_monitor_manager_confirm_configuration (GfMonitorManager
*manager,
+ gboolean
ok);
G_END_DECLS
diff --git a/gnome-flashback/gf-application.c b/gnome-flashback/gf-application.c
index 9c81a3e..2e45d0b 100644
--- a/gnome-flashback/gf-application.c
+++ b/gnome-flashback/gf-application.c
@@ -21,6 +21,7 @@
#include <gtk/gtk.h>
#include "gf-application.h"
+#include "gf-confirm-display-change-dialog.h"
#include "backends/gf-backend.h"
#include "libaudio-device-selection/gf-audio-device-selection.h"
#include "libautomount-manager/gsd-automount-manager.h"
@@ -73,6 +74,8 @@ struct _GfApplication
GfSoundApplet *sound;
GfStatusNotifierWatcher *status_notifier_watcher;
GfWorkarounds *workarounds;
+
+ GtkWidget *display_change_dialog;
};
G_DEFINE_TYPE (GfApplication, gf_application, G_TYPE_OBJECT)
@@ -216,18 +219,55 @@ gf_application_dispose (GObject *object)
g_clear_object (&application->status_notifier_watcher);
g_clear_object (&application->workarounds);
+ g_clear_pointer (&application->display_change_dialog, gtk_widget_destroy);
+
g_clear_object (&application->backend);
G_OBJECT_CLASS (gf_application_parent_class)->dispose (object);
}
static void
+keep_changes_cb (GfConfirmDisplayChangeDialog *dialog,
+ gboolean keep_changes,
+ GfApplication *application)
+{
+ GfMonitorManager *monitor_manager;
+
+ monitor_manager = gf_backend_get_monitor_manager (application->backend);
+
+ gf_monitor_manager_confirm_configuration (monitor_manager, keep_changes);
+ g_clear_pointer (&application->display_change_dialog, gtk_widget_destroy);
+}
+
+static void
+confirm_display_change_cb (GfMonitorManager *monitor_manager,
+ GfApplication *application)
+{
+ gint timeout;
+
+ timeout = gf_monitor_manager_get_display_configuration_timeout ();
+
+ g_clear_pointer (&application->display_change_dialog, gtk_widget_destroy);
+ application->display_change_dialog = gf_confirm_display_change_dialog_new (timeout);
+
+ g_signal_connect (application->display_change_dialog, "keep-changes",
+ G_CALLBACK (keep_changes_cb), application);
+
+ gtk_window_present (GTK_WINDOW (application->display_change_dialog));
+}
+
+static void
gf_application_init (GfApplication *application)
{
GtkSettings *settings;
+ GfMonitorManager *monitor_manager;
application->backend = gf_backend_new (GF_BACKEND_TYPE_X11_CM);
+ monitor_manager = gf_backend_get_monitor_manager (application->backend);
+ g_signal_connect (monitor_manager, "confirm-display-change",
+ G_CALLBACK (confirm_display_change_cb), application);
+
application->settings = g_settings_new ("org.gnome.gnome-flashback");
settings = gtk_settings_get_default ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]