diff --git a/proto.h b/proto.h index addc6fd..7d54e93 100644 --- a/proto.h +++ b/proto.h @@ -257,7 +257,9 @@ void rdp_send_scancode(uint32 time, uint16 flags, uint8 scancode); /* xwin.c */ RD_BOOL get_key_state(unsigned int state, uint32 keysym); RD_BOOL ui_init(void); -void ui_init_connection(void); +void ui_get_screen_size(uint32 *width, uint32 *height); +void ui_get_screen_size_from_percentage(uint32 pw, uint32 ph, uint32 *width, uint32 *height); +void ui_get_workarea_size(uint32 *width, uint32 *height); void ui_deinit(void); RD_BOOL ui_create_window(uint32 width, uint32 height); void ui_resize_window(uint32 width, uint32 height); diff --git a/rdesktop.c b/rdesktop.c index 9ec06a2..298b2b6 100644 --- a/rdesktop.c +++ b/rdesktop.c @@ -729,6 +729,32 @@ int parse_geometry_string(const char *optarg) return 0; } +static void +setup_user_requested_session_size() +{ + switch(g_window_size_type) + { + case Fullscreen: + ui_get_screen_size(&g_requested_session_width, &g_requested_session_height); + break; + + case Workarea: + ui_get_workarea_size(&g_requested_session_width, &g_requested_session_height); + break; + + case Fixed: + break; + + case PercentageOfScreen: + ui_get_screen_size_from_percentage(g_requested_session_width, + g_requested_session_height, + &g_requested_session_width, + &g_requested_session_height); + break; + } +} + + /* Client program */ int main(int argc, char *argv[]) @@ -1297,7 +1323,8 @@ main(int argc, char *argv[]) dvc_init(); rdpedisp_init(); - ui_init_connection(); + + setup_user_requested_session_size(); g_reconnect_loop = False; while (1) diff --git a/tests/Makefile b/tests/Makefile index d131181..f7b39c8 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -21,7 +21,7 @@ RESIZE_MOCKS=x11_mock.o cache_mock.o xclip_mock.o xkeymap_mock.o seamless_mock.o PARSE_MOCKS=ui_mock.o rdpdr_mock.o rdpedisp_mock.o ssl_mock.o ctrl_mock.o secure_mock.o \ tcp_mock.o dvc_mock.o rdp_mock.o cache_mock.o cliprdr_mock.o disk_mock.o lspci_mock.o \ - parallel_mock.o printer_mock.o serial_mock.o xkeymap_mock.o utils_mock.o + parallel_mock.o printer_mock.o serial_mock.o xkeymap_mock.o utils_mock.o xwin_mock.o all: test diff --git a/tests/xwin_mock.c b/tests/xwin_mock.c new file mode 100644 index 0000000..6f84821 --- /dev/null +++ b/tests/xwin_mock.c @@ -0,0 +1,17 @@ +#include +#include "../rdesktop.h" + +void ui_get_screen_size(uint32 *width, uint32 *height) +{ + mock(width, height); +} + +void ui_get_screen_size_from_percentage(uint32 pw, uint32 ph, uint32 *width, uint32 *height) +{ + mock(pw, ph, width, height); +} + +void ui_get_workarea_size(uint32 *width, uint32 *height) +{ + mock(width, height); +} diff --git a/xwin.c b/xwin.c index bed4635..07e4932 100644 --- a/xwin.c +++ b/xwin.c @@ -1961,44 +1961,37 @@ ui_init(void) return True; } - -/* - Initialize connection specific data, such as initial session size. - */ void -ui_init_connection(void) +ui_get_screen_size(uint32 *width, uint32 *height) { - /* - * Determine desktop size - */ - if (g_window_size_type == Fullscreen) + *width = WidthOfScreen(g_screen); + *height = HeightOfScreen(g_screen); +} + +void +ui_get_screen_size_from_percentage(uint32 pw, uint32 ph, uint32 *width, uint32 *height) +{ + uint32 sw,sh; + ui_get_screen_size(&sw, &sh); + *width = sw * pw / 100; + *height = sh * ph / 100; +} + +void +ui_get_workarea_size(uint32 *width, uint32 *height) +{ + uint32 x, y, w, h; + if (get_current_workarea(&x, &y, &w, &h) == 0) { - g_requested_session_width = WidthOfScreen(g_screen); - g_requested_session_height = HeightOfScreen(g_screen); + *width = w; + *height = h; g_using_full_workarea = True; } - else if (g_window_size_type == PercentageOfScreen) + else { - /* g_requested_session_width/height holds percentage of screen in each axis */ - g_requested_session_height = HeightOfScreen(g_screen) * g_requested_session_height / 100; - g_requested_session_width = WidthOfScreen(g_screen) * g_requested_session_width / 100; - } - else if (g_window_size_type == Workarea) - { - uint32 x, y, cx, cy; - if (get_current_workarea(&x, &y, &cx, &cy) == 0) - { - g_requested_session_width = cx; - g_requested_session_height = cy; - g_using_full_workarea = True; - } - else - { - logger(GUI, Warning, - "Failed to get workarea: probably your window manager does not support extended hints, using full screensize as fallback\n"); - g_requested_session_width = WidthOfScreen(g_screen); - g_requested_session_height = HeightOfScreen(g_screen); - } + logger(GUI, Warning, + "Failed to get workarea: probably your window manager does not support extended hints, using full screensize as fallback\n"); + ui_get_screen_size(width, height); } }