2012-08-12 12:18:43 +02:00
|
|
|
#undef I3__FILE__
|
|
|
|
#define I3__FILE__ "xcursor.c"
|
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
|
2015-04-04 02:17:56 +02:00
|
|
|
* © 2009 Michael Stapelberg and contributors (see also: LICENSE)
|
2011-10-23 00:40:02 +02:00
|
|
|
*
|
2013-07-13 10:58:06 +02:00
|
|
|
* xcursor.c: xcursor support for themed cursors.
|
2011-10-23 00:40:02 +02:00
|
|
|
*
|
2010-11-28 13:02:29 +01:00
|
|
|
*/
|
2010-11-27 00:26:51 +01:00
|
|
|
#include <assert.h>
|
2013-07-13 10:58:06 +02:00
|
|
|
#include <xcb/xcb_cursor.h>
|
2010-11-27 00:26:51 +01:00
|
|
|
|
|
|
|
#include "i3.h"
|
|
|
|
#include "xcb.h"
|
|
|
|
#include "xcursor.h"
|
|
|
|
|
2013-07-13 10:58:06 +02:00
|
|
|
static xcb_cursor_context_t *ctx;
|
|
|
|
static xcb_cursor_t cursors[XCURSOR_CURSOR_MAX];
|
2010-11-27 00:26:51 +01:00
|
|
|
|
|
|
|
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,
|
2014-06-15 19:07:02 +02:00
|
|
|
XCB_CURSOR_WATCH};
|
2010-11-27 00:26:51 +01:00
|
|
|
|
2012-03-31 10:53:04 +02:00
|
|
|
void xcursor_load_cursors(void) {
|
2013-07-13 10:58:06 +02:00
|
|
|
if (xcb_cursor_context_new(conn, root_screen, &ctx) < 0) {
|
|
|
|
ELOG("xcursor support unavailable\n");
|
|
|
|
xcursor_supported = false;
|
|
|
|
return;
|
|
|
|
}
|
2014-06-15 19:07:02 +02:00
|
|
|
#define LOAD_CURSOR(constant, name) \
|
|
|
|
do { \
|
2013-07-13 10:58:06 +02:00
|
|
|
cursors[constant] = xcb_cursor_load_cursor(ctx, name); \
|
|
|
|
} while (0)
|
|
|
|
LOAD_CURSOR(XCURSOR_CURSOR_POINTER, "left_ptr");
|
|
|
|
LOAD_CURSOR(XCURSOR_CURSOR_RESIZE_HORIZONTAL, "sb_h_double_arrow");
|
|
|
|
LOAD_CURSOR(XCURSOR_CURSOR_RESIZE_VERTICAL, "sb_v_double_arrow");
|
|
|
|
LOAD_CURSOR(XCURSOR_CURSOR_WATCH, "watch");
|
|
|
|
LOAD_CURSOR(XCURSOR_CURSOR_MOVE, "fleur");
|
|
|
|
LOAD_CURSOR(XCURSOR_CURSOR_TOP_LEFT_CORNER, "top_left_corner");
|
|
|
|
LOAD_CURSOR(XCURSOR_CURSOR_TOP_RIGHT_CORNER, "top_right_corner");
|
|
|
|
LOAD_CURSOR(XCURSOR_CURSOR_BOTTOM_LEFT_CORNER, "bottom_left_corner");
|
|
|
|
LOAD_CURSOR(XCURSOR_CURSOR_BOTTOM_RIGHT_CORNER, "bottom_right_corner");
|
|
|
|
#undef LOAD_CURSOR
|
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.
|
|
|
|
*
|
|
|
|
*/
|
2011-10-10 16:53:57 +02:00
|
|
|
void xcursor_set_root_cursor(int cursor_id) {
|
2013-07-13 10:58:06 +02:00
|
|
|
xcb_change_window_attributes(conn, root, XCB_CW_CURSOR,
|
2015-03-01 17:16:03 +01:00
|
|
|
(uint32_t[]){xcursor_get_cursor(cursor_id)});
|
2010-11-27 00:26:51 +01:00
|
|
|
}
|
|
|
|
|
2013-07-13 10:58:06 +02:00
|
|
|
xcb_cursor_t xcursor_get_cursor(enum xcursor_cursor_t c) {
|
2014-02-08 21:03:26 +01:00
|
|
|
assert(c < XCURSOR_CURSOR_MAX);
|
2010-11-27 00:26:51 +01:00
|
|
|
return cursors[c];
|
|
|
|
}
|
|
|
|
|
2010-11-28 13:02:29 +01:00
|
|
|
int xcursor_get_xcb_cursor(enum xcursor_cursor_t c) {
|
2014-02-08 21:03:26 +01:00
|
|
|
assert(c < XCURSOR_CURSOR_MAX);
|
2010-11-27 00:26:51 +01:00
|
|
|
return xcb_cursors[c];
|
|
|
|
}
|