Skip to content

Commit

Permalink
Make sticky windows stick to their monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
baskerville committed Oct 6, 2013
1 parent 7a40791 commit 35e9927
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 30 deletions.
1 change: 0 additions & 1 deletion bspwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ void init(void)
status_fifo = NULL;
last_motion_time = last_motion_x = last_motion_y = 0;
visible = auto_raise = sticky_still = true;
num_sticky = 0;
randr_base = 0;
exit_status = 0;
}
Expand Down
1 change: 0 additions & 1 deletion bspwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ xcb_connection_t *dpy;
int default_screen, screen_width, screen_height;
uint32_t num_clients;
uint32_t num_desktops;
int num_sticky;
unsigned int num_monitors;
unsigned int monitor_uid;
unsigned int desktop_uid;
Expand Down
5 changes: 5 additions & 0 deletions doc/bspwm.1
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,11 @@ Color of the border of an unfocused locked window\&.
Color of the border of a focused sticky window of a focused monitor\&.
.RE
.PP
\fIactive_sticky_border_color\fR
.RS 4
Color of the border of a focused sticky window of an unfocused monitor\&.
.RE
.PP
\fInormal_sticky_border_color\fR
.RS 4
Color of the border of an unfocused sticky window\&.
Expand Down
3 changes: 3 additions & 0 deletions doc/bspwm.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,9 @@ Global Settings
'focused_sticky_border_color'::
Color of the border of a focused sticky window of a focused monitor.

'active_sticky_border_color'::
Color of the border of a focused sticky window of an unfocused monitor.

'normal_sticky_border_color'::
Color of the border of an unfocused sticky window.

Expand Down
4 changes: 2 additions & 2 deletions events.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void destroy_notify(xcb_generic_event_t *evt)

coordinates_t loc;
if (locate_window(e->window, &loc)) {
remove_node(loc.desktop, loc.node);
remove_node(loc.monitor, loc.desktop, loc.node);
arrange(loc.monitor, loc.desktop);
}
}
Expand All @@ -162,7 +162,7 @@ void unmap_notify(xcb_generic_event_t *evt)

coordinates_t loc;
if (locate_window(e->window, &loc)) {
remove_node(loc.desktop, loc.node);
remove_node(loc.monitor, loc.desktop, loc.node);
arrange(loc.monitor, loc.desktop);
}
}
Expand Down
4 changes: 3 additions & 1 deletion messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ bool cmd_window(char **args, int num)
} else if (streq("-k", *args) || streq("--kill", *args)) {
if (num > 1)
return false;
window_kill(trg.desktop, trg.node);
window_kill(trg.monitor, trg.desktop, trg.node);
dirty = true;
} else {
return false;
Expand Down Expand Up @@ -988,6 +988,7 @@ bool set_setting(coordinates_t loc, char *name, char *value)
SETCOLOR(active_locked_border_color)
SETCOLOR(normal_locked_border_color)
SETCOLOR(focused_sticky_border_color)
SETCOLOR(active_sticky_border_color)
SETCOLOR(normal_sticky_border_color)
SETCOLOR(urgent_border_color)
#undef SETCOLOR
Expand Down Expand Up @@ -1075,6 +1076,7 @@ bool get_setting(coordinates_t loc, char *name, char* rsp)
GETCOLOR(active_locked_border_color)
GETCOLOR(normal_locked_border_color)
GETCOLOR(focused_sticky_border_color)
GETCOLOR(active_sticky_border_color)
GETCOLOR(normal_sticky_border_color)
GETCOLOR(urgent_border_color)
#undef GETCOLOR
Expand Down
1 change: 1 addition & 0 deletions monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ monitor_t *make_monitor(xcb_rectangle_t rect)
m->rectangle = rect;
m->top_padding = m->right_padding = m->bottom_padding = m->left_padding = 0;
m->wired = true;
m->num_sticky = 0;
uint32_t mask = XCB_CW_EVENT_MASK;
uint32_t values[] = {XCB_EVENT_MASK_ENTER_WINDOW};
m->root = xcb_generate_id(dpy);
Expand Down
2 changes: 1 addition & 1 deletion restore.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void restore_tree(char *file_path)
if (end != 0)
d->focus = n;
if (c->sticky)
num_sticky++;
m->num_sticky++;
}
if (br == 'a')
n->birth_rotation = 90;
Expand Down
1 change: 1 addition & 0 deletions settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ void load_settings(void)
snprintf(active_locked_border_color, sizeof(active_locked_border_color), "%s", ACTIVE_LOCKED_BORDER_COLOR);
snprintf(normal_locked_border_color, sizeof(normal_locked_border_color), "%s", NORMAL_LOCKED_BORDER_COLOR);
snprintf(focused_sticky_border_color, sizeof(focused_sticky_border_color), "%s", FOCUSED_STICKY_BORDER_COLOR);
snprintf(active_sticky_border_color, sizeof(active_sticky_border_color), "%s", ACTIVE_STICKY_BORDER_COLOR);
snprintf(normal_sticky_border_color, sizeof(normal_sticky_border_color), "%s", NORMAL_STICKY_BORDER_COLOR);
snprintf(urgent_border_color, sizeof(urgent_border_color), "%s", URGENT_BORDER_COLOR);

Expand Down
2 changes: 2 additions & 0 deletions settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define ACTIVE_LOCKED_BORDER_COLOR "#545350"
#define NORMAL_LOCKED_BORDER_COLOR "#3F3E3B"
#define FOCUSED_STICKY_BORDER_COLOR "#E3A5DA"
#define ACTIVE_STICKY_BORDER_COLOR "#545350"
#define NORMAL_STICKY_BORDER_COLOR "#3F3E3B"
#define URGENT_BORDER_COLOR "#EFA29A"

Expand All @@ -39,6 +40,7 @@ char focused_locked_border_color[MAXLEN];
char active_locked_border_color[MAXLEN];
char normal_locked_border_color[MAXLEN];
char focused_sticky_border_color[MAXLEN];
char active_sticky_border_color[MAXLEN];
char normal_sticky_border_color[MAXLEN];
char urgent_border_color[MAXLEN];

Expand Down
13 changes: 7 additions & 6 deletions tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void set_visibility(monitor_t *m, desktop_t *d, node_t *n, bool visible)
pseudo_focus(d, n);
}
} else {
if (m->desk == d)
if (m->desk == d || n->client->sticky)
window_hide(n->client->window);
if (d->focus == n) {
node_t *f = history_get_node(d, n);
Expand Down Expand Up @@ -133,15 +133,16 @@ void tag_desktop(monitor_t *m, desktop_t *d, unsigned int tags_field)
if (num_tags < 1)
return;
bool dirty = false;
unsigned int old_tags_field = d->tags_field;
d->tags_field = tags_field;
for (node_t *n = first_extrema(d->root); n != NULL; n = next_leaf(n, d->root)) {
bool visible = is_visible(d, n);
if ((visible && (tags_field & n->client->tags_field) == 0)
|| (!visible && (tags_field & n->client->tags_field) != 0)) {
set_visibility(m, d, n, !visible);
bool old_visible = (old_tags_field & n->client->tags_field) != 0;
bool visible = (tags_field & n->client->tags_field) != 0;
if (old_visible != visible) {
set_visibility(m, d, n, visible);
dirty = true;
}
}
d->tags_field = tags_field;
if (dirty)
arrange(m, d);
if (d == mon->desk)
Expand Down
16 changes: 8 additions & 8 deletions tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void insert_node(monitor_t *m, desktop_t *d, node_t *n, node_t *f)
update_vacant_state(p);
}
if (n->client->sticky)
num_sticky++;
m->num_sticky++;
put_status();
}

Expand All @@ -230,7 +230,7 @@ void focus_node(monitor_t *m, desktop_t *d, node_t *n)
if (mon->desk != d || n == NULL)
clear_input_focus();

if (num_sticky > 0 && d != mon->desk) {
if (m->num_sticky > 0 && mon == m && d != mon->desk) {
node_t *a = first_extrema(mon->desk->root);
sticky_still = false;
while (a != NULL) {
Expand All @@ -240,7 +240,7 @@ void focus_node(monitor_t *m, desktop_t *d, node_t *n)
a = b;
}
sticky_still = true;
if (n == NULL)
if (n == NULL && d->focus != NULL && is_visible(d, d->focus))
n = d->focus;
}

Expand Down Expand Up @@ -765,7 +765,7 @@ int balance_tree(node_t *n)
}
}

void unlink_node(desktop_t *d, node_t *n)
void unlink_node(monitor_t *m, desktop_t *d, node_t *n)
{
if (d == NULL || n == NULL)
return;
Expand Down Expand Up @@ -814,18 +814,18 @@ void unlink_node(desktop_t *d, node_t *n)
update_vacant_state(b->parent);
}
if (n->client->sticky)
num_sticky--;
m->num_sticky--;
put_status();
}

void remove_node(desktop_t *d, node_t *n)
void remove_node(monitor_t *m, desktop_t *d, node_t *n)
{
if (n == NULL)
return;

PRINTF("remove node %X\n", n->client->window);

unlink_node(d, n);
unlink_node(m, d, n);
history_remove(d, n);
remove_stack_node(n);
free(n->client);
Expand Down Expand Up @@ -938,7 +938,7 @@ bool transfer_node(monitor_t *ms, desktop_t *ds, node_t *ns, monitor_t *md, desk
if (focused)
clear_input_focus();

unlink_node(ds, ns);
unlink_node(ms, ds, ns);
insert_node(md, dd, ns, nd);

if (md != ms)
Expand Down
4 changes: 2 additions & 2 deletions tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ void unrotate_tree(node_t *n, int rot);
void unrotate_brother(node_t *n);
void flip_tree(node_t *n, flip_t flp);
int balance_tree(node_t *n);
void unlink_node(desktop_t *d, node_t *n);
void remove_node(desktop_t *d, node_t *n);
void unlink_node(monitor_t *m, desktop_t *d, node_t *n);
void remove_node(monitor_t *m, desktop_t *d, node_t *n);
void destroy_tree(node_t *n);
bool swap_nodes(monitor_t *m1, desktop_t *d1, node_t *n1, monitor_t *m2, desktop_t *d2, node_t *n2);
bool transfer_node(monitor_t *ms, desktop_t *ds, node_t *ns, monitor_t *md, desktop_t *dd, node_t *nd);
Expand Down
1 change: 1 addition & 0 deletions types.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ struct monitor_t {
desktop_t *desk_tail;
monitor_t *prev;
monitor_t *next;
int num_sticky;
};

typedef struct {
Expand Down
18 changes: 11 additions & 7 deletions window.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ void window_close(node_t *n)
send_client_message(n->client->window, ewmh->WM_PROTOCOLS, WM_DELETE_WINDOW);
}

void window_kill(desktop_t *d, node_t *n)
void window_kill(monitor_t *m, desktop_t *d, node_t *n)
{
if (n == NULL)
return;
Expand All @@ -303,7 +303,7 @@ void window_kill(desktop_t *d, node_t *n)
PRINTF("kill window %X\n", win);

xcb_kill_client(dpy, win);
remove_node(d, n);
remove_node(m, d, n);
}

void set_fullscreen(node_t *n, bool value)
Expand Down Expand Up @@ -373,16 +373,16 @@ void set_sticky(monitor_t *m, desktop_t *d, node_t *n, bool value)

PRINTF("set sticky %X: %s\n", c->window, BOOLSTR(value));

if (d != mon->desk)
transfer_node(m, d, n, mon, mon->desk, mon->desk->focus);
if (d != m->desk)
transfer_node(m, d, n, m, m->desk, m->desk->focus);

c->sticky = value;
if (value)
num_sticky++;
m->num_sticky++;
else
num_sticky--;
m->num_sticky--;

window_draw_border(n, mon->desk->focus == n, true);
window_draw_border(n, mon->desk->focus == n, m == mon);
}

void set_urgency(monitor_t *m, desktop_t *d, node_t *n, bool value)
Expand Down Expand Up @@ -430,6 +430,8 @@ uint32_t get_border_color(client_t *c, bool focused_window, bool focused_monitor
get_color(urgent_border_color, c->window, &pxl);
else if (c->locked)
get_color(active_locked_border_color, c->window, &pxl);
else if (c->sticky)
get_color(active_sticky_border_color, c->window, &pxl);
else
get_color(active_border_color, c->window, &pxl);
} else {
Expand Down Expand Up @@ -556,11 +558,13 @@ void window_set_visibility(xcb_window_t win, bool visible)

void window_hide(xcb_window_t win)
{
PRINTF("window hide %X\n", win);
window_set_visibility(win, false);
}

void window_show(xcb_window_t win)
{
PRINTF("window show %X\n", win);
window_set_visibility(win, true);
}

Expand Down
2 changes: 1 addition & 1 deletion window.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ monitor_t *monitor_from_point(xcb_point_t pt);
monitor_t *underlying_monitor(client_t *c);
void adopt_orphans(void);
void window_close(node_t *n);
void window_kill(desktop_t *d, node_t *n);
void window_kill(monitor_t *m, desktop_t *d, node_t *n);
void set_fullscreen(node_t *n, bool value);
void set_floating(node_t *n, bool value);
void set_locked(monitor_t *m, desktop_t *d, node_t *n, bool value);
Expand Down

0 comments on commit 35e9927

Please sign in to comment.