[epiphany] Also save the window position in gsettings
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] Also save the window position in gsettings
- Date: Tue, 31 Jan 2017 16:08:55 +0000 (UTC)
commit aff4396245565d11fb588aa68504515ff6c0585a
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Tue Jan 31 14:28:23 2017 +0100
Also save the window position in gsettings
data/org.gnome.epiphany.gschema.xml | 5 ++
src/ephy-session.c | 8 +--
src/ephy-window.c | 80 ++++++++++++++++++++++++++--------
src/ephy-window.h | 3 +
4 files changed, 72 insertions(+), 24 deletions(-)
---
diff --git a/data/org.gnome.epiphany.gschema.xml b/data/org.gnome.epiphany.gschema.xml
index b99017e..6654dad 100644
--- a/data/org.gnome.epiphany.gschema.xml
+++ b/data/org.gnome.epiphany.gschema.xml
@@ -200,6 +200,11 @@
<key type="as" name="recent-encodings">
<default>['' ]</default>
</key>
+ <key type="(ii)" name="window-position">
+ <default>(-1, -1)</default>
+ <summary>Window position</summary>
+ <description>The position to use for a new window that is not restored from a
previous session.</description>
+ </key>
<key type="(ii)" name="window-size">
<default>(-1, -1)</default>
<summary>Window size</summary>
diff --git a/src/ephy-session.c b/src/ephy-session.c
index 08aa66d..b07346f 100644
--- a/src/ephy-session.c
+++ b/src/ephy-session.c
@@ -1025,13 +1025,11 @@ static void
restore_geometry (GtkWindow *window,
GdkRectangle *geometry)
{
- if (geometry->x >= 0 && geometry->y >= 0) {
- gtk_window_move (window, geometry->x, geometry->y);
- }
+ if (geometry->x >= 0 && geometry->y >= 0)
+ ephy_window_set_default_position (EPHY_WINDOW (window), geometry->x, geometry->y);
- if (geometry->width > 0 && geometry->height > 0) {
+ if (geometry->width > 0 && geometry->height > 0)
ephy_window_set_default_size (EPHY_WINDOW (window), geometry->width, geometry->height);
- }
}
typedef struct {
diff --git a/src/ephy-window.c b/src/ephy-window.c
index fd6ccb4..7385f98 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -148,8 +148,11 @@ struct _EphyWindow {
gint current_width;
gint current_height;
+ gint current_x;
+ gint current_y;
guint has_default_size : 1;
+ guint has_default_position : 1;
guint is_maximized : 1;
guint is_fullscreen : 1;
guint closing : 1;
@@ -2684,19 +2687,25 @@ ephy_window_get_property (GObject *object,
}
}
-static void
-ephy_window_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation)
+static gboolean
+ephy_window_configure_event (GtkWidget *widget,
+ GdkEventConfigure *event)
{
EphyWindow *window = EPHY_WINDOW (widget);
+ gboolean result;
- GTK_WIDGET_CLASS (ephy_window_parent_class)->size_allocate (widget, allocation);
+ result = GTK_WIDGET_CLASS (ephy_window_parent_class)->configure_event (widget, event);
if (!window->is_maximized && !window->is_fullscreen) {
+ gtk_window_get_position (GTK_WINDOW (widget),
+ &window->current_x,
+ &window->current_y);
gtk_window_get_size (GTK_WINDOW (widget),
&window->current_width,
&window->current_height);
}
+
+ return result;
}
static gboolean
@@ -2744,28 +2753,57 @@ ephy_window_set_default_size (EphyWindow *window,
window->has_default_size = TRUE;
}
+void
+ephy_window_set_default_position (EphyWindow *window,
+ gint x,
+ gint y)
+{
+ gtk_window_move (GTK_WINDOW (window), x, y);
+ window->has_default_position = TRUE;
+}
+
static void
ephy_window_show (GtkWidget *widget)
{
EphyWindow *window = EPHY_WINDOW (widget);
- if (!window->has_default_size && !window->is_popup) {
- g_settings_get (EPHY_SETTINGS_STATE,
- "window-size", "(ii)",
- &window->current_width,
- &window->current_height);
- window->is_maximized = g_settings_get_boolean (EPHY_SETTINGS_STATE, "is-maximized");
-
- if (window->current_width > 0 && window->current_height > 0) {
- gtk_window_resize (GTK_WINDOW (window),
- window->current_width,
- window->current_height);
+ if (window->is_popup) {
+ GTK_WIDGET_CLASS (ephy_window_parent_class)->show (widget);
+ return;
+ }
+
+ window->is_maximized = g_settings_get_boolean (EPHY_SETTINGS_STATE, "is-maximized");
+ if (window->is_maximized)
+ gtk_window_maximize (GTK_WINDOW (window));
+ else {
+ if (!window->has_default_position) {
+ g_settings_get (EPHY_SETTINGS_STATE,
+ "window-position", "(ii)",
+ &window->current_x,
+ &window->current_y);
+ if (window->current_x >= 0 && window->current_y >= 0) {
+ gtk_window_move (GTK_WINDOW (window),
+ window->current_x,
+ window->current_y);
+ }
+
+ window->has_default_position = TRUE;
}
- if (window->is_maximized)
- gtk_window_maximize (GTK_WINDOW (window));
+ if (!window->has_default_size) {
+ g_settings_get (EPHY_SETTINGS_STATE,
+ "window-size", "(ii)",
+ &window->current_width,
+ &window->current_height);
- window->has_default_size = TRUE;
+ if (window->current_width > 0 && window->current_height > 0) {
+ gtk_window_resize (GTK_WINDOW (window),
+ window->current_width,
+ window->current_height);
+ }
+
+ window->has_default_size = TRUE;
+ }
}
GTK_WIDGET_CLASS (ephy_window_parent_class)->show (widget);
@@ -2781,6 +2819,10 @@ ephy_window_destroy (GtkWidget *widget)
"window-size", "(ii)",
window->current_width,
window->current_height);
+ g_settings_set (EPHY_SETTINGS_STATE,
+ "window-position", "(ii)",
+ window->current_x,
+ window->current_y);
g_settings_set_boolean (EPHY_SETTINGS_STATE, "is-maximized", window->is_maximized);
}
@@ -3110,7 +3152,7 @@ ephy_window_class_init (EphyWindowClass *klass)
object_class->set_property = ephy_window_set_property;
widget_class->key_press_event = ephy_window_key_press_event;
- widget_class->size_allocate = ephy_window_size_allocate;
+ widget_class->configure_event = ephy_window_configure_event;
widget_class->window_state_event = ephy_window_state_event;
widget_class->show = ephy_window_show;
widget_class->destroy = ephy_window_destroy;
diff --git a/src/ephy-window.h b/src/ephy-window.h
index b4e5a6a..1a6feab 100644
--- a/src/ephy-window.h
+++ b/src/ephy-window.h
@@ -74,5 +74,8 @@ void ephy_window_set_location (EphyWindow *window,
void ephy_window_set_default_size (EphyWindow *window,
gint width,
gint height);
+void ephy_window_set_default_position (EphyWindow *window,
+ gint x,
+ gint y);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]