Skip to content

Commit 30692f6

Browse files
committed
feat: add option hotarea_corner
1 parent 2e6e236 commit 30692f6

3 files changed

Lines changed: 61 additions & 11 deletions

File tree

src/config/parse_config.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ typedef struct {
232232
int32_t center_when_single_stack;
233233

234234
uint32_t hotarea_size;
235+
uint32_t hotarea_corner;
235236
uint32_t enable_hotarea;
236237
uint32_t ov_tab_mode;
237238
int32_t overviewgappi;
@@ -1452,6 +1453,8 @@ void parse_option(Config *config, char *key, char *value) {
14521453
config->center_when_single_stack = atoi(value);
14531454
} else if (strcmp(key, "hotarea_size") == 0) {
14541455
config->hotarea_size = atoi(value);
1456+
} else if (strcmp(key, "hotarea_corner") == 0) {
1457+
config->hotarea_corner = atoi(value);
14551458
} else if (strcmp(key, "enable_hotarea") == 0) {
14561459
config->enable_hotarea = atoi(value);
14571460
} else if (strcmp(key, "ov_tab_mode") == 0) {
@@ -2739,6 +2742,7 @@ void override_config(void) {
27392742

27402743
// 概述模式设置
27412744
hotarea_size = CLAMP_INT(config.hotarea_size, 1, 1000);
2745+
hotarea_corner = CLAMP_INT(config.hotarea_corner, 0, 3);
27422746
enable_hotarea = CLAMP_INT(config.enable_hotarea, 0, 1);
27432747
ov_tab_mode = CLAMP_INT(config.ov_tab_mode, 0, 1);
27442748
overviewgappi = CLAMP_INT(config.overviewgappi, 0, 1000);
@@ -2901,8 +2905,9 @@ void set_value_default() {
29012905

29022906
config.numlockon = numlockon; // 是否打开右边小键盘
29032907

2904-
config.ov_tab_mode = ov_tab_mode; // alt tab切换模式
2905-
config.hotarea_size = hotarea_size; // 热区大小,10x10
2908+
config.ov_tab_mode = ov_tab_mode; // alt tab切换模式
2909+
config.hotarea_size = hotarea_size; // 热区大小,10x10
2910+
config.hotarea_corner = hotarea_corner;
29062911
config.enable_hotarea = enable_hotarea; // 是否启用鼠标热区
29072912
config.smartgaps =
29082913
smartgaps; /* 1 means no outer gap when there is only one window */

src/config/preset.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ int32_t log_level = WLR_ERROR;
4747
uint32_t numlockon = 0; // 是否打开右边小键盘
4848
uint32_t capslock = 0; // 是否启用快捷键
4949

50-
uint32_t ov_tab_mode = 0; // alt tab切换模式
51-
uint32_t hotarea_size = 10; // 热区大小,10x10
50+
uint32_t ov_tab_mode = 0; // alt tab切换模式
51+
uint32_t hotarea_size = 10; // 热区大小,10x10
52+
uint32_t hotarea_corner = BOTTOM_LEFT;
5253
uint32_t enable_hotarea = 1; // 是否启用鼠标热区
5354
int32_t smartgaps = 0; /* 1 means no outer gap when there is only one window */
5455
int32_t sloppyfocus = 1; /* focus follows mouse */

src/mango.c

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@
143143
#define BAKED_POINTS_COUNT 256
144144

145145
/* enums */
146+
enum { TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT };
147+
146148
enum { VERTICAL, HORIZONTAL };
147149
enum { SWIPE_UP, SWIPE_DOWN, SWIPE_LEFT, SWIPE_RIGHT };
148150
enum { CurNormal, CurPressed, CurMove, CurResize }; /* cursor */
@@ -1215,17 +1217,59 @@ void toggle_hotarea(int32_t x_root, int32_t y_root) {
12151217
if (grabc)
12161218
return;
12171219

1218-
unsigned hx = selmon->m.x + hotarea_size;
1219-
unsigned hy = selmon->m.y + selmon->m.height - hotarea_size;
1220+
// 根据热角位置计算不同的热区坐标
1221+
unsigned hx, hy;
1222+
1223+
switch (hotarea_corner) {
1224+
case BOTTOM_RIGHT: // 右下角
1225+
hx = selmon->m.x + selmon->m.width - hotarea_size;
1226+
hy = selmon->m.y + selmon->m.height - hotarea_size;
1227+
break;
1228+
case TOP_LEFT: // 左上角
1229+
hx = selmon->m.x + hotarea_size;
1230+
hy = selmon->m.y + hotarea_size;
1231+
break;
1232+
case TOP_RIGHT: // 右上角
1233+
hx = selmon->m.x + selmon->m.width - hotarea_size;
1234+
hy = selmon->m.y + hotarea_size;
1235+
break;
1236+
case BOTTOM_LEFT: // 左下角(默认)
1237+
default:
1238+
hx = selmon->m.x + hotarea_size;
1239+
hy = selmon->m.y + selmon->m.height - hotarea_size;
1240+
break;
1241+
}
1242+
1243+
// 判断鼠标是否在热区内
1244+
int in_hotarea = 0;
1245+
1246+
switch (hotarea_corner) {
1247+
case BOTTOM_RIGHT: // 右下角
1248+
in_hotarea = (y_root > hy && x_root > hx &&
1249+
x_root <= (selmon->m.x + selmon->m.width) &&
1250+
y_root <= (selmon->m.y + selmon->m.height));
1251+
break;
1252+
case TOP_LEFT: // 左上角
1253+
in_hotarea = (y_root < hy && x_root < hx && x_root >= selmon->m.x &&
1254+
y_root >= selmon->m.y);
1255+
break;
1256+
case TOP_RIGHT: // 右上角
1257+
in_hotarea = (y_root < hy && x_root > hx &&
1258+
x_root <= (selmon->m.x + selmon->m.width) &&
1259+
y_root >= selmon->m.y);
1260+
break;
1261+
case BOTTOM_LEFT: // 左下角(默认)
1262+
default:
1263+
in_hotarea = (y_root > hy && x_root < hx && x_root >= selmon->m.x &&
1264+
y_root <= (selmon->m.y + selmon->m.height));
1265+
break;
1266+
}
12201267

1221-
if (enable_hotarea == 1 && selmon->is_in_hotarea == 0 && y_root > hy &&
1222-
x_root < hx && x_root >= selmon->m.x &&
1223-
y_root <= (selmon->m.y + selmon->m.height)) {
1268+
if (enable_hotarea == 1 && selmon->is_in_hotarea == 0 && in_hotarea) {
12241269
toggleoverview(&arg);
12251270
selmon->is_in_hotarea = 1;
12261271
} else if (enable_hotarea == 1 && selmon->is_in_hotarea == 1 &&
1227-
(y_root <= hy || x_root >= hx || x_root < selmon->m.x ||
1228-
y_root > (selmon->m.y + selmon->m.height))) {
1272+
!in_hotarea) {
12291273
selmon->is_in_hotarea = 0;
12301274
}
12311275
}

0 commit comments

Comments
 (0)