Skip to content

Commit

Permalink
Merge pull request #1053 from absolutelynothelix/dependencies-cleanup
Browse files Browse the repository at this point in the history
core: separate work with the x extensions
  • Loading branch information
yshui authored Nov 11, 2024
2 parents 1131c2e + ea391c2 commit af3cf50
Show file tree
Hide file tree
Showing 14 changed files with 345 additions and 334 deletions.
2 changes: 1 addition & 1 deletion src/backend/gl/glx.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ static backend_t *glx_init(session_t *ps, xcb_window_t target) {
XVisualInfo *pvis = NULL;

// Check for GLX extension
if (!ps->glx_exists) {
if (!ps->c.e.has_glx) {
log_error("No GLX extension.");
goto end;
}
Expand Down
7 changes: 4 additions & 3 deletions src/backend/xrender/xrender.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ xrender_make_rounded_corner_cache(struct x_connection *c, xcb_render_picture_t s
}
#undef ADD_POINT

XCB_AWAIT_VOID(xcb_render_tri_strip, c->c, XCB_RENDER_PICT_OP_SRC, src, picture,
XCB_AWAIT_VOID(xcb_render_tri_strip, c, XCB_RENDER_PICT_OP_SRC, src, picture,
x_get_pictfmt_for_standard(c, XCB_PICT_STANDARD_A_8), 0, 0,
(uint32_t)point_count, points);
free(points);
Expand Down Expand Up @@ -641,7 +641,8 @@ xrender_bind_pixmap(backend_t *base, xcb_pixmap_t pixmap, struct xvisual_info fm
auto r = xcb_get_geometry_reply(base->c->c, xcb_get_geometry(base->c->c, pixmap), &e);
if (!r) {
log_error("Invalid pixmap: %#010x", pixmap);
x_print_error(e->full_sequence, e->major_code, e->minor_code, e->error_code);
x_print_error(base->c, e->full_sequence, e->major_code, e->minor_code,
e->error_code);
free(e);
return NULL;
}
Expand Down Expand Up @@ -892,7 +893,7 @@ static backend_t *xrender_init(session_t *ps, xcb_window_t target) {
XCB_RENDER_CP_SUBWINDOW_MODE, &pa);

xd->vsync = ps->o.vsync;
if (ps->present_exists) {
if (ps->c.e.has_present) {
auto eid = x_new_id(&ps->c);
auto e =
xcb_request_check(ps->c.c, xcb_present_select_input_checked(
Expand Down
44 changes: 0 additions & 44 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,52 +207,8 @@ typedef struct session {
long paint_tm_offset;

// === X extension related ===
/// Event base number for X Fixes extension.
int xfixes_event;
/// Error base number for X Fixes extension.
int xfixes_error;
/// Event base number for X Damage extension.
int damage_event;
/// Error base number for X Damage extension.
int damage_error;
/// Event base number for X Render extension.
int render_event;
/// Error base number for X Render extension.
int render_error;
/// Event base number for X Composite extension.
int composite_event;
/// Error base number for X Composite extension.
int composite_error;
/// Major opcode for X Composite extension.
int composite_opcode;
/// Whether X Shape extension exists.
bool shape_exists;
/// Event base number for X Shape extension.
int shape_event;
/// Error base number for X Shape extension.
int shape_error;
/// Whether X RandR extension exists.
bool randr_exists;
/// Event base number for X RandR extension.
int randr_event;
/// Error base number for X RandR extension.
int randr_error;
/// Whether X Present extension exists.
bool present_exists;
/// Whether X GLX extension exists.
bool glx_exists;
/// Event base number for X GLX extension.
int glx_event;
/// Error base number for X GLX extension.
int glx_error;
/// Information about monitors.
struct x_monitors monitors;
/// Whether X Sync extension exists.
bool xsync_exists;
/// Event base number for X Sync extension.
int xsync_event;
/// Error base number for X Sync extension.
int xsync_error;

// === Atoms ===
struct atom *atoms;
Expand Down
10 changes: 6 additions & 4 deletions src/diagnostic.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
void print_diagnostics(session_t *ps, const char *config_file, bool compositor_running) {
printf("**Version:** " PICOM_FULL_VERSION "\n");
// printf("**CFLAGS:** %s\n", "??");
printf("\n### Extensions:\n\n");
printf("* Shape: %s\n", ps->shape_exists ? "Yes" : "No");
printf("* RandR: %s\n", ps->randr_exists ? "Yes" : "No");
printf("* Present: %s\n", ps->present_exists ? "Present" : "Not Present");
printf("\n### X extensions:\n\n");
printf("* GLX: %s\n", ps->c.e.has_glx ? "present" : "absent");
printf("* Present: %s\n", ps->c.e.has_present ? "present" : "absent");
printf("* RandR: %s\n", ps->c.e.has_randr ? "present" : "absent");
printf("* Shape: %s\n", ps->c.e.has_shape ? "present" : "absent");
printf("* Sync: %s\n", ps->c.e.has_sync ? "present" : "absent");
printf("\n### Misc:\n\n");
printf("* Use Overlay: %s\n", ps->overlay != XCB_NONE ? "Yes" : "No");
if (ps->overlay == XCB_NONE) {
Expand Down
37 changes: 19 additions & 18 deletions src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ static inline xcb_window_t attr_pure ev_window(session_t *ps, xcb_generic_event_
case XCB_PROPERTY_NOTIFY: return ((xcb_property_notify_event_t *)ev)->window;
case XCB_CLIENT_MESSAGE: return ((xcb_client_message_event_t *)ev)->window;
default:
if (ps->damage_event + XCB_DAMAGE_NOTIFY == ev->response_type) {
if (ps->c.e.damage_event + XCB_DAMAGE_NOTIFY == ev->response_type) {
return ((xcb_damage_notify_event_t *)ev)->drawable;
}

if (ps->shape_exists && ev->response_type == ps->shape_event) {
if (ps->c.e.has_shape && ev->response_type == ps->c.e.shape_event) {
return ((xcb_shape_notify_event_t *)ev)->affected_window;
}

Expand Down Expand Up @@ -133,16 +133,16 @@ static inline const char *ev_name(session_t *ps, xcb_generic_event_t *ev) {
CASESTRRET(CLIENT_MESSAGE);
}

if (ps->damage_event + XCB_DAMAGE_NOTIFY == ev->response_type) {
if (ps->c.e.damage_event + XCB_DAMAGE_NOTIFY == ev->response_type) {
return "DAMAGE_NOTIFY";
}

if (ps->shape_exists && ev->response_type == ps->shape_event) {
if (ps->c.e.has_shape && ev->response_type == ps->c.e.shape_event) {
return "SHAPE_NOTIFY";
}

if (ps->xsync_exists) {
int o = ev->response_type - ps->xsync_event;
if (ps->c.e.has_sync) {
int o = ev->response_type - ps->c.e.sync_event;
switch (o) {
CASESTRRET(SYNC_COUNTER_NOTIFY);
CASESTRRET(SYNC_ALARM_NOTIFY);
Expand Down Expand Up @@ -199,7 +199,7 @@ struct ev_ewmh_active_win_request {
/// Does not change anything if we fail to get the attribute or the window
/// returned could not be found.
static void
update_ewmh_active_win(struct x_connection * /*c*/, struct x_async_request_base *req_base,
update_ewmh_active_win(struct x_connection *c, struct x_async_request_base *req_base,
const xcb_raw_generic_event_t *reply_or_error) {
auto ps = ((struct ev_ewmh_active_win_request *)req_base)->ps;
free(req_base);
Expand All @@ -213,7 +213,7 @@ update_ewmh_active_win(struct x_connection * /*c*/, struct x_async_request_base

if (reply_or_error->response_type == 0) {
log_error("Failed to get _NET_ACTIVE_WINDOW: %s",
x_strerror(((xcb_generic_error_t *)reply_or_error)));
x_strerror(c, (xcb_generic_error_t *)reply_or_error));
return;
}

Expand Down Expand Up @@ -246,7 +246,7 @@ struct ev_recheck_focus_request {
* @param ps current session
* @return struct _win of currently focused window, NULL if not found
*/
static void recheck_focus(struct x_connection * /*c*/, struct x_async_request_base *req_base,
static void recheck_focus(struct x_connection *c, struct x_async_request_base *req_base,
const xcb_raw_generic_event_t *reply_or_error) {
auto ps = ((struct ev_ewmh_active_win_request *)req_base)->ps;
free(req_base);
Expand All @@ -263,7 +263,7 @@ static void recheck_focus(struct x_connection * /*c*/, struct x_async_request_ba
if (reply_or_error->response_type == 0) {
// Not able to get input focus means very not good things...
auto e = (xcb_generic_error_t *)reply_or_error;
log_error_x_error(e, "Failed to get focused window.");
log_error_x_error(c, e, "Failed to get focused window.");
return;
}

Expand Down Expand Up @@ -419,7 +419,7 @@ static inline void ev_map_notify(session_t *ps, xcb_map_notify_event_t *ev) {
if (!ps->redirected) {
log_debug("Overlay is mapped while we are not redirected");
auto succeeded =
XCB_AWAIT_VOID(xcb_unmap_window, ps->c.c, ps->overlay);
XCB_AWAIT_VOID(xcb_unmap_window, &ps->c, ps->overlay);
if (!succeeded) {
log_error("Failed to unmap the overlay window");
}
Expand Down Expand Up @@ -641,8 +641,8 @@ static inline void repair_win(session_t *ps, struct win *w) {
xcb_damage_subtract_checked(ps->c.c, w->damage, XCB_NONE, XCB_NONE));
if (e) {
if (ps->o.show_all_xerrors) {
x_print_error(e->sequence, e->major_code, e->minor_code,
e->error_code);
x_print_error(&ps->c, e->sequence, e->major_code,
e->minor_code, e->error_code);
}
free(e);
}
Expand Down Expand Up @@ -717,7 +717,7 @@ ev_selection_clear(session_t *ps, xcb_selection_clear_event_t attr_unused *ev) {

void ev_handle(session_t *ps, xcb_generic_event_t *ev) {
xcb_window_t wid = ev_window(ps, ev);
if (ev->response_type != ps->damage_event + XCB_DAMAGE_NOTIFY) {
if (ev->response_type != ps->c.e.damage_event + XCB_DAMAGE_NOTIFY) {
log_debug("event %10.10s serial %#010x window %#010x \"%s\"",
ev_name(ps, ev), ev->full_sequence, wid, ev_window_name(ps, wid));
} else {
Expand Down Expand Up @@ -786,16 +786,17 @@ void ev_handle(session_t *ps, xcb_generic_event_t *ev) {
ev_selection_clear(ps, (xcb_selection_clear_event_t *)ev);
break;
default:
if (ps->shape_exists && ev->response_type == ps->shape_event) {
if (ps->c.e.has_shape && ev->response_type == ps->c.e.shape_event) {
ev_shape_notify(ps, (xcb_shape_notify_event_t *)ev);
break;
}
if (ps->randr_exists &&
ev->response_type == (ps->randr_event + XCB_RANDR_SCREEN_CHANGE_NOTIFY)) {
if (ps->c.e.has_randr &&
ev->response_type ==
(ps->c.e.randr_event + XCB_RANDR_SCREEN_CHANGE_NOTIFY)) {
x_update_monitors_async(&ps->c, &ps->monitors);
break;
}
if (ps->damage_event + XCB_DAMAGE_NOTIFY == ev->response_type) {
if (ps->c.e.damage_event + XCB_DAMAGE_NOTIFY == ev->response_type) {
ev_damage_notify(ps, (xcb_damage_notify_event_t *)ev);
break;
}
Expand Down
11 changes: 5 additions & 6 deletions src/inspect.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ xcb_window_t inspect_select_window(struct x_connection *c) {
xcb_cursor_t cursor = x_new_id(c);
const char font_name[] = "cursor";
static const uint16_t CROSSHAIR_CHAR = 34;
XCB_AWAIT_VOID(xcb_open_font, c->c, font, sizeof(font_name) - 1, font_name);
XCB_AWAIT_VOID(xcb_create_glyph_cursor, c->c, cursor, font, font, CROSSHAIR_CHAR,
XCB_AWAIT_VOID(xcb_open_font, c, font, sizeof(font_name) - 1, font_name);
XCB_AWAIT_VOID(xcb_create_glyph_cursor, c, cursor, font, font, CROSSHAIR_CHAR,
CROSSHAIR_CHAR + 1, 0, 0, 0, 0xffff, 0xffff, 0xffff);
auto grab_reply = XCB_AWAIT(
xcb_grab_pointer, c->c, false, c->screen_info->root,
xcb_grab_pointer, c, false, c->screen_info->root,
XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE, XCB_GRAB_MODE_SYNC,
XCB_GRAB_MODE_ASYNC, c->screen_info->root, cursor, XCB_CURRENT_TIME);
if (grab_reply->status != XCB_GRAB_STATUS_SUCCESS) {
Expand All @@ -45,8 +45,7 @@ xcb_window_t inspect_select_window(struct x_connection *c) {
xcb_window_t target = XCB_NONE;
int buttons_pressed = 0;
while ((target == XCB_NONE) || (buttons_pressed > 0)) {
XCB_AWAIT_VOID(xcb_allow_events, c->c, XCB_ALLOW_ASYNC_POINTER,
XCB_CURRENT_TIME);
XCB_AWAIT_VOID(xcb_allow_events, c, XCB_ALLOW_ASYNC_POINTER, XCB_CURRENT_TIME);
xcb_generic_event_t *ev = xcb_wait_for_event(c->c);
if (!ev) {
log_fatal("Connection to X server lost");
Expand Down Expand Up @@ -74,7 +73,7 @@ xcb_window_t inspect_select_window(struct x_connection *c) {
}
free(ev);
}
XCB_AWAIT_VOID(xcb_ungrab_pointer, c->c, XCB_CURRENT_TIME);
XCB_AWAIT_VOID(xcb_ungrab_pointer, c, XCB_CURRENT_TIME);
return target;
}

Expand Down
Loading

0 comments on commit af3cf50

Please sign in to comment.