From 96629c3045364dfd5ae6f4e60d8283aa7e2991a6 Mon Sep 17 00:00:00 2001 From: Zedhugh Chen Date: Wed, 27 Aug 2025 04:27:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20raise=20or=20run=20?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=B9=B6=E6=B7=BB=E5=8A=A0=E5=AF=B9=E5=BA=94?= =?UTF-8?q?=E5=BF=AB=E6=8D=B7=E9=94=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/action.h | 1 + src/config.h | 32 +++++++++++++++++++++++--------- src/main.c | 25 ++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/src/action.h b/src/action.h index 8c245f3..b031014 100644 --- a/src/action.h +++ b/src/action.h @@ -8,3 +8,4 @@ void select_tag(const user_action_arg_t *arg); void kill_client(const user_action_arg_t *arg); void focus_stack(const user_action_arg_t *arg); void focus_monitor(const user_action_arg_t *arg); +void raise_or_run(const user_action_arg_t *arg); diff --git a/src/config.h b/src/config.h index 941be45..3d6f0a0 100644 --- a/src/config.h +++ b/src/config.h @@ -95,15 +95,29 @@ const keybinding_t keys[] = { {ALT, XK_k, focus_stack, {.b = false}}, {SUPER | SHIFT, XK_j, focus_monitor, {.b = true}}, {SUPER | SHIFT, XK_k, focus_monitor, {.b = false}}, - {SUPER, XK_1, select_tag, {.ui = 0}}, - {SUPER, XK_2, select_tag, {.ui = 1}}, - {SUPER, XK_3, select_tag, {.ui = 2}}, - {SUPER, XK_4, select_tag, {.ui = 3}}, - {SUPER, XK_5, select_tag, {.ui = 4}}, - {SUPER, XK_6, select_tag, {.ui = 5}}, - {SUPER, XK_7, select_tag, {.ui = 6}}, - {SUPER, XK_8, select_tag, {.ui = 7}}, - {SUPER, XK_9, select_tag, {.ui = 8}}, + { + SUPER, + XK_a, + raise_or_run, + {.ptr = (char *[]){"Google-chrome", "google-chrome-stable"}}, + }, + { + SUPER, + XK_e, + raise_or_run, + {.ptr = (char *[]){"Emacs", "emacsclient -a '' -c -n"}}, + }, + {ALT | CTRL, XK_r, raise_or_run, {.ptr = (char *[]){"St", "st"}}}, + {SUPER, XK_q, raise_or_run, {.ptr = (char *[]){"firefox", "firefox-bin"}}}, + {SUPER, XK_1, select_tag, {.ui = 1 << 0}}, + {SUPER, XK_2, select_tag, {.ui = 1 << 1}}, + {SUPER, XK_3, select_tag, {.ui = 1 << 2}}, + {SUPER, XK_4, select_tag, {.ui = 1 << 3}}, + {SUPER, XK_5, select_tag, {.ui = 1 << 4}}, + {SUPER, XK_6, select_tag, {.ui = 1 << 5}}, + {SUPER, XK_7, select_tag, {.ui = 1 << 6}}, + {SUPER, XK_8, select_tag, {.ui = 1 << 7}}, + {SUPER, XK_9, select_tag, {.ui = 1 << 8}}, }; const char *const bar_bg = "#222222"; diff --git a/src/main.c b/src/main.c index 2343ef7..0df873c 100644 --- a/src/main.c +++ b/src/main.c @@ -101,7 +101,7 @@ void quit(const user_action_arg_t *arg) { void select_tag(const user_action_arg_t *arg) { uint32_t tags_mask = get_tags_mask_of_monitor(current_monitor); - uint32_t target_tag = (1 << arg->ui) & tags_mask; + uint32_t target_tag = arg->ui & tags_mask; if (!target_tag || current_monitor->selected_tags == target_tag) return; current_monitor->selected_tags = target_tag; @@ -161,6 +161,29 @@ void focus_monitor(const user_action_arg_t *arg) { /* TODO: 调整鼠标光标 */ } +void raise_or_run(const user_action_arg_t *arg) { + const char *class = ((const char **)arg->ptr)[0]; + const char *command = ((const char **)arg->ptr)[1]; + user_action_arg_t argument; + for (monitor_t *m = monitors; m; m = m->next) { + for (client_t *c = m->clients; c; c = c->next) { + window_class_instance_t class_instance; + get_window_class_instance(c->window, &class_instance); + if (!strncmp(class, class_instance.class, sizeof(class_instance.class))) { + current_monitor = m; + argument.ui = c->tags; + select_tag(&argument); + focus(c); + raise_window(c->window); + return; + } + } + } + + argument.ptr = command; + spawn(&argument); +} + /* 调试函数,开发完成后删除 */ static void print_monitor_list_info(monitor_t *monitor_list) { logger("========================= monitor info =========================\n");