diff --git a/client/X11/xf_event.c b/client/X11/xf_event.c index 31245ce51..2d5130b86 100644 --- a/client/X11/xf_event.c +++ b/client/X11/xf_event.c @@ -97,7 +97,7 @@ BOOL xf_event_action_script_init(xfContext* xfc) return FALSE; ArrayList_Object(xfc->xevents)->fnObjectFree = free; - sprintf_s(command, sizeof(command), "%s xevent", xfc->actionScript); + sprintf_s(command, sizeof(command), "%s xevent", xfc->context.settings->ActionScript); actionScript = popen(command, "r"); if (!actionScript) @@ -140,7 +140,7 @@ static BOOL xf_event_execute_action_script(xfContext* xfc, XEvent* event) char buffer[1024] = { 0 }; char command[1024] = { 0 }; - if (!xfc->actionScript || !xfc->xevents) + if (!xfc->actionScriptExists || !xfc->xevents) return FALSE; if (event->type > (sizeof(X11_EVENT_STRINGS) / sizeof(const char*))) @@ -164,7 +164,7 @@ static BOOL xf_event_execute_action_script(xfContext* xfc, XEvent* event) return FALSE; sprintf_s(command, sizeof(command), "%s xevent %s %lu", - xfc->actionScript, xeventName, (unsigned long) xfc->window->handle); + xfc->context.settings->ActionScript, xeventName, (unsigned long) xfc->window->handle); actionScript = popen(command, "r"); if (!actionScript) diff --git a/client/X11/xf_keyboard.c b/client/X11/xf_keyboard.c index c1a2e4d59..575d60fc6 100644 --- a/client/X11/xf_keyboard.c +++ b/client/X11/xf_keyboard.c @@ -53,16 +53,9 @@ BOOL xf_keyboard_action_script_init(xfContext* xfc) char buffer[1024] = { 0 }; char command[1024] = { 0 }; - if (xfc->actionScript) - { - free(xfc->actionScript); - xfc->actionScript = NULL; - } + xfc->actionScriptExists = PathFileExistsA(xfc->context.settings->ActionScript); - if (PathFileExistsA("/usr/share/freerdp/action.sh")) - xfc->actionScript = _strdup("/usr/share/freerdp/action.sh"); - - if (!xfc->actionScript) + if (!xfc->actionScriptExists) return FALSE; xfc->keyCombinations = ArrayList_New(TRUE); @@ -71,13 +64,12 @@ BOOL xf_keyboard_action_script_init(xfContext* xfc) return FALSE; ArrayList_Object(xfc->keyCombinations)->fnObjectFree = free; - sprintf_s(command, sizeof(command), "%s key", xfc->actionScript); + sprintf_s(command, sizeof(command), "%s key", xfc->context.settings->ActionScript); keyScript = popen(command, "r"); if (!keyScript) { - free(xfc->actionScript); - xfc->actionScript = NULL; + xfc->actionScriptExists = FALSE; return FALSE; } @@ -89,8 +81,7 @@ BOOL xf_keyboard_action_script_init(xfContext* xfc) if (!keyCombination || ArrayList_Add(xfc->keyCombinations, keyCombination) < 0) { ArrayList_Free(xfc->keyCombinations); - free(xfc->actionScript); - xfc->actionScript = NULL; + xfc->actionScriptExists = FALSE; pclose(keyScript); return FALSE; } @@ -108,12 +99,7 @@ void xf_keyboard_action_script_free(xfContext* xfc) { ArrayList_Free(xfc->keyCombinations); xfc->keyCombinations = NULL; - } - - if (xfc->actionScript) - { - free(xfc->actionScript); - xfc->actionScript = NULL; + xfc->actionScriptExists = FALSE; } } @@ -380,7 +366,7 @@ static int xf_keyboard_execute_action_script(xfContext* xfc, char command[1024] = { 0 }; char combination[1024] = { 0 }; - if (!xfc->actionScript) + if (!xfc->actionScriptExists) return 1; if ((keysym == XK_Shift_L) || (keysym == XK_Shift_R) || @@ -424,7 +410,7 @@ static int xf_keyboard_execute_action_script(xfContext* xfc, return 1; sprintf_s(command, sizeof(command), "%s key %s", - xfc->actionScript, combination); + xfc->context.settings->ActionScript, combination); keyScript = popen(command, "r"); if (!keyScript) diff --git a/client/X11/xf_keyboard.h b/client/X11/xf_keyboard.h index 4392dc6bb..3c33f66b2 100644 --- a/client/X11/xf_keyboard.h +++ b/client/X11/xf_keyboard.h @@ -25,8 +25,6 @@ #include "xf_client.h" #include "xfreerdp.h" -#define XF_ACTION_SCRIPT "~/.config/freerdp/action.sh" - struct _XF_MODIFIER_KEYS { BOOL Shift; diff --git a/client/X11/xfreerdp.h b/client/X11/xfreerdp.h index ecad9d748..da743a5fa 100644 --- a/client/X11/xfreerdp.h +++ b/client/X11/xfreerdp.h @@ -171,7 +171,7 @@ struct xf_context XModifierKeymap* modifierMap; wArrayList* keyCombinations; wArrayList* xevents; - char* actionScript; + BOOL actionScriptExists; XSetWindowAttributes attribs; BOOL complex_regions; diff --git a/client/common/cmdline.c b/client/common/cmdline.c index 476e445d7..83c810162 100644 --- a/client/common/cmdline.c +++ b/client/common/cmdline.c @@ -187,6 +187,7 @@ static COMMAND_LINE_ARGUMENT_A args[] = { "scale", COMMAND_LINE_VALUE_REQUIRED, "", "100", NULL, -1, NULL, "Scaling factor of the display (value of 100, 140, or 180)" }, { "scale-desktop", COMMAND_LINE_VALUE_REQUIRED, "", "100", NULL, -1, NULL, "Scaling factor for desktop applications (value between 100 and 500)" }, { "scale-device", COMMAND_LINE_VALUE_REQUIRED, "", "100", NULL, -1, NULL, "Scaling factor for app store applications (100, 140, or 180)" }, + { "action-script", COMMAND_LINE_VALUE_REQUIRED, "", "/usr/share/freerdp/action.sh", NULL, -1, NULL, "Action script" }, { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } }; @@ -2506,6 +2507,12 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings, return COMMAND_LINE_ERROR; } } + CommandLineSwitchCase(arg, "action-script") + { + free (settings->ActionScript); + if (!(settings->ActionScript = _strdup(arg->Value))) + return COMMAND_LINE_ERROR_MEMORY; + } CommandLineSwitchDefault(arg) { } diff --git a/include/freerdp/settings.h b/include/freerdp/settings.h index 0e3d13ca8..509d4d659 100644 --- a/include/freerdp/settings.h +++ b/include/freerdp/settings.h @@ -1434,6 +1434,7 @@ struct rdp_settings ALIGN64 BYTE* SettingsModified; /* byte array marking fields that have been modified from their default value */ + ALIGN64 char* ActionScript; }; typedef struct rdp_settings rdpSettings; diff --git a/libfreerdp/core/settings.c b/libfreerdp/core/settings.c index 3eef4e830..194ec8f7a 100644 --- a/libfreerdp/core/settings.c +++ b/libfreerdp/core/settings.c @@ -680,6 +680,7 @@ rdpSettings* freerdp_settings_clone(rdpSettings* settings) CHECKED_STRDUP(RemoteApplicationCmdLine); /* 2118 */ CHECKED_STRDUP(ImeFileName); /* 2628 */ CHECKED_STRDUP(DrivesToRedirect); /* 4290 */ + CHECKED_STRDUP(ActionScript); /** * Manual Code */ @@ -1080,6 +1081,7 @@ void freerdp_settings_free(rdpSettings* settings) free(settings->DrivesToRedirect); free(settings->WindowTitle); free(settings->WmClass); + free(settings->ActionScript); freerdp_target_net_addresses_free(settings); freerdp_device_collection_free(settings); freerdp_static_channel_collection_free(settings);