...
 
Commits (11)
......@@ -52,7 +52,6 @@ static void expose(XEvent *);
static void focusin(XEvent *);
static void keypress(XEvent *);
static void keyrelease(XEvent *);
static struct monitor *locaterect(struct position *pos, struct size *size);
static void mappingnotify(XEvent *);
static void maprequest(XEvent *);
static void propertynotify(XEvent *);
......@@ -481,27 +480,28 @@ expose(XEvent *e)
void
focusin(XEvent *e)
{
(void) e;
/* TODO: reenable and adapt if this becomes a problem again (used to be
* for VTE terminals that would occasionally steal focus)
*/
#if 0
Window win = e->xfocus.window;
if (win == x11.root) {
if (win == x11.root)
return;
if (!seat->selmon
|| !seat->selmon->selws
|| !seat->selmon->selws->selcli) {
warn("focusin on unfocused window %d (focus is set to none)",
e->xfocus.window);
XSetInputFocus(x11.dpy, x11.root, RevertToPointerRoot,
CurrentTime);
return;
}
if (!seat->selmon->selws->selcli
|| win != seat->selmon->selws->selcli->win)
{
if (seat->selmon->selws->selcli->win != win) {
warn("focusin on unfocused window %d (focus is on %d)",
e->xfocus.window, seat->selmon->selws->selcli
? seat->selmon->selws->selcli->win
: 0);
updatefocus();
e->xfocus.window, win);
workspace_focus_client(seat->selmon->selws,
seat->selmon->selws->selcli);
return;
}
#endif
}
void
......@@ -559,27 +559,6 @@ killclient(union arg arg)
client_kill(seat->selmon->selws->selcli);
}
struct monitor *
locaterect(struct position *pos, struct size *size)
{
struct monitor *m, *selm;
int unsigned a, sela;
unsigned int i;
for (i = 0, selm = seat->selmon, sela = 0;
i < seat->monitors->size;
++i)
{
m = seat->monitors->elements[i];
a = rectangle_intersection2(&m->dim.pos, &m->dim.size, pos, size);
if (a > sela) {
sela = a;
selm = m;
}
}
return selm;
}
void
maprequest(XEvent *e)
{
......@@ -720,7 +699,7 @@ movemouse(union arg arg)
} while (ev.type != ButtonRelease);
/* check if it has been moved to another monitor */
mon = locaterect(&c->dim.pos, &c->dim.size);
mon = seat_locate_rectangle(seat, c->dim);
if (mon != seat->selmon) {
debug("Client has changed monitor, transferring");
workspace_detach_client(c->ws, c);
......@@ -992,15 +971,15 @@ sendfollowclient(union arg arg)
if (!seat->selmon
|| !seat->selmon->selws
|| workspace_isempty(seat->selmon->selws))
|| !seat->selmon->selws->selcli)
return;
c = seat->selmon->selws->selcli;
workspace_detach_client(seat->selmon->selws, c);
stepws(arg);
workspace_attach_client(seat->selmon->selws, c);
monitor_restack(seat->selmon);
monitor_arrange(seat->selmon);
updatefocus();
}
void
......@@ -1066,8 +1045,8 @@ setpad(union arg arg)
state->scratchpad.client);
state->scratchpad.client = NULL;
state->scratchpad.monitor = NULL;
monitor_restack(seat->selmon);
monitor_arrange(seat->selmon);
updatefocus();
return;
}
......@@ -1078,11 +1057,11 @@ setpad(union arg arg)
/* set current focus as pad, remove old pad if necessary */
newpad = seat->selmon->selws->selcli;
workspace_detach_client(seat->selmon->selws, newpad);
if (state->scratchpad.client) {
if (state->scratchpad.client)
workspace_attach_client(seat->selmon->selws,
state->scratchpad.client);
}
state->scratchpad.client = newpad;
monitor_restack(seat->selmon);
monitor_arrange(seat->selmon);
togglepad((union arg) { .i = 0 });
}
......@@ -1651,12 +1630,12 @@ unmapnotify(XEvent *e)
if (state->scratchpad.client
&& e->xunmap.window == state->scratchpad.client->win) {
client_destroy(state->scratchpad.client);
if (state->scratchpad.monitor) {
/* scratchpad visible, focus monitor again */
monitor_focus(seat->selmon, true);
state->scratchpad.monitor = NULL;
updatefocus();
}
state->scratchpad.monitor = NULL;
client_destroy(state->scratchpad.client);
state->scratchpad.client = NULL;
return;
}
......
......@@ -38,7 +38,6 @@ monitor_arrange(struct monitor *mon)
client_moveresize(c, c->dim_floating.pos, c->dim_floating.size);
}
state_set_clientmask(mon->seat->state, true);
mon->selws->dirty = false;
mon->selws->mon = mon;
}
......
......@@ -6,14 +6,14 @@
#include <string.h>
int unsigned
rectangle_intersection(struct rectangle *r1, struct rectangle *r2)
rectangle_intersection(struct rectangle r1, struct rectangle r2)
{
int left = MAX(r1->x, r2->x);
int right = MIN(r1->x + (int signed) r1->width,
r2->x + (int signed) r2->width);
int top = MAX(r1->y, r2->y);
int bottom = MIN(r1->y + (int signed) r1->height,
r2->y + (int signed) r2->height);
int left = MAX(r1.x, r2.x);
int right = MIN(r1.x + (int signed) r1.width,
r2.x + (int signed) r2.width);
int top = MAX(r1.y, r2.y);
int bottom = MIN(r1.y + (int signed) r1.height,
r2.y + (int signed) r2.height);
if (left > right || bottom > top)
/* no intersection */
......@@ -21,12 +21,3 @@ rectangle_intersection(struct rectangle *r1, struct rectangle *r2)
return (int unsigned) ((right - left) * (bottom - top));
}
int unsigned
rectangle_intersection2(struct position *p1, struct size *s1,
struct position *p2, struct size *s2)
{
struct rectangle r1 = (struct rectangle) { .pos = *p1, .size = *s1 };
struct rectangle r2 = (struct rectangle) { .pos = *p2, .size = *s2 };
return rectangle_intersection(&r1, &r2);
}
......@@ -21,8 +21,6 @@ struct rectangle {
};
};
int unsigned rectangle_intersection(struct rectangle *r1, struct rectangle *r2);
int unsigned rectangle_intersection2(struct position *p1, struct size *s1,
struct position *p2, struct size *s2);
int unsigned rectangle_intersection(struct rectangle r1, struct rectangle r2);
#endif /* ndef _KWM_GEOMETRY_H */
......@@ -123,3 +123,23 @@ seat_grab_keys(struct seat *s, enum input_mode mode)
break;
}
}
struct monitor *
seat_locate_rectangle(struct seat *s, struct rectangle r)
{
struct monitor *mon, *selmon;
int unsigned a, sela;
int unsigned i;
selmon = NULL;
sela = 0u;
for (i = 0; i < s->monitors->size; ++i) {
mon = s->monitors->elements[i];
a = rectangle_intersection(mon->dim, r);
if (a > sela) {
sela = a;
selmon = mon;
}
}
return selmon;
}
......@@ -19,5 +19,6 @@ void seat_destroy(struct seat *s);
void seat_detach_monitor(struct seat *s, struct monitor *mon);
void seat_focus_monitor(struct seat *s, struct monitor *mon);
void seat_grab_keys(struct seat *s, enum input_mode mode);
struct monitor *seat_locate_rectangle(struct seat *s, struct rectangle r);
#endif /* ndef _KWM_SEAT_H */
......@@ -52,7 +52,6 @@ workspace_create(int x, int y)
ws->selcli = NULL;
ws->x = x;
ws->y = y;
ws->dirty = false;
ws->layout = layout_create(ws->tiled, LAYOUT_RSTACK);
ws->state = NULL;
ws->mon = NULL;
......@@ -79,6 +78,7 @@ workspace_detach_client(struct workspace *ws, struct client *c)
{
unsigned int i;
struct list *clients, *otherclients;
struct client *nextc;
if (c->ws != ws) {
warn("Attempt to detach client from wrong workspace");
......@@ -88,26 +88,21 @@ workspace_detach_client(struct workspace *ws, struct client *c)
clients = c->floating ? ws->floating : ws->tiled;
otherclients = c->floating ? ws->tiled : ws->floating;
if (!list_contains(clients, c, NULL)) {
warn("Client is not attached to its workspace");
c->ws = NULL;
return;
}
if (!list_contains(clients, c, NULL))
die("Client %lu (%s) is not attached to this workspace",
c->win, c->name);
/* get next client to focus */
/* focus next client */
for (i = 0; i < clients->size && clients->elements[i] != c; ++i);
ws->selcli = i < clients->size - 1 ? clients->elements[i + 1]
: i > 0 ? clients->elements[i - 1]
: NULL;
if (!ws->selcli && otherclients->size > 0)
ws->selcli = otherclients->elements[0];
nextc = i < clients->size - 1 ? clients->elements[i + 1]
: i > 0 ? clients->elements[i - 1]
: otherclients->size > 0 ? otherclients->elements[0]
: NULL;
workspace_focus_client(ws, nextc);
/* remove current client */
list_remove(clients, c, NULL);
c->ws = NULL;
if (!c->floating)
ws->dirty = true;
}
void
......@@ -131,14 +126,18 @@ void
workspace_focus_client(struct workspace *ws, struct client *c)
{
if (ws->selcli == c)
/* nothing to do */
return;
if (ws->focused && ws->selcli)
client_set_focus(ws->selcli, false);
ws->selcli = c;
if (ws->focused)
client_set_focus(ws->selcli, true);
if (ws->focused) {
if (ws->selcli)
client_set_focus(ws->selcli, true);
else
XSetInputFocus(x11.dpy, x11.root, RevertToPointerRoot,
CurrentTime);
}
}
bool
......
......@@ -10,8 +10,6 @@ struct workspace {
struct wsmbox *wsmbox;
char name[256];
int x, y;
//int ilayout;
bool dirty;
struct monitor *mon;
struct layout *layout;
struct state *state;
......