format code

This commit is contained in:
DreamMaoMao 2025-05-07 17:40:27 +08:00
parent bb0e360f27
commit 2a60dd433b
2 changed files with 344 additions and 311 deletions

View file

@ -89,8 +89,8 @@ typedef struct {
} GestureBinding; } GestureBinding;
typedef struct { typedef struct {
int id; // 标签ID (1-9) int id; // 标签ID (1-9)
char* layout_name; // 布局名称 char *layout_name; // 布局名称
int no_render_border; int no_render_border;
} ConfigTagRule; } ConfigTagRule;
@ -177,8 +177,8 @@ typedef struct {
char autostart[3][256]; char autostart[3][256];
ConfigTagRule *tag_rules; // 动态数组 ConfigTagRule *tag_rules; // 动态数组
int tag_rules_count; // 数量 int tag_rules_count; // 数量
ConfigWinRule *window_rules; ConfigWinRule *window_rules;
int window_rules_count; int window_rules_count;
@ -420,16 +420,17 @@ void convert_hex_to_rgba(float *color, unsigned long int hex) {
unsigned int parse_num_type(char *str) { unsigned int parse_num_type(char *str) {
switch (str[0]) { switch (str[0]) {
case '-': case '-':
return NUM_TYPE_MINUS; return NUM_TYPE_MINUS;
case '+': case '+':
return NUM_TYPE_PLUS; return NUM_TYPE_PLUS;
default: default:
return NUM_TYPE_DEFAULT; return NUM_TYPE_DEFAULT;
} }
} }
FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value, char *arg_value2, char *arg_value3, char *arg_value4) { FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value,
char *arg_value2, char *arg_value3, char *arg_value4) {
FuncType func = NULL; FuncType func = NULL;
(*arg).v = NULL; (*arg).v = NULL;
@ -557,14 +558,18 @@ FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value, char *arg_v
func = resizewin; func = resizewin;
(*arg).ui = parse_num_type(arg_value); (*arg).ui = parse_num_type(arg_value);
(*arg).ui2 = parse_num_type(arg_value2); (*arg).ui2 = parse_num_type(arg_value2);
(*arg).i = (*arg).ui == NUM_TYPE_DEFAULT ? atoi(arg_value) : atoi(arg_value+1); (*arg).i =
(*arg).i2 = (*arg).ui2 == NUM_TYPE_DEFAULT ? atoi(arg_value2) : atoi(arg_value2+1); (*arg).ui == NUM_TYPE_DEFAULT ? atoi(arg_value) : atoi(arg_value + 1);
(*arg).i2 = (*arg).ui2 == NUM_TYPE_DEFAULT ? atoi(arg_value2)
: atoi(arg_value2 + 1);
} else if (strcmp(func_name, "movewin") == 0) { } else if (strcmp(func_name, "movewin") == 0) {
func = movewin; func = movewin;
(*arg).ui = parse_num_type(arg_value); (*arg).ui = parse_num_type(arg_value);
(*arg).ui2 = parse_num_type(arg_value2); (*arg).ui2 = parse_num_type(arg_value2);
(*arg).i = (*arg).ui == NUM_TYPE_DEFAULT ? atoi(arg_value) : atoi(arg_value+1); (*arg).i =
(*arg).i2 = (*arg).ui2 == NUM_TYPE_DEFAULT ? atoi(arg_value2) : atoi(arg_value2+1); (*arg).ui == NUM_TYPE_DEFAULT ? atoi(arg_value) : atoi(arg_value + 1);
(*arg).i2 = (*arg).ui2 == NUM_TYPE_DEFAULT ? atoi(arg_value2)
: atoi(arg_value2 + 1);
} else if (strcmp(func_name, "toggle_named_scratch") == 0) { } else if (strcmp(func_name, "toggle_named_scratch") == 0) {
func = toggle_named_scratch; func = toggle_named_scratch;
(*arg).v = strdup(arg_value); (*arg).v = strdup(arg_value);
@ -580,7 +585,7 @@ FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value, char *arg_v
void run_exec() { void run_exec() {
Arg arg; Arg arg;
for(int i = 0; i < config.exec_count; i++) { for (int i = 0; i < config.exec_count; i++) {
arg.v = config.exec[i]; arg.v = config.exec[i];
spawn(&arg); spawn(&arg);
} }
@ -589,7 +594,7 @@ void run_exec() {
void run_exec_once() { void run_exec_once() {
Arg arg; Arg arg;
for(int i = 0; i < config.exec_once_count; i++) { for (int i = 0; i < config.exec_once_count; i++) {
arg.v = config.exec_once[i]; arg.v = config.exec_once[i];
spawn(&arg); spawn(&arg);
} }
@ -917,11 +922,12 @@ void parse_config_line(Config *config, const char *line) {
fprintf(stderr, "Error: Invalid autostart format: %s\n", value); fprintf(stderr, "Error: Invalid autostart format: %s\n", value);
} }
} else if (strcmp(key, "tags") == 0) { } else if (strcmp(key, "tags") == 0) {
config->tag_rules = realloc(config->tag_rules, config->tag_rules =
(config->tag_rules_count + 1) * sizeof(ConfigTagRule)); realloc(config->tag_rules,
(config->tag_rules_count + 1) * sizeof(ConfigTagRule));
if (!config->tag_rules) { if (!config->tag_rules) {
fprintf(stderr, "Error: Failed to allocate memory for tag rules\n"); fprintf(stderr, "Error: Failed to allocate memory for tag rules\n");
return; return;
} }
ConfigTagRule *rule = &config->tag_rules[config->tag_rules_count]; ConfigTagRule *rule = &config->tag_rules[config->tag_rules_count];
@ -933,21 +939,21 @@ void parse_config_line(Config *config, const char *line) {
char *token = strtok(value, ","); char *token = strtok(value, ",");
while (token != NULL) { while (token != NULL) {
char *colon = strchr(token, ':'); char *colon = strchr(token, ':');
if (colon != NULL) { if (colon != NULL) {
*colon = '\0'; *colon = '\0';
char *key = token; char *key = token;
char *val = colon + 1; char *val = colon + 1;
if (strcmp(key, "id") == 0) { if (strcmp(key, "id") == 0) {
rule->id = atoi(val); rule->id = atoi(val);
} else if (strcmp(key, "layout_name") == 0) { } else if (strcmp(key, "layout_name") == 0) {
rule->layout_name = strdup(val); rule->layout_name = strdup(val);
} else if (strcmp(key, "no_render_border") == 0) { } else if (strcmp(key, "no_render_border") == 0) {
rule->no_render_border = atoi(val); rule->no_render_border = atoi(val);
}
} }
token = strtok(NULL, ","); }
token = strtok(NULL, ",");
} }
config->tag_rules_count++; config->tag_rules_count++;
@ -1078,41 +1084,43 @@ void parse_config_line(Config *config, const char *line) {
} else if (strncmp(key, "env", 3) == 0) { } else if (strncmp(key, "env", 3) == 0) {
char env_type[256], env_value[256]; char env_type[256], env_value[256];
if (sscanf(value, "%[^,],%[^\n]", env_type,env_value) < 2) { if (sscanf(value, "%[^,],%[^\n]", env_type, env_value) < 2) {
fprintf(stderr, "Error: Invalid bind format: %s\n", value); fprintf(stderr, "Error: Invalid bind format: %s\n", value);
return; return;
} }
setenv(env_type, env_value, 1); setenv(env_type, env_value, 1);
} else if (strncmp(key, "exec", 9) == 0) { } else if (strncmp(key, "exec", 9) == 0) {
char **new_exec = realloc(config->exec, (config->exec_count + 1) * sizeof(char *)); char **new_exec =
realloc(config->exec, (config->exec_count + 1) * sizeof(char *));
if (!new_exec) { if (!new_exec) {
fprintf(stderr, "Error: Failed to allocate memory for exec\n"); fprintf(stderr, "Error: Failed to allocate memory for exec\n");
return; return;
} }
config->exec = new_exec; config->exec = new_exec;
config->exec[config->exec_count] = strdup(value); config->exec[config->exec_count] = strdup(value);
if (!config->exec[config->exec_count]) { if (!config->exec[config->exec_count]) {
fprintf(stderr, "Error: Failed to duplicate exec string\n"); fprintf(stderr, "Error: Failed to duplicate exec string\n");
return; return;
} }
config->exec_count++; config->exec_count++;
} else if (strncmp(key, "exec-once", 9) == 0) { } else if (strncmp(key, "exec-once", 9) == 0) {
char **new_exec_once = realloc(config->exec_once, (config->exec_once_count + 1) * sizeof(char *)); char **new_exec_once = realloc(
config->exec_once, (config->exec_once_count + 1) * sizeof(char *));
if (!new_exec_once) { if (!new_exec_once) {
fprintf(stderr, "Error: Failed to allocate memory for exec_once\n"); fprintf(stderr, "Error: Failed to allocate memory for exec_once\n");
return; return;
} }
config->exec_once = new_exec_once; config->exec_once = new_exec_once;
config->exec_once[config->exec_once_count] = strdup(value); config->exec_once[config->exec_once_count] = strdup(value);
if (!config->exec_once[config->exec_once_count]) { if (!config->exec_once[config->exec_once_count]) {
fprintf(stderr, "Error: Failed to duplicate exec_once string\n"); fprintf(stderr, "Error: Failed to duplicate exec_once string\n");
return; return;
} }
config->exec_once_count++; config->exec_once_count++;
@ -1129,9 +1137,12 @@ void parse_config_line(Config *config, const char *line) {
KeyBinding *binding = &config->key_bindings[config->key_bindings_count]; KeyBinding *binding = &config->key_bindings[config->key_bindings_count];
memset(binding, 0, sizeof(KeyBinding)); memset(binding, 0, sizeof(KeyBinding));
char mod_str[256], keysym_str[256], func_name[256], arg_value[256] = "none",arg_value2[256] = "none", arg_value3[256] = "none", arg_value4[256] = "none"; char mod_str[256], keysym_str[256], func_name[256],
if (sscanf(value, "%[^,],%[^,],%[^,],%[^,],%[^,],%[^,],%[^\n]", mod_str, keysym_str, arg_value[256] = "none", arg_value2[256] = "none",
func_name, arg_value, arg_value2, arg_value3, arg_value4) < 3) { arg_value3[256] = "none", arg_value4[256] = "none";
if (sscanf(value, "%[^,],%[^,],%[^,],%[^,],%[^,],%[^,],%[^\n]", mod_str,
keysym_str, func_name, arg_value, arg_value2, arg_value3,
arg_value4) < 3) {
fprintf(stderr, "Error: Invalid bind format: %s\n", value); fprintf(stderr, "Error: Invalid bind format: %s\n", value);
return; return;
} }
@ -1140,7 +1151,8 @@ void parse_config_line(Config *config, const char *line) {
binding->keysym = parse_keysym(keysym_str); binding->keysym = parse_keysym(keysym_str);
binding->arg.v = NULL; binding->arg.v = NULL;
binding->arg.v2 = NULL; binding->arg.v2 = NULL;
binding->func = parse_func_name(func_name, &binding->arg, arg_value, arg_value2, arg_value3, arg_value4); binding->func = parse_func_name(func_name, &binding->arg, arg_value,
arg_value2, arg_value3, arg_value4);
if (!binding->func) { if (!binding->func) {
if (binding->arg.v) { if (binding->arg.v) {
free(binding->arg.v); free(binding->arg.v);
@ -1168,9 +1180,12 @@ void parse_config_line(Config *config, const char *line) {
&config->mouse_bindings[config->mouse_bindings_count]; &config->mouse_bindings[config->mouse_bindings_count];
memset(binding, 0, sizeof(MouseBinding)); memset(binding, 0, sizeof(MouseBinding));
char mod_str[256], button_str[256], func_name[256], arg_value[256] = "none", arg_value2[256] = "none", arg_value3[256] = "none", arg_value4[256] = "none"; char mod_str[256], button_str[256], func_name[256],
if (sscanf(value, "%[^,],%[^,],%[^,],%[^,],%[^,],%[^,],%[^\n]", mod_str, button_str, arg_value[256] = "none", arg_value2[256] = "none",
func_name, arg_value, arg_value2, arg_value3, arg_value4) < 3) { arg_value3[256] = "none", arg_value4[256] = "none";
if (sscanf(value, "%[^,],%[^,],%[^,],%[^,],%[^,],%[^,],%[^\n]", mod_str,
button_str, func_name, arg_value, arg_value2, arg_value3,
arg_value4) < 3) {
fprintf(stderr, "Error: Invalid mousebind format: %s\n", value); fprintf(stderr, "Error: Invalid mousebind format: %s\n", value);
return; return;
} }
@ -1179,7 +1194,8 @@ void parse_config_line(Config *config, const char *line) {
binding->button = parse_button(button_str); binding->button = parse_button(button_str);
binding->arg.v = NULL; binding->arg.v = NULL;
binding->arg.v2 = NULL; binding->arg.v2 = NULL;
binding->func = parse_func_name(func_name, &binding->arg, arg_value, arg_value2, arg_value3, arg_value4); binding->func = parse_func_name(func_name, &binding->arg, arg_value,
arg_value2, arg_value3, arg_value4);
if (!binding->func) { if (!binding->func) {
if (binding->arg.v) { if (binding->arg.v) {
free(binding->arg.v); free(binding->arg.v);
@ -1205,9 +1221,12 @@ void parse_config_line(Config *config, const char *line) {
AxisBinding *binding = &config->axis_bindings[config->axis_bindings_count]; AxisBinding *binding = &config->axis_bindings[config->axis_bindings_count];
memset(binding, 0, sizeof(AxisBinding)); memset(binding, 0, sizeof(AxisBinding));
char mod_str[256], dir_str[256], func_name[256], arg_value[256] = "none", arg_value2[256] = "none", arg_value3[256] = "none", arg_value4[256] = "none"; char mod_str[256], dir_str[256], func_name[256],
if (sscanf(value, "%[^,],%[^,],%[^,],%[^,],%[^,],%[^,],%[^\n]", mod_str, dir_str, func_name, arg_value[256] = "none", arg_value2[256] = "none",
arg_value, arg_value2, arg_value3, arg_value4) < 3) { arg_value3[256] = "none", arg_value4[256] = "none";
if (sscanf(value, "%[^,],%[^,],%[^,],%[^,],%[^,],%[^,],%[^\n]", mod_str,
dir_str, func_name, arg_value, arg_value2, arg_value3,
arg_value4) < 3) {
fprintf(stderr, "Error: Invalid axisbind format: %s\n", value); fprintf(stderr, "Error: Invalid axisbind format: %s\n", value);
return; return;
} }
@ -1216,7 +1235,8 @@ void parse_config_line(Config *config, const char *line) {
binding->dir = parse_direction(dir_str); binding->dir = parse_direction(dir_str);
binding->arg.v = NULL; binding->arg.v = NULL;
binding->arg.v2 = NULL; binding->arg.v2 = NULL;
binding->func = parse_func_name(func_name, &binding->arg, arg_value, arg_value2, arg_value3, arg_value4); binding->func = parse_func_name(func_name, &binding->arg, arg_value,
arg_value2, arg_value3, arg_value4);
if (!binding->func) { if (!binding->func) {
if (binding->arg.v) { if (binding->arg.v) {
@ -1247,9 +1267,11 @@ void parse_config_line(Config *config, const char *line) {
memset(binding, 0, sizeof(GestureBinding)); memset(binding, 0, sizeof(GestureBinding));
char mod_str[256], motion_str[256], fingers_count_str[256], func_name[256], char mod_str[256], motion_str[256], fingers_count_str[256], func_name[256],
arg_value[256] = "none", arg_value2[256] = "none", arg_value3[256] = "none", arg_value4[256] = "none"; arg_value[256] = "none", arg_value2[256] = "none",
if (sscanf(value, "%[^,],%[^,],%[^,],%[^,],%[^,],%[^,],%[^,],%[^\n]", mod_str, motion_str, arg_value3[256] = "none", arg_value4[256] = "none";
fingers_count_str, func_name, arg_value, arg_value2, arg_value3, arg_value4) < 4) { if (sscanf(value, "%[^,],%[^,],%[^,],%[^,],%[^,],%[^,],%[^,],%[^\n]",
mod_str, motion_str, fingers_count_str, func_name, arg_value,
arg_value2, arg_value3, arg_value4) < 4) {
fprintf(stderr, "Error: Invalid gesturebind format: %s\n", value); fprintf(stderr, "Error: Invalid gesturebind format: %s\n", value);
return; return;
} }
@ -1259,7 +1281,8 @@ void parse_config_line(Config *config, const char *line) {
binding->fingers_count = atoi(fingers_count_str); binding->fingers_count = atoi(fingers_count_str);
binding->arg.v = NULL; binding->arg.v = NULL;
binding->arg.v2 = NULL; binding->arg.v2 = NULL;
binding->func = parse_func_name(func_name, &binding->arg, arg_value, arg_value2, arg_value3, arg_value4); binding->func = parse_func_name(func_name, &binding->arg, arg_value,
arg_value2, arg_value3, arg_value4);
if (!binding->func) { if (!binding->func) {
if (binding->arg.v) { if (binding->arg.v) {
@ -1471,7 +1494,7 @@ void free_config(void) {
config.scroller_proportion_preset_count = 0; config.scroller_proportion_preset_count = 0;
} }
if(config.cursor_theme) { if (config.cursor_theme) {
free(config.cursor_theme); free(config.cursor_theme);
config.cursor_theme = NULL; config.cursor_theme = NULL;
} }
@ -1481,7 +1504,6 @@ void free_config(void) {
// 释放动画资源 // 释放动画资源
free_baked_points(); free_baked_points();
} }
void override_config(void) { void override_config(void) {
@ -1769,7 +1791,7 @@ void reload_config(const Arg *arg) {
} }
} }
// reset keyboard repeat rate when config change // reset keyboard repeat rate when config change
wl_list_for_each(kb, &keyboards, link) { wl_list_for_each(kb, &keyboards, link) {
wlr_keyboard_set_repeat_info(kb->wlr_keyboard, repeat_rate, repeat_delay); wlr_keyboard_set_repeat_info(kb->wlr_keyboard, repeat_rate, repeat_delay);
} }
@ -1800,7 +1822,8 @@ void reload_config(const Arg *arg) {
if (i > 0 && strlen(config.tag_rules[i - 1].layout_name) > 0) { if (i > 0 && strlen(config.tag_rules[i - 1].layout_name) > 0) {
for (jk = 0; jk < LENGTH(layouts); jk++) { for (jk = 0; jk < LENGTH(layouts); jk++) {
if (strcmp(layouts[jk].name, config.tag_rules[i - 1].layout_name) == 0) { if (strcmp(layouts[jk].name, config.tag_rules[i - 1].layout_name) ==
0) {
m->pertag->ltidxs[i] = &layouts[jk]; m->pertag->ltidxs[i] = &layouts[jk];
} }
} }

View file

@ -203,8 +203,8 @@ typedef struct Client Client;
struct Client { struct Client {
/* Must keep these three elements in this order */ /* Must keep these three elements in this order */
unsigned int type; /* XDGShell or X11* */ unsigned int type; /* XDGShell or X11* */
struct wlr_box geom, pending, oldgeom,scratch_geom, animainit_geom, overview_backup_geom, struct wlr_box geom, pending, oldgeom, scratch_geom, animainit_geom,
current; /* layout-relative, includes border */ overview_backup_geom, current; /* layout-relative, includes border */
Monitor *mon; Monitor *mon;
struct wlr_scene_tree *scene; struct wlr_scene_tree *scene;
struct wlr_scene_rect *border[4]; /* top, bottom, left, right */ struct wlr_scene_rect *border[4]; /* top, bottom, left, right */
@ -421,7 +421,7 @@ arrange(Monitor *m,
static void arrangelayer(Monitor *m, struct wl_list *list, static void arrangelayer(Monitor *m, struct wl_list *list,
struct wlr_box *usable_area, int exclusive); struct wlr_box *usable_area, int exclusive);
static void arrangelayers(Monitor *m); static void arrangelayers(Monitor *m);
static char* get_autostart_path(char*, size_t); // 自启动命令执行 static char *get_autostart_path(char *, size_t); // 自启动命令执行
static void axisnotify(struct wl_listener *listener, static void axisnotify(struct wl_listener *listener,
void *data); // 滚轮事件处理 void *data); // 滚轮事件处理
static void buttonpress(struct wl_listener *listener, static void buttonpress(struct wl_listener *listener,
@ -496,12 +496,10 @@ static void dwl_ipc_output_set_tags(struct wl_client *client,
static void dwl_ipc_output_quit(struct wl_client *client, static void dwl_ipc_output_quit(struct wl_client *client,
struct wl_resource *resource); struct wl_resource *resource);
static void dwl_ipc_output_dispatch(struct wl_client *client, static void dwl_ipc_output_dispatch(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *resource,
const char *dispatch, const char *dispatch, const char *arg1,
const char* arg1, const char *arg2, const char *arg3,
const char* arg2, const char *arg4);
const char* arg3,
const char* arg4);
static void dwl_ipc_output_release(struct wl_client *client, static void dwl_ipc_output_release(struct wl_client *client,
struct wl_resource *resource); struct wl_resource *resource);
static void focusclient(Client *c, int lift); static void focusclient(Client *c, int lift);
@ -1058,15 +1056,15 @@ void apply_border(Client *c, struct wlr_box clip_box, int offsetx,
if (c->iskilling || !client_surface(c)->mapped) if (c->iskilling || !client_surface(c)->mapped)
return; return;
if(clip_box.width > c->animation.current.width) { if (clip_box.width > c->animation.current.width) {
clip_box.width = c->animation.current.width; clip_box.width = c->animation.current.width;
} }
if(clip_box.height > c->animation.current.height) { if (clip_box.height > c->animation.current.height) {
clip_box.height = c->animation.current.height; clip_box.height = c->animation.current.height;
} }
if(!render_border) { if (!render_border) {
set_rect_size(c->border[0], 0, 0); set_rect_size(c->border[0], 0, 0);
set_rect_size(c->border[1], 0, 0); set_rect_size(c->border[1], 0, 0);
set_rect_size(c->border[2], 0, 0); set_rect_size(c->border[2], 0, 0);
@ -1074,8 +1072,9 @@ void apply_border(Client *c, struct wlr_box clip_box, int offsetx,
return; return;
} }
for(i=0;i< config.tag_rules_count;i++) { for (i = 0; i < config.tag_rules_count; i++) {
if(c->tags & (1 << (config.tag_rules[i].id - 1)) && config.tag_rules[i].no_render_border) { if (c->tags & (1 << (config.tag_rules[i].id - 1)) &&
config.tag_rules[i].no_render_border) {
set_rect_size(c->border[0], 0, 0); set_rect_size(c->border[0], 0, 0);
set_rect_size(c->border[1], 0, 0); set_rect_size(c->border[1], 0, 0);
set_rect_size(c->border[2], 0, 0); set_rect_size(c->border[2], 0, 0);
@ -1102,21 +1101,28 @@ 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(c->border[3], GEZERO(c->bw - (c->animation.current.x + c->animation.current.width - c->mon->m.x + c->mon->m.width)), set_rect_size(
clip_box.height - 2 * c->bw); c->border[3],
GEZERO(c->bw - (c->animation.current.x + c->animation.current.width -
c->mon->m.x + c->mon->m.width)),
clip_box.height - 2 * c->bw);
} 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(c->border[1], clip_box.width, GEZERO(c->bw - (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 - (c->animation.current.y + c->animation.current.height -
c->mon->m.y + c->mon->m.height)));
} }
} }
wlr_scene_node_set_position(&c->border[0]->node, offsetx, offsety); wlr_scene_node_set_position(&c->border[0]->node, offsetx, offsety);
wlr_scene_node_set_position(&c->border[2]->node, offsetx, c->bw + offsety); wlr_scene_node_set_position(&c->border[2]->node, offsetx, c->bw + offsety);
wlr_scene_node_set_position(&c->border[1]->node, offsetx, clip_box.height - c->bw + offsety); wlr_scene_node_set_position(&c->border[1]->node, offsetx,
wlr_scene_node_set_position(&c->border[3]->node, clip_box.width - c->bw + offsetx, clip_box.height - c->bw + offsety);
c->bw + offsety); wlr_scene_node_set_position(
&c->border[3]->node, clip_box.width - c->bw + offsetx, c->bw + offsety);
} }
struct uvec2 clip_to_hide(Client *c, struct wlr_box *clip_box) { struct uvec2 clip_to_hide(Client *c, struct wlr_box *clip_box) {
@ -1169,11 +1175,11 @@ struct uvec2 clip_to_hide(Client *c, struct wlr_box *clip_box) {
wlr_scene_node_set_enabled(&c->scene->node, true); wlr_scene_node_set_enabled(&c->scene->node, true);
} }
if(clip_box->width > c->animation.current.width) { if (clip_box->width > c->animation.current.width) {
clip_box->width = c->animation.current.width; clip_box->width = c->animation.current.width;
} }
if(clip_box->height > c->animation.current.height) { if (clip_box->height > c->animation.current.height) {
clip_box->height = c->animation.current.height; clip_box->height = c->animation.current.height;
} }
@ -1341,23 +1347,30 @@ void show_scratchpad(Client *c) {
c->bw = borderpx; // 恢复非全屏的border c->bw = borderpx; // 恢复非全屏的border
} }
if(c->oldgeom.width) if (c->oldgeom.width)
c->scratch_geom.width = c->oldgeom.width; c->scratch_geom.width = c->oldgeom.width;
if(c->oldgeom.height) if (c->oldgeom.height)
c->scratch_geom.height = c->oldgeom.height; c->scratch_geom.height = c->oldgeom.height;
/* return if fullscreen */ /* return if fullscreen */
if (!c->isfloating) { if (!c->isfloating) {
setfloating(c, 1); setfloating(c, 1);
c->geom.width = c->scratch_geom.width ? c->scratch_geom.width: c->mon->w.width * 0.7; c->geom.width =
c->geom.height = c->scratch_geom.height? c->scratch_geom.height : c->mon->w.height * 0.8; c->scratch_geom.width ? c->scratch_geom.width : c->mon->w.width * 0.7;
c->geom.height = c->scratch_geom.height ? c->scratch_geom.height
: c->mon->w.height * 0.8;
// 重新计算居中的坐标 // 重新计算居中的坐标
c->geom = c->animainit_geom = c->animation.current = setclient_coordinate_center(c->geom, 0, 0); c->geom = c->animainit_geom = c->animation.current =
setclient_coordinate_center(c->geom, 0, 0);
resize(c, c->geom, 0); resize(c, c->geom, 0);
} else if(c->geom.width != c->scratch_geom.width || c->geom.height != c->scratch_geom.height) { } else if (c->geom.width != c->scratch_geom.width ||
c->geom.width = c->scratch_geom.width ? c->scratch_geom.width: c->mon->w.width * 0.7; c->geom.height != c->scratch_geom.height) {
c->geom.height = c->scratch_geom.height? c->scratch_geom.height : c->mon->w.height * 0.8; c->geom.width =
c->geom = c->animainit_geom = c->animation.current = setclient_coordinate_center(c->geom, 0, 0); c->scratch_geom.width ? c->scratch_geom.width : c->mon->w.width * 0.7;
c->geom.height = c->scratch_geom.height ? c->scratch_geom.height
: c->mon->w.height * 0.8;
c->geom = c->animainit_geom = c->animation.current =
setclient_coordinate_center(c->geom, 0, 0);
resize(c, c->geom, 0); resize(c, c->geom, 0);
} }
c->oldtags = selmon->tagset[selmon->seltags]; c->oldtags = selmon->tagset[selmon->seltags];
@ -1528,8 +1541,8 @@ void toggle_named_scratch(const Arg *arg) {
(arg_id && strstr(appid, arg_id) && !arg_title) || (arg_id && strstr(appid, arg_id) && !arg_title) ||
(arg_id && strstr(appid, arg_id) && arg_title && (arg_id && strstr(appid, arg_id) && arg_title &&
strstr(title, arg_title))) { strstr(title, arg_title))) {
target_client = c; target_client = c;
break; break;
} }
} }
@ -1540,7 +1553,7 @@ void toggle_named_scratch(const Arg *arg) {
if (c->mon != selmon) { if (c->mon != selmon) {
continue; continue;
} }
if(c->is_in_scratchpad && c->is_scratchpad_show && c != target_client) { if (c->is_in_scratchpad && c->is_scratchpad_show && c != target_client) {
set_minized(c); set_minized(c);
} }
} }
@ -1548,7 +1561,7 @@ void toggle_named_scratch(const Arg *arg) {
target_client->scratch_geom.width = arg->ui; target_client->scratch_geom.width = arg->ui;
target_client->scratch_geom.height = arg->ui2; target_client->scratch_geom.height = arg->ui2;
if(!target_client->is_in_scratchpad) if (!target_client->is_in_scratchpad)
set_minized(target_client); set_minized(target_client);
else else
switch_scratch_client_state(target_client); switch_scratch_client_state(target_client);
@ -1561,8 +1574,8 @@ void toggle_scratchpad(const Arg *arg) {
if (c->mon != selmon) { if (c->mon != selmon) {
continue; continue;
} }
hit =switch_scratch_client_state(c); hit = switch_scratch_client_state(c);
if(hit) if (hit)
break; break;
} }
} }
@ -1593,13 +1606,12 @@ void gpureset(struct wl_listener *listener, void *data) {
wlr_renderer_destroy(old_drw); wlr_renderer_destroy(old_drw);
} }
void void handlesig(int signo) {
handlesig(int signo) if (signo == SIGCHLD)
{ while (waitpid(-1, NULL, WNOHANG) > 0)
if (signo == SIGCHLD) ;
while (waitpid(-1, NULL, WNOHANG) > 0); else if (signo == SIGINT || signo == SIGTERM)
else if (signo == SIGINT || signo == SIGTERM) quit(NULL);
quit(NULL);
} }
void toggle_hotarea(int x_root, int y_root) { void toggle_hotarea(int x_root, int y_root) {
@ -1752,8 +1764,10 @@ applyrules(Client *c) {
strstr(title, r->title))) { strstr(title, r->title))) {
c->isterm = r->isterm > 0 ? r->isterm : c->isterm; c->isterm = r->isterm > 0 ? r->isterm : c->isterm;
c->noswallow = r->noswallow > 0 ? r->noswallow : c->noswallow; c->noswallow = r->noswallow > 0 ? r->noswallow : c->noswallow;
c->scratch_geom.width = r->scratch_width > 0 ? r->scratch_width : c->scratch_geom.width; c->scratch_geom.width =
c->scratch_geom.height = r->scratch_height > 0 ? r->scratch_height : c->scratch_geom.height; r->scratch_width > 0 ? r->scratch_width : c->scratch_geom.width;
c->scratch_geom.height =
r->scratch_height > 0 ? r->scratch_height : c->scratch_geom.height;
c->isfloating = r->isfloating > 0 ? r->isfloating : c->isfloating; c->isfloating = r->isfloating > 0 ? r->isfloating : c->isfloating;
c->isfullscreen = r->isfullscreen > 0 ? r->isfullscreen : c->isfullscreen; c->isfullscreen = r->isfullscreen > 0 ? r->isfullscreen : c->isfullscreen;
c->animation_type_open = r->animation_type_open == NULL c->animation_type_open = r->animation_type_open == NULL
@ -2021,8 +2035,7 @@ void apply_window_snap(Client *c) {
snap_left_mon = c->geom.x - c->mon->m.x; snap_left_mon = c->geom.x - c->mon->m.x;
snap_right_mon = c->mon->m.x + c->mon->m.width - c->geom.x - c->geom.width; snap_right_mon = c->mon->m.x + c->mon->m.width - c->geom.x - c->geom.width;
snap_up_mon = c->geom.y - c->mon->m.y; snap_up_mon = c->geom.y - c->mon->m.y;
snap_down_mon = snap_down_mon = c->mon->m.y + c->mon->m.height - c->geom.y - c->geom.height;
c->mon->m.y + c->mon->m.height - c->geom.y - c->geom.height;
if (snap_up_mon > 0 && snap_up_mon < snap_up) if (snap_up_mon > 0 && snap_up_mon < snap_up)
snap_up = snap_up_mon; snap_up = snap_up_mon;
@ -2033,7 +2046,6 @@ void apply_window_snap(Client *c) {
if (snap_right_mon > 0 && snap_right_mon < snap_right) if (snap_right_mon > 0 && snap_right_mon < snap_right)
snap_right = snap_right_mon; snap_right = snap_right_mon;
snap_left_screen = c->geom.x - c->mon->w.x; snap_left_screen = c->geom.x - c->mon->w.x;
snap_right_screen = c->mon->w.x + c->mon->w.width - c->geom.x - c->geom.width; snap_right_screen = c->mon->w.x + c->mon->w.width - c->geom.x - c->geom.width;
snap_up_screen = c->geom.y - c->mon->w.y; snap_up_screen = c->geom.y - c->mon->w.y;
@ -2298,7 +2310,7 @@ void arrangelayers(Monitor *m) {
} }
} }
char* get_autostart_path(char *autostart_path, size_t buf_size) { char *get_autostart_path(char *autostart_path, size_t buf_size) {
const char *maomaoconfig = getenv("MAOMAOCONFIG"); const char *maomaoconfig = getenv("MAOMAOCONFIG");
if (maomaoconfig && maomaoconfig[0] != '\0') { if (maomaoconfig && maomaoconfig[0] != '\0') {
@ -2309,7 +2321,8 @@ char* get_autostart_path(char *autostart_path, size_t buf_size) {
fprintf(stderr, "Error: HOME environment variable not set.\n"); fprintf(stderr, "Error: HOME environment variable not set.\n");
return NULL; return NULL;
} }
snprintf(autostart_path, buf_size, "%s/.config/maomao/autostart.sh", homedir); snprintf(autostart_path, buf_size, "%s/.config/maomao/autostart.sh",
homedir);
} }
return autostart_path; return autostart_path;
@ -2636,11 +2649,11 @@ void cleanup(void) {
xwayland = NULL; xwayland = NULL;
#endif #endif
wl_display_destroy_clients(dpy); wl_display_destroy_clients(dpy);
if (child_pid > 0) { if (child_pid > 0) {
kill(-child_pid, SIGTERM); kill(-child_pid, SIGTERM);
waitpid(child_pid, NULL, 0); waitpid(child_pid, NULL, 0);
} }
wlr_xcursor_manager_destroy(cursor_mgr); wlr_xcursor_manager_destroy(cursor_mgr);
destroykeyboardgroup(&kb_group->destroy, NULL); destroykeyboardgroup(&kb_group->destroy, NULL);
@ -3143,7 +3156,8 @@ void createmon(struct wl_listener *listener, void *data) {
if (i > 0 && strlen(config.tag_rules[i - 1].layout_name) > 0) { if (i > 0 && strlen(config.tag_rules[i - 1].layout_name) > 0) {
for (jk = 0; jk < LENGTH(layouts); jk++) { for (jk = 0; jk < LENGTH(layouts); jk++) {
if (strcmp(layouts[jk].name, config.tag_rules[i - 1].layout_name) == 0) { if (strcmp(layouts[jk].name, config.tag_rules[i - 1].layout_name) ==
0) {
m->pertag->ltidxs[i] = &layouts[jk]; m->pertag->ltidxs[i] = &layouts[jk];
} }
} }
@ -3616,17 +3630,17 @@ void dwl_ipc_output_quit(struct wl_client *client,
} }
void dwl_ipc_output_dispatch(struct wl_client *client, void dwl_ipc_output_dispatch(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *resource, const char *dispatch,
const char *dispatch, const char *arg1, const char *arg1, const char *arg2,
const char *arg2, const char *arg3, const char *arg4) { const char *arg3, const char *arg4) {
void (*func)(const Arg *); void (*func)(const Arg *);
Arg arg; Arg arg;
func = parse_func_name((char*)dispatch, &arg, (char*)arg1, (char*)arg2, (char*)arg3, (char*)arg4); func = parse_func_name((char *)dispatch, &arg, (char *)arg1, (char *)arg2,
if(func) { (char *)arg3, (char *)arg4);
if (func) {
func(&arg); func(&arg);
} }
} }
void dwl_ipc_output_release(struct wl_client *client, void dwl_ipc_output_release(struct wl_client *client,
@ -3672,7 +3686,8 @@ void focusclient(Client *c, int lift) {
// decide whether need to re-arrange // decide whether need to re-arrange
if (c && selmon->prevsel && !selmon->prevsel->isfloating && if (c && selmon->prevsel && !selmon->prevsel->isfloating &&
(selmon->prevsel->tags & selmon->tagset[selmon->seltags]) && (c->tags & selmon->tagset[selmon->seltags]) && !c->isfloating && (selmon->prevsel->tags & selmon->tagset[selmon->seltags]) &&
(c->tags & selmon->tagset[selmon->seltags]) && !c->isfloating &&
!c->isfullscreen && !c->isfullscreen &&
strcmp(selmon->pertag->ltidxs[selmon->pertag->curtag]->name, strcmp(selmon->pertag->ltidxs[selmon->pertag->curtag]->name,
"scroller") == 0) { "scroller") == 0) {
@ -5148,33 +5163,34 @@ run(char *startup_cmd) {
/* Now that the socket exists and the backend is started, run the startup /* Now that the socket exists and the backend is started, run the startup
* command */ * command */
if(!startup_cmd) if (!startup_cmd)
startup_cmd = get_autostart_path(autostart_temp_path, sizeof(autostart_temp_path)); startup_cmd =
get_autostart_path(autostart_temp_path, sizeof(autostart_temp_path));
if (startup_cmd) { if (startup_cmd) {
int piperw[2]; int piperw[2];
if (pipe(piperw) < 0) if (pipe(piperw) < 0)
die("startup: pipe:"); die("startup: pipe:");
if ((child_pid = fork()) < 0) if ((child_pid = fork()) < 0)
die("startup: fork:"); die("startup: fork:");
if (child_pid == 0) { if (child_pid == 0) {
setsid(); setsid();
dup2(piperw[0], STDIN_FILENO); dup2(piperw[0], STDIN_FILENO);
close(piperw[0]); close(piperw[0]);
close(piperw[1]); close(piperw[1]);
execl("/bin/sh", "/bin/sh", "-c", startup_cmd, NULL); execl("/bin/sh", "/bin/sh", "-c", startup_cmd, NULL);
die("startup: execl:"); die("startup: execl:");
} }
dup2(piperw[1], STDOUT_FILENO); dup2(piperw[1], STDOUT_FILENO);
close(piperw[1]); close(piperw[1]);
close(piperw[0]); close(piperw[0]);
} }
/* Mark stdout as non-blocking to avoid people who does not close stdin /* Mark stdout as non-blocking to avoid people who does not close stdin
* nor consumes it in their startup script getting dwl frozen */ * nor consumes it in their startup script getting dwl frozen */
if (fd_set_nonblock(STDOUT_FILENO) < 0) if (fd_set_nonblock(STDOUT_FILENO) < 0)
close(STDOUT_FILENO); close(STDOUT_FILENO);
printstatus(); printstatus();
/* At this point the outputs are initialized, choose initial selmon based on /* At this point the outputs are initialized, choose initial selmon based on
* cursor position, and set default cursor image */ * cursor position, and set default cursor image */
@ -5228,11 +5244,11 @@ setfloating(Client *c, int floating) {
if (!c || !c->mon || !client_surface(c)->mapped || c->iskilling) if (!c || !c->mon || !client_surface(c)->mapped || c->iskilling)
return; return;
if(c->isoverlay) { if (c->isoverlay) {
wlr_scene_node_reparent(&c->scene->node, layers[LyrOverlay]); wlr_scene_node_reparent(&c->scene->node, layers[LyrOverlay]);
} else { } else {
wlr_scene_node_reparent(&c->scene->node, wlr_scene_node_reparent(&c->scene->node,
layers[c->isfloating ? LyrFloat : LyrTile]); layers[c->isfloating ? LyrFloat : LyrTile]);
} }
target_box = c->geom; target_box = c->geom;
@ -5348,12 +5364,12 @@ void setfullscreen(Client *c, int fullscreen) // 用自定义全屏代理自带
client_set_fullscreen(c, fullscreen); client_set_fullscreen(c, fullscreen);
if(c->isoverlay) { if (c->isoverlay) {
wlr_scene_node_reparent(&c->scene->node, layers[LyrOverlay]); wlr_scene_node_reparent(&c->scene->node, layers[LyrOverlay]);
} else { } else {
wlr_scene_node_reparent(&c->scene->node, layers[fullscreen ? LyrFloat wlr_scene_node_reparent(&c->scene->node, layers[fullscreen ? LyrFloat
: c->isfloating ? LyrFloat : c->isfloating ? LyrFloat
: LyrTile]); : LyrTile]);
} }
if (fullscreen) { if (fullscreen) {
@ -5999,9 +6015,7 @@ void tagmon(const Arg *arg) {
} }
} }
void overview(Monitor *m) { void overview(Monitor *m) { grid(m); }
grid(m);
}
void fibonacci(Monitor *mon, int s) { void fibonacci(Monitor *mon, int s) {
unsigned int i = 0, n = 0, nx, ny, nw, nh; unsigned int i = 0, n = 0, nx, ny, nw, nh;
@ -6012,13 +6026,13 @@ void fibonacci(Monitor *mon, int s) {
unsigned int cur_gappov = enablegaps ? mon->gappov : 0; unsigned int cur_gappov = enablegaps ? mon->gappov : 0;
// Count visible clients // Count visible clients
wl_list_for_each(c, &clients, link) wl_list_for_each(c, &clients, link) if (VISIBLEON(c, mon) && !c->isfloating &&
if (VISIBLEON(c, mon) && !c->isfloating && !c->iskilling && !c->iskilling && !c->isfullscreen &&
!c->isfullscreen && !c->ismaxmizescreen && !c->animation.tagouting) !c->ismaxmizescreen &&
n++; !c->animation.tagouting) n++;
if (n == 0) if (n == 0)
return; return;
// Initial dimensions including outer gaps // Initial dimensions including outer gaps
nx = mon->w.x + cur_gappoh; nx = mon->w.x + cur_gappoh;
@ -6028,107 +6042,101 @@ void fibonacci(Monitor *mon, int s) {
// First pass: calculate client geometries // First pass: calculate client geometries
wl_list_for_each(c, &clients, link) { wl_list_for_each(c, &clients, link) {
if (!VISIBLEON(c, mon) || c->isfloating || c->iskilling || if (!VISIBLEON(c, mon) || c->isfloating || c->iskilling ||
c->isfullscreen || c->ismaxmizescreen || c->animation.tagouting) c->isfullscreen || c->ismaxmizescreen || c->animation.tagouting)
continue; continue;
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) {
if (i == 1) { if (i == 1) {
nh = nh * mon->pertag->smfacts[mon->pertag->curtag]; nh = nh * mon->pertag->smfacts[mon->pertag->curtag];
} else { } else {
nh = (nh - cur_gappiv) / 2; nh = (nh - cur_gappiv) / 2;
}
} else {
nw = (nw - cur_gappih) / 2;
}
if ((i % 4) == 2 && !s)
nx += nw + cur_gappih;
else if ((i % 4) == 3 && !s)
ny += nh + cur_gappiv;
} }
} else {
nw = (nw - cur_gappih) / 2;
}
if ((i % 4) == 0) { if ((i % 4) == 2 && !s)
if (s) nx += nw + cur_gappih;
ny += nh + cur_gappiv; else if ((i % 4) == 3 && !s)
else ny += nh + cur_gappiv;
ny -= nh + cur_gappiv;
} else if ((i % 4) == 1)
nx += nw + cur_gappih;
else if ((i % 4) == 2)
ny += nh + cur_gappiv;
else if ((i % 4) == 3) {
if (s)
nx += nw + cur_gappih;
else
nx -= nw + cur_gappih;
}
if (i == 0) {
if (n != 1)
nw = (mon->w.width - 2 * cur_gappoh) * mon->pertag->mfacts[mon->pertag->curtag];
ny = mon->w.y + cur_gappov;
} else if (i == 1) {
nw = mon->w.width - 2 * cur_gappoh - nw - cur_gappih;
} else if (i == 2) {
nh = mon->w.height - 2 * cur_gappov - nh - cur_gappiv;
}
i++;
} }
c->geom = (struct wlr_box){.x = nx, .y = ny, .width = nw, .height = nh}; if ((i % 4) == 0) {
if (s)
ny += nh + cur_gappiv;
else
ny -= nh + cur_gappiv;
} else if ((i % 4) == 1)
nx += nw + cur_gappih;
else if ((i % 4) == 2)
ny += nh + cur_gappiv;
else if ((i % 4) == 3) {
if (s)
nx += nw + cur_gappih;
else
nx -= nw + cur_gappih;
}
if (i == 0) {
if (n != 1)
nw = (mon->w.width - 2 * cur_gappoh) *
mon->pertag->mfacts[mon->pertag->curtag];
ny = mon->w.y + cur_gappov;
} else if (i == 1) {
nw = mon->w.width - 2 * cur_gappoh - nw - cur_gappih;
} else if (i == 2) {
nh = mon->w.height - 2 * cur_gappov - nh - cur_gappiv;
}
i++;
}
c->geom = (struct wlr_box){.x = nx, .y = ny, .width = nw, .height = nh};
} }
// Second pass: apply gaps between clients // Second pass: apply gaps between clients
wl_list_for_each(c, &clients, link) { wl_list_for_each(c, &clients, link) {
if (!VISIBLEON(c, mon) || c->isfloating || c->iskilling || if (!VISIBLEON(c, mon) || c->isfloating || c->iskilling ||
c->isfullscreen || c->ismaxmizescreen || c->animation.tagouting) c->isfullscreen || c->ismaxmizescreen || c->animation.tagouting)
continue; continue;
unsigned int right_gap = 0; unsigned int right_gap = 0;
unsigned int bottom_gap = 0; unsigned int bottom_gap = 0;
Client *nc; Client *nc;
wl_list_for_each(nc, &clients, link) { wl_list_for_each(nc, &clients, link) {
if (!VISIBLEON(nc, mon) || nc->isfloating || nc->iskilling || if (!VISIBLEON(nc, mon) || nc->isfloating || nc->iskilling ||
nc->isfullscreen || nc->ismaxmizescreen || nc->animation.tagouting) nc->isfullscreen || nc->ismaxmizescreen || nc->animation.tagouting)
continue; continue;
if (c == nc) continue; if (c == nc)
continue;
// Check for right neighbor // Check for right neighbor
if (c->geom.y == nc->geom.y && if (c->geom.y == nc->geom.y && c->geom.x + c->geom.width == nc->geom.x) {
c->geom.x + c->geom.width == nc->geom.x) { right_gap = cur_gappih;
right_gap = cur_gappih;
}
// Check for bottom neighbor
if (c->geom.x == nc->geom.x &&
c->geom.y + c->geom.height == nc->geom.y) {
bottom_gap = cur_gappiv;
}
} }
resize(c, // Check for bottom neighbor
(struct wlr_box){ if (c->geom.x == nc->geom.x && c->geom.y + c->geom.height == nc->geom.y) {
.x = c->geom.x, bottom_gap = cur_gappiv;
.y = c->geom.y, }
.width = c->geom.width - right_gap, }
.height = c->geom.height - bottom_gap
}, resize(c,
0); (struct wlr_box){.x = c->geom.x,
.y = c->geom.y,
.width = c->geom.width - right_gap,
.height = c->geom.height - bottom_gap},
0);
} }
} }
void dwindle(Monitor *mon) { void dwindle(Monitor *mon) { fibonacci(mon, 1); }
fibonacci(mon, 1);
}
void spiral(Monitor *mon) { void spiral(Monitor *mon) { fibonacci(mon, 0); }
fibonacci(mon, 0);
}
// 网格布局窗口大小和位置计算 // 网格布局窗口大小和位置计算
void grid(Monitor *m) { void grid(Monitor *m) {
@ -6208,7 +6216,8 @@ void grid(Monitor *m) {
// 处理多余的列 // 处理多余的列
overcols = n % cols; overcols = n % cols;
if (overcols) { if (overcols) {
dx = (m->w.width - overcols * cw - (overcols - 1) * overviewgappi) / 2 - overviewgappo; dx = (m->w.width - overcols * cw - (overcols - 1) * overviewgappi) / 2 -
overviewgappo;
} }
// 调整每个客户端的位置和大小 // 调整每个客户端的位置和大小
@ -6241,11 +6250,12 @@ void scroller(Monitor *m) {
struct wlr_box target_geom; struct wlr_box target_geom;
int focus_client_index = 0; int focus_client_index = 0;
bool need_scroller = false; bool need_scroller = false;
unsigned int cur_gappih = enablegaps? m->gappih : 0; unsigned int cur_gappih = enablegaps ? m->gappih : 0;
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;
unsigned int max_client_width = m->w.width - 2 * scroller_structs - cur_gappih; unsigned int max_client_width =
m->w.width - 2 * scroller_structs - cur_gappih;
// 第一次遍历,计算 n 的值 // 第一次遍历,计算 n 的值
wl_list_for_each(c, &clients, link) { wl_list_for_each(c, &clients, link) {
@ -6349,15 +6359,16 @@ void scroller(Monitor *m) {
for (i = 1; i <= focus_client_index; i++) { for (i = 1; i <= focus_client_index; i++) {
c = tempClients[focus_client_index - i]; c = tempClients[focus_client_index - i];
target_geom.width = max_client_width * c->scroller_proportion; target_geom.width = max_client_width * c->scroller_proportion;
target_geom.x = tempClients[focus_client_index - i + 1]->geom.x - cur_gappih - target_geom.x = tempClients[focus_client_index - i + 1]->geom.x -
target_geom.width; cur_gappih - target_geom.width;
resize(c, target_geom, 0); resize(c, target_geom, 0);
} }
for (i = 1; i < n - focus_client_index; i++) { for (i = 1; i < n - focus_client_index; i++) {
c = tempClients[focus_client_index + i]; c = tempClients[focus_client_index + i];
target_geom.width = max_client_width * c->scroller_proportion; target_geom.width = max_client_width * c->scroller_proportion;
target_geom.x = tempClients[focus_client_index + i - 1]->geom.x + cur_gappih + target_geom.x = tempClients[focus_client_index + i - 1]->geom.x +
cur_gappih +
tempClients[focus_client_index + i - 1]->geom.width; tempClients[focus_client_index + i - 1]->geom.width;
resize(c, target_geom, 0); resize(c, target_geom, 0);
} }
@ -7026,7 +7037,7 @@ void view_in_mon(const Arg *arg, bool want_animation, Monitor *m) {
if (arg->ui == ~0) if (arg->ui == ~0)
m->pertag->curtag = 0; m->pertag->curtag = 0;
else { else {
for (i = 0; !(arg->ui & 1 << i) && i <LENGTH(tags) && arg->ui != 0; i++) for (i = 0; !(arg->ui & 1 << i) && i < LENGTH(tags) && arg->ui != 0; i++)
; ;
m->pertag->curtag = i >= LENGTH(tags) ? LENGTH(tags) : i + 1; m->pertag->curtag = i >= LENGTH(tags) ? LENGTH(tags) : i + 1;
} }
@ -7362,28 +7373,28 @@ void resizewin(const Arg *arg) {
if (!c->isfloating) if (!c->isfloating)
togglefloating(NULL); togglefloating(NULL);
switch(arg->ui) { switch (arg->ui) {
case NUM_TYPE_MINUS: case NUM_TYPE_MINUS:
c->geom.width -= arg->i; c->geom.width -= arg->i;
break; break;
case NUM_TYPE_PLUS: case NUM_TYPE_PLUS:
c->geom.width += arg->i; c->geom.width += arg->i;
break; break;
default: default:
c->geom.width = arg->i; c->geom.width = arg->i;
break; break;
} }
switch(arg->ui2) { switch (arg->ui2) {
case NUM_TYPE_MINUS: case NUM_TYPE_MINUS:
c->geom.height -= arg->i2; c->geom.height -= arg->i2;
break; break;
case NUM_TYPE_PLUS: case NUM_TYPE_PLUS:
c->geom.height += arg->i2; c->geom.height += arg->i2;
break; break;
default: default:
c->geom.height = arg->i2; c->geom.height = arg->i2;
break; break;
} }
c->oldgeom = c->geom; c->oldgeom = c->geom;
@ -7398,35 +7409,34 @@ void movewin(const Arg *arg) {
if (!c->isfloating) if (!c->isfloating)
togglefloating(NULL); togglefloating(NULL);
switch(arg->ui) { switch (arg->ui) {
case NUM_TYPE_MINUS: case NUM_TYPE_MINUS:
c->geom.x -= arg->i; c->geom.x -= arg->i;
break; break;
case NUM_TYPE_PLUS: case NUM_TYPE_PLUS:
c->geom.x += arg->i; c->geom.x += arg->i;
break; break;
default: default:
c->geom.x = arg->i; c->geom.x = arg->i;
break; break;
} }
switch(arg->ui2) { switch (arg->ui2) {
case NUM_TYPE_MINUS: case NUM_TYPE_MINUS:
c->geom.y -= arg->i2; c->geom.y -= arg->i2;
break; break;
case NUM_TYPE_PLUS: case NUM_TYPE_PLUS:
c->geom.y += arg->i2; c->geom.y += arg->i2;
break; break;
default: default:
c->geom.y = arg->i2; c->geom.y = arg->i2;
break; break;
} }
c->oldgeom = c->geom; c->oldgeom = c->geom;
resize(c, c->geom, 0); resize(c, c->geom, 0);
} }
void smartmovewin(const Arg *arg) { void smartmovewin(const Arg *arg) {
Client *c, *tc; Client *c, *tc;
int nx, ny; int nx, ny;