00001 /* 00002 * vim:ts=4:sw=4:expandtab 00003 */ 00004 #include <assert.h> 00005 #include <X11/Xcursor/Xcursor.h> 00006 #include <X11/cursorfont.h> 00007 00008 #include "i3.h" 00009 #include "xcb.h" 00010 #include "xcursor.h" 00011 00012 static Cursor cursors[XCURSOR_CURSOR_MAX]; 00013 00014 static const int xcb_cursors[XCURSOR_CURSOR_MAX] = { 00015 XCB_CURSOR_LEFT_PTR, 00016 XCB_CURSOR_SB_H_DOUBLE_ARROW, 00017 XCB_CURSOR_SB_V_DOUBLE_ARROW 00018 }; 00019 00020 static Cursor load_cursor(const char *name) { 00021 Cursor c = XcursorLibraryLoadCursor(xlibdpy, name); 00022 if (c == None) 00023 xcursor_supported = false; 00024 return c; 00025 } 00026 00027 void xcursor_load_cursors() { 00028 cursors[XCURSOR_CURSOR_POINTER] = load_cursor("left_ptr"); 00029 cursors[XCURSOR_CURSOR_RESIZE_HORIZONTAL] = load_cursor("sb_h_double_arrow"); 00030 cursors[XCURSOR_CURSOR_RESIZE_VERTICAL] = load_cursor("sb_v_double_arrow"); 00031 } 00032 00033 /* 00034 * Sets the cursor of the root window to the 'pointer' cursor. 00035 * 00036 * This function is called when i3 is initialized, because with some login 00037 * managers, the root window will not have a cursor otherwise. 00038 * 00039 * We have a separate xcursor function to use the same X11 connection as the 00040 * xcursor_load_cursors() function. If we mix the Xlib and the XCB connection, 00041 * races might occur (even though we flush the Xlib connection). 00042 * 00043 */ 00044 void xcursor_set_root_cursor() { 00045 XSetWindowAttributes attributes; 00046 attributes.cursor = xcursor_get_cursor(XCURSOR_CURSOR_POINTER); 00047 XChangeWindowAttributes(xlibdpy, DefaultRootWindow(xlibdpy), CWCursor, &attributes); 00048 XFlush(xlibdpy); 00049 } 00050 00051 Cursor xcursor_get_cursor(enum xcursor_cursor_t c) { 00052 assert(c >= 0 && c < XCURSOR_CURSOR_MAX); 00053 return cursors[c]; 00054 } 00055 00056 int xcursor_get_xcb_cursor(enum xcursor_cursor_t c) { 00057 assert(c >= 0 && c < XCURSOR_CURSOR_MAX); 00058 return xcb_cursors[c]; 00059 }