46 Commits
0.1 ... 0.3

Author SHA1 Message Date
Dylan Araps
b0a8d244e0 patches: rebase 2019-10-17 19:48:23 +03:00
Dylan Araps
cd03f2e3d1 patches: optimize rounded corners further. 2019-10-17 19:47:34 +03:00
Dylan Araps
9353c2be35 patches: rebase 2019-10-17 19:43:06 +03:00
Dylan Araps
cada809f65 sowm: use simpler structure for storing workspaces. 2019-10-17 18:45:47 +03:00
Dylan Araps
0ae4e7918f sowm: move tiny tiny functions to macros. 2019-10-17 18:10:22 +03:00
Dylan Araps
1248c93bcd sowm: clean up 2019-10-17 17:02:42 +03:00
Dylan Araps
ec1f32020e sowm: removed comments for now. Will be added back in a better format. 2019-10-17 15:44:49 +03:00
Dylan Araps
f098fde9cd sowm: Shorter math for window centering. 2019-10-17 15:41:19 +03:00
Dylan Araps
518bb08dc0 sowm: None is just 0 and it's shorter 2019-10-17 15:11:14 +03:00
Dylan Araps
7a995a4970 sowm: skip setting unneeded variables. 2019-10-17 14:28:17 +03:00
Dylan Araps
c4d0b2ee8c sowm: clean up 2019-10-17 14:24:33 +03:00
Dylan Araps
ce819bd126 sowm: subscribe to even less events 2019-10-17 13:43:05 +03:00
Dylan Araps
fa90c629df docs: update 2019-10-17 13:22:28 +03:00
Dylan Araps
fa5526c842 sowm: Don't force window location when the window wants to be put elsewhere. 2019-10-17 11:26:31 +03:00
Dylan Araps
c1f3193b0f Merge branch 'master' of github.com:dylanaraps/sowm 2019-10-17 09:40:41 +03:00
Dylan Araps
3662ca427d sowm: turns out we can't pass 0 as an error handler. :P 2019-10-17 09:40:24 +03:00
Dylan Araps
fdcf245866 docs: update 2019-10-17 09:16:32 +03:00
Dylan Araps
60d88980fb sowm: subscribe to less window events! 2019-10-17 09:16:22 +03:00
Dylan Araps
4af0d54147 sowm: remove unneeded function 2019-10-17 09:03:03 +03:00
Dylan Araps
8e3c9da820 sowm: Remove unneeded call to ws_go on start 2019-10-17 08:53:59 +03:00
Dylan Araps
de4a08ace0 sowm: avoid branch and variable. 2019-10-17 08:39:40 +03:00
Dylan Araps
669ca21407 sowm: simpler window geometry 2019-10-16 17:25:40 +03:00
Dylan Araps
a5503f8159 sowm: avoid global and remove uneeded initial value. 2019-10-16 15:50:10 +03:00
Dylan Araps
42e126009f sowm: void unneeded variable 2019-10-16 15:46:09 +03:00
Dylan Araps
72a0f32dd4 docs: update 2019-10-16 15:22:28 +03:00
Dylan Araps
fa96cc7b18 sowm: reduce scope of client 2019-10-16 14:15:34 +03:00
Dylan Araps
f36c78d9bb sowm: move two overly simple functions to macros. 2019-10-16 13:21:36 +03:00
Dylan Araps
d6de000725 docs: update 2019-10-16 12:50:18 +03:00
Dylan Araps
2c17908a78 docs: update 2019-10-16 11:50:38 +03:00
Dylan Araps
5161ad72f8 docs: update 2019-10-16 11:45:27 +03:00
Dylan Araps
43025432ac sowm: intialize cursor buttons using loop to remove duplicate code 2019-10-16 11:44:59 +03:00
Dylan Araps
8bdffcacda docs: update 2019-10-16 09:19:56 +03:00
Dylan Araps
446ad2e02c sowm: Use modifier from config for mouse controls. 2019-10-16 09:17:46 +03:00
Dylan Araps
19e3078aea docs: update 2019-10-16 09:16:11 +03:00
Dylan Araps
41ad0ff832 patches: rebase 2019-10-16 08:32:46 +03:00
Dylan Araps
abb9445bfb patches: rebase 2019-10-16 08:31:27 +03:00
Dylan Araps
2928148534 patches: rebase 2019-10-16 08:29:58 +03:00
Dylan Araps
f19fd045a8 sowm: resize optimization 2019-10-15 23:44:04 +03:00
Dylan Araps
d271e266e6 patches: Added normal kill. 2019-10-15 20:03:50 +03:00
Dylan Araps
cd37b0ad39 patches: Added normal kill. 2019-10-15 20:01:41 +03:00
Dylan Araps
69499117c2 patches: rebase 2019-10-15 19:50:26 +03:00
Dylan Araps
1866f5ff02 patches: rebase 2019-10-15 19:49:30 +03:00
Dylan Araps
70dda04916 patches: rebase 2019-10-15 19:48:44 +03:00
Dylan Araps
5668ad1259 sowm: fixed all compiler warnings. 2019-10-15 19:45:24 +03:00
Dylan Araps
c4e64e27b7 docs: update 2019-10-15 17:33:40 +03:00
Dylan Araps
a20543402c sowm: provide config.def.h instead 2019-10-15 17:12:10 +03:00
7 changed files with 183 additions and 408 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
sowm
sowm.o
config.h

View File

@@ -1,4 +1,4 @@
CFLAGS+= -std=c99 -Wall -Wno-deprecated-declarations -pedantic
CFLAGS+= -std=c99 -Wall -Wextra -pedantic -Wno-deprecated-declarations
LDADD+= -lX11
LDFLAGS=
PREFIX?= /usr
@@ -6,10 +6,13 @@ BINDIR?= $(PREFIX)/bin
CC ?= gcc
all: sowm
all: config.h sowm
config.h:
cp config.def.h config.h
sowm: sowm.o
$(CC) $(LDFLAGS) -Os -o $@ $+ $(LDADD)
$(CC) $(LDFLAGS) -O3 -o $@ $+ $(LDADD)
install: all
install -Dm 755 sowm $(DESTDIR)$(BINDIR)/sowm

View File

@@ -2,7 +2,7 @@
<a href="https://user-images.githubusercontent.com/6799467/66687576-9747c200-ec72-11e9-947d-5b96753eab03.jpg"><img src="https://user-images.githubusercontent.com/6799467/66687576-9747c200-ec72-11e9-947d-5b96753eab03.jpg" width="43%" align="right"></a>
An itsy bitsy floating window manager (*270~ sloc / 24kb compiled!*).
An itsy bitsy floating window manager (*240~ sloc / 24kb compiled!*).
- Floating only.
- Fullscreen toggle.
@@ -15,9 +15,8 @@ An itsy bitsy floating window manager (*270~ sloc / 24kb compiled!*).
- Alt-Tab window focusing.
- All windows die on exit.
- No borders.
- No bar support.
- No ICCCM.
- No window borders.
- [No ICCCM](https://web.archive.org/web/20190617214524/https://raw.githubusercontent.com/kfish/xsel/1a1c5edf0dc129055f7764c666da2dd468df6016/rant.txt).
- No EMWH.
- etc etc etc
@@ -62,7 +61,7 @@ An itsy bitsy floating window manager (*270~ sloc / 24kb compiled!*).
## Installation
1) Modify `config.h` to suit your needs.
1) Copy `config.def.h` to `config.h` and modify it to suit your needs.
2) Run `make` to build `sowm`.
3) Copy it to your path or run `make install`.
- `DESTDIR` and `PREFIX` are supported.

View File

@@ -15,7 +15,7 @@ const char* colors[] = {"bud", "/home/goldie/Pictures/Wallpapers", 0};
static struct key keys[] = {
{MOD, XK_q, win_kill, {0}},
{MOD, XK_c, win_center, {.i = 0}},
{MOD, XK_c, win_center, {.w = 0}},
{MOD, XK_f, win_fs, {0}},
{Mod1Mask, XK_Tab, win_next, {0}},

View File

@@ -0,0 +1,51 @@
diff --git a/patches/sowm-normal-kill.patch b/patches/sowm-normal-kill.patch
index 4b11cd4..e69de29 100644
--- a/patches/sowm-normal-kill.patch
+++ b/patches/sowm-normal-kill.patch
@@ -1,23 +0,0 @@
-diff --git a/sowm.c b/sowm.c
-index 0d74d4b..ff70968 100644
---- a/sowm.c
-+++ b/sowm.c
-@@ -326,7 +326,17 @@ void win_del(Window w) {
- "Shoot first and don't ask questions later?.."
- */
- void win_kill() {
-- if (win_current() != root) XKillClient(d, cur);
-+ if (win_current() == root) return;
-+
-+ XEvent ev = { .type = ClientMessage };
-+
-+ ev.xclient.window = cur;
-+ ev.xclient.format = 32;
-+ ev.xclient.message_type = XInternAtom(d, "WM_PROTOCOLS", True);
-+ ev.xclient.data.l[0] = XInternAtom(d, "WM_DELETE_WINDOW", True);
-+ ev.xclient.data.l[1] = CurrentTime;
-+
-+ XSendEvent(d, cur, False, NoEventMask, &ev);
- }
-
- /*
diff --git a/sowm.c b/sowm.c
index 126aca0..cd8af6f 100644
--- a/sowm.c
+++ b/sowm.c
@@ -180,7 +180,17 @@ void win_del(Window w) {
}
void win_kill() {
- if (win_current() ^ root) XKillClient(d, cur);
+ if (win_current() == root) return;
+
+ XEvent ev = { .type = ClientMessage };
+
+ ev.xclient.window = cur;
+ ev.xclient.format = 32;
+ ev.xclient.message_type = XInternAtom(d, "WM_PROTOCOLS", True);
+ ev.xclient.data.l[0] = XInternAtom(d, "WM_DELETE_WINDOW", True);
+ ev.xclient.data.l[1] = CurrentTime;
+
+ XSendEvent(d, cur, False, NoEventMask, &ev);
}
void win_center(const Arg arg) {

View File

@@ -1,28 +1,28 @@
diff --git a/Makefile b/Makefile
index 2549d3a..04c2222 100644
index 3154a2f..243b744 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
CFLAGS+= -std=c99 -Wall -Wno-deprecated-declarations -pedantic
CFLAGS+= -std=c99 -Wall -Wextra -pedantic -Wno-deprecated-declarations
-LDADD+= -lX11
+LDADD+= -lX11 -lXext
LDFLAGS=
PREFIX?= /usr
BINDIR?= $(PREFIX)/bin
diff --git a/config.h b/config.h
index 864c9a7..1525894 100644
--- a/config.h
+++ b/config.h
diff --git a/config.def.h b/config.def.h
index 3cef34b..e7f1518 100644
--- a/config.def.h
+++ b/config.def.h
@@ -2,6 +2,7 @@
#define CONFIG_H
#define MOD Mod4Mask
+#define ROUND_CORNERS 20
const char* menu[] = {"dmenu_run", 0};
const char* term[] = {"st", 0};
diff --git a/sowm.c b/sowm.c
index b9e8867..4c0b3fa 100644
index 126aca0..5c99c5c 100644
--- a/sowm.c
+++ b/sowm.c
@@ -3,6 +3,7 @@
@@ -33,50 +33,37 @@ index b9e8867..4c0b3fa 100644
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
@@ -59,6 +59,7 @@ static void win_del(Window w);
@@ -41,6 +42,7 @@ static void win_del(Window w);
static void win_fs();
static void win_kill();
static void win_next();
+static void win_round_corners(Window w, int rad);
static void win_to_ws(const Arg arg);
static void ws_go(const Arg arg);
static void ws_save(int i);
@@ -183,6 +185,8 @@ void notify_motion(XEvent *e) {
attr.width + (mouse.button==3 ? xd : 0),
attr.height + (mouse.button==3 ? yd : 0));
+ win_round_corners(mouse.subwindow, ROUND_CORNERS);
static int xerror() { return 0;}
@@ -105,6 +107,9 @@ void notify_motion(XEvent *e) {
wy + (mouse.button == 1 ? yd : 0),
ww + (mouse.button == 3 ? xd : 0),
wh + (mouse.button == 3 ? yd : 0));
+
for WIN if (c->w == mouse.subwindow) c->f = 0;
}
+ if (mouse.button == 3)
+ win_round_corners(mouse.subwindow, ROUND_CORNERS);
}
@@ -367,9 +367,58 @@ void win_fs() {
void key_press(XEvent *e) {
@@ -201,9 +206,44 @@ void win_fs() {
} else
XMoveResizeWindow(d, cur, c->a.x, c->a.y, c->a.width, c->a.height);
XMoveResizeWindow(d, cur, c->wx, c->wy, c->ww, c->wh);
+
+ win_round_corners(cur, c->f ? 0 : ROUND_CORNERS);
}
}
+/*
+ Round the corners of the desired window.
+
+ This isn't included in the actual source as it
+ requires the 'shape' extension to Xorg and I'd
+ like to keep the original source simple.
+
+ This is very similar to the rounded corners
+ implementations in the 'dwm' and 'openbox'
+ patches.
+*/
+void win_round_corners(Window w, int rad) {
+ XWindowAttributes attr2;
+ XGetWindowAttributes(d, w, &attr2);
+ unsigned int ww, wh, dia = 2 * rad;
+
+ int dia = 2 * rad;
+ int ww = attr2.width;
+ int wh = attr2.height;
+ win_size(w, &(int){1}, &(int){1}, &ww, &wh);
+
+ if (ww < dia || wh < dia) return;
+
@@ -104,16 +91,16 @@ index b9e8867..4c0b3fa 100644
+ XShapeCombineMask(d, w, ShapeBounding, 0, 0, mask, ShapeSet);
+ XFreePixmap(d, mask);
+ XFreeGC(d, shape_gc);
+ }
+}
+
/*
This function simply moves the focused window to
the desired desktop.
@@ -510,6 +510,7 @@ void map_request(XEvent *e) {
EnterWindowMask|FocusChangeMask);
win_center((Arg){.i = w});
void win_to_ws(const Arg arg) {
int tmp = ws;
win_current();
@@ -275,6 +315,7 @@ void map_request(XEvent *e) {
if (wx == 0 && wy == 0) win_center((Arg){.i = w});
XMapWindow(d, w);
+ win_round_corners(w, ROUND_CORNERS);
FOC(w);
win_focus(w);
win_add(w);
}

438
sowm.c
View File

@@ -7,22 +7,10 @@
#include <signal.h>
#include <unistd.h>
/*
This iterates over the current desktop's
window list and is inserted where needed.
*/
#define WIN (c=list;c;c=c->next)
/*
This sets focus to the given window. It
could very well be a function but I feel
it belongs here.
*/
#define FOC(W) XSetInputFocus(d, W, RevertToParent, CurrentTime);
typedef union {
const char** com;
const int i;
const Window w;
} Arg;
struct key {
@@ -32,21 +20,15 @@ struct key {
const Arg arg;
};
typedef struct client client;
struct client{
client *next, *prev;
Window w;
XWindowAttributes a;
int f;
};
typedef struct desktop desktop;
struct desktop{client *list;};
typedef struct client {
struct client *next, *prev;
int f, wx, wy;
unsigned int w, ww, wh;
} client;
static void button_press(XEvent *e);
static void button_release();
static void configure_request(XEvent *e);
static void key_grab();
static void key_press(XEvent *e);
static void map_request(XEvent *e);
static void notify_destroy(XEvent *e);
@@ -61,24 +43,16 @@ static void win_kill();
static void win_next();
static void win_to_ws(const Arg arg);
static void ws_go(const Arg arg);
static void ws_save(int i);
static void ws_sel(int i);
static int xerror() { return 0;}
static client *list = {0};
static desktop ws_list[10];
static int ws = 1, sh, sw, s, j;
static client *list = {0}, *ws_list[10] = {0};
static int ws = 1, sw, sh, wx, wy;
static unsigned int ww, wh;
static Display *d;
static Window root, cur;
static XButtonEvent mouse;
static XWindowAttributes attr;
static Display *d;
static Window root, cur;
static XButtonEvent mouse;
#include "config.h"
/*
The list of events to subscribe to and the paired functions
to call on an event.
*/
static void (*events[LASTEvent])(XEvent *e) = {
[ButtonPress] = button_press,
[ButtonRelease] = button_release,
@@ -90,167 +64,71 @@ static void (*events[LASTEvent])(XEvent *e) = {
[MotionNotify] = notify_motion
};
/*
'sowm' doesn't keep track of the currently focused window
and instead grabs window under the cursor when needed.
#include "config.h"
This is a super lazy way of handling current focus, however
it aligns perfectly with mouse-follows-focus.
#define win (client *c=list;c;c=c->next)
#define win_focus(W) XSetInputFocus(d, W, RevertToParent, CurrentTime)
#define ws_save(W) ws_list[W] = list
#define ws_sel(W) list = ws_list[ws = W]
Logic below will select a real window if this function
returns the 'root' window.
#define win_size(W, gx, gy, gw, gh) \
XGetGeometry(d, W, &(Window){0}, gx, gy, gw, gh, \
&(unsigned int){0}, &(unsigned int){0})
This function returns the current window while at the same
time defining a global variable to contain its value. This
allows for stupidily simple usage.
Example: if (win_current() != root) XKillClient(d, cur);
The value can be used as function output and then
the same value can be used as a variable directly afterwards.
*/
Window win_current() {
XGetInputFocus(d, &cur, &j);
XGetInputFocus(d, &cur, (int[]){1});
return cur;
}
/*
When a window is destroyed it is first removed from the
current desktop's window list and finally focus is shifted.
Focus goes to the window under the cursor if it is *not*
the root window. If it is the root window, focus goes to
the first window in the desktop.
*/
void notify_destroy(XEvent *e) {
win_del(e->xdestroywindow.window);
if (list) FOC(win_current() == root ? list->w : cur);
if (list) win_focus(win_current() == root ? list->w : cur);
}
/*
When the mouse enters or leaves a window this function
handles which window shall be focused next.
The while loop firstly compresses all 'EnterNotify'
events down to only the latest which is an optimization
when focus changes very quickly (e.g a desktop focus).
There's no use in computing each and every event as we
only really care about the newest one.
Focus is only then changed if the mouse has entered a
window which is *not* the root window.
*/
void notify_enter(XEvent *e) {
while(XCheckTypedEvent(d, EnterNotify, e));
if (e->xcrossing.window != root) FOC(e->xcrossing.window)
win_focus(e->xcrossing.window);
}
/*
When the mouse is moved and the paired modifier is
pressed this function handles a window move or a window
resize.
'mouse' is defined on a modifier+mouse press and then
discarded on a modifier+mouse release.
The while loop firstly compresses all 'MotionNotify'
events down to only the latest which is an optimization
when motion happens very quickly.
There's no use in computing each and every event as we
only really care about the newest one.
The window is then moved or resized and finally its
fullscreen value is reset to '0' (False).
*/
void notify_motion(XEvent *e) {
client *c;
if (mouse.subwindow == 0) return;
if (mouse.subwindow != None) {
int xd = e->xbutton.x_root - mouse.x_root;
int yd = e->xbutton.y_root - mouse.y_root;
int xd = e->xbutton.x_root - mouse.x_root;
int yd = e->xbutton.y_root - mouse.y_root;
while(XCheckTypedEvent(d, MotionNotify, e));
while(XCheckTypedEvent(d, MotionNotify, e));
XMoveResizeWindow(d, mouse.subwindow,
attr.x + (mouse.button==1 ? xd : 0),
attr.y + (mouse.button==1 ? yd : 0),
attr.width + (mouse.button==3 ? xd : 0),
attr.height + (mouse.button==3 ? yd : 0));
for WIN if (c->w == mouse.subwindow) c->f = 0;
}
XMoveResizeWindow(d, mouse.subwindow,
wx + (mouse.button == 1 ? xd : 0),
wy + (mouse.button == 1 ? yd : 0),
ww + (mouse.button == 3 ? xd : 0),
wh + (mouse.button == 3 ? yd : 0));
}
/*
This function initializes all key bindings defined in 'config.h'.
Simple stuff, nothing fancy or different from other window
managers happens here.
*/
void key_grab() {
KeyCode code;
for (int i=0; i < sizeof(keys)/sizeof(*keys); ++i)
if ((code = XKeysymToKeycode(d, keys[i].keysym)))
XGrabKey(d, code, keys[i].mod, root,
True, GrabModeAsync, GrabModeAsync);
}
/*
This function fires on a key press and checks to see if there
is a matching and defined key binding. If there is a match the
function bound to the key is executed.
The deprecated 'XKeycodeToKeysym' is used as the replacement
requires an additional include and I want to keep them to a
minimum.
I highly doubt this deprecated function goes away any time soon
and worst case, I simply update this code. Win-win.
*/
void key_press(XEvent *e) {
KeySym keysym = XKeycodeToKeysym(d, e->xkey.keycode, 0);
for (int i=0; i < sizeof(keys)/sizeof(*keys); ++i)
for (unsigned int i=0; i < sizeof(keys)/sizeof(*keys); ++i)
if (keys[i].keysym == keysym && keys[i].mod == e->xkey.state)
keys[i].function(keys[i].arg);
}
/*
On a mouse button press the window below the cursor's
attributes are stored, the window is raised and the 'mouse'
global is set.
Setting the 'mouse' global tells the motion handling function
that it should operate on the window as the user desires a move
or resize.
*/
void button_press(XEvent *e) {
if (e->xbutton.subwindow == None) return;
if (e->xbutton.subwindow == 0) return;
XGetWindowAttributes(d, e->xbutton.subwindow, &attr);
win_size(e->xbutton.subwindow, &wx, &wy, &ww, &wh);
XRaiseWindow(d, e->xbutton.subwindow);
mouse = e->xbutton;
}
/*
On a mouse button release we simply unset the 'mouse' global
as all of this mouse pointer nonsense is done.
*/
void button_release() {
mouse.subwindow = None;
for win if (c->w == mouse.subwindow) c->f = 0;
mouse.subwindow = 0;
}
/*
This function is called whenever a window is mapped to the
screen or moved to another desktop.
Memory is allocated for the new window and the current
desktop's window list is updated.
*/
void win_add(Window w) {
client *c, *t;
@@ -258,8 +136,7 @@ void win_add(Window w) {
exit(1);
if (!list) {
c->next = 0;
c->prev = 0;
c->next = c->prev = 0;
c->w = w;
list = c;
@@ -275,17 +152,8 @@ void win_add(Window w) {
ws_save(ws);
}
/*
This function is called whenever a window is destoyed
or moved to another desktop.
Memory is freed and the current desktop's window list
is updated.
*/
void win_del(Window w) {
client *c;
for WIN if (c->w == w) {
for win if (c->w == w) {
if (!c->prev && !c->next) {
free(list);
list = 0;
@@ -311,77 +179,31 @@ void win_del(Window w) {
}
}
/*
This function is called from a key binding to
close the currently focused window.
This differs from other window managers as we skip
the questions and go straight to the killing of
the window.
When I want to close a window I'm not asking, I
want the window closed and so it should immediately
close.
"Shoot first and don't ask questions later?.."
*/
void win_kill() {
if (win_current() != root) XKillClient(d, cur);
if (win_current() ^ root) XKillClient(d, cur);
}
/*
This function simply centers the window passed as
an argument. If the argument is '0', use the
currently focused window.
*/
void win_center(const Arg arg) {
Window w = arg.i ? arg.i : win_current();
Window w = arg.w ? arg.w : win_current();
XGetWindowAttributes(d, w, &attr);
win_size(w, &(int){0}, &(int){0}, &ww, &wh);
XMoveWindow(d, w, sw / 2 - attr.width / 2,
sh / 2 - attr.height / 2);
XMoveWindow(d, w, (sw - ww) / 2, (sh - wh) / 2);
}
/*
This function toggles the fullscreen state for the
window passed as an argument.
The window's data stucture holds an integer which
is set to '0' for False and '1' for True.
When a window is set to fullscreen it is simply
resized to fit the screen and the prior size and
positioning is stored so it can be restored when
the window is un-fullscreened.
*/
void win_fs() {
client *c;
win_current();
for WIN if (c->w == cur) {
for win if (c->w == cur) {
if ((c->f = c->f == 0 ? 1 : 0)) {
XGetWindowAttributes(d, cur, &c->a);
win_size(cur, &c->wx, &c->wy, &c->ww, &c->wh);
XMoveResizeWindow(d, cur, 0, 0, sw, sh);
} else
XMoveResizeWindow(d, cur, c->a.x, c->a.y, c->a.width, c->a.height);
XMoveResizeWindow(d, cur, c->wx, c->wy, c->ww, c->wh);
}
}
/*
This function simply moves the focused window to
the desired desktop.
It firstly adds the window to the destination
desktop's window list and secondly deletes it
from the current desktop's window list.
The window is then unmapped from the screen and
the focus is shifted to the first window in the
list.
*/
void win_to_ws(const Arg arg) {
int tmp = ws;
win_current();
@@ -397,45 +219,22 @@ void win_to_ws(const Arg arg) {
XUnmapWindow(d, cur);
ws_save(tmp);
if (list) FOC(list->w);
if (list) win_focus(list->w);
}
/*
This function focuses the next window in the
current desktop's window list.
If the end of the window list is reached it
wraps back around to the start of the list.
The newly focused window is then raised to
the top of the stack.
*/
void win_next() {
win_current();
client *c;
if (list) {
for WIN if (c->w == cur) break;
for win if (c->w == cur) {
c = c->next ? c->next : list;
FOC(c->w);
win_focus(c->w);
XRaiseWindow(d, c->w);
return;
}
}
/*
This function changes the focus to another desktop.
To make this operation invisible the destination
desktop's windows are mapped first and the previous
desktop's windows are then unmapped afterwards.
Finally, focus is shifted to the first window on the
destination desktop's window list.
*/
void ws_go(const Arg arg) {
client *c;
int tmp = ws;
if (arg.i == ws) return;
@@ -443,81 +242,43 @@ void ws_go(const Arg arg) {
ws_save(ws);
ws_sel(arg.i);
if (list) for WIN XMapWindow(d, c->w);
if (list) for win XMapWindow(d, c->w);
ws_sel(tmp);
if (list) for WIN XUnmapWindow(d, c->w);
if (list) for win XUnmapWindow(d, c->w);
ws_sel(arg.i);
if (list) FOC(list->w);
if (list) win_focus(list->w);
}
/*
This function saves the current desktop's window list.
Simple, nothing to see here.
*/
void ws_save(int i) {
ws_list[i].list = list;
}
/*
This function restores a saved desktop's window list.
Simple, nothing to see here.
*/
void ws_sel(int i) {
list = ws_list[i].list;
ws = i;
}
/*
This function allows a window to request a size,
position and other attributes.
This is required so programs like Firefox or MPV
are able to display and function correctly.
*/
void configure_request(XEvent *e) {
XConfigureRequestEvent *ev = &e->xconfigurerequest;
XWindowChanges wc;
wc.x = ev->x;
wc.y = ev->y;
wc.width = ev->width;
wc.height = ev->height;
wc.sibling = ev->above;
wc.stack_mode = ev->detail;
XConfigureWindow(d, ev->window, ev->value_mask, &wc);
XConfigureWindow(d, ev->window, ev->value_mask, &(XWindowChanges) {
.x = ev->x,
.y = ev->y,
.width = ev->width,
.height = ev->height,
.sibling = ev->above,
.stack_mode = ev->detail
});
}
/*
This function is executed whenever a window is mapped to
the screen.
The window is centered, mapped to the screen, focused and
finally added to the current desktop's window list.
'XSelectInput' is called to subscribe to various events
related to the window. For example, this is used to get
focus-follows-cursor to work.
*/
void map_request(XEvent *e) {
Window w = e->xmaprequest.window;
XSelectInput(d, w, PropertyChangeMask|StructureNotifyMask|
EnterWindowMask|FocusChangeMask);
win_center((Arg){.i = w});
XSelectInput(d, w, StructureNotifyMask|EnterWindowMask);
win_size(w, &wx, &wy, &ww, &wh);
if (wx == 0 && wy == 0) win_center((Arg){.i = w});
XMapWindow(d, w);
FOC(w);
win_focus(w);
win_add(w);
}
/*
This function is executed by keybindings to run the
specified program. Simple enough.
*/
void run(const Arg arg) {
if (fork()) return;
if (d) close(ConnectionNumber(d));
@@ -526,60 +287,31 @@ void run(const Arg arg) {
execvp((char*)arg.com[0], (char**)arg.com);
}
/*
This window manager ignores all Xorg related errors.
The window manager either crashes (due to Xorg or
itself) or it continues on its merry way.
The only errors which are handled are failed memory
allocations or a failure to open the display on start.
*/
int xerror(Display *d, XErrorEvent *e) {
return 0;
}
/*
Initialize the window manager by registering all
keybindings, setting some globals and starting the
event loop.
There's no 'XClosDisplay' or clean up as the only way
to exit this window manager is to kill the process.
This fires up Xorg's internal clean up which covers
everything allocated and executed here. It's free!
*/
int main(void) {
XEvent ev;
if (!(d = XOpenDisplay(0x0))) return 0;
if (!(d = XOpenDisplay(0))) exit(1);
signal(SIGCHLD, SIG_IGN);
XSetErrorHandler(xerror);
s = DefaultScreen(d);
root = RootWindow(d, s);
sw = XDisplayWidth(d, s);
sh = XDisplayHeight(d, s);
key_grab();
ws_go((Arg){.i = 1});
XSelectInput(d, root, SubstructureNotifyMask|
SubstructureRedirectMask|EnterWindowMask|LeaveWindowMask);
XGrabButton(d, 1, Mod4Mask, root, True,
ButtonPressMask|ButtonReleaseMask|PointerMotionMask,
GrabModeAsync, GrabModeAsync, None, None);
XGrabButton(d, 3, Mod4Mask, root, True,
ButtonPressMask|ButtonReleaseMask|PointerMotionMask,
GrabModeAsync, GrabModeAsync, None, None);
int s = DefaultScreen(d);
root = RootWindow(d, s);
sw = XDisplayWidth(d, s);
sh = XDisplayHeight(d, s);
XSelectInput(d, root, SubstructureRedirectMask);
XDefineCursor(d, root, XCreateFontCursor(d, 68));
while(1 && !XNextEvent(d, &ev))
for (unsigned int i=0; i < sizeof(keys)/sizeof(*keys); ++i)
XGrabKey(d, XKeysymToKeycode(d, keys[i].keysym), keys[i].mod,
root, True, GrabModeAsync, GrabModeAsync);
for (int i=1; i<4; i+=2)
XGrabButton(d, i, MOD, root, True,
ButtonPressMask|ButtonReleaseMask|PointerMotionMask,
GrabModeAsync, GrabModeAsync, 0, 0);
while (1 && !XNextEvent(d, &ev))
if (events[ev.type]) events[ev.type](&ev);
}