[epiphany] Take care of maximize and fullscreen window states
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] Take care of maximize and fullscreen window states
- Date: Mon, 17 Feb 2020 23:09:01 +0000 (UTC)
commit 0cba9cac2afc10ce4d43b551a06d1b784beaff61
Author: Jan-Michael Brummer <jan brummer tabos org>
Date: Sat Feb 15 13:12:48 2020 +0100
Take care of maximize and fullscreen window states
Fixes: https://gitlab.gnome.org/GNOME/epiphany/issues/1091
src/ephy-session.c | 61 +++++++++++++++++++++++++++++++++++++-------------
src/ephy-window.c | 65 +++++++++++++++++++++++++++++++-----------------------
src/ephy-window.h | 7 ++++++
3 files changed, 90 insertions(+), 43 deletions(-)
---
diff --git a/src/ephy-session.c b/src/ephy-session.c
index 9f1b5ac2c..432ac6866 100644
--- a/src/ephy-session.c
+++ b/src/ephy-session.c
@@ -536,12 +536,24 @@ ephy_session_close (EphySession *session)
session->dont_save = TRUE;
}
+typedef struct {
+ GdkRectangle geometry;
+ gboolean is_maximized;
+ gboolean is_fullscreen;
+ char *role;
+
+ GList *tabs;
+ gint active_tab;
+} SessionWindow;
+
static void
-get_window_geometry (GtkWindow *window,
- GdkRectangle *rectangle)
+get_window_geometry (EphyWindow *window,
+ SessionWindow *session_window)
{
- gtk_window_get_size (window, &rectangle->width, &rectangle->height);
- gtk_window_get_position (window, &rectangle->x, &rectangle->y);
+ session_window->is_maximized = ephy_window_is_maximized (window);
+ session_window->is_fullscreen = ephy_window_is_fullscreen (window);
+
+ ephy_window_get_geometry (window, &session_window->geometry);
}
typedef struct {
@@ -600,14 +612,6 @@ session_tab_free (SessionTab *tab)
g_free (tab);
}
-typedef struct {
- GdkRectangle geometry;
- char *role;
-
- GList *tabs;
- gint active_tab;
-} SessionWindow;
-
static SessionWindow *
session_window_new (EphyWindow *window,
EphySession *session)
@@ -625,7 +629,7 @@ session_window_new (EphyWindow *window,
}
session_window = g_new0 (SessionWindow, 1);
- get_window_geometry (GTK_WINDOW (window), &session_window->geometry);
+ get_window_geometry (window, session_window);
session_window->role = g_strdup (gtk_window_get_role (GTK_WINDOW (window)));
notebook = GTK_NOTEBOOK (ephy_window_get_notebook (window));
@@ -760,7 +764,9 @@ write_tab (xmlTextWriterPtr writer,
static int
write_window_geometry (xmlTextWriterPtr writer,
- GdkRectangle *geometry)
+ GdkRectangle *geometry,
+ gboolean is_maximized,
+ gboolean is_fullscreen)
{
int ret;
@@ -782,6 +788,17 @@ write_window_geometry (xmlTextWriterPtr writer,
ret = xmlTextWriterWriteFormatAttribute (writer, (const xmlChar *)"height", "%d",
geometry->height);
+ if (ret < 0)
+ return ret;
+
+ ret = xmlTextWriterWriteFormatAttribute (writer, (const xmlChar *)"is-maximized", "%d",
+ is_maximized);
+ if (ret < 0)
+ return ret;
+
+ ret = xmlTextWriterWriteFormatAttribute (writer, (const xmlChar *)"is-fullscreen", "%d",
+ is_fullscreen);
+
return ret;
}
@@ -796,7 +813,7 @@ write_ephy_window (xmlTextWriterPtr writer,
if (ret < 0)
return ret;
- ret = write_window_geometry (writer, &window->geometry);
+ ret = write_window_geometry (writer, &window->geometry, window->is_maximized, window->is_fullscreen);
if (ret < 0)
return ret;
@@ -1115,6 +1132,8 @@ session_parse_window (SessionParserContext *context,
const gchar **values)
{
GdkRectangle geometry = { -1, -1, 0, 0 };
+ gboolean is_maximized = FALSE;
+ gboolean is_fullscreen = FALSE;
guint i;
if (context->window) {
@@ -1140,6 +1159,12 @@ session_parse_window (SessionParserContext *context,
} else if (strcmp (names[i], "height") == 0) {
ephy_string_to_int (values[i], &int_value);
geometry.height = int_value;
+ } else if (strcmp (names[i], "is-maximized") == 0) {
+ ephy_string_to_int (values[i], &int_value);
+ is_maximized = int_value != 0;
+ } else if (strcmp (names[i], "is-fullscreen") == 0) {
+ ephy_string_to_int (values[i], &int_value);
+ is_fullscreen = int_value != 0;
} else if (strcmp (names[i], "role") == 0) {
gtk_window_set_role (GTK_WINDOW (context->window), values[i]);
} else if (strcmp (names[i], "active-tab") == 0) {
@@ -1149,6 +1174,12 @@ session_parse_window (SessionParserContext *context,
}
restore_geometry (GTK_WINDOW (context->window), &geometry);
+
+ if (is_maximized)
+ gtk_window_maximize (GTK_WINDOW (context->window));
+
+ if (is_fullscreen)
+ gtk_window_fullscreen (GTK_WINDOW (context->window));
}
static void
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 6c667f91e..c45d6fd0e 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -3197,33 +3197,6 @@ ephy_window_get_property (GObject *object,
}
}
-static gboolean
-ephy_window_configure_event (GtkWidget *widget,
- GdkEventConfigure *event)
-{
- EphyWindow *window = EPHY_WINDOW (widget);
- gboolean result;
- gint width, height;
-
- result = GTK_WIDGET_CLASS (ephy_window_parent_class)->configure_event (widget, event);
-
- gtk_window_get_size (GTK_WINDOW (widget),
- &width,
- &height);
-
- if (!window->is_maximized && !window->is_fullscreen) {
- gtk_window_get_position (GTK_WINDOW (widget),
- &window->current_x,
- &window->current_y);
- window->current_width = width;
- window->current_height = height;
- }
-
- update_adaptive_mode (window);
-
- return result;
-}
-
static gboolean
ephy_window_state_event (GtkWidget *widget,
GdkEventWindowState *event)
@@ -3636,6 +3609,20 @@ download_completed_cb (EphyDownload *download,
g_application_quit (G_APPLICATION (shell));
}
+static void
+ephy_window_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ EphyWindow *window = EPHY_WINDOW (widget);
+
+ GTK_WIDGET_CLASS (ephy_window_parent_class)->size_allocate (widget, allocation);
+
+ if (!(window->is_maximized || window->is_fullscreen))
+ gtk_window_get_size (GTK_WINDOW (widget), &window->current_width, &window->current_height);
+
+ update_adaptive_mode (window);
+}
+
static void
ephy_window_constructed (GObject *object)
{
@@ -3853,11 +3840,11 @@ 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->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;
widget_class->delete_event = ephy_window_delete_event;
+ widget_class->size_allocate = ephy_window_size_allocate;
g_object_class_override_property (object_class,
PROP_ACTIVE_CHILD,
@@ -4333,3 +4320,25 @@ ephy_window_get_position_for_new_embed (EphyWindow *window,
return position;
}
+
+gboolean
+ephy_window_is_maximized (EphyWindow *window)
+{
+ return window->is_maximized;
+}
+
+gboolean
+ephy_window_is_fullscreen (EphyWindow *window)
+{
+ return window->is_fullscreen;
+}
+
+void
+ephy_window_get_geometry (EphyWindow *window,
+ GdkRectangle *rectangle)
+{
+ rectangle->x = window->current_x;
+ rectangle->y = window->current_y;
+ rectangle->width = window->current_width;
+ rectangle->height = window->current_height;
+}
diff --git a/src/ephy-window.h b/src/ephy-window.h
index 32cab7595..3e92c7f94 100644
--- a/src/ephy-window.h
+++ b/src/ephy-window.h
@@ -87,4 +87,11 @@ int ephy_window_get_position_for_new_embed (EphyWindow *window,
void ephy_window_update_entry_focus (EphyWindow *window,
EphyWebView *view);
+gboolean ephy_window_is_maximized (EphyWindow *window);
+
+gboolean ephy_window_is_fullscreen (EphyWindow *window);
+
+void ephy_window_get_geometry (EphyWindow *window,
+ GdkRectangle *rectangle);
+
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]