xfreerdp: add action script options for X11 events

This commit is contained in:
Marc-André Moreau 2014-03-22 17:12:50 -04:00
parent 770defc706
commit 234a3fa453
4 changed files with 103 additions and 1 deletions

View File

@ -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);

View File

@ -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, ...);

View File

@ -35,6 +35,8 @@
#include <freerdp/locale/keyboard.h>
#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);

View File

@ -129,6 +129,7 @@ struct xf_context
BOOL KeyboardState[256];
XModifierKeymap* modifierMap;
wArrayList* keyCombinations;
wArrayList* xevents;
char* actionScript;
XSetWindowAttributes attribs;