显示窗口
This commit is contained in:
114
src/main.c
114
src/main.c
@@ -34,6 +34,15 @@ static void update_bars(void);
|
||||
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);
|
||||
static void configure_request(configure_request_event_t *event);
|
||||
static void map_request(map_request_event_t *event);
|
||||
static void manage_window(xcb_window_t window);
|
||||
static void update_client_name(client_t *client);
|
||||
static void apply_rules(client_t *client);
|
||||
static void attach_client(client_t *client);
|
||||
static void show_hide_client(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,
|
||||
gpointer userdata);
|
||||
static void cleanup(void);
|
||||
@@ -50,6 +59,7 @@ static uint32_t dpi = dpi_fallback;
|
||||
static uint32_t bar_y_pad = bar_y_padding;
|
||||
static uint32_t tag_x_pad = tag_x_padding;
|
||||
static uint32_t bar_height = 0;
|
||||
static uint32_t border_px = border_width;
|
||||
|
||||
static bool need_restart = false;
|
||||
|
||||
@@ -358,6 +368,7 @@ void get_xresource_config(void) {
|
||||
get_xresource_uint32("zswm.font_size", &font_size);
|
||||
get_xresource_uint32("zswm.bar_y_padding", &bar_y_pad);
|
||||
get_xresource_uint32("zswm.tag_x_padding", &tag_x_pad);
|
||||
get_xresource_uint32("zswm.border_width", &border_px);
|
||||
|
||||
printf("dpi: %u, font family: %s, font size: %u\n", dpi, font_family,
|
||||
font_size);
|
||||
@@ -383,9 +394,17 @@ void init_xcb_event_loop(void) {
|
||||
|
||||
void xcb_event_handler(generic_event_t *event, void *user_data) {
|
||||
switch (event->type) {
|
||||
case EVENT_TYPE_KEY_PRESS:
|
||||
key_press((key_press_event_t *)event);
|
||||
break;
|
||||
#define EVENT(type, callback) \
|
||||
case type: \
|
||||
callback((void *)event); \
|
||||
break
|
||||
|
||||
EVENT(EVENT_TYPE_KEY_PRESS, key_press);
|
||||
EVENT(EVENT_TYPE_CONFIGURE_REQUEST, configure_request);
|
||||
EVENT(EVENT_TYPE_MAP_REQUEST, map_request);
|
||||
|
||||
#undef EVENT
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -402,6 +421,93 @@ void key_press(key_press_event_t *event) {
|
||||
}
|
||||
}
|
||||
|
||||
void configure_request(configure_request_event_t *event) {
|
||||
client_t *client = get_client_of_window(event->window);
|
||||
if (!client) {
|
||||
configure_window(event->window, event->x, event->y, event->width,
|
||||
event->height, event->border_width);
|
||||
flush_xcb_connection();
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void map_request(map_request_event_t *event) {
|
||||
if (!get_window_visible(event->window)) return;
|
||||
if (get_client_of_window(event->window)) return;
|
||||
if (event->parent != get_root_window()) return;
|
||||
|
||||
manage_window(event->window);
|
||||
}
|
||||
|
||||
void manage_window(xcb_window_t window) {
|
||||
window_geometry_t *geometry = get_window_geometry(window);
|
||||
client_t *c = ecalloc(1, sizeof(client_t));
|
||||
c->window = window;
|
||||
c->x = c->old_x = geometry->x;
|
||||
c->y = c->old_y = geometry->y;
|
||||
c->width = c->old_width = geometry->width;
|
||||
c->height = c->old_height = geometry->height;
|
||||
c->old_border_width = geometry->border_width;
|
||||
c->border_width = border_px;
|
||||
update_client_name(c);
|
||||
|
||||
printf("== manage window: %u\n", window);
|
||||
printf("== x: %d, y: %d, w: %u, h: %u, bw: %u\n", c->x, c->y, c->width,
|
||||
c->height, c->border_width);
|
||||
|
||||
xcb_window_t tw = get_transient_window_for(window);
|
||||
client_t *tc = NULL;
|
||||
if (tw != WINDOW_NONE && (tc = get_client_of_window(tw))) {
|
||||
c->monitor = tc->monitor;
|
||||
c->tags = tc->tags;
|
||||
} else {
|
||||
c->monitor = current_monitor;
|
||||
apply_rules(c);
|
||||
}
|
||||
|
||||
attach_client(c);
|
||||
apply_monitor_layout(c->monitor);
|
||||
init_window_event_mask(window);
|
||||
change_window_border_color(window, color_set->border_color.argb);
|
||||
map_window(window);
|
||||
show_hide_client(c);
|
||||
flush_xcb_connection();
|
||||
|
||||
update_bars();
|
||||
}
|
||||
|
||||
void update_client_name(client_t *client) {
|
||||
char *name = get_window_name(client->window);
|
||||
strncpy(client->name, name, sizeof(client->name) - 1);
|
||||
free(name);
|
||||
}
|
||||
|
||||
void apply_rules(client_t *client) { /* TODO: */ }
|
||||
|
||||
void attach_client(client_t *client) {
|
||||
client->next = client->monitor->clients;
|
||||
client->monitor->clients = client;
|
||||
}
|
||||
|
||||
void show_hide_client(client_t *client) { /* TODO: */ }
|
||||
|
||||
void apply_monitor_layout(monitor_t *monitor) { /* TODO: */ }
|
||||
|
||||
client_t *get_client_of_window(xcb_window_t window) {
|
||||
for (monitor_t *m = monitors; m; m = m->next) {
|
||||
for (client_t *c = m->clients; c; c = c->next) {
|
||||
if (c->window == window) return c;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gboolean handle_xcb_event(GIOChannel *channel, GIOCondition condition,
|
||||
gpointer userdata) {
|
||||
if (condition & (G_IO_HUP | G_IO_ERR)) {
|
||||
@@ -456,7 +562,7 @@ int main(int argc, char *argv[]) {
|
||||
init_monitors();
|
||||
init_color_set();
|
||||
init_monitor_bar();
|
||||
set_root_cursor(cursor_normal);
|
||||
change_window_cursor(get_root_window(), cursor_normal);
|
||||
init_wallpaper();
|
||||
|
||||
update_bars();
|
||||
|
||||
Reference in New Issue
Block a user