[mousetweaks] Add "geometry" option to set size and position of the click-type window



commit 9b3d734fa83d80e96dbfa3e99fde59c36e48cfa1
Author: Gerd Kohlberger <gerdk src gnome org>
Date:   Thu Oct 28 20:10:08 2010 +0200

    Add "geometry" option to set size and position of the click-type window
    
    Replaces the --ctw-x and --ctw-y command-line arguments.

 data/mousetweaks.ui                       |    8 ++--
 data/org.gnome.mousetweaks.gschema.xml.in |    5 +++
 man/mousetweaks.1                         |   14 +++-----
 src/mt-common.h                           |    1 +
 src/mt-ctw.c                              |   48 +++++++++++++++++++---------
 src/mt-ctw.h                              |    6 +++-
 src/mt-main.c                             |   32 ++++++++++---------
 src/mt-settings.c                         |   29 +++++++++++++++++-
 src/mt-settings.h                         |    3 +-
 9 files changed, 100 insertions(+), 46 deletions(-)
---
diff --git a/data/mousetweaks.ui b/data/mousetweaks.ui
index 793e853..4c73e5d 100644
--- a/data/mousetweaks.ui
+++ b/data/mousetweaks.ui
@@ -4,8 +4,8 @@
   <!-- interface-naming-policy project-wide -->
   <object class="GtkWindow" id="ctw">
     <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
-    <property name="border_width">4</property>
-    <property name="title" translatable="yes">Dwell Click Type</property>
+    <property name="border_width">2</property>
+    <property name="title" translatable="yes">Dwell Click-Type</property>
     <property name="icon_name">input-mouse</property>
     <property name="type_hint">dialog</property>
     <child>
@@ -136,7 +136,7 @@
                     <property name="visible">True</property>
                     <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                     <property name="yalign">0</property>
-                    <property name="label" translatable="yes">Drag Click</property>
+                    <property name="label" translatable="yes" comments="'Drag' like in a Drag and Drop operation">Drag</property>
                   </object>
                   <packing>
                     <property name="position">1</property>
@@ -181,7 +181,7 @@
                     <property name="visible">True</property>
                     <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                     <property name="yalign">0</property>
-                    <property name="label" translatable="yes">Right Click</property>
+                    <property name="label" translatable="yes">Secondary Click</property>
                   </object>
                   <packing>
                     <property name="position">1</property>
diff --git a/data/org.gnome.mousetweaks.gschema.xml.in b/data/org.gnome.mousetweaks.gschema.xml.in
index 36c0e74..5a6f1d1 100644
--- a/data/org.gnome.mousetweaks.gschema.xml.in
+++ b/data/org.gnome.mousetweaks.gschema.xml.in
@@ -10,5 +10,10 @@
       <_summary>Click-type window orientation</_summary>
       <_description>Orientation of the click-type window.</_description>
     </key>
+    <key name="click-type-window-geometry" type="s">
+      <default>''</default>
+      <_summary>Click-type window geometry</_summary>
+      <_description>Size and position of the click-type window. The format is a standard X Window System geometry string.</_description>
+    </key>
   </schema>
 </schemalist>
diff --git a/man/mousetweaks.1 b/man/mousetweaks.1
index 4cda45b..96914d4 100644
--- a/man/mousetweaks.1
+++ b/man/mousetweaks.1
@@ -6,8 +6,8 @@ mousetweaks \- Accessibility enhancements for pointing devices
 [\-\-dwell] [\-\-ssc]
 [\-\-dwell\-time=FLOAT] [\-\-ssc\-time=FLOAT]
 [\-m|\-\-dwell\-mode=STRING] [\-c|\-\-show\-ctw]
-[\-x|\-\-ctw\-x=INT] [\-y|\-\-ctw\-y=INT]
-[\-t|\-\-threshold=INT] [\-s|\-\-shutdown]
+[\-t|\-\-threshold=INT] [\-g|\-\-geometry]
+[\-s|\-\-shutdown]
 [\-\-daemonize] [\-?|\-\-help]
 .SH DESCRIPTION
 .B mousetweaks
@@ -40,15 +40,13 @@ Select a dwell mode. Available options:
 .B \-c, \-\-show\-ctw
 Show the click\-type window. Only useful in combination with \-\-dwell\-mode=window.
 .TP
-.B \-x, \-\-ctw\-x=INT
-x\-position of the click\-type window on screen.
-.TP
-.B \-y, \-\-ctw\-y=INT
-y\-position of the click\-type window on screen.
-.TP
 .B \-t, \-\-threshold=INT
 Ignore small pointer movements. Range: 0 \- 30 pixels.
 .TP
+.B \-g, \-\-geometry
+Size and position of the click-type window. Expects a standard X Window System
+geometry string. ie. WIDTHxHEIGHT+X+Y
+.TP
 .B \-s, \-\-shutdown
 Stop the mousetweaks daemon.
 .TP
diff --git a/src/mt-common.h b/src/mt-common.h
index c6e4663..712d5c7 100644
--- a/src/mt-common.h
+++ b/src/mt-common.h
@@ -43,6 +43,7 @@ G_BEGIN_DECLS
 #define MOUSETWEAKS_SCHEMA_ID       "org.gnome.mousetweaks"
 #define KEY_CTW_STYLE               "click-type-window-style"
 #define KEY_CTW_ORIENTATION         "click-type-window-orientation"
+#define KEY_CTW_GEOMETRY            "click-type-window-geometry"
 
 #define A11Y_MOUSE_SCHEMA_ID        "org.gnome.desktop.a11y.mouse"
 #define KEY_DWELL_ENABLED           "dwell-click-enabled"
diff --git a/src/mt-ctw.c b/src/mt-ctw.c
index 1cd75ee..2d9060a 100644
--- a/src/mt-ctw.c
+++ b/src/mt-ctw.c
@@ -17,8 +17,6 @@
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <gtk/gtk.h>
-
 #include "mt-ctw.h"
 #include "mt-service.h"
 #include "mt-settings.h"
@@ -59,14 +57,14 @@ static void
 ctw_style_changed (MtSettings *ms, GParamSpec *pspec)
 {
     GtkWidget *icon, *label;
-    const gchar *l[] = { "single_l", "double_l", "drag_l", "right_l" };
-    const gchar *img[] = { "single_i", "double_i", "drag_i", "right_i" };
+    const gchar *label_names[] = { "single_l", "double_l", "drag_l", "right_l" };
+    const gchar *icon_names[] = { "single_i", "double_i", "drag_i", "right_i" };
     gint i;
 
     for (i = 0; i < N_CLICK_TYPES; i++)
     {
-        label = W (l[i]);
-        icon = W (img[i]);
+        label = W (label_names[i]);
+        icon = W (icon_names[i]);
 
         switch (ms->ctw_style)
         {
@@ -207,7 +205,7 @@ ctw_window_delete (GtkWidget *widget, GdkEvent *event, gpointer data)
 }
 
 gboolean
-mt_ctw_init (gint x, gint y)
+mt_ctw_init (void)
 {
     MtSettings *ms;
     MtService *service;
@@ -263,9 +261,6 @@ mt_ctw_init (gint x, gint y)
                       "signal::notify::dwell-mode", G_CALLBACK (ctw_sensitivity_changed), NULL,
                       NULL);
 
-    ctw_visibility_changed (ms, NULL);
-    ctw_sensitivity_changed (ms, NULL);
-
     /* context menu: button style */
     switch (ms->ctw_style)
     {
@@ -309,12 +304,12 @@ mt_ctw_init (gint x, gint y)
     ctw_orientation_changed (ms, NULL);
     ctw_menu_label_set_bold (W ("menu_button_style"));
 
-    /* XXX: remember window position */
-    if (x != -1 && y != -1)
-    {
-        gtk_widget_realize (ctw);
-        gtk_window_move (GTK_WINDOW (ctw), x, y);
-    }
+    /* window geometry */
+    gtk_widget_show (W ("box"));
+    gtk_window_parse_geometry (GTK_WINDOW (ctw), ms->ctw_geometry);
+
+    ctw_visibility_changed (ms, NULL);
+    ctw_sensitivity_changed (ms, NULL);
 
     return TRUE;
 }
@@ -334,3 +329,24 @@ mt_ctw_get_window (void)
 {
     return W ("ctw");
 }
+
+void
+mt_ctw_save_geometry (void)
+{
+    GtkWidget *ctw;
+    gchar *geometry;
+    gint x, y, width, height;
+
+    ctw = mt_ctw_get_window ();
+
+    if (gtk_widget_get_visible (ctw))
+    {
+        gtk_window_get_size (GTK_WINDOW (ctw), &width, &height);
+        gtk_window_get_position (GTK_WINDOW (ctw), &x, &y);
+
+        /* X geometry string */
+        geometry = g_strdup_printf ("%ix%i+%i+%i", width, height, x, y);
+        g_object_set (mt_settings_get_default (), "ctw-geometry", geometry, NULL);
+        g_free (geometry);
+    }
+}
diff --git a/src/mt-ctw.h b/src/mt-ctw.h
index 35029f4..027a849 100644
--- a/src/mt-ctw.h
+++ b/src/mt-ctw.h
@@ -20,14 +20,18 @@
 #ifndef __MT_CTW_H__
 #define __MT_CTW_H__
 
+#include <gtk/gtk.h>
+
 G_BEGIN_DECLS
 
-gboolean        mt_ctw_init               (gint x, gint y);
+gboolean        mt_ctw_init               (void);
 
 void            mt_ctw_fini               (void);
 
 GtkWidget *     mt_ctw_get_window         (void);
 
+void            mt_ctw_save_geometry      (void);
+
 G_END_DECLS
 
 #endif /* __MT_CTW_H__ */
diff --git a/src/mt-main.c b/src/mt-main.c
index 3fbf6a0..e4bb077 100644
--- a/src/mt-main.c
+++ b/src/mt-main.c
@@ -49,8 +49,7 @@ typedef struct _MtCliArgs
     gdouble  ssc_time;
     gdouble  dwell_time;
     gchar   *mode;
-    gint     pos_x;
-    gint     pos_y;
+    gchar   *geometry;
     gint     threshold;
     gboolean ssc_enabled;
     gboolean dwell_enabled;
@@ -542,6 +541,7 @@ mt_main_sig_handler (MtSigHandler *sigh,
                      gint          signal_id,
                      gpointer      data)
 {
+    mt_ctw_save_geometry ();
     signal_handler (signal_id);
 }
 
@@ -599,9 +599,9 @@ mt_parse_options (int *argc, char ***argv)
     GOptionEntry entries[] =
     {
         {"dwell", 0, 0, G_OPTION_ARG_NONE, &ca.dwell_enabled,
-            N_("Enable dwell click"), 0},
+            N_("Enable dwell click"), NULL},
         {"ssc", 0, 0, G_OPTION_ARG_NONE, &ca.ssc_enabled,
-            N_("Enable simulated secondary click"), 0},
+            N_("Enable simulated secondary click"), NULL},
         {"dwell-time", 0, 0, G_OPTION_ARG_DOUBLE, &ca.dwell_time,
             N_("Time to wait before a dwell click"), "[0.2-3.0]"},
         {"ssc-time", 0, 0, G_OPTION_ARG_DOUBLE, &ca.ssc_time,
@@ -609,19 +609,17 @@ mt_parse_options (int *argc, char ***argv)
         {"dwell-mode", 'm', 0, G_OPTION_ARG_STRING, &ca.mode,
             N_("Set the active dwell mode"), "[window|gesture]"},
         {"show-ctw", 'c', 0, G_OPTION_ARG_NONE, &ca.ctw,
-            N_("Show a click-type window"), 0},
-        {"ctw-x", 'x', 0, G_OPTION_ARG_INT, &ca.pos_x,
-            N_("Click-type window X position"), 0},
-        {"ctw-y", 'y', 0, G_OPTION_ARG_INT, &ca.pos_y,
-            N_("Click-type window Y position"), 0},
+            N_("Show a click-type window"), NULL},
         {"threshold", 't', 0, G_OPTION_ARG_INT, &ca.threshold,
             N_("Ignore small pointer movements"), "[0-30]"},
+        {"geometry", 'g', 0, G_OPTION_ARG_STRING, &ca.geometry,
+            N_("Click-type window geometry"), "WIDTHxHEIGHT+X+Y"},
         {"shutdown", 's', 0, G_OPTION_ARG_NONE, &ca.shutdown,
-            N_("Shut down mousetweaks"), 0},
+            N_("Shut down mousetweaks"), NULL},
         {"daemonize", 0, 0, G_OPTION_ARG_NONE, &ca.daemonize,
-            N_("Start mousetweaks as a daemon"), 0},
+            N_("Start mousetweaks as a daemon"), NULL},
         {"login", 0, 0, G_OPTION_ARG_NONE, &ca.login,
-            N_("Start mousetweaks in login mode"), 0},
+            N_("Start mousetweaks in login mode"), NULL},
         { NULL }
     };
 
@@ -629,8 +627,7 @@ mt_parse_options (int *argc, char ***argv)
     ca.ssc_time      = -1.;
     ca.dwell_time    = -1.;
     ca.mode          = NULL;
-    ca.pos_x         = -1;
-    ca.pos_y         = -1;
+    ca.geometry      = NULL;
     ca.threshold     = -1;
     ca.ssc_enabled   = FALSE;
     ca.dwell_enabled = FALSE;
@@ -724,9 +721,14 @@ mt_main (int argc, char **argv, MtCliArgs cli_args)
 
         g_free (cli_args.mode);
     }
+    if (cli_args.geometry)
+    {
+        g_free (ms->ctw_geometry);
+        ms->ctw_geometry = cli_args.geometry;
+    }
 
     /* init click-type window */
-    if (!mt_ctw_init (cli_args.pos_x, cli_args.pos_y))
+    if (!mt_ctw_init ())
         goto CLEANUP;
 
     /* init cursor animation */
diff --git a/src/mt-settings.c b/src/mt-settings.c
index ce74bd5..3d37d31 100644
--- a/src/mt-settings.c
+++ b/src/mt-settings.c
@@ -37,7 +37,8 @@ enum
     PROP_SSC_ENABLED,
     PROP_CTW_VISIBLE,
     PROP_CTW_STYLE,
-    PROP_CTW_ORIENTATION
+    PROP_CTW_ORIENTATION,
+    PROP_CTW_GEOMETRY
 };
 
 G_DEFINE_TYPE (MtSettings, mt_settings, G_TYPE_OBJECT)
@@ -46,9 +47,11 @@ static void
 mt_settings_init (MtSettings *ms)
 {
     ms->mt_settings = g_settings_new (MOUSETWEAKS_SCHEMA_ID);
+    ms->ctw_geometry = NULL;
 
     BIND_PROP (ms->mt_settings, "ctw-style", KEY_CTW_STYLE);
     BIND_PROP (ms->mt_settings, "ctw-orientation", KEY_CTW_ORIENTATION);
+    BIND_PROP (ms->mt_settings, "ctw-geometry", KEY_CTW_GEOMETRY);
 
     ms->a11y_settings = g_settings_new (A11Y_MOUSE_SCHEMA_ID);
 
@@ -84,6 +87,16 @@ mt_settings_dispose (GObject *object)
 }
 
 static void
+mt_settings_finalize (GObject *object)
+{
+    MtSettings *ms = MT_SETTINGS (object);
+
+    g_free (ms->ctw_geometry);
+
+    G_OBJECT_CLASS (mt_settings_parent_class)->finalize (object);
+}
+
+static void
 mt_settings_set_property (GObject      *object,
                           guint         prop_id,
                           const GValue *value,
@@ -126,6 +139,10 @@ mt_settings_set_property (GObject      *object,
         case PROP_CTW_ORIENTATION:
             ms->ctw_orientation = g_value_get_enum (value);
             break;
+        case PROP_CTW_GEOMETRY:
+            g_free (ms->ctw_geometry);
+            ms->ctw_geometry = g_value_dup_string (value);
+            break;
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -174,6 +191,9 @@ mt_settings_get_property (GObject    *object,
         case PROP_CTW_ORIENTATION:
             g_value_set_enum (value, ms->ctw_orientation);
             break;
+        case PROP_CTW_GEOMETRY:
+            g_value_set_string (value, ms->ctw_geometry);
+            break;
         default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
     }
@@ -188,6 +208,7 @@ mt_settings_class_init (MtSettingsClass *klass)
     object_class->set_property = mt_settings_set_property;
     object_class->get_property = mt_settings_get_property;
     object_class->dispose = mt_settings_dispose;
+    object_class->finalize = mt_settings_finalize;
 
     g_object_class_install_property (object_class,
                                      PROP_DWELL_ENABLED,
@@ -269,6 +290,12 @@ mt_settings_class_init (MtSettingsClass *klass)
                                                         MT_TYPE_CLICK_TYPE_WINDOW_ORIENTATION,
                                                         MT_CLICK_TYPE_WINDOW_ORIENTATION_HORIZONTAL,
                                                         PFLAGS));
+    g_object_class_install_property (object_class,
+                                     PROP_CTW_GEOMETRY,
+                                     g_param_spec_string ("ctw-geometry",
+                                                          "Click-type window geometry",
+                                                          "Size and position of the click-type window",
+                                                          NULL, PFLAGS));
 }
 
 MtSettings *
diff --git a/src/mt-settings.h b/src/mt-settings.h
index 38c3d2b..10b09b7 100644
--- a/src/mt-settings.h
+++ b/src/mt-settings.h
@@ -49,10 +49,11 @@ struct _MtSettings
 
     MtClickTypeWindowStyle          ctw_style;
     MtClickTypeWindowOrientation    ctw_orientation;
+    gchar                          *ctw_geometry;
 
+    guint                           ctw_visible    : 1;
     guint                           dwell_enabled  : 1;
     guint                           ssc_enabled    : 1;
-    guint                           ctw_visible    : 1;
 };
 
 GType             mt_settings_get_type              (void) G_GNUC_CONST;



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