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);
}
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,
uint32_t height) {
#ifdef XWAYLAND

133
maomao.c
View file

@ -12,7 +12,6 @@
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <wlr/types/wlr_fractional_scale_v1.h>
#include <wayland-server-core.h>
#include <wlr/backend.h>
#include <wlr/backend/libinput.h>
@ -559,8 +558,8 @@ void incovgaps(const Arg *arg);
void incigaps(const Arg *arg);
void defaultgaps(const Arg *arg);
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 *data);
void snap_scene_buffer_apply_size(struct wlr_scene_buffer *buffer, int sx,
int sy, void *data);
// int timer_tick_action(void *data);
#include "dispatch.h"
@ -712,19 +711,18 @@ struct vec2 calculate_animation_curve_at(double t, int type) {
return point;
}
void init_baked_points(void) {
baked_points_move = calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_move));
baked_points_open = calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_open));
baked_points_tag = calloc(BAKED_POINTS_COUNT, sizeof(*baked_points_tag));
for (size_t i = 0; i < BAKED_POINTS_COUNT; i++) {
baked_points_move[i] =
calculate_animation_curve_at((double)i / (BAKED_POINTS_COUNT - 1), MOVE);
baked_points_move[i] = calculate_animation_curve_at(
(double)i / (BAKED_POINTS_COUNT - 1), MOVE);
}
for (size_t i = 0; i < BAKED_POINTS_COUNT; i++) {
baked_points_open[i] =
calculate_animation_curve_at((double)i / (BAKED_POINTS_COUNT - 1), OPEN);
baked_points_open[i] = calculate_animation_curve_at(
(double)i / (BAKED_POINTS_COUNT - 1), OPEN);
}
for (size_t i = 0; i < BAKED_POINTS_COUNT; i++) {
baked_points_tag[i] =
@ -754,11 +752,11 @@ double find_animation_curve_at(double t,int type) {
middle = (up + down) / 2;
}
return baked_points[up].y;
}
// 有 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) {
struct wlr_scene_rect *rect = wlr_scene_rect_from_node(node);
// Assuming the rect has a color field and we can modify it
@ -770,14 +768,20 @@ void apply_opacity_to_rect_nodes(Client *c,struct wlr_scene_node *node, double a
// TODO: 判断当前窗口是否在屏幕外,如果在屏幕外就不要绘制
// 划出的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
// } 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) {
// 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
// } 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
// } 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) {
// 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
// } 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
@ -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) {
if (!c)
return;
@ -822,13 +825,13 @@ void fadeout_client_animation_next_tick(Client *c) {
double opacity = MAX(fadeout_begin_opacity - animation_passed, 0);
wlr_scene_node_for_each_buffer(&c->scene->node,
scene_buffer_apply_opacity, &opacity);
wlr_scene_node_for_each_buffer(&c->scene->node, scene_buffer_apply_opacity,
&opacity);
apply_opacity_to_rect_nodes(c, &c->scene->node, animation_passed);
if((c->animation_type && strcmp(c->animation_type, "zoom") == 0)
|| (!c->animation_type && strcmp(animation_type, "zoom") == 0)) {
if ((c->animation_type && strcmp(c->animation_type, "zoom") == 0) ||
(!c->animation_type && strcmp(animation_type, "zoom") == 0)) {
scale_data.width = width;
scale_data.height = height;
@ -925,7 +928,8 @@ void client_actual_size(Client *c, uint32_t *width, uint32_t *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)
return;
@ -937,8 +941,7 @@ 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_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[1]->node, 0,
clip_box.height - c->bw);
wlr_scene_node_set_position(&c->border[1]->node, 0, clip_box.height - c->bw);
wlr_scene_node_set_position(&c->border[3]->node, clip_box.width - c->bw,
c->bw);
@ -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[1]->node, offsetx,
clip_box.height - c->bw + offsety);
wlr_scene_node_set_position(&c->border[3]->node, clip_box.width - c->bw + offsetx,
c->bw + offsety);
wlr_scene_node_set_position(
&c->border[3]->node, clip_box.width - c->bw + offsetx, c->bw + offsety);
}
void client_apply_clip(Client *c) {
@ -1023,7 +1026,6 @@ void client_apply_clip(Client *c) {
(c->animation.current.y + c->animation.current.height -
c->mon->m.y - c->mon->m.height);
}
}
animationScale scale_data;
@ -1050,7 +1052,8 @@ bool client_draw_frame(Client *c) {
client_apply_clip(c);
} else {
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);
c->need_output_flush = 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 *data) {
void snap_scene_buffer_apply_size(struct wlr_scene_buffer *buffer, int sx,
int sy, void *data) {
animationScale *scale_data = (animationScale *)data;
wlr_scene_buffer_set_dest_size(buffer, scale_data->width, scale_data->height);
}
@ -4481,10 +4484,15 @@ void switch_layout(const Arg *arg) {
if (config.circle_layout_count != 0) {
for (jk = 0; jk < config.circle_layout_count; jk++) {
len = MAX(strlen(config.circle_layout[jk]), strlen(selmon->pertag->ltidxs[selmon->pertag->curtag]->name));
len = MAX(strlen(config.circle_layout[jk]),
strlen(selmon->pertag->ltidxs[selmon->pertag->curtag]->name));
if(strncmp(config.circle_layout[jk], 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];
if (strncmp(config.circle_layout[jk],
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;
}
}
@ -4535,8 +4543,7 @@ setmfact(const Arg *arg) {
arrange(selmon, false);
}
void
setsmfact(const Arg *arg) {
void setsmfact(const Arg *arg) {
float f;
if (!arg || !selmon ||
@ -5077,8 +5084,7 @@ void overview(Monitor *m, unsigned int gappo, unsigned int gappi) {
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;
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 &&
!c->iskilling && !c->isfullscreen &&
!c->ismaxmizescreen &&
!c->animation.tagouting)
{
if ((i % 2 && nh / 2 > 2 * c->bw) || (!(i % 2) && nw / 2 > 2 * c->bw))
{
if (i < n - 1)
{
if (i % 2)
{
!c->animation.tagouting) {
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 * c->mon->pertag->smfacts[selmon->pertag->curtag];
else
nh /= 2;
}
else
} else
nw /= 2;
if ((i % 4) == 2 && !s)
nx += nw;
@ -5118,37 +5119,30 @@ void fibonacci(Monitor *mon, int s)
ny += nh;
}
if ((i % 4) == 0)
{
if ((i % 4) == 0) {
if (s)
ny += nh;
else
ny -= nh;
}
else if ((i % 4) == 1)
} else if ((i % 4) == 1)
nx += nw;
else if ((i % 4) == 2)
ny += nh;
else if ((i % 4) == 3)
{
else if ((i % 4) == 3) {
if (s)
nx += nw;
else
nx -= nw;
}
if (i == 0)
{
if (i == 0) {
if (n != 1)
nw = (mon->w.width - gappoh) *
mon->pertag->mfacts[mon->pertag->curtag];
ny = mon->w.y + gappov;
}
else if (i == 1)
{
} else if (i == 1) {
nw = mon->w.width - gappoh - nw;
}
else if (i == 2)
} else if (i == 2)
nh = mon->w.height - gappov - nh;
i++;
}
@ -5480,7 +5474,8 @@ void switch_proportion_preset(const Arg *arg) {
if (selmon->sel) {
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) {
target_proportion = config.scroller_proportion_preset[0];
break;
@ -5757,15 +5752,19 @@ void init_fadeout_client(Client *c) {
fadeout_cient->animation.initial.x = 0;
fadeout_cient->animation.initial.y = 0;
if((c->animation_type && strcmp(c->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
? c->mon->m.height - (c->animation.current.y - c->mon->m.y) //down out
if ((c->animation_type && strcmp(c->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
? c->mon->m.height -
(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 {
fadeout_cient->current.y = (c->geom.height - c->geom.height* zoom_initial_ratio)/2;
fadeout_cient->current.x = (c->geom.width - c->geom.width* zoom_initial_ratio)/2;
fadeout_cient->current.y =
(c->geom.height - c->geom.height * zoom_initial_ratio) / 2;
fadeout_cient->current.x =
(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;
}

View file

@ -164,10 +164,12 @@ Config config;
// 清理字符串中的不可见字符(包括 \r, \n, 空格等)
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;
while (end > str && !isprint((unsigned char)*end)) end--;
while (end > str && !isprint((unsigned char)*end))
end--;
*(end + 1) = '\0';
return str;
}
@ -488,15 +490,19 @@ void parse_config_line(Config *config, const char *line) {
config->animation_duration_close = atoi(value);
} else if (strcmp(key, "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) {
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) {
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) {
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) {
if (sscanf(value, "%lf,%lf,%lf,%lf", &config->animation_curve_tag[0],
@ -514,12 +520,14 @@ void parse_config_line(Config *config, const char *line) {
// 1. 统计 value 中有多少个逗号,确定需要解析的浮点数个数
int count = 0; // 初始化为 0
for (const char *p = value; *p; p++) {
if (*p == ',') count++;
if (*p == ',')
count++;
}
int float_count = count + 1; // 浮点数的数量是逗号数量加 1
// 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) {
fprintf(stderr, "Error: Memory allocation failed\n");
return;
@ -532,7 +540,10 @@ void parse_config_line(Config *config, const char *line) {
while (token != NULL && i < float_count) {
if (sscanf(token, "%f", &config->scroller_proportion_preset[i]) != 1) {
fprintf(stderr, "Error: Invalid float value in scroller_proportion_preset: %s\n", token);
fprintf(
stderr,
"Error: Invalid float value in scroller_proportion_preset: %s\n",
token);
free(value_copy);
free(config->scroller_proportion_preset); // 释放已分配的内存
config->scroller_proportion_preset = NULL; // 防止野指针
@ -544,7 +555,8 @@ void parse_config_line(Config *config, const char *line) {
// 4. 检查解析的浮点数数量是否匹配
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",
value);
free(value_copy);
free(config->scroller_proportion_preset); // 释放已分配的内存
config->scroller_proportion_preset = NULL; // 防止野指针
@ -559,7 +571,8 @@ void parse_config_line(Config *config, const char *line) {
// 1. 统计 value 中有多少个逗号,确定需要解析的字符串个数
int count = 0; // 初始化为 0
for (const char *p = value; *p; p++) {
if (*p == ',') count++;
if (*p == ',')
count++;
}
int string_count = count + 1; // 字符串的数量是逗号数量加 1
@ -581,7 +594,8 @@ void parse_config_line(Config *config, const char *line) {
cleaned_token = sanitize_string(token);
config->circle_layout[i] = strdup(cleaned_token);
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]);
@ -1050,9 +1064,12 @@ void override_config(void) {
animation_duration_close = config.animation_duration_close;
// 复制数组类型的变量
memcpy(animation_curve_move, config.animation_curve_move, sizeof(animation_curve_move));
memcpy(animation_curve_open, config.animation_curve_open, sizeof(animation_curve_open));
memcpy(animation_curve_tag, config.animation_curve_tag, sizeof(animation_curve_tag));
memcpy(animation_curve_move, config.animation_curve_move,
sizeof(animation_curve_move));
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_default_proportion = config.scroller_default_proportion;
@ -1157,9 +1174,12 @@ void set_value_default() {
config.left_handed = 0;
config.middle_button_emulation = 0;
memcpy(config.animation_curve_move, animation_curve_move, sizeof(animation_curve_move));
memcpy(config.animation_curve_open, animation_curve_open, sizeof(animation_curve_open));
memcpy(config.animation_curve_tag, animation_curve_tag, sizeof(animation_curve_tag));
memcpy(config.animation_curve_move, animation_curve_move,
sizeof(animation_curve_move));
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) {

View file

@ -19,7 +19,6 @@ 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_tag[4] = {0.46, 1.0, 0.29, 0.99}; // 动画曲线
/* appearance */
unsigned int axis_bind_apply_timeout = 100; // 滚轮绑定动作的触发的时间间隔
unsigned int focus_on_activate = 1; // 收到窗口激活请求是否自动跳转聚焦