opt: animations logic all use the int type

This commit is contained in:
DreamMaoMao 2026-01-03 09:47:49 +08:00
parent e5cfd4e4fc
commit 7d019b7032
21 changed files with 835 additions and 820 deletions

View file

@ -10,8 +10,9 @@
// 整数版本 - 截断小数部分
#define CLAMP_INT(x, min, max) \
((int)(x) < (int)(min) ? (int)(min) \
: ((int)(x) > (int)(max) ? (int)(max) : (int)(x)))
((int32_t)(x) < (int32_t)(min) \
? (int32_t)(min) \
: ((int32_t)(x) > (int32_t)(max) ? (int32_t)(max) : (int32_t)(x)))
// 浮点数版本 - 保留小数部分
#define CLAMP_FLOAT(x, min, max) \
@ -30,13 +31,13 @@ typedef struct {
typedef struct {
xkb_keysym_t keysym;
MultiKeycode keycode;
int type;
int32_t type;
} KeySymCode;
typedef struct {
uint32_t mod;
KeySymCode keysymcode;
int (*func)(const Arg *);
int32_t (*func)(const Arg *);
Arg arg;
char mode[28];
bool iscommonmode;
@ -55,40 +56,40 @@ typedef struct {
const char *id;
const char *title;
uint32_t tags;
int isfloating;
int isfullscreen;
int32_t isfloating;
int32_t isfullscreen;
float scroller_proportion;
const char *animation_type_open;
const char *animation_type_close;
const char *layer_animation_type_open;
const char *layer_animation_type_close;
int isnoborder;
int isnoshadow;
int isnoanimation;
int isopensilent;
int istagsilent;
int isnamedscratchpad;
int isunglobal;
int isglobal;
int isoverlay;
int allow_shortcuts_inhibit;
int ignore_maximize;
int ignore_minimize;
int isnosizehint;
int32_t isnoborder;
int32_t isnoshadow;
int32_t isnoanimation;
int32_t isopensilent;
int32_t istagsilent;
int32_t isnamedscratchpad;
int32_t isunglobal;
int32_t isglobal;
int32_t isoverlay;
int32_t allow_shortcuts_inhibit;
int32_t ignore_maximize;
int32_t ignore_minimize;
int32_t isnosizehint;
const char *monitor;
int offsetx;
int offsety;
int width;
int height;
int nofocus;
int nofadein;
int nofadeout;
int no_force_center;
int isterm;
int allow_csd;
int force_maximize;
int force_tearing;
int noswallow;
int32_t offsetx;
int32_t offsety;
int32_t width;
int32_t height;
int32_t nofocus;
int32_t nofadein;
int32_t nofadeout;
int32_t no_force_center;
int32_t isterm;
int32_t allow_csd;
int32_t force_maximize;
int32_t force_tearing;
int32_t noswallow;
float focused_opacity;
float unfocused_opacity;
float scroller_proportion_single;
@ -98,15 +99,15 @@ typedef struct {
} ConfigWinRule;
typedef struct {
const char *name; // 显示器名称
float mfact; // 主区域比例
int nmaster; // 主区域窗口数量
const char *layout; // 布局名称(字符串)
int rr; // 旋转和翻转(假设为整数)
float scale; // 显示器缩放比例
int x, y; // 显示器位置
int width, height; // 显示器分辨率
float refresh; // 刷新率
const char *name; // 显示器名称
float mfact; // 主区域比例
int32_t nmaster; // 主区域窗口数量
const char *layout; // 布局名称(字符串)
int32_t rr; // 旋转和翻转(假设为整数)
float scale; // 显示器缩放比例
int32_t x, y; // 显示器位置
int32_t width, height; // 显示器分辨率
float refresh; // 刷新率
} ConfigMonitorRule;
// 修改后的宏定义
@ -127,20 +128,20 @@ KeyBinding default_key_bindings[] = {CHVT(1), CHVT(2), CHVT(3), CHVT(4),
typedef struct {
uint32_t mod;
uint32_t button;
int (*func)(const Arg *);
int32_t (*func)(const Arg *);
Arg arg;
} MouseBinding;
typedef struct {
uint32_t mod;
uint32_t dir;
int (*func)(const Arg *);
int32_t (*func)(const Arg *);
Arg arg;
} AxisBinding;
typedef struct {
uint32_t fold;
int (*func)(const Arg *);
int32_t (*func)(const Arg *);
Arg arg;
} SwitchBinding;
@ -148,36 +149,36 @@ typedef struct {
uint32_t mod;
uint32_t motion;
uint32_t fingers_count;
int (*func)(const Arg *);
int32_t (*func)(const Arg *);
Arg arg;
} GestureBinding;
typedef struct {
int id; // 标签ID (1-9)
int32_t id; // 标签ID (1-9)
char *layout_name; // 布局名称
char *monitor_name;
int no_render_border;
int no_hide;
int32_t no_render_border;
int32_t no_hide;
} ConfigTagRule;
typedef struct {
char *layer_name; // 布局名称
char *animation_type_open;
char *animation_type_close;
int noblur;
int noanim;
int32_t noblur;
int32_t noanim;
} ConfigLayerRule;
typedef struct {
int animations;
int layer_animations;
int32_t animations;
int32_t layer_animations;
char animation_type_open[10];
char animation_type_close[10];
char layer_animation_type_open[10];
char layer_animation_type_close[10];
int animation_fade_in;
int animation_fade_out;
int tag_animation_direction;
int32_t animation_fade_in;
int32_t animation_fade_out;
int32_t tag_animation_direction;
float zoom_initial_ratio;
float zoom_end_ratio;
float fadein_begin_opacity;
@ -195,65 +196,65 @@ typedef struct {
double animation_curve_opafadein[4];
double animation_curve_opafadeout[4];
int scroller_structs;
int32_t scroller_structs;
float scroller_default_proportion;
float scroller_default_proportion_single;
int scroller_ignore_proportion_single;
int scroller_focus_center;
int scroller_prefer_center;
int edge_scroller_pointer_focus;
int focus_cross_monitor;
int exchange_cross_monitor;
int scratchpad_cross_monitor;
int focus_cross_tag;
int view_current_to_back;
int no_border_when_single;
int snap_distance;
int enable_floating_snap;
int drag_tile_to_tile;
int32_t scroller_ignore_proportion_single;
int32_t scroller_focus_center;
int32_t scroller_prefer_center;
int32_t edge_scroller_pointer_focus;
int32_t focus_cross_monitor;
int32_t exchange_cross_monitor;
int32_t scratchpad_cross_monitor;
int32_t focus_cross_tag;
int32_t view_current_to_back;
int32_t no_border_when_single;
int32_t snap_distance;
int32_t enable_floating_snap;
int32_t drag_tile_to_tile;
uint32_t swipe_min_threshold;
float focused_opacity;
float unfocused_opacity;
float *scroller_proportion_preset;
int scroller_proportion_preset_count;
int32_t scroller_proportion_preset_count;
char **circle_layout;
int circle_layout_count;
int32_t circle_layout_count;
uint32_t new_is_master;
float default_mfact;
uint32_t default_nmaster;
int center_master_overspread;
int center_when_single_stack;
int32_t center_master_overspread;
int32_t center_when_single_stack;
uint32_t hotarea_size;
uint32_t enable_hotarea;
uint32_t ov_tab_mode;
int overviewgappi;
int overviewgappo;
int32_t overviewgappi;
int32_t overviewgappo;
uint32_t cursor_hide_timeout;
uint32_t axis_bind_apply_timeout;
uint32_t focus_on_activate;
int idleinhibit_ignore_visible;
int sloppyfocus;
int warpcursor;
int32_t idleinhibit_ignore_visible;
int32_t sloppyfocus;
int32_t warpcursor;
/* keyboard */
int repeat_rate;
int repeat_delay;
int32_t repeat_rate;
int32_t repeat_delay;
uint32_t numlockon;
/* Trackpad */
int disable_trackpad;
int tap_to_click;
int tap_and_drag;
int drag_lock;
int mouse_natural_scrolling;
int trackpad_natural_scrolling;
int disable_while_typing;
int left_handed;
int middle_button_emulation;
int32_t disable_trackpad;
int32_t tap_to_click;
int32_t tap_and_drag;
int32_t drag_lock;
int32_t mouse_natural_scrolling;
int32_t trackpad_natural_scrolling;
int32_t disable_while_typing;
int32_t left_handed;
int32_t middle_button_emulation;
uint32_t accel_profile;
double accel_speed;
uint32_t scroll_method;
@ -262,7 +263,7 @@ typedef struct {
uint32_t send_events_mode;
uint32_t button_map;
double axis_scroll_factor;
int smartgaps;
int32_t smartgaps;
uint32_t gappih;
uint32_t gappiv;
uint32_t gappoh;
@ -282,51 +283,51 @@ typedef struct {
char autostart[3][256];
ConfigTagRule *tag_rules; // 动态数组
int tag_rules_count; // 数量
int32_t tag_rules_count; // 数量
ConfigLayerRule *layer_rules; // 动态数组
int layer_rules_count; // 数量
int32_t layer_rules_count; // 数量
ConfigWinRule *window_rules;
int window_rules_count;
int32_t window_rules_count;
ConfigMonitorRule *monitor_rules; // 动态数组
int monitor_rules_count; // 条数
int32_t monitor_rules_count; // 条数
KeyBinding *key_bindings;
int key_bindings_count;
int32_t key_bindings_count;
MouseBinding *mouse_bindings;
int mouse_bindings_count;
int32_t mouse_bindings_count;
AxisBinding *axis_bindings;
int axis_bindings_count;
int32_t axis_bindings_count;
SwitchBinding *switch_bindings;
int switch_bindings_count;
int32_t switch_bindings_count;
GestureBinding *gesture_bindings;
int gesture_bindings_count;
int32_t gesture_bindings_count;
ConfigEnv **env;
int env_count;
int32_t env_count;
char **exec;
int exec_count;
int32_t exec_count;
char **exec_once;
int exec_once_count;
int32_t exec_once_count;
char *cursor_theme;
uint32_t cursor_size;
int single_scratchpad;
int xwayland_persistence;
int syncobj_enable;
int adaptive_sync;
int allow_tearing;
int allow_shortcuts_inhibit;
int allow_lock_transparent;
int32_t single_scratchpad;
int32_t xwayland_persistence;
int32_t syncobj_enable;
int32_t adaptive_sync;
int32_t allow_tearing;
int32_t allow_shortcuts_inhibit;
int32_t allow_lock_transparent;
struct xkb_rule_names xkb_rules;
@ -336,7 +337,7 @@ typedef struct {
struct xkb_keymap *keymap;
} Config;
typedef int (*FuncType)(const Arg *);
typedef int32_t (*FuncType)(const Arg *);
Config config;
void parse_config_file(Config *config, const char *file_path);
@ -367,10 +368,11 @@ void trim_whitespace(char *str) {
}
}
int parse_double_array(const char *input, double *output, int max_count) {
int32_t parse_double_array(const char *input, double *output,
int32_t max_count) {
char *dup = strdup(input);
char *token;
int count = 0;
int32_t count = 0;
// 先清空整个数组
memset(output, 0, max_count * sizeof(double));
@ -418,7 +420,7 @@ void parse_bind_flags(const char *str, KeyBinding *kb) {
const char *suffix = str + 4; // 跳过"bind"
// 遍历后缀字符
for (int i = 0; suffix[i] != '\0'; i++) {
for (int32_t i = 0; suffix[i] != '\0'; i++) {
switch (suffix[i]) {
case 's':
kb->keysymcode.type = KEY_TYPE_SYM;
@ -439,10 +441,10 @@ void parse_bind_flags(const char *str, KeyBinding *kb) {
}
}
int parse_circle_direction(const char *str) {
int32_t parse_circle_direction(const char *str) {
// 将输入字符串转换为小写
char lowerStr[10];
int i = 0;
int32_t i = 0;
while (str[i] && i < 9) {
lowerStr[i] = tolower(str[i]);
i++;
@ -457,10 +459,10 @@ int parse_circle_direction(const char *str) {
}
}
int parse_direction(const char *str) {
int32_t parse_direction(const char *str) {
// 将输入字符串转换为小写
char lowerStr[10];
int i = 0;
int32_t i = 0;
while (str[i] && i < 9) {
lowerStr[i] = tolower(str[i]);
i++;
@ -481,10 +483,10 @@ int parse_direction(const char *str) {
}
}
int parse_fold_state(const char *str) {
int32_t parse_fold_state(const char *str) {
// 将输入字符串转换为小写
char lowerStr[10];
int i = 0;
int32_t i = 0;
while (str[i] && i < 9) {
lowerStr[i] = tolower(str[i]);
i++;
@ -500,9 +502,9 @@ int parse_fold_state(const char *str) {
return INVALIDFOLD;
}
}
long int parse_color(const char *hex_str) {
int64_t parse_color(const char *hex_str) {
char *endptr;
long int hex_num = strtol(hex_str, &endptr, 16);
int64_t hex_num = strtol(hex_str, &endptr, 16);
if (*endptr != '\0') {
return -1;
}
@ -600,8 +602,9 @@ uint32_t parse_mod(const char *mod_str) {
}
// 定义辅助函数:在 keymap 中查找 keysym 对应的多个 keycode
static int find_keycodes_for_keysym(struct xkb_keymap *keymap, xkb_keysym_t sym,
MultiKeycode *multi_kc) {
static int32_t find_keycodes_for_keysym(struct xkb_keymap *keymap,
xkb_keysym_t sym,
MultiKeycode *multi_kc) {
xkb_keycode_t min_keycode = xkb_keymap_min_keycode(keymap);
xkb_keycode_t max_keycode = xkb_keymap_max_keycode(keymap);
@ -609,16 +612,16 @@ static int find_keycodes_for_keysym(struct xkb_keymap *keymap, xkb_keysym_t sym,
multi_kc->keycode2 = 0;
multi_kc->keycode3 = 0;
int found_count = 0;
int32_t found_count = 0;
for (xkb_keycode_t keycode = min_keycode;
keycode <= max_keycode && found_count < 3; keycode++) {
// 使用布局0和层级0
const xkb_keysym_t *syms;
int num_syms =
int32_t num_syms =
xkb_keymap_key_get_syms_by_level(keymap, keycode, 0, 0, &syms);
for (int i = 0; i < num_syms; i++) {
for (int32_t i = 0; i < num_syms; i++) {
if (syms[i] == sym) {
switch (found_count) {
case 0:
@ -696,7 +699,7 @@ KeySymCode parse_key(const char *key_str, bool isbindsym) {
if (sym != XKB_KEY_NoSymbol) {
// 尝试找到对应的多个 keycode
int found_count =
int32_t found_count =
find_keycodes_for_keysym(config.keymap, sym, &kc.keycode);
if (found_count > 0) {
kc.type = KEY_TYPE_CODE;
@ -716,10 +719,10 @@ KeySymCode parse_key(const char *key_str, bool isbindsym) {
return kc;
}
int parse_button(const char *str) {
int32_t parse_button(const char *str) {
// 将输入字符串转换为小写
char lowerStr[20];
int i = 0;
int32_t i = 0;
while (str[i] && i < 19) {
lowerStr[i] = tolower(str[i]);
i++;
@ -748,10 +751,10 @@ int parse_button(const char *str) {
}
}
int parse_mouse_action(const char *str) {
int32_t parse_mouse_action(const char *str) {
// 将输入字符串转换为小写
char lowerStr[20];
int i = 0;
int32_t i = 0;
while (str[i] && i < 19) {
lowerStr[i] = tolower(str[i]);
i++;
@ -772,7 +775,7 @@ int parse_mouse_action(const char *str) {
}
}
void convert_hex_to_rgba(float *color, unsigned long int hex) {
void convert_hex_to_rgba(float *color, uint32_t hex) {
color[0] = ((hex >> 24) & 0xFF) / 255.0f;
color[1] = ((hex >> 16) & 0xFF) / 255.0f;
color[2] = ((hex >> 8) & 0xFF) / 255.0f;
@ -859,7 +862,7 @@ FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value,
// 收集需要拼接的参数
const char *non_empty_params[4] = {NULL};
int param_index = 0;
int32_t param_index = 0;
if (arg_value2 && arg_value2[0] != '\0')
non_empty_params[param_index++] = arg_value2;
@ -876,7 +879,7 @@ FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value,
} else {
// 计算总长度
size_t len = 0;
for (int i = 0; i < param_index; i++) {
for (int32_t i = 0; i < param_index; i++) {
len += strlen(non_empty_params[i]);
}
len += (param_index - 1) + 1; // 逗号数 + null终止符
@ -884,7 +887,7 @@ FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value,
char *temp = malloc(len);
if (temp) {
char *cursor = temp;
for (int i = 0; i < param_index; i++) {
for (int32_t i = 0; i < param_index; i++) {
if (i > 0) {
*cursor++ = ',';
}
@ -988,7 +991,7 @@ FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value,
token = strtok_r(arg_copy, "|", &saveptr);
while (token != NULL) {
int num = atoi(token);
int32_t num = atoi(token);
if (num > 0 && num <= LENGTH(tags)) {
mask |= (1 << (num - 1));
}
@ -1064,7 +1067,7 @@ FuncType parse_func_name(char *func_name, Arg *arg, char *arg_value,
}
void set_env() {
for (int i = 0; i < config.env_count; i++) {
for (int32_t i = 0; i < config.env_count; i++) {
setenv(config.env[i]->type, config.env[i]->value, 1);
}
}
@ -1072,7 +1075,7 @@ void set_env() {
void run_exec() {
Arg arg;
for (int i = 0; i < config.exec_count; i++) {
for (int32_t i = 0; i < config.exec_count; i++) {
arg.v = config.exec[i];
spawn_shell(&arg);
}
@ -1081,7 +1084,7 @@ void run_exec() {
void run_exec_once() {
Arg arg;
for (int i = 0; i < config.exec_once_count; i++) {
for (int32_t i = 0; i < config.exec_once_count; i++) {
arg.v = config.exec_once[i];
spawn_shell(&arg);
}
@ -1135,39 +1138,43 @@ void parse_option(Config *config, char *key, char *value) {
} else if (strcmp(key, "animation_duration_focus") == 0) {
config->animation_duration_focus = atoi(value);
} else if (strcmp(key, "animation_curve_move") == 0) {
int num = parse_double_array(value, config->animation_curve_move, 4);
int32_t 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);
}
} else if (strcmp(key, "animation_curve_open") == 0) {
int num = parse_double_array(value, config->animation_curve_open, 4);
int32_t 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);
}
} else if (strcmp(key, "animation_curve_tag") == 0) {
int num = parse_double_array(value, config->animation_curve_tag, 4);
int32_t 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);
}
} else if (strcmp(key, "animation_curve_close") == 0) {
int num = parse_double_array(value, config->animation_curve_close, 4);
int32_t 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);
}
} else if (strcmp(key, "animation_curve_focus") == 0) {
int num = parse_double_array(value, config->animation_curve_focus, 4);
int32_t num =
parse_double_array(value, config->animation_curve_focus, 4);
if (num != 4) {
fprintf(stderr,
"Error: Failed to parse animation_curve_focus: %s\n",
value);
}
} else if (strcmp(key, "animation_curve_opafadein") == 0) {
int num =
int32_t num =
parse_double_array(value, config->animation_curve_opafadein, 4);
if (num != 4) {
fprintf(stderr,
@ -1175,7 +1182,7 @@ void parse_option(Config *config, char *key, char *value) {
value);
}
} else if (strcmp(key, "animation_curve_opafadeout") == 0) {
int num =
int32_t num =
parse_double_array(value, config->animation_curve_opafadeout, 4);
if (num != 4) {
fprintf(stderr,
@ -1256,12 +1263,12 @@ void parse_option(Config *config, char *key, char *value) {
'\0'; // 确保字符串以 null 结尾
} else if (strcmp(key, "scroller_proportion_preset") == 0) {
// 1. 统计 value 中有多少个逗号,确定需要解析的浮点数个数
int count = 0; // 初始化为 0
int32_t count = 0; // 初始化为 0
for (const char *p = value; *p; p++) {
if (*p == ',')
count++;
}
int float_count = count + 1; // 浮点数的数量是逗号数量加 1
int32_t float_count = count + 1; // 浮点数的数量是逗号数量加 1
// 2. 动态分配内存,存储浮点数
config->scroller_proportion_preset =
@ -1275,7 +1282,7 @@ void parse_option(Config *config, char *key, char *value) {
char *value_copy =
strdup(value); // 复制 value因为 strtok 会修改原字符串
char *token = strtok(value_copy, ",");
int i = 0;
int32_t i = 0;
float value_set;
while (token != NULL && i < float_count) {
@ -1315,12 +1322,12 @@ void parse_option(Config *config, char *key, char *value) {
free(value_copy);
} else if (strcmp(key, "circle_layout") == 0) {
// 1. 统计 value 中有多少个逗号,确定需要解析的字符串个数
int count = 0; // 初始化为 0
int32_t count = 0; // 初始化为 0
for (const char *p = value; *p; p++) {
if (*p == ',')
count++;
}
int string_count = count + 1; // 字符串的数量是逗号数量加 1
int32_t string_count = count + 1; // 字符串的数量是逗号数量加 1
// 2. 动态分配内存,存储字符串指针
config->circle_layout = (char **)malloc(string_count * sizeof(char *));
@ -1334,7 +1341,7 @@ void parse_option(Config *config, char *key, char *value) {
char *value_copy =
strdup(value); // 复制 value因为 strtok 会修改原字符串
char *token = strtok(value_copy, ",");
int i = 0;
int32_t i = 0;
char *cleaned_token;
while (token != NULL && i < string_count) {
// 为每个字符串分配内存并复制内容
@ -1345,7 +1352,7 @@ void parse_option(Config *config, char *key, char *value) {
"Error: Memory allocation failed for string: %s\n",
token);
// 释放之前分配的内存
for (int j = 0; j < i; j++) {
for (int32_t j = 0; j < i; j++) {
free(config->circle_layout[j]);
}
free(config->circle_layout);
@ -1362,7 +1369,7 @@ void parse_option(Config *config, char *key, char *value) {
if (i != string_count) {
fprintf(stderr, "Error: Invalid circle_layout format: %s\n", value);
// 释放之前分配的内存
for (int j = 0; j < i; j++) {
for (int32_t j = 0; j < i; j++) {
free(config->circle_layout[j]);
}
free(config->circle_layout);
@ -1468,7 +1475,7 @@ void parse_option(Config *config, char *key, char *value) {
} else if (strcmp(key, "borderpx") == 0) {
config->borderpx = atoi(value);
} else if (strcmp(key, "rootcolor") == 0) {
long int color = parse_color(value);
int64_t color = parse_color(value);
if (color == -1) {
fprintf(stderr, "Error: Invalid rootcolor format: %s\n", value);
} else {
@ -1476,21 +1483,21 @@ void parse_option(Config *config, char *key, char *value) {
}
} else if (strcmp(key, "bordercolor") == 0) {
long int color = parse_color(value);
int64_t color = parse_color(value);
if (color == -1) {
fprintf(stderr, "Error: Invalid bordercolor format: %s\n", value);
} else {
convert_hex_to_rgba(config->bordercolor, color);
}
} else if (strcmp(key, "focuscolor") == 0) {
long int color = parse_color(value);
int64_t color = parse_color(value);
if (color == -1) {
fprintf(stderr, "Error: Invalid focuscolor format: %s\n", value);
} else {
convert_hex_to_rgba(config->focuscolor, color);
}
} else if (strcmp(key, "maximizescreencolor") == 0) {
long int color = parse_color(value);
int64_t color = parse_color(value);
if (color == -1) {
fprintf(stderr, "Error: Invalid maximizescreencolor format: %s\n",
value);
@ -1498,14 +1505,14 @@ void parse_option(Config *config, char *key, char *value) {
convert_hex_to_rgba(config->maximizescreencolor, color);
}
} else if (strcmp(key, "urgentcolor") == 0) {
long int color = parse_color(value);
int64_t color = parse_color(value);
if (color == -1) {
fprintf(stderr, "Error: Invalid urgentcolor format: %s\n", value);
} else {
convert_hex_to_rgba(config->urgentcolor, color);
}
} else if (strcmp(key, "scratchpadcolor") == 0) {
long int color = parse_color(value);
int64_t color = parse_color(value);
if (color == -1) {
fprintf(stderr, "Error: Invalid scratchpadcolor format: %s\n",
value);
@ -1513,14 +1520,14 @@ void parse_option(Config *config, char *key, char *value) {
convert_hex_to_rgba(config->scratchpadcolor, color);
}
} else if (strcmp(key, "globalcolor") == 0) {
long int color = parse_color(value);
int64_t color = parse_color(value);
if (color == -1) {
fprintf(stderr, "Error: Invalid globalcolor format: %s\n", value);
} else {
convert_hex_to_rgba(config->globalcolor, color);
}
} else if (strcmp(key, "overlaycolor") == 0) {
long int color = parse_color(value);
int64_t color = parse_color(value);
if (color == -1) {
fprintf(stderr, "Error: Invalid overlaycolor format: %s\n", value);
} else {
@ -1635,7 +1642,7 @@ void parse_option(Config *config, char *key, char *value) {
ConfigWinRule *rule = &config->window_rules[config->window_rules_count];
memset(rule, 0, sizeof(ConfigWinRule));
// int rule value, relay to a client property
// int32_t rule value, relay to a client property
rule->isfloating = -1;
rule->isfullscreen = -1;
rule->isnoborder = -1;
@ -1804,7 +1811,7 @@ void parse_option(Config *config, char *key, char *value) {
raw_height[256], raw_refresh[256];
// 先读取所有字段为字符串
int parsed =
int32_t parsed =
sscanf(value,
"%255[^,],%255[^,],%255[^,],%255[^,],%255[^,],%255["
"^,],%255[^,],%255[^,],%255[^,],%255[^,],%255s",
@ -2318,7 +2325,7 @@ void parse_config_file(Config *config, const char *file_path) {
void free_circle_layout(Config *config) {
if (config->circle_layout) {
// 释放每个字符串
for (int i = 0; i < config->circle_layout_count; i++) {
for (int32_t i = 0; i < config->circle_layout_count; i++) {
if (config->circle_layout[i]) {
free(config->circle_layout[i]); // 释放单个字符串
config->circle_layout[i] = NULL; // 防止野指针
@ -2364,11 +2371,11 @@ void free_baked_points(void) {
void free_config(void) {
// 释放内存
int i;
int32_t i;
// 释放 window_rules
if (config.window_rules) {
for (int i = 0; i < config.window_rules_count; i++) {
for (int32_t i = 0; i < config.window_rules_count; i++) {
ConfigWinRule *rule = &config.window_rules[i];
if (rule->id)
free((void *)rule->id);
@ -2397,7 +2404,7 @@ void free_config(void) {
// 释放 monitor_rules
if (config.monitor_rules) {
for (int i = 0; i < config.monitor_rules_count; i++) {
for (int32_t i = 0; i < config.monitor_rules_count; i++) {
ConfigMonitorRule *rule = &config.monitor_rules[i];
free((void *)rule->name);
free((void *)rule->layout);
@ -2514,7 +2521,7 @@ void free_config(void) {
// 释放 tag_rules
if (config.tag_rules) {
for (int i = 0; i < config.tag_rules_count; i++) {
for (int32_t i = 0; i < config.tag_rules_count; i++) {
if (config.tag_rules[i].layout_name)
free((void *)config.tag_rules[i].layout_name);
if (config.tag_rules[i].monitor_name)
@ -2527,7 +2534,7 @@ void free_config(void) {
// 释放 layer_rules
if (config.layer_rules) {
for (int i = 0; i < config.layer_rules_count; i++) {
for (int32_t i = 0; i < config.layer_rules_count; i++) {
if (config.layer_rules[i].layer_name)
free((void *)config.layer_rules[i].layer_name);
if (config.layer_rules[i].animation_type_open)
@ -2542,7 +2549,7 @@ void free_config(void) {
// 释放 env
if (config.env) {
for (int i = 0; i < config.env_count; i++) {
for (int32_t i = 0; i < config.env_count; i++) {
if (config.env[i]->type) {
free((void *)config.env[i]->type);
}
@ -3007,7 +3014,7 @@ void parse_config(void) {
void reapply_monitor_rules(void) {
ConfigMonitorRule *mr;
Monitor *m = NULL;
int ji, jk;
int32_t ji, jk;
struct wlr_output_state state;
struct wlr_output_mode *internal_mode = NULL;
wlr_output_state_init(&state);
@ -3045,7 +3052,7 @@ void reapply_monitor_rules(void) {
} else if (wlr_output_is_headless(m->wlr_output)) {
wlr_output_state_set_custom_mode(
&state, mr->width, mr->height,
(int)roundf(mr->refresh * 1000));
(int32_t)roundf(mr->refresh * 1000));
}
}
@ -3142,7 +3149,7 @@ void reapply_pointer(void) {
void reapply_master(void) {
int i;
int32_t i;
Monitor *m = NULL;
for (i = 0; i <= LENGTH(tags); i++) {
wl_list_for_each(m, &mons, link) {
@ -3160,7 +3167,7 @@ void reapply_master(void) {
}
void parse_tagrule(Monitor *m) {
int i, jk;
int32_t i, jk;
ConfigTagRule tr;
for (i = 0; i < config.tag_rules_count; i++) {
@ -3212,7 +3219,7 @@ void reset_option(void) {
arrange(selmon, false, false);
}
int reload_config(const Arg *arg) {
int32_t reload_config(const Arg *arg) {
parse_config();
reset_option();
printstatus();