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 */
|
/* xwin.c */
|
||||||
RD_BOOL get_key_state(unsigned int state, uint32 keysym);
|
RD_BOOL get_key_state(unsigned int state, uint32 keysym);
|
||||||
RD_BOOL ui_init(void);
|
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);
|
void ui_deinit(void);
|
||||||
RD_BOOL ui_create_window(uint32 width, uint32 height);
|
RD_BOOL ui_create_window(uint32 width, uint32 height);
|
||||||
void ui_resize_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;
|
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 */
|
/* Client program */
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
@ -1297,7 +1323,8 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
dvc_init();
|
dvc_init();
|
||||||
rdpedisp_init();
|
rdpedisp_init();
|
||||||
ui_init_connection();
|
|
||||||
|
setup_user_requested_session_size();
|
||||||
|
|
||||||
g_reconnect_loop = False;
|
g_reconnect_loop = False;
|
||||||
while (1)
|
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 \
|
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 \
|
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
|
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);
|
||||||
|
}
|
51
xwin.c
51
xwin.c
@ -1961,44 +1961,37 @@ ui_init(void)
|
|||||||
return True;
|
return True;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
Initialize connection specific data, such as initial session size.
|
|
||||||
*/
|
|
||||||
void
|
void
|
||||||
ui_init_connection(void)
|
ui_get_screen_size(uint32 *width, uint32 *height)
|
||||||
{
|
{
|
||||||
/*
|
*width = WidthOfScreen(g_screen);
|
||||||
* Determine desktop size
|
*height = HeightOfScreen(g_screen);
|
||||||
*/
|
}
|
||||||
if (g_window_size_type == Fullscreen)
|
|
||||||
|
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);
|
*width = w;
|
||||||
g_requested_session_height = HeightOfScreen(g_screen);
|
*height = h;
|
||||||
g_using_full_workarea = True;
|
|
||||||
}
|
|
||||||
else if (g_window_size_type == PercentageOfScreen)
|
|
||||||
{
|
|
||||||
/* 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;
|
g_using_full_workarea = True;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logger(GUI, Warning,
|
logger(GUI, Warning,
|
||||||
"Failed to get workarea: probably your window manager does not support extended hints, using full screensize as fallback\n");
|
"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);
|
ui_get_screen_size(width, height);
|
||||||
g_requested_session_height = HeightOfScreen(g_screen);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user