CFLAGS += -Wall
CFLAGS += -D_GNU_SOURCE
CFLAGS += $(shell pkg-config --cflags cairo xcb-keysyms xcb-dpms)
-LDFLAGS += $(shell pkg-config --libs cairo xcb-keysyms xcb-dpms)
+LDFLAGS += $(shell pkg-config --libs cairo xcb-keysyms xcb-dpms xcb-image)
LDFLAGS += -lpam
FILES:=$(wildcard *.c)
+#define CURS_NONE 0
+#define CURS_WIN 1
+#define CURS_DEFAULT 2
+
#define curs_invisible_width 8
#define curs_invisible_height 8
Priority: extra
Maintainer: Michael Stapelberg <michael@stapelberg.de>
DM-Upload-Allowed: yes
-Build-Depends: debhelper (>= 5), libx11-dev, libpam0g-dev, libcairo2-dev, libxcb1-dev, libxcb-dpms0-dev, libxcb-keysyms1-dev
+Build-Depends: debhelper (>= 5), libx11-dev, libpam0g-dev, libcairo2-dev, libxcb1-dev, libxcb-dpms0-dev, libxcb-keysyms1-dev, libxcb-image0-dev
Standards-Version: 3.8.2
Homepage: http://i3.zekjur.net/i3lock/
#include "keysym2ucs.h"
#include "ucs2_to_utf8.h"
#include "xcb.h"
+#include "cursors.h"
static xcb_connection_t *conn;
static xcb_key_symbols_t *symbols;
xcb_generic_event_t *event;
xcb_screen_t *scr;
xcb_window_t win;
+ xcb_cursor_t cursor;
+ int curs_choice = CURS_NONE;
char o;
int optind = 0;
struct option longopts[] = {
/* TODO: tile image */
break;
case 'p':
- /* TODO: cursor */
+ if (!strcmp(optarg, "win")) {
+ curs_choice = CURS_WIN;
+ }
+ if (!strcmp(optarg, "default")) {
+ curs_choice = CURS_DEFAULT;
+ }
break;
default:
errx(1, "i3lock: Unknown option. Syntax: i3lock [-v] [-n] [-b] [-d] [-i image.png] [-c color] [-t] [-p win|default]\n");
* ready to handle the expose event immediately afterwards) */
win = open_fullscreen_window(conn, scr, color);
- grab_pointer_and_keyboard(conn, scr);
+ cursor = create_cursor(conn, scr, win, curs_choice);
+
+ grab_pointer_and_keyboard(conn, scr, cursor);
if (image_path)
img = cairo_image_surface_create_from_png(image_path);
*/
#include <xcb/xcb.h>
#include <xcb/xcb_keysyms.h>
+#include <xcb/xcb_image.h>
#include <xcb/dpms.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <err.h>
+#include "cursors.h"
+
static uint32_t get_colorpixel(char *hex) {
char strgroups[3][3] = {{hex[0], hex[1], '\0'},
{hex[2], hex[3], '\0'},
* Repeatedly tries to grab pointer and keyboard (up to 1000 times).
*
*/
-void grab_pointer_and_keyboard(xcb_connection_t *conn, xcb_screen_t *screen) {
+void grab_pointer_and_keyboard(xcb_connection_t *conn, xcb_screen_t *screen, xcb_cursor_t cursor) {
xcb_grab_pointer_cookie_t pcookie;
xcb_grab_pointer_reply_t *preply;
XCB_GRAB_MODE_ASYNC, /* pointer events should continue as normal */
XCB_GRAB_MODE_ASYNC, /* keyboard mode */
XCB_NONE, /* confine_to = in which window should the cursor stay */
- XCB_NONE, /* don’t display a special cursor */
+ cursor, /* we change the cursor to whatever the user wanted */
XCB_CURRENT_TIME
);
usleep(50);
}
+ if (cursor != XCB_NONE)
+ xcb_free_cursor(conn, cursor);
+
while (tries-- > 0) {
kcookie = xcb_grab_keyboard(
conn,
if (tries <= 0)
errx(EXIT_FAILURE, "Cannot grab pointer/keyboard");
}
+
+xcb_cursor_t create_cursor(xcb_connection_t *conn, xcb_screen_t *screen, xcb_window_t win, int choice) {
+ xcb_pixmap_t bitmap;
+ xcb_pixmap_t mask;
+ xcb_cursor_t cursor;
+
+ unsigned char* curs_bits;
+ unsigned char* mask_bits;
+ int curs_w, curs_h;
+
+ switch (choice) {
+ case CURS_NONE:
+ curs_bits = curs_invisible_bits;
+ mask_bits = curs_invisible_bits;
+ curs_w = curs_invisible_width;
+ curs_h = curs_invisible_height;
+ break;
+ case CURS_WIN:
+ curs_bits = curs_windows_bits;
+ mask_bits = mask_windows_bits;
+ curs_w = curs_windows_width;
+ curs_h = curs_windows_height;
+ break;
+ case CURS_DEFAULT:
+ default:
+ return XCB_NONE; /* XCB_NONE is xcb's way of saying "don't change the cursor" */
+ }
+
+ bitmap = xcb_create_pixmap_from_bitmap_data(conn,
+ win,
+ curs_bits,
+ curs_w,
+ curs_h,
+ 1,
+ screen->white_pixel,
+ screen->black_pixel,
+ NULL);
+
+ mask = xcb_create_pixmap_from_bitmap_data(conn,
+ win,
+ mask_bits,
+ curs_w,
+ curs_h,
+ 1,
+ screen->white_pixel,
+ screen->black_pixel,
+ NULL);
+
+ cursor = xcb_generate_id(conn);
+
+ xcb_create_cursor(conn,
+ cursor,
+ bitmap,
+ mask,
+ 65535,65535,65535,
+ 0,0,0,
+ 0,0);
+
+ xcb_free_pixmap(conn, bitmap);
+ xcb_free_pixmap(conn, mask);
+
+ return cursor;
+}
xcb_visualtype_t *get_root_visual_type(xcb_screen_t *s);
xcb_window_t open_fullscreen_window(xcb_connection_t *conn, xcb_screen_t *scr, char *color);
-void grab_pointer_and_keyboard(xcb_connection_t *conn, xcb_screen_t *screen);
+void grab_pointer_and_keyboard(xcb_connection_t *conn, xcb_screen_t *screen, xcb_cursor_t cursor);
uint32_t get_mod_mask(xcb_connection_t *conn, xcb_key_symbols_t *symbols, uint32_t keycode);
void dpms_turn_off_screen(xcb_connection_t *conn);
+xcb_cursor_t create_cursor(xcb_connection_t *conn, xcb_screen_t *screen, xcb_window_t win, int choice);
#endif