添加 raise or run 功能并添加对应快捷键

This commit is contained in:
2025-08-27 04:27:12 +08:00
parent 8d9becbf0f
commit 96629c3045
3 changed files with 48 additions and 10 deletions

View File

@@ -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);

View File

@@ -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";

View File

@@ -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");