xdo_window_search by name from libxdo and from xdotool

406 views
Skip to first unread message

Bert Vankeirsbilck

unread,
Mar 13, 2012, 11:05:12 AM3/13/12
to xdotool-users, dieter....@intec.ugent.be
We are currently trying to integrate the functionalities of libxdo
into one of our programs, but have encountered the following issue. We
assume we must make wrong use of the functions because from within our
program we get somewhat undeterministic behaviour, while the command-
line xdotool equivalent is stable and gives different results.

we start xclock for example and want to find that by name

- the xdotool command we want to mimic: `xdotool search --name xclock'
steadily returns one number

- our small test program has following code, which is compiled without
errors/warnings with -lxdo
#include <stdio.h>
#include <stdlib.h>
#include <xdo.h>

int main(int argc, char *argv[]) {
//window by name searching
xdo_t *xdo = xdo_new(NULL);
xdo_search_t search;
Window *list = NULL;
int nwindows;
int retval;

//fill in search struct
search.winname = "xclock";
search.searchmask = SEARCH_NAME;
search.limit = 0;
search.require = SEARCH_ANY;
search.only_visible = 1;
search.max_depth = 1;

printf("Performing a search for window with name '%s'!
\n",search.winname);
retval = xdo_window_search(xdo, &search, &list, &nwindows);

printf("xdo_window_search returned %d windows, retval %d\n",
nwindows, list, retval); fflush(stdout);
if (list != NULL) {
free(list);
}
xdo_free(xdo);

return 0;
}

before, it returned: "Performing a search... xdo_window_search
returned 0 windows, retval 0",
every now and then, it gave a warning "Failed to compile regex (return
code 9): ' � {�' " added to the output as above;
and now we are stuck with segmentation faults on the
xdo_window_search.

Would you have an idea on where we have misinterpreted the
declarations in the xdo.h file?

Kind regards,
Bert

Jordan Sissel

unread,
Mar 13, 2012, 2:08:03 PM3/13/12
to bvan...@intec.ugent.be, xdotool-users, dieter....@intec.ugent.be
Sounds like a bug in libxdo actually, it's doing extra work it doesn't need to (compiling regexps you aren't providing.

xdotool works around this (by accident, I suppose) in cmd_search.c:

  memset(&search, 0, sizeof(xdo_search_t));

This will zero the 'search' struct, and should solve your problem. Let me know if it doesn't! :)

-Jordan

Bert Vankeirsbilck

unread,
Mar 14, 2012, 5:23:11 AM3/14/12
to xdotool-users
Your solution worked on my laptop (Ubuntu Maverick with
1:2.20110530.1-3ubuntu1 of libxdo-dev and gnome 2).
At first the solution did not work on my desktop (Ubuntu Oneiric with
same package version and gnome 3), it solved the segmentation fault
but didn't find the xclock window.

After some tweaking, I found out the search.max_depth was the cause.
On my laptop the xclock window is at depth 1, where on my desktop it
is at depth 2.

Perhaps a useful addition to the library might be a new_xdo_search
method in analogy with new_xdo?

Thanks for your help,

Bert

P.S. noticed the search.limit field was not present on my laptop's
xdo.h file, which is kind of weird, since the packages have the same
version.


On Mar 13, 7:08 pm, Jordan Sissel <j...@semicomplete.com> wrote:
> On Tue, Mar 13, 2012 at 8:05 AM, Bert Vankeirsbilck <bvank...@intec.ugent.be
Reply all
Reply to author
Forward
0 new messages