Skip to content

Commit e2057b4

Browse files
Dominic Mdominic
Dominic M
and
dominic
authored
Added command getwindowclassname (#247)
Co-authored-by: dominic <[email protected]>
1 parent 7141bfd commit e2057b4

File tree

5 files changed

+58
-1
lines changed

5 files changed

+58
-1
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ CMDOBJS= cmd_click.o cmd_mousemove.o cmd_mousemove_relative.o cmd_mousedown.o \
4949
cmd_set_desktop_for_window.o cmd_get_desktop_for_window.o \
5050
cmd_get_desktop_viewport.o cmd_set_desktop_viewport.o \
5151
cmd_windowkill.o cmd_behave.o cmd_window_select.o \
52-
cmd_getwindowname.o cmd_behave_screen_edge.o \
52+
cmd_getwindowname.o cmd_getwindowclassname.o cmd_behave_screen_edge.o \
5353
cmd_windowminimize.o cmd_exec.o cmd_getwindowgeometry.o \
5454
cmd_windowclose.o cmd_windowquit.o \
5555
cmd_sleep.o cmd_get_display_geometry.o

cmd_getwindowclassname.c

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include "xdo_cmd.h"
2+
3+
int cmd_getwindowclassname(context_t *context) {
4+
char *cmd = context->argv[0];
5+
6+
int c;
7+
static struct option longopts[] = {
8+
{ "help", no_argument, NULL, 'h' },
9+
{ 0, 0, 0, 0 },
10+
};
11+
static const char *usage =
12+
"Usage: %s [window=%1]\n"
13+
HELP_SEE_WINDOW_STACK;
14+
int option_index;
15+
16+
while ((c = getopt_long_only(context->argc, context->argv, "+h",
17+
longopts, &option_index)) != -1) {
18+
switch (c) {
19+
case 'h':
20+
printf(usage, cmd);
21+
consume_args(context, context->argc);
22+
return EXIT_SUCCESS;
23+
break;
24+
default:
25+
fprintf(stderr, usage, cmd);
26+
return EXIT_FAILURE;
27+
}
28+
}
29+
30+
consume_args(context, optind);
31+
32+
const char *window_arg = "%1";
33+
if (!window_get_arg(context, 0, 0, &window_arg)) {
34+
fprintf(stderr, usage, cmd);
35+
return EXIT_FAILURE;
36+
}
37+
38+
unsigned char *name;
39+
40+
window_each(context, window_arg, {
41+
xdo_get_window_classname(context->xdo, window, &name);
42+
xdotool_output(context, "%s", name);
43+
XFree(name);
44+
}); /* window_each(...) */
45+
return EXIT_SUCCESS;
46+
}
47+

xdo.c

+8
Original file line numberDiff line numberDiff line change
@@ -1915,6 +1915,14 @@ int xdo_get_window_name(const xdo_t *xdo, Window window,
19151915
return 0;
19161916
}
19171917

1918+
int xdo_get_window_classname(const xdo_t *xdo, Window window, unsigned char **name_ret) {
1919+
XClassHint classhint;
1920+
XGetClassHint(xdo->xdpy, window, &classhint);
1921+
XFree(classhint.res_name);
1922+
*name_ret = (char*) classhint.res_class;
1923+
return 0;
1924+
}
1925+
19181926
int xdo_window_state(xdo_t *xdo, Window window, unsigned long action, const char *property) {
19191927
int ret;
19201928
XEvent xev;

xdotool.c

+1
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ struct dispatch {
220220
{ "getactivewindow", cmd_getactivewindow, },
221221
{ "getwindowfocus", cmd_getwindowfocus, },
222222
{ "getwindowname", cmd_getwindowname, },
223+
{ "getwindowclassname", cmd_getwindowclassname},
223224
{ "getwindowpid", cmd_getwindowpid, },
224225
{ "getwindowgeometry", cmd_getwindowgeometry, },
225226
{ "getdisplaygeometry", cmd_get_display_geometry, },

xdotool.h

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ int cmd_getactivewindow(context_t *context);
4949
int cmd_getmouselocation(context_t *context);
5050
int cmd_getwindowfocus(context_t *context);
5151
int cmd_getwindowname(context_t *context);
52+
int cmd_getwindowclassname(context_t *context);
5253
int cmd_getwindowpid(context_t *context);
5354
int cmd_getwindowgeometry(context_t *context);
5455
int cmd_help(context_t *context);

0 commit comments

Comments
 (0)