...
 
Commits (5)
......@@ -47,6 +47,7 @@ karuiwm_sources = [
'src/button.c',
'src/client.c',
'src/config.c',
'src/direction.c',
'src/icon.c',
'src/karuiwm.c',
'src/key.c',
......
#include "direction.h"
void
direction_relative(struct position start, struct position *end,
enum direction dir)
{
*end = start;
switch (dir) {
case DIR_LEFT: --end->x; break;
case DIR_RIGHT: ++end->x; break;
case DIR_UP: --end->y; break;
case DIR_DOWN: ++end->y; break;
}
}
#ifndef _KWM_DIRECTION_H
#define _KWM_DIRECTION_H
enum direction { DIR_LEFT, DIR_RIGHT, DIR_UP, DIR_DOWN };
#include "position.h"
void
direction_relative(struct position start, struct position *end,
enum direction dir);
#endif /* ndef _KWM_DIRECTION_H */
......@@ -363,12 +363,12 @@ dmenueval(void)
switch (dmenu_state) {
case DMenuClients:
c = state_locate_client(state, 0, buf);
if (c->ws != seat->selmon->selws)
if (c->ws != seat->selmon->workspace)
monitor_show_workspace(seat->selmon, c->ws);
workspace_focus_client(seat->selmon->selws, c);
workspace_focus_client(seat->selmon->workspace, c);
break;
case DMenuRename:
state_rename_workspace(state, seat->selmon->selws, buf);
state_rename_workspace(state, seat->selmon->workspace, buf);
statusbar_update(seat->selmon->bar);
break;
case DMenuSend:
......@@ -377,13 +377,13 @@ dmenueval(void)
warn("No workspace named `%s`", buf);
break;
}
if (!seat->selmon->selws
|| workspace_isempty(seat->selmon->selws)) {
if (!seat->selmon->workspace
|| workspace_isempty(seat->selmon->workspace)) {
debug("No client to be sent to a workspace");
break;
}
c = seat->selmon->selws->selcli;
workspace_detach_client(seat->selmon->selws, c);
c = seat->selmon->workspace->selcli;
workspace_detach_client(seat->selmon->workspace, c);
monitor_arrange(seat->selmon);
workspace_attach_client(ws, c);
if (ws->mon)
......@@ -475,8 +475,8 @@ focusin(XEvent *e)
return;
if (!seat->selmon
|| !seat->selmon->selws
|| !seat->selmon->selws->selcli) {
|| !seat->selmon->workspace
|| !seat->selmon->workspace->selcli) {
warn("focusin on unfocused window %d (focus is set to none)",
e->xfocus.window);
XSetInputFocus(x11.dpy, x11.root, RevertToPointerRoot,
......@@ -484,11 +484,11 @@ focusin(XEvent *e)
return;
}
if (seat->selmon->selws->selcli->win != win) {
if (seat->selmon->workspace->selcli->win != win) {
warn("focusin on unfocused window %d (focus is on %d)",
e->xfocus.window, win);
workspace_focus_client(seat->selmon->selws,
seat->selmon->selws->selcli);
workspace_focus_client(seat->selmon->workspace,
seat->selmon->workspace->selcli);
return;
}
}
......@@ -539,11 +539,11 @@ killclient(union arg arg)
(void) arg;
if (!seat->selmon
|| !seat->selmon->selws
|| workspace_isempty(seat->selmon->selws))
|| !seat->selmon->workspace
|| workspace_isempty(seat->selmon->workspace))
return;
client_kill(seat->selmon->selws->selcli);
client_kill(seat->selmon->workspace->selcli);
}
void
......@@ -578,7 +578,7 @@ maprequest(XEvent *e)
XMapWindow(x11.dpy, c->win);
ws = seat->selmon->scratchpad ? seat->selmon->scratchpad
: seat->selmon->selws;
: seat->selmon->workspace;
workspace_attach_client(ws, c);
monitor_restack(seat->selmon);
monitor_arrange(seat->selmon);
......@@ -622,7 +622,7 @@ movemouse(union arg arg)
debug("Scratchpad active, not moving");
return;
}
ws = mon->selws;
ws = mon->workspace;
if (!ws) {
debug("No focused workspace");
return;
......@@ -707,7 +707,7 @@ movemouse(union arg arg)
} else if (mon != seat->selmon) {
debug("Client has changed monitor, transferring");
workspace_detach_client(c->ws, c);
workspace_attach_client(mon->selws, c);
workspace_attach_client(mon->workspace, c);
seat_focus_monitor(seat, mon);
}
......@@ -798,7 +798,7 @@ resizemouse(union arg arg)
debug("Scratchpad active, not resizing");
return;
}
ws = mon->selws;
ws = mon->workspace;
if (!ws) {
debug("No focused workspace");
return;
......@@ -874,7 +874,7 @@ resizemouse(union arg arg)
} else if (mon != seat->selmon) {
debug("Client has changed monitor, transferring");
workspace_detach_client(c->ws, c);
workspace_attach_client(mon->selws, c);
workspace_attach_client(mon->workspace, c);
seat_focus_monitor(seat, mon);
}
......@@ -1021,13 +1021,13 @@ sendfollowclient(union arg arg)
debug("Scratchpad enabled, not sending/following client");
return;
}
if (!seat->selmon->selws || !seat->selmon->selws->selcli)
if (!seat->selmon->workspace || !seat->selmon->workspace->selcli)
return;
c = seat->selmon->selws->selcli;
c = seat->selmon->workspace->selcli;
workspace_detach_client(seat->selmon->selws, c);
workspace_detach_client(seat->selmon->workspace, c);
stepws(arg);
workspace_attach_client(seat->selmon->selws, c);
workspace_attach_client(seat->selmon->workspace, c);
monitor_restack(seat->selmon);
monitor_arrange(seat->selmon);
}
......@@ -1072,7 +1072,7 @@ setmfact(union arg arg)
(void) arg;
ws = seat->selmon->scratchpad ? seat->selmon->scratchpad
: seat->selmon->selws;
: seat->selmon->workspace;
layout_setmfact(ws->layout, arg.f);
monitor_arrange(seat->selmon);
}
......@@ -1085,7 +1085,7 @@ setnmaster(union arg arg)
(void) arg;
ws = seat->selmon->scratchpad ? seat->selmon->scratchpad
: seat->selmon->selws;
: seat->selmon->workspace;
layout_setnmaster(ws->layout, (ssize_t) arg.i);
monitor_arrange(seat->selmon);
}
......@@ -1103,8 +1103,8 @@ setpad(union arg arg)
/* determine involved workspaces (regular & scratchpad) */
srcws = seat->selmon->scratchpad ? seat->selmon->scratchpad
: seat->selmon->selws;
dstws = srcws == state->scratchpad ? seat->selmon->selws
: seat->selmon->workspace;
dstws = srcws == state->scratchpad ? seat->selmon->workspace
: state->scratchpad;
if (!srcws || !srcws->selcli)
return;
......@@ -1318,7 +1318,7 @@ setws(struct monitor *mon, int x, int y)
{
struct workspace *srcws, *dstws;
srcws = mon->selws;
srcws = mon->workspace;
dstws = NULL;
if (state_locate_workspace(state, &dstws, NULL, x, y, NULL)) {
......@@ -1346,7 +1346,7 @@ shiftclient(union arg arg)
return;
ws = seat->selmon->scratchpad ? seat->selmon->scratchpad
: seat->selmon->selws;
: seat->selmon->workspace;
if (!ws)
return;
......@@ -1379,7 +1379,7 @@ shiftws(union arg arg)
struct workspace *src=NULL, *dst=NULL;
struct workspace *ref = state->wsmap->active
? state->wsmap->target
: seat->selmon->selws;
: seat->selmon->workspace;
int dx, dy;
reltoxy(&dx, &dy, ref, arg.i);
......@@ -1441,7 +1441,7 @@ stepfocus(union arg arg)
return;
ws = seat->selmon->scratchpad ? seat->selmon->scratchpad
: seat->selmon->selws;
: seat->selmon->workspace;
if (!ws)
return;
......@@ -1476,7 +1476,7 @@ steplayout(union arg arg)
return;
ws = seat->selmon->scratchpad ? seat->selmon->scratchpad
: seat->selmon->selws;
: seat->selmon->workspace;
switch (ws->layout->type) {
case LAYOUT_RSTACK:
......@@ -1493,7 +1493,7 @@ steplayout(union arg arg)
ws->layout = layout_create(ws->tiled, next_type);
monitor_arrange(seat->selmon);
if (ws == seat->selmon->selws)
if (ws == seat->selmon->workspace)
statusbar_update(seat->selmon->bar);
}
......@@ -1527,7 +1527,7 @@ void
stepws(union arg arg)
{
int x, y;
reltoxy(&x, &y, seat->selmon->selws, arg.i);
reltoxy(&x, &y, seat->selmon->workspace, arg.i);
setws(seat->selmon, x, y);
}
......@@ -1560,7 +1560,7 @@ togglefloat(union arg arg)
return;
}
c = seat->selmon->selws->selcli;
c = seat->selmon->workspace->selcli;
if (!c) {
warn("No client focused for toggling floating");
return;
......@@ -1616,12 +1616,12 @@ togglewsm(union arg arg)
LIST_FOR (state->workspaces, i, ws)
ws->wsmbox = wsmbox_create(ws, state->wsmap);
state->wsmap->target->wsmbox = wsmbox_create(state->wsmap->target, state->wsmap);
XRaiseWindow(x11.dpy, seat->selmon->selws->wsmbox->window);
XRaiseWindow(x11.dpy, seat->selmon->workspace->wsmbox->window);
XRaiseWindow(x11.dpy, state->wsmap->target->wsmbox->window);
/* initial target is the current workspace (make a "0-step") */
state->wsmap->target->x = seat->selmon->selws->x;
state->wsmap->target->y = seat->selmon->selws->y;
state->wsmap->target->x = seat->selmon->workspace->x;
state->wsmap->target->y = seat->selmon->workspace->y;
stepwsmbox((union arg const) { .i = NoDirection });
/* grab input */
......@@ -1903,7 +1903,7 @@ void
zoom(union arg arg)
{
unsigned int thispos, otherpos;
struct workspace *ws = seat->selmon->selws;
struct workspace *ws = seat->selmon->workspace;
struct list *clients = ws->tiled;
struct client *thisc = ws->selcli, *otherc;
......
......@@ -38,21 +38,21 @@ monitor_arrange(struct monitor *mon)
layout_apply(mon->scratchpad->layout, &mon->dim_pad);
/* fullscreen */
LIST_FOR (mon->selws->tiled, i, c)
LIST_FOR (mon->workspace->tiled, i, c)
if (c->fullscreen)
client_moveresize_fullscreen(c, mon->dim);
LIST_FOR (mon->selws->floating, i, c)
LIST_FOR (mon->workspace->floating, i, c)
if (c->fullscreen)
client_moveresize_fullscreen(c, mon->dim);
/* floating */
LIST_FOR (mon->selws->floating, i, c) {
LIST_FOR (mon->workspace->floating, i, c) {
fit(mon->dim_work, &c->dim_floating);
client_moveresize(c, c->dim_floating);
}
/* tiled */
layout_apply(mon->selws->layout, &mon->dim_work);
layout_apply(mon->workspace->layout, &mon->dim_work);
state_set_clientmask(mon->seat->state, true);
}
......@@ -75,7 +75,7 @@ monitor_create(void)
mon->seat = NULL;
mon->focused = false;
mon->scratchpad = NULL;
mon->selws = NULL;
mon->workspace = NULL;
return mon;
}
......@@ -95,8 +95,8 @@ monitor_focus(struct monitor *mon, bool focus)
mon->focused = focus;
if (mon->scratchpad)
workspace_focus(mon->scratchpad, focus);
else if (mon->selws)
workspace_focus(mon->selws, focus);
else if (mon->workspace)
workspace_focus(mon->workspace, focus);
else if (focus)
XSetInputFocus(x11.dpy, x11.root, RevertToPointerRoot,
CurrentTime);
......@@ -142,9 +142,9 @@ monitor_restack(struct monitor *mon)
size_t nwindows;
int unsigned i, si;
if (!mon->selws)
if (!mon->workspace)
return;
nwindows = mon->selws->tiled->size + mon->selws->floating->size;
nwindows = mon->workspace->tiled->size + mon->workspace->floating->size;
if (mon->scratchpad)
/* scratchpad should not have any floating windows */
nwindows += mon->scratchpad->tiled->size;
......@@ -166,30 +166,30 @@ monitor_restack(struct monitor *mon)
}
/* fullscreen */
LIST_FOR (mon->selws->tiled, i, c)
if (c->fullscreen && c == mon->selws->selcli)
LIST_FOR (mon->workspace->tiled, i, c)
if (c->fullscreen && c == mon->workspace->selcli)
windows[si++] = c->win;
LIST_FOR (mon->selws->floating, i, c)
if (c->fullscreen && c == mon->selws->selcli)
LIST_FOR (mon->workspace->floating, i, c)
if (c->fullscreen && c == mon->workspace->selcli)
windows[si++] = c->win;
LIST_FOR (mon->selws->tiled, i, c)
if (c->fullscreen && c != mon->selws->selcli)
LIST_FOR (mon->workspace->tiled, i, c)
if (c->fullscreen && c != mon->workspace->selcli)
windows[si++] = c->win;
LIST_FOR (mon->selws->floating, i, c)
if (c->fullscreen && c != mon->selws->selcli)
LIST_FOR (mon->workspace->floating, i, c)
if (c->fullscreen && c != mon->workspace->selcli)
windows[si++] = c->win;
/* floating */
LIST_FOR (mon->selws->floating, i, c)
LIST_FOR (mon->workspace->floating, i, c)
if (!c->fullscreen)
windows[si++] = c->win;
/* tiled */
LIST_FOR (mon->selws->tiled, i, c)
if (!c->fullscreen && c == mon->selws->selcli)
LIST_FOR (mon->workspace->tiled, i, c)
if (!c->fullscreen && c == mon->workspace->selcli)
windows[si++] = c->win;
LIST_FOR (mon->selws->tiled, i, c)
if (!c->fullscreen && c != mon->selws->selcli)
LIST_FOR (mon->workspace->tiled, i, c)
if (!c->fullscreen && c != mon->workspace->selcli)
windows[si++] = c->win;
XRestackWindows(x11.dpy, windows, (int signed) nwindows);
......@@ -222,12 +222,13 @@ monitor_show_scratchpad(struct monitor *mon, struct workspace *pad)
monitor_arrange(mon);
/* unfocus regular workspace */
if (mon->selws)
workspace_focus(mon->selws, false);
if (mon->workspace)
workspace_focus(mon->workspace, false);
} else {
/* focus regular workspace */
if (mon->selws)
workspace_focus(mon->selws, mon == mon->seat->selmon);
if (mon->workspace)
workspace_focus(mon->workspace,
mon == mon->seat->selmon);
/* unfocus and hide scratchpad */
workspace_focus(mon->scratchpad, false);
......@@ -239,8 +240,8 @@ monitor_show_scratchpad(struct monitor *mon, struct workspace *pad)
if (oldmon) {
/* scratchpad was visible on other monitor */
oldmon->scratchpad = NULL;
if (oldmon->selws && oldmon == mon->seat->selmon)
workspace_focus(oldmon->selws, true);
if (oldmon->workspace && oldmon == mon->seat->selmon)
workspace_focus(oldmon->workspace, true);
}
}
......@@ -251,7 +252,7 @@ monitor_show_workspace(struct monitor *mon, struct workspace *ws)
struct monitor *oldmon;
/* get other references */
oldws = mon->selws;
oldws = mon->workspace;
oldmon = ws ? ws->mon : NULL;
/* if nothing changes, don't do anything */
......@@ -259,7 +260,7 @@ monitor_show_workspace(struct monitor *mon, struct workspace *ws)
return;
/* update workspace for this monitor */
mon->selws = ws;
mon->workspace = ws;
if (ws) {
ws->mon = mon;
monitor_arrange(mon);
......@@ -287,7 +288,7 @@ monitor_show_workspace(struct monitor *mon, struct workspace *ws)
}
} else {
/* update workspace for other monitor */
oldmon->selws = oldws;
oldmon->workspace = oldws;
oldws->mon = oldmon;
monitor_arrange(oldmon);
workspace_focus(oldws, oldmon->focused);
......
......@@ -5,7 +5,7 @@
#include <stdbool.h>
struct monitor {
struct workspace *selws;
struct workspace *workspace;
struct rectangle dim, dim_work, dim_pad;
struct statusbar *bar;
struct seat *seat;
......
......@@ -92,15 +92,15 @@ statusbar_redraw(struct statusbar *bar)
bar->size.width, bar->size.height);
/* content */
if (mon->selws) {
if (mon->workspace) {
/* layout icon */
l = mon->selws->layout;
l = mon->workspace->layout;
i = bar->focused ? l->icon_active : l->icon_inactive;
XCopyArea(x11.dpy, i->pixmap, bar->pm, x11.gc,
0, 0, i->w, i->h, 2, 0);
/* workspace name */
sprintf(bar->buffer, "%s", mon->selws->name);
sprintf(bar->buffer, "%s", mon->workspace->name);
XSetForeground(x11.dpy, x11.gc, fg);
Xutf8DrawString(x11.dpy, bar->pm, x11.font.xfontset, x11.gc,
(int signed) (i->w + 12),
......
#include "wsmap.h"
#include "config.h"
#include "direction.h"
#include "list.h"
#include "log.h"
#include "monitor.h"
#include "wsmbox.h"
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#if 0
static void arrange(struct wsmap *wsm);
static void arrangebox(struct wsmap *wsm, struct wsmbox *box);
static struct wsmbox *get_neighbour(struct wsmap *wsm, struct wsmbox *box,
enum direction dir);
static void
arrange(struct wsmap *wsm)
......@@ -50,6 +55,22 @@ arrangebox(struct wsmap *wsm, struct wsmbox *box)
wsmbox_move(box, pos);
}
static struct wsmbox *
get_neighbour(struct wsmap *wsm, struct wsmbox *box, enum direction dir)
{
struct position pos;
bool exists;
direction_relative(box->pos, &pos, dir);
exists = list_contains(wsm->boxes, &pos,
(list_eqfunc) wsmbox_has_position);
if (!exists)
return NULL;
return list_find(wsm->boxes, &pos, (list_eqfunc) wsmbox_has_position);
}
#endif
struct wsmap *
wsmap_create(void)
{
......
......@@ -146,6 +146,12 @@ wsmbox_has_name(struct wsmbox *wb, char const *name)
&& strcmp(wb->workspace->name, name) == 0;
}
bool
wsmbox_has_position(struct wsmbox *wb, struct position *pos)
{
return wb->pos.x == pos->x && wb->pos.y == pos->y;
}
bool
wsmbox_manages_window(struct wsmbox *wb, Window *win)
{
......@@ -215,17 +221,17 @@ wsmbox_update(struct wsmbox *wb, struct wsmap *wsm)
{
struct config const *config = config_get();
struct workspace *ws = wb->workspace;
bool selws = ws->mon && ws == ws->mon->seat->selmon->selws;
bool workspace = ws->mon && ws == ws->mon->seat->selmon->workspace;
bool target = ws == wsm->target;
uint32_t fg = target ? config->wsmbox.selected.foreground.colour :
selws ? config->wsmbox.focused.foreground.colour :
workspace ? config->wsmbox.focused.foreground.colour :
config->wsmbox.unfocused.foreground.colour;
uint32_t bg = target ? config->wsmbox.selected.background.colour :
selws ? config->wsmbox.focused.background.colour :
workspace ? config->wsmbox.focused.background.colour :
config->wsmbox.unfocused.background.colour;
uint32_t border = target ? config->wsmbox.selected.border.colour :
selws ? config->wsmbox.focused.border.colour :
workspace ? config->wsmbox.focused.border.colour :
config->wsmbox.unfocused.border.colour;
int unsigned w = config->wsmbox.size.width;
int unsigned h = config->wsmbox.size.height;
......
......@@ -22,6 +22,7 @@ struct wsmbox *wsmbox_create(struct workspace *ws, struct wsmap *map);
struct wsmbox *wsmbox_create_ng(void);
void wsmbox_destroy(struct wsmbox *wb);
bool wsmbox_has_name(struct wsmbox *wb, char const *name);
bool wsmbox_has_position(struct wsmbox *wb, struct position *pos);
bool wsmbox_manages_window(struct wsmbox *wb, Window *win);
bool wsmbox_manages_workspace(struct wsmbox *wb, struct workspace *ws);
void wsmbox_move(struct wsmbox *wb, struct position pos);
......