diff --git a/src/animation/client.h b/src/animation/client.h index 8de9b06..c2b48e3 100644 --- a/src/animation/client.h +++ b/src/animation/client.h @@ -237,7 +237,7 @@ void buffer_set_effect(Client *c, BufferData data) { data.should_scale = false; } - if (c == grabc) + if (c == server.grabc) data.should_scale = false; if (c->isnoradius || c->isfullscreen || @@ -315,7 +315,7 @@ void client_draw_shadow(Client *c) { int32_t right_offset, bottom_offset, left_offset, top_offset; - if (c == grabc) { + if (c == server.grabc) { right_offset = 0; bottom_offset = 0; left_offset = 0; @@ -382,7 +382,7 @@ void apply_border(Client *c) { int32_t right_offset, bottom_offset, left_offset, top_offset; - if (c == grabc) { + if (c == server.grabc) { right_offset = 0; bottom_offset = 0; left_offset = 0; @@ -741,12 +741,13 @@ void client_animation_next_tick(Client *c) { c->animation.current = c->geom; } - xytonode(cursor->x, cursor->y, NULL, &pointer_c, NULL, &sx, &sy); + xytonode(server.cursor->x, server.cursor->y, NULL, &pointer_c, NULL, + &sx, &sy); surface = pointer_c && pointer_c == c ? client_surface(pointer_c) : NULL; - if (surface && pointer_c == selmon->sel) { - wlr_seat_pointer_notify_enter(seat, surface, sx, sy); + if (surface && pointer_c == server.selmon->sel) { + wlr_seat_pointer_notify_enter(server.seat, surface, sx, sy); } // end flush in next frame, not the current frame @@ -777,7 +778,7 @@ void init_fadeout_client(Client *c) { wlr_scene_node_set_enabled(&c->scene->node, true); client_set_border_color(c, bordercolor); fadeout_cient->scene = - wlr_scene_tree_snapshot(&c->scene->node, layers[LyrFadeOut]); + wlr_scene_tree_snapshot(&c->scene->node, server.layers[LyrFadeOut]); wlr_scene_node_set_enabled(&c->scene->node, false); if (!fadeout_cient->scene) { @@ -836,7 +837,7 @@ void init_fadeout_client(Client *c) { fadeout_cient->animation.time_started = get_now_in_ms(); wlr_scene_node_set_enabled(&fadeout_cient->scene->node, true); - wl_list_insert(&fadeout_clients, &fadeout_cient->fadeout_link); + wl_list_insert(&server.fadeout_clients, &fadeout_cient->fadeout_link); // 请求刷新屏幕 request_fresh_all_monitors(); @@ -871,7 +872,7 @@ void client_set_pending_state(Client *c) { c->animation.should_animate = false; } else if (animations && c->animation.tagining) { c->animation.should_animate = true; - } else if (!animations || c == grabc || + } else if (!animations || c == server.grabc || (!c->is_pending_open_animation && wlr_box_equal(&c->current, &c->pending))) { c->animation.should_animate = false; @@ -892,7 +893,7 @@ void client_set_pending_state(Client *c) { c->istagswitching = 0; } - if (start_drag_window) { + if (server.start_drag_window) { c->animation.should_animate = false; c->animation.duration = 0; } @@ -925,9 +926,10 @@ void resize(Client *c, struct wlr_box geo, int32_t interact) { c->dirty = true; // float_geom = c->geom; - bbox = (interact || c->isfloating || c->isfullscreen) ? &sgeom : &c->mon->w; + bbox = (interact || c->isfloating || c->isfullscreen) ? &server.sgeom + : &c->mon->w; - if (is_scroller_layout(c->mon) && (!c->isfloating || c == grabc)) { + if (is_scroller_layout(c->mon) && (!c->isfloating || c == server.grabc)) { c->geom = geo; c->geom.width = MAX(1 + 2 * (int32_t)c->bw, c->geom.width); c->geom.height = MAX(1 + 2 * (int32_t)c->bw, c->geom.height); @@ -990,7 +992,7 @@ void resize(Client *c, struct wlr_box geo, int32_t interact) { c->configure_serial = client_set_size(c, c->geom.width - 2 * c->bw, c->geom.height - 2 * c->bw); - if (c == grabc) { + if (c == server.grabc) { c->animation.running = false; c->need_output_flush = false; @@ -1109,7 +1111,7 @@ bool client_apply_focus_opacity(Client *c) { float percent = animation_fade_in && !c->nofadein ? opacity_eased_progress : 1.0; float opacity = - c == selmon->sel ? c->focused_opacity : c->unfocused_opacity; + c == server.selmon->sel ? c->focused_opacity : c->unfocused_opacity; float target_opacity = percent * (1.0 - fadein_begin_opacity) + fadein_begin_opacity; @@ -1157,7 +1159,7 @@ bool client_apply_focus_opacity(Client *c) { } else { return true; } - } else if (c == selmon->sel) { + } else if (c == server.selmon->sel) { c->opacity_animation.running = false; c->opacity_animation.current_opacity = c->focused_opacity; memcpy(c->opacity_animation.current_border_color, border_color, diff --git a/src/animation/common.h b/src/animation/common.h index 9f022db..e38b25f 100644 --- a/src/animation/common.h +++ b/src/animation/common.h @@ -29,44 +29,47 @@ struct dvec2 calculate_animation_curve_at(double t, int32_t type) { } void init_baked_points(void) { - baked_points_move = calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_move)); - baked_points_open = calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_open)); - baked_points_tag = calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_tag)); - baked_points_close = - calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_close)); - baked_points_focus = - calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_focus)); - baked_points_opafadein = - calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_opafadein)); - baked_points_opafadeout = - calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_opafadeout)); + server.baked_points_move = + calloc(BAKED_POINTS_COUNT, sizeof(*server.baked_points_move)); + server.baked_points_open = + calloc(BAKED_POINTS_COUNT, sizeof(*server.baked_points_open)); + server.baked_points_tag = + calloc(BAKED_POINTS_COUNT, sizeof(*server.baked_points_tag)); + server.baked_points_close = + calloc(BAKED_POINTS_COUNT, sizeof(*server.baked_points_close)); + server.baked_points_focus = + calloc(BAKED_POINTS_COUNT, sizeof(*server.baked_points_focus)); + server.baked_points_opafadein = + calloc(BAKED_POINTS_COUNT, sizeof(*server.baked_points_opafadein)); + server.baked_points_opafadeout = + calloc(BAKED_POINTS_COUNT, sizeof(*server.baked_points_opafadeout)); for (int32_t i = 0; i < BAKED_POINTS_COUNT; i++) { - baked_points_move[i] = calculate_animation_curve_at( + server.baked_points_move[i] = calculate_animation_curve_at( (double)i / (BAKED_POINTS_COUNT - 1), MOVE); } for (int32_t i = 0; i < BAKED_POINTS_COUNT; i++) { - baked_points_open[i] = calculate_animation_curve_at( + server.baked_points_open[i] = calculate_animation_curve_at( (double)i / (BAKED_POINTS_COUNT - 1), OPEN); } for (int32_t i = 0; i < BAKED_POINTS_COUNT; i++) { - baked_points_tag[i] = calculate_animation_curve_at( + server.baked_points_tag[i] = calculate_animation_curve_at( (double)i / (BAKED_POINTS_COUNT - 1), TAG); } for (int32_t i = 0; i < BAKED_POINTS_COUNT; i++) { - baked_points_close[i] = calculate_animation_curve_at( + server.baked_points_close[i] = calculate_animation_curve_at( (double)i / (BAKED_POINTS_COUNT - 1), CLOSE); } for (int32_t i = 0; i < BAKED_POINTS_COUNT; i++) { - baked_points_focus[i] = calculate_animation_curve_at( + server.baked_points_focus[i] = calculate_animation_curve_at( (double)i / (BAKED_POINTS_COUNT - 1), FOCUS); } for (int32_t i = 0; i < BAKED_POINTS_COUNT; i++) { - baked_points_opafadein[i] = calculate_animation_curve_at( + server.baked_points_opafadein[i] = calculate_animation_curve_at( (double)i / (BAKED_POINTS_COUNT - 1), OPAFADEIN); } for (int32_t i = 0; i < BAKED_POINTS_COUNT; i++) { - baked_points_opafadeout[i] = calculate_animation_curve_at( + server.baked_points_opafadeout[i] = calculate_animation_curve_at( (double)i / (BAKED_POINTS_COUNT - 1), OPAFADEOUT); } } @@ -78,21 +81,21 @@ double find_animation_curve_at(double t, int32_t type) { int32_t middle = (up + down) / 2; struct dvec2 *baked_points; if (type == MOVE) { - baked_points = baked_points_move; + baked_points = server.baked_points_move; } else if (type == OPEN) { - baked_points = baked_points_open; + baked_points = server.baked_points_open; } else if (type == TAG) { - baked_points = baked_points_tag; + baked_points = server.baked_points_tag; } else if (type == CLOSE) { - baked_points = baked_points_close; + baked_points = server.baked_points_close; } else if (type == FOCUS) { - baked_points = baked_points_focus; + baked_points = server.baked_points_focus; } else if (type == OPAFADEIN) { - baked_points = baked_points_opafadein; + baked_points = server.baked_points_opafadein; } else if (type == OPAFADEOUT) { - baked_points = baked_points_opafadeout; + baked_points = server.baked_points_opafadeout; } else { - baked_points = baked_points_move; + baked_points = server.baked_points_move; } while (up - down != 1) { @@ -238,7 +241,8 @@ struct wlr_scene_tree *wlr_scene_tree_snapshot(struct wlr_scene_node *node, } // Disable and enable the snapshot tree like so to atomically update - // the scene-graph. This will prevent over-damaging or other weirdness. + // the server.scene -graph. This will prevent over-damaging or other + // weirdness. wlr_scene_node_set_enabled(&snapshot->node, false); if (!scene_node_snapshot(node, 0, 0, snapshot)) { @@ -253,7 +257,7 @@ struct wlr_scene_tree *wlr_scene_tree_snapshot(struct wlr_scene_node *node, void request_fresh_all_monitors(void) { Monitor *m = NULL; - wl_list_for_each(m, &mons, link) { + wl_list_for_each(m, &server.mons, link) { if (!m->wlr_output->enabled) { continue; } diff --git a/src/animation/layer.h b/src/animation/layer.h index 568d52b..c894aa3 100644 --- a/src/animation/layer.h +++ b/src/animation/layer.h @@ -395,7 +395,7 @@ void init_fadeout_layers(LayerSurface *l) { wlr_scene_node_set_enabled(&l->scene->node, true); fadeout_layer->scene = - wlr_scene_tree_snapshot(&l->scene->node, layers[LyrFadeOut]); + wlr_scene_tree_snapshot(&l->scene->node, server.layers[LyrFadeOut]); wlr_scene_node_set_enabled(&l->scene->node, false); if (!fadeout_layer->scene) { @@ -463,7 +463,7 @@ void init_fadeout_layers(LayerSurface *l) { // 将节点插入到关闭动画链表中,屏幕刷新哪里会检查链表中是否有节点可以应用于动画 wlr_scene_node_set_enabled(&fadeout_layer->scene->node, true); - wl_list_insert(&fadeout_layers, &fadeout_layer->fadeout_link); + wl_list_insert(&server.fadeout_layers, &fadeout_layer->fadeout_link); // 请求刷新屏幕 if (l->mon) diff --git a/src/client/client.h b/src/client/client.h index 8995a5d..f38c582 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -279,10 +279,10 @@ static inline int32_t client_is_unmanaged(Client *c) { static inline void client_notify_enter(struct wlr_surface *s, struct wlr_keyboard *kb) { if (kb) - wlr_seat_keyboard_notify_enter(seat, s, kb->keycodes, kb->num_keycodes, - &kb->modifiers); + wlr_seat_keyboard_notify_enter(server.seat, s, kb->keycodes, + kb->num_keycodes, &kb->modifiers); else - wlr_seat_keyboard_notify_enter(seat, s, NULL, 0, NULL); + wlr_seat_keyboard_notify_enter(server.seat, s, NULL, 0, NULL); } static inline void client_send_close(Client *c) { diff --git a/src/config/parse_config.h b/src/config/parse_config.h index b2fd8eb..2146a99 100644 --- a/src/config/parse_config.h +++ b/src/config/parse_config.h @@ -2667,8 +2667,8 @@ void parse_config_file(Config *config, const char *file_path) { if (file_path[0] == '.' && file_path[1] == '/') { // Relative path - if (cli_config_path) { - char *config_path = strdup(cli_config_path); + if (server.cli_config_path) { + char *config_path = strdup(server.cli_config_path); char *config_dir = dirname(config_path); snprintf(full_path, sizeof(full_path), "%s/%s", config_dir, file_path + 1); @@ -2750,33 +2750,33 @@ void free_circle_layout(Config *config) { } void free_baked_points(void) { - if (baked_points_move) { - free(baked_points_move); - baked_points_move = NULL; + if (server.baked_points_move) { + free(server.baked_points_move); + server.baked_points_move = NULL; } - if (baked_points_open) { - free(baked_points_open); - baked_points_open = NULL; + if (server.baked_points_open) { + free(server.baked_points_open); + server.baked_points_open = NULL; } - if (baked_points_close) { - free(baked_points_close); - baked_points_close = NULL; + if (server.baked_points_close) { + free(server.baked_points_close); + server.baked_points_close = NULL; } - if (baked_points_tag) { - free(baked_points_tag); - baked_points_tag = NULL; + if (server.baked_points_tag) { + free(server.baked_points_tag); + server.baked_points_tag = NULL; } - if (baked_points_focus) { - free(baked_points_focus); - baked_points_focus = NULL; + if (server.baked_points_focus) { + free(server.baked_points_focus); + server.baked_points_focus = NULL; } - if (baked_points_opafadein) { - free(baked_points_opafadein); - baked_points_opafadein = NULL; + if (server.baked_points_opafadein) { + free(server.baked_points_opafadein); + server.baked_points_opafadein = NULL; } - if (baked_points_opafadeout) { - free(baked_points_opafadeout); - baked_points_opafadeout = NULL; + if (server.baked_points_opafadeout) { + free(server.baked_points_opafadeout); + server.baked_points_opafadeout = NULL; } } @@ -3300,7 +3300,7 @@ void set_value_default() { config.overviewgappo = overviewgappo; /* overview时 窗口与窗口 缝隙大小 */ config.cursor_hide_timeout = cursor_hide_timeout; - config.warpcursor = warpcursor; /* Warp cursor to focused client */ + config.warpcursor = warpcursor; /* Warp server.cursor to focused client */ config.drag_corner = drag_corner; config.drag_warp_cursor = drag_warp_cursor; @@ -3453,8 +3453,8 @@ void parse_config(void) { create_config_keymap(); - if (cli_config_path) { - snprintf(filename, sizeof(filename), "%s", cli_config_path); + if (server.cli_config_path) { + snprintf(filename, sizeof(filename), "%s", server.cli_config_path); } else { // 获取当前用户家目录 const char *homedir = getenv("HOME"); @@ -3484,21 +3484,22 @@ void parse_config(void) { void reset_blur_params(void) { if (blur) { Monitor *m = NULL; - wl_list_for_each(m, &mons, link) { + wl_list_for_each(m, &server.mons, link) { if (m->blur != NULL) { wlr_scene_node_destroy(&m->blur->node); } - m->blur = wlr_scene_optimized_blur_create(&scene->tree, 0, 0); - wlr_scene_node_reparent(&m->blur->node, layers[LyrBlur]); + m->blur = + wlr_scene_optimized_blur_create(&server.scene->tree, 0, 0); + wlr_scene_node_reparent(&m->blur->node, server.layers[LyrBlur]); wlr_scene_optimized_blur_set_size(m->blur, m->m.width, m->m.height); wlr_scene_set_blur_data( - scene, blur_params.num_passes, blur_params.radius, + server.scene, blur_params.num_passes, blur_params.radius, blur_params.noise, blur_params.brightness, blur_params.contrast, blur_params.saturation); } } else { Monitor *m = NULL; - wl_list_for_each(m, &mons, link) { + wl_list_for_each(m, &server.mons, link) { if (m->blur) { wlr_scene_node_destroy(&m->blur->node); @@ -3517,7 +3518,7 @@ void reapply_monitor_rules(void) { struct wlr_output_mode *internal_mode = NULL; wlr_output_state_init(&state); - wl_list_for_each(m, &mons, link) { + wl_list_for_each(m, &server.mons, link) { if (!m->wlr_output->enabled) { continue; } @@ -3553,7 +3554,8 @@ void reapply_monitor_rules(void) { wlr_output_state_set_scale(&state, mr->scale); wlr_output_state_set_transform(&state, mr->rr); - wlr_output_layout_add(output_layout, m->wlr_output, mx, my); + wlr_output_layout_add(server.output_layout, m->wlr_output, mx, + my); } } @@ -3564,36 +3566,38 @@ void reapply_monitor_rules(void) { } void reapply_cursor_style(void) { - if (hide_source) { - wl_event_source_timer_update(hide_source, 0); - wl_event_source_remove(hide_source); - hide_source = NULL; + if (server.hide_source) { + wl_event_source_timer_update(server.hide_source, 0); + wl_event_source_remove(server.hide_source); + server.hide_source = NULL; } - wlr_cursor_unset_image(cursor); + wlr_cursor_unset_image(server.cursor); - wlr_cursor_set_surface(cursor, NULL, 0, 0); + wlr_cursor_set_surface(server.cursor, NULL, 0, 0); - if (cursor_mgr) { - wlr_xcursor_manager_destroy(cursor_mgr); - cursor_mgr = NULL; + if (server.cursor_mgr) { + wlr_xcursor_manager_destroy(server.cursor_mgr); + server.cursor_mgr = NULL; } - cursor_mgr = wlr_xcursor_manager_create(config.cursor_theme, cursor_size); + server.cursor_mgr = + wlr_xcursor_manager_create(config.cursor_theme, cursor_size); Monitor *m = NULL; - wl_list_for_each(m, &mons, link) { - wlr_xcursor_manager_load(cursor_mgr, m->wlr_output->scale); + wl_list_for_each(m, &server.mons, link) { + wlr_xcursor_manager_load(server.cursor_mgr, m->wlr_output->scale); } - wlr_cursor_set_xcursor(cursor, cursor_mgr, "left_ptr"); + wlr_cursor_set_xcursor(server.cursor, server.cursor_mgr, "left_ptr"); - hide_source = wl_event_loop_add_timer(wl_display_get_event_loop(dpy), - hidecursor, cursor); - if (cursor_hidden) { - wlr_cursor_unset_image(cursor); + server.hide_source = wl_event_loop_add_timer( + wl_display_get_event_loop(server.dpy), hidecursor, server.cursor); + if (server.cursor_hidden) { + wlr_cursor_unset_image(server.cursor); } else { - wl_event_source_timer_update(hide_source, cursor_hide_timeout * 1000); + wl_event_source_timer_update(server.hide_source, + cursor_hide_timeout * 1000); } } @@ -3601,7 +3605,7 @@ void reapply_border(void) { Client *c = NULL; // reset border width when config change - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (c && !c->iskilling) { if (!c->isnoborder && !c->isfullscreen) { c->bw = borderpx; @@ -3612,7 +3616,7 @@ void reapply_border(void) { void reapply_keyboard(void) { InputDevice *id; - wl_list_for_each(id, &inputdevices, link) { + wl_list_for_each(id, &server.inputdevices, link) { if (id->wlr_device->type != WLR_INPUT_DEVICE_KEYBOARD) { continue; } @@ -3624,7 +3628,7 @@ void reapply_keyboard(void) { void reapply_pointer(void) { InputDevice *id; struct libinput_device *device; - wl_list_for_each(id, &inputdevices, link) { + wl_list_for_each(id, &server.inputdevices, link) { if (id->wlr_device->type != WLR_INPUT_DEVICE_POINTER) { continue; @@ -3642,7 +3646,7 @@ void reapply_master(void) { int32_t i; Monitor *m = NULL; for (i = 0; i <= LENGTH(tags); i++) { - wl_list_for_each(m, &mons, link) { + wl_list_for_each(m, &server.mons, link) { if (!m->wlr_output->enabled) { continue; } @@ -3693,7 +3697,7 @@ void parse_tagrule(Monitor *m) { } for (i = 1; i <= LENGTH(tags); i++) { - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if ((c->tags & (1 << (i - 1)) & TAGMASK) && ISTILED(c)) { if (m->pertag->mfacts[i] > 0.0f) c->master_mfact_per = m->pertag->mfacts[i]; @@ -3704,7 +3708,7 @@ void parse_tagrule(Monitor *m) { void reapply_tagrule(void) { Monitor *m = NULL; - wl_list_for_each(m, &mons, link) { + wl_list_for_each(m, &server.mons, link) { if (!m->wlr_output->enabled) { continue; } @@ -3729,7 +3733,7 @@ void reset_option(void) { reapply_tagrule(); reapply_monitor_rules(); - arrange(selmon, false, false); + arrange(server.selmon, false, false); } int32_t reload_config(const Arg *arg) { diff --git a/src/dispatch/bind_define.h b/src/dispatch/bind_define.h index fbf1cd3..8818baa 100644 --- a/src/dispatch/bind_define.h +++ b/src/dispatch/bind_define.h @@ -2,22 +2,22 @@ int32_t bind_to_view(const Arg *arg) { uint32_t target = arg->ui; - if (view_current_to_back && selmon->pertag->curtag && - (target & TAGMASK) == (selmon->tagset[selmon->seltags])) { - if (selmon->pertag->prevtag) - target = 1 << (selmon->pertag->prevtag - 1); + if (view_current_to_back && server.selmon->pertag->curtag && + (target & TAGMASK) == (server.selmon->tagset[server.selmon->seltags])) { + if (server.selmon->pertag->prevtag) + target = 1 << (server.selmon->pertag->prevtag - 1); else target = 0; } if (!view_current_to_back && - (target & TAGMASK) == (selmon->tagset[selmon->seltags])) { + (target & TAGMASK) == (server.selmon->tagset[server.selmon->seltags])) { return 0; } - if ((int32_t)target == INT_MIN && selmon->pertag->curtag == 0) { - if (view_current_to_back && selmon->pertag->prevtag) - target = 1 << (selmon->pertag->prevtag - 1); + if ((int32_t)target == INT_MIN && server.selmon->pertag->curtag == 0) { + if (view_current_to_back && server.selmon->pertag->prevtag) + target = 1 << (server.selmon->pertag->prevtag - 1); else target = 0; } @@ -34,37 +34,38 @@ int32_t chvt(const Arg *arg) { struct timespec ts; // prevent the animation to rquest the new frame - allow_frame_scheduling = false; + server.allow_frame_scheduling = false; // backup current tag and monitor name - if (selmon) { - chvt_backup_tag = selmon->pertag->curtag; - strncpy(chvt_backup_selmon, selmon->wlr_output->name, - sizeof(chvt_backup_selmon) - 1); + if (server.selmon) { + server.chvt_backup_tag = server.selmon->pertag->curtag; + strncpy(server.chvt_backup_selmon, server.selmon->wlr_output->name, + sizeof(server.chvt_backup_selmon) - 1); } - wlr_session_change_vt(session, arg->ui); + wlr_session_change_vt(server.session, arg->ui); - // wait for DRM device to stabilize and ensure the session state is inactive + // wait for DRM device to stabilize and ensure the server.session state is + // inactive ts.tv_sec = 0; ts.tv_nsec = 100000000; // 200ms nanosleep(&ts, NULL); // allow frame scheduling, - // because session state is now inactive, rendermon will not enter - allow_frame_scheduling = true; + // because server.session state is now inactive, rendermon will not enter + server.allow_frame_scheduling = true; return 1; } int32_t create_virtual_output(const Arg *arg) { - if (!wlr_backend_is_multi(backend)) { - wlr_log(WLR_ERROR, "Expected a multi backend"); + if (!wlr_backend_is_multi(server.backend)) { + wlr_log(WLR_ERROR, "Expected a multi server.backend"); return 0; } bool done = false; - wlr_multi_for_each_backend(backend, create_output, &done); + wlr_multi_for_each_backend(server.backend, create_output, &done); if (!done) { wlr_log(WLR_ERROR, "Failed to create virtual output"); @@ -77,16 +78,16 @@ int32_t create_virtual_output(const Arg *arg) { int32_t destroy_all_virtual_output(const Arg *arg) { - if (!wlr_backend_is_multi(backend)) { - wlr_log(WLR_ERROR, "Expected a multi backend"); + if (!wlr_backend_is_multi(server.backend)) { + wlr_log(WLR_ERROR, "Expected a multi server.backend"); return 0; } Monitor *m, *tmp; - wl_list_for_each_safe(m, tmp, &mons, link) { + wl_list_for_each_safe(m, tmp, &server.mons, link) { if (wlr_output_is_headless(m->wlr_output)) { - // if(selmon == m) - // selmon = NULL; + // if(server.selmon == m) + // server.selmon = NULL; wlr_output_destroy(m->wlr_output); wlr_log(WLR_INFO, "Virtual output destroyed"); } @@ -100,7 +101,7 @@ int32_t defaultgaps(const Arg *arg) { } int32_t exchange_client(const Arg *arg) { - Client *c = selmon->sel; + Client *c = server.selmon->sel; if (!c || c->isfloating) return 0; @@ -112,7 +113,7 @@ int32_t exchange_client(const Arg *arg) { } int32_t exchange_stack_client(const Arg *arg) { - Client *c = selmon->sel; + Client *c = server.selmon->sel; Client *tc = NULL; if (!c || c->isfloating || c->isfullscreen || c->ismaximizescreen) return 0; @@ -154,18 +155,18 @@ int32_t focuslast(const Arg *arg) { bool begin = false; uint32_t target = 0; - wl_list_for_each(c, &fstack, flink) { + wl_list_for_each(c, &server.fstack, flink) { if (c->iskilling || c->isminimized || c->isunglobal || !client_surface(c)->mapped || client_is_unmanaged(c) || client_is_x11_popup(c)) continue; - if (selmon && !selmon->sel) { + if (server.selmon && !server.selmon->sel) { tc = c; break; } - if (selmon && c == selmon->sel && !begin) { + if (server.selmon && c == server.selmon->sel && !begin) { begin = true; continue; } @@ -200,7 +201,7 @@ int32_t focusmon(const Arg *arg) { if (arg->i != UNDIR) { tm = dirtomon(arg->i); } else if (arg->v) { - wl_list_for_each(m, &mons, link) { + wl_list_for_each(m, &server.mons, link) { if (!m->wlr_output->enabled) { continue; } @@ -213,18 +214,18 @@ int32_t focusmon(const Arg *arg) { return 0; } - if (!tm || !tm->wlr_output->enabled || tm == selmon) + if (!tm || !tm->wlr_output->enabled || tm == server.selmon) return 0; - selmon = tm; + server.selmon = tm; if (warpcursor) { - warp_cursor_to_selmon(selmon); + warp_cursor_to_selmon(server.selmon); } - c = focustop(selmon); + c = focustop(server.selmon); if (!c) { - selmon->sel = NULL; - wlr_seat_pointer_notify_clear_focus(seat); - wlr_seat_keyboard_notify_clear_focus(seat); + server.selmon->sel = NULL; + wlr_seat_pointer_notify_clear_focus(server.seat); + wlr_seat_keyboard_notify_clear_focus(server.seat); focusclient(NULL, 0); } else focusclient(c, 1); @@ -233,8 +234,8 @@ int32_t focusmon(const Arg *arg) { } int32_t focusstack(const Arg *arg) { - /* Focus the next or previous client (in tiling order) on selmon */ - Client *sel = focustop(selmon); + /* Focus the next or previous client (in tiling order) on server.selmon */ + Client *sel = focustop(server.selmon); Client *tc = NULL; if (!sel) @@ -244,7 +245,7 @@ int32_t focusstack(const Arg *arg) { } else { tc = get_next_stack_client(sel, true); } - /* If only one client is visible on selmon, then c == sel */ + /* If only one client is visible on server.selmon , then c == sel */ if (!tc) return 0; @@ -256,53 +257,54 @@ int32_t focusstack(const Arg *arg) { } int32_t incnmaster(const Arg *arg) { - if (!arg || !selmon) + if (!arg || !server.selmon) return 0; - selmon->pertag->nmasters[selmon->pertag->curtag] = - MAX(selmon->pertag->nmasters[selmon->pertag->curtag] + arg->i, 0); - arrange(selmon, false, false); + server.selmon->pertag->nmasters[server.selmon->pertag->curtag] = MAX( + server.selmon->pertag->nmasters[server.selmon->pertag->curtag] + arg->i, + 0); + arrange(server.selmon, false, false); return 0; } int32_t incgaps(const Arg *arg) { - setgaps(selmon->gappoh + arg->i, selmon->gappov + arg->i, - selmon->gappih + arg->i, selmon->gappiv + arg->i); + setgaps(server.selmon->gappoh + arg->i, server.selmon->gappov + arg->i, + server.selmon->gappih + arg->i, server.selmon->gappiv + arg->i); return 0; } int32_t incigaps(const Arg *arg) { - setgaps(selmon->gappoh, selmon->gappov, selmon->gappih + arg->i, - selmon->gappiv + arg->i); + setgaps(server.selmon->gappoh, server.selmon->gappov, + server.selmon->gappih + arg->i, server.selmon->gappiv + arg->i); return 0; } int32_t incogaps(const Arg *arg) { - setgaps(selmon->gappoh + arg->i, selmon->gappov + arg->i, selmon->gappih, - selmon->gappiv); + setgaps(server.selmon->gappoh + arg->i, server.selmon->gappov + arg->i, + server.selmon->gappih, server.selmon->gappiv); return 0; } int32_t incihgaps(const Arg *arg) { - setgaps(selmon->gappoh, selmon->gappov, selmon->gappih + arg->i, - selmon->gappiv); + setgaps(server.selmon->gappoh, server.selmon->gappov, + server.selmon->gappih + arg->i, server.selmon->gappiv); return 0; } int32_t incivgaps(const Arg *arg) { - setgaps(selmon->gappoh, selmon->gappov, selmon->gappih, - selmon->gappiv + arg->i); + setgaps(server.selmon->gappoh, server.selmon->gappov, server.selmon->gappih, + server.selmon->gappiv + arg->i); return 0; } int32_t incohgaps(const Arg *arg) { - setgaps(selmon->gappoh + arg->i, selmon->gappov, selmon->gappih, - selmon->gappiv); + setgaps(server.selmon->gappoh + arg->i, server.selmon->gappov, + server.selmon->gappih, server.selmon->gappiv); return 0; } int32_t incovgaps(const Arg *arg) { - setgaps(selmon->gappoh, selmon->gappov + arg->i, selmon->gappih, - selmon->gappiv); + setgaps(server.selmon->gappoh, server.selmon->gappov + arg->i, + server.selmon->gappih, server.selmon->gappiv); return 0; } @@ -310,27 +312,29 @@ int32_t setmfact(const Arg *arg) { float f; Client *c = NULL; - if (!arg || !selmon || - !selmon->pertag->ltidxs[selmon->pertag->curtag]->arrange) + if (!arg || !server.selmon || + !server.selmon->pertag->ltidxs[server.selmon->pertag->curtag]->arrange) return 0; - f = arg->f < 1.0 ? arg->f + selmon->pertag->mfacts[selmon->pertag->curtag] - : arg->f - 1.0; + f = arg->f < 1.0 + ? arg->f + + server.selmon->pertag->mfacts[server.selmon->pertag->curtag] + : arg->f - 1.0; if (f < 0.1 || f > 0.9) return 0; - selmon->pertag->mfacts[selmon->pertag->curtag] = f; - wl_list_for_each(c, &clients, link) { - if (VISIBLEON(c, selmon) && ISTILED(c)) { + server.selmon->pertag->mfacts[server.selmon->pertag->curtag] = f; + wl_list_for_each(c, &server.clients, link) { + if (VISIBLEON(c, server.selmon) && ISTILED(c)) { c->master_mfact_per = f; } } - arrange(selmon, false, false); + arrange(server.selmon, false, false); return 0; } int32_t killclient(const Arg *arg) { Client *c = NULL; - c = selmon->sel; + c = server.selmon->sel; if (c) { pending_kill_client(c); } @@ -341,56 +345,66 @@ int32_t moveresize(const Arg *arg) { const char *cursors[] = {"nw-resize", "ne-resize", "sw-resize", "se-resize"}; - if (cursor_mode != CurNormal && cursor_mode != CurPressed) + if (server.cursor_mode != CurNormal && server.cursor_mode != CurPressed) return 0; - xytonode(cursor->x, cursor->y, NULL, &grabc, NULL, NULL, NULL); - if (!grabc || client_is_unmanaged(grabc) || grabc->isfullscreen || - grabc->ismaximizescreen) { - grabc = NULL; + xytonode(server.cursor->x, server.cursor->y, NULL, &server.grabc, NULL, + NULL, NULL); + if (!server.grabc || client_is_unmanaged(server.grabc) || + server.grabc->isfullscreen || server.grabc->ismaximizescreen) { + server.grabc = NULL; return 0; } /* Float the window and tell motionnotify to grab it */ - if (grabc->isfloating == 0 && arg->ui == CurMove) { - grabc->drag_to_tile = true; - setfloating(grabc, 1); + if (server.grabc->isfloating == 0 && arg->ui == CurMove) { + server.grabc->drag_to_tile = true; + setfloating(server.grabc, 1); } - switch (cursor_mode = arg->ui) { + switch (server.cursor_mode = arg->ui) { case CurMove: - grabcx = cursor->x - grabc->geom.x; - grabcy = cursor->y - grabc->geom.y; - wlr_cursor_set_xcursor(cursor, cursor_mgr, "grab"); + server.grabcx = server.cursor->x - server.grabc->geom.x; + server.grabcy = server.cursor->y - server.grabc->geom.y; + wlr_cursor_set_xcursor(server.cursor, server.cursor_mgr, "grab"); break; case CurResize: /* Doesn't work for X11 output - the next absolute motion event - * returns the cursor to where it started */ - if (grabc->isfloating) { - rzcorner = drag_corner; - grabcx = (int)round(cursor->x); - grabcy = (int)round(cursor->y); - if (rzcorner == 4) + * returns the server.cursor to where it started */ + if (server.grabc->isfloating) { + server.rzcorner = drag_corner; + server.grabcx = (int)round(server.cursor->x); + server.grabcy = (int)round(server.cursor->y); + if (server.rzcorner == 4) /* identify the closest corner index */ - rzcorner = (grabcx - grabc->geom.x < - grabc->geom.x + grabc->geom.width - grabcx - ? 0 - : 1) + - (grabcy - grabc->geom.y < - grabc->geom.y + grabc->geom.height - grabcy - ? 0 - : 2); + server.rzcorner = + (server.grabcx - server.grabc->geom.x < + server.grabc->geom.x + server.grabc->geom.width - + server.grabcx + ? 0 + : 1) + + (server.grabcy - server.grabc->geom.y < + server.grabc->geom.y + server.grabc->geom.height - + server.grabcy + ? 0 + : 2); if (drag_warp_cursor) { - grabcx = rzcorner & 1 ? grabc->geom.x + grabc->geom.width - : grabc->geom.x; - grabcy = rzcorner & 2 ? grabc->geom.y + grabc->geom.height - : grabc->geom.y; - wlr_cursor_warp_closest(cursor, NULL, grabcx, grabcy); + server.grabcx = + server.rzcorner & 1 + ? server.grabc->geom.x + server.grabc->geom.width + : server.grabc->geom.x; + server.grabcy = + server.rzcorner & 2 + ? server.grabc->geom.y + server.grabc->geom.height + : server.grabc->geom.y; + wlr_cursor_warp_closest(server.cursor, NULL, server.grabcx, + server.grabcy); } - wlr_cursor_set_xcursor(cursor, cursor_mgr, cursors[rzcorner]); + wlr_cursor_set_xcursor(server.cursor, server.cursor_mgr, + cursors[server.rzcorner]); } else { - wlr_cursor_set_xcursor(cursor, cursor_mgr, "grab"); + wlr_cursor_set_xcursor(server.cursor, server.cursor_mgr, "grab"); } break; } @@ -399,7 +413,7 @@ int32_t moveresize(const Arg *arg) { int32_t movewin(const Arg *arg) { Client *c = NULL; - c = selmon->sel; + c = server.selmon->sel; if (!c || c->isfullscreen) return 0; if (!c->isfloating) @@ -436,13 +450,13 @@ int32_t movewin(const Arg *arg) { } int32_t quit(const Arg *arg) { - wl_display_terminate(dpy); + wl_display_terminate(server.dpy); return 0; } int32_t resizewin(const Arg *arg) { Client *c = NULL; - c = selmon->sel; + c = server.selmon->sel; int32_t offsetx = 0, offsety = 0; if (!c || c->isfullscreen || c->ismaximizescreen) @@ -515,20 +529,21 @@ int32_t resizewin(const Arg *arg) { int32_t restore_minimized(const Arg *arg) { Client *c = NULL; - if (selmon && selmon->isoverview) + if (server.selmon && server.selmon->isoverview) return 0; - if (selmon && selmon->sel && selmon->sel->is_in_scratchpad && - selmon->sel->is_scratchpad_show) { - selmon->sel->isminimized = 0; - selmon->sel->is_scratchpad_show = 0; - selmon->sel->is_in_scratchpad = 0; - selmon->sel->isnamedscratchpad = 0; - setborder_color(selmon->sel); + if (server.selmon && server.selmon->sel && + server.selmon->sel->is_in_scratchpad && + server.selmon->sel->is_scratchpad_show) { + server.selmon->sel->isminimized = 0; + server.selmon->sel->is_scratchpad_show = 0; + server.selmon->sel->is_in_scratchpad = 0; + server.selmon->sel->isnamedscratchpad = 0; + setborder_color(server.selmon->sel); return 0; } - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (c->isminimized && !c->isnamedscratchpad) { c->is_scratchpad_show = 0; c->is_in_scratchpad = 0; @@ -549,9 +564,10 @@ int32_t setlayout(const Arg *arg) { for (jk = 0; jk < LENGTH(layouts); jk++) { if (strcmp(layouts[jk].name, arg->v) == 0) { - selmon->pertag->ltidxs[selmon->pertag->curtag] = &layouts[jk]; - clear_fullscreen_and_maximized_state(selmon); - arrange(selmon, false, false); + server.selmon->pertag->ltidxs[server.selmon->pertag->curtag] = + &layouts[jk]; + clear_fullscreen_and_maximized_state(server.selmon); + arrange(server.selmon, false, false); printstatus(); return 0; } @@ -578,22 +594,22 @@ int32_t setkeymode(const Arg *arg) { int32_t set_proportion(const Arg *arg) { - if (selmon->isoverview || !is_scroller_layout(selmon)) + if (server.selmon->isoverview || !is_scroller_layout(server.selmon)) return 0; - if (selmon->visible_tiling_clients == 1 && + if (server.selmon->visible_tiling_clients == 1 && !scroller_ignore_proportion_single) return 0; - Client *tc = selmon->sel; + Client *tc = server.selmon->sel; if (tc) { tc = get_scroll_stack_head(tc); uint32_t max_client_width = - selmon->w.width - 2 * scroller_structs - gappih; + server.selmon->w.width - 2 * scroller_structs - gappih; tc->scroller_proportion = arg->f; tc->geom.width = max_client_width * arg->f; - arrange(selmon, false, false); + arrange(server.selmon, false, false); } return 0; } @@ -602,11 +618,11 @@ int32_t smartmovewin(const Arg *arg) { Client *c = NULL, *tc = NULL; int32_t nx, ny; int32_t buttom, top, left, right, tar; - c = selmon->sel; + c = server.selmon->sel; if (!c || c->isfullscreen) return 0; if (!c->isfloating) - setfloating(selmon->sel, true); + setfloating(server.selmon->sel, true); nx = c->geom.x; ny = c->geom.y; @@ -616,8 +632,8 @@ int32_t smartmovewin(const Arg *arg) { top = c->geom.y; ny -= c->mon->w.height / 4; - wl_list_for_each(tc, &clients, link) { - if (!VISIBLEON(tc, selmon) || !tc->isfloating || tc == c) + wl_list_for_each(tc, &server.clients, link) { + if (!VISIBLEON(tc, server.selmon) || !tc->isfloating || tc == c) continue; if (c->geom.x + c->geom.width < tc->geom.x || c->geom.x > tc->geom.x + tc->geom.width) @@ -636,8 +652,8 @@ int32_t smartmovewin(const Arg *arg) { buttom = c->geom.y + c->geom.height; ny += c->mon->w.height / 4; - wl_list_for_each(tc, &clients, link) { - if (!VISIBLEON(tc, selmon) || !tc->isfloating || tc == c) + wl_list_for_each(tc, &server.clients, link) { + if (!VISIBLEON(tc, server.selmon) || !tc->isfloating || tc == c) continue; if (c->geom.x + c->geom.width < tc->geom.x || c->geom.x > tc->geom.x + tc->geom.width) @@ -656,8 +672,8 @@ int32_t smartmovewin(const Arg *arg) { left = c->geom.x; nx -= c->mon->w.width / 6; - wl_list_for_each(tc, &clients, link) { - if (!VISIBLEON(tc, selmon) || !tc->isfloating || tc == c) + wl_list_for_each(tc, &server.clients, link) { + if (!VISIBLEON(tc, server.selmon) || !tc->isfloating || tc == c) continue; if (c->geom.y + c->geom.height < tc->geom.y || c->geom.y > tc->geom.y + tc->geom.height) @@ -675,8 +691,8 @@ int32_t smartmovewin(const Arg *arg) { tar = 99999; right = c->geom.x + c->geom.width; nx += c->mon->w.width / 6; - wl_list_for_each(tc, &clients, link) { - if (!VISIBLEON(tc, selmon) || !tc->isfloating || tc == c) + wl_list_for_each(tc, &server.clients, link) { + if (!VISIBLEON(tc, server.selmon) || !tc->isfloating || tc == c) continue; if (c->geom.y + c->geom.height < tc->geom.y || c->geom.y > tc->geom.y + tc->geom.height) @@ -703,7 +719,7 @@ int32_t smartresizewin(const Arg *arg) { Client *c = NULL, *tc = NULL; int32_t nw, nh; int32_t buttom, top, left, right, tar; - c = selmon->sel; + c = server.selmon->sel; if (!c || c->isfullscreen) return 0; if (!c->isfloating) @@ -713,16 +729,16 @@ int32_t smartresizewin(const Arg *arg) { switch (arg->i) { case UP: - nh -= selmon->w.height / 8; - nh = MAX(nh, selmon->w.height / 10); + nh -= server.selmon->w.height / 8; + nh = MAX(nh, server.selmon->w.height / 10); break; case DOWN: tar = -99999; buttom = c->geom.y + c->geom.height; - nh += selmon->w.height / 8; + nh += server.selmon->w.height / 8; - wl_list_for_each(tc, &clients, link) { - if (!VISIBLEON(tc, selmon) || !tc->isfloating || tc == c) + wl_list_for_each(tc, &server.clients, link) { + if (!VISIBLEON(tc, server.selmon) || !tc->isfloating || tc == c) continue; if (c->geom.x + c->geom.width < tc->geom.x || c->geom.x > tc->geom.x + tc->geom.width) @@ -733,19 +749,21 @@ int32_t smartresizewin(const Arg *arg) { }; } nh = tar == -99999 ? nh : tar; - if (c->geom.y + nh + gappov > selmon->w.y + selmon->w.height) - nh = selmon->w.y + selmon->w.height - c->geom.y - gappov; + if (c->geom.y + nh + gappov > + server.selmon->w.y + server.selmon->w.height) + nh = server.selmon->w.y + server.selmon->w.height - c->geom.y - + gappov; break; case LEFT: - nw -= selmon->w.width / 16; - nw = MAX(nw, selmon->w.width / 10); + nw -= server.selmon->w.width / 16; + nw = MAX(nw, server.selmon->w.width / 10); break; case RIGHT: tar = 99999; right = c->geom.x + c->geom.width; - nw += selmon->w.width / 16; - wl_list_for_each(tc, &clients, link) { - if (!VISIBLEON(tc, selmon) || !tc->isfloating || tc == c) + nw += server.selmon->w.width / 16; + wl_list_for_each(tc, &server.clients, link) { + if (!VISIBLEON(tc, server.selmon) || !tc->isfloating || tc == c) continue; if (c->geom.y + c->geom.height < tc->geom.y || c->geom.y > tc->geom.y + tc->geom.height) @@ -757,8 +775,10 @@ int32_t smartresizewin(const Arg *arg) { } nw = tar == 99999 ? nw : tar; - if (c->geom.x + nw + gappoh > selmon->w.x + selmon->w.width) - nw = selmon->w.x + selmon->w.width - c->geom.x - gappoh; + if (c->geom.x + nw + gappoh > + server.selmon->w.x + server.selmon->w.width) + nw = server.selmon->w.x + server.selmon->w.width - c->geom.x - + gappoh; break; } @@ -771,7 +791,7 @@ int32_t smartresizewin(const Arg *arg) { int32_t centerwin(const Arg *arg) { Client *c = NULL; - c = selmon->sel; + c = server.selmon->sel; if (!c || c->isfullscreen || c->ismaximizescreen) return 0; @@ -783,19 +803,22 @@ int32_t centerwin(const Arg *arg) { return 0; } - if (!is_scroller_layout(selmon)) + if (!is_scroller_layout(server.selmon)) return 0; Client *stack_head = get_scroll_stack_head(c); - if (selmon->pertag->ltidxs[selmon->pertag->curtag]->id == SCROLLER) { + if (server.selmon->pertag->ltidxs[server.selmon->pertag->curtag]->id == + SCROLLER) { stack_head->geom.x = - selmon->w.x + (selmon->w.width - stack_head->geom.width) / 2; + server.selmon->w.x + + (server.selmon->w.width - stack_head->geom.width) / 2; } else { stack_head->geom.y = - selmon->w.y + (selmon->w.height - stack_head->geom.height) / 2; + server.selmon->w.y + + (server.selmon->w.height - stack_head->geom.height) / 2; } - arrange(selmon, false, false); + arrange(server.selmon, false, false); return 0; } @@ -870,8 +893,8 @@ int32_t spawn_on_empty(const Arg *arg) { bool is_empty = true; Client *c = NULL; - wl_list_for_each(c, &clients, link) { - if (arg->ui & c->tags && c->mon == selmon) { + wl_list_for_each(c, &server.clients, link) { + if (arg->ui & c->tags && c->mon == server.selmon) { is_empty = false; break; } @@ -887,12 +910,12 @@ int32_t spawn_on_empty(const Arg *arg) { } int32_t switch_keyboard_layout(const Arg *arg) { - if (!kb_group || !kb_group->wlr_group || !seat) { - wlr_log(WLR_ERROR, "Invalid keyboard group or seat"); + if (!server.kb_group || !server.kb_group->wlr_group || !server.seat) { + wlr_log(WLR_ERROR, "Invalid keyboard group or server.seat "); return 0; } - struct wlr_keyboard *keyboard = &kb_group->wlr_group->keyboard; + struct wlr_keyboard *keyboard = &server.kb_group->wlr_group->keyboard; if (!keyboard || !keyboard->keymap) { wlr_log(WLR_ERROR, "Invalid keyboard or keymap"); return 0; @@ -911,18 +934,19 @@ int32_t switch_keyboard_layout(const Arg *arg) { // 6. 应用新 keymap uint32_t depressed = keyboard->modifiers.depressed; uint32_t latched = keyboard->modifiers.latched; - uint32_t locked = keyboard->modifiers.locked; + // uint32_t locked = keyboard->modifiers.locked; wlr_keyboard_set_keymap(keyboard, keyboard->keymap); - wlr_keyboard_notify_modifiers(keyboard, depressed, latched, locked, next); + wlr_keyboard_notify_modifiers(keyboard, depressed, latched, server.locked, + next); keyboard->modifiers.group = 0; - // 7. 更新 seat - wlr_seat_set_keyboard(seat, keyboard); - wlr_seat_keyboard_notify_modifiers(seat, &keyboard->modifiers); + // 7. 更新 server.seat + wlr_seat_set_keyboard(server.seat, keyboard); + wlr_seat_keyboard_notify_modifiers(server.seat, &keyboard->modifiers); InputDevice *id; - wl_list_for_each(id, &inputdevices, link) { + wl_list_for_each(id, &server.inputdevices, link) { if (id->wlr_device->type != WLR_INPUT_DEVICE_KEYBOARD) { continue; } @@ -930,12 +954,13 @@ int32_t switch_keyboard_layout(const Arg *arg) { struct wlr_keyboard *tkb = (struct wlr_keyboard *)id->device_data; wlr_keyboard_set_keymap(tkb, keyboard->keymap); - wlr_keyboard_notify_modifiers(tkb, depressed, latched, locked, next); + wlr_keyboard_notify_modifiers(tkb, depressed, latched, server.locked, + next); tkb->modifiers.group = 0; - // 7. 更新 seat - wlr_seat_set_keyboard(seat, tkb); - wlr_seat_keyboard_notify_modifiers(seat, &tkb->modifiers); + // 7. 更新 server.seat + wlr_seat_set_keyboard(server.seat, tkb); + wlr_seat_keyboard_notify_modifiers(server.seat, &tkb->modifiers); } printstatus(); @@ -951,13 +976,16 @@ int32_t switch_layout(const Arg *arg) { if (config.circle_layout_count != 0) { for (jk = 0; jk < config.circle_layout_count; jk++) { - len = MAX( - strlen(config.circle_layout[jk]), - strlen(selmon->pertag->ltidxs[selmon->pertag->curtag]->name)); + len = MAX(strlen(config.circle_layout[jk]), + strlen(server.selmon->pertag + ->ltidxs[server.selmon->pertag->curtag] + ->name)); - if (strncmp(config.circle_layout[jk], - selmon->pertag->ltidxs[selmon->pertag->curtag]->name, - len) == 0) { + if (strncmp( + config.circle_layout[jk], + server.selmon->pertag->ltidxs[server.selmon->pertag->curtag] + ->name, + len) == 0) { target_layout_name = jk == config.circle_layout_count - 1 ? config.circle_layout[0] : config.circle_layout[jk + 1]; @@ -972,24 +1000,26 @@ int32_t switch_layout(const Arg *arg) { for (ji = 0; ji < LENGTH(layouts); ji++) { len = MAX(strlen(layouts[ji].name), strlen(target_layout_name)); if (strncmp(layouts[ji].name, target_layout_name, len) == 0) { - selmon->pertag->ltidxs[selmon->pertag->curtag] = &layouts[ji]; + server.selmon->pertag->ltidxs[server.selmon->pertag->curtag] = + &layouts[ji]; break; } } - clear_fullscreen_and_maximized_state(selmon); - arrange(selmon, false, false); + clear_fullscreen_and_maximized_state(server.selmon); + arrange(server.selmon, false, false); printstatus(); return 0; } for (jk = 0; jk < LENGTH(layouts); jk++) { if (strcmp(layouts[jk].name, - selmon->pertag->ltidxs[selmon->pertag->curtag]->name) == 0) { - selmon->pertag->ltidxs[selmon->pertag->curtag] = + server.selmon->pertag->ltidxs[server.selmon->pertag->curtag] + ->name) == 0) { + server.selmon->pertag->ltidxs[server.selmon->pertag->curtag] = jk == LENGTH(layouts) - 1 ? &layouts[0] : &layouts[jk + 1]; - clear_fullscreen_and_maximized_state(selmon); - arrange(selmon, false, false); + clear_fullscreen_and_maximized_state(server.selmon); + arrange(server.selmon, false, false); printstatus(); return 0; } @@ -1004,14 +1034,14 @@ int32_t switch_proportion_preset(const Arg *arg) { return 0; } - if (selmon->isoverview || !is_scroller_layout(selmon)) + if (server.selmon->isoverview || !is_scroller_layout(server.selmon)) return 0; - if (selmon->visible_tiling_clients == 1 && + if (server.selmon->visible_tiling_clients == 1 && !scroller_ignore_proportion_single) return 0; - Client *tc = selmon->sel; + Client *tc = server.selmon->sel; if (tc) { tc = get_scroll_stack_head(tc); @@ -1034,23 +1064,23 @@ int32_t switch_proportion_preset(const Arg *arg) { } uint32_t max_client_width = - selmon->w.width - 2 * scroller_structs - gappih; + server.selmon->w.width - 2 * scroller_structs - gappih; tc->scroller_proportion = target_proportion; tc->geom.width = max_client_width * target_proportion; - arrange(selmon, false, false); + arrange(server.selmon, false, false); } return 0; } int32_t tag(const Arg *arg) { - Client *target_client = selmon->sel; + Client *target_client = server.selmon->sel; tag_client(arg, target_client); return 0; } int32_t tagmon(const Arg *arg) { Monitor *m = NULL, *cm = NULL; - Client *c = focustop(selmon); + Client *c = focustop(server.selmon); if (!c) return 0; @@ -1058,7 +1088,7 @@ int32_t tagmon(const Arg *arg) { if (arg->i != UNDIR) { m = dirtomon(arg->i); } else if (arg->v) { - wl_list_for_each(cm, &mons, link) { + wl_list_for_each(cm, &server.mons, link) { if (!cm->wlr_output->enabled) { continue; } @@ -1082,8 +1112,8 @@ int32_t tagmon(const Arg *arg) { return 0; } - if (c == selmon->sel) { - selmon->sel = NULL; + if (c == server.selmon->sel) { + server.selmon->sel = NULL; } setmon(c, m, newtags, true); @@ -1091,11 +1121,11 @@ int32_t tagmon(const Arg *arg) { reset_foreign_tolevel(c); - c->float_geom.width = - (int32_t)(c->float_geom.width * c->mon->w.width / selmon->w.width); - c->float_geom.height = - (int32_t)(c->float_geom.height * c->mon->w.height / selmon->w.height); - selmon = c->mon; + c->float_geom.width = (int32_t)(c->float_geom.width * c->mon->w.width / + server.selmon->w.width); + c->float_geom.height = (int32_t)(c->float_geom.height * c->mon->w.height / + server.selmon->w.height); + server.selmon = c->mon; c->float_geom = setclient_coordinate_center(c, c->mon, c->float_geom, 0, 0); // 重新计算居中的坐标 @@ -1107,11 +1137,11 @@ int32_t tagmon(const Arg *arg) { focusclient(c, 1); resize(c, c->geom, 1); } else { - selmon = c->mon; + server.selmon = c->mon; target = get_tags_first_tag(c->tags); view(&(Arg){.ui = target}, true); focusclient(c, 1); - arrange(selmon, false, false); + arrange(server.selmon, false, false); } if (warpcursor) { warp_cursor_to_selmon(c->mon); @@ -1123,37 +1153,41 @@ int32_t tagsilent(const Arg *arg) { Client *fc = NULL; Client *target_client = NULL; - if (!selmon || !selmon->sel) + if (!server.selmon || !server.selmon->sel) return 0; - target_client = selmon->sel; + target_client = server.selmon->sel; target_client->tags = arg->ui & TAGMASK; - wl_list_for_each(fc, &clients, link) { + wl_list_for_each(fc, &server.clients, link) { if (fc && fc != target_client && target_client->tags & fc->tags && ISFULLSCREEN(fc) && !target_client->isfloating) { clear_fullscreen_flag(fc); } } exit_scroller_stack(target_client); - focusclient(focustop(selmon), 1); + focusclient(focustop(server.selmon), 1); arrange(target_client->mon, false, false); return 0; } int32_t tagtoleft(const Arg *arg) { - if (selmon->sel != NULL && - __builtin_popcount(selmon->tagset[selmon->seltags] & TAGMASK) == 1 && - selmon->tagset[selmon->seltags] > 1) { - tag(&(Arg){.ui = selmon->tagset[selmon->seltags] >> 1, .i = arg->i}); + if (server.selmon->sel != NULL && + __builtin_popcount(server.selmon->tagset[server.selmon->seltags] & + TAGMASK) == 1 && + server.selmon->tagset[server.selmon->seltags] > 1) { + tag(&(Arg){.ui = server.selmon->tagset[server.selmon->seltags] >> 1, + .i = arg->i}); } return 0; } int32_t tagtoright(const Arg *arg) { - if (selmon->sel != NULL && - __builtin_popcount(selmon->tagset[selmon->seltags] & TAGMASK) == 1 && - selmon->tagset[selmon->seltags] & (TAGMASK >> 1)) { - tag(&(Arg){.ui = selmon->tagset[selmon->seltags] << 1, .i = arg->i}); + if (server.selmon->sel != NULL && + __builtin_popcount(server.selmon->tagset[server.selmon->seltags] & + TAGMASK) == 1 && + server.selmon->tagset[server.selmon->seltags] & (TAGMASK >> 1)) { + tag(&(Arg){.ui = server.selmon->tagset[server.selmon->seltags] << 1, + .i = arg->i}); } return 0; } @@ -1178,8 +1212,8 @@ int32_t toggle_named_scratchpad(const Arg *arg) { } int32_t toggle_render_border(const Arg *arg) { - render_border = !render_border; - arrange(selmon, false, false); + server.render_border = !server.render_border; + arrange(server.selmon, false, false); return 0; } @@ -1188,11 +1222,11 @@ int32_t toggle_scratchpad(const Arg *arg) { bool hit = false; Client *tmp = NULL; - if (selmon && selmon->isoverview) + if (server.selmon && server.selmon->isoverview) return 0; - wl_list_for_each_safe(c, tmp, &clients, link) { - if (!scratchpad_cross_monitor && c->mon != selmon) { + wl_list_for_each_safe(c, tmp, &server.clients, link) { + if (!scratchpad_cross_monitor && c->mon != server.selmon) { continue; } @@ -1213,16 +1247,16 @@ int32_t toggle_scratchpad(const Arg *arg) { } int32_t togglefakefullscreen(const Arg *arg) { - Client *sel = focustop(selmon); + Client *sel = focustop(server.selmon); if (sel) setfakefullscreen(sel, !sel->isfakefullscreen); return 0; } int32_t togglefloating(const Arg *arg) { - Client *sel = focustop(selmon); + Client *sel = focustop(server.selmon); - if (selmon && selmon->isoverview) + if (server.selmon && server.selmon->isoverview) return 0; if (!sel) @@ -1239,7 +1273,7 @@ int32_t togglefloating(const Arg *arg) { } int32_t togglefullscreen(const Arg *arg) { - Client *sel = focustop(selmon); + Client *sel = focustop(server.selmon); if (!sel) return 0; @@ -1255,31 +1289,31 @@ int32_t togglefullscreen(const Arg *arg) { } int32_t toggleglobal(const Arg *arg) { - if (!selmon->sel) + if (!server.selmon->sel) return 0; - if (selmon->sel->is_in_scratchpad) { - selmon->sel->is_in_scratchpad = 0; - selmon->sel->is_scratchpad_show = 0; - selmon->sel->isnamedscratchpad = 0; + if (server.selmon->sel->is_in_scratchpad) { + server.selmon->sel->is_in_scratchpad = 0; + server.selmon->sel->is_scratchpad_show = 0; + server.selmon->sel->isnamedscratchpad = 0; } - selmon->sel->isglobal ^= 1; - if (selmon->sel->isglobal && - (selmon->sel->prev_in_stack || selmon->sel->next_in_stack)) { - exit_scroller_stack(selmon->sel); - arrange(selmon, false, false); + server.selmon->sel->isglobal ^= 1; + if (server.selmon->sel->isglobal && (server.selmon->sel->prev_in_stack || + server.selmon->sel->next_in_stack)) { + exit_scroller_stack(server.selmon->sel); + arrange(server.selmon, false, false); } - setborder_color(selmon->sel); + setborder_color(server.selmon->sel); return 0; } int32_t togglegaps(const Arg *arg) { - enablegaps ^= 1; - arrange(selmon, false, false); + server.enablegaps ^= 1; + arrange(server.selmon, false, false); return 0; } int32_t togglemaximizescreen(const Arg *arg) { - Client *sel = focustop(selmon); + Client *sel = focustop(server.selmon); if (!sel) return 0; @@ -1297,29 +1331,33 @@ int32_t togglemaximizescreen(const Arg *arg) { } int32_t toggleoverlay(const Arg *arg) { - if (!selmon->sel || !selmon->sel->mon || selmon->sel->isfullscreen) { + if (!server.selmon->sel || !server.selmon->sel->mon || + server.selmon->sel->isfullscreen) { return 0; } - selmon->sel->isoverlay ^= 1; + server.selmon->sel->isoverlay ^= 1; - if (selmon->sel->isoverlay) { - wlr_scene_node_reparent(&selmon->sel->scene->node, layers[LyrOverlay]); - wlr_scene_node_raise_to_top(&selmon->sel->scene->node); - } else if (client_should_overtop(selmon->sel) && selmon->sel->isfloating) { - wlr_scene_node_reparent(&selmon->sel->scene->node, layers[LyrTop]); + if (server.selmon->sel->isoverlay) { + wlr_scene_node_reparent(&server.selmon->sel->scene->node, + server.layers[LyrOverlay]); + wlr_scene_node_raise_to_top(&server.selmon->sel->scene->node); + } else if (client_should_overtop(server.selmon->sel) && + server.selmon->sel->isfloating) { + wlr_scene_node_reparent(&server.selmon->sel->scene->node, + server.layers[LyrTop]); } else { wlr_scene_node_reparent( - &selmon->sel->scene->node, - layers[selmon->sel->isfloating ? LyrTop : LyrTile]); + &server.selmon->sel->scene->node, + server.layers[server.selmon->sel->isfloating ? LyrTop : LyrTile]); } - setborder_color(selmon->sel); + setborder_color(server.selmon->sel); return 0; } int32_t toggletag(const Arg *arg) { uint32_t newtags; - Client *sel = focustop(selmon); + Client *sel = focustop(server.selmon); if (!sel) return 0; @@ -1333,8 +1371,8 @@ int32_t toggletag(const Arg *arg) { if (newtags) { sel->tags = newtags; - focusclient(focustop(selmon), 1); - arrange(selmon, false, false); + focusclient(focustop(server.selmon), 1); + arrange(server.selmon, false, false); } printstatus(); return 0; @@ -1346,22 +1384,23 @@ int32_t toggleview(const Arg *arg) { target = arg->ui == 0 ? ~0 & TAGMASK : arg->ui; - newtagset = - selmon ? selmon->tagset[selmon->seltags] ^ (target & TAGMASK) : 0; + newtagset = server.selmon ? server.selmon->tagset[server.selmon->seltags] ^ + (target & TAGMASK) + : 0; if (newtagset) { - selmon->tagset[selmon->seltags] = newtagset; - focusclient(focustop(selmon), 1); - arrange(selmon, false, false); + server.selmon->tagset[server.selmon->seltags] = newtagset; + focusclient(focustop(server.selmon), 1); + arrange(server.selmon, false, false); } printstatus(); return 0; } int32_t viewtoleft(const Arg *arg) { - uint32_t target = selmon->tagset[selmon->seltags]; + uint32_t target = server.selmon->tagset[server.selmon->seltags]; - if (selmon->isoverview || selmon->pertag->curtag == 0) { + if (server.selmon->isoverview || server.selmon->pertag->curtag == 0) { return 0; } @@ -1371,7 +1410,8 @@ int32_t viewtoleft(const Arg *arg) { return 0; } - if (!selmon || (target) == selmon->tagset[selmon->seltags]) + if (!server.selmon || + (target) == server.selmon->tagset[server.selmon->seltags]) return 0; view(&(Arg){.ui = target & TAGMASK, .i = arg->i}, true); @@ -1379,13 +1419,14 @@ int32_t viewtoleft(const Arg *arg) { } int32_t viewtoright(const Arg *arg) { - if (selmon->isoverview || selmon->pertag->curtag == 0) { + if (server.selmon->isoverview || server.selmon->pertag->curtag == 0) { return 0; } - uint32_t target = selmon->tagset[selmon->seltags]; + uint32_t target = server.selmon->tagset[server.selmon->seltags]; target <<= 1; - if (!selmon || (target) == selmon->tagset[selmon->seltags]) + if (!server.selmon || + (target) == server.selmon->tagset[server.selmon->seltags]) return 0; if (!(target & TAGMASK)) { return 0; @@ -1397,10 +1438,11 @@ int32_t viewtoright(const Arg *arg) { int32_t viewtoleft_have_client(const Arg *arg) { uint32_t n; - uint32_t current = get_tags_first_tag_num(selmon->tagset[selmon->seltags]); + uint32_t current = + get_tags_first_tag_num(server.selmon->tagset[server.selmon->seltags]); bool found = false; - if (selmon->isoverview) { + if (server.selmon->isoverview) { return 0; } @@ -1408,7 +1450,7 @@ int32_t viewtoleft_have_client(const Arg *arg) { return 0; for (n = current - 1; n >= 1; n--) { - if (get_tag_status(n, selmon)) { + if (get_tag_status(n, server.selmon)) { found = true; break; } @@ -1421,10 +1463,11 @@ int32_t viewtoleft_have_client(const Arg *arg) { int32_t viewtoright_have_client(const Arg *arg) { uint32_t n; - uint32_t current = get_tags_first_tag_num(selmon->tagset[selmon->seltags]); + uint32_t current = + get_tags_first_tag_num(server.selmon->tagset[server.selmon->seltags]); bool found = false; - if (selmon->isoverview) { + if (server.selmon->isoverview) { return 0; } @@ -1432,7 +1475,7 @@ int32_t viewtoright_have_client(const Arg *arg) { return 0; for (n = current + 1; n <= LENGTH(tags); n++) { - if (get_tag_status(n, selmon)) { + if (get_tag_status(n, server.selmon)) { found = true; break; } @@ -1445,16 +1488,16 @@ int32_t viewtoright_have_client(const Arg *arg) { int32_t viewcrossmon(const Arg *arg) { focusmon(&(Arg){.v = arg->v, .i = UNDIR}); - view_in_mon(arg, true, selmon, true); + view_in_mon(arg, true, server.selmon, true); return 0; } int32_t tagcrossmon(const Arg *arg) { - if (!selmon || !selmon->sel) + if (!server.selmon || !server.selmon->sel) return 0; - if (regex_match(selmon->wlr_output->name, arg->v)) { - tag_client(arg, selmon->sel); + if (regex_match(server.selmon->wlr_output->name, arg->v)) { + tag_client(arg, server.selmon->sel); return 0; } @@ -1465,15 +1508,15 @@ int32_t tagcrossmon(const Arg *arg) { int32_t comboview(const Arg *arg) { uint32_t newtags = arg->ui & TAGMASK; - if (!newtags || !selmon) + if (!newtags || !server.selmon) return 0; - if (tag_combo) { - selmon->tagset[selmon->seltags] |= newtags; - focusclient(focustop(selmon), 1); - arrange(selmon, false, false); + if (server.tag_combo) { + server.selmon->tagset[server.selmon->seltags] |= newtags; + focusclient(focustop(server.selmon), 1); + arrange(server.selmon, false, false); } else { - tag_combo = true; + server.tag_combo = true; view(&(Arg){.ui = newtags}, false); } @@ -1482,24 +1525,25 @@ int32_t comboview(const Arg *arg) { } int32_t zoom(const Arg *arg) { - Client *c = NULL, *sel = focustop(selmon); + Client *c = NULL, *sel = focustop(server.selmon); - if (!sel || !selmon || - !selmon->pertag->ltidxs[selmon->pertag->curtag]->arrange || + if (!sel || !server.selmon || + !server.selmon->pertag->ltidxs[server.selmon->pertag->curtag] + ->arrange || sel->isfloating) return 0; /* Search for the first tiled window that is not sel, marking sel as * NULL if we pass it along the way */ - wl_list_for_each(c, &clients, - link) if (VISIBLEON(c, selmon) && !c->isfloating) { + wl_list_for_each(c, &server.clients, + link) if (VISIBLEON(c, server.selmon) && !c->isfloating) { if (c != sel) break; sel = NULL; } /* Return if no other tiled window was found */ - if (&c->link == &clients) + if (&c->link == &server.clients) return 0; /* If we passed sel, move c to the front; otherwise, move sel to the @@ -1507,10 +1551,10 @@ int32_t zoom(const Arg *arg) { if (!sel) sel = c; wl_list_remove(&sel->link); - wl_list_insert(&clients, &sel->link); + wl_list_insert(&server.clients, &sel->link); focusclient(sel, 1); - arrange(selmon, false, false); + arrange(server.selmon, false, false); return 0; } @@ -1523,11 +1567,11 @@ int32_t setoption(const Arg *arg) { int32_t minimized(const Arg *arg) { - if (selmon && selmon->isoverview) + if (server.selmon && server.selmon->isoverview) return 0; - if (selmon->sel && !selmon->sel->isminimized) { - set_minimized(selmon->sel); + if (server.selmon->sel && !server.selmon->sel->isminimized) { + set_minimized(server.selmon->sel); } return 0; } @@ -1535,49 +1579,50 @@ int32_t minimized(const Arg *arg) { int32_t toggleoverview(const Arg *arg) { Client *c = NULL; - if (selmon->isoverview && ov_tab_mode && arg->i != 1 && selmon->sel) { + if (server.selmon->isoverview && ov_tab_mode && arg->i != 1 && + server.selmon->sel) { focusstack(&(Arg){.i = 1}); return 0; } - selmon->isoverview ^= 1; + server.selmon->isoverview ^= 1; uint32_t target; uint32_t visible_client_number = 0; - if (selmon->isoverview) { - wl_list_for_each(c, &clients, link) if (c && c->mon == selmon && - !client_is_unmanaged(c) && - !client_is_x11_popup(c) && - !c->isminimized && - !c->isunglobal) { + if (server.selmon->isoverview) { + wl_list_for_each(c, &server.clients, + link) if (c && c->mon == server.selmon && + !client_is_unmanaged(c) && + !client_is_x11_popup(c) && !c->isminimized && + !c->isunglobal) { visible_client_number++; } if (visible_client_number > 0) { target = ~0 & TAGMASK; } else { - selmon->isoverview ^= 1; + server.selmon->isoverview ^= 1; return 0; } - } else if (!selmon->isoverview && selmon->sel) { - target = get_tags_first_tag(selmon->sel->tags); - } else if (!selmon->isoverview && !selmon->sel) { - target = (1 << (selmon->pertag->prevtag - 1)); + } else if (!server.selmon->isoverview && server.selmon->sel) { + target = get_tags_first_tag(server.selmon->sel->tags); + } else if (!server.selmon->isoverview && !server.selmon->sel) { + target = (1 << (server.selmon->pertag->prevtag - 1)); view(&(Arg){.ui = target}, false); - refresh_monitors_workspaces_status(selmon); + refresh_monitors_workspaces_status(server.selmon); return 0; } // 正常视图到overview,退出所有窗口的浮动和全屏状态参与平铺, // overview到正常视图,还原之前退出的浮动和全屏窗口状态 - if (selmon->isoverview) { - wl_list_for_each(c, &clients, link) { - if (c && c->mon == selmon && !client_is_unmanaged(c) && + if (server.selmon->isoverview) { + wl_list_for_each(c, &server.clients, link) { + if (c && c->mon == server.selmon && !client_is_unmanaged(c) && !client_is_x11_popup(c) && !c->isunglobal) overview_backup(c); } } else { - wl_list_for_each(c, &clients, link) { - if (c && c->mon == selmon && !c->iskilling && + wl_list_for_each(c, &server.clients, link) { + if (c && c->mon == server.selmon && !c->iskilling && !client_is_unmanaged(c) && !c->isunglobal && !client_is_x11_popup(c) && client_surface(c)->mapped) overview_restore(c, &(Arg){.ui = target}); @@ -1586,14 +1631,14 @@ int32_t toggleoverview(const Arg *arg) { view(&(Arg){.ui = target}, false); - refresh_monitors_workspaces_status(selmon); + refresh_monitors_workspaces_status(server.selmon); return 0; } int32_t disable_monitor(const Arg *arg) { Monitor *m = NULL; struct wlr_output_state state = {0}; - wl_list_for_each(m, &mons, link) { + wl_list_for_each(m, &server.mons, link) { if (regex_match(arg->v, m->wlr_output->name)) { wlr_output_state_set_enabled(&state, false); wlr_output_commit_state(m->wlr_output, &state); @@ -1608,7 +1653,7 @@ int32_t disable_monitor(const Arg *arg) { int32_t enable_monitor(const Arg *arg) { Monitor *m = NULL; struct wlr_output_state state = {0}; - wl_list_for_each(m, &mons, link) { + wl_list_for_each(m, &server.mons, link) { if (regex_match(arg->v, m->wlr_output->name)) { wlr_output_state_set_enabled(&state, true); wlr_output_commit_state(m->wlr_output, &state); @@ -1623,7 +1668,7 @@ int32_t enable_monitor(const Arg *arg) { int32_t toggle_monitor(const Arg *arg) { Monitor *m = NULL; struct wlr_output_state state = {0}; - wl_list_for_each(m, &mons, link) { + wl_list_for_each(m, &server.mons, link) { if (regex_match(arg->v, m->wlr_output->name)) { wlr_output_state_set_enabled(&state, !m->wlr_output->enabled); wlr_output_commit_state(m->wlr_output, &state); @@ -1636,10 +1681,10 @@ int32_t toggle_monitor(const Arg *arg) { } int32_t scroller_stack(const Arg *arg) { - Client *c = selmon->sel; + Client *c = server.selmon->sel; Client *stack_head = NULL; Client *source_stack_head = NULL; - if (!c || !c->mon || c->isfloating || !is_scroller_layout(selmon)) + if (!c || !c->mon || c->isfloating || !is_scroller_layout(server.selmon)) return 0; if (c && (!client_only_in_one_tag(c) || c->isglobal || c->isunglobal)) @@ -1681,14 +1726,14 @@ int32_t scroller_stack(const Arg *arg) { exit_scroller_stack(c); wl_list_remove(&c->link); wl_list_insert(source_stack_head->link.prev, &c->link); - arrange(selmon, false, false); + arrange(server.selmon, false, false); } else if ((is_horizontal_layout && arg->i == RIGHT) || (!is_horizontal_layout && arg->i == DOWN)) { exit_scroller_stack(c); wl_list_remove(&c->link); wl_list_insert(&source_stack_head->link, &c->link); - arrange(selmon, false, false); + arrange(server.selmon, false, false); } return 0; } else if (c->next_in_stack) { @@ -1698,13 +1743,13 @@ int32_t scroller_stack(const Arg *arg) { exit_scroller_stack(c); wl_list_remove(&c->link); wl_list_insert(next_in_stack->link.prev, &c->link); - arrange(selmon, false, false); + arrange(server.selmon, false, false); } else if ((is_horizontal_layout && arg->i == RIGHT) || (!is_horizontal_layout && arg->i == DOWN)) { exit_scroller_stack(c); wl_list_remove(&c->link); wl_list_insert(&next_in_stack->link, &c->link); - arrange(selmon, false, false); + arrange(server.selmon, false, false); } return 0; } @@ -1734,6 +1779,6 @@ int32_t scroller_stack(const Arg *arg) { setfullscreen(stack_head, 0); } - arrange(selmon, false, false); + arrange(server.selmon, false, false); return 0; } \ No newline at end of file diff --git a/src/ext-protocol/dwl-ipc.h b/src/ext-protocol/dwl-ipc.h index ed93c95..a66f074 100644 --- a/src/ext-protocol/dwl-ipc.h +++ b/src/ext-protocol/dwl-ipc.h @@ -116,14 +116,15 @@ void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output) { const char *title, *appid, *symbol; char kb_layout[32]; focused = focustop(monitor); - zdwl_ipc_output_v2_send_active(ipc_output->resource, monitor == selmon); + zdwl_ipc_output_v2_send_active(ipc_output->resource, + monitor == server.selmon); for (tag = 0; tag < LENGTH(tags); tag++) { numclients = state = focused_client = 0; tagmask = 1 << tag; if ((tagmask & monitor->tagset[monitor->seltags]) != 0) state |= ZDWL_IPC_OUTPUT_V2_TAG_STATE_ACTIVE; - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (c->mon != monitor) continue; if (!(c->tags & tagmask)) @@ -147,7 +148,7 @@ void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output) { symbol = monitor->pertag->ltidxs[monitor->pertag->curtag]->symbol; } - keyboard = &kb_group->wlr_group->keyboard; + keyboard = &server.kb_group->wlr_group->keyboard; current = xkb_state_serialize_layout(keyboard->xkb_state, XKB_STATE_LAYOUT_EFFECTIVE); get_layout_abbr(kb_layout, @@ -202,7 +203,8 @@ void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output) { if (wl_resource_get_version(ipc_output->resource) >= ZDWL_IPC_OUTPUT_V2_KEYMODE_SINCE_VERSION) { - zdwl_ipc_output_v2_send_keymode(ipc_output->resource, server.keymode.name); + zdwl_ipc_output_v2_send_keymode(ipc_output->resource, + server.keymode.name); } if (wl_resource_get_version(ipc_output->resource) >= @@ -236,9 +238,9 @@ void dwl_ipc_output_set_client_tags(struct wl_client *client, return; selected_client->tags = newtags; - if (selmon == monitor) + if (server.selmon == monitor) focusclient(focustop(monitor), 1); - arrange(selmon, false, false); + arrange(server.selmon, false, false); printstatus(); } diff --git a/src/ext-protocol/ext-workspace.h b/src/ext-protocol/ext-workspace.h index 28aaeee..f9d8238 100644 --- a/src/ext-protocol/ext-workspace.h +++ b/src/ext-protocol/ext-workspace.h @@ -180,8 +180,8 @@ void refresh_monitors_workspaces_status(Monitor *m) { } void workspaces_init() { - /* Create the global workspace manager with activation capability */ - ext_manager = wlr_ext_workspace_manager_v1_create(dpy, 1); + /* Create the global workspace manager with server.activation capability */ + ext_manager = wlr_ext_workspace_manager_v1_create(server.dpy, 1); /* Initialize the global workspaces list */ wl_list_init(&workspaces); } \ No newline at end of file diff --git a/src/ext-protocol/tearing.h b/src/ext-protocol/tearing.h index 8e02656..296d489 100644 --- a/src/ext-protocol/tearing.h +++ b/src/ext-protocol/tearing.h @@ -64,7 +64,7 @@ bool check_tearing_frame_allow(Monitor *m) { return false; } - Client *c = selmon->sel; + Client *c = server.selmon->sel; /* tearing is only allowed for the output with the active client */ if (!c || c->mon != m) { diff --git a/src/ext-protocol/text-input.h b/src/ext-protocol/text-input.h index dbd97e1..0e53e47 100644 --- a/src/ext-protocol/text-input.h +++ b/src/ext-protocol/text-input.h @@ -69,7 +69,7 @@ void dwl_im_relay_set_focus(struct dwl_input_method_relay *relay, /*------------------协议内部代码------------------------------*/ Monitor *output_from_wlr_output(struct wlr_output *wlr_output) { Monitor *m = NULL; - wl_list_for_each(m, &mons, link) { + wl_list_for_each(m, &server.mons, link) { if (m->wlr_output == wlr_output) { return m; } @@ -79,11 +79,11 @@ Monitor *output_from_wlr_output(struct wlr_output *wlr_output) { Monitor *output_nearest_to(int32_t lx, int32_t ly) { double closest_x, closest_y; - wlr_output_layout_closest_point(output_layout, NULL, lx, ly, &closest_x, - &closest_y); + wlr_output_layout_closest_point(server.output_layout, NULL, lx, ly, + &closest_x, &closest_y); - return output_from_wlr_output( - wlr_output_layout_output_at(output_layout, closest_x, closest_y)); + return output_from_wlr_output(wlr_output_layout_output_at( + server.output_layout, closest_x, closest_y)); } bool output_is_usable(Monitor *m) { return m && m->wlr_output->enabled; } @@ -112,7 +112,7 @@ get_keyboard_grab(KeyboardGroup *keyboard) { } // kb_group是一个物理键盘组,它不应该被过滤掉 - if (keyboard != kb_group) + if (keyboard != server.kb_group) return NULL; if (is_keyboard_emulated_by_input_method(&keyboard->wlr_group->keyboard, @@ -259,7 +259,8 @@ static void update_popup_position(struct dwl_input_method_popup *popup) { if (!output_is_usable(output)) { return; } - wlr_output_layout_get_box(output_layout, output->wlr_output, &output_box); + wlr_output_layout_get_box(server.output_layout, output->wlr_output, + &output_box); pointer_rules = (struct wlr_xdg_positioner_rules){ .anchor_rect = cursor_rect, @@ -348,7 +349,7 @@ static void handle_input_method_grab_keyboard(struct wl_listener *listener, wl_container_of(listener, relay, input_method_grab_keyboard); struct wlr_input_method_keyboard_grab_v2 *keyboard_grab = data; - struct wlr_keyboard *active_keyboard = wlr_seat_get_keyboard(seat); + struct wlr_keyboard *active_keyboard = wlr_seat_get_keyboard(server.seat); if (!is_keyboard_emulated_by_input_method(active_keyboard, relay->input_method)) { @@ -411,7 +412,7 @@ static void handle_input_method_new_popup_surface(struct wl_listener *listener, wl_signal_add(&popup->popup_surface->surface->events.commit, &popup->commit); - popup->tree = wlr_scene_tree_create(layers[LyrIMPopup]); + popup->tree = wlr_scene_tree_create(server.layers[LyrIMPopup]); popup->scene_surface = wlr_scene_subsurface_tree_create( popup->tree, popup->popup_surface->surface); popup->scene_surface->node.data = popup; @@ -425,7 +426,7 @@ static void handle_new_input_method(struct wl_listener *listener, void *data) { struct dwl_input_method_relay *relay = wl_container_of(listener, relay, new_input_method); struct wlr_input_method_v2 *input_method = data; - if (seat != input_method->seat) { + if (server.seat != input_method->seat) { return; } @@ -531,7 +532,7 @@ static void handle_new_text_input(struct wl_listener *listener, void *data) { struct wlr_text_input_v3 *wlr_text_input = data; struct text_input *text_input = ecalloc(1, sizeof(struct text_input)); - if (seat != wlr_text_input->seat) { + if (server.seat != wlr_text_input->seat) { return; } @@ -568,7 +569,7 @@ struct dwl_input_method_relay *dwl_im_relay_create() { ecalloc(1, sizeof(struct dwl_input_method_relay)); wl_list_init(&relay->text_inputs); wl_list_init(&relay->popups); - relay->popup_tree = wlr_scene_tree_create(&scene->tree); + relay->popup_tree = wlr_scene_tree_create(&server.scene->tree); relay->new_text_input.notify = handle_new_text_input; wl_signal_add(&text_input_manager->events.text_input, diff --git a/src/fetch/client.h b/src/fetch/client.h index bf30e17..bfe9b46 100644 --- a/src/fetch/client.h +++ b/src/fetch/client.h @@ -1,7 +1,7 @@ bool check_hit_no_border(Client *c) { int32_t i; bool hit_no_border = false; - if (!render_border) { + if (!server.render_border) { hit_no_border = true; } @@ -25,7 +25,7 @@ Client *termforwin(Client *w) { if (!w->pid || w->isterm || w->noswallow) return NULL; - wl_list_for_each(c, &fstack, flink) { + wl_list_for_each(c, &server.fstack, flink) { if (c->isterm && !c->swallowing && c->pid && isdescprocess(c->pid, w->pid)) { return c; @@ -38,8 +38,8 @@ Client *get_client_by_id_or_title(const char *arg_id, const char *arg_title) { Client *target_client = NULL; const char *appid, *title; Client *c = NULL; - wl_list_for_each(c, &clients, link) { - if (!scratchpad_cross_monitor && c->mon != selmon) { + wl_list_for_each(c, &server.clients, link) { + if (!scratchpad_cross_monitor && c->mon != server.selmon) { continue; } @@ -81,7 +81,7 @@ setclient_coordinate_center(Client *c, Monitor *tm, struct wlr_box geom, struct wlr_box tempbox; int32_t offset = 0; int32_t len = 0; - Monitor *m = tm ? tm : selmon; + Monitor *m = tm ? tm : server.selmon; uint32_t cbw = check_hit_no_border(c) ? c->bw : 0; @@ -140,7 +140,7 @@ Client *center_tiled_select(Monitor *m) { int64_t mini_distance = -1; int32_t dirx, diry; int64_t distance; - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (c && VISIBLEON(c, m) && ISSCROLLTILED(c) && client_surface(c)->mapped && !c->isfloating && !client_is_unmanaged(c)) { @@ -162,7 +162,7 @@ Client *find_client_by_direction(Client *tc, const Arg *arg, bool findfloating, int32_t last = -1; // 第一次遍历,计算客户端数量 - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (c && (findfloating || !c->isfloating) && !c->isunglobal && (focus_cross_monitor || c->mon == tc->mon) && (c->tags & c->mon->tagset[c->mon->seltags])) { @@ -183,7 +183,7 @@ Client *find_client_by_direction(Client *tc, const Arg *arg, bool findfloating, // 第二次遍历,填充 tempClients last = -1; - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (c && (findfloating || !c->isfloating) && !c->isunglobal && (focus_cross_monitor || c->mon == tc->mon) && (c->tags & c->mon->tagset[c->mon->seltags])) { @@ -444,20 +444,20 @@ Client *find_client_by_direction(Client *tc, const Arg *arg, bool findfloating, Client *direction_select(const Arg *arg) { - Client *tc = selmon->sel; + Client *tc = server.selmon->sel; if (!tc) return NULL; if (tc && (tc->isfullscreen || tc->ismaximizescreen) && - (!is_scroller_layout(selmon) || tc->isfloating)) { + (!is_scroller_layout(server.selmon) || tc->isfloating)) { return NULL; } - return find_client_by_direction( - tc, arg, true, - (is_scroller_layout(selmon) || is_centertile_layout(selmon)) && - !selmon->isoverview); + return find_client_by_direction(tc, arg, true, + (is_scroller_layout(server.selmon) || + is_centertile_layout(server.selmon)) && + !server.selmon->isoverview); } /* We probably should change the name of this, it sounds like @@ -465,7 +465,7 @@ Client *direction_select(const Arg *arg) { * only return that client */ Client *focustop(Monitor *m) { Client *c = NULL; - wl_list_for_each(c, &fstack, flink) { + wl_list_for_each(c, &server.fstack, flink) { if (c->iskilling || c->isunglobal) continue; if (VISIBLEON(c, m)) @@ -481,7 +481,7 @@ Client *get_next_stack_client(Client *c, bool reverse) { Client *next = NULL; if (reverse) { wl_list_for_each_reverse(next, &c->link, link) { - if (&next->link == &clients) + if (&next->link == &server.clients) continue; /* wrap past the sentinel node */ if (next->isunglobal) @@ -492,7 +492,7 @@ Client *get_next_stack_client(Client *c, bool reverse) { } } else { wl_list_for_each(next, &c->link, link) { - if (&next->link == &clients) + if (&next->link == &server.clients) continue; /* wrap past the sentinel node */ if (next->isunglobal) @@ -507,19 +507,21 @@ Client *get_next_stack_client(Client *c, bool reverse) { float *get_border_color(Client *c) { - if (c->mon != selmon) { + if (c->mon != server.selmon) { return bordercolor; } else if (c->isurgent) { return urgentcolor; - } else if (c->is_in_scratchpad && selmon && c == selmon->sel) { + } else if (c->is_in_scratchpad && server.selmon && + c == server.selmon->sel) { return scratchpadcolor; - } else if (c->isglobal && selmon && c == selmon->sel) { + } else if (c->isglobal && server.selmon && c == server.selmon->sel) { return globalcolor; - } else if (c->isoverlay && selmon && c == selmon->sel) { + } else if (c->isoverlay && server.selmon && c == server.selmon->sel) { return overlaycolor; - } else if (c->ismaximizescreen && selmon && c == selmon->sel) { + } else if (c->ismaximizescreen && server.selmon && + c == server.selmon->sel) { return maximizescreencolor; - } else if (selmon && c == selmon->sel) { + } else if (server.selmon && c == server.selmon->sel) { return focuscolor; } else { return bordercolor; @@ -609,7 +611,7 @@ Client *get_focused_stack_client(Client *sc) { if (fc->isfloating || sc->isfloating) return sc; - wl_list_for_each(tc, &fstack, flink) { + wl_list_for_each(tc, &server.fstack, flink) { if (tc->iskilling || tc->isunglobal) continue; if (!VISIBLEON(tc, sc->mon)) diff --git a/src/fetch/common.h b/src/fetch/common.h index 58e69dc..724874f 100644 --- a/src/fetch/common.h +++ b/src/fetch/common.h @@ -90,7 +90,8 @@ void xytonode(double x, double y, struct wlr_surface **psurface, Client **pc, if (layer == LyrFadeOut) continue; - if (!(node = wlr_scene_node_at(&layers[layer]->node, x, y, nx, ny))) + if (!(node = + wlr_scene_node_at(&server.layers[layer]->node, x, y, nx, ny))) continue; if (!node->enabled) diff --git a/src/fetch/monitor.h b/src/fetch/monitor.h index 7a1ca4d..5c4ba8a 100644 --- a/src/fetch/monitor.h +++ b/src/fetch/monitor.h @@ -1,18 +1,19 @@ Monitor *dirtomon(enum wlr_direction dir) { struct wlr_output *next; - if (!wlr_output_layout_get(output_layout, selmon->wlr_output)) - return selmon; - if ((next = wlr_output_layout_adjacent_output(output_layout, 1 << dir, - selmon->wlr_output, - selmon->m.x, selmon->m.y))) + if (!wlr_output_layout_get(server.output_layout, server.selmon->wlr_output)) + return server.selmon; + if ((next = wlr_output_layout_adjacent_output( + server.output_layout, 1 << dir, server.selmon->wlr_output, + server.selmon->m.x, server.selmon->m.y))) return next->data; if ((next = wlr_output_layout_farthest_output( - output_layout, + server.output_layout, dir ^ (WLR_DIRECTION_LEFT | WLR_DIRECTION_RIGHT | WLR_DIRECTION_UP | WLR_DIRECTION_DOWN), - selmon->wlr_output, selmon->m.x, selmon->m.y))) + server.selmon->wlr_output, server.selmon->m.x, + server.selmon->m.y))) return next->data; - return selmon; + return server.selmon; } bool is_scroller_layout(Monitor *m) { @@ -37,7 +38,7 @@ bool is_centertile_layout(Monitor *m) { uint32_t get_tag_status(uint32_t tag, Monitor *m) { Client *c = NULL; uint32_t status = 0; - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (c->mon == m && c->tags & 1 << (tag - 1) & TAGMASK) { if (c->isurgent) { status = 2; @@ -54,7 +55,7 @@ uint32_t get_tags_first_tag_num(uint32_t source_tags) { tag = 0; if (!source_tags) { - return selmon->pertag->curtag; + return server.selmon->pertag->curtag; } for (i = 0; !(tag & 1) && source_tags != 0 && i < LENGTH(tags); i++) { @@ -76,7 +77,7 @@ uint32_t get_tags_first_tag(uint32_t source_tags) { tag = 0; if (!source_tags) { - return selmon->pertag->curtag; + return server.selmon->pertag->curtag; } for (i = 0; !(tag & 1) && source_tags != 0 && i < LENGTH(tags); i++) { @@ -93,6 +94,7 @@ uint32_t get_tags_first_tag(uint32_t source_tags) { } Monitor *xytomon(double x, double y) { - struct wlr_output *o = wlr_output_layout_output_at(output_layout, x, y); + struct wlr_output *o = + wlr_output_layout_output_at(server.output_layout, x, y); return o ? o->data : NULL; } diff --git a/src/layout/arrange.h b/src/layout/arrange.h index 3721364..5a8d318 100644 --- a/src/layout/arrange.h +++ b/src/layout/arrange.h @@ -5,7 +5,7 @@ void set_size_per(Monitor *m, Client *c) { if (!m || !c) return; - wl_list_for_each(fc, &clients, link) { + wl_list_for_each(fc, &server.clients, link) { if (VISIBLEON(fc, m) && ISTILED(fc) && fc != c) { c->master_mfact_per = fc->master_mfact_per; c->master_inner_per = fc->master_inner_per; @@ -22,7 +22,7 @@ void set_size_per(Monitor *m, Client *c) { } } -void resize_tile_master_horizontal(Client *grabc, bool isdrag, int32_t offsetx, +void resize_tile_master_horizontal(Client *rec, bool isdrag, int32_t offsetx, int32_t offsety, uint32_t time, int32_t type) { Client *tc = NULL; @@ -36,14 +36,16 @@ void resize_tile_master_horizontal(Client *grabc, bool isdrag, int32_t offsetx, bool begin_find_prevprev = false; // 从当前节点的下一个开始遍历 - for (node = grabc->link.next; node != &clients; node = node->next) { + for (node = rec->link.next; node != &server.clients; + node = node->next) { tc = wl_container_of(node, tc, link); - if (begin_find_nextnext && VISIBLEON(tc, grabc->mon) && ISTILED(tc)) { + if (begin_find_nextnext && VISIBLEON(tc, rec->mon) && + ISTILED(tc)) { nextnext = tc; break; } - if (!begin_find_nextnext && VISIBLEON(tc, grabc->mon) && + if (!begin_find_nextnext && VISIBLEON(tc, rec->mon) && ISTILED(tc)) { // 根据你的实际字段名调整 next = tc; begin_find_nextnext = true; @@ -52,15 +54,17 @@ void resize_tile_master_horizontal(Client *grabc, bool isdrag, int32_t offsetx, } // 从当前节点的上一个开始遍历 - for (node = grabc->link.prev; node != &clients; node = node->prev) { + for (node = rec->link.prev; node != &server.clients; + node = node->prev) { tc = wl_container_of(node, tc, link); - if (begin_find_prevprev && VISIBLEON(tc, grabc->mon) && ISTILED(tc)) { + if (begin_find_prevprev && VISIBLEON(tc, rec->mon) && + ISTILED(tc)) { prevprev = tc; break; } - if (!begin_find_prevprev && VISIBLEON(tc, grabc->mon) && + if (!begin_find_prevprev && VISIBLEON(tc, rec->mon) && ISTILED(tc)) { // 根据你的实际字段名调整 prev = tc; begin_find_prevprev = true; @@ -68,45 +72,48 @@ void resize_tile_master_horizontal(Client *grabc, bool isdrag, int32_t offsetx, } } - if (!start_drag_window && isdrag) { - drag_begin_cursorx = cursor->x; - drag_begin_cursory = cursor->y; - start_drag_window = true; + if (!server.start_drag_window && isdrag) { + server.drag_begin_cursorx = server.cursor->x; + server.drag_begin_cursory = server.cursor->y; + server.start_drag_window = true; // 记录初始状态 - grabc->old_master_mfact_per = grabc->master_mfact_per; - grabc->old_master_inner_per = grabc->master_inner_per; - grabc->old_stack_inner_per = grabc->stack_inner_per; - grabc->cursor_in_upper_half = - cursor->y < grabc->geom.y + grabc->geom.height / 2; - grabc->cursor_in_left_half = - cursor->x < grabc->geom.x + grabc->geom.width / 2; + rec->old_master_mfact_per = rec->master_mfact_per; + rec->old_master_inner_per = rec->master_inner_per; + rec->old_stack_inner_per = rec->stack_inner_per; + rec->cursor_in_upper_half = + server.cursor->y < + rec->geom.y + rec->geom.height / 2; + rec->cursor_in_left_half = + server.cursor->x < + rec->geom.x + rec->geom.width / 2; // 记录初始几何信息 - grabc->drag_begin_geom = grabc->geom; + rec->drag_begin_geom = rec->geom; } else { // 计算相对于屏幕尺寸的比例变化 if (isdrag) { - offsetx = cursor->x - drag_begin_cursorx; - offsety = cursor->y - drag_begin_cursory; + offsetx = server.cursor->x - server.drag_begin_cursorx; + offsety = server.cursor->y - server.drag_begin_cursory; } else { - grabc->old_master_mfact_per = grabc->master_mfact_per; - grabc->old_master_inner_per = grabc->master_inner_per; - grabc->old_stack_inner_per = grabc->stack_inner_per; - grabc->drag_begin_geom = grabc->geom; - grabc->cursor_in_upper_half = true; - grabc->cursor_in_left_half = false; + rec->old_master_mfact_per = rec->master_mfact_per; + rec->old_master_inner_per = rec->master_inner_per; + rec->old_stack_inner_per = rec->stack_inner_per; + rec->drag_begin_geom = rec->geom; + rec->cursor_in_upper_half = true; + rec->cursor_in_left_half = false; } - if (grabc->ismaster) { - delta_x = (float)(offsetx) * (grabc->old_master_mfact_per) / - grabc->drag_begin_geom.width; - delta_y = (float)(offsety) * (grabc->old_master_inner_per) / - grabc->drag_begin_geom.height; + if (rec->ismaster) { + delta_x = (float)(offsetx) * (rec->old_master_mfact_per) / + rec->drag_begin_geom.width; + delta_y = (float)(offsety) * (rec->old_master_inner_per) / + rec->drag_begin_geom.height; } else { - delta_x = (float)(offsetx) * (1 - grabc->old_master_mfact_per) / - grabc->drag_begin_geom.width; - delta_y = (float)(offsety) * (grabc->old_stack_inner_per) / - grabc->drag_begin_geom.height; + delta_x = (float)(offsetx) * + (1 - rec->old_master_mfact_per) / + rec->drag_begin_geom.width; + delta_y = (float)(offsety) * (rec->old_stack_inner_per) / + rec->drag_begin_geom.height; } bool moving_up; bool moving_down; @@ -115,49 +122,50 @@ void resize_tile_master_horizontal(Client *grabc, bool isdrag, int32_t offsetx, moving_up = offsety < 0 ? true : false; moving_down = offsety > 0 ? true : false; } else { - moving_up = cursor->y < drag_begin_cursory; - moving_down = cursor->y > drag_begin_cursory; + moving_up = server.cursor->y < server.drag_begin_cursory; + moving_down = server.cursor->y > server.drag_begin_cursory; } - if (grabc->ismaster && !prev) { + if (rec->ismaster && !prev) { if (moving_up) { delta_y = -fabsf(delta_y); } else { delta_y = fabsf(delta_y); } - } else if (grabc->ismaster && next && !next->ismaster) { + } else if (rec->ismaster && next && !next->ismaster) { if (moving_up) { delta_y = fabsf(delta_y); } else { delta_y = -fabsf(delta_y); } - } else if (!grabc->ismaster && prev && prev->ismaster) { + } else if (!rec->ismaster && prev && prev->ismaster) { if (moving_up) { delta_y = -fabsf(delta_y); } else { delta_y = fabsf(delta_y); } - } else if (!grabc->ismaster && !next) { + } else if (!rec->ismaster && !next) { if (moving_up) { delta_y = fabsf(delta_y); } else { delta_y = -fabsf(delta_y); } - } else if (type == CENTER_TILE && !grabc->ismaster && !nextnext) { + } else if (type == CENTER_TILE && !rec->ismaster && + !nextnext) { if (moving_up) { delta_y = fabsf(delta_y); } else { delta_y = -fabsf(delta_y); } - } else if (type == CENTER_TILE && !grabc->ismaster && prevprev && + } else if (type == CENTER_TILE && !rec->ismaster && prevprev && prevprev->ismaster) { if (moving_up) { delta_y = -fabsf(delta_y); } else { delta_y = fabsf(delta_y); } - } else if ((grabc->cursor_in_upper_half && moving_up) || - (!grabc->cursor_in_upper_half && moving_down)) { + } else if ((rec->cursor_in_upper_half && moving_up) || + (!rec->cursor_in_upper_half && moving_down)) { // 光标在窗口上方且向上移动,或在窗口下方且向下移动 → 增加高度 delta_y = fabsf(delta_y); delta_y = delta_y * 2; @@ -167,16 +175,17 @@ void resize_tile_master_horizontal(Client *grabc, bool isdrag, int32_t offsetx, delta_y = delta_y * 2; } - if (!grabc->ismaster && grabc->isleftstack && type == CENTER_TILE) { + if (!rec->ismaster && rec->isleftstack && + type == CENTER_TILE) { delta_x = delta_x * -1.0f; } - if (grabc->ismaster && type == CENTER_TILE && - grabc->cursor_in_left_half) { + if (rec->ismaster && type == CENTER_TILE && + rec->cursor_in_left_half) { delta_x = delta_x * -1.0f; } - if (grabc->ismaster && type == CENTER_TILE) { + if (rec->ismaster && type == CENTER_TILE) { delta_x = delta_x * 2; } @@ -185,9 +194,11 @@ void resize_tile_master_horizontal(Client *grabc, bool isdrag, int32_t offsetx, } // 直接设置新的比例,基于初始值 + 变化量 - float new_master_mfact_per = grabc->old_master_mfact_per + delta_x; - float new_master_inner_per = grabc->old_master_inner_per + delta_y; - float new_stack_inner_per = grabc->old_stack_inner_per + delta_y; + float new_master_mfact_per = + rec->old_master_mfact_per + delta_x; + float new_master_inner_per = + rec->old_master_inner_per + delta_y; + float new_stack_inner_per = rec->old_stack_inner_per + delta_y; // 应用限制,确保比例在合理范围内 new_master_mfact_per = fmaxf(0.1f, fminf(0.9f, new_master_mfact_per)); @@ -195,29 +206,29 @@ void resize_tile_master_horizontal(Client *grabc, bool isdrag, int32_t offsetx, new_stack_inner_per = fmaxf(0.1f, fminf(0.9f, new_stack_inner_per)); // 应用到所有平铺窗口 - wl_list_for_each(tc, &clients, link) { - if (VISIBLEON(tc, grabc->mon) && ISTILED(tc)) { + wl_list_for_each(tc, &server.clients, link) { + if (VISIBLEON(tc, rec->mon) && ISTILED(tc)) { tc->master_mfact_per = new_master_mfact_per; } } - grabc->master_inner_per = new_master_inner_per; - grabc->stack_inner_per = new_stack_inner_per; + rec->master_inner_per = new_master_inner_per; + rec->stack_inner_per = new_stack_inner_per; if (!isdrag) { - arrange(grabc->mon, false, false); + arrange(rec->mon, false, false); return; } - if (last_apply_drap_time == 0 || - time - last_apply_drap_time > drag_tile_refresh_interval) { - arrange(grabc->mon, false, false); - last_apply_drap_time = time; + if (server.last_apply_drag_time == 0 || + time - server.last_apply_drag_time > drag_tile_refresh_interval) { + arrange(rec->mon, false, false); + server.last_apply_drag_time = time; } } } -void resize_tile_master_vertical(Client *grabc, bool isdrag, int32_t offsetx, +void resize_tile_master_vertical(Client *rec, bool isdrag, int32_t offsetx, int32_t offsety, uint32_t time, int32_t type) { Client *tc = NULL; float delta_x, delta_y; @@ -226,10 +237,11 @@ void resize_tile_master_vertical(Client *grabc, bool isdrag, int32_t offsetx, struct wl_list *node; // 从当前节点的下一个开始遍历 - for (node = grabc->link.next; node != &clients; node = node->next) { + for (node = rec->link.next; node != &server.clients; + node = node->next) { tc = wl_container_of(node, tc, link); - if (VISIBLEON(tc, grabc->mon) && + if (VISIBLEON(tc, rec->mon) && ISTILED(tc)) { // 根据你的实际字段名调整 next = tc; break; @@ -237,58 +249,62 @@ void resize_tile_master_vertical(Client *grabc, bool isdrag, int32_t offsetx, } // 从当前节点的上一个开始遍历 - for (node = grabc->link.prev; node != &clients; node = node->prev) { + for (node = rec->link.prev; node != &server.clients; + node = node->prev) { tc = wl_container_of(node, tc, link); - if (VISIBLEON(tc, grabc->mon) && + if (VISIBLEON(tc, rec->mon) && ISTILED(tc)) { // 根据你的实际字段名调整 prev = tc; break; } } - if (!start_drag_window && isdrag) { - drag_begin_cursorx = cursor->x; - drag_begin_cursory = cursor->y; - start_drag_window = true; + if (!server.start_drag_window && isdrag) { + server.drag_begin_cursorx = server.cursor->x; + server.drag_begin_cursory = server.cursor->y; + server.start_drag_window = true; // 记录初始状态 - grabc->old_master_mfact_per = grabc->master_mfact_per; - grabc->old_master_inner_per = grabc->master_inner_per; - grabc->old_stack_inner_per = grabc->stack_inner_per; - grabc->cursor_in_upper_half = - cursor->y < grabc->geom.y + grabc->geom.height / 2; - grabc->cursor_in_left_half = - cursor->x < grabc->geom.x + grabc->geom.width / 2; + rec->old_master_mfact_per = rec->master_mfact_per; + rec->old_master_inner_per = rec->master_inner_per; + rec->old_stack_inner_per = rec->stack_inner_per; + rec->cursor_in_upper_half = + server.cursor->y < + rec->geom.y + rec->geom.height / 2; + rec->cursor_in_left_half = + server.cursor->x < + rec->geom.x + rec->geom.width / 2; // 记录初始几何信息 - grabc->drag_begin_geom = grabc->geom; + rec->drag_begin_geom = rec->geom; } else { // 计算相对于屏幕尺寸的比例变化 // 计算相对于屏幕尺寸的比例变化 if (isdrag) { - offsetx = cursor->x - drag_begin_cursorx; - offsety = cursor->y - drag_begin_cursory; + offsetx = server.cursor->x - server.drag_begin_cursorx; + offsety = server.cursor->y - server.drag_begin_cursory; } else { - grabc->old_master_mfact_per = grabc->master_mfact_per; - grabc->old_master_inner_per = grabc->master_inner_per; - grabc->old_stack_inner_per = grabc->stack_inner_per; - grabc->drag_begin_geom = grabc->geom; - grabc->cursor_in_upper_half = true; - grabc->cursor_in_left_half = false; + rec->old_master_mfact_per = rec->master_mfact_per; + rec->old_master_inner_per = rec->master_inner_per; + rec->old_stack_inner_per = rec->stack_inner_per; + rec->drag_begin_geom = rec->geom; + rec->cursor_in_upper_half = true; + rec->cursor_in_left_half = false; } - if (grabc->ismaster) { + if (rec->ismaster) { // 垂直版本:左右移动调整高度比例,上下移动调整宽度比例 - delta_x = (float)(offsetx) * (grabc->old_master_inner_per) / - grabc->drag_begin_geom.width; - delta_y = (float)(offsety) * (grabc->old_master_mfact_per) / - grabc->drag_begin_geom.height; + delta_x = (float)(offsetx) * (rec->old_master_inner_per) / + rec->drag_begin_geom.width; + delta_y = (float)(offsety) * (rec->old_master_mfact_per) / + rec->drag_begin_geom.height; } else { - delta_x = (float)(offsetx) * (grabc->old_stack_inner_per) / - grabc->drag_begin_geom.width; - delta_y = (float)(offsety) * (1 - grabc->old_master_mfact_per) / - grabc->drag_begin_geom.height; + delta_x = (float)(offsetx) * (rec->old_stack_inner_per) / + rec->drag_begin_geom.width; + delta_y = (float)(offsety) * + (1 - rec->old_master_mfact_per) / + rec->drag_begin_geom.height; } bool moving_left; @@ -298,37 +314,37 @@ void resize_tile_master_vertical(Client *grabc, bool isdrag, int32_t offsetx, moving_left = offsetx < 0 ? true : false; moving_right = offsetx > 0 ? true : false; } else { - moving_left = cursor->x < drag_begin_cursorx; - moving_right = cursor->x > drag_begin_cursorx; + moving_left = server.cursor->x < server.drag_begin_cursorx; + moving_right = server.cursor->x > server.drag_begin_cursorx; } // 调整主区域和栈区域的高度比例(垂直分割) - if (grabc->ismaster && !prev) { + if (rec->ismaster && !prev) { if (moving_left) { delta_x = -fabsf(delta_x); // 向上移动减少主区域高度 } else { delta_x = fabsf(delta_x); // 向下移动增加主区域高度 } - } else if (grabc->ismaster && next && !next->ismaster) { + } else if (rec->ismaster && next && !next->ismaster) { if (moving_left) { delta_x = fabsf(delta_x); // 向上移动增加主区域高度 } else { delta_x = -fabsf(delta_x); // 向下移动减少主区域高度 } - } else if (!grabc->ismaster && prev && prev->ismaster) { + } else if (!rec->ismaster && prev && prev->ismaster) { if (moving_left) { delta_x = -fabsf(delta_x); // 向上移动减少栈区域高度 } else { delta_x = fabsf(delta_x); // 向下移动增加栈区域高度 } - } else if (!grabc->ismaster && !next) { + } else if (!rec->ismaster && !next) { if (moving_left) { delta_x = fabsf(delta_x); // 向上移动增加栈区域高度 } else { delta_x = -fabsf(delta_x); // 向下移动减少栈区域高度 } - } else if ((grabc->cursor_in_left_half && moving_left) || - (!grabc->cursor_in_left_half && moving_right)) { + } else if ((rec->cursor_in_left_half && moving_left) || + (!rec->cursor_in_left_half && moving_right)) { // 光标在窗口左侧且向左移动,或在窗口右侧且向右移动 → 增加宽度 delta_x = fabsf(delta_x); delta_x = delta_x * 2; @@ -339,11 +355,11 @@ void resize_tile_master_vertical(Client *grabc, bool isdrag, int32_t offsetx, } // 直接设置新的比例,基于初始值 + 变化量 - float new_master_mfact_per = grabc->old_master_mfact_per + + float new_master_mfact_per = rec->old_master_mfact_per + delta_y; // 垂直:delta_y调整主区域高度 - float new_master_inner_per = grabc->old_master_inner_per + + float new_master_inner_per = rec->old_master_inner_per + delta_x; // 垂直:delta_x调整主区域内部宽度 - float new_stack_inner_per = grabc->old_stack_inner_per + + float new_stack_inner_per = rec->old_stack_inner_per + delta_x; // 垂直:delta_x调整栈区域内部宽度 // 应用限制,确保比例在合理范围内 @@ -352,85 +368,87 @@ void resize_tile_master_vertical(Client *grabc, bool isdrag, int32_t offsetx, new_stack_inner_per = fmaxf(0.1f, fminf(0.9f, new_stack_inner_per)); // 应用到所有平铺窗口 - wl_list_for_each(tc, &clients, link) { - if (VISIBLEON(tc, grabc->mon) && ISTILED(tc)) { + wl_list_for_each(tc, &server.clients, link) { + if (VISIBLEON(tc, rec->mon) && ISTILED(tc)) { tc->master_mfact_per = new_master_mfact_per; } } - grabc->master_inner_per = new_master_inner_per; - grabc->stack_inner_per = new_stack_inner_per; + rec->master_inner_per = new_master_inner_per; + rec->stack_inner_per = new_stack_inner_per; if (!isdrag) { - arrange(grabc->mon, false, false); + arrange(rec->mon, false, false); return; } - if (last_apply_drap_time == 0 || - time - last_apply_drap_time > drag_tile_refresh_interval) { - arrange(grabc->mon, false, false); - last_apply_drap_time = time; + if (server.last_apply_drag_time == 0 || + time - server.last_apply_drag_time > drag_tile_refresh_interval) { + arrange(rec->mon, false, false); + server.last_apply_drag_time = time; } } } -void resize_tile_scroller(Client *grabc, bool isdrag, int32_t offsetx, +void resize_tile_scroller(Client *rec, bool isdrag, int32_t offsetx, int32_t offsety, uint32_t time, bool isvertical) { float delta_x, delta_y; float new_scroller_proportion; float new_stack_proportion; - Client *stack_head = get_scroll_stack_head(grabc); + Client *stack_head = get_scroll_stack_head(rec); - if (grabc && grabc->mon->visible_tiling_clients == 1 && + if (rec && rec->mon->visible_tiling_clients == 1 && !scroller_ignore_proportion_single) return; - if (!start_drag_window && isdrag) { - drag_begin_cursorx = cursor->x; - drag_begin_cursory = cursor->y; - start_drag_window = true; + if (!server.start_drag_window && isdrag) { + server.drag_begin_cursorx = server.cursor->x; + server.drag_begin_cursory = server.cursor->y; + server.start_drag_window = true; // 记录初始状态 stack_head->old_scroller_pproportion = stack_head->scroller_proportion; - grabc->old_stack_proportion = grabc->stack_proportion; + rec->old_stack_proportion = rec->stack_proportion; - grabc->cursor_in_left_half = - cursor->x < grabc->geom.x + grabc->geom.width / 2; - grabc->cursor_in_upper_half = - cursor->y < grabc->geom.y + grabc->geom.height / 2; + rec->cursor_in_left_half = + server.cursor->x < + rec->geom.x + rec->geom.width / 2; + rec->cursor_in_upper_half = + server.cursor->y < + rec->geom.y + rec->geom.height / 2; // 记录初始几何信息 - grabc->drag_begin_geom = grabc->geom; + rec->drag_begin_geom = rec->geom; } else { // 计算相对于屏幕尺寸的比例变化 // 计算相对于屏幕尺寸的比例变化 if (isdrag) { - offsetx = cursor->x - drag_begin_cursorx; - offsety = cursor->y - drag_begin_cursory; + offsetx = server.cursor->x - server.drag_begin_cursorx; + offsety = server.cursor->y - server.drag_begin_cursory; } else { - grabc->old_master_mfact_per = grabc->master_mfact_per; - grabc->old_master_inner_per = grabc->master_inner_per; - grabc->old_stack_inner_per = grabc->stack_inner_per; - grabc->drag_begin_geom = grabc->geom; + rec->old_master_mfact_per = rec->master_mfact_per; + rec->old_master_inner_per = rec->master_inner_per; + rec->old_stack_inner_per = rec->stack_inner_per; + rec->drag_begin_geom = rec->geom; stack_head->old_scroller_pproportion = stack_head->scroller_proportion; - grabc->old_stack_proportion = grabc->stack_proportion; - grabc->cursor_in_upper_half = false; - grabc->cursor_in_left_half = false; + rec->old_stack_proportion = rec->stack_proportion; + rec->cursor_in_upper_half = false; + rec->cursor_in_left_half = false; } if (isvertical) { delta_y = (float)(offsety) * (stack_head->old_scroller_pproportion) / - grabc->drag_begin_geom.height; - delta_x = (float)(offsetx) * (grabc->old_stack_proportion) / - grabc->drag_begin_geom.width; + rec->drag_begin_geom.height; + delta_x = (float)(offsetx) * (rec->old_stack_proportion) / + rec->drag_begin_geom.width; } else { delta_x = (float)(offsetx) * (stack_head->old_scroller_pproportion) / - grabc->drag_begin_geom.width; - delta_y = (float)(offsety) * (grabc->old_stack_proportion) / - grabc->drag_begin_geom.height; + rec->drag_begin_geom.width; + delta_y = (float)(offsety) * (rec->old_stack_proportion) / + rec->drag_begin_geom.height; } bool moving_up; @@ -444,14 +462,14 @@ void resize_tile_scroller(Client *grabc, bool isdrag, int32_t offsetx, moving_left = offsetx < 0 ? true : false; moving_right = offsetx > 0 ? true : false; } else { - moving_up = cursor->y < drag_begin_cursory; - moving_down = cursor->y > drag_begin_cursory; - moving_left = cursor->x < drag_begin_cursorx; - moving_right = cursor->x > drag_begin_cursorx; + moving_up = server.cursor->y < server.drag_begin_cursory; + moving_down = server.cursor->y > server.drag_begin_cursory; + moving_left = server.cursor->x < server.drag_begin_cursorx; + moving_right = server.cursor->x > server.drag_begin_cursorx; } - if ((grabc->cursor_in_upper_half && moving_up) || - (!grabc->cursor_in_upper_half && moving_down)) { + if ((rec->cursor_in_upper_half && moving_up) || + (!rec->cursor_in_upper_half && moving_down)) { // 光标在窗口上方且向上移动,或在窗口下方且向下移动 → 增加高度 delta_y = fabsf(delta_y); } else { @@ -459,25 +477,28 @@ void resize_tile_scroller(Client *grabc, bool isdrag, int32_t offsetx, delta_y = -fabsf(delta_y); } - if ((grabc->cursor_in_left_half && moving_left) || - (!grabc->cursor_in_left_half && moving_right)) { + if ((rec->cursor_in_left_half && moving_left) || + (!rec->cursor_in_left_half && moving_right)) { delta_x = fabsf(delta_x); } else { delta_x = -fabsf(delta_x); } if (isvertical) { - if (!grabc->next_in_stack && grabc->prev_in_stack && !isdrag) { + if (!rec->next_in_stack && rec->prev_in_stack && + !isdrag) { delta_x = delta_x * -1.0f; } - if (!grabc->next_in_stack && grabc->prev_in_stack && isdrag) { + if (!rec->next_in_stack && rec->prev_in_stack && + isdrag) { if (moving_right) { delta_x = -fabsf(delta_x); } else { delta_x = fabsf(delta_x); } } - if (!grabc->prev_in_stack && grabc->next_in_stack && isdrag) { + if (!rec->prev_in_stack && rec->next_in_stack && + isdrag) { if (moving_left) { delta_x = -fabsf(delta_x); } else { @@ -494,17 +515,20 @@ void resize_tile_scroller(Client *grabc, bool isdrag, int32_t offsetx, } } else { - if (!grabc->next_in_stack && grabc->prev_in_stack && !isdrag) { + if (!rec->next_in_stack && rec->prev_in_stack && + !isdrag) { delta_y = delta_y * -1.0f; } - if (!grabc->next_in_stack && grabc->prev_in_stack && isdrag) { + if (!rec->next_in_stack && rec->prev_in_stack && + isdrag) { if (moving_down) { delta_y = -fabsf(delta_y); } else { delta_y = fabsf(delta_y); } } - if (!grabc->prev_in_stack && grabc->next_in_stack && isdrag) { + if (!rec->prev_in_stack && rec->next_in_stack && + isdrag) { if (moving_up) { delta_y = -fabsf(delta_y); } else { @@ -525,12 +549,12 @@ void resize_tile_scroller(Client *grabc, bool isdrag, int32_t offsetx, if (isvertical) { new_scroller_proportion = stack_head->old_scroller_pproportion + delta_y; - new_stack_proportion = grabc->old_stack_proportion + delta_x; + new_stack_proportion = rec->old_stack_proportion + delta_x; } else { new_scroller_proportion = stack_head->old_scroller_pproportion + delta_x; - new_stack_proportion = grabc->old_stack_proportion + delta_y; + new_stack_proportion = rec->old_stack_proportion + delta_y; } // 应用限制,确保比例在合理范围内 @@ -538,49 +562,53 @@ void resize_tile_scroller(Client *grabc, bool isdrag, int32_t offsetx, fmaxf(0.1f, fminf(1.0f, new_scroller_proportion)); new_stack_proportion = fmaxf(0.1f, fminf(1.0f, new_stack_proportion)); - grabc->stack_proportion = new_stack_proportion; + rec->stack_proportion = new_stack_proportion; stack_head->scroller_proportion = new_scroller_proportion; if (!isdrag) { - arrange(grabc->mon, false, false); + arrange(rec->mon, false, false); return; } - if (last_apply_drap_time == 0 || - time - last_apply_drap_time > drag_tile_refresh_interval) { - arrange(grabc->mon, false, false); - last_apply_drap_time = time; + if (server.last_apply_drag_time == 0 || + time - server.last_apply_drag_time > drag_tile_refresh_interval) { + arrange(rec->mon, false, false); + server.last_apply_drag_time = time; } } } -void resize_tile_client(Client *grabc, bool isdrag, int32_t offsetx, +void resize_tile_client(Client *rec, bool isdrag, int32_t offsetx, int32_t offsety, uint32_t time) { - if (!grabc || grabc->isfullscreen || grabc->ismaximizescreen) + if (!rec || rec->isfullscreen || + rec->ismaximizescreen) return; - if (grabc->mon->isoverview) + if (rec->mon->isoverview) return; const Layout *current_layout = - grabc->mon->pertag->ltidxs[grabc->mon->pertag->curtag]; + rec->mon->pertag->ltidxs[rec->mon->pertag->curtag]; if (current_layout->id == TILE || current_layout->id == DECK || current_layout->id == CENTER_TILE || current_layout->id == RIGHT_TILE || - (current_layout->id == TGMIX && grabc->mon->visible_tiling_clients <= 3) + (current_layout->id == TGMIX && + rec->mon->visible_tiling_clients <= 3) ) { - resize_tile_master_horizontal(grabc, isdrag, offsetx, offsety, time, - current_layout->id); + resize_tile_master_horizontal(rec, isdrag, offsetx, offsety, + time, current_layout->id); } else if (current_layout->id == VERTICAL_TILE || current_layout->id == VERTICAL_DECK) { - resize_tile_master_vertical(grabc, isdrag, offsetx, offsety, time, - current_layout->id); + resize_tile_master_vertical(rec, isdrag, offsetx, offsety, + time, current_layout->id); } else if (current_layout->id == SCROLLER) { - resize_tile_scroller(grabc, isdrag, offsetx, offsety, time, false); + resize_tile_scroller(rec, isdrag, offsetx, offsety, time, + false); } else if (current_layout->id == VERTICAL_SCROLLER) { - resize_tile_scroller(grabc, isdrag, offsetx, offsety, time, true); + resize_tile_scroller(rec, isdrag, offsetx, offsety, time, + true); } } @@ -597,7 +625,7 @@ void reset_size_per_mon(Monitor *m, int32_t tile_cilent_num, if (m->pertag->ltidxs[m->pertag->curtag]->id != CENTER_TILE) { - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (VISIBLEON(c, m) && ISTILED(c)) { if (total_master_inner_percent > 0.0 && i < nmasters) { c->ismaster = true; @@ -617,7 +645,7 @@ void reset_size_per_mon(Monitor *m, int32_t tile_cilent_num, } } } else { - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (VISIBLEON(c, m) && ISTILED(c)) { if (total_master_inner_percent > 0.0 && i < nmasters) { c->ismaster = true; @@ -658,6 +686,34 @@ void reset_size_per_mon(Monitor *m, int32_t tile_cilent_num, } } +void resize_floating_window(Client *rec) { + int cdx = (int)round(server.cursor->x) - server.grabcx; + int cdy = (int)round(server.cursor->y) - server.grabcy; + + cdx = !(server.rzcorner & 1) && + rec->geom.width - 2 * (int)rec->bw - cdx < 1 + ? 0 + : cdx; + cdy = + !(server.rzcorner & 2) && + rec->geom.height - 2 * (int)rec->bw - cdy < 1 + ? 0 + : cdy; + + const struct wlr_box box = { + .x = rec->geom.x + (server.rzcorner & 1 ? 0 : cdx), + .y = rec->geom.y + (server.rzcorner & 2 ? 0 : cdy), + .width = rec->geom.width + (server.rzcorner & 1 ? cdx : -cdx), + .height = + rec->geom.height + (server.rzcorner & 2 ? cdy : -cdy)}; + + rec->float_geom = box; + + resize(rec, box, 1); + server.grabcx += cdx; + server.grabcy += cdy; +} + void // 17 arrange(Monitor *m, bool want_animation, bool from_view) { Client *c = NULL; @@ -680,7 +736,7 @@ arrange(Monitor *m, bool want_animation, bool from_view) { m->visible_tiling_clients = 0; m->visible_scroll_tiling_clients = 0; - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (!client_only_in_one_tag(c) || c->isglobal || c->isunglobal) { exit_scroller_stack(c); @@ -718,7 +774,7 @@ arrange(Monitor *m, bool want_animation, bool from_view) { nmasters = m->pertag->nmasters[m->pertag->curtag]; - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (c->iskilling) continue; @@ -771,7 +827,7 @@ arrange(Monitor *m, bool want_animation, bool from_view) { m->pertag->ltidxs[m->pertag->curtag]->arrange(m); } - if (!start_drag_window) { + if (!server.start_drag_window) { motionnotify(0, NULL, 0, 0, 0, 0); checkidleinhibitor(NULL); } diff --git a/src/layout/horizontal.h b/src/layout/horizontal.h index e1a335d..21392e3 100644 --- a/src/layout/horizontal.h +++ b/src/layout/horizontal.h @@ -7,9 +7,9 @@ void grid(Monitor *m) { Client *c = NULL; n = 0; int32_t target_gappo = - enablegaps ? m->isoverview ? overviewgappo : gappoh : 0; + server.enablegaps ? m->isoverview ? overviewgappo : gappoh : 0; int32_t target_gappi = - enablegaps ? m->isoverview ? overviewgappi : gappih : 0; + server.enablegaps ? m->isoverview ? overviewgappi : gappih : 0; float single_width_ratio = m->isoverview ? 0.7 : 0.9; float single_height_ratio = m->isoverview ? 0.8 : 0.9; @@ -20,7 +20,7 @@ void grid(Monitor *m) { } if (n == 1) { - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (c->mon != m) continue; @@ -43,7 +43,7 @@ void grid(Monitor *m) { cw = (m->w.width - 2 * target_gappo - target_gappi) / 2; ch = (m->w.height - 2 * target_gappo) * 0.65; i = 0; - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (c->mon != m) continue; @@ -89,7 +89,7 @@ void grid(Monitor *m) { // 调整每个客户端的位置和大小 i = 0; - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (c->mon != m) continue; @@ -119,9 +119,9 @@ void deck(Monitor *m) { float mfact; uint32_t nmasters = m->pertag->nmasters[m->pertag->curtag]; - int32_t cur_gappih = enablegaps ? m->gappih : 0; - int32_t cur_gappoh = enablegaps ? m->gappoh : 0; - int32_t cur_gappov = enablegaps ? m->gappov : 0; + int32_t cur_gappih = server.enablegaps ? m->gappih : 0; + int32_t cur_gappoh = server.enablegaps ? m->gappoh : 0; + int32_t cur_gappov = server.enablegaps ? m->gappov : 0; cur_gappih = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappih; cur_gappoh = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappoh; @@ -132,7 +132,7 @@ void deck(Monitor *m) { if (n == 0) return; - wl_list_for_each(fc, &clients, link) { + wl_list_for_each(fc, &server.clients, link) { if (VISIBLEON(fc, m) && ISTILED(fc)) break; @@ -149,12 +149,12 @@ void deck(Monitor *m) { mw = m->w.width - 2 * cur_gappoh; i = my = 0; - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (!VISIBLEON(c, m) || !ISTILED(c)) continue; if (i < nmasters) { c->master_mfact_per = mfact; - // Master area clients + // Master area server.clients resize( c, (struct wlr_box){.x = m->w.x + cur_gappoh, @@ -165,7 +165,7 @@ void deck(Monitor *m) { 0); my += c->geom.height; } else { - // Stack area clients + // Stack area server.clients c->master_mfact_per = mfact; resize(c, (struct wlr_box){.x = m->w.x + mw + cur_gappoh + cur_gappih, @@ -184,9 +184,9 @@ void deck(Monitor *m) { void horizontal_scroll_adjust_fullandmax(Client *c, struct wlr_box *target_geom) { Monitor *m = c->mon; - int32_t cur_gappih = enablegaps ? m->gappih : 0; - int32_t cur_gappoh = enablegaps ? m->gappoh : 0; - int32_t cur_gappov = enablegaps ? m->gappov : 0; + int32_t cur_gappih = server.enablegaps ? m->gappih : 0; + int32_t cur_gappoh = server.enablegaps ? m->gappoh : 0; + int32_t cur_gappov = server.enablegaps ? m->gappov : 0; cur_gappih = smartgaps && m->visible_scroll_tiling_clients == 1 ? 0 : cur_gappih; @@ -283,10 +283,10 @@ void scroller(Monitor *m) { struct wlr_box target_geom; int32_t focus_client_index = 0; bool need_scroller = false; - int32_t cur_gappih = enablegaps ? m->gappih : 0; - int32_t cur_gappoh = enablegaps ? m->gappoh : 0; - int32_t cur_gappov = enablegaps ? m->gappov : 0; - int32_t cur_gappiv = enablegaps ? m->gappiv : 0; + int32_t cur_gappih = server.enablegaps ? m->gappih : 0; + int32_t cur_gappoh = server.enablegaps ? m->gappoh : 0; + int32_t cur_gappov = server.enablegaps ? m->gappov : 0; + int32_t cur_gappiv = server.enablegaps ? m->gappiv : 0; cur_gappih = smartgaps && m->visible_scroll_tiling_clients == 1 ? 0 : cur_gappih; @@ -312,7 +312,7 @@ void scroller(Monitor *m) { // 第二次遍历,填充 tempClients j = 0; - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (VISIBLEON(c, m) && ISSCROLLTILED(c) && !c->prev_in_stack) { tempClients[j] = c; j++; @@ -375,7 +375,7 @@ void scroller(Monitor *m) { need_scroller = true; } - if (start_drag_window) + if (server.start_drag_window) need_scroller = false; target_geom.height = m->w.height - 2 * cur_gappov; @@ -444,7 +444,7 @@ void scroller(Monitor *m) { } void center_tile(Monitor *m) { - int32_t i, n = 0, h, r, ie = enablegaps, mw, mx, my, oty, ety, tw; + int32_t i, n = 0, h, r, ie = server.enablegaps, mw, mx, my, oty, ety, tw; Client *c = NULL; Client *fc = NULL; double mfact = 0; @@ -461,16 +461,16 @@ void center_tile(Monitor *m) { return; // 获取第一个可见的平铺客户端用于主区域宽度百分比 - wl_list_for_each(fc, &clients, link) { + wl_list_for_each(fc, &server.clients, link) { if (VISIBLEON(fc, m) && ISTILED(fc)) break; } // 间隙参数处理 - int32_t cur_gappiv = enablegaps ? m->gappiv : 0; // 内部垂直间隙 - int32_t cur_gappih = enablegaps ? m->gappih : 0; // 内部水平间隙 - int32_t cur_gappov = enablegaps ? m->gappov : 0; // 外部垂直间隙 - int32_t cur_gappoh = enablegaps ? m->gappoh : 0; // 外部水平间隙 + int32_t cur_gappiv = server.enablegaps ? m->gappiv : 0; // 内部垂直间隙 + int32_t cur_gappih = server.enablegaps ? m->gappih : 0; // 内部水平间隙 + int32_t cur_gappov = server.enablegaps ? m->gappov : 0; // 外部垂直间隙 + int32_t cur_gappoh = server.enablegaps ? m->gappoh : 0; // 外部水平间隙 // 智能间隙处理 cur_gappiv = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappiv; @@ -540,7 +540,7 @@ void center_tile(Monitor *m) { ety = cur_gappov; i = 0; - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (!VISIBLEON(c, m) || !ISTILED(c)) continue; @@ -676,7 +676,7 @@ void center_tile(Monitor *m) { } void tile(Monitor *m) { - int32_t i, n = 0, h, r, ie = enablegaps, mw, my, ty; + int32_t i, n = 0, h, r, ie = server.enablegaps, mw, my, ty; Client *c = NULL; Client *fc = NULL; double mfact = 0; @@ -691,17 +691,17 @@ void tile(Monitor *m) { if (n == 0) return; - int32_t cur_gappiv = enablegaps ? m->gappiv : 0; - int32_t cur_gappih = enablegaps ? m->gappih : 0; - int32_t cur_gappov = enablegaps ? m->gappov : 0; - int32_t cur_gappoh = enablegaps ? m->gappoh : 0; + int32_t cur_gappiv = server.enablegaps ? m->gappiv : 0; + int32_t cur_gappih = server.enablegaps ? m->gappih : 0; + int32_t cur_gappov = server.enablegaps ? m->gappov : 0; + int32_t cur_gappoh = server.enablegaps ? m->gappoh : 0; cur_gappiv = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappiv; cur_gappih = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappih; cur_gappov = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappov; cur_gappoh = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappoh; - wl_list_for_each(fc, &clients, link) { + wl_list_for_each(fc, &server.clients, link) { if (VISIBLEON(fc, m) && ISTILED(fc)) break; @@ -727,7 +727,7 @@ void tile(Monitor *m) { (m->w.height - 2 * cur_gappov - cur_gappiv * ie * (stack_num - 1)); float slave_surplus_ratio = 1.0; - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (!VISIBLEON(c, m) || !ISTILED(c)) continue; if (i < m->pertag->nmasters[m->pertag->curtag]) { @@ -786,7 +786,7 @@ void tile(Monitor *m) { } void right_tile(Monitor *m) { - int32_t i, n = 0, h, r, ie = enablegaps, mw, my, ty; + int32_t i, n = 0, h, r, ie = server.enablegaps, mw, my, ty; Client *c = NULL; Client *fc = NULL; double mfact = 0; @@ -801,17 +801,17 @@ void right_tile(Monitor *m) { if (n == 0) return; - int32_t cur_gappiv = enablegaps ? m->gappiv : 0; - int32_t cur_gappih = enablegaps ? m->gappih : 0; - int32_t cur_gappov = enablegaps ? m->gappov : 0; - int32_t cur_gappoh = enablegaps ? m->gappoh : 0; + int32_t cur_gappiv = server.enablegaps ? m->gappiv : 0; + int32_t cur_gappih = server.enablegaps ? m->gappih : 0; + int32_t cur_gappov = server.enablegaps ? m->gappov : 0; + int32_t cur_gappoh = server.enablegaps ? m->gappoh : 0; cur_gappiv = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappiv; cur_gappih = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappih; cur_gappov = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappov; cur_gappoh = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappoh; - wl_list_for_each(fc, &clients, link) { + wl_list_for_each(fc, &server.clients, link) { if (VISIBLEON(fc, m) && ISTILED(fc)) break; @@ -837,7 +837,7 @@ void right_tile(Monitor *m) { (m->w.height - 2 * cur_gappov - cur_gappiv * ie * (stack_num - 1)); float slave_surplus_ratio = 1.0; - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (!VISIBLEON(c, m) || !ISTILED(c)) continue; if (i < m->pertag->nmasters[m->pertag->curtag]) { @@ -901,13 +901,13 @@ monocle(Monitor *m) { Client *c = NULL; struct wlr_box geom; - int32_t cur_gappov = enablegaps ? m->gappov : 0; - int32_t cur_gappoh = enablegaps ? m->gappoh : 0; + int32_t cur_gappov = server.enablegaps ? m->gappov : 0; + int32_t cur_gappoh = server.enablegaps ? m->gappoh : 0; cur_gappoh = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappoh; cur_gappov = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappov; - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (!VISIBLEON(c, m) || !ISTILED(c)) continue; geom.x = m->w.x + cur_gappoh; diff --git a/src/layout/vertical.h b/src/layout/vertical.h index f7bd442..b4278a6 100644 --- a/src/layout/vertical.h +++ b/src/layout/vertical.h @@ -1,5 +1,5 @@ void vertical_tile(Monitor *m) { - int32_t i, n = 0, w, r, ie = enablegaps, mh, mx, tx; + int32_t i, n = 0, w, r, ie = server.enablegaps, mh, mx, tx; Client *c = NULL; Client *fc = NULL; double mfact = 0; @@ -14,17 +14,17 @@ void vertical_tile(Monitor *m) { if (n == 0) return; - int32_t cur_gapih = enablegaps ? m->gappih : 0; - int32_t cur_gapiv = enablegaps ? m->gappiv : 0; - int32_t cur_gapoh = enablegaps ? m->gappoh : 0; - int32_t cur_gapov = enablegaps ? m->gappov : 0; + int32_t cur_gapih = server.enablegaps ? m->gappih : 0; + int32_t cur_gapiv = server.enablegaps ? m->gappiv : 0; + int32_t cur_gapoh = server.enablegaps ? m->gappoh : 0; + int32_t cur_gapov = server.enablegaps ? m->gappov : 0; cur_gapih = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gapih; cur_gapiv = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gapiv; cur_gapoh = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gapoh; cur_gapov = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gapov; - wl_list_for_each(fc, &clients, link) { + wl_list_for_each(fc, &server.clients, link) { if (VISIBLEON(fc, m) && ISTILED(fc)) break; } @@ -50,7 +50,7 @@ void vertical_tile(Monitor *m) { (m->w.width - 2 * cur_gapoh - cur_gapih * ie * (stack_num - 1)); float slave_surplus_ratio = 1.0; - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (!VISIBLEON(c, m) || !ISTILED(c)) continue; if (i < m->pertag->nmasters[m->pertag->curtag]) { @@ -112,9 +112,9 @@ void vertical_deck(Monitor *m) { float mfact; uint32_t nmasters = m->pertag->nmasters[m->pertag->curtag]; - int32_t cur_gappiv = enablegaps ? m->gappiv : 0; - int32_t cur_gappoh = enablegaps ? m->gappoh : 0; - int32_t cur_gappov = enablegaps ? m->gappov : 0; + int32_t cur_gappiv = server.enablegaps ? m->gappiv : 0; + int32_t cur_gappoh = server.enablegaps ? m->gappoh : 0; + int32_t cur_gappov = server.enablegaps ? m->gappov : 0; cur_gappiv = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappiv; cur_gappoh = smartgaps && m->visible_tiling_clients == 1 ? 0 : cur_gappoh; @@ -125,7 +125,7 @@ void vertical_deck(Monitor *m) { if (n == 0) return; - wl_list_for_each(fc, &clients, link) { + wl_list_for_each(fc, &server.clients, link) { if (VISIBLEON(fc, m) && ISTILED(fc)) break; @@ -141,7 +141,7 @@ void vertical_deck(Monitor *m) { mh = m->w.height - 2 * cur_gappov; i = mx = 0; - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (!VISIBLEON(c, m) || !ISTILED(c)) continue; if (i < nmasters) { @@ -171,9 +171,9 @@ void vertical_deck(Monitor *m) { void vertical_scroll_adjust_fullandmax(Client *c, struct wlr_box *target_geom) { Monitor *m = c->mon; - int32_t cur_gappiv = enablegaps ? m->gappiv : 0; - int32_t cur_gappov = enablegaps ? m->gappov : 0; - int32_t cur_gappoh = enablegaps ? m->gappoh : 0; + int32_t cur_gappiv = server.enablegaps ? m->gappiv : 0; + int32_t cur_gappov = server.enablegaps ? m->gappov : 0; + int32_t cur_gappoh = server.enablegaps ? m->gappoh : 0; cur_gappiv = smartgaps && m->visible_scroll_tiling_clients == 1 ? 0 : cur_gappiv; @@ -270,10 +270,10 @@ void vertical_scroller(Monitor *m) { struct wlr_box target_geom; int32_t focus_client_index = 0; bool need_scroller = false; - int32_t cur_gappiv = enablegaps ? m->gappiv : 0; - int32_t cur_gappov = enablegaps ? m->gappov : 0; - int32_t cur_gappoh = enablegaps ? m->gappoh : 0; - int32_t cur_gappih = enablegaps ? m->gappih : 0; + int32_t cur_gappiv = server.enablegaps ? m->gappiv : 0; + int32_t cur_gappov = server.enablegaps ? m->gappov : 0; + int32_t cur_gappoh = server.enablegaps ? m->gappoh : 0; + int32_t cur_gappih = server.enablegaps ? m->gappih : 0; cur_gappiv = smartgaps && m->visible_scroll_tiling_clients == 1 ? 0 : cur_gappiv; @@ -296,7 +296,7 @@ void vertical_scroller(Monitor *m) { } j = 0; - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (VISIBLEON(c, m) && ISSCROLLTILED(c) && !c->prev_in_stack) { tempClients[j] = c; j++; @@ -359,7 +359,7 @@ void vertical_scroller(Monitor *m) { need_scroller = true; } - if (start_drag_window) + if (server.start_drag_window) need_scroller = false; target_geom.width = m->w.width - 2 * cur_gappoh; @@ -439,9 +439,9 @@ void vertical_grid(Monitor *m) { int32_t rows, cols, overrows; Client *c = NULL; int32_t target_gappo = - enablegaps ? m->isoverview ? overviewgappo : gappov : 0; + server.enablegaps ? m->isoverview ? overviewgappo : gappov : 0; int32_t target_gappi = - enablegaps ? m->isoverview ? overviewgappi : gappiv : 0; + server.enablegaps ? m->isoverview ? overviewgappi : gappiv : 0; float single_width_ratio = m->isoverview ? 0.7 : 0.9; float single_height_ratio = m->isoverview ? 0.8 : 0.9; @@ -452,7 +452,7 @@ void vertical_grid(Monitor *m) { } if (n == 1) { - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (c->mon != m) continue; @@ -475,7 +475,7 @@ void vertical_grid(Monitor *m) { ch = (m->w.height - 2 * target_gappo - target_gappi) / 2; cw = (m->w.width - 2 * target_gappo) * 0.65; i = 0; - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (c->mon != m) continue; @@ -518,7 +518,7 @@ void vertical_grid(Monitor *m) { } i = 0; - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (c->mon != m) continue; diff --git a/src/mango.c b/src/mango.c index 12ee9ee..b5663c7 100644 --- a/src/mango.c +++ b/src/mango.c @@ -147,7 +147,7 @@ enum { TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT }; enum { VERTICAL, HORIZONTAL }; enum { SWIPE_UP, SWIPE_DOWN, SWIPE_LEFT, SWIPE_RIGHT }; -enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */ +enum { CurNormal, CurPressed, CurMove, CurResize }; /* server.cursor */ enum { XDGShell, LayerShell, X11 }; /* client types */ enum { AxisUp, AxisDown, AxisLeft, AxisRight }; // 滚轮滚动的方向 enum { @@ -161,7 +161,7 @@ enum { LyrIMPopup, // text-input layer LyrBlock, NUM_LAYERS -}; /* scene layers */ +}; /* server.scene server.layers */ #ifdef XWAYLAND enum { NetWMWindowTypeDialog, @@ -539,8 +539,124 @@ typedef struct { struct wl_listener destroy; } SessionLock; +// 在你的头文件中(比如 server.h) +// 在你的头文件中(比如 server.h) typedef struct { + // 键盘模式相关 KeyMode keymode; + + // 核心 Wayland/WLRoots 对象 + struct wl_display *dpy; + struct wl_event_loop *event_loop; + struct wlr_backend *backend; + struct wlr_backend *headless_backend; + struct wlr_scene *scene; + struct wlr_scene_tree *layers[NUM_LAYERS]; + struct wlr_renderer *drw; + struct wlr_allocator *alloc; + struct wlr_compositor *compositor; + + // Shell 相关 + struct wlr_xdg_shell *xdg_shell; + struct wlr_xdg_activation_v1 *activation; + struct wlr_xdg_decoration_manager_v1 *xdg_decoration_mgr; + struct wl_list clients; /* tiling order */ + struct wl_list fstack; /* focus order */ + struct wl_list fadeout_clients; + struct wl_list fadeout_layers; + struct wlr_idle_notifier_v1 *idle_notifier; + struct wlr_idle_inhibit_manager_v1 *idle_inhibit_mgr; + struct wlr_layer_shell_v1 *layer_shell; + struct wlr_output_manager_v1 *output_mgr; + struct wlr_virtual_keyboard_manager_v1 *virtual_keyboard_mgr; + struct wlr_keyboard_shortcuts_inhibit_manager_v1 + *keyboard_shortcuts_inhibit; + struct wlr_virtual_pointer_manager_v1 *virtual_pointer_mgr; + struct wlr_output_power_manager_v1 *power_mgr; + struct wlr_pointer_gestures_v1 *pointer_gestures; + struct wlr_drm_lease_v1_manager *drm_lease_manager; + struct mango_print_status_manager *print_status_manager; + + // 光标和输入相关 + struct wlr_cursor *cursor; + struct wlr_xcursor_manager *cursor_mgr; + struct wlr_session *session; + + // 界面元素 + struct wlr_scene_rect *root_bg; + struct wlr_session_lock_manager_v1 *session_lock_mgr; + struct wlr_scene_rect *locked_bg; + struct wlr_session_lock_v1 *cur_lock; + struct wlr_scene_tree *drag_icon; + struct wlr_cursor_shape_manager_v1 *cursor_shape_mgr; + struct wlr_pointer_constraints_v1 *pointer_constraints; + struct wlr_relative_pointer_manager_v1 *relative_pointer_mgr; + struct wlr_pointer_constraint_v1 *active_constraint; + + // 座位和键盘 + struct wlr_seat *seat; + KeyboardGroup *kb_group; + struct wl_list inputdevices; + struct wl_list keyboard_shortcut_inhibitors; + + // 布局相关 + struct wlr_output_layout *output_layout; + struct wl_list mons; + Monitor *selmon; + struct wlr_box sgeom; + + // 动画曲线数据 + struct dvec2 *baked_points_move; + struct dvec2 *baked_points_open; + struct dvec2 *baked_points_tag; + struct dvec2 *baked_points_close; + struct dvec2 *baked_points_focus; + struct dvec2 *baked_points_opafadein; + struct dvec2 *baked_points_opafadeout; + + // 事件源 + struct wl_event_source *hide_source; + + // 光标状态 + struct { + enum wp_cursor_shape_device_v1_shape shape; + struct wlr_surface *surface; + int32_t hotspot_x; + int32_t hotspot_y; + } last_cursor; + + // 各种状态变量 + pid_t child_pid; + int32_t locked; + uint32_t locked_mods; + void *exclusive_focus; + uint32_t cursor_mode; + Client *grabc; + int32_t rzcorner; + int32_t grabcx, grabcy; + int32_t drag_begin_cursorx, drag_begin_cursory; + bool start_drag_window; + int32_t last_apply_drag_time; + + int32_t enablegaps; + int32_t axis_apply_time; + int32_t axis_apply_dir; + int32_t scroller_focus_lock; + + uint32_t swipe_fingers; + double swipe_dx; + double swipe_dy; + + bool render_border; + uint32_t chvt_backup_tag; + bool allow_frame_scheduling; + char chvt_backup_selmon[32]; + + bool cursor_hidden; + bool tag_combo; + + // 配置路径 + const char *cli_config_path; } Server; /* function declarations */ @@ -772,7 +888,7 @@ static void enable_adaptive_sync(Monitor *m, struct wlr_output_state *state); static Client *get_next_stack_client(Client *c, bool reverse); static void set_float_malposition(Client *tc); static void set_size_per(Monitor *m, Client *c); -static void resize_tile_client(Client *grabc, bool isdrag, int32_t offsetx, +static void resize_tile_client(Client *rec, bool isdrag, int32_t offsetx, int32_t offsety, uint32_t time); static void refresh_monitors_workspaces_status(Monitor *m); static void init_client_properties(Client *c); @@ -794,106 +910,7 @@ static bool client_is_in_same_stack(Client *sc, Client *tc, Client *fc); /* variables */ Server server; static const char broken[] = "broken"; -static pid_t child_pid = -1; -static int32_t locked; -static uint32_t locked_mods = 0; -static void *exclusive_focus; -static struct wl_display *dpy; -static struct wl_event_loop *event_loop; -static struct wlr_backend *backend; -static struct wlr_backend *headless_backend; -static struct wlr_scene *scene; -static struct wlr_scene_tree *layers[NUM_LAYERS]; -static struct wlr_renderer *drw; -static struct wlr_allocator *alloc; -static struct wlr_compositor *compositor; - -static struct wlr_xdg_shell *xdg_shell; -static struct wlr_xdg_activation_v1 *activation; -static struct wlr_xdg_decoration_manager_v1 *xdg_decoration_mgr; -static struct wl_list clients; /* tiling order */ -static struct wl_list fstack; /* focus order */ -static struct wl_list fadeout_clients; -static struct wl_list fadeout_layers; -static struct wlr_idle_notifier_v1 *idle_notifier; -static struct wlr_idle_inhibit_manager_v1 *idle_inhibit_mgr; -static struct wlr_layer_shell_v1 *layer_shell; -static struct wlr_output_manager_v1 *output_mgr; -static struct wlr_virtual_keyboard_manager_v1 *virtual_keyboard_mgr; -static struct wlr_keyboard_shortcuts_inhibit_manager_v1 - *keyboard_shortcuts_inhibit; -static struct wlr_virtual_pointer_manager_v1 *virtual_pointer_mgr; -static struct wlr_output_power_manager_v1 *power_mgr; -static struct wlr_pointer_gestures_v1 *pointer_gestures; -static struct wlr_drm_lease_v1_manager *drm_lease_manager; -struct mango_print_status_manager *print_status_manager; - -static struct wlr_cursor *cursor; -static struct wlr_xcursor_manager *cursor_mgr; -static struct wlr_session *session; - -static struct wlr_scene_rect *root_bg; -static struct wlr_session_lock_manager_v1 *session_lock_mgr; -static struct wlr_scene_rect *locked_bg; -static struct wlr_session_lock_v1 *cur_lock; static const int32_t layermap[] = {LyrBg, LyrBottom, LyrTop, LyrOverlay}; -static struct wlr_scene_tree *drag_icon; -static struct wlr_cursor_shape_manager_v1 *cursor_shape_mgr; -static struct wlr_pointer_constraints_v1 *pointer_constraints; -static struct wlr_relative_pointer_manager_v1 *relative_pointer_mgr; -static struct wlr_pointer_constraint_v1 *active_constraint; - -static struct wlr_seat *seat; -static KeyboardGroup *kb_group; -static struct wl_list inputdevices; -static struct wl_list keyboard_shortcut_inhibitors; -static uint32_t cursor_mode; -static Client *grabc; -static int32_t rzcorner; -static int32_t grabcx, grabcy; /* client-relative */ -static int32_t drag_begin_cursorx, drag_begin_cursory; /* client-relative */ -static bool start_drag_window = false; -static int32_t last_apply_drap_time = 0; - -static struct wlr_output_layout *output_layout; -static struct wlr_box sgeom; -static struct wl_list mons; -static Monitor *selmon; - -static int32_t enablegaps = 1; /* enables gaps, used by togglegaps */ -static int32_t axis_apply_time = 0; -static int32_t axis_apply_dir = 0; -static int32_t scroller_focus_lock = 0; - -static uint32_t swipe_fingers = 0; -static double swipe_dx = 0; -static double swipe_dy = 0; - -bool render_border = true; - -uint32_t chvt_backup_tag = 0; -bool allow_frame_scheduling = true; -char chvt_backup_selmon[32] = {0}; - -struct dvec2 *baked_points_move; -struct dvec2 *baked_points_open; -struct dvec2 *baked_points_tag; -struct dvec2 *baked_points_close; -struct dvec2 *baked_points_focus; -struct dvec2 *baked_points_opafadein; -struct dvec2 *baked_points_opafadeout; - -static struct wl_event_source *hide_source; -static bool cursor_hidden = false; -static bool tag_combo = false; -static const char *cli_config_path = NULL; - -static struct { - enum wp_cursor_shape_device_v1_shape shape; - struct wlr_surface *surface; - int32_t hotspot_x; - int32_t hotspot_y; -} last_cursor; #include "client/client.h" #include "config/preset.h" @@ -973,11 +990,116 @@ static struct wlr_xwayland *xwayland; #include "layout/vertical.h" void init_server() { + // 清零整个结构体 + memset(&server, 0, sizeof(Server)); + + // 初始化链表 + wl_list_init(&server.clients); + wl_list_init(&server.fstack); + wl_list_init(&server.fadeout_clients); + wl_list_init(&server.fadeout_layers); + wl_list_init(&server.inputdevices); + wl_list_init(&server.keyboard_shortcut_inhibitors); + wl_list_init(&server.mons); + + // 初始化 keymode server.keymode = (KeyMode){ .is_default = true, .is_common = false, .name = strdup("default"), }; + + // 初始化状态变量 + server.child_pid = -1; + server.enablegaps = 1; + server.render_border = true; + server.allow_frame_scheduling = true; + server.locked = false; + server.locked_mods = 0; + server.axis_apply_dir = 0; + server.axis_apply_time = 0; + server.scroller_focus_lock = 0; + server.cursor_mode = CurNormal; + server.cursor_hidden = false; + server.tag_combo = false; + server.start_drag_window = false; + server.rzcorner = 0; + server.grabcx = 0; + server.grabcy = 0; + server.drag_begin_cursorx = 0; + server.drag_begin_cursory = 0; + server.last_apply_drag_time = 0; + server.chvt_backup_tag = 0; + server.swipe_fingers = 0; + server.swipe_dx = 0.0; + server.swipe_dy = 0.0; + + // 初始化指针为 NULL + server.dpy = NULL; + server.event_loop = NULL; + server.backend = NULL; + server.headless_backend = NULL; + server.scene = NULL; + server.drw = NULL; + server.alloc = NULL; + server.compositor = NULL; + server.xdg_shell = NULL; + server.activation = NULL; + server.xdg_decoration_mgr = NULL; + server.idle_notifier = NULL; + server.idle_inhibit_mgr = NULL; + server.layer_shell = NULL; + server.output_mgr = NULL; + server.virtual_keyboard_mgr = NULL; + server.keyboard_shortcuts_inhibit = NULL; + server.virtual_pointer_mgr = NULL; + server.power_mgr = NULL; + server.pointer_gestures = NULL; + server.drm_lease_manager = NULL; + server.print_status_manager = NULL; + server.cursor = NULL; + server.cursor_mgr = NULL; + server.session = NULL; + server.root_bg = NULL; + server.session_lock_mgr = NULL; + server.locked_bg = NULL; + server.cur_lock = NULL; + server.drag_icon = NULL; + server.cursor_shape_mgr = NULL; + server.pointer_constraints = NULL; + server.relative_pointer_mgr = NULL; + server.active_constraint = NULL; + server.seat = NULL; + server.kb_group = NULL; + server.output_layout = NULL; + server.selmon = NULL; + server.baked_points_move = NULL; + server.baked_points_open = NULL; + server.baked_points_tag = NULL; + server.baked_points_close = NULL; + server.baked_points_focus = NULL; + server.baked_points_opafadein = NULL; + server.baked_points_opafadeout = NULL; + server.hide_source = NULL; + server.grabc = NULL; + server.exclusive_focus = NULL; + server.cli_config_path = NULL; + + // 初始化 server.last_cursor + server.last_cursor.shape = 0; + server.last_cursor.surface = NULL; + server.last_cursor.hotspot_x = 0; + server.last_cursor.hotspot_y = 0; + + // 清零数组 + memset(server.layers, 0, sizeof(server.layers)); + memset(server.chvt_backup_selmon, 0, sizeof(server.chvt_backup_selmon)); + + // 设置 server.sgeom 初始值 + server.sgeom.x = 0; + server.sgeom.y = 0; + server.sgeom.width = 0; + server.sgeom.height = 0; } void free_server() { free(server.keymode.name); } @@ -1007,7 +1129,7 @@ void applybounds(Client *c, struct wlr_box *bbox) { void clear_fullscreen_and_maximized_state(Monitor *m) { Client *fc = NULL; - wl_list_for_each(fc, &clients, link) { + wl_list_for_each(fc, &server.clients, link) { if (fc && VISIBLEON(fc, m) && ISFULLSCREEN(fc)) { clear_fullscreen_flag(fc); } @@ -1059,8 +1181,8 @@ void show_scratchpad(Client *c) { } c->oldtags = c->mon->tagset[c->mon->seltags]; - wl_list_remove(&c->link); // 从原来位置移除 - wl_list_insert(clients.prev->next, &c->link); // 插入开头 + wl_list_remove(&c->link); // 从原来位置移除 + wl_list_insert(server.clients.prev->next, &c->link); // 插入开头 show_hide_client(c); setborder_color(c); } @@ -1118,14 +1240,14 @@ void swallow(Client *c, Client *w) { bool switch_scratchpad_client_state(Client *c) { - if (scratchpad_cross_monitor && selmon && c->mon != selmon && + if (scratchpad_cross_monitor && server.selmon && c->mon != server.selmon && c->is_in_scratchpad) { // 保存原始monitor用于尺寸计算 Monitor *oldmon = c->mon; c->scratchpad_switching_mon = true; - c->mon = selmon; + c->mon = server.selmon; reset_foreign_tolevel(c); - client_update_oldmonname_record(c, selmon); + client_update_oldmonname_record(c, server.selmon); // 根据新monitor调整窗口尺寸 c->float_geom.width = @@ -1138,9 +1260,10 @@ bool switch_scratchpad_client_state(Client *c) { // 只有显示状态的scratchpad才需要聚焦和返回true if (c->is_scratchpad_show) { - c->tags = get_tags_first_tag(selmon->tagset[selmon->seltags]); + c->tags = get_tags_first_tag( + server.selmon->tagset[server.selmon->seltags]); resize(c, c->float_geom, 0); - arrange(selmon, false, false); + arrange(server.selmon, false, false); focusclient(c, true); c->scratchpad_switching_mon = false; return true; @@ -1170,9 +1293,9 @@ bool switch_scratchpad_client_state(Client *c) { void apply_named_scratchpad(Client *target_client) { Client *c = NULL; - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { - if (!scratchpad_cross_monitor && c->mon != selmon) { + if (!scratchpad_cross_monitor && c->mon != server.selmon) { continue; } @@ -1190,25 +1313,25 @@ void apply_named_scratchpad(Client *target_client) { } void gpureset(struct wl_listener *listener, void *data) { - struct wlr_renderer *old_drw = drw; - struct wlr_allocator *old_alloc = alloc; + struct wlr_renderer *old_drw = server.drw; + struct wlr_allocator *old_alloc = server.alloc; struct Monitor *m = NULL; wlr_log(WLR_DEBUG, "gpu reset"); - if (!(drw = fx_renderer_create(backend))) + if (!(server.drw = fx_renderer_create(server.backend))) die("couldn't recreate renderer"); - if (!(alloc = wlr_allocator_autocreate(backend, drw))) + if (!(server.alloc = wlr_allocator_autocreate(server.backend, server.drw))) die("couldn't recreate allocator"); wl_list_remove(&gpu_reset.link); - wl_signal_add(&drw->events.lost, &gpu_reset); + wl_signal_add(&server.drw->events.lost, &gpu_reset); - wlr_compositor_set_renderer(compositor, drw); + wlr_compositor_set_renderer(server.compositor, server.drw); - wl_list_for_each(m, &mons, link) { - wlr_output_init_render(m->wlr_output, alloc, drw); + wl_list_for_each(m, &server.mons, link) { + wlr_output_init_render(m->wlr_output, server.alloc, server.drw); } wlr_allocator_destroy(old_alloc); @@ -1229,10 +1352,10 @@ void toggle_hotarea(int32_t x_root, int32_t y_root) { // 在刚启动的时候,selmon为NULL,但鼠标可能已经处于热区, // 必须判断避免奔溃 - if (!selmon) + if (!server.selmon) return; - if (grabc) + if (server.grabc) return; // 根据热角位置计算不同的热区坐标 @@ -1240,21 +1363,21 @@ void toggle_hotarea(int32_t x_root, int32_t y_root) { switch (hotarea_corner) { case BOTTOM_RIGHT: // 右下角 - hx = selmon->m.x + selmon->m.width - hotarea_size; - hy = selmon->m.y + selmon->m.height - hotarea_size; + hx = server.selmon->m.x + server.selmon->m.width - hotarea_size; + hy = server.selmon->m.y + server.selmon->m.height - hotarea_size; break; case TOP_LEFT: // 左上角 - hx = selmon->m.x + hotarea_size; - hy = selmon->m.y + hotarea_size; + hx = server.selmon->m.x + hotarea_size; + hy = server.selmon->m.y + hotarea_size; break; case TOP_RIGHT: // 右上角 - hx = selmon->m.x + selmon->m.width - hotarea_size; - hy = selmon->m.y + hotarea_size; + hx = server.selmon->m.x + server.selmon->m.width - hotarea_size; + hy = server.selmon->m.y + hotarea_size; break; case BOTTOM_LEFT: // 左下角(默认) default: - hx = selmon->m.x + hotarea_size; - hy = selmon->m.y + selmon->m.height - hotarea_size; + hx = server.selmon->m.x + hotarea_size; + hy = server.selmon->m.y + server.selmon->m.height - hotarea_size; break; } @@ -1264,31 +1387,34 @@ void toggle_hotarea(int32_t x_root, int32_t y_root) { switch (hotarea_corner) { case BOTTOM_RIGHT: // 右下角 in_hotarea = (y_root > hy && x_root > hx && - x_root <= (selmon->m.x + selmon->m.width) && - y_root <= (selmon->m.y + selmon->m.height)); + x_root <= (server.selmon->m.x + server.selmon->m.width) && + y_root <= (server.selmon->m.y + server.selmon->m.height)); break; case TOP_LEFT: // 左上角 - in_hotarea = (y_root < hy && x_root < hx && x_root >= selmon->m.x && - y_root >= selmon->m.y); + in_hotarea = + (y_root < hy && x_root < hx && x_root >= server.selmon->m.x && + y_root >= server.selmon->m.y); break; case TOP_RIGHT: // 右上角 in_hotarea = (y_root < hy && x_root > hx && - x_root <= (selmon->m.x + selmon->m.width) && - y_root >= selmon->m.y); + x_root <= (server.selmon->m.x + server.selmon->m.width) && + y_root >= server.selmon->m.y); break; case BOTTOM_LEFT: // 左下角(默认) default: - in_hotarea = (y_root > hy && x_root < hx && x_root >= selmon->m.x && - y_root <= (selmon->m.y + selmon->m.height)); + in_hotarea = + (y_root > hy && x_root < hx && x_root >= server.selmon->m.x && + y_root <= (server.selmon->m.y + server.selmon->m.height)); break; } - if (enable_hotarea == 1 && selmon->is_in_hotarea == 0 && in_hotarea) { + if (enable_hotarea == 1 && server.selmon->is_in_hotarea == 0 && + in_hotarea) { toggleoverview(&arg); - selmon->is_in_hotarea = 1; - } else if (enable_hotarea == 1 && selmon->is_in_hotarea == 1 && + server.selmon->is_in_hotarea = 1; + } else if (enable_hotarea == 1 && server.selmon->is_in_hotarea == 1 && !in_hotarea) { - selmon->is_in_hotarea = 0; + server.selmon->is_in_hotarea = 0; } } @@ -1338,7 +1464,7 @@ void set_float_malposition(Client *tc) { yreverse = 1; offset = MIN(tc->mon->w.width / 20, tc->mon->w.height / 20); - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (c->isfloating && c != tc && VISIBLEON(c, tc->mon) && abs(x - c->geom.x) < offset && abs(y - c->geom.y) < offset) { @@ -1381,7 +1507,7 @@ void applyrules(Client *c) { parent = client_get_parent(c); - Monitor *mon = parent && parent->mon ? parent->mon : selmon; + Monitor *mon = parent && parent->mon ? parent->mon : server.selmon; c->isfloating = client_is_float_type(c) || parent; if (!(appid = client_get_appid(c))) @@ -1408,7 +1534,7 @@ void applyrules(Client *c) { } // set monitor of client - wl_list_for_each(m, &mons, link) { + wl_list_for_each(m, &server.mons, link) { if (regex_match(r->monitor, m->wlr_output->name)) { mon = m; } @@ -1489,7 +1615,8 @@ void applyrules(Client *c) { newtags & mon->tagset[mon->seltags])); if (c->mon && - !(c->mon == selmon && c->tags & c->mon->tagset[c->mon->seltags]) && + !(c->mon == server.selmon && + c->tags & c->mon->tagset[c->mon->seltags]) && !c->isopensilent && !c->istagsilent) { c->animation.tag_from_rule = true; view_in_mon(&(Arg){.ui = c->tags}, true, c->mon, true); @@ -1501,7 +1628,7 @@ void applyrules(Client *c) { if there is a new non-floating window in the current tag, the fullscreen window in the current tag will exit fullscreen and participate in tiling */ - wl_list_for_each(fc, &clients, + wl_list_for_each(fc, &server.clients, link) if (fc && fc != c && c->tags & fc->tags && VISIBLEON(fc, c->mon) && ISFULLSCREEN(fc) && !c->isfloating) { @@ -1511,7 +1638,7 @@ void applyrules(Client *c) { if (c->isfloating && !c->iscustompos && !c->isnamedscratchpad) { wl_list_remove(&c->link); - wl_list_insert(clients.prev, &c->link); + wl_list_insert(server.clients.prev, &c->link); set_float_malposition(c); } @@ -1522,7 +1649,7 @@ void applyrules(Client *c) { // apply overlay rule if (c->isoverlay) { - wlr_scene_node_reparent(&c->scene->node, layers[LyrOverlay]); + wlr_scene_node_reparent(&c->scene->node, server.layers[LyrOverlay]); wlr_scene_node_raise_to_top(&c->scene->node); } } @@ -1559,7 +1686,7 @@ void apply_window_snap(Client *c) { int32_t snap_up_mon = 0, snap_down_mon = 0, snap_left_mon = 0, snap_right_mon = 0; - uint32_t cbw = !render_border || c->fake_no_border ? borderpx : 0; + uint32_t cbw = !server.render_border || c->fake_no_border ? borderpx : 0; uint32_t tcbw; uint32_t cx, cy, cw, ch, tcx, tcy, tcw, tch; cx = c->geom.x + cbw; @@ -1574,11 +1701,11 @@ void apply_window_snap(Client *c) { if (!c->isfloating || !enable_floating_snap) return; - wl_list_for_each(tc, &clients, link) { + wl_list_for_each(tc, &server.clients, link) { if (tc && tc->isfloating && !tc->iskilling && client_surface(tc)->mapped && VISIBLEON(tc, c->mon)) { - tcbw = !render_border || tc->fake_no_border ? borderpx : 0; + tcbw = !server.render_border || tc->fake_no_border ? borderpx : 0; tcx = tc->geom.x + tcbw; tcy = tc->geom.y + tcbw; tcw = tc->geom.width - 2 * tcbw; @@ -1655,7 +1782,8 @@ void apply_window_snap(Client *c) { void focuslayer(LayerSurface *l) { focusclient(NULL, 0); dwl_im_relay_set_focus(dwl_input_method_relay, l->layer_surface->surface); - client_notify_enter(l->layer_surface->surface, wlr_seat_get_keyboard(seat)); + client_notify_enter(l->layer_surface->surface, + wlr_seat_get_keyboard(server.seat)); } void reset_exclusive_layer(Monitor *m) { @@ -1672,23 +1800,23 @@ void reset_exclusive_layer(Monitor *m) { for (i = 0; i < (int32_t)LENGTH(layers_above_shell); i++) { wl_list_for_each_reverse(l, &m->layers[layers_above_shell[i]], link) { - if (l == exclusive_focus && + if (l == server.exclusive_focus && l->layer_surface->current.keyboard_interactive != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE) - exclusive_focus = NULL; + server.exclusive_focus = NULL; if (l->layer_surface->current.keyboard_interactive == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE && l->layer_surface->surface == - seat->keyboard_state.focused_surface) - focusclient(focustop(selmon), 1); + server.seat->keyboard_state.focused_surface) + focusclient(focustop(server.selmon), 1); - if (locked || + if (server.locked || l->layer_surface->current.keyboard_interactive != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE || - !l->mapped || l == exclusive_focus) + !l->mapped || l == server.exclusive_focus) continue; /* Deactivate the focused client. */ - exclusive_focus = l; + server.exclusive_focus = l; focuslayer(l); return; } @@ -1722,8 +1850,8 @@ void arrangelayers(Monitor *m) { void // 鼠标滚轮事件 axisnotify(struct wl_listener *listener, void *data) { - /* This event is forwarded by the cursor when a pointer emits an axis event, - * for example when you move the scroll wheel. */ + /* This event is forwarded by the server.cursor when a pointer emits an axis + * event, for example when you move the scroll wheel. */ struct wlr_pointer_axis_event *event = data; struct wlr_keyboard *keyboard, *hard_keyboard; uint32_t mods, hard_mods; @@ -1732,16 +1860,16 @@ axisnotify(struct wl_listener *listener, void *data) { uint32_t adir; // IDLE_NOTIFY_ACTIVITY; handlecursoractivity(); - wlr_idle_notifier_v1_notify_activity(idle_notifier, seat); + wlr_idle_notifier_v1_notify_activity(server.idle_notifier, server.seat); if (check_trackpad_disabled(event->pointer)) { return; } - hard_keyboard = &kb_group->wlr_group->keyboard; + hard_keyboard = &server.kb_group->wlr_group->keyboard; hard_mods = hard_keyboard ? wlr_keyboard_get_modifiers(hard_keyboard) : 0; - keyboard = wlr_seat_get_keyboard(seat); + keyboard = wlr_seat_get_keyboard(server.seat); mods = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0; mods = mods | hard_mods; @@ -1757,15 +1885,16 @@ axisnotify(struct wl_listener *listener, void *data) { a = &config.axis_bindings[ji]; if (CLEANMASK(mods) == CLEANMASK(a->mod) && // 按键一致 adir == a->dir && a->func) { // 滚轮方向判断一致且处理函数存在 - if (event->time_msec - axis_apply_time > axis_bind_apply_timeout || - axis_apply_dir * event->delta < 0) { + if (event->time_msec - server.axis_apply_time > + axis_bind_apply_timeout || + server.axis_apply_dir * event->delta < 0) { a->func(&a->arg); - axis_apply_time = event->time_msec; - axis_apply_dir = event->delta > 0 ? 1 : -1; + server.axis_apply_time = event->time_msec; + server.axis_apply_dir = event->delta > 0 ? 1 : -1; return; // 如果成功匹配就不把这个滚轮事件传送给客户端了 } else { - axis_apply_dir = event->delta > 0 ? 1 : -1; - axis_apply_time = event->time_msec; + server.axis_apply_dir = event->delta > 0 ? 1 : -1; + server.axis_apply_time = event->time_msec; return; } } @@ -1776,7 +1905,7 @@ axisnotify(struct wl_listener *listener, void *data) { */ /* Notify the client with pointer focus of the axis event. */ wlr_seat_pointer_notify_axis( - seat, // 滚轮事件发送给客户端也就是窗口 + server.seat, // 滚轮事件发送给客户端也就是窗口 event->time_msec, event->orientation, event->delta * axis_scroll_factor, roundf(event->delta_discrete * axis_scroll_factor), event->source, event->relative_direction); @@ -1787,8 +1916,8 @@ int32_t ongesture(struct wlr_pointer_swipe_end_event *event) { uint32_t mods, hard_mods; const GestureBinding *g; uint32_t motion; - uint32_t adx = (int32_t)round(fabs(swipe_dx)); - uint32_t ady = (int32_t)round(fabs(swipe_dy)); + uint32_t adx = (int32_t)round(fabs(server.swipe_dx)); + uint32_t ady = (int32_t)round(fabs(server.swipe_dy)); int32_t handled = 0; int32_t ji; @@ -1802,15 +1931,15 @@ int32_t ongesture(struct wlr_pointer_swipe_end_event *event) { } if (adx > ady) { - motion = swipe_dx < 0 ? SWIPE_LEFT : SWIPE_RIGHT; + motion = server.swipe_dx < 0 ? SWIPE_LEFT : SWIPE_RIGHT; } else { - motion = swipe_dy < 0 ? SWIPE_UP : SWIPE_DOWN; + motion = server.swipe_dy < 0 ? SWIPE_UP : SWIPE_DOWN; } - hard_keyboard = &kb_group->wlr_group->keyboard; + hard_keyboard = &server.kb_group->wlr_group->keyboard; hard_mods = hard_keyboard ? wlr_keyboard_get_modifiers(hard_keyboard) : 0; - keyboard = wlr_seat_get_keyboard(seat); + keyboard = wlr_seat_get_keyboard(server.seat); mods = keyboard ? wlr_keyboard_get_modifiers(keyboard) : 0; mods = mods | hard_mods; @@ -1820,7 +1949,7 @@ int32_t ongesture(struct wlr_pointer_swipe_end_event *event) { break; g = &config.gesture_bindings[ji]; if (CLEANMASK(mods) == CLEANMASK(g->mod) && - swipe_fingers == g->fingers_count && motion == g->motion && + server.swipe_fingers == g->fingers_count && motion == g->motion && g->func) { g->func(&g->arg); handled = 1; @@ -1833,30 +1962,31 @@ void swipe_begin(struct wl_listener *listener, void *data) { struct wlr_pointer_swipe_begin_event *event = data; // Forward swipe begin event to client - wlr_pointer_gestures_v1_send_swipe_begin(pointer_gestures, seat, - event->time_msec, event->fingers); + wlr_pointer_gestures_v1_send_swipe_begin( + server.pointer_gestures, server.seat, event->time_msec, event->fingers); } void swipe_update(struct wl_listener *listener, void *data) { struct wlr_pointer_swipe_update_event *event = data; - swipe_fingers = event->fingers; + server.swipe_fingers = event->fingers; // Accumulate swipe distance - swipe_dx += event->dx; - swipe_dy += event->dy; + server.swipe_dx += event->dx; + server.swipe_dy += event->dy; // Forward swipe update event to client - wlr_pointer_gestures_v1_send_swipe_update( - pointer_gestures, seat, event->time_msec, event->dx, event->dy); + wlr_pointer_gestures_v1_send_swipe_update(server.pointer_gestures, + server.seat, event->time_msec, + event->dx, event->dy); } void swipe_end(struct wl_listener *listener, void *data) { struct wlr_pointer_swipe_end_event *event = data; ongesture(event); - swipe_dx = 0; - swipe_dy = 0; + server.swipe_dx = 0; + server.swipe_dy = 0; // Forward swipe end event to client - wlr_pointer_gestures_v1_send_swipe_end(pointer_gestures, seat, + wlr_pointer_gestures_v1_send_swipe_end(server.pointer_gestures, server.seat, event->time_msec, event->cancelled); } @@ -1864,8 +1994,8 @@ void pinch_begin(struct wl_listener *listener, void *data) { struct wlr_pointer_pinch_begin_event *event = data; // Forward pinch begin event to client - wlr_pointer_gestures_v1_send_pinch_begin(pointer_gestures, seat, - event->time_msec, event->fingers); + wlr_pointer_gestures_v1_send_pinch_begin( + server.pointer_gestures, server.seat, event->time_msec, event->fingers); } void pinch_update(struct wl_listener *listener, void *data) { @@ -1873,15 +2003,15 @@ void pinch_update(struct wl_listener *listener, void *data) { // Forward pinch update event to client wlr_pointer_gestures_v1_send_pinch_update( - pointer_gestures, seat, event->time_msec, event->dx, event->dy, - event->scale, event->rotation); + server.pointer_gestures, server.seat, event->time_msec, event->dx, + event->dy, event->scale, event->rotation); } void pinch_end(struct wl_listener *listener, void *data) { struct wlr_pointer_pinch_end_event *event = data; // Forward pinch end event to client - wlr_pointer_gestures_v1_send_pinch_end(pointer_gestures, seat, + wlr_pointer_gestures_v1_send_pinch_end(server.pointer_gestures, server.seat, event->time_msec, event->cancelled); } @@ -1889,15 +2019,15 @@ void hold_begin(struct wl_listener *listener, void *data) { struct wlr_pointer_hold_begin_event *event = data; // Forward hold begin event to client - wlr_pointer_gestures_v1_send_hold_begin(pointer_gestures, seat, - event->time_msec, event->fingers); + wlr_pointer_gestures_v1_send_hold_begin( + server.pointer_gestures, server.seat, event->time_msec, event->fingers); } void hold_end(struct wl_listener *listener, void *data) { struct wlr_pointer_hold_end_event *event = data; // Forward hold end event to client - wlr_pointer_gestures_v1_send_hold_end(pointer_gestures, seat, + wlr_pointer_gestures_v1_send_hold_end(server.pointer_gestures, server.seat, event->time_msec, event->cancelled); } @@ -1908,10 +2038,10 @@ void place_drag_tile_client(Client *c) { long temp_distant; int32_t x, y; - wl_list_for_each(tc, &clients, link) { + wl_list_for_each(tc, &server.clients, link) { if (tc != c && ISTILED(tc) && VISIBLEON(tc, c->mon)) { - x = tc->geom.x + (int32_t)(tc->geom.width / 2) - cursor->x; - y = tc->geom.y + (int32_t)(tc->geom.height / 2) - cursor->y; + x = tc->geom.x + (int32_t)(tc->geom.width / 2) - server.cursor->x; + y = tc->geom.y + (int32_t)(tc->geom.height / 2) - server.cursor->y; temp_distant = x * x + y * y; if (temp_distant < min_distant) { min_distant = temp_distant; @@ -1961,10 +2091,10 @@ buttonpress(struct wl_listener *listener, void *data) { int32_t ji; const MouseBinding *m; struct wlr_surface *old_pointer_focus_surface = - seat->pointer_state.focused_surface; + server.seat->pointer_state.focused_surface; handlecursoractivity(); - wlr_idle_notifier_v1_notify_activity(idle_notifier, seat); + wlr_idle_notifier_v1_notify_activity(server.idle_notifier, server.seat); if (check_trackpad_disabled(event->pointer)) { return; @@ -1972,24 +2102,25 @@ buttonpress(struct wl_listener *listener, void *data) { switch (event->state) { case WL_POINTER_BUTTON_STATE_PRESSED: - cursor_mode = CurPressed; - selmon = xytomon(cursor->x, cursor->y); - if (locked) + server.cursor_mode = CurPressed; + server.selmon = xytomon(server.cursor->x, server.cursor->y); + if (server.locked) break; - xytonode(cursor->x, cursor->y, &surface, NULL, NULL, NULL, NULL); + xytonode(server.cursor->x, server.cursor->y, &surface, NULL, NULL, NULL, + NULL); if (toplevel_from_wlr_surface(surface, &c, &l) >= 0) { if (c && c->scene->node.enabled && (!client_is_unmanaged(c) || client_wants_focus(c))) focusclient(c, 1); if (surface != old_pointer_focus_surface) { - wlr_seat_pointer_notify_clear_focus(seat); + wlr_seat_pointer_notify_clear_focus(server.seat); motionnotify(0, NULL, 0, 0, 0, 0); } // 聚焦按需要交互焦点的layer,但注意不能抢占独占焦点的layer - if (l && !exclusive_focus && + if (l && !server.exclusive_focus && l->layer_surface->current.keyboard_interactive == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ON_DEMAND) { focuslayer(l); @@ -1998,11 +2129,11 @@ buttonpress(struct wl_listener *listener, void *data) { // 当鼠标焦点在layer上的时候,不检测虚拟键盘的mod状态, // 避免layer虚拟键盘锁死mod按键状态 - hard_keyboard = &kb_group->wlr_group->keyboard; + hard_keyboard = &server.kb_group->wlr_group->keyboard; hard_mods = hard_keyboard ? wlr_keyboard_get_modifiers(hard_keyboard) : 0; - keyboard = wlr_seat_get_keyboard(seat); + keyboard = wlr_seat_get_keyboard(server.seat); mods = keyboard && !l ? wlr_keyboard_get_modifiers(keyboard) : 0; mods = mods | hard_mods; @@ -2013,7 +2144,8 @@ buttonpress(struct wl_listener *listener, void *data) { m = &config.mouse_bindings[ji]; if (CLEANMASK(mods) == CLEANMASK(m->mod) && event->button == m->button && m->func && - (selmon->isoverview == 1 || m->button == BTN_MIDDLE) && c) { + (server.selmon->isoverview == 1 || m->button == BTN_MIDDLE) && + c) { m->func(&m->arg); return; } else if (CLEANMASK(mods) == CLEANMASK(m->mod) && @@ -2026,26 +2158,28 @@ buttonpress(struct wl_listener *listener, void *data) { break; case WL_POINTER_BUTTON_STATE_RELEASED: /* If you released any buttons, we exit interactive move/resize mode. */ - if (!locked && cursor_mode != CurNormal && cursor_mode != CurPressed) { - cursor_mode = CurNormal; - /* Clear the pointer focus, this way if the cursor is over a surface - * we will send an enter event after which the client will provide - * us a cursor surface */ - wlr_seat_pointer_clear_focus(seat); + if (!server.locked && server.cursor_mode != CurNormal && + server.cursor_mode != CurPressed) { + server.cursor_mode = CurNormal; + /* Clear the pointer focus, this way if the server.cursor is over a + * surface we will send an enter event after which the client will + * provide us a server.cursor surface */ + wlr_seat_pointer_clear_focus(server.seat); motionnotify(0, NULL, 0, 0, 0, 0); /* Drop the window off on its new monitor */ - if (grabc == selmon->sel) { - selmon->sel = NULL; + if (server.grabc == server.selmon->sel) { + server.selmon->sel = NULL; } - selmon = xytomon(cursor->x, cursor->y); - client_update_oldmonname_record(grabc, selmon); - setmon(grabc, selmon, 0, true); - selmon->prevsel = ISTILED(selmon->sel) ? selmon->sel : NULL; - selmon->sel = grabc; - tmpc = grabc; - grabc = NULL; - start_drag_window = false; - last_apply_drap_time = 0; + server.selmon = xytomon(server.cursor->x, server.cursor->y); + client_update_oldmonname_record(server.grabc, server.selmon); + setmon(server.grabc, server.selmon, 0, true); + server.selmon->prevsel = + ISTILED(server.selmon->sel) ? server.selmon->sel : NULL; + server.selmon->sel = server.grabc; + tmpc = server.grabc; + server.grabc = NULL; + server.start_drag_window = false; + server.last_apply_drag_time = 0; if (tmpc->drag_to_tile && drag_tile_to_tile) { place_drag_tile_client(tmpc); } else { @@ -2054,13 +2188,13 @@ buttonpress(struct wl_listener *listener, void *data) { tmpc->drag_to_tile = false; return; } else { - cursor_mode = CurNormal; + server.cursor_mode = CurNormal; } break; } - /* If the event wasn't handled by the compositor, notify the client with - * pointer focus that a button press has occurred */ - wlr_seat_pointer_notify_button(seat, event->time_msec, event->button, + /* If the event wasn't handled by the server.compositor, notify the client + * with pointer focus that a button press has occurred */ + wlr_seat_pointer_notify_button(server.seat, event->time_msec, event->button, event->state); } @@ -2070,7 +2204,7 @@ void checkidleinhibitor(struct wlr_surface *exclude) { struct wlr_surface *surface = NULL; struct wlr_idle_inhibitor_v1 *inhibitor; - wl_list_for_each(inhibitor, &idle_inhibit_mgr->inhibitors, link) { + wl_list_for_each(inhibitor, &server.idle_inhibit_mgr->inhibitors, link) { surface = wlr_surface_get_root_surface(inhibitor->surface); if (exclude == surface) { @@ -2091,21 +2225,21 @@ void checkidleinhibitor(struct wlr_surface *exclude) { } } - wlr_idle_notifier_v1_set_inhibited(idle_notifier, inhibited); + wlr_idle_notifier_v1_set_inhibited(server.idle_notifier, inhibited); } void setcursorshape(struct wl_listener *listener, void *data) { struct wlr_cursor_shape_manager_v1_request_set_shape_event *event = data; - if (cursor_mode != CurNormal && cursor_mode != CurPressed) + if (server.cursor_mode != CurNormal && server.cursor_mode != CurPressed) return; /* This can be sent by any client, so we check to make sure this one is - * actually has pointer focus first. If so, we can tell the cursor to - * use the provided cursor shape. */ - if (event->seat_client == seat->pointer_state.focused_client) { - last_cursor.shape = event->shape; - last_cursor.surface = NULL; - if (!cursor_hidden) - wlr_cursor_set_xcursor(cursor, cursor_mgr, + * actually has pointer focus first. If so, we can tell the server.cursor to + * use the provided server.cursor shape. */ + if (event->seat_client == server.seat->pointer_state.focused_client) { + server.last_cursor.shape = event->shape; + server.last_cursor.surface = NULL; + if (!server.cursor_hidden) + wlr_cursor_set_xcursor(server.cursor, server.cursor_mgr, wlr_cursor_shape_v1_name(event->shape)); } } @@ -2142,7 +2276,7 @@ void cleanuplisteners(void) { wl_list_remove(&new_session_lock.link); wl_list_remove(&tearing_new_object.link); wl_list_remove(&keyboard_shortcuts_inhibit_new_inhibitor.link); - if (drm_lease_manager) { + if (server.drm_lease_manager) { wl_list_remove(&drm_lease_request.link); } #ifdef XWAYLAND @@ -2158,25 +2292,26 @@ void cleanup(void) { xwayland = NULL; #endif - wl_display_destroy_clients(dpy); - if (child_pid > 0) { - kill(-child_pid, SIGTERM); - waitpid(child_pid, NULL, 0); + wl_display_destroy_clients(server.dpy); + if (server.child_pid > 0) { + kill(-server.child_pid, SIGTERM); + waitpid(server.child_pid, NULL, 0); } - wlr_xcursor_manager_destroy(cursor_mgr); + wlr_xcursor_manager_destroy(server.cursor_mgr); - destroykeyboardgroup(&kb_group->destroy, NULL); + destroykeyboardgroup(&server.kb_group->destroy, NULL); dwl_im_relay_finish(dwl_input_method_relay); /* If it's not destroyed manually it will cause a use-after-free of * wlr_seat. Destroy it until it's fixed in the wlroots side */ - wlr_backend_destroy(backend); + wlr_backend_destroy(server.backend); - wl_display_destroy(dpy); + wl_display_destroy(server.dpy); /* Destroy after the wayland display (when the monitors are already - destroyed) to avoid destroying them with an invalid scene output. */ - wlr_scene_node_destroy(&scene->tree.node); + destroyed) to avoid destroying them with an invalid server.scene output. + */ + wlr_scene_node_destroy(&server.scene->tree.node); free_server(); } @@ -2204,7 +2339,7 @@ void cleanupmon(struct wl_listener *listener, void *data) { if (m->lock_surface) destroylocksurface(&m->destroy_lock_surface, NULL); m->wlr_output->data = NULL; - wlr_output_layout_remove(output_layout, m->wlr_output); + wlr_output_layout_remove(server.output_layout, m->wlr_output); wlr_scene_output_destroy(m->scene_output); closemon(m); @@ -2218,29 +2353,30 @@ void cleanupmon(struct wl_listener *listener, void *data) { } void closemon(Monitor *m) { - /* update selmon if needed and - * move closed monitor's clients to the focused one */ + /* update server.selmon if needed and + * move closed monitor's server.clients to the focused one */ Client *c = NULL; - int32_t i = 0, nmons = wl_list_length(&mons); + int32_t i = 0, nmons = wl_list_length(&server.mons); if (!nmons) { - selmon = NULL; - } else if (m == selmon) { - do /* don't switch to disabled mons */ - selmon = wl_container_of(mons.next, selmon, link); - while (!selmon->wlr_output->enabled && i++ < nmons); + server.selmon = NULL; + } else if (m == server.selmon) { + do /* don't switch to disabled server.mons */ + server.selmon = + wl_container_of(server.mons.next, server.selmon, link); + while (!server.selmon->wlr_output->enabled && i++ < nmons); - if (!selmon->wlr_output->enabled) - selmon = NULL; + if (!server.selmon->wlr_output->enabled) + server.selmon = NULL; } - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (c->mon == m) { - if (selmon == NULL) { + if (server.selmon == NULL) { remove_foreign_topleve(c); c->mon = NULL; } else { - client_change_mon(c, selmon); + client_change_mon(c, server.selmon); } // record the oldmonname which is used to restore if (c->oldmonname[0] == '\0') { @@ -2248,8 +2384,8 @@ void closemon(Monitor *m) { } } } - if (selmon) { - focusclient(focustop(selmon), 1); + if (server.selmon) { + focusclient(focustop(server.selmon), 1); printstatus(); } } @@ -2331,7 +2467,7 @@ void maplayersurfacenotify(struct wl_listener *listener, void *data) { arrangelayers(l->mon); // 按需交互layer需要像正常窗口一样抢占非独占layer的焦点 - if (!exclusive_focus && + if (!server.exclusive_focus && l->layer_surface->current.keyboard_interactive == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ON_DEMAND) { focuslayer(l); @@ -2342,7 +2478,7 @@ void commitlayersurfacenotify(struct wl_listener *listener, void *data) { LayerSurface *l = wl_container_of(listener, l, surface_commit); struct wlr_layer_surface_v1 *layer_surface = l->layer_surface; struct wlr_scene_tree *scene_layer = - layers[layermap[layer_surface->current.layer]]; + server.layers[layermap[layer_surface->current.layer]]; struct wlr_layer_surface_v1_state old_state; struct wlr_box box; @@ -2408,10 +2544,10 @@ void commitlayersurfacenotify(struct wl_listener *listener, void *data) { } } - if (layer_surface == exclusive_focus && + if (layer_surface == server.exclusive_focus && layer_surface->current.keyboard_interactive != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE) - exclusive_focus = NULL; + server.exclusive_focus = NULL; if (layer_surface->current.committed == 0 && l->mapped == layer_surface->surface->mapped) @@ -2425,7 +2561,7 @@ void commitlayersurfacenotify(struct wl_listener *listener, void *data) { wlr_scene_node_reparent( &l->popups->node, (layer_surface->current.layer < ZWLR_LAYER_SHELL_V1_LAYER_TOP - ? layers[LyrTop] + ? server.layers[LyrTop] : scene_layer)); } @@ -2490,7 +2626,7 @@ void commitnotify(struct wl_listener *listener, void *data) { new_geo->x != 0 || new_geo->y != 0; } - if (c == grabc || !c->dirty) + if (c == server.grabc || !c->dirty) return; resize(c, c->geom, 0); @@ -2576,16 +2712,17 @@ void createkeyboard(struct wlr_keyboard *keyboard) { wl_signal_add(&keyboard->base.events.destroy, &input_dev->destroy_listener); - wl_list_insert(&inputdevices, &input_dev->link); + wl_list_insert(&server.inputdevices, &input_dev->link); } /* Set the keymap to match the group keymap */ - wlr_keyboard_set_keymap(keyboard, kb_group->wlr_group->keyboard.keymap); + wlr_keyboard_set_keymap(keyboard, + server.kb_group->wlr_group->keyboard.keymap); - wlr_keyboard_notify_modifiers(keyboard, 0, 0, locked_mods, 0); + wlr_keyboard_notify_modifiers(keyboard, 0, 0, server.locked_mods, 0); /* Add the new keyboard to the group */ - wlr_keyboard_group_add_keyboard(kb_group->wlr_group, keyboard); + wlr_keyboard_group_add_keyboard(server.kb_group->wlr_group, keyboard); } KeyboardGroup *createkeyboardgroup(void) { @@ -2608,19 +2745,19 @@ KeyboardGroup *createkeyboardgroup(void) { xkb_mod_index_t mod_index = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_NUM); if (mod_index != XKB_MOD_INVALID) - locked_mods |= (uint32_t)1 << mod_index; + server.locked_mods |= (uint32_t)1 << mod_index; } if (capslock) { xkb_mod_index_t mod_index = xkb_keymap_mod_get_index(keymap, XKB_MOD_NAME_CAPS); if (mod_index != XKB_MOD_INVALID) - locked_mods |= (uint32_t)1 << mod_index; + server.locked_mods |= (uint32_t)1 << mod_index; } - if (locked_mods) + if (server.locked_mods) wlr_keyboard_notify_modifiers(&group->wlr_group->keyboard, 0, 0, - locked_mods, 0); + server.locked_mods, 0); xkb_keymap_unref(keymap); xkb_context_unref(context); @@ -2634,14 +2771,15 @@ KeyboardGroup *createkeyboardgroup(void) { keypressmod); group->key_repeat_source = - wl_event_loop_add_timer(event_loop, keyrepeat, group); + wl_event_loop_add_timer(server.event_loop, keyrepeat, group); - /* A seat can only have one keyboard, but this is a limitation of the - * Wayland protocol - not wlroots. We assign all connected keyboards to the - * same wlr_keyboard_group, which provides a single wlr_keyboard interface - * for all of them. Set this combined wlr_keyboard as the seat keyboard. + /* A server.seat can only have one keyboard, but this is a limitation of + * the Wayland protocol - not wlroots. We assign all connected keyboards to + * the same wlr_keyboard_group, which provides a single wlr_keyboard + * interface for all of them. Set this combined wlr_keyboard as the + * server.seat keyboard. */ - wlr_seat_set_keyboard(seat, &group->wlr_group->keyboard); + wlr_seat_set_keyboard(server.seat, &group->wlr_group->keyboard); return group; } @@ -2650,10 +2788,11 @@ void createlayersurface(struct wl_listener *listener, void *data) { LayerSurface *l = NULL; struct wlr_surface *surface = layer_surface->surface; struct wlr_scene_tree *scene_layer = - layers[layermap[layer_surface->pending.layer]]; + server.layers[layermap[layer_surface->pending.layer]]; if (!layer_surface->output && - !(layer_surface->output = selmon ? selmon->wlr_output : NULL)) { + !(layer_surface->output = + server.selmon ? server.selmon->wlr_output : NULL)) { wlr_layer_surface_v1_destroy(layer_surface); return; } @@ -2672,7 +2811,7 @@ void createlayersurface(struct wl_listener *listener, void *data) { l->scene = l->scene_layer->tree; l->popups = surface->data = wlr_scene_tree_create( layer_surface->current.layer < ZWLR_LAYER_SHELL_V1_LAYER_TOP - ? layers[LyrTop] + ? server.layers[LyrTop] : scene_layer); l->scene->node.data = l->popups->node.data = l; @@ -2697,8 +2836,9 @@ void createlocksurface(struct wl_listener *listener, void *data) { LISTEN(&lock_surface->events.destroy, &m->destroy_lock_surface, destroylocksurface); - if (m == selmon) - client_notify_enter(lock_surface->surface, wlr_seat_get_keyboard(seat)); + if (m == server.selmon) + client_notify_enter(lock_surface->surface, + wlr_seat_get_keyboard(server.seat)); } struct wlr_output_mode *get_nearest_output_mode(struct wlr_output *output, @@ -2735,8 +2875,8 @@ void enable_adaptive_sync(Monitor *m, struct wlr_output_state *state) { } void createmon(struct wl_listener *listener, void *data) { - /* This event is raised by the backend when a new output (aka a display or - * monitor) becomes available. */ + /* This event is raised by the server.backend when a new output (aka a + * display or monitor) becomes available. */ struct wlr_output *wlr_output = data; const ConfigMonitorRule *r; uint32_t i; @@ -2746,12 +2886,12 @@ void createmon(struct wl_listener *listener, void *data) { struct wlr_output_mode *internal_mode = NULL; bool custom_monitor_mode = false; - if (!wlr_output_init_render(wlr_output, alloc, drw)) + if (!wlr_output_init_render(wlr_output, server.alloc, server.drw)) return; if (wlr_output->non_desktop) { - if (drm_lease_manager) { - wlr_drm_lease_v1_manager_offer_output(drm_lease_manager, + if (server.drm_lease_manager) { + wlr_drm_lease_v1_manager_offer_output(server.drm_lease_manager, wlr_output); } return; @@ -2820,8 +2960,8 @@ void createmon(struct wl_listener *listener, void *data) { /* The mode is a tuple of (width, height, refresh rate), and each * monitor supports only a specific set of modes. We just pick the - * monitor's preferred mode; a more sophisticated compositor would let - * the user configure it. */ + * monitor's preferred mode; a more sophisticated server.compositor would + * let the user configure it. */ if (!custom_monitor_mode) wlr_output_state_set_mode(&state, wlr_output_preferred_mode(wlr_output)); @@ -2836,14 +2976,15 @@ void createmon(struct wl_listener *listener, void *data) { wlr_output_commit_state(wlr_output, &state); wlr_output_state_finish(&state); - wl_list_insert(&mons, &m->link); + wl_list_insert(&server.mons, &m->link); m->pertag = calloc(1, sizeof(Pertag)); - if (chvt_backup_tag && - regex_match(chvt_backup_selmon, m->wlr_output->name)) { - m->tagset[0] = m->tagset[1] = (1 << (chvt_backup_tag - 1)) & TAGMASK; - m->pertag->curtag = m->pertag->prevtag = chvt_backup_tag; - chvt_backup_tag = 0; - memset(chvt_backup_selmon, 0, sizeof(chvt_backup_selmon)); + if (server.chvt_backup_tag && + regex_match(server.chvt_backup_selmon, m->wlr_output->name)) { + m->tagset[0] = m->tagset[1] = + (1 << (server.chvt_backup_tag - 1)) & TAGMASK; + m->pertag->curtag = m->pertag->prevtag = server.chvt_backup_tag; + server.chvt_backup_tag = 0; + memset(server.chvt_backup_selmon, 0, sizeof(server.chvt_backup_selmon)); } else { m->tagset[0] = m->tagset[1] = 1; m->pertag->curtag = m->pertag->prevtag = 1; @@ -2860,9 +3001,9 @@ void createmon(struct wl_listener *listener, void *data) { /* The xdg-protocol specifies: * - * If the fullscreened surface is not opaque, the compositor must make - * sure that other screen content not part of the same surface tree (made - * up of subsurfaces, popups or similarly coupled surfaces) are not + * If the fullscreened surface is not opaque, the server.compositor must + * make sure that other screen content not part of the same surface tree + * (made up of subsurfaces, popups or similarly coupled surfaces) are not * visible below the fullscreened surface. * */ @@ -2870,19 +3011,19 @@ void createmon(struct wl_listener *listener, void *data) { /* Adds this to the output layout in the order it was configured. * * The output layout utility automatically adds a wl_output global to the - * display, which Wayland clients can see to find out information about the - * output (such as DPI, scale factor, manufacturer, etc). + * display, which Wayland server.clients can see to find out information + * about the output (such as DPI, scale factor, manufacturer, etc). */ - m->scene_output = wlr_scene_output_create(scene, wlr_output); + m->scene_output = wlr_scene_output_create(server.scene, wlr_output); if (m->m.x == INT32_MAX || m->m.y == INT32_MAX) - wlr_output_layout_add_auto(output_layout, wlr_output); + wlr_output_layout_add_auto(server.output_layout, wlr_output); else - wlr_output_layout_add(output_layout, wlr_output, m->m.x, m->m.y); + wlr_output_layout_add(server.output_layout, wlr_output, m->m.x, m->m.y); if (blur) { - m->blur = wlr_scene_optimized_blur_create(&scene->tree, 0, 0); + m->blur = wlr_scene_optimized_blur_create(&server.scene->tree, 0, 0); wlr_scene_node_set_position(&m->blur->node, m->m.x, m->m.y); - wlr_scene_node_reparent(&m->blur->node, layers[LyrBlur]); + wlr_scene_node_reparent(&m->blur->node, server.layers[LyrBlur]); wlr_scene_optimized_blur_set_size(m->blur, m->m.width, m->m.height); // wlr_scene_node_set_enabled(&m->blur->node, 1); } @@ -3019,9 +3160,9 @@ void createpointer(struct wlr_pointer *pointer) { wl_signal_add(&pointer->base.events.destroy, &input_dev->destroy_listener); - wl_list_insert(&inputdevices, &input_dev->link); + wl_list_insert(&server.inputdevices, &input_dev->link); } - wlr_cursor_attach_input_device(cursor, &pointer->base); + wlr_cursor_attach_input_device(server.cursor, &pointer->base); } void switch_toggle(struct wl_listener *listener, void *data) { @@ -3073,7 +3214,7 @@ void createswitch(struct wlr_switch *switch_device) { wl_signal_add(&switch_device->events.toggle, &sw->toggle); // 添加到全局列表 - wl_list_insert(&inputdevices, &input_dev->link); + wl_list_insert(&server.inputdevices, &input_dev->link); } } @@ -3093,42 +3234,42 @@ void createpopup(struct wl_listener *listener, void *data) { } void cursorconstrain(struct wlr_pointer_constraint_v1 *constraint) { - if (active_constraint == constraint) + if (server.active_constraint == constraint) return; - if (active_constraint) - wlr_pointer_constraint_v1_send_deactivated(active_constraint); + if (server.active_constraint) + wlr_pointer_constraint_v1_send_deactivated(server.active_constraint); - active_constraint = constraint; + server.active_constraint = constraint; wlr_pointer_constraint_v1_send_activated(constraint); } void cursorframe(struct wl_listener *listener, void *data) { - /* This event is forwarded by the cursor when a pointer emits an frame - * event. Frame events are sent after regular pointer events to group + /* This event is forwarded by the server.cursor when a pointer emits an + * frame event. Frame events are sent after regular pointer events to group * multiple events together. For instance, two axis events may happen at * the same time, in which case a frame event won't be sent in between. */ /* Notify the client with pointer focus of the frame event. */ - wlr_seat_pointer_notify_frame(seat); + wlr_seat_pointer_notify_frame(server.seat); } void cursorwarptohint(void) { Client *c = NULL; - double sx = active_constraint->current.cursor_hint.x; - double sy = active_constraint->current.cursor_hint.y; + double sx = server.active_constraint->current.cursor_hint.x; + double sy = server.active_constraint->current.cursor_hint.y; - toplevel_from_wlr_surface(active_constraint->surface, &c, NULL); - if (c && active_constraint->current.cursor_hint.enabled) { - wlr_cursor_warp(cursor, NULL, sx + c->geom.x + c->bw, + toplevel_from_wlr_surface(server.active_constraint->surface, &c, NULL); + if (c && server.active_constraint->current.cursor_hint.enabled) { + wlr_cursor_warp(server.cursor, NULL, sx + c->geom.x + c->bw, sy + c->geom.y + c->bw); - wlr_seat_pointer_warp(active_constraint->seat, sx, sy); + wlr_seat_pointer_warp(server.active_constraint->seat, sx, sy); } } void destroydragicon(struct wl_listener *listener, void *data) { /* Focus enter isn't sent during drag, so refocus the focused node. */ - focusclient(focustop(selmon), 1); + focusclient(focustop(server.selmon), 1); motionnotify(0, NULL, 0, 0, 0, 0); wl_list_remove(&listener->link); free(listener); @@ -3156,15 +3297,15 @@ void destroylayernodenotify(struct wl_listener *listener, void *data) { } void destroylock(SessionLock *lock, int32_t unlock) { - wlr_seat_keyboard_notify_clear_focus(seat); - if ((locked = !unlock)) + wlr_seat_keyboard_notify_clear_focus(server.seat); + if ((server.locked = !unlock)) goto destroy; - if (locked_bg->node.enabled) { - wlr_scene_node_set_enabled(&locked_bg->node, false); + if (server.locked_bg->node.enabled) { + wlr_scene_node_set_enabled(&server.locked_bg->node, false); } - focusclient(focustop(selmon), 0); + focusclient(focustop(server.selmon), 0); motionnotify(0, NULL, 0, 0, 0, 0); destroy: @@ -3173,7 +3314,7 @@ destroy: wl_list_remove(&lock->destroy.link); wlr_scene_node_destroy(&lock->scene->node); - cur_lock = NULL; + server.cur_lock = NULL; free(lock); } @@ -3185,23 +3326,26 @@ void destroylocksurface(struct wl_listener *listener, void *data) { m->lock_surface = NULL; wl_list_remove(&m->destroy_lock_surface.link); - if (lock_surface->surface != seat->keyboard_state.focused_surface) { - if (exclusive_focus && !locked) { - exclusive_focus = NULL; + if (lock_surface->surface != server.seat->keyboard_state.focused_surface) { + if (server.exclusive_focus && !server.locked) { + server.exclusive_focus = NULL; reset_exclusive_layer(m); } return; } - if (locked && cur_lock && !wl_list_empty(&cur_lock->surfaces)) { - surface = wl_container_of(cur_lock->surfaces.next, surface, link); - client_notify_enter(surface->surface, wlr_seat_get_keyboard(seat)); - } else if (!locked) { - exclusive_focus = NULL; - reset_exclusive_layer(selmon); - focusclient(focustop(selmon), 1); + if (server.locked && server.cur_lock && + !wl_list_empty(&server.cur_lock->surfaces)) { + surface = + wl_container_of(server.cur_lock->surfaces.next, surface, link); + client_notify_enter(surface->surface, + wlr_seat_get_keyboard(server.seat)); + } else if (!server.locked) { + server.exclusive_focus = NULL; + reset_exclusive_layer(server.selmon); + focusclient(focustop(server.selmon), 1); } else { - wlr_seat_keyboard_clear_focus(seat); + wlr_seat_keyboard_clear_focus(server.seat); } } @@ -3235,9 +3379,9 @@ void destroypointerconstraint(struct wl_listener *listener, void *data) { PointerConstraint *pointer_constraint = wl_container_of(listener, pointer_constraint, destroy); - if (active_constraint == pointer_constraint->constraint) { + if (server.active_constraint == pointer_constraint->constraint) { cursorwarptohint(); - active_constraint = NULL; + server.active_constraint = NULL; } wl_list_remove(&pointer_constraint->destroy.link); @@ -3265,9 +3409,9 @@ void focusclient(Client *c, int32_t lift) { Monitor *um = NULL; struct wlr_surface *old_keyboard_focus_surface = - seat->keyboard_state.focused_surface; + server.seat->keyboard_state.focused_surface; - if (locked) + if (server.locked) return; if (c && c->iskilling) @@ -3286,22 +3430,22 @@ void focusclient(Client *c, int32_t lift) { if (c && lift) wlr_scene_node_raise_to_top(&c->scene->node); // 将视图提升到顶层 - if (c && client_surface(c) == old_keyboard_focus_surface && selmon && - selmon->sel) + if (c && client_surface(c) == old_keyboard_focus_surface && server.selmon && + server.selmon->sel) return; - if (selmon && selmon->sel && selmon->sel != c && - selmon->sel->foreign_toplevel) { + if (server.selmon && server.selmon->sel && server.selmon->sel != c && + server.selmon->sel->foreign_toplevel) { wlr_foreign_toplevel_handle_v1_set_activated( - selmon->sel->foreign_toplevel, false); + server.selmon->sel->foreign_toplevel, false); } if (c && !c->iskilling && !client_is_unmanaged(c) && c->mon) { - last_focus_client = selmon->sel; - selmon = c->mon; - selmon->prevsel = selmon->sel; - selmon->sel = c; + last_focus_client = server.selmon->sel; + server.selmon = c->mon; + server.selmon->prevsel = server.selmon->sel; + server.selmon->sel = c; c->isfocusing = true; if (last_focus_client && !last_focus_client->iskilling && @@ -3314,24 +3458,25 @@ void focusclient(Client *c, int32_t lift) { // decide whether need to re-arrange - if (c && selmon->prevsel && - (selmon->prevsel->tags & selmon->tagset[selmon->seltags]) && - (c->tags & selmon->tagset[selmon->seltags]) && !c->isfloating && - is_scroller_layout(selmon)) { - arrange(selmon, false, false); + if (c && server.selmon->prevsel && + (server.selmon->prevsel->tags & + server.selmon->tagset[server.selmon->seltags]) && + (c->tags & server.selmon->tagset[server.selmon->seltags]) && + !c->isfloating && is_scroller_layout(server.selmon)) { + arrange(server.selmon, false, false); } // change focus link position wl_list_remove(&c->flink); - wl_list_insert(&fstack, &c->flink); + wl_list_insert(&server.fstack, &c->flink); // change border color c->isurgent = 0; } // update other monitor focus disappear - wl_list_for_each(um, &mons, link) { - if (um->wlr_output->enabled && um != selmon && um->sel && + wl_list_for_each(um, &server.mons, link) { + if (um->wlr_output->enabled && um != server.selmon && um->sel && !um->sel->iskilling && um->sel->isfocusing) { um->sel->isfocusing = false; client_set_unfocused_opacity_animation(um->sel); @@ -3344,23 +3489,23 @@ void focusclient(Client *c, int32_t lift) { /* Deactivate old client if focus is changing */ if (old_keyboard_focus_surface && (!c || client_surface(c) != old_keyboard_focus_surface)) { - /* If an exclusive_focus layer is focused, don't focus or activate - * the client, but only update its position in fstack to render its - * border with focuscolor and focus it after the exclusive_focus - * layer is closed. */ + /* If an server.exclusive_focus layer is focused, don't focus or + * activate the client, but only update its position in server.fstack to + * render its border with focuscolor and focus it after the + * server.exclusive_focus layer is closed. */ Client *w = NULL; LayerSurface *l = NULL; int32_t type = toplevel_from_wlr_surface(old_keyboard_focus_surface, &w, &l); if (type == LayerShell && l->scene->node.enabled && l->layer_surface->current.layer >= ZWLR_LAYER_SHELL_V1_LAYER_TOP && - l == exclusive_focus) { + l == server.exclusive_focus) { return; - } else if (w && w == exclusive_focus && client_wants_focus(w)) { + } else if (w && w == server.exclusive_focus && client_wants_focus(w)) { return; /* Don't deactivate old_keyboard_focus_surface client if the new * one wants focus, as this causes issues with winecfg and - * probably other clients */ + * probably other server.clients */ } else if (w && !client_is_unmanaged(w) && (!c || !client_wants_focus(c))) { client_activate_surface(old_keyboard_focus_surface, 0); @@ -3370,18 +3515,19 @@ void focusclient(Client *c, int32_t lift) { if (!c) { - if (selmon && selmon->sel && - (!VISIBLEON(selmon->sel, selmon) || selmon->sel->iskilling || - !client_surface(selmon->sel)->mapped)) - selmon->sel = NULL; + if (server.selmon && server.selmon->sel && + (!VISIBLEON(server.selmon->sel, server.selmon) || + server.selmon->sel->iskilling || + !client_surface(server.selmon->sel)->mapped)) + server.selmon->sel = NULL; // clear text input focus state dwl_im_relay_set_focus(dwl_input_method_relay, NULL); - wlr_seat_keyboard_notify_clear_focus(seat); + wlr_seat_keyboard_notify_clear_focus(server.seat); return; } - /* Change cursor surface */ + /* Change server.cursor surface */ motionnotify(0, NULL, 0, 0, 0, 0); // set text input focus @@ -3390,7 +3536,7 @@ void focusclient(Client *c, int32_t lift) { dwl_im_relay_set_focus(dwl_input_method_relay, client_surface(c)); /* Have a client, so focus its top-level wlr_surface */ - client_notify_enter(client_surface(c), wlr_seat_get_keyboard(seat)); + client_notify_enter(client_surface(c), wlr_seat_get_keyboard(server.seat)); /* Activate the new client */ client_activate_surface(client_surface(c), 1); @@ -3435,8 +3581,8 @@ void requestmonstate(struct wl_listener *listener, void *data) { } void inputdevice(struct wl_listener *listener, void *data) { - /* This event is raised by the backend when a new input device becomes - * available. */ + /* This event is raised by the server.backend when a new input device + * becomes available. */ struct wlr_input_device *device = data; uint32_t caps; @@ -3456,14 +3602,14 @@ void inputdevice(struct wl_listener *listener, void *data) { } /* We need to let the wlr_seat know what our capabilities are, which is - * communiciated to the client. In dwl we always have a cursor, even if - * there are no pointer devices, so we always include that capability. + * communiciated to the client. In dwl we always have a server.cursor, even + * if there are no pointer devices, so we always include that capability. */ - /* TODO do we actually require a cursor? */ + /* TODO do we actually require a server.cursor? */ caps = WL_SEAT_CAPABILITY_POINTER; - if (!wl_list_empty(&kb_group->wlr_group->devices)) + if (!wl_list_empty(&server.kb_group->wlr_group->devices)) caps |= WL_SEAT_CAPABILITY_KEYBOARD; - wlr_seat_set_capabilities(seat, caps); + wlr_seat_set_capabilities(server.seat, caps); } int32_t keyrepeat(void *data) { @@ -3486,7 +3632,7 @@ int32_t keyrepeat(void *data) { bool is_keyboard_shortcut_inhibitor(struct wlr_surface *surface) { KeyboardShortcutsInhibitor *kbsinhibitor; - wl_list_for_each(kbsinhibitor, &keyboard_shortcut_inhibitors, link) { + wl_list_for_each(kbsinhibitor, &server.keyboard_shortcut_inhibitors, link) { if (kbsinhibitor->inhibitor->surface == surface) { return true; } @@ -3498,9 +3644,9 @@ int32_t // 17 keybinding(uint32_t state, bool locked, uint32_t mods, xkb_keysym_t sym, uint32_t keycode) { /* - * Here we handle compositor keybindings. This is when the compositor is - * processing keys, rather than passing them on to the client for its - * own processing. + * Here we handle server.compositor keybindings. This is when the + * server.compositor is processing keys, rather than passing them on to the + * client for its own processing. */ int32_t handled = 0; const KeyBinding *k; @@ -3513,7 +3659,8 @@ keybinding(uint32_t state, bool locked, uint32_t mods, xkb_keysym_t sym, keycode == 62 || keycode == 108 || keycode == 105 || keycode == 134) return false; - if (is_keyboard_shortcut_inhibitor(seat->keyboard_state.focused_surface)) { + if (is_keyboard_shortcut_inhibitor( + server.seat->keyboard_state.focused_surface)) { return false; } @@ -3521,7 +3668,7 @@ keybinding(uint32_t state, bool locked, uint32_t mods, xkb_keysym_t sym, if (config.key_bindings_count < 1) break; - if (locked && config.key_bindings[ji].islockapply == false) + if (server.locked && config.key_bindings[ji].islockapply == false) continue; if (state == WL_KEYBOARD_KEY_STATE_RELEASED && @@ -3570,7 +3717,7 @@ bool keypressglobal(struct wlr_surface *last_surface, struct wlr_keyboard *keyboard, struct wlr_keyboard_key_event *event, uint32_t mods, xkb_keysym_t keysym, uint32_t keycode) { - Client *c = NULL, *lastc = focustop(selmon); + Client *c = NULL, *lastc = focustop(server.selmon); uint32_t keycodes[32] = {0}; int32_t reset = false; const char *appid = NULL; @@ -3598,7 +3745,7 @@ bool keypressglobal(struct wlr_surface *last_surface, r->globalkeybinding.keysymcode.keycode.keycode2 == keycode || r->globalkeybinding.keysymcode.keycode.keycode3 == keycode))) && r->globalkeybinding.mod == mods) { - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (c && c != lastc) { appid = client_get_appid(c); title = client_get_title(c); @@ -3608,12 +3755,12 @@ bool keypressglobal(struct wlr_surface *last_surface, (r->id && regex_match(r->id, appid) && r->title && regex_match(r->title, title))) { reset = true; - wlr_seat_keyboard_enter(seat, client_surface(c), + wlr_seat_keyboard_enter(server.seat, client_surface(c), keycodes, 0, &keyboard->modifiers); - wlr_seat_keyboard_send_key(seat, event->time_msec, - event->keycode, - event->state); + wlr_seat_keyboard_send_key( + server.seat, event->time_msec, event->keycode, + event->state); goto done; } } @@ -3623,7 +3770,7 @@ bool keypressglobal(struct wlr_surface *last_surface, done: if (reset) - wlr_seat_keyboard_enter(seat, last_surface, keycodes, 0, + wlr_seat_keyboard_enter(server.seat, last_surface, keycodes, 0, &keyboard->modifiers); return reset; } @@ -3634,7 +3781,8 @@ void keypress(struct wl_listener *listener, void *data) { KeyboardGroup *group = wl_container_of(listener, group, key); struct wlr_keyboard_key_event *event = data; - struct wlr_surface *last_surface = seat->keyboard_state.focused_surface; + struct wlr_surface *last_surface = + server.seat->keyboard_state.focused_surface; struct wlr_xdg_surface *xdg_surface = last_surface ? wlr_xdg_surface_try_from_wlr_surface(last_surface) : NULL; @@ -3656,27 +3804,28 @@ void keypress(struct wl_listener *listener, void *data) { int32_t handled = 0; uint32_t mods = wlr_keyboard_get_modifiers(&group->wlr_group->keyboard); - wlr_idle_notifier_v1_notify_activity(idle_notifier, seat); + wlr_idle_notifier_v1_notify_activity(server.idle_notifier, server.seat); // ov tab mode detect moe key release - if (ov_tab_mode && !locked && group == kb_group && + if (ov_tab_mode && !server.locked && group == server.kb_group && event->state == WL_KEYBOARD_KEY_STATE_RELEASED && (keycode == 133 || keycode == 37 || keycode == 64 || keycode == 50 || keycode == 134 || keycode == 105 || keycode == 108 || keycode == 62) && - selmon && selmon->sel) { - if (selmon->isoverview && selmon->sel) { + server.selmon && server.selmon->sel) { + if (server.selmon->isoverview && server.selmon->sel) { toggleoverview(&(Arg){.i = 1}); } } /* On _press_ if there is no active screen locker, - * attempt to process a compositor keybinding. */ + * attempt to process a server.compositor keybinding. */ for (i = 0; i < nsyms; i++) handled = - keybinding(event->state, locked, mods, syms[i], keycode) || handled; + keybinding(event->state, server.locked, mods, syms[i], keycode) || + handled; if (event->state == WL_KEYBOARD_KEY_STATE_RELEASED) { - tag_combo = false; + server.tag_combo = false; } if (handled && group->wlr_group->keyboard.repeat_info.delay > 0) { @@ -3713,10 +3862,10 @@ void keypress(struct wl_listener *listener, void *data) { return; } if (!dwl_im_keyboard_grab_forward_key(group, event)) { - wlr_seat_set_keyboard(seat, &group->wlr_group->keyboard); + wlr_seat_set_keyboard(server.seat, &group->wlr_group->keyboard); /* Pass unhandled keycodes along to the client. */ - wlr_seat_keyboard_notify_key(seat, event->time_msec, event->keycode, - event->state); + wlr_seat_keyboard_notify_key(server.seat, event->time_msec, + event->keycode, event->state); } } @@ -3727,10 +3876,10 @@ void keypressmod(struct wl_listener *listener, void *data) { if (!dwl_im_keyboard_grab_forward_modifiers(group)) { - wlr_seat_set_keyboard(seat, &group->wlr_group->keyboard); + wlr_seat_set_keyboard(server.seat, &group->wlr_group->keyboard); /* Send modifiers to the client. */ wlr_seat_keyboard_notify_modifiers( - seat, &group->wlr_group->keyboard.modifiers); + server.seat, &group->wlr_group->keyboard.modifiers); } } @@ -3744,18 +3893,18 @@ void locksession(struct wl_listener *listener, void *data) { struct wlr_session_lock_v1 *session_lock = data; SessionLock *lock; if (!allow_lock_transparent) { - wlr_scene_node_set_enabled(&locked_bg->node, true); + wlr_scene_node_set_enabled(&server.locked_bg->node, true); } - if (cur_lock) { + if (server.cur_lock) { wlr_session_lock_v1_destroy(session_lock); return; } lock = session_lock->data = ecalloc(1, sizeof(*lock)); focusclient(NULL, 0); - lock->scene = wlr_scene_tree_create(layers[LyrBlock]); - cur_lock = lock->lock = session_lock; - locked = 1; + lock->scene = wlr_scene_tree_create(server.layers[LyrBlock]); + server.cur_lock = lock->lock = session_lock; + server.locked = 1; LISTEN(&session_lock->events.new_surface, &lock->new_surface, createlocksurface); @@ -3860,8 +4009,9 @@ mapnotify(struct wl_listener *listener, void *data) { /* Called when the surface is mapped, or ready to display on-screen. */ Client *at_client = NULL; Client *c = wl_container_of(listener, c, map); - /* Create scene tree for this client and its border */ - c->scene = client_surface(c)->data = wlr_scene_tree_create(layers[LyrTile]); + /* Create server.scene tree for this client and its border */ + c->scene = client_surface(c)->data = + wlr_scene_tree_create(server.layers[LyrTile]); wlr_scene_node_set_enabled(&c->scene->node, c->type != XDGShell); c->scene_surface = c->type == XDGShell @@ -3890,15 +4040,16 @@ mapnotify(struct wl_listener *listener, void *data) { c->geom.width += 2 * c->bw; c->geom.height += 2 * c->bw; - /* Handle unmanaged clients first so we can return prior create borders + /* Handle unmanaged server.clients first so we can return prior create + * borders */ if (client_is_unmanaged(c)) { - /* Unmanaged clients always are floating */ - wlr_scene_node_reparent(&c->scene->node, layers[LyrOverlay]); + /* Unmanaged server.clients always are floating */ + wlr_scene_node_reparent(&c->scene->node, server.layers[LyrOverlay]); wlr_scene_node_set_position(&c->scene->node, c->geom.x, c->geom.y); if (client_wants_focus(c)) { focusclient(c, 1); - exclusive_focus = c; + server.exclusive_focus = c; } #ifdef XWAYLAND if (client_is_x11(c)) { @@ -3924,17 +4075,17 @@ mapnotify(struct wl_listener *listener, void *data) { wlr_scene_node_lower_to_bottom(&c->shadow->node); wlr_scene_node_set_enabled(&c->shadow->node, true); - if (new_is_master && selmon && !is_scroller_layout(selmon)) + if (new_is_master && server.selmon && !is_scroller_layout(server.selmon)) // tile at the top - wl_list_insert(&clients, &c->link); // 新窗口是master,头部入栈 - else if (selmon && is_scroller_layout(selmon) && - selmon->visible_scroll_tiling_clients > 0) { + wl_list_insert(&server.clients, &c->link); // 新窗口是master,头部入栈 + else if (server.selmon && is_scroller_layout(server.selmon) && + server.selmon->visible_scroll_tiling_clients > 0) { - if (selmon->sel && ISSCROLLTILED(selmon->sel) && - VISIBLEON(selmon->sel, selmon)) { - at_client = get_scroll_stack_head(selmon->sel); + if (server.selmon->sel && ISSCROLLTILED(server.selmon->sel) && + VISIBLEON(server.selmon->sel, server.selmon)) { + at_client = get_scroll_stack_head(server.selmon->sel); } else { - at_client = center_tiled_select(selmon); + at_client = center_tiled_select(server.selmon); } if (at_client) { @@ -3943,11 +4094,11 @@ mapnotify(struct wl_listener *listener, void *data) { c->link.next = at_client->link.next; at_client->link.next = &c->link; } else { - wl_list_insert(clients.prev, &c->link); // 尾部入栈 + wl_list_insert(server.clients.prev, &c->link); // 尾部入栈 } } else - wl_list_insert(clients.prev, &c->link); // 尾部入栈 - wl_list_insert(&fstack, &c->flink); + wl_list_insert(server.clients.prev, &c->link); // 尾部入栈 + wl_list_insert(&server.fstack, &c->flink); applyrules(c); @@ -4018,12 +4169,12 @@ void set_minimized(Client *c) { c->isminimized = 1; c->is_in_scratchpad = 1; c->is_scratchpad_show = 0; - focusclient(focustop(selmon), 1); + focusclient(focustop(server.selmon), 1); arrange(c->mon, false, false); wlr_foreign_toplevel_handle_v1_set_activated(c->foreign_toplevel, false); wlr_foreign_toplevel_handle_v1_set_minimized(c->foreign_toplevel, true); - wl_list_remove(&c->link); // 从原来位置移除 - wl_list_insert(clients.prev, &c->link); // 插入尾部 + wl_list_remove(&c->link); // 从原来位置移除 + wl_list_insert(server.clients.prev, &c->link); // 插入尾部 } void minimizenotify(struct wl_listener *listener, void *data) { @@ -4045,7 +4196,7 @@ void minimizenotify(struct wl_listener *listener, void *data) { } void motionabsolute(struct wl_listener *listener, void *data) { - /* This event is forwarded by the cursor when a pointer emits an + /* This event is forwarded by the server.cursor when a pointer emits an * _absolute_ motion event, from 0..1 on each axis. This happens, for * example, when wlroots is running under a Wayland window rather than * KMS+DRM, and you move the mouse over the window. You could enter the @@ -4059,40 +4210,16 @@ void motionabsolute(struct wl_listener *listener, void *data) { } if (!event->time_msec) /* this is 0 with virtual pointer */ - wlr_cursor_warp_absolute(cursor, &event->pointer->base, event->x, + wlr_cursor_warp_absolute(server.cursor, &event->pointer->base, event->x, event->y); - wlr_cursor_absolute_to_layout_coords(cursor, &event->pointer->base, + wlr_cursor_absolute_to_layout_coords(server.cursor, &event->pointer->base, event->x, event->y, &lx, &ly); - dx = lx - cursor->x; - dy = ly - cursor->y; + dx = lx - server.cursor->x; + dy = ly - server.cursor->y; motionnotify(event->time_msec, &event->pointer->base, dx, dy, dx, dy); } -void resize_floating_window(Client *grabc) { - int cdx = (int)round(cursor->x) - grabcx; - int cdy = (int)round(cursor->y) - grabcy; - - cdx = !(rzcorner & 1) && grabc->geom.width - 2 * (int)grabc->bw - cdx < 1 - ? 0 - : cdx; - cdy = !(rzcorner & 2) && grabc->geom.height - 2 * (int)grabc->bw - cdy < 1 - ? 0 - : cdy; - - const struct wlr_box box = { - .x = grabc->geom.x + (rzcorner & 1 ? 0 : cdx), - .y = grabc->geom.y + (rzcorner & 2 ? 0 : cdy), - .width = grabc->geom.width + (rzcorner & 1 ? cdx : -cdx), - .height = grabc->geom.height + (rzcorner & 2 ? cdy : -cdy)}; - - grabc->float_geom = box; - - resize(grabc, box, 1); - grabcx += cdx; - grabcy += cdy; -} - void motionnotify(uint32_t time, struct wlr_input_device *device, double dx, double dy, double dx_unaccel, double dy_unaccel) { double sx = 0, sy = 0, sx_confined, sy_confined; @@ -4103,96 +4230,100 @@ void motionnotify(uint32_t time, struct wlr_input_device *device, double dx, bool should_lock = false; /* Find the client under the pointer and send the event along. */ - xytonode(cursor->x, cursor->y, &surface, &c, NULL, &sx, &sy); + xytonode(server.cursor->x, server.cursor->y, &surface, &c, NULL, &sx, &sy); - if (cursor_mode == CurPressed && !seat->drag && - surface != seat->pointer_state.focused_surface && - toplevel_from_wlr_surface(seat->pointer_state.focused_surface, &w, - &l) >= 0) { + if (server.cursor_mode == CurPressed && !server.seat->drag && + surface != server.seat->pointer_state.focused_surface && + toplevel_from_wlr_surface(server.seat->pointer_state.focused_surface, + &w, &l) >= 0) { c = w; - surface = seat->pointer_state.focused_surface; - sx = cursor->x - (l ? l->scene->node.x : w->geom.x); - sy = cursor->y - (l ? l->scene->node.y : w->geom.y); + surface = server.seat->pointer_state.focused_surface; + sx = server.cursor->x - (l ? l->scene->node.x : w->geom.x); + sy = server.cursor->y - (l ? l->scene->node.y : w->geom.y); } /* time is 0 in internal calls meant to restore pointer focus. */ if (time) { wlr_relative_pointer_manager_v1_send_relative_motion( - relative_pointer_mgr, seat, (uint64_t)time * 1000, dx, dy, - dx_unaccel, dy_unaccel); + server.relative_pointer_mgr, server.seat, (uint64_t)time * 1000, dx, + dy, dx_unaccel, dy_unaccel); - wl_list_for_each(constraint, &pointer_constraints->constraints, link) - cursorconstrain(constraint); + wl_list_for_each(constraint, &server.pointer_constraints->constraints, + link) cursorconstrain(constraint); - if (active_constraint && cursor_mode != CurResize && - cursor_mode != CurMove) { - toplevel_from_wlr_surface(active_constraint->surface, &c, NULL); - if (c && active_constraint->surface == - seat->pointer_state.focused_surface) { - sx = cursor->x - c->geom.x - c->bw; - sy = cursor->y - c->geom.y - c->bw; - if (wlr_region_confine(&active_constraint->region, sx, sy, - sx + dx, sy + dy, &sx_confined, + if (server.active_constraint && server.cursor_mode != CurResize && + server.cursor_mode != CurMove) { + toplevel_from_wlr_surface(server.active_constraint->surface, &c, + NULL); + if (c && server.active_constraint->surface == + server.seat->pointer_state.focused_surface) { + sx = server.cursor->x - c->geom.x - c->bw; + sy = server.cursor->y - c->geom.y - c->bw; + if (wlr_region_confine(&server.active_constraint->region, sx, + sy, sx + dx, sy + dy, &sx_confined, &sy_confined)) { dx = sx_confined - sx; dy = sy_confined - sy; } - if (active_constraint->type == WLR_POINTER_CONSTRAINT_V1_LOCKED) + if (server.active_constraint->type == + WLR_POINTER_CONSTRAINT_V1_LOCKED) return; } } - wlr_cursor_move(cursor, device, dx, dy); + wlr_cursor_move(server.cursor, device, dx, dy); handlecursoractivity(); - wlr_idle_notifier_v1_notify_activity(idle_notifier, seat); + wlr_idle_notifier_v1_notify_activity(server.idle_notifier, server.seat); - /* Update selmon (even while dragging a window) */ + /* Update server.selmon (even while dragging a window) */ if (sloppyfocus) - selmon = xytomon(cursor->x, cursor->y); + server.selmon = xytomon(server.cursor->x, server.cursor->y); } /* Update drag icon's position */ - wlr_scene_node_set_position(&drag_icon->node, (int32_t)round(cursor->x), - (int32_t)round(cursor->y)); + wlr_scene_node_set_position(&server.drag_icon->node, + (int32_t)round(server.cursor->x), + (int32_t)round(server.cursor->y)); /* If we are currently grabbing the mouse, handle and return */ - if (cursor_mode == CurMove) { + if (server.cursor_mode == CurMove) { /* Move the grabbed client to the new position. */ - grabc->iscustomsize = 1; - grabc->float_geom = - (struct wlr_box){.x = (int32_t)round(cursor->x) - grabcx, - .y = (int32_t)round(cursor->y) - grabcy, - .width = grabc->geom.width, - .height = grabc->geom.height}; - resize(grabc, grabc->float_geom, 1); + server.grabc->iscustomsize = 1; + server.grabc->float_geom = (struct wlr_box){ + .x = (int32_t)round(server.cursor->x) - server.grabcx, + .y = (int32_t)round(server.cursor->y) - server.grabcy, + .width = server.grabc->geom.width, + .height = server.grabc->geom.height}; + resize(server.grabc, server.grabc->float_geom, 1); return; - } else if (cursor_mode == CurResize) { - if (grabc->isfloating) { - grabc->iscustomsize = 1; - if (last_apply_drap_time == 0 || - time - last_apply_drap_time > drag_floating_refresh_interval) { - resize_floating_window(grabc); - last_apply_drap_time = time; + } else if (server.cursor_mode == CurResize) { + if (server.grabc->isfloating) { + server.grabc->iscustomsize = 1; + if (server.last_apply_drag_time == 0 || + time - server.last_apply_drag_time > + drag_floating_refresh_interval) { + resize_floating_window(server.grabc); + server.last_apply_drag_time = time; } return; } else { - resize_tile_client(grabc, true, 0, 0, time); + resize_tile_client(server.grabc, true, 0, 0, time); } } - /* If there's no client surface under the cursor, set the cursor image - * to a default. This is what makes the cursor image appear when you - * move it off of a client or over its border. */ - if (!surface && !seat->drag && !cursor_hidden) - wlr_cursor_set_xcursor(cursor, cursor_mgr, "default"); + /* If there's no client surface under the server.cursor, set the + * server.cursor image to a default. This is what makes the server.cursor + * image appear when you move it off of a client or over its border. */ + if (!surface && !server.seat->drag && !server.cursor_hidden) + wlr_cursor_set_xcursor(server.cursor, server.cursor_mgr, "default"); if (c && c->mon && !c->animation.running && (INSIDEMON(c) || !ISTILED(c))) { - scroller_focus_lock = 0; + server.scroller_focus_lock = 0; } should_lock = false; - if (!scroller_focus_lock || !(c && c->mon && !INSIDEMON(c))) { + if (!server.scroller_focus_lock || !(c && c->mon && !INSIDEMON(c))) { if (c && c->mon && is_scroller_layout(c->mon) && !INSIDEMON(c)) { should_lock = true; } @@ -4202,20 +4333,20 @@ void motionnotify(uint32_t time, struct wlr_input_device *device, double dx, pointerfocus(c, surface, sx, sy, time); if (should_lock && c && c->mon && ISTILED(c) && c == c->mon->sel) { - scroller_focus_lock = 1; + server.scroller_focus_lock = 1; } } } void motionrelative(struct wl_listener *listener, void *data) { - /* This event is forwarded by the cursor when a pointer emits a + /* This event is forwarded by the server.cursor when a pointer emits a * _relative_ pointer motion event (i.e. a delta) */ struct wlr_pointer_motion_event *event = data; - /* The cursor doesn't move unless we tell it to. The cursor + /* The server.cursor doesn't move unless we tell it to. The server.cursor * automatically handles constraining the motion to the output layout, * as well as any special configuration applied for the specific input * device which generated the event. You can pass NULL for the device if - * you want to move the cursor around without any input. */ + * you want to move the server.cursor around without any input. */ if (check_trackpad_disabled(event->pointer)) { return; @@ -4223,7 +4354,7 @@ void motionrelative(struct wl_listener *listener, void *data) { motionnotify(event->time_msec, &event->pointer->base, event->delta_x, event->delta_y, event->unaccel_dx, event->unaccel_dy); - toggle_hotarea(cursor->x, cursor->y); + toggle_hotarea(server.cursor->x, server.cursor->y); } void outputmgrapply(struct wl_listener *listener, void *data) { @@ -4237,7 +4368,7 @@ outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int32_t test) { * Called when a client such as wlr-randr requests a change in output * configuration. This is only one way that the layout can be changed, * so any Monitor information should be updated by updatemons() after an - * output_layout.change event, not here. + * server.output_layout.change event, not here. */ struct wlr_output_configuration_head_v1 *config_head; int32_t ok = 1; @@ -4278,7 +4409,7 @@ outputmgrapplyortest(struct wlr_output_configuration_v1 *config, int32_t test) { * wlr_output_layout_add does not like disabled outputs */ if (!test && wlr_output->enabled && (m->m.x != config_head->state.x || m->m.y != config_head->state.y)) - wlr_output_layout_add(output_layout, wlr_output, + wlr_output_layout_add(server.output_layout, wlr_output, config_head->state.x, config_head->state.y); wlr_output_state_finish(&state); @@ -4303,15 +4434,15 @@ void pointerfocus(Client *c, struct wlr_surface *surface, double sx, double sy, uint32_t time) { struct timespec now; - if (sloppyfocus && !start_drag_window && c && time && + if (sloppyfocus && !server.start_drag_window && c && time && c->scene->node.enabled && !c->animation.tagining && - (surface != seat->pointer_state.focused_surface) && + (surface != server.seat->pointer_state.focused_surface) && !client_is_unmanaged(c) && VISIBLEON(c, c->mon)) focusclient(c, 0); /* If surface is NULL, clear pointer focus */ if (!surface) { - wlr_seat_pointer_notify_clear_focus(seat); + wlr_seat_pointer_notify_clear_focus(server.seat); return; } @@ -4320,11 +4451,11 @@ void pointerfocus(Client *c, struct wlr_surface *surface, double sx, double sy, time = now.tv_sec * 1000 + now.tv_nsec / 1000000; } - /* Let the client know that the mouse cursor has entered one + /* Let the client know that the mouse server.cursor has entered one * of its surfaces, and make keyboard focus follow if desired. * wlroots makes this a no-op if surface is already focused */ - wlr_seat_pointer_notify_enter(seat, surface, sx, sy); - wlr_seat_pointer_notify_motion(seat, time, sx, sy); + wlr_seat_pointer_notify_enter(server.seat, surface, sx, sy); + wlr_seat_pointer_notify_motion(server.seat, time, sx, sy); } // 修改printstatus函数,接受掩码参数 @@ -4368,11 +4499,11 @@ void rendermon(struct wl_listener *listener, void *data) { struct timespec now; bool need_more_frames = false; - if (session && !session->active) { + if (server.session && !server.session->active) { return; } - if (!m->wlr_output->enabled || !allow_frame_scheduling) + if (!m->wlr_output->enabled || !server.allow_frame_scheduling) return; frame_allow_tearing = check_tearing_frame_allow(m); @@ -4385,16 +4516,16 @@ void rendermon(struct wl_listener *listener, void *data) { } } - wl_list_for_each_safe(c, tmp, &fadeout_clients, fadeout_link) { + wl_list_for_each_safe(c, tmp, &server.fadeout_clients, fadeout_link) { need_more_frames = client_draw_fadeout_frame(c) || need_more_frames; } - wl_list_for_each_safe(l, tmpl, &fadeout_layers, fadeout_link) { + wl_list_for_each_safe(l, tmpl, &server.fadeout_layers, fadeout_link) { need_more_frames = layer_draw_fadeout_frame(l) || need_more_frames; } // 绘制客户端 - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { need_more_frames = client_draw_frame(c) || need_more_frames; if (!animations && !(allow_tearing && frame_allow_tearing) && c->configure_serial && !c->isfloating && @@ -4421,7 +4552,7 @@ skip: } // 如果需要更多帧,确保安排下一帧 - if (need_more_frames && allow_frame_scheduling) { + if (need_more_frames && server.allow_frame_scheduling) { request_fresh_all_monitors(); } } @@ -4457,9 +4588,9 @@ static void requestdrmlease(struct wl_listener *listener, void *data) { void requeststartdrag(struct wl_listener *listener, void *data) { struct wlr_seat_request_start_drag_event *event = data; - if (wlr_seat_validate_pointer_grab_serial(seat, event->origin, + if (wlr_seat_validate_pointer_grab_serial(server.seat, event->origin, event->serial)) - wlr_seat_start_pointer_drag(seat, event->drag, event->serial); + wlr_seat_start_pointer_drag(server.seat, event->drag, event->serial); else wlr_data_source_destroy(event->drag->source); } @@ -4606,26 +4737,26 @@ run(char *startup_cmd) { set_env(); /* Add a Unix socket to the Wayland display. */ - const char *socket = wl_display_add_socket_auto(dpy); + const char *socket = wl_display_add_socket_auto(server.dpy); if (!socket) die("startup: display_add_socket_auto"); setenv("WAYLAND_DISPLAY", socket, 1); - /* Start the backend. This will enumerate outputs and inputs, become the - * DRM master, etc */ - if (!wlr_backend_start(backend)) + /* Start the server.backend. This will enumerate outputs and inputs, become + * the DRM master, etc */ + if (!wlr_backend_start(server.backend)) die("startup: backend_start"); - /* Now that the socket exists and the backend is started, run the + /* Now that the socket exists and the server.backend is started, run the * startup command */ if (startup_cmd) { int32_t piperw[2]; if (pipe(piperw) < 0) die("startup: pipe:"); - if ((child_pid = fork()) < 0) + if ((server.child_pid = fork()) < 0) die("startup: fork:"); - if (child_pid == 0) { + if (server.child_pid == 0) { setsid(); dup2(piperw[0], STDIN_FILENO); close(piperw[0]); @@ -4645,53 +4776,54 @@ run(char *startup_cmd) { printstatus(); - /* At this point the outputs are initialized, choose initial selmon - * based on cursor position, and set default cursor image */ - selmon = xytomon(cursor->x, cursor->y); + /* At this point the outputs are initialized, choose initial server.selmon + * based on server.cursor position, and set default server.cursor image */ + server.selmon = xytomon(server.cursor->x, server.cursor->y); - /* TODO hack to get cursor to display in its initial location (100, 100) - * instead of (0, 0) and then jumping. still may not be fully + /* TODO hack to get server.cursor to display in its initial location (100, + * 100) instead of (0, 0) and then jumping. still may not be fully * initialized, as the image/coordinates are not transformed for the * monitor when displayed here */ - wlr_cursor_warp_closest(cursor, NULL, cursor->x, cursor->y); - wlr_cursor_set_xcursor(cursor, cursor_mgr, "left_ptr"); + wlr_cursor_warp_closest(server.cursor, NULL, server.cursor->x, + server.cursor->y); + wlr_cursor_set_xcursor(server.cursor, server.cursor_mgr, "left_ptr"); handlecursoractivity(); run_exec(); run_exec_once(); /* Run the Wayland event loop. This does not return until you exit the - * compositor. Starting the backend rigged up all of the necessary event - * loop configuration to listen to libinput events, DRM events, generate - * frame events at the refresh rate, and so on. */ + * server.compositor. Starting the server.backend rigged up all of the + * necessary event loop configuration to listen to libinput events, DRM + * events, generate frame events at the refresh rate, and so on. */ - wl_display_run(dpy); + wl_display_run(server.dpy); } void setcursor(struct wl_listener *listener, void *data) { - /* This event is raised by the seat when a client provides a cursor - * image */ + /* This event is raised by the server.seat when a client provides a + * server.cursor image */ struct wlr_seat_pointer_request_set_cursor_event *event = data; - /* If we're "grabbing" the cursor, don't use the client's image, we will - * restore it after "grabbing" sending a leave event, followed by a + /* If we're "grabbing" the server.cursor, don't use the client's image, we + * will restore it after "grabbing" sending a leave event, followed by a * enter event, which will result in the client requesting set the - * cursor surface + * server.cursor surface */ - if (cursor_mode != CurNormal && cursor_mode != CurPressed) + if (server.cursor_mode != CurNormal && server.cursor_mode != CurPressed) return; /* This can be sent by any client, so we check to make sure this one is - * actually has pointer focus first. If so, we can tell the cursor to - * use the provided surface as the cursor image. It will set the - * hardware cursor on the output that it's currently on and continue to - * do so as the cursor moves between outputs. */ - if (event->seat_client == seat->pointer_state.focused_client) { - last_cursor.shape = 0; - last_cursor.surface = event->surface; - last_cursor.hotspot_x = event->hotspot_x; - last_cursor.hotspot_y = event->hotspot_y; - if (!cursor_hidden) - wlr_cursor_set_surface(cursor, event->surface, event->hotspot_x, - event->hotspot_y); + * actually has pointer focus first. If so, we can tell the server.cursor to + * use the provided surface as the server.cursor image. It will set the + * hardware server.cursor on the output that it's currently on and continue + * to do so as the server.cursor moves between outputs. */ + if (event->seat_client == server.seat->pointer_state.focused_client) { + server.last_cursor.shape = 0; + server.last_cursor.surface = event->surface; + server.last_cursor.hotspot_x = event->hotspot_x; + server.last_cursor.hotspot_y = event->hotspot_y; + if (!server.cursor_hidden) + wlr_cursor_set_surface(server.cursor, event->surface, + event->hotspot_x, event->hotspot_y); } } @@ -4709,7 +4841,7 @@ setfloating(Client *c, int32_t floating) { target_box = c->geom; - if (floating == 1 && c != grabc) { + if (floating == 1 && c != server.grabc) { if (c->isfullscreen || c->ismaximizescreen) { c->isfullscreen = 0; // 清除窗口全屏标志 @@ -4746,7 +4878,7 @@ setfloating(Client *c, int32_t floating) { } c->need_float_size_reduce = 0; - } else if (c->isfloating && c == grabc) { + } else if (c->isfloating && c == server.grabc) { c->need_float_size_reduce = 0; } else { c->need_float_size_reduce = 1; @@ -4754,7 +4886,7 @@ setfloating(Client *c, int32_t floating) { c->is_in_scratchpad = 0; c->isnamedscratchpad = 0; // 让当前tag中的全屏窗口退出全屏参与平铺 - wl_list_for_each(fc, &clients, + wl_list_for_each(fc, &server.clients, link) if (fc && fc != c && VISIBLEON(fc, c->mon) && c->tags & fc->tags && ISFULLSCREEN(fc)) { clear_fullscreen_flag(fc); @@ -4762,12 +4894,12 @@ setfloating(Client *c, int32_t floating) { } if (c->isoverlay) { - wlr_scene_node_reparent(&c->scene->node, layers[LyrOverlay]); + wlr_scene_node_reparent(&c->scene->node, server.layers[LyrOverlay]); } else if (client_should_overtop(c) && c->isfloating) { - wlr_scene_node_reparent(&c->scene->node, layers[LyrTop]); + wlr_scene_node_reparent(&c->scene->node, server.layers[LyrTop]); } else { - wlr_scene_node_reparent(&c->scene->node, - layers[c->isfloating ? LyrTop : LyrTile]); + wlr_scene_node_reparent( + &c->scene->node, server.layers[c->isfloating ? LyrTop : LyrTile]); } if (!c->isfloating && old_floating_state) { @@ -4848,7 +4980,7 @@ void setmaximizescreen(Client *c, int32_t maximizescreen) { } wlr_scene_node_reparent(&c->scene->node, - layers[c->isfloating ? LyrTop : LyrTile]); + server.layers[c->isfloating ? LyrTop : LyrTile]); if (!c->ismaximizescreen && old_maximizescreen_state) { set_size_per(c->mon, c); } @@ -4911,13 +5043,13 @@ void setfullscreen(Client *c, int32_t fullscreen) // 用自定义全屏代理自 } if (c->isoverlay) { - wlr_scene_node_reparent(&c->scene->node, layers[LyrOverlay]); + wlr_scene_node_reparent(&c->scene->node, server.layers[LyrOverlay]); } else if (client_should_overtop(c) && c->isfloating) { - wlr_scene_node_reparent(&c->scene->node, layers[LyrTop]); + wlr_scene_node_reparent(&c->scene->node, server.layers[LyrTop]); } else { wlr_scene_node_reparent( &c->scene->node, - layers[fullscreen || c->isfloating ? LyrTop : LyrTile]); + server.layers[fullscreen || c->isfloating ? LyrTop : LyrTile]); } if (!c->isfullscreen && old_fullscreen_state) { @@ -4928,20 +5060,20 @@ void setfullscreen(Client *c, int32_t fullscreen) // 用自定义全屏代理自 } void setgaps(int32_t oh, int32_t ov, int32_t ih, int32_t iv) { - selmon->gappoh = MAX(oh, 0); - selmon->gappov = MAX(ov, 0); - selmon->gappih = MAX(ih, 0); - selmon->gappiv = MAX(iv, 0); - arrange(selmon, false, false); + server.selmon->gappoh = MAX(oh, 0); + server.selmon->gappov = MAX(ov, 0); + server.selmon->gappih = MAX(ih, 0); + server.selmon->gappiv = MAX(iv, 0); + arrange(server.selmon, false, false); } void reset_keyboard_layout(void) { - if (!kb_group || !kb_group->wlr_group || !seat) { - wlr_log(WLR_ERROR, "Invalid keyboard group or seat"); + if (!server.kb_group || !server.kb_group->wlr_group || !server.seat) { + wlr_log(WLR_ERROR, "Invalid keyboard group or server.seat "); return; } - struct wlr_keyboard *keyboard = &kb_group->wlr_group->keyboard; + struct wlr_keyboard *keyboard = &server.kb_group->wlr_group->keyboard; if (!keyboard || !keyboard->keymap) { wlr_log(WLR_ERROR, "Invalid keyboard or keymap"); return; @@ -4993,19 +5125,20 @@ void reset_keyboard_layout(void) { // Apply the new keymap uint32_t depressed = keyboard->modifiers.depressed; uint32_t latched = keyboard->modifiers.latched; - uint32_t locked = keyboard->modifiers.locked; + // uint32_t locked = keyboard->modifiers.locked; wlr_keyboard_set_keymap(keyboard, new_keymap); - wlr_keyboard_notify_modifiers(keyboard, depressed, latched, locked, 0); + wlr_keyboard_notify_modifiers(keyboard, depressed, latched, server.locked, + 0); keyboard->modifiers.group = current; // Keep the same layout index - // Update seat - wlr_seat_set_keyboard(seat, keyboard); - wlr_seat_keyboard_notify_modifiers(seat, &keyboard->modifiers); + // Update server.seat + wlr_seat_set_keyboard(server.seat, keyboard); + wlr_seat_keyboard_notify_modifiers(server.seat, &keyboard->modifiers); InputDevice *id; - wl_list_for_each(id, &inputdevices, link) { + wl_list_for_each(id, &server.inputdevices, link) { if (id->wlr_device->type != WLR_INPUT_DEVICE_KEYBOARD) { continue; } @@ -5013,12 +5146,13 @@ void reset_keyboard_layout(void) { struct wlr_keyboard *tkb = (struct wlr_keyboard *)id->device_data; wlr_keyboard_set_keymap(tkb, keyboard->keymap); - wlr_keyboard_notify_modifiers(tkb, depressed, latched, locked, 0); + wlr_keyboard_notify_modifiers(tkb, depressed, latched, server.locked, + 0); tkb->modifiers.group = 0; - // 7. 更新 seat - wlr_seat_set_keyboard(seat, tkb); - wlr_seat_keyboard_notify_modifiers(seat, &tkb->modifiers); + // 7. 更新 server.seat + wlr_seat_set_keyboard(server.seat, tkb); + wlr_seat_keyboard_notify_modifiers(server.seat, &tkb->modifiers); } // Cleanup @@ -5059,28 +5193,28 @@ void setmon(Client *c, Monitor *m, uint32_t newtags, bool focus) { } if (focus && !client_is_x11_popup(c)) { - focusclient(focustop(selmon), 1); + focusclient(focustop(server.selmon), 1); } } void setpsel(struct wl_listener *listener, void *data) { - /* This event is raised by the seat when a client wants to set the + /* This event is raised by the server.seat when a client wants to set the * selection, usually when the user copies something. wlroots allows * compositors to ignore such requests if they so choose, but in dwl we * always honor */ struct wlr_seat_request_set_primary_selection_event *event = data; - wlr_seat_set_primary_selection(seat, event->source, event->serial); + wlr_seat_set_primary_selection(server.seat, event->source, event->serial); } void setsel(struct wl_listener *listener, void *data) { - /* This event is raised by the seat when a client wants to set the + /* This event is raised by the server.seat when a client wants to set the * selection, usually when the user copies something. wlroots allows * compositors to ignore such requests if they so choose, but in dwl we * always honor */ struct wlr_seat_request_set_selection_event *event = data; - wlr_seat_set_selection(seat, event->source, event->serial); + wlr_seat_set_selection(server.seat, event->source, event->serial); } void show_hide_client(Client *c) { @@ -5107,16 +5241,16 @@ void create_output(struct wlr_backend *backend, void *data) { return; } - if (wlr_backend_is_wl(backend)) { - wlr_wl_output_create(backend); + if (wlr_backend_is_wl(server.backend)) { + wlr_wl_output_create(server.backend); *done = true; - } else if (wlr_backend_is_headless(backend)) { - wlr_headless_add_output(backend, 1920, 1080); + } else if (wlr_backend_is_headless(server.backend)) { + wlr_headless_add_output(server.backend, 1920, 1080); *done = true; } #if WLR_HAS_X11_BACKEND - else if (wlr_backend_is_x11(backend)) { - wlr_x11_output_create(backend); + else if (wlr_backend_is_x11(server.backend)) { + wlr_x11_output_create(server.backend); *done = true; } #endif @@ -5126,7 +5260,7 @@ void create_output(struct wlr_backend *backend, void *data) { void handle_print_status(struct wl_listener *listener, void *data) { Monitor *m = NULL; - wl_list_for_each(m, &mons, link) { + wl_list_for_each(m, &server.mons, link) { if (!m->wlr_output->enabled) { continue; } @@ -5154,112 +5288,120 @@ void setup(void) { wlr_log_init(log_level, NULL); /* The Wayland display is managed by libwayland. It handles accepting - * clients from the Unix socket, manging Wayland globals, and so on. */ - dpy = wl_display_create(); - event_loop = wl_display_get_event_loop(dpy); - /* The backend is a wlroots feature which abstracts the underlying input - * and output hardware. The autocreate option will choose the most - * suitable backend based on the current environment, such as opening an - * X11 window if an X11 server is running. The NULL argument here + * server.clients from the Unix socket, manging Wayland globals, and so on. + */ + server.dpy = wl_display_create(); + server.event_loop = wl_display_get_event_loop(server.dpy); + /* The server.backend is a wlroots feature which abstracts the underlying + * input and output hardware. The autocreate option will choose the most + * suitable server.backend based on the current environment, such as opening + * an X11 window if an X11 server is running. The NULL argument here * optionally allows you to pass in a custom renderer if wlr_renderer - * doesn't meet your needs. The backend uses the renderer, for example, - * to fall back to software cursors if the backend does not support - * hardware cursors (some older GPUs don't). */ - if (!(backend = wlr_backend_autocreate(event_loop, &session))) - die("couldn't create backend"); + * doesn't meet your needs. The server.backend uses the renderer, for + * example, to fall back to software cursors if the server.backend does not + * support hardware cursors (some older GPUs don't). */ + if (!(server.backend = + wlr_backend_autocreate(server.event_loop, &server.session))) + die("couldn't create server.backend"); - headless_backend = wlr_headless_backend_create(event_loop); - if (!headless_backend) { - wlr_log(WLR_ERROR, "Failed to create secondary headless backend"); + server.headless_backend = wlr_headless_backend_create(server.event_loop); + if (!server.headless_backend) { + wlr_log(WLR_ERROR, + "Failed to create secondary headless server.backend"); } else { - wlr_multi_backend_add(backend, headless_backend); + wlr_multi_backend_add(server.backend, server.headless_backend); } - /* Initialize the scene graph used to lay out windows */ - scene = wlr_scene_create(); - root_bg = wlr_scene_rect_create(&scene->tree, 0, 0, rootcolor); + /* Initialize the server.scene graph used to lay out windows */ + server.scene = wlr_scene_create(); + server.root_bg = + wlr_scene_rect_create(&server.scene->tree, 0, 0, rootcolor); for (i = 0; i < NUM_LAYERS; i++) - layers[i] = wlr_scene_tree_create(&scene->tree); - drag_icon = wlr_scene_tree_create(&scene->tree); - wlr_scene_node_place_below(&drag_icon->node, &layers[LyrBlock]->node); + server.layers[i] = wlr_scene_tree_create(&server.scene->tree); + server.drag_icon = wlr_scene_tree_create(&server.scene->tree); + wlr_scene_node_place_below(&server.drag_icon->node, + &server.layers[LyrBlock]->node); /* Create a renderer with the default implementation */ - if (!(drw = fx_renderer_create(backend))) + if (!(server.drw = fx_renderer_create(server.backend))) die("couldn't create renderer"); - wl_signal_add(&drw->events.lost, &gpu_reset); + wl_signal_add(&server.drw->events.lost, &gpu_reset); /* Create shm, drm and linux_dmabuf interfaces by ourselves. * The simplest way is call: - * wlr_renderer_init_wl_display(drw); + * wlr_renderer_init_wl_display(server.drw); * but we need to create manually the linux_dmabuf interface to * integrate it with wlr_scene. */ - wlr_renderer_init_wl_shm(drw, dpy); + wlr_renderer_init_wl_shm(server.drw, server.dpy); - if (wlr_renderer_get_texture_formats(drw, WLR_BUFFER_CAP_DMABUF)) { - wlr_drm_create(dpy, drw); - wlr_scene_set_linux_dmabuf_v1( - scene, wlr_linux_dmabuf_v1_create_with_renderer(dpy, 5, drw)); + if (wlr_renderer_get_texture_formats(server.drw, WLR_BUFFER_CAP_DMABUF)) { + wlr_drm_create(server.dpy, server.drw); + wlr_scene_set_linux_dmabuf_v1(server.scene, + wlr_linux_dmabuf_v1_create_with_renderer( + server.dpy, 5, server.drw)); } - if (syncobj_enable && (drm_fd = wlr_renderer_get_drm_fd(drw)) >= 0 && - drw->features.timeline && backend->features.timeline) - wlr_linux_drm_syncobj_manager_v1_create(dpy, 1, drm_fd); + if (syncobj_enable && (drm_fd = wlr_renderer_get_drm_fd(server.drw)) >= 0 && + server.drw->features.timeline && server.backend->features.timeline) + wlr_linux_drm_syncobj_manager_v1_create(server.dpy, 1, drm_fd); /* Create a default allocator */ - if (!(alloc = wlr_allocator_autocreate(backend, drw))) + if (!(server.alloc = wlr_allocator_autocreate(server.backend, server.drw))) die("couldn't create allocator"); - /* This creates some hands-off wlroots interfaces. The compositor is - * necessary for clients to allocate surfaces and the data device + /* This creates some hands-off wlroots interfaces. The server.compositor is + * necessary for server.clients to allocate surfaces and the data device * manager handles the clipboard. Each of these wlroots interfaces has * room for you to dig your fingers in and play with their behavior if - * you want. Note that the clients cannot set the selection directly - * without compositor approval, see the setsel() function. */ - compositor = wlr_compositor_create(dpy, 6, drw); - wlr_export_dmabuf_manager_v1_create(dpy); - wlr_screencopy_manager_v1_create(dpy); - wlr_ext_image_copy_capture_manager_v1_create(dpy, 1); - wlr_ext_output_image_capture_source_manager_v1_create(dpy, 1); - wlr_data_control_manager_v1_create(dpy); - wlr_data_device_manager_create(dpy); - wlr_primary_selection_v1_device_manager_create(dpy); - wlr_viewporter_create(dpy); - wlr_single_pixel_buffer_manager_v1_create(dpy); - wlr_fractional_scale_manager_v1_create(dpy, 1); - wlr_presentation_create(dpy, backend, 2); - wlr_subcompositor_create(dpy); - wlr_alpha_modifier_v1_create(dpy); - wlr_ext_data_control_manager_v1_create(dpy, 1); + * you want. Note that the server.clients cannot set the selection directly + * without server.compositor approval, see the setsel() function. */ + server.compositor = wlr_compositor_create(server.dpy, 6, server.drw); + wlr_export_dmabuf_manager_v1_create(server.dpy); + wlr_screencopy_manager_v1_create(server.dpy); + wlr_ext_image_copy_capture_manager_v1_create(server.dpy, 1); + wlr_ext_output_image_capture_source_manager_v1_create(server.dpy, 1); + wlr_data_control_manager_v1_create(server.dpy); + wlr_data_device_manager_create(server.dpy); + wlr_primary_selection_v1_device_manager_create(server.dpy); + wlr_viewporter_create(server.dpy); + wlr_single_pixel_buffer_manager_v1_create(server.dpy); + wlr_fractional_scale_manager_v1_create(server.dpy, 1); + wlr_presentation_create(server.dpy, server.backend, 2); + wlr_subcompositor_create(server.dpy); + wlr_alpha_modifier_v1_create(server.dpy); + wlr_ext_data_control_manager_v1_create(server.dpy, 1); // 在 setup 函数中 wl_signal_init(&mango_print_status); wl_signal_add(&mango_print_status, &print_status_listener); /* Initializes the interface used to implement urgency hints */ - activation = wlr_xdg_activation_v1_create(dpy); - wl_signal_add(&activation->events.request_activate, &request_activate); + server.activation = wlr_xdg_activation_v1_create(server.dpy); + wl_signal_add(&server.activation->events.request_activate, + &request_activate); wlr_scene_set_gamma_control_manager_v1( - scene, wlr_gamma_control_manager_v1_create(dpy)); + server.scene, wlr_gamma_control_manager_v1_create(server.dpy)); - power_mgr = wlr_output_power_manager_v1_create(dpy); - wl_signal_add(&power_mgr->events.set_mode, &output_power_mgr_set_mode); + server.power_mgr = wlr_output_power_manager_v1_create(server.dpy); + wl_signal_add(&server.power_mgr->events.set_mode, + &output_power_mgr_set_mode); - tearing_control = wlr_tearing_control_manager_v1_create(dpy, 1); + tearing_control = wlr_tearing_control_manager_v1_create(server.dpy, 1); tearing_new_object.notify = handle_tearing_new_object; wl_signal_add(&tearing_control->events.new_object, &tearing_new_object); /* Creates an output layout, which a wlroots utility for working with an * arrangement of screens in a physical layout. */ - output_layout = wlr_output_layout_create(dpy); - wl_signal_add(&output_layout->events.change, &layout_change); - wlr_xdg_output_manager_v1_create(dpy, output_layout); + server.output_layout = wlr_output_layout_create(server.dpy); + wl_signal_add(&server.output_layout->events.change, &layout_change); + wlr_xdg_output_manager_v1_create(server.dpy, server.output_layout); /* Configure a listener to be notified when new outputs are available on - * the backend. */ - wl_list_init(&mons); - wl_signal_add(&backend->events.new_output, &new_output); + * the server.backend. */ + wl_list_init(&server.mons); + wl_signal_add(&server.backend->events.new_output, &new_output); /* Set up our client lists and the xdg-shell. The xdg-shell is a * Wayland protocol which is used for application windows. For more @@ -5267,159 +5409,166 @@ void setup(void) { * * https://drewdevault.com/2018/07/29/Wayland-shells.html */ - wl_list_init(&clients); - wl_list_init(&fstack); - wl_list_init(&fadeout_clients); - wl_list_init(&fadeout_layers); - idle_notifier = wlr_idle_notifier_v1_create(dpy); + server.idle_notifier = wlr_idle_notifier_v1_create(server.dpy); - idle_inhibit_mgr = wlr_idle_inhibit_v1_create(dpy); - wl_signal_add(&idle_inhibit_mgr->events.new_inhibitor, &new_idle_inhibitor); + server.idle_inhibit_mgr = wlr_idle_inhibit_v1_create(server.dpy); + wl_signal_add(&server.idle_inhibit_mgr->events.new_inhibitor, + &new_idle_inhibitor); - layer_shell = wlr_layer_shell_v1_create(dpy, 4); - wl_signal_add(&layer_shell->events.new_surface, &new_layer_surface); + server.layer_shell = wlr_layer_shell_v1_create(server.dpy, 4); + wl_signal_add(&server.layer_shell->events.new_surface, &new_layer_surface); - xdg_shell = wlr_xdg_shell_create(dpy, 6); - wl_signal_add(&xdg_shell->events.new_toplevel, &new_xdg_toplevel); - wl_signal_add(&xdg_shell->events.new_popup, &new_xdg_popup); + server.xdg_shell = wlr_xdg_shell_create(server.dpy, 6); + wl_signal_add(&server.xdg_shell->events.new_toplevel, &new_xdg_toplevel); + wl_signal_add(&server.xdg_shell->events.new_popup, &new_xdg_popup); - session_lock_mgr = wlr_session_lock_manager_v1_create(dpy); - wl_signal_add(&session_lock_mgr->events.new_lock, &new_session_lock); + server.session_lock_mgr = wlr_session_lock_manager_v1_create(server.dpy); + wl_signal_add(&server.session_lock_mgr->events.new_lock, &new_session_lock); - locked_bg = - wlr_scene_rect_create(layers[LyrBlock], sgeom.width, sgeom.height, - (float[4]){0.1, 0.1, 0.1, 1.0}); - wlr_scene_node_set_enabled(&locked_bg->node, false); + server.locked_bg = wlr_scene_rect_create( + server.layers[LyrBlock], server.sgeom.width, server.sgeom.height, + (float[4]){0.1, 0.1, 0.1, 1.0}); + wlr_scene_node_set_enabled(&server.locked_bg->node, false); /* Use decoration protocols to negotiate server-side decorations */ wlr_server_decoration_manager_set_default_mode( - wlr_server_decoration_manager_create(dpy), + wlr_server_decoration_manager_create(server.dpy), WLR_SERVER_DECORATION_MANAGER_MODE_SERVER); - xdg_decoration_mgr = wlr_xdg_decoration_manager_v1_create(dpy); - wl_signal_add(&xdg_decoration_mgr->events.new_toplevel_decoration, + server.xdg_decoration_mgr = + wlr_xdg_decoration_manager_v1_create(server.dpy); + wl_signal_add(&server.xdg_decoration_mgr->events.new_toplevel_decoration, &new_xdg_decoration); - pointer_constraints = wlr_pointer_constraints_v1_create(dpy); - wl_signal_add(&pointer_constraints->events.new_constraint, + server.pointer_constraints = wlr_pointer_constraints_v1_create(server.dpy); + wl_signal_add(&server.pointer_constraints->events.new_constraint, &new_pointer_constraint); - relative_pointer_mgr = wlr_relative_pointer_manager_v1_create(dpy); + server.relative_pointer_mgr = + wlr_relative_pointer_manager_v1_create(server.dpy); /* - * Creates a cursor, which is a wlroots utility for tracking the cursor - * image shown on screen. + * Creates a server.cursor, which is a wlroots utility for tracking the + * server.cursor image shown on screen. */ - cursor = wlr_cursor_create(); - wlr_cursor_attach_output_layout(cursor, output_layout); + server.cursor = wlr_cursor_create(); + wlr_cursor_attach_output_layout(server.cursor, server.output_layout); /* Creates an xcursor manager, another wlroots utility which loads up - * Xcursor themes to source cursor images from and makes sure that - * cursor images are available at all scale factors on the screen + * Xcursor themes to source server.cursor images from and makes sure that + * server.cursor images are available at all scale factors on the screen * (necessary for HiDPI support). Scaled cursors will be loaded with * each output. */ - // cursor_mgr = wlr_xcursor_manager_create(cursor_theme, 24); - cursor_mgr = wlr_xcursor_manager_create(config.cursor_theme, cursor_size); + // server.cursor_mgr = wlr_xcursor_manager_create(cursor_theme, 24); + server.cursor_mgr = + wlr_xcursor_manager_create(config.cursor_theme, cursor_size); /* * wlr_cursor *only* displays an image on screen. It does not move * around when the pointer moves. However, we can attach input devices * to it, and it will generate aggregate events for all of them. In * these events, we can choose how we want to process them, forwarding - * them to clients and moving the cursor around. More detail on this - * process is described in my input handling blog post: + * them to server.clients and moving the server.cursor around. More detail + * on this process is described in my input handling blog post: * * https://drewdevault.com/2018/07/17/Input-handling-in-wlroots.html * * And more comments are sprinkled throughout the notify functions * above. */ - wl_signal_add(&cursor->events.motion, &cursor_motion); - wl_signal_add(&cursor->events.motion_absolute, &cursor_motion_absolute); - wl_signal_add(&cursor->events.button, &cursor_button); - wl_signal_add(&cursor->events.axis, &cursor_axis); - wl_signal_add(&cursor->events.frame, &cursor_frame); + wl_signal_add(&server.cursor->events.motion, &cursor_motion); + wl_signal_add(&server.cursor->events.motion_absolute, + &cursor_motion_absolute); + wl_signal_add(&server.cursor->events.button, &cursor_button); + wl_signal_add(&server.cursor->events.axis, &cursor_axis); + wl_signal_add(&server.cursor->events.frame, &cursor_frame); // 这两句代码会造成obs窗口里的鼠标光标消失,不知道注释有什么影响 - cursor_shape_mgr = wlr_cursor_shape_manager_v1_create(dpy, 1); - wl_signal_add(&cursor_shape_mgr->events.request_set_shape, + server.cursor_shape_mgr = wlr_cursor_shape_manager_v1_create(server.dpy, 1); + wl_signal_add(&server.cursor_shape_mgr->events.request_set_shape, &request_set_cursor_shape); - hide_source = wl_event_loop_add_timer(wl_display_get_event_loop(dpy), - hidecursor, cursor); + server.hide_source = wl_event_loop_add_timer( + wl_display_get_event_loop(server.dpy), hidecursor, server.cursor); /* - * Configures a seat, which is a single "seat" at which a user sits and - * operates the computer. This conceptually includes up to one keyboard, - * pointer, touch, and drawing tablet device. We also rig up a listener - * to let us know when new input devices are available on the backend. + * Configures a server.seat , which is a single "server.seat " at which a + * user sits and operates the computer. This conceptually includes up to one + * keyboard, pointer, touch, and drawing tablet device. We also rig up a + * listener to let us know when new input devices are available on the + * server.backend. */ - wl_list_init(&inputdevices); - wl_list_init(&keyboard_shortcut_inhibitors); - wl_signal_add(&backend->events.new_input, &new_input_device); - virtual_keyboard_mgr = wlr_virtual_keyboard_manager_v1_create(dpy); - wl_signal_add(&virtual_keyboard_mgr->events.new_virtual_keyboard, + wl_signal_add(&server.backend->events.new_input, &new_input_device); + server.virtual_keyboard_mgr = + wlr_virtual_keyboard_manager_v1_create(server.dpy); + wl_signal_add(&server.virtual_keyboard_mgr->events.new_virtual_keyboard, &new_virtual_keyboard); - virtual_pointer_mgr = wlr_virtual_pointer_manager_v1_create(dpy); - wl_signal_add(&virtual_pointer_mgr->events.new_virtual_pointer, + server.virtual_pointer_mgr = + wlr_virtual_pointer_manager_v1_create(server.dpy); + wl_signal_add(&server.virtual_pointer_mgr->events.new_virtual_pointer, &new_virtual_pointer); - pointer_gestures = wlr_pointer_gestures_v1_create(dpy); - LISTEN_STATIC(&cursor->events.swipe_begin, swipe_begin); - LISTEN_STATIC(&cursor->events.swipe_update, swipe_update); - LISTEN_STATIC(&cursor->events.swipe_end, swipe_end); - LISTEN_STATIC(&cursor->events.pinch_begin, pinch_begin); - LISTEN_STATIC(&cursor->events.pinch_update, pinch_update); - LISTEN_STATIC(&cursor->events.pinch_end, pinch_end); - LISTEN_STATIC(&cursor->events.hold_begin, hold_begin); - LISTEN_STATIC(&cursor->events.hold_end, hold_end); + server.pointer_gestures = wlr_pointer_gestures_v1_create(server.dpy); + LISTEN_STATIC(&server.cursor->events.swipe_begin, swipe_begin); + LISTEN_STATIC(&server.cursor->events.swipe_update, swipe_update); + LISTEN_STATIC(&server.cursor->events.swipe_end, swipe_end); + LISTEN_STATIC(&server.cursor->events.pinch_begin, pinch_begin); + LISTEN_STATIC(&server.cursor->events.pinch_update, pinch_update); + LISTEN_STATIC(&server.cursor->events.pinch_end, pinch_end); + LISTEN_STATIC(&server.cursor->events.hold_begin, hold_begin); + LISTEN_STATIC(&server.cursor->events.hold_end, hold_end); - seat = wlr_seat_create(dpy, "seat0"); - wl_signal_add(&seat->events.request_set_cursor, &request_cursor); - wl_signal_add(&seat->events.request_set_selection, &request_set_sel); - wl_signal_add(&seat->events.request_set_primary_selection, + server.seat = wlr_seat_create(server.dpy, "seat0"); + wl_signal_add(&server.seat->events.request_set_cursor, &request_cursor); + wl_signal_add(&server.seat->events.request_set_selection, &request_set_sel); + wl_signal_add(&server.seat->events.request_set_primary_selection, &request_set_psel); - wl_signal_add(&seat->events.request_start_drag, &request_start_drag); - wl_signal_add(&seat->events.start_drag, &start_drag); + wl_signal_add(&server.seat->events.request_start_drag, &request_start_drag); + wl_signal_add(&server.seat->events.start_drag, &start_drag); - kb_group = createkeyboardgroup(); - wl_list_init(&kb_group->destroy.link); + server.kb_group = createkeyboardgroup(); + wl_list_init(&server.kb_group->destroy.link); - keyboard_shortcuts_inhibit = wlr_keyboard_shortcuts_inhibit_v1_create(dpy); - wl_signal_add(&keyboard_shortcuts_inhibit->events.new_inhibitor, + server.keyboard_shortcuts_inhibit = + wlr_keyboard_shortcuts_inhibit_v1_create(server.dpy); + wl_signal_add(&server.keyboard_shortcuts_inhibit->events.new_inhibitor, &keyboard_shortcuts_inhibit_new_inhibitor); - output_mgr = wlr_output_manager_v1_create(dpy); - wl_signal_add(&output_mgr->events.apply, &output_mgr_apply); - wl_signal_add(&output_mgr->events.test, &output_mgr_test); + server.output_mgr = wlr_output_manager_v1_create(server.dpy); + wl_signal_add(&server.output_mgr->events.apply, &output_mgr_apply); + wl_signal_add(&server.output_mgr->events.test, &output_mgr_test); // blur - wlr_scene_set_blur_data(scene, blur_params.num_passes, blur_params.radius, - blur_params.noise, blur_params.brightness, - blur_params.contrast, blur_params.saturation); + wlr_scene_set_blur_data(server.scene, blur_params.num_passes, + blur_params.radius, blur_params.noise, + blur_params.brightness, blur_params.contrast, + blur_params.saturation); /* create text_input-, and input_method-protocol relevant globals */ - input_method_manager = wlr_input_method_manager_v2_create(dpy); - text_input_manager = wlr_text_input_manager_v3_create(dpy); + input_method_manager = wlr_input_method_manager_v2_create(server.dpy); + text_input_manager = wlr_text_input_manager_v3_create(server.dpy); dwl_input_method_relay = dwl_im_relay_create(); - drm_lease_manager = wlr_drm_lease_v1_manager_create(dpy, backend); - if (drm_lease_manager) { - wl_signal_add(&drm_lease_manager->events.request, &drm_lease_request); + server.drm_lease_manager = + wlr_drm_lease_v1_manager_create(server.dpy, server.backend); + if (server.drm_lease_manager) { + wl_signal_add(&server.drm_lease_manager->events.request, + &drm_lease_request); } else { wlr_log(WLR_DEBUG, "Failed to create wlr_drm_lease_device_v1."); wlr_log(WLR_INFO, "VR will not be available."); } - wl_global_create(dpy, &zdwl_ipc_manager_v2_interface, 2, NULL, + wl_global_create(server.dpy, &zdwl_ipc_manager_v2_interface, 2, NULL, dwl_ipc_manager_bind); // 创建顶层管理句柄 - foreign_toplevel_manager = wlr_foreign_toplevel_manager_v1_create(dpy); + foreign_toplevel_manager = + wlr_foreign_toplevel_manager_v1_create(server.dpy); struct wlr_xdg_foreign_registry *foreign_registry = - wlr_xdg_foreign_registry_create(dpy); - wlr_xdg_foreign_v1_create(dpy, foreign_registry); - wlr_xdg_foreign_v2_create(dpy, foreign_registry); + wlr_xdg_foreign_registry_create(server.dpy); + wlr_xdg_foreign_v1_create(server.dpy, foreign_registry); + wlr_xdg_foreign_v2_create(server.dpy, foreign_registry); // ext-workspace协议 workspaces_init(); @@ -5428,7 +5577,8 @@ void setup(void) { * Initialise the XWayland X server. * It will be started when the first X client is started. */ - xwayland = wlr_xwayland_create(dpy, compositor, !xwayland_persistence); + xwayland = wlr_xwayland_create(server.dpy, server.compositor, + !xwayland_persistence); if (xwayland) { wl_signal_add(&xwayland->events.ready, &xwayland_ready); wl_signal_add(&xwayland->events.new_surface, &new_xwayland_surface); @@ -5446,7 +5596,8 @@ void startdrag(struct wl_listener *listener, void *data) { if (!drag->icon) return; - drag->icon->data = &wlr_scene_drag_icon_create(drag_icon, drag->icon)->node; + drag->icon->data = + &wlr_scene_drag_icon_create(server.drag_icon, drag->icon)->node; LISTEN_STATIC(&drag->icon->events.destroy, destroydragicon); } @@ -5458,7 +5609,7 @@ void tag_client(const Arg *arg, Client *target_client) { target_client->tags = arg->ui & TAGMASK; target_client->istagswitching = 1; - wl_list_for_each(fc, &clients, link) { + wl_list_for_each(fc, &server.clients, link) { if (fc && fc != target_client && target_client->tags & fc->tags && ISFULLSCREEN(fc) && !target_client->isfloating) { clear_fullscreen_flag(fc); @@ -5479,9 +5630,9 @@ void overview(Monitor *m) { grid(m); } // 目标窗口有其他窗口和它同个tag就返回0 uint32_t want_restore_fullscreen(Client *target_client) { Client *c = NULL; - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { if (c && c != target_client && c->tags == target_client->tags && - c == selmon->sel && + c == server.selmon->sel && c->mon->pertag->ltidxs[get_tags_first_tag_num(c->tags)]->id != SCROLLER && c->mon->pertag->ltidxs[get_tags_first_tag_num(c->tags)]->id != @@ -5528,7 +5679,7 @@ void overview_restore(Client *c, const Arg *arg) { c->is_restoring_from_ov = (arg->ui & c->tags & TAGMASK) == 0 ? true : false; if (c->isfloating) { - // XRaiseWindow(dpy, c->win); // 提升悬浮窗口到顶层 + // XRaiseWindow(server.dpy, c->win); // 提升悬浮窗口到顶层 resize(c, c->overview_backup_geom, 0); } else if (c->isfullscreen || c->ismaximizescreen) { if (want_restore_fullscreen(c) && c->ismaximizescreen) { @@ -5554,24 +5705,27 @@ void overview_restore(Client *c, const Arg *arg) { } void handlecursoractivity(void) { - wl_event_source_timer_update(hide_source, cursor_hide_timeout * 1000); + wl_event_source_timer_update(server.hide_source, + cursor_hide_timeout * 1000); - if (!cursor_hidden) + if (!server.cursor_hidden) return; - cursor_hidden = false; + server.cursor_hidden = false; - if (last_cursor.shape) - wlr_cursor_set_xcursor(cursor, cursor_mgr, - wlr_cursor_shape_v1_name(last_cursor.shape)); + if (server.last_cursor.shape) + wlr_cursor_set_xcursor( + server.cursor, server.cursor_mgr, + wlr_cursor_shape_v1_name(server.last_cursor.shape)); else - wlr_cursor_set_surface(cursor, last_cursor.surface, - last_cursor.hotspot_x, last_cursor.hotspot_y); + wlr_cursor_set_surface(server.cursor, server.last_cursor.surface, + server.last_cursor.hotspot_x, + server.last_cursor.hotspot_y); } int32_t hidecursor(void *data) { - wlr_cursor_unset_image(cursor); - cursor_hidden = true; + wlr_cursor_unset_image(server.cursor); + server.cursor_hidden = true; return 1; } @@ -5589,12 +5743,13 @@ void unmaplayersurfacenotify(struct wl_listener *listener, void *data) { init_fadeout_layers(l); wlr_scene_node_set_enabled(&l->scene->node, false); - if (l == exclusive_focus) - exclusive_focus = NULL; + if (l == server.exclusive_focus) + server.exclusive_focus = NULL; if (l->layer_surface->output && (l->mon = l->layer_surface->output->data)) arrangelayers(l->mon); - if (l->layer_surface->surface == seat->keyboard_state.focused_surface) - focusclient(focustop(selmon), 1); + if (l->layer_surface->surface == + server.seat->keyboard_state.focused_surface) + focusclient(focustop(server.selmon), 1); motionnotify(0, NULL, 0, 0, 0, 0); l->being_unmapped = false; wlr_scene_node_destroy(&l->shadow->node); @@ -5624,12 +5779,12 @@ void unmapnotify(struct wl_listener *listener, void *data) { exit_scroller_stack(c); } - if (c == grabc) { - cursor_mode = CurNormal; - grabc = NULL; + if (c == server.grabc) { + server.cursor_mode = CurNormal; + server.grabc = NULL; } - wl_list_for_each(m, &mons, link) { + wl_list_for_each(m, &server.mons, link) { if (!m->wlr_output->enabled) { continue; } @@ -5641,20 +5796,20 @@ void unmapnotify(struct wl_listener *listener, void *data) { } } - if (c->mon && c->mon == selmon) { + if (c->mon && c->mon == server.selmon) { if (next_in_stack && !c->swallowedby) { nextfocus = next_in_stack; } else if (prev_in_stack && !c->swallowedby) { nextfocus = prev_in_stack; } else { - nextfocus = focustop(selmon); + nextfocus = focustop(server.selmon); } if (nextfocus) { focusclient(nextfocus, 0); } - if (!nextfocus && selmon->isoverview) { + if (!nextfocus && server.selmon->isoverview) { Arg arg = {0}; toggleoverview(&arg); } @@ -5666,10 +5821,10 @@ void unmapnotify(struct wl_listener *listener, void *data) { wl_list_remove(&c->set_geometry.link); } #endif - if (c == exclusive_focus) - exclusive_focus = NULL; - if (client_surface(c) == seat->keyboard_state.focused_surface) - focusclient(focustop(selmon), 1); + if (c == server.exclusive_focus) + server.exclusive_focus = NULL; + if (client_surface(c) == server.seat->keyboard_state.focused_surface) + focusclient(focustop(server.selmon), 1); } else { if (!c->swallowing) wl_list_remove(&c->link); @@ -5720,36 +5875,40 @@ void updatemons(struct wl_listener *listener, void *data) { int32_t mon_pos_offsetx, mon_pos_offsety, oldx, oldy; /* First remove from the layout the disabled monitors */ - wl_list_for_each(m, &mons, link) { + wl_list_for_each(m, &server.mons, link) { if (m->wlr_output->enabled || m->asleep) continue; config_head = wlr_output_configuration_head_v1_create(config, m->wlr_output); config_head->state.enabled = 0; - /* Remove this output from the layout to avoid cursor enter inside - * it */ - wlr_output_layout_remove(output_layout, m->wlr_output); + /* Remove this output from the layout to avoid server.cursor enter + * inside it */ + wlr_output_layout_remove(server.output_layout, m->wlr_output); closemon(m); m->m = m->w = (struct wlr_box){0}; } /* Insert outputs that need to */ - wl_list_for_each(m, &mons, link) { + wl_list_for_each(m, &server.mons, link) { if (m->wlr_output->enabled && - !wlr_output_layout_get(output_layout, m->wlr_output)) - wlr_output_layout_add_auto(output_layout, m->wlr_output); + !wlr_output_layout_get(server.output_layout, m->wlr_output)) + wlr_output_layout_add_auto(server.output_layout, m->wlr_output); } /* Now that we update the output layout we can get its box */ - wlr_output_layout_get_box(output_layout, NULL, &sgeom); + wlr_output_layout_get_box(server.output_layout, NULL, &server.sgeom); - wlr_scene_node_set_position(&root_bg->node, sgeom.x, sgeom.y); - wlr_scene_rect_set_size(root_bg, sgeom.width, sgeom.height); + wlr_scene_node_set_position(&server.root_bg->node, server.sgeom.x, + server.sgeom.y); + wlr_scene_rect_set_size(server.root_bg, server.sgeom.width, + server.sgeom.height); - /* Make sure the clients are hidden when dwl is locked */ - wlr_scene_node_set_position(&locked_bg->node, sgeom.x, sgeom.y); - wlr_scene_rect_set_size(locked_bg, sgeom.width, sgeom.height); + /* Make sure the server.clients are hidden when dwl is server.locked */ + wlr_scene_node_set_position(&server.locked_bg->node, server.sgeom.x, + server.sgeom.y); + wlr_scene_rect_set_size(server.locked_bg, server.sgeom.width, + server.sgeom.height); - wl_list_for_each(m, &mons, link) { + wl_list_for_each(m, &server.mons, link) { if (!m->wlr_output->enabled) continue; config_head = @@ -5758,12 +5917,12 @@ void updatemons(struct wl_listener *listener, void *data) { oldx = m->m.x; oldy = m->m.y; /* Get the effective monitor geometry to use for surfaces */ - wlr_output_layout_get_box(output_layout, m->wlr_output, &m->m); + wlr_output_layout_get_box(server.output_layout, m->wlr_output, &m->m); m->w = m->m; mon_pos_offsetx = m->m.x - oldx; mon_pos_offsety = m->m.y - oldy; - wl_list_for_each(c, &clients, link) { + wl_list_for_each(c, &server.clients, link) { // floating window position auto adjust the change of monitor // position if (c->isfloating && c->mon == m) { @@ -5798,44 +5957,45 @@ void updatemons(struct wl_listener *listener, void *data) { m->m.height); } - /* Calculate the effective monitor geometry to use for clients */ + /* Calculate the effective monitor geometry to use for server.clients */ arrangelayers(m); - /* Don't move clients to the left output when plugging monitors */ + /* Don't move server.clients to the left output when plugging monitors + */ arrange(m, false, false); - /* make sure fullscreen clients have the right size */ + /* make sure fullscreen server.clients have the right size */ if ((c = focustop(m)) && c->isfullscreen) resize(c, m->m, 0); config_head->state.x = m->m.x; config_head->state.y = m->m.y; - if (!selmon) - selmon = m; + if (!server.selmon) + server.selmon = m; } - if (selmon && selmon->wlr_output->enabled) { - wl_list_for_each(c, &clients, link) { + if (server.selmon && server.selmon->wlr_output->enabled) { + wl_list_for_each(c, &server.clients, link) { if (!c->mon && client_surface(c)->mapped) { - c->mon = selmon; + c->mon = server.selmon; reset_foreign_tolevel(c); } } - focusclient(focustop(selmon), 1); - if (selmon->lock_surface) { - client_notify_enter(selmon->lock_surface->surface, - wlr_seat_get_keyboard(seat)); - client_activate_surface(selmon->lock_surface->surface, 1); + focusclient(focustop(server.selmon), 1); + if (server.selmon->lock_surface) { + client_notify_enter(server.selmon->lock_surface->surface, + wlr_seat_get_keyboard(server.seat)); + client_activate_surface(server.selmon->lock_surface->surface, 1); } } - /* FIXME: figure out why the cursor image is at 0,0 after turning all + /* FIXME: figure out why the server.cursor image is at 0,0 after turning all * the monitors on. - * Move the cursor image where it used to be. It does not generate a - * wl_pointer.motion event for the clients, it's only the image what + * Move the server.cursor image where it used to be. It does not generate a + * wl_pointer.motion event for the server.clients, it's only the image what * it's at the wrong position after all. */ - wlr_cursor_move(cursor, NULL, 0, 0); + wlr_cursor_move(server.cursor, NULL, 0, 0); - wlr_output_manager_v1_set_configuration(output_mgr, config); + wlr_output_manager_v1_set_configuration(server.output_mgr, config); } void updatetitle(struct wl_listener *listener, void *data) { @@ -5861,11 +6021,12 @@ urgent(struct wl_listener *listener, void *data) { if (!c || !c->foreign_toplevel) return; - if (focus_on_activate && !c->istagsilent && c != selmon->sel) { - if (!(c->mon == selmon && c->tags & c->mon->tagset[c->mon->seltags])) + if (focus_on_activate && !c->istagsilent && c != server.selmon->sel) { + if (!(c->mon == server.selmon && + c->tags & c->mon->tagset[c->mon->seltags])) view_in_mon(&(Arg){.ui = c->tags}, true, c->mon, true); focusclient(c, 1); - } else if (c != focustop(selmon)) { + } else if (c != focustop(server.selmon)) { c->isurgent = 1; if (client_surface(c)->mapped) setborder_color(c); @@ -5930,15 +6091,15 @@ toggleseltags: void view(const Arg *arg, bool want_animation) { Monitor *m = NULL; if (arg->i) { - view_in_mon(arg, want_animation, selmon, true); - wl_list_for_each(m, &mons, link) { - if (!m->wlr_output->enabled || m == selmon) + view_in_mon(arg, want_animation, server.selmon, true); + wl_list_for_each(m, &server.mons, link) { + if (!m->wlr_output->enabled || m == server.selmon) continue; // only arrange, not change monitor focus view_in_mon(arg, want_animation, m, false); } } else { - view_in_mon(arg, want_animation, selmon, true); + view_in_mon(arg, want_animation, server.selmon, true); } } @@ -5964,7 +6125,7 @@ void handle_keyboard_shortcuts_inhibit_new_inhibitor( return; } - // per-view, seat-agnostic config via criteria + // per-view, server.seat -agnostic config via criteria Client *c = NULL; LayerSurface *l = NULL; @@ -5987,7 +6148,7 @@ void handle_keyboard_shortcuts_inhibit_new_inhibitor( kbsinhibitor->destroy.notify = handle_keyboard_shortcuts_inhibitor_destroy; wl_signal_add(&inhibitor->events.destroy, &kbsinhibitor->destroy); - wl_list_insert(&keyboard_shortcut_inhibitors, &kbsinhibitor->link); + wl_list_insert(&server.keyboard_shortcut_inhibitors, &kbsinhibitor->link); wlr_keyboard_shortcuts_inhibitor_v1_activate(inhibitor); } @@ -6006,9 +6167,12 @@ void virtualkeyboard(struct wl_listener *listener, void *data) { } void warp_cursor(const Client *c) { - if (cursor->x < c->geom.x || cursor->x > c->geom.x + c->geom.width || - cursor->y < c->geom.y || cursor->y > c->geom.y + c->geom.height) { - wlr_cursor_warp_closest(cursor, NULL, c->geom.x + c->geom.width / 2.0, + if (server.cursor->x < c->geom.x || + server.cursor->x > c->geom.x + c->geom.width || + server.cursor->y < c->geom.y || + server.cursor->y > c->geom.y + c->geom.height) { + wlr_cursor_warp_closest(server.cursor, NULL, + c->geom.x + c->geom.width / 2.0, c->geom.y + c->geom.height / 2.0); motionnotify(0, NULL, 0, 0, 0, 0); } @@ -6016,9 +6180,9 @@ void warp_cursor(const Client *c) { void warp_cursor_to_selmon(Monitor *m) { - wlr_cursor_warp_closest(cursor, NULL, m->w.x + m->w.width / 2.0, + wlr_cursor_warp_closest(server.cursor, NULL, m->w.x + m->w.width / 2.0, m->w.y + m->w.height / 2.0); - wlr_cursor_set_xcursor(cursor, cursor_mgr, "default"); + wlr_cursor_set_xcursor(server.cursor, server.cursor_mgr, "default"); handlecursoractivity(); } @@ -6026,9 +6190,10 @@ void virtualpointer(struct wl_listener *listener, void *data) { struct wlr_virtual_pointer_v1_new_pointer_event *event = data; struct wlr_input_device *device = &event->new_pointer->pointer.base; - wlr_cursor_attach_input_device(cursor, device); + wlr_cursor_attach_input_device(server.cursor, device); if (event->suggested_output) - wlr_cursor_map_input_to_output(cursor, device, event->suggested_output); + wlr_cursor_map_input_to_output(server.cursor, device, + event->suggested_output); handlecursoractivity(); } @@ -6058,13 +6223,14 @@ void activatex11(struct wl_listener *listener, void *data) { } } - if (focus_on_activate && !c->istagsilent && c != selmon->sel) { - if (!(c->mon == selmon && c->tags & c->mon->tagset[c->mon->seltags])) + if (focus_on_activate && !c->istagsilent && c != server.selmon->sel) { + if (!(c->mon == server.selmon && + c->tags & c->mon->tagset[c->mon->seltags])) view_in_mon(&(Arg){.ui = c->tags}, true, c->mon, true); wlr_xwayland_surface_activate(c->surface.xwayland, 1); focusclient(c, 1); need_arrange = true; - } else if (c != focustop(selmon)) { + } else if (c != focustop(server.selmon)) { c->isurgent = 1; if (client_surface(c)->mapped) setborder_color(c); @@ -6091,7 +6257,7 @@ void configurex11(struct wl_listener *listener, void *data) { event->width, event->height); return; } - if ((c->isfloating && c != grabc) || + if ((c->isfloating && c != server.grabc) || !c->mon->pertag->ltidxs[c->mon->pertag->curtag]->arrange) { resize(c, (struct wlr_box){.x = event->x - c->bw, @@ -6142,7 +6308,7 @@ void dissociatex11(struct wl_listener *listener, void *data) { void sethints(struct wl_listener *listener, void *data) { Client *c = wl_container_of(listener, c, set_hints); struct wlr_surface *surface = client_surface(c); - if (c == focustop(selmon) || !c || !c->surface.xwayland->hints) + if (c == focustop(server.selmon) || !c || !c->surface.xwayland->hints) return; c->isurgent = xcb_icccm_wm_hints_get_urgency(c->surface.xwayland->hints); @@ -6155,11 +6321,12 @@ void sethints(struct wl_listener *listener, void *data) { void xwaylandready(struct wl_listener *listener, void *data) { struct wlr_xcursor *xcursor; - /* assign the one and only seat */ - wlr_xwayland_set_seat(xwayland, seat); + /* assign the one and only server.seat */ + wlr_xwayland_set_seat(xwayland, server.seat); - /* Set the default XWayland cursor to match the rest of dwl. */ - if ((xcursor = wlr_xcursor_manager_get_xcursor(cursor_mgr, "default", 1))) + /* Set the default XWayland server.cursor to match the rest of dwl. */ + if ((xcursor = + wlr_xcursor_manager_get_xcursor(server.cursor_mgr, "default", 1))) wlr_xwayland_set_cursor( xwayland, xcursor->images[0]->buffer, xcursor->images[0]->width * 4, xcursor->images[0]->width, xcursor->images[0]->height, @@ -6188,7 +6355,7 @@ int32_t main(int32_t argc, char *argv[]) { printf("mango " VERSION "\n"); return EXIT_SUCCESS; } else if (c == 'c') { - cli_config_path = optarg; + server.cli_config_path = optarg; } else if (c == 'p') { parse_config(); return EXIT_SUCCESS;