libxdo
 All Data Structures Files Functions Variables Typedefs
xdo.h
Go to the documentation of this file.
1 
4 #ifndef _XDO_H_
5 #define _XDO_H_
6 
7 #ifndef __USE_XOPEN
8 #define __USE_XOPEN
9 #endif /* __USE_XOPEN */
10 
11 #include <sys/types.h>
12 #include <X11/Xlib.h>
13 #include <X11/X.h>
14 #include <unistd.h>
15 #include <wchar.h>
16 
37 #define SIZE_USEHINTS (1L << 0)
38 #define SIZE_USEHINTS_X (1L << 1)
39 #define SIZE_USEHINTS_Y (1L << 2)
40 
49 #define CURRENTWINDOW (0)
50 
55 typedef struct keysym_charmap {
56  const char *keysym;
57  wchar_t key;
59 
65 typedef struct charcodemap {
66  wchar_t key;
67  KeyCode code;
68  KeySym symbol;
69  int index;
70  int modmask;
75 
76 typedef enum {
77  XDO_FEATURE_XTEST,
78 } XDO_FEATURES;
79 
83 typedef struct xdo {
84 
86  Display *xdpy;
87 
89  char *display_name;
90 
92  charcodemap_t *charcodes;
93 
95  int charcodes_len;
96 
98  XModifierKeymap *modmap;
99 
101  KeySym *keymap;
102 
104  int keycode_high; /* highest and lowest keycodes */
105 
107  int keycode_low; /* used by this X server */
108 
110  int keysyms_per_keycode;
111 
114 
116  int quiet;
117 
119  int debug;
120 
123 
124 } xdo_t;
125 
126 
131 #define SEARCH_TITLE (1UL << 0)
132 
137 #define SEARCH_CLASS (1UL << 1)
138 
143 #define SEARCH_NAME (1UL << 2)
144 
149 #define SEARCH_PID (1UL << 3)
150 
155 #define SEARCH_ONLYVISIBLE (1UL << 4)
156 
162 #define SEARCH_SCREEN (1UL << 5)
163 
168 #define SEARCH_CLASSNAME (1UL << 6)
169 
175 #define SEARCH_DESKTOP (1UL << 7)
176 
177 
183 typedef struct xdo_search {
184  const char *title;
185  const char *winclass;
186  const char *winclassname;
187  const char *winname;
188  int pid;
189  long max_depth;
191  int screen;
196  enum { SEARCH_ANY, SEARCH_ALL } require;
197 
201  unsigned int searchmask;
202 
204  long desktop;
205 
207  unsigned int limit;
208 } xdo_search_t;
209 
210 #define XDO_ERROR 1
211 #define XDO_SUCCESS 0
212 
221 xdo_t* xdo_new(const char *display);
222 
231 xdo_t* xdo_new_with_opened_display(Display *xdpy, const char *display,
232  int close_display_when_freed);
233 
237 const char *xdo_version(void);
238 
244 void xdo_free(xdo_t *xdo);
245 
253 int xdo_move_mouse(const xdo_t *xdo, int x, int y, int screen);
254 
262 int xdo_move_mouse_relative_to_window(const xdo_t *xdo, Window window, int x, int y);
263 
270 int xdo_move_mouse_relative(const xdo_t *xdo, int x, int y);
271 
280 int xdo_mouse_down(const xdo_t *xdo, Window window, int button);
281 
290 int xdo_mouse_up(const xdo_t *xdo, Window window, int button);
291 
299 int xdo_get_mouse_location(const xdo_t *xdo, int *x, int *y, int *screen_num);
300 
306 int xdo_get_window_at_mouse(const xdo_t *xdo, Window *window_ret);
307 
320 int xdo_get_mouse_location2(const xdo_t *xdo, int *x_ret, int *y_ret,
321  int *screen_num_ret, Window *window_ret);
322 
330 int xdo_wait_for_mouse_move_from(const xdo_t *xdo, int origin_x, int origin_y);
331 
339 int xdo_wait_for_mouse_move_to(const xdo_t *xdo, int dest_x, int dest_y);
340 
348 int xdo_click_window(const xdo_t *xdo, Window window, int button);
349 
358 int xdo_click_window_multiple(const xdo_t *xdo, Window window, int button,
359  int repeat, useconds_t delay);
360 
372 int xdo_enter_text_window(const xdo_t *xdo, Window window, const char *string, useconds_t delay);
373 
395 int xdo_send_keysequence_window(const xdo_t *xdo, Window window,
396  const char *keysequence, useconds_t delay);
397 
403 int xdo_send_keysequence_window_up(const xdo_t *xdo, Window window,
404  const char *keysequence, useconds_t delay);
405 
411 int xdo_send_keysequence_window_down(const xdo_t *xdo, Window window,
412  const char *keysequence, useconds_t delay);
413 
425 int xdo_send_keysequence_window_list_do(const xdo_t *xdo, Window window,
426  charcodemap_t *keys, int nkeys,
427  int pressed, int *modifier, useconds_t delay);
428 
437  int *nkeys);
438 
451 int xdo_wait_for_window_map_state(const xdo_t *xdo, Window wid, int map_state);
452 
453 #define SIZE_TO 0
454 #define SIZE_FROM 1
455 int xdo_wait_for_window_size(const xdo_t *xdo, Window window, unsigned int width,
456  unsigned int height, int flags, int to_or_from);
457 
458 
468 int xdo_move_window(const xdo_t *xdo, Window wid, int x, int y);
469 
482 int xdo_translate_window_with_sizehint(const xdo_t *xdo, Window window,
483  unsigned int width, unsigned int height,
484  unsigned int *width_ret, unsigned int *height_ret);
485 
495 int xdo_set_window_size(const xdo_t *xdo, Window wid, int w, int h, int flags);
496 
506 int xdo_set_window_property(const xdo_t *xdo, Window wid, const char *property,
507  const char *value);
508 
515 int xdo_set_window_class(const xdo_t *xdo, Window wid, const char *name,
516  const char *_class);
517 
521 int xdo_set_window_urgency (const xdo_t *xdo, Window wid, int urgency);
522 
532 int xdo_set_window_override_redirect(const xdo_t *xdo, Window wid,
533  int override_redirect);
534 
541 int xdo_focus_window(const xdo_t *xdo, Window wid);
542 
549 int xdo_raise_window(const xdo_t *xdo, Window wid);
550 
557 int xdo_get_focused_window(const xdo_t *xdo, Window *window_ret);
558 
565 int xdo_wait_for_window_focus(const xdo_t *xdo, Window window, int want_focus);
566 
574 int xdo_get_pid_window(const xdo_t *xdo, Window window);
575 
585 int xdo_get_focused_window_sane(const xdo_t *xdo, Window *window_ret);
586 
598 int xdo_activate_window(const xdo_t *xdo, Window wid);
599 
609 int xdo_wait_for_window_active(const xdo_t *xdo, Window window, int active);
610 
617 int xdo_map_window(const xdo_t *xdo, Window wid);
618 
624 int xdo_unmap_window(const xdo_t *xdo, Window wid);
625 
629 int xdo_minimize_window(const xdo_t *xdo, Window wid);
630 
637 int xdo_reparent_window(const xdo_t *xdo, Window wid_source, Window wid_target);
638 
650 int xdo_get_window_location(const xdo_t *xdo, Window wid,
651  int *x_ret, int *y_ret, Screen **screen_ret);
652 
660 int xdo_get_window_size(const xdo_t *xdo, Window wid, unsigned int *width_ret,
661  unsigned int *height_ret);
662 
663 /* pager-like behaviors */
664 
672 int xdo_get_active_window(const xdo_t *xdo, Window *window_ret);
673 
680 int xdo_select_window_with_click(const xdo_t *xdo, Window *window_ret);
681 
688 int xdo_set_number_of_desktops(const xdo_t *xdo, long ndesktops);
689 
697 int xdo_get_number_of_desktops(const xdo_t *xdo, long *ndesktops);
698 
705 int xdo_set_current_desktop(const xdo_t *xdo, long desktop);
706 
713 int xdo_get_current_desktop(const xdo_t *xdo, long *desktop);
714 
722 int xdo_set_desktop_for_window(const xdo_t *xdo, Window wid, long desktop);
723 
734 int xdo_get_desktop_for_window(const xdo_t *xdo, Window wid, long *desktop);
735 
744 int xdo_search_windows(const xdo_t *xdo, const xdo_search_t *search,
745  Window **windowlist_ret, unsigned int *nwindows_ret);
746 
758 unsigned char *xdo_get_window_property_by_atom(const xdo_t *xdo, Window window, Atom atom,
759  long *nitems, Atom *type, int *size);
760 
772 int xdo_get_window_property(const xdo_t *xdo, Window window, const char *property,
773  unsigned char **value, long *nitems, Atom *type, int *size);
774 
782 unsigned int xdo_get_input_state(const xdo_t *xdo);
783 
789 
798 const char **xdo_get_symbol_map(void);
799 
800 /* active modifiers stuff */
801 
810  int *nkeys);
811 
817 int xdo_clear_active_modifiers(const xdo_t *xdo, Window window,
818  charcodemap_t *active_mods,
819  int active_mods_n);
820 
826 int xdo_set_active_modifiers(const xdo_t *xdo, Window window,
827  charcodemap_t *active_mods,
828  int active_mods_n);
829 
836 int xdo_get_desktop_viewport(const xdo_t *xdo, int *x_ret, int *y_ret);
837 
844 int xdo_set_desktop_viewport(const xdo_t *xdo, int x, int y);
845 
850 int xdo_kill_window(const xdo_t *xdo, Window window);
851 
855 #define XDO_FIND_PARENTS (0)
856 
860 #define XDO_FIND_CHILDREN (1)
861 
866 int xdo_find_window_client(const xdo_t *xdo, Window window, Window *window_ret,
867  int direction);
868 
874 int xdo_get_window_name(const xdo_t *xdo, Window window,
875  unsigned char **name_ret, int *name_len_ret,
876  int *name_type);
877 
886 void xdo_disable_feature(xdo_t *xdo, int feature);
887 
896 void xdo_enable_feature(xdo_t *xdo, int feature);
897 
906 int xdo_has_feature(xdo_t *xdo, int feature);
907 
915 int xdo_get_viewport_dimensions(xdo_t *xdo, unsigned int *width,
916  unsigned int *height, int screen);
917 #endif /* ifndef _XDO_H_ */
int xdo_activate_window(const xdo_t *xdo, Window wid)
Activate a window.
Definition: xdo.c:470
int xdo_focus_window(const xdo_t *xdo, Window wid)
Focus a window.
Definition: xdo.c:403
int xdo_wait_for_mouse_move_from(const xdo_t *xdo, int origin_x, int origin_y)
Wait for the mouse to move from a location.
Definition: xdo.c:1898
xdo_t * xdo_new_with_opened_display(Display *xdpy, const char *display, int close_display_when_freed)
Create a new xdo_t instance with an existing X11 Display instance.
Definition: xdo.c:106
int xdo_get_window_at_mouse(const xdo_t *xdo, Window *window_ret)
Get the window the mouse is currently over.
Definition: xdo.c:874
int xdo_get_viewport_dimensions(xdo_t *xdo, unsigned int *width, unsigned int *height, int screen)
Query the viewport (your display) dimensions.
Definition: xdo.c:2082
int xdo_wait_for_window_active(const xdo_t *xdo, Window window, int active)
Wait for a window to be active or not active.
Definition: xdo.c:450
int xdo_move_window(const xdo_t *xdo, Window wid, int x, int y)
Move a window to a specific location.
Definition: xdo.c:261
int pid
pattern to test against a window name
Definition: xdo.h:188
int xdo_get_window_property(const xdo_t *xdo, Window window, const char *property, unsigned char **value, long *nitems, Atom *type, int *size)
Get property of window by name of atom.
Definition: xdo.c:1557
int xdo_enter_text_window(const xdo_t *xdo, Window window, const char *string, useconds_t delay)
Type a string to the specified window.
Definition: xdo.c:963
const char * xdo_version(void)
Return a string representing the version of this library.
Definition: xdo.c:163
void xdo_disable_feature(xdo_t *xdo, int feature)
Disable an xdo feature.
Definition: xdo.c:2074
int xdo_get_desktop_viewport(const xdo_t *xdo, int *x_ret, int *y_ret)
Get the position of the current viewport.
Definition: xdo.c:1929
struct xdo_search xdo_search_t
The window search query structure.
int xdo_get_window_size(const xdo_t *xdo, Window wid, unsigned int *width_ret, unsigned int *height_ret)
Get a window's size.
Definition: xdo.c:244
int xdo_select_window_with_click(const xdo_t *xdo, Window *window_ret)
Get a window ID by clicking on it.
Definition: xdo.c:727
int close_display_when_freed
Should we close the display when calling xdo_free?
Definition: xdo.h:113
const keysym_charmap_t * xdo_get_keysym_charmap(void)
If you need the keysym-to-character map, you can fetch it using this method.
Definition: xdo.c:1813
int xdo_get_window_location(const xdo_t *xdo, Window wid, int *x_ret, int *y_ret, Screen **screen_ret)
Get a window's location.
Definition: xdo.c:200
unsigned int limit
How many results to return? If 0, return all.
Definition: xdo.h:207
KeyCode code
the letter for this key, like 'a'
Definition: xdo.h:67
int xdo_has_feature(xdo_t *xdo, int feature)
Check if a feature is enabled.
Definition: xdo.c:2078
int screen
boolean; set true to search only visible windows
Definition: xdo.h:191
int xdo_map_window(const xdo_t *xdo, Window wid)
Map a window.
Definition: xdo.c:179
int debug
Enable debug output?
Definition: xdo.h:119
int xdo_get_number_of_desktops(const xdo_t *xdo, long *ndesktops)
Get the current number of desktops.
Definition: xdo.c:541
struct xdo xdo_t
The main context.
Definition: xdo.h:65
int xdo_minimize_window(const xdo_t *xdo, Window wid)
Minimize a window.
Definition: xdo.c:2033
int xdo_click_window_multiple(const xdo_t *xdo, Window window, int button, int repeat, useconds_t delay)
Send a one or more clicks for a specific mouse button at the current mouse location.
Definition: xdo.c:945
int xdo_kill_window(const xdo_t *xdo, Window window)
Kill a window and the client owning it.
Definition: xdo.c:1989
void xdo_enable_feature(xdo_t *xdo, int feature)
Enable an xdo feature.
Definition: xdo.c:2070
int needs_binding
the modifiers activated by this key
Definition: xdo.h:73
int xdo_get_desktop_for_window(const xdo_t *xdo, Window wid, long *desktop)
Get the desktop a window is on.
Definition: xdo.c:667
int xdo_get_current_desktop(const xdo_t *xdo, long *desktop)
Get the current desktop.
Definition: xdo.c:604
int xdo_set_window_property(const xdo_t *xdo, Window wid, const char *property, const char *value)
Change a window property.
Definition: xdo.c:380
int modmask
the index in the keysym-per-keycode list that is this key
Definition: xdo.h:70
int xdo_get_focused_window_sane(const xdo_t *xdo, Window *window_ret)
Like xdo_get_focused_window, but return the first ancestor-or-self window * having a property of WM_C...
Definition: xdo.c:1220
int xdo_get_window_name(const xdo_t *xdo, Window window, unsigned char **name_ret, int *name_len_ret, int *name_type)
Get a window's name, if any.
Definition: xdo.c:1995
enum xdo_search::@0 require
what screen to search, if any.
const char * winname
pattern to test against a window class
Definition: xdo.h:187
int xdo_get_active_keys_to_keycode_list(const xdo_t *xdo, charcodemap_t **keys, int *nkeys)
Get a list of active keys.
int xdo_get_active_window(const xdo_t *xdo, Window *window_ret)
Get the currently-active window.
Definition: xdo.c:697
int xdo_translate_window_with_sizehint(const xdo_t *xdo, Window window, unsigned int width, unsigned int height, unsigned int *width_ret, unsigned int *height_ret)
Apply a window's sizing hints (if any) to a given width and height.
Definition: xdo.c:271
int xdo_mouse_up(const xdo_t *xdo, Window window, int button)
Send a mouse release (aka mouse up) for a given button at the current mouse location.
Definition: xdo.c:861
char * display_name
The display name, if any.
Definition: xdo.h:89
int xdo_get_pid_window(const xdo_t *xdo, Window window)
Get the PID owning a window.
Definition: xdo.c:1876
int xdo_set_window_class(const xdo_t *xdo, Window wid, const char *name, const char *_class)
Change the window's classname and or class.
Definition: xdo.c:348
int features_mask
Feature flags, such as XDO_FEATURE_XTEST, etc...
Definition: xdo.h:122
int xdo_get_mouse_location(const xdo_t *xdo, int *x, int *y, int *screen_num)
Get the current mouse location (coordinates and screen number).
Definition: xdo.c:869
int xdo_get_mouse_location2(const xdo_t *xdo, int *x_ret, int *y_ret, int *screen_num_ret, Window *window_ret)
Get all mouse location-related data.
Definition: xdo.c:878
The window search query structure.
Definition: xdo.h:183
int only_visible
depth of search.
Definition: xdo.h:190
int xdo_get_active_modifiers(const xdo_t *xdo, charcodemap_t **keys, int *nkeys)
Get a list of active keys.
Definition: xdo.c:1763
unsigned int xdo_get_input_state(const xdo_t *xdo)
Get the current input state.
Definition: xdo.c:1801
KeySym symbol
the keycode that this key is on
Definition: xdo.h:68
int xdo_send_keysequence_window_list_do(const xdo_t *xdo, Window window, charcodemap_t *keys, int nkeys, int pressed, int *modifier, useconds_t delay)
Send a series of keystrokes.
Definition: xdo.c:1075
long desktop
What desktop to search, if any.
Definition: xdo.h:204
int quiet
Be extra quiet? (omits some error/message output)
Definition: xdo.h:116
int xdo_set_window_override_redirect(const xdo_t *xdo, Window wid, int override_redirect)
Set the override_redirect value for a window.
Definition: xdo.c:337
unsigned int searchmask
bitmask of things you are searching for, such as SEARCH_NAME, etc.
Definition: xdo.h:201
int xdo_set_desktop_for_window(const xdo_t *xdo, Window wid, long desktop)
Move a window to another desktop Uses _NET_WM_DESKTOP of the EWMH spec.
Definition: xdo.c:636
int xdo_search_windows(const xdo_t *xdo, const xdo_search_t *search, Window **windowlist_ret, unsigned int *nwindows_ret)
Search for windows.
Definition: xdo_search.c:31
int xdo_raise_window(const xdo_t *xdo, Window wid)
Raise a window to the top of the window stack.
Definition: xdo.c:769
Definition: xdo.h:55
xdo_t * xdo_new(const char *display)
Create a new xdo_t instance.
Definition: xdo.c:90
int xdo_unmap_window(const xdo_t *xdo, Window wid)
Unmap a window.
Definition: xdo.c:186
int xdo_set_desktop_viewport(const xdo_t *xdo, int x, int y)
Set the position of the current viewport.
Definition: xdo.c:1966
int xdo_mouse_down(const xdo_t *xdo, Window window, int button)
Send a mouse press (aka mouse down) for a given button at the current mouse location.
Definition: xdo.c:865
int xdo_move_mouse(const xdo_t *xdo, int x, int y, int screen)
Move the mouse to a specific location.
Definition: xdo.c:776
int xdo_find_window_client(const xdo_t *xdo, Window window, Window *window_ret, int direction)
Find a client window (child) in a given window.
Definition: xdo.c:1226
int xdo_send_keysequence_window_up(const xdo_t *xdo, Window window, const char *keysequence, useconds_t delay)
Send key release (up) events for the given key sequence.
Definition: xdo.c:1162
int xdo_set_window_size(const xdo_t *xdo, Window wid, int w, int h, int flags)
Change the window size.
Definition: xdo.c:302
const char * winclass
pattern to test against a window title
Definition: xdo.h:185
unsigned char * xdo_get_window_property_by_atom(const xdo_t *xdo, Window window, Atom atom, long *nitems, Atom *type, int *size)
Generic property fetch.
Definition: xdo.c:1568
int xdo_send_keysequence_window_down(const xdo_t *xdo, Window window, const char *keysequence, useconds_t delay)
Send key press (down) events for the given key sequence.
Definition: xdo.c:1157
int xdo_wait_for_mouse_move_to(const xdo_t *xdo, int dest_x, int dest_y)
Wait for the mouse to move to a location.
Definition: xdo.c:1914
Display * xdpy
The Display for Xlib.
Definition: xdo.h:86
const char * winclassname
pattern to test against a window class
Definition: xdo.h:186
int xdo_click_window(const xdo_t *xdo, Window window, int button)
Send a click for a specific mouse button at the current mouse location.
Definition: xdo.c:933
int xdo_clear_active_modifiers(const xdo_t *xdo, Window window, charcodemap_t *active_mods, int active_mods_n)
Send any events necesary to clear the the active modifiers.
Definition: xdo.c:1821
int xdo_send_keysequence_window(const xdo_t *xdo, Window window, const char *keysequence, useconds_t delay)
Send a keysequence to the specified window.
Definition: xdo.c:1167
long max_depth
window pid (From window atom _NET_WM_PID)
Definition: xdo.h:189
int xdo_reparent_window(const xdo_t *xdo, Window wid_source, Window wid_target)
Reparents a window.
Definition: xdo.c:193
int xdo_wait_for_window_map_state(const xdo_t *xdo, Window wid, int map_state)
Wait for a window to have a specific map state.
Definition: xdo.c:167
int xdo_move_mouse_relative(const xdo_t *xdo, int x, int y)
Move the mouse relative to it's current position.
Definition: xdo.c:801
void xdo_free(xdo_t *xdo)
Free and destroy an xdo_t instance.
Definition: xdo.c:145
int xdo_set_active_modifiers(const xdo_t *xdo, Window window, charcodemap_t *active_mods, int active_mods_n)
Send any events necessary to make these modifiers active.
Definition: xdo.c:1849
int xdo_wait_for_window_focus(const xdo_t *xdo, Window window, int want_focus)
Wait for a window to have or lose focus.
Definition: xdo.c:1195
int xdo_move_mouse_relative_to_window(const xdo_t *xdo, Window window, int x, int y)
Move the mouse to a specific location relative to the top-left corner of a window.
Definition: xdo.c:790
int xdo_set_current_desktop(const xdo_t *xdo, long desktop)
Switch to another desktop.
Definition: xdo.c:572
int xdo_set_window_urgency(const xdo_t *xdo, Window wid, int urgency)
Sets the urgency hint for a window.
Definition: xdo.c:364
int xdo_get_focused_window(const xdo_t *xdo, Window *window_ret)
Get the window currently having focus.
Definition: xdo.c:1178
const char ** xdo_get_symbol_map(void)
If you need the symbol map, use this method.
Definition: xdo.c:1817
int xdo_set_number_of_desktops(const xdo_t *xdo, long ndesktops)
Set the number of desktops.
Definition: xdo.c:510
int index
the symbol representing this key
Definition: xdo.h:69
The main context.
Definition: xdo.h:83