From 614a28abd1fac284cc4647b855954b0e0b3d5b09 Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Mon, 5 May 2025 17:45:25 +0800 Subject: [PATCH] feat: add cursor_size and cursor_theme option in config --- config.conf | 2 ++ src/config/parse_config.h | 16 ++++++++++++++++ src/config/preset_config.h | 1 + src/maomao.c | 12 +++++------- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/config.conf b/config.conf index fade1a1..883bdcd 100644 --- a/config.conf +++ b/config.conf @@ -51,6 +51,8 @@ focus_cross_monitor=0 focus_cross_tag=1 enable_floating_snap=0 snap_distance=30 +cursor_size=24 +# cursro_theme=Buuf # keyboard repeat_rate=25 diff --git a/src/config/parse_config.h b/src/config/parse_config.h index 564e456..7f49d51 100644 --- a/src/config/parse_config.h +++ b/src/config/parse_config.h @@ -204,6 +204,9 @@ typedef struct { char **exec_once; int exec_once_count; + char *cursor_theme; + unsigned int cursor_size; + } Config; typedef void (*FuncType)(const Arg *); @@ -832,6 +835,10 @@ void parse_config_line(Config *config, const char *line) { config->mouse_natural_scrolling = atoi(value); } else if (strcmp(key, "trackpad_natural_scrolling") == 0) { config->trackpad_natural_scrolling = atoi(value); + } else if (strcmp(key, "cursor_size") == 0) { + config->cursor_size = atoi(value); + } else if (strcmp(key, "cursor_theme") == 0) { + config->cursor_theme = strdup(value); } else if (strcmp(key, "disable_while_typing") == 0) { config->disable_while_typing = atoi(value); } else if (strcmp(key, "left_handed") == 0) { @@ -1464,11 +1471,17 @@ void free_config(void) { config.scroller_proportion_preset_count = 0; } + if(config.cursor_theme) { + free(config.cursor_theme); + config.cursor_theme = NULL; + } + // 释放 circle_layout free_circle_layout(&config); // 释放动画资源 free_baked_points(); + } void override_config(void) { @@ -1534,6 +1547,7 @@ void override_config(void) { tap_and_drag = config.tap_and_drag; drag_lock = config.drag_lock; mouse_natural_scrolling = config.mouse_natural_scrolling; + cursor_size = config.cursor_size; trackpad_natural_scrolling = config.trackpad_natural_scrolling; disable_while_typing = config.disable_while_typing; left_handed = config.left_handed; @@ -1622,6 +1636,7 @@ void set_value_default() { config.tap_and_drag = tap_and_drag; config.drag_lock = drag_lock; config.mouse_natural_scrolling = mouse_natural_scrolling; + config.cursor_size = cursor_size; config.trackpad_natural_scrolling = trackpad_natural_scrolling; config.disable_while_typing = disable_while_typing; config.left_handed = left_handed; @@ -1703,6 +1718,7 @@ void parse_config(void) { config.circle_layout_count = 0; config.tag_rules = NULL; config.tag_rules_count = 0; + config.cursor_theme = NULL; // 获取 MAOMAOCONFIG 环境变量 const char *maomaoconfig = getenv("MAOMAOCONFIG"); diff --git a/src/config/preset_config.h b/src/config/preset_config.h index a9f05e4..7d9abda 100644 --- a/src/config/preset_config.h +++ b/src/config/preset_config.h @@ -53,6 +53,7 @@ int focus_cross_monitor = 0; int focus_cross_tag = 0; int snap_distance = 30; int enable_floating_snap = 0; +unsigned int cursor_size = 24; unsigned int swipe_min_threshold = 20; diff --git a/src/maomao.c b/src/maomao.c index d7adf64..b0a9375 100644 --- a/src/maomao.c +++ b/src/maomao.c @@ -5588,13 +5588,12 @@ void handle_foreign_destroy(struct wl_listener *listener, void *data) { void setup(void) { - // signal(SIGSEGV, signalhandler); - parse_config(); - - init_baked_points(); - + setenv("XCURSOR_SIZE", "24", 1); setenv("XDG_CURRENT_DESKTOP", "maomao", 1); + parse_config(); + init_baked_points(); + int drm_fd, i, sig[] = {SIGCHLD, SIGINT, SIGTERM, SIGPIPE}; struct sigaction sa = {.sa_flags = SA_RESTART, .sa_handler = handlesig}; sigemptyset(&sa.sa_mask); @@ -5750,8 +5749,7 @@ void setup(void) { * images are available at all scale factors on the screen (necessary for * HiDPI support). Scaled cursors will be loaded with each output. */ // cursor_mgr = wlr_xcursor_manager_create(cursor_theme, 24); - cursor_mgr = wlr_xcursor_manager_create(NULL, 24); - setenv("XCURSOR_SIZE", "24", 1); + cursor_mgr = wlr_xcursor_manager_create(config.cursor_theme, cursor_size); /* * wlr_cursor *only* displays an image on screen. It does not move around