[Xfce4-commits] [apps/mousepad] 01/09: Implement more saving/restoring window state
noreply at xfce.org
noreply at xfce.org
Sun Jul 13 05:10:19 CEST 2014
This is an automated email from the git hooks/post-receive script.
mbrush pushed a commit to branch master
in repository apps/mousepad.
commit ea2b28e09dd8477af5a5a238c58bf42944a6f8a4
Author: Matthew Brush <mbrush at codebrainz.ca>
Date: Sat Jul 12 16:34:09 2014 -0700
Implement more saving/restoring window state
Before it only saved the size and whether the window was fullscreen.
Add default-off option to enable saving and restoring the window
position and window state (maximized, fullscreen).
---
mousepad/mousepad-prefs-dialog.c | 8 +-
mousepad/mousepad-prefs-dialog.glade | 148 +++++++++++++++++++-------------
mousepad/mousepad-settings.h | 7 +-
mousepad/mousepad-window.c | 123 +++++++++++++++++++++-----
mousepad/org.xfce.mousepad.gschema.xml | 40 ++++++++-
5 files changed, 240 insertions(+), 86 deletions(-)
diff --git a/mousepad/mousepad-prefs-dialog.c b/mousepad/mousepad-prefs-dialog.c
index 8ea7a10..19fa080 100644
--- a/mousepad/mousepad-prefs-dialog.c
+++ b/mousepad/mousepad-prefs-dialog.c
@@ -31,7 +31,9 @@
/* Window page */
#define WID_STATUSBAR_VISIBLE_CHECK "/prefs/window/general/show-statusbar-check"
#define WID_PATH_IN_TITLE_CHECK "/prefs/window/general/show-path-in-title-check"
-#define WID_REMEMBER_GEOMETRY_CHECK "/prefs/window/general/remember-window-size-check"
+#define WID_REMEMBER_SIZE_CHECK "/prefs/window/general/remember-window-size-check"
+#define WID_REMEMBER_POSITION_CHECK "/prefs/window/general/remember-window-position-check"
+#define WID_REMEMBER_STATE_CHECK "/prefs/window/general/remember-window-state-check"
#define WID_ALWAYS_SHOW_TABS_CHECK "/prefs/window/notebook/always-show-tabs-check"
#define WID_CYCLE_TABS_CHECK "/prefs/window/notebook/cycle-tabs-check"
#define WID_TOOLBAR_VISIBLE_CHECK "/prefs/window/toolbar/visible-check"
@@ -479,7 +481,9 @@ mousepad_prefs_dialog_init (MousepadPrefsDialog *self)
/* Window */
BIND_CHECKBOX (STATUSBAR_VISIBLE);
BIND_CHECKBOX (PATH_IN_TITLE);
- BIND_CHECKBOX (REMEMBER_GEOMETRY);
+ BIND_CHECKBOX (REMEMBER_SIZE);
+ BIND_CHECKBOX (REMEMBER_POSITION);
+ BIND_CHECKBOX (REMEMBER_STATE);
BIND_CHECKBOX (ALWAYS_SHOW_TABS);
BIND_CHECKBOX (CYCLE_TABS);
BIND_CHECKBOX (TOOLBAR_VISIBLE);
diff --git a/mousepad/mousepad-prefs-dialog.glade b/mousepad/mousepad-prefs-dialog.glade
index 2f952ee..6d05328 100644
--- a/mousepad/mousepad-prefs-dialog.glade
+++ b/mousepad/mousepad-prefs-dialog.glade
@@ -67,6 +67,66 @@
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
+ <object class="GtkListStore" id="/prefs/window/toolbar/icon-size-model">
+ <columns>
+ <!-- column-name size -->
+ <column type="GtkIconSize"/>
+ <!-- column-name name -->
+ <column type="gchararray"/>
+ </columns>
+ <data>
+ <row>
+ <col id="0">menu</col>
+ <col id="1" translatable="yes">Menu</col>
+ </row>
+ <row>
+ <col id="0">small-toolbar</col>
+ <col id="1" translatable="yes">Small Toolbar</col>
+ </row>
+ <row>
+ <col id="0">large-toolbar</col>
+ <col id="1" translatable="yes">Large Toolbar</col>
+ </row>
+ <row>
+ <col id="0">button</col>
+ <col id="1" translatable="yes">Button</col>
+ </row>
+ <row>
+ <col id="0">dnd</col>
+ <col id="1" translatable="yes">Drag & Drop</col>
+ </row>
+ <row>
+ <col id="0">dialog</col>
+ <col id="1" translatable="yes">Dialog</col>
+ </row>
+ </data>
+ </object>
+ <object class="GtkListStore" id="/prefs/window/toolbar/style-model">
+ <columns>
+ <!-- column-name style -->
+ <column type="GtkToolbarStyle"/>
+ <!-- column-name name -->
+ <column type="gchararray"/>
+ </columns>
+ <data>
+ <row>
+ <col id="0">icons</col>
+ <col id="1" translatable="yes">Icons Only</col>
+ </row>
+ <row>
+ <col id="0">text</col>
+ <col id="1" translatable="yes">Text Only</col>
+ </row>
+ <row>
+ <col id="0">both</col>
+ <col id="1" translatable="yes">Text Below Icons</col>
+ </row>
+ <row>
+ <col id="0">both-horiz</col>
+ <col id="1" translatable="yes">Text Beside Icons</col>
+ </row>
+ </data>
+ </object>
<object class="GtkNotebook" id="/prefs/main-notebook">
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -659,6 +719,34 @@
<property name="position">2</property>
</packing>
</child>
+ <child>
+ <object class="GtkCheckButton" id="/prefs/window/general/remember-window-position-check">
+ <property name="label" translatable="yes">Remember window position</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="/prefs/window/general/remember-window-state-check">
+ <property name="label" translatable="yes">Remember window state</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">4</property>
+ </packing>
+ </child>
</object>
</child>
</object>
@@ -883,64 +971,4 @@
</packing>
</child>
</object>
- <object class="GtkListStore" id="/prefs/window/toolbar/icon-size-model">
- <columns>
- <!-- column-name size -->
- <column type="GtkIconSize"/>
- <!-- column-name name -->
- <column type="gchararray"/>
- </columns>
- <data>
- <row>
- <col id="0">menu</col>
- <col id="1" translatable="yes">Menu</col>
- </row>
- <row>
- <col id="0">small-toolbar</col>
- <col id="1" translatable="yes">Small Toolbar</col>
- </row>
- <row>
- <col id="0">large-toolbar</col>
- <col id="1" translatable="yes">Large Toolbar</col>
- </row>
- <row>
- <col id="0">button</col>
- <col id="1" translatable="yes">Button</col>
- </row>
- <row>
- <col id="0">dnd</col>
- <col id="1" translatable="yes">Drag & Drop</col>
- </row>
- <row>
- <col id="0">dialog</col>
- <col id="1" translatable="yes">Dialog</col>
- </row>
- </data>
- </object>
- <object class="GtkListStore" id="/prefs/window/toolbar/style-model">
- <columns>
- <!-- column-name style -->
- <column type="GtkToolbarStyle"/>
- <!-- column-name name -->
- <column type="gchararray"/>
- </columns>
- <data>
- <row>
- <col id="0">icons</col>
- <col id="1" translatable="yes">Icons Only</col>
- </row>
- <row>
- <col id="0">text</col>
- <col id="1" translatable="yes">Text Only</col>
- </row>
- <row>
- <col id="0">both</col>
- <col id="1" translatable="yes">Text Below Icons</col>
- </row>
- <row>
- <col id="0">both-horiz</col>
- <col id="1" translatable="yes">Text Beside Icons</col>
- </row>
- </data>
- </object>
</interface>
diff --git a/mousepad/mousepad-settings.h b/mousepad/mousepad-settings.h
index c919a66..152cb02 100644
--- a/mousepad/mousepad-settings.h
+++ b/mousepad/mousepad-settings.h
@@ -34,7 +34,9 @@ G_BEGIN_DECLS
#define MOUSEPAD_SETTING_DEFAULT_TAB_SIZES "/preferences/window/default-tab-sizes"
#define MOUSEPAD_SETTING_PATH_IN_TITLE "/preferences/window/path-in-title"
#define MOUSEPAD_SETTING_RECENT_MENU_ITEMS "/preferences/window/recent-menu-items"
-#define MOUSEPAD_SETTING_REMEMBER_GEOMETRY "/preferences/window/remember-geometry"
+#define MOUSEPAD_SETTING_REMEMBER_SIZE "/preferences/window/remember-size"
+#define MOUSEPAD_SETTING_REMEMBER_POSITION "/preferences/window/remember-position"
+#define MOUSEPAD_SETTING_REMEMBER_STATE "/preferences/window/remember-state"
/* State setting names */
#define MOUSEPAD_SETTING_SEARCH_DIRECTION "/state/search/direction"
@@ -44,6 +46,9 @@ G_BEGIN_DECLS
#define MOUSEPAD_SETTING_SEARCH_REPLACE_ALL_LOCATION "/state/search/replace-all-location"
#define MOUSEPAD_SETTING_WINDOW_HEIGHT "/state/window/height"
#define MOUSEPAD_SETTING_WINDOW_WIDTH "/state/window/width"
+#define MOUSEPAD_SETTING_WINDOW_TOP "/state/window/top"
+#define MOUSEPAD_SETTING_WINDOW_LEFT "/state/window/left"
+#define MOUSEPAD_SETTING_WINDOW_MAXIMIZED "/state/window/maximized"
#define MOUSEPAD_SETTING_WINDOW_FULLSCREEN "/state/window/fullscreen"
void mousepad_settings_init (void);
diff --git a/mousepad/mousepad-window.c b/mousepad/mousepad-window.c
index 231d052..21cc878 100644
--- a/mousepad/mousepad-window.c
+++ b/mousepad/mousepad-window.c
@@ -623,6 +623,58 @@ mousepad_window_update_toolbar (MousepadWindow *window,
}
+
+static void
+mousepad_window_restore (MousepadWindow *window)
+{
+ gboolean remember_size, remember_position, remember_state;
+
+ remember_size = MOUSEPAD_SETTING_GET_BOOLEAN (REMEMBER_SIZE);
+ remember_position = MOUSEPAD_SETTING_GET_BOOLEAN (REMEMBER_POSITION);
+ remember_state = MOUSEPAD_SETTING_GET_BOOLEAN (REMEMBER_STATE);
+
+ /* first restore size */
+ if (remember_size)
+ {
+ gint width, height;
+
+ width = MOUSEPAD_SETTING_GET_INT (WINDOW_WIDTH);
+ height = MOUSEPAD_SETTING_GET_INT (WINDOW_HEIGHT);
+
+ gtk_window_set_default_size (GTK_WINDOW (window), width, height);
+ }
+
+ /* then restore position */
+ if (remember_position)
+ {
+ gint left, top;
+
+ left = MOUSEPAD_SETTING_GET_INT (WINDOW_LEFT);
+ top = MOUSEPAD_SETTING_GET_INT (WINDOW_TOP);
+
+ gtk_window_move (GTK_WINDOW (window), left, top);
+ }
+
+ /* finally restore window state */
+ if (remember_state)
+ {
+ gboolean maximized, fullscreen;
+
+ maximized = MOUSEPAD_SETTING_GET_BOOLEAN (WINDOW_MAXIMIZED);
+ fullscreen = MOUSEPAD_SETTING_GET_BOOLEAN (WINDOW_FULLSCREEN);
+
+ /* first restore if it was maximized */
+ if (maximized)
+ gtk_window_maximize (GTK_WINDOW (window));
+
+ /* then restore if it was fullscreen */
+ if (fullscreen)
+ gtk_window_fullscreen (GTK_WINDOW (window));
+ }
+}
+
+
+
static void
mousepad_window_init (MousepadWindow *window)
{
@@ -633,7 +685,6 @@ mousepad_window_init (MousepadWindow *window)
GtkWidget *ebox;
GtkWidget *item;
GtkAction *action;
- gint width, height;
gboolean active;
/* initialize stuff */
@@ -664,12 +715,8 @@ mousepad_window_init (MousepadWindow *window)
g_closure_ref (window->menu_item_deselected_closure);
g_closure_sink (window->menu_item_deselected_closure);
- /* read settings from the preferences */
- width = MOUSEPAD_SETTING_GET_INT (WINDOW_WIDTH);
- height = MOUSEPAD_SETTING_GET_INT (WINDOW_HEIGHT);
-
- /* set the default window size */
- gtk_window_set_default_size (GTK_WINDOW (window), width, height);
+ /* restore window settings */
+ mousepad_window_restore (window);
/* the action group for this window */
window->action_group = gtk_action_group_new ("MousepadWindow");
@@ -903,7 +950,10 @@ mousepad_window_configure_event (GtkWidget *widget,
MousepadWindow *window = MOUSEPAD_WINDOW (widget);
/* check if we have a new dimension here */
- if (widget->allocation.width != event->width || widget->allocation.height != event->height)
+ if (widget->allocation.width != event->width ||
+ widget->allocation.height != event->height ||
+ widget->allocation.x != event->x ||
+ widget->allocation.y != event->y)
{
/* drop any previous timer source */
if (window->save_geometry_timer_id > 0)
@@ -1029,16 +1079,16 @@ mousepad_window_save_geometry_timer (gpointer user_data)
{
GdkWindowState state;
MousepadWindow *window = MOUSEPAD_WINDOW (user_data);
- gboolean remember_geometry;
- gint width;
- gint height;
+ gboolean remember_size, remember_position, remember_state;
GDK_THREADS_ENTER ();
/* check if we should remember the window geometry */
- remember_geometry = MOUSEPAD_SETTING_GET_BOOLEAN (REMEMBER_GEOMETRY);
+ remember_size = MOUSEPAD_SETTING_GET_BOOLEAN (REMEMBER_SIZE);
+ remember_position = MOUSEPAD_SETTING_GET_BOOLEAN (REMEMBER_POSITION);
+ remember_state = MOUSEPAD_SETTING_GET_BOOLEAN (REMEMBER_STATE);
- if (G_LIKELY (remember_geometry))
+ if (remember_size || remember_position || remember_state)
{
/* check if the window is still visible */
if (gtk_widget_get_visible (GTK_WIDGET(window)))
@@ -1049,12 +1099,36 @@ mousepad_window_save_geometry_timer (gpointer user_data)
/* don't save geometry for maximized or fullscreen windows */
if ((state & (GDK_WINDOW_STATE_MAXIMIZED | GDK_WINDOW_STATE_FULLSCREEN)) == 0)
{
- /* determine the current width/height of the window... */
- gtk_window_get_size (GTK_WINDOW (window), &width, &height);
+ if (remember_size)
+ {
+ gint width, height;
+
+ /* determine the current width/height of the window... */
+ gtk_window_get_size (GTK_WINDOW (window), &width, &height);
+
+ /* ...and remember them as default for new windows */
+ MOUSEPAD_SETTING_SET_INT (WINDOW_WIDTH, width);
+ MOUSEPAD_SETTING_SET_INT (WINDOW_HEIGHT, height);
+ }
- /* ...and remember them as default for new windows */
- MOUSEPAD_SETTING_SET_INT (WINDOW_WIDTH, width);
- MOUSEPAD_SETTING_SET_INT (WINDOW_HEIGHT, height);
+ if (remember_position)
+ {
+ gint left, top;
+
+ /* determine the current left/top position of the window */
+ gtk_window_get_position (GTK_WINDOW (window), &left, &top);
+
+ /* and then remember it for next startup */
+ MOUSEPAD_SETTING_SET_INT (WINDOW_LEFT, left);
+ MOUSEPAD_SETTING_SET_INT (WINDOW_TOP, top);
+ }
+ }
+
+ if (remember_state)
+ {
+ /* remember whether the window is maximized or full screen or not */
+ MOUSEPAD_SETTING_SET_BOOLEAN (WINDOW_MAXIMIZED, (state & GDK_WINDOW_STATE_MAXIMIZED));
+ MOUSEPAD_SETTING_SET_BOOLEAN (WINDOW_FULLSCREEN, (state & GDK_WINDOW_STATE_FULLSCREEN));
}
}
}
@@ -4942,17 +5016,24 @@ static void
mousepad_window_action_fullscreen (GtkToggleAction *action,
MousepadWindow *window)
{
- gboolean fullscreen;
+ gboolean fullscreen;
+ GdkWindow *gdk_window;
+ GdkWindowState state;
+
+ if (! gtk_widget_get_visible (GTK_WIDGET (window)))
+ return;
fullscreen = MOUSEPAD_SETTING_GET_BOOLEAN (WINDOW_FULLSCREEN);
+ gdk_window = gtk_widget_get_window (GTK_WIDGET (window));
+ state = gdk_window_get_state (gdk_window);
- if (fullscreen)
+ if (fullscreen && !(state & GDK_WINDOW_STATE_FULLSCREEN))
{
gtk_window_fullscreen (GTK_WINDOW (window));
gtk_action_set_stock_id (GTK_ACTION (action), GTK_STOCK_LEAVE_FULLSCREEN);
gtk_action_set_tooltip (GTK_ACTION (action), _("Leave fullscreen mode"));
}
- else
+ else if (state & GDK_WINDOW_STATE_FULLSCREEN)
{
gtk_window_unfullscreen (GTK_WINDOW (window));
gtk_action_set_stock_id (GTK_ACTION (action), GTK_STOCK_FULLSCREEN);
diff --git a/mousepad/org.xfce.mousepad.gschema.xml b/mousepad/org.xfce.mousepad.gschema.xml
index 2275b40..055e087 100644
--- a/mousepad/org.xfce.mousepad.gschema.xml
+++ b/mousepad/org.xfce.mousepad.gschema.xml
@@ -254,13 +254,34 @@
The number of recent documents to track and show in the user interace.
</description>
</key>
- <key name="remember-geometry" type="b">
+ <key name="remember-size" type="b">
<default>true</default>
- <summary>Remember window geometry</summary>
+ <summary>Remember window size</summary>
<description>
When true the size of the window will be saved and restored.
</description>
</key>
+ <key name="remember-position" type="b">
+ <default>false</default>
+ <summary>Remember window position</summary>
+ <description>
+ When true will attempt to save and restore the position of the window
+ when false it won't. Note that window placement is supposed to be the
+ job of the Window Manager and that there's no guarantee the restored
+ window position will be respected, accurate, or even visible on any
+ screen.
+ </description>
+ </key>
+ <key name="remember-state" type="b">
+ <default>true</default>
+ <summary>Remember window state</summary>
+ <description>
+ When true will attempt to save and restore the windows state (ex.
+ normal, maximized, fullscreen, etc, when false it will not. Your
+ Window Manager may very well not report when retrieving or not respect
+ it when setting.
+ </description>
+ </key>
</schema>
<!-- search state -->
@@ -323,6 +344,21 @@
<summary>window width</summary>
<description>The width of windows in pixels.</description>
</key>
+ <key name="top" type="i">
+ <default>-1</default>
+ <summary>window top</summary>
+ <description>The Y coordinate of the window's position</description>
+ </key>
+ <key name="left" type="i">
+ <default>-1</default>
+ <summary>window left</summary>
+ <description>The X coordinate of the window's position</description>
+ </key>
+ <key name="maximized" type="b">
+ <default>false</default>
+ <summary>window maximized</summary>
+ <description>Whether the window is maximized or not.</description>
+ </key>
<key name="fullscreen" type="b">
<default>false</default>
<summary>window fullscreen</summary>
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list