opt: format code

This commit is contained in:
DreamMaoMao 2025-03-02 18:51:16 +08:00
parent 2ac477becf
commit 72e477416a
4 changed files with 218 additions and 195 deletions

View file

@ -313,6 +313,11 @@ static inline void client_set_fullscreen(Client *c, int fullscreen) {
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));
}
static inline uint32_t client_set_size(Client *c, uint32_t width, static inline uint32_t client_set_size(Client *c, uint32_t width,
uint32_t height) { uint32_t height) {
#ifdef XWAYLAND #ifdef XWAYLAND

217
maomao.c
View file

@ -12,7 +12,6 @@
#include <sys/wait.h> #include <sys/wait.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
#include <wlr/types/wlr_fractional_scale_v1.h>
#include <wayland-server-core.h> #include <wayland-server-core.h>
#include <wlr/backend.h> #include <wlr/backend.h>
#include <wlr/backend/libinput.h> #include <wlr/backend/libinput.h>
@ -124,7 +123,7 @@ enum {
}; /* EWMH atoms */ }; /* EWMH atoms */
#endif #endif
enum { UP, DOWN, LEFT, RIGHT, UNDIR }; /* movewin */ enum { UP, DOWN, LEFT, RIGHT, UNDIR }; /* movewin */
enum {NONE,OPEN,MOVE,CLOSE,TAG}; enum { NONE, OPEN, MOVE, CLOSE, TAG };
typedef struct { typedef struct {
int i; int i;
@ -559,8 +558,8 @@ void incovgaps(const Arg *arg);
void incigaps(const Arg *arg); void incigaps(const Arg *arg);
void defaultgaps(const Arg *arg); void defaultgaps(const Arg *arg);
void buffer_set_size(Client *c, animationScale scale_data); void buffer_set_size(Client *c, animationScale scale_data);
void snap_scene_buffer_apply_size(struct wlr_scene_buffer *buffer, int sx, int sy, void snap_scene_buffer_apply_size(struct wlr_scene_buffer *buffer, int sx,
void *data); int sy, void *data);
// int timer_tick_action(void *data); // int timer_tick_action(void *data);
#include "dispatch.h" #include "dispatch.h"
@ -669,9 +668,9 @@ struct NumTags {
}; };
struct Pertag { struct Pertag {
unsigned int curtag, prevtag; /* current and previous tag */ unsigned int curtag, prevtag; /* current and previous tag */
int nmasters[LENGTH(tags) + 1]; /* number of windows in master area */ int nmasters[LENGTH(tags) + 1]; /* number of windows in master area */
float mfacts[LENGTH(tags) + 1]; /* mfacts per tag */ float mfacts[LENGTH(tags) + 1]; /* mfacts per tag */
float smfacts[LENGTH(tags) + 1]; /* smfacts per tag */ float smfacts[LENGTH(tags) + 1]; /* smfacts per tag */
const Layout const Layout
*ltidxs[LENGTH(tags) + 1]; /* matrix of tags and layouts indexes */ *ltidxs[LENGTH(tags) + 1]; /* matrix of tags and layouts indexes */
@ -704,27 +703,26 @@ struct vec2 calculate_animation_curve_at(double t, int type) {
} }
point.x = 3 * t * (1 - t) * (1 - t) * animation_curve[0] + point.x = 3 * t * (1 - t) * (1 - t) * animation_curve[0] +
3 * t * t * (1 - t) * animation_curve[2] + t * t * t; 3 * t * t * (1 - t) * animation_curve[2] + t * t * t;
point.y = 3 * t * (1 - t) * (1 - t) * animation_curve[1] + point.y = 3 * t * (1 - t) * (1 - t) * animation_curve[1] +
3 * t * t * (1 - t) * animation_curve[3] + t * t * t; 3 * t * t * (1 - t) * animation_curve[3] + t * t * t;
return point; return point;
} }
void init_baked_points(void) { void init_baked_points(void) {
baked_points_move = calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_move)); baked_points_move = calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_move));
baked_points_open = calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_open)); baked_points_open = calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_open));
baked_points_tag = calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_tag)); baked_points_tag = calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_tag));
for (size_t i = 0; i < BAKED_POINTS_COUNT; i++) { for (size_t i = 0; i < BAKED_POINTS_COUNT; i++) {
baked_points_move[i] = baked_points_move[i] = calculate_animation_curve_at(
calculate_animation_curve_at((double)i / (BAKED_POINTS_COUNT - 1), MOVE); (double)i / (BAKED_POINTS_COUNT - 1), MOVE);
} }
for (size_t i = 0; i < BAKED_POINTS_COUNT; i++) { for (size_t i = 0; i < BAKED_POINTS_COUNT; i++) {
baked_points_open[i] = baked_points_open[i] = calculate_animation_curve_at(
calculate_animation_curve_at((double)i / (BAKED_POINTS_COUNT - 1), OPEN); (double)i / (BAKED_POINTS_COUNT - 1), OPEN);
} }
for (size_t i = 0; i < BAKED_POINTS_COUNT; i++) { for (size_t i = 0; i < BAKED_POINTS_COUNT; i++) {
baked_points_tag[i] = baked_points_tag[i] =
@ -732,17 +730,17 @@ void init_baked_points(void) {
} }
} }
double find_animation_curve_at(double t,int type) { double find_animation_curve_at(double t, int type) {
size_t down = 0; size_t down = 0;
size_t up = BAKED_POINTS_COUNT - 1; size_t up = BAKED_POINTS_COUNT - 1;
size_t middle = (up + down) / 2; size_t middle = (up + down) / 2;
struct vec2 *baked_points; struct vec2 *baked_points;
if(type == MOVE) { if (type == MOVE) {
baked_points = baked_points_move; baked_points = baked_points_move;
} else if(type == OPEN) { } else if (type == OPEN) {
baked_points = baked_points_open; baked_points = baked_points_open;
} else if(type == TAG) { } else if (type == TAG) {
baked_points = baked_points_tag; baked_points = baked_points_tag;
} }
while (up - down != 1) { while (up - down != 1) {
@ -754,30 +752,36 @@ double find_animation_curve_at(double t,int type) {
middle = (up + down) / 2; middle = (up + down) / 2;
} }
return baked_points[up].y; return baked_points[up].y;
} }
// 有 bug,只是让上面那根透明了 // 有 bug,只是让上面那根透明了
void apply_opacity_to_rect_nodes(Client *c,struct wlr_scene_node *node, double animation_passed) { void apply_opacity_to_rect_nodes(Client *c, struct wlr_scene_node *node,
double animation_passed) {
if (node->type == WLR_SCENE_NODE_RECT) { if (node->type == WLR_SCENE_NODE_RECT) {
struct wlr_scene_rect *rect = wlr_scene_rect_from_node(node); struct wlr_scene_rect *rect = wlr_scene_rect_from_node(node);
// Assuming the rect has a color field and we can modify it // Assuming the rect has a color field and we can modify it
rect->color[0] = (1- animation_passed ) * rect->color[0]; rect->color[0] = (1 - animation_passed) * rect->color[0];
rect->color[1] = (1- animation_passed ) * rect->color[1]; rect->color[1] = (1 - animation_passed) * rect->color[1];
rect->color[2] = (1- animation_passed ) * rect->color[2]; rect->color[2] = (1 - animation_passed) * rect->color[2];
rect->color[3] = (1- animation_passed ) * rect->color[3]; rect->color[3] = (1 - animation_passed) * rect->color[3];
wlr_scene_rect_set_color(rect, rect->color); wlr_scene_rect_set_color(rect, rect->color);
// TODO: 判断当前窗口是否在屏幕外,如果在屏幕外就不要绘制 // TODO: 判断当前窗口是否在屏幕外,如果在屏幕外就不要绘制
// 划出的border剪切屏幕之外的这里底部bttome可以了左右的还不不对 // 划出的border剪切屏幕之外的这里底部bttome可以了左右的还不不对
// if(node->y > c->geom.height/2 && c->geom.y + c->animation.current.y + node->y >= c->mon->m.y + c->mon->m.height){ // if(node->y > c->geom.height/2 && c->geom.y + c->animation.current.y +
// node->y >= c->mon->m.y + c->mon->m.height){
// wlr_scene_rect_set_size(rect, 0, 0); // down // wlr_scene_rect_set_size(rect, 0, 0); // down
// } else if(node->x > c->geom.width/2 && c->geom.y + c->animation.current.y + node->y >= c->mon->m.y + c->mon->m.height) { // } else if(node->x > c->geom.width/2 && c->geom.y +
// wlr_scene_rect_set_size(rect, c->bw,rect->height - (c->geom.y + c->animation.current.y + node->y - c->mon->m.y - c->mon->m.height)); // right // c->animation.current.y + node->y >= c->mon->m.y + c->mon->m.height) {
// } else if(rect->height > rect->width && c->geom.y + c->animation.current.y + node->y >= c->mon->m.y + c->mon->m.height) { // wlr_scene_rect_set_size(rect, c->bw,rect->height - (c->geom.y +
// wlr_scene_rect_set_size(rect, c->bw,rect->height - (c->geom.y + c->animation.current.y + node->y - c->mon->m.y - c->mon->m.height)); // left // c->animation.current.y + node->y - c->mon->m.y - c->mon->m.height)); //
// right
// } else if(rect->height > rect->width && c->geom.y +
// c->animation.current.y + node->y >= c->mon->m.y + c->mon->m.height) {
// wlr_scene_rect_set_size(rect, c->bw,rect->height - (c->geom.y +
// c->animation.current.y + node->y - c->mon->m.y - c->mon->m.height)); //
// left
// } // }
} }
// If the node is a tree, recursively traverse its children // If the node is a tree, recursively traverse its children
@ -790,7 +794,6 @@ void apply_opacity_to_rect_nodes(Client *c,struct wlr_scene_node *node, double a
} }
} }
void fadeout_client_animation_next_tick(Client *c) { void fadeout_client_animation_next_tick(Client *c) {
if (!c) if (!c)
return; return;
@ -800,7 +803,7 @@ void fadeout_client_animation_next_tick(Client *c) {
double animation_passed = double animation_passed =
(double)c->animation.passed_frames / c->animation.total_frames; (double)c->animation.passed_frames / c->animation.total_frames;
int type = c->animation.action == NONE ? MOVE : c->animation.action; int type = c->animation.action == NONE ? MOVE : c->animation.action;
double factor = find_animation_curve_at(animation_passed,type); double factor = find_animation_curve_at(animation_passed, type);
uint32_t width = c->animation.initial.width + uint32_t width = c->animation.initial.width +
(c->current.width - c->animation.initial.width) * factor; (c->current.width - c->animation.initial.width) * factor;
uint32_t height = c->animation.initial.height + uint32_t height = c->animation.initial.height +
@ -822,13 +825,13 @@ void fadeout_client_animation_next_tick(Client *c) {
double opacity = MAX(fadeout_begin_opacity - animation_passed, 0); double opacity = MAX(fadeout_begin_opacity - animation_passed, 0);
wlr_scene_node_for_each_buffer(&c->scene->node, wlr_scene_node_for_each_buffer(&c->scene->node, scene_buffer_apply_opacity,
scene_buffer_apply_opacity, &opacity); &opacity);
apply_opacity_to_rect_nodes(c, &c->scene->node, animation_passed); apply_opacity_to_rect_nodes(c, &c->scene->node, animation_passed);
if((c->animation_type && strcmp(c->animation_type, "zoom") == 0) if ((c->animation_type && strcmp(c->animation_type, "zoom") == 0) ||
|| (!c->animation_type && strcmp(animation_type, "zoom") == 0)) { (!c->animation_type && strcmp(animation_type, "zoom") == 0)) {
scale_data.width = width; scale_data.width = width;
scale_data.height = height; scale_data.height = height;
@ -837,7 +840,7 @@ void fadeout_client_animation_next_tick(Client *c) {
wlr_scene_node_for_each_buffer(&c->scene->node, wlr_scene_node_for_each_buffer(&c->scene->node,
snap_scene_buffer_apply_size, &scale_data); snap_scene_buffer_apply_size, &scale_data);
} }
if (animation_passed == 1.0) { if (animation_passed == 1.0) {
wl_list_remove(&c->fadeout_link); wl_list_remove(&c->fadeout_link);
@ -854,7 +857,7 @@ void client_animation_next_tick(Client *c) {
(double)c->animation.passed_frames / c->animation.total_frames; (double)c->animation.passed_frames / c->animation.total_frames;
int type = c->animation.action == NONE ? MOVE : c->animation.action; int type = c->animation.action == NONE ? MOVE : c->animation.action;
double factor = find_animation_curve_at(animation_passed,type); double factor = find_animation_curve_at(animation_passed, type);
Client *pointer_c = NULL; Client *pointer_c = NULL;
double sx = 0, sy = 0; double sx = 0, sy = 0;
@ -925,7 +928,8 @@ void client_actual_size(Client *c, uint32_t *width, uint32_t *height) {
*height = c->animation.current.height; *height = c->animation.current.height;
} }
void apply_border(Client *c, struct wlr_box clip_box, int offsetx, int offsety) { void apply_border(Client *c, struct wlr_box clip_box, int offsetx,
int offsety) {
if (c->iskilling || !client_surface(c)->mapped) if (c->iskilling || !client_surface(c)->mapped)
return; return;
@ -937,21 +941,20 @@ void apply_border(Client *c, struct wlr_box clip_box, int offsetx, int offsety)
wlr_scene_rect_set_size(c->border[3], c->bw, clip_box.height - 2 * c->bw); wlr_scene_rect_set_size(c->border[3], c->bw, clip_box.height - 2 * c->bw);
wlr_scene_node_set_position(&c->border[0]->node, 0, 0); wlr_scene_node_set_position(&c->border[0]->node, 0, 0);
wlr_scene_node_set_position(&c->border[2]->node, 0, c->bw); wlr_scene_node_set_position(&c->border[2]->node, 0, c->bw);
wlr_scene_node_set_position(&c->border[1]->node, 0, wlr_scene_node_set_position(&c->border[1]->node, 0, clip_box.height - c->bw);
clip_box.height - c->bw);
wlr_scene_node_set_position(&c->border[3]->node, clip_box.width - c->bw, wlr_scene_node_set_position(&c->border[3]->node, clip_box.width - c->bw,
c->bw); c->bw);
if (c->animation.running && c->animation.action != MOVE) { if (c->animation.running && c->animation.action != MOVE) {
if (c->animation.current.x < c->mon->m.x) { if (c->animation.current.x < c->mon->m.x) {
wlr_scene_rect_set_size(c->border[2], 0, 0); wlr_scene_rect_set_size(c->border[2], 0, 0);
} else if (c->animation.current.x + c->geom.width > } else if (c->animation.current.x + c->geom.width >
c->mon->m.x + c->mon->m.width) { c->mon->m.x + c->mon->m.width) {
wlr_scene_rect_set_size(c->border[3], 0, 0); wlr_scene_rect_set_size(c->border[3], 0, 0);
} else if (c->animation.current.y < c->mon->m.y) { } else if (c->animation.current.y < c->mon->m.y) {
wlr_scene_rect_set_size(c->border[0], 0, 0); wlr_scene_rect_set_size(c->border[0], 0, 0);
} else if (c->animation.current.y + c->geom.height > } else if (c->animation.current.y + c->geom.height >
c->mon->m.y + c->mon->m.height) { c->mon->m.y + c->mon->m.height) {
wlr_scene_rect_set_size(c->border[1], 0, 0); wlr_scene_rect_set_size(c->border[1], 0, 0);
} }
} }
@ -960,8 +963,8 @@ void apply_border(Client *c, struct wlr_box clip_box, int offsetx, int offsety)
wlr_scene_node_set_position(&c->border[2]->node, offsetx, c->bw + offsety); wlr_scene_node_set_position(&c->border[2]->node, offsetx, c->bw + offsety);
wlr_scene_node_set_position(&c->border[1]->node, offsetx, wlr_scene_node_set_position(&c->border[1]->node, offsetx,
clip_box.height - c->bw + offsety); clip_box.height - c->bw + offsety);
wlr_scene_node_set_position(&c->border[3]->node, clip_box.width - c->bw + offsetx, wlr_scene_node_set_position(
c->bw + offsety); &c->border[3]->node, clip_box.width - c->bw + offsetx, c->bw + offsety);
} }
void client_apply_clip(Client *c) { void client_apply_clip(Client *c) {
@ -970,15 +973,15 @@ void client_apply_clip(Client *c) {
return; return;
struct wlr_box clip_box; struct wlr_box clip_box;
if(!animations) { if (!animations) {
c->animation.running = false; c->animation.running = false;
c->need_output_flush = false; c->need_output_flush = false;
c->animainit_geom = c->current = c->pending = c->animation.current = c->animainit_geom = c->current = c->pending = c->animation.current =
c->geom; c->geom;
apply_border(c, c->geom, 0, 0); apply_border(c, c->geom, 0, 0);
client_get_clip(c, &clip_box); client_get_clip(c, &clip_box);
wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &clip_box); wlr_scene_subsurface_tree_set_clip(&c->scene_surface->node, &clip_box);
return; return;
} }
uint32_t width, height; uint32_t width, height;
@ -1020,10 +1023,9 @@ void client_apply_clip(Client *c) {
} else if (c->animation.current.y + c->geom.height >= } else if (c->animation.current.y + c->geom.height >=
c->mon->m.y + c->mon->m.height) { c->mon->m.y + c->mon->m.height) {
clip_box.height = clip_box.height - clip_box.height = clip_box.height -
(c->animation.current.y + c->animation.current.height - (c->animation.current.y + c->animation.current.height -
c->mon->m.y - c->mon->m.height); c->mon->m.y - c->mon->m.height);
} }
} }
animationScale scale_data; animationScale scale_data;
@ -1050,7 +1052,8 @@ bool client_draw_frame(Client *c) {
client_apply_clip(c); client_apply_clip(c);
} else { } else {
wlr_scene_node_set_position(&c->scene->node, c->pending.x, c->pending.y); wlr_scene_node_set_position(&c->scene->node, c->pending.x, c->pending.y);
c->animainit_geom = c->animation.initial = c->pending = c->current = c->geom; c->animainit_geom = c->animation.initial = c->pending = c->current =
c->geom;
client_apply_clip(c); client_apply_clip(c);
c->need_output_flush = false; c->need_output_flush = false;
} }
@ -2027,7 +2030,7 @@ commitlayersurfacenotify(struct wl_listener *listener, void *data) {
void client_set_pending_state(Client *c) { void client_set_pending_state(Client *c) {
// 判断是否需要动画 // 判断是否需要动画
if(!animations) { if (!animations) {
c->animation.should_animate = false; c->animation.should_animate = false;
} else if (c->isglobal && c->isfloating) { } else if (c->isglobal && c->isfloating) {
c->animation.should_animate = false; c->animation.should_animate = false;
@ -3897,8 +3900,8 @@ void scene_buffer_apply_size(struct wlr_scene_buffer *buffer, int sx, int sy,
} }
} }
void snap_scene_buffer_apply_size(struct wlr_scene_buffer *buffer, int sx, int sy, void snap_scene_buffer_apply_size(struct wlr_scene_buffer *buffer, int sx,
void *data) { int sy, void *data) {
animationScale *scale_data = (animationScale *)data; animationScale *scale_data = (animationScale *)data;
wlr_scene_buffer_set_dest_size(buffer, scale_data->width, scale_data->height); wlr_scene_buffer_set_dest_size(buffer, scale_data->width, scale_data->height);
} }
@ -4474,29 +4477,34 @@ setlayout(const Arg *arg) {
void switch_layout(const Arg *arg) { void switch_layout(const Arg *arg) {
int jk,ji; int jk, ji;
char *target_layout_name=NULL; char *target_layout_name = NULL;
size_t len; size_t len;
if(config.circle_layout_count != 0) { if (config.circle_layout_count != 0) {
for(jk = 0; jk < config.circle_layout_count; jk++) { 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(selmon->pertag->ltidxs[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],
target_layout_name = jk == config.circle_layout_count - 1 ? config.circle_layout[0] : config.circle_layout[jk + 1]; selmon->pertag->ltidxs[selmon->pertag->curtag]->name,
len) == 0) {
target_layout_name = jk == config.circle_layout_count - 1
? config.circle_layout[0]
: config.circle_layout[jk + 1];
break; break;
} }
} }
if(!target_layout_name) { if (!target_layout_name) {
target_layout_name = config.circle_layout[0]; target_layout_name = config.circle_layout[0];
} }
for (ji = 0; ji < LENGTH(layouts); ji++) { for (ji = 0; ji < LENGTH(layouts); ji++) {
len = MAX(strlen(layouts[ji].name), strlen(target_layout_name)); len = MAX(strlen(layouts[ji].name), strlen(target_layout_name));
if (strncmp(layouts[ji].name,target_layout_name,len) == 0) { if (strncmp(layouts[ji].name, target_layout_name, len) == 0) {
selmon->pertag->ltidxs[selmon->pertag->curtag] = &layouts[ji]; selmon->pertag->ltidxs[selmon->pertag->curtag] = &layouts[ji];
break; break;
} }
} }
@ -4535,8 +4543,7 @@ setmfact(const Arg *arg) {
arrange(selmon, false); arrange(selmon, false);
} }
void void setsmfact(const Arg *arg) {
setsmfact(const Arg *arg) {
float f; float f;
if (!arg || !selmon || if (!arg || !selmon ||
@ -5077,8 +5084,7 @@ void overview(Monitor *m, unsigned int gappo, unsigned int gappi) {
grid(m, overviewgappo, overviewgappi); grid(m, overviewgappo, overviewgappi);
} }
void fibonacci(Monitor *mon, int s) void fibonacci(Monitor *mon, int s) {
{
unsigned int i = 0, n = 0, nx, ny, nw, nh; unsigned int i = 0, n = 0, nx, ny, nw, nh;
Client *c; Client *c;
@ -5097,20 +5103,15 @@ void fibonacci(Monitor *mon, int s)
wl_list_for_each(c, &clients, link) if (VISIBLEON(c, mon) && !c->isfloating && wl_list_for_each(c, &clients, link) if (VISIBLEON(c, mon) && !c->isfloating &&
!c->iskilling && !c->isfullscreen && !c->iskilling && !c->isfullscreen &&
!c->ismaxmizescreen && !c->ismaxmizescreen &&
!c->animation.tagouting) !c->animation.tagouting) {
{ if ((i % 2 && nh / 2 > 2 * c->bw) || (!(i % 2) && nw / 2 > 2 * c->bw)) {
if ((i % 2 && nh / 2 > 2 * c->bw) || (!(i % 2) && nw / 2 > 2 * c->bw)) if (i < n - 1) {
{ if (i % 2) {
if (i < n - 1)
{
if (i % 2)
{
if (i == 1) if (i == 1)
nh = nh * c->mon->pertag->smfacts[selmon->pertag->curtag]; nh = nh * c->mon->pertag->smfacts[selmon->pertag->curtag];
else else
nh /= 2; nh /= 2;
} } else
else
nw /= 2; nw /= 2;
if ((i % 4) == 2 && !s) if ((i % 4) == 2 && !s)
nx += nw; nx += nw;
@ -5118,37 +5119,30 @@ void fibonacci(Monitor *mon, int s)
ny += nh; ny += nh;
} }
if ((i % 4) == 0) if ((i % 4) == 0) {
{
if (s) if (s)
ny += nh; ny += nh;
else else
ny -= nh; ny -= nh;
} } else if ((i % 4) == 1)
else if ((i % 4) == 1)
nx += nw; nx += nw;
else if ((i % 4) == 2) else if ((i % 4) == 2)
ny += nh; ny += nh;
else if ((i % 4) == 3) else if ((i % 4) == 3) {
{
if (s) if (s)
nx += nw; nx += nw;
else else
nx -= nw; nx -= nw;
} }
if (i == 0) if (i == 0) {
{
if (n != 1) if (n != 1)
nw = (mon->w.width - gappoh) * nw = (mon->w.width - gappoh) *
mon->pertag->mfacts[mon->pertag->curtag]; mon->pertag->mfacts[mon->pertag->curtag];
ny = mon->w.y + gappov; ny = mon->w.y + gappov;
} } else if (i == 1) {
else if (i == 1)
{
nw = mon->w.width - gappoh - nw; nw = mon->w.width - gappoh - nw;
} } else if (i == 2)
else if (i == 2)
nh = mon->w.height - gappov - nh; nh = mon->w.height - gappov - nh;
i++; i++;
} }
@ -5480,7 +5474,8 @@ void switch_proportion_preset(const Arg *arg) {
if (selmon->sel) { if (selmon->sel) {
for (int i = 0; i < config.scroller_proportion_preset_count; i++) { for (int i = 0; i < config.scroller_proportion_preset_count; i++) {
if (config.scroller_proportion_preset[i] == selmon->sel->scroller_proportion) { if (config.scroller_proportion_preset[i] ==
selmon->sel->scroller_proportion) {
if (i == config.scroller_proportion_preset_count - 1) { if (i == config.scroller_proportion_preset_count - 1) {
target_proportion = config.scroller_proportion_preset[0]; target_proportion = config.scroller_proportion_preset[0];
break; break;
@ -5736,7 +5731,7 @@ void init_fadeout_client(Client *c) {
Client *fadeout_cient = ecalloc(1, sizeof(*fadeout_cient)); Client *fadeout_cient = ecalloc(1, sizeof(*fadeout_cient));
wlr_scene_node_set_enabled(&c->scene->node, true); wlr_scene_node_set_enabled(&c->scene->node, true);
client_set_border_color(c,bordercolor); client_set_border_color(c, bordercolor);
fadeout_cient->scene = fadeout_cient->scene =
wlr_scene_tree_snapshot(&c->scene->node, layers[LyrFadeOut]); wlr_scene_tree_snapshot(&c->scene->node, layers[LyrFadeOut]);
wlr_scene_node_set_enabled(&c->scene->node, false); wlr_scene_node_set_enabled(&c->scene->node, false);
@ -5748,26 +5743,30 @@ void init_fadeout_client(Client *c) {
fadeout_cient->animation.duration = animation_duration_close; fadeout_cient->animation.duration = animation_duration_close;
fadeout_cient->current = fadeout_cient->animainit_geom = fadeout_cient->current = fadeout_cient->animainit_geom =
fadeout_cient->animation.initial = c->animation.current; fadeout_cient->animation.initial = c->animation.current;
fadeout_cient->mon = c->mon; fadeout_cient->mon = c->mon;
fadeout_cient->animation_type = c->animation_type; fadeout_cient->animation_type = c->animation_type;
// 这里snap节点的坐标设置是使用的相对坐标所以不能加上原来坐标 // 这里snap节点的坐标设置是使用的相对坐标所以不能加上原来坐标
// 这跟普通node有区别 // 这跟普通node有区别
fadeout_cient->animation.initial.x = 0; fadeout_cient->animation.initial.x = 0;
fadeout_cient->animation.initial.y = 0; fadeout_cient->animation.initial.y = 0;
if((c->animation_type && strcmp(c->animation_type, "slide") == 0) if ((c->animation_type && strcmp(c->animation_type, "slide") == 0) ||
|| (!c->animation_type && strcmp(animation_type, "slide") == 0)) { (!c->animation_type && strcmp(animation_type, "slide") == 0)) {
fadeout_cient->current.y = c->geom.y+c->geom.height/2 > c->mon->m.y+c->mon->m.height/2 fadeout_cient->current.y =
? c->mon->m.height - (c->animation.current.y - c->mon->m.y) //down out c->geom.y + c->geom.height / 2 > c->mon->m.y + c->mon->m.height / 2
: c->mon->m.y - c->geom.height; //up out ? c->mon->m.height -
fadeout_cient->current.x = 0; // x无偏差垂直划出 (c->animation.current.y - c->mon->m.y) // down out
: c->mon->m.y - c->geom.height; // up out
fadeout_cient->current.x = 0; // x无偏差垂直划出
} else { } else {
fadeout_cient->current.y = (c->geom.height - c->geom.height* zoom_initial_ratio)/2; fadeout_cient->current.y =
fadeout_cient->current.x = (c->geom.width - c->geom.width* zoom_initial_ratio)/2; (c->geom.height - c->geom.height * zoom_initial_ratio) / 2;
fadeout_cient->current.width = c->geom.width* zoom_initial_ratio; fadeout_cient->current.x =
fadeout_cient->current.height = c->geom.height* zoom_initial_ratio; (c->geom.width - c->geom.width * zoom_initial_ratio) / 2;
fadeout_cient->current.width = c->geom.width * zoom_initial_ratio;
fadeout_cient->current.height = c->geom.height * zoom_initial_ratio;
} }
fadeout_cient->animation.passed_frames = 0; fadeout_cient->animation.passed_frames = 0;
@ -5785,7 +5784,7 @@ void unmapnotify(struct wl_listener *listener, void *data) {
if (c->is_fadeout_client) if (c->is_fadeout_client)
return; return;
if(animations) if (animations)
init_fadeout_client(c); init_fadeout_client(c);
if (c == grabc) { if (c == grabc) {

View file

@ -4,7 +4,7 @@
#include <string.h> #include <string.h>
#ifndef SYSCONFDIR #ifndef SYSCONFDIR
#define SYSCONFDIR "/etc" #define SYSCONFDIR "/etc"
#endif #endif
typedef struct { typedef struct {
@ -162,12 +162,14 @@ typedef void (*FuncType)(const Arg *);
Config config; Config config;
// 清理字符串中的不可见字符(包括 \r, \n, 空格等) // 清理字符串中的不可见字符(包括 \r, \n, 空格等)
char* sanitize_string(char *str) { char *sanitize_string(char *str) {
// 去除首部不可见字符 // 去除首部不可见字符
while (*str != '\0' && !isprint((unsigned char)*str)) str++; while (*str != '\0' && !isprint((unsigned char)*str))
str++;
// 去除尾部不可见字符 // 去除尾部不可见字符
char *end = str + strlen(str) - 1; char *end = str + strlen(str) - 1;
while (end > str && !isprint((unsigned char)*end)) end--; while (end > str && !isprint((unsigned char)*end))
end--;
*(end + 1) = '\0'; *(end + 1) = '\0';
return str; return str;
} }
@ -488,15 +490,19 @@ void parse_config_line(Config *config, const char *line) {
config->animation_duration_close = atoi(value); config->animation_duration_close = atoi(value);
} else if (strcmp(key, "animation_curve_move") == 0) { } else if (strcmp(key, "animation_curve_move") == 0) {
if (sscanf(value, "%lf,%lf,%lf,%lf", &config->animation_curve_move[0], if (sscanf(value, "%lf,%lf,%lf,%lf", &config->animation_curve_move[0],
&config->animation_curve_move[1], &config->animation_curve_move[2], &config->animation_curve_move[1],
&config->animation_curve_move[2],
&config->animation_curve_move[3]) != 4) { &config->animation_curve_move[3]) != 4) {
fprintf(stderr, "Error: Invalid animation_curve_move format: %s\n", value); fprintf(stderr, "Error: Invalid animation_curve_move format: %s\n",
value);
} }
} else if (strcmp(key, "animation_curve_open") == 0) { } else if (strcmp(key, "animation_curve_open") == 0) {
if (sscanf(value, "%lf,%lf,%lf,%lf", &config->animation_curve_open[0], if (sscanf(value, "%lf,%lf,%lf,%lf", &config->animation_curve_open[0],
&config->animation_curve_open[1], &config->animation_curve_open[2], &config->animation_curve_open[1],
&config->animation_curve_open[2],
&config->animation_curve_open[3]) != 4) { &config->animation_curve_open[3]) != 4) {
fprintf(stderr, "Error: Invalid animation_curve_open format: %s\n", value); fprintf(stderr, "Error: Invalid animation_curve_open format: %s\n",
value);
} }
} else if (strcmp(key, "animation_curve_tag") == 0) { } else if (strcmp(key, "animation_curve_tag") == 0) {
if (sscanf(value, "%lf,%lf,%lf,%lf", &config->animation_curve_tag[0], if (sscanf(value, "%lf,%lf,%lf,%lf", &config->animation_curve_tag[0],
@ -514,15 +520,17 @@ void parse_config_line(Config *config, const char *line) {
// 1. 统计 value 中有多少个逗号,确定需要解析的浮点数个数 // 1. 统计 value 中有多少个逗号,确定需要解析的浮点数个数
int count = 0; // 初始化为 0 int count = 0; // 初始化为 0
for (const char *p = value; *p; p++) { for (const char *p = value; *p; p++) {
if (*p == ',') count++; if (*p == ',')
count++;
} }
int float_count = count + 1; // 浮点数的数量是逗号数量加 1 int float_count = count + 1; // 浮点数的数量是逗号数量加 1
// 2. 动态分配内存,存储浮点数 // 2. 动态分配内存,存储浮点数
config->scroller_proportion_preset = (float *)malloc(float_count * sizeof(float)); config->scroller_proportion_preset =
(float *)malloc(float_count * sizeof(float));
if (!config->scroller_proportion_preset) { if (!config->scroller_proportion_preset) {
fprintf(stderr, "Error: Memory allocation failed\n"); fprintf(stderr, "Error: Memory allocation failed\n");
return; return;
} }
// 3. 解析 value 中的浮点数 // 3. 解析 value 中的浮点数
@ -531,89 +539,95 @@ void parse_config_line(Config *config, const char *line) {
int i = 0; int i = 0;
while (token != NULL && i < float_count) { while (token != NULL && i < float_count) {
if (sscanf(token, "%f", &config->scroller_proportion_preset[i]) != 1) { if (sscanf(token, "%f", &config->scroller_proportion_preset[i]) != 1) {
fprintf(stderr, "Error: Invalid float value in scroller_proportion_preset: %s\n", token); fprintf(
free(value_copy); stderr,
free(config->scroller_proportion_preset); // 释放已分配的内存 "Error: Invalid float value in scroller_proportion_preset: %s\n",
config->scroller_proportion_preset = NULL; // 防止野指针 token);
return; free(value_copy);
} free(config->scroller_proportion_preset); // 释放已分配的内存
token = strtok(NULL, ","); config->scroller_proportion_preset = NULL; // 防止野指针
i++; return;
}
token = strtok(NULL, ",");
i++;
} }
// 4. 检查解析的浮点数数量是否匹配 // 4. 检查解析的浮点数数量是否匹配
if (i != float_count) { if (i != float_count) {
fprintf(stderr, "Error: Invalid scroller_proportion_preset format: %s\n", value); fprintf(stderr, "Error: Invalid scroller_proportion_preset format: %s\n",
free(value_copy); value);
free(config->scroller_proportion_preset); // 释放已分配的内存 free(value_copy);
config->scroller_proportion_preset = NULL; // 防止野指针 free(config->scroller_proportion_preset); // 释放已分配的内存
config->scroller_proportion_preset_count = 0; config->scroller_proportion_preset = NULL; // 防止野指针
return; config->scroller_proportion_preset_count = 0;
return;
} }
config->scroller_proportion_preset_count = float_count; config->scroller_proportion_preset_count = float_count;
// 5. 释放临时复制的字符串 // 5. 释放临时复制的字符串
free(value_copy); free(value_copy);
} else if (strcmp(key, "circle_layout") == 0) { } else if (strcmp(key, "circle_layout") == 0) {
// 1. 统计 value 中有多少个逗号,确定需要解析的字符串个数 // 1. 统计 value 中有多少个逗号,确定需要解析的字符串个数
int count = 0; // 初始化为 0 int count = 0; // 初始化为 0
for (const char *p = value; *p; p++) { for (const char *p = value; *p; p++) {
if (*p == ',') count++; if (*p == ',')
} count++;
int string_count = count + 1; // 字符串的数量是逗号数量加 1 }
int string_count = count + 1; // 字符串的数量是逗号数量加 1
// 2. 动态分配内存,存储字符串指针 // 2. 动态分配内存,存储字符串指针
config->circle_layout = (char **)malloc(string_count * sizeof(char *)); config->circle_layout = (char **)malloc(string_count * sizeof(char *));
memset(config->circle_layout, 0, string_count * sizeof(char *)); memset(config->circle_layout, 0, string_count * sizeof(char *));
if (!config->circle_layout) { if (!config->circle_layout) {
fprintf(stderr, "Error: Memory allocation failed\n"); fprintf(stderr, "Error: Memory allocation failed\n");
return; return;
} }
// 3. 解析 value 中的字符串 // 3. 解析 value 中的字符串
char *value_copy = strdup(value); // 复制 value因为 strtok 会修改原字符串 char *value_copy = strdup(value); // 复制 value因为 strtok 会修改原字符串
char *token = strtok(value_copy, ","); char *token = strtok(value_copy, ",");
int i = 0; int i = 0;
char *cleaned_token; char *cleaned_token;
while (token != NULL && i < string_count) { while (token != NULL && i < string_count) {
// 为每个字符串分配内存并复制内容 // 为每个字符串分配内存并复制内容
cleaned_token = sanitize_string(token); cleaned_token = sanitize_string(token);
config->circle_layout[i] = strdup(cleaned_token); config->circle_layout[i] = strdup(cleaned_token);
if (!config->circle_layout[i]) { if (!config->circle_layout[i]) {
fprintf(stderr, "Error: Memory allocation failed for string: %s\n", token); fprintf(stderr, "Error: Memory allocation failed for string: %s\n",
// 释放之前分配的内存 token);
for (int j = 0; j < i; j++) { // 释放之前分配的内存
free(config->circle_layout[j]); for (int j = 0; j < i; j++) {
} free(config->circle_layout[j]);
free(config->circle_layout); }
free(value_copy); free(config->circle_layout);
config->circle_layout = NULL; // 防止野指针 free(value_copy);
config->circle_layout_count = 0; config->circle_layout = NULL; // 防止野指针
return; config->circle_layout_count = 0;
return;
} }
token = strtok(NULL, ","); token = strtok(NULL, ",");
i++; i++;
} }
// 4. 检查解析的字符串数量是否匹配 // 4. 检查解析的字符串数量是否匹配
if (i != string_count) { if (i != string_count) {
fprintf(stderr, "Error: Invalid circle_layout format: %s\n", value); fprintf(stderr, "Error: Invalid circle_layout format: %s\n", value);
// 释放之前分配的内存 // 释放之前分配的内存
for (int j = 0; j < i; j++) { for (int j = 0; j < i; j++) {
free(config->circle_layout[j]); free(config->circle_layout[j]);
} }
free(config->circle_layout); free(config->circle_layout);
free(value_copy); free(value_copy);
config->circle_layout = NULL; // 防止野指针 config->circle_layout = NULL; // 防止野指针
config->circle_layout_count = 0; config->circle_layout_count = 0;
return; return;
} }
config->circle_layout_count = string_count; config->circle_layout_count = string_count;
// 5. 释放临时复制的字符串 // 5. 释放临时复制的字符串
free(value_copy); free(value_copy);
} else if (strcmp(key, "new_is_master") == 0) { } else if (strcmp(key, "new_is_master") == 0) {
config->new_is_master = atoi(value); config->new_is_master = atoi(value);
} else if (strcmp(key, "default_mfact") == 0) { } else if (strcmp(key, "default_mfact") == 0) {
config->default_mfact = atof(value); config->default_mfact = atof(value);
@ -969,16 +983,16 @@ void parse_config_file(Config *config, const char *file_path) {
void free_circle_layout(Config *config) { void free_circle_layout(Config *config) {
if (config->circle_layout) { if (config->circle_layout) {
// 释放每个字符串 // 释放每个字符串
for (int i = 0; i < config->circle_layout_count; i++) { for (int i = 0; i < config->circle_layout_count; i++) {
if (config->circle_layout[i]) { if (config->circle_layout[i]) {
free(config->circle_layout[i]); // 释放单个字符串 free(config->circle_layout[i]); // 释放单个字符串
config->circle_layout[i] = NULL; // 防止野指针 config->circle_layout[i] = NULL; // 防止野指针
}
} }
// 释放 circle_layout 数组本身 }
free(config->circle_layout); // 释放 circle_layout 数组本身
config->circle_layout = NULL; // 防止野指针 free(config->circle_layout);
config->circle_layout = NULL; // 防止野指针
} }
config->circle_layout_count = 0; // 重置计数 config->circle_layout_count = 0; // 重置计数
} }
@ -1050,9 +1064,12 @@ void override_config(void) {
animation_duration_close = config.animation_duration_close; animation_duration_close = config.animation_duration_close;
// 复制数组类型的变量 // 复制数组类型的变量
memcpy(animation_curve_move, config.animation_curve_move, sizeof(animation_curve_move)); memcpy(animation_curve_move, config.animation_curve_move,
memcpy(animation_curve_open, config.animation_curve_open, sizeof(animation_curve_open)); sizeof(animation_curve_move));
memcpy(animation_curve_tag, config.animation_curve_tag, sizeof(animation_curve_tag)); memcpy(animation_curve_open, config.animation_curve_open,
sizeof(animation_curve_open));
memcpy(animation_curve_tag, config.animation_curve_tag,
sizeof(animation_curve_tag));
scroller_structs = config.scroller_structs; scroller_structs = config.scroller_structs;
scroller_default_proportion = config.scroller_default_proportion; scroller_default_proportion = config.scroller_default_proportion;
@ -1157,9 +1174,12 @@ void set_value_default() {
config.left_handed = 0; config.left_handed = 0;
config.middle_button_emulation = 0; config.middle_button_emulation = 0;
memcpy(config.animation_curve_move, animation_curve_move, sizeof(animation_curve_move)); memcpy(config.animation_curve_move, animation_curve_move,
memcpy(config.animation_curve_open, animation_curve_open, sizeof(animation_curve_open)); sizeof(animation_curve_move));
memcpy(config.animation_curve_tag, animation_curve_tag, sizeof(animation_curve_tag)); memcpy(config.animation_curve_open, animation_curve_open,
sizeof(animation_curve_open));
memcpy(config.animation_curve_tag, animation_curve_tag,
sizeof(animation_curve_tag));
} }
void parse_config(void) { void parse_config(void) {
@ -1196,7 +1216,7 @@ void parse_config(void) {
// 检查文件是否存在 // 检查文件是否存在
if (access(filename, F_OK) != 0) { if (access(filename, F_OK) != 0) {
// 如果文件不存在,则使用 /etc/maomao/config.conf // 如果文件不存在,则使用 /etc/maomao/config.conf
snprintf(filename, sizeof(filename), "%s/maomao/config.conf",SYSCONFDIR); snprintf(filename, sizeof(filename), "%s/maomao/config.conf", SYSCONFDIR);
} }
} else { } else {
// 使用 MAOMAOCONFIG 环境变量作为配置文件夹路径 // 使用 MAOMAOCONFIG 环境变量作为配置文件夹路径

View file

@ -11,14 +11,13 @@ char animation_fade_in = 1; // Enable animation fade in
float zoom_initial_ratio = 0.5; // 动画起始窗口比例 float zoom_initial_ratio = 0.5; // 动画起始窗口比例
float fadein_begin_opacity = 0.5; // Begin opac window ratio for animations float fadein_begin_opacity = 0.5; // Begin opac window ratio for animations
float fadeout_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_move = 500; // Animation move speed
uint32_t animation_duration_open = 400; // Animation open speed uint32_t animation_duration_open = 400; // Animation open speed
uint32_t animation_duration_tag = 300; // Animation tag speed uint32_t animation_duration_tag = 300; // Animation tag speed
uint32_t animation_duration_close = 300; // Animation close 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_move[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线
double animation_curve_open[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 double animation_curve_open[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线
double animation_curve_tag[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线 double animation_curve_tag[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线
/* appearance */ /* appearance */
unsigned int axis_bind_apply_timeout = 100; // 滚轮绑定动作的触发的时间间隔 unsigned int axis_bind_apply_timeout = 100; // 滚轮绑定动作的触发的时间间隔