2012-08-01 12:56:57 +02:00
|
|
|
#include <stdio.h>
|
2012-08-29 18:37:31 +02:00
|
|
|
#include <stdlib.h>
|
2012-08-01 12:56:57 +02:00
|
|
|
#include <xcb/xcb.h>
|
|
|
|
#include <xcb/xcb_event.h>
|
2012-08-20 22:38:29 +02:00
|
|
|
#include "helpers.h"
|
2012-08-25 15:24:35 +02:00
|
|
|
#include "types.h"
|
2012-08-28 21:15:29 +02:00
|
|
|
#include "bspwm.h"
|
2012-09-13 13:56:53 +02:00
|
|
|
#include "settings.h"
|
2012-08-28 21:15:29 +02:00
|
|
|
#include "utils.h"
|
2012-08-01 12:56:57 +02:00
|
|
|
#include "events.h"
|
2012-09-01 21:55:35 +02:00
|
|
|
#include "tree.h"
|
2012-09-11 22:48:26 +02:00
|
|
|
#include "ewmh.h"
|
2012-08-01 12:56:57 +02:00
|
|
|
|
|
|
|
void handle_event(xcb_generic_event_t *evt)
|
|
|
|
{
|
|
|
|
switch (XCB_EVENT_RESPONSE_TYPE(evt)) {
|
|
|
|
case XCB_MAP_REQUEST:
|
2012-08-01 23:16:07 +02:00
|
|
|
PUTS("received a map request\n");
|
2012-08-25 15:24:35 +02:00
|
|
|
map_request(evt);
|
2012-08-01 23:16:07 +02:00
|
|
|
break;
|
2012-09-11 22:48:26 +02:00
|
|
|
case XCB_CLIENT_MESSAGE:
|
|
|
|
PUTS("received a map request\n");
|
|
|
|
client_message(evt);
|
|
|
|
break;
|
2012-08-01 23:16:07 +02:00
|
|
|
case XCB_CONFIGURE_REQUEST:
|
2012-08-30 21:35:39 +02:00
|
|
|
PUTS("received a configure request\n");
|
2012-08-01 23:16:07 +02:00
|
|
|
break;
|
|
|
|
case XCB_BUTTON_PRESS:
|
2012-09-11 22:48:26 +02:00
|
|
|
PUTS("button press event");
|
2012-08-01 12:56:57 +02:00
|
|
|
break;
|
|
|
|
default:
|
2012-09-12 14:56:51 +02:00
|
|
|
/* PRINTF("received event %i\n", XCB_EVENT_RESPONSE_TYPE(evt)); */
|
|
|
|
break;
|
2012-08-01 12:56:57 +02:00
|
|
|
}
|
|
|
|
}
|
2012-08-25 15:24:35 +02:00
|
|
|
|
|
|
|
void map_request(xcb_generic_event_t *evt)
|
|
|
|
{
|
|
|
|
xcb_map_request_event_t *e = (xcb_map_request_event_t *) evt;
|
2012-08-28 21:15:29 +02:00
|
|
|
xcb_get_window_attributes_reply_t *wa;
|
2012-08-25 15:24:35 +02:00
|
|
|
xcb_window_t win = e->window;
|
2012-08-28 21:15:29 +02:00
|
|
|
wa = xcb_get_window_attributes_reply(dpy, xcb_get_window_attributes(dpy, win), NULL);
|
2012-09-03 21:40:30 +02:00
|
|
|
|
2012-09-07 12:32:24 +02:00
|
|
|
if ((wa != NULL && wa->override_redirect) || is_managed(win))
|
2012-08-28 21:15:29 +02:00
|
|
|
return;
|
2012-09-03 21:40:30 +02:00
|
|
|
|
2012-08-29 18:37:31 +02:00
|
|
|
free(wa);
|
2012-09-01 21:55:35 +02:00
|
|
|
bool takes_focus = true;
|
2012-09-05 14:07:06 +02:00
|
|
|
client_t *c = make_client(win);
|
2012-08-28 21:15:29 +02:00
|
|
|
num_clients++;
|
2012-09-01 21:55:35 +02:00
|
|
|
node_t *birth = make_node();
|
|
|
|
birth->client = c;
|
2012-09-05 14:07:06 +02:00
|
|
|
insert_node(desk, birth);
|
2012-09-13 13:56:53 +02:00
|
|
|
window_border_width(c->window, border_width);
|
|
|
|
apply_layout(desk, desk->root, root_rect);
|
|
|
|
xcb_map_window(dpy, c->window);
|
2012-09-05 14:07:06 +02:00
|
|
|
if (takes_focus)
|
|
|
|
focus_node(desk, birth);
|
2012-08-25 15:24:35 +02:00
|
|
|
}
|
2012-09-11 22:48:26 +02:00
|
|
|
|
|
|
|
void client_message(xcb_generic_event_t *evt)
|
|
|
|
{
|
|
|
|
xcb_client_message_event_t *e = (xcb_client_message_event_t *) evt;
|
|
|
|
window_location_t wl = locate_window(e->window);
|
|
|
|
if (wl.desktop == NULL || wl.node == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (e->type == ewmh._NET_WM_STATE) {
|
|
|
|
handle_state(wl.node, e->data.data32[1], e->data.data32[0]);
|
|
|
|
handle_state(wl.node, e->data.data32[2], e->data.data32[0]);
|
|
|
|
} else if (e->type == ewmh._NET_ACTIVE_WINDOW) {
|
|
|
|
focus_node(wl.desktop, wl.node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void handle_state(node_t *n, xcb_atom_t state, unsigned int action)
|
|
|
|
{
|
|
|
|
if (state == ewmh._NET_WM_STATE_FULLSCREEN) {
|
|
|
|
bool fs = n->client->fullscreen;
|
|
|
|
if (action == XCB_EWMH_WM_STATE_TOGGLE
|
|
|
|
|| (fs && action == XCB_EWMH_WM_STATE_REMOVE)
|
|
|
|
|| (!fs && action == XCB_EWMH_WM_STATE_ADD))
|
2012-09-12 14:56:51 +02:00
|
|
|
toggle_fullscreen(n->client);
|
2012-09-11 22:48:26 +02:00
|
|
|
}
|
|
|
|
}
|