libwm

A small library for X window manipulation
git clone git://git.zepp.club/libwm.git
Log | Files | Refs | README | LICENSE

wm.h (6795B)


      1 #ifndef __LIBWM_H__
      2 #define __LIBWM_H__
      3 
      4 /*
      5  * Variables used to hold the connection to the X server, and the first screen
      6  * of this connection. Both have to be defined as `extern`.
      7  */
      8 extern xcb_connection_t *conn;
      9 extern xcb_screen_t     *scrn;
     10 
     11 /*
     12  * Mask attributes used to select which windows have to be listed by the
     13  * function `wm_is_listable(wid, mask)`.
     14  */
     15 enum {
     16 	LIST_HIDDEN = 1 << 0, /* windows that are not on-screen */
     17 	LIST_IGNORE = 1 << 1, /* windows with override_redirect set to 1 */
     18 	LIST_ALL    = 1 << 2  /* All existing windows */
     19 };
     20 
     21 /*
     22  * Actions used by the `wm_remap(wid, mode)` function to select what needs to be
     23  * done.
     24  */
     25 enum {
     26 	MAP     = 1 << 0,
     27 	UNMAP   = 1 << 1,
     28 	TOGGLE  = 1 << 2
     29 };
     30 
     31 /*
     32  * Attributes used internally by different functions to refer to windows
     33  * attributes, and select them.
     34  */
     35 enum {
     36 	ATTR_W = 1 << 0,
     37 	ATTR_H = 1 << 1,
     38 	ATTR_X = 1 << 2,
     39 	ATTR_Y = 1 << 3,
     40 	ATTR_B = 1 << 4,
     41 	ATTR_M = 1 << 5,
     42 	ATTR_I = 1 << 6,
     43 	ATTR_D = 1 << 7,
     44 	ATTR_MAX
     45 };
     46 
     47 /*
     48  * Selector used  by both `wm_move(wid, mode, x, y)` and `wm_resize(wid, mode, w, h)`
     49  * to choose between relative or absolute coordinates
     50  */
     51 enum {
     52 	ABSOLUTE = 0,
     53 	RELATIVE = 1
     54 };
     55 
     56 /*
     57  * Initialize the connection to the X server. The connection could then be
     58  * accessed by other functions through the "conn" variable.
     59  */
     60 int wm_init_xcb();
     61 
     62 /*
     63  * Close connection to the X server.
     64  */
     65 int wm_kill_xcb();
     66 
     67 /*
     68  * Check existence of a window.
     69  * + 1 - window exists
     70  * + 0 - window doesn't exist
     71  */
     72 int wm_is_alive(xcb_window_t wid);
     73 
     74 /*
     75  * Returns the value of the "override_redirect" attribute of a window.
     76  * When this attribute is set to 1, it means the window manager should NOT
     77  * handle this window.
     78  */
     79 int wm_is_ignored(xcb_window_t wid);
     80 
     81 /*
     82  * Returns 1 if a window match the mask, 0 otherwise.
     83  * Possible value for the masks are:
     84  * 	LIST_HIDDEN
     85  * 	LIST_IGNORE
     86  * 	LIST_ALL
     87  */
     88 int wm_is_listable(xcb_window_t wid, int mask);
     89 
     90 /*
     91  * Returns 1 if the window is mapped on screen, 0 otherwise
     92  */
     93 int wm_is_mapped(xcb_window_t wid);
     94 
     95 /*
     96  * Request the X server to add a new atom, and return this new atom ID
     97  */
     98 xcb_atom_t wm_add_atom(char *name, size_t len);
     99 
    100 /*
    101  * Change the value of the specified atom
    102  */
    103 int wm_set_atom(xcb_window_t wid, xcb_atom_t atom, xcb_atom_t type, size_t len, void *data);
    104 
    105 /*
    106  * Retrieve the value of the given atom. The value length is set in the
    107  * `len` pointer if specified
    108  */
    109 void *wm_get_atom(xcb_window_t wid, xcb_atom_t atom, xcb_atom_t type, size_t *len);
    110 
    111 /*
    112  * Retrieve the name of the given atom. The name length is set in the
    113  * `len` pointer if specified
    114  */
    115 char *wm_get_atom_name(xcb_atom_t atom, size_t *len);
    116 
    117 /*
    118  * Get the first screen, and set the `scrn` global variable accordingly.
    119  */
    120 int wm_get_screen();
    121 
    122 /*
    123  * Ask the list of all existing windows to the X server, and fills the `*list`
    124  * argument with them.
    125  * The windows are listed in stacking order, from lower to upper window.
    126  * Returns the number of windows in the *list array
    127  */
    128 int wm_get_windows(xcb_window_t wid, xcb_window_t **list);
    129 
    130 /*
    131  * Returns the window that has keyboard focus
    132  * Will return the root window ID if no window has focus
    133  */
    134 xcb_window_t wm_get_focus(void);
    135 
    136 /*
    137  * Retrieve the value of an attribute for a specific windows.
    138  * The possible values for the attributes are:
    139  * 	ATTR_W - width
    140  * 	ATTR_H - height
    141  * 	ATTR_X - X offset
    142  * 	ATTR_Y - Y offset
    143  * 	ATTR_B - border width
    144  * 	ATTR_M - map state
    145  * 	ATTR_I - ignore state (override_redirect)
    146  */
    147 int wm_get_attribute(xcb_window_t wid, int attr);
    148 
    149 /*
    150  * Get the cursor position, and store its coordinates in the `x` and `y`
    151  * pointers.
    152  * The `mode` attribute isn't used yet, but is reserved to ask for either
    153  * absolute or relative coordinates
    154  */
    155 int wm_get_cursor(int mode, uint32_t wid, int *x, int *y);
    156 
    157 /*
    158  * Set a window's border.
    159  * The color should be an hexadecimal number, eg: 0xdeadca7
    160  */
    161 int wm_set_border(int width, int color, xcb_window_t wid);
    162 
    163 /*
    164  * Give the input focus to the specified window
    165  */
    166 int wm_set_focus(xcb_window_t wid);
    167 
    168 /*
    169  * Change the cursor position, either relatively or absolutely, eg:
    170  * 	wm_set_cursor(10, 10, ABSOLUTE);
    171  * 	wm_set_cursor(-10, 20, RELATIVE);
    172  */
    173 int wm_set_cursor(int x, int y, int mode);
    174 
    175 /*
    176  * Set override_redirect value for given window
    177  */
    178 int wm_set_override(xcb_window_t wid, int override);
    179 
    180 /*
    181  * Teleport a window to the given position.
    182  */
    183 int wm_teleport(xcb_window_t wid, int w, int h, int x, int y);
    184 
    185 /*
    186  * Move a window to the given position, either relatively or absolutely.
    187  * If the wm_move is supposed to wm_move the window outside the screen, then the
    188  * windows will only be wm_moved to the edge of the screen.
    189  *
    190  * You cannot wm_move windows outside the screen with this method. Use
    191  * `wm_teleport()` instead.
    192  */
    193 int wm_move(xcb_window_t wid, int mode, int x, int y);
    194 
    195 /*
    196  * Resize a window to the given size, either relatively or absolutely.
    197  * If the wm_resize is supposed to put an area of the window outside the screen,
    198  * then the windows will only be wm_resized to the edge of the screen.
    199  *
    200  * You cannot wm_resize windows farther than the screen edge with this method. Use
    201  * `wm_teleport()` instead.
    202  */
    203 int wm_resize(xcb_window_t wid, int mode, int w, int h);
    204 
    205 /*
    206  * Change the mapping state of a window. The `mode` attribute can be as follow:
    207  * 	MAP
    208  * 	UNMAP
    209  * 	TOGGLE
    210  */
    211 int wm_remap(xcb_window_t wid, int mode);
    212 
    213 /*
    214  * Change the position of the given window in the stack order.
    215  * You can either put it at the top, or at the bottom.
    216  * The possible values for the mode are:
    217  * 	XCB_STACK_MODE_ABOVE
    218  * 	XCB_STACK_MODE_BELOW
    219  * 	XCB_STACK_MODE_OPPOSITE
    220  */
    221 int wm_restack(xcb_window_t wid, uint32_t mode);
    222 
    223 /*
    224  * Register the given event(s) on the window.
    225  * Multiple events can be registered by ORing them together
    226  */
    227 int wm_reg_window_event(xcb_window_t wid, uint32_t mask);
    228 
    229 /*
    230  * Register the given cursor event(s) on the window.
    231  * Multiple events can be registered by ORing them together.
    232  * The cursor will be changed to the `cursor` while the pointer is
    233  * grabbed, if not NULL.
    234  */
    235 int wm_reg_cursor_event(xcb_window_t wid, uint32_t mask, char *cursor);
    236 
    237 /*
    238  * Return the number of active monitors connected to the display where
    239  * window `wid` is sitting.
    240  * The `list` argument, if not NULL, will be filled with the monitor's
    241  * index numbers. Note that `list` must be big enough to hold all indexes,
    242  * as it is not reallocated.
    243  */
    244 int wm_get_monitors(xcb_window_t wid, int *list);
    245 
    246 /*
    247  * Return the info scructure defining monitor with index number `index`.
    248  */
    249 xcb_randr_monitor_info_t *wm_get_monitor(int index);
    250 
    251 /*
    252  * Return the index of the (first) monitor associated with the
    253  * coordinates.
    254  */
    255 int wm_find_monitor(int x, int y);
    256 
    257 #endif /* __LIBWM_H__ */