Skip to content

Commit

Permalink
x: x_error_code_to_string doesn't need ps_g anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
absolutelynothelix committed Oct 18, 2024
1 parent b1446b4 commit a723772
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 124 deletions.
5 changes: 3 additions & 2 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
14 changes: 7 additions & 7 deletions src/event.c
Original file line number Diff line number Diff line change
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
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
36 changes: 19 additions & 17 deletions src/picom.c
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ static bool initialize_backend(session_t *ps) {
void configure_root(session_t *ps) {
// TODO(yshui) re-initializing backend should be done outside of the
// critical section. Probably set a flag and do it in draw_callback_impl.
auto r = XCB_AWAIT(xcb_get_geometry, ps->c.c, ps->c.screen_info->root);
auto r = XCB_AWAIT(xcb_get_geometry, &ps->c, ps->c.screen_info->root);
if (!r) {
log_fatal("Failed to fetch root geometry");
abort();
Expand Down Expand Up @@ -949,7 +949,7 @@ static int register_cm(session_t *ps) {
prop_is_utf8[i] ? ps->atoms->aUTF8_STRING : XCB_ATOM_STRING,
8, strlen("picom"), "picom"));
if (e) {
log_error_x_error(e, "Failed to set window property %d",
log_error_x_error(&ps->c, e, "Failed to set window property %d",
prop_atoms[i]);
free(e);
}
Expand All @@ -961,7 +961,7 @@ static int register_cm(session_t *ps) {
ps->atoms->aWM_CLASS, XCB_ATOM_STRING, 8,
ARR_SIZE(picom_class), picom_class));
if (e) {
log_error_x_error(e, "Failed to set the WM_CLASS property");
log_error_x_error(&ps->c, e, "Failed to set the WM_CLASS property");
free(e);
}

Expand All @@ -978,8 +978,9 @@ static int register_cm(session_t *ps) {
ps->atoms->aWM_CLIENT_MACHINE, XCB_ATOM_STRING,
8, (uint32_t)strlen(hostname), hostname));
if (e) {
log_error_x_error(e, "Failed to set the WM_CLIENT_MACHINE"
" property");
log_error_x_error(&ps->c, e,
"Failed to set the WM_CLIENT_MACHINE"
" property");
free(e);
}
} else {
Expand All @@ -1002,7 +1003,7 @@ static int register_cm(session_t *ps) {
ps->atoms->aCOMPTON_VERSION, XCB_ATOM_STRING, 8,
(uint32_t)strlen(PICOM_VERSION), PICOM_VERSION));
if (e) {
log_error_x_error(e, "Failed to set COMPTON_VERSION.");
log_error_x_error(&ps->c, e, "Failed to set COMPTON_VERSION.");
free(e);
}

Expand Down Expand Up @@ -1066,13 +1067,13 @@ static bool init_overlay(session_t *ps) {
if (ps->overlay != XCB_NONE) {
// Set window region of the overlay window, code stolen from
// compiz-0.8.8
if (!XCB_AWAIT_VOID(xcb_shape_mask, ps->c.c, XCB_SHAPE_SO_SET,
if (!XCB_AWAIT_VOID(xcb_shape_mask, &ps->c, XCB_SHAPE_SO_SET,
XCB_SHAPE_SK_BOUNDING, ps->overlay, 0, 0, 0)) {
log_fatal("Failed to set the bounding shape of overlay, giving "
"up.");
return false;
}
if (!XCB_AWAIT_VOID(xcb_shape_rectangles, ps->c.c, XCB_SHAPE_SO_SET,
if (!XCB_AWAIT_VOID(xcb_shape_rectangles, &ps->c, XCB_SHAPE_SO_SET,
XCB_SHAPE_SK_INPUT, XCB_CLIP_ORDERING_UNSORTED,
ps->overlay, 0, 0, 0, NULL)) {
log_fatal("Failed to set the input shape of overlay, giving up.");
Expand All @@ -1088,7 +1089,7 @@ static bool init_overlay(session_t *ps) {
// root_damage = XDamageCreate(ps->dpy, root, XDamageReportNonEmpty);

// Unmap the overlay, we will map it when needed in redirect_start
XCB_AWAIT_VOID(xcb_unmap_window, ps->c.c, ps->overlay);
XCB_AWAIT_VOID(xcb_unmap_window, &ps->c, ps->overlay);
} else {
log_error("Cannot get X Composite overlay window. Falling "
"back to painting on root window.");
Expand Down Expand Up @@ -1174,7 +1175,7 @@ static bool redirect_start(session_t *ps) {
xcb_map_window(ps->c.c, ps->overlay);
}

bool success = XCB_AWAIT_VOID(xcb_composite_redirect_subwindows, ps->c.c,
bool success = XCB_AWAIT_VOID(xcb_composite_redirect_subwindows, &ps->c,
ps->c.screen_info->root, session_redirection_mode(ps));
if (!success) {
log_fatal("Another composite manager is already running "
Expand Down Expand Up @@ -2012,7 +2013,7 @@ static session_t *session_init(int argc, char **argv, Display *dpy,
}

ps->x_region = x_new_id(&ps->c);
if (!XCB_AWAIT_VOID(xcb_xfixes_create_region, ps->c.c, ps->x_region, 0, NULL)) {
if (!XCB_AWAIT_VOID(xcb_xfixes_create_region, &ps->c, ps->x_region, 0, NULL)) {
log_fatal("Failed to create a XFixes region");
goto err;
}
Expand Down Expand Up @@ -2111,9 +2112,10 @@ static session_t *session_init(int argc, char **argv, Display *dpy,
ps->c.c, ps->c.screen_info->root, ps->sync_fence, 0));
if (e) {
if (ps->o.xrender_sync_fence) {
log_error_x_error(e, "Failed to create a XSync fence. "
"xrender-sync-fence will be "
"disabled");
log_error_x_error(&ps->c, e,
"Failed to create a XSync fence. "
"xrender-sync-fence will be "
"disabled");
ps->o.xrender_sync_fence = false;
}
ps->sync_fence = XCB_NONE;
Expand Down Expand Up @@ -2238,14 +2240,14 @@ static session_t *session_init(int argc, char **argv, Display *dpy,
XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY |
XCB_EVENT_MASK_PROPERTY_CHANGE}));
if (e) {
log_error_x_error(e, "Failed to setup root window event mask");
log_error_x_error(&ps->c, e, "Failed to setup root window event mask");
free(e);
goto err;
}

// Query the size of the root window. We need the size information before any
// window can be managed.
auto r = XCB_AWAIT(xcb_get_geometry, ps->c.c, ps->c.screen_info->root);
auto r = XCB_AWAIT(xcb_get_geometry, &ps->c, ps->c.screen_info->root);
if (!r) {
log_fatal("Failed to get geometry of the root window");
goto err;
Expand Down Expand Up @@ -2279,7 +2281,7 @@ static session_t *session_init(int argc, char **argv, Display *dpy,
// release it.
auto get_overlay =
xcb_composite_get_overlay_window(ps->c.c, ps->c.screen_info->root);
XCB_AWAIT_VOID(xcb_composite_release_overlay_window, ps->c.c,
XCB_AWAIT_VOID(xcb_composite_release_overlay_window, &ps->c,
ps->c.screen_info->root);
auto overlay_reply =
xcb_composite_get_overlay_window_reply(ps->c.c, get_overlay, NULL);
Expand Down
32 changes: 16 additions & 16 deletions src/utils/ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ui_message_box_draw_text(struct ui *ui, struct x_connection *c, xcb_window_t win
content->size.width > UINT16_MAX ? UINT16_MAX : (uint16_t)content->size.width;
uint16_t height =
content->size.height > UINT16_MAX ? UINT16_MAX : (uint16_t)content->size.height;
if (!XCB_AWAIT_VOID(xcb_create_pixmap, c->c, c->screen_info->root_depth, pixmap,
if (!XCB_AWAIT_VOID(xcb_create_pixmap, c, c->screen_info->root_depth, pixmap,
window, width, height)) {
return XCB_NONE;
}
Expand All @@ -34,7 +34,7 @@ ui_message_box_draw_text(struct ui *ui, struct x_connection *c, xcb_window_t win
uint32_t value_list[3] = {c->screen_info->black_pixel,
c->screen_info->black_pixel};

if (!XCB_AWAIT_VOID(xcb_create_gc, c->c, gc, pixmap, mask, value_list)) {
if (!XCB_AWAIT_VOID(xcb_create_gc, c, gc, pixmap, mask, value_list)) {
return XCB_NONE;
}
}
Expand All @@ -45,14 +45,14 @@ ui_message_box_draw_text(struct ui *ui, struct x_connection *c, xcb_window_t win

const char yellow_name[] = "yellow";
const char red_name[] = "red";
auto r = XCB_AWAIT(xcb_alloc_named_color, c->c, c->screen_info->default_colormap,
auto r = XCB_AWAIT(xcb_alloc_named_color, c, c->screen_info->default_colormap,
ARR_SIZE(yellow_name) - 1, yellow_name);
if (r == NULL) {
return XCB_NONE;
}
auto yellow_pixel = r->pixel;
free(r);
r = XCB_AWAIT(xcb_alloc_named_color, c->c, c->screen_info->default_colormap,
r = XCB_AWAIT(xcb_alloc_named_color, c, c->screen_info->default_colormap,
ARR_SIZE(red_name) - 1, red_name);
if (r == NULL) {
return XCB_NONE;
Expand Down Expand Up @@ -85,12 +85,11 @@ ui_message_box_draw_text(struct ui *ui, struct x_connection *c, xcb_window_t win

void ui_message_box_place(struct x_connection *c, struct ui_message_box_content *content,
int16_t *x, int16_t *y) {
auto r =
XCB_AWAIT(xcb_randr_get_screen_resources_current, c->c, c->screen_info->root);
auto r = XCB_AWAIT(xcb_randr_get_screen_resources_current, c, c->screen_info->root);
if (r == NULL) {
return;
}
auto pointer = XCB_AWAIT(xcb_query_pointer, c->c, c->screen_info->root);
auto pointer = XCB_AWAIT(xcb_query_pointer, c, c->screen_info->root);
if (pointer == NULL) {
free(r);
return;
Expand All @@ -100,7 +99,7 @@ void ui_message_box_place(struct x_connection *c, struct ui_message_box_content
auto crtcs = xcb_randr_get_screen_resources_current_crtcs(r);
for (int i = 0; i < num_crtc; i++) {
auto crtc_info_ptr =
XCB_AWAIT(xcb_randr_get_crtc_info, c->c, crtcs[i], r->config_timestamp);
XCB_AWAIT(xcb_randr_get_crtc_info, c, crtcs[i], r->config_timestamp);
if (crtc_info_ptr == NULL ||
crtc_info_ptr->status != XCB_RANDR_SET_CONFIG_SUCCESS) {
free(crtc_info_ptr);
Expand Down Expand Up @@ -166,7 +165,7 @@ bool ui_message_box_show(struct ui *ui, struct x_connection *c,
XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_BUTTON_PRESS |
XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_POINTER_MOTION |
XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW};
bool success = XCB_AWAIT_VOID(xcb_create_window, c->c, c->screen_info->root_depth,
bool success = XCB_AWAIT_VOID(xcb_create_window, c, c->screen_info->root_depth,
win, c->screen_info->root, x, y, width, height,
/*border_width=*/0, XCB_WINDOW_CLASS_INPUT_OUTPUT,
c->screen_info->root_visual, mask, values);
Expand All @@ -187,17 +186,17 @@ bool ui_message_box_show(struct ui *ui, struct x_connection *c,
.matrix22 = DOUBLE_TO_XFIXED(1.0F / content->scale),
.matrix33 = DOUBLE_TO_XFIXED(1.0),
};
if (!XCB_AWAIT_VOID(xcb_render_set_picture_transform, c->c, content_picture, transform)) {
if (!XCB_AWAIT_VOID(xcb_render_set_picture_transform, c, content_picture, transform)) {
return false;
}

const char filter_name[] = "nearest";
if (!XCB_AWAIT_VOID(xcb_render_set_picture_filter, c->c, content_picture,
if (!XCB_AWAIT_VOID(xcb_render_set_picture_filter, c, content_picture,
ARR_SIZE(filter_name) - 1, filter_name, 0, NULL)) {
return false;
}

if (!XCB_AWAIT_VOID(xcb_map_window, c->c, win)) {
if (!XCB_AWAIT_VOID(xcb_map_window, c, win)) {
xcb_destroy_window(c->c, win);
return false;
}
Expand Down Expand Up @@ -304,7 +303,7 @@ static bool ui_message_box_line_extent(struct ui *ui, struct x_connection *c,
text16[i].byte1 = 0;
text16[i].byte2 = (uint8_t)line->text[i];
}
auto r = XCB_AWAIT(xcb_query_text_extents, c->c, font, len, text16);
auto r = XCB_AWAIT(xcb_query_text_extents, c, font, len, text16);
free(text16);

if (!r) {
Expand Down Expand Up @@ -367,15 +366,16 @@ struct ui *ui_new(struct x_connection *c) {

xcb_generic_error_t *e = xcb_request_check(c->c, cookie1);
if (e != NULL) {
log_error_x_error(e, "Cannot open the fixed font");
log_error_x_error(c, e, "Cannot open the fixed font");
free(e);
return NULL;
}
e = xcb_request_check(c->c, cookie2);
if (e != NULL) {
ui->bold_font = ui->normal_font;
log_error_x_error(e, "Cannot open the bold font, falling back to normal "
"font");
log_error_x_error(c, e,
"Cannot open the bold font, falling back to normal "
"font");
free(e);
}
return ui;
Expand Down
Loading

0 comments on commit a723772

Please sign in to comment.