添加切换 tag 的快捷键
This commit is contained in:
@@ -4,3 +4,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);
|
||||
|
||||
@@ -90,6 +90,15 @@ const keybinding_t keys[] = {
|
||||
{SUPER, XK_p, spawn, {.ptr = launcher}},
|
||||
{SUPER, XK_q, quit, {.b = false}},
|
||||
{SUPER, XK_r, quit, {.b = true}},
|
||||
{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 }},
|
||||
};
|
||||
|
||||
const char *const bar_bg = "#222222";
|
||||
|
||||
101
src/main.c
101
src/main.c
@@ -31,7 +31,8 @@ static void init_color_set(void);
|
||||
static void parse_color(const char *hex, color_t *color);
|
||||
static void init_monitor_bar(void);
|
||||
static void get_xresource_config(void);
|
||||
static void update_bars(void);
|
||||
static void draw_all_monitor_bars(void);
|
||||
static void draw_monitor_bar(monitor_t *monitor);
|
||||
static void init_xcb_event_loop(void);
|
||||
static void xcb_event_handler(generic_event_t *event, void *user_data);
|
||||
static void key_press(key_press_event_t *event);
|
||||
@@ -42,11 +43,15 @@ static void manage_window(xcb_window_t window);
|
||||
static void unmanage_client(client_t *client);
|
||||
static void update_client_name(client_t *client);
|
||||
static void apply_rules(client_t *client);
|
||||
static uint32_t get_tags_mask_of_monitor(monitor_t *monitor);
|
||||
static void attach_client(client_t *client);
|
||||
static void detach_client(client_t *client);
|
||||
static void attach_stack_client(client_t *client);
|
||||
static void detach_stack_client(client_t *client);
|
||||
static void arrange(monitor_t *monitor);
|
||||
static void show_hide_client(client_t *client);
|
||||
static void restack(monitor_t *monitor);
|
||||
static void focus(client_t *client);
|
||||
static void apply_monitor_layout(monitor_t *monitor);
|
||||
static client_t *get_client_of_window(xcb_window_t window);
|
||||
static gboolean handle_xcb_event(GIOChannel *channel, GIOCondition condition,
|
||||
@@ -77,6 +82,16 @@ void quit(const user_action_arg_t *arg) {
|
||||
g_main_loop_quit(loop);
|
||||
}
|
||||
|
||||
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;
|
||||
if (!target_tag || current_monitor->selected_tags == target_tag) return;
|
||||
|
||||
current_monitor->selected_tags = target_tag;
|
||||
focus(NULL);
|
||||
arrange(current_monitor);
|
||||
}
|
||||
|
||||
/* 调试函数,开发完成后删除 */
|
||||
static void print_monitor_list_info(monitor_t *monitor_list) {
|
||||
printf("========================= monitor info =========================\n");
|
||||
@@ -412,10 +427,12 @@ void get_xresource_config(void) {
|
||||
clean_xresource();
|
||||
}
|
||||
|
||||
void update_bars(void) {
|
||||
for (monitor_t *m = monitors; m; m = m->next) {
|
||||
draw_bar(m, m == current_monitor, color_set, bar_height, tag_x_padding);
|
||||
}
|
||||
void draw_all_monitor_bars(void) {
|
||||
for (monitor_t *m = monitors; m; m = m->next) draw_monitor_bar(m);
|
||||
}
|
||||
|
||||
void draw_monitor_bar(monitor_t *m) {
|
||||
draw_bar(m, m == current_monitor, color_set, bar_height, tag_x_pad);
|
||||
flush_xcb_connection();
|
||||
}
|
||||
|
||||
@@ -516,14 +533,11 @@ void manage_window(xcb_window_t window) {
|
||||
|
||||
attach_client(c);
|
||||
attach_stack_client(c);
|
||||
apply_monitor_layout(c->monitor);
|
||||
init_window_event_mask(window);
|
||||
change_window_border_color(window, color_set->border_color.argb);
|
||||
arrange(c->monitor);
|
||||
map_window(window);
|
||||
show_hide_client(c);
|
||||
flush_xcb_connection();
|
||||
|
||||
update_bars();
|
||||
draw_all_monitor_bars();
|
||||
}
|
||||
|
||||
void unmanage_client(client_t *client) {
|
||||
@@ -532,7 +546,7 @@ void unmanage_client(client_t *client) {
|
||||
detach_client(client);
|
||||
detach_stack_client(client);
|
||||
free(client);
|
||||
apply_monitor_layout(monitor);
|
||||
arrange(monitor);
|
||||
flush_xcb_connection();
|
||||
}
|
||||
|
||||
@@ -581,8 +595,7 @@ void apply_rules(client_t *client) {
|
||||
for (uint32_t i = 0; i < tag->monitor_index; i++) m = m ? m->next : NULL;
|
||||
if (!m) continue;
|
||||
|
||||
uint32_t tags_mask = 0;
|
||||
for (uint32_t i = 0; m->tags[i]; i++) tags_mask |= (1 << i);
|
||||
uint32_t tags_mask = get_tags_mask_of_monitor(m);
|
||||
client->tags = tag->tags & tags_mask;
|
||||
}
|
||||
}
|
||||
@@ -600,6 +613,12 @@ void apply_rules(client_t *client) {
|
||||
printf("apply rules done\n");
|
||||
}
|
||||
|
||||
uint32_t get_tags_mask_of_monitor(monitor_t *monitor) {
|
||||
uint32_t tags_mask = 0;
|
||||
for (uint32_t i = 0; monitor->tags[i]; i++) tags_mask |= (1 << i);
|
||||
return tags_mask;
|
||||
}
|
||||
|
||||
void attach_client(client_t *client) {
|
||||
client->next = client->monitor->clients;
|
||||
client->monitor->clients = client;
|
||||
@@ -628,12 +647,52 @@ void detach_stack_client(client_t *client) {
|
||||
}
|
||||
}
|
||||
|
||||
void arrange(monitor_t *monitor) {
|
||||
if (monitor) {
|
||||
show_hide_client(monitor->clients_stack);
|
||||
apply_monitor_layout(monitor);
|
||||
restack(monitor);
|
||||
} else {
|
||||
for (monitor = monitors; monitor; monitor = monitor->next) {
|
||||
show_hide_client(monitor->clients_stack);
|
||||
apply_monitor_layout(monitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void restack(monitor_t *monitor) { /* TODO: */ draw_monitor_bar(monitor); }
|
||||
void focus(client_t *client) {
|
||||
/* TODO: */
|
||||
current_monitor->selected_client = client;
|
||||
draw_all_monitor_bars();
|
||||
}
|
||||
|
||||
void show_hide_client(client_t *client) {
|
||||
if (!client || CLIENT_VISIBLE(client)) return;
|
||||
client->x = client->monitor->monitor_x;
|
||||
client->y = client->monitor->monitor_y + client->monitor->monitor_height;
|
||||
configure_window(client->window, client->x, client->y, client->window,
|
||||
client->height, client->border_width);
|
||||
if (!client) return;
|
||||
|
||||
if (CLIENT_VISIBLE(client)) {
|
||||
if (client->fullscreen) {
|
||||
fullscreen_client(client);
|
||||
} else if (client->maximize) {
|
||||
maximize_client(client);
|
||||
} else if (!client->monitor->layout->arrange || client->floating) {
|
||||
client->x = client->old_x;
|
||||
client->y = client->old_y;
|
||||
}
|
||||
configure_window(client->window, client->x, client->y, client->width,
|
||||
client->height, client->border_width);
|
||||
show_hide_client(client->stack_next);
|
||||
} else {
|
||||
if (!client->monitor->layout->arrange || client->floating) {
|
||||
client->old_x = client->x;
|
||||
client->old_y = client->y;
|
||||
}
|
||||
client->x = client->monitor->monitor_x;
|
||||
client->y = client->monitor->monitor_y + client->monitor->monitor_height;
|
||||
show_hide_client(client->stack_next);
|
||||
configure_window(client->window, client->x, client->y, client->window,
|
||||
client->height, client->border_width);
|
||||
}
|
||||
}
|
||||
|
||||
void apply_monitor_layout(monitor_t *monitor) {
|
||||
@@ -642,13 +701,9 @@ void apply_monitor_layout(monitor_t *monitor) {
|
||||
monitor->layout->arrange(monitor);
|
||||
for (client_t *c = next_visible_client(monitor->clients); c;
|
||||
c = next_visible_client(c->next)) {
|
||||
printf("apply window[0x%x] rect: x: %d, y: %d, w: %u, h: %u, bw: %u\n",
|
||||
c->window, c->x, c->y, c->width, c->height, c->border_width);
|
||||
configure_window(c->window, c->x, c->y, c->width, c->height,
|
||||
c->border_width);
|
||||
}
|
||||
|
||||
printf("apply monitor layout\n");
|
||||
}
|
||||
|
||||
client_t *get_client_of_window(xcb_window_t window) {
|
||||
@@ -717,7 +772,7 @@ int main(int argc, char *argv[]) {
|
||||
change_window_cursor(get_root_window(), cursor_normal);
|
||||
init_wallpaper();
|
||||
|
||||
update_bars();
|
||||
draw_all_monitor_bars();
|
||||
|
||||
window_list_t *window_list = scan_window_list();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user