From 234a3fa45348d082ea8f280ba29807678a58bdba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Sat, 22 Mar 2014 17:12:50 -0400 Subject: [PATCH] xfreerdp: add action script options for X11 events --- client/X11/xf_event.c | 92 ++++++++++++++++++++++++++++++++++++++++ client/X11/xf_event.h | 3 ++ client/X11/xf_keyboard.c | 8 +++- client/X11/xfreerdp.h | 1 + 4 files changed, 103 insertions(+), 1 deletion(-) diff --git a/client/X11/xf_event.c b/client/X11/xf_event.c index 46f19bba6..072066be5 100644 --- a/client/X11/xf_event.c +++ b/client/X11/xf_event.c @@ -87,6 +87,96 @@ const char* const X11_EVENT_STRINGS[] = #define DEBUG_X11_LMS(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__) #endif +int xf_event_action_script_init(xfContext* xfc) +{ + int exitCode; + char* xevent; + FILE* actionScript; + char buffer[1024] = { 0 }; + char command[1024] = { 0 }; + + xfc->xevents = ArrayList_New(TRUE); + ArrayList_Object(xfc->xevents)->fnObjectFree = free; + + sprintf_s(command, sizeof(command), "%s xevent", xfc->actionScript); + + actionScript = popen(command, "r"); + + if (actionScript < 0) + return -1; + + while (fgets(buffer, sizeof(buffer), actionScript) != NULL) + { + strtok(buffer, "\n"); + xevent = _strdup(buffer); + ArrayList_Add(xfc->xevents, xevent); + } + + exitCode = pclose(actionScript); + + return 1; +} + +void xf_event_action_script_free(xfContext* xfc) +{ + if (xfc->xevents) + { + ArrayList_Free(xfc->xevents); + xfc->xevents = NULL; + } +} + +int xf_event_execute_action_script(xfContext* xfc, XEvent* event) +{ + int index; + int count; + char* name; + int exitCode; + FILE* actionScript; + BOOL match = FALSE; + const char* xeventName; + char buffer[1024] = { 0 }; + char command[1024] = { 0 }; + + if (event->type > (sizeof(X11_EVENT_STRINGS) / sizeof(const char*))) + return 1; + + xeventName = X11_EVENT_STRINGS[event->type]; + + count = ArrayList_Count(xfc->xevents); + + for (index = 0; index < count; index++) + { + name = (char*) ArrayList_GetItem(xfc->xevents, index); + + if (_stricmp(name, xeventName) == 0) + { + match = TRUE; + break; + } + } + + if (!match) + return 1; + + sprintf_s(command, sizeof(command), "%s xevent %s %d", + xfc->actionScript, xeventName, (int) xfc->window->handle); + + actionScript = popen(command, "r"); + + if (actionScript < 0) + return -1; + + while (fgets(buffer, sizeof(buffer), actionScript) != NULL) + { + strtok(buffer, "\n"); + } + + exitCode = pclose(actionScript); + + return 1; +} + static BOOL xf_event_Expose(xfContext* xfc, XEvent* event, BOOL app) { int x, y; @@ -935,6 +1025,8 @@ BOOL xf_event_process(freerdp* instance, XEvent* event) } } + xf_event_execute_action_script(xfc, event); + if (event->type != MotionNotify) DEBUG_X11("%s Event(%d): wnd=0x%04X", X11_EVENT_STRINGS[event->type], event->type, (UINT32) event->xany.window); diff --git a/client/X11/xf_event.h b/client/X11/xf_event.h index 05d4e3e04..4198ab2f2 100644 --- a/client/X11/xf_event.h +++ b/client/X11/xf_event.h @@ -25,6 +25,9 @@ #include "xf_client.h" #include "xfreerdp.h" +int xf_event_action_script_init(xfContext* xfc); +void xf_event_action_script_free(xfContext* xfc); + BOOL xf_event_process(freerdp* instance, XEvent* event); void xf_event_SendClientEvent(xfContext* xfc, xfWindow* window, Atom atom, unsigned int numArgs, ...); diff --git a/client/X11/xf_keyboard.c b/client/X11/xf_keyboard.c index bb2e1750e..852546b53 100644 --- a/client/X11/xf_keyboard.c +++ b/client/X11/xf_keyboard.c @@ -35,6 +35,8 @@ #include +#include "xf_event.h" + #include "xf_keyboard.h" int xf_keyboard_action_script_init(xfContext* xfc) @@ -80,11 +82,15 @@ int xf_keyboard_action_script_init(xfContext* xfc) exitCode = pclose(keyScript); + xf_event_action_script_init(xfc); + return 1; } void xf_keyboard_action_script_free(xfContext* xfc) { + xf_event_action_script_free(xfc); + if (xfc->keyCombinations) { ArrayList_Free(xfc->keyCombinations); @@ -348,7 +354,7 @@ int xf_keyboard_execute_action_script(xfContext* xfc, XF_MODIFIER_KEYS* mod, Key } if (!match) - return 0; + return 1; sprintf_s(command, sizeof(command), "%s key %s", xfc->actionScript, combination); diff --git a/client/X11/xfreerdp.h b/client/X11/xfreerdp.h index a23c92c0e..aa01ae905 100644 --- a/client/X11/xfreerdp.h +++ b/client/X11/xfreerdp.h @@ -129,6 +129,7 @@ struct xf_context BOOL KeyboardState[256]; XModifierKeymap* modifierMap; wArrayList* keyCombinations; + wArrayList* xevents; char* actionScript; XSetWindowAttributes attribs;