From: Armin Novak Date: Wed, 21 Nov 2018 08:49:50 +0000 (+0100) Subject: Fixed #5040: Unified xfreerdp window title setting. X-Git-Tag: 2.0.0~593^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=594d10620e8a7feb50b702c8811c7866eb3e242d;p=platform%2Fupstream%2Ffreerdp.git Fixed #5040: Unified xfreerdp window title setting. --- diff --git a/client/X11/xf_client.c b/client/X11/xf_client.c index d6bb2a8..455f41a 100644 --- a/client/X11/xf_client.c +++ b/client/X11/xf_client.c @@ -501,6 +501,37 @@ static BOOL xf_process_x_events(freerdp* instance) return status; } +static char* xf_window_get_title(rdpSettings* settings) +{ + BOOL port; + char* windowTitle; + size_t size; + char* name; + const char* prefix = "FreeRDP:"; + + if (!settings) + return NULL; + + name = settings->ServerHostname; + + if (settings->WindowTitle) + return _strdup(settings->WindowTitle); + + port = (settings->ServerPort != 3389); + size = strlen(name) + 16; + windowTitle = calloc(size, sizeof(char)); + + if (!windowTitle) + return NULL; + + if (!port) + sprintf_s(windowTitle, size, "%s %s", prefix, name); + else + sprintf_s(windowTitle, size, "%s %s:%i", prefix, name, settings->ServerPort); + + return windowTitle; +} + BOOL xf_create_window(xfContext* xfc) { XGCValues gcv; @@ -532,37 +563,10 @@ BOOL xf_create_window(xfContext* xfc) xfc->offset_x = 0; xfc->offset_y = 0; #endif + windowTitle = xf_window_get_title(settings); - if (settings->WindowTitle) - { - windowTitle = _strdup(settings->WindowTitle); - - if (!windowTitle) - return FALSE; - } - else if (settings->ServerPort == 3389) - { - size_t size = 1 + sizeof("FreeRDP: ") + strlen( - settings->ServerHostname); - windowTitle = malloc(size); - - if (!windowTitle) - return FALSE; - - sprintf_s(windowTitle, size, "FreeRDP: %s", settings->ServerHostname); - } - else - { - size_t size = 1 + sizeof("FreeRDP: ") + strlen(settings->ServerHostname) - + sizeof(":00000"); - windowTitle = malloc(size); - - if (!windowTitle) - return FALSE; - - sprintf_s(windowTitle, size, "FreeRDP: %s:%i", settings->ServerHostname, - settings->ServerPort); - } + if (!windowTitle) + return FALSE; #ifdef WITH_XRENDER diff --git a/client/X11/xf_floatbar.c b/client/X11/xf_floatbar.c index 5188c0f..d3d9b2c 100644 --- a/client/X11/xf_floatbar.c +++ b/client/X11/xf_floatbar.c @@ -78,6 +78,7 @@ struct xf_floatbar DWORD flags; BOOL created; Window root_window; + char* title; }; struct xf_floatbar_button @@ -296,7 +297,7 @@ xfFloatbarButton* xf_floatbar_new_button(xfFloatbar* floatbar, int type) return button; } -xfFloatbar* xf_floatbar_new(xfContext* xfc, Window window, DWORD flags) +xfFloatbar* xf_floatbar_new(xfContext* xfc, Window window, const char* name, DWORD flags) { xfFloatbar* floatbar; @@ -316,12 +317,20 @@ xfFloatbar* xf_floatbar_new(xfContext* xfc, Window window, DWORD flags) if (!floatbar) return NULL; + floatbar->title = _strdup(name); + + if (!floatbar->title) + goto fail; + floatbar->root_window = window; floatbar->flags = flags; floatbar->xfc = xfc; floatbar->locked = flags & 0x0002; xf_floatbar_toggle_fullscreen(floatbar, FALSE); return floatbar; +fail: + xf_floatbar_free(floatbar); + return NULL; } static unsigned long xf_floatbar_get_color(xfFloatbar* floatbar, char* rgb_value) @@ -342,7 +351,6 @@ static void xf_floatbar_event_expose(xfFloatbar* floatbar, XEvent* event) Pixmap pmap; XPoint shape[5], border[5]; int len; - rdpSettings* settings = floatbar->xfc->context.settings; Display* display = floatbar->xfc->display; /* create the pixmap that we'll use for shaping the window */ pmap = XCreatePixmap(display, floatbar->handle, floatbar->width, floatbar->height, 1); @@ -385,10 +393,10 @@ static void xf_floatbar_event_expose(xfFloatbar* floatbar, XEvent* event) XSetForeground(display, gc, xf_floatbar_get_color(floatbar, FLOATBAR_COLOR_BORDER)); XDrawLines(display, floatbar->handle, gc, border, 5, CoordModeOrigin); /* draw the host name connected to */ - len = strlen(settings->ServerHostname); + len = strlen(floatbar->title); XSetForeground(display, gc, xf_floatbar_get_color(floatbar, FLOATBAR_COLOR_FOREGROUND)); XDrawString(display, floatbar->handle, gc, floatbar->width / 2 - len * 2, 15, - settings->ServerHostname, len); + floatbar->title, len); XFreeGC(display, gc); XFreeGC(display, shape_gc); } @@ -785,6 +793,7 @@ void xf_floatbar_free(xfFloatbar* floatbar) if (!floatbar) return; + free(floatbar->title); xfc = floatbar->xfc; size = ARRAYSIZE(floatbar->buttons); diff --git a/client/X11/xf_floatbar.h b/client/X11/xf_floatbar.h index be92642..42ab5f3 100644 --- a/client/X11/xf_floatbar.h +++ b/client/X11/xf_floatbar.h @@ -22,7 +22,7 @@ typedef struct xf_floatbar xfFloatbar; #include "xfreerdp.h" -xfFloatbar* xf_floatbar_new(xfContext* xfc, Window window, DWORD flags); +xfFloatbar* xf_floatbar_new(xfContext* xfc, Window window, const char* title, DWORD flags); void xf_floatbar_free(xfFloatbar* floatbar); BOOL xf_floatbar_event_process(xfFloatbar* floatbar, XEvent* event); diff --git a/client/X11/xf_window.c b/client/X11/xf_window.c index 4e1d2b0..83306f0 100644 --- a/client/X11/xf_window.c +++ b/client/X11/xf_window.c @@ -585,7 +585,7 @@ xfWindow* xf_CreateDesktopWindow(xfContext* xfc, char* name, int width, settings->DesktopPosY); } - window->floatbar = xf_floatbar_new(xfc, window->handle, settings->Floatbar); + window->floatbar = xf_floatbar_new(xfc, window->handle, name, settings->Floatbar); return window; }