Refactor handling of user requested window sizes
Extract ui_init_connection() into smaller functions to clarify purpose. Signed-off-by: Henrik Andersson <hean01@cendio.com> Signed-off-by: Thomas Nilefalk <thoni56@cendio.se>
This commit is contained in:
parent
884f56a8e7
commit
1f3d1fb3e0
4
proto.h
4
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);
|
||||
|
29
rdesktop.c
29
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)
|
||||
|
@ -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
|
||||
|
||||
|
17
tests/xwin_mock.c
Normal file
17
tests/xwin_mock.c
Normal file
@ -0,0 +1,17 @@
|
||||
#include <cgreen/mocks.h>
|
||||
#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);
|
||||
}
|
43
xwin.c
43
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)
|
||||
{
|
||||
g_requested_session_width = WidthOfScreen(g_screen);
|
||||
g_requested_session_height = HeightOfScreen(g_screen);
|
||||
g_using_full_workarea = True;
|
||||
*width = WidthOfScreen(g_screen);
|
||||
*height = HeightOfScreen(g_screen);
|
||||
}
|
||||
else if (g_window_size_type == PercentageOfScreen)
|
||||
|
||||
void
|
||||
ui_get_screen_size_from_percentage(uint32 pw, uint32 ph, uint32 *width, uint32 *height)
|
||||
{
|
||||
/* 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;
|
||||
uint32 sw,sh;
|
||||
ui_get_screen_size(&sw, &sh);
|
||||
*width = sw * pw / 100;
|
||||
*height = sh * ph / 100;
|
||||
}
|
||||
else if (g_window_size_type == Workarea)
|
||||
|
||||
void
|
||||
ui_get_workarea_size(uint32 *width, uint32 *height)
|
||||
{
|
||||
uint32 x, y, cx, cy;
|
||||
if (get_current_workarea(&x, &y, &cx, &cy) == 0)
|
||||
uint32 x, y, w, h;
|
||||
if (get_current_workarea(&x, &y, &w, &h) == 0)
|
||||
{
|
||||
g_requested_session_width = cx;
|
||||
g_requested_session_height = cy;
|
||||
*width = w;
|
||||
*height = h;
|
||||
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);
|
||||
}
|
||||
ui_get_screen_size(width, height);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user