2012-09-18 17:21:04 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "types.h"
|
2013-09-20 11:57:09 +02:00
|
|
|
#include "monitor.h"
|
2012-09-18 17:21:04 +02:00
|
|
|
#include "tree.h"
|
|
|
|
#include "bspwm.h"
|
|
|
|
#include "settings.h"
|
|
|
|
#include "ewmh.h"
|
2013-07-08 11:42:05 +02:00
|
|
|
#include "query.h"
|
2013-09-19 15:38:22 +02:00
|
|
|
#include "rule.h"
|
2012-09-18 17:21:04 +02:00
|
|
|
#include "window.h"
|
|
|
|
|
2013-09-19 15:02:49 +02:00
|
|
|
pointer_state_t *make_pointer_state(void)
|
|
|
|
{
|
|
|
|
pointer_state_t *p = malloc(sizeof(pointer_state_t));
|
|
|
|
p->monitor = NULL;
|
|
|
|
p->desktop = NULL;
|
|
|
|
p->node = p->vertical_fence = p->horizontal_fence = NULL;
|
|
|
|
p->client = NULL;
|
|
|
|
p->window = XCB_NONE;
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2012-12-14 15:43:22 +01:00
|
|
|
void center(xcb_rectangle_t a, xcb_rectangle_t *b)
|
|
|
|
{
|
|
|
|
if (b->width < a.width)
|
|
|
|
b->x = a.x + (a.width - b->width) / 2;
|
|
|
|
if (b->height < a.height)
|
|
|
|
b->y = a.y + (a.height - b->height) / 2;
|
|
|
|
}
|
|
|
|
|
2012-12-13 14:00:45 +01:00
|
|
|
bool contains(xcb_rectangle_t a, xcb_rectangle_t b)
|
|
|
|
{
|
|
|
|
return (a.x <= b.x && (a.x + a.width) >= (b.x + b.width)
|
|
|
|
&& a.y <= b.y && (a.y + a.height) >= (b.y + b.height));
|
|
|
|
}
|
|
|
|
|
2013-03-09 19:40:47 +01:00
|
|
|
bool is_inside(monitor_t *m, xcb_point_t pt)
|
2012-11-08 18:24:17 +01:00
|
|
|
{
|
|
|
|
xcb_rectangle_t r = m->rectangle;
|
2013-03-09 19:40:47 +01:00
|
|
|
return (r.x <= pt.x && pt.x < (r.x + r.width)
|
|
|
|
&& r.y <= pt.y && pt.y < (r.y + r.height));
|
2012-11-08 18:24:17 +01:00
|
|
|
}
|
|
|
|
|
2013-06-06 23:51:30 +02:00
|
|
|
xcb_rectangle_t get_rectangle(client_t *c)
|
|
|
|
{
|
|
|
|
if (is_tiled(c))
|
|
|
|
return c->tiled_rectangle;
|
|
|
|
else
|
|
|
|
return c->floating_rectangle;
|
|
|
|
}
|
|
|
|
|
2013-05-07 22:45:14 +02:00
|
|
|
void get_side_handle(client_t *c, direction_t dir, xcb_point_t *pt)
|
|
|
|
{
|
2013-06-06 23:51:30 +02:00
|
|
|
xcb_rectangle_t rect = get_rectangle(c);
|
2013-05-07 22:45:14 +02:00
|
|
|
switch (dir) {
|
|
|
|
case DIR_RIGHT:
|
|
|
|
pt->x = rect.x + rect.width;
|
|
|
|
pt->y = rect.y + (rect.height / 2);
|
|
|
|
break;
|
|
|
|
case DIR_DOWN:
|
|
|
|
pt->x = rect.x + (rect.width / 2);
|
|
|
|
pt->y = rect.y + rect.height;
|
|
|
|
break;
|
|
|
|
case DIR_LEFT:
|
|
|
|
pt->x = rect.x;
|
|
|
|
pt->y = rect.y + (rect.height / 2);
|
|
|
|
break;
|
|
|
|
case DIR_UP:
|
|
|
|
pt->x = rect.x + (rect.width / 2);
|
|
|
|
pt->y = rect.y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-09 19:40:47 +01:00
|
|
|
monitor_t *monitor_from_point(xcb_point_t pt)
|
2012-11-08 18:24:17 +01:00
|
|
|
{
|
|
|
|
for (monitor_t *m = mon_head; m != NULL; m = m->next)
|
2013-03-09 19:40:47 +01:00
|
|
|
if (is_inside(m, pt))
|
2012-11-08 18:24:17 +01:00
|
|
|
return m;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-03-09 19:40:47 +01:00
|
|
|
monitor_t *underlying_monitor(client_t *c)
|
|
|
|
{
|
|
|
|
xcb_point_t pt = (xcb_point_t) {c->floating_rectangle.x, c->floating_rectangle.y};
|
|
|
|
return monitor_from_point(pt);
|
|
|
|
}
|
|
|
|
|
2012-10-25 21:49:14 +02:00
|
|
|
void manage_window(monitor_t *m, desktop_t *d, xcb_window_t win)
|
2012-10-24 16:34:56 +02:00
|
|
|
{
|
2013-07-08 11:42:05 +02:00
|
|
|
coordinates_t loc;
|
2012-10-24 16:34:56 +02:00
|
|
|
xcb_get_window_attributes_reply_t *wa = xcb_get_window_attributes_reply(dpy, xcb_get_window_attributes(dpy, win), NULL);
|
|
|
|
uint8_t override_redirect = 0;
|
|
|
|
|
|
|
|
if (wa != NULL) {
|
|
|
|
override_redirect = wa->override_redirect;
|
|
|
|
free(wa);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (override_redirect || locate_window(win, &loc))
|
|
|
|
return;
|
|
|
|
|
2013-09-18 11:42:20 +02:00
|
|
|
bool floating = false, fullscreen = false, locked = false, follow = false, transient = false, takes_focus = true, manage = true;
|
|
|
|
handle_rules(win, &m, &d, &floating, &fullscreen, &locked, &follow, &transient, &takes_focus, &manage);
|
2012-10-24 16:34:56 +02:00
|
|
|
|
|
|
|
if (!manage) {
|
2013-09-05 15:37:54 +02:00
|
|
|
disable_floating_atom(win);
|
2012-10-24 16:34:56 +02:00
|
|
|
window_show(win);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
client_t *c = make_client(win);
|
|
|
|
update_floating_rectangle(c);
|
|
|
|
|
|
|
|
xcb_icccm_get_wm_class_reply_t reply;
|
|
|
|
if (xcb_icccm_get_wm_class_reply(dpy, xcb_icccm_get_wm_class(dpy, win), &reply, NULL) == 1) {
|
2013-09-21 12:39:59 +02:00
|
|
|
snprintf(c->class_name, sizeof(c->class_name), "%s", reply.class_name);
|
2012-10-24 16:34:56 +02:00
|
|
|
xcb_icccm_get_wm_class_reply_wipe(&reply);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c->transient)
|
|
|
|
floating = true;
|
|
|
|
|
2013-06-06 23:51:30 +02:00
|
|
|
node_t *n = make_node();
|
|
|
|
n->client = c;
|
2012-10-24 16:34:56 +02:00
|
|
|
|
2013-06-27 17:11:30 +02:00
|
|
|
insert_node(m, d, n, d->focus);
|
2012-10-24 16:34:56 +02:00
|
|
|
|
2013-09-05 15:37:54 +02:00
|
|
|
disable_floating_atom(c->window);
|
2013-09-18 11:42:20 +02:00
|
|
|
set_floating(d, n, floating);
|
|
|
|
set_locked(m, d, n, locked);
|
2012-10-24 16:34:56 +02:00
|
|
|
|
2012-10-25 21:49:14 +02:00
|
|
|
if (d->focus != NULL && d->focus->client->fullscreen)
|
2013-07-08 11:42:05 +02:00
|
|
|
set_fullscreen(d, d->focus, false);
|
2012-10-24 16:34:56 +02:00
|
|
|
|
2013-09-18 11:42:20 +02:00
|
|
|
set_fullscreen(d, n, fullscreen);
|
2012-10-24 16:34:56 +02:00
|
|
|
|
|
|
|
c->transient = transient;
|
|
|
|
|
2013-09-12 16:26:01 +02:00
|
|
|
bool give_focus = (takes_focus && (d == mon->desk || follow));
|
|
|
|
if (give_focus) {
|
2013-06-06 23:51:30 +02:00
|
|
|
focus_node(m, d, n);
|
2013-09-12 16:26:01 +02:00
|
|
|
} else if (takes_focus) {
|
|
|
|
pseudo_focus(d, n);
|
|
|
|
} else {
|
|
|
|
node_t *f = d->focus;
|
2013-06-06 23:51:30 +02:00
|
|
|
pseudo_focus(d, n);
|
2013-09-12 16:26:01 +02:00
|
|
|
if (f != NULL)
|
|
|
|
pseudo_focus(d, f);
|
|
|
|
}
|
2012-10-24 16:34:56 +02:00
|
|
|
|
2013-06-06 23:51:30 +02:00
|
|
|
xcb_rectangle_t *frect = &n->client->floating_rectangle;
|
2012-12-14 15:43:22 +01:00
|
|
|
if (frect->x == 0 && frect->y == 0)
|
|
|
|
center(m->rectangle, frect);
|
|
|
|
|
2013-06-06 23:51:30 +02:00
|
|
|
fit_monitor(m, n->client);
|
2012-12-14 15:47:36 +01:00
|
|
|
|
2012-10-25 21:49:14 +02:00
|
|
|
arrange(m, d);
|
2012-12-14 15:47:36 +01:00
|
|
|
|
2012-12-23 12:11:08 +01:00
|
|
|
if (d == m->desk && visible)
|
2012-10-25 21:49:14 +02:00
|
|
|
window_show(c->window);
|
2012-10-24 16:34:56 +02:00
|
|
|
|
2013-05-29 11:36:01 +02:00
|
|
|
/* the same function is already called in `focus_node` but has no effects on unmapped windows */
|
2013-05-29 14:34:27 +02:00
|
|
|
if (give_focus)
|
2012-10-24 16:34:56 +02:00
|
|
|
xcb_set_input_focus(dpy, XCB_INPUT_FOCUS_POINTER_ROOT, win, XCB_CURRENT_TIME);
|
|
|
|
|
2013-03-04 11:25:12 +01:00
|
|
|
uint32_t values[] = {(focus_follows_pointer ? CLIENT_EVENT_MASK_FFP : CLIENT_EVENT_MASK)};
|
2012-10-24 16:34:56 +02:00
|
|
|
xcb_change_window_attributes(dpy, c->window, XCB_CW_EVENT_MASK, values);
|
|
|
|
|
|
|
|
num_clients++;
|
2013-06-06 23:51:30 +02:00
|
|
|
ewmh_set_wm_desktop(n, d);
|
2012-10-24 16:34:56 +02:00
|
|
|
ewmh_update_client_list();
|
|
|
|
}
|
|
|
|
|
2012-10-25 21:02:04 +02:00
|
|
|
void adopt_orphans(void)
|
|
|
|
{
|
2013-01-02 12:36:54 +01:00
|
|
|
xcb_query_tree_reply_t *qtr = xcb_query_tree_reply(dpy, xcb_query_tree(dpy, root), NULL);
|
2012-10-25 21:02:04 +02:00
|
|
|
if (qtr == NULL)
|
|
|
|
return;
|
2013-05-29 21:25:38 +02:00
|
|
|
|
|
|
|
PUTS("adopt orphans");
|
|
|
|
|
2012-10-25 21:02:04 +02:00
|
|
|
int len = xcb_query_tree_children_length(qtr);
|
|
|
|
xcb_window_t *wins = xcb_query_tree_children(qtr);
|
|
|
|
for (int i = 0; i < len; i++) {
|
2012-10-25 21:49:14 +02:00
|
|
|
uint32_t idx;
|
2012-10-25 21:02:04 +02:00
|
|
|
xcb_window_t win = wins[i];
|
2012-12-25 23:02:16 +01:00
|
|
|
window_hide(win);
|
2012-10-25 21:49:14 +02:00
|
|
|
if (xcb_ewmh_get_wm_desktop_reply(ewmh, xcb_ewmh_get_wm_desktop(ewmh, win), &idx, NULL) == 1) {
|
2013-07-08 11:42:05 +02:00
|
|
|
coordinates_t loc;
|
2012-10-25 21:49:14 +02:00
|
|
|
if (ewmh_locate_desktop(idx, &loc))
|
|
|
|
manage_window(loc.monitor, loc.desktop, win);
|
|
|
|
else
|
|
|
|
manage_window(mon, mon->desk, win);
|
|
|
|
}
|
2012-10-25 21:02:04 +02:00
|
|
|
}
|
|
|
|
free(qtr);
|
|
|
|
}
|
|
|
|
|
2012-10-17 16:18:40 +02:00
|
|
|
void window_draw_border(node_t *n, bool focused_window, bool focused_monitor)
|
2012-09-18 17:21:04 +02:00
|
|
|
{
|
2013-02-06 22:23:49 +01:00
|
|
|
if (n == NULL || border_width < 1 || n->client->border_width < 1)
|
2012-09-18 17:21:04 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
xcb_window_t win = n->client->window;
|
2013-02-06 22:23:49 +01:00
|
|
|
uint32_t border_color_pxl = get_border_color(n->client, focused_window, focused_monitor);
|
2012-09-18 17:21:04 +02:00
|
|
|
|
2013-06-27 17:26:52 +02:00
|
|
|
if (n->split_mode == MODE_AUTOMATIC) {
|
2013-02-06 22:23:49 +01:00
|
|
|
xcb_change_window_attributes(dpy, win, XCB_CW_BORDER_PIXEL, &border_color_pxl);
|
|
|
|
} else {
|
2013-09-04 21:57:26 +02:00
|
|
|
uint32_t presel_border_color_pxl;
|
|
|
|
get_color(presel_border_color, win, &presel_border_color_pxl);
|
|
|
|
|
2013-06-06 23:51:30 +02:00
|
|
|
xcb_rectangle_t actual_rectangle = get_rectangle(n->client);
|
2012-09-18 17:21:04 +02:00
|
|
|
|
2013-02-06 22:23:49 +01:00
|
|
|
uint16_t width = actual_rectangle.width;
|
|
|
|
uint16_t height = actual_rectangle.height;
|
2012-09-18 17:21:04 +02:00
|
|
|
|
2013-02-06 22:23:49 +01:00
|
|
|
uint16_t full_width = width + 2 * border_width;
|
|
|
|
uint16_t full_height = height + 2 * border_width;
|
2012-09-18 17:21:04 +02:00
|
|
|
|
2013-02-06 22:23:49 +01:00
|
|
|
xcb_rectangle_t border_rectangles[] =
|
|
|
|
{
|
|
|
|
{ width, 0, 2 * border_width, height + 2 * border_width },
|
|
|
|
{ 0, height, width + 2 * border_width, 2 * border_width }
|
|
|
|
};
|
2012-09-18 17:21:04 +02:00
|
|
|
|
2013-02-06 22:23:49 +01:00
|
|
|
xcb_rectangle_t *presel_rectangles;
|
2012-09-20 23:32:32 +02:00
|
|
|
|
2013-04-01 12:29:45 +02:00
|
|
|
uint8_t win_depth = root_depth;
|
|
|
|
xcb_get_geometry_reply_t *geo = xcb_get_geometry_reply(dpy, xcb_get_geometry(dpy, win), NULL);
|
|
|
|
if (geo != NULL)
|
|
|
|
win_depth = geo->depth;
|
|
|
|
free(geo);
|
|
|
|
|
2013-09-04 21:57:26 +02:00
|
|
|
xcb_pixmap_t pixmap = xcb_generate_id(dpy);
|
|
|
|
xcb_create_pixmap(dpy, win_depth, pixmap, win, full_width, full_height);
|
2012-09-18 17:21:04 +02:00
|
|
|
|
2013-02-06 22:23:49 +01:00
|
|
|
xcb_gcontext_t gc = xcb_generate_id(dpy);
|
2013-09-04 21:57:26 +02:00
|
|
|
xcb_create_gc(dpy, gc, pixmap, 0, NULL);
|
2012-09-18 17:21:04 +02:00
|
|
|
|
2013-02-06 22:23:49 +01:00
|
|
|
xcb_change_gc(dpy, gc, XCB_GC_FOREGROUND, &border_color_pxl);
|
2013-09-04 21:57:26 +02:00
|
|
|
xcb_poly_fill_rectangle(dpy, pixmap, gc, LENGTH(border_rectangles), border_rectangles);
|
2012-09-18 17:21:04 +02:00
|
|
|
|
2013-06-27 17:26:52 +02:00
|
|
|
uint16_t fence = (int16_t) (n->split_ratio * ((n->split_dir == DIR_UP || n->split_dir == DIR_DOWN) ? height : width));
|
2012-09-18 17:21:04 +02:00
|
|
|
presel_rectangles = malloc(2 * sizeof(xcb_rectangle_t));
|
2013-06-27 17:26:52 +02:00
|
|
|
switch (n->split_dir) {
|
2012-09-18 17:21:04 +02:00
|
|
|
case DIR_UP:
|
|
|
|
presel_rectangles[0] = (xcb_rectangle_t) {width, 0, 2 * border_width, fence};
|
|
|
|
presel_rectangles[1] = (xcb_rectangle_t) {0, height + border_width, full_width, border_width};
|
|
|
|
break;
|
|
|
|
case DIR_DOWN:
|
|
|
|
presel_rectangles[0] = (xcb_rectangle_t) {width, fence + 1, 2 * border_width, height + border_width - (fence + 1)};
|
|
|
|
presel_rectangles[1] = (xcb_rectangle_t) {0, height, full_width, border_width};
|
|
|
|
break;
|
|
|
|
case DIR_LEFT:
|
|
|
|
presel_rectangles[0] = (xcb_rectangle_t) {0, height, fence, 2 * border_width};
|
|
|
|
presel_rectangles[1] = (xcb_rectangle_t) {width + border_width, 0, border_width, full_height};
|
|
|
|
break;
|
|
|
|
case DIR_RIGHT:
|
|
|
|
presel_rectangles[0] = (xcb_rectangle_t) {fence + 1, height, width + border_width - (fence + 1), 2 * border_width};
|
|
|
|
presel_rectangles[1] = (xcb_rectangle_t) {width, 0, border_width, full_height};
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
xcb_change_gc(dpy, gc, XCB_GC_FOREGROUND, &presel_border_color_pxl);
|
2013-09-04 21:57:26 +02:00
|
|
|
xcb_poly_fill_rectangle(dpy, pixmap, gc, 2, presel_rectangles);
|
|
|
|
xcb_change_window_attributes(dpy, win, XCB_CW_BORDER_PIXMAP, &pixmap);
|
2012-09-18 17:21:04 +02:00
|
|
|
free(presel_rectangles);
|
2013-02-06 22:23:49 +01:00
|
|
|
xcb_free_gc(dpy, gc);
|
2013-09-04 21:57:26 +02:00
|
|
|
xcb_free_pixmap(dpy, pixmap);
|
2012-09-18 17:21:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-28 15:59:29 +02:00
|
|
|
void window_close(node_t *n)
|
2012-09-18 17:21:04 +02:00
|
|
|
{
|
|
|
|
if (n == NULL || n->client->locked)
|
|
|
|
return;
|
|
|
|
|
2012-09-21 12:15:25 +02:00
|
|
|
PRINTF("close window %X\n", n->client->window);
|
2012-09-18 17:21:04 +02:00
|
|
|
|
2013-09-10 10:39:25 +02:00
|
|
|
send_client_message(n->client->window, ewmh->WM_PROTOCOLS, WM_DELETE_WINDOW);
|
2012-09-18 17:21:04 +02:00
|
|
|
}
|
|
|
|
|
2013-07-08 11:42:05 +02:00
|
|
|
void window_kill(desktop_t *d, node_t *n)
|
2012-09-28 15:59:29 +02:00
|
|
|
{
|
|
|
|
if (n == NULL)
|
|
|
|
return;
|
|
|
|
|
2013-06-06 23:51:30 +02:00
|
|
|
xcb_window_t win = n->client->window;
|
|
|
|
PRINTF("kill window %X\n", win);
|
2012-09-28 15:59:29 +02:00
|
|
|
|
2013-06-06 23:51:30 +02:00
|
|
|
xcb_kill_client(dpy, win);
|
2012-09-28 15:59:29 +02:00
|
|
|
remove_node(d, n);
|
|
|
|
}
|
|
|
|
|
2013-07-08 11:42:05 +02:00
|
|
|
void set_fullscreen(desktop_t *d, node_t *n, bool value)
|
2012-09-18 17:21:04 +02:00
|
|
|
{
|
2013-07-08 11:42:05 +02:00
|
|
|
if (n == NULL || n->client->fullscreen == value)
|
2013-06-08 18:31:55 +02:00
|
|
|
return;
|
|
|
|
|
2013-06-06 23:51:30 +02:00
|
|
|
client_t *c = n->client;
|
|
|
|
|
2013-07-08 11:42:05 +02:00
|
|
|
PRINTF("fullscreen %X: %s\n", c->window, BOOLSTR(value));
|
2012-10-06 12:03:12 +02:00
|
|
|
|
2013-07-08 11:42:05 +02:00
|
|
|
if (value) {
|
2012-09-18 17:21:04 +02:00
|
|
|
c->fullscreen = true;
|
|
|
|
xcb_atom_t values[] = {ewmh->_NET_WM_STATE_FULLSCREEN};
|
|
|
|
xcb_ewmh_set_wm_state(ewmh, c->window, LENGTH(values), values);
|
2013-07-08 11:42:05 +02:00
|
|
|
} else {
|
|
|
|
c->fullscreen = false;
|
|
|
|
xcb_atom_t values[] = {XCB_NONE};
|
|
|
|
xcb_ewmh_set_wm_state(ewmh, c->window, LENGTH(values), values);
|
2012-09-18 17:21:04 +02:00
|
|
|
}
|
2013-09-12 16:26:01 +02:00
|
|
|
|
|
|
|
stack(d, n);
|
2012-09-18 17:21:04 +02:00
|
|
|
}
|
|
|
|
|
2013-07-08 11:42:05 +02:00
|
|
|
void set_floating(desktop_t *d, node_t *n, bool value)
|
2012-09-20 23:32:32 +02:00
|
|
|
{
|
2013-07-08 11:42:05 +02:00
|
|
|
if (n == NULL || n->client->transient || n->client->fullscreen || n->client->floating == value)
|
2012-09-20 23:32:32 +02:00
|
|
|
return;
|
|
|
|
|
2013-07-08 11:42:05 +02:00
|
|
|
PRINTF("floating %X: %s\n", n->client->window, BOOLSTR(value));
|
2012-09-20 23:32:32 +02:00
|
|
|
|
2013-06-27 17:26:52 +02:00
|
|
|
n->split_mode = MODE_AUTOMATIC;
|
2012-09-20 23:32:32 +02:00
|
|
|
client_t *c = n->client;
|
2013-07-08 11:42:05 +02:00
|
|
|
c->floating = n->vacant = value;
|
2012-09-20 23:32:32 +02:00
|
|
|
update_vacant_state(n->parent);
|
2013-09-12 16:26:01 +02:00
|
|
|
|
2013-07-08 11:42:05 +02:00
|
|
|
if (value) {
|
2013-09-05 15:37:54 +02:00
|
|
|
enable_floating_atom(c->window);
|
2013-05-08 14:10:53 +02:00
|
|
|
unrotate_brother(n);
|
|
|
|
} else {
|
2013-09-05 15:37:54 +02:00
|
|
|
disable_floating_atom(c->window);
|
2013-05-08 14:10:53 +02:00
|
|
|
rotate_brother(n);
|
2013-05-08 11:28:42 +02:00
|
|
|
}
|
2013-09-12 16:26:01 +02:00
|
|
|
|
2013-06-06 23:51:30 +02:00
|
|
|
stack(d, n);
|
2012-09-20 23:32:32 +02:00
|
|
|
}
|
|
|
|
|
2013-07-08 11:42:05 +02:00
|
|
|
void set_locked(monitor_t *m, desktop_t *d, node_t *n, bool value)
|
2012-09-20 23:32:32 +02:00
|
|
|
{
|
2013-07-08 11:42:05 +02:00
|
|
|
if (n == NULL || n->client->locked == value)
|
2013-06-08 18:31:55 +02:00
|
|
|
return;
|
|
|
|
|
2013-06-06 23:51:30 +02:00
|
|
|
client_t *c = n->client;
|
|
|
|
|
2013-07-08 11:42:05 +02:00
|
|
|
PRINTF("set locked %X: %s\n", c->window, BOOLSTR(value));
|
2012-10-06 12:03:12 +02:00
|
|
|
|
2013-07-08 11:42:05 +02:00
|
|
|
c->locked = value;
|
2013-06-06 23:51:30 +02:00
|
|
|
window_draw_border(n, d->focus == n, m == mon);
|
2012-09-20 23:32:32 +02:00
|
|
|
}
|
|
|
|
|
2013-03-26 11:34:06 +01:00
|
|
|
void set_urgency(monitor_t *m, desktop_t *d, node_t *n, bool value)
|
|
|
|
{
|
|
|
|
if (value && mon->desk->focus == n)
|
|
|
|
return;
|
|
|
|
n->client->urgent = value;
|
2013-06-08 18:31:55 +02:00
|
|
|
window_draw_border(n, d->focus == n, m == mon);
|
2013-03-26 11:34:06 +01:00
|
|
|
put_status();
|
|
|
|
}
|
|
|
|
|
2013-09-05 15:37:54 +02:00
|
|
|
void set_floating_atom(xcb_window_t win, uint32_t value)
|
2012-11-29 15:28:43 +01:00
|
|
|
{
|
2013-09-05 15:37:54 +02:00
|
|
|
if (!apply_floating_atom)
|
2013-01-19 20:58:21 +01:00
|
|
|
return;
|
2013-09-05 15:37:54 +02:00
|
|
|
set_atom(win, _BSPWM_FLOATING_WINDOW, value);
|
2012-11-29 15:28:43 +01:00
|
|
|
}
|
|
|
|
|
2013-09-05 15:37:54 +02:00
|
|
|
void enable_floating_atom(xcb_window_t win)
|
2012-11-29 15:28:43 +01:00
|
|
|
{
|
2013-09-05 15:37:54 +02:00
|
|
|
set_floating_atom(win, 1);
|
2012-11-29 15:28:43 +01:00
|
|
|
}
|
|
|
|
|
2013-09-05 15:37:54 +02:00
|
|
|
void disable_floating_atom(xcb_window_t win)
|
2012-11-29 15:28:43 +01:00
|
|
|
{
|
2013-09-05 15:37:54 +02:00
|
|
|
set_floating_atom(win, 0);
|
2012-11-29 15:28:43 +01:00
|
|
|
}
|
|
|
|
|
2013-02-06 22:23:49 +01:00
|
|
|
uint32_t get_border_color(client_t *c, bool focused_window, bool focused_monitor)
|
2012-09-20 23:32:32 +02:00
|
|
|
{
|
|
|
|
if (c == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2013-09-04 21:57:26 +02:00
|
|
|
uint32_t pxl = 0;
|
|
|
|
|
2012-10-17 16:18:40 +02:00
|
|
|
if (focused_monitor && focused_window) {
|
|
|
|
if (c->locked)
|
2013-09-04 21:57:26 +02:00
|
|
|
get_color(focused_locked_border_color, c->window, &pxl);
|
2012-10-17 16:18:40 +02:00
|
|
|
else
|
2013-09-04 21:57:26 +02:00
|
|
|
get_color(focused_border_color, c->window, &pxl);
|
2012-10-17 16:18:40 +02:00
|
|
|
} else if (focused_window) {
|
2012-12-26 10:30:50 +01:00
|
|
|
if (c->urgent)
|
2013-09-04 21:57:26 +02:00
|
|
|
get_color(urgent_border_color, c->window, &pxl);
|
2012-12-26 10:30:50 +01:00
|
|
|
else if (c->locked)
|
2013-09-04 21:57:26 +02:00
|
|
|
get_color(active_locked_border_color, c->window, &pxl);
|
2012-09-20 23:32:32 +02:00
|
|
|
else
|
2013-09-04 21:57:26 +02:00
|
|
|
get_color(active_border_color, c->window, &pxl);
|
2012-09-20 23:32:32 +02:00
|
|
|
} else {
|
|
|
|
if (c->urgent)
|
2013-09-04 21:57:26 +02:00
|
|
|
get_color(urgent_border_color, c->window, &pxl);
|
2012-09-20 23:32:32 +02:00
|
|
|
else if (c->locked)
|
2013-09-04 21:57:26 +02:00
|
|
|
get_color(normal_locked_border_color, c->window, &pxl);
|
2012-09-20 23:32:32 +02:00
|
|
|
else
|
2013-09-04 21:57:26 +02:00
|
|
|
get_color(normal_border_color, c->window, &pxl);
|
2012-09-20 23:32:32 +02:00
|
|
|
}
|
2013-09-04 21:57:26 +02:00
|
|
|
|
|
|
|
return pxl;
|
2012-09-20 23:32:32 +02:00
|
|
|
}
|
|
|
|
|
2012-09-22 15:10:59 +02:00
|
|
|
void update_floating_rectangle(client_t *c)
|
|
|
|
{
|
2013-04-01 12:29:45 +02:00
|
|
|
xcb_get_geometry_reply_t *geo = xcb_get_geometry_reply(dpy, xcb_get_geometry(dpy, c->window), NULL);
|
2012-09-22 15:10:59 +02:00
|
|
|
|
2013-04-01 12:29:45 +02:00
|
|
|
if (geo != NULL)
|
|
|
|
c->floating_rectangle = (xcb_rectangle_t) {geo->x, geo->y, geo->width, geo->height};
|
|
|
|
else
|
2012-10-17 16:18:40 +02:00
|
|
|
c->floating_rectangle = (xcb_rectangle_t) {0, 0, 32, 24};
|
2013-04-01 12:29:45 +02:00
|
|
|
|
|
|
|
free(geo);
|
2012-09-22 15:10:59 +02:00
|
|
|
}
|
|
|
|
|
2013-03-04 11:25:12 +01:00
|
|
|
|
2013-03-07 21:53:45 +01:00
|
|
|
void query_pointer(xcb_window_t *win, xcb_point_t *pt)
|
2013-03-04 11:25:12 +01:00
|
|
|
{
|
|
|
|
window_lower(motion_recorder);
|
2013-09-12 16:26:01 +02:00
|
|
|
|
2013-03-04 11:25:12 +01:00
|
|
|
xcb_query_pointer_reply_t *qpr = xcb_query_pointer_reply(dpy, xcb_query_pointer(dpy, root), NULL);
|
2013-09-12 16:26:01 +02:00
|
|
|
|
2013-03-04 11:25:12 +01:00
|
|
|
if (qpr != NULL) {
|
2013-03-07 21:53:45 +01:00
|
|
|
if (win != NULL)
|
|
|
|
*win = qpr->child;
|
|
|
|
if (pt != NULL)
|
|
|
|
*pt = (xcb_point_t) {qpr->root_x, qpr->root_y};
|
2013-03-04 11:25:12 +01:00
|
|
|
free(qpr);
|
|
|
|
}
|
2013-09-12 16:26:01 +02:00
|
|
|
|
2013-03-04 11:25:12 +01:00
|
|
|
window_raise(motion_recorder);
|
|
|
|
}
|
|
|
|
|
2013-09-22 11:16:06 +02:00
|
|
|
bool window_focus(xcb_window_t win)
|
2013-01-09 21:33:19 +01:00
|
|
|
{
|
2013-07-08 11:42:05 +02:00
|
|
|
coordinates_t loc;
|
2013-01-09 21:33:19 +01:00
|
|
|
if (locate_window(win, &loc)) {
|
2013-09-22 11:16:06 +02:00
|
|
|
if (loc.node != mon->desk->focus)
|
|
|
|
focus_node(loc.monitor, loc.desktop, loc.node);
|
|
|
|
return true;
|
2013-01-09 21:33:19 +01:00
|
|
|
}
|
2013-09-22 11:16:06 +02:00
|
|
|
return false;
|
2013-01-09 21:33:19 +01:00
|
|
|
}
|
|
|
|
|
2012-09-18 17:21:04 +02:00
|
|
|
void window_border_width(xcb_window_t win, uint32_t bw)
|
|
|
|
{
|
|
|
|
uint32_t values[] = {bw};
|
|
|
|
xcb_configure_window(dpy, win, XCB_CONFIG_WINDOW_BORDER_WIDTH, values);
|
|
|
|
}
|
|
|
|
|
2012-09-22 15:10:59 +02:00
|
|
|
void window_move(xcb_window_t win, int16_t x, int16_t y)
|
|
|
|
{
|
|
|
|
uint32_t values[] = {x, y};
|
|
|
|
xcb_configure_window(dpy, win, XCB_CONFIG_WINDOW_X_Y, values);
|
|
|
|
}
|
|
|
|
|
2013-06-02 22:03:51 +02:00
|
|
|
void window_resize(xcb_window_t win, uint16_t w, uint16_t h)
|
|
|
|
{
|
|
|
|
uint32_t values[] = {w, h};
|
|
|
|
xcb_configure_window(dpy, win, XCB_CONFIG_WINDOW_WIDTH_HEIGHT, values);
|
|
|
|
}
|
|
|
|
|
2012-09-18 17:21:04 +02:00
|
|
|
void window_move_resize(xcb_window_t win, int16_t x, int16_t y, uint16_t w, uint16_t h)
|
|
|
|
{
|
|
|
|
uint32_t values[] = {x, y, w, h};
|
|
|
|
xcb_configure_window(dpy, win, XCB_CONFIG_WINDOW_X_Y_WIDTH_HEIGHT, values);
|
|
|
|
}
|
|
|
|
|
|
|
|
void window_raise(xcb_window_t win)
|
|
|
|
{
|
|
|
|
uint32_t values[] = {XCB_STACK_MODE_ABOVE};
|
|
|
|
xcb_configure_window(dpy, win, XCB_CONFIG_WINDOW_STACK_MODE, values);
|
|
|
|
}
|
2012-09-19 22:59:13 +02:00
|
|
|
|
2013-09-12 16:26:01 +02:00
|
|
|
void window_stack(xcb_window_t w1, xcb_window_t w2, uint32_t mode)
|
|
|
|
{
|
|
|
|
if (w2 == XCB_NONE)
|
|
|
|
return;
|
|
|
|
uint16_t mask = XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE;
|
|
|
|
uint32_t values[] = {w2, mode};
|
|
|
|
xcb_configure_window(dpy, w1, mask, values);
|
|
|
|
}
|
|
|
|
|
|
|
|
void window_above(xcb_window_t w1, xcb_window_t w2)
|
|
|
|
{
|
|
|
|
window_stack(w1, w2, XCB_STACK_MODE_ABOVE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void window_below(xcb_window_t w1, xcb_window_t w2)
|
2012-11-04 14:35:17 +01:00
|
|
|
{
|
2013-09-12 16:26:01 +02:00
|
|
|
window_stack(w1, w2, XCB_STACK_MODE_BELOW);
|
2012-11-04 14:35:17 +01:00
|
|
|
}
|
|
|
|
|
2013-06-01 14:27:18 +02:00
|
|
|
void stack(desktop_t *d, node_t *n)
|
|
|
|
{
|
2013-09-12 16:26:01 +02:00
|
|
|
if (is_leaf(d->root))
|
|
|
|
return;
|
|
|
|
if (n->client->fullscreen) {
|
2013-07-15 20:28:28 +02:00
|
|
|
window_raise(n->client->window);
|
2013-09-12 16:26:01 +02:00
|
|
|
} else {
|
|
|
|
if (n->client->floating && !auto_raise)
|
|
|
|
return;
|
|
|
|
xcb_window_t latest_tiled = XCB_NONE;
|
|
|
|
xcb_window_t oldest_floating = XCB_NONE;
|
|
|
|
for (node_list_t *a = d->history->head; a != NULL; a = a->next) {
|
|
|
|
if (a->latest && a->node != n) {
|
|
|
|
if (a->node->client->floating == n->client->floating) {
|
|
|
|
window_above(n->client->window, a->node->client->window);
|
|
|
|
return;
|
|
|
|
} else if (latest_tiled == XCB_NONE && !a->node->client->floating) {
|
|
|
|
latest_tiled = a->node->client->window;
|
|
|
|
} else if (a->node->client->floating) {
|
|
|
|
oldest_floating = a->node->client->window;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (n->client->floating)
|
|
|
|
window_above(n->client->window, latest_tiled);
|
|
|
|
else
|
|
|
|
window_below(n->client->window, oldest_floating);
|
|
|
|
}
|
2013-06-01 14:27:18 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 22:59:13 +02:00
|
|
|
void window_lower(xcb_window_t win)
|
|
|
|
{
|
|
|
|
uint32_t values[] = {XCB_STACK_MODE_BELOW};
|
|
|
|
xcb_configure_window(dpy, win, XCB_CONFIG_WINDOW_STACK_MODE, values);
|
|
|
|
}
|
2012-09-21 19:05:42 +02:00
|
|
|
|
2013-05-29 14:34:27 +02:00
|
|
|
void window_set_visibility(xcb_window_t win, bool visible)
|
|
|
|
{
|
2012-09-21 19:05:42 +02:00
|
|
|
uint32_t values_off[] = {ROOT_EVENT_MASK & ~XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY};
|
|
|
|
uint32_t values_on[] = {ROOT_EVENT_MASK};
|
2013-01-02 12:36:54 +01:00
|
|
|
xcb_change_window_attributes(dpy, root, XCB_CW_EVENT_MASK, values_off);
|
2013-09-19 10:29:19 +02:00
|
|
|
if (visible)
|
2012-09-21 19:05:42 +02:00
|
|
|
xcb_map_window(dpy, win);
|
2013-09-19 10:29:19 +02:00
|
|
|
else
|
2012-09-21 19:05:42 +02:00
|
|
|
xcb_unmap_window(dpy, win);
|
2013-01-02 12:36:54 +01:00
|
|
|
xcb_change_window_attributes(dpy, root, XCB_CW_EVENT_MASK, values_on);
|
2012-09-21 19:05:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void window_hide(xcb_window_t win)
|
|
|
|
{
|
|
|
|
window_set_visibility(win, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void window_show(xcb_window_t win)
|
|
|
|
{
|
|
|
|
window_set_visibility(win, true);
|
|
|
|
}
|
2012-12-23 12:11:08 +01:00
|
|
|
|
|
|
|
void toggle_visibility(void)
|
|
|
|
{
|
|
|
|
visible = !visible;
|
2013-07-08 11:42:05 +02:00
|
|
|
if (!visible)
|
|
|
|
clear_input_focus();
|
2012-12-24 11:02:15 +01:00
|
|
|
for (monitor_t *m = mon_head; m != NULL; m = m->next)
|
2013-05-07 22:45:14 +02:00
|
|
|
for (node_t *n = first_extrema(m->desk->root); n != NULL; n = next_leaf(n, m->desk->root))
|
2013-01-08 15:52:20 +01:00
|
|
|
window_set_visibility(n->client->window, visible);
|
2012-12-23 12:14:30 +01:00
|
|
|
if (visible)
|
2013-06-29 21:09:56 +02:00
|
|
|
update_input_focus();
|
2012-12-23 12:11:08 +01:00
|
|
|
}
|
2013-03-04 11:25:12 +01:00
|
|
|
|
|
|
|
void enable_motion_recorder(void)
|
|
|
|
{
|
2013-06-03 20:59:27 +02:00
|
|
|
PUTS("enable motion recorder");
|
2013-03-04 11:25:12 +01:00
|
|
|
window_raise(motion_recorder);
|
|
|
|
window_show(motion_recorder);
|
|
|
|
}
|
|
|
|
|
|
|
|
void disable_motion_recorder(void)
|
|
|
|
{
|
2013-06-03 20:59:27 +02:00
|
|
|
PUTS("disable motion recorder");
|
2013-03-04 11:25:12 +01:00
|
|
|
window_hide(motion_recorder);
|
|
|
|
}
|
2013-03-18 19:44:09 +01:00
|
|
|
|
2013-06-02 22:03:51 +02:00
|
|
|
void update_motion_recorder(void)
|
|
|
|
{
|
|
|
|
xcb_get_geometry_reply_t *geo = xcb_get_geometry_reply(dpy, xcb_get_geometry(dpy, root), NULL);
|
|
|
|
|
2013-06-03 20:59:27 +02:00
|
|
|
if (geo != NULL) {
|
2013-06-02 22:03:51 +02:00
|
|
|
window_resize(motion_recorder, geo->width, geo->height);
|
2013-06-03 20:59:27 +02:00
|
|
|
PRINTF("update motion recorder size: %ux%u\n", geo->width, geo->height);
|
|
|
|
}
|
2013-06-02 22:03:51 +02:00
|
|
|
|
|
|
|
free(geo);
|
|
|
|
}
|
|
|
|
|
2013-06-29 21:09:56 +02:00
|
|
|
void update_input_focus(void)
|
|
|
|
{
|
|
|
|
set_input_focus(mon->desk->focus);
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_input_focus(node_t *n)
|
|
|
|
{
|
2013-09-05 15:37:54 +02:00
|
|
|
if (n == NULL) {
|
2013-07-30 14:53:44 +02:00
|
|
|
clear_input_focus();
|
2013-09-05 15:37:54 +02:00
|
|
|
} else {
|
|
|
|
if (n->client->icccm_focus)
|
2013-09-10 10:39:25 +02:00
|
|
|
send_client_message(n->client->window, ewmh->WM_PROTOCOLS, WM_TAKE_FOCUS);
|
2013-09-07 10:14:14 +02:00
|
|
|
xcb_set_input_focus(dpy, XCB_INPUT_FOCUS_POINTER_ROOT, n->client->window, XCB_CURRENT_TIME);
|
2013-09-05 15:37:54 +02:00
|
|
|
}
|
2013-06-29 21:09:56 +02:00
|
|
|
}
|
|
|
|
|
2013-03-18 19:44:09 +01:00
|
|
|
void clear_input_focus(void)
|
|
|
|
{
|
|
|
|
xcb_set_input_focus(dpy, XCB_INPUT_FOCUS_POINTER_ROOT, root, XCB_CURRENT_TIME);
|
|
|
|
}
|
2013-06-05 21:21:12 +02:00
|
|
|
|
|
|
|
void center_pointer(monitor_t *m)
|
|
|
|
{
|
|
|
|
int16_t cx = m->rectangle.x + m->rectangle.width / 2;
|
|
|
|
int16_t cy = m->rectangle.y + m->rectangle.height / 2;
|
2013-06-08 11:53:48 +02:00
|
|
|
window_lower(motion_recorder);
|
2013-06-05 21:21:12 +02:00
|
|
|
xcb_warp_pointer(dpy, XCB_NONE, root, 0, 0, 0, 0, cx, cy);
|
2013-06-08 11:53:48 +02:00
|
|
|
window_raise(motion_recorder);
|
2013-06-05 21:21:12 +02:00
|
|
|
}
|
2013-09-05 15:37:54 +02:00
|
|
|
|
|
|
|
void get_atom(char *name, xcb_atom_t *atom)
|
|
|
|
{
|
|
|
|
xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(dpy, xcb_intern_atom(dpy, 0, strlen(name), name), NULL);
|
|
|
|
if (reply != NULL)
|
|
|
|
*atom = reply->atom;
|
|
|
|
else
|
|
|
|
*atom = XCB_NONE;
|
|
|
|
free(reply);
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_atom(xcb_window_t win, xcb_atom_t atom, uint32_t value)
|
|
|
|
{
|
|
|
|
xcb_change_property(dpy, XCB_PROP_MODE_REPLACE, win, atom, XCB_ATOM_CARDINAL, 32, 1, &value);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool has_proto(xcb_atom_t atom, xcb_icccm_get_wm_protocols_reply_t *protocols)
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < protocols->atoms_len; i++)
|
|
|
|
if (protocols->atoms[i] == atom)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-09-10 10:39:25 +02:00
|
|
|
void send_client_message(xcb_window_t win, xcb_atom_t property, xcb_atom_t value)
|
2013-09-05 15:37:54 +02:00
|
|
|
{
|
|
|
|
xcb_client_message_event_t e;
|
|
|
|
|
|
|
|
e.response_type = XCB_CLIENT_MESSAGE;
|
|
|
|
e.window = win;
|
|
|
|
e.format = 32;
|
|
|
|
e.sequence = 0;
|
2013-09-10 10:39:25 +02:00
|
|
|
e.type = property;
|
|
|
|
e.data.data32[0] = value;
|
2013-09-05 15:37:54 +02:00
|
|
|
e.data.data32[1] = XCB_CURRENT_TIME;
|
|
|
|
|
|
|
|
xcb_send_event(dpy, false, win, XCB_EVENT_MASK_NO_EVENT, (char *) &e);
|
|
|
|
}
|