2014-10-22 11:53:03 +02:00
|
|
|
/* Copyright (c) 2012, Bastien Dejean
|
2013-10-08 21:05:56 +02:00
|
|
|
* All rights reserved.
|
2014-01-19 14:41:37 +01:00
|
|
|
*
|
2014-01-18 16:30:00 +01:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
2014-01-19 14:41:37 +01:00
|
|
|
*
|
2014-01-18 16:30:00 +01:00
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
2014-01-19 14:41:37 +01:00
|
|
|
*
|
2014-01-18 16:30:00 +01:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
2013-10-08 21:05:56 +02:00
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
2014-01-18 16:30:00 +01:00
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
2013-10-08 21:05:56 +02:00
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdbool.h>
|
2013-05-07 22:45:14 +02:00
|
|
|
#include <float.h>
|
2013-10-01 10:48:03 +02:00
|
|
|
#include <limits.h>
|
2012-09-04 21:01:50 +02:00
|
|
|
#include "bspwm.h"
|
2013-09-19 15:38:22 +02:00
|
|
|
#include "desktop.h"
|
2013-10-01 10:48:03 +02:00
|
|
|
#include "ewmh.h"
|
2013-09-19 15:38:22 +02:00
|
|
|
#include "history.h"
|
2013-10-01 10:48:03 +02:00
|
|
|
#include "monitor.h"
|
2013-09-19 15:38:22 +02:00
|
|
|
#include "query.h"
|
2016-02-26 14:22:03 +01:00
|
|
|
#include "geometry.h"
|
2015-05-09 21:12:19 +02:00
|
|
|
#include "subscribe.h"
|
2013-10-01 10:48:03 +02:00
|
|
|
#include "settings.h"
|
2016-04-07 18:08:32 +02:00
|
|
|
#include "pointer.h"
|
2013-10-01 10:48:03 +02:00
|
|
|
#include "stack.h"
|
|
|
|
#include "window.h"
|
|
|
|
#include "tree.h"
|
2012-08-17 22:18:26 +02:00
|
|
|
|
2013-09-20 11:57:09 +02:00
|
|
|
void arrange(monitor_t *m, desktop_t *d)
|
|
|
|
{
|
2015-12-22 19:25:45 +01:00
|
|
|
if (d->root == NULL) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
|
2016-01-10 18:29:51 +01:00
|
|
|
layout_t last_layout = d->layout;
|
2015-12-22 19:25:45 +01:00
|
|
|
|
|
|
|
if (single_monocle && tiled_count(d->root) == 1) {
|
2015-08-05 23:20:07 +02:00
|
|
|
d->layout = LAYOUT_MONOCLE;
|
2015-08-07 08:47:24 +02:00
|
|
|
}
|
2015-08-05 23:20:07 +02:00
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
xcb_rectangle_t rect = m->rectangle;
|
2016-01-10 18:29:51 +01:00
|
|
|
|
|
|
|
if (!paddingless_monocle || d->layout != LAYOUT_MONOCLE) {
|
2016-03-21 14:28:04 +01:00
|
|
|
rect.x += m->padding.left + d->padding.left;
|
|
|
|
rect.y += m->padding.top + d->padding.top;
|
|
|
|
rect.width -= m->padding.left + d->padding.left + d->padding.right + m->padding.right;
|
|
|
|
rect.height -= m->padding.top + d->padding.top + d->padding.bottom + m->padding.bottom;
|
2016-01-10 18:29:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!gapless_monocle || d->layout != LAYOUT_MONOCLE) {
|
|
|
|
rect.x += d->window_gap;
|
|
|
|
rect.y += d->window_gap;
|
|
|
|
rect.width -= d->window_gap;
|
|
|
|
rect.height -= d->window_gap;
|
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
apply_layout(m, d, d->root, rect, rect);
|
2015-08-05 23:20:07 +02:00
|
|
|
|
2016-01-10 18:29:51 +01:00
|
|
|
d->layout = last_layout;
|
2013-09-20 11:57:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void apply_layout(monitor_t *m, desktop_t *d, node_t *n, xcb_rectangle_t rect, xcb_rectangle_t root_rect)
|
|
|
|
{
|
2015-12-22 19:25:45 +01:00
|
|
|
if (n == NULL) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
|
|
|
|
n->rectangle = rect;
|
|
|
|
|
2016-04-07 18:08:32 +02:00
|
|
|
if (pointer_follows_focus && mon->desk->focus == n) {
|
2015-12-22 19:25:45 +01:00
|
|
|
xcb_rectangle_t r = rect;
|
|
|
|
r.width -= d->window_gap;
|
|
|
|
r.height -= d->window_gap;
|
|
|
|
center_pointer(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n->presel != NULL) {
|
|
|
|
draw_presel_feedback(m, d, n);
|
|
|
|
}
|
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
if (is_leaf(n)) {
|
|
|
|
|
2016-03-26 11:47:17 +01:00
|
|
|
if (n->client == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-09 14:47:27 +01:00
|
|
|
unsigned int bw;
|
2015-11-05 14:00:49 +01:00
|
|
|
if ((borderless_monocle && n->client->state == STATE_TILED && d->layout == LAYOUT_MONOCLE)
|
|
|
|
|| n->client->state == STATE_FULLSCREEN) {
|
2014-02-09 14:47:27 +01:00
|
|
|
bw = 0;
|
2015-11-05 14:00:49 +01:00
|
|
|
} else {
|
2014-02-09 14:47:27 +01:00
|
|
|
bw = n->client->border_width;
|
2015-11-05 14:00:49 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
|
|
|
|
xcb_rectangle_t r;
|
2016-04-15 16:34:45 +02:00
|
|
|
xcb_rectangle_t cr = get_window_rectangle(n);
|
2015-11-05 14:00:49 +01:00
|
|
|
client_state_t s = n->client->state;
|
|
|
|
if (s == STATE_TILED || s == STATE_PSEUDO_TILED) {
|
|
|
|
int wg = (gapless_monocle && d->layout == LAYOUT_MONOCLE ? 0 : d->window_gap);
|
|
|
|
/* tiled clients */
|
|
|
|
if (s == STATE_TILED) {
|
|
|
|
r = rect;
|
|
|
|
int bleed = wg + 2 * bw;
|
|
|
|
r.width = (bleed < r.width ? r.width - bleed : 1);
|
|
|
|
r.height = (bleed < r.height ? r.height - bleed : 1);
|
|
|
|
/* pseudo-tiled clients */
|
2014-01-18 16:30:00 +01:00
|
|
|
} else {
|
|
|
|
r = n->client->floating_rectangle;
|
2015-11-05 14:00:49 +01:00
|
|
|
if (center_pseudo_tiled) {
|
|
|
|
r.x = rect.x - bw + (rect.width - wg - r.width) / 2;
|
|
|
|
r.y = rect.y - bw + (rect.height - wg - r.height) / 2;
|
|
|
|
} else {
|
|
|
|
r.x = rect.x;
|
|
|
|
r.y = rect.y;
|
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
2015-11-07 11:57:47 +01:00
|
|
|
n->client->tiled_rectangle = r;
|
2015-11-05 14:00:49 +01:00
|
|
|
/* floating clients */
|
|
|
|
} else if (s == STATE_FLOATING) {
|
|
|
|
r = n->client->floating_rectangle;
|
|
|
|
/* fullscreen clients */
|
2014-01-18 16:30:00 +01:00
|
|
|
} else {
|
|
|
|
r = m->rectangle;
|
2016-04-15 16:34:45 +02:00
|
|
|
n->client->tiled_rectangle = r;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
|
2016-04-07 18:08:32 +02:00
|
|
|
apply_size_hints(n->client, &r.width, &r.height);
|
|
|
|
|
2016-02-11 18:37:48 +01:00
|
|
|
if (!rect_eq(r, cr)) {
|
|
|
|
window_move_resize(n->id, r.x, r.y, r.width, r.height);
|
2016-04-07 18:08:32 +02:00
|
|
|
if (!grabbing) {
|
2016-03-23 11:24:47 +01:00
|
|
|
put_status(SBSC_MASK_NODE_GEOMETRY, "node_geometry 0x%08X 0x%08X 0x%08X %ux%u+%i+%i\n", m->id, d->id, n->id, r.width, r.height, r.x, r.y);
|
2016-02-11 18:37:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
window_border_width(n->id, bw);
|
2014-01-18 16:30:00 +01:00
|
|
|
|
|
|
|
} else {
|
|
|
|
xcb_rectangle_t first_rect;
|
|
|
|
xcb_rectangle_t second_rect;
|
|
|
|
|
|
|
|
if (d->layout == LAYOUT_MONOCLE || n->first_child->vacant || n->second_child->vacant) {
|
|
|
|
first_rect = second_rect = rect;
|
|
|
|
} else {
|
|
|
|
unsigned int fence;
|
|
|
|
if (n->split_type == TYPE_VERTICAL) {
|
|
|
|
fence = rect.width * n->split_ratio;
|
|
|
|
first_rect = (xcb_rectangle_t) {rect.x, rect.y, fence, rect.height};
|
|
|
|
second_rect = (xcb_rectangle_t) {rect.x + fence, rect.y, rect.width - fence, rect.height};
|
|
|
|
} else {
|
|
|
|
fence = rect.height * n->split_ratio;
|
|
|
|
first_rect = (xcb_rectangle_t) {rect.x, rect.y, rect.width, fence};
|
|
|
|
second_rect = (xcb_rectangle_t) {rect.x, rect.y + fence, rect.width, rect.height - fence};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
apply_layout(m, d, n->first_child, first_rect, root_rect);
|
|
|
|
apply_layout(m, d, n->second_child, second_rect, root_rect);
|
|
|
|
}
|
2013-09-20 11:57:09 +02:00
|
|
|
}
|
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
presel_t *make_presel(void)
|
|
|
|
{
|
|
|
|
presel_t *p = malloc(sizeof(presel_t));
|
|
|
|
p->split_dir = DIR_EAST;
|
|
|
|
p->split_ratio = split_ratio;
|
|
|
|
p->feedback = XCB_NONE;
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2016-03-26 11:47:17 +01:00
|
|
|
void set_ratio(node_t *n, double rat)
|
|
|
|
{
|
|
|
|
if (n == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
n->split_ratio = rat;
|
|
|
|
}
|
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
void presel_dir(monitor_t *m, desktop_t *d, node_t *n, direction_t dir)
|
|
|
|
{
|
|
|
|
if (n->presel == NULL) {
|
|
|
|
n->presel = make_presel();
|
|
|
|
}
|
|
|
|
|
|
|
|
n->presel->split_dir = dir;
|
|
|
|
|
2016-03-23 11:24:47 +01:00
|
|
|
put_status(SBSC_MASK_NODE_PRESEL, "node_presel 0x%08X 0x%08X 0x%08X dir %s\n", m->id, d->id, n->id, SPLIT_DIR_STR(dir));
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void presel_ratio(monitor_t *m, desktop_t *d, node_t *n, double ratio)
|
|
|
|
{
|
|
|
|
if (n->presel == NULL) {
|
|
|
|
n->presel = make_presel();
|
|
|
|
}
|
|
|
|
|
|
|
|
n->presel->split_ratio = ratio;
|
|
|
|
|
2016-03-23 11:24:47 +01:00
|
|
|
put_status(SBSC_MASK_NODE_PRESEL, "node_presel 0x%08X 0x%08X 0x%08X ratio %lf\n", m->id, d->id, n->id, ratio);
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void cancel_presel(monitor_t *m, desktop_t *d, node_t *n)
|
2013-09-20 11:57:09 +02:00
|
|
|
{
|
2015-12-22 19:25:45 +01:00
|
|
|
if (n->presel == NULL) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (n->presel->feedback != XCB_NONE) {
|
|
|
|
xcb_destroy_window(dpy, n->presel->feedback);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(n->presel);
|
|
|
|
n->presel = NULL;
|
2014-01-18 16:30:00 +01:00
|
|
|
|
2016-03-23 11:24:47 +01:00
|
|
|
put_status(SBSC_MASK_NODE_PRESEL, "node_presel 0x%08X 0x%08X 0x%08X cancel\n", m->id, d->id, n->id);
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
node_t *find_public(desktop_t *d)
|
|
|
|
{
|
|
|
|
unsigned int b_manual_area = 0;
|
|
|
|
unsigned int b_automatic_area = 0;
|
|
|
|
node_t *b_manual = NULL;
|
|
|
|
node_t *b_automatic = NULL;
|
|
|
|
for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) {
|
|
|
|
if (n->vacant) {
|
|
|
|
continue;
|
|
|
|
}
|
2016-02-12 22:49:06 +01:00
|
|
|
unsigned int n_area = node_area(d, n);
|
2015-12-22 19:25:45 +01:00
|
|
|
if (n_area > b_manual_area && (n->presel != NULL || !n->private)) {
|
|
|
|
b_manual = n;
|
|
|
|
b_manual_area = n_area;
|
|
|
|
}
|
|
|
|
if (n_area > b_automatic_area &&
|
|
|
|
n->presel == NULL && !n->private && private_count(n->parent) == 0) {
|
|
|
|
b_automatic = n;
|
|
|
|
b_automatic_area = n_area;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (b_automatic != NULL) {
|
|
|
|
return b_automatic;
|
|
|
|
} else {
|
|
|
|
return b_manual;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
node_t *insert_node(monitor_t *m, desktop_t *d, node_t *n, node_t *f)
|
|
|
|
{
|
|
|
|
if (d == NULL || n == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* n: inserted node */
|
|
|
|
/* c: new internal node */
|
2014-01-18 16:30:00 +01:00
|
|
|
/* f: focus or insertion anchor */
|
|
|
|
/* p: parent of focus */
|
|
|
|
/* g: grand parent of focus */
|
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
if (f == NULL) {
|
2014-01-18 16:30:00 +01:00
|
|
|
f = d->root;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
|
|
|
|
if (f == NULL) {
|
|
|
|
d->root = n;
|
2016-03-26 11:47:17 +01:00
|
|
|
} else if (IS_RECEPTACLE(f) && f->presel == NULL) {
|
|
|
|
node_t *p = f->parent;
|
|
|
|
if (p != NULL) {
|
|
|
|
if (is_first_child(f)) {
|
|
|
|
p->first_child = n;
|
|
|
|
} else {
|
|
|
|
p->second_child = n;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
d->root = n;
|
|
|
|
}
|
|
|
|
n->parent = p;
|
|
|
|
free(f);
|
2016-04-11 18:13:05 +02:00
|
|
|
f = NULL;
|
2014-01-18 16:30:00 +01:00
|
|
|
} else {
|
2015-12-22 19:25:45 +01:00
|
|
|
node_t *c = make_node(XCB_NONE);
|
2014-01-18 16:30:00 +01:00
|
|
|
node_t *p = f->parent;
|
2015-12-22 19:25:45 +01:00
|
|
|
if (f->presel == NULL && (f->private || private_count(f->parent) > 0)) {
|
|
|
|
node_t *k = find_public(d);
|
|
|
|
if (k != NULL) {
|
|
|
|
f = k;
|
2014-01-18 16:30:00 +01:00
|
|
|
p = f->parent;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
if (f->presel == NULL && (f->private || private_count(f->parent) > 0)) {
|
2016-02-12 22:49:06 +01:00
|
|
|
xcb_rectangle_t rect = get_rectangle(d, f);
|
2015-12-22 19:25:45 +01:00
|
|
|
presel_dir(m, d, f, (rect.width >= rect.height ? DIR_EAST : DIR_SOUTH));
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
if (f->presel == NULL && p != NULL && p->vacant) {
|
2015-01-13 17:43:09 +01:00
|
|
|
f = p;
|
|
|
|
p = f->parent;
|
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
n->parent = c;
|
|
|
|
c->birth_rotation = f->birth_rotation;
|
2015-12-22 19:25:45 +01:00
|
|
|
if (f->presel == NULL) {
|
|
|
|
if (p == NULL) {
|
|
|
|
if (initial_polarity == FIRST_CHILD) {
|
|
|
|
c->first_child = n;
|
|
|
|
c->second_child = f;
|
|
|
|
} else {
|
|
|
|
c->first_child = f;
|
|
|
|
c->second_child = n;
|
|
|
|
}
|
|
|
|
if (m->rectangle.width > m->rectangle.height) {
|
|
|
|
c->split_type = TYPE_VERTICAL;
|
|
|
|
} else {
|
|
|
|
c->split_type = TYPE_HORIZONTAL;
|
|
|
|
}
|
|
|
|
f->parent = c;
|
|
|
|
d->root = c;
|
|
|
|
} else {
|
|
|
|
node_t *g = p->parent;
|
|
|
|
c->parent = g;
|
|
|
|
if (g != NULL) {
|
|
|
|
if (is_first_child(p)) {
|
|
|
|
g->first_child = c;
|
2015-01-06 20:10:09 +01:00
|
|
|
} else {
|
2015-12-22 19:25:45 +01:00
|
|
|
g->second_child = c;
|
2015-01-06 20:10:09 +01:00
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
} else {
|
2014-01-18 16:30:00 +01:00
|
|
|
d->root = c;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
c->split_type = p->split_type;
|
|
|
|
c->split_ratio = p->split_ratio;
|
|
|
|
p->parent = c;
|
|
|
|
int rot;
|
|
|
|
if (is_first_child(f)) {
|
|
|
|
c->first_child = n;
|
|
|
|
c->second_child = p;
|
|
|
|
rot = 90;
|
2014-01-18 16:30:00 +01:00
|
|
|
} else {
|
2015-12-22 19:25:45 +01:00
|
|
|
c->first_child = p;
|
|
|
|
c->second_child = n;
|
|
|
|
rot = 270;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
n->birth_rotation = rot;
|
|
|
|
if (!n->vacant) {
|
|
|
|
rotate_tree(p, rot);
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (p != NULL) {
|
|
|
|
if (is_first_child(f)) {
|
|
|
|
p->first_child = c;
|
|
|
|
} else {
|
|
|
|
p->second_child = c;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
c->split_ratio = f->presel->split_ratio;
|
|
|
|
c->parent = p;
|
|
|
|
f->parent = c;
|
|
|
|
f->birth_rotation = 0;
|
|
|
|
switch (f->presel->split_dir) {
|
|
|
|
case DIR_WEST:
|
|
|
|
c->split_type = TYPE_VERTICAL;
|
|
|
|
c->first_child = n;
|
|
|
|
c->second_child = f;
|
|
|
|
break;
|
|
|
|
case DIR_EAST:
|
|
|
|
c->split_type = TYPE_VERTICAL;
|
|
|
|
c->first_child = f;
|
|
|
|
c->second_child = n;
|
|
|
|
break;
|
|
|
|
case DIR_NORTH:
|
|
|
|
c->split_type = TYPE_HORIZONTAL;
|
|
|
|
c->first_child = n;
|
|
|
|
c->second_child = f;
|
|
|
|
break;
|
|
|
|
case DIR_SOUTH:
|
|
|
|
c->split_type = TYPE_HORIZONTAL;
|
|
|
|
c->first_child = f;
|
|
|
|
c->second_child = n;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (d->root == f) {
|
|
|
|
d->root = c;
|
|
|
|
}
|
|
|
|
cancel_presel(m, d, f);
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
|
2016-04-16 18:13:31 +02:00
|
|
|
propagate_flags_upward(m, d, n);
|
|
|
|
|
|
|
|
if (d->focus == NULL && is_focusable(n)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
d->focus = n;
|
2015-11-01 14:05:18 +01:00
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
|
|
|
|
return f;
|
2013-09-20 11:57:09 +02:00
|
|
|
}
|
|
|
|
|
2016-03-26 11:47:17 +01:00
|
|
|
void insert_receptacle(monitor_t *m, desktop_t *d, node_t *n)
|
2013-09-20 11:57:09 +02:00
|
|
|
{
|
2016-03-26 11:47:17 +01:00
|
|
|
node_t *r = make_node(XCB_NONE);
|
|
|
|
insert_node(m, d, r, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool activate_node(monitor_t *m, desktop_t *d, node_t *n)
|
|
|
|
{
|
2016-04-16 18:13:31 +02:00
|
|
|
if (d == mon->desk || (n != NULL && !is_focusable(n))) {
|
2016-03-26 11:47:17 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
if (n == NULL && d->root != NULL) {
|
|
|
|
n = history_last_node(d, NULL);
|
|
|
|
if (n == NULL) {
|
2016-03-26 11:47:17 +01:00
|
|
|
n = first_focusable_leaf(d->root);
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
if (n != NULL) {
|
2015-12-22 19:25:45 +01:00
|
|
|
if (d->focus != NULL && n != d->focus) {
|
|
|
|
neutralize_occluding_windows(m, d, n);
|
2015-11-06 23:10:23 +01:00
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
stack(d, n, true);
|
2014-01-18 16:30:00 +01:00
|
|
|
if (d->focus != n) {
|
2015-12-22 19:25:45 +01:00
|
|
|
for (node_t *f = first_extrema(d->focus); f != NULL; f = next_leaf(f, d->focus)) {
|
2016-03-26 11:47:17 +01:00
|
|
|
if (f->client != NULL && !is_descendant(f, n)) {
|
2015-12-22 19:25:45 +01:00
|
|
|
window_draw_border(f->id, get_border_color(false, (m == mon)));
|
|
|
|
}
|
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
draw_border(n, true, (m == mon));
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
d->focus = n;
|
2016-03-26 11:47:17 +01:00
|
|
|
history_add(m, d, n);
|
2015-12-22 19:25:45 +01:00
|
|
|
|
|
|
|
put_status(SBSC_MASK_REPORT);
|
2016-03-16 15:15:27 +01:00
|
|
|
|
|
|
|
if (n == NULL) {
|
2016-03-26 11:47:17 +01:00
|
|
|
return true;
|
2016-03-16 15:15:27 +01:00
|
|
|
}
|
|
|
|
|
2016-03-23 11:24:47 +01:00
|
|
|
put_status(SBSC_MASK_NODE_ACTIVATE, "node_activate 0x%08X 0x%08X 0x%08X\n", m->id, d->id, n->id);
|
2016-03-26 11:47:17 +01:00
|
|
|
|
|
|
|
return true;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void transfer_sticky_nodes(monitor_t *m, desktop_t *ds, desktop_t *dd, node_t *n)
|
|
|
|
{
|
|
|
|
if (n == NULL) {
|
|
|
|
return;
|
|
|
|
} else if (n->sticky) {
|
|
|
|
transfer_node(m, ds, n, m, dd, dd->focus);
|
|
|
|
} else {
|
|
|
|
/* we need references to the children because n might be freed after
|
|
|
|
* the first recursive call */
|
|
|
|
node_t *first_child = n->first_child;
|
|
|
|
node_t *second_child = n->second_child;
|
|
|
|
transfer_sticky_nodes(m, ds, dd, first_child);
|
|
|
|
transfer_sticky_nodes(m, ds, dd, second_child);
|
|
|
|
}
|
2013-09-20 11:57:09 +02:00
|
|
|
}
|
|
|
|
|
2016-03-26 11:47:17 +01:00
|
|
|
bool focus_node(monitor_t *m, desktop_t *d, node_t *n)
|
2013-09-20 11:57:09 +02:00
|
|
|
{
|
2016-04-16 18:13:31 +02:00
|
|
|
if (n != NULL && !is_focusable(n)) {
|
2016-03-26 11:47:17 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
if (n == NULL && d->root != NULL) {
|
|
|
|
n = history_last_node(d, NULL);
|
|
|
|
if (n == NULL) {
|
2016-03-26 11:47:17 +01:00
|
|
|
n = first_focusable_leaf(d->root);
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mon->desk != d || n == NULL || n->client == NULL) {
|
2014-01-18 16:30:00 +01:00
|
|
|
clear_input_focus();
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
if (m->sticky_count > 0 && d != m->desk) {
|
2014-01-18 16:30:00 +01:00
|
|
|
sticky_still = false;
|
2015-12-22 19:25:45 +01:00
|
|
|
transfer_sticky_nodes(m, m->desk, d, m->desk->root);
|
2014-01-18 16:30:00 +01:00
|
|
|
sticky_still = true;
|
2015-12-22 19:25:45 +01:00
|
|
|
if (n == NULL && d->focus != NULL) {
|
2014-01-18 16:30:00 +01:00
|
|
|
n = d->focus;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
if (d->focus != NULL && n != d->focus) {
|
|
|
|
neutralize_occluding_windows(m, d, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n != NULL && n->client != NULL && n->client->urgent) {
|
|
|
|
set_urgent(m, d, n, false);
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mon != m) {
|
2015-12-22 19:25:45 +01:00
|
|
|
for (desktop_t *e = mon->desk_head; e != NULL; e = e->next) {
|
|
|
|
draw_border(e->focus, true, false);
|
2015-11-05 14:00:49 +01:00
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
for (desktop_t *e = m->desk_head; e != NULL; e = e->next) {
|
|
|
|
if (e == d) {
|
|
|
|
continue;
|
2015-11-05 14:00:49 +01:00
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
draw_border(e->focus, true, true);
|
2015-11-05 14:00:49 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (d->focus != n) {
|
2015-12-22 19:25:45 +01:00
|
|
|
for (node_t *f = first_extrema(d->focus); f != NULL; f = next_leaf(f, d->focus)) {
|
2016-03-26 11:47:17 +01:00
|
|
|
if (f->client != NULL && !is_descendant(f, n)) {
|
2015-12-22 19:25:45 +01:00
|
|
|
window_draw_border(f->id, get_border_color(false, true));
|
|
|
|
}
|
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
draw_border(n, true, true);
|
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
focus_desktop(m, d);
|
|
|
|
|
|
|
|
d->focus = n;
|
2015-12-22 19:25:45 +01:00
|
|
|
ewmh_update_active_window();
|
|
|
|
history_add(m, d, n);
|
|
|
|
|
|
|
|
put_status(SBSC_MASK_REPORT);
|
2014-01-18 16:30:00 +01:00
|
|
|
|
|
|
|
if (n == NULL) {
|
2016-03-26 11:47:17 +01:00
|
|
|
return true;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
|
2016-03-23 11:24:47 +01:00
|
|
|
put_status(SBSC_MASK_NODE_FOCUS, "node_focus 0x%08X 0x%08X 0x%08X\n", m->id, d->id, n->id);
|
2014-01-18 16:30:00 +01:00
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
stack(d, n, true);
|
2014-01-18 16:30:00 +01:00
|
|
|
set_input_focus(n);
|
|
|
|
|
2014-10-22 11:24:51 +02:00
|
|
|
if (pointer_follows_focus) {
|
2016-02-12 22:49:06 +01:00
|
|
|
center_pointer(get_rectangle(d, n));
|
2014-10-22 11:24:51 +02:00
|
|
|
}
|
2016-03-26 11:47:17 +01:00
|
|
|
|
|
|
|
return true;
|
2013-09-20 11:57:09 +02:00
|
|
|
}
|
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
void update_focused(void)
|
2013-09-20 11:57:09 +02:00
|
|
|
{
|
2014-01-18 16:30:00 +01:00
|
|
|
focus_node(mon, mon->desk, mon->desk->focus);
|
2013-09-20 11:57:09 +02:00
|
|
|
}
|
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
void hide_node(node_t *n)
|
2013-09-19 15:02:49 +02:00
|
|
|
{
|
2015-12-22 19:25:45 +01:00
|
|
|
if (n == NULL) {
|
|
|
|
return;
|
|
|
|
} else {
|
2016-04-16 18:13:31 +02:00
|
|
|
if (!n->hidden) {
|
|
|
|
if (n->presel != NULL) {
|
|
|
|
window_hide(n->presel->feedback);
|
|
|
|
}
|
|
|
|
if (n->client != NULL) {
|
|
|
|
window_hide(n->id);
|
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
if (n->client != NULL) {
|
2016-04-16 18:13:31 +02:00
|
|
|
n->client->shown = false;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
hide_node(n->first_child);
|
|
|
|
hide_node(n->second_child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void show_node(node_t *n)
|
|
|
|
{
|
|
|
|
if (n == NULL) {
|
|
|
|
return;
|
|
|
|
} else {
|
2016-04-16 18:13:31 +02:00
|
|
|
if (!n->hidden) {
|
|
|
|
if (n->client != NULL) {
|
|
|
|
window_show(n->id);
|
|
|
|
}
|
|
|
|
if (n->presel != NULL) {
|
|
|
|
window_show(n->presel->feedback);
|
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2016-04-16 18:13:31 +02:00
|
|
|
if (n->client != NULL) {
|
|
|
|
n->client->shown = true;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
show_node(n->first_child);
|
|
|
|
show_node(n->second_child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
node_t *make_node(uint32_t id)
|
|
|
|
{
|
|
|
|
if (id == XCB_NONE) {
|
|
|
|
id = xcb_generate_id(dpy);
|
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
node_t *n = malloc(sizeof(node_t));
|
2015-12-22 19:25:45 +01:00
|
|
|
n->id = id;
|
2014-01-18 16:30:00 +01:00
|
|
|
n->parent = n->first_child = n->second_child = NULL;
|
2016-04-16 18:13:31 +02:00
|
|
|
n->vacant = n->hidden = n->sticky = n->private = n->locked = false;
|
2014-01-18 16:30:00 +01:00
|
|
|
n->split_ratio = split_ratio;
|
|
|
|
n->split_type = TYPE_VERTICAL;
|
|
|
|
n->birth_rotation = 0;
|
2015-12-22 19:25:45 +01:00
|
|
|
n->presel = NULL;
|
2014-01-18 16:30:00 +01:00
|
|
|
n->client = NULL;
|
|
|
|
return n;
|
2013-09-19 15:02:49 +02:00
|
|
|
}
|
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
client_t *make_client(void)
|
2013-09-19 15:02:49 +02:00
|
|
|
{
|
2016-04-16 18:13:31 +02:00
|
|
|
client_t *c = malloc(sizeof(client_t));
|
2015-11-05 14:00:49 +01:00
|
|
|
c->state = c->last_state = STATE_TILED;
|
2015-11-03 09:42:09 +01:00
|
|
|
c->layer = c->last_layer = LAYER_NORMAL;
|
2014-01-18 16:30:00 +01:00
|
|
|
snprintf(c->class_name, sizeof(c->class_name), "%s", MISSING_VALUE);
|
|
|
|
snprintf(c->instance_name, sizeof(c->instance_name), "%s", MISSING_VALUE);
|
2014-02-09 14:47:27 +01:00
|
|
|
c->border_width = border_width;
|
2016-04-16 18:13:31 +02:00
|
|
|
c->wm_flags = 0;
|
2016-04-10 14:34:24 +02:00
|
|
|
c->icccm_props.input_hint = true;
|
2016-04-16 18:13:31 +02:00
|
|
|
c->icccm_props.take_focus = false;
|
|
|
|
c->size_hints.flags = 0;
|
2015-12-22 19:25:45 +01:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
void initialize_client(node_t *n)
|
|
|
|
{
|
|
|
|
xcb_window_t win = n->id;
|
2016-04-07 18:08:32 +02:00
|
|
|
client_t *c = n->client;
|
|
|
|
xcb_icccm_get_wm_protocols_reply_t protos;
|
|
|
|
if (xcb_icccm_get_wm_protocols_reply(dpy, xcb_icccm_get_wm_protocols(dpy, win, ewmh->WM_PROTOCOLS), &protos, NULL) == 1) {
|
|
|
|
if (has_proto(WM_TAKE_FOCUS, &protos)) {
|
|
|
|
c->icccm_props.take_focus = true;
|
|
|
|
}
|
|
|
|
xcb_icccm_get_wm_protocols_reply_wipe(&protos);
|
|
|
|
}
|
|
|
|
xcb_ewmh_get_atoms_reply_t wm_state;
|
|
|
|
if (xcb_ewmh_get_wm_state_reply(ewmh, xcb_ewmh_get_wm_state(ewmh, win), &wm_state, NULL) == 1) {
|
|
|
|
for (unsigned int i = 0; i < wm_state.atoms_len && i < MAX_WM_STATES; i++) {
|
|
|
|
#define HANDLE_WM_STATE(s) \
|
|
|
|
if (wm_state.atoms[i] == ewmh->_NET_WM_STATE_##s) { \
|
|
|
|
c->wm_flags |= WM_FLAG_##s; continue; \
|
2015-11-22 14:41:00 +01:00
|
|
|
}
|
2016-04-07 18:08:32 +02:00
|
|
|
HANDLE_WM_STATE(MODAL)
|
|
|
|
HANDLE_WM_STATE(STICKY)
|
|
|
|
HANDLE_WM_STATE(MAXIMIZED_VERT)
|
|
|
|
HANDLE_WM_STATE(MAXIMIZED_HORZ)
|
|
|
|
HANDLE_WM_STATE(SHADED)
|
|
|
|
HANDLE_WM_STATE(SKIP_TASKBAR)
|
|
|
|
HANDLE_WM_STATE(SKIP_PAGER)
|
|
|
|
HANDLE_WM_STATE(HIDDEN)
|
|
|
|
HANDLE_WM_STATE(FULLSCREEN)
|
|
|
|
HANDLE_WM_STATE(ABOVE)
|
|
|
|
HANDLE_WM_STATE(BELOW)
|
|
|
|
HANDLE_WM_STATE(DEMANDS_ATTENTION)
|
|
|
|
#undef HANDLE_WM_STATE
|
|
|
|
}
|
|
|
|
xcb_ewmh_get_atoms_reply_wipe(&wm_state);
|
|
|
|
}
|
|
|
|
xcb_icccm_wm_hints_t hints;
|
|
|
|
if (xcb_icccm_get_wm_hints_reply(dpy, xcb_icccm_get_wm_hints(dpy, win), &hints, NULL) == 1
|
|
|
|
&& (hints.flags & XCB_ICCCM_WM_HINT_INPUT)) {
|
|
|
|
c->icccm_props.input_hint = hints.input;
|
|
|
|
}
|
|
|
|
xcb_icccm_get_wm_normal_hints_reply(dpy, xcb_icccm_get_wm_normal_hints(dpy, win), &c->size_hints, NULL);
|
2013-09-19 15:02:49 +02:00
|
|
|
}
|
|
|
|
|
2016-04-16 18:13:31 +02:00
|
|
|
bool is_focusable(node_t *n)
|
|
|
|
{
|
|
|
|
for (node_t *f = first_extrema(n); f != NULL; f = next_leaf(f, n)) {
|
|
|
|
if (f->client != NULL && !f->hidden) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-29 18:37:31 +02:00
|
|
|
bool is_leaf(node_t *n)
|
2012-08-19 10:34:08 +02:00
|
|
|
{
|
2014-01-18 16:30:00 +01:00
|
|
|
return (n != NULL && n->first_child == NULL && n->second_child == NULL);
|
2012-08-19 10:34:08 +02:00
|
|
|
}
|
2012-09-01 21:55:35 +02:00
|
|
|
|
|
|
|
bool is_first_child(node_t *n)
|
|
|
|
{
|
2014-01-18 16:30:00 +01:00
|
|
|
return (n != NULL && n->parent != NULL && n->parent->first_child == n);
|
2012-09-01 21:55:35 +02:00
|
|
|
}
|
|
|
|
|
2012-09-04 11:14:01 +02:00
|
|
|
bool is_second_child(node_t *n)
|
|
|
|
{
|
2014-01-18 16:30:00 +01:00
|
|
|
return (n != NULL && n->parent != NULL && n->parent->second_child == n);
|
2012-09-04 11:14:01 +02:00
|
|
|
}
|
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
unsigned int clients_count_in(node_t *n)
|
2013-06-27 19:25:55 +02:00
|
|
|
{
|
2015-12-22 19:25:45 +01:00
|
|
|
if (n == NULL) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return (n->client != NULL ? 1 : 0) +
|
|
|
|
clients_count_in(n->first_child) +
|
|
|
|
clients_count_in(n->second_child);
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
2013-06-27 19:25:55 +02:00
|
|
|
}
|
|
|
|
|
2013-08-27 23:48:50 +02:00
|
|
|
node_t *brother_tree(node_t *n)
|
|
|
|
{
|
2015-12-22 19:25:45 +01:00
|
|
|
if (n == NULL || n->parent == NULL) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return NULL;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
if (is_first_child(n)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return n->parent->second_child;
|
2015-12-22 19:25:45 +01:00
|
|
|
} else {
|
2014-01-18 16:30:00 +01:00
|
|
|
return n->parent->first_child;
|
|
|
|
}
|
2013-10-12 21:16:51 +02:00
|
|
|
}
|
|
|
|
|
2012-08-29 18:37:31 +02:00
|
|
|
node_t *first_extrema(node_t *n)
|
2012-08-17 22:18:26 +02:00
|
|
|
{
|
2015-12-22 19:25:45 +01:00
|
|
|
if (n == NULL) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return NULL;
|
2015-12-22 19:25:45 +01:00
|
|
|
} else if (n->first_child == NULL) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return n;
|
2015-12-22 19:25:45 +01:00
|
|
|
} else {
|
2014-01-18 16:30:00 +01:00
|
|
|
return first_extrema(n->first_child);
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2012-08-17 22:18:26 +02:00
|
|
|
}
|
|
|
|
|
2012-08-29 18:37:31 +02:00
|
|
|
node_t *second_extrema(node_t *n)
|
2012-08-17 22:18:26 +02:00
|
|
|
{
|
2015-12-22 19:25:45 +01:00
|
|
|
if (n == NULL) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return NULL;
|
2015-12-22 19:25:45 +01:00
|
|
|
} else if (n->second_child == NULL) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return n;
|
2015-12-22 19:25:45 +01:00
|
|
|
} else {
|
2014-01-18 16:30:00 +01:00
|
|
|
return second_extrema(n->second_child);
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2012-08-17 22:18:26 +02:00
|
|
|
}
|
|
|
|
|
2016-03-26 11:47:17 +01:00
|
|
|
node_t *first_focusable_leaf(node_t *n)
|
|
|
|
{
|
|
|
|
for (node_t *f = first_extrema(n); f != NULL; f = next_leaf(f, n)) {
|
2016-04-16 18:13:31 +02:00
|
|
|
if (f->client != NULL && !f->hidden) {
|
2016-03-26 11:47:17 +01:00
|
|
|
return f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-05-07 22:45:14 +02:00
|
|
|
node_t *next_leaf(node_t *n, node_t *r)
|
2012-09-04 11:14:01 +02:00
|
|
|
{
|
2015-11-22 14:41:00 +01:00
|
|
|
if (n == NULL) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return NULL;
|
2015-11-22 14:41:00 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
node_t *p = n;
|
2015-11-22 14:41:00 +01:00
|
|
|
while (is_second_child(p) && p != r) {
|
2014-01-18 16:30:00 +01:00
|
|
|
p = p->parent;
|
2015-11-22 14:41:00 +01:00
|
|
|
}
|
|
|
|
if (p == r) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return NULL;
|
2015-11-22 14:41:00 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
return first_extrema(p->parent->second_child);
|
2012-09-04 11:14:01 +02:00
|
|
|
}
|
|
|
|
|
2013-05-07 22:45:14 +02:00
|
|
|
node_t *prev_leaf(node_t *n, node_t *r)
|
2012-09-04 11:14:01 +02:00
|
|
|
{
|
2015-12-22 19:25:45 +01:00
|
|
|
if (n == NULL) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return NULL;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
node_t *p = n;
|
2015-12-22 19:25:45 +01:00
|
|
|
while (is_first_child(p) && p != r) {
|
2014-01-18 16:30:00 +01:00
|
|
|
p = p->parent;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
if (p == r) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return NULL;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
return second_extrema(p->parent->first_child);
|
2012-09-04 11:14:01 +02:00
|
|
|
}
|
|
|
|
|
2016-03-26 11:47:17 +01:00
|
|
|
node_t *next_tiled_leaf(node_t *n, node_t *r)
|
2013-10-06 10:42:13 +02:00
|
|
|
{
|
2014-01-18 16:30:00 +01:00
|
|
|
node_t *next = next_leaf(n, r);
|
2016-04-16 18:13:31 +02:00
|
|
|
if (next == NULL || (next->client != NULL && !next->vacant)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return next;
|
2015-12-22 19:25:45 +01:00
|
|
|
} else {
|
2016-03-26 11:47:17 +01:00
|
|
|
return next_tiled_leaf(next, r);
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2013-10-06 10:42:13 +02:00
|
|
|
}
|
|
|
|
|
2016-03-26 11:47:17 +01:00
|
|
|
node_t *prev_tiled_leaf(node_t *n, node_t *r)
|
2013-10-06 10:42:13 +02:00
|
|
|
{
|
2014-01-18 16:30:00 +01:00
|
|
|
node_t *prev = prev_leaf(n, r);
|
2016-04-16 18:13:31 +02:00
|
|
|
if (prev == NULL || (prev->client != NULL && !prev->vacant)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return prev;
|
2015-12-22 19:25:45 +01:00
|
|
|
} else {
|
2016-03-26 11:47:17 +01:00
|
|
|
return prev_tiled_leaf(prev, r);
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2013-10-06 10:42:13 +02:00
|
|
|
}
|
|
|
|
|
2013-07-08 11:42:05 +02:00
|
|
|
/* Returns true if *b* is adjacent to *a* in the direction *dir* */
|
|
|
|
bool is_adjacent(node_t *a, node_t *b, direction_t dir)
|
2013-06-24 16:25:50 +02:00
|
|
|
{
|
2014-01-18 16:30:00 +01:00
|
|
|
switch (dir) {
|
2015-12-22 19:25:45 +01:00
|
|
|
case DIR_EAST:
|
2014-01-18 16:30:00 +01:00
|
|
|
return (a->rectangle.x + a->rectangle.width) == b->rectangle.x;
|
|
|
|
break;
|
2015-12-22 19:25:45 +01:00
|
|
|
case DIR_SOUTH:
|
2014-01-18 16:30:00 +01:00
|
|
|
return (a->rectangle.y + a->rectangle.height) == b->rectangle.y;
|
|
|
|
break;
|
2015-12-22 19:25:45 +01:00
|
|
|
case DIR_WEST:
|
2014-01-18 16:30:00 +01:00
|
|
|
return (b->rectangle.x + b->rectangle.width) == a->rectangle.x;
|
|
|
|
break;
|
2015-12-22 19:25:45 +01:00
|
|
|
case DIR_NORTH:
|
2014-01-18 16:30:00 +01:00
|
|
|
return (b->rectangle.y + b->rectangle.height) == a->rectangle.y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
2013-06-24 16:25:50 +02:00
|
|
|
}
|
|
|
|
|
2012-08-29 18:37:31 +02:00
|
|
|
node_t *find_fence(node_t *n, direction_t dir)
|
2012-08-17 22:18:26 +02:00
|
|
|
{
|
2014-01-18 16:30:00 +01:00
|
|
|
node_t *p;
|
2012-08-18 14:55:16 +02:00
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
if (n == NULL) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return NULL;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2012-08-18 14:55:16 +02:00
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
p = n->parent;
|
2012-08-20 12:20:12 +02:00
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
while (p != NULL) {
|
2015-12-22 19:25:45 +01:00
|
|
|
if ((dir == DIR_NORTH && p->split_type == TYPE_HORIZONTAL && p->rectangle.y < n->rectangle.y) ||
|
|
|
|
(dir == DIR_WEST && p->split_type == TYPE_VERTICAL && p->rectangle.x < n->rectangle.x) ||
|
|
|
|
(dir == DIR_SOUTH && p->split_type == TYPE_HORIZONTAL && (p->rectangle.y + p->rectangle.height) > (n->rectangle.y + n->rectangle.height)) ||
|
|
|
|
(dir == DIR_EAST && p->split_type == TYPE_VERTICAL && (p->rectangle.x + p->rectangle.width) > (n->rectangle.x + n->rectangle.width)))
|
2014-01-18 16:30:00 +01:00
|
|
|
return p;
|
|
|
|
p = p->parent;
|
|
|
|
}
|
2012-08-18 22:36:46 +02:00
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
return NULL;
|
2012-08-18 22:36:46 +02:00
|
|
|
}
|
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
node_t *nearest_neighbor(monitor_t *m, desktop_t *d, node_t *n, direction_t dir, node_select_t sel)
|
2013-06-25 12:41:59 +02:00
|
|
|
{
|
2015-12-22 19:25:45 +01:00
|
|
|
if (n == NULL || (n->client != NULL && IS_FULLSCREEN(n->client)) ||
|
|
|
|
(d->layout == LAYOUT_MONOCLE && (n->client != NULL && IS_TILED(n->client)))) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return NULL;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
|
|
|
|
node_t *nearest = NULL;
|
2015-12-22 19:25:45 +01:00
|
|
|
if (history_aware_focus) {
|
2014-01-18 16:30:00 +01:00
|
|
|
nearest = nearest_from_history(m, d, n, dir, sel);
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2016-04-11 06:07:48 +10:00
|
|
|
if (nearest == NULL) {
|
|
|
|
if (focus_by_distance) {
|
|
|
|
nearest = nearest_from_distance(m, d, n, dir, sel);
|
|
|
|
} else {
|
|
|
|
nearest = nearest_from_tree(m, d, n, dir, sel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nearest;
|
2014-07-18 19:21:58 +02:00
|
|
|
}
|
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
/* returns *true* if *a* is a child of *b* */
|
|
|
|
bool is_child(node_t *a, node_t *b)
|
|
|
|
{
|
|
|
|
if (a == NULL || b == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return (a->parent != NULL && a->parent == b);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* returns *true* if *a* is a descendant of *b* */
|
|
|
|
bool is_descendant(node_t *a, node_t *b)
|
|
|
|
{
|
|
|
|
if (a == NULL || b == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
while (a != b && a != NULL) {
|
|
|
|
a = a->parent;
|
|
|
|
}
|
|
|
|
return a == b;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool find_by_id(uint32_t id, coordinates_t *loc)
|
|
|
|
{
|
|
|
|
for (monitor_t *m = mon_head; m != NULL; m = m->next) {
|
|
|
|
for (desktop_t *d = m->desk_head; d != NULL; d = d->next) {
|
|
|
|
node_t *n = find_by_id_in(d->root, id);
|
|
|
|
if (n != NULL) {
|
|
|
|
loc->monitor = m;
|
|
|
|
loc->desktop = d;
|
|
|
|
loc->node = n;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
node_t *find_by_id_in(node_t *r, uint32_t id)
|
|
|
|
{
|
|
|
|
if (r == NULL) {
|
|
|
|
return NULL;
|
|
|
|
} else if (r->id == id) {
|
|
|
|
return r;
|
|
|
|
} else {
|
|
|
|
node_t *f = find_by_id_in(r->first_child, id);
|
|
|
|
if (f != NULL) {
|
|
|
|
return f;
|
|
|
|
} else {
|
|
|
|
return find_by_id_in(r->second_child, id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
node_t *nearest_from_tree(monitor_t *m, desktop_t *d, node_t *n, direction_t dir, node_select_t sel)
|
2014-07-18 19:21:58 +02:00
|
|
|
{
|
2016-04-11 06:07:48 +10:00
|
|
|
if (n == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-07-18 19:21:58 +02:00
|
|
|
|
2016-04-11 06:07:48 +10:00
|
|
|
node_t *fence = find_fence(n, dir);
|
2014-07-18 19:21:58 +02:00
|
|
|
|
2016-04-11 06:07:48 +10:00
|
|
|
if (fence == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-07-18 19:21:58 +02:00
|
|
|
|
2016-04-11 06:07:48 +10:00
|
|
|
node_t *nearest = NULL;
|
2014-07-18 19:21:58 +02:00
|
|
|
|
2016-04-11 06:07:48 +10:00
|
|
|
if (dir == DIR_NORTH || dir == DIR_WEST) {
|
|
|
|
nearest = second_extrema(fence->first_child);
|
|
|
|
} else if (dir == DIR_SOUTH || dir == DIR_EAST) {
|
|
|
|
nearest = first_extrema(fence->second_child);
|
|
|
|
}
|
2014-07-18 19:21:58 +02:00
|
|
|
|
2014-07-28 11:45:00 +02:00
|
|
|
coordinates_t ref = {m, d, n};
|
|
|
|
coordinates_t loc = {m, d, nearest};
|
|
|
|
|
2016-03-26 11:47:17 +01:00
|
|
|
if (nearest != NULL && (nearest->vacant ||
|
|
|
|
nearest->client == NULL || !node_matches(&loc, &ref, sel))) {
|
2014-07-28 11:45:00 +02:00
|
|
|
return NULL;
|
2015-11-05 14:00:49 +01:00
|
|
|
}
|
2016-03-26 11:47:17 +01:00
|
|
|
|
|
|
|
return nearest;
|
2012-08-17 22:18:26 +02:00
|
|
|
}
|
2012-08-18 12:19:58 +02:00
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
node_t *nearest_from_history(monitor_t *m, desktop_t *d, node_t *n, direction_t dir, node_select_t sel)
|
2013-05-07 22:45:14 +02:00
|
|
|
{
|
2015-12-22 19:25:45 +01:00
|
|
|
if (n == NULL || (n->client != NULL && !IS_TILED(n->client))) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return NULL;
|
2015-11-05 14:00:49 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
|
|
|
|
node_t *target = find_fence(n, dir);
|
2015-12-22 19:25:45 +01:00
|
|
|
if (target == NULL) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return NULL;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
if (dir == DIR_NORTH || dir == DIR_WEST) {
|
2014-01-18 16:30:00 +01:00
|
|
|
target = target->first_child;
|
2015-12-22 19:25:45 +01:00
|
|
|
} else if (dir == DIR_SOUTH || dir == DIR_EAST) {
|
2014-01-18 16:30:00 +01:00
|
|
|
target = target->second_child;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
|
|
|
|
node_t *nearest = NULL;
|
|
|
|
int min_rank = INT_MAX;
|
|
|
|
coordinates_t ref = {m, d, n};
|
|
|
|
|
|
|
|
for (node_t *a = first_extrema(target); a != NULL; a = next_leaf(a, target)) {
|
2016-03-26 11:47:17 +01:00
|
|
|
if (a->vacant || a->client == NULL || !is_adjacent(n, a, dir) || a == n) {
|
2014-01-18 16:30:00 +01:00
|
|
|
continue;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
coordinates_t loc = {m, d, a};
|
2015-12-22 19:25:45 +01:00
|
|
|
if (!node_matches(&loc, &ref, sel)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
continue;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
int rank = history_rank(d, a);
|
|
|
|
if (rank >= 0 && rank < min_rank) {
|
|
|
|
nearest = a;
|
|
|
|
min_rank = rank;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nearest;
|
2013-05-07 22:45:14 +02:00
|
|
|
}
|
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
node_t *nearest_from_distance(monitor_t *m, desktop_t *d, node_t *n, direction_t dir, node_select_t sel)
|
2013-05-07 22:45:14 +02:00
|
|
|
{
|
2015-12-22 19:25:45 +01:00
|
|
|
if (n == NULL) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return NULL;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
|
|
|
|
node_t *target = NULL;
|
|
|
|
|
2016-01-07 10:18:32 +01:00
|
|
|
if (n->client == NULL || IS_TILED(n->client)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
target = find_fence(n, dir);
|
2015-12-22 19:25:45 +01:00
|
|
|
if (target == NULL) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return NULL;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
if (dir == DIR_NORTH || dir == DIR_WEST) {
|
2014-01-18 16:30:00 +01:00
|
|
|
target = target->first_child;
|
2015-12-22 19:25:45 +01:00
|
|
|
} else if (dir == DIR_SOUTH || dir == DIR_EAST) {
|
2014-01-18 16:30:00 +01:00
|
|
|
target = target->second_child;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
} else {
|
|
|
|
target = d->root;
|
|
|
|
}
|
|
|
|
|
|
|
|
node_t *nearest = NULL;
|
2016-02-26 22:08:59 +01:00
|
|
|
direction_t dir2 = DIR_NORTH;
|
2014-01-18 16:30:00 +01:00
|
|
|
xcb_point_t pt;
|
|
|
|
xcb_point_t pt2;
|
2016-02-12 22:49:06 +01:00
|
|
|
get_side_handle(d, n, dir, &pt);
|
2014-01-18 16:30:00 +01:00
|
|
|
get_opposite(dir, &dir2);
|
|
|
|
double ds = DBL_MAX;
|
|
|
|
coordinates_t ref = {m, d, n};
|
|
|
|
|
|
|
|
for (node_t *a = first_extrema(target); a != NULL; a = next_leaf(a, target)) {
|
|
|
|
coordinates_t loc = {m, d, a};
|
|
|
|
if (a == n ||
|
2016-03-26 11:47:17 +01:00
|
|
|
a->client == NULL ||
|
2016-04-16 18:13:31 +02:00
|
|
|
a->hidden ||
|
2014-01-18 16:30:00 +01:00
|
|
|
!node_matches(&loc, &ref, sel) ||
|
2016-01-07 10:18:32 +01:00
|
|
|
(n->client != NULL && (IS_TILED(a->client) != IS_TILED(n->client))) ||
|
2015-12-22 19:25:45 +01:00
|
|
|
(IS_TILED(a->client) && !is_adjacent(n, a, dir))) {
|
2014-01-18 16:30:00 +01:00
|
|
|
continue;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2016-02-12 22:49:06 +01:00
|
|
|
get_side_handle(d, a, dir2, &pt2);
|
2014-01-18 16:30:00 +01:00
|
|
|
double ds2 = distance(pt, pt2);
|
|
|
|
if (ds2 < ds) {
|
|
|
|
ds = ds2;
|
|
|
|
nearest = a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nearest;
|
2013-05-07 22:45:14 +02:00
|
|
|
}
|
|
|
|
|
2013-06-24 16:25:50 +02:00
|
|
|
void get_opposite(direction_t src, direction_t *dst)
|
|
|
|
{
|
2014-01-18 16:30:00 +01:00
|
|
|
switch (src) {
|
2015-12-22 19:25:45 +01:00
|
|
|
case DIR_EAST:
|
|
|
|
*dst = DIR_WEST;
|
2014-01-18 16:30:00 +01:00
|
|
|
break;
|
2015-12-22 19:25:45 +01:00
|
|
|
case DIR_SOUTH:
|
|
|
|
*dst = DIR_NORTH;
|
2014-01-18 16:30:00 +01:00
|
|
|
break;
|
2015-12-22 19:25:45 +01:00
|
|
|
case DIR_WEST:
|
|
|
|
*dst = DIR_EAST;
|
2014-01-18 16:30:00 +01:00
|
|
|
break;
|
2015-12-22 19:25:45 +01:00
|
|
|
case DIR_NORTH:
|
|
|
|
*dst = DIR_SOUTH;
|
2014-01-18 16:30:00 +01:00
|
|
|
break;
|
|
|
|
}
|
2013-06-24 16:25:50 +02:00
|
|
|
}
|
|
|
|
|
2016-02-12 22:49:06 +01:00
|
|
|
unsigned int node_area(desktop_t *d, node_t *n)
|
2013-04-02 15:02:45 +02:00
|
|
|
{
|
2015-12-22 19:25:45 +01:00
|
|
|
if (n == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
2016-02-26 14:22:03 +01:00
|
|
|
return area(get_rectangle(d, n));
|
2013-04-02 15:02:45 +02:00
|
|
|
}
|
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
int tiled_count(node_t *n)
|
2015-08-07 08:47:24 +02:00
|
|
|
{
|
2015-12-22 19:25:45 +01:00
|
|
|
if (n == NULL) {
|
|
|
|
return 0;
|
|
|
|
}
|
2015-08-07 08:47:24 +02:00
|
|
|
int cnt = 0;
|
2015-12-22 19:25:45 +01:00
|
|
|
for (node_t *f = first_extrema(n); f != NULL; f = next_leaf(f, n)) {
|
2016-03-26 11:47:17 +01:00
|
|
|
if (f->client != NULL && IS_TILED(f->client)) {
|
2015-08-07 08:47:24 +02:00
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
node_t *find_biggest(monitor_t *m, desktop_t *d, node_t *n, node_select_t sel)
|
2013-04-02 15:02:45 +02:00
|
|
|
{
|
2015-12-22 19:25:45 +01:00
|
|
|
if (d == NULL) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return NULL;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
node_t *b = NULL;
|
|
|
|
unsigned int b_area = 0;
|
2014-01-18 16:30:00 +01:00
|
|
|
coordinates_t ref = {m, d, n};
|
|
|
|
|
|
|
|
for (node_t *f = first_extrema(d->root); f != NULL; f = next_leaf(f, d->root)) {
|
|
|
|
coordinates_t loc = {m, d, f};
|
2016-03-26 11:47:17 +01:00
|
|
|
if (f->client == NULL || f->vacant || !node_matches(&loc, &ref, sel)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
continue;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2016-02-12 22:49:06 +01:00
|
|
|
unsigned int f_area = node_area(d, f);
|
2015-12-22 19:25:45 +01:00
|
|
|
if (f_area > b_area) {
|
|
|
|
b = f;
|
|
|
|
b_area = f_area;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
return b;
|
2012-09-05 14:07:06 +02:00
|
|
|
}
|
|
|
|
|
2013-09-20 11:57:09 +02:00
|
|
|
void rotate_tree(node_t *n, int deg)
|
2012-09-05 14:07:06 +02:00
|
|
|
{
|
2015-12-22 19:25:45 +01:00
|
|
|
if (n == NULL || is_leaf(n) || deg == 0) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
|
|
|
|
node_t *tmp;
|
|
|
|
|
|
|
|
if ((deg == 90 && n->split_type == TYPE_HORIZONTAL) ||
|
|
|
|
(deg == 270 && n->split_type == TYPE_VERTICAL) ||
|
|
|
|
deg == 180) {
|
|
|
|
tmp = n->first_child;
|
|
|
|
n->first_child = n->second_child;
|
|
|
|
n->second_child = tmp;
|
|
|
|
n->split_ratio = 1.0 - n->split_ratio;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (deg != 180) {
|
2015-12-22 19:25:45 +01:00
|
|
|
if (n->split_type == TYPE_HORIZONTAL) {
|
2014-01-18 16:30:00 +01:00
|
|
|
n->split_type = TYPE_VERTICAL;
|
2015-12-22 19:25:45 +01:00
|
|
|
} else if (n->split_type == TYPE_VERTICAL) {
|
2014-01-18 16:30:00 +01:00
|
|
|
n->split_type = TYPE_HORIZONTAL;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
rotate_tree(n->first_child, deg);
|
|
|
|
rotate_tree(n->second_child, deg);
|
2013-09-20 11:57:09 +02:00
|
|
|
}
|
2013-05-29 14:34:27 +02:00
|
|
|
|
2013-09-20 11:57:09 +02:00
|
|
|
void rotate_brother(node_t *n)
|
|
|
|
{
|
2014-01-18 16:30:00 +01:00
|
|
|
rotate_tree(brother_tree(n), n->birth_rotation);
|
2013-09-20 11:57:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void unrotate_tree(node_t *n, int rot)
|
|
|
|
{
|
2015-12-22 19:25:45 +01:00
|
|
|
if (rot == 0) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
rotate_tree(n, 360 - rot);
|
2013-09-20 11:57:09 +02:00
|
|
|
}
|
2013-05-29 14:34:27 +02:00
|
|
|
|
2013-09-20 11:57:09 +02:00
|
|
|
void unrotate_brother(node_t *n)
|
|
|
|
{
|
2014-01-18 16:30:00 +01:00
|
|
|
unrotate_tree(brother_tree(n), n->birth_rotation);
|
2013-09-20 11:57:09 +02:00
|
|
|
}
|
2013-05-29 14:34:27 +02:00
|
|
|
|
2013-09-20 11:57:09 +02:00
|
|
|
void flip_tree(node_t *n, flip_t flp)
|
|
|
|
{
|
2015-12-22 19:25:45 +01:00
|
|
|
if (n == NULL || is_leaf(n)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2013-05-29 14:34:27 +02:00
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
node_t *tmp;
|
2013-03-22 18:26:30 +01:00
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
if ((flp == FLIP_HORIZONTAL && n->split_type == TYPE_HORIZONTAL) ||
|
|
|
|
(flp == FLIP_VERTICAL && n->split_type == TYPE_VERTICAL)) {
|
|
|
|
tmp = n->first_child;
|
|
|
|
n->first_child = n->second_child;
|
|
|
|
n->second_child = tmp;
|
|
|
|
n->split_ratio = 1.0 - n->split_ratio;
|
|
|
|
}
|
2012-09-16 14:16:58 +02:00
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
flip_tree(n->first_child, flp);
|
|
|
|
flip_tree(n->second_child, flp);
|
2012-09-05 14:07:06 +02:00
|
|
|
}
|
2012-09-04 21:01:50 +02:00
|
|
|
|
2014-01-04 12:15:42 +01:00
|
|
|
void equalize_tree(node_t *n)
|
|
|
|
{
|
2014-01-18 16:30:00 +01:00
|
|
|
if (n == NULL || n->vacant) {
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
n->split_ratio = split_ratio;
|
|
|
|
equalize_tree(n->first_child);
|
|
|
|
equalize_tree(n->second_child);
|
|
|
|
}
|
2014-01-04 12:15:42 +01:00
|
|
|
}
|
|
|
|
|
2013-09-20 11:57:09 +02:00
|
|
|
int balance_tree(node_t *n)
|
2012-09-19 22:59:13 +02:00
|
|
|
{
|
2014-01-18 16:30:00 +01:00
|
|
|
if (n == NULL || n->vacant) {
|
|
|
|
return 0;
|
|
|
|
} else if (is_leaf(n)) {
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
int b1 = balance_tree(n->first_child);
|
|
|
|
int b2 = balance_tree(n->second_child);
|
|
|
|
int b = b1 + b2;
|
2015-12-22 19:25:45 +01:00
|
|
|
if (b1 > 0 && b2 > 0) {
|
2014-01-18 16:30:00 +01:00
|
|
|
n->split_ratio = (double) b1 / b;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
return b;
|
|
|
|
}
|
2012-09-19 22:59:13 +02:00
|
|
|
}
|
|
|
|
|
2013-10-06 16:58:02 +02:00
|
|
|
void unlink_node(monitor_t *m, desktop_t *d, node_t *n)
|
2012-09-05 18:37:54 +02:00
|
|
|
{
|
2015-12-22 19:25:45 +01:00
|
|
|
if (d == NULL || n == NULL) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
|
|
|
|
node_t *p = n->parent;
|
|
|
|
|
|
|
|
if (p == NULL) {
|
|
|
|
d->root = NULL;
|
|
|
|
d->focus = NULL;
|
|
|
|
} else {
|
2015-12-22 19:25:45 +01:00
|
|
|
if (d->focus == p || is_descendant(d->focus, n)) {
|
|
|
|
d->focus = NULL;
|
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
node_t *b = brother_tree(n);
|
2014-01-18 16:30:00 +01:00
|
|
|
node_t *g = p->parent;
|
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
if (!n->vacant) {
|
|
|
|
unrotate_tree(b, n->birth_rotation);
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
b->parent = g;
|
|
|
|
|
|
|
|
if (g != NULL) {
|
2015-12-22 19:25:45 +01:00
|
|
|
if (is_first_child(p)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
g->first_child = b;
|
2015-12-22 19:25:45 +01:00
|
|
|
} else {
|
2014-01-18 16:30:00 +01:00
|
|
|
g->second_child = b;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
} else {
|
|
|
|
d->root = b;
|
|
|
|
}
|
|
|
|
|
|
|
|
b->birth_rotation = p->birth_rotation;
|
|
|
|
n->parent = NULL;
|
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
history_remove(d, p, false);
|
|
|
|
cancel_presel(m, d, p);
|
|
|
|
if (p->sticky) {
|
|
|
|
m->sticky_count--;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
free(p);
|
2015-11-22 14:41:00 +01:00
|
|
|
|
2016-04-16 18:13:31 +02:00
|
|
|
propagate_flags_upward(m, d, b);
|
2015-11-22 14:41:00 +01:00
|
|
|
}
|
2012-09-11 16:29:43 +02:00
|
|
|
}
|
|
|
|
|
2016-03-26 11:47:17 +01:00
|
|
|
void close_node(node_t *n)
|
|
|
|
{
|
|
|
|
if (n == NULL) {
|
|
|
|
return;
|
|
|
|
} else if (n->client != NULL) {
|
|
|
|
send_client_message(n->id, ewmh->WM_PROTOCOLS, WM_DELETE_WINDOW);
|
|
|
|
} else {
|
|
|
|
close_node(n->first_child);
|
|
|
|
close_node(n->second_child);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void kill_node(monitor_t *m, desktop_t *d, node_t *n)
|
|
|
|
{
|
|
|
|
if (n == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (node_t *f = first_extrema(n); f != NULL; f = next_leaf(f, n)) {
|
|
|
|
if (f->client != NULL) {
|
|
|
|
xcb_kill_client(dpy, f->id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
remove_node(m, d, n);
|
|
|
|
}
|
|
|
|
|
2013-10-06 16:58:02 +02:00
|
|
|
void remove_node(monitor_t *m, desktop_t *d, node_t *n)
|
2012-09-11 16:29:43 +02:00
|
|
|
{
|
2015-12-22 19:25:45 +01:00
|
|
|
if (n == NULL) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2012-09-18 17:21:04 +02:00
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
node_t *last_focus = d->focus;
|
2015-11-09 15:00:47 +01:00
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
unlink_node(m, d, n);
|
2015-12-22 19:25:45 +01:00
|
|
|
history_remove(d, n, true);
|
2014-01-18 16:30:00 +01:00
|
|
|
remove_stack_node(n);
|
2015-12-22 19:25:45 +01:00
|
|
|
cancel_presel(m, d, n);
|
|
|
|
if (m->sticky_count > 0) {
|
|
|
|
m->sticky_count -= sticky_count(n);
|
|
|
|
}
|
|
|
|
clients_count -= clients_count_in(n);
|
2016-04-07 18:08:32 +02:00
|
|
|
if (grabbed_node == n) {
|
|
|
|
grabbed_node = NULL;
|
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
free(n->client);
|
|
|
|
free(n);
|
2012-09-18 17:21:04 +02:00
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
ewmh_update_client_list(false);
|
2016-02-26 22:14:26 +01:00
|
|
|
ewmh_update_client_list(true);
|
2012-09-18 17:21:04 +02:00
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
if (d->focus != last_focus) {
|
|
|
|
if (d == mon->desk) {
|
|
|
|
focus_node(m, d, d->focus);
|
|
|
|
} else {
|
|
|
|
activate_node(m, d, d->focus);
|
|
|
|
}
|
2015-11-22 14:41:00 +01:00
|
|
|
}
|
2012-09-16 14:16:58 +02:00
|
|
|
}
|
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
void destroy_tree(monitor_t *m, desktop_t *d, node_t *n)
|
2012-12-27 22:36:06 +01:00
|
|
|
{
|
2015-11-22 14:41:00 +01:00
|
|
|
if (n == NULL) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return;
|
2015-11-22 14:41:00 +01:00
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
node_t *first_child = n->first_child;
|
|
|
|
node_t *second_child = n->second_child;
|
2014-01-18 16:30:00 +01:00
|
|
|
if (n->client != NULL) {
|
2015-11-22 14:41:00 +01:00
|
|
|
remove_stack_node(n);
|
2015-12-22 19:25:45 +01:00
|
|
|
clients_count--;
|
|
|
|
}
|
|
|
|
if (n->sticky) {
|
|
|
|
m->sticky_count--;
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
cancel_presel(m, d, n);
|
|
|
|
free(n->client);
|
2014-01-18 16:30:00 +01:00
|
|
|
free(n);
|
2015-12-22 19:25:45 +01:00
|
|
|
if (first_child != NULL && second_child != NULL) {
|
|
|
|
first_child->parent = second_child->parent = NULL;
|
|
|
|
destroy_tree(m, d, first_child);
|
|
|
|
destroy_tree(m, d, second_child);
|
|
|
|
}
|
2012-12-27 22:36:06 +01:00
|
|
|
}
|
|
|
|
|
2013-10-01 20:45:27 +02:00
|
|
|
bool swap_nodes(monitor_t *m1, desktop_t *d1, node_t *n1, monitor_t *m2, desktop_t *d2, node_t *n2)
|
2012-09-16 14:16:58 +02:00
|
|
|
{
|
2015-12-22 19:25:45 +01:00
|
|
|
if (n1 == NULL || n2 == NULL || n1 == n2 || is_descendant(n1, n2) || is_descendant(n2, n1) ||
|
|
|
|
(d1 != d2 && ((m1->sticky_count > 0 && sticky_count(n1) > 0) ||
|
|
|
|
(m2->sticky_count > 0 && sticky_count(n2) > 0)))) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return false;
|
2015-11-09 15:00:47 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
|
2016-03-23 11:24:47 +01:00
|
|
|
put_status(SBSC_MASK_NODE_SWAP, "node_swap 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n", m1->id, d1->id, n1->id, m2->id, d2->id, n2->id);
|
2014-01-18 16:30:00 +01:00
|
|
|
|
|
|
|
node_t *pn1 = n1->parent;
|
|
|
|
node_t *pn2 = n2->parent;
|
|
|
|
bool n1_first_child = is_first_child(n1);
|
|
|
|
bool n2_first_child = is_first_child(n2);
|
|
|
|
int br1 = n1->birth_rotation;
|
|
|
|
int br2 = n2->birth_rotation;
|
2015-12-22 19:25:45 +01:00
|
|
|
bool n1_held_focus = is_descendant(d1->focus, n1);
|
|
|
|
bool n2_held_focus = is_descendant(d2->focus, n2);
|
|
|
|
node_t *last_d1_focus = d1->focus;
|
|
|
|
node_t *last_d2_focus = d2->focus;
|
2014-01-18 16:30:00 +01:00
|
|
|
|
|
|
|
if (pn1 != NULL) {
|
2015-12-22 19:25:45 +01:00
|
|
|
if (n1_first_child) {
|
2014-01-18 16:30:00 +01:00
|
|
|
pn1->first_child = n2;
|
2015-12-22 19:25:45 +01:00
|
|
|
} else {
|
2014-01-18 16:30:00 +01:00
|
|
|
pn1->second_child = n2;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pn2 != NULL) {
|
2015-12-22 19:25:45 +01:00
|
|
|
if (n2_first_child) {
|
2014-01-18 16:30:00 +01:00
|
|
|
pn2->first_child = n1;
|
2015-12-22 19:25:45 +01:00
|
|
|
} else {
|
2014-01-18 16:30:00 +01:00
|
|
|
pn2->second_child = n1;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
n1->parent = pn2;
|
|
|
|
n2->parent = pn1;
|
|
|
|
n1->birth_rotation = br2;
|
|
|
|
n2->birth_rotation = br1;
|
|
|
|
|
2016-04-16 18:13:31 +02:00
|
|
|
propagate_flags_upward(m2, d2, n1);
|
|
|
|
propagate_flags_upward(m1, d1, n2);
|
2014-01-18 16:30:00 +01:00
|
|
|
|
|
|
|
if (d1 != d2) {
|
2015-12-22 19:25:45 +01:00
|
|
|
if (d1->root == n1) {
|
2014-01-18 16:30:00 +01:00
|
|
|
d1->root = n2;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (d2->root == n2) {
|
2014-01-18 16:30:00 +01:00
|
|
|
d2->root = n1;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (n1_held_focus) {
|
|
|
|
d1->focus = n2_held_focus ? last_d2_focus : n2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n2_held_focus) {
|
|
|
|
d2->focus = n1_held_focus ? last_d1_focus : n1;
|
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
|
|
|
|
if (m1 != m2) {
|
2015-12-22 19:25:45 +01:00
|
|
|
adapt_geometry(&m2->rectangle, &m1->rectangle, n2);
|
|
|
|
adapt_geometry(&m1->rectangle, &m2->rectangle, n1);
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ewmh_set_wm_desktop(n1, d2);
|
|
|
|
ewmh_set_wm_desktop(n2, d1);
|
2015-12-22 19:25:45 +01:00
|
|
|
|
2014-01-18 16:30:00 +01:00
|
|
|
history_swap_nodes(m1, d1, n1, m2, d2, n2);
|
|
|
|
|
|
|
|
if (m1->desk != d1 && m2->desk == d2) {
|
2015-12-22 19:25:45 +01:00
|
|
|
show_node(n1);
|
|
|
|
hide_node(n2);
|
2014-01-18 16:30:00 +01:00
|
|
|
} else if (m1->desk == d1 && m2->desk != d2) {
|
2015-12-22 19:25:45 +01:00
|
|
|
hide_node(n1);
|
|
|
|
show_node(n2);
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
if (n1_held_focus) {
|
|
|
|
if (d1 == mon->desk) {
|
|
|
|
focus_node(m1, d1, d1->focus);
|
|
|
|
} else {
|
|
|
|
activate_node(m1, d1, d1->focus);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
draw_border(n2, is_descendant(n2, d1->focus), (m1 == mon));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n2_held_focus) {
|
|
|
|
if (d2 == mon->desk) {
|
|
|
|
focus_node(m2, d2, d2->focus);
|
|
|
|
} else {
|
|
|
|
activate_node(m2, d2, d2->focus);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
draw_border(n1, is_descendant(n1, d2->focus), (m2 == mon));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
arrange(m1, d1);
|
|
|
|
|
|
|
|
if (d1 != d2) {
|
|
|
|
arrange(m2, d2);
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2013-10-01 10:48:03 +02:00
|
|
|
}
|
2012-09-19 22:59:13 +02:00
|
|
|
|
2013-10-01 20:45:27 +02:00
|
|
|
bool transfer_node(monitor_t *ms, desktop_t *ds, node_t *ns, monitor_t *md, desktop_t *dd, node_t *nd)
|
2013-10-01 10:48:03 +02:00
|
|
|
{
|
2015-12-22 19:25:45 +01:00
|
|
|
if (ns == NULL || ns == nd || is_child(ns, nd) || is_descendant(nd, ns)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int sc = 0;
|
|
|
|
|
|
|
|
if (sticky_still && ms->sticky_count > 0 && ds != dd && (sc = sticky_count(ns)) > 0) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return false;
|
2015-11-05 22:05:07 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
|
2016-03-23 11:24:47 +01:00
|
|
|
put_status(SBSC_MASK_NODE_TRANSFER, "node_transfer 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X 0x%08X\n", ms->id, ds->id, ns->id, md->id, dd->id, nd!=NULL?nd->id:0);
|
2014-01-18 16:30:00 +01:00
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
bool held_focus = is_descendant(ds->focus, ns);
|
|
|
|
/* avoid ending up with a dangling pointer (because of unlink_node) */
|
|
|
|
node_t *last_ds_focus = is_child(ns, ds->focus) ? NULL : ds->focus;
|
2014-01-18 16:30:00 +01:00
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
if (held_focus && ds == mon->desk) {
|
2014-01-18 16:30:00 +01:00
|
|
|
clear_input_focus();
|
2015-11-05 22:05:07 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
|
|
|
|
unlink_node(ms, ds, ns);
|
|
|
|
insert_node(md, dd, ns, nd);
|
|
|
|
|
2016-03-26 14:25:40 +01:00
|
|
|
if (md != ms && (ns->client == NULL || monitor_from_client(ns->client) != md)) {
|
2015-12-22 19:25:45 +01:00
|
|
|
adapt_geometry(&ms->rectangle, &md->rectangle, ns);
|
2015-11-05 22:05:07 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
|
|
|
|
if (ds != dd) {
|
|
|
|
ewmh_set_wm_desktop(ns, dd);
|
2015-12-22 19:25:45 +01:00
|
|
|
if (sc == 0) {
|
2015-11-05 22:05:07 +01:00
|
|
|
if (ds == ms->desk && dd != md->desk) {
|
2015-12-22 19:25:45 +01:00
|
|
|
hide_node(ns);
|
2015-11-05 22:05:07 +01:00
|
|
|
} else if (ds != ms->desk && dd == md->desk) {
|
2015-12-22 19:25:45 +01:00
|
|
|
show_node(ns);
|
2015-11-05 22:05:07 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
history_transfer_node(md, dd, ns);
|
2015-12-22 19:25:45 +01:00
|
|
|
stack(dd, ns, false);
|
2014-01-18 16:30:00 +01:00
|
|
|
|
|
|
|
if (ds == dd) {
|
2015-12-22 19:25:45 +01:00
|
|
|
if (held_focus) {
|
|
|
|
if (ds == mon->desk) {
|
|
|
|
focus_node(ms, ds, last_ds_focus);
|
|
|
|
} else {
|
|
|
|
activate_node(ms, ds, last_ds_focus);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
draw_border(ns, is_descendant(ns, ds->focus), (ms == mon));
|
2015-11-05 22:05:07 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
} else {
|
2015-12-22 19:25:45 +01:00
|
|
|
if (held_focus) {
|
|
|
|
if (ds == mon->desk) {
|
|
|
|
focus_node(ms, ds, ds->focus);
|
|
|
|
} else {
|
|
|
|
activate_node(ms, ds, ds->focus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (dd->focus == ns) {
|
|
|
|
if (dd == mon->desk) {
|
|
|
|
focus_node(md, dd, held_focus ? last_ds_focus : dd->focus);
|
|
|
|
} else {
|
|
|
|
activate_node(md, dd, held_focus ? last_ds_focus : dd->focus);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
draw_border(ns, is_descendant(ns, dd->focus), (md == mon));
|
2015-11-05 22:05:07 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
arrange(ms, ds);
|
2015-11-05 22:05:07 +01:00
|
|
|
|
|
|
|
if (ds != dd) {
|
2014-01-18 16:30:00 +01:00
|
|
|
arrange(md, dd);
|
2015-11-05 22:05:07 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
|
|
|
|
return true;
|
2013-06-27 19:41:01 +02:00
|
|
|
}
|
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
node_t *closest_node(monitor_t *m, desktop_t *d, node_t *n, cycle_dir_t dir, node_select_t sel)
|
2012-09-12 14:56:51 +02:00
|
|
|
{
|
2015-12-22 19:25:45 +01:00
|
|
|
if (n == NULL) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return NULL;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
|
|
|
|
node_t *f = (dir == CYCLE_PREV ? prev_leaf(n, d->root) : next_leaf(n, d->root));
|
2015-12-22 19:25:45 +01:00
|
|
|
if (f == NULL) {
|
2014-01-18 16:30:00 +01:00
|
|
|
f = (dir == CYCLE_PREV ? second_extrema(d->root) : first_extrema(d->root));
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
|
|
|
|
coordinates_t ref = {m, d, n};
|
|
|
|
while (f != n) {
|
|
|
|
coordinates_t loc = {m, d, f};
|
2016-04-16 18:13:31 +02:00
|
|
|
if (f->client != NULL && !f->hidden && node_matches(&loc, &ref, sel)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return f;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
f = (dir == CYCLE_PREV ? prev_leaf(f, d->root) : next_leaf(f, d->root));
|
2015-12-22 19:25:45 +01:00
|
|
|
if (f == NULL) {
|
2014-01-18 16:30:00 +01:00
|
|
|
f = (dir == CYCLE_PREV ? second_extrema(d->root) : first_extrema(d->root));
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
|
|
|
return NULL;
|
2012-10-23 13:31:11 +02:00
|
|
|
}
|
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
void circulate_leaves(monitor_t *m, desktop_t *d, node_t *n, circulate_dir_t dir)
|
2013-05-29 14:34:27 +02:00
|
|
|
{
|
2016-03-26 11:47:17 +01:00
|
|
|
if (n == NULL || d->focus == NULL || is_leaf(n)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2014-01-18 16:30:00 +01:00
|
|
|
node_t *p = d->focus->parent;
|
|
|
|
bool focus_first_child = is_first_child(d->focus);
|
2015-12-22 19:25:45 +01:00
|
|
|
if (dir == CIRCULATE_FORWARD) {
|
2016-03-26 11:47:17 +01:00
|
|
|
node_t *e = second_extrema(n);
|
|
|
|
while (e != NULL && (e->client == NULL || !IS_TILED(e->client))) {
|
|
|
|
e = prev_leaf(e, n);
|
|
|
|
}
|
|
|
|
for (node_t *s = e, *f = prev_tiled_leaf(s, n); f != NULL; s = prev_tiled_leaf(f, n), f = prev_tiled_leaf(s, n)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
swap_nodes(m, d, f, m, d, s);
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
} else {
|
2016-03-26 11:47:17 +01:00
|
|
|
node_t *e = first_extrema(n);
|
|
|
|
while (e != NULL && (e->client == NULL || !IS_TILED(e->client))) {
|
|
|
|
e = next_leaf(e, n);
|
|
|
|
}
|
|
|
|
for (node_t *f = e, *s = next_tiled_leaf(f, n); s != NULL; f = next_tiled_leaf(s, n), s = next_tiled_leaf(f, n)) {
|
2014-01-18 16:30:00 +01:00
|
|
|
swap_nodes(m, d, f, m, d, s);
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (focus_first_child) {
|
2014-01-18 16:30:00 +01:00
|
|
|
focus_node(m, d, p->first_child);
|
2015-12-22 19:25:45 +01:00
|
|
|
} else {
|
2014-01-18 16:30:00 +01:00
|
|
|
focus_node(m, d, p->second_child);
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
2012-11-01 22:47:03 +01:00
|
|
|
}
|
|
|
|
|
2016-04-16 18:13:31 +02:00
|
|
|
void set_vacant(monitor_t *m, desktop_t *d, node_t *n, bool value)
|
|
|
|
{
|
|
|
|
if (n->vacant == value) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
propagate_vacant_downward(m, d, n, value);
|
|
|
|
propagate_vacant_upward(m, d, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_vacant_local(monitor_t *m, desktop_t *d, node_t *n, bool value)
|
2012-09-07 13:55:03 +02:00
|
|
|
{
|
2015-11-19 15:08:54 +01:00
|
|
|
n->vacant = value;
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
unrotate_brother(n);
|
2016-04-16 18:13:31 +02:00
|
|
|
cancel_presel(m, d, n);
|
2015-11-19 15:08:54 +01:00
|
|
|
} else {
|
|
|
|
rotate_brother(n);
|
|
|
|
}
|
2016-04-16 18:13:31 +02:00
|
|
|
}
|
2015-11-19 15:08:54 +01:00
|
|
|
|
2016-04-16 18:13:31 +02:00
|
|
|
void propagate_vacant_downward(monitor_t *m, desktop_t *d, node_t *n, bool value)
|
|
|
|
{
|
|
|
|
if (n == NULL) {
|
|
|
|
return;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
|
2016-04-16 18:13:31 +02:00
|
|
|
set_vacant_local(m, d, n, value);
|
|
|
|
|
|
|
|
propagate_vacant_downward(m, d, n->first_child, value);
|
|
|
|
propagate_vacant_downward(m, d, n->second_child, value);
|
2015-11-19 15:08:54 +01:00
|
|
|
}
|
|
|
|
|
2016-04-16 18:13:31 +02:00
|
|
|
void propagate_vacant_upward(monitor_t *m, desktop_t *d, node_t *n)
|
2015-11-19 15:08:54 +01:00
|
|
|
{
|
|
|
|
if (n == NULL) {
|
2014-01-18 16:30:00 +01:00
|
|
|
return;
|
2015-11-19 15:08:54 +01:00
|
|
|
}
|
2012-09-18 17:21:04 +02:00
|
|
|
|
2015-11-19 15:08:54 +01:00
|
|
|
node_t *p = n->parent;
|
2012-09-18 17:21:04 +02:00
|
|
|
|
2016-04-16 18:13:31 +02:00
|
|
|
if (p != NULL) {
|
|
|
|
set_vacant_local(m, d, p, (p->first_child->vacant && p->second_child->vacant));
|
2014-01-18 16:30:00 +01:00
|
|
|
}
|
2016-04-16 18:13:31 +02:00
|
|
|
|
|
|
|
propagate_vacant_upward(m, d, p);
|
2012-09-07 13:55:03 +02:00
|
|
|
}
|
2013-10-12 21:16:51 +02:00
|
|
|
|
2016-03-26 11:47:17 +01:00
|
|
|
bool set_layer(monitor_t *m, desktop_t *d, node_t *n, stack_layer_t l)
|
2013-10-12 21:16:51 +02:00
|
|
|
{
|
2015-12-22 19:25:45 +01:00
|
|
|
if (n == NULL || n->client->layer == l) {
|
2016-03-26 11:47:17 +01:00
|
|
|
return false;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
n->client->last_layer = n->client->layer;
|
|
|
|
n->client->layer = l;
|
|
|
|
|
2016-04-07 18:08:32 +02:00
|
|
|
if (l == LAYER_ABOVE) {
|
|
|
|
n->client->wm_flags |= WM_FLAG_ABOVE;
|
|
|
|
n->client->wm_flags &= ~WM_FLAG_BELOW;
|
|
|
|
} else if (l == LAYER_BELOW) {
|
|
|
|
n->client->wm_flags |= WM_FLAG_BELOW;
|
|
|
|
n->client->wm_flags &= ~WM_FLAG_ABOVE;
|
|
|
|
} else {
|
|
|
|
n->client->wm_flags &= ~(WM_FLAG_ABOVE | WM_FLAG_BELOW);
|
|
|
|
}
|
|
|
|
|
|
|
|
ewmh_wm_state_update(n);
|
|
|
|
|
2016-03-23 11:24:47 +01:00
|
|
|
put_status(SBSC_MASK_NODE_LAYER, "node_layer 0x%08X 0x%08X 0x%08X %s\n", m->id, d->id, n->id, LAYER_STR(l));
|
2015-12-22 19:25:45 +01:00
|
|
|
|
|
|
|
if (d->focus == n) {
|
|
|
|
neutralize_occluding_windows(m, d, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
stack(d, n, (d->focus == n));
|
2016-03-26 11:47:17 +01:00
|
|
|
|
|
|
|
return true;
|
2013-10-12 21:16:51 +02:00
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
|
2016-03-26 11:47:17 +01:00
|
|
|
bool set_state(monitor_t *m, desktop_t *d, node_t *n, client_state_t s)
|
2015-12-22 19:25:45 +01:00
|
|
|
{
|
2016-04-12 06:09:15 +10:00
|
|
|
if (n == NULL || n->client == NULL || n->client->state == s) {
|
2016-03-26 11:47:17 +01:00
|
|
|
return false;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
client_t *c = n->client;
|
|
|
|
|
|
|
|
c->last_state = c->state;
|
|
|
|
c->state = s;
|
|
|
|
|
|
|
|
switch (c->last_state) {
|
|
|
|
case STATE_TILED:
|
|
|
|
case STATE_PSEUDO_TILED:
|
|
|
|
break;
|
|
|
|
case STATE_FLOATING:
|
|
|
|
set_floating(m, d, n, false);
|
|
|
|
break;
|
|
|
|
case STATE_FULLSCREEN:
|
|
|
|
set_fullscreen(m, d, n, false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-03-23 11:24:47 +01:00
|
|
|
put_status(SBSC_MASK_NODE_STATE, "node_state 0x%08X 0x%08X 0x%08X %s off\n", m->id, d->id, n->id, STATE_STR(c->last_state));
|
2015-12-22 19:25:45 +01:00
|
|
|
|
|
|
|
switch (c->state) {
|
|
|
|
case STATE_TILED:
|
|
|
|
case STATE_PSEUDO_TILED:
|
|
|
|
break;
|
|
|
|
case STATE_FLOATING:
|
|
|
|
set_floating(m, d, n, true);
|
|
|
|
break;
|
|
|
|
case STATE_FULLSCREEN:
|
|
|
|
set_fullscreen(m, d, n, true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-03-23 11:24:47 +01:00
|
|
|
put_status(SBSC_MASK_NODE_STATE, "node_state 0x%08X 0x%08X 0x%08X %s on\n", m->id, d->id, n->id, STATE_STR(c->state));
|
2015-12-22 19:25:45 +01:00
|
|
|
|
|
|
|
if (n == m->desk->focus) {
|
|
|
|
put_status(SBSC_MASK_REPORT);
|
|
|
|
}
|
2016-03-26 11:47:17 +01:00
|
|
|
|
|
|
|
return true;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void set_floating(monitor_t *m, desktop_t *d, node_t *n, bool value)
|
|
|
|
{
|
|
|
|
if (n == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
cancel_presel(m, d, n);
|
2016-04-16 18:13:31 +02:00
|
|
|
set_vacant(m, d, n, value);
|
2015-12-22 19:25:45 +01:00
|
|
|
|
|
|
|
if (!value && d->focus == n) {
|
|
|
|
neutralize_occluding_windows(m, d, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
stack(d, n, (d->focus == n));
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_fullscreen(monitor_t *m, desktop_t *d, node_t *n, bool value)
|
|
|
|
{
|
|
|
|
if (n == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
client_t *c = n->client;
|
|
|
|
|
|
|
|
cancel_presel(m, d, n);
|
2016-04-16 18:13:31 +02:00
|
|
|
set_vacant(m, d, n, value);
|
2015-12-22 19:25:45 +01:00
|
|
|
|
|
|
|
if (value) {
|
2016-04-07 18:08:32 +02:00
|
|
|
c->wm_flags |= WM_FLAG_FULLSCREEN;
|
2015-12-22 19:25:45 +01:00
|
|
|
c->last_layer = c->layer;
|
|
|
|
c->layer = LAYER_ABOVE;
|
|
|
|
} else {
|
2016-04-07 18:08:32 +02:00
|
|
|
c->wm_flags &= ~WM_FLAG_FULLSCREEN;
|
2015-12-22 19:25:45 +01:00
|
|
|
c->layer = c->last_layer;
|
|
|
|
if (d->focus == n) {
|
|
|
|
neutralize_occluding_windows(m, d, n);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-07 18:08:32 +02:00
|
|
|
ewmh_wm_state_update(n);
|
2015-12-22 19:25:45 +01:00
|
|
|
stack(d, n, (d->focus == n));
|
|
|
|
}
|
|
|
|
|
|
|
|
void neutralize_occluding_windows(monitor_t *m, desktop_t *d, node_t *n)
|
|
|
|
{
|
2016-03-26 11:47:17 +01:00
|
|
|
bool changed = false;
|
2015-12-22 19:25:45 +01:00
|
|
|
for (node_t *f = first_extrema(n); f != NULL; f = next_leaf(f, n)) {
|
|
|
|
for (node_t *a = first_extrema(d->root); a != NULL; a = next_leaf(a, d->root)) {
|
2016-03-26 11:47:17 +01:00
|
|
|
if (a != f && a->client != NULL && f->client != NULL &&
|
|
|
|
IS_FULLSCREEN(a->client) && stack_cmp(f->client, a->client) < 0) {
|
2015-12-22 19:25:45 +01:00
|
|
|
set_state(m, d, a, a->client->last_state);
|
2016-03-26 11:47:17 +01:00
|
|
|
changed = true;
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-03-26 11:47:17 +01:00
|
|
|
if (changed) {
|
2015-12-22 19:25:45 +01:00
|
|
|
arrange(m, d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-16 18:13:31 +02:00
|
|
|
void propagate_flags_upward(monitor_t *m, desktop_t *d, node_t *n)
|
2015-12-22 19:25:45 +01:00
|
|
|
{
|
2016-04-16 18:13:31 +02:00
|
|
|
if (n == NULL) {
|
2015-12-22 19:25:45 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-16 18:13:31 +02:00
|
|
|
node_t *p = n->parent;
|
2015-12-22 19:25:45 +01:00
|
|
|
|
2016-04-16 18:13:31 +02:00
|
|
|
if (p != NULL) {
|
|
|
|
set_vacant_local(m, d, p, (p->first_child->vacant && p->second_child->vacant));
|
|
|
|
set_hidden_local(m, d, p, (p->first_child->hidden && p->second_child->hidden));
|
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
|
2016-04-16 18:13:31 +02:00
|
|
|
propagate_flags_upward(m, d, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_hidden(monitor_t *m, desktop_t *d, node_t *n, bool value)
|
|
|
|
{
|
|
|
|
if (n == NULL || n->hidden == value) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool held_focus = is_descendant(d->focus, n);
|
|
|
|
|
|
|
|
propagate_hidden_downward(m, d, n, value);
|
|
|
|
propagate_hidden_upward(m, d, n);
|
|
|
|
|
|
|
|
put_status(SBSC_MASK_NODE_FLAG, "node_flag 0x%08X 0x%08X 0x%08X hidden %s\n", m->id, d->id, n->id, ON_OFF_STR(value));
|
|
|
|
|
|
|
|
if (held_focus || d->focus == NULL) {
|
|
|
|
if (d->focus != NULL) {
|
|
|
|
d->focus = NULL;
|
|
|
|
draw_border(n, false, (mon == m));
|
|
|
|
}
|
|
|
|
if (d == mon->desk) {
|
|
|
|
focus_node(m, d, d->focus);
|
|
|
|
} else {
|
|
|
|
activate_node(m, d, d->focus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_hidden_local(monitor_t *m, desktop_t *d, node_t *n, bool value)
|
|
|
|
{
|
|
|
|
n->hidden = value;
|
2016-04-16 18:22:49 +02:00
|
|
|
|
2016-04-16 18:13:31 +02:00
|
|
|
if (n->client != NULL) {
|
|
|
|
window_set_visibility(n->id, !value);
|
2016-04-16 18:22:49 +02:00
|
|
|
|
2016-04-16 18:13:31 +02:00
|
|
|
if (IS_TILED(n->client)) {
|
|
|
|
set_vacant(m, d, n, value);
|
|
|
|
}
|
2016-04-16 18:22:49 +02:00
|
|
|
|
2016-04-16 18:13:31 +02:00
|
|
|
if (value) {
|
|
|
|
n->client->wm_flags |= WM_FLAG_HIDDEN;
|
|
|
|
} else {
|
|
|
|
n->client->wm_flags &= ~WM_FLAG_HIDDEN;
|
|
|
|
}
|
2016-04-16 18:22:49 +02:00
|
|
|
|
|
|
|
ewmh_wm_state_update(n);
|
2015-12-22 19:25:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-16 18:13:31 +02:00
|
|
|
void propagate_hidden_downward(monitor_t *m, desktop_t *d, node_t *n, bool value)
|
|
|
|
{
|
|
|
|
if (n == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_hidden_local(m, d, n, value);
|
|
|
|
|
|
|
|
propagate_hidden_downward(m, d, n->first_child, value);
|
|
|
|
propagate_hidden_downward(m, d, n->second_child, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void propagate_hidden_upward(monitor_t *m, desktop_t *d, node_t *n)
|
|
|
|
{
|
|
|
|
if (n == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
node_t *p = n->parent;
|
|
|
|
|
|
|
|
if (p != NULL) {
|
|
|
|
set_hidden_local(m, d, p, p->first_child->hidden && p->second_child->hidden);
|
|
|
|
}
|
|
|
|
|
|
|
|
propagate_hidden_upward(m, d, p);
|
|
|
|
}
|
|
|
|
|
2015-12-22 19:25:45 +01:00
|
|
|
void set_sticky(monitor_t *m, desktop_t *d, node_t *n, bool value)
|
|
|
|
{
|
|
|
|
if (n == NULL || n->sticky == value) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d != m->desk) {
|
|
|
|
transfer_node(m, d, n, m, m->desk, m->desk->focus);
|
|
|
|
}
|
|
|
|
|
|
|
|
n->sticky = value;
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
m->sticky_count++;
|
|
|
|
} else {
|
|
|
|
m->sticky_count--;
|
|
|
|
}
|
|
|
|
|
2016-04-07 18:08:32 +02:00
|
|
|
if (n->client != NULL) {
|
|
|
|
if (value) {
|
|
|
|
n->client->wm_flags |= WM_FLAG_STICKY;
|
|
|
|
} else {
|
|
|
|
n->client->wm_flags &= ~WM_FLAG_STICKY;
|
|
|
|
}
|
|
|
|
ewmh_wm_state_update(n);
|
|
|
|
}
|
|
|
|
|
2016-03-23 11:24:47 +01:00
|
|
|
put_status(SBSC_MASK_NODE_FLAG, "node_flag 0x%08X 0x%08X 0x%08X sticky %s\n", m->id, d->id, n->id, ON_OFF_STR(value));
|
2015-12-22 19:25:45 +01:00
|
|
|
|
|
|
|
if (n == m->desk->focus) {
|
|
|
|
put_status(SBSC_MASK_REPORT);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_private(monitor_t *m, desktop_t *d, node_t *n, bool value)
|
|
|
|
{
|
|
|
|
if (n == NULL || n->private == value) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
n->private = value;
|
|
|
|
|
2016-03-23 11:24:47 +01:00
|
|
|
put_status(SBSC_MASK_NODE_FLAG, "node_flag 0x%08X 0x%08X 0x%08X private %s\n", m->id, d->id, n->id, ON_OFF_STR(value));
|
2016-04-16 18:13:31 +02:00
|
|
|
|
|
|
|
if (n == m->desk->focus) {
|
|
|
|
put_status(SBSC_MASK_REPORT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_locked(monitor_t *m, desktop_t *d, node_t *n, bool value)
|
|
|
|
{
|
|
|
|
if (n == NULL || n->locked == value) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
n->locked = value;
|
|
|
|
|
|
|
|
put_status(SBSC_MASK_NODE_FLAG, "node_flag 0x%08X 0x%08X 0x%08X locked %s\n", m->id, d->id, n->id, ON_OFF_STR(value));
|
2015-12-22 19:25:45 +01:00
|
|
|
|
|
|
|
if (n == m->desk->focus) {
|
|
|
|
put_status(SBSC_MASK_REPORT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_urgent(monitor_t *m, desktop_t *d, node_t *n, bool value)
|
|
|
|
{
|
|
|
|
if (value && mon->desk->focus == n) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
n->client->urgent = value;
|
|
|
|
|
2016-04-07 18:08:32 +02:00
|
|
|
if (value) {
|
|
|
|
n->client->wm_flags |= WM_FLAG_DEMANDS_ATTENTION;
|
|
|
|
} else {
|
|
|
|
n->client->wm_flags &= ~WM_FLAG_DEMANDS_ATTENTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
ewmh_wm_state_update(n);
|
|
|
|
|
2016-03-23 11:24:47 +01:00
|
|
|
put_status(SBSC_MASK_NODE_FLAG, "node_flag 0x%08X 0x%08X 0x%08X urgent %s\n", m->id, d->id, n->id, ON_OFF_STR(value));
|
2015-12-22 19:25:45 +01:00
|
|
|
put_status(SBSC_MASK_REPORT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns true if a contains b */
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2016-02-12 22:49:06 +01:00
|
|
|
xcb_rectangle_t get_rectangle(desktop_t *d, node_t *n)
|
2015-12-22 19:25:45 +01:00
|
|
|
{
|
|
|
|
client_t *c = n->client;
|
|
|
|
if (c != NULL) {
|
2016-04-15 16:34:45 +02:00
|
|
|
if (IS_FLOATING(c)) {
|
|
|
|
return c->floating_rectangle;
|
2016-02-12 22:49:06 +01:00
|
|
|
} else {
|
2016-04-15 16:34:45 +02:00
|
|
|
return c->tiled_rectangle;
|
2016-02-12 22:49:06 +01:00
|
|
|
}
|
2015-12-22 19:25:45 +01:00
|
|
|
} else {
|
2015-12-23 22:21:43 +01:00
|
|
|
int wg = (d == NULL ? 0 : (gapless_monocle && d->layout == LAYOUT_MONOCLE ? 0 : d->window_gap));
|
2015-12-22 19:25:45 +01:00
|
|
|
xcb_rectangle_t rect = n->rectangle;
|
|
|
|
rect.width -= wg;
|
|
|
|
rect.height -= wg;
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-12 22:49:06 +01:00
|
|
|
void get_side_handle(desktop_t *d, node_t *n, direction_t dir, xcb_point_t *pt)
|
2015-12-22 19:25:45 +01:00
|
|
|
{
|
2016-02-12 22:49:06 +01:00
|
|
|
xcb_rectangle_t rect = get_rectangle(d, n);
|
2015-12-22 19:25:45 +01:00
|
|
|
|
|
|
|
switch (dir) {
|
|
|
|
case DIR_EAST:
|
|
|
|
pt->x = rect.x + rect.width;
|
|
|
|
pt->y = rect.y + (rect.height / 2);
|
|
|
|
break;
|
|
|
|
case DIR_SOUTH:
|
|
|
|
pt->x = rect.x + (rect.width / 2);
|
|
|
|
pt->y = rect.y + rect.height;
|
|
|
|
break;
|
|
|
|
case DIR_WEST:
|
|
|
|
pt->x = rect.x;
|
|
|
|
pt->y = rect.y + (rect.height / 2);
|
|
|
|
break;
|
|
|
|
case DIR_NORTH:
|
|
|
|
pt->x = rect.x + (rect.width / 2);
|
|
|
|
pt->y = rect.y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DEF_FLAG_COUNT(flag) \
|
|
|
|
unsigned int flag##_count(node_t *n) \
|
|
|
|
{ \
|
|
|
|
if (n == NULL) { \
|
|
|
|
return 0; \
|
|
|
|
} else { \
|
|
|
|
return ((n->flag ? 1 : 0) + \
|
|
|
|
flag##_count(n->first_child) + \
|
|
|
|
flag##_count(n->second_child)); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
DEF_FLAG_COUNT(sticky)
|
|
|
|
DEF_FLAG_COUNT(private)
|
|
|
|
DEF_FLAG_COUNT(locked)
|
|
|
|
#undef DEF_FLAG_COUNT
|