添加布局算法并在新建窗口时应用规则
This commit is contained in:
102
src/main.c
102
src/main.c
@@ -14,6 +14,7 @@
|
||||
#include "action.h"
|
||||
#include "config.h"
|
||||
#include "event-adapter.h"
|
||||
#include "layout.h"
|
||||
#include "renderer.h"
|
||||
#include "types.h"
|
||||
#include "utils.h"
|
||||
@@ -124,6 +125,21 @@ static void print_window_list(window_list_t *window_list) {
|
||||
printf("window[%u]: 0x%x\n", i, window_list->list[i]);
|
||||
}
|
||||
}
|
||||
static char *bool2string(bool b) { return b ? "true" : "false"; }
|
||||
static void print_client(client_t *c) {
|
||||
if (!c) return;
|
||||
|
||||
printf("======= client info ========\n");
|
||||
printf("window: 0x%x, x: %d, y: %d, w: %u, h: %u, bw: %u\n", c->window, c->x,
|
||||
c->y, c->width, c->height, c->border_width);
|
||||
printf("floating: %s, fullscreen: %s, maximize: %s\n",
|
||||
bool2string(c->floating), bool2string(c->fullscreen),
|
||||
bool2string(c->maximize));
|
||||
printf("tags: %b, monitor selected tags: %b\n", c->tags,
|
||||
c->monitor->selected_tags);
|
||||
printf("name: %s\n", c->name);
|
||||
printf("===== client info end ======\n");
|
||||
}
|
||||
/* 调试函数结束 */
|
||||
|
||||
void init_monitors(void) {
|
||||
@@ -137,6 +153,7 @@ void init_monitors(void) {
|
||||
m->monitor_width = mr->width;
|
||||
m->monitor_height = mr->height;
|
||||
m->index = i;
|
||||
m->layout = &layouts[0];
|
||||
|
||||
if (prev_monitor) {
|
||||
prev_monitor->next = m;
|
||||
@@ -153,7 +170,7 @@ void init_monitors(void) {
|
||||
}
|
||||
for (monitor_t *m = monitors; m; m = m->next) {
|
||||
m->tags = get_monitor_tags(i, m->index);
|
||||
m->selected_tag = 0x1;
|
||||
m->selected_tags = 0x1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -426,15 +443,13 @@ void configure_request(configure_request_event_t *event) {
|
||||
if (!client) {
|
||||
configure_window(event->window, event->x, event->y, event->width,
|
||||
event->height, event->border_width);
|
||||
flush_xcb_connection();
|
||||
return;
|
||||
} else {
|
||||
configure_window(client->window, client->x, client->y, client->width,
|
||||
client->height, client->border_width);
|
||||
printf("configure request: %s\n", client->name);
|
||||
}
|
||||
|
||||
printf("window: %u, parent: %u, sibling: %u\n", event->window, event->parent,
|
||||
event->sibling);
|
||||
printf("x: %d, y: %d, w: %u, h: %u, bw: %u\n", event->x, event->y,
|
||||
event->width, event->height, event->border_width);
|
||||
printf("mask: %u, stack: %u\n", event->value_mask, event->stack_mode);
|
||||
flush_xcb_connection();
|
||||
}
|
||||
|
||||
void map_request(map_request_event_t *event) {
|
||||
@@ -488,16 +503,81 @@ void update_client_name(client_t *client) {
|
||||
free(name);
|
||||
}
|
||||
|
||||
void apply_rules(client_t *client) { /* TODO: */ }
|
||||
void apply_rules(client_t *client) {
|
||||
uint32_t monitor_amount = 0;
|
||||
for (monitor_t *m = monitors; m; m = m->next) monitor_amount++;
|
||||
|
||||
window_class_instance_t class_instance;
|
||||
get_window_class_instance(client->window, &class_instance);
|
||||
printf("class: %s, instance: %s\n", class_instance.class,
|
||||
class_instance.instance);
|
||||
|
||||
bool switch_to_tag = 0;
|
||||
for (int i = 0; i < LENGTH(rules); i++) {
|
||||
const rule_t *r = &rules[i];
|
||||
if (!((!r->monitor_amount || monitor_amount == r->monitor_amount) &&
|
||||
(!r->title || strstr(client->name, r->title)) &&
|
||||
(!r->class || strstr(class_instance.class, r->class)) &&
|
||||
(!r->instance || strstr(class_instance.instance, r->instance)))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch_to_tag = r->switch_to_tag;
|
||||
client->fullscreen = r->fullscreen;
|
||||
client->maximize = r->maximize;
|
||||
client->floating = r->floating;
|
||||
|
||||
if (r->tags) {
|
||||
monitor_t *m = monitors;
|
||||
for (uint32_t i = 0; i < r->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 << 0;
|
||||
}
|
||||
client->tags = r->tags & tags_mask;
|
||||
}
|
||||
}
|
||||
if (!client->tags) {
|
||||
client->monitor = current_monitor;
|
||||
client->tags = current_monitor->selected_tags;
|
||||
}
|
||||
if (switch_to_tag) {
|
||||
current_monitor = client->monitor;
|
||||
current_monitor->selected_tags = client->tags;
|
||||
}
|
||||
|
||||
printf("apply rules done\n");
|
||||
}
|
||||
|
||||
void attach_client(client_t *client) {
|
||||
client->next = client->monitor->clients;
|
||||
client->monitor->clients = client;
|
||||
}
|
||||
|
||||
void show_hide_client(client_t *client) { /* TODO: */ }
|
||||
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);
|
||||
}
|
||||
|
||||
void apply_monitor_layout(monitor_t *monitor) { /* TODO: */ }
|
||||
void apply_monitor_layout(monitor_t *monitor) {
|
||||
if (!monitor || !monitor->layout || !monitor->layout->arrange) return;
|
||||
|
||||
monitor->layout->arrange(monitor);
|
||||
print_client(monitor->clients);
|
||||
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) {
|
||||
for (monitor_t *m = monitors; m; m = m->next) {
|
||||
|
||||
Reference in New Issue
Block a user