diff --git a/src/config/parse_config.h b/src/config/parse_config.h index 81eda9d..c345836 100644 --- a/src/config/parse_config.h +++ b/src/config/parse_config.h @@ -232,6 +232,7 @@ typedef struct { int32_t center_when_single_stack; uint32_t hotarea_size; + uint32_t hotarea_corner; uint32_t enable_hotarea; uint32_t ov_tab_mode; int32_t overviewgappi; @@ -1452,6 +1453,8 @@ void parse_option(Config *config, char *key, char *value) { config->center_when_single_stack = atoi(value); } else if (strcmp(key, "hotarea_size") == 0) { config->hotarea_size = atoi(value); + } else if (strcmp(key, "hotarea_corner") == 0) { + config->hotarea_corner = atoi(value); } else if (strcmp(key, "enable_hotarea") == 0) { config->enable_hotarea = atoi(value); } else if (strcmp(key, "ov_tab_mode") == 0) { @@ -2739,6 +2742,7 @@ void override_config(void) { // 概述模式设置 hotarea_size = CLAMP_INT(config.hotarea_size, 1, 1000); + hotarea_corner = CLAMP_INT(config.hotarea_corner, 0, 3); enable_hotarea = CLAMP_INT(config.enable_hotarea, 0, 1); ov_tab_mode = CLAMP_INT(config.ov_tab_mode, 0, 1); overviewgappi = CLAMP_INT(config.overviewgappi, 0, 1000); @@ -2901,8 +2905,9 @@ void set_value_default() { config.numlockon = numlockon; // 是否打开右边小键盘 - config.ov_tab_mode = ov_tab_mode; // alt tab切换模式 - config.hotarea_size = hotarea_size; // 热区大小,10x10 + config.ov_tab_mode = ov_tab_mode; // alt tab切换模式 + config.hotarea_size = hotarea_size; // 热区大小,10x10 + config.hotarea_corner = hotarea_corner; config.enable_hotarea = enable_hotarea; // 是否启用鼠标热区 config.smartgaps = smartgaps; /* 1 means no outer gap when there is only one window */ diff --git a/src/config/preset.h b/src/config/preset.h index c8474dd..3d05161 100644 --- a/src/config/preset.h +++ b/src/config/preset.h @@ -47,8 +47,9 @@ int32_t log_level = WLR_ERROR; uint32_t numlockon = 0; // 是否打开右边小键盘 uint32_t capslock = 0; // 是否启用快捷键 -uint32_t ov_tab_mode = 0; // alt tab切换模式 -uint32_t hotarea_size = 10; // 热区大小,10x10 +uint32_t ov_tab_mode = 0; // alt tab切换模式 +uint32_t hotarea_size = 10; // 热区大小,10x10 +uint32_t hotarea_corner = BOTTOM_LEFT; uint32_t enable_hotarea = 1; // 是否启用鼠标热区 int32_t smartgaps = 0; /* 1 means no outer gap when there is only one window */ int32_t sloppyfocus = 1; /* focus follows mouse */ diff --git a/src/mango.c b/src/mango.c index ed4e12a..a32be83 100644 --- a/src/mango.c +++ b/src/mango.c @@ -143,6 +143,8 @@ #define BAKED_POINTS_COUNT 256 /* enums */ +enum { TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT }; + enum { VERTICAL, HORIZONTAL }; enum { SWIPE_UP, SWIPE_DOWN, SWIPE_LEFT, SWIPE_RIGHT }; enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */ @@ -1215,17 +1217,59 @@ void toggle_hotarea(int32_t x_root, int32_t y_root) { if (grabc) return; - unsigned hx = selmon->m.x + hotarea_size; - unsigned hy = selmon->m.y + selmon->m.height - hotarea_size; + // 根据热角位置计算不同的热区坐标 + unsigned hx, hy; - if (enable_hotarea == 1 && selmon->is_in_hotarea == 0 && y_root > hy && - x_root < hx && x_root >= selmon->m.x && - y_root <= (selmon->m.y + selmon->m.height)) { + switch (hotarea_corner) { + case BOTTOM_RIGHT: // 右下角 + hx = selmon->m.x + selmon->m.width - hotarea_size; + hy = selmon->m.y + selmon->m.height - hotarea_size; + break; + case TOP_LEFT: // 左上角 + hx = selmon->m.x + hotarea_size; + hy = selmon->m.y + hotarea_size; + break; + case TOP_RIGHT: // 右上角 + hx = selmon->m.x + selmon->m.width - hotarea_size; + hy = selmon->m.y + hotarea_size; + break; + case BOTTOM_LEFT: // 左下角(默认) + default: + hx = selmon->m.x + hotarea_size; + hy = selmon->m.y + selmon->m.height - hotarea_size; + break; + } + + // 判断鼠标是否在热区内 + int in_hotarea = 0; + + switch (hotarea_corner) { + case BOTTOM_RIGHT: // 右下角 + in_hotarea = (y_root > hy && x_root > hx && + x_root <= (selmon->m.x + selmon->m.width) && + y_root <= (selmon->m.y + selmon->m.height)); + break; + case TOP_LEFT: // 左上角 + in_hotarea = (y_root < hy && x_root < hx && x_root >= selmon->m.x && + y_root >= selmon->m.y); + break; + case TOP_RIGHT: // 右上角 + in_hotarea = (y_root < hy && x_root > hx && + x_root <= (selmon->m.x + selmon->m.width) && + y_root >= selmon->m.y); + break; + case BOTTOM_LEFT: // 左下角(默认) + default: + in_hotarea = (y_root > hy && x_root < hx && x_root >= selmon->m.x && + y_root <= (selmon->m.y + selmon->m.height)); + break; + } + + if (enable_hotarea == 1 && selmon->is_in_hotarea == 0 && in_hotarea) { toggleoverview(&arg); selmon->is_in_hotarea = 1; } else if (enable_hotarea == 1 && selmon->is_in_hotarea == 1 && - (y_root <= hy || x_root >= hx || x_root < selmon->m.x || - y_root > (selmon->m.y + selmon->m.height))) { + !in_hotarea) { selmon->is_in_hotarea = 0; } }