libxdo
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
17#ifdef __cplusplus
18extern "C" {
19#endif
20
41#define SIZE_USEHINTS (1L << 0)
42#define SIZE_USEHINTS_X (1L << 1)
43#define SIZE_USEHINTS_Y (1L << 2)
44
53#define CURRENTWINDOW (0)
54
60typedef struct charcodemap {
61 wchar_t key;
62 KeyCode code;
63 KeySym symbol;
64 int group;
65 int modmask;
70
71typedef enum {
72 XDO_FEATURE_XTEST,
73} XDO_FEATURES;
74
78typedef struct xdo {
79
81 Display *xdpy;
82
85
87 charcodemap_t *charcodes;
88
90 int charcodes_len;
91
93 int keycode_high; /* highest and lowest keycodes */
94
96 int keycode_low; /* used by this X server */
97
99 int keysyms_per_keycode;
100
103
105 int quiet;
106
108 int debug;
109
112
114
115
120#define SEARCH_TITLE (1UL << 0)
121
126#define SEARCH_CLASS (1UL << 1)
127
132#define SEARCH_NAME (1UL << 2)
133
138#define SEARCH_PID (1UL << 3)
139
144#define SEARCH_ONLYVISIBLE (1UL << 4)
145
151#define SEARCH_SCREEN (1UL << 5)
152
157#define SEARCH_CLASSNAME (1UL << 6)
158
164#define SEARCH_DESKTOP (1UL << 7)
165
170#define SEARCH_ROLE (1UL << 8)
171
177typedef struct xdo_search {
178 const char *title;
179 const char *winclass;
180 const char *winclassname;
181 const char *winname;
182 const char *winrole;
183 int pid;
186 int screen;
191 enum { SEARCH_ANY, SEARCH_ALL } require;
192
196 unsigned int searchmask;
197
200
202 unsigned int limit;
204
205#define XDO_ERROR 1
206#define XDO_SUCCESS 0
207
216xdo_t* xdo_new(const char *display);
217
226xdo_t* xdo_new_with_opened_display(Display *xdpy, const char *display,
227 int close_display_when_freed);
228
232const char *xdo_version(void);
233
239void xdo_free(xdo_t *xdo);
240
248int xdo_move_mouse(const xdo_t *xdo, int x, int y, int screen);
249
257int xdo_move_mouse_relative_to_window(const xdo_t *xdo, Window window, int x, int y);
258
265int xdo_move_mouse_relative(const xdo_t *xdo, int x, int y);
266
275int xdo_mouse_down(const xdo_t *xdo, Window window, int button);
276
285int xdo_mouse_up(const xdo_t *xdo, Window window, int button);
286
294int xdo_get_mouse_location(const xdo_t *xdo, int *x, int *y, int *screen_num);
295
301int xdo_get_window_at_mouse(const xdo_t *xdo, Window *window_ret);
302
315int xdo_get_mouse_location2(const xdo_t *xdo, int *x_ret, int *y_ret,
316 int *screen_num_ret, Window *window_ret);
317
325int xdo_wait_for_mouse_move_from(const xdo_t *xdo, int origin_x, int origin_y);
326
334int xdo_wait_for_mouse_move_to(const xdo_t *xdo, int dest_x, int dest_y);
335
343int xdo_click_window(const xdo_t *xdo, Window window, int button);
344
353int xdo_click_window_multiple(const xdo_t *xdo, Window window, int button,
354 int repeat, useconds_t delay);
355
367int xdo_enter_text_window(const xdo_t *xdo, Window window, const char *string, useconds_t delay);
368
390int xdo_send_keysequence_window(const xdo_t *xdo, Window window,
391 const char *keysequence, useconds_t delay);
392
398int xdo_send_keysequence_window_up(const xdo_t *xdo, Window window,
399 const char *keysequence, useconds_t delay);
400
406int xdo_send_keysequence_window_down(const xdo_t *xdo, Window window,
407 const char *keysequence, useconds_t delay);
408
420int xdo_send_keysequence_window_list_do(const xdo_t *xdo, Window window,
421 charcodemap_t *keys, int nkeys,
422 int pressed, int *modifier, useconds_t delay);
423
424
437int xdo_wait_for_window_map_state(const xdo_t *xdo, Window wid, int map_state);
438
439#define SIZE_TO 0
440#define SIZE_FROM 1
441int xdo_wait_for_window_size(const xdo_t *xdo, Window window, unsigned int width,
442 unsigned int height, int flags, int to_or_from);
443
444
454int xdo_move_window(const xdo_t *xdo, Window wid, int x, int y);
455
468int xdo_translate_window_with_sizehint(const xdo_t *xdo, Window window,
469 unsigned int width, unsigned int height,
470 unsigned int *width_ret, unsigned int *height_ret);
471
481int xdo_set_window_size(const xdo_t *xdo, Window wid, int w, int h, int flags);
482
492int xdo_set_window_property(const xdo_t *xdo, Window wid, const char *property,
493 const char *value);
494
501int xdo_set_window_class(const xdo_t *xdo, Window wid, const char *name,
502 const char *_class);
503
507int xdo_set_window_urgency (const xdo_t *xdo, Window wid, int urgency);
508
518int xdo_set_window_override_redirect(const xdo_t *xdo, Window wid,
519 int override_redirect);
520
527int xdo_focus_window(const xdo_t *xdo, Window wid);
528
535int xdo_raise_window(const xdo_t *xdo, Window wid);
536
543int xdo_lower_window(const xdo_t *xdo, Window wid);
544
551int xdo_get_focused_window(const xdo_t *xdo, Window *window_ret);
552
559int xdo_wait_for_window_focus(const xdo_t *xdo, Window window, int want_focus);
560
568int xdo_get_pid_window(const xdo_t *xdo, Window window);
569
579int xdo_get_focused_window_sane(const xdo_t *xdo, Window *window_ret);
580
592int xdo_activate_window(const xdo_t *xdo, Window wid);
593
603int xdo_wait_for_window_active(const xdo_t *xdo, Window window, int active);
604
611int xdo_map_window(const xdo_t *xdo, Window wid);
612
618int xdo_unmap_window(const xdo_t *xdo, Window wid);
619
623int xdo_minimize_window(const xdo_t *xdo, Window wid);
624
625#define _NET_WM_STATE_REMOVE 0 /* remove/unset property */
626#define _NET_WM_STATE_ADD 1 /* add/set property */
627#define _NET_WM_STATE_TOGGLE 2 /* toggle property */
628
634int xdo_get_window_classname(const xdo_t *xdo, Window window, unsigned char **class_ret);
635
640int xdo_window_state(xdo_t *xdo, Window window, unsigned long action, const char *property);
641
648int xdo_reparent_window(const xdo_t *xdo, Window wid_source, Window wid_target);
649
661int xdo_get_window_location(const xdo_t *xdo, Window wid,
662 int *x_ret, int *y_ret, Screen **screen_ret);
663
671int xdo_get_window_size(const xdo_t *xdo, Window wid, unsigned int *width_ret,
672 unsigned int *height_ret);
673
674/* pager-like behaviors */
675
683int xdo_get_active_window(const xdo_t *xdo, Window *window_ret);
684
691int xdo_select_window_with_click(const xdo_t *xdo, Window *window_ret);
692
699int xdo_set_number_of_desktops(const xdo_t *xdo, long ndesktops);
700
708int xdo_get_number_of_desktops(const xdo_t *xdo, long *ndesktops);
709
716int xdo_set_current_desktop(const xdo_t *xdo, long desktop);
717
724int xdo_get_current_desktop(const xdo_t *xdo, long *desktop);
725
733int xdo_set_desktop_for_window(const xdo_t *xdo, Window wid, long desktop);
734
745int xdo_get_desktop_for_window(const xdo_t *xdo, Window wid, long *desktop);
746
755int xdo_search_windows(const xdo_t *xdo, const xdo_search_t *search,
756 Window **windowlist_ret, unsigned int *nwindows_ret);
757
769unsigned char *xdo_get_window_property_by_atom(const xdo_t *xdo, Window window, Atom atom,
770 long *nitems, Atom *type, int *size);
771
783int xdo_get_window_property(const xdo_t *xdo, Window window, const char *property,
784 unsigned char **value, long *nitems, Atom *type, int *size);
785
793unsigned int xdo_get_input_state(const xdo_t *xdo);
794
803const char **xdo_get_symbol_map(void);
804
805/* active modifiers stuff */
806
815 int *nkeys);
816
822int xdo_clear_active_modifiers(const xdo_t *xdo, Window window,
823 charcodemap_t *active_mods,
824 int active_mods_n);
825
831int xdo_set_active_modifiers(const xdo_t *xdo, Window window,
832 charcodemap_t *active_mods,
833 int active_mods_n);
834
841int xdo_get_desktop_viewport(const xdo_t *xdo, int *x_ret, int *y_ret);
842
849int xdo_set_desktop_viewport(const xdo_t *xdo, int x, int y);
850
855int xdo_kill_window(const xdo_t *xdo, Window window);
856
861int xdo_close_window(const xdo_t *xdo, Window window);
862
867int xdo_quit_window(const xdo_t *xdo, Window window);
868
872#define XDO_FIND_PARENTS (0)
873
877#define XDO_FIND_CHILDREN (1)
878
883int xdo_find_window_client(const xdo_t *xdo, Window window, Window *window_ret,
884 int direction);
885
894int xdo_get_window_name(const xdo_t *xdo, Window window,
895 unsigned char **name_ret, int *name_len_ret,
896 int *name_type);
897
906void xdo_disable_feature(xdo_t *xdo, int feature);
907
916void xdo_enable_feature(xdo_t *xdo, int feature);
917
926int xdo_has_feature(xdo_t *xdo, int feature);
927
935int xdo_get_viewport_dimensions(xdo_t *xdo, unsigned int *width,
936 unsigned int *height, int screen);
937
938
939#ifdef __cplusplus
940} /* extern "C" */
941#endif
942
943#endif /* ifndef _XDO_H_ */
944
Definition: xdo.h:60
int modmask
the keyboard group that has this key in it
Definition: xdo.h:65
int group
the symbol representing this key
Definition: xdo.h:64
KeySym symbol
the keycode that this key is on
Definition: xdo.h:63
KeyCode code
the letter for this key, like 'a'
Definition: xdo.h:62
int needs_binding
the modifiers to apply when sending this key
Definition: xdo.h:68
The window search query structure.
Definition: xdo.h:177
long desktop
What desktop to search, if any.
Definition: xdo.h:199
unsigned int limit
How many results to return? If 0, return all.
Definition: xdo.h:202
const char * winclassname
pattern to test against a window class
Definition: xdo.h:180
int screen
boolean; set true to search only visible windows
Definition: xdo.h:186
enum xdo_search::@0 require
what screen to search, if any.
unsigned int searchmask
bitmask of things you are searching for, such as SEARCH_NAME, etc.
Definition: xdo.h:196
int only_visible
depth of search.
Definition: xdo.h:185
int pid
pattern to test against a window role
Definition: xdo.h:183
const char * winrole
pattern to test against a window name
Definition: xdo.h:182
const char * winclass
pattern to test against a window title
Definition: xdo.h:179
long max_depth
window pid (From window atom _NET_WM_PID)
Definition: xdo.h:184
const char * winname
pattern to test against a window class
Definition: xdo.h:181
The main context.
Definition: xdo.h:78
int debug
Enable debug output?
Definition: xdo.h:108
int features_mask
Feature flags, such as XDO_FEATURE_XTEST, etc...
Definition: xdo.h:111
int quiet
Be extra quiet? (omits some error/message output)
Definition: xdo.h:105
int close_display_when_freed
Should we close the display when calling xdo_free?
Definition: xdo.h:102
Display * xdpy
The Display for Xlib.
Definition: xdo.h:81
char * display_name
The display name, if any.
Definition: xdo.h:84
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:639
int xdo_kill_window(const xdo_t *xdo, Window window)
Kill a window and the client owning it.
Definition: xdo.c:1965
void xdo_disable_feature(xdo_t *xdo, int feature)
Disable an xdo feature.
Definition: xdo.c:2114
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:340
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:1902
struct xdo xdo_t
The main context.
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:247
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:955
int xdo_clear_active_modifiers(const xdo_t *xdo, Window window, charcodemap_t *active_mods, int active_mods_n)
Send any events necessary to clear the active modifiers.
Definition: xdo.c:1794
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:891
int xdo_set_window_size(const xdo_t *xdo, Window wid, int w, int h, int flags)
Change the window size.
Definition: xdo.c:305
int xdo_quit_window(const xdo_t *xdo, Window window)
Request that a window close, gracefully.
Definition: xdo.c:1977
const char ** xdo_get_symbol_map(void)
If you need the symbol map, use this method.
Definition: xdo.c:1790
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:1185
int xdo_get_number_of_desktops(const xdo_t *xdo, long *ndesktops)
Get the current number of desktops.
Definition: xdo.c:544
int xdo_map_window(const xdo_t *xdo, Window wid)
Map a window.
Definition: xdo.c:182
unsigned int xdo_get_input_state(const xdo_t *xdo)
Get the current input state.
Definition: xdo.c:1778
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:823
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:111
int xdo_get_window_classname(const xdo_t *xdo, Window window, unsigned char **class_ret)
Get window classname.
Definition: xdo.c:2038
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:967
int xdo_lower_window(const xdo_t *xdo, Window wid)
Lower a window to the bottom of the window stack.
Definition: xdo.c:787
int xdo_get_current_desktop(const xdo_t *xdo, long *desktop)
Get the current desktop.
Definition: xdo.c:607
int xdo_reparent_window(const xdo_t *xdo, Window wid_source, Window wid_target)
Reparents a window.
Definition: xdo.c:196
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:1822
int xdo_unmap_window(const xdo_t *xdo, Window wid)
Unmap a window.
Definition: xdo.c:189
void xdo_free(xdo_t *xdo)
Free and destroy an xdo_t instance.
Definition: xdo.c:154
int xdo_get_active_window(const xdo_t *xdo, Window *window_ret)
Get the currently-active window.
Definition: xdo.c:703
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:1127
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:2000
int xdo_has_feature(xdo_t *xdo, int feature)
Check if a feature is enabled.
Definition: xdo.c:2118
int xdo_activate_window(const xdo_t *xdo, Window wid)
Activate a window.
Definition: xdo.c:473
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:887
xdo_t * xdo_new(const char *display)
Create a new xdo_t instance.
Definition: xdo.c:86
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:1122
int xdo_get_desktop_for_window(const xdo_t *xdo, Window wid, long *desktop)
Get the desktop a window is on.
Definition: xdo.c:670
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:453
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:1132
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:274
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:1871
int xdo_set_current_desktop(const xdo_t *xdo, long desktop)
Switch to another desktop.
Definition: xdo.c:575
struct xdo_search xdo_search_t
The window search query structure.
int xdo_get_pid_window(const xdo_t *xdo, Window window)
Get the PID owning a window.
Definition: xdo.c:1849
int xdo_select_window_with_click(const xdo_t *xdo, Window *window_ret)
Get a window ID by clicking on it.
Definition: xdo.c:733
int xdo_get_focused_window(const xdo_t *xdo, Window *window_ret)
Get the window currently having focus.
Definition: xdo.c:1143
int xdo_focus_window(const xdo_t *xdo, Window wid)
Focus a window.
Definition: xdo.c:406
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:1038
int xdo_move_window(const xdo_t *xdo, Window wid, int x, int y)
Move a window to a specific location.
Definition: xdo.c:264
int xdo_close_window(const xdo_t *xdo, Window window)
Close a window without trying to kill the client.
Definition: xdo.c:1971
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:351
void xdo_enable_feature(xdo_t *xdo, int feature)
Enable an xdo feature.
Definition: xdo.c:2110
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:900
int xdo_minimize_window(const xdo_t *xdo, Window wid)
Minimize a window.
Definition: xdo.c:2071
int xdo_get_window_at_mouse(const xdo_t *xdo, Window *window_ret)
Get the window the mouse is currently over.
Definition: xdo.c:896
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:32
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:2122
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:812
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:986
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:170
int xdo_move_mouse(const xdo_t *xdo, int x, int y, int screen)
Move the mouse to a specific location.
Definition: xdo.c:794
int xdo_set_number_of_desktops(const xdo_t *xdo, long ndesktops)
Set the number of desktops.
Definition: xdo.c:513
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:1551
int xdo_set_window_property(const xdo_t *xdo, Window wid, const char *property, const char *value)
Change a window property.
Definition: xdo.c:383
int xdo_raise_window(const xdo_t *xdo, Window wid)
Raise a window to the top of the window stack.
Definition: xdo.c:780
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:1887
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:883
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:203
int xdo_get_active_modifiers(const xdo_t *xdo, charcodemap_t **keys, int *nkeys)
Get a list of active keys.
Definition: xdo.c:1734
const char * xdo_version(void)
Return a string representing the version of this library.
Definition: xdo.c:166
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:1540
int xdo_set_window_urgency(const xdo_t *xdo, Window wid, int urgency)
Sets the urgency hint for a window.
Definition: xdo.c:367
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:1160
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:1191
int xdo_set_desktop_viewport(const xdo_t *xdo, int x, int y)
Set the position of the current viewport.
Definition: xdo.c:1942
int xdo_window_state(xdo_t *xdo, Window window, unsigned long action, const char *property)
Change window state.
Definition: xdo.c:2051