2012-09-18 17:21:04 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <xcb/xcb.h>
|
|
|
|
#include <xcb/xcb_event.h>
|
2012-10-24 16:34:56 +02:00
|
|
|
#include <xcb/xcb_icccm.h>
|
2012-09-18 17:21:04 +02:00
|
|
|
#include "types.h"
|
|
|
|
#include "tree.h"
|
|
|
|
#include "bspwm.h"
|
|
|
|
#include "settings.h"
|
|
|
|
#include "ewmh.h"
|
2012-10-24 16:34:56 +02:00
|
|
|
#include "rules.h"
|
2012-09-18 17:21:04 +02:00
|
|
|
#include "window.h"
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool might_cover(desktop_t *d, node_t *n)
|
|
|
|
{
|
|
|
|
for (node_t *f = first_extrema(d->root); f != NULL; f = next_leaf(f))
|
|
|
|
if (f != n && is_floating(f->client) && contains(n->client->floating_rectangle, f->client->floating_rectangle))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-09-18 17:21:04 +02:00
|
|
|
bool locate_window(xcb_window_t win, window_location_t *loc)
|
|
|
|
{
|
2012-10-23 12:17:19 +02:00
|
|
|
for (monitor_t *m = mon_head; m != NULL; m = m->next)
|
|
|
|
for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
|
|
|
|
for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n))
|
2012-10-17 16:18:40 +02:00
|
|
|
if (n->client->window == win) {
|
|
|
|
loc->monitor = m;
|
|
|
|
loc->desktop = d;
|
|
|
|
loc->node = n;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2012-09-18 17:21:04 +02:00
|
|
|
|
2012-10-17 16:18:40 +02:00
|
|
|
bool locate_desktop(char *name, desktop_location_t *loc)
|
|
|
|
{
|
2012-10-25 21:49:14 +02:00
|
|
|
for (monitor_t *m = mon_head; m != NULL; m = m->next)
|
|
|
|
for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
|
2012-10-17 16:18:40 +02:00
|
|
|
if (strcmp(d->name, name) == 0) {
|
|
|
|
loc->monitor = m;
|
2012-09-18 17:21:04 +02:00
|
|
|
loc->desktop = d;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-08 18:24:17 +01:00
|
|
|
bool is_inside(monitor_t *m, xcb_point_t p)
|
|
|
|
{
|
|
|
|
xcb_rectangle_t r = m->rectangle;
|
|
|
|
return (r.x <= p.x && p.x < (r.x + r.width)
|
|
|
|
&& r.y <= p.y && p.y < (r.y + r.height));
|
|
|
|
}
|
|
|
|
|
|
|
|
monitor_t *underlying_monitor(client_t *c)
|
|
|
|
{
|
|
|
|
xcb_point_t p = (xcb_point_t) {c->floating_rectangle.x, c->floating_rectangle.y};
|
|
|
|
for (monitor_t *m = mon_head; m != NULL; m = m->next)
|
|
|
|
if (is_inside(m, p))
|
|
|
|
return m;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
window_location_t loc;
|
|
|
|
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;
|
|
|
|
|
|
|
|
bool floating = false, transient = false, fullscreen = false, takes_focus = true, manage = true;
|
|
|
|
|
2012-11-11 18:40:55 +01:00
|
|
|
handle_rules(win, &m, &d, &floating, &transient, &fullscreen, &takes_focus, &manage);
|
2012-10-24 16:34:56 +02:00
|
|
|
|
|
|
|
if (!manage) {
|
2013-01-19 20:09:02 +01:00
|
|
|
disable_shadow(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) {
|
|
|
|
strncpy(c->class_name, reply.class_name, sizeof(c->class_name));
|
|
|
|
xcb_icccm_get_wm_class_reply_wipe(&reply);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (c->transient)
|
|
|
|
floating = true;
|
|
|
|
|
|
|
|
node_t *birth = make_node();
|
|
|
|
birth->client = c;
|
|
|
|
|
|
|
|
if (floating)
|
|
|
|
split_mode = MODE_MANUAL;
|
|
|
|
|
2012-10-29 10:45:47 +01:00
|
|
|
insert_node(m, d, birth);
|
2012-10-24 16:34:56 +02:00
|
|
|
|
2012-11-29 15:28:43 +01:00
|
|
|
disable_shadow(c->window);
|
|
|
|
|
2012-10-24 16:34:56 +02:00
|
|
|
if (floating)
|
|
|
|
toggle_floating(birth);
|
|
|
|
|
2012-10-25 21:49:14 +02:00
|
|
|
if (d->focus != NULL && d->focus->client->fullscreen)
|
|
|
|
toggle_fullscreen(m, d->focus->client);
|
2012-10-24 16:34:56 +02:00
|
|
|
|
|
|
|
if (fullscreen)
|
2012-10-25 21:49:14 +02:00
|
|
|
toggle_fullscreen(m, birth->client);
|
2012-10-24 16:34:56 +02:00
|
|
|
|
2012-10-24 22:17:45 +02:00
|
|
|
if (is_tiled(c))
|
|
|
|
window_lower(c->window);
|
|
|
|
|
2012-10-24 16:34:56 +02:00
|
|
|
c->transient = transient;
|
|
|
|
|
|
|
|
if (takes_focus)
|
2012-10-25 21:49:14 +02:00
|
|
|
focus_node(m, d, birth, false);
|
2012-10-24 16:34:56 +02:00
|
|
|
|
2012-12-14 15:43:22 +01:00
|
|
|
xcb_rectangle_t *frect = &birth->client->floating_rectangle;
|
|
|
|
if (frect->x == 0 && frect->y == 0)
|
|
|
|
center(m->rectangle, frect);
|
|
|
|
|
2012-10-25 21:49:14 +02:00
|
|
|
fit_monitor(m, birth->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
|
|
|
|
|
|
|
if (takes_focus)
|
|
|
|
xcb_set_input_focus(dpy, XCB_INPUT_FOCUS_POINTER_ROOT, win, XCB_CURRENT_TIME);
|
|
|
|
|
2013-01-08 15:52:20 +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++;
|
2012-10-25 21:49:14 +02:00
|
|
|
ewmh_set_wm_desktop(birth, 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;
|
|
|
|
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) {
|
|
|
|
desktop_location_t loc;
|
|
|
|
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
|
|
|
{
|
|
|
|
if (n == NULL)
|
|
|
|
return;
|
|
|
|
|
2012-09-28 22:39:32 +02:00
|
|
|
if (border_width < 1 || n->client->border_width < 1)
|
2012-09-18 17:21:04 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
xcb_window_t win = n->client->window;
|
|
|
|
|
2012-09-21 17:39:22 +02:00
|
|
|
xcb_rectangle_t actual_rectangle = (is_tiled(n->client) ? n->client->tiled_rectangle : n->client->floating_rectangle);
|
2012-09-18 17:21:04 +02:00
|
|
|
|
2012-09-21 17:39:22 +02:00
|
|
|
uint16_t width = actual_rectangle.width;
|
|
|
|
uint16_t height = actual_rectangle.height;
|
2012-09-18 17:21:04 +02:00
|
|
|
|
|
|
|
uint16_t full_width = width + 2 * border_width;
|
|
|
|
uint16_t full_height = height + 2 * border_width;
|
|
|
|
|
|
|
|
xcb_rectangle_t inner_rectangles[] =
|
|
|
|
{
|
|
|
|
{ width, 0, 2 * border_width, height + 2 * border_width },
|
|
|
|
{ 0, height, width + 2 * border_width, 2 * border_width }
|
|
|
|
};
|
|
|
|
|
|
|
|
xcb_rectangle_t main_rectangles[] =
|
|
|
|
{
|
|
|
|
{ width + inner_border_width, 0, 2 * (main_border_width + outer_border_width), height + 2 * border_width },
|
|
|
|
{ 0, height + inner_border_width, width + 2 * border_width, 2 * (main_border_width + outer_border_width) }
|
|
|
|
};
|
|
|
|
|
|
|
|
xcb_rectangle_t outer_rectangles[] =
|
|
|
|
{
|
|
|
|
{ width + inner_border_width + main_border_width, 0, 2 * outer_border_width, height + 2 * border_width },
|
|
|
|
{ 0, height + inner_border_width + main_border_width, width + 2 * border_width, 2 * outer_border_width }
|
|
|
|
};
|
|
|
|
|
|
|
|
xcb_rectangle_t *presel_rectangles;
|
|
|
|
|
|
|
|
xcb_pixmap_t pix = xcb_generate_id(dpy);
|
2012-09-21 17:39:22 +02:00
|
|
|
xcb_create_pixmap(dpy, root_depth, pix, win, full_width, full_height);
|
2012-09-18 17:21:04 +02:00
|
|
|
|
|
|
|
xcb_gcontext_t gc = xcb_generate_id(dpy);
|
|
|
|
xcb_create_gc(dpy, gc, pix, 0, NULL);
|
|
|
|
|
2012-10-17 16:18:40 +02:00
|
|
|
uint32_t main_border_color_pxl = get_main_border_color(n->client, focused_window, focused_monitor);
|
2012-09-20 23:32:32 +02:00
|
|
|
|
2012-09-18 17:21:04 +02:00
|
|
|
/* inner border */
|
|
|
|
if (inner_border_width > 0) {
|
|
|
|
xcb_change_gc(dpy, gc, XCB_GC_FOREGROUND, &inner_border_color_pxl);
|
|
|
|
xcb_poly_fill_rectangle(dpy, pix, gc, LENGTH(inner_rectangles), inner_rectangles);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* main border */
|
|
|
|
if (main_border_width > 0) {
|
|
|
|
xcb_change_gc(dpy, gc, XCB_GC_FOREGROUND, &main_border_color_pxl);
|
|
|
|
xcb_poly_fill_rectangle(dpy, pix, gc, LENGTH(main_rectangles), main_rectangles);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* outer border */
|
|
|
|
if (outer_border_width > 0) {
|
|
|
|
xcb_change_gc(dpy, gc, XCB_GC_FOREGROUND, &outer_border_color_pxl);
|
|
|
|
xcb_poly_fill_rectangle(dpy, pix, gc, LENGTH(outer_rectangles), outer_rectangles);
|
|
|
|
}
|
|
|
|
|
2012-10-17 16:18:40 +02:00
|
|
|
if (split_mode == MODE_MANUAL && focused_monitor && focused_window) {
|
2012-09-18 17:21:04 +02:00
|
|
|
uint16_t fence = (int16_t) (n->split_ratio * ((split_dir == DIR_UP || split_dir == DIR_DOWN) ? height : width));
|
|
|
|
presel_rectangles = malloc(2 * sizeof(xcb_rectangle_t));
|
|
|
|
switch (split_dir) {
|
|
|
|
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);
|
|
|
|
xcb_poly_fill_rectangle(dpy, pix, gc, 2, presel_rectangles);
|
|
|
|
free(presel_rectangles);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* apply border pixmap */
|
|
|
|
xcb_change_window_attributes(dpy, win, XCB_CW_BORDER_PIXMAP, &pix);
|
|
|
|
|
|
|
|
xcb_free_gc(dpy, gc);
|
|
|
|
xcb_free_pixmap(dpy, pix);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
xcb_atom_t WM_DELETE_WINDOW;
|
|
|
|
xcb_window_t win = n->client->window;
|
|
|
|
xcb_client_message_event_t e;
|
|
|
|
|
|
|
|
xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(dpy, xcb_intern_atom(dpy, 0, strlen("WM_DELETE_WINDOW"), "WM_DELETE_WINDOW"), NULL);
|
|
|
|
if (reply) {
|
|
|
|
WM_DELETE_WINDOW = reply->atom;
|
|
|
|
free(reply);
|
|
|
|
} else {
|
2012-10-06 12:03:12 +02:00
|
|
|
warn("close_window %X: could not acquire WM_DELETE_WINDOW atom\n", win);
|
2012-09-18 17:21:04 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
e.response_type = XCB_CLIENT_MESSAGE;
|
|
|
|
e.window = win;
|
|
|
|
e.format = 32;
|
|
|
|
e.sequence = 0;
|
|
|
|
e.type = ewmh->WM_PROTOCOLS;
|
|
|
|
e.data.data32[0] = WM_DELETE_WINDOW;
|
|
|
|
e.data.data32[1] = XCB_CURRENT_TIME;
|
|
|
|
|
|
|
|
xcb_send_event(dpy, false, win, XCB_EVENT_MASK_NO_EVENT, (char *) &e);
|
|
|
|
}
|
|
|
|
|
2012-09-28 15:59:29 +02:00
|
|
|
void window_kill(desktop_t *d, node_t *n)
|
|
|
|
{
|
|
|
|
if (n == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
PRINTF("kill window %X\n", n->client->window);
|
|
|
|
|
|
|
|
xcb_kill_client(dpy, n->client->window);
|
|
|
|
remove_node(d, n);
|
|
|
|
}
|
|
|
|
|
2012-10-18 11:09:17 +02:00
|
|
|
void toggle_fullscreen(monitor_t *m, client_t *c)
|
2012-09-18 17:21:04 +02:00
|
|
|
{
|
2012-10-06 12:03:12 +02:00
|
|
|
PRINTF("toggle fullscreen %X\n", c->window);
|
|
|
|
|
2012-09-18 17:21:04 +02:00
|
|
|
if (c->fullscreen) {
|
|
|
|
c->fullscreen = false;
|
|
|
|
xcb_atom_t values[] = {XCB_NONE};
|
|
|
|
xcb_ewmh_set_wm_state(ewmh, c->window, LENGTH(values), values);
|
2012-10-24 22:17:45 +02:00
|
|
|
if (is_tiled(c))
|
|
|
|
window_lower(c->window);
|
2012-09-18 17:21:04 +02:00
|
|
|
} else {
|
|
|
|
c->fullscreen = true;
|
|
|
|
xcb_atom_t values[] = {ewmh->_NET_WM_STATE_FULLSCREEN};
|
|
|
|
xcb_ewmh_set_wm_state(ewmh, c->window, LENGTH(values), values);
|
|
|
|
window_raise(c->window);
|
|
|
|
window_border_width(c->window, 0);
|
2012-10-18 11:09:17 +02:00
|
|
|
xcb_rectangle_t r = m->rectangle;
|
|
|
|
window_move_resize(c->window, r.x, r.y, r.width, r.height);
|
2012-09-18 17:21:04 +02:00
|
|
|
}
|
2012-11-04 14:35:17 +01:00
|
|
|
update_current();
|
2012-09-18 17:21:04 +02:00
|
|
|
}
|
|
|
|
|
2012-09-20 23:32:32 +02:00
|
|
|
void toggle_floating(node_t *n)
|
|
|
|
{
|
|
|
|
if (n == NULL || n->client->transient)
|
|
|
|
return;
|
|
|
|
|
2012-10-06 12:04:18 +02:00
|
|
|
PRINTF("toggle floating %X\n", n->client->window);
|
2012-09-20 23:32:32 +02:00
|
|
|
|
|
|
|
client_t *c = n->client;
|
|
|
|
c->floating = !c->floating;
|
|
|
|
n->vacant = !n->vacant;
|
|
|
|
update_vacant_state(n->parent);
|
|
|
|
if (c->floating)
|
|
|
|
window_raise(c->window);
|
2012-09-21 12:15:25 +02:00
|
|
|
else if (is_tiled(c))
|
|
|
|
window_lower(c->window);
|
2012-11-29 15:28:43 +01:00
|
|
|
if (c->floating)
|
|
|
|
enable_shadow(c->window);
|
|
|
|
else
|
|
|
|
disable_shadow(c->window);
|
2012-11-04 14:35:17 +01:00
|
|
|
update_current();
|
2012-09-20 23:32:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void toggle_locked(client_t *c)
|
|
|
|
{
|
2012-10-06 12:03:12 +02:00
|
|
|
PRINTF("toggle locked %X\n", c->window);
|
|
|
|
|
2012-09-20 23:32:32 +02:00
|
|
|
c->locked = !c->locked;
|
|
|
|
}
|
|
|
|
|
2012-11-29 15:28:43 +01:00
|
|
|
void set_shadow(xcb_window_t win, uint32_t value)
|
|
|
|
{
|
2013-01-19 20:58:21 +01:00
|
|
|
if (!apply_shadow_property)
|
|
|
|
return;
|
2012-11-29 15:28:43 +01:00
|
|
|
xcb_change_property(dpy, XCB_PROP_MODE_REPLACE, win, compton_shadow, XCB_ATOM_CARDINAL, 32, sizeof(value), &value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void enable_shadow(xcb_window_t win)
|
|
|
|
{
|
|
|
|
set_shadow(win, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void disable_shadow(xcb_window_t win)
|
|
|
|
{
|
|
|
|
set_shadow(win, 0);
|
|
|
|
}
|
|
|
|
|
2012-09-18 17:21:04 +02:00
|
|
|
void list_windows(char *rsp)
|
|
|
|
{
|
2012-10-04 14:46:41 +02:00
|
|
|
char line[MAXLEN];
|
2012-09-18 17:21:04 +02:00
|
|
|
|
2012-10-17 16:18:40 +02:00
|
|
|
for (monitor_t *m = mon_head; m != NULL; m = m->next)
|
|
|
|
for (desktop_t *d = m->desk_head; d != NULL; d = d->next)
|
|
|
|
for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n)) {
|
|
|
|
snprintf(line, sizeof(line), "0x%X\n", n->client->window);
|
|
|
|
strncat(rsp, line, REMLEN(rsp));
|
|
|
|
}
|
2012-09-18 17:21:04 +02:00
|
|
|
}
|
|
|
|
|
2012-10-17 16:18:40 +02:00
|
|
|
uint32_t get_main_border_color(client_t *c, bool focused_window, bool focused_monitor)
|
2012-09-20 23:32:32 +02:00
|
|
|
{
|
|
|
|
if (c == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2012-10-17 16:18:40 +02:00
|
|
|
if (focused_monitor && focused_window) {
|
|
|
|
if (c->locked)
|
|
|
|
return focused_locked_border_color_pxl;
|
|
|
|
else
|
|
|
|
return focused_border_color_pxl;
|
|
|
|
} else if (focused_window) {
|
2012-12-26 10:30:50 +01:00
|
|
|
if (c->urgent)
|
2012-12-26 00:41:23 +00:00
|
|
|
return urgent_border_color_pxl;
|
2012-12-26 10:30:50 +01:00
|
|
|
else if (c->locked)
|
2012-09-20 23:32:32 +02:00
|
|
|
return active_locked_border_color_pxl;
|
|
|
|
else
|
|
|
|
return active_border_color_pxl;
|
|
|
|
} else {
|
|
|
|
if (c->urgent)
|
|
|
|
return urgent_border_color_pxl;
|
|
|
|
else if (c->locked)
|
|
|
|
return normal_locked_border_color_pxl;
|
|
|
|
else
|
|
|
|
return normal_border_color_pxl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-22 15:10:59 +02:00
|
|
|
void update_floating_rectangle(client_t *c)
|
|
|
|
{
|
|
|
|
xcb_get_geometry_reply_t *geom = xcb_get_geometry_reply(dpy, xcb_get_geometry(dpy, c->window), NULL);
|
|
|
|
|
|
|
|
if (geom) {
|
|
|
|
c->floating_rectangle = (xcb_rectangle_t) {geom->x, geom->y, geom->width, geom->height};
|
|
|
|
free(geom);
|
|
|
|
} else {
|
2012-10-17 16:18:40 +02:00
|
|
|
c->floating_rectangle = (xcb_rectangle_t) {0, 0, 32, 24};
|
2012-09-22 15:10:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-09 21:33:19 +01:00
|
|
|
|
|
|
|
void save_pointer_position(xcb_point_t *pos)
|
|
|
|
{
|
|
|
|
xcb_query_pointer_reply_t *qpr = xcb_query_pointer_reply(dpy, xcb_query_pointer(dpy, root), NULL);
|
|
|
|
if (qpr != NULL) {
|
|
|
|
*pos = (xcb_point_t) {qpr->root_x, qpr->root_y};
|
|
|
|
free(qpr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void window_focus(xcb_window_t win)
|
|
|
|
{
|
|
|
|
window_location_t loc;
|
|
|
|
if (locate_window(win, &loc)) {
|
|
|
|
if (loc.node == mon->desk->focus)
|
|
|
|
return;
|
|
|
|
select_monitor(loc.monitor);
|
|
|
|
select_desktop(loc.desktop);
|
|
|
|
focus_node(loc.monitor, loc.desktop, loc.node, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2012-11-04 14:35:17 +01:00
|
|
|
void window_pseudo_raise(desktop_t *d, xcb_window_t win)
|
|
|
|
{
|
|
|
|
for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n))
|
|
|
|
if (is_tiled(n->client) && n->client->window != win)
|
|
|
|
window_lower(n->client->window);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
void window_set_visibility(xcb_window_t win, bool visible) {
|
|
|
|
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);
|
2012-09-21 19:05:42 +02:00
|
|
|
if (visible)
|
|
|
|
xcb_map_window(dpy, win);
|
|
|
|
else
|
|
|
|
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;
|
2012-12-24 11:02:15 +01:00
|
|
|
for (monitor_t *m = mon_head; m != NULL; m = m->next)
|
2013-01-08 15:52:20 +01:00
|
|
|
for (node_t *n = first_extrema(m->desk->root); n != NULL; n = next_leaf(n))
|
|
|
|
window_set_visibility(n->client->window, visible);
|
2012-12-23 12:14:30 +01:00
|
|
|
if (visible)
|
|
|
|
update_current();
|
2012-12-23 12:11:08 +01:00
|
|
|
}
|