From 05a8bf08a2e3d2d498bdc6efeffd38ca6b45351c Mon Sep 17 00:00:00 2001 From: Nick Treleaven Date: Wed, 26 Sep 2007 16:22:20 +0000 Subject: [PATCH] Make common bash Ctrl-[a-z] keyboard shortcuts work in the VTE. (Not sure why Ctrl-Shift-[cv] copy/paste shortcuts still don't work). git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1908 ea778897-0a13-0410-b9d1-a72fbfd435f5 --- ChangeLog | 3 +++ NEWS | 1 + src/keybindings.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++- src/vte.c | 23 ++++++++++++------- 4 files changed, 76 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6dd7bda4..bb4eb554 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,9 @@ * src/keybindings.c: Fix selecting text with Shift-{PageUp,PageDown} (closes #1801315). + * src/keybindings.c, src/vte.c: + Make common bash Ctrl-[a-z] keyboard shortcuts work in the VTE. + (Not sure why Ctrl-Shift-[cv] copy/paste shortcuts still don't work). 2007-09-25 Nick Treleaven diff --git a/NEWS b/NEWS index 277055c8..f9877e7b 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,7 @@ Geany 0.12 (TBA) Bugs fixed: * Fixed opening the same file twice from the message window/command-line. * Fixed Ctrl-Shift keybindings not working when caps lock is on. + * Fixed common bash Ctrl-[a-z] keyboard shortcuts not working in the VTE. * Fixed saving the wrong document when using Save All with unnamed documents. * Fixed replacing with '^' or '$' regex chars. diff --git a/src/keybindings.c b/src/keybindings.c index ac7eb6e9..5406e40e 100644 --- a/src/keybindings.c +++ b/src/keybindings.c @@ -43,6 +43,7 @@ #include "tools.h" #include "navqueue.h" #include "symbols.h" +#include "vte.h" const gboolean swap_alt_tab_order = FALSE; @@ -654,6 +655,59 @@ static gboolean check_construct_completion(GdkEventKey *event) } +static gboolean set_sensitive(gpointer widget) +{ + gtk_widget_set_sensitive(GTK_WIDGET(widget), TRUE); + return FALSE; +} + + +static gboolean check_vte(GdkEventKey *event, guint keyval) +{ +#ifndef HAVE_VTE + return FALSE; +#else + GtkWidget *menubar; + + if (! vte_info.have_vte) + return FALSE; + if (gtk_window_get_focus(GTK_WINDOW(app->window)) != vc->vte) + return FALSE; + if (event->state == (GDK_CONTROL_MASK | GDK_SHIFT_MASK) && + (keyval == GDK_c || keyval == GDK_v)) // copy/paste + return TRUE; + if (event->state != GDK_CONTROL_MASK) + return FALSE; + + // Check Ctrl-[a-z] terminal shortcuts + switch (keyval) + { + case GDK_a: + case GDK_c: + case GDK_d: + case GDK_e: + case GDK_k: + case GDK_q: + case GDK_r: + case GDK_s: + case GDK_u: + case GDK_w: + case GDK_z: + break; + default: + return FALSE; + } + /* Temporarily disable the menubar to prevent conflicting menu accelerators. + * Ideally we would just somehow disable the menubar without redrawing it, + * but maybe that's not possible. */ + menubar = lookup_widget(app->window, "menubar1"); + gtk_widget_set_sensitive(menubar, FALSE); + g_idle_add(&set_sensitive, (gpointer) menubar); + return TRUE; +#endif +} + + /* central keypress event handler, almost all keypress events go to this function */ gboolean keybindings_got_event(GtkWidget *widget, GdkEventKey *event, gpointer user_data) { @@ -673,7 +727,9 @@ gboolean keybindings_got_event(GtkWidget *widget, GdkEventKey *event, gpointer u if (event->state & GDK_MOD2_MASK) event->state -= GDK_MOD2_MASK; - // special case + // special cases + if (check_vte(event, keyval)) + return FALSE; if (check_construct_completion(event)) return TRUE; diff --git a/src/vte.c b/src/vte.c index 45c19284..62663971 100644 --- a/src/vte.c +++ b/src/vte.c @@ -60,6 +60,7 @@ static const gchar VTE_WORDCHARS[] = "-A-Za-z0-9,./?%&#:_"; #define VTE_TERMINAL(obj) (GTK_CHECK_CAST((obj), VTE_TYPE_TERMINAL, VteTerminal)) #define VTE_TYPE_TERMINAL (vf->vte_terminal_get_type()) +static void create_vte(); static void vte_start(GtkWidget *widget); static gboolean vte_button_pressed(GtkWidget *widget, GdkEventButton *event, gpointer user_data); static gboolean vte_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data); @@ -76,6 +77,7 @@ enum POPUP_PREFERENCES }; + /* taken from anjuta, thanks */ static gchar **vte_get_child_environment(void) { @@ -133,9 +135,6 @@ static void override_menu_key() void vte_init(void) { - - GtkWidget *vte, *scrollbar, *hbox, *frame; - if (vte_info.have_vte == FALSE) { // app->have_vte can be false, even if VTE is compiled in, think of command line option geany_debug("Disabling terminal support"); @@ -171,6 +170,17 @@ void vte_init(void) vte_register_symbols(module); } + create_vte(); + + // setup the f10 menu override (so it works before the widget is first realized). + override_menu_key(); +} + + +static void create_vte() +{ + GtkWidget *vte, *scrollbar, *hbox, *frame; + vte = vf->vte_terminal_new(); vc->vte = vte; scrollbar = gtk_vscrollbar_new(GTK_ADJUSTMENT(VTE_TERMINAL(vte)->adjustment)); @@ -206,9 +216,6 @@ void vte_init(void) // the vte widget has to be realised before color changes take effect g_signal_connect(G_OBJECT(vte), "realize", G_CALLBACK(vte_apply_user_settings), NULL); - - // setup the f10 menu override (so it works before the widget is first realized). - override_menu_key(); } @@ -240,7 +247,8 @@ static gboolean vte_keypress(GtkWidget *widget, GdkEventKey *event, gpointer dat event->keyval == GDK_d || event->keyval == GDK_C || event->keyval == GDK_D) && - event->state & GDK_CONTROL_MASK) + event->state & GDK_CONTROL_MASK && + ! (event->state & GDK_SHIFT_MASK) && ! (event->state & GDK_MOD1_MASK)) { vte_get_working_directory(); // try to keep the working directory when restarting the VTE @@ -254,7 +262,6 @@ static gboolean vte_keypress(GtkWidget *widget, GdkEventKey *event, gpointer dat return TRUE; } - return FALSE; }