Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend xdotool with getwindowstacklen command. #144

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_getwindowstacklen.o cmd_behave_screen_edge.o \
cmd_windowminimize.o cmd_exec.o cmd_getwindowgeometry.o \
cmd_windowclose.o \
cmd_sleep.o cmd_get_display_geometry.o
Expand Down
36 changes: 36 additions & 0 deletions cmd_getwindowstacklen.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "xdo_cmd.h"

int cmd_getwindowstacklen(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 \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);
xdotool_output(context, "stack_length:%i", context->nwindows);

return context->nwindows? EXIT_SUCCESS : EXIT_FAILURE;
}

15 changes: 15 additions & 0 deletions cmd_search.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ int cmd_search(context_t *context) {
char out_prefix[17] = {'\0'};
int search_class = 0;
int search_classname = 0;
char flg_keep_chain = 0;
typedef enum {
opt_unused, opt_title, opt_onlyvisible, opt_name, opt_shell, opt_prefix, opt_class, opt_maxdepth,
opt_pid, opt_help, opt_any, opt_all, opt_screen, opt_classname, opt_desktop,
Expand Down Expand Up @@ -139,6 +140,16 @@ int cmd_search(context_t *context) {
}
}

/*
* Look-ahead if next command can work with empty window stack or not.
*/
if(context->argc > optind + 1){
if(*(context->argv + optind + 1)){
if(strcasecmp(*(context->argv + optind + 1), "getwindowstacklen") == 0){
flg_keep_chain = 1;
}
}
}
consume_args(context, optind);

/* We require a pattern or a pid to search for */
Expand Down Expand Up @@ -206,6 +217,10 @@ int cmd_search(context_t *context) {
context->windows = list;
context->nwindows = nwindows;

if(flg_keep_chain){
return EXIT_SUCCESS;
}

/* error if number of windows found is zero (behave like grep)
but return success when being used inside eval (--shell option)*/
return (nwindows || out_shell ? EXIT_SUCCESS : EXIT_FAILURE);
Expand Down
1 change: 1 addition & 0 deletions xdotool.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ struct dispatch {
{ "getwindowname", cmd_getwindowname, },
{ "getwindowpid", cmd_getwindowpid, },
{ "getwindowgeometry", cmd_getwindowgeometry, },
{ "getwindowstacklen", cmd_getwindowstacklen, },
{ "getdisplaygeometry", cmd_get_display_geometry, },
{ "search", cmd_search, },
{ "selectwindow", cmd_window_select, },
Expand Down
1 change: 1 addition & 0 deletions xdotool.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ int cmd_getwindowfocus(context_t *context);
int cmd_getwindowname(context_t *context);
int cmd_getwindowpid(context_t *context);
int cmd_getwindowgeometry(context_t *context);
int cmd_getwindowstacklen(context_t *context);
int cmd_help(context_t *context);
int cmd_key(context_t *context);
int cmd_mousedown(context_t *context);
Expand Down
4 changes: 4 additions & 0 deletions xdotool.pod
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,10 @@ Output values suitable for 'eval' in a shell.

=back

=item B<getwindowstacklen>

Output the length of window stack. See L<WINDOW STACK> for more details.

=item B<getwindowfocus> [-f]

Prints the window id of the currently focused window. Saves the result to the
Expand Down