format code index to tab no space

This commit is contained in:
DreamMaoMao 2025-06-07 13:53:12 +08:00
parent 0af8799a2d
commit 5aaf8d7625
11 changed files with 8896 additions and 8749 deletions

4
.clang-format Normal file
View file

@ -0,0 +1,4 @@
BasedOnStyle: LLVM
UseTab: Always
TabWidth: 4
IndentWidth: 4

View file

@ -8,405 +8,413 @@
/* Leave these functions first; they're used in the others */
static inline int client_is_x11(Client *c) {
#ifdef XWAYLAND
return c->type == X11;
return c->type == X11;
#endif
return 0;
return 0;
}
static inline struct wlr_surface *client_surface(Client *c) {
#ifdef XWAYLAND
if (client_is_x11(c))
return c->surface.xwayland->surface;
if (client_is_x11(c))
return c->surface.xwayland->surface;
#endif
return c->surface.xdg->surface;
return c->surface.xdg->surface;
}
static inline int toplevel_from_wlr_surface(struct wlr_surface *s, Client **pc,
LayerSurface **pl) {
struct wlr_xdg_surface *xdg_surface, *tmp_xdg_surface;
struct wlr_surface *root_surface;
struct wlr_layer_surface_v1 *layer_surface;
Client *c = NULL;
LayerSurface *l = NULL;
int type = -1;
LayerSurface **pl) {
struct wlr_xdg_surface *xdg_surface, *tmp_xdg_surface;
struct wlr_surface *root_surface;
struct wlr_layer_surface_v1 *layer_surface;
Client *c = NULL;
LayerSurface *l = NULL;
int type = -1;
#ifdef XWAYLAND
struct wlr_xwayland_surface *xsurface;
struct wlr_xwayland_surface *xsurface;
#endif
if (!s)
return -1;
root_surface = wlr_surface_get_root_surface(s);
if (!s)
return -1;
root_surface = wlr_surface_get_root_surface(s);
#ifdef XWAYLAND
if ((xsurface = wlr_xwayland_surface_try_from_wlr_surface(root_surface))) {
c = xsurface->data;
type = c->type;
goto end;
}
if ((xsurface = wlr_xwayland_surface_try_from_wlr_surface(root_surface))) {
c = xsurface->data;
type = c->type;
goto end;
}
#endif
if ((layer_surface =
wlr_layer_surface_v1_try_from_wlr_surface(root_surface))) {
l = layer_surface->data;
type = LayerShell;
goto end;
}
if ((layer_surface =
wlr_layer_surface_v1_try_from_wlr_surface(root_surface))) {
l = layer_surface->data;
type = LayerShell;
goto end;
}
xdg_surface = wlr_xdg_surface_try_from_wlr_surface(root_surface);
while (xdg_surface) {
tmp_xdg_surface = NULL;
switch (xdg_surface->role) {
case WLR_XDG_SURFACE_ROLE_POPUP:
if (!xdg_surface->popup || !xdg_surface->popup->parent)
return -1;
xdg_surface = wlr_xdg_surface_try_from_wlr_surface(root_surface);
while (xdg_surface) {
tmp_xdg_surface = NULL;
switch (xdg_surface->role) {
case WLR_XDG_SURFACE_ROLE_POPUP:
if (!xdg_surface->popup || !xdg_surface->popup->parent)
return -1;
tmp_xdg_surface =
wlr_xdg_surface_try_from_wlr_surface(xdg_surface->popup->parent);
tmp_xdg_surface = wlr_xdg_surface_try_from_wlr_surface(
xdg_surface->popup->parent);
if (!tmp_xdg_surface)
return toplevel_from_wlr_surface(xdg_surface->popup->parent, pc, pl);
if (!tmp_xdg_surface)
return toplevel_from_wlr_surface(xdg_surface->popup->parent, pc,
pl);
xdg_surface = tmp_xdg_surface;
break;
case WLR_XDG_SURFACE_ROLE_TOPLEVEL:
c = xdg_surface->data;
type = c->type;
goto end;
case WLR_XDG_SURFACE_ROLE_NONE:
return -1;
}
}
xdg_surface = tmp_xdg_surface;
break;
case WLR_XDG_SURFACE_ROLE_TOPLEVEL:
c = xdg_surface->data;
type = c->type;
goto end;
case WLR_XDG_SURFACE_ROLE_NONE:
return -1;
}
}
end:
if (pl)
*pl = l;
if (pc)
*pc = c;
return type;
if (pl)
*pl = l;
if (pc)
*pc = c;
return type;
}
/* The others */
static inline void client_activate_surface(struct wlr_surface *s,
int activated) {
struct wlr_xdg_toplevel *toplevel;
int activated) {
struct wlr_xdg_toplevel *toplevel;
#ifdef XWAYLAND
struct wlr_xwayland_surface *xsurface;
if ((xsurface = wlr_xwayland_surface_try_from_wlr_surface(s))) {
wlr_xwayland_surface_activate(xsurface, activated);
return;
}
struct wlr_xwayland_surface *xsurface;
if ((xsurface = wlr_xwayland_surface_try_from_wlr_surface(s))) {
wlr_xwayland_surface_activate(xsurface, activated);
return;
}
#endif
if ((toplevel = wlr_xdg_toplevel_try_from_wlr_surface(s)))
wlr_xdg_toplevel_set_activated(toplevel, activated);
if ((toplevel = wlr_xdg_toplevel_try_from_wlr_surface(s)))
wlr_xdg_toplevel_set_activated(toplevel, activated);
}
static inline uint32_t client_set_bounds(Client *c, int32_t width,
int32_t height) {
int32_t height) {
#ifdef XWAYLAND
if (client_is_x11(c))
return 0;
if (client_is_x11(c))
return 0;
#endif
if (wl_resource_get_version(c->surface.xdg->toplevel->resource) >=
XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION &&
width >= 0 && height >= 0 &&
(c->bounds.width != width || c->bounds.height != height)) {
c->bounds.width = width;
c->bounds.height = height;
return wlr_xdg_toplevel_set_bounds(c->surface.xdg->toplevel, width, height);
}
return 0;
if (wl_resource_get_version(c->surface.xdg->toplevel->resource) >=
XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION &&
width >= 0 && height >= 0 &&
(c->bounds.width != width || c->bounds.height != height)) {
c->bounds.width = width;
c->bounds.height = height;
return wlr_xdg_toplevel_set_bounds(c->surface.xdg->toplevel, width,
height);
}
return 0;
}
static inline const char *client_get_appid(Client *c) {
#ifdef XWAYLAND
if (client_is_x11(c))
return c->surface.xwayland->class ? c->surface.xwayland->class : "broken";
if (client_is_x11(c))
return c->surface.xwayland->class ? c->surface.xwayland->class
: "broken";
#endif
return c->surface.xdg->toplevel->app_id ? c->surface.xdg->toplevel->app_id
: "broken";
return c->surface.xdg->toplevel->app_id ? c->surface.xdg->toplevel->app_id
: "broken";
}
static inline int client_get_pid(Client *c) {
pid_t pid;
pid_t pid;
#ifdef XWAYLAND
if (client_is_x11(c))
return c->surface.xwayland->pid;
if (client_is_x11(c))
return c->surface.xwayland->pid;
#endif
wl_client_get_credentials(c->surface.xdg->client->client, &pid, NULL, NULL);
return pid;
wl_client_get_credentials(c->surface.xdg->client->client, &pid, NULL, NULL);
return pid;
}
static inline void client_get_clip(Client *c, struct wlr_box *clip) {
*clip = (struct wlr_box){
.x = 0,
.y = 0,
.width = c->geom.width - c->bw,
.height = c->geom.height - c->bw,
};
*clip = (struct wlr_box){
.x = 0,
.y = 0,
.width = c->geom.width - c->bw,
.height = c->geom.height - c->bw,
};
#ifdef XWAYLAND
if (client_is_x11(c))
return;
if (client_is_x11(c))
return;
#endif
clip->x = c->surface.xdg->geometry.x;
clip->y = c->surface.xdg->geometry.y;
clip->x = c->surface.xdg->geometry.x;
clip->y = c->surface.xdg->geometry.y;
}
static inline void client_get_geometry(Client *c, struct wlr_box *geom) {
#ifdef XWAYLAND
if (client_is_x11(c)) {
geom->x = c->surface.xwayland->x;
geom->y = c->surface.xwayland->y;
geom->width = c->surface.xwayland->width;
geom->height = c->surface.xwayland->height;
return;
}
if (client_is_x11(c)) {
geom->x = c->surface.xwayland->x;
geom->y = c->surface.xwayland->y;
geom->width = c->surface.xwayland->width;
geom->height = c->surface.xwayland->height;
return;
}
#endif
*geom = c->surface.xdg->geometry;
*geom = c->surface.xdg->geometry;
}
static inline Client *client_get_parent(Client *c) {
Client *p = NULL;
Client *p = NULL;
#ifdef XWAYLAND
if (client_is_x11(c)) {
if (c->surface.xwayland->parent)
toplevel_from_wlr_surface(c->surface.xwayland->parent->surface, &p, NULL);
return p;
}
if (client_is_x11(c)) {
if (c->surface.xwayland->parent)
toplevel_from_wlr_surface(c->surface.xwayland->parent->surface, &p,
NULL);
return p;
}
#endif
if (c->surface.xdg->toplevel->parent)
toplevel_from_wlr_surface(c->surface.xdg->toplevel->parent->base->surface,
&p, NULL);
return p;
if (c->surface.xdg->toplevel->parent)
toplevel_from_wlr_surface(
c->surface.xdg->toplevel->parent->base->surface, &p, NULL);
return p;
}
static inline int client_has_children(Client *c) {
#ifdef XWAYLAND
if (client_is_x11(c))
return !wl_list_empty(&c->surface.xwayland->children);
if (client_is_x11(c))
return !wl_list_empty(&c->surface.xwayland->children);
#endif
/* surface.xdg->link is never empty because it always contains at least the
* surface itself. */
return wl_list_length(&c->surface.xdg->link) > 1;
/* surface.xdg->link is never empty because it always contains at least the
* surface itself. */
return wl_list_length(&c->surface.xdg->link) > 1;
}
static inline const char *client_get_title(Client *c) {
#ifdef XWAYLAND
if (client_is_x11(c))
return c->surface.xwayland->title ? c->surface.xwayland->title : "broken";
if (client_is_x11(c))
return c->surface.xwayland->title ? c->surface.xwayland->title
: "broken";
#endif
return c->surface.xdg->toplevel->title ? c->surface.xdg->toplevel->title
: "broken";
return c->surface.xdg->toplevel->title ? c->surface.xdg->toplevel->title
: "broken";
}
static inline int client_is_float_type(Client *c) {
struct wlr_xdg_toplevel *toplevel;
struct wlr_xdg_toplevel_state state;
struct wlr_xdg_toplevel *toplevel;
struct wlr_xdg_toplevel_state state;
#ifdef XWAYLAND
if (client_is_x11(c)) {
struct wlr_xwayland_surface *surface = c->surface.xwayland;
xcb_size_hints_t *size_hints = surface->size_hints;
if (surface->modal)
return 1;
if (client_is_x11(c)) {
struct wlr_xwayland_surface *surface = c->surface.xwayland;
xcb_size_hints_t *size_hints = surface->size_hints;
if (surface->modal)
return 1;
if (wlr_xwayland_surface_has_window_type(
surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DIALOG) ||
wlr_xwayland_surface_has_window_type(
surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_SPLASH) ||
wlr_xwayland_surface_has_window_type(
surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_TOOLBAR) ||
wlr_xwayland_surface_has_window_type(
surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_UTILITY)) {
return 1;
}
if (wlr_xwayland_surface_has_window_type(
surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DIALOG) ||
wlr_xwayland_surface_has_window_type(
surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_SPLASH) ||
wlr_xwayland_surface_has_window_type(
surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_TOOLBAR) ||
wlr_xwayland_surface_has_window_type(
surface, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_UTILITY)) {
return 1;
}
return size_hints && size_hints->min_width > 0 &&
size_hints->min_height > 0 &&
(size_hints->max_width == size_hints->min_width ||
size_hints->max_height == size_hints->min_height);
}
return size_hints && size_hints->min_width > 0 &&
size_hints->min_height > 0 &&
(size_hints->max_width == size_hints->min_width ||
size_hints->max_height == size_hints->min_height);
}
#endif
toplevel = c->surface.xdg->toplevel;
state = toplevel->current;
return toplevel->parent || (state.min_width != 0 && state.min_height != 0 &&
(state.min_width == state.max_width ||
state.min_height == state.max_height));
toplevel = c->surface.xdg->toplevel;
state = toplevel->current;
return toplevel->parent || (state.min_width != 0 && state.min_height != 0 &&
(state.min_width == state.max_width ||
state.min_height == state.max_height));
}
static inline int client_is_rendered_on_mon(Client *c, Monitor *m) {
/* This is needed for when you don't want to check formal assignment,
* but rather actual displaying of the pixels.
* Usually VISIBLEON suffices and is also faster. */
struct wlr_surface_output *s;
int unused_lx, unused_ly;
if (!wlr_scene_node_coords(&c->scene->node, &unused_lx, &unused_ly))
return 0;
wl_list_for_each(s, &client_surface(c)->current_outputs,
link) if (s->output == m->wlr_output) return 1;
return 0;
/* This is needed for when you don't want to check formal assignment,
* but rather actual displaying of the pixels.
* Usually VISIBLEON suffices and is also faster. */
struct wlr_surface_output *s;
int unused_lx, unused_ly;
if (!wlr_scene_node_coords(&c->scene->node, &unused_lx, &unused_ly))
return 0;
wl_list_for_each(s, &client_surface(c)->current_outputs,
link) if (s->output == m->wlr_output) return 1;
return 0;
}
static inline int client_is_stopped(Client *c) {
int pid;
siginfo_t in = {0};
int pid;
siginfo_t in = {0};
#ifdef XWAYLAND
if (client_is_x11(c))
return 0;
if (client_is_x11(c))
return 0;
#endif
wl_client_get_credentials(c->surface.xdg->client->client, &pid, NULL, NULL);
if (waitid(P_PID, pid, &in, WNOHANG | WCONTINUED | WSTOPPED | WNOWAIT) < 0) {
/* This process is not our child process, while is very unluckely that
* it is stopped, in order to do not skip frames assume that it is. */
if (errno == ECHILD)
return 1;
} else if (in.si_pid) {
if (in.si_code == CLD_STOPPED || in.si_code == CLD_TRAPPED)
return 1;
if (in.si_code == CLD_CONTINUED)
return 0;
}
wl_client_get_credentials(c->surface.xdg->client->client, &pid, NULL, NULL);
if (waitid(P_PID, pid, &in, WNOHANG | WCONTINUED | WSTOPPED | WNOWAIT) <
0) {
/* This process is not our child process, while is very unluckely that
* it is stopped, in order to do not skip frames assume that it is. */
if (errno == ECHILD)
return 1;
} else if (in.si_pid) {
if (in.si_code == CLD_STOPPED || in.si_code == CLD_TRAPPED)
return 1;
if (in.si_code == CLD_CONTINUED)
return 0;
}
return 0;
return 0;
}
static inline int client_is_unmanaged(Client *c) {
#ifdef XWAYLAND
if (client_is_x11(c))
return c->surface.xwayland->override_redirect;
if (client_is_x11(c))
return c->surface.xwayland->override_redirect;
#endif
return 0;
return 0;
}
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);
else
wlr_seat_keyboard_notify_enter(seat, s, NULL, 0, NULL);
struct wlr_keyboard *kb) {
if (kb)
wlr_seat_keyboard_notify_enter(seat, s, kb->keycodes, kb->num_keycodes,
&kb->modifiers);
else
wlr_seat_keyboard_notify_enter(seat, s, NULL, 0, NULL);
}
static inline void client_send_close(Client *c) {
#ifdef XWAYLAND
if (client_is_x11(c)) {
wlr_xwayland_surface_close(c->surface.xwayland);
return;
}
if (client_is_x11(c)) {
wlr_xwayland_surface_close(c->surface.xwayland);
return;
}
#endif
wlr_xdg_toplevel_send_close(c->surface.xdg->toplevel);
wlr_xdg_toplevel_send_close(c->surface.xdg->toplevel);
}
static inline void client_set_border_color(Client *c,
const float color[static 4]) {
int i;
for (i = 0; i < 4; i++)
wlr_scene_rect_set_color(c->border[i], color);
const float color[static 4]) {
int i;
for (i = 0; i < 4; i++)
wlr_scene_rect_set_color(c->border[i], color);
}
static inline void client_set_fullscreen(Client *c, int fullscreen) {
#ifdef XWAYLAND
if (client_is_x11(c)) {
wlr_xwayland_surface_set_fullscreen(c->surface.xwayland, fullscreen);
return;
}
if (client_is_x11(c)) {
wlr_xwayland_surface_set_fullscreen(c->surface.xwayland, fullscreen);
return;
}
#endif
wlr_xdg_toplevel_set_fullscreen(c->surface.xdg->toplevel, fullscreen);
wlr_xdg_toplevel_set_fullscreen(c->surface.xdg->toplevel, fullscreen);
}
static inline void client_set_scale(struct wlr_surface *s, float scale) {
wlr_fractional_scale_v1_notify_scale(s, scale);
wlr_surface_set_preferred_buffer_scale(s, (int32_t)ceilf(scale));
wlr_fractional_scale_v1_notify_scale(s, scale);
wlr_surface_set_preferred_buffer_scale(s, (int32_t)ceilf(scale));
}
static inline uint32_t client_set_size(Client *c, uint32_t width,
uint32_t height) {
uint32_t height) {
#ifdef XWAYLAND
if (client_is_x11(c)) {
wlr_xwayland_surface_configure(c->surface.xwayland, c->geom.x + c->bw,
c->geom.y + c->bw, width, height);
return 0;
}
if (client_is_x11(c)) {
wlr_xwayland_surface_configure(c->surface.xwayland, c->geom.x + c->bw,
c->geom.y + c->bw, width, height);
return 0;
}
#endif
if ((int32_t)width == c->surface.xdg->toplevel->current.width &&
(int32_t)height == c->surface.xdg->toplevel->current.height)
return 0;
return wlr_xdg_toplevel_set_size(c->surface.xdg->toplevel, (int32_t)width,
(int32_t)height);
if ((int32_t)width == c->surface.xdg->toplevel->current.width &&
(int32_t)height == c->surface.xdg->toplevel->current.height)
return 0;
return wlr_xdg_toplevel_set_size(c->surface.xdg->toplevel, (int32_t)width,
(int32_t)height);
}
static inline void client_set_tiled(Client *c, uint32_t edges) {
#ifdef XWAYLAND
if (client_is_x11(c)) {
wlr_xwayland_surface_set_maximized(
c->surface.xwayland, edges != WLR_EDGE_NONE, edges != WLR_EDGE_NONE);
return;
}
if (client_is_x11(c)) {
wlr_xwayland_surface_set_maximized(c->surface.xwayland,
edges != WLR_EDGE_NONE,
edges != WLR_EDGE_NONE);
return;
}
#endif
if (wl_resource_get_version(c->surface.xdg->toplevel->resource) >=
XDG_TOPLEVEL_STATE_TILED_RIGHT_SINCE_VERSION) {
wlr_xdg_toplevel_set_tiled(c->surface.xdg->toplevel, edges);
}
wlr_xdg_toplevel_set_maximized(c->surface.xdg->toplevel,
edges != WLR_EDGE_NONE);
if (wl_resource_get_version(c->surface.xdg->toplevel->resource) >=
XDG_TOPLEVEL_STATE_TILED_RIGHT_SINCE_VERSION) {
wlr_xdg_toplevel_set_tiled(c->surface.xdg->toplevel, edges);
}
wlr_xdg_toplevel_set_maximized(c->surface.xdg->toplevel,
edges != WLR_EDGE_NONE);
}
static inline void client_set_suspended(Client *c, int suspended) {
#ifdef XWAYLAND
if (client_is_x11(c))
return;
if (client_is_x11(c))
return;
#endif
wlr_xdg_toplevel_set_suspended(c->surface.xdg->toplevel, suspended);
wlr_xdg_toplevel_set_suspended(c->surface.xdg->toplevel, suspended);
}
static inline int client_should_ignore_focus(Client *c) {
#ifdef XWAYLAND
if (client_is_x11(c)) {
struct wlr_xwayland_surface *surface = c->surface.xwayland;
// 处理不需要焦点的窗口类型
const uint32_t no_focus_types[] = {
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_COMBO,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DND,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DROPDOWN_MENU,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_MENU,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_NOTIFICATION,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_POPUP_MENU,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_SPLASH,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DESKTOP,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_TOOLTIP,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_UTILITY};
// 检查窗口类型是否需要禁止焦点
for (size_t i = 0; i < sizeof(no_focus_types) / sizeof(no_focus_types[0]);
++i) {
if (wlr_xwayland_surface_has_window_type(surface, no_focus_types[i])) {
return 1;
}
}
}
if (client_is_x11(c)) {
struct wlr_xwayland_surface *surface = c->surface.xwayland;
// 处理不需要焦点的窗口类型
const uint32_t no_focus_types[] = {
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_COMBO,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DND,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DROPDOWN_MENU,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_MENU,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_NOTIFICATION,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_POPUP_MENU,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_SPLASH,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DESKTOP,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_TOOLTIP,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_UTILITY};
// 检查窗口类型是否需要禁止焦点
for (size_t i = 0;
i < sizeof(no_focus_types) / sizeof(no_focus_types[0]); ++i) {
if (wlr_xwayland_surface_has_window_type(surface,
no_focus_types[i])) {
return 1;
}
}
}
#endif
return 0;
return 0;
}
static inline int client_wants_focus(Client *c) {
#ifdef XWAYLAND
return client_is_unmanaged(c) &&
wlr_xwayland_surface_override_redirect_wants_focus(
c->surface.xwayland) &&
wlr_xwayland_surface_icccm_input_model(c->surface.xwayland) !=
WLR_ICCCM_INPUT_MODEL_NONE;
return client_is_unmanaged(c) &&
wlr_xwayland_surface_override_redirect_wants_focus(
c->surface.xwayland) &&
wlr_xwayland_surface_icccm_input_model(c->surface.xwayland) !=
WLR_ICCCM_INPUT_MODEL_NONE;
#endif
return 0;
return 0;
}
static inline int client_wants_fullscreen(Client *c) {
#ifdef XWAYLAND
if (client_is_x11(c))
return c->surface.xwayland->fullscreen;
if (client_is_x11(c))
return c->surface.xwayland->fullscreen;
#endif
return c->surface.xdg->toplevel->requested.fullscreen;
return c->surface.xdg->toplevel->requested.fullscreen;
}

View file

@ -7,34 +7,34 @@
#include <string.h>
static void die_if_null(void *ptr) {
if (!ptr) {
perror("Failed to allocate memory");
exit(EXIT_FAILURE);
}
if (!ptr) {
perror("Failed to allocate memory");
exit(EXIT_FAILURE);
}
}
void *xzalloc(size_t size) {
if (!size) {
return NULL;
}
void *ptr = calloc(1, size);
die_if_null(ptr);
return ptr;
if (!size) {
return NULL;
}
void *ptr = calloc(1, size);
die_if_null(ptr);
return ptr;
}
void *xrealloc(void *ptr, size_t size) {
if (!size) {
free(ptr);
return NULL;
}
ptr = realloc(ptr, size);
die_if_null(ptr);
return ptr;
if (!size) {
free(ptr);
return NULL;
}
ptr = realloc(ptr, size);
die_if_null(ptr);
return ptr;
}
char *xstrdup(const char *str) {
assert(str);
char *copy = strdup(str);
die_if_null(copy);
return copy;
assert(str);
char *copy = strdup(str);
die_if_null(copy);
return copy;
}

View file

@ -47,18 +47,17 @@ char *xstrdup(const char *str);
* <ptr> before assigning the result.
*/
#define xstrdup_replace(ptr, str) \
do { \
free(ptr); \
(ptr) = xstrdup(str); \
} while (0)
do { \
free(ptr); \
(ptr) = xstrdup(str); \
} while (0)
/*
* Frees memory pointed to by <ptr> and sets <ptr> to NULL.
* Does nothing if <ptr> is already NULL.
*/
#define zfree(ptr) \
do { \
free(ptr); \
(ptr) = NULL; \
} while (0)
do { \
free(ptr); \
(ptr) = NULL; \
} while (0)

View file

@ -11,71 +11,63 @@
#include <pcre2.h>
void die(const char *fmt, ...) {
va_list ap;
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
if (fmt[0] && fmt[strlen(fmt) - 1] == ':') {
fputc(' ', stderr);
perror(NULL);
} else {
fputc('\n', stderr);
}
if (fmt[0] && fmt[strlen(fmt) - 1] == ':') {
fputc(' ', stderr);
perror(NULL);
} else {
fputc('\n', stderr);
}
exit(1);
exit(1);
}
void *ecalloc(size_t nmemb, size_t size) {
void *p;
void *p;
if (!(p = calloc(nmemb, size)))
die("calloc:");
return p;
if (!(p = calloc(nmemb, size)))
die("calloc:");
return p;
}
int fd_set_nonblock(int fd) {
int flags = fcntl(fd, F_GETFL);
if (flags < 0) {
perror("fcntl(F_GETFL):");
return -1;
}
if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
perror("fcntl(F_SETFL):");
return -1;
}
int flags = fcntl(fd, F_GETFL);
if (flags < 0) {
perror("fcntl(F_GETFL):");
return -1;
}
if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
perror("fcntl(F_SETFL):");
return -1;
}
return 0;
return 0;
}
int regex_match(const char *pattern, const char *str) {
int errnum;
PCRE2_SIZE erroffset;
pcre2_code *re = pcre2_compile(
(PCRE2_SPTR)pattern,
PCRE2_ZERO_TERMINATED,
PCRE2_UTF, // 启用 UTF-8 支持
&errnum, &erroffset, NULL
);
if (!re) {
PCRE2_UCHAR errbuf[256];
pcre2_get_error_message(errnum, errbuf, sizeof(errbuf));
fprintf(stderr, "PCRE2 error: %s at offset %zu\n", errbuf, erroffset);
return 0;
}
int errnum;
PCRE2_SIZE erroffset;
pcre2_code *re = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED,
PCRE2_UTF, // 启用 UTF-8 支持
&errnum, &erroffset, NULL);
if (!re) {
PCRE2_UCHAR errbuf[256];
pcre2_get_error_message(errnum, errbuf, sizeof(errbuf));
fprintf(stderr, "PCRE2 error: %s at offset %zu\n", errbuf, erroffset);
return 0;
}
pcre2_match_data *match_data = pcre2_match_data_create_from_pattern(re, NULL);
int ret = pcre2_match(
re,
(PCRE2_SPTR)str,
strlen(str),
0, 0,
match_data,
NULL
);
pcre2_match_data *match_data =
pcre2_match_data_create_from_pattern(re, NULL);
int ret =
pcre2_match(re, (PCRE2_SPTR)str, strlen(str), 0, 0, match_data, NULL);
pcre2_match_data_free(match_data);
pcre2_code_free(re);
return ret >= 0;
pcre2_match_data_free(match_data);
pcre2_code_free(re);
return ret >= 0;
}

View file

@ -1,6 +1,5 @@
/* See LICENSE.dwm file for copyright and license details. */
void die(const char *fmt, ...);
void *ecalloc(size_t nmemb, size_t size);
int fd_set_nonblock(int fd);

File diff suppressed because it is too large Load diff

View file

@ -4,22 +4,22 @@
/* speedie's maomao config */
#define COLOR(hex) \
{((hex >> 24) & 0xFF) / 255.0f, ((hex >> 16) & 0xFF) / 255.0f, \
((hex >> 8) & 0xFF) / 255.0f, (hex & 0xFF) / 255.0f}
{((hex >> 24) & 0xFF) / 255.0f, ((hex >> 16) & 0xFF) / 255.0f, \
((hex >> 8) & 0xFF) / 255.0f, (hex & 0xFF) / 255.0f}
/* animaion */
char *animation_type_open = "slide"; // 是否启用动画 //slide,zoom
char *animation_type_close = "slide"; // 是否启用动画 //slide,zoom
int animations = 1; // 是否启用动画
char *animation_type_open = "slide"; // 是否启用动画 //slide,zoom
char *animation_type_close = "slide"; // 是否启用动画 //slide,zoom
int animations = 1; // 是否启用动画
int tag_animation_direction = HORIZONTAL; // 标签动画方向
int animation_fade_in = 1; // Enable animation fade in
int animation_fade_out = 1; // Enable animation fade out
float zoom_initial_ratio = 0.5; // 动画起始窗口比例
int animation_fade_in = 1; // Enable animation fade in
int animation_fade_out = 1; // Enable animation fade out
float zoom_initial_ratio = 0.5; // 动画起始窗口比例
float fadein_begin_opacity = 0.5; // Begin opac window ratio for animations
float fadeout_begin_opacity = 0.5; // Begin opac window ratio for animations
uint32_t animation_duration_move = 500; // Animation move speed
uint32_t animation_duration_open = 400; // Animation open speed
uint32_t animation_duration_tag = 300; // Animation tag speed
uint32_t animation_duration_move = 500; // Animation move speed
uint32_t animation_duration_open = 400; // Animation open speed
uint32_t animation_duration_tag = 300; // Animation tag speed
uint32_t animation_duration_close = 300; // Animation close speed
double animation_curve_move[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线
double animation_curve_open[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线
@ -28,20 +28,20 @@ double animation_curve_close[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线
/* appearance */
unsigned int axis_bind_apply_timeout = 100; // 滚轮绑定动作的触发的时间间隔
unsigned int focus_on_activate = 1; // 收到窗口激活请求是否自动跳转聚焦
unsigned int new_is_master = 1; // 新窗口是否插在头部
double default_mfact = 0.55f; // master 窗口比例
double default_smfact = 0.5f; // 第一个stack窗口比例
unsigned int default_nmaster = 1; // 默认master数量
unsigned int focus_on_activate = 1; // 收到窗口激活请求是否自动跳转聚焦
unsigned int new_is_master = 1; // 新窗口是否插在头部
double default_mfact = 0.55f; // master 窗口比例
double default_smfact = 0.5f; // 第一个stack窗口比例
unsigned int default_nmaster = 1; // 默认master数量
/* logging */
int log_level = WLR_ERROR;
unsigned int numlockon = 1; // 是否打开右边小键盘
unsigned int capslock = 0; // 是否启用快捷键
unsigned int capslock = 0; // 是否启用快捷键
unsigned int ov_tab_mode = 0; // alt tab切换模式
unsigned int hotarea_size = 10; // 热区大小,10x10
unsigned int ov_tab_mode = 0; // alt tab切换模式
unsigned int hotarea_size = 10; // 热区大小,10x10
unsigned int enable_hotarea = 1; // 是否启用鼠标热区
int smartgaps = 0; /* 1 means no outer gap when there is only one window */
int smartgaps = 0; /* 1 means no outer gap when there is only one window */
int sloppyfocus = 1; /* focus follows mouse */
unsigned int gappih = 5; /* horiz inner gap between windows */
unsigned int gappiv = 5; /* vert inner gap between windows */
@ -65,8 +65,8 @@ unsigned int cursor_hide_timeout = 0;
unsigned int swipe_min_threshold = 20;
int bypass_surface_visibility =
0; /* 1 means idle inhibitors will disable idle tracking even if it's
surface isn't visible */
0; /* 1 means idle inhibitors will disable idle tracking even if it's
surface isn't visible */
unsigned int borderpx = 4; /* border pixel of windows */
float rootcolor[] = COLOR(0x323232ff);
float bordercolor[] = COLOR(0x444444ff);
@ -78,36 +78,36 @@ float globalcolor[] = COLOR(0xb153a7ff);
float overlaycolor[] = COLOR(0x14a57cff);
// char *cursor_theme = "Bibata-Modern-Ice";
int overviewgappi = 5; /* overview时 窗口与边缘 缝隙大小 */
int overviewgappi = 5; /* overview时 窗口与边缘 缝隙大小 */
int overviewgappo = 30; /* overview时 窗口与窗口 缝隙大小 */
/* To conform the xdg-protocol, set the alpha to zero to restore the old
* behavior */
float fullscreen_bg[] = {0.1, 0.1, 0.1, 1.0};
int warpcursor = 1; /* Warp cursor to focused client */
int warpcursor = 1; /* Warp cursor to focused client */
int xwayland_persistence = 1; /* xwayland persistence */
/* layout(s) */
Layout overviewlayout = {"󰃇", overview, "overview"};
Layout layouts[] = {
// 最少两个,不能删除少于两个
/* symbol arrange function name */
{"S", scroller, "scroller"}, // 滚动布局
{"T", tile, "tile"}, // 堆栈布局
{"G", grid, "grid"}, {"M", monocle, "monocle"},
{"D", dwindle, "dwindle"}, {"P", spiral, "spiral"},
{"K", deck, "deck"},
// 最少两个,不能删除少于两个
/* symbol arrange function name */
{"S", scroller, "scroller"}, // 滚动布局
{"T", tile, "tile"}, // 堆栈布局
{"G", grid, "grid"}, {"M", monocle, "monocle"},
{"D", dwindle, "dwindle"}, {"P", spiral, "spiral"},
{"K", deck, "deck"},
};
/* keyboard */
struct xkb_rule_names xkb_rules = {
/* can specify fields: rules, model, layout, variant, options */
/* example:
.options = "ctrl:nocaps",
*/
.options = NULL,
/* can specify fields: rules, model, layout, variant, options */
/* example:
.options = "ctrl:nocaps",
*/
.options = NULL,
};
int repeat_rate = 25;
@ -138,7 +138,7 @@ LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS
LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER
*/
enum libinput_config_click_method click_method =
LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS;
LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS;
/* You can choose between:
LIBINPUT_CONFIG_SEND_EVENTS_ENABLED
@ -152,7 +152,7 @@ LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT
LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE
*/
enum libinput_config_accel_profile accel_profile =
LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE;
LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE;
double accel_speed = 0.0;
/* You can choose between:
LIBINPUT_CONFIG_TAP_MAP_LRM -- 1/2/3 finger tap maps to left/right/middle
@ -164,5 +164,5 @@ enum libinput_config_tap_button_map button_map = LIBINPUT_CONFIG_TAP_MAP_LRM;
#define MODKEY WLR_MODIFIER_ALT
static const char *tags[] = {
"1", "2", "3", "4", "5", "6", "7", "8", "9",
"1", "2", "3", "4", "5", "6", "7", "8", "9",
};

View file

@ -1,119 +1,122 @@
void fibonacci(Monitor *mon, int s) {
unsigned int i = 0, n = 0, nx, ny, nw, nh;
Client *c;
unsigned int cur_gappih = enablegaps ? mon->gappih : 0;
unsigned int cur_gappiv = enablegaps ? mon->gappiv : 0;
unsigned int cur_gappoh = enablegaps ? mon->gappoh : 0;
unsigned int cur_gappov = enablegaps ? mon->gappov : 0;
unsigned int i = 0, n = 0, nx, ny, nw, nh;
Client *c;
unsigned int cur_gappih = enablegaps ? mon->gappih : 0;
unsigned int cur_gappiv = enablegaps ? mon->gappiv : 0;
unsigned int cur_gappoh = enablegaps ? mon->gappoh : 0;
unsigned int cur_gappov = enablegaps ? mon->gappov : 0;
cur_gappih = smartgaps && mon->visible_clients == 1 ? 0 : cur_gappih;
cur_gappiv = smartgaps && mon->visible_clients == 1 ? 0 : cur_gappiv;
cur_gappoh = smartgaps && mon->visible_clients == 1 ? 0 : cur_gappoh;
cur_gappov = smartgaps && mon->visible_clients == 1 ? 0 : cur_gappov;
// Count visible clients
wl_list_for_each(c, &clients, link) if (VISIBLEON(c, mon) && ISTILED(c)) n++;
cur_gappih = smartgaps && mon->visible_clients == 1 ? 0 : cur_gappih;
cur_gappiv = smartgaps && mon->visible_clients == 1 ? 0 : cur_gappiv;
cur_gappoh = smartgaps && mon->visible_clients == 1 ? 0 : cur_gappoh;
cur_gappov = smartgaps && mon->visible_clients == 1 ? 0 : cur_gappov;
// Count visible clients
wl_list_for_each(c, &clients, link) if (VISIBLEON(c, mon) && ISTILED(c))
n++;
if (n == 0)
return;
if (n == 0)
return;
// Initial dimensions including outer gaps
nx = mon->w.x + cur_gappoh;
ny = mon->w.y + cur_gappov;
nw = mon->w.width - 2 * cur_gappoh;
nh = mon->w.height - 2 * cur_gappov;
// Initial dimensions including outer gaps
nx = mon->w.x + cur_gappoh;
ny = mon->w.y + cur_gappov;
nw = mon->w.width - 2 * cur_gappoh;
nh = mon->w.height - 2 * cur_gappov;
// First pass: calculate client geometries
wl_list_for_each(c, &clients, link) {
if (!VISIBLEON(c, mon) || !ISTILED(c))
continue;
// First pass: calculate client geometries
wl_list_for_each(c, &clients, link) {
if (!VISIBLEON(c, mon) || !ISTILED(c))
continue;
c->bw = mon->visible_clients == 1 && no_border_when_single && smartgaps
? 0
: borderpx;
if ((i % 2 && nh / 2 > 2 * c->bw) || (!(i % 2) && nw / 2 > 2 * c->bw)) {
if (i < n - 1) {
if (i % 2) {
if (i == 1) {
nh = nh * mon->pertag->smfacts[mon->pertag->curtag];
} else {
nh = (nh - cur_gappiv) / 2;
}
} else {
nw = (nw - cur_gappih) / 2;
}
c->bw = mon->visible_clients == 1 && no_border_when_single && smartgaps
? 0
: borderpx;
if ((i % 2 && nh / 2 > 2 * c->bw) || (!(i % 2) && nw / 2 > 2 * c->bw)) {
if (i < n - 1) {
if (i % 2) {
if (i == 1) {
nh = nh * mon->pertag->smfacts[mon->pertag->curtag];
} else {
nh = (nh - cur_gappiv) / 2;
}
} else {
nw = (nw - cur_gappih) / 2;
}
if ((i % 4) == 2 && !s)
nx += nw + cur_gappih;
else if ((i % 4) == 3 && !s)
ny += nh + cur_gappiv;
}
if ((i % 4) == 2 && !s)
nx += nw + cur_gappih;
else if ((i % 4) == 3 && !s)
ny += nh + cur_gappiv;
}
if ((i % 4) == 0) {
if (s)
ny += nh + cur_gappiv;
else
ny -= nh + cur_gappiv;
} else if ((i % 4) == 1)
nx += nw + cur_gappih;
else if ((i % 4) == 2)
ny += nh + cur_gappiv;
else if ((i % 4) == 3) {
if (s)
nx += nw + cur_gappih;
else
nx -= nw + cur_gappih;
}
if ((i % 4) == 0) {
if (s)
ny += nh + cur_gappiv;
else
ny -= nh + cur_gappiv;
} else if ((i % 4) == 1)
nx += nw + cur_gappih;
else if ((i % 4) == 2)
ny += nh + cur_gappiv;
else if ((i % 4) == 3) {
if (s)
nx += nw + cur_gappih;
else
nx -= nw + cur_gappih;
}
if (i == 0) {
if (n != 1)
nw = (mon->w.width - 2 * cur_gappoh) *
mon->pertag->mfacts[mon->pertag->curtag];
ny = mon->w.y + cur_gappov;
} else if (i == 1) {
nw = mon->w.width - 2 * cur_gappoh - nw - cur_gappih;
} else if (i == 2) {
nh = mon->w.height - 2 * cur_gappov - nh - cur_gappiv;
}
i++;
}
if (i == 0) {
if (n != 1)
nw = (mon->w.width - 2 * cur_gappoh) *
mon->pertag->mfacts[mon->pertag->curtag];
ny = mon->w.y + cur_gappov;
} else if (i == 1) {
nw = mon->w.width - 2 * cur_gappoh - nw - cur_gappih;
} else if (i == 2) {
nh = mon->w.height - 2 * cur_gappov - nh - cur_gappiv;
}
i++;
}
c->geom = (struct wlr_box){.x = nx, .y = ny, .width = nw, .height = nh};
}
c->geom = (struct wlr_box){.x = nx, .y = ny, .width = nw, .height = nh};
}
// Second pass: apply gaps between clients
wl_list_for_each(c, &clients, link) {
if (!VISIBLEON(c, mon) || !ISTILED(c))
continue;
// Second pass: apply gaps between clients
wl_list_for_each(c, &clients, link) {
if (!VISIBLEON(c, mon) || !ISTILED(c))
continue;
unsigned int right_gap = 0;
unsigned int bottom_gap = 0;
Client *nc;
unsigned int right_gap = 0;
unsigned int bottom_gap = 0;
Client *nc;
wl_list_for_each(nc, &clients, link) {
if (!VISIBLEON(nc, mon) || !ISTILED(nc))
continue;
wl_list_for_each(nc, &clients, link) {
if (!VISIBLEON(nc, mon) || !ISTILED(nc))
continue;
if (c == nc)
continue;
if (c == nc)
continue;
// Check for right neighbor
if (c->geom.y == nc->geom.y && c->geom.x + c->geom.width == nc->geom.x) {
right_gap = cur_gappih;
}
// Check for right neighbor
if (c->geom.y == nc->geom.y &&
c->geom.x + c->geom.width == nc->geom.x) {
right_gap = cur_gappih;
}
// Check for bottom neighbor
if (c->geom.x == nc->geom.x && c->geom.y + c->geom.height == nc->geom.y) {
bottom_gap = cur_gappiv;
}
}
// Check for bottom neighbor
if (c->geom.x == nc->geom.x &&
c->geom.y + c->geom.height == nc->geom.y) {
bottom_gap = cur_gappiv;
}
}
resize(c,
(struct wlr_box){.x = c->geom.x,
.y = c->geom.y,
.width = c->geom.width - right_gap,
.height = c->geom.height - bottom_gap},
0);
}
resize(c,
(struct wlr_box){.x = c->geom.x,
.y = c->geom.y,
.width = c->geom.width - right_gap,
.height = c->geom.height - bottom_gap},
0);
}
}
void dwindle(Monitor *mon) { fibonacci(mon, 1); }
@ -122,370 +125,377 @@ void spiral(Monitor *mon) { fibonacci(mon, 0); }
// 网格布局窗口大小和位置计算
void grid(Monitor *m) {
unsigned int i, n;
unsigned int cx, cy, cw, ch;
unsigned int dx;
unsigned int cols, rows, overcols;
Client *c;
n = 0;
unsigned int i, n;
unsigned int cx, cy, cw, ch;
unsigned int dx;
unsigned int cols, rows, overcols;
Client *c;
n = 0;
// 第一次遍历,计算 n 的值
wl_list_for_each(c, &clients, link) {
if (VISIBLEON(c, c->mon) && !c->isunglobal && (m->isoverview || ISTILED(c))) {
n++;
}
}
// 第一次遍历,计算 n 的值
wl_list_for_each(c, &clients, link) {
if (VISIBLEON(c, c->mon) && !c->isunglobal &&
(m->isoverview || ISTILED(c))) {
n++;
}
}
if (n == 0) {
return; // 没有需要处理的客户端,直接返回
}
if (n == 0) {
return; // 没有需要处理的客户端,直接返回
}
if (n == 1) {
wl_list_for_each(c, &clients, link) {
c->bw = m->visible_clients == 1 && no_border_when_single && smartgaps
? 0
: borderpx;
if (VISIBLEON(c, c->mon) && !c->isunglobal && (m->isoverview || ISTILED(c))) {
cw = (m->w.width - 2 * overviewgappo) * 0.7;
ch = (m->w.height - 2 * overviewgappo) * 0.8;
c->geom.x = m->w.x + (m->w.width - cw) / 2;
c->geom.y = m->w.y + (m->w.height - ch) / 2;
c->geom.width = cw - 2 * c->bw;
c->geom.height = ch - 2 * c->bw;
resize(c, c->geom, 0);
return;
}
}
}
if (n == 1) {
wl_list_for_each(c, &clients, link) {
c->bw =
m->visible_clients == 1 && no_border_when_single && smartgaps
? 0
: borderpx;
if (VISIBLEON(c, c->mon) && !c->isunglobal &&
(m->isoverview || ISTILED(c))) {
cw = (m->w.width - 2 * overviewgappo) * 0.7;
ch = (m->w.height - 2 * overviewgappo) * 0.8;
c->geom.x = m->w.x + (m->w.width - cw) / 2;
c->geom.y = m->w.y + (m->w.height - ch) / 2;
c->geom.width = cw - 2 * c->bw;
c->geom.height = ch - 2 * c->bw;
resize(c, c->geom, 0);
return;
}
}
}
if (n == 2) {
cw = (m->w.width - 2 * overviewgappo - overviewgappi) / 2;
ch = (m->w.height - 2 * overviewgappo) * 0.65;
i = 0;
wl_list_for_each(c, &clients, link) {
c->bw = m->visible_clients == 1 && no_border_when_single && smartgaps
? 0
: borderpx;
if (VISIBLEON(c, c->mon) && !c->isunglobal && (m->isoverview || ISTILED(c))) {
if (i == 0) {
c->geom.x = m->w.x + overviewgappo;
c->geom.y = m->w.y + (m->w.height - ch) / 2 + overviewgappo;
c->geom.width = cw - 2 * c->bw;
c->geom.height = ch - 2 * c->bw;
resize(c, c->geom, 0);
} else if (i == 1) {
c->geom.x = m->w.x + cw + overviewgappo + overviewgappi;
c->geom.y = m->w.y + (m->w.height - ch) / 2 + overviewgappo;
c->geom.width = cw - 2 * c->bw;
c->geom.height = ch - 2 * c->bw;
resize(c, c->geom, 0);
}
i++;
}
}
return;
}
if (n == 2) {
cw = (m->w.width - 2 * overviewgappo - overviewgappi) / 2;
ch = (m->w.height - 2 * overviewgappo) * 0.65;
i = 0;
wl_list_for_each(c, &clients, link) {
c->bw =
m->visible_clients == 1 && no_border_when_single && smartgaps
? 0
: borderpx;
if (VISIBLEON(c, c->mon) && !c->isunglobal &&
(m->isoverview || ISTILED(c))) {
if (i == 0) {
c->geom.x = m->w.x + overviewgappo;
c->geom.y = m->w.y + (m->w.height - ch) / 2 + overviewgappo;
c->geom.width = cw - 2 * c->bw;
c->geom.height = ch - 2 * c->bw;
resize(c, c->geom, 0);
} else if (i == 1) {
c->geom.x = m->w.x + cw + overviewgappo + overviewgappi;
c->geom.y = m->w.y + (m->w.height - ch) / 2 + overviewgappo;
c->geom.width = cw - 2 * c->bw;
c->geom.height = ch - 2 * c->bw;
resize(c, c->geom, 0);
}
i++;
}
}
return;
}
// 计算列数和行数
for (cols = 0; cols <= n / 2; cols++) {
if (cols * cols >= n) {
break;
}
}
rows = (cols && (cols - 1) * cols >= n) ? cols - 1 : cols;
// 计算列数和行数
for (cols = 0; cols <= n / 2; cols++) {
if (cols * cols >= n) {
break;
}
}
rows = (cols && (cols - 1) * cols >= n) ? cols - 1 : cols;
// 计算每个客户端的高度和宽度
ch = (m->w.height - 2 * overviewgappo - (rows - 1) * overviewgappi) / rows;
cw = (m->w.width - 2 * overviewgappo - (cols - 1) * overviewgappi) / cols;
// 计算每个客户端的高度和宽度
ch = (m->w.height - 2 * overviewgappo - (rows - 1) * overviewgappi) / rows;
cw = (m->w.width - 2 * overviewgappo - (cols - 1) * overviewgappi) / cols;
// 处理多余的列
overcols = n % cols;
if (overcols) {
dx = (m->w.width - overcols * cw - (overcols - 1) * overviewgappi) / 2 -
overviewgappo;
}
// 处理多余的列
overcols = n % cols;
if (overcols) {
dx = (m->w.width - overcols * cw - (overcols - 1) * overviewgappi) / 2 -
overviewgappo;
}
// 调整每个客户端的位置和大小
i = 0;
wl_list_for_each(c, &clients, link) {
c->bw = m->visible_clients == 1 && no_border_when_single && smartgaps
? 0
: borderpx;
if (VISIBLEON(c, c->mon) && !c->isunglobal && (m->isoverview || ISTILED(c))) {
cx = m->w.x + (i % cols) * (cw + overviewgappi);
cy = m->w.y + (i / cols) * (ch + overviewgappi);
if (overcols && i >= n - overcols) {
cx += dx;
}
c->geom.x = cx + overviewgappo;
c->geom.y = cy + overviewgappo;
c->geom.width = cw - 2 * c->bw;
c->geom.height = ch - 2 * c->bw;
resize(c, c->geom, 0);
i++;
}
}
// 调整每个客户端的位置和大小
i = 0;
wl_list_for_each(c, &clients, link) {
c->bw = m->visible_clients == 1 && no_border_when_single && smartgaps
? 0
: borderpx;
if (VISIBLEON(c, c->mon) && !c->isunglobal &&
(m->isoverview || ISTILED(c))) {
cx = m->w.x + (i % cols) * (cw + overviewgappi);
cy = m->w.y + (i / cols) * (ch + overviewgappi);
if (overcols && i >= n - overcols) {
cx += dx;
}
c->geom.x = cx + overviewgappo;
c->geom.y = cy + overviewgappo;
c->geom.width = cw - 2 * c->bw;
c->geom.height = ch - 2 * c->bw;
resize(c, c->geom, 0);
i++;
}
}
}
void deck(Monitor *m) {
unsigned int mw, my;
int i, n = 0;
Client *c;
unsigned int cur_gappih = enablegaps ? m->gappih : 0;
unsigned int cur_gappiv = enablegaps ? m->gappiv : 0;
unsigned int cur_gappoh = enablegaps ? m->gappoh : 0;
unsigned int cur_gappov = enablegaps ? m->gappov : 0;
unsigned int mw, my;
int i, n = 0;
Client *c;
unsigned int cur_gappih = enablegaps ? m->gappih : 0;
unsigned int cur_gappiv = enablegaps ? m->gappiv : 0;
unsigned int cur_gappoh = enablegaps ? m->gappoh : 0;
unsigned int cur_gappov = enablegaps ? m->gappov : 0;
cur_gappih = smartgaps && m->visible_clients == 1 ? 0 : cur_gappih;
cur_gappiv = smartgaps && m->visible_clients == 1 ? 0 : cur_gappiv;
cur_gappoh = smartgaps && m->visible_clients == 1 ? 0 : cur_gappoh;
cur_gappov = smartgaps && m->visible_clients == 1 ? 0 : cur_gappov;
cur_gappih = smartgaps && m->visible_clients == 1 ? 0 : cur_gappih;
cur_gappiv = smartgaps && m->visible_clients == 1 ? 0 : cur_gappiv;
cur_gappoh = smartgaps && m->visible_clients == 1 ? 0 : cur_gappoh;
cur_gappov = smartgaps && m->visible_clients == 1 ? 0 : cur_gappov;
wl_list_for_each(c, &clients, link) if (VISIBLEON(c, m) && ISTILED(c)) n++;
if (n == 0)
return;
wl_list_for_each(c, &clients, link) if (VISIBLEON(c, m) && ISTILED(c)) n++;
if (n == 0)
return;
// Calculate master width using mfact from pertag
float mfact = m->pertag ? m->pertag->mfacts[m->pertag->curtag] : m->mfact;
// Calculate master width using mfact from pertag
float mfact = m->pertag ? m->pertag->mfacts[m->pertag->curtag] : m->mfact;
// Calculate master width including outer gaps
if (n > m->nmaster)
mw = m->nmaster ? round((m->w.width - 2 * cur_gappoh) * mfact) : 0;
else
mw = m->w.width - 2 * cur_gappoh;
// Calculate master width including outer gaps
if (n > m->nmaster)
mw = m->nmaster ? round((m->w.width - 2 * cur_gappoh) * mfact) : 0;
else
mw = m->w.width - 2 * cur_gappoh;
i = my = 0;
wl_list_for_each(c, &clients, link) {
if (!VISIBLEON(c, m) || !ISTILED(c))
continue;
if (i < m->nmaster) {
// Master area clients
resize(c,
(struct wlr_box){.x = m->w.x + cur_gappoh,
.y = m->w.y + cur_gappov + my,
.width = mw,
.height =
(m->w.height - cur_gappov - my - cur_gappiv) /
(MIN(n, m->nmaster) - i)},
0);
my += c->geom.height + cur_gappiv;
} else {
// Stack area clients
resize(c,
(struct wlr_box){.x = m->w.x + mw + cur_gappoh + cur_gappih,
.y = m->w.y + cur_gappov,
.width =
m->w.width - mw - 2 * cur_gappoh - cur_gappih,
.height = m->w.height - 2 * cur_gappov},
0);
if (c == focustop(m))
wlr_scene_node_raise_to_top(&c->scene->node);
}
i++;
}
i = my = 0;
wl_list_for_each(c, &clients, link) {
if (!VISIBLEON(c, m) || !ISTILED(c))
continue;
if (i < m->nmaster) {
// Master area clients
resize(c,
(struct wlr_box){
.x = m->w.x + cur_gappoh,
.y = m->w.y + cur_gappov + my,
.width = mw,
.height = (m->w.height - cur_gappov - my - cur_gappiv) /
(MIN(n, m->nmaster) - i)},
0);
my += c->geom.height + cur_gappiv;
} else {
// Stack area clients
resize(c,
(struct wlr_box){.x = m->w.x + mw + cur_gappoh + cur_gappih,
.y = m->w.y + cur_gappov,
.width = m->w.width - mw - 2 * cur_gappoh -
cur_gappih,
.height = m->w.height - 2 * cur_gappov},
0);
if (c == focustop(m))
wlr_scene_node_raise_to_top(&c->scene->node);
}
i++;
}
}
// 滚动布局
void scroller(Monitor *m) {
unsigned int i, n;
unsigned int i, n;
Client *c, *root_client = NULL;
Client **tempClients = NULL; // 初始化为 NULL
n = 0;
struct wlr_box target_geom;
int focus_client_index = 0;
bool need_scroller = false;
unsigned int cur_gappih = enablegaps ? m->gappih : 0;
unsigned int cur_gappoh = enablegaps ? m->gappoh : 0;
unsigned int cur_gappov = enablegaps ? m->gappov : 0;
Client *c, *root_client = NULL;
Client **tempClients = NULL; // 初始化为 NULL
n = 0;
struct wlr_box target_geom;
int focus_client_index = 0;
bool need_scroller = false;
unsigned int cur_gappih = enablegaps ? m->gappih : 0;
unsigned int cur_gappoh = enablegaps ? m->gappoh : 0;
unsigned int cur_gappov = enablegaps ? m->gappov : 0;
cur_gappih = smartgaps && m->visible_clients == 1 ? 0 : cur_gappih;
cur_gappoh = smartgaps && m->visible_clients == 1 ? 0 : cur_gappoh;
cur_gappov = smartgaps && m->visible_clients == 1 ? 0 : cur_gappov;
cur_gappih = smartgaps && m->visible_clients == 1 ? 0 : cur_gappih;
cur_gappoh = smartgaps && m->visible_clients == 1 ? 0 : cur_gappoh;
cur_gappov = smartgaps && m->visible_clients == 1 ? 0 : cur_gappov;
unsigned int max_client_width =
m->w.width - 2 * scroller_structs - cur_gappih;
unsigned int max_client_width =
m->w.width - 2 * scroller_structs - cur_gappih;
// 第一次遍历,计算 n 的值
wl_list_for_each(c, &clients, link) {
if (VISIBLEON(c, c->mon) && ISTILED(c)) {
n++;
}
}
// 第一次遍历,计算 n 的值
wl_list_for_each(c, &clients, link) {
if (VISIBLEON(c, c->mon) && ISTILED(c)) {
n++;
}
}
if (n == 0) {
return; // 没有需要处理的客户端,直接返回
}
if (n == 0) {
return; // 没有需要处理的客户端,直接返回
}
// 动态分配内存
tempClients = malloc(n * sizeof(Client *));
if (!tempClients) {
// 处理内存分配失败的情况
return;
}
// 动态分配内存
tempClients = malloc(n * sizeof(Client *));
if (!tempClients) {
// 处理内存分配失败的情况
return;
}
// 第二次遍历,填充 tempClients
n = 0;
wl_list_for_each(c, &clients, link) {
if (VISIBLEON(c, c->mon) && ISTILED(c)) {
tempClients[n] = c;
n++;
}
}
// 第二次遍历,填充 tempClients
n = 0;
wl_list_for_each(c, &clients, link) {
if (VISIBLEON(c, c->mon) && ISTILED(c)) {
tempClients[n] = c;
n++;
}
}
if (n == 1) {
c = tempClients[0];
target_geom.height = m->w.height - 2 * cur_gappov;
target_geom.width =
(m->w.width - 2 * cur_gappoh) * scroller_default_proportion_single;
target_geom.x = m->w.x + (m->w.width - target_geom.width) / 2;
target_geom.y = m->w.y + (m->w.height - target_geom.height) / 2;
resize(c, target_geom, 0);
free(tempClients); // 释放内存
return;
}
if (n == 1) {
c = tempClients[0];
target_geom.height = m->w.height - 2 * cur_gappov;
target_geom.width =
(m->w.width - 2 * cur_gappoh) * scroller_default_proportion_single;
target_geom.x = m->w.x + (m->w.width - target_geom.width) / 2;
target_geom.y = m->w.y + (m->w.height - target_geom.height) / 2;
resize(c, target_geom, 0);
free(tempClients); // 释放内存
return;
}
if (m->sel && !client_is_unmanaged(m->sel) && !m->sel->isfloating &&
!m->sel->ismaxmizescreen && !m->sel->isfullscreen) {
root_client = m->sel;
} else if (m->prevsel && !client_is_unmanaged(m->prevsel) &&
!m->prevsel->isfloating && !m->prevsel->ismaxmizescreen &&
!m->prevsel->isfullscreen) {
root_client = m->prevsel;
} else {
root_client = center_select(m);
}
if (m->sel && !client_is_unmanaged(m->sel) && !m->sel->isfloating &&
!m->sel->ismaxmizescreen && !m->sel->isfullscreen) {
root_client = m->sel;
} else if (m->prevsel && !client_is_unmanaged(m->prevsel) &&
!m->prevsel->isfloating && !m->prevsel->ismaxmizescreen &&
!m->prevsel->isfullscreen) {
root_client = m->prevsel;
} else {
root_client = center_select(m);
}
if (!root_client) {
free(tempClients); // 释放内存
return;
}
if (!root_client) {
free(tempClients); // 释放内存
return;
}
for (i = 0; i < n; i++) {
c = tempClients[i];
if (root_client == c) {
if (!c->is_open_animation && c->geom.x >= m->w.x + scroller_structs &&
c->geom.x + c->geom.width <= m->w.x + m->w.width - scroller_structs) {
need_scroller = false;
} else {
need_scroller = true;
}
focus_client_index = i;
break;
}
}
for (i = 0; i < n; i++) {
c = tempClients[i];
if (root_client == c) {
if (!c->is_open_animation &&
c->geom.x >= m->w.x + scroller_structs &&
c->geom.x + c->geom.width <=
m->w.x + m->w.width - scroller_structs) {
need_scroller = false;
} else {
need_scroller = true;
}
focus_client_index = i;
break;
}
}
target_geom.height = m->w.height - 2 * cur_gappov;
target_geom.width = max_client_width * c->scroller_proportion;
target_geom.y = m->w.y + (m->w.height - target_geom.height) / 2;
target_geom.height = m->w.height - 2 * cur_gappov;
target_geom.width = max_client_width * c->scroller_proportion;
target_geom.y = m->w.y + (m->w.height - target_geom.height) / 2;
if (need_scroller) {
if (scroller_focus_center ||
((!m->prevsel ||
(m->prevsel->scroller_proportion * max_client_width) +
(root_client->scroller_proportion * max_client_width) >
m->w.width - 2 * scroller_structs - cur_gappih) &&
scroller_prefer_center)) {
target_geom.x = m->w.x + (m->w.width - target_geom.width) / 2;
} else {
target_geom.x =
root_client->geom.x > m->w.x + (m->w.width) / 2
? m->w.x + (m->w.width -
root_client->scroller_proportion * max_client_width -
scroller_structs)
: m->w.x + scroller_structs;
}
resize(tempClients[focus_client_index], target_geom, 0);
} else {
target_geom.x = c->geom.x;
resize(tempClients[focus_client_index], target_geom, 0);
}
if (need_scroller) {
if (scroller_focus_center ||
((!m->prevsel ||
(m->prevsel->scroller_proportion * max_client_width) +
(root_client->scroller_proportion * max_client_width) >
m->w.width - 2 * scroller_structs - cur_gappih) &&
scroller_prefer_center)) {
target_geom.x = m->w.x + (m->w.width - target_geom.width) / 2;
} else {
target_geom.x = root_client->geom.x > m->w.x + (m->w.width) / 2
? m->w.x + (m->w.width -
root_client->scroller_proportion *
max_client_width -
scroller_structs)
: m->w.x + scroller_structs;
}
resize(tempClients[focus_client_index], target_geom, 0);
} else {
target_geom.x = c->geom.x;
resize(tempClients[focus_client_index], target_geom, 0);
}
for (i = 1; i <= focus_client_index; i++) {
c = tempClients[focus_client_index - i];
target_geom.width = max_client_width * c->scroller_proportion;
target_geom.x = tempClients[focus_client_index - i + 1]->geom.x -
cur_gappih - target_geom.width;
resize(c, target_geom, 0);
}
for (i = 1; i <= focus_client_index; i++) {
c = tempClients[focus_client_index - i];
target_geom.width = max_client_width * c->scroller_proportion;
target_geom.x = tempClients[focus_client_index - i + 1]->geom.x -
cur_gappih - target_geom.width;
resize(c, target_geom, 0);
}
for (i = 1; i < n - focus_client_index; i++) {
c = tempClients[focus_client_index + i];
target_geom.width = max_client_width * c->scroller_proportion;
target_geom.x = tempClients[focus_client_index + i - 1]->geom.x +
cur_gappih +
tempClients[focus_client_index + i - 1]->geom.width;
resize(c, target_geom, 0);
}
for (i = 1; i < n - focus_client_index; i++) {
c = tempClients[focus_client_index + i];
target_geom.width = max_client_width * c->scroller_proportion;
target_geom.x = tempClients[focus_client_index + i - 1]->geom.x +
cur_gappih +
tempClients[focus_client_index + i - 1]->geom.width;
resize(c, target_geom, 0);
}
free(tempClients); // 最后释放内存
free(tempClients); // 最后释放内存
}
void tile(Monitor *m) {
unsigned int i, n = 0, h, r, ie = enablegaps, mw, my, ty;
Client *c;
unsigned int i, n = 0, h, r, ie = enablegaps, mw, my, ty;
Client *c;
wl_list_for_each(c, &clients,
link) if (VISIBLEON(c, m) && ISTILED(c)) n++;
if (n == 0)
return;
wl_list_for_each(c, &clients, link) if (VISIBLEON(c, m) && ISTILED(c)) n++;
if (n == 0)
return;
unsigned int cur_gappih = enablegaps ? m->gappih : 0;
unsigned int cur_gappiv = enablegaps ? m->gappiv : 0;
unsigned int cur_gappoh = enablegaps ? m->gappoh : 0;
unsigned int cur_gappov = enablegaps ? m->gappov : 0;
unsigned int cur_gappih = enablegaps ? m->gappih : 0;
unsigned int cur_gappiv = enablegaps ? m->gappiv : 0;
unsigned int cur_gappoh = enablegaps ? m->gappoh : 0;
unsigned int cur_gappov = enablegaps ? m->gappov : 0;
cur_gappih = smartgaps && m->visible_clients == 1 ? 0 : cur_gappih;
cur_gappiv = smartgaps && m->visible_clients == 1 ? 0 : cur_gappiv;
cur_gappoh = smartgaps && m->visible_clients == 1 ? 0 : cur_gappoh;
cur_gappov = smartgaps && m->visible_clients == 1 ? 0 : cur_gappov;
cur_gappih = smartgaps && m->visible_clients == 1 ? 0 : cur_gappih;
cur_gappiv = smartgaps && m->visible_clients == 1 ? 0 : cur_gappiv;
cur_gappoh = smartgaps && m->visible_clients == 1 ? 0 : cur_gappoh;
cur_gappov = smartgaps && m->visible_clients == 1 ? 0 : cur_gappov;
if (n > selmon->pertag->nmasters[selmon->pertag->curtag])
mw = selmon->pertag->nmasters[selmon->pertag->curtag]
? (m->w.width + cur_gappiv * ie) *
selmon->pertag->mfacts[selmon->pertag->curtag]
: 0;
else
mw = m->w.width - 2 * cur_gappov + cur_gappiv * ie;
i = 0;
my = ty = cur_gappoh;
wl_list_for_each(c, &clients, link) {
if (!VISIBLEON(c, m) || !ISTILED(c))
continue;
if (i < selmon->pertag->nmasters[selmon->pertag->curtag]) {
r = MIN(n, selmon->pertag->nmasters[selmon->pertag->curtag]) - i;
h = (m->w.height - my - cur_gappoh - cur_gappih * ie * (r - 1)) / r;
resize(c,
(struct wlr_box){.x = m->w.x + cur_gappov,
.y = m->w.y + my,
.width = mw - cur_gappiv * ie,
.height = h},
0);
my += c->geom.height + cur_gappih * ie;
} else {
r = n - i;
h = (m->w.height - ty - cur_gappoh - cur_gappih * ie * (r - 1)) / r;
resize(c,
(struct wlr_box){.x = m->w.x + mw + cur_gappov,
.y = m->w.y + ty,
.width = m->w.width - mw - 2 * cur_gappov,
.height = h},
0);
ty += c->geom.height + cur_gappih * ie;
}
i++;
}
if (n > selmon->pertag->nmasters[selmon->pertag->curtag])
mw = selmon->pertag->nmasters[selmon->pertag->curtag]
? (m->w.width + cur_gappiv * ie) *
selmon->pertag->mfacts[selmon->pertag->curtag]
: 0;
else
mw = m->w.width - 2 * cur_gappov + cur_gappiv * ie;
i = 0;
my = ty = cur_gappoh;
wl_list_for_each(c, &clients, link) {
if (!VISIBLEON(c, m) || !ISTILED(c))
continue;
if (i < selmon->pertag->nmasters[selmon->pertag->curtag]) {
r = MIN(n, selmon->pertag->nmasters[selmon->pertag->curtag]) - i;
h = (m->w.height - my - cur_gappoh - cur_gappih * ie * (r - 1)) / r;
resize(c,
(struct wlr_box){.x = m->w.x + cur_gappov,
.y = m->w.y + my,
.width = mw - cur_gappiv * ie,
.height = h},
0);
my += c->geom.height + cur_gappih * ie;
} else {
r = n - i;
h = (m->w.height - ty - cur_gappoh - cur_gappih * ie * (r - 1)) / r;
resize(c,
(struct wlr_box){.x = m->w.x + mw + cur_gappov,
.y = m->w.y + ty,
.width = m->w.width - mw - 2 * cur_gappov,
.height = h},
0);
ty += c->geom.height + cur_gappih * ie;
}
i++;
}
}
void // 17
monocle(Monitor *m) {
Client *c;
Client *c;
wl_list_for_each(c, &clients, link) {
if (!VISIBLEON(c, m) || !ISTILED(c))
continue;
resize(c, m->w, 0);
}
if ((c = focustop(m)))
wlr_scene_node_raise_to_top(&c->scene->node);
wl_list_for_each(c, &clients, link) {
if (!VISIBLEON(c, m) || !ISTILED(c))
continue;
resize(c, m->w, 0);
}
if ((c = focustop(m)))
wlr_scene_node_raise_to_top(&c->scene->node);
}

11336
src/maomao.c

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff