[console/wip/msandova/remember-window-size: 3/4] window: Use active window size for new windows
- From: Maximiliano <msandova src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [console/wip/msandova/remember-window-size: 3/4] window: Use active window size for new windows
- Date: Fri, 29 Jul 2022 22:46:52 +0000 (UTC)
commit 2606ec940897df04fc3b1ea00fc7bc7a966d1c4c
Author: Maximiliano Sandoval R <msandova gnome org>
Date: Sat Jul 30 00:39:29 2022 +0200
window: Use active window size for new windows
src/kgx-application.c | 34 +++++++++++++++++++++++++++++-----
src/kgx-application.h | 1 +
src/kgx-window.c | 4 ++++
3 files changed, 34 insertions(+), 5 deletions(-)
---
diff --git a/src/kgx-application.c b/src/kgx-application.c
index 5405902..cd1be5e 100644
--- a/src/kgx-application.c
+++ b/src/kgx-application.c
@@ -192,6 +192,7 @@ kgx_application_activate (GApplication *app)
window = gtk_application_get_active_window (GTK_APPLICATION (app));
if (window == NULL) {
kgx_application_add_terminal (KGX_APPLICATION (app),
+ NULL,
NULL,
timestamp,
NULL,
@@ -377,10 +378,15 @@ kgx_application_open (GApplication *app,
const char *hint)
{
guint32 timestamp = GDK_CURRENT_TIME;
+ GtkWindow *active_window;
+
+ /* If this is launched from Console, we use the active window's size */
+ active_window = gtk_application_get_active_window (GTK_APPLICATION (app));
for (int i = 0; i < n_files; i++) {
kgx_application_add_terminal (KGX_APPLICATION (app),
NULL,
+ active_window,
timestamp,
files[i],
NULL,
@@ -433,6 +439,7 @@ kgx_application_command_line (GApplication *app,
GApplicationCommandLine *cli)
{
KgxApplication *self = KGX_APPLICATION (app);
+ GtkWindow *active_window;
guint32 timestamp = GDK_CURRENT_TIME;
GVariantDict *options = NULL;
g_auto (GStrv) argv = NULL;
@@ -504,15 +511,18 @@ kgx_application_command_line (GApplication *app,
}
}
+ active_window = gtk_application_get_active_window (GTK_APPLICATION (self));
if (g_variant_dict_lookup (options, "tab", "b", &tab) && tab) {
kgx_application_add_terminal (self,
- KGX_WINDOW (gtk_application_get_active_window (GTK_APPLICATION (self))),
+ KGX_WINDOW (active_window),
+ NULL,
timestamp,
path,
argv,
title);
} else {
- kgx_application_add_terminal (self, NULL, timestamp, path, argv, title);
+ kgx_application_add_terminal (self, NULL, active_window, timestamp, path,
+ argv, title);
}
return EXIT_SUCCESS;
@@ -806,7 +816,8 @@ new_window_activated (GSimpleAction *action,
KgxApplication *self = KGX_APPLICATION (data);
guint32 timestamp = GDK_CURRENT_TIME;
- kgx_application_add_terminal (self, NULL, timestamp, NULL, NULL, NULL);
+ kgx_application_add_terminal (self, NULL, NULL, timestamp, NULL,
+ NULL, NULL);
}
@@ -824,9 +835,11 @@ new_tab_activated (GSimpleAction *action,
if (window) {
dir = kgx_window_get_working_dir (KGX_WINDOW (window));
- kgx_application_add_terminal (self, KGX_WINDOW (window), timestamp, dir, NULL, NULL);
+ kgx_application_add_terminal (self, KGX_WINDOW (window), NULL, timestamp,
+ dir, NULL, NULL);
} else {
- kgx_application_add_terminal (self, NULL, timestamp, NULL, NULL, NULL);
+ kgx_application_add_terminal (self, NULL, NULL, timestamp, NULL, NULL,
+ NULL);
}
}
@@ -1124,6 +1137,7 @@ started (GObject *src,
KgxTab *
kgx_application_add_terminal (KgxApplication *self,
KgxWindow *existing_window,
+ GtkWindow *active_window,
guint32 timestamp,
GFile *working_directory,
GStrv argv,
@@ -1174,6 +1188,16 @@ kgx_application_add_terminal (KgxApplication *self,
if (existing_window) {
window = GTK_WINDOW (existing_window);
+ } else if (active_window) {
+ int width, height;
+
+ gtk_window_get_default_size (active_window, &width, &height);
+
+ window = g_object_new (KGX_TYPE_WINDOW,
+ "application", self,
+ "default-width", width,
+ "default-height", height,
+ NULL);
} else {
window = g_object_new (KGX_TYPE_WINDOW,
"application", self,
diff --git a/src/kgx-application.h b/src/kgx-application.h
index ed12c6e..8a8327b 100644
--- a/src/kgx-application.h
+++ b/src/kgx-application.h
@@ -108,6 +108,7 @@ KgxTab *kgx_application_lookup_page (KgxApplication *self,
guint id);
KgxTab * kgx_application_add_terminal (KgxApplication *self,
KgxWindow *existing_window,
+ GtkWindow *active_window,
guint32 timestamp,
GFile *working_directory,
GStrv command,
diff --git a/src/kgx-window.c b/src/kgx-window.c
index 7e26fd3..d2ef820 100644
--- a/src/kgx-window.c
+++ b/src/kgx-window.c
@@ -452,13 +452,16 @@ new_activated (GSimpleAction *action,
KgxWindow *self = data;
guint32 timestamp = GDK_CURRENT_TIME;
GtkApplication *application = NULL;
+ GtkWindow *active_window;
g_autoptr (GFile) dir = NULL;
application = gtk_window_get_application (GTK_WINDOW (self));
+ active_window = gtk_application_get_active_window (application);
dir = kgx_window_get_working_dir (KGX_WINDOW (data));
kgx_application_add_terminal (KGX_APPLICATION (application),
NULL,
+ active_window,
timestamp,
dir,
NULL,
@@ -481,6 +484,7 @@ new_tab_activated (GSimpleAction *action,
kgx_application_add_terminal (KGX_APPLICATION (application),
self,
+ NULL,
timestamp,
dir,
NULL,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]