-
Notifications
You must be signed in to change notification settings - Fork 2
/
select.c
68 lines (67 loc) · 2.04 KB
/
select.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// jbwm - Minimalist Window Manager for X
// Copyright 2008-2020, Alisa Bedard <alisabedard@gmail.com>
// Copyright 1999-2015, Ciaran Anscomb <evilwm@6809.org.uk>
// See README for license and other details.
#include "select.h"
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include "client.h"
#include "ewmh.h"
#include "ewmh_state.h"
#include "atom.h"
#include "JBWMClient.h"
#include "util.h"
#define WM_STATE(a) EWMH_ATOM(WM_STATE_##a)
static inline jbwm_pixel_t get_bg(struct JBWMClient * c)
{
return c->screen->pixels.bg;
}
static void set_state_not_focused(struct JBWMClient * c)
{
Display *d=c->screen->xlib->display;
XSetWindowBorder(d, c->parent, get_bg(c));
jbwm_ewmh_remove_state(d, c->window, XInternAtom(d,
"_NET_WM_STATE_FOCUSED",false));
}
static void set_border(struct JBWMClient * c)
{
struct JBWMPixels * p = &c->screen->pixels;
XSetWindowBorder(c->screen->xlib->display, c->parent,
c->opt.sticky ? p->fc : p->fg);
}
static void set_focused(struct JBWMClient * c)
{
Display * d = c->screen->xlib->display;
XInstallColormap(d, c->cmap);
const Window w = c->window;
XSetInputFocus(d, w, RevertToPointerRoot, CurrentTime);
jbwm_ewmh_add_state(d, w, jbwm_atoms[JBWM_NET_WM_STATE_FOCUSED]);
}
static void set_active_window_property(struct JBWMClient * c)
{
/* Store the window id as a static variable here in case
* client c is freed before the X server handles the event.
* If the property is read after the client is freed, it will
* cause a segmentation fault. */
static Window w;
Display *d;
w = c->window;
d=c->screen->xlib->display;
XChangeProperty(d, c->screen->xlib->root,
jbwm_atoms[JBWM_NET_ACTIVE_WINDOW], XA_WINDOW, 32,
PropModeReplace, (unsigned char *)&w, 1);
}
void jbwm_select_client(struct JBWMClient * target,
struct JBWMClient ** current_client)
{
struct JBWMClient * prev;
prev = *current_client;
set_border(target);
set_focused(target);
set_active_window_property(target);
*current_client = target;
if (prev != target) {
if (prev)
set_state_not_focused(prev);
}
}