forked from jordansissel/xdotool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_set_window.c
104 lines (94 loc) · 3.17 KB
/
cmd_set_window.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#define _GNU_SOURCE 1
#ifndef __USE_BSD
#define __USE_BSD /* for strdup on linux/glibc */
#endif /* __USE_BSD */
#include <string.h>
#include "xdo_cmd.h"
int cmd_set_window(context_t *context) {
char *cmd = *context->argv;
int c;
char *role = NULL, *icon = NULL, *name = NULL, *_class = NULL,
*classname = NULL;
int override_redirect = -1;
int urgency = -1;
const char *window_arg = "%1";
struct option longopts[] = {
{ "name", required_argument, NULL, 'n' },
{ "icon-name", required_argument, NULL, 'i' },
{ "role", required_argument, NULL, 'r' },
{ "class", required_argument, NULL, 'C' },
{ "classname", required_argument, NULL, 'N' },
{ "overrideredirect", required_argument, NULL, 'O' },
{ "urgency", required_argument, NULL, 'u' },
{ "help", no_argument, NULL, 'h' },
{ 0, 0, 0, 0 },
};
int option_index;
static const char *usage =
"Usage: %s [options] [window=%1]\n"
"--name NAME - set the window name (aka title)\n"
"--icon-name NAME - set the window name while minimized/iconified\n"
"--role ROLE - set the window's role string\n"
"--class CLASS - set the window's class\n"
"--classname CLASSNAME - set the window's classname\n"
"--overrideredirect OVERRIDE - set override_redirect.\n"
" 1 means the window manager will not manage this window.\n"
"--urgency URGENT - set the window's urgency hint.\n"
" 1 sets the urgency flag, 0 removes it.\n";
while ((c = getopt_long_only(context->argc, context->argv, "+hn:i:r:C:N:u:",
longopts, &option_index)) != -1) {
switch(c) {
case 'n':
name = strdup(optarg);
break;
case 'i':
icon = strdup(optarg);
break;
case 'r':
role = strdup(optarg);
break;
case 'C':
_class = strdup(optarg);
break;
case 'N':
classname = strdup(optarg);
break;
case 'O':
override_redirect = (atoi(optarg) > 0);
break;
case 'u':
urgency = (atoi(optarg) > 0);
break;
case 'h':
printf(usage, cmd);
consume_args(context, context->argc);
return EXIT_SUCCESS;
default:
fprintf(stderr, usage, cmd);
return EXIT_FAILURE;
}
}
/* adjust context->argc, argv */
consume_args(context, optind);
if (!window_get_arg(context, 0, 0, &window_arg)) {
fprintf(stderr, usage, cmd);
return EXIT_FAILURE;
}
/* TODO(sissel): error handling needed... */
window_each(context, window_arg, {
if (name)
xdo_set_window_property(context->xdo, window, "WM_NAME", name);
if (icon)
xdo_set_window_property(context->xdo, window, "WM_ICON_NAME", icon);
if (role)
xdo_set_window_property(context->xdo, window, "WM_WINDOW_ROLE", role);
if (classname || _class)
xdo_set_window_class(context->xdo, window, classname, _class);
if (override_redirect != -1)
xdo_set_window_override_redirect(context->xdo, window,
override_redirect);
if (urgency != -1)
xdo_set_window_urgency(context->xdo, window, urgency);
}); /* window_each(...) */
return 0;
}