[PATCH] Add GTK actions for listing screens on a window and switching active screen
I'm submitting a patch which uses the GAction
org.gtk.Actions` interface to expose two new states on the window object via DBus:
-
screens
: a read-only property which lists the screen IDs attached to the window. -
active-screen
: when queried, returns the screen ID (i.e. the value embedded in the environment variableGNOME_TERMINAL_SCREEN
) of theTerminalScreen
in the active tab (currently focused tab). When activated with a valid screen ID as a parameter, finds the tab containing the screen with the corresponding ID, and focuses it by callingterminal_mdi_container_set_active_screen
.
Together, these make it possible for a script running in any tab to determine
- which window contains the VTE its running in
- whether that window has tabs, if the tab containing itself is focused, (and if necessary, to make itself focused)
I'm including the patch with adds the GActions
. To exercise the functionality, simply poke `` and Describe
and `SetState` methods under the `org.gtk.Actions` interface on a running window, with `screens` or `active-screen` arguments. `SetState(active-screen)` takes an argument of type `s`.
The patch (included inline and as an attachment) was generated against the 3.44.2
branch.
0001-Add-screens-and-active-screen-actions-states.patch
Inline patch
``` From 6f6fd76615ab243f1adbe0b6049b5bfe550fd32e Mon Sep 17 00:00:00 2001 From: Jesse Dhillon Date: Sun, 16 Oct 2022 19:56:56 -0700 Subject: [PATCH] Add 'screens' and 'active-screen' actions/statessrc/terminal-screen.cc | 1 - src/terminal-window.cc | 82 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 1 deletion(-)
diff --git a/src/terminal-screen.cc b/src/terminal-screen.cc index b793ee77..3a3d60c1 100644 --- a/src/terminal-screen.cc +++ b/src/terminal-screen.cc @@ -20,7 +20,6 @@
#include "terminal-pcre2.hh" #include "terminal-regex.hh" -#include "terminal-screen.hh" #include "terminal-client-utils.hh"
#include <errno.h> diff --git a/src/terminal-window.cc b/src/terminal-window.cc index 76f18000..d813d023 100644 --- a/src/terminal-window.cc +++ b/src/terminal-window.cc @@ -38,6 +38,7 @@ #include "terminal-menu-button.hh" #include "terminal-notebook.hh" #include "terminal-schemas.hh" +#include "terminal-screen.hh" #include "terminal-screen-container.hh" #include "terminal-search-popover.hh" #include "terminal-tab-label.hh" @@ -807,6 +808,11 @@ tab_switch_relative (TerminalWindow *window,
g_action_change_state (G_ACTION (lookup_action (window, "active-tab")), g_variant_new_int32 (value)); +
- TerminalScreen *screen = terminal_mdi_container_get_active_screen (priv->mdi_container);
- g_simple_action_set_state (lookup_action (window, "active-screen"),
-
g_variant_new_string( terminal_screen_get_uuid( screen ) ));
}
static void @@ -1348,6 +1354,46 @@ action_active_tab_set_cb (GSimpleAction *action, g_action_change_state (G_ACTION (action), g_variant_new_int32 (value)); }
+static void +action_active_screen_set_cb (GSimpleAction *action,
-
GVariant *parameter,
-
gpointer user_data)
+{
- TerminalWindow window = (TerminalWindow)user_data;
- TerminalWindowPrivate *priv = window->priv;
- GList *l, *list;
- g_assert_nonnull (parameter);
- const gchar* uuid = g_variant_get_string (parameter, nullptr);
- list = terminal_mdi_container_list_screens (priv->mdi_container);
- for (l = list ; l != nullptr; l = l->next) {
- TerminalScreen* screen = (TerminalScreen*) l->data;
- if (g_strcmp0 (terminal_screen_get_uuid(screen), uuid) == 0) {
-
g_action_change_state (G_ACTION (action), g_variant_new_string (uuid));
- }
- } +}
+static void +action_state_screens_update (GSimpleAction *action,
-
gpointer user_data)
+{
- TerminalWindow window = (TerminalWindow)user_data;
- TerminalWindowPrivate *priv = window->priv;
- GList *l, *screens = terminal_mdi_container_list_screens (priv->mdi_container);
- GVariantBuilder* builder;
- builder = g_variant_builder_new (G_VARIANT_TYPE( "as" ));
- for (l = screens; l != nullptr; l = l->next)
- g_variant_builder_add( builder, "s", terminal_screen_get_uuid( (TerminalScreen*) l->data) );
- g_simple_action_set_state (action, g_variant_new( "as", builder) );
- g_variant_builder_unref( builder ); +}
static void action_active_tab_state_cb (GSimpleAction *action, GVariant *state, @@ -1363,6 +1409,32 @@ action_active_tab_state_cb (GSimpleAction *action, terminal_mdi_container_set_active_screen_num (priv->mdi_container, g_variant_get_int32 (state)); }
+static void +action_active_screen_state_cb (GSimpleAction *action,
-
GVariant *state,
-
gpointer user_data)
+{
- TerminalWindow window = (TerminalWindow)user_data;
- TerminalWindowPrivate *priv = window->priv;
- GList *l, *list;
- g_assert_nonnull (state);
- const gchar *uuid = g_variant_get_string (state, nullptr);
- list = terminal_mdi_container_list_screens (priv->mdi_container);
- for (l = list ; l != nullptr; l = l->next) {
- TerminalScreen* screen = (TerminalScreen*) l->data;
- if (g_strcmp0 (terminal_screen_get_uuid(screen), uuid) == 0) {
-
g_simple_action_set_state (action, g_variant_new_string (uuid));
-
terminal_mdi_container_set_active_screen (priv->mdi_container, screen);
-
return;
- }
- }
- g_warning ("screen with uuid %s not found", uuid); +}
/* Menubar mnemonics & accel settings handling */
static void @@ -1626,6 +1698,10 @@ terminal_window_update_tabs_actions_sensitivity (TerminalWindow *window) g_simple_action_set_state (lookup_action (window, "active-tab"), g_variant_new_int32 (page_num));
-
TerminalScreen *screen = terminal_mdi_container_get_active_screen (priv->mdi_container);
-
g_simple_action_set_state (lookup_action (window, "active-screen"),
-
g_variant_new_string( terminal_screen_get_uuid( screen ) ));
-
/* Keynav wraps around? See bug #92139 */ gboolean keynav_wrap_around; g_object_get (gtk_widget_get_settings (GTK_WIDGET (window)), @@ -2125,6 +2201,8 @@ terminal_window_init (TerminalWindow *window)
/* Actions with state */ { "active-tab", action_active_tab_set_cb, "i", "@i 0", action_active_tab_state_cb },
-
{ "active-screen", action_active_screen_set_cb , "s", "''", action_active_screen_state_cb },
-
{ "screens", nullptr /* toggles state /, nullptr, "@as []", nullptr }, { "header-menu", nullptr / toggles state /, nullptr, "false", nullptr }, { "fullscreen", nullptr / toggles state /, nullptr, "false", action_fullscreen_state_cb }, { "menubar-visible", nullptr / toggles state */, nullptr, "true", action_menubar_visible_state_cb }, @@ -2886,6 +2964,8 @@ mdi_screen_added_cb (TerminalMdiContainer *container, { terminal_window_update_size (window); }
-
action_state_screens_update( lookup_action (window, "screens"), window ); }
static void @@ -2963,6 +3043,8 @@ mdi_screen_removed_cb (TerminalMdiContainer *container,
terminal_window_update_size (window);
}
- action_state_screens_update( lookup_action (window, "screens"), window ); }
static void
2.34.1
</details>