Assume xcb_cursor_context_new never fails (#3955)
According to libxcb-cursor code, the only condition in which xcb_cursor_context_new() returns a non-zero result is a memory allocation failure[1]. Thus, it is safe to assume that xcursor_supported is always true, and remove dead code. [1]: https://gitlab.freedesktop.org/xorg/lib/libxcb-cursor/blob/0.1.3/cursor/cursor.c#L131-132
This commit is contained in:
@ -175,7 +175,7 @@ drag_result_t drag_pointer(Con *con, const xcb_button_press_event_t *event,
|
||||
xcb_window_t confine_to, int cursor,
|
||||
bool use_threshold, callback_t callback,
|
||||
const void *extra) {
|
||||
xcb_cursor_t xcursor = (cursor && xcursor_supported) ? xcursor_get_cursor(cursor) : XCB_NONE;
|
||||
xcb_cursor_t xcursor = cursor ? xcursor_get_cursor(cursor) : XCB_NONE;
|
||||
|
||||
/* Grab the pointer */
|
||||
xcb_grab_pointer_cookie_t cookie;
|
||||
|
@ -87,7 +87,6 @@ struct assignments_head assignments = TAILQ_HEAD_INITIALIZER(assignments);
|
||||
struct ws_assignments_head ws_assignments = TAILQ_HEAD_INITIALIZER(ws_assignments);
|
||||
|
||||
/* We hope that those are supported and set them to true */
|
||||
bool xcursor_supported = true;
|
||||
bool xkb_supported = true;
|
||||
bool shape_supported = true;
|
||||
|
||||
@ -641,10 +640,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
/* Set a cursor for the root window (otherwise the root window will show no
|
||||
cursor until the first client is launched). */
|
||||
if (xcursor_supported)
|
||||
xcursor_set_root_cursor(XCURSOR_CURSOR_POINTER);
|
||||
else
|
||||
xcb_set_root_cursor(XCURSOR_CURSOR_POINTER);
|
||||
xcursor_set_root_cursor(XCURSOR_CURSOR_POINTER);
|
||||
|
||||
const xcb_query_extension_reply_t *extreply;
|
||||
xcb_prefetch_extension_data(conn, &xcb_xkb_id);
|
||||
|
@ -201,10 +201,7 @@ void start_application(const char *command, bool no_startup_id) {
|
||||
|
||||
if (!no_startup_id) {
|
||||
/* Change the pointer of the root window to indicate progress */
|
||||
if (xcursor_supported)
|
||||
xcursor_set_root_cursor(XCURSOR_CURSOR_WATCH);
|
||||
else
|
||||
xcb_set_root_cursor(XCURSOR_CURSOR_WATCH);
|
||||
xcursor_set_root_cursor(XCURSOR_CURSOR_WATCH);
|
||||
}
|
||||
}
|
||||
|
||||
@ -246,10 +243,7 @@ void startup_monitor_event(SnMonitorEvent *event, void *userdata) {
|
||||
if (_prune_startup_sequences() == 0) {
|
||||
DLOG("No more startup sequences running, changing root window cursor to default pointer.\n");
|
||||
/* Change the pointer of the root window to indicate progress */
|
||||
if (xcursor_supported)
|
||||
xcursor_set_root_cursor(XCURSOR_CURSOR_POINTER);
|
||||
else
|
||||
xcb_set_root_cursor(XCURSOR_CURSOR_POINTER);
|
||||
xcursor_set_root_cursor(XCURSOR_CURSOR_POINTER);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
34
src/xcb.c
34
src/xcb.c
@ -45,20 +45,8 @@ xcb_window_t create_window(xcb_connection_t *conn, Rect dims,
|
||||
}
|
||||
|
||||
/* 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 {
|
||||
xcb_cursor_t cursor_id = xcb_generate_id(conn);
|
||||
i3Font cursor_font = load_font("cursor", false);
|
||||
int xcb_cursor = xcursor_get_xcb_cursor(cursor);
|
||||
xcb_create_glyph_cursor(conn, cursor_id, cursor_font.specific.xcb.id,
|
||||
cursor_font.specific.xcb.id, 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);
|
||||
}
|
||||
uint32_t cursor_values[] = {xcursor_get_cursor(cursor)};
|
||||
xcb_change_window_attributes(conn, result, XCB_CW_CURSOR, cursor_values);
|
||||
|
||||
/* Map the window (= make it visible) */
|
||||
if (map)
|
||||
@ -175,24 +163,6 @@ bool xcb_reply_contains_atom(xcb_get_property_reply_t *prop, xcb_atom_t atom) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the cursor of the root window to the given cursor id.
|
||||
* This function should only be used if xcursor_supported == false.
|
||||
* Otherwise, use xcursor_set_root_cursor().
|
||||
*
|
||||
*/
|
||||
void xcb_set_root_cursor(int cursor) {
|
||||
xcb_cursor_t cursor_id = xcb_generate_id(conn);
|
||||
i3Font cursor_font = load_font("cursor", false);
|
||||
int xcb_cursor = xcursor_get_xcb_cursor(cursor);
|
||||
xcb_create_glyph_cursor(conn, cursor_id, cursor_font.specific.xcb.id,
|
||||
cursor_font.specific.xcb.id, xcb_cursor, xcb_cursor + 1, 0, 0, 0,
|
||||
65535, 65535, 65535);
|
||||
xcb_change_window_attributes(conn, root, XCB_CW_CURSOR, &cursor_id);
|
||||
xcb_free_cursor(conn, cursor_id);
|
||||
xcb_flush(conn);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get depth of visual specified by visualid
|
||||
*
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <config.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <err.h>
|
||||
#include <xcb/xcb_cursor.h>
|
||||
|
||||
#include "i3.h"
|
||||
@ -19,17 +20,9 @@
|
||||
static xcb_cursor_context_t *ctx;
|
||||
static xcb_cursor_t 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,
|
||||
XCB_CURSOR_WATCH};
|
||||
|
||||
void xcursor_load_cursors(void) {
|
||||
if (xcb_cursor_context_new(conn, root_screen, &ctx) < 0) {
|
||||
ELOG("xcursor support unavailable\n");
|
||||
xcursor_supported = false;
|
||||
return;
|
||||
errx(EXIT_FAILURE, "Cannot allocate xcursor context");
|
||||
}
|
||||
#define LOAD_CURSOR(constant, name) \
|
||||
do { \
|
||||
@ -63,8 +56,3 @@ xcb_cursor_t xcursor_get_cursor(enum xcursor_cursor_t c) {
|
||||
assert(c < XCURSOR_CURSOR_MAX);
|
||||
return cursors[c];
|
||||
}
|
||||
|
||||
int xcursor_get_xcb_cursor(enum xcursor_cursor_t c) {
|
||||
assert(c < XCURSOR_CURSOR_MAX);
|
||||
return xcb_cursors[c];
|
||||
}
|
||||
|
Reference in New Issue
Block a user