[Xfce4-commits] [apps/xfce4-terminal] 01/01: Add support for the Tab key in shortcuts
noreply at xfce.org
noreply at xfce.org
Wed Mar 27 18:02:25 CET 2019
This is an automated email from the git hooks/post-receive script.
f 2 4 0 4 p u s h e d a c o m m i t t o b r a n c h m a s t e r
in repository apps/xfce4-terminal.
commit 650b4f8324d3b977bd3cf2ccdef4a08f0a067e7d
Author: Igor <f2404 at yandex.ru>
Date: Wed Mar 27 12:55:41 2019 -0400
Add support for the Tab key in shortcuts
By default, GTK does not allow to use Tab in keyboard shortcuts.
Bug #15201
---
terminal/terminal-app.c | 48 ++++++++++++++++++++++++++++++++++++++++-
terminal/terminal-preferences.c | 11 ----------
terminal/terminal-window.c | 47 +++++++++++++++++++++++++++++-----------
terminal/terminal-window.h | 9 ++++++++
4 files changed, 90 insertions(+), 25 deletions(-)
diff --git a/terminal/terminal-app.c b/terminal/terminal-app.c
index 145f525..7bcb465 100644
--- a/terminal/terminal-app.c
+++ b/terminal/terminal-app.c
@@ -55,6 +55,11 @@
static void terminal_app_finalize (GObject *object);
static void terminal_app_update_accels (TerminalApp *app);
+static void terminal_app_update_tab_key_accels (gpointer data,
+ const gchar *accel_path,
+ guint accel_key,
+ GdkModifierType accel_mods,
+ gboolean changed);
static void terminal_app_update_mnemonics (TerminalApp *app);
static void terminal_app_update_windows_accels (gpointer user_data);
static gboolean terminal_app_accel_map_load (gpointer user_data);
@@ -95,6 +100,7 @@ struct _TerminalApp
guint accel_map_load_id;
guint accel_map_save_id;
GtkAccelMap *accel_map;
+ GSList *tab_key_accels;
};
@@ -188,6 +194,10 @@ terminal_app_finalize (GObject *object)
if (app->session_client != NULL)
g_object_unref (G_OBJECT (app->session_client));
+ for (lp = app->tab_key_accels; lp != NULL; lp = lp->next)
+ g_free (((TerminalAccel*) lp->data)->path);
+ g_slist_free_full (app->tab_key_accels, g_free);
+
(*G_OBJECT_CLASS (terminal_app_parent_class)->finalize) (object);
}
@@ -221,6 +231,27 @@ terminal_app_update_accels (TerminalApp *app)
static void
+terminal_app_update_tab_key_accels (gpointer data,
+ const gchar *accel_path,
+ guint accel_key,
+ GdkModifierType accel_mods,
+ gboolean changed)
+{
+ if (accel_key == GDK_KEY_Tab || accel_key == GDK_KEY_ISO_Left_Tab)
+ {
+ TerminalApp *app = TERMINAL_APP (data);
+ TerminalAccel *accel = g_new0 (TerminalAccel, 1);
+
+ accel->path = g_strdup (g_strrstr (accel_path, "/") + 1); // <Actions>/terminal-window/action
+ accel->mods = accel_mods;
+
+ app->tab_key_accels = g_slist_prepend (app->tab_key_accels, accel);
+ }
+}
+
+
+
+static void
terminal_app_update_mnemonics (TerminalApp *app)
{
gboolean no_mnemonics;
@@ -242,7 +273,10 @@ terminal_app_update_windows_accels (gpointer user_data)
GSList *lp;
for (lp = app->windows; lp != NULL; lp = lp->next)
- terminal_window_rebuild_tabs_menu (TERMINAL_WINDOW (lp->data));
+ {
+ terminal_window_rebuild_tabs_menu (TERMINAL_WINDOW (lp->data));
+ terminal_window_update_tab_key_accels (TERMINAL_WINDOW (lp->data), app->tab_key_accels);
+ }
app->accel_map_load_id = 0;
}
@@ -316,6 +350,16 @@ terminal_app_accel_map_load (gpointer user_data)
gtk_accel_map_change_entry (name, GDK_KEY_0 + i, GDK_MOD1_MASK, FALSE);
}
+ /* identify accelerators containing the Tab key */
+ if (app->tab_key_accels != NULL)
+ {
+ GSList *lp;
+ for (lp = app->tab_key_accels; lp != NULL; lp = lp->next)
+ g_free (((TerminalAccel*) lp->data)->path);
+ g_slist_free_full (app->tab_key_accels, g_free);
+ }
+ gtk_accel_map_foreach (app, terminal_app_update_tab_key_accels);
+
return FALSE;
}
@@ -367,6 +411,8 @@ terminal_app_take_window (TerminalApp *app,
g_signal_connect (G_OBJECT (window), "key-release-event",
G_CALLBACK (terminal_app_unset_urgent_bell), app);
app->windows = g_slist_prepend (app->windows, window);
+
+ terminal_window_update_tab_key_accels (TERMINAL_WINDOW (window), app->tab_key_accels);
}
diff --git a/terminal/terminal-preferences.c b/terminal/terminal-preferences.c
index ce07969..c356db5 100644
--- a/terminal/terminal-preferences.c
+++ b/terminal/terminal-preferences.c
@@ -114,7 +114,6 @@ enum
PROP_MISC_SLIM_TABS,
PROP_MISC_NEW_TAB_ADJACENT,
PROP_MISC_SEARCH_DIALOG_OPACITY,
- PROP_MISC_USE_TAB_KEY_TO_CYCLE_TABS,
PROP_MISC_SHOW_UNSAFE_PASTE_DIALOG,
PROP_SCROLLING_BAR,
PROP_SCROLLING_LINES,
@@ -1072,16 +1071,6 @@ terminal_preferences_class_init (TerminalPreferencesClass *klass)
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
/**
- * TerminalPreferences:misc-use-tab-key-to-cycle-tabs:
- **/
- preferences_props[PROP_MISC_USE_TAB_KEY_TO_CYCLE_TABS] =
- g_param_spec_boolean ("misc-use-tab-key-to-cycle-tabs",
- NULL,
- "MiscUseTabKeyToCycleTabs",
- FALSE,
- G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
-
- /**
* TerminalPreferences:misc-show-unsafe-paste-dialog:
**/
preferences_props[PROP_MISC_SHOW_UNSAFE_PASTE_DIALOG] =
diff --git a/terminal/terminal-window.c b/terminal/terminal-window.c
index 8524edd..9767fb8 100644
--- a/terminal/terminal-window.c
+++ b/terminal/terminal-window.c
@@ -331,6 +331,8 @@ struct _TerminalWindowPrivate
TerminalVisibility scrollbar_visibility;
TerminalZoomLevel zoom;
+ GSList *tab_key_accels;
+
/* if this is a TerminalWindowDropdown */
guint drop_down : 1;
};
@@ -794,22 +796,27 @@ terminal_window_key_press_event (GtkWidget *widget,
{
TerminalWindow *window = TERMINAL_WINDOW (widget);
const guint modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
- gboolean use_tab;
-
- /* whether to use Ctrl+Tab/Ctrl+Shift+Tab as Next/Prev Tab shortcuts, respectively */
- g_object_get (G_OBJECT (window->priv->preferences), "misc-use-tab-key-to-cycle-tabs", &use_tab, NULL);
- if (G_UNLIKELY (use_tab && (event->keyval == GDK_KEY_Tab || event->keyval == GDK_KEY_ISO_Left_Tab)))
+ /* support shortcuts that contain the Tab key
+ Tab sometimes becomes ISO_Left_Tab (e.g. in Ctrl+Shift+Tab) so check both here */
+ if (G_UNLIKELY (window->priv->tab_key_accels != NULL
+ && (event->keyval == GDK_KEY_Tab || event->keyval == GDK_KEY_ISO_Left_Tab)))
{
- if (modifiers == (GDK_CONTROL_MASK | GDK_SHIFT_MASK))
- {
- terminal_window_action_prev_tab (NULL, window);
- return TRUE;
- }
- else if (modifiers == GDK_CONTROL_MASK)
+ GSList *lp;
+ for (lp = window->priv->tab_key_accels; lp != NULL; lp = lp->next)
{
- terminal_window_action_next_tab (NULL, window);
- return TRUE;
+ TerminalAccel *accel = lp->data;
+ if (accel->mods == modifiers)
+ {
+ GtkAction *action = terminal_window_get_action (window, accel->path);
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+ if (G_LIKELY (GTK_IS_ACTION (action)))
+ {
+ gtk_action_activate (action);
+ return TRUE;
+ }
+G_GNUC_END_IGNORE_DEPRECATIONS
+ }
}
}
@@ -3301,3 +3308,17 @@ G_GNUC_END_IGNORE_DEPRECATIONS
terminal_window_size_pop (window);
}
+
+
+
+/**
+ * terminal_window_action_show_menubar:
+ * @window : A #TerminalWindow.
+ * @tab_key_accels : A list of Tab key accelerators.
+ **/
+void
+terminal_window_update_tab_key_accels (TerminalWindow *window,
+ GSList *tab_key_accels)
+{
+ window->priv->tab_key_accels = tab_key_accels;
+}
diff --git a/terminal/terminal-window.h b/terminal/terminal-window.h
index 9bd8389..75d17d6 100644
--- a/terminal/terminal-window.h
+++ b/terminal/terminal-window.h
@@ -47,6 +47,12 @@ typedef struct
TerminalWindowPrivate *priv;
} TerminalWindow;
+typedef struct
+{
+ gchar *path;
+ guint mods;
+} TerminalAccel;
+
GType terminal_window_get_type (void) G_GNUC_CONST;
GtkWidget *terminal_window_new (const gchar *role,
@@ -106,6 +112,9 @@ void terminal_window_rebuild_tabs_menu (TerminalWindow
void terminal_window_action_show_menubar (GtkToggleAction *action,
TerminalWindow *window);
+void terminal_window_update_tab_key_accels (TerminalWindow *window,
+ GSList *tab_key_accels);
+
G_END_DECLS
#endif /* !TERMINAL_WINDOW_H */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list