diff --git a/src/action.h b/src/action.h index 721b436..9c8e012 100644 --- a/src/action.h +++ b/src/action.h @@ -6,3 +6,4 @@ void spawn(const user_action_arg_t *arg); void quit(const user_action_arg_t *arg); 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); diff --git a/src/config.h b/src/config.h index 0e7ccc1..c9e110b 100644 --- a/src/config.h +++ b/src/config.h @@ -91,6 +91,8 @@ const keybinding_t keys[] = { {SUPER | SHIFT, XK_q, quit, {.b = false}}, {SUPER | CTRL, XK_r, quit, {.b = true}}, {SUPER | SHIFT, XK_c, kill_client, {0}}, + {ALT, XK_j, focus_stack, {.b = true}}, + {ALT, XK_k, focus_stack, {.b = false}}, {SUPER, XK_1, select_tag, {.ui = 0}}, {SUPER, XK_2, select_tag, {.ui = 1}}, {SUPER, XK_3, select_tag, {.ui = 2}}, diff --git a/src/main.c b/src/main.c index de777eb..eea114f 100644 --- a/src/main.c +++ b/src/main.c @@ -117,6 +117,36 @@ void kill_client(const user_action_arg_t *arg) { } } +void focus_stack(const user_action_arg_t *arg) { + if (!current_monitor->selected_client) return; + + bool forward = arg->b; + client_t *client = NULL; + if (forward) { + for (client = current_monitor->selected_client->next; + client && !CLIENT_VISIBLE(client); client = client->next); + if (!client) { + for (client = current_monitor->clients; client && !CLIENT_VISIBLE(client); + client = client->next); + } + } else { + client_t *c = NULL; + for (c = current_monitor->clients; c != current_monitor->selected_client; + c = c->next) { + if (CLIENT_VISIBLE(c)) client = c; + } + if (!client) { + for (; c; c = c->next) { + if (CLIENT_VISIBLE(c)) client = c; + } + } + } + if (client) { + focus(client); + restack(current_monitor); + } +} + /* 调试函数,开发完成后删除 */ static void print_monitor_list_info(monitor_t *monitor_list) { logger("========================= monitor info =========================\n");