[mousetweaks/wayland] Save the HoverClick window geometry



commit 6842cb92466064de4d4754ba3b7510c375ad610c
Author: Gerd Kohlberger <gerdk src gnome org>
Date:   Mon Oct 28 09:26:31 2013 +0100

    Save the HoverClick window geometry

 data/window.ui           |    5 ++-
 src/hover_click_window.c |   55 +++++++++++++++++++++++++++++++++++-----------
 2 files changed, 45 insertions(+), 15 deletions(-)
---
diff --git a/data/window.ui b/data/window.ui
index c2f0b13..5ce18d2 100644
--- a/data/window.ui
+++ b/data/window.ui
@@ -1,11 +1,10 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.15.3 on Sun Oct 27 09:16:51 2013 -->
+<!-- Generated with glade 3.15.3 on Mon Oct 28 09:20:55 2013 -->
 <interface>
   <!-- interface-requires gtk+ 3.10 -->
   <template class="HoverClickWindow" parent="GtkApplicationWindow">
     <property name="can_focus">False</property>
     <property name="title" translatable="yes">Hover Click</property>
-    <property name="resizable">False</property>
     <property name="icon_name">input-mouse</property>
     <property name="type_hint">dialog</property>
     <property name="deletable">False</property>
@@ -22,6 +21,8 @@
         </style>
         <child>
           <object class="GtkRadioButton" id="button_primary">
+            <property name="width_request">45</property>
+            <property name="height_request">45</property>
             <property name="visible">True</property>
             <property name="can_focus">True</property>
             <property name="receives_default">False</property>
diff --git a/src/hover_click_window.c b/src/hover_click_window.c
index d5b5329..48d057d 100644
--- a/src/hover_click_window.c
+++ b/src/hover_click_window.c
@@ -18,6 +18,7 @@
  */
 
 #include <glib/gi18n.h>
+#include <glib-unix.h>
 #include <gtk/gtk.h>
 
 #include "config.h"
@@ -191,7 +192,7 @@ mousetweaks_proxy_ready (GDBusConnection  *connection,
     {
         g_warning ("%s", error->message);
         g_error_free (error);
-        g_object_set (win, "application", NULL, NULL);
+        gtk_widget_destroy (GTK_WIDGET (win));
         return;
     }
 
@@ -222,14 +223,8 @@ orientation_notify (GObject          *object,
                     GParamSpec       *pspec,
                     HoverClickWindow *win)
 {
-    HoverClickWindowPrivate *priv = win->priv;
-    GtkOrientation o;
-
-    o = gtk_orientable_get_orientation (GTK_ORIENTABLE (priv->box));
-    if (o == GTK_ORIENTATION_VERTICAL)
-        gtk_widget_set_size_request (GTK_WIDGET (priv->button_primary), 110, 50);
-    else
-        gtk_widget_set_size_request (GTK_WIDGET (priv->button_primary), 80, 50);
+    /* reset to minimum size */
+    gtk_window_resize (GTK_WINDOW (win), 1, 1);
 }
 
 static gboolean
@@ -284,6 +279,30 @@ set_menu_header (HoverClickWindow *win)
 }
 
 static void
+apply_window_geometry (HoverClickWindow *win)
+{
+    gchar *geo;
+
+    geo = g_settings_get_string (win->priv->settings, "window-geometry");
+    gtk_window_parse_geometry (GTK_WINDOW (win), geo);
+    g_free (geo);
+}
+
+static void
+save_window_geometry (HoverClickWindow *win)
+{
+    gint x, y, w, h;
+    gchar *geo;
+
+    gtk_window_get_size (GTK_WINDOW (win), &w, &h);
+    gtk_window_get_position (GTK_WINDOW (win), &x, &y);
+
+    geo = g_strdup_printf ("%ix%i+%i+%i", w, h, x, y);
+    g_settings_set_string (win->priv->settings, "window-geometry", geo);
+    g_free (geo);
+}
+
+static void
 hover_click_window_init (HoverClickWindow *win)
 {
     HoverClickWindowPrivate *priv;
@@ -298,9 +317,6 @@ hover_click_window_init (HoverClickWindow *win)
     g_object_set (gtk_settings_get_default (),
                   "gtk-application-prefer-dark-theme", TRUE, NULL);
 
-    g_signal_connect (priv->box, "notify::orientation",
-                      G_CALLBACK (orientation_notify), win);
-
     g_settings_bind_with_mapping (priv->settings, "window-orientation",
                                   priv->box, "orientation",
                                   G_SETTINGS_BIND_DEFAULT,
@@ -308,6 +324,9 @@ hover_click_window_init (HoverClickWindow *win)
                                   orientation_set_mapping,
                                   NULL, NULL);
 
+    g_signal_connect (priv->box, "notify::orientation",
+                      G_CALLBACK (orientation_notify), win);
+
     g_signal_connect (priv->button_primary, "toggled", G_CALLBACK (button_primary_toggled), win);
     g_signal_connect (priv->button_double, "toggled", G_CALLBACK (button_double_toggled), win);
     g_signal_connect (priv->button_secondary, "toggled", G_CALLBACK (button_secondary_toggled), win);
@@ -330,7 +349,6 @@ hover_click_window_init (HoverClickWindow *win)
 
     gtk_window_stick (GTK_WINDOW (win));
     gtk_window_set_keep_above (GTK_WINDOW (win), TRUE);
-    gtk_window_move (GTK_WINDOW (win), 30, 30);
 }
 
 static void
@@ -353,6 +371,13 @@ hover_click_window_class_init (HoverClickWindowClass *klass)
 }
 
 static void
+sighup_received (HoverClickWindow *win)
+{
+    save_window_geometry (win);
+    gtk_widget_destroy (GTK_WIDGET (win));
+}
+
+static void
 application_activate (GApplication *app,
                       gpointer      data)
 {
@@ -369,6 +394,10 @@ application_activate (GApplication *app,
     gtk_application_add_window (GTK_APPLICATION (app), GTK_WINDOW (win));
     gtk_widget_show (win);
 
+    apply_window_geometry (HOVER_CLICK_WINDOW (win));
+
+    g_unix_signal_add (SIGHUP, (GSourceFunc) sighup_received, win);
+
     g_dbus_proxy_new (g_application_get_dbus_connection (app),
                       G_DBUS_PROXY_FLAGS_NONE,
                       NULL,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]