* yajl (the IPC interface uses JSON to serialize data)
* asciidoc >= 8.3.0 for docs/hacking-howto
* asciidoc, xmlto, docbook-xml for man/i3.man
+ * libxcursor
* Xlib, the one that comes with your X-Server
* x11-utils for xmessage (only for displaying the welcome message, so this is
mainly interesting for distributors)
# Depend on the object files of all source-files in src/*.c and on all header files
AUTOGENERATED:=src/cfgparse.tab.c src/cfgparse.yy.c src/cmdparse.tab.c src/cmdparse.yy.c
-FILES:=src/ipc.c src/main.c src/log.c src/util.c src/tree.c src/xcb.c src/manage.c src/workspace.c src/x.c src/floating.c src/click.c src/config.c src/handlers.c src/randr.c src/xinerama.c src/con.c src/load_layout.c src/render.c src/window.c src/match.c
+FILES:=src/ipc.c src/main.c src/log.c src/util.c src/tree.c src/xcb.c src/manage.c src/workspace.c src/x.c src/floating.c src/click.c src/config.c src/handlers.c src/randr.c src/xinerama.c src/con.c src/load_layout.c src/render.c src/window.c src/match.c src/xcursor.c
FILES:=$(FILES:.c=.o)
HEADERS:=$(filter-out include/loglevels.h,$(wildcard include/*.h))
LDFLAGS += -lxcb-randr
LDFLAGS += -lxcb
LDFLAGS += -lyajl
+LDFLAGS += -lXcursor
LDFLAGS += -lX11
LDFLAGS += -lev
LDFLAGS += -L/usr/local/lib -L/usr/pkg/lib
Priority: extra
Maintainer: Michael Stapelberg <michael@stapelberg.de>
DM-Upload-Allowed: yes
-Build-Depends: debhelper (>= 5), libx11-dev, libxcb-aux0-dev (>= 0.3.3), libxcb-keysyms1-dev, libxcb-xinerama0-dev (>= 1.1), libxcb-randr0-dev, libxcb-event1-dev (>= 0.3.3), libxcb-property1-dev (>= 0.3.3), libxcb-atom1-dev (>= 0.3.3), libxcb-icccm1-dev (>= 0.3.3), asciidoc (>= 8.4.4), xmlto, docbook-xml, pkg-config, libev-dev, flex, bison, libyajl-dev
+Build-Depends: debhelper (>= 5), libx11-dev, libxcb-aux0-dev (>= 0.3.3), libxcb-keysyms1-dev, libxcb-xinerama0-dev (>= 1.1), libxcb-randr0-dev, libxcb-event1-dev (>= 0.3.3), libxcb-property1-dev (>= 0.3.3), libxcb-atom1-dev (>= 0.3.3), libxcb-icccm1-dev (>= 0.3.3), libxcursor-dev, asciidoc (>= 8.4.4), xmlto, docbook-xml, pkg-config, libev-dev, flex, bison, libyajl-dev
Standards-Version: 3.8.3
Homepage: http://i3.zekjur.net/
#include "window.h"
#include "match.h"
#include "cmdparse.h"
+#include "xcursor.h"
#endif
extern xcb_connection_t *conn;
extern xcb_key_symbols_t *keysyms;
extern char **start_argv;
-extern Display *xkbdpy;
+extern Display *xlibdpy, *xkbdpy;
extern int xkb_current_group;
extern TAILQ_HEAD(bindings_head, Binding) *bindings;
extern TAILQ_HEAD(autostarts_head, Autostart) autostarts;
extern xcb_event_handlers_t evenths;
extern xcb_property_handlers_t prophs;
extern uint8_t root_depth;
-extern bool xkb_supported;
+extern bool xcursor_supported, xkb_supported;
extern xcb_atom_t atoms[NUM_ATOMS];
extern xcb_window_t root;
#define _XCB_H
#include "data.h"
+#include "xcursor.h"
#define _NET_WM_STATE_REMOVE 0
#define _NET_WM_STATE_ADD 1
*
*/
xcb_window_t create_window(xcb_connection_t *conn, Rect r, uint16_t window_class,
- int cursor, bool map, uint32_t mask, uint32_t *values);
+ enum xcursor_cursor_t cursor, bool map, uint32_t mask, uint32_t *values);
/**
* Changes a single value in the graphic context (so one doesn’t have to
--- /dev/null
+#ifndef _XCURSOR_CURSOR_H
+#define _XCURSOR_CURSOR_H
+
+#include <X11/Xlib.h>
+
+enum xcursor_cursor_t {
+ XCURSOR_CURSOR_POINTER = 0,
+ XCURSOR_CURSOR_RESIZE_HORIZONTAL,
+ XCURSOR_CURSOR_RESIZE_VERTICAL,
+ XCURSOR_CURSOR_MAX
+};
+
+extern void xcursor_load_cursors();
+extern Cursor xcursor_get_cursor(enum xcursor_cursor_t c);
+extern int xcursor_get_xcb_cursor(enum xcursor_cursor_t c);
+
+#endif
* vim:ts=4:sw=4:expandtab
*/
#include <ev.h>
+#include <fcntl.h>
#include <limits.h>
#include "all.h"
xcb_key_symbols_t *keysyms;
+/* Those are our connections to X11 for use with libXcursor and XKB */
+Display *xlibdpy, *xkbdpy;
+
/* The list of key bindings */
struct bindings_head *bindings;
/* The list of assignments */
struct assignments_head assignments = TAILQ_HEAD_INITIALIZER(assignments);
+/* We hope that those are supported and set them to true */
+bool xcursor_supported = true;
+bool xkb_supported = true;
+
/*
* This callback is only a dummy, see xcb_prepare_cb and xcb_check_cb.
* See also man libev(3): "ev_prepare" and "ev_check" - customise your event loop
REQUEST_ATOM(_NET_ACTIVE_WINDOW);
REQUEST_ATOM(_NET_WORKAREA);
+ /* Initialize the Xlib connection */
+ xlibdpy = xkbdpy = XOpenDisplay(NULL);
+
+ /* Try to load the X cursors and initialize the XKB extension */
+ if (xlibdpy == NULL) {
+ ELOG("ERROR: XOpenDisplay() failed, disabling libXcursor/XKB support\n");
+ xcursor_supported = false;
+ xkb_supported = false;
+ } else if (fcntl(ConnectionNumber(xlibdpy), F_SETFD, FD_CLOEXEC) == -1) {
+ ELOG("Could not set FD_CLOEXEC on xkbdpy\n");
+ return 1;
+ } else {
+ xcursor_load_cursors();
+ /*init_xkb();*/
+ }
+
memset(&evenths, 0, sizeof(xcb_event_handlers_t));
memset(&prophs, 0, sizeof(xcb_property_handlers_t));
values[1] = FRAME_EVENT_MASK;
Rect dims = { -15, -15, 10, 10 };
- con->frame = create_window(conn, dims, XCB_WINDOW_CLASS_INPUT_OUTPUT, -1, false, mask, values);
+ con->frame = create_window(conn, dims, XCB_WINDOW_CLASS_INPUT_OUTPUT, XCURSOR_CURSOR_POINTER, false, mask, values);
con->gc = xcb_generate_id(conn);
xcb_create_gc(conn, con->gc, con->frame, 0, 0);
* for errors.
*
*/
-xcb_window_t create_window(xcb_connection_t *conn, Rect dims, uint16_t window_class, int cursor,
- bool map, uint32_t mask, uint32_t *values) {
- xcb_window_t root = xcb_setup_roots_iterator(xcb_get_setup(conn)).data->root;
- xcb_window_t result = xcb_generate_id(conn);
- xcb_cursor_t cursor_id = xcb_generate_id(conn);
-
- /* If the window class is XCB_WINDOW_CLASS_INPUT_ONLY, depth has to be 0 */
- uint16_t depth = (window_class == XCB_WINDOW_CLASS_INPUT_ONLY ? 0 : XCB_COPY_FROM_PARENT);
-
- xcb_create_window(conn,
- depth,
- result, /* the window id */
- root, /* parent == root */
- dims.x, dims.y, dims.width, dims.height, /* dimensions */
- 0, /* border = 0, we draw our own */
- window_class,
- XCB_WINDOW_CLASS_COPY_FROM_PARENT, /* copy visual from parent */
- mask,
- values);
-
- /* Set the cursor */
+xcb_window_t create_window(xcb_connection_t *conn, Rect dims, uint16_t window_class,
+ enum xcursor_cursor_t cursor, bool map, uint32_t mask, uint32_t *values) {
+ xcb_window_t root = xcb_setup_roots_iterator(xcb_get_setup(conn)).data->root;
+ xcb_window_t result = xcb_generate_id(conn);
+ xcb_cursor_t cursor_id = xcb_generate_id(conn);
+
+ /* If the window class is XCB_WINDOW_CLASS_INPUT_ONLY, depth has to be 0 */
+ uint16_t depth = (window_class == XCB_WINDOW_CLASS_INPUT_ONLY ? 0 : XCB_COPY_FROM_PARENT);
+
+ xcb_create_window(conn,
+ depth,
+ result, /* the window id */
+ root, /* parent == root */
+ dims.x, dims.y, dims.width, dims.height, /* dimensions */
+ 0, /* border = 0, we draw our own */
+ window_class,
+ XCB_WINDOW_CLASS_COPY_FROM_PARENT, /* copy visual from parent */
+ mask,
+ values);
+
+ /* Set the cursor */
+ if (xcursor_supported) {
+ mask = XCB_CW_CURSOR;
+ values[0] = xcursor_get_cursor(cursor);
+ xcb_change_window_attributes(conn, result, mask, values);
+ } else {
i3Font *cursor_font = load_font(conn, "cursor");
+ int xcb_cursor = xcursor_get_xcb_cursor(cursor);
xcb_create_glyph_cursor(conn, cursor_id, cursor_font->id, cursor_font->id,
- (cursor == -1 ? XCB_CURSOR_LEFT_PTR : cursor),
- (cursor == -1 ? XCB_CURSOR_LEFT_PTR : cursor) + 1,
- 0, 0, 0, 65535, 65535, 65535);
+ xcb_cursor, xcb_cursor + 1, 0, 0, 0, 65535, 65535, 65535);
xcb_change_window_attributes(conn, result, XCB_CW_CURSOR, &cursor_id);
xcb_free_cursor(conn, cursor_id);
+ }
- /* Map the window (= make it visible) */
- if (map)
- xcb_map_window(conn, result);
+ /* Map the window (= make it visible) */
+ if (map)
+ xcb_map_window(conn, result);
- return result;
+ return result;
}
/*
--- /dev/null
+#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,
+ XCB_CURSOR_SB_V_DOUBLE_ARROW
+};
+
+static Cursor load_cursor(const char *name, int font)
+{
+ Cursor c = XcursorLibraryLoadCursor(xlibdpy, name);
+ if (c == None)
+ c = XCreateFontCursor(xlibdpy, font);
+ return c;
+}
+
+void xcursor_load_cursors()
+{
+ cursors[XCURSOR_CURSOR_POINTER] = load_cursor("left_ptr", XC_left_ptr);
+ cursors[XCURSOR_CURSOR_RESIZE_HORIZONTAL] = load_cursor("sb_h_double_arrow", XC_sb_h_double_arrow);
+ cursors[XCURSOR_CURSOR_RESIZE_VERTICAL] = load_cursor("sb_v_double_arrow", XC_sb_v_double_arrow);
+}
+
+Cursor xcursor_get_cursor(enum xcursor_cursor_t c)
+{
+ assert(c >= 0 && c < XCURSOR_CURSOR_MAX);
+ return cursors[c];
+}
+
+int xcursor_get_xcb_cursor(enum xcursor_cursor_t c)
+{
+ assert(c >= 0 && c < XCURSOR_CURSOR_MAX);
+ return xcb_cursors[c];
+}