...
 
Commits (11)
......@@ -52,12 +52,10 @@ grab_input(struct client *c)
XUngrabButton(x11.dpy, AnyButton, AnyModifier, c->win);
if (c->focused) {
for (i = 0; i < config->normal.buttons->size; ++i) {
b = config->normal.buttons->elements[i];
LIST_FOR (config->normal.buttons, i, b)
XGrabButton(x11.dpy, b->button, b->mod,
c->win, false, BUTTONMASK,
GrabModeAsync, GrabModeAsync, None, None);
}
XSetInputFocus(x11.dpy, c->win, RevertToPointerRoot,
CurrentTime);
} else {
......
This diff is collapsed.
......@@ -4,6 +4,10 @@
#include <stdbool.h>
#include <stddef.h>
#define LIST_FOR(L,I,E) \
for (I = 0; I < L->size; ++I) \
for (E = L->elements[I]; E != NULL; E = NULL)
typedef bool (*list_eqfunc)(void *e1, void *e2);
typedef int (*list_cmpfunc)(void *e1, void *e2);
......
......@@ -38,20 +38,15 @@ monitor_arrange(struct monitor *mon)
layout_apply(mon->scratchpad->layout, &mon->dim_pad);
/* fullscreen */
for (i = 0; i < mon->selws->tiled->size; ++i) {
c = mon->selws->tiled->elements[i];
LIST_FOR (mon->selws->tiled, i, c)
if (c->fullscreen)
client_moveresize_fullscreen(c, mon->dim);
}
for (i = 0; i < mon->selws->floating->size; ++i) {
c = mon->selws->floating->elements[i];
LIST_FOR (mon->selws->floating, i, c)
if (c->fullscreen)
client_moveresize_fullscreen(c, mon->dim);
}
/* floating */
for (i = 0; i < mon->selws->floating->size; i++) {
c = mon->selws->floating->elements[i];
LIST_FOR (mon->selws->floating, i, c) {
fit(mon->dim_work, &c->dim_floating);
client_moveresize(c, c->dim_floating);
}
......@@ -164,63 +159,93 @@ monitor_restack(struct monitor *mon)
/* scratchpad */
if (mon->scratchpad) {
for (i = 0; i < mon->scratchpad->tiled->size; ++i) {
c = mon->scratchpad->tiled->elements[i];
LIST_FOR (mon->scratchpad->tiled, i, c)
if (c == mon->scratchpad->selcli)
windows[si++] = c->win;
}
for (i = 0; i < mon->scratchpad->tiled->size; ++i) {
c = mon->scratchpad->tiled->elements[i];
LIST_FOR (mon->scratchpad->tiled, i, c)
if (c != mon->scratchpad->selcli)
windows[si++] = c->win;
}
}
/* fullscreen */
for (i = 0; i < mon->selws->tiled->size; ++i) {
c = mon->selws->tiled->elements[i];
LIST_FOR (mon->selws->tiled, i, c)
if (c->fullscreen && c == mon->selws->selcli)
windows[si++] = c->win;
}
for (i = 0; i < mon->selws->floating->size; ++i) {
c = mon->selws->floating->elements[i];
LIST_FOR (mon->selws->floating, i, c)
if (c->fullscreen && c == mon->selws->selcli)
windows[si++] = c->win;
}
for (i = 0; i < mon->selws->tiled->size; ++i) {
c = mon->selws->tiled->elements[i];
if (c->fullscreen)
LIST_FOR (mon->selws->tiled, i, c)
if (c->fullscreen && c != mon->selws->selcli)
windows[si++] = c->win;
}
for (i = 0; i < mon->selws->floating->size; ++i) {
c = mon->selws->floating->elements[i];
if (c->fullscreen)
LIST_FOR (mon->selws->floating, i, c)
if (c->fullscreen && c != mon->selws->selcli)
windows[si++] = c->win;
}
/* floating */
for (i = 0; i < mon->selws->floating->size; ++i) {
c = mon->selws->floating->elements[i];
LIST_FOR (mon->selws->floating, i, c)
if (!c->fullscreen)
windows[si++] = c->win;
}
/* tiled */
for (i = 0; i < mon->selws->tiled->size; ++i) {
c = mon->selws->tiled->elements[i];
LIST_FOR (mon->selws->tiled, i, c)
if (!c->fullscreen && c == mon->selws->selcli)
windows[si++] = c->win;
}
for (i = 0; i < mon->selws->tiled->size; ++i) {
c = mon->selws->tiled->elements[i];
LIST_FOR (mon->selws->tiled, i, c)
if (!c->fullscreen && c != mon->selws->selcli)
windows[si++] = c->win;
}
XRestackWindows(x11.dpy, windows, (int signed) nwindows);
free(windows);
}
void
monitor_show_scratchpad(struct monitor *mon, struct workspace *pad)
{
struct monitor *oldmon;
struct workspace *oldpad;
/* get other monitor */
oldmon = pad ? pad->mon : NULL;
oldpad = mon->scratchpad;
/* if nothing changes, don't do anything */
if (pad == oldpad || mon == oldmon)
return;
if (pad) {
/* show and focus scratchpad */
mon->scratchpad = pad;
mon->scratchpad->mon = mon;
pad->mon = mon;
if (!oldmon)
workspace_show(pad, true);
workspace_focus(pad, mon == mon->seat->selmon);
monitor_restack(mon);
monitor_arrange(mon);
/* unfocus regular workspace */
if (mon->selws)
workspace_focus(mon->selws, false);
} else {
/* focus regular workspace */
if (mon->selws)
workspace_focus(mon->selws, mon == mon->seat->selmon);
/* unfocus and hide scratchpad */
workspace_focus(mon->scratchpad, false);
workspace_show(mon->scratchpad, false);
mon->scratchpad->mon = NULL;
mon->scratchpad = NULL;
}
if (oldmon) {
/* scratchpad was visible on other monitor */
oldmon->scratchpad = NULL;
if (oldmon->selws && oldmon == mon->seat->selmon)
workspace_focus(oldmon->selws, true);
}
}
void
monitor_show_workspace(struct monitor *mon, struct workspace *ws)
{
......
......@@ -22,6 +22,7 @@ void monitor_destroy(struct monitor *mon);
void monitor_focus(struct monitor *mon, bool focus);
void monitor_moveresize(struct monitor *mon, struct rectangle dimensions);
void monitor_restack(struct monitor *mon);
void monitor_show_scratchpad(struct monitor *mon, struct workspace *pad);
void monitor_show_workspace(struct monitor *mon, struct workspace *ws);
#endif /* ndef _KWM_MONITOR_H */
......@@ -55,20 +55,15 @@ seat_destroy(struct seat *s)
void
seat_detach_monitor(struct seat *s, struct monitor *mon)
{
int unsigned i;
list_remove(s->monitors, mon, NULL);
mon->seat = NULL;
if (mon == s->selmon) {
for (i = 0;
i < s->monitors->size && s->monitors->elements[i] != mon;
++i);
if (i < s->monitors->size)
seat_focus_monitor(s, s->monitors->elements[i]);
if (s->monitors->size > 0)
seat_focus_monitor(s, s->monitors->elements[0]);
else
seat_focus_monitor(s, NULL);
}
list_remove(s->monitors, mon, NULL);
mon->seat = NULL;
}
void
......@@ -100,12 +95,10 @@ seat_grab_keys(struct seat *s, enum input_mode mode)
XUngrabKey(x11.dpy, AnyKey, AnyModifier, x11.root);
switch (mode) {
case IM_NORMAL:
for (i = 0; i < config->normal.keys->size; ++i) {
k = config->normal.keys->elements[i];
LIST_FOR (config->normal.keys, i, k)
XGrabKey(x11.dpy, XKeysymToKeycode(x11.dpy, k->key),
k->mod, x11.root, true, GrabModeAsync,
GrabModeAsync);
}
break;
case IM_WSM:
if (!s->state->wsmap->target->wsmbox) {
......@@ -114,12 +107,10 @@ seat_grab_keys(struct seat *s, enum input_mode mode)
}
XGrabKeyboard(x11.dpy, s->state->wsmap->target->wsmbox->window,
true, GrabModeAsync, GrabModeAsync, CurrentTime);
for (i = 0; i < config->wsm.keys->size; ++i) {
k = config->wsm.keys->elements[i];
LIST_FOR (config->wsm.keys, i, k)
XGrabKey(x11.dpy, XKeysymToKeycode(x11.dpy, k->key),
k->mod, x11.root, true, GrabModeAsync,
GrabModeAsync);
}
break;
}
}
......@@ -133,8 +124,7 @@ seat_locate_rectangle(struct seat *s, struct rectangle r)
selmon = NULL;
sela = 0u;
for (i = 0; i < s->monitors->size; ++i) {
mon = s->monitors->elements[i];
LIST_FOR (s->monitors, i, mon) {
a = rectangle_intersection(mon->dim, r);
if (a > sela) {
sela = a;
......
......@@ -27,6 +27,7 @@ state_create(void)
sizeof(struct state), strerror(errno));
s->workspaces = list_create();
s->wsmap = NULL;
s->scratchpad = workspace_create(0, 0);
return s;
}
......@@ -54,6 +55,13 @@ state_destroy(struct state *s)
}
list_destroy(s->workspaces);
while (s->scratchpad->tiled->size > 0) {
c = s->scratchpad->tiled->elements[0];
workspace_detach_client(s->scratchpad, c);
client_destroy(c);
}
workspace_destroy(s->scratchpad);
if (s->wsmap) {
workspace_destroy(s->wsmap->target);
free(s->wsmap);
......@@ -82,10 +90,16 @@ state_locate_client(struct state *s, Window w, char const *name)
struct client *c;
if (name) debug("searching for client '%s'", name);
for (j = 0; j < s->workspaces->size; j++) {
ws = s->workspaces->elements[j];
for (i = 0; i < ws->tiled->size; i++) {
c = ws->tiled->elements[i];
LIST_FOR (s->scratchpad->tiled, i, c) {
if (name) {
if (strcmp(c->name, name) == 0)
return c;
} else if (c->win == w) {
return c;
}
}
LIST_FOR (s->workspaces, j, ws) {
LIST_FOR (ws->tiled, i, c) {
if (name) {
if (strcmp(c->name, name) == 0)
return c;
......@@ -93,8 +107,7 @@ state_locate_client(struct state *s, Window w, char const *name)
return c;
}
}
for (i = 0; i < ws->floating->size; ++i) {
c = ws->floating->elements[i];
LIST_FOR (ws->floating, i, c) {
if (name) {
if (strcmp(c->name, name) == 0)
return c;
......@@ -114,8 +127,7 @@ state_locate_workspace(struct state *s, struct workspace **ws,
unsigned int i;
struct workspace *_ws;
for (i = 0; i < s->workspaces->size; ++i) {
_ws = s->workspaces->elements[i];
LIST_FOR (s->workspaces, i, _ws) {
if (name) {
if (strcmp(_ws->name, name) != 0)
/* name does not match */
......@@ -138,11 +150,9 @@ state_next_free_workspace(struct state *s)
int unsigned i;
struct workspace *ws;
for (i = 0; i < s->workspaces->size; ++i) {
ws = s->workspaces->elements[i];
LIST_FOR (s->workspaces, i, ws)
if (!ws->mon)
return ws;
}
return NULL;
}
......@@ -170,15 +180,12 @@ state_set_clientmask(struct state *s, bool set)
struct client *c;
int unsigned i, j;
for (j = 0; j < s->workspaces->size; ++j) {
ws = s->workspaces->elements[j];
for (i = 0; i < ws->tiled->size; ++i) {
c = ws->tiled->elements[i];
LIST_FOR (s->scratchpad->tiled, i, c)
XSelectInput(x11.dpy, c->win, set ? CLIENTMASK : 0);
LIST_FOR (s->workspaces, j, ws) {
LIST_FOR (ws->tiled, i, c)
XSelectInput(x11.dpy, c->win, set ? CLIENTMASK : 0);
}
for (i = 0; i < ws->floating->size; ++i) {
c = ws->floating->elements[i];
LIST_FOR (ws->floating, i, c)
XSelectInput(x11.dpy, c->win, set ? CLIENTMASK : 0);
}
}
}
......@@ -4,10 +4,7 @@
struct state {
struct list *workspaces;
struct wsmap *wsmap;
struct {
struct client *client;
struct monitor *monitor;
} scratchpad;
struct workspace *scratchpad;
};
#include "client.h"
......
......@@ -20,9 +20,7 @@ workspace_attach_client(struct workspace *ws, struct client *c)
if (list->size == 0) {
pos = 0;
} else {
for (i = 0;
i < list->size && list->elements[i] != ws->selcli;
++i);
i = list_find_index(list, ws->selcli, NULL);
pos = MIN(i + 1, (int unsigned) list->size);
}
list_insert(list, c, pos);
......@@ -93,7 +91,7 @@ workspace_detach_client(struct workspace *ws, struct client *c)
c->win, c->name);
/* focus next client */
for (i = 0; i < clients->size && clients->elements[i] != c; ++i);
i = list_find_index(clients, c, NULL);
nextc = i < clients->size - 1 ? clients->elements[i + 1]
: i > 0 ? clients->elements[i - 1]
: otherclients->size > 0 ? otherclients->elements[0]
......@@ -192,10 +190,11 @@ workspace_set_floating(struct workspace *ws, struct client *c, bool floating)
void
workspace_show(struct workspace *ws, bool show)
{
struct client *c;
int unsigned i;
for (i = 0; i < ws->tiled->size; ++i)
client_show(ws->tiled->elements[i], show);
for (i = 0; i < ws->floating->size; ++i)
client_show(ws->floating->elements[i], show);
LIST_FOR (ws->tiled, i, c)
client_show(c, show);
LIST_FOR (ws->floating, i, c)
client_show(c, show);
}