Skip to content

Commit

Permalink
Added command getwindowclassname (jordansissel#247)
Browse files Browse the repository at this point in the history
Co-authored-by: dominic <[email protected]>
  • Loading branch information
Dominic M and dominic committed Feb 13, 2021
1 parent 7141bfd commit e2057b4
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ CMDOBJS= cmd_click.o cmd_mousemove.o cmd_mousemove_relative.o cmd_mousedown.o \
cmd_set_desktop_for_window.o cmd_get_desktop_for_window.o \
cmd_get_desktop_viewport.o cmd_set_desktop_viewport.o \
cmd_windowkill.o cmd_behave.o cmd_window_select.o \
cmd_getwindowname.o cmd_behave_screen_edge.o \
cmd_getwindowname.o cmd_getwindowclassname.o cmd_behave_screen_edge.o \
cmd_windowminimize.o cmd_exec.o cmd_getwindowgeometry.o \
cmd_windowclose.o cmd_windowquit.o \
cmd_sleep.o cmd_get_display_geometry.o
Expand Down
47 changes: 47 additions & 0 deletions cmd_getwindowclassname.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include "xdo_cmd.h"

int cmd_getwindowclassname(context_t *context) {
char *cmd = context->argv[0];

int c;
static struct option longopts[] = {
{ "help", no_argument, NULL, 'h' },
{ 0, 0, 0, 0 },
};
static const char *usage =
"Usage: %s [window=%1]\n"
HELP_SEE_WINDOW_STACK;
int option_index;

while ((c = getopt_long_only(context->argc, context->argv, "+h",
longopts, &option_index)) != -1) {
switch (c) {
case 'h':
printf(usage, cmd);
consume_args(context, context->argc);
return EXIT_SUCCESS;
break;
default:
fprintf(stderr, usage, cmd);
return EXIT_FAILURE;
}
}

consume_args(context, optind);

const char *window_arg = "%1";
if (!window_get_arg(context, 0, 0, &window_arg)) {
fprintf(stderr, usage, cmd);
return EXIT_FAILURE;
}

unsigned char *name;

window_each(context, window_arg, {
xdo_get_window_classname(context->xdo, window, &name);
xdotool_output(context, "%s", name);
XFree(name);
}); /* window_each(...) */
return EXIT_SUCCESS;
}

8 changes: 8 additions & 0 deletions xdo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1915,6 +1915,14 @@ int xdo_get_window_name(const xdo_t *xdo, Window window,
return 0;
}

int xdo_get_window_classname(const xdo_t *xdo, Window window, unsigned char **name_ret) {
XClassHint classhint;
XGetClassHint(xdo->xdpy, window, &classhint);
XFree(classhint.res_name);
*name_ret = (char*) classhint.res_class;
return 0;
}

int xdo_window_state(xdo_t *xdo, Window window, unsigned long action, const char *property) {
int ret;
XEvent xev;
Expand Down
1 change: 1 addition & 0 deletions xdotool.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ struct dispatch {
{ "getactivewindow", cmd_getactivewindow, },
{ "getwindowfocus", cmd_getwindowfocus, },
{ "getwindowname", cmd_getwindowname, },
{ "getwindowclassname", cmd_getwindowclassname},
{ "getwindowpid", cmd_getwindowpid, },
{ "getwindowgeometry", cmd_getwindowgeometry, },
{ "getdisplaygeometry", cmd_get_display_geometry, },
Expand Down
1 change: 1 addition & 0 deletions xdotool.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ int cmd_getactivewindow(context_t *context);
int cmd_getmouselocation(context_t *context);
int cmd_getwindowfocus(context_t *context);
int cmd_getwindowname(context_t *context);
int cmd_getwindowclassname(context_t *context);
int cmd_getwindowpid(context_t *context);
int cmd_getwindowgeometry(context_t *context);
int cmd_help(context_t *context);
Expand Down

0 comments on commit e2057b4

Please sign in to comment.