diff --git a/src/action.h b/src/action.h index 9c8e012..8c245f3 100644 --- a/src/action.h +++ b/src/action.h @@ -7,3 +7,4 @@ 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); +void focus_monitor(const user_action_arg_t *arg); diff --git a/src/config.h b/src/config.h index c9e110b..941be45 100644 --- a/src/config.h +++ b/src/config.h @@ -93,6 +93,8 @@ const keybinding_t keys[] = { {SUPER | SHIFT, XK_c, kill_client, {0}}, {ALT, XK_j, focus_stack, {.b = true}}, {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}}, diff --git a/src/main.c b/src/main.c index eea114f..2343ef7 100644 --- a/src/main.c +++ b/src/main.c @@ -67,6 +67,7 @@ static void set_client_fullscreen(client_t *client, bool fullscreen); static void apply_monitor_layout(monitor_t *monitor); static client_t *get_client_of_window(xcb_window_t window); static monitor_t *get_monitor_of_window(xcb_window_t window); +static monitor_t *get_monitor_by_direction(bool forward); static gboolean handle_xcb_event(GIOChannel *channel, GIOCondition condition, gpointer userdata); static void cleanup(void); @@ -147,6 +148,19 @@ void focus_stack(const user_action_arg_t *arg) { } } +void focus_monitor(const user_action_arg_t *arg) { + if (!monitors->next) return; + + bool forward = arg->b; + monitor_t *monitor = get_monitor_by_direction(forward); + if (monitor == current_monitor) return; + + unfocus(current_monitor->selected_client, false); + current_monitor = monitor; + focus(NULL); + /* TODO: 调整鼠标光标 */ +} + /* 调试函数,开发完成后删除 */ static void print_monitor_list_info(monitor_t *monitor_list) { logger("========================= monitor info =========================\n"); @@ -1056,6 +1070,18 @@ monitor_t *get_monitor_of_window(xcb_window_t window) { return current_monitor; } +monitor_t *get_monitor_by_direction(bool forward) { + monitor_t *m = NULL; + if (forward) { + if (!(m = current_monitor->next)) m = monitors; + } else if (current_monitor == monitors) { + for (m = monitors; m->next; m = m->next); + } else { + for (m = monitors; m->next != current_monitor; m = m->next); + } + return m; +} + gboolean handle_xcb_event(GIOChannel *channel, GIOCondition condition, gpointer userdata) { if (condition & (G_IO_HUP | G_IO_ERR)) {