mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2026-04-06 07:15:53 -04:00
改进scoller默认宽度为动态宽度
This commit is contained in:
parent
2f8a6285b2
commit
cec8d2d69e
3 changed files with 57 additions and 17 deletions
14
maomao.c
14
maomao.c
|
|
@ -5339,26 +5339,26 @@ void overview_restore(Client *c, const Arg *arg) {
|
||||||
void switch_proportion_preset(const Arg *arg) {
|
void switch_proportion_preset(const Arg *arg) {
|
||||||
float target_proportion = 0;
|
float target_proportion = 0;
|
||||||
|
|
||||||
if (LENGTH(scroller_proportion_preset) == 0) {
|
if (config.scroller_proportion_preset_count == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selmon->sel) {
|
if (selmon->sel) {
|
||||||
|
|
||||||
for (int i = 0; i < LENGTH(scroller_proportion_preset); i++) {
|
for (int i = 0; i < config.scroller_proportion_preset_count; i++) {
|
||||||
if (scroller_proportion_preset[i] == selmon->sel->scroller_proportion) {
|
if (config.scroller_proportion_preset[i] == selmon->sel->scroller_proportion) {
|
||||||
if (i == LENGTH(scroller_proportion_preset) - 1) {
|
if (i == config.scroller_proportion_preset_count - 1) {
|
||||||
target_proportion = scroller_proportion_preset[0];
|
target_proportion = config.scroller_proportion_preset[0];
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
target_proportion = scroller_proportion_preset[i + 1];
|
target_proportion = config.scroller_proportion_preset[i + 1];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target_proportion == 0) {
|
if (target_proportion == 0) {
|
||||||
target_proportion = scroller_proportion_preset[0];
|
target_proportion = config.scroller_proportion_preset[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int max_client_width =
|
unsigned int max_client_width =
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,8 @@ typedef struct {
|
||||||
int scroller_structs;
|
int scroller_structs;
|
||||||
float scroller_default_proportion;
|
float scroller_default_proportion;
|
||||||
int scoller_focus_center;
|
int scoller_focus_center;
|
||||||
float scroller_proportion_preset[3];
|
float *scroller_proportion_preset;
|
||||||
|
int scroller_proportion_preset_count;
|
||||||
|
|
||||||
unsigned int new_is_master;
|
unsigned int new_is_master;
|
||||||
float default_mfact;
|
float default_mfact;
|
||||||
|
|
@ -478,12 +479,50 @@ void parse_config_line(Config *config, const char *line) {
|
||||||
} else if (strcmp(key, "scoller_focus_center") == 0) {
|
} else if (strcmp(key, "scoller_focus_center") == 0) {
|
||||||
config->scoller_focus_center = atoi(value);
|
config->scoller_focus_center = atoi(value);
|
||||||
} else if (strcmp(key, "scroller_proportion_preset") == 0) {
|
} else if (strcmp(key, "scroller_proportion_preset") == 0) {
|
||||||
if (sscanf(value, "%f,%f,%f", &config->scroller_proportion_preset[0],
|
// 1. 统计 value 中有多少个逗号,确定需要解析的浮点数个数
|
||||||
&config->scroller_proportion_preset[1],
|
int count = 0; // 初始化为 0
|
||||||
&config->scroller_proportion_preset[2]) != 3) {
|
for (const char *p = value; *p; p++) {
|
||||||
fprintf(stderr, "Error: Invalid scroller_proportion_preset format: %s\n",
|
if (*p == ',') count++;
|
||||||
value);
|
|
||||||
}
|
}
|
||||||
|
int float_count = count + 1; // 浮点数的数量是逗号数量加 1
|
||||||
|
|
||||||
|
// 2. 动态分配内存,存储浮点数
|
||||||
|
config->scroller_proportion_preset = (float *)malloc(float_count * sizeof(float));
|
||||||
|
if (!config->scroller_proportion_preset) {
|
||||||
|
fprintf(stderr, "Error: Memory allocation failed\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. 解析 value 中的浮点数
|
||||||
|
char *value_copy = strdup(value); // 复制 value,因为 strtok 会修改原字符串
|
||||||
|
char *token = strtok(value_copy, ",");
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
while (token != NULL && i < float_count) {
|
||||||
|
if (sscanf(token, "%f", &config->scroller_proportion_preset[i]) != 1) {
|
||||||
|
fprintf(stderr, "Error: Invalid float value in scroller_proportion_preset: %s\n", token);
|
||||||
|
free(value_copy);
|
||||||
|
free(config->scroller_proportion_preset); // 释放已分配的内存
|
||||||
|
config->scroller_proportion_preset = NULL; // 防止野指针
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
token = strtok(NULL, ",");
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. 检查解析的浮点数数量是否匹配
|
||||||
|
if (i != float_count) {
|
||||||
|
fprintf(stderr, "Error: Invalid scroller_proportion_preset format: %s\n", value);
|
||||||
|
free(value_copy);
|
||||||
|
free(config->scroller_proportion_preset); // 释放已分配的内存
|
||||||
|
config->scroller_proportion_preset = NULL; // 防止野指针
|
||||||
|
config->scroller_proportion_preset_count = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
config->scroller_proportion_preset_count = float_count;
|
||||||
|
|
||||||
|
// 5. 释放临时复制的字符串
|
||||||
|
free(value_copy);
|
||||||
} else if (strcmp(key, "new_is_master") == 0) {
|
} else if (strcmp(key, "new_is_master") == 0) {
|
||||||
config->new_is_master = atoi(value);
|
config->new_is_master = atoi(value);
|
||||||
} else if (strcmp(key, "default_mfact") == 0) {
|
} else if (strcmp(key, "default_mfact") == 0) {
|
||||||
|
|
@ -882,6 +921,10 @@ void free_config(void) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(config.axis_bindings);
|
free(config.axis_bindings);
|
||||||
|
|
||||||
|
free(config.scroller_proportion_preset);
|
||||||
|
config.scroller_proportion_preset = NULL;
|
||||||
|
config.scroller_proportion_preset_count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void override_config(void) {
|
void override_config(void) {
|
||||||
|
|
@ -898,8 +941,6 @@ void override_config(void) {
|
||||||
|
|
||||||
// 复制数组类型的变量
|
// 复制数组类型的变量
|
||||||
memcpy(animation_curve, config.animation_curve, sizeof(animation_curve));
|
memcpy(animation_curve, config.animation_curve, sizeof(animation_curve));
|
||||||
memcpy(scroller_proportion_preset, config.scroller_proportion_preset,
|
|
||||||
sizeof(scroller_proportion_preset));
|
|
||||||
|
|
||||||
scroller_structs = config.scroller_structs;
|
scroller_structs = config.scroller_structs;
|
||||||
scroller_default_proportion = config.scroller_default_proportion;
|
scroller_default_proportion = config.scroller_default_proportion;
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,6 @@ unsigned int gappov = 10; /* vert outer gap between windows and screen edge */
|
||||||
int scroller_structs = 20;
|
int scroller_structs = 20;
|
||||||
float scroller_default_proportion = 0.9;
|
float scroller_default_proportion = 0.9;
|
||||||
int scoller_focus_center = 0;
|
int scoller_focus_center = 0;
|
||||||
float scroller_proportion_preset[] = {0.5, 0.9, 1.0};
|
|
||||||
|
|
||||||
int bypass_surface_visibility =
|
int bypass_surface_visibility =
|
||||||
0; /* 1 means idle inhibitors will disable idle tracking even if it's
|
0; /* 1 means idle inhibitors will disable idle tracking even if it's
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue