format code

This commit is contained in:
DreamMaoMao
2025-05-13 18:20:41 +08:00
parent 29d9d12b23
commit 2d5388a4d7
5 changed files with 286 additions and 272 deletions

View File

@@ -368,7 +368,7 @@ static inline int client_surface_wants_focus(Client *c) {
#ifdef XWAYLAND #ifdef XWAYLAND
if (client_is_x11(c)) { if (client_is_x11(c)) {
struct wlr_xwayland_surface *surface = c->surface.xwayland; struct wlr_xwayland_surface *surface = c->surface.xwayland;
// 处理不需要焦点的窗口类型 // 处理不需要焦点的窗口类型
const uint32_t no_focus_types[] = { const uint32_t no_focus_types[] = {
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_COMBO, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_COMBO,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DND, 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_SPLASH,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DESKTOP, WLR_XWAYLAND_NET_WM_WINDOW_TYPE_DESKTOP,
WLR_XWAYLAND_NET_WM_WINDOW_TYPE_TOOLTIP, 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) { for (size_t i = 0; i < sizeof(no_focus_types) / sizeof(no_focus_types[0]);
if (wlr_xwayland_surface_has_window_type(surface, no_focus_types[i])) { ++i) {
return 0; if (wlr_xwayland_surface_has_window_type(surface, no_focus_types[i])) {
} return 0;
}
} }
} }
#endif #endif
return 1; return 1;
} }
static inline int client_wants_focus(Client *c) { static inline int client_wants_focus(Client *c) {

View File

@@ -214,55 +214,55 @@ typedef struct {
typedef void (*FuncType)(const Arg *); typedef void (*FuncType)(const Arg *);
Config config; Config config;
void parse_config_file(Config *config, const char *file_path); void parse_config_file(Config *config, const char *file_path);
// Helper function to trim whitespace from start and end of a string // Helper function to trim whitespace from start and end of a string
void trim_whitespace(char *str) { void trim_whitespace(char *str) {
if (str == NULL || *str == '\0') return; if (str == NULL || *str == '\0')
return;
// Trim leading space // Trim leading space
char *start = str; char *start = str;
while (isspace((unsigned char)*start)) { while (isspace((unsigned char)*start)) {
start++; start++;
} }
// Trim trailing space // Trim trailing space
char *end = str + strlen(str) - 1; char *end = str + strlen(str) - 1;
while (end > start && isspace((unsigned char)*end)) { while (end > start && isspace((unsigned char)*end)) {
end--; end--;
} }
// Null-terminate the trimmed string // Null-terminate the trimmed string
*(end + 1) = '\0'; *(end + 1) = '\0';
// Move the trimmed part to the beginning if needed // Move the trimmed part to the beginning if needed
if (start != str) { if (start != str) {
memmove(str, start, end - start + 2); // +2 to include null terminator memmove(str, start, end - start + 2); // +2 to include null terminator
} }
} }
int parse_double_array(const char *input, double *output, int max_count) { int parse_double_array(const char *input, double *output, int max_count) {
char *dup = strdup(input); // 复制一份用于修改 char *dup = strdup(input); // 复制一份用于修改
char *token; char *token;
int count = 0; int count = 0;
token = strtok(dup, ","); token = strtok(dup, ",");
while (token != NULL && count < max_count) { while (token != NULL && count < max_count) {
trim_whitespace(token); // 对每一个分割后的 token 去除前后空格 trim_whitespace(token); // 对每一个分割后的 token 去除前后空格
char *endptr; char *endptr;
double val = strtod(token, &endptr); double val = strtod(token, &endptr);
if (endptr == token || *endptr != '\0') { if (endptr == token || *endptr != '\0') {
fprintf(stderr, "Error: Invalid number in array: %s\n", token); fprintf(stderr, "Error: Invalid number in array: %s\n", token);
free(dup); free(dup);
return -1; // 解析失败 return -1; // 解析失败
}
output[count++] = val;
token = strtok(NULL, ",");
} }
output[count++] = val;
token = strtok(NULL, ",");
}
free(dup); free(dup);
return count; return count;
} }
// 清理字符串中的不可见字符(包括 \r, \n, 空格等) // 清理字符串中的不可见字符(包括 \r, \n, 空格等)
@@ -697,22 +697,26 @@ void parse_config_line(Config *config, const char *line) {
} else if (strcmp(key, "animation_curve_move") == 0) { } else if (strcmp(key, "animation_curve_move") == 0) {
int num = parse_double_array(value, config->animation_curve_move, 4); int num = parse_double_array(value, config->animation_curve_move, 4);
if (num != 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) { } else if (strcmp(key, "animation_curve_open") == 0) {
int num = parse_double_array(value, config->animation_curve_open, 4); int num = parse_double_array(value, config->animation_curve_open, 4);
if (num != 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) { } else if (strcmp(key, "animation_curve_tag") == 0) {
int num = parse_double_array(value, config->animation_curve_tag, 4); int num = parse_double_array(value, config->animation_curve_tag, 4);
if (num != 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) { } else if (strcmp(key, "animation_curve_close") == 0) {
int num = parse_double_array(value, config->animation_curve_close, 4); int num = parse_double_array(value, config->animation_curve_close, 4);
if (num != 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) { } else if (strcmp(key, "scroller_structs") == 0) {
config->scroller_structs = atoi(value); config->scroller_structs = atoi(value);
@@ -728,8 +732,8 @@ void parse_config_line(Config *config, const char *line) {
config->focus_cross_monitor = atoi(value); config->focus_cross_monitor = atoi(value);
} else if (strcmp(key, "focus_cross_tag") == 0) { } else if (strcmp(key, "focus_cross_tag") == 0) {
config->focus_cross_tag = atoi(value); config->focus_cross_tag = atoi(value);
} else if (strcmp(key, "no_border_when_single") == 0) { } else if (strcmp(key, "no_border_when_single") == 0) {
config->no_border_when_single= atoi(value); config->no_border_when_single = atoi(value);
} else if (strcmp(key, "snap_distance") == 0) { } else if (strcmp(key, "snap_distance") == 0) {
config->snap_distance = atoi(value); config->snap_distance = atoi(value);
} else if (strcmp(key, "enable_floating_snap") == 0) { } 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++; config->window_rules_count++;
} else if (strcmp(key, "monitorrule") == 0) { } else if (strcmp(key, "monitorrule") == 0) {
config->monitor_rules = config->monitor_rules =
realloc(config->monitor_rules, realloc(config->monitor_rules,
(config->monitor_rules_count + 1) * sizeof(ConfigMonitorRule)); (config->monitor_rules_count + 1) * sizeof(ConfigMonitorRule));
if (!config->monitor_rules) { if (!config->monitor_rules) {
fprintf(stderr, "Error: Failed to allocate memory for monitor rules\n"); fprintf(stderr, "Error: Failed to allocate memory for monitor rules\n");
return; 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_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 { } else {
fprintf(stderr, "Error: Invalid monitorrule format: %s\n", value); fprintf(stderr, "Error: Invalid monitorrule format: %s\n", value);
} }
@@ -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')) { if (file_path[0] == '~' && (file_path[1] == '/' || file_path[1] == '\0')) {
const char *home = getenv("HOME"); const char *home = getenv("HOME");
if (!home) { if (!home) {
fprintf(stderr, "Error: HOME environment variable not set.\n"); fprintf(stderr, "Error: HOME environment variable not set.\n");
return; return;
} }
// 构建完整路径(家目录 + / + 原路径去掉 ~ // 构建完整路径(家目录 + / + 原路径去掉 ~
@@ -1441,8 +1448,8 @@ void parse_config_file(Config *config, const char *file_path) {
file = fopen(full_path, "r"); file = fopen(full_path, "r");
if (!file) { if (!file) {
perror("Error opening file"); perror("Error opening file");
return; return;
} }
} else { } else {
file = fopen(file_path, "r"); file = fopen(file_path, "r");
@@ -1679,7 +1686,7 @@ void override_config(void) {
scroller_focus_center = config.scroller_focus_center; scroller_focus_center = config.scroller_focus_center;
focus_cross_monitor = config.focus_cross_monitor; focus_cross_monitor = config.focus_cross_monitor;
focus_cross_tag = config.focus_cross_tag; 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; snap_distance = config.snap_distance;
enable_floating_snap = config.enable_floating_snap; enable_floating_snap = config.enable_floating_snap;
swipe_min_threshold = config.swipe_min_threshold; swipe_min_threshold = config.swipe_min_threshold;
@@ -1779,7 +1786,7 @@ void set_value_default() {
config.scroller_prefer_center = scroller_prefer_center; config.scroller_prefer_center = scroller_prefer_center;
config.focus_cross_monitor = focus_cross_monitor; config.focus_cross_monitor = focus_cross_monitor;
config.focus_cross_tag = focus_cross_tag; 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.snap_distance = snap_distance;
config.enable_floating_snap = enable_floating_snap; config.enable_floating_snap = enable_floating_snap;
config.swipe_min_threshold = swipe_min_threshold; config.swipe_min_threshold = swipe_min_threshold;

View File

@@ -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 */ /* speedie's maomao config */

View File

@@ -6,10 +6,10 @@ void fibonacci(Monitor *mon, int s) {
unsigned int cur_gappoh = enablegaps ? mon->gappoh : 0; unsigned int cur_gappoh = enablegaps ? mon->gappoh : 0;
unsigned int cur_gappov = enablegaps ? mon->gappov : 0; unsigned int cur_gappov = enablegaps ? mon->gappov : 0;
cur_gappih = smartgaps && mon->visible_clients == 1 ? 0 : cur_gappih; cur_gappih = smartgaps && mon->visible_clients == 1 ? 0 : cur_gappih;
cur_gappiv = smartgaps && mon->visible_clients == 1 ? 0 : cur_gappiv; cur_gappiv = smartgaps && mon->visible_clients == 1 ? 0 : cur_gappiv;
cur_gappoh = smartgaps && mon->visible_clients == 1 ? 0 : cur_gappoh; cur_gappoh = smartgaps && mon->visible_clients == 1 ? 0 : cur_gappoh;
cur_gappov = smartgaps && mon->visible_clients == 1 ? 0 : cur_gappov; cur_gappov = smartgaps && mon->visible_clients == 1 ? 0 : cur_gappov;
// Count visible clients // Count visible clients
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 &&
@@ -31,7 +31,9 @@ void fibonacci(Monitor *mon, int s) {
c->isfullscreen || c->ismaxmizescreen || c->animation.tagouting) c->isfullscreen || c->ismaxmizescreen || c->animation.tagouting)
continue; 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 % 2 && nh / 2 > 2 * c->bw) || (!(i % 2) && nw / 2 > 2 * c->bw)) {
if (i < n - 1) { if (i < n - 1) {
if (i % 2) { if (i % 2) {
@@ -147,7 +149,9 @@ void grid(Monitor *m) {
if (n == 1) { if (n == 1) {
wl_list_for_each(c, &clients, link) { 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 && if (VISIBLEON(c, c->mon) && !c->iskilling && !c->animation.tagouting &&
c->mon == selmon) { c->mon == selmon) {
cw = (m->w.width - 2 * overviewgappo) * 0.7; cw = (m->w.width - 2 * overviewgappo) * 0.7;
@@ -167,7 +171,9 @@ void grid(Monitor *m) {
ch = (m->w.height - 2 * overviewgappo) * 0.65; ch = (m->w.height - 2 * overviewgappo) * 0.65;
i = 0; i = 0;
wl_list_for_each(c, &clients, link) { 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 && if (VISIBLEON(c, c->mon) && !c->iskilling && !c->animation.tagouting &&
c->mon == selmon) { c->mon == selmon) {
if (i == 0) { if (i == 0) {
@@ -211,7 +217,9 @@ void grid(Monitor *m) {
// 调整每个客户端的位置和大小 // 调整每个客户端的位置和大小
i = 0; i = 0;
wl_list_for_each(c, &clients, link) { 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 && if (VISIBLEON(c, c->mon) && !c->iskilling && !c->animation.tagouting &&
c->mon == selmon) { c->mon == selmon) {
cx = m->w.x + (i % cols) * (cw + overviewgappi); 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 cur_gappih = smartgaps && m->visible_clients == 1 ? 0 : cur_gappih;
deck(Monitor *m) cur_gappiv = smartgaps && m->visible_clients == 1 ? 0 : cur_gappiv;
{ cur_gappoh = smartgaps && m->visible_clients == 1 ? 0 : cur_gappoh;
unsigned int mw, my; cur_gappov = smartgaps && m->visible_clients == 1 ? 0 : cur_gappov;
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; wl_list_for_each(c, &clients, link) if (VISIBLEON(c, m) && !c->isfloating &&
cur_gappiv = smartgaps && m->visible_clients == 1 ? 0 : cur_gappiv; !c->isfullscreen) n++;
cur_gappoh = smartgaps && m->visible_clients == 1 ? 0 : cur_gappoh; if (n == 0)
cur_gappov = smartgaps && m->visible_clients == 1 ? 0 : cur_gappov; return;
wl_list_for_each(c, &clients, link) // Calculate master width using mfact from pertag
if (VISIBLEON(c, m) && !c->isfloating && !c->isfullscreen) float mfact = m->pertag ? m->pertag->mfacts[m->pertag->curtag] : m->mfact;
n++;
if (n == 0)
return;
// Calculate master width using mfact from pertag // Calculate master width including outer gaps
float mfact = m->pertag ? m->pertag->mfacts[m->pertag->curtag] : m->mfact; 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 i = my = 0;
if (n > m->nmaster) wl_list_for_each(c, &clients, link) {
mw = m->nmaster ? round((m->w.width - 2 * cur_gappoh) * mfact) : 0; if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen)
else continue;
mw = m->w.width - 2 * cur_gappoh; if (i < m->nmaster) {
// Master area clients
i = my = 0; resize(c,
wl_list_for_each(c, &clients, link) { (struct wlr_box){.x = m->w.x + cur_gappoh,
if (!VISIBLEON(c, m) || c->isfloating || c->isfullscreen) .y = m->w.y + cur_gappov + my,
continue; .width = mw,
if (i < m->nmaster) { .height =
// Master area clients (m->w.height - cur_gappov - my - cur_gappiv) /
resize(c, (struct wlr_box){ (MIN(n, m->nmaster) - i)},
.x = m->w.x + cur_gappoh, 0);
.y = m->w.y + cur_gappov + my, my += c->geom.height + cur_gappiv;
.width = mw, } else {
.height = (m->w.height - cur_gappov - my - cur_gappiv) / (MIN(n, m->nmaster) - i) // Stack area clients
}, 0); resize(c,
my += c->geom.height + cur_gappiv; (struct wlr_box){.x = m->w.x + mw + cur_gappoh + cur_gappih,
} else { .y = m->w.y + cur_gappov,
// Stack area clients .width =
resize(c, (struct wlr_box){ m->w.width - mw - 2 * cur_gappoh - cur_gappih,
.x = m->w.x + mw + cur_gappoh + cur_gappih, .height = m->w.height - 2 * cur_gappov},
.y = m->w.y + cur_gappov, 0);
.width = m->w.width - mw - 2 * cur_gappoh - cur_gappih, if (c == focustop(m))
.height = m->w.height - 2 * cur_gappov wlr_scene_node_raise_to_top(&c->scene->node);
}, 0); }
if (c == focustop(m)) i++;
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_gappoh = enablegaps ? m->gappoh : 0;
unsigned int cur_gappov = enablegaps ? m->gappov : 0; unsigned int cur_gappov = enablegaps ? m->gappov : 0;
cur_gappih = smartgaps && m->visible_clients == 1 ? 0 : cur_gappih; cur_gappih = smartgaps && m->visible_clients == 1 ? 0 : cur_gappih;
cur_gappoh = smartgaps && m->visible_clients == 1 ? 0 : cur_gappoh; cur_gappoh = smartgaps && m->visible_clients == 1 ? 0 : cur_gappoh;
cur_gappov = smartgaps && m->visible_clients == 1 ? 0 : cur_gappov; cur_gappov = smartgaps && m->visible_clients == 1 ? 0 : cur_gappov;
unsigned int max_client_width = unsigned int max_client_width =
m->w.width - 2 * scroller_structs - cur_gappih; 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_gappoh = enablegaps ? m->gappoh : 0;
unsigned int cur_gappov = enablegaps ? m->gappov : 0; unsigned int cur_gappov = enablegaps ? m->gappov : 0;
cur_gappih = smartgaps && m->visible_clients == 1 ? 0 : cur_gappih; cur_gappih = smartgaps && m->visible_clients == 1 ? 0 : cur_gappih;
cur_gappiv = smartgaps && m->visible_clients == 1 ? 0 : cur_gappiv; cur_gappiv = smartgaps && m->visible_clients == 1 ? 0 : cur_gappiv;
cur_gappoh = smartgaps && m->visible_clients == 1 ? 0 : cur_gappoh; cur_gappoh = smartgaps && m->visible_clients == 1 ? 0 : cur_gappoh;
cur_gappov = smartgaps && m->visible_clients == 1 ? 0 : cur_gappov; cur_gappov = smartgaps && m->visible_clients == 1 ? 0 : cur_gappov;
if (n > selmon->pertag->nmasters[selmon->pertag->curtag]) if (n > selmon->pertag->nmasters[selmon->pertag->curtag])
mw = selmon->pertag->nmasters[selmon->pertag->curtag] mw = selmon->pertag->nmasters[selmon->pertag->curtag]
@@ -458,16 +465,16 @@ void tile(Monitor *m) {
else else
mw = m->w.width - 2 * cur_gappov + cur_gappiv * ie; mw = m->w.width - 2 * cur_gappov + cur_gappiv * ie;
i = 0; i = 0;
my = ty =cur_gappoh ; my = ty = cur_gappoh;
wl_list_for_each(c, &clients, link) { wl_list_for_each(c, &clients, link) {
if (!VISIBLEON(c, m) || c->iskilling || c->animation.tagouting || if (!VISIBLEON(c, m) || c->iskilling || c->animation.tagouting ||
c->isfloating || c->isfullscreen || c->ismaxmizescreen) c->isfloating || c->isfullscreen || c->ismaxmizescreen)
continue; continue;
if (i < selmon->pertag->nmasters[selmon->pertag->curtag]) { if (i < selmon->pertag->nmasters[selmon->pertag->curtag]) {
r = MIN(n, selmon->pertag->nmasters[selmon->pertag->curtag]) - i; 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, 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, .y = m->w.y + my,
.width = mw - cur_gappiv * ie, .width = mw - cur_gappiv * ie,
.height = h}, .height = h},
@@ -475,7 +482,7 @@ void tile(Monitor *m) {
my += c->geom.height + cur_gappih * ie; my += c->geom.height + cur_gappih * ie;
} else { } else {
r = n - i; 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, resize(c,
(struct wlr_box){.x = m->w.x + mw + cur_gappov, (struct wlr_box){.x = m->w.x + mw + cur_gappov,
.y = m->w.y + ty, .y = m->w.y + ty,

View File

@@ -717,10 +717,10 @@ struct vec2 *baked_points_close;
static struct wl_event_source *hide_source; static struct wl_event_source *hide_source;
static bool cursor_hidden = false; static bool cursor_hidden = false;
static struct { static struct {
enum wp_cursor_shape_device_v1_shape shape; enum wp_cursor_shape_device_v1_shape shape;
struct wlr_surface *surface; struct wlr_surface *surface;
int hotspot_x; int hotspot_x;
int hotspot_y; int hotspot_y;
} last_cursor; } last_cursor;
#include "config/preset_config.h" #include "config/preset_config.h"
@@ -794,8 +794,8 @@ static struct wlr_xwayland *xwayland;
#include "client/client.h" #include "client/client.h"
#include "config/parse_config.h" #include "config/parse_config.h"
#include "text_input/ime.h"
#include "layout/layout.h" #include "layout/layout.h"
#include "text_input/ime.h"
struct vec2 calculate_animation_curve_at(double t, int type) { struct vec2 calculate_animation_curve_at(double t, int type) {
struct vec2 point; struct vec2 point;
@@ -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; hit_no_border = true;
} }
if(hit_no_border && smartgaps) { if (hit_no_border && smartgaps) {
c->bw = 0; c->bw = 0;
} else if (hit_no_border && !smartgaps) { } else if (hit_no_border && !smartgaps) {
set_rect_size(c->border[0], 0, 0); set_rect_size(c->border[0], 0, 0);
@@ -1100,7 +1100,7 @@ void apply_border(Client *c, struct wlr_box clip_box, int offsetx,
wlr_scene_node_set_position(&c->scene_surface->node, c->bw, c->bw); wlr_scene_node_set_position(&c->scene_surface->node, c->bw, c->bw);
return; return;
} else if(!c->isfullscreen && VISIBLEON(c, c->mon)) { } else if (!c->isfullscreen && VISIBLEON(c, c->mon)) {
c->bw = c->isnoborder ? 0 : borderpx; c->bw = c->isnoborder ? 0 : borderpx;
} }
@@ -1122,31 +1122,32 @@ void apply_border(Client *c, struct wlr_box clip_box, int offsetx,
clip_box.height - 2 * c->bw); clip_box.height - 2 * c->bw);
} else if (c->animation.current.x + c->animation.current.width > } else if (c->animation.current.x + c->animation.current.width >
c->mon->m.x + c->mon->m.width) { c->mon->m.x + c->mon->m.width) {
set_rect_size( set_rect_size(c->border[3],
c->border[3], GEZERO(c->bw - GEZERO(c->animation.current.x +
GEZERO(c->bw - GEZERO(c->animation.current.x + c->animation.current.width - c->animation.current.width -
c->mon->m.x - c->mon->m.width)), c->mon->m.x - c->mon->m.width)),
clip_box.height - 2 * c->bw); 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[0], clip_box.width + c->bw,
set_rect_size( GEZERO(c->bw - offsety));
c->border[1], clip_box.width + c->bw, set_rect_size(c->border[1], clip_box.width + c->bw,
GEZERO(c->bw - GEZERO(c->animation.current.y + c->animation.current.height - GEZERO(c->bw - GEZERO(c->animation.current.y +
c->mon->m.y - c->mon->m.height))); c->animation.current.height -
c->mon->m.y - c->mon->m.height)));
} else if (c->animation.current.y < c->mon->m.y) { } else if (c->animation.current.y < c->mon->m.y) {
set_rect_size(c->border[0], clip_box.width, GEZERO(c->bw - offsety)); set_rect_size(c->border[0], clip_box.width, GEZERO(c->bw - offsety));
} else if (c->animation.current.y + c->animation.current.height > } else if (c->animation.current.y + c->animation.current.height >
c->mon->m.y + c->mon->m.height) { c->mon->m.y + c->mon->m.height) {
set_rect_size( set_rect_size(c->border[1], clip_box.width,
c->border[1], clip_box.width, GEZERO(c->bw - GEZERO(c->animation.current.y +
GEZERO(c->bw - GEZERO(c->animation.current.y + c->animation.current.height - c->animation.current.height -
c->mon->m.y - c->mon->m.height))); c->mon->m.y - c->mon->m.height)));
set_rect_size(c->border[2], GEZERO(c->bw - offsetx), set_rect_size(c->border[2], GEZERO(c->bw - offsetx),
clip_box.height - c->bw); clip_box.height - c->bw);
set_rect_size( set_rect_size(c->border[3],
c->border[3], GEZERO(c->bw - GEZERO(c->animation.current.x +
GEZERO(c->bw - GEZERO(c->animation.current.x + c->animation.current.width - c->animation.current.width -
c->mon->m.x - c->mon->m.width)), c->mon->m.x - c->mon->m.width)),
clip_box.height - c->bw); 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) { c->mon->m.x + c->mon->m.width) {
clip_box->width = clip_box->width - clip_box->width = clip_box->width -
(c->animation.current.x + c->animation.current.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) { 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) { 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->bw; c->mon->m.y - c->mon->m.height) -
c->bw;
} }
} }
offset.x = offsetx; offset.x = offsetx;
offset.y = offsety; 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; c->is_clip_to_hide = true;
wlr_scene_node_set_enabled(&c->scene->node, false); wlr_scene_node_set_enabled(&c->scene->node, false);
} else if (c->is_clip_to_hide && VISIBLEON(c, c->mon)) { } else if (c->is_clip_to_hide && VISIBLEON(c, c->mon)) {
@@ -1758,7 +1762,8 @@ applyrulesgeom(Client *c) {
c->geom.width = r->width > 0 ? r->width : c->geom.width; c->geom.width = r->width > 0 ? r->width : c->geom.width;
c->geom.height = r->height > 0 ? r->height : c->geom.height; 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); c->geom = setclient_coordinate_center(c->geom, r->offsetx, r->offsety);
hit = r->height > 0 || r->width > 0 || r->offsetx != 0 || r->offsety != 0 hit = r->height > 0 || r->width > 0 || r->offsetx != 0 || r->offsety != 0
? 1 ? 1
@@ -1821,8 +1826,10 @@ applyrules(Client *c) {
c->geom.width = r->width > 0 ? r->width : c->geom.width; c->geom.width = r->width > 0 ? r->width : c->geom.width;
c->geom.height = r->height > 0 ? r->height : c->geom.height; 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 ||
c->geom = setclient_coordinate_center(c->geom, r->offsetx, r->offsety); (!client_is_x11(c) || client_surface_wants_focus(c)))
c->geom =
setclient_coordinate_center(c->geom, r->offsetx, r->offsety);
} }
} }
} }
@@ -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 * actually has pointer focus first. If so, we can tell the cursor to
* use the provided cursor shape. */ * use the provided cursor shape. */
if (event->seat_client == seat->pointer_state.focused_client) { if (event->seat_client == seat->pointer_state.focused_client) {
last_cursor.shape = event->shape; last_cursor.shape = event->shape;
last_cursor.surface = NULL; last_cursor.surface = NULL;
if (!cursor_hidden) if (!cursor_hidden)
wlr_cursor_set_xcursor(cursor, cursor_mgr, wlr_cursor_set_xcursor(cursor, cursor_mgr,
wlr_cursor_shape_v1_name(event->shape)); 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) >= if (wl_resource_get_version(ipc_output->resource) >=
ZDWL_IPC_OUTPUT_V2_FLOATING_SINCE_VERSION) { ZDWL_IPC_OUTPUT_V2_FLOATING_SINCE_VERSION) {
zdwl_ipc_output_v2_send_x(ipc_output->resource, 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) >= if (wl_resource_get_version(ipc_output->resource) >=
ZDWL_IPC_OUTPUT_V2_FLOATING_SINCE_VERSION) { ZDWL_IPC_OUTPUT_V2_FLOATING_SINCE_VERSION) {
zdwl_ipc_output_v2_send_y(ipc_output->resource, 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) >= if (wl_resource_get_version(ipc_output->resource) >=
ZDWL_IPC_OUTPUT_V2_FLOATING_SINCE_VERSION) { ZDWL_IPC_OUTPUT_V2_FLOATING_SINCE_VERSION) {
zdwl_ipc_output_v2_send_width(ipc_output->resource, 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) >= if (wl_resource_get_version(ipc_output->resource) >=
ZDWL_IPC_OUTPUT_V2_FLOATING_SINCE_VERSION) { ZDWL_IPC_OUTPUT_V2_FLOATING_SINCE_VERSION) {
zdwl_ipc_output_v2_send_height(ipc_output->resource, 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); 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) if (c && c->animation.tagouting && !c->animation.tagouting)
return; return;
if(c && client_is_x11(c) && !client_surface_wants_focus(c)) { if (c && client_is_x11(c) && !client_surface_wants_focus(c)) {
return; return;
} }
@@ -4303,7 +4310,7 @@ mapnotify(struct wl_listener *listener, void *data) {
client_get_geometry(c, &c->geom); 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->bw = 0;
c->isnoborder = 1; c->isnoborder = 1;
} else { } 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 * 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 * hardware cursor on the output that it's currently on and continue to
* do so as the cursor moves between outputs. */ * do so as the cursor moves between outputs. */
if (event->seat_client == seat->pointer_state.focused_client) { if (event->seat_client == seat->pointer_state.focused_client) {
last_cursor.shape = 0; last_cursor.shape = 0;
last_cursor.surface = event->surface; last_cursor.surface = event->surface;
last_cursor.hotspot_x = event->hotspot_x; last_cursor.hotspot_x = event->hotspot_x;
last_cursor.hotspot_y = event->hotspot_y; last_cursor.hotspot_y = event->hotspot_y;
if (!cursor_hidden) if (!cursor_hidden)
wlr_cursor_set_surface(cursor, event->surface, wlr_cursor_set_surface(cursor, event->surface, event->hotspot_x,
event->hotspot_x, event->hotspot_y); event->hotspot_y);
} }
} }
void // 0.5 void // 0.5
@@ -5330,7 +5337,7 @@ setfloating(Client *c, int floating) {
target_box.width = target_box.width * 0.8; 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); target_box = setclient_coordinate_center(target_box, 0, 0);
backup_box = c->geom; backup_box = c->geom;
hit = applyrulesgeom(c); hit = applyrulesgeom(c);
@@ -5952,7 +5959,7 @@ void setup(void) {
wl_signal_add(&cursor_shape_mgr->events.request_set_shape, wl_signal_add(&cursor_shape_mgr->events.request_set_shape,
&request_set_cursor_shape); &request_set_cursor_shape);
hide_source = wl_event_loop_add_timer(wl_display_get_event_loop(dpy), 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 * 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); } void overview(Monitor *m) { grid(m); }
// 目标窗口有其他窗口和它同个tag就返回0 // 目标窗口有其他窗口和它同个tag就返回0
unsigned int want_restore_fullscreen(Client *target_client) { unsigned int want_restore_fullscreen(Client *target_client) {
Client *c = NULL; Client *c = NULL;
@@ -6219,8 +6224,7 @@ void overview_restore(Client *c, const Arg *arg) {
} }
} }
if (c->bw == 0 && if (c->bw == 0 && !c->isfullscreen) { // 如果是在ov模式中创建的窗口,没有bw记录
!c->isfullscreen) { // 如果是在ov模式中创建的窗口,没有bw记录
c->bw = c->isnoborder ? 0 : borderpx; c->bw = c->isnoborder ? 0 : borderpx;
} }
} }
@@ -6271,30 +6275,26 @@ void set_proportion(const Arg *arg) {
} }
} }
void void handlecursoractivity(void) {
handlecursoractivity(void) wl_event_source_timer_update(hide_source, cursor_hide_timeout * 1000);
{
wl_event_source_timer_update(hide_source, cursor_hide_timeout * 1000);
if (!cursor_hidden) if (!cursor_hidden)
return; return;
cursor_hidden = false; cursor_hidden = false;
if (last_cursor.shape) if (last_cursor.shape)
wlr_cursor_set_xcursor(cursor, cursor_mgr, wlr_cursor_set_xcursor(cursor, cursor_mgr,
wlr_cursor_shape_v1_name(last_cursor.shape)); wlr_cursor_shape_v1_name(last_cursor.shape));
else else
wlr_cursor_set_surface(cursor, last_cursor.surface, wlr_cursor_set_surface(cursor, last_cursor.surface, last_cursor.hotspot_x,
last_cursor.hotspot_x, last_cursor.hotspot_y); last_cursor.hotspot_y);
} }
int int hidecursor(void *data) {
hidecursor(void *data) wlr_cursor_unset_image(cursor);
{ cursor_hidden = true;
wlr_cursor_unset_image(cursor); return 1;
cursor_hidden = true;
return 1;
} }
void increase_proportion(const Arg *arg) { void increase_proportion(const Arg *arg) {
@@ -6362,7 +6362,6 @@ void toggleoverview(const Arg *arg) {
} }
} }
void togglefloating(const Arg *arg) { void togglefloating(const Arg *arg) {
Client *sel = focustop(selmon); Client *sel = focustop(selmon);