Skip to content

Commit b11bd2f

Browse files
committed
fix: Missing percentage precision for window size #[488]
Use strtod() instead of strtoul() for percentage parsing, and the window size should be calculated using a percentage value if a percentage is specified. other changes: Fix argument count validation error message. Fixes #[#488]
1 parent 4a2f1f8 commit b11bd2f

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

cmd_windowsize.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
int cmd_windowsize(context_t *context) {
55
int ret = 0;
66
unsigned int width, height;
7+
double width_percent, height_percent;
78
int is_width_percent = 0, is_height_percent = 0;
89
int c;
910
int opsync = 0;
@@ -53,8 +54,8 @@ int cmd_windowsize(context_t *context) {
5354
const char *window_arg = "%1";
5455

5556
if (!window_get_arg(context, 2, 0, &window_arg)) {
56-
fprintf(stderr, "Invalid argument count, got %d, expected %d\n",
57-
3, context->argc);
57+
fprintf(stderr, "Invalid argument count, got %d, expected %d\n",
58+
context->argc - optind, 2);
5859
fprintf(stderr, usage, cmd);
5960
return EXIT_FAILURE;
6061
}
@@ -77,8 +78,12 @@ int cmd_windowsize(context_t *context) {
7778
}
7879
}
7980

80-
width = (unsigned int)strtoul(context->argv[0], NULL, 0);
81-
height = (unsigned int)strtoul(context->argv[1], NULL, 0);
81+
width_percent = strtod(context->argv[0], NULL);
82+
height_percent = strtod(context->argv[1], NULL);
83+
84+
width = (unsigned int)width_percent;
85+
height = (unsigned int)height_percent;
86+
8287
consume_args(context, 2);
8388

8489
XWindowAttributes wattr;
@@ -93,11 +98,11 @@ int cmd_windowsize(context_t *context) {
9398
xdo_get_window_size(context->xdo, root, &root_w, &root_h);
9499

95100
if (is_width_percent) {
96-
width = (root_w * width / 100);
101+
width = (unsigned int)(root_w * width_percent / 100.0 + 0.5);
97102
}
98103

99104
if (is_height_percent) {
100-
height = (root_h * height / 100);
105+
height = (unsigned int)(root_h * height_percent / 100.0 + 0.5);
101106
}
102107
}
103108

0 commit comments

Comments
 (0)