From 2d5388a4d7011a2a96b9fc11e4c6f3d8ca4cf378 Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Tue, 13 May 2025 18:20:41 +0800 Subject: [PATCH] format code --- src/client/client.h | 16 +-- src/config/parse_config.h | 207 +++++++++++++++++++------------------ src/config/preset_config.h | 3 +- src/layout/layout.h | 151 ++++++++++++++------------- src/maomao.c | 181 ++++++++++++++++---------------- 5 files changed, 286 insertions(+), 272 deletions(-) diff --git a/src/client/client.h b/src/client/client.h index f93e497..0eb79b8 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -368,7 +368,7 @@ static inline int client_surface_wants_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, @@ -379,17 +379,17 @@ static inline int client_surface_wants_focus(Client *c) { 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 - }; + 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 0; - } + 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 0; + } } } #endif - return 1; + return 1; } static inline int client_wants_focus(Client *c) { diff --git a/src/config/parse_config.h b/src/config/parse_config.h index d833e8d..e0b1df6 100644 --- a/src/config/parse_config.h +++ b/src/config/parse_config.h @@ -214,55 +214,55 @@ typedef struct { typedef void (*FuncType)(const Arg *); Config config; - void parse_config_file(Config *config, const char *file_path); // Helper function to trim whitespace from start and end of a string void trim_whitespace(char *str) { - if (str == NULL || *str == '\0') return; + if (str == NULL || *str == '\0') + return; - // Trim leading space - char *start = str; - while (isspace((unsigned char)*start)) { - start++; - } + // Trim leading space + char *start = str; + while (isspace((unsigned char)*start)) { + start++; + } - // Trim trailing space - char *end = str + strlen(str) - 1; - while (end > start && isspace((unsigned char)*end)) { - end--; - } - - // Null-terminate the trimmed string - *(end + 1) = '\0'; + // Trim trailing space + char *end = str + strlen(str) - 1; + while (end > start && isspace((unsigned char)*end)) { + end--; + } - // Move the trimmed part to the beginning if needed - if (start != str) { - memmove(str, start, end - start + 2); // +2 to include null terminator - } + // Null-terminate the trimmed string + *(end + 1) = '\0'; + + // Move the trimmed part to the beginning if needed + if (start != str) { + memmove(str, start, end - start + 2); // +2 to include null terminator + } } int parse_double_array(const char *input, double *output, int max_count) { - char *dup = strdup(input); // 复制一份用于修改 - char *token; - int count = 0; + char *dup = strdup(input); // 复制一份用于修改 + char *token; + int count = 0; - token = strtok(dup, ","); - while (token != NULL && count < max_count) { - trim_whitespace(token); // 对每一个分割后的 token 去除前后空格 - char *endptr; - double val = strtod(token, &endptr); - if (endptr == token || *endptr != '\0') { - fprintf(stderr, "Error: Invalid number in array: %s\n", token); - free(dup); - return -1; // 解析失败 - } - output[count++] = val; - token = strtok(NULL, ","); + token = strtok(dup, ","); + while (token != NULL && count < max_count) { + trim_whitespace(token); // 对每一个分割后的 token 去除前后空格 + char *endptr; + double val = strtod(token, &endptr); + if (endptr == token || *endptr != '\0') { + fprintf(stderr, "Error: Invalid number in array: %s\n", token); + free(dup); + return -1; // 解析失败 } + output[count++] = val; + token = strtok(NULL, ","); + } - free(dup); - return count; + free(dup); + return count; } // 清理字符串中的不可见字符(包括 \r, \n, 空格等) @@ -697,22 +697,26 @@ void parse_config_line(Config *config, const char *line) { } else if (strcmp(key, "animation_curve_move") == 0) { int num = parse_double_array(value, config->animation_curve_move, 4); if (num != 4) { - fprintf(stderr, "Error: Failed to parse animation_curve_move: %s\n", value); + fprintf(stderr, "Error: Failed to parse animation_curve_move: %s\n", + value); } } else if (strcmp(key, "animation_curve_open") == 0) { int num = parse_double_array(value, config->animation_curve_open, 4); if (num != 4) { - fprintf(stderr, "Error: Failed to parse animation_curve_open: %s\n", value); + fprintf(stderr, "Error: Failed to parse animation_curve_open: %s\n", + value); } } else if (strcmp(key, "animation_curve_tag") == 0) { int num = parse_double_array(value, config->animation_curve_tag, 4); if (num != 4) { - fprintf(stderr, "Error: Failed to parse animation_curve_tag: %s\n", value); + fprintf(stderr, "Error: Failed to parse animation_curve_tag: %s\n", + value); } } else if (strcmp(key, "animation_curve_close") == 0) { int num = parse_double_array(value, config->animation_curve_close, 4); if (num != 4) { - fprintf(stderr, "Error: Failed to parse animation_curve_close: %s\n", value); + fprintf(stderr, "Error: Failed to parse animation_curve_close: %s\n", + value); } } else if (strcmp(key, "scroller_structs") == 0) { config->scroller_structs = atoi(value); @@ -728,8 +732,8 @@ void parse_config_line(Config *config, const char *line) { config->focus_cross_monitor = atoi(value); } else if (strcmp(key, "focus_cross_tag") == 0) { config->focus_cross_tag = atoi(value); - } else if (strcmp(key, "no_border_when_single") == 0) { - config->no_border_when_single= atoi(value); + } else if (strcmp(key, "no_border_when_single") == 0) { + config->no_border_when_single = atoi(value); } else if (strcmp(key, "snap_distance") == 0) { config->snap_distance = atoi(value); } else if (strcmp(key, "enable_floating_snap") == 0) { @@ -1113,58 +1117,61 @@ void parse_config_line(Config *config, const char *line) { } config->window_rules_count++; } else if (strcmp(key, "monitorrule") == 0) { -config->monitor_rules = - realloc(config->monitor_rules, - (config->monitor_rules_count + 1) * sizeof(ConfigMonitorRule)); -if (!config->monitor_rules) { - fprintf(stderr, "Error: Failed to allocate memory for monitor rules\n"); - return; -} - -ConfigMonitorRule *rule = &config->monitor_rules[config->monitor_rules_count]; -memset(rule, 0, sizeof(ConfigMonitorRule)); - -// 临时存储每个字段的原始字符串 -char raw_name[256], raw_layout[256]; -char raw_mfact[256], raw_nmaster[256], raw_rr[256]; -char raw_scale[256], raw_x[256], raw_y[256]; - -// 先读取所有字段为字符串 -int parsed = sscanf(value, "%255[^,],%255[^,],%255[^,],%255[^,],%255[^,],%255[^,],%255[^,],%255s", - raw_name, raw_mfact, raw_nmaster, raw_layout, - raw_rr, raw_scale, raw_x, raw_y); - -if (parsed == 8) { - // 修剪每个字段的空格 - trim_whitespace(raw_name); - trim_whitespace(raw_mfact); - trim_whitespace(raw_nmaster); - trim_whitespace(raw_layout); - trim_whitespace(raw_rr); - trim_whitespace(raw_scale); - trim_whitespace(raw_x); - trim_whitespace(raw_y); - - // 转换修剪后的字符串为特定类型 - rule->name = strdup(raw_name); - rule->layout = strdup(raw_layout); - rule->mfact = atof(raw_mfact); - rule->nmaster = atoi(raw_nmaster); - rule->rr = atoi(raw_rr); - rule->scale = atof(raw_scale); - rule->x = atoi(raw_x); - rule->y = atoi(raw_y); - - if (!rule->name || !rule->layout) { - if (rule->name) - free((void *)rule->name); - if (rule->layout) - free((void *)rule->layout); - fprintf(stderr, "Error: Failed to allocate memory for monitor rule\n"); - return; + config->monitor_rules = + realloc(config->monitor_rules, + (config->monitor_rules_count + 1) * sizeof(ConfigMonitorRule)); + if (!config->monitor_rules) { + fprintf(stderr, "Error: Failed to allocate memory for monitor rules\n"); + return; } - config->monitor_rules_count++; + ConfigMonitorRule *rule = + &config->monitor_rules[config->monitor_rules_count]; + memset(rule, 0, sizeof(ConfigMonitorRule)); + + // 临时存储每个字段的原始字符串 + char raw_name[256], raw_layout[256]; + char raw_mfact[256], raw_nmaster[256], raw_rr[256]; + char raw_scale[256], raw_x[256], raw_y[256]; + + // 先读取所有字段为字符串 + int parsed = sscanf( + value, + "%255[^,],%255[^,],%255[^,],%255[^,],%255[^,],%255[^,],%255[^,],%255s", + raw_name, raw_mfact, raw_nmaster, raw_layout, raw_rr, raw_scale, raw_x, + raw_y); + + if (parsed == 8) { + // 修剪每个字段的空格 + trim_whitespace(raw_name); + trim_whitespace(raw_mfact); + trim_whitespace(raw_nmaster); + trim_whitespace(raw_layout); + trim_whitespace(raw_rr); + trim_whitespace(raw_scale); + trim_whitespace(raw_x); + trim_whitespace(raw_y); + + // 转换修剪后的字符串为特定类型 + rule->name = strdup(raw_name); + rule->layout = strdup(raw_layout); + rule->mfact = atof(raw_mfact); + rule->nmaster = atoi(raw_nmaster); + rule->rr = atoi(raw_rr); + rule->scale = atof(raw_scale); + rule->x = atoi(raw_x); + rule->y = atoi(raw_y); + + if (!rule->name || !rule->layout) { + if (rule->name) + free((void *)rule->name); + if (rule->layout) + free((void *)rule->layout); + fprintf(stderr, "Error: Failed to allocate memory for monitor rule\n"); + return; + } + + config->monitor_rules_count++; } else { fprintf(stderr, "Error: Invalid monitorrule format: %s\n", value); } @@ -1393,7 +1400,7 @@ if (parsed == 8) { trim_whitespace(func_name); trim_whitespace(arg_value); trim_whitespace(arg_value2); - trim_whitespace(arg_value3); + trim_whitespace(arg_value3); trim_whitespace(arg_value4); binding->mod = parse_mod(mod_str); @@ -1431,8 +1438,8 @@ void parse_config_file(Config *config, const char *file_path) { if (file_path[0] == '~' && (file_path[1] == '/' || file_path[1] == '\0')) { const char *home = getenv("HOME"); if (!home) { - fprintf(stderr, "Error: HOME environment variable not set.\n"); - return; + fprintf(stderr, "Error: HOME environment variable not set.\n"); + return; } // 构建完整路径(家目录 + / + 原路径去掉 ~) @@ -1441,8 +1448,8 @@ void parse_config_file(Config *config, const char *file_path) { file = fopen(full_path, "r"); if (!file) { - perror("Error opening file"); - return; + perror("Error opening file"); + return; } } else { file = fopen(file_path, "r"); @@ -1451,7 +1458,7 @@ void parse_config_file(Config *config, const char *file_path) { return; } } - + char line[512]; while (fgets(line, sizeof(line), file)) { if (line[0] == '#' || line[0] == '\n') @@ -1679,7 +1686,7 @@ void override_config(void) { scroller_focus_center = config.scroller_focus_center; focus_cross_monitor = config.focus_cross_monitor; focus_cross_tag = config.focus_cross_tag; - no_border_when_single= config.no_border_when_single; + no_border_when_single = config.no_border_when_single; snap_distance = config.snap_distance; enable_floating_snap = config.enable_floating_snap; swipe_min_threshold = config.swipe_min_threshold; @@ -1779,7 +1786,7 @@ void set_value_default() { config.scroller_prefer_center = scroller_prefer_center; config.focus_cross_monitor = focus_cross_monitor; config.focus_cross_tag = focus_cross_tag; - config.no_border_when_single= no_border_when_single; + config.no_border_when_single = no_border_when_single; config.snap_distance = snap_distance; config.enable_floating_snap = enable_floating_snap; config.swipe_min_threshold = swipe_min_threshold; diff --git a/src/config/preset_config.h b/src/config/preset_config.h index 364352a..ca12760 100644 --- a/src/config/preset_config.h +++ b/src/config/preset_config.h @@ -1,4 +1,5 @@ -// TODO: remove this file in the future, replace all global variables with config.xxx +// TODO: remove this file in the future, replace all global variables with +// config.xxx /* speedie's maomao config */ diff --git a/src/layout/layout.h b/src/layout/layout.h index e976f02..6e5fbcc 100644 --- a/src/layout/layout.h +++ b/src/layout/layout.h @@ -6,10 +6,10 @@ void fibonacci(Monitor *mon, int s) { 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; + 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) && !c->isfloating && !c->iskilling && !c->isfullscreen && @@ -31,7 +31,9 @@ void fibonacci(Monitor *mon, int s) { c->isfullscreen || c->ismaxmizescreen || c->animation.tagouting) continue; - c->bw = mon->visible_clients == 1 && no_border_when_single && smartgaps ? 0 : borderpx; + 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) { @@ -147,7 +149,9 @@ void grid(Monitor *m) { if (n == 1) { wl_list_for_each(c, &clients, link) { - c->bw = m->visible_clients == 1 && no_border_when_single && smartgaps ? 0 : borderpx; + c->bw = m->visible_clients == 1 && no_border_when_single && smartgaps + ? 0 + : borderpx; if (VISIBLEON(c, c->mon) && !c->iskilling && !c->animation.tagouting && c->mon == selmon) { cw = (m->w.width - 2 * overviewgappo) * 0.7; @@ -167,7 +171,9 @@ void grid(Monitor *m) { 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; + c->bw = m->visible_clients == 1 && no_border_when_single && smartgaps + ? 0 + : borderpx; if (VISIBLEON(c, c->mon) && !c->iskilling && !c->animation.tagouting && c->mon == selmon) { if (i == 0) { @@ -211,7 +217,9 @@ void grid(Monitor *m) { // 调整每个客户端的位置和大小 i = 0; wl_list_for_each(c, &clients, link) { - c->bw = m->visible_clients == 1 && no_border_when_single && smartgaps ? 0 : borderpx; + c->bw = m->visible_clients == 1 && no_border_when_single && smartgaps + ? 0 + : borderpx; if (VISIBLEON(c, c->mon) && !c->iskilling && !c->animation.tagouting && c->mon == selmon) { cx = m->w.x + (i % cols) * (cw + overviewgappi); @@ -229,64 +237,63 @@ void grid(Monitor *m) { } } +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; -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; + 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) && !c->isfloating && + !c->isfullscreen) n++; + if (n == 0) + return; - wl_list_for_each(c, &clients, link) - if (VISIBLEON(c, m) && !c->isfloating && !c->isfullscreen) - 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) || c->isfloating || c->isfullscreen) - 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) || c->isfloating || c->isfullscreen) + 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++; + } } // 滚动布局 @@ -303,9 +310,9 @@ void scroller(Monitor *m) { 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; @@ -445,10 +452,10 @@ void tile(Monitor *m) { 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] @@ -458,16 +465,16 @@ void tile(Monitor *m) { else mw = m->w.width - 2 * cur_gappov + cur_gappiv * ie; i = 0; - my = ty =cur_gappoh ; + my = ty = cur_gappoh; wl_list_for_each(c, &clients, link) { if (!VISIBLEON(c, m) || c->iskilling || c->animation.tagouting || c->isfloating || c->isfullscreen || c->ismaxmizescreen) 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; + h = (m->w.height - my - cur_gappoh - cur_gappih * ie * (r - 1)) / r; resize(c, - (struct wlr_box){.x = m->w.x + cur_gappov , + (struct wlr_box){.x = m->w.x + cur_gappov, .y = m->w.y + my, .width = mw - cur_gappiv * ie, .height = h}, @@ -475,7 +482,7 @@ void tile(Monitor *m) { my += c->geom.height + cur_gappih * ie; } else { r = n - i; - h = (m->w.height - ty -cur_gappoh - cur_gappih * ie * (r - 1)) / r; + 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, diff --git a/src/maomao.c b/src/maomao.c index 578d308..9b6e98c 100644 --- a/src/maomao.c +++ b/src/maomao.c @@ -717,10 +717,10 @@ struct vec2 *baked_points_close; static struct wl_event_source *hide_source; static bool cursor_hidden = false; static struct { - enum wp_cursor_shape_device_v1_shape shape; - struct wlr_surface *surface; - int hotspot_x; - int hotspot_y; + enum wp_cursor_shape_device_v1_shape shape; + struct wlr_surface *surface; + int hotspot_x; + int hotspot_y; } last_cursor; #include "config/preset_config.h" @@ -794,8 +794,8 @@ static struct wlr_xwayland *xwayland; #include "client/client.h" #include "config/parse_config.h" -#include "text_input/ime.h" #include "layout/layout.h" +#include "text_input/ime.h" struct vec2 calculate_animation_curve_at(double t, int type) { struct vec2 point; @@ -1077,7 +1077,7 @@ void apply_border(Client *c, struct wlr_box clip_box, int offsetx, if (!render_border) { hit_no_border = true; - } + } for (i = 0; i < config.tag_rules_count; i++) { if (c->tags & (1 << (config.tag_rules[i].id - 1)) && @@ -1086,11 +1086,11 @@ void apply_border(Client *c, struct wlr_box clip_box, int offsetx, } } - if(no_border_when_single && c->mon->visible_clients == 1) { + if (no_border_when_single && c->mon->visible_clients == 1) { hit_no_border = true; } - if(hit_no_border && smartgaps) { + if (hit_no_border && smartgaps) { c->bw = 0; } else if (hit_no_border && !smartgaps) { set_rect_size(c->border[0], 0, 0); @@ -1099,9 +1099,9 @@ void apply_border(Client *c, struct wlr_box clip_box, int offsetx, set_rect_size(c->border[3], 0, 0); wlr_scene_node_set_position(&c->scene_surface->node, c->bw, c->bw); - return; - } else if(!c->isfullscreen && VISIBLEON(c, c->mon)) { - c->bw = c->isnoborder ? 0 : borderpx; + return; + } else if (!c->isfullscreen && VISIBLEON(c, c->mon)) { + c->bw = c->isnoborder ? 0 : borderpx; } wlr_scene_node_set_position(&c->scene_surface->node, c->bw, c->bw); @@ -1122,31 +1122,32 @@ void apply_border(Client *c, struct wlr_box clip_box, int offsetx, clip_box.height - 2 * c->bw); } else if (c->animation.current.x + c->animation.current.width > c->mon->m.x + c->mon->m.width) { - set_rect_size( - c->border[3], - GEZERO(c->bw - GEZERO(c->animation.current.x + c->animation.current.width - - c->mon->m.x - c->mon->m.width)), - clip_box.height - 2 * c->bw); - set_rect_size(c->border[0], clip_box.width + c->bw, GEZERO(c->bw - offsety)); - set_rect_size( - c->border[1], clip_box.width + c->bw, - GEZERO(c->bw - GEZERO(c->animation.current.y + c->animation.current.height - - c->mon->m.y - c->mon->m.height))); + set_rect_size(c->border[3], + GEZERO(c->bw - GEZERO(c->animation.current.x + + c->animation.current.width - + c->mon->m.x - c->mon->m.width)), + clip_box.height - 2 * c->bw); + set_rect_size(c->border[0], clip_box.width + c->bw, + GEZERO(c->bw - offsety)); + set_rect_size(c->border[1], clip_box.width + c->bw, + GEZERO(c->bw - GEZERO(c->animation.current.y + + c->animation.current.height - + c->mon->m.y - c->mon->m.height))); } else if (c->animation.current.y < c->mon->m.y) { set_rect_size(c->border[0], clip_box.width, GEZERO(c->bw - offsety)); } else if (c->animation.current.y + c->animation.current.height > c->mon->m.y + c->mon->m.height) { - set_rect_size( - c->border[1], clip_box.width, - GEZERO(c->bw - GEZERO(c->animation.current.y + c->animation.current.height - - c->mon->m.y - c->mon->m.height))); + set_rect_size(c->border[1], clip_box.width, + GEZERO(c->bw - GEZERO(c->animation.current.y + + c->animation.current.height - + c->mon->m.y - c->mon->m.height))); set_rect_size(c->border[2], GEZERO(c->bw - offsetx), clip_box.height - c->bw); - set_rect_size( - c->border[3], - GEZERO(c->bw - GEZERO(c->animation.current.x + c->animation.current.width - - c->mon->m.x - c->mon->m.width)), - clip_box.height - c->bw); + set_rect_size(c->border[3], + GEZERO(c->bw - GEZERO(c->animation.current.x + + c->animation.current.width - + c->mon->m.x - c->mon->m.width)), + clip_box.height - c->bw); } } @@ -1180,7 +1181,8 @@ struct uvec2 clip_to_hide(Client *c, struct wlr_box *clip_box) { c->mon->m.x + c->mon->m.width) { clip_box->width = clip_box->width - (c->animation.current.x + c->animation.current.width - - c->mon->m.x - c->mon->m.width) - c->bw; + c->mon->m.x - c->mon->m.width) - + c->bw; } if (c->animation.current.y <= c->mon->m.y) { @@ -1191,14 +1193,16 @@ struct uvec2 clip_to_hide(Client *c, struct wlr_box *clip_box) { c->mon->m.y + c->mon->m.height) { clip_box->height = clip_box->height - (c->animation.current.y + c->animation.current.height - - c->mon->m.y - c->mon->m.height) - c->bw; + c->mon->m.y - c->mon->m.height) - + c->bw; } } offset.x = offsetx; offset.y = offsety; - if ((clip_box->width <= 0 || clip_box->height <= 0) && (ISTILED(c) || c->animation.tagouting || c->animation.tagining)) { + if ((clip_box->width <= 0 || clip_box->height <= 0) && + (ISTILED(c) || c->animation.tagouting || c->animation.tagining)) { c->is_clip_to_hide = true; wlr_scene_node_set_enabled(&c->scene->node, false); } else if (c->is_clip_to_hide && VISIBLEON(c, c->mon)) { @@ -1318,7 +1322,7 @@ void clear_fullscreen_flag(Client *c) { c->isfullscreen = 0; c->isfloating = 0; c->ismaxmizescreen = 0; - c->bw = c->isnoborder ? 0 : borderpx; + c->bw = c->isnoborder ? 0 : borderpx; client_set_fullscreen(c, false); } } @@ -1375,7 +1379,7 @@ void show_scratchpad(Client *c) { if (c->isfullscreen || c->ismaxmizescreen) { c->isfullscreen = 0; // 清除窗口全屏标志 c->ismaxmizescreen = 0; - c->bw = c->isnoborder ? 0 : borderpx; + c->bw = c->isnoborder ? 0 : borderpx; } if (c->oldgeom.width) @@ -1758,7 +1762,8 @@ applyrulesgeom(Client *c) { c->geom.width = r->width > 0 ? r->width : c->geom.width; c->geom.height = r->height > 0 ? r->height : c->geom.height; // 重新计算居中的坐标 - if(r->offsetx || r->offsety || (!client_is_x11(c) || client_surface_wants_focus(c))) + if (r->offsetx || r->offsety || + (!client_is_x11(c) || client_surface_wants_focus(c))) c->geom = setclient_coordinate_center(c->geom, r->offsetx, r->offsety); hit = r->height > 0 || r->width > 0 || r->offsetx != 0 || r->offsety != 0 ? 1 @@ -1821,8 +1826,10 @@ applyrules(Client *c) { c->geom.width = r->width > 0 ? r->width : c->geom.width; c->geom.height = r->height > 0 ? r->height : c->geom.height; // 重新计算居中的坐标 - if(r->offsetx || r->offsety || (!client_is_x11(c) || client_surface_wants_focus(c))) - c->geom = setclient_coordinate_center(c->geom, r->offsetx, r->offsety); + if (r->offsetx || r->offsety || + (!client_is_x11(c) || client_surface_wants_focus(c))) + c->geom = + setclient_coordinate_center(c->geom, r->offsetx, r->offsety); } } } @@ -1887,7 +1894,7 @@ arrange(Monitor *m, bool want_animation) { focusclient(c, 0); } - if (c->mon == m) { + if (c->mon == m) { if (VISIBLEON(c, m)) { m->visible_clients++; @@ -2641,11 +2648,11 @@ void setcursorshape(struct wl_listener *listener, void *data) { * actually has pointer focus first. If so, we can tell the cursor to * use the provided cursor shape. */ if (event->seat_client == seat->pointer_state.focused_client) { - last_cursor.shape = event->shape; - last_cursor.surface = NULL; - if (!cursor_hidden) - wlr_cursor_set_xcursor(cursor, cursor_mgr, - wlr_cursor_shape_v1_name(event->shape)); + last_cursor.shape = event->shape; + last_cursor.surface = NULL; + if (!cursor_hidden) + wlr_cursor_set_xcursor(cursor, cursor_mgr, + wlr_cursor_shape_v1_name(event->shape)); } } @@ -3605,22 +3612,22 @@ void dwl_ipc_output_printstatus_to(DwlIpcOutput *ipc_output) { if (wl_resource_get_version(ipc_output->resource) >= ZDWL_IPC_OUTPUT_V2_FLOATING_SINCE_VERSION) { zdwl_ipc_output_v2_send_x(ipc_output->resource, - focused ? focused->geom.x : 0); + focused ? focused->geom.x : 0); } if (wl_resource_get_version(ipc_output->resource) >= ZDWL_IPC_OUTPUT_V2_FLOATING_SINCE_VERSION) { zdwl_ipc_output_v2_send_y(ipc_output->resource, - focused ? focused->geom.y : 0); + focused ? focused->geom.y : 0); } if (wl_resource_get_version(ipc_output->resource) >= ZDWL_IPC_OUTPUT_V2_FLOATING_SINCE_VERSION) { zdwl_ipc_output_v2_send_width(ipc_output->resource, - focused ? focused->geom.width : 0); + focused ? focused->geom.width : 0); } if (wl_resource_get_version(ipc_output->resource) >= ZDWL_IPC_OUTPUT_V2_FLOATING_SINCE_VERSION) { zdwl_ipc_output_v2_send_height(ipc_output->resource, - focused ? focused->geom.height : 0); + focused ? focused->geom.height : 0); } zdwl_ipc_output_v2_send_frame(ipc_output->resource); } @@ -3726,7 +3733,7 @@ void focusclient(Client *c, int lift) { if (c && c->animation.tagouting && !c->animation.tagouting) return; - if(c && client_is_x11(c) && !client_surface_wants_focus(c)) { + if (c && client_is_x11(c) && !client_surface_wants_focus(c)) { return; } @@ -4303,7 +4310,7 @@ mapnotify(struct wl_listener *listener, void *data) { client_get_geometry(c, &c->geom); - if(client_is_unmanaged(c) || !client_surface_wants_focus(c)) { + if (client_is_unmanaged(c) || !client_surface_wants_focus(c)) { c->bw = 0; c->isnoborder = 1; } else { @@ -5286,15 +5293,15 @@ void setcursor(struct wl_listener *listener, void *data) { * use the provided surface as the cursor image. It will set the * hardware cursor on the output that it's currently on and continue to * do so as the cursor moves between outputs. */ - if (event->seat_client == seat->pointer_state.focused_client) { - last_cursor.shape = 0; - last_cursor.surface = event->surface; - last_cursor.hotspot_x = event->hotspot_x; - last_cursor.hotspot_y = event->hotspot_y; - if (!cursor_hidden) - wlr_cursor_set_surface(cursor, event->surface, - event->hotspot_x, event->hotspot_y); - } + if (event->seat_client == seat->pointer_state.focused_client) { + last_cursor.shape = 0; + last_cursor.surface = event->surface; + last_cursor.hotspot_x = event->hotspot_x; + last_cursor.hotspot_y = event->hotspot_y; + if (!cursor_hidden) + wlr_cursor_set_surface(cursor, event->surface, event->hotspot_x, + event->hotspot_y); + } } void // 0.5 @@ -5322,7 +5329,7 @@ setfloating(Client *c, int floating) { if (c->isfullscreen || c->ismaxmizescreen) { c->isfullscreen = 0; // 清除窗口全屏标志 c->ismaxmizescreen = 0; - c->bw = c->isnoborder ? 0 : borderpx; + c->bw = c->isnoborder ? 0 : borderpx; } if (c->need_float_size_reduce && !c->swallowing && !c->is_open_animation) { @@ -5330,7 +5337,7 @@ setfloating(Client *c, int floating) { target_box.width = target_box.width * 0.8; } // 重新计算居中的坐标 - if(!client_is_x11(c) || client_surface_wants_focus(c)) + if (!client_is_x11(c) || client_surface_wants_focus(c)) target_box = setclient_coordinate_center(target_box, 0, 0); backup_box = c->geom; hit = applyrulesgeom(c); @@ -5401,7 +5408,7 @@ void setmaxmizescreen(Client *c, int maxmizescreen) { resize(c, maxmizescreen_box, 0); c->ismaxmizescreen = 1; } else { - c->bw = c->isnoborder ? 0 : borderpx; + c->bw = c->isnoborder ? 0 : borderpx; c->ismaxmizescreen = 0; c->isfullscreen = 0; client_set_fullscreen(c, false); @@ -5451,7 +5458,7 @@ void setfullscreen(Client *c, int fullscreen) // 用自定义全屏代理自带 c->isfullscreen = 1; // c->isfloating = 0; } else { - c->bw = c->isnoborder ? 0 : borderpx; + c->bw = c->isnoborder ? 0 : borderpx; c->isfullscreen = 0; c->isfullscreen = 0; c->ismaxmizescreen = 0; @@ -5749,7 +5756,7 @@ void destroy_all_virtual_output(const Arg *arg) { Monitor *m, *tmp; wl_list_for_each_safe(m, tmp, &mons, link) { if (wlr_output_is_headless(m->wlr_output)) { - // if(selmon == m) + // if(selmon == m) // selmon = NULL; wlr_output_destroy(m->wlr_output); wlr_log(WLR_INFO, "Virtual output destroyed"); @@ -5952,7 +5959,7 @@ void setup(void) { wl_signal_add(&cursor_shape_mgr->events.request_set_shape, &request_set_cursor_shape); hide_source = wl_event_loop_add_timer(wl_display_get_event_loop(dpy), - hidecursor, cursor); + hidecursor, cursor); /* * Configures a seat, which is a single "seat" at which a user sits and @@ -6152,8 +6159,6 @@ void tagmon(const Arg *arg) { void overview(Monitor *m) { grid(m); } - - // 目标窗口有其他窗口和它同个tag就返回0 unsigned int want_restore_fullscreen(Client *target_client) { Client *c = NULL; @@ -6185,7 +6190,7 @@ void overview_backup(Client *c) { c->isfullscreen = 0; // 清除窗口全屏标志 c->ismaxmizescreen = 0; } - c->bw = c->isnoborder ? 0 : borderpx; + c->bw = c->isnoborder ? 0 : borderpx; } // overview切回到普通视图还原窗口的状态 @@ -6219,9 +6224,8 @@ void overview_restore(Client *c, const Arg *arg) { } } - if (c->bw == 0 && - !c->isfullscreen) { // 如果是在ov模式中创建的窗口,没有bw记录 - c->bw = c->isnoborder ? 0 : borderpx; + if (c->bw == 0 && !c->isfullscreen) { // 如果是在ov模式中创建的窗口,没有bw记录 + c->bw = c->isnoborder ? 0 : borderpx; } } @@ -6271,30 +6275,26 @@ void set_proportion(const Arg *arg) { } } -void -handlecursoractivity(void) -{ - wl_event_source_timer_update(hide_source, cursor_hide_timeout * 1000); +void handlecursoractivity(void) { + wl_event_source_timer_update(hide_source, cursor_hide_timeout * 1000); - if (!cursor_hidden) - return; + if (!cursor_hidden) + return; - cursor_hidden = false; + cursor_hidden = false; - if (last_cursor.shape) - wlr_cursor_set_xcursor(cursor, cursor_mgr, - wlr_cursor_shape_v1_name(last_cursor.shape)); - else - wlr_cursor_set_surface(cursor, last_cursor.surface, - last_cursor.hotspot_x, last_cursor.hotspot_y); + if (last_cursor.shape) + wlr_cursor_set_xcursor(cursor, cursor_mgr, + wlr_cursor_shape_v1_name(last_cursor.shape)); + else + wlr_cursor_set_surface(cursor, last_cursor.surface, last_cursor.hotspot_x, + last_cursor.hotspot_y); } -int -hidecursor(void *data) -{ - wlr_cursor_unset_image(cursor); - cursor_hidden = true; - return 1; +int hidecursor(void *data) { + wlr_cursor_unset_image(cursor); + cursor_hidden = true; + return 1; } void increase_proportion(const Arg *arg) { @@ -6362,7 +6362,6 @@ void toggleoverview(const Arg *arg) { } } - void togglefloating(const Arg *arg) { Client *sel = focustop(selmon);