From 263e2e4260f90774b7d7300b37756ee60ae9e5cd Mon Sep 17 00:00:00 2001 From: DreamMaoMao <2523610504@qq.com> Date: Fri, 4 Jul 2025 12:29:49 +0800 Subject: [PATCH] feat: add option to set default scratchpad size --- config.conf | 2 ++ src/config/parse_config.h | 12 ++++++++++++ src/config/preset.h | 2 ++ src/maomao.c | 10 ++++++---- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/config.conf b/config.conf index 8ee6f97..87eb814 100644 --- a/config.conf +++ b/config.conf @@ -106,6 +106,8 @@ gappih=5 gappiv=5 gappoh=10 gappov=10 +scratchpad_width_ratio=0.8 +scratchpad_height_ratio=0.9 borderpx=4 rootcolor=0x201b14ff bordercolor=0x444444ff diff --git a/src/config/parse_config.h b/src/config/parse_config.h index 1afc32c..e6fdf4c 100644 --- a/src/config/parse_config.h +++ b/src/config/parse_config.h @@ -230,6 +230,8 @@ typedef struct { unsigned int gappoh; unsigned int gappov; unsigned int borderpx; + float scratchpad_width_ratio; + float scratchpad_height_ratio; float rootcolor[4]; float bordercolor[4]; float focuscolor[4]; @@ -1191,6 +1193,10 @@ void parse_config_line(Config *config, const char *line) { config->gappoh = atoi(value); } else if (strcmp(key, "gappov") == 0) { config->gappov = atoi(value); + } else if (strcmp(key, "scratchpad_width_ratio") == 0) { + config->scratchpad_width_ratio = atof(value); + } else if (strcmp(key, "scratchpad_height_ratio") == 0) { + config->scratchpad_height_ratio = atof(value); } else if (strcmp(key, "borderpx") == 0) { config->borderpx = atoi(value); } else if (strcmp(key, "rootcolor") == 0) { @@ -2194,6 +2200,10 @@ void override_config(void) { gappiv = CLAMP_INT(config.gappiv, 0, 1000); gappoh = CLAMP_INT(config.gappoh, 0, 1000); gappov = CLAMP_INT(config.gappov, 0, 1000); + scratchpad_width_ratio = + CLAMP_FLOAT(config.scratchpad_width_ratio, 0.1f, 1.0f); + scratchpad_height_ratio = + CLAMP_FLOAT(config.scratchpad_height_ratio, 0.1f, 1.0f); borderpx = CLAMP_INT(config.borderpx, 0, 200); smartgaps = CLAMP_INT(config.smartgaps, 0, 1); @@ -2282,6 +2292,8 @@ void set_value_default() { config.gappoh = gappoh; /* horiz outer gap between windows and screen edge */ config.gappov = gappov; /* vert outer gap between windows and screen edge */ + config.scratchpad_width_ratio = scratchpad_width_ratio; + config.scratchpad_height_ratio = scratchpad_height_ratio; config.scroller_structs = scroller_structs; config.scroller_default_proportion = scroller_default_proportion; diff --git a/src/config/preset.h b/src/config/preset.h index e14469c..9468074 100644 --- a/src/config/preset.h +++ b/src/config/preset.h @@ -48,6 +48,8 @@ unsigned int gappih = 5; /* horiz inner gap between windows */ unsigned int gappiv = 5; /* vert inner gap between windows */ unsigned int gappoh = 10; /* horiz outer gap between windows and screen edge */ unsigned int gappov = 10; /* vert outer gap between windows and screen edge */ +float scratchpad_width_ratio = 0.8; +float scratchpad_height_ratio = 0.9; int scroller_structs = 20; float scroller_default_proportion = 0.9; diff --git a/src/maomao.c b/src/maomao.c index b0e0686..d4a062d 100644 --- a/src/maomao.c +++ b/src/maomao.c @@ -1695,10 +1695,12 @@ void show_scratchpad(Client *c) { /* return if fullscreen */ if (!c->isfloating) { setfloating(c, 1); - c->geom.width = c->scratchpad_geom.width ? c->scratchpad_geom.width - : c->mon->w.width * 0.7; - c->geom.height = c->scratchpad_geom.height ? c->scratchpad_geom.height - : c->mon->w.height * 0.8; + c->geom.width = c->scratchpad_geom.width + ? c->scratchpad_geom.width + : c->mon->w.width * scratchpad_width_ratio; + c->geom.height = c->scratchpad_geom.height + ? c->scratchpad_geom.height + : c->mon->w.height * scratchpad_height_ratio; // 重新计算居中的坐标 c->oldgeom = c->geom = c->animainit_geom = c->animation.current = setclient_coordinate_center(c, c->geom, 0, 0);