2015-07-27 04:17:12 -04:00
|
|
|
#ifndef X11_ROFI_HELPER_H
|
|
|
|
#define X11_ROFI_HELPER_H
|
2016-03-05 05:08:32 -05:00
|
|
|
#include <glib.h>
|
2016-01-09 10:22:09 -05:00
|
|
|
#include <cairo.h>
|
2016-02-21 13:42:32 -05:00
|
|
|
#include <xcb/xcb.h>
|
2017-02-17 08:06:31 -05:00
|
|
|
#include <xkbcommon/xkbcommon.h>
|
2015-02-09 13:35:51 -05:00
|
|
|
|
2016-02-22 05:39:52 -05:00
|
|
|
#include "xkb.h"
|
|
|
|
|
2016-01-07 02:54:24 -05:00
|
|
|
/**
|
|
|
|
* @defgroup X11Helper X11Helper
|
|
|
|
* @ingroup HELPERS
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2015-02-09 13:35:51 -05:00
|
|
|
/**
|
2016-02-27 18:09:05 -05:00
|
|
|
* @param w The xcb_window_t to read property from.
|
2015-02-09 13:35:51 -05:00
|
|
|
* @param atom The property identifier
|
|
|
|
*
|
|
|
|
* Get text property defined by atom from window.
|
|
|
|
* Support utf8.
|
|
|
|
*
|
|
|
|
* @returns a newly allocated string with the result or NULL
|
|
|
|
*/
|
2016-03-01 12:11:55 -05:00
|
|
|
char* window_get_text_prop ( xcb_window_t w, xcb_atom_t atom );
|
2015-02-09 13:35:51 -05:00
|
|
|
|
|
|
|
/**
|
2016-10-14 10:46:54 -04:00
|
|
|
* @param w The xcb_window_t to set property on
|
|
|
|
* @param prop Atom of the property to change
|
|
|
|
* @param atoms List of atoms to change the property too
|
2016-11-15 15:54:31 -05:00
|
|
|
* @param count The length of the atoms list.
|
2016-10-14 10:46:54 -04:00
|
|
|
*
|
|
|
|
* Set property on window.
|
2015-02-09 13:35:51 -05:00
|
|
|
*/
|
2016-10-14 10:46:54 -04:00
|
|
|
void window_set_atom_prop ( xcb_window_t w, xcb_atom_t prop, xcb_atom_t *atoms, int count );
|
|
|
|
|
|
|
|
/** For getting the atoms in an enum */
|
2015-02-09 13:35:51 -05:00
|
|
|
#define ATOM_ENUM( x ) x
|
2016-10-14 10:46:54 -04:00
|
|
|
/** Get the atoms as strings. */
|
2015-02-09 13:35:51 -05:00
|
|
|
#define ATOM_CHAR( x ) # x
|
|
|
|
|
2016-10-14 10:46:54 -04:00
|
|
|
/** Atoms we want to pre-load */
|
2016-02-28 09:32:53 -05:00
|
|
|
#define EWMH_ATOMS( X ) \
|
|
|
|
X ( _NET_WM_WINDOW_OPACITY ), \
|
|
|
|
X ( I3_SOCKET_PATH ), \
|
2016-04-10 06:05:34 -04:00
|
|
|
X ( UTF8_STRING ), \
|
|
|
|
X ( STRING ), \
|
2016-12-24 08:12:54 -05:00
|
|
|
X ( CLIPBOARD ), \
|
2016-05-06 06:40:28 -04:00
|
|
|
X ( WM_WINDOW_ROLE ), \
|
|
|
|
X ( _XROOTPMAP_ID ), \
|
2016-09-08 02:53:14 -04:00
|
|
|
X ( _MOTIF_WM_HINTS ), \
|
2016-05-06 06:40:28 -04:00
|
|
|
X ( ESETROOT_PMAP_ID )
|
2015-02-09 13:35:51 -05:00
|
|
|
|
2016-10-14 10:46:54 -04:00
|
|
|
/** enumeration of the atoms. */
|
2015-02-09 13:35:51 -05:00
|
|
|
enum { EWMH_ATOMS ( ATOM_ENUM ), NUM_NETATOMS };
|
2016-10-14 10:46:54 -04:00
|
|
|
/** atoms as string */
|
2015-02-09 13:35:51 -05:00
|
|
|
extern const char *netatom_names[];
|
2016-10-14 10:46:54 -04:00
|
|
|
/** atoms */
|
2016-02-27 18:09:05 -05:00
|
|
|
extern xcb_atom_t netatoms[NUM_NETATOMS];
|
2016-08-19 04:46:38 -04:00
|
|
|
|
2016-10-14 10:46:54 -04:00
|
|
|
/**
|
|
|
|
* Enumerator describing the different modifier keys.
|
|
|
|
*/
|
2016-09-02 12:19:16 -04:00
|
|
|
enum
|
|
|
|
{
|
2016-10-14 10:46:54 -04:00
|
|
|
/** Shift key */
|
2016-09-02 12:19:16 -04:00
|
|
|
X11MOD_SHIFT,
|
2016-10-14 10:46:54 -04:00
|
|
|
/** Control Key */
|
2016-09-02 12:19:16 -04:00
|
|
|
X11MOD_CONTROL,
|
2016-10-14 10:46:54 -04:00
|
|
|
/** Alt key */
|
2016-09-02 12:19:16 -04:00
|
|
|
X11MOD_ALT,
|
2016-10-14 10:46:54 -04:00
|
|
|
/** Meta key */
|
2016-09-02 12:19:16 -04:00
|
|
|
X11MOD_META,
|
2016-10-14 10:46:54 -04:00
|
|
|
/** Super (window) key */
|
2016-09-02 12:19:16 -04:00
|
|
|
X11MOD_SUPER,
|
2016-10-14 10:46:54 -04:00
|
|
|
/** Hyper key */
|
2016-09-02 12:19:16 -04:00
|
|
|
X11MOD_HYPER,
|
2016-10-14 10:46:54 -04:00
|
|
|
/** Any modifier */
|
2016-09-02 12:19:16 -04:00
|
|
|
X11MOD_ANY,
|
2016-10-14 10:46:54 -04:00
|
|
|
/** Number of modifier keys */
|
2016-09-02 12:19:16 -04:00
|
|
|
NUM_X11MOD
|
|
|
|
};
|
|
|
|
|
2016-10-14 10:46:54 -04:00
|
|
|
/**
|
|
|
|
* Structure describing a workarea/monitor.
|
|
|
|
*/
|
2016-08-19 04:46:38 -04:00
|
|
|
typedef struct _workarea
|
2015-02-09 13:35:51 -05:00
|
|
|
{
|
2016-10-14 10:46:54 -04:00
|
|
|
/** numeric monitor id. */
|
2016-08-19 04:46:38 -04:00
|
|
|
int monitor_id;
|
2016-10-14 10:46:54 -04:00
|
|
|
/** if monitor is set as primary monitor. */
|
2016-08-19 04:46:38 -04:00
|
|
|
int primary;
|
2016-10-14 10:46:54 -04:00
|
|
|
/** Horizontal location (in pixels) of the monitor. */
|
|
|
|
int x;
|
|
|
|
/** Vertical location (in pixels) of the monitor. */
|
|
|
|
int y;
|
|
|
|
/** Width of the monitor. */
|
|
|
|
int w;
|
|
|
|
/** Height of the monitor */
|
|
|
|
int h;
|
2017-01-21 06:58:52 -05:00
|
|
|
int mw, mh;
|
2016-10-14 10:46:54 -04:00
|
|
|
/** Output name of the monitor, e.g. eDP1 or VGA-1 */
|
2016-08-19 04:46:38 -04:00
|
|
|
char *name;
|
2016-10-14 10:46:54 -04:00
|
|
|
/** Pointer to next monitor */
|
2016-08-19 04:46:38 -04:00
|
|
|
struct _workarea *next;
|
2015-02-09 13:35:51 -05:00
|
|
|
} workarea;
|
|
|
|
|
2016-10-14 10:46:54 -04:00
|
|
|
/**
|
|
|
|
* @param mon workarea to be filled in.
|
|
|
|
*
|
|
|
|
* Fills in #mon with the information about the monitor rofi should show on.
|
|
|
|
*
|
|
|
|
* @returns TRUE if monitor is found, FALSE if no monitor could be detected.
|
|
|
|
*/
|
|
|
|
int monitor_active ( workarea *mon );
|
2015-02-09 13:35:51 -05:00
|
|
|
|
|
|
|
/**
|
2016-10-14 10:46:54 -04:00
|
|
|
* Release keyboard grab on root window.
|
2015-02-09 13:35:51 -05:00
|
|
|
*/
|
2016-03-01 12:11:55 -05:00
|
|
|
void release_keyboard ( void );
|
2016-10-14 10:46:54 -04:00
|
|
|
/**
|
|
|
|
* Release pointer grab on root window.
|
|
|
|
*/
|
2016-05-09 02:47:28 -04:00
|
|
|
void release_pointer ( void );
|
2015-02-09 13:35:51 -05:00
|
|
|
|
|
|
|
/**
|
2016-02-27 18:09:05 -05:00
|
|
|
* @param w xcb_window_t we want to grab keyboard on.
|
2017-01-06 05:00:27 -05:00
|
|
|
* @param iters Number of retries.
|
2015-02-09 13:35:51 -05:00
|
|
|
*
|
2016-10-14 10:46:54 -04:00
|
|
|
* Grab keyboard.
|
2015-02-09 13:35:51 -05:00
|
|
|
*
|
|
|
|
* @return 1 when keyboard is grabbed, 0 not.
|
|
|
|
*/
|
2017-01-06 05:00:27 -05:00
|
|
|
int take_keyboard ( xcb_window_t w, int iters );
|
2016-10-14 10:46:54 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param w xcb_window_t we want to grab mouse on.
|
2017-01-06 05:00:27 -05:00
|
|
|
* @param iters Number of retries.
|
2016-10-14 10:46:54 -04:00
|
|
|
*
|
|
|
|
* Grab mouse.
|
|
|
|
*
|
|
|
|
* @return 1 when mouse is grabbed, 0 not.
|
|
|
|
*/
|
2017-01-06 05:00:27 -05:00
|
|
|
int take_pointer ( xcb_window_t w, int iters );
|
2015-02-09 13:35:51 -05:00
|
|
|
|
2016-02-23 04:44:36 -05:00
|
|
|
/**
|
|
|
|
* @param mask The mask to canonilize
|
|
|
|
*
|
|
|
|
* @return The canonilized mask
|
|
|
|
*/
|
|
|
|
unsigned int x11_canonalize_mask ( unsigned int mask );
|
|
|
|
|
2016-10-14 10:46:54 -04:00
|
|
|
/**
|
|
|
|
* @param xkb the xkb structure.
|
|
|
|
*
|
|
|
|
* Calculates the mask of all active modifier keys.
|
|
|
|
*
|
|
|
|
* @returns the mask describing all active modifier keys.
|
|
|
|
*/
|
2016-04-07 14:28:40 -04:00
|
|
|
unsigned int x11_get_current_mask ( xkb_stuff *xkb );
|
|
|
|
|
2015-02-09 14:05:30 -05:00
|
|
|
/**
|
|
|
|
* @param combo String representing the key combo
|
|
|
|
* @param mod [out] The modifier specified (or AnyModifier if not specified)
|
|
|
|
* @param key [out] The key specified
|
2016-07-29 02:32:34 -04:00
|
|
|
* @param release [out] If it should react on key-release, not key-press
|
2015-02-09 14:05:30 -05:00
|
|
|
*
|
|
|
|
* Parse key from user input string.
|
|
|
|
*/
|
2016-11-14 12:32:22 -05:00
|
|
|
gboolean x11_parse_key ( const char *combo, unsigned int *mod, xkb_keysym_t *key, gboolean *release, GString * );
|
2015-02-09 13:35:51 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Setup several items required.
|
|
|
|
* * Error handling,
|
|
|
|
* * Numlock detection
|
|
|
|
* * Cache
|
|
|
|
*/
|
2016-03-01 12:11:55 -05:00
|
|
|
void x11_setup ( xkb_stuff *xkb );
|
2015-02-14 13:42:04 -05:00
|
|
|
|
2016-10-14 10:46:54 -04:00
|
|
|
/**
|
|
|
|
* Depth of visual
|
|
|
|
*/
|
|
|
|
extern xcb_depth_t *depth;
|
|
|
|
/**
|
|
|
|
* Visual to use for creating window
|
|
|
|
*/
|
2016-02-21 13:42:32 -05:00
|
|
|
extern xcb_visualtype_t *visual;
|
2016-10-14 10:46:54 -04:00
|
|
|
/**
|
|
|
|
* Color map to use for creating window
|
|
|
|
*/
|
|
|
|
extern xcb_colormap_t map;
|
2016-11-15 02:24:06 -05:00
|
|
|
|
2015-02-14 13:42:04 -05:00
|
|
|
/**
|
|
|
|
* This function tries to create a 32bit TrueColor colormap.
|
|
|
|
* If this fails, it falls back to the default for the connected display.
|
|
|
|
*/
|
2016-03-01 12:11:55 -05:00
|
|
|
void x11_create_visual_and_colormap ( void );
|
2015-02-14 13:42:04 -05:00
|
|
|
|
2016-10-14 10:46:54 -04:00
|
|
|
/**
|
|
|
|
* Structure describing a cairo color.
|
|
|
|
*/
|
2016-02-21 13:27:53 -05:00
|
|
|
typedef struct
|
|
|
|
{
|
2016-10-14 10:46:54 -04:00
|
|
|
/** red channel */
|
|
|
|
double red;
|
|
|
|
/** green channel */
|
|
|
|
double green;
|
|
|
|
/** blue channel */
|
|
|
|
double blue;
|
|
|
|
/** alpha channel */
|
|
|
|
double alpha;
|
2016-02-21 13:27:53 -05:00
|
|
|
} Color;
|
|
|
|
|
2015-02-14 13:42:04 -05:00
|
|
|
/**
|
|
|
|
* @param name String representing the color.
|
|
|
|
*
|
|
|
|
* Allocate a pixel value for an X named color
|
|
|
|
*/
|
2016-02-21 13:42:32 -05:00
|
|
|
Color color_get ( const char *const name );
|
2015-04-06 11:13:26 -04:00
|
|
|
|
2016-05-06 06:40:28 -04:00
|
|
|
/**
|
|
|
|
* Gets a surface containing the background image of the desktop.
|
|
|
|
*
|
2016-07-29 02:32:34 -04:00
|
|
|
* @returns a cairo surface with the background image of the desktop.
|
2016-05-06 06:40:28 -04:00
|
|
|
*/
|
|
|
|
cairo_surface_t * x11_helper_get_bg_surface ( void );
|
2016-11-15 02:24:06 -05:00
|
|
|
/**
|
|
|
|
* Gets a surface for the root window of the desktop.
|
|
|
|
*
|
|
|
|
* Can be used to take screenshot.
|
|
|
|
*
|
|
|
|
* @returns a cairo surface for the root window of the desktop.
|
|
|
|
*/
|
|
|
|
cairo_surface_t *x11_helper_get_screenshot_surface ( void );
|
2016-08-19 04:46:38 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an internal represenation of the available monitors.
|
|
|
|
* Used for positioning rofi.
|
|
|
|
*/
|
|
|
|
void x11_build_monitor_layout ( void );
|
2016-10-14 10:46:54 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Dump the monitor layout to stdout.
|
|
|
|
*/
|
2016-08-19 04:46:38 -04:00
|
|
|
void x11_dump_monitor_layout ( void );
|
2016-10-14 10:46:54 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param mask the mask to check for key
|
|
|
|
* @param key the key to check in mask
|
|
|
|
*
|
|
|
|
* Check if key is in the modifier mask.
|
|
|
|
*
|
|
|
|
* @returns TRUE if key is in the modifier mask
|
|
|
|
*/
|
2016-09-08 02:53:14 -04:00
|
|
|
int x11_modifier_active ( unsigned int mask, int key );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param window The X11 window to modify
|
|
|
|
*
|
|
|
|
* Set the right hints to disable the window decoration.
|
|
|
|
* (Set MOTIF_WM_HINTS, decoration field)
|
|
|
|
*/
|
|
|
|
void x11_disable_decoration ( xcb_window_t window );
|
2017-02-11 10:53:37 -05:00
|
|
|
|
2017-03-11 07:20:46 -05:00
|
|
|
/**
|
|
|
|
* List of window managers that need different behaviour to functioning.
|
|
|
|
*/
|
2017-03-04 13:41:06 -05:00
|
|
|
typedef enum
|
|
|
|
{
|
2017-02-11 10:53:37 -05:00
|
|
|
/** Default EWHM compatible window manager */
|
2017-03-04 13:41:06 -05:00
|
|
|
WM_EWHM = 0,
|
2017-02-11 10:53:37 -05:00
|
|
|
/** I3 Window manager */
|
2017-03-04 13:41:06 -05:00
|
|
|
WM_I3 = 1,
|
2017-02-11 10:53:37 -05:00
|
|
|
/** Awesome window manager */
|
2017-03-04 13:41:06 -05:00
|
|
|
WM_AWESOME = 2,
|
2017-02-18 04:47:53 -05:00
|
|
|
/** Openbox window manager */
|
2017-03-04 13:41:06 -05:00
|
|
|
WM_OPENBOX = 4
|
2017-02-11 10:53:37 -05:00
|
|
|
} WindowManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates the current window manager.
|
|
|
|
* This is used for work-arounds.
|
|
|
|
*/
|
|
|
|
extern WindowManager current_window_manager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* discover the window manager.
|
|
|
|
*/
|
|
|
|
void x11_helper_discover_window_manager ( void );
|
2016-01-07 02:54:24 -05:00
|
|
|
/*@}*/
|
2015-02-09 13:35:51 -05:00
|
|
|
#endif
|