Merge pull request #5018 from hardening/windowpos

cmdline: add window-position argument to set initial window position
This commit is contained in:
Bernhard Miklautz 2018-11-15 16:46:57 +00:00 committed by GitHub
commit fe1a79759e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 78 additions and 58 deletions

View File

@ -173,8 +173,8 @@ void xf_SetWindowFullscreen(xfContext* xfc, xfWindow* window, BOOL fullscreen)
xfc->savedHeight = xfc->window->height;
xfc->savedPosX = xfc->window->left;
xfc->savedPosY = xfc->window->top;
startX = settings->DesktopPosX;
startY = settings->DesktopPosY;
startX = (settings->DesktopPosX != UINT32_MAX) ? settings->DesktopPosX : 0;
startY = (settings->DesktopPosY != UINT32_MAX) ? settings->DesktopPosY : 0;
}
else
{
@ -580,7 +580,7 @@ xfWindow* xf_CreateDesktopWindow(xfContext* xfc, char* name, int width,
{
XMoveWindow(xfc->display, window->handle, 0, 0);
}
else if (settings->DesktopPosX || settings->DesktopPosY)
else if (settings->DesktopPosX != UINT32_MAX && settings->DesktopPosY != UINT32_MAX)
{
XMoveWindow(xfc->display, window->handle, settings->DesktopPosX,
settings->DesktopPosY);

View File

@ -220,6 +220,7 @@ static int freerdp_client_command_line_pre_filter(void* context, int index,
return 0;
}
BOOL freerdp_client_add_device_channel(rdpSettings* settings, int count,
char** params)
{
@ -1315,6 +1316,45 @@ static void activate_smartcard_logon_rdp(rdpSettings* settings)
freerdp_set_param_bool(settings, FreeRDP_PasswordIsSmartcardPin, TRUE);
}
/**
* parses a string value with the format <v1>x<v2>
* @param input: input string
* @param v1: pointer to output v1
* @param v2: pointer to output v2
* @return if the parsing was successful
*/
static BOOL parseSizeValue(const char *input, unsigned long *v1, unsigned long *v2)
{
const char *xcharpos;
char *endPtr;
unsigned long v;
errno = 0;
v = strtoul(input, &endPtr, 10);
if ((v == 0 || v == ULONG_MAX) && (errno != 0))
return FALSE;
if (v1)
*v1 = v;
xcharpos = strchr(input, 'x');
if (!xcharpos || xcharpos != endPtr)
return FALSE;
errno = 0;
v = strtoul(xcharpos + 1, &endPtr, 10);
if ((v == 0 || v == ULONG_MAX) && (errno != 0))
return FALSE;
if (*endPtr != '\0')
return FALSE;
if (v2)
*v2 = v;
return TRUE;
}
int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
int argc, char** argv, BOOL allowUnknown)
{
@ -1536,39 +1576,23 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
}
CommandLineSwitchCase(arg, "size")
{
if (!(str = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
p = strchr(str, 'x');
p = strchr(arg->Value, 'x');
if (p)
{
*p = '\0';
{
long val = strtol(str, NULL, 0);
unsigned long w, h;
if (!parseSizeValue(arg->Value, &w, &h) || (w > UINT16_MAX) || (h > UINT16_MAX))
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
if ((errno != 0) || (val <= 0) || (val > UINT16_MAX))
{
free(str);
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
}
settings->DesktopWidth = val;
}
{
long val = strtol(&p[1], NULL, 0);
if ((errno != 0) || (val <= 0) || (val > UINT16_MAX))
{
free(str);
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
}
settings->DesktopHeight = val;
}
settings->DesktopWidth = w;
settings->DesktopHeight = h;
}
else
{
if (!(str = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
p = strchr(str, '%');
if (p)
@ -1606,9 +1630,9 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
settings->PercentScreen = val;
}
}
}
free(str);
free(str);
}
}
CommandLineSwitchCase(arg, "f")
{
@ -1700,34 +1724,13 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
if (arg->Value)
{
if (!(str = _strdup(arg->Value)))
return COMMAND_LINE_ERROR_MEMORY;
unsigned long w, h;
if ((p = strchr(str, 'x')))
{
unsigned long w, h;
*p = '\0';
w = strtoul(str, NULL, 0);
if (!parseSizeValue(arg->Value, &w, &h) || (w > UINT16_MAX) || (h > UINT16_MAX))
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
if ((errno != 0) || (w == 0) || (w > UINT16_MAX))
{
free(str);
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
}
h = strtoul(&p[1], NULL, 0);
if ((errno != 0) || (h == 0) || (h > UINT16_MAX))
{
free(str);
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
}
settings->SmartSizingWidth = w;
settings->SmartSizingHeight = h;
}
free(str);
settings->SmartSizingWidth = w;
settings->SmartSizingHeight = h;
}
}
CommandLineSwitchCase(arg, "bpp")
@ -2192,6 +2195,22 @@ int freerdp_client_settings_parse_command_line_arguments(rdpSettings* settings,
{
settings->DisableFullWindowDrag = !enable;
}
CommandLineSwitchCase(arg, "window-position")
{
unsigned long x, y;
if (!arg->Value)
return COMMAND_LINE_ERROR_MISSING_ARGUMENT;
if (!parseSizeValue(arg->Value, &x, &y) || x > UINT16_MAX || y > UINT16_MAX)
{
WLog_ERR(TAG, "invalid window-position argument");
return COMMAND_LINE_ERROR_MISSING_ARGUMENT;
}
settings->DesktopPosX = x;
settings->DesktopPosY = y;
}
CommandLineSwitchCase(arg, "menu-anims")
{
settings->DisableMenuAnims = !enable;

View File

@ -182,6 +182,7 @@ static COMMAND_LINE_ARGUMENT_A args[] =
{ "w", COMMAND_LINE_VALUE_REQUIRED, "<width>", "1024", NULL, -1, NULL, "Width" },
{ "wallpaper", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueTrue, NULL, -1, NULL, "wallpaper" },
{ "window-drag", COMMAND_LINE_VALUE_BOOL, NULL, BoolValueFalse, NULL, -1, NULL, "full window drag" },
{ "window-position", COMMAND_LINE_VALUE_REQUIRED, "<xpos>x<ypos>", NULL, NULL, -1, NULL, "window position" },
{ "wm-class", COMMAND_LINE_VALUE_REQUIRED, "<class-name>", NULL, NULL, -1, NULL, "Set the WM_CLASS hint for the window instance" },
{ "workarea", COMMAND_LINE_VALUE_FLAG, NULL, NULL, NULL, -1, NULL, "Use available work area" },
{ NULL, 0, NULL, NULL, NULL, -1, NULL, NULL }

View File

@ -320,8 +320,8 @@ rdpSettings* freerdp_settings_new(DWORD flags)
settings->DesktopResize = TRUE;
settings->ToggleFullscreen = TRUE;
settings->Floatbar = TRUE;
settings->DesktopPosX = 0;
settings->DesktopPosY = 0;
settings->DesktopPosX = UINT32_MAX;
settings->DesktopPosY = UINT32_MAX;
settings->SoftwareGdi = TRUE;
settings->UnmapButtons = FALSE;
settings->PerformanceFlags = PERF_FLAG_NONE;