2010-11-28 13:02:29 +01:00
|
|
|
/*
|
|
|
|
* vim:ts=4:sw=4:expandtab
|
2011-10-23 00:40:02 +02:00
|
|
|
*
|
|
|
|
* i3 - an improved dynamic tiling window manager
|
|
|
|
* © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
|
|
|
|
*
|
|
|
|
* xcursor.c: libXcursor support for themed cursors.
|
|
|
|
*
|
2010-11-28 13:02:29 +01:00
|
|
|
*/
|
2010-11-27 00:26:51 +01:00
|
|
|
#include <assert.h>
|
|
|
|
#include <X11/Xcursor/Xcursor.h>
|
|
|
|
#include <X11/cursorfont.h>
|
|
|
|
|
|
|
|
#include "i3.h"
|
|
|
|
#include "xcb.h"
|
|
|
|
#include "xcursor.h"
|
|
|
|
|
|
|
|
static Cursor cursors[XCURSOR_CURSOR_MAX];
|
|
|
|
|
|
|
|
static const int xcb_cursors[XCURSOR_CURSOR_MAX] = {
|
|
|
|
XCB_CURSOR_LEFT_PTR,
|
|
|
|
XCB_CURSOR_SB_H_DOUBLE_ARROW,
|
2011-10-10 16:53:57 +02:00
|
|
|
XCB_CURSOR_SB_V_DOUBLE_ARROW,
|
|
|
|
XCB_CURSOR_WATCH
|
2010-11-27 00:26:51 +01:00
|
|
|
};
|
|
|
|
|
2011-02-05 17:23:02 +01:00
|
|
|
static Cursor load_cursor(const char *name) {
|
2010-11-27 00:26:51 +01:00
|
|
|
Cursor c = XcursorLibraryLoadCursor(xlibdpy, name);
|
|
|
|
if (c == None)
|
2011-02-05 17:23:02 +01:00
|
|
|
xcursor_supported = false;
|
2010-11-27 00:26:51 +01:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2010-11-28 13:02:29 +01:00
|
|
|
void xcursor_load_cursors() {
|
2011-02-05 17:23:02 +01:00
|
|
|
cursors[XCURSOR_CURSOR_POINTER] = load_cursor("left_ptr");
|
|
|
|
cursors[XCURSOR_CURSOR_RESIZE_HORIZONTAL] = load_cursor("sb_h_double_arrow");
|
|
|
|
cursors[XCURSOR_CURSOR_RESIZE_VERTICAL] = load_cursor("sb_v_double_arrow");
|
2011-10-10 16:53:57 +02:00
|
|
|
cursors[XCURSOR_CURSOR_WATCH] = load_cursor("watch");
|
2011-07-29 13:12:28 +02:00
|
|
|
}
|
2011-04-01 21:57:08 +02:00
|
|
|
|
2011-07-29 13:12:28 +02:00
|
|
|
/*
|
|
|
|
* Sets the cursor of the root window to the 'pointer' cursor.
|
|
|
|
*
|
|
|
|
* This function is called when i3 is initialized, because with some login
|
|
|
|
* managers, the root window will not have a cursor otherwise.
|
|
|
|
*
|
|
|
|
* We have a separate xcursor function to use the same X11 connection as the
|
|
|
|
* xcursor_load_cursors() function. If we mix the Xlib and the XCB connection,
|
|
|
|
* races might occur (even though we flush the Xlib connection).
|
|
|
|
*
|
|
|
|
*/
|
2011-10-10 16:53:57 +02:00
|
|
|
void xcursor_set_root_cursor(int cursor_id) {
|
2011-07-29 13:12:28 +02:00
|
|
|
XSetWindowAttributes attributes;
|
2011-10-10 16:53:57 +02:00
|
|
|
attributes.cursor = xcursor_get_cursor(cursor_id);
|
2011-07-29 13:12:28 +02:00
|
|
|
XChangeWindowAttributes(xlibdpy, DefaultRootWindow(xlibdpy), CWCursor, &attributes);
|
2011-04-01 21:57:08 +02:00
|
|
|
XFlush(xlibdpy);
|
2010-11-27 00:26:51 +01:00
|
|
|
}
|
|
|
|
|
2010-11-28 13:02:29 +01:00
|
|
|
Cursor xcursor_get_cursor(enum xcursor_cursor_t c) {
|
2010-11-27 00:26:51 +01:00
|
|
|
assert(c >= 0 && c < XCURSOR_CURSOR_MAX);
|
|
|
|
return cursors[c];
|
|
|
|
}
|
|
|
|
|
2010-11-28 13:02:29 +01:00
|
|
|
int xcursor_get_xcb_cursor(enum xcursor_cursor_t c) {
|
2010-11-27 00:26:51 +01:00
|
|
|
assert(c >= 0 && c < XCURSOR_CURSOR_MAX);
|
|
|
|
return xcb_cursors[c];
|
|
|
|
}
|