Branch: refs/heads/master Author: Jiří Techet techet@gmail.com Committer: elextr elextr@gmail.com Date: Mon, 21 May 2018 23:35:44 UTC Commit: 38a0e4f5b01ac2ed6ad91de8724cd769c0cfab37 https://github.com/geany/geany/commit/38a0e4f5b01ac2ed6ad91de8724cd769c0cfab...
Log Message: ----------- Allow plugins to process keypress events before Geany (#1829)
In addition, the signal allows plugins swallow the event so it's not processed by Geany.
Modified Paths: -------------- doc/pluginsignals.c src/geanyobject.c src/geanyobject.h src/keybindings.c src/plugindata.h
Modified: doc/pluginsignals.c 20 lines changed, 20 insertions(+), 0 deletions(-) =================================================================== @@ -270,3 +270,23 @@ signal void (*update_editor_menu)(GObject *obj, const gchar *word, gint pos, Gea */ signal gboolean (*editor_notify)(GObject *obj, GeanyEditor *editor, SCNotification *nt, gpointer user_data); + +/** Sent whenever a key is pressed. + * + * This signal allows plugins to receive key press events before they are processed + * by Geany. Plugins can then process key presses before Geany and decide, + * whether Geany should receive the key press event or not. + * + * @warning This signal should be used carefully. If multiple plugins use this + * signal, the result could be unpredictble depending on which plugin + * receives the signal first. + * + * @param obj a GeanyObject instance, should be ignored. + * @param key The GdkEventKey corresponding to the key press. + * @param user_data user data. + * @return @c TRUE to stop other handlers from being invoked for the event. + * @c FALSE to propagate the event further. + * + * @since 1.34 + */ +signal gboolean (*key_press)(GObject *obj, GdkEventKey *key, gpointer user_data);
Modified: src/geanyobject.c 9 lines changed, 9 insertions(+), 0 deletions(-) =================================================================== @@ -229,6 +229,15 @@ static void create_signals(GObjectClass *g_object_class) 0, NULL, NULL, g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, G_TYPE_KEY_FILE); + + /* Key press signal */ + geany_object_signals[GCB_KEY_PRESS_NOTIFY] = g_signal_new ( + "key-press", + G_OBJECT_CLASS_TYPE (g_object_class), + G_SIGNAL_RUN_LAST, + 0, boolean_handled_accumulator, NULL, NULL, + G_TYPE_BOOLEAN, 1, + GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); }
Modified: src/geanyobject.h 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -57,6 +57,7 @@ typedef enum GCB_BUILD_START, GCB_SAVE_SETTINGS, GCB_LOAD_SETTINGS, + GCB_KEY_PRESS_NOTIFY, GCB_MAX } GeanyCallbackId;
Modified: src/keybindings.c 6 lines changed, 6 insertions(+), 0 deletions(-) =================================================================== @@ -38,6 +38,7 @@ #include "callbacks.h" #include "documentprivate.h" #include "filetypes.h" +#include "geanyobject.h" #include "keybindingsprivate.h" #include "main.h" #include "msgwindow.h" @@ -1350,10 +1351,15 @@ static gboolean on_key_press_event(GtkWidget *widget, GdkEventKey *ev, gpointer GeanyDocument *doc; GeanyKeyGroup *group; GeanyKeyBinding *kb; + gboolean key_press_ret;
if (ev->keyval == 0) return FALSE;
+ g_signal_emit_by_name(geany_object, "key-press", ev, &key_press_ret); + if (key_press_ret) + return TRUE; + doc = document_get_current(); if (doc) document_check_disk_status(doc, FALSE);
Modified: src/plugindata.h 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -59,7 +59,7 @@ G_BEGIN_DECLS * @warning You should not test for values below 200 as previously * @c GEANY_API_VERSION was defined as an enum value, not a macro. */ -#define GEANY_API_VERSION 236 +#define GEANY_API_VERSION 237
/* hack to have a different ABI when built with GTK3 because loading GTK2-linked plugins * with GTK3-linked Geany leads to crash */
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).