opt: format code

This commit is contained in:
DreamMaoMao 2025-02-24 19:31:16 +08:00
parent fda94aefa7
commit 9b4d8d88b7
3 changed files with 264 additions and 257 deletions

View file

@ -721,7 +721,6 @@ double find_animation_curve_at(double t) {
return baked_points[up].y;
}
void fadeout_client_animation_next_tick(Client *c) {
if (!c)
return;
@ -762,7 +761,6 @@ void fadeout_client_animation_next_tick(Client *c) {
}
}
void client_animation_next_tick(Client *c) {
double animation_passed =
(double)c->animation.passed_frames / c->animation.total_frames;
@ -963,7 +961,6 @@ bool client_draw_frame(Client *c) {
return true;
}
bool client_draw_fadeout_frame(Client *c) {
if (!c)
return false;
@ -972,7 +969,6 @@ bool client_draw_fadeout_frame(Client *c) {
return true;
}
void // 0.5
applybounds(Client *c, struct wlr_box *bbox) {
/* set minimum possible */
@ -1609,12 +1605,14 @@ void autostartexec(void) {
size_t i = 0;
const char *maomaoconfig = getenv("MAOMAOCONFIG");
static const char *autostart[4]; // 声明一个全局数组,大小为 5包括 NULL 结 尾)
static const char
*autostart[4]; // 声明一个全局数组,大小为 5包括 NULL 结 尾)
char autostart_path[1024]; // 用于存储脚本的完整路径
if (maomaoconfig && maomaoconfig[0] != '\0') {
// 如果 MAOMAOCONFIG 存在且不为空,使用它作为配置文件夹
snprintf(autostart_path, sizeof(autostart_path), "%s/autostart.sh", maomaoconfig);
snprintf(autostart_path, sizeof(autostart_path), "%s/autostart.sh",
maomaoconfig);
} else {
// 否则使用 HOME 环境变量下的默认路径
const char *homedir = getenv("HOME");
@ -1623,7 +1621,8 @@ void autostartexec(void) {
fprintf(stderr, "Error: HOME environment variable not set.\n");
return;
}
snprintf(autostart_path, sizeof(autostart_path), "%s/.config/maomao/autostart.sh", homedir);
snprintf(autostart_path, sizeof(autostart_path),
"%s/.config/maomao/autostart.sh", homedir);
}
autostart[0] = "/bin/sh"; // 使用 /bin/sh 执行脚本
@ -1714,7 +1713,6 @@ buttonpress(struct wl_listener *listener, void *data) {
struct wlr_surface *old_pointer_focus_surface =
seat->pointer_state.focused_surface;
wlr_idle_notifier_v1_notify_activity(idle_notifier, seat);
switch (event->state) {
@ -1986,9 +1984,8 @@ void commitnotify(struct wl_listener *listener, void *data) {
// if don't do this, some client may resize uncompleted
resize(c, c->geom, (c->isfloating && !c->isfullscreen));
// if (c->configure_serial && c->configure_serial <= c->surface.xdg->current.configure_serial)
// c->configure_serial = 0;
// if (c->configure_serial && c->configure_serial <=
// c->surface.xdg->current.configure_serial) c->configure_serial = 0;
}
void // 0.5
@ -2781,7 +2778,6 @@ void focusclient(Client *c, int lift) {
if (c && client_surface(c) == old_keyboard_focus_surface)
return;
if (c && c->mon && c->mon != selmon) {
selmon = c->mon;
}
@ -3153,8 +3149,6 @@ keypressmod(struct wl_listener *listener, void *data) {
wlr_seat_keyboard_notify_modifiers(seat, &kb->wlr_keyboard->modifiers);
}
static bool scene_node_snapshot(struct wlr_scene_node *node, int lx, int ly,
struct wlr_scene_tree *snapshot_tree) {
if (!node->enabled && node->type != WLR_SCENE_NODE_TREE) {
@ -3188,8 +3182,7 @@ static bool scene_node_snapshot(struct wlr_scene_node *node, int lx, int ly,
break;
case WLR_SCENE_NODE_BUFFER:;
struct wlr_scene_buffer *scene_buffer =
wlr_scene_buffer_from_node(node);
struct wlr_scene_buffer *scene_buffer = wlr_scene_buffer_from_node(node);
struct wlr_scene_buffer *snapshot_buffer =
wlr_scene_buffer_create(snapshot_tree, NULL);
@ -3203,10 +3196,8 @@ static bool scene_node_snapshot(struct wlr_scene_node *node, int lx, int ly,
scene_buffer->dst_height);
wlr_scene_buffer_set_opaque_region(snapshot_buffer,
&scene_buffer->opaque_region);
wlr_scene_buffer_set_source_box(snapshot_buffer,
&scene_buffer->src_box);
wlr_scene_buffer_set_transform(snapshot_buffer,
scene_buffer->transform);
wlr_scene_buffer_set_source_box(snapshot_buffer, &scene_buffer->src_box);
wlr_scene_buffer_set_transform(snapshot_buffer, scene_buffer->transform);
wlr_scene_buffer_set_filter_mode(snapshot_buffer,
scene_buffer->filter_mode);
@ -3226,7 +3217,6 @@ static bool scene_node_snapshot(struct wlr_scene_node *node, int lx, int ly,
wlr_scene_buffer_set_buffer(snapshot_buffer, scene_buffer->buffer);
}
break;
}
if (snapshot_node != NULL) {
@ -3263,7 +3253,8 @@ void pending_kill_client(Client *c) {
wlr_scene_node_destroy(&c->snapshot_scene->node);
}
if (c->mon) {
c->snapshot_scene = wlr_scene_tree_snapshot(&c->scene->node, layers[LyrFadeOut]);
c->snapshot_scene =
wlr_scene_tree_snapshot(&c->scene->node, layers[LyrFadeOut]);
wlr_scene_node_set_enabled(&c->snapshot_scene->node, false);
}
// c->iskilling = 1; //不可以提前标记已经杀掉,因为有些客户端可能拒绝
@ -3323,8 +3314,8 @@ mapnotify(struct wl_listener *listener, void *data) {
c->scene->node.data = c->scene_surface->node.data = c;
client_get_geometry(c, &c->geom);
// c->timer_tick = wl_event_loop_add_timer(wl_display_get_event_loop(dpy), timer_tick_action, c);
// wl_event_source_timer_update(c->timer_tick, 0);
// c->timer_tick = wl_event_loop_add_timer(wl_display_get_event_loop(dpy),
// timer_tick_action, c); wl_event_source_timer_update(c->timer_tick, 0);
/* Handle unmanaged clients first so we can return prior create borders */
if (client_is_unmanaged(c)) {
@ -3836,21 +3827,27 @@ void scene_buffer_apply_opacity(struct wlr_scene_buffer *buffer, int sx, int sy,
wlr_scene_buffer_set_opacity(buffer, *(double *)data);
}
void scene_buffer_apply_size(struct wlr_scene_buffer *buffer, int sx, int sy, void *data) {
void scene_buffer_apply_size(struct wlr_scene_buffer *buffer, int sx, int sy,
void *data) {
animationScale *scale_data = (animationScale *)data;
struct wlr_scene_surface *surface = wlr_scene_surface_try_from_buffer(buffer);
if (wlr_subsurface_try_from_wlr_surface(surface->surface) != NULL) {
wlr_scene_buffer_set_dest_size(buffer, buffer->dst_width * scale_data->width_scale, buffer->dst_height * scale_data->height_scale);
wlr_scene_buffer_set_dest_size(
buffer, buffer->dst_width * scale_data->width_scale,
buffer->dst_height * scale_data->height_scale);
} else {
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);
}
}
void buffer_set_size(Client *c, animationScale data) {
if (c->animation.current.width <= c->geom.width && c->animation.current.height <= c->geom.height) {
if (c->animation.current.width <= c->geom.width &&
c->animation.current.height <= c->geom.height) {
return;
}
if(c->iskilling|| c->animation.tagouting || c->animation.tagining || c->animation.tagouted) {
if (c->iskilling || c->animation.tagouting || c->animation.tagining ||
c->animation.tagouted) {
return;
}
@ -4164,7 +4161,8 @@ void resize(Client *c, struct wlr_box geo, int interact) {
if (c == grabc) {
c->animation.running = false;
c->need_output_flush = false;
c->animainit_geom = c->current = c->pending = c->animation.current = c->geom;
c->animainit_geom = c->current = c->pending = c->animation.current =
c->geom;
wlr_scene_node_set_position(&c->scene->node, c->geom.x, c->geom.y);
apply_border(c, c->geom, 0);
wlr_scene_node_set_position(&c->scene_surface->node, c->bw, c->bw);
@ -4173,7 +4171,6 @@ void resize(Client *c, struct wlr_box geo, int interact) {
return;
}
// 如果不是工作区切换时划出去的窗口,就让动画的结束位置,就是上面的真实位置和大小
// c->pending 决定动画的终点一般在其他调用resize的函数的附近设置了
if (!c->animation.tagouting && !c->iskilling) {
@ -4571,7 +4568,8 @@ void signalhandler(int signalnumber) {
return;
}
// 构建日志文件路径
snprintf(filename, sizeof(filename), "%s/.config/maomao/crash.log", homedir);
snprintf(filename, sizeof(filename), "%s/.config/maomao/crash.log",
homedir);
} else {
// 使用 MAOMAOCONFIG 环境变量作为配置文件夹路径
snprintf(filename, sizeof(filename), "%s/crash.log", maomaoconfig);
@ -5607,7 +5605,8 @@ void init_fadeout_client(Client *c) {
Client *fadeout_cient = ecalloc(1, sizeof(*fadeout_cient));
wlr_scene_node_set_enabled(&c->scene->node, true);
fadeout_cient->snapshot_scene = wlr_scene_tree_snapshot(&c->scene->node, layers[LyrFadeOut]);
fadeout_cient->snapshot_scene =
wlr_scene_tree_snapshot(&c->scene->node, layers[LyrFadeOut]);
wlr_scene_node_set_enabled(&c->scene->node, false);
if (!fadeout_cient->snapshot_scene) {
@ -5616,11 +5615,13 @@ void init_fadeout_client(Client *c) {
}
fadeout_cient->animation.duration = animation_duration_close;
fadeout_cient->current = fadeout_cient->animainit_geom = c->animation.initial = c->animation.current;
fadeout_cient->current = fadeout_cient->animainit_geom =
c->animation.initial = c->animation.current;
fadeout_cient->mon = c->mon;
// 这里snap节点的坐标设置是使用的相对坐标所以不能加上原来坐标
// 这根普通node有区别
fadeout_cient->current.y = c->mon->m.height - (c->animation.current.y - c->mon->m.y);
fadeout_cient->current.y =
c->mon->m.height - (c->animation.current.y - c->mon->m.y);
fadeout_cient->current.x = 0; // x无偏差垂直划出
fadeout_cient->animation.passed_frames = 0;
fadeout_cient->animation.total_frames =
@ -5681,7 +5682,6 @@ void unmapnotify(struct wl_listener *listener, void *data) {
wlr_scene_node_destroy(&c->scene->node);
printstatus();
motionnotify(0, NULL, 0, 0, 0, 0);
}
void // 0.5

View file

@ -35,13 +35,17 @@ typedef struct {
} KeyBinding;
// 定义一个宏来简化默认按键绑定的添加
#define CHVT(n) { WLR_MODIFIER_CTRL|WLR_MODIFIER_ALT, XKB_KEY_XF86Switch_VT_##n, chvt, {.ui = (n)} }
#define CHVT(n) \
{ \
WLR_MODIFIER_CTRL | WLR_MODIFIER_ALT, XKB_KEY_XF86Switch_VT_##n, chvt, { \
.ui = (n) \
} \
}
// 默认的按键绑定数组
KeyBinding default_key_bindings[] = {
CHVT(1), CHVT(2), CHVT(3), CHVT(4), CHVT(5), CHVT(6),
CHVT(7), CHVT(8), CHVT(9), CHVT(10), CHVT(11), CHVT(12)
};
KeyBinding default_key_bindings[] = {CHVT(1), CHVT(2), CHVT(3), CHVT(4),
CHVT(5), CHVT(6), CHVT(7), CHVT(8),
CHVT(9), CHVT(10), CHVT(11), CHVT(12)};
typedef struct {
unsigned int mod;
@ -105,7 +109,6 @@ typedef struct {
int left_handed;
int middle_button_emulation;
int smartgaps;
unsigned int gappih;
unsigned int gappiv;
@ -727,18 +730,22 @@ void parse_config_line(Config *config, const char *line) {
}
// 计算默认按键绑定的数量
size_t default_key_bindings_count = sizeof(default_key_bindings) / sizeof(KeyBinding);
size_t default_key_bindings_count =
sizeof(default_key_bindings) / sizeof(KeyBinding);
// 重新分配内存以容纳新的默认按键绑定
config->key_bindings = realloc(config->key_bindings,
(config->key_bindings_count + default_key_bindings_count) * sizeof(KeyBinding));
config->key_bindings =
realloc(config->key_bindings,
(config->key_bindings_count + default_key_bindings_count) *
sizeof(KeyBinding));
if (!config->key_bindings) {
return;
}
// 将默认按键绑定复制到配置的按键绑定数组中
for (size_t i = 0; i < default_key_bindings_count; i++) {
config->key_bindings[config->key_bindings_count + i] = default_key_bindings[i];
config->key_bindings[config->key_bindings_count + i] =
default_key_bindings[i];
}
// 更新按键绑定的总数
@ -965,7 +972,6 @@ config.bypass_surface_visibility =
0; /* 1 means idle inhibitors will disable idle tracking even if it's
surface isn't visible */
config.overviewgappi = 5; /* overview时 窗口与边缘 缝隙大小 */
config.overviewgappo = 30; /* overview时 窗口与窗口 缝隙大小 */
@ -1012,7 +1018,8 @@ void parse_config(void) {
return;
}
// 构建日志文件路径
snprintf(filename, sizeof(filename), "%s/.config/maomao/config.conf", homedir);
snprintf(filename, sizeof(filename), "%s/.config/maomao/config.conf",
homedir);
// 检查文件是否存在
if (access(filename, F_OK) != 0) {