style: 禁掉 clang-format 的 AlignConsecutiveAssignments 规则并重新格式化整个项目

This commit is contained in:
2026-06-24 13:05:56 +08:00
parent 8f671bd755
commit bf3de7fb92
38 changed files with 763 additions and 731 deletions

View File

@@ -42,14 +42,14 @@ output_remove_duplication(const output_info_t *output, const size_t count) {
}
output_info_t *list = p_new(output_info_t, amount);
amount = 0;
amount = 0;
for (size_t i = 0; i < count; i++) {
if (remove[i]) continue;
list[amount++] = output[i];
}
p_delete(&remove);
backend_detect_t *detect = p_new(backend_detect_t, 1);
detect->outputs = list;
detect->output_count = amount;
detect->outputs = list;
detect->output_count = amount;
return detect;
}

View File

@@ -40,7 +40,7 @@ typedef struct atom_item_t {
static void atoms_init(backend_t *backend) {
xcb_connection_t *conn = backend->conn;
atoms_t *atoms = &backend->atoms;
atoms_t *atoms = &backend->atoms;
#define ATOM_ITEM(name) {#name, sizeof(#name) - 1, &atoms->name},
atom_item_t atom_list[] = {ATOM_LIST(ATOM_ITEM)};
@@ -58,7 +58,7 @@ static void atoms_init(backend_t *backend) {
if (!reply) continue;
atom_item_t *atom = &atom_list[i];
*atom->atom = reply->atom;
*atom->atom = reply->atom;
p_delete(&reply);
}
@@ -80,22 +80,22 @@ static void atoms_init(backend_t *backend) {
static void create_wm_check_window(backend_t *backend) {
xcb_connection_t *conn = backend->conn;
xcb_window_t root = backend->screen->root;
uint8_t depth = backend->screen->root_depth;
xcb_visualid_t v = backend->screen->root_visual;
uint16_t _c = XCB_WINDOW_CLASS_COPY_FROM_PARENT;
uint32_t m = XCB_NONE;
void *p = nullptr;
xcb_window_t root = backend->screen->root;
uint8_t depth = backend->screen->root_depth;
xcb_visualid_t v = backend->screen->root_visual;
uint16_t _c = XCB_WINDOW_CLASS_COPY_FROM_PARENT;
uint32_t m = XCB_NONE;
void *p = nullptr;
xcb_window_t win = xcb_generate_id(conn);
xcb_create_window(conn, depth, win, root, -1, -1, 1, 1, 0, _c, v, m, p);
window_set_class_instance(conn, win);
window_set_name_static(conn, win, APP_NAME);
uint8_t mode = XCB_PROP_MODE_REPLACE;
uint8_t mode = XCB_PROP_MODE_REPLACE;
xcb_atom_t prop = backend->atoms._NET_WM_NAME;
xcb_atom_t type = backend->atoms.UTF8_STRING;
auto data_len = sizeof(APP_NAME) - 1;
auto data_len = sizeof(APP_NAME) - 1;
xcb_change_property(conn, mode, win, prop, type, 8, data_len, APP_NAME);
prop = backend->atoms._NET_SUPPORTING_WM_CHECK;
@@ -103,27 +103,27 @@ static void create_wm_check_window(backend_t *backend) {
xcb_change_property(conn, mode, win, prop, type, 32, 1, &win);
xcb_change_property(conn, mode, root, prop, type, 32, 1, &win);
prop = backend->atoms._NET_WM_PID;
type = XCB_ATOM_CARDINAL;
prop = backend->atoms._NET_WM_PID;
type = XCB_ATOM_CARDINAL;
pid_t pid = getpid();
xcb_change_property(conn, mode, win, prop, type, 32, 1, &pid);
}
static void create_no_focus_window(backend_t *backend) {
xcb_connection_t *conn = backend->conn;
xcb_window_t root = backend->screen->root;
uint8_t d = backend->screen->root_depth;
xcb_visualid_t v = backend->screen->root_visual;
uint16_t _c = XCB_WINDOW_CLASS_COPY_FROM_PARENT;
xcb_window_t root = backend->screen->root;
uint8_t d = backend->screen->root_depth;
xcb_visualid_t v = backend->screen->root_visual;
uint16_t _c = XCB_WINDOW_CLASS_COPY_FROM_PARENT;
xcb_window_t win = xcb_generate_id(conn);
uint32_t m = XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXEL |
uint32_t m = XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXEL |
XCB_CW_OVERRIDE_REDIRECT | XCB_CW_COLORMAP;
const xcb_create_window_value_list_t p = {
.override_redirect = true,
.background_pixel = backend->screen->black_pixel,
.border_pixel = backend->screen->black_pixel,
.colormap = backend->screen->default_colormap,
.background_pixel = backend->screen->black_pixel,
.border_pixel = backend->screen->black_pixel,
.colormap = backend->screen->default_colormap,
};
xcb_create_window_aux(conn, d, win, root, -1, -1, 1, 1, 0, _c, v, m, &p);
window_set_class_instance(conn, win);
@@ -134,9 +134,9 @@ static void create_no_focus_window(backend_t *backend) {
}
backend_t *backend_create(const char *display_name) {
int screen_num = 0;
int screen_num = 0;
xcb_connection_t *conn = xcb_connect(display_name, &screen_num);
int xcb_conn_error = xcb_connection_has_error(conn);
int xcb_conn_error = xcb_connection_has_error(conn);
if (xcb_conn_error) {
fatal("cannot open display %s, error %d", display_name, xcb_conn_error);
}
@@ -145,7 +145,7 @@ backend_t *backend_create(const char *display_name) {
if (!screen) fatal("cannot get screen info");
xcb_window_t root = screen->root;
uint32_t mask = XCB_CW_EVENT_MASK;
uint32_t mask = XCB_CW_EVENT_MASK;
const xcb_params_cw_t params = {
.event_mask = XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT,
};
@@ -159,9 +159,9 @@ backend_t *backend_create(const char *display_name) {
}
backend_t *backend = p_new(backend_t, 1);
backend->conn = conn;
backend->screen = screen;
backend->screenp = screen_num;
backend->conn = conn;
backend->screen = screen;
backend->screenp = screen_num;
xcb_prefetch_extension_data(conn, &xcb_xfixes_id);
const xcb_query_extension_reply_t *query =
@@ -268,10 +268,10 @@ static bool detect_monitor_by_randr(
xcb_randr_monitor_info_iterator_t iter =
xcb_randr_get_monitors_monitors_iterator(monitors_reply);
for (int i = 0; iter.rem; xcb_randr_monitor_info_next(&iter), i++) {
output_info_t *output = &output_list[i];
output->geometry.x = iter.data->x;
output->geometry.y = iter.data->y;
output->geometry.width = iter.data->width;
output_info_t *output = &output_list[i];
output->geometry.x = iter.data->x;
output->geometry.y = iter.data->y;
output->geometry.width = iter.data->width;
output->geometry.height = iter.data->height;
xcb_get_atom_name_cookie_t name_cookie =
@@ -280,8 +280,8 @@ static bool detect_monitor_by_randr(
xcb_get_atom_name_reply(backend->conn, name_cookie, nullptr);
if (name_reply) {
char *name = xcb_get_atom_name_name(name_reply);
int length = xcb_get_atom_name_name_length(name_reply);
char *name = xcb_get_atom_name_name(name_reply);
int length = xcb_get_atom_name_name_length(name_reply);
output->name = p_strndup(name, length);
p_delete(&name_reply);
}
@@ -350,10 +350,10 @@ static bool detect_monitor_by_xinerama(
output_info_t *output_list = p_new(output_info_t, len);
for (int i = 0; i < len; i++) {
output_info_t *output = &output_list[i];
output->geometry.x = screen_info[i].x_org;
output->geometry.y = screen_info[i].y_org;
output->geometry.width = screen_info[i].width;
output_info_t *output = &output_list[i];
output->geometry.x = screen_info[i].x_org;
output->geometry.y = screen_info[i].y_org;
output->geometry.width = screen_info[i].width;
output->geometry.height = screen_info[i].height;
}
p_delete(&screens_reply);
@@ -371,7 +371,7 @@ static bool detect_monitor_by_xinerama(
backend_detect_t *backend_detect(backend_t *backend) {
output_info_t *outputs = nullptr;
size_t count = 0;
size_t count = 0;
if (detect_monitor_by_randr(backend, &outputs, &count)) {
backend_detect_t *detect = output_remove_duplication(outputs, count);
@@ -385,15 +385,15 @@ backend_detect_t *backend_detect(backend_t *backend) {
return detect;
}
output_info_t *output = p_new(output_info_t, 1);
output->geometry.x = 0;
output->geometry.y = 0;
output->geometry.width = backend->screen->width_in_pixels;
output_info_t *output = p_new(output_info_t, 1);
output->geometry.x = 0;
output->geometry.y = 0;
output->geometry.width = backend->screen->width_in_pixels;
output->geometry.height = backend->screen->height_in_pixels;
backend_detect_t *detect = p_new(backend_detect_t, 1);
detect->outputs = output;
detect->output_count = 1;
detect->outputs = output;
detect->output_count = 1;
return detect;
}
@@ -410,16 +410,16 @@ void backend_detect_destroy(backend_detect_t *detect) {
static void backend_focus_window(backend_t *backend, xcb_window_t window) {
xcb_connection_t *conn = backend->conn;
xcb_window_t root = backend->screen->root;
const atoms_t *atoms = &backend->atoms;
xcb_atom_t property = atoms->_NET_ACTIVE_WINDOW;
xcb_timestamp_t time = XCB_TIME_CURRENT_TIME;
xcb_window_t root = backend->screen->root;
const atoms_t *atoms = &backend->atoms;
xcb_atom_t property = atoms->_NET_ACTIVE_WINDOW;
xcb_timestamp_t time = XCB_TIME_CURRENT_TIME;
if (window == XCB_WINDOW_NONE || window == root) {
window = backend->window_no_focus;
xcb_set_input_focus(conn, XCB_INPUT_FOCUS_PARENT, window, time);
xcb_delete_property(conn, root, property);
} else {
uint8_t mode = XCB_PROP_MODE_REPLACE;
uint8_t mode = XCB_PROP_MODE_REPLACE;
xcb_atom_t type = XCB_ATOM_WINDOW;
xcb_set_input_focus(conn, XCB_INPUT_FOCUS_PARENT, window, time);
xcb_change_property(conn, mode, root, property, type, 32, 1, &window);
@@ -449,12 +449,12 @@ static void
backend_restack_windows(backend_t *backend, const effect_window_list_t *list) {
if (list->count == 0) return;
xcb_connection_t *conn = backend->conn;
xcb_connection_t *conn = backend->conn;
xcb_window_t sibling_window = backend->window_no_focus;
for (size_t i = 0; i < list->count; ++i) {
uint16_t mask = XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE;
xcb_configure_window_value_list_t params = {
.sibling = sibling_window,
.sibling = sibling_window,
.stack_mode = XCB_STACK_MODE_ABOVE
};
sibling_window = list->windows[i];
@@ -468,7 +468,7 @@ static void window_configure_list_reset(window_configure_list_t *configs) {
}
static void backend_apply_window_configure_list(backend_t *backend) {
xcb_connection_t *conn = backend->conn;
xcb_connection_t *conn = backend->conn;
window_configure_list_t *configs = &backend->config_list;
for (size_t i = 0; i < configs->count; ++i) {
window_configure_t *cfg = &configs->cfgs[i];
@@ -489,7 +489,7 @@ find_or_push_configure(window_configure_list_t *configs, xcb_window_t window) {
cfg = array_push(configs->cfgs, configs->count, configs->capacity);
p_clear(cfg, 1);
cfg->window = window;
cfg->mask = 0;
cfg->mask = 0;
return cfg;
}
@@ -501,8 +501,8 @@ static void merge_window_configure_params(
#define FIELD_MERGE(MASK, VALUE_FIELD, DATA_FIELD) \
if (data->changed_fields & (MASK)) { \
cfg->mask |= (MASK); \
cfg->value.VALUE_FIELD = data->DATA_FIELD; \
cfg->mask |= (MASK); \
cfg->value.VALUE_FIELD = data->DATA_FIELD; \
}
FIELD_MERGE(ZDWM_CONFIGURE_FIELD_X, x, x);
@@ -526,13 +526,13 @@ static void backend_grab_button(
backend_t *backend,
const effect_grab_button_t *grab_button
) {
auto conn = backend->conn;
auto conn = backend->conn;
auto window = grab_button->window;
xcb_ungrab_button(conn, XCB_BUTTON_INDEX_ANY, window, XCB_MOD_MASK_ANY);
auto buttons = grab_button->buttons;
for (size_t i = 0; i < grab_button->count; ++i) {
auto button = buttons[i].button;
auto button = buttons[i].button;
auto modifiers = buttons[i].modifiers;
window_grab_button(backend, window, button, modifiers);
}
@@ -543,9 +543,9 @@ static void backend_grab_pointer(backend_t *backend, cursor_t cursor) {
auto root = backend->screen->root;
auto mask = XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE |
XCB_EVENT_MASK_POINTER_MOTION;
auto mode = XCB_GRAB_MODE_ASYNC;
auto mode = XCB_GRAB_MODE_ASYNC;
auto xcursor = cursor_get_xcb_cursor(backend, cursor);
auto time = XCB_TIME_CURRENT_TIME;
auto time = XCB_TIME_CURRENT_TIME;
xcb_grab_pointer(conn, false, root, mask, mode, mode, root, xcursor, time);
}
@@ -584,7 +584,7 @@ static void backend_merge_effects(
backend_grab_pointer(backend, ZDWM_CURSOR_RESIZE);
break;
case ZDWM_EFFECT_MINIMIZE_WINDOW: {
auto window = e->as.minimize.window;
auto window = e->as.minimize.window;
xcb_icccm_wm_state_t state = XCB_ICCCM_WM_STATE_NORMAL;
if (e->as.minimize.value) state = XCB_ICCCM_WM_STATE_ICONIC;
window_set_icccm_wm_state(backend->conn, window, state);
@@ -697,10 +697,10 @@ bool backend_apply_effect(
}
backend_scan_result_t *backend_scan_windows(backend_t *backend) {
auto conn = backend->conn;
auto root = backend->screen->root;
auto conn = backend->conn;
auto root = backend->screen->root;
auto cookie = xcb_query_tree_unchecked(conn, root);
auto reply = xcb_query_tree_reply(conn, cookie, nullptr);
auto reply = xcb_query_tree_reply(conn, cookie, nullptr);
if (!reply) return nullptr;
auto length = xcb_query_tree_children_length(reply);
@@ -711,20 +711,20 @@ backend_scan_result_t *backend_scan_windows(backend_t *backend) {
auto list = xcb_query_tree_children(reply);
auto result = p_new(backend_scan_result_t, 1);
auto result = p_new(backend_scan_result_t, 1);
auto sub_result = p_new(backend_scan_result_t, 1);
for (typeof(length) i = 0; i < length; ++i) {
auto window = list[i];
auto wa = window_get_attributes(backend, window);
auto wa = window_get_attributes(backend, window);
if (!wa) continue;
auto override_redirect = wa->override_redirect;
auto map_state = wa->map_state;
auto map_state = wa->map_state;
p_delete(&wa);
if (override_redirect) continue;
auto hints = (xcb_icccm_wm_hints_t){0};
auto hints = (xcb_icccm_wm_hints_t){0};
auto hints_getted = window_get_wm_hints(backend, window, &hints);
if (!(map_state == XCB_MAP_STATE_VIEWABLE ||
(hints_getted && hints.initial_state == XCB_ICCCM_WM_STATE_ICONIC))) {
@@ -732,10 +732,11 @@ backend_scan_result_t *backend_scan_windows(backend_t *backend) {
}
auto transient_for = window_get_transient_for(backend, window);
auto r = transient_for == XCB_WINDOW_NONE ? result : sub_result;
auto slot = array_push(r->windows, r->count, r->capacity);
if (!populate_window_event(backend, list[i], slot) ||
slot->override_redirect) {
auto r = transient_for == XCB_WINDOW_NONE ? result : sub_result;
auto slot = array_push(r->windows, r->count, r->capacity);
if (
!populate_window_event(backend, list[i], slot) || slot->override_redirect
) {
window_layer_props_cleanup(&slot->props);
window_metadata_cleanup(&slot->metadata);
r->count--;
@@ -746,7 +747,7 @@ backend_scan_result_t *backend_scan_windows(backend_t *backend) {
for (size_t i = 0; i < sub_result->count; ++i) {
auto slot = array_push(result->windows, result->count, result->capacity);
*slot = sub_result->windows[i];
*slot = sub_result->windows[i];
}
p_clear(sub_result->windows, sub_result->count);
@@ -779,13 +780,13 @@ backend_bar_window_t backend_create_bar_window(
rect_t geometry,
uint32_t bg_pixel
) {
auto conn = backend->conn;
auto root = backend->screen->root;
auto conn = backend->conn;
auto root = backend->screen->root;
auto visual = window_get_visual(backend, true);
static xcb_colormap_t colormap = XCB_NONE;
if (colormap == XCB_NONE) {
colormap = xcb_generate_id(conn);
colormap = xcb_generate_id(conn);
uint8_t alloc = XCB_COLORMAP_ALLOC_NONE;
xcb_create_colormap(conn, alloc, colormap, root, visual->visual->visual_id);
}
@@ -793,18 +794,18 @@ backend_bar_window_t backend_create_bar_window(
window_clean_event_mask(conn, root);
xcb_grab_server(conn);
auto window_id = xcb_generate_id(conn);
uint16_t _class = XCB_WINDOW_CLASS_INPUT_OUTPUT;
auto window_id = xcb_generate_id(conn);
uint16_t _class = XCB_WINDOW_CLASS_INPUT_OUTPUT;
uint32_t value_mask = XCB_CW_OVERRIDE_REDIRECT | XCB_CW_BACK_PIXEL |
XCB_CW_BORDER_PIXEL | XCB_CW_EVENT_MASK |
XCB_CW_COLORMAP;
const xcb_create_window_value_list_t value_list = {
.override_redirect = true,
.background_pixel = bg_pixel,
.border_pixel = 0,
.event_mask = XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_EXPOSURE,
.colormap = colormap,
.background_pixel = bg_pixel,
.border_pixel = 0,
.event_mask = XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_EXPOSURE,
.colormap = colormap,
};
auto cookie = xcb_create_window_aux_checked(
conn,
@@ -833,11 +834,11 @@ backend_bar_window_t backend_create_bar_window(
root_set_event_mask(backend);
xcb_aux_sync(conn);
auto width = geometry.width;
auto height = geometry.height;
auto vid = visual->visual;
auto width = geometry.width;
auto height = geometry.height;
auto vid = visual->visual;
auto surface = cairo_xcb_surface_create(conn, window_id, vid, width, height);
auto cr = cairo_create(surface);
auto cr = cairo_create(surface);
cairo_surface_destroy(surface);
p_delete(&visual);

View File

@@ -8,14 +8,14 @@
static const char *const cursor_name_map[] = {
[ZDWM_CURSOR_NORMAL] = "left_ptr",
[ZDWM_CURSOR_MOVE] = "fleur",
[ZDWM_CURSOR_MOVE] = "fleur",
[ZDWM_CURSOR_RESIZE] = "bottom_right_corner",
};
static xcb_cursor_context_t *get_xcb_cursor_context(backend_t *backend) {
if (backend->cursor_context) return backend->cursor_context;
auto conn = backend->conn;
auto conn = backend->conn;
auto screen = backend->screen;
if (xcb_cursor_context_new(conn, screen, &backend->cursor_context) == 0) {
return backend->cursor_context;
@@ -29,7 +29,7 @@ void cursor_init(backend_t *backend) {
if (!ctx) return;
for (size_t i = 0; i < countof(backend->cursors); ++i) {
auto cursor_name = cursor_name_map[i];
auto cursor_name = cursor_name_map[i];
backend->cursors[i] = xcb_cursor_load_cursor(ctx, cursor_name);
}
}

View File

@@ -28,7 +28,7 @@ static window_state_t *derive_window_states(
return nullptr;
}
window_state_t *buf = p_new(window_state_t, count);
size_t valid = 0;
size_t valid = 0;
for (uint32_t i = 0; i < count; i++) {
window_state_t s = atom_to_window_state(atoms, raw[i]);
if (s != (window_state_t)-1) buf[valid++] = s;
@@ -58,8 +58,10 @@ static bool maximized_from_states(
uint32_t state_count
) {
for (uint32_t i = 0; i < state_count; i++) {
if (state_atoms[i] == atoms->_NET_WM_STATE_MAXIMIZED_VERT ||
state_atoms[i] == atoms->_NET_WM_STATE_MAXIMIZED_HORZ)
if (
state_atoms[i] == atoms->_NET_WM_STATE_MAXIMIZED_VERT ||
state_atoms[i] == atoms->_NET_WM_STATE_MAXIMIZED_HORZ
)
return true;
}
return false;
@@ -101,11 +103,11 @@ static void parse_size_hints(
*max = (zdwm_size_t){.width = INT32_MAX, .height = INT32_MAX};
if (hints->flags & XCB_ICCCM_SIZE_HINT_P_MIN_SIZE) {
min->width = hints->min_width;
min->width = hints->min_width;
min->height = hints->min_height;
}
if (hints->flags & XCB_ICCCM_SIZE_HINT_P_MAX_SIZE) {
max->width = hints->max_width;
max->width = hints->max_width;
max->height = hints->max_height;
}
}
@@ -115,7 +117,7 @@ bool populate_window_event(
xcb_window_t window,
window_map_request_event_t *ev
) {
ev->window = (window_id_t)window;
ev->window = (window_id_t)window;
ev->transient_for = window_get_transient_for(backend, window);
auto wa = window_get_attributes(backend, window);
@@ -125,7 +127,7 @@ bool populate_window_event(
xcb_icccm_wm_hints_t wm_hints = {0};
if (window_get_wm_hints(backend, window, &wm_hints)) {
ev->urgent = (bool)xcb_icccm_wm_hints_get_urgency(&wm_hints);
ev->urgent = (bool)xcb_icccm_wm_hints_get_urgency(&wm_hints);
ev->minimized = wm_hints.initial_state == XCB_ICCCM_WM_STATE_ICONIC;
}
@@ -135,9 +137,9 @@ bool populate_window_event(
if (!window_get_geometry(backend, window, &ev->rect)) return false;
const atoms_t *atoms = &backend->atoms;
const atoms_t *atoms = &backend->atoms;
xcb_atom_t *state_atoms = nullptr;
uint32_t state_count = 0;
uint32_t state_count = 0;
if (!window_get_atom_array(
backend,
window,
@@ -149,8 +151,8 @@ bool populate_window_event(
}
if (state_atoms) {
ev->maximized = maximized_from_states(atoms, state_atoms, state_count);
ev->fullscreen = fullscreen_from_states(atoms, state_atoms, state_count);
ev->maximized = maximized_from_states(atoms, state_atoms, state_count);
ev->fullscreen = fullscreen_from_states(atoms, state_atoms, state_count);
ev->skip_taskbar = derive_skip_taskbar(atoms, state_atoms, state_count);
ev->props.states = derive_window_states(
atoms,
@@ -171,7 +173,7 @@ bool populate_window_event(
return false;
}
ev->metadata.role = window_get_role(backend, window);
ev->metadata.role = window_get_role(backend, window);
ev->metadata.title = window_get_title(backend, window);
window_get_class(
backend,
@@ -201,7 +203,7 @@ static bool handle_unmap_notify(
event_t *event,
const xcb_unmap_notify_event_t *xcb_event
) {
event->type = ZDWM_EVENT_WINDOW_REMOVE;
event->type = ZDWM_EVENT_WINDOW_REMOVE;
event->as.window_remove.window = xcb_event->window;
if (XCB_EVENT_SENT(xcb_event)) {
event->as.window_remove.reason = ZDWM_WINDOW_REMOVE_WITHDRAWN;
@@ -217,7 +219,7 @@ static bool handle_destroy_notify(
event_t *event,
const xcb_destroy_notify_event_t *xcb_event
) {
event->type = ZDWM_EVENT_WINDOW_REMOVE;
event->type = ZDWM_EVENT_WINDOW_REMOVE;
event->as.window_remove.window = xcb_event->window;
event->as.window_remove.reason = ZDWM_WINDOW_REMOVE_DESTROY;
@@ -229,14 +231,14 @@ static bool handle_configure_request(
event_t *event,
const xcb_configure_request_event_t *xcb_event
) {
event->type = ZDWM_EVENT_CONFIGURE_REQUEST;
auto data = &event->as.configure_request;
data->window = xcb_event->window;
event->type = ZDWM_EVENT_CONFIGURE_REQUEST;
auto data = &event->as.configure_request;
data->window = xcb_event->window;
data->changed_fields = 0u;
#define EXTRACT_FIELD(XCB_MASK, FIELD_MASK, DATA_FIELD, EVENT_FIELD) \
if (xcb_event->value_mask & XCB_CONFIG_WINDOW_##XCB_MASK) { \
data->DATA_FIELD = xcb_event->EVENT_FIELD; \
data->DATA_FIELD = xcb_event->EVENT_FIELD; \
data->changed_fields |= ZDWM_CONFIGURE_FIELD_##FIELD_MASK; \
}
@@ -263,9 +265,9 @@ static bool handle_key_press(
/* keysym without any modifiers */
auto keysym = xcb_key_symbols_get_keysym(backend->key_symbols, keycode, 0);
event->type = ZDWM_EVENT_KEY_PRESS;
event->as.key_press.keycode = keycode;
event->as.key_press.keysym = keysym;
event->type = ZDWM_EVENT_KEY_PRESS;
event->as.key_press.keycode = keycode;
event->as.key_press.keysym = keysym;
event->as.key_press.modifiers = modifiers_xcb_to_zdwm(xcb_event->state);
return true;
@@ -278,10 +280,10 @@ static bool fill_button_event(
auto button = button_xcb_to_zdwm(xcb_event->detail);
data->modifiers = modifiers_xcb_to_zdwm(xcb_event->state);
data->button = button;
data->window = xcb_event->event;
data->root = (point_t){.x = xcb_event->root_x, .y = xcb_event->root_y};
data->local = (point_t){.x = xcb_event->event_x, .y = xcb_event->event_y};
data->button = button;
data->window = xcb_event->event;
data->root = (point_t){.x = xcb_event->root_x, .y = xcb_event->root_y};
data->local = (point_t){.x = xcb_event->event_x, .y = xcb_event->event_y};
return true;
}
@@ -291,7 +293,7 @@ static bool handle_button_press(
event_t *event,
const xcb_button_press_event_t *xcb_event
) {
auto press = &event->as.pointer_button_press;
auto press = &event->as.pointer_button_press;
auto handled = fill_button_event(xcb_event, press);
if (handled) event->type = ZDWM_EVENT_POINTER_BUTTON_PRESS;
@@ -317,10 +319,10 @@ static bool handle_motion_notify(
) {
event->type = ZDWM_EVENT_POINTER_MOTION;
auto data = &event->as.pointer_motion;
auto data = &event->as.pointer_motion;
data->window = xcb_event->event;
data->root = (point_t){.x = xcb_event->root_x, .y = xcb_event->root_y};
data->local = (point_t){.x = xcb_event->event_x, .y = xcb_event->event_y};
data->root = (point_t){.x = xcb_event->root_x, .y = xcb_event->root_y};
data->local = (point_t){.x = xcb_event->event_x, .y = xcb_event->event_y};
return true;
}
@@ -329,7 +331,7 @@ static bool handle_enter_notify(
event_t *event,
const xcb_enter_notify_event_t *xcb_event
) {
event->type = ZDWM_EVENT_POINTER_ENTER;
event->type = ZDWM_EVENT_POINTER_ENTER;
event->as.pointer_enter.window = xcb_event->event;
return true;
@@ -341,12 +343,14 @@ static bool handle_property_notify(
const xcb_property_notify_event_t *xcb_event
) {
auto window_id = xcb_event->window;
if (xcb_event->atom == backend->atoms.WM_NAME ||
xcb_event->atom == backend->atoms._NET_WM_NAME) {
if (
xcb_event->atom == backend->atoms.WM_NAME ||
xcb_event->atom == backend->atoms._NET_WM_NAME
) {
event->type = ZDWM_EVENT_WINDOW_METADATA_CHANGED;
auto data = &event->as.window_metadata_change;
data->window = window_id;
auto data = &event->as.window_metadata_change;
data->window = window_id;
data->metadata.title = window_get_title(backend, window_id);
data->changed_fields = ZDWM_WINDOW_METADATA_CHANGE_TITLE;
return true;
@@ -355,9 +359,9 @@ static bool handle_property_notify(
if (xcb_event->atom == backend->atoms.WM_WINDOW_ROLE) {
event->type = ZDWM_EVENT_WINDOW_METADATA_CHANGED;
auto data = &event->as.window_metadata_change;
data->window = window_id;
data->metadata.role = window_get_role(backend, window_id);
auto data = &event->as.window_metadata_change;
data->window = window_id;
data->metadata.role = window_get_role(backend, window_id);
data->changed_fields = ZDWM_WINDOW_METADATA_CHANGE_ROLE;
return true;
}
@@ -365,7 +369,7 @@ static bool handle_property_notify(
if (xcb_event->atom == XCB_ATOM_WM_CLASS) {
event->type = ZDWM_EVENT_WINDOW_METADATA_CHANGED;
auto data = &event->as.window_metadata_change;
auto data = &event->as.window_metadata_change;
data->window = window_id;
window_get_class(
backend,
@@ -384,11 +388,11 @@ static bool handle_property_notify(
event->type = ZDWM_EVENT_WINDOW_HINTS_CHANGED;
auto data = &event->as.hints;
auto data = &event->as.hints;
data->window = window_id;
if (hints.flags & XCB_ICCCM_WM_HINT_X_URGENCY) {
data->changed_fields |= ZDWM_HINT_FIELD_URGENT;
data->urgent = xcb_icccm_wm_hints_get_urgency(&hints);
data->urgent = xcb_icccm_wm_hints_get_urgency(&hints);
return true;
}
return false;
@@ -400,7 +404,7 @@ static bool handle_property_notify(
event->type = ZDWM_EVENT_WINDOW_HINTS_CHANGED;
auto data = &event->as.hints;
auto data = &event->as.hints;
data->window = window_id;
data->changed_fields |= ZDWM_HINT_FIELD_SIZE;
@@ -427,7 +431,7 @@ static bool handle_client_message(
if (xcb_event->type == atoms->WM_CHANGE_STATE) {
if (xcb_event->data.data32[0] == XCB_ICCCM_WM_STATE_ICONIC) {
event->type = ZDWM_EVENT_WINDOW_STATE_REQUEST;
event->type = ZDWM_EVENT_WINDOW_STATE_REQUEST;
event->as.window_state_request.window = xcb_event->window;
event->as.window_state_request.type = ZDWM_WINDOW_STATE_REQUEST_MINIMIZED;
event->as.window_state_request.action = ZDWM_WINDOW_STATE_ACTION_ADD;
@@ -437,8 +441,8 @@ static bool handle_client_message(
}
if (xcb_event->type == atoms->_NET_WM_STATE) {
event->type = ZDWM_EVENT_WINDOW_STATE_REQUEST;
auto data = &event->as.window_state_request;
event->type = ZDWM_EVENT_WINDOW_STATE_REQUEST;
auto data = &event->as.window_state_request;
data->window = xcb_event->window;
/**
* _NET_WM_STATE 协议数据格式为
@@ -467,7 +471,7 @@ static bool handle_client_message(
break;
}
auto properties = &xcb_event->data.data32[1];
uint32_t count = 2;
uint32_t count = 2;
if (maximized_from_states(atoms, properties, count)) {
data->type = ZDWM_WINDOW_STATE_REQUEST_MAXIMIZED;
@@ -484,9 +488,9 @@ static bool handle_client_message(
}
if (urgent_from_states(atoms, properties, count)) {
event->type = ZDWM_EVENT_WINDOW_HINTS_CHANGED;
event->type = ZDWM_EVENT_WINDOW_HINTS_CHANGED;
event->as.hints = (typeof(event->as.hints)){
.urgent = true,
.urgent = true,
.changed_fields = ZDWM_HINT_FIELD_URGENT,
};
return true;
@@ -504,7 +508,7 @@ static bool handle_event(
event_t *event
) {
uint8_t response_type = XCB_EVENT_RESPONSE_TYPE(raw_event);
bool handled = false;
bool handled = false;
auto label = xcb_event_get_label(response_type);
printf("xcb event type: %s[%u]\n", label, response_type);

View File

@@ -34,14 +34,16 @@ static char *window_get_text_property(
xcb_get_property_reply(backend->conn, cookie, nullptr);
if (!reply) return nullptr;
int length = xcb_get_property_value_length(reply);
int length = xcb_get_property_value_length(reply);
char *value = (char *)xcb_get_property_value(reply);
char *text = nullptr;
if (length && reply->format == 8 &&
(reply->type == XCB_ATOM_STRING ||
reply->type == backend->atoms.UTF8_STRING ||
reply->type == backend->atoms.COMPOUND_TEXT)) {
if (
length && reply->format == 8 &&
(reply->type == XCB_ATOM_STRING ||
reply->type == backend->atoms.UTF8_STRING ||
reply->type == backend->atoms.COMPOUND_TEXT)
) {
text = p_strndup(value, (size_t)length);
}
@@ -56,10 +58,10 @@ char *window_get_role(backend_t *backend, xcb_window_t window) {
char *window_get_title(backend_t *backend, xcb_window_t window) {
xcb_atom_t property = backend->atoms._NET_WM_NAME;
char *name = window_get_text_property(backend, window, property);
char *name = window_get_text_property(backend, window, property);
if (!name) {
property = backend->atoms.WM_NAME;
name = window_get_text_property(backend, window, property);
name = window_get_text_property(backend, window, property);
}
return name;
}
@@ -134,7 +136,7 @@ bool window_get_types(
size_t *count
) {
uint32_t atom_count = 0;
xcb_atom_t *atoms = nullptr;
xcb_atom_t *atoms = nullptr;
if (!window_get_atom_array(
backend,
window,
@@ -181,9 +183,9 @@ bool window_get_geometry(backend_t *backend, xcb_window_t window, rect_t *out) {
xcb_get_geometry_reply(backend->conn, cookie, nullptr);
if (!reply) return false;
out->x = reply->x;
out->y = reply->y;
out->width = reply->width;
out->x = reply->x;
out->y = reply->y;
out->width = reply->width;
out->height = reply->height;
p_delete(&reply);
@@ -215,7 +217,7 @@ bool window_get_atom_array(
*out_atoms =
p_copy((xcb_atom_t *)xcb_get_property_value(reply), reply->value_len);
} else {
*out_len = 0;
*out_len = 0;
*out_atoms = nullptr;
}
@@ -251,7 +253,7 @@ window_send_event(backend_t *backend, xcb_window_t window, xcb_atom_t atom) {
bool exist = false;
xcb_connection_t *conn = backend->conn;
auto WM_PROTOCOLS = backend->atoms.WM_PROTOCOLS;
auto WM_PROTOCOLS = backend->atoms.WM_PROTOCOLS;
xcb_get_property_cookie_t cookie =
xcb_icccm_get_wm_protocols_unchecked(conn, window, WM_PROTOCOLS);
@@ -266,10 +268,10 @@ window_send_event(backend_t *backend, xcb_window_t window, xcb_atom_t atom) {
if (exist) {
xcb_client_message_event_t ev = {
.response_type = XCB_CLIENT_MESSAGE,
.format = 32,
.window = window,
.type = WM_PROTOCOLS,
.data.data32 = {atom, XCB_CURRENT_TIME},
.format = 32,
.window = window,
.type = WM_PROTOCOLS,
.data.data32 = {atom, XCB_CURRENT_TIME},
};
xcb_send_event(conn, false, window, XCB_EVENT_MASK_NO_EVENT, (char *)&ev);
}
@@ -288,9 +290,9 @@ void window_kill(backend_t *backend, xcb_window_t window) {
}
void root_set_event_mask(backend_t *backend) {
xcb_connection_t *conn = backend->conn;
xcb_window_t root = backend->screen->root;
xcb_cw_t change_mask = XCB_CW_EVENT_MASK;
xcb_connection_t *conn = backend->conn;
xcb_window_t root = backend->screen->root;
xcb_cw_t change_mask = XCB_CW_EVENT_MASK;
xcb_change_window_attributes_value_list_t value_list = {
.event_mask =
XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_KEY_PRESS,
@@ -299,7 +301,7 @@ void root_set_event_mask(backend_t *backend) {
}
void window_set_event_mask(xcb_connection_t *conn, xcb_window_t window) {
xcb_cw_t change_mask = XCB_CW_EVENT_MASK;
xcb_cw_t change_mask = XCB_CW_EVENT_MASK;
xcb_change_window_attributes_value_list_t value_list = {
.event_mask = XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_FOCUS_CHANGE |
XCB_EVENT_MASK_PROPERTY_CHANGE |
@@ -310,7 +312,7 @@ void window_set_event_mask(xcb_connection_t *conn, xcb_window_t window) {
}
void window_clean_event_mask(xcb_connection_t *conn, xcb_window_t window) {
xcb_cw_t change_mask = XCB_CW_EVENT_MASK;
xcb_cw_t change_mask = XCB_CW_EVENT_MASK;
xcb_change_window_attributes_value_list_t value_list = {
.event_mask = XCB_EVENT_MASK_NO_EVENT,
};
@@ -385,7 +387,7 @@ void window_grab_keys(
const key_bind_t *keys,
size_t count
) {
auto conn = backend->conn;
auto conn = backend->conn;
auto key_symbols = backend->key_symbols;
xcb_ungrab_key(conn, XCB_GRAB_ANY, window, XCB_MOD_MASK_ANY);
@@ -393,7 +395,7 @@ void window_grab_keys(
xcb_grab_mode_t mode = XCB_GRAB_MODE_ASYNC;
for (size_t i = 0; i < count; ++i) {
auto key = &keys[i];
auto key = &keys[i];
auto keycodes = xcb_key_symbols_get_keycode(key_symbols, key->keysym);
if (!keycodes) continue;
@@ -413,9 +415,9 @@ static visual_t *get_alpha_visual(backend_t *backend) {
auto visual_iter = xcb_depth_visuals_iterator(depth_iter.data);
for (; visual_iter.rem; xcb_visualtype_next(&visual_iter)) {
if (visual_iter.data->_class == XCB_VISUAL_CLASS_TRUE_COLOR) {
auto visual = p_new(visual_t, 1);
auto visual = p_new(visual_t, 1);
visual->visual = visual_iter.data;
visual->depth = depth_iter.data->depth;
visual->depth = depth_iter.data->depth;
return visual;
}
}
@@ -426,14 +428,14 @@ static visual_t *get_alpha_visual(backend_t *backend) {
static visual_t *get_root_visual(backend_t *backend) {
auto depth_iter = xcb_screen_allowed_depths_iterator(backend->screen);
auto visual_id = backend->screen->root_visual;
auto visual_id = backend->screen->root_visual;
for (; depth_iter.rem; xcb_depth_next(&depth_iter)) {
auto visual_iter = xcb_depth_visuals_iterator(depth_iter.data);
for (; visual_iter.rem; xcb_visualtype_next(&visual_iter)) {
if (visual_iter.data->visual_id == visual_id) {
auto visual = p_new(visual_t, 1);
auto visual = p_new(visual_t, 1);
visual->visual = visual_iter.data;
visual->depth = depth_iter.data->depth;
visual->depth = depth_iter.data->depth;
return visual;
}
}
@@ -456,7 +458,7 @@ void window_change_cursor(
xcb_window_t window,
cursor_t cursor
) {
auto conn = backend->conn;
auto conn = backend->conn;
xcb_params_cw_t params = {.cursor = cursor_get_xcb_cursor(backend, cursor)};
xcb_aux_change_window_attributes(conn, window, XCB_CW_CURSOR, &params);
}