libXcursor support (themed cursors).
This commit is contained in:
parent
3bab222aa7
commit
69fc6449dc
1
DEPENDS
1
DEPENDS
|
@ -11,6 +11,7 @@ mentioned below until a fix is provided.
|
||||||
* yajl (the IPC interface uses JSON to serialize data)
|
* yajl (the IPC interface uses JSON to serialize data)
|
||||||
* asciidoc >= 8.3.0 for docs/hacking-howto
|
* asciidoc >= 8.3.0 for docs/hacking-howto
|
||||||
* asciidoc, xmlto, docbook-xml for man/i3.man
|
* asciidoc, xmlto, docbook-xml for man/i3.man
|
||||||
|
* libxcursor
|
||||||
* Xlib, the one that comes with your X-Server
|
* Xlib, the one that comes with your X-Server
|
||||||
* x11-utils for xmessage (only for displaying the welcome message, so this is
|
* x11-utils for xmessage (only for displaying the welcome message, so this is
|
||||||
mainly interesting for distributors)
|
mainly interesting for distributors)
|
||||||
|
|
2
Makefile
2
Makefile
|
@ -4,7 +4,7 @@ include $(TOPDIR)/common.mk
|
||||||
|
|
||||||
# Depend on the object files of all source-files in src/*.c and on all header files
|
# 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
|
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)
|
FILES:=$(FILES:.c=.o)
|
||||||
HEADERS:=$(filter-out include/loglevels.h,$(wildcard include/*.h))
|
HEADERS:=$(filter-out include/loglevels.h,$(wildcard include/*.h))
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ LDFLAGS += -lxcb-xinerama
|
||||||
LDFLAGS += -lxcb-randr
|
LDFLAGS += -lxcb-randr
|
||||||
LDFLAGS += -lxcb
|
LDFLAGS += -lxcb
|
||||||
LDFLAGS += -lyajl
|
LDFLAGS += -lyajl
|
||||||
|
LDFLAGS += -lXcursor
|
||||||
LDFLAGS += -lX11
|
LDFLAGS += -lX11
|
||||||
LDFLAGS += -lev
|
LDFLAGS += -lev
|
||||||
LDFLAGS += -L/usr/local/lib -L/usr/pkg/lib
|
LDFLAGS += -L/usr/local/lib -L/usr/pkg/lib
|
||||||
|
|
|
@ -3,7 +3,7 @@ Section: utils
|
||||||
Priority: extra
|
Priority: extra
|
||||||
Maintainer: Michael Stapelberg <michael@stapelberg.de>
|
Maintainer: Michael Stapelberg <michael@stapelberg.de>
|
||||||
DM-Upload-Allowed: yes
|
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
|
Standards-Version: 3.8.3
|
||||||
Homepage: http://i3.zekjur.net/
|
Homepage: http://i3.zekjur.net/
|
||||||
|
|
||||||
|
|
|
@ -51,5 +51,6 @@
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
#include "match.h"
|
#include "match.h"
|
||||||
#include "cmdparse.h"
|
#include "cmdparse.h"
|
||||||
|
#include "xcursor.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
extern xcb_connection_t *conn;
|
extern xcb_connection_t *conn;
|
||||||
extern xcb_key_symbols_t *keysyms;
|
extern xcb_key_symbols_t *keysyms;
|
||||||
extern char **start_argv;
|
extern char **start_argv;
|
||||||
extern Display *xkbdpy;
|
extern Display *xlibdpy, *xkbdpy;
|
||||||
extern int xkb_current_group;
|
extern int xkb_current_group;
|
||||||
extern TAILQ_HEAD(bindings_head, Binding) *bindings;
|
extern TAILQ_HEAD(bindings_head, Binding) *bindings;
|
||||||
extern TAILQ_HEAD(autostarts_head, Autostart) autostarts;
|
extern TAILQ_HEAD(autostarts_head, Autostart) autostarts;
|
||||||
|
@ -35,7 +35,7 @@ extern SLIST_HEAD(stack_wins_head, Stack_Window) stack_wins;
|
||||||
extern xcb_event_handlers_t evenths;
|
extern xcb_event_handlers_t evenths;
|
||||||
extern xcb_property_handlers_t prophs;
|
extern xcb_property_handlers_t prophs;
|
||||||
extern uint8_t root_depth;
|
extern uint8_t root_depth;
|
||||||
extern bool xkb_supported;
|
extern bool xcursor_supported, xkb_supported;
|
||||||
extern xcb_atom_t atoms[NUM_ATOMS];
|
extern xcb_atom_t atoms[NUM_ATOMS];
|
||||||
extern xcb_window_t root;
|
extern xcb_window_t root;
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#define _XCB_H
|
#define _XCB_H
|
||||||
|
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
|
#include "xcursor.h"
|
||||||
|
|
||||||
#define _NET_WM_STATE_REMOVE 0
|
#define _NET_WM_STATE_REMOVE 0
|
||||||
#define _NET_WM_STATE_ADD 1
|
#define _NET_WM_STATE_ADD 1
|
||||||
|
@ -94,7 +95,7 @@ uint32_t get_colorpixel(char *hex);
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
xcb_window_t create_window(xcb_connection_t *conn, Rect r, uint16_t window_class,
|
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
|
* Changes a single value in the graphic context (so one doesn’t have to
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
#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
|
24
src/main.c
24
src/main.c
|
@ -2,6 +2,7 @@
|
||||||
* vim:ts=4:sw=4:expandtab
|
* vim:ts=4:sw=4:expandtab
|
||||||
*/
|
*/
|
||||||
#include <ev.h>
|
#include <ev.h>
|
||||||
|
#include <fcntl.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include "all.h"
|
#include "all.h"
|
||||||
|
|
||||||
|
@ -23,6 +24,9 @@ uint8_t root_depth;
|
||||||
|
|
||||||
xcb_key_symbols_t *keysyms;
|
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 */
|
/* The list of key bindings */
|
||||||
struct bindings_head *bindings;
|
struct bindings_head *bindings;
|
||||||
|
|
||||||
|
@ -32,6 +36,10 @@ struct autostarts_head autostarts = TAILQ_HEAD_INITIALIZER(autostarts);
|
||||||
/* The list of assignments */
|
/* The list of assignments */
|
||||||
struct assignments_head assignments = TAILQ_HEAD_INITIALIZER(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.
|
* 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
|
* See also man libev(3): "ev_prepare" and "ev_check" - customise your event loop
|
||||||
|
@ -195,6 +203,22 @@ int main(int argc, char *argv[]) {
|
||||||
REQUEST_ATOM(_NET_ACTIVE_WINDOW);
|
REQUEST_ATOM(_NET_ACTIVE_WINDOW);
|
||||||
REQUEST_ATOM(_NET_WORKAREA);
|
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(&evenths, 0, sizeof(xcb_event_handlers_t));
|
||||||
memset(&prophs, 0, sizeof(xcb_property_handlers_t));
|
memset(&prophs, 0, sizeof(xcb_property_handlers_t));
|
||||||
|
|
||||||
|
|
2
src/x.c
2
src/x.c
|
@ -82,7 +82,7 @@ void x_con_init(Con *con) {
|
||||||
values[1] = FRAME_EVENT_MASK;
|
values[1] = FRAME_EVENT_MASK;
|
||||||
|
|
||||||
Rect dims = { -15, -15, 10, 10 };
|
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);
|
con->gc = xcb_generate_id(conn);
|
||||||
xcb_create_gc(conn, con->gc, con->frame, 0, 0);
|
xcb_create_gc(conn, con->gc, con->frame, 0, 0);
|
||||||
|
|
||||||
|
|
55
src/xcb.c
55
src/xcb.c
|
@ -80,40 +80,45 @@ uint32_t get_colorpixel(char *hex) {
|
||||||
* for errors.
|
* for errors.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
xcb_window_t create_window(xcb_connection_t *conn, Rect dims, uint16_t window_class, int cursor,
|
xcb_window_t create_window(xcb_connection_t *conn, Rect dims, uint16_t window_class,
|
||||||
bool map, uint32_t mask, uint32_t *values) {
|
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 root = xcb_setup_roots_iterator(xcb_get_setup(conn)).data->root;
|
||||||
xcb_window_t result = xcb_generate_id(conn);
|
xcb_window_t result = xcb_generate_id(conn);
|
||||||
xcb_cursor_t cursor_id = 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 */
|
/* 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);
|
uint16_t depth = (window_class == XCB_WINDOW_CLASS_INPUT_ONLY ? 0 : XCB_COPY_FROM_PARENT);
|
||||||
|
|
||||||
xcb_create_window(conn,
|
xcb_create_window(conn,
|
||||||
depth,
|
depth,
|
||||||
result, /* the window id */
|
result, /* the window id */
|
||||||
root, /* parent == root */
|
root, /* parent == root */
|
||||||
dims.x, dims.y, dims.width, dims.height, /* dimensions */
|
dims.x, dims.y, dims.width, dims.height, /* dimensions */
|
||||||
0, /* border = 0, we draw our own */
|
0, /* border = 0, we draw our own */
|
||||||
window_class,
|
window_class,
|
||||||
XCB_WINDOW_CLASS_COPY_FROM_PARENT, /* copy visual from parent */
|
XCB_WINDOW_CLASS_COPY_FROM_PARENT, /* copy visual from parent */
|
||||||
mask,
|
mask,
|
||||||
values);
|
values);
|
||||||
|
|
||||||
/* Set the cursor */
|
/* 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");
|
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,
|
xcb_create_glyph_cursor(conn, cursor_id, cursor_font->id, cursor_font->id,
|
||||||
(cursor == -1 ? XCB_CURSOR_LEFT_PTR : cursor),
|
xcb_cursor, xcb_cursor + 1, 0, 0, 0, 65535, 65535, 65535);
|
||||||
(cursor == -1 ? XCB_CURSOR_LEFT_PTR : cursor) + 1,
|
|
||||||
0, 0, 0, 65535, 65535, 65535);
|
|
||||||
xcb_change_window_attributes(conn, result, XCB_CW_CURSOR, &cursor_id);
|
xcb_change_window_attributes(conn, result, XCB_CW_CURSOR, &cursor_id);
|
||||||
xcb_free_cursor(conn, cursor_id);
|
xcb_free_cursor(conn, cursor_id);
|
||||||
|
}
|
||||||
|
|
||||||
/* Map the window (= make it visible) */
|
/* Map the window (= make it visible) */
|
||||||
if (map)
|
if (map)
|
||||||
xcb_map_window(conn, result);
|
xcb_map_window(conn, result);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
#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];
|
||||||
|
}
|
Loading…
Reference in New Issue