This commit is contained in:
Mykolas Bamberg 2026-06-19 08:46:09 +02:00 committed by GitHub
commit 6369a8b944
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 10 deletions

View file

@ -145,7 +145,10 @@ typedef struct {
} AxisBinding; } AxisBinding;
typedef struct { typedef struct {
uint32_t fold; struct {
enum wlr_switch_type type;
enum wlr_switch_state state;
} switch_action;
int32_t (*func)(const Arg *); int32_t (*func)(const Arg *);
Arg arg; Arg arg;
} SwitchBinding; } SwitchBinding;
@ -587,24 +590,41 @@ int32_t parse_force(const char *str) {
} }
} }
int32_t parse_fold_state(const char *str) { typeof((SwitchBinding){}.switch_action) parse_switch_action(const char *str) {
// 将输入字符串转换为小写 // 将输入字符串转换为小写
char lowerStr[10]; char lowerStr[18];
int32_t i = 0; int32_t i = 0;
while (str[i] && i < 9) { while (str[i] && i < 17) {
lowerStr[i] = tolower(str[i]); lowerStr[i] = tolower(str[i]);
i++; i++;
} }
lowerStr[i] = '\0'; lowerStr[i] = '\0';
// 根据转换后的小写字符串返回对应的枚举值 // 根据转换后的小写字符串返回对应的枚举值
typeof((SwitchBinding){}.switch_action) result = {};
if (strcmp(lowerStr, "fold") == 0) { if (strcmp(lowerStr, "fold") == 0) {
return FOLD; result.type = WLR_SWITCH_TYPE_LID;
result.state = WLR_SWITCH_STATE_ON;
} else if (strcmp(lowerStr, "unfold") == 0) { } else if (strcmp(lowerStr, "unfold") == 0) {
return UNFOLD; result.type = WLR_SWITCH_TYPE_LID;
result.state = WLR_SWITCH_STATE_OFF;
} else if (strcmp(lowerStr, "tablet_on") == 0) {
result.type = WLR_SWITCH_TYPE_TABLET_MODE;
result.state = WLR_SWITCH_STATE_ON;
} else if (strcmp(lowerStr, "tablet_off") == 0) {
result.type = WLR_SWITCH_TYPE_TABLET_MODE;
result.state = WLR_SWITCH_STATE_OFF;
} else if (strcmp(lowerStr, "keypad_slide_on") == 0) {
result.type = WLR_SWITCH_TYPE_KEYPAD_SLIDE;
result.state = WLR_SWITCH_STATE_ON;
} else if (strcmp(lowerStr, "keypad_slide_off") == 0) {
result.type = WLR_SWITCH_TYPE_KEYPAD_SLIDE;
result.state = WLR_SWITCH_STATE_OFF;
} else { } else {
return INVALIDFOLD; result.type = -1;
result.state = -1;
} }
return result;
} }
int64_t parse_color(const char *hex_str) { int64_t parse_color(const char *hex_str) {
char *endptr; char *endptr;
@ -2889,7 +2909,7 @@ bool parse_option(Config *config, char *key, char *value) {
trim_whitespace(arg_value4); trim_whitespace(arg_value4);
trim_whitespace(arg_value5); trim_whitespace(arg_value5);
binding->fold = parse_fold_state(fold_str); binding->switch_action = parse_switch_action(fold_str);
binding->func = binding->func =
parse_func_name(func_name, &binding->arg, arg_value, arg_value2, parse_func_name(func_name, &binding->arg, arg_value, arg_value2,
arg_value3, arg_value4, arg_value5); arg_value3, arg_value4, arg_value5);

View file

@ -192,7 +192,6 @@ enum {
#endif #endif
enum { UP, DOWN, LEFT, RIGHT, UNDIR }; /* smartmovewin */ enum { UP, DOWN, LEFT, RIGHT, UNDIR }; /* smartmovewin */
enum { NONE, OPEN, MOVE, CLOSE, TAG, FOCUS, OPAFADEIN, OPAFADEOUT, OVERVIEW }; enum { NONE, OPEN, MOVE, CLOSE, TAG, FOCUS, OPAFADEIN, OPAFADEOUT, OVERVIEW };
enum { UNFOLD, FOLD, INVALIDFOLD };
enum { PREV, NEXT }; enum { PREV, NEXT };
enum { STATE_UNSPECIFIED = 0, STATE_ENABLED, STATE_DISABLED }; enum { STATE_UNSPECIFIED = 0, STATE_ENABLED, STATE_DISABLED };
enum { FORCE, UNFORCE }; enum { FORCE, UNFORCE };
@ -3601,7 +3600,8 @@ void switch_toggle(struct wl_listener *listener, void *data) {
if (config.switch_bindings_count < 1) if (config.switch_bindings_count < 1)
break; break;
s = &config.switch_bindings[ji]; s = &config.switch_bindings[ji];
if (event->switch_state == s->fold && s->func) { if (event->switch_type == s->switch_action.type &&
event->switch_state == s->switch_action.state && s->func) {
s->func(&s->arg); s->func(&s->arg);
return; return;
} }