Refactor g_sizeopt into an enumeration for clarity
Signed-off-by: Henrik Andersson <hean01@cendio.com> Signed-off-by: Karl Mikaelsson <derfian@cendio.se>
This commit is contained in:
parent
e2f5a7b532
commit
ba41f749c6
22
rdesktop.c
22
rdesktop.c
@ -67,10 +67,6 @@ unsigned int g_keylayout = 0x409; /* Defaults to US keyboard layout */
|
||||
int g_keyboard_type = 0x4; /* Defaults to US keyboard layout */
|
||||
int g_keyboard_subtype = 0x0; /* Defaults to US keyboard layout */
|
||||
int g_keyboard_functionkeys = 0xc; /* Defaults to US keyboard layout */
|
||||
int g_sizeopt = 0; /* If non-zero, a special size has been
|
||||
requested. If 1, the geometry will be fetched
|
||||
from _NET_WORKAREA. If negative, absolute value
|
||||
specifies the percent of the whole screen. */
|
||||
int g_dpi = 0; /* device DPI: default not set */
|
||||
|
||||
/* Following variables holds the initial width and height for a
|
||||
@ -79,6 +75,9 @@ int g_dpi = 0; /* device DPI: default not set */
|
||||
uint32 g_initial_width = 1024;
|
||||
uint32 g_initial_height = 768;
|
||||
|
||||
window_size_type_t g_window_size_type = Fixed;
|
||||
|
||||
|
||||
int g_xpos = 0;
|
||||
int g_ypos = 0;
|
||||
int g_pos = 0; /* 0 position unspecified,
|
||||
@ -602,7 +601,7 @@ int parse_geometry_string(const char *optarg)
|
||||
/* special keywords */
|
||||
if (strcmp(optarg, "workarea") == 0)
|
||||
{
|
||||
g_sizeopt = 1;
|
||||
g_window_size_type = Workarea;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -627,7 +626,7 @@ int parse_geometry_string(const char *optarg)
|
||||
|
||||
if (*ps == '%')
|
||||
{
|
||||
g_sizeopt = -1;
|
||||
g_window_size_type = PercentageOfScreen;
|
||||
ps++;
|
||||
pe++;
|
||||
}
|
||||
@ -645,13 +644,13 @@ int parse_geometry_string(const char *optarg)
|
||||
g_initial_height = value;
|
||||
ps = pe;
|
||||
|
||||
if (*ps == '%' && g_sizeopt == 0)
|
||||
if (*ps == '%' && g_window_size_type == Fixed)
|
||||
{
|
||||
logger(Core, Error, "invalid geometry, unexpected '%%' after height");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (g_sizeopt == -1)
|
||||
if (g_window_size_type == PercentageOfScreen)
|
||||
{
|
||||
if (*ps != '%')
|
||||
{
|
||||
@ -664,9 +663,9 @@ int parse_geometry_string(const char *optarg)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (g_sizeopt == -1)
|
||||
if (g_window_size_type == PercentageOfScreen)
|
||||
{
|
||||
/* same percentage of screen for both width and height */
|
||||
/* percentage of screen used for both width and height */
|
||||
g_initial_height = g_initial_width;
|
||||
}
|
||||
else
|
||||
@ -1178,7 +1177,8 @@ main(int argc, char *argv[])
|
||||
logger(Core, Error, "You cannot use -4 and -A at the same time");
|
||||
return EX_USAGE;
|
||||
}
|
||||
g_sizeopt = -100;
|
||||
|
||||
g_window_size_type = Fullscreen;
|
||||
g_grab_keyboard = False;
|
||||
}
|
||||
|
||||
|
@ -26,77 +26,78 @@ RD_BOOL g_using_full_workarea;
|
||||
|
||||
Ensure(ParseGeometry, HandlesWxH)
|
||||
{
|
||||
g_initial_width = g_initial_height = g_sizeopt = 0;
|
||||
g_initial_width = g_initial_height = 0;
|
||||
|
||||
assert_that(parse_geometry_string("1234x2345"), is_equal_to(0));
|
||||
|
||||
assert_that(g_initial_width, is_equal_to(1234));
|
||||
assert_that(g_initial_height, is_equal_to(2345));
|
||||
assert_that(g_sizeopt, is_equal_to(0));
|
||||
assert_that(g_window_size_type, is_equal_to(Fixed));
|
||||
}
|
||||
|
||||
Ensure(ParseGeometry, FailsOnMissingHeight)
|
||||
{
|
||||
|
||||
always_expect_error_log();
|
||||
|
||||
g_initial_width = g_initial_height = g_sizeopt = 0;
|
||||
g_initial_width = g_initial_height = 0;
|
||||
assert_that(parse_geometry_string("1234"), is_equal_to(-1));
|
||||
|
||||
assert_that(g_initial_width, is_equal_to(1234));
|
||||
assert_that(g_initial_height, is_equal_to(0));
|
||||
assert_that(g_sizeopt, is_equal_to(0));
|
||||
assert_that(g_window_size_type, is_equal_to(Fixed));
|
||||
}
|
||||
|
||||
Ensure(ParseGeometry, FailsOnMissingHeightVariant2)
|
||||
{
|
||||
always_expect_error_log();
|
||||
|
||||
g_initial_width = g_initial_height = g_sizeopt = 0;
|
||||
g_initial_width = g_initial_height = 0;
|
||||
assert_that(parse_geometry_string("1234x"), is_equal_to(-1));
|
||||
|
||||
assert_that(g_initial_width, is_equal_to(1234));
|
||||
assert_that(g_initial_height, is_equal_to(0));
|
||||
assert_that(g_sizeopt, is_equal_to(0));
|
||||
assert_that(g_window_size_type, is_equal_to(Fixed));
|
||||
}
|
||||
|
||||
Ensure(ParseGeometry, HandlesPercentageOfScreen)
|
||||
{
|
||||
g_initial_width = g_initial_height = g_sizeopt = 0;
|
||||
g_initial_width = g_initial_height = 0;
|
||||
|
||||
assert_that(parse_geometry_string("80%"), is_equal_to(0));
|
||||
|
||||
assert_that(g_initial_width, is_equal_to(80));
|
||||
assert_that(g_initial_height, is_equal_to(80));
|
||||
assert_that(g_sizeopt, is_equal_to(-1));
|
||||
assert_that(g_window_size_type, is_equal_to(PercentageOfScreen));
|
||||
}
|
||||
|
||||
Ensure(ParseGeometry, HandlesSpecificWidthAndHeightPercentageOfScreen)
|
||||
{
|
||||
g_initial_width = g_initial_height = g_sizeopt = 0;
|
||||
g_initial_width = g_initial_height = 0;
|
||||
|
||||
assert_that(parse_geometry_string("100%x60%"), is_equal_to(0));
|
||||
|
||||
assert_that(g_initial_width, is_equal_to(100));
|
||||
assert_that(g_initial_height, is_equal_to(60));
|
||||
assert_that(g_sizeopt, is_equal_to(-1));
|
||||
assert_that(g_window_size_type, is_equal_to(PercentageOfScreen));
|
||||
}
|
||||
|
||||
Ensure(ParseGeometry, HandlesSpecifiedDPI)
|
||||
{
|
||||
g_dpi = g_initial_width = g_initial_height = g_sizeopt = 0;
|
||||
g_dpi = g_initial_width = g_initial_height = 0;
|
||||
|
||||
assert_that(parse_geometry_string("1234x2345@234"), is_equal_to(0));
|
||||
|
||||
assert_that(g_dpi, is_equal_to(234));
|
||||
assert_that(g_initial_width, is_equal_to(1234));
|
||||
assert_that(g_initial_height, is_equal_to(2345));
|
||||
assert_that(g_sizeopt, is_equal_to(0));
|
||||
assert_that(g_window_size_type, is_equal_to(Fixed));
|
||||
}
|
||||
|
||||
|
||||
Ensure(ParseGeometry, HandlesSpecifiedXPosition)
|
||||
{
|
||||
g_xpos = g_ypos = g_initial_width = g_initial_height = g_sizeopt = 0;
|
||||
g_xpos = g_ypos = g_initial_width = g_initial_height = 0;
|
||||
|
||||
assert_that(parse_geometry_string("1234x2345+123"), is_equal_to(0));
|
||||
|
||||
@ -105,12 +106,12 @@ Ensure(ParseGeometry, HandlesSpecifiedXPosition)
|
||||
assert_that(g_pos, is_equal_to(1));
|
||||
assert_that(g_initial_width, is_equal_to(1234));
|
||||
assert_that(g_initial_height, is_equal_to(2345));
|
||||
assert_that(g_sizeopt, is_equal_to(0));
|
||||
assert_that(g_window_size_type, is_equal_to(Fixed));
|
||||
}
|
||||
|
||||
Ensure(ParseGeometry, HandlesSpecifiedNegativeXPosition)
|
||||
{
|
||||
g_ypos = g_xpos = g_initial_width = g_initial_height = g_sizeopt = 0;
|
||||
g_ypos = g_xpos = g_initial_width = g_initial_height = 0;
|
||||
|
||||
assert_that(parse_geometry_string("1234x2345-500"), is_equal_to(0));
|
||||
|
||||
@ -119,12 +120,12 @@ Ensure(ParseGeometry, HandlesSpecifiedNegativeXPosition)
|
||||
assert_that(g_pos, is_equal_to(2));
|
||||
assert_that(g_initial_width, is_equal_to(1234));
|
||||
assert_that(g_initial_height, is_equal_to(2345));
|
||||
assert_that(g_sizeopt, is_equal_to(0));
|
||||
assert_that(g_window_size_type, is_equal_to(Fixed));
|
||||
}
|
||||
|
||||
Ensure(ParseGeometry, HandlesSpecifiedNegativeXAndYPosition)
|
||||
{
|
||||
g_ypos = g_xpos = g_initial_width = g_initial_height = g_sizeopt = 0;
|
||||
g_ypos = g_xpos = g_initial_width = g_initial_height = 0;
|
||||
|
||||
assert_that(parse_geometry_string("1234x2345-500-501"), is_equal_to(0));
|
||||
|
||||
@ -133,12 +134,12 @@ Ensure(ParseGeometry, HandlesSpecifiedNegativeXAndYPosition)
|
||||
assert_that(g_pos, is_equal_to(2 | 4));
|
||||
assert_that(g_initial_width, is_equal_to(1234));
|
||||
assert_that(g_initial_height, is_equal_to(2345));
|
||||
assert_that(g_sizeopt, is_equal_to(0));
|
||||
assert_that(g_window_size_type, is_equal_to(Fixed));
|
||||
}
|
||||
|
||||
Ensure(ParseGeometry, HandlesSpecifiedXandYPosition)
|
||||
{
|
||||
g_xpos = g_ypos = g_initial_width = g_initial_height = g_sizeopt = 0;
|
||||
g_xpos = g_ypos = g_initial_width = g_initial_height = 0;
|
||||
|
||||
assert_that(parse_geometry_string("1234x2345+123+234"), is_equal_to(0));
|
||||
|
||||
@ -147,12 +148,12 @@ Ensure(ParseGeometry, HandlesSpecifiedXandYPosition)
|
||||
assert_that(g_pos, is_equal_to(1));
|
||||
assert_that(g_initial_width, is_equal_to(1234));
|
||||
assert_that(g_initial_height, is_equal_to(2345));
|
||||
assert_that(g_sizeopt, is_equal_to(0));
|
||||
assert_that(g_window_size_type, is_equal_to(Fixed));
|
||||
}
|
||||
|
||||
Ensure(ParseGeometry, HandlesSpecifiedXandYPositionWithDPI)
|
||||
{
|
||||
g_dpi = g_xpos = g_ypos = g_initial_width = g_initial_height = g_sizeopt = 0;
|
||||
g_dpi = g_xpos = g_ypos = g_initial_width = g_initial_height = 0;
|
||||
|
||||
assert_that(parse_geometry_string("1234x2345@678+123+234"), is_equal_to(0));
|
||||
|
||||
@ -161,14 +162,14 @@ Ensure(ParseGeometry, HandlesSpecifiedXandYPositionWithDPI)
|
||||
assert_that(g_ypos, is_equal_to(234));
|
||||
assert_that(g_initial_width, is_equal_to(1234));
|
||||
assert_that(g_initial_height, is_equal_to(2345));
|
||||
assert_that(g_sizeopt, is_equal_to(0));
|
||||
assert_that(g_window_size_type, is_equal_to(Fixed));
|
||||
}
|
||||
|
||||
Ensure(ParseGeometry, HandlesSpecialNameWorkarea)
|
||||
{
|
||||
assert_that(parse_geometry_string("workarea"), is_equal_to(0));
|
||||
|
||||
assert_that(g_sizeopt, is_equal_to(1));
|
||||
assert_that(g_window_size_type, is_equal_to(Workarea));
|
||||
}
|
||||
|
||||
|
||||
@ -199,10 +200,10 @@ Ensure(ParseGeometry, FailsOnMixingPixelsAndPercents)
|
||||
{
|
||||
always_expect_error_log();
|
||||
|
||||
g_sizeopt = 0;
|
||||
g_window_size_type = Fixed;
|
||||
assert_that(parse_geometry_string("1234%x2345"), is_equal_to(-1));
|
||||
|
||||
g_sizeopt = 0;
|
||||
g_window_size_type = Fixed;
|
||||
assert_that(parse_geometry_string("1234x2345%"), is_equal_to(-1));
|
||||
}
|
||||
|
||||
@ -210,19 +211,19 @@ Ensure(ParseGeometry, FailsOnGarbageAtEndOfString)
|
||||
{
|
||||
always_expect_error_log();
|
||||
|
||||
g_sizeopt = 0;
|
||||
g_window_size_type = Fixed;
|
||||
assert_that(parse_geometry_string("1234%1239123081232345abcdefgadkfjafa4af048"), is_equal_to(-1));
|
||||
|
||||
g_sizeopt = 0;
|
||||
g_window_size_type = Fixed;
|
||||
assert_that(parse_geometry_string("1235abcer9823461"), is_equal_to(-1));
|
||||
|
||||
g_sizeopt = 0;
|
||||
g_window_size_type = Fixed;
|
||||
assert_that(parse_geometry_string("1235%x123%+123123+123123asdkjfasdf"), is_equal_to(-1));
|
||||
|
||||
g_sizeopt = 0;
|
||||
g_window_size_type = Fixed;
|
||||
assert_that(parse_geometry_string("1235%x123%@123asdkjfasdf"), is_equal_to(-1));
|
||||
|
||||
g_sizeopt = 0;
|
||||
g_window_size_type = Fixed;
|
||||
assert_that(parse_geometry_string("1235%x123%@123+1-2asdkjfasdf"), is_equal_to(-1));
|
||||
}
|
||||
|
||||
|
@ -11,9 +11,9 @@ AfterEach(Resize) {};
|
||||
/* globals driven by xwin.c */
|
||||
RD_BOOL g_user_quit;
|
||||
RD_BOOL g_exit_mainloop;
|
||||
int g_sizeopt;
|
||||
uint32 g_initial_width;
|
||||
uint32 g_initial_height;
|
||||
window_size_type_t g_window_size_type;
|
||||
uint16 g_session_width;
|
||||
uint16 g_session_height;
|
||||
int g_xpos;
|
||||
|
@ -17,9 +17,9 @@ AfterEach(XWIN) {};
|
||||
RD_BOOL g_user_quit;
|
||||
RD_BOOL g_exit_mainloop;
|
||||
|
||||
int g_sizeopt;
|
||||
uint32 g_initial_width;
|
||||
uint32 g_initial_height;
|
||||
window_size_type_t g_window_size_type;
|
||||
uint16 g_session_width;
|
||||
uint16 g_session_height;
|
||||
int g_xpos;
|
||||
|
7
types.h
7
types.h
@ -308,4 +308,11 @@ FILEINFO;
|
||||
|
||||
typedef RD_BOOL(*str_handle_lines_t) (const char *line, void *data);
|
||||
|
||||
typedef enum {
|
||||
Fixed,
|
||||
PercentageOfScreen,
|
||||
Workarea,
|
||||
Fullscreen,
|
||||
} window_size_type_t;
|
||||
|
||||
#endif /* _TYPES_H */
|
||||
|
19
xwin.c
19
xwin.c
@ -45,7 +45,7 @@
|
||||
extern RD_BOOL g_user_quit;
|
||||
extern RD_BOOL g_exit_mainloop;
|
||||
|
||||
extern int g_sizeopt;
|
||||
extern window_size_type_t g_window_size_type;
|
||||
extern uint32 g_initial_width;
|
||||
extern uint32 g_initial_height;
|
||||
extern uint16 g_session_width;
|
||||
@ -1971,25 +1971,20 @@ ui_init_connection(void)
|
||||
/*
|
||||
* Determine desktop size
|
||||
*/
|
||||
if (g_fullscreen)
|
||||
if (g_fullscreen || g_window_size_type == Fullscreen)
|
||||
{
|
||||
g_initial_width = WidthOfScreen(g_screen);
|
||||
g_initial_height = HeightOfScreen(g_screen);
|
||||
g_using_full_workarea = True;
|
||||
}
|
||||
else if (g_sizeopt < 0)
|
||||
else if (g_window_size_type == PercentageOfScreen)
|
||||
{
|
||||
/* Percent of screen */
|
||||
if (-g_sizeopt >= 100)
|
||||
g_using_full_workarea = True;
|
||||
|
||||
/* g_initial_width/height holds percentage of screen in each axis */
|
||||
g_initial_height = HeightOfScreen(g_screen) * g_initial_height / 100;
|
||||
g_initial_width = WidthOfScreen(g_screen) * g_initial_width / 100;
|
||||
}
|
||||
else if (g_sizeopt == 1)
|
||||
else if (g_window_size_type == Workarea)
|
||||
{
|
||||
/* Fetch geometry from _NET_WORKAREA */
|
||||
uint32 x, y, cx, cy;
|
||||
if (get_current_workarea(&x, &y, &cx, &cy) == 0)
|
||||
{
|
||||
@ -2000,7 +1995,7 @@ ui_init_connection(void)
|
||||
else
|
||||
{
|
||||
logger(GUI, Warning,
|
||||
"Failed to get workarea: probably your window manager does not support extended hints\n");
|
||||
"Failed to get workarea: probably your window manager does not support extended hints, using full screensize as fallback\n");
|
||||
g_initial_width = WidthOfScreen(g_screen);
|
||||
g_initial_height = HeightOfScreen(g_screen);
|
||||
}
|
||||
@ -2831,7 +2826,9 @@ xwin_process_events(void)
|
||||
if (xevent.xconfigure.window == DefaultRootWindow(g_display))
|
||||
{
|
||||
/* only for fullscreen or x%-of-screen-sized windows */
|
||||
if (g_sizeopt || g_fullscreen)
|
||||
if (g_window_size_type == PercentageOfScreen
|
||||
|| g_window_size_type == Fullscreen
|
||||
|| g_fullscreen)
|
||||
{
|
||||
if (xevent.xconfigure.width != WidthOfScreen(g_screen)
|
||||
|| xevent.xconfigure.height != HeightOfScreen(g_screen))
|
||||
|
Loading…
Reference in New Issue
Block a user