-
Notifications
You must be signed in to change notification settings - Fork 321
/
cmd_get_display_geometry.c
56 lines (48 loc) · 1.41 KB
/
cmd_get_display_geometry.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "xdo_cmd.h"
int cmd_get_display_geometry(context_t *context) {
int ret = 0;
char *cmd = context->argv[0];
int c;
int screen = DefaultScreen(context->xdo->xdpy);
int shell_output = False;
enum { opt_unused, opt_help, opt_screen, opt_shell };
static struct option longopts[] = {
{ "help", no_argument, NULL, opt_help },
{ "screen", required_argument, NULL, opt_screen },
{ "shell", no_argument, NULL, opt_shell },
{ 0, 0, 0, 0 },
};
static const char *usage = "Usage: %s\n";
int option_index;
while ((c = getopt_long_only(context->argc, context->argv, "+h",
longopts, &option_index)) != -1) {
switch (c) {
case 'h':
case opt_help:
printf(usage, cmd);
consume_args(context, context->argc);
return EXIT_SUCCESS;
break;
case opt_screen:
screen = atoi(optarg);
break;
case opt_shell:
shell_output = True;
break;
default:
fprintf(stderr, usage, cmd);
return EXIT_FAILURE;
}
}
consume_args(context, optind);
unsigned int width = 0;
unsigned int height = 0;
ret = xdo_get_viewport_dimensions(context->xdo, &width, &height, screen);
if (shell_output) {
xdotool_output(context, "WIDTH=%d", width);
xdotool_output(context, "HEIGHT=%d", height);
} else {
xdotool_output(context, "%d %d", width, height);
}
return ret;
}