[gnome-builder/wip/gtk4-port: 246/1774] libide/gui: make workspace size saving optional
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port: 246/1774] libide/gui: make workspace size saving optional
- Date: Mon, 11 Jul 2022 22:31:04 +0000 (UTC)
commit ef1e4cea23f2dc4babf4c2b7447089322e8a7f0d
Author: Christian Hergert <chergert redhat com>
Date: Thu Mar 31 00:40:33 2022 -0700
libide/gui: make workspace size saving optional
We already have optional restore, but we should optionally save it too so
that the greeter doesn't override things.
Long term, we'll want to use the shell API for this anyway which would
have a "token" for the window state.
src/libide/greeter/ide-greeter-workspace.c | 1 +
src/libide/gui/ide-workspace.c | 40 +++++++++++++++++++-----------
src/libide/gui/ide-workspace.h | 3 +++
3 files changed, 30 insertions(+), 14 deletions(-)
---
diff --git a/src/libide/greeter/ide-greeter-workspace.c b/src/libide/greeter/ide-greeter-workspace.c
index 1941e4de1..a86fdcde7 100644
--- a/src/libide/greeter/ide-greeter-workspace.c
+++ b/src/libide/greeter/ide-greeter-workspace.c
@@ -673,6 +673,7 @@ ide_greeter_workspace_class_init (IdeGreeterWorkspaceClass *klass)
object_class->set_property = ide_greeter_workspace_set_property;
workspace_class->restore_size = NULL;
+ workspace_class->save_size = NULL;
/**
* IdeGreeterWorkspace:selection-mode:
diff --git a/src/libide/gui/ide-workspace.c b/src/libide/gui/ide-workspace.c
index 53b25dac1..1fa6cf760 100644
--- a/src/libide/gui/ide-workspace.c
+++ b/src/libide/gui/ide-workspace.c
@@ -269,27 +269,25 @@ ide_workspace_save_settings (gpointer data)
{
IdeWorkspace *self = data;
IdeWorkspacePrivate *priv = ide_workspace_get_instance_private (self);
+ GdkRectangle geom = {0};
+ gboolean maximized;
g_assert (IDE_IS_WORKSPACE (self));
priv->queued_window_save = 0;
- if (gtk_widget_get_realized (GTK_WIDGET (self)) &&
- gtk_widget_get_visible (GTK_WIDGET (self)))
- {
- GdkRectangle geom = {0};
- gboolean maximized;
-
- if (settings == NULL)
- settings = g_settings_new ("org.gnome.builder");
+ if (!gtk_widget_get_realized (GTK_WIDGET (self)) ||
+ !gtk_widget_get_visible (GTK_WIDGET (self)) ||
+ !IDE_WORKSPACE_GET_CLASS (self)->save_size (self, &geom.width, &geom.height))
+ return G_SOURCE_REMOVE;
- gtk_window_get_default_size (GTK_WINDOW (self), &geom.width, &geom.height);
+ if (settings == NULL)
+ settings = g_settings_new ("org.gnome.builder");
- maximized = gtk_window_is_maximized (GTK_WINDOW (self));
+ maximized = gtk_window_is_maximized (GTK_WINDOW (self));
- g_settings_set (settings, "window-size", "(ii)", geom.width, geom.height);
- g_settings_set_boolean (settings, "window-maximized", maximized);
- }
+ g_settings_set (settings, "window-size", "(ii)", geom.width, geom.height);
+ g_settings_set_boolean (settings, "window-maximized", maximized);
return G_SOURCE_REMOVE;
}
@@ -307,7 +305,8 @@ ide_workspace_size_allocate (GtkWidget *widget,
GTK_WIDGET_CLASS (ide_workspace_parent_class)->size_allocate (widget, width, height, baseline);
- if (priv->queued_window_save == 0)
+ if (priv->queued_window_save == 0 &&
+ IDE_WORKSPACE_GET_CLASS (self)->save_size != NULL)
priv->queued_window_save = g_timeout_add_seconds (1, ide_workspace_save_settings, self);
}
@@ -321,6 +320,18 @@ ide_workspace_restore_size (IdeWorkspace *workspace,
gtk_window_set_default_size (GTK_WINDOW (workspace), width, height);
}
+static gboolean
+ide_workspace_save_size (IdeWorkspace *workspace,
+ int *width,
+ int *height)
+{
+ g_assert (IDE_IS_WORKSPACE (workspace));
+
+ gtk_window_get_default_size (GTK_WINDOW (workspace), width, height);
+
+ return TRUE;
+}
+
static void
ide_workspace_realize (GtkWidget *widget)
{
@@ -412,6 +423,7 @@ ide_workspace_class_init (IdeWorkspaceClass *klass)
klass->agree_to_close_async = ide_workspace_agree_to_close_async;
klass->agree_to_close_finish = ide_workspace_agree_to_close_finish;
klass->restore_size = ide_workspace_restore_size;
+ klass->save_size = ide_workspace_save_size;
/**
* IdeWorkspace:context:
diff --git a/src/libide/gui/ide-workspace.h b/src/libide/gui/ide-workspace.h
index 9bb09335e..541dc0f4d 100644
--- a/src/libide/gui/ide-workspace.h
+++ b/src/libide/gui/ide-workspace.h
@@ -69,6 +69,9 @@ struct _IdeWorkspaceClass
void (*restore_size) (IdeWorkspace *self,
int width,
int height);
+ gboolean (*save_size) (IdeWorkspace *self,
+ int *width,
+ int *height);
};
IDE_AVAILABLE_IN_ALL
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]