I am using ubuntu. The command to get window id of a window by its name in terminal is
xdotool search --name "name of the window"
But i want to get the same using c++ program.
I am using ubuntu. The command to get window id of a window by its name in terminal is
xdotool search --name "name of the window"
But i want to get the same using c++ program.
References:
Sending Keystrokes to a X Window
I cannot compile myself and check, but I think this is the minimal code to search for a window by name.
#include <xdo.h>
Window *list;
xdo_search_t search;
unsigned int nwindows;
memset(&search, 0, sizeof(xdo_search_t));
search.max_depth = -1;
search.require = xdo_search::SEARCH_ANY;
search.searchmask |= SEARCH_NAME;
search.winname = "enter name here";
// the context
xdo_t* p_xdo = xdo_new(NULL);
int id = xdo_window_search(p_xdo, &search, &list, &nwindows);
I've had the same proble for xdo_window_search
. Check the function's name in xdo.h
, because of changing names.
I've had the same problem with (xdo_window_search
changed to xdo_search_windows
as ewen said)
undefined reference to xdo_new'
undefined reference to xdo_search_windows'
it was fixed using in terminal
sudo apt-get install libxdo-dev
in addition to, in cpp file,
#include <xdotool-master/xdo.h>
in my particular case, was used for a qt application. For it, I've had to add the line below in .pro file too
LIBS += -lxdo
but the last variable 'id' always returns zero (0).
To get the window ID definitively, I used code in link below, using xdotool command too. In this case, the use should be carefully, because a program can generate more than one ID until fully open and the code runs faster than the ID is available to read. So a timer or a another strategy is necessary.
How do I execute a command and get the output of the command within C++ using POSIX?