mirror of
https://github.com/dylanaraps/sowm.git
synced 2025-07-25 17:21:56 -07:00
Compare commits
145 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
d9f72fdffc | ||
|
fbf145e5af | ||
|
4a369b4ab2 | ||
|
37648b9576 | ||
|
710659f788 | ||
|
aae3efc546 | ||
|
16a80214b8 | ||
|
a9e3490de7 | ||
|
02f08fba01 | ||
|
c75d34b7b1 | ||
|
136c30403b | ||
|
d1535393aa | ||
|
0e6e6f469f | ||
|
a047141f91 | ||
|
196e8db5f6 | ||
|
b5eca40b64 | ||
|
3e711082e7 | ||
|
2e4015f988 | ||
|
a743d166fe | ||
|
5c998e05f4 | ||
|
04b35c3f5e | ||
|
1a4c655b9d | ||
|
d327a0978a | ||
|
0964d47d07 | ||
|
6ca1ff91a4 | ||
|
dabe77272b | ||
|
ea47780ab0 | ||
|
0ed080b99c | ||
|
7e4466e38e | ||
|
56bdacaa84 | ||
|
e22087856b | ||
|
f201a467ea | ||
|
7821aac0d2 | ||
|
a1c80d9b23 | ||
|
0df345e1da | ||
|
b5087acaac | ||
|
3ed647f467 | ||
|
e491a637fe | ||
|
21a35be863 | ||
|
5547cc3a51 | ||
|
67d323458c | ||
|
0004ff3e18 | ||
|
5cc5d25823 | ||
|
0e8cc9fe86 | ||
|
2c3c353d74 | ||
|
69f2c71fb7 | ||
|
a31091472a | ||
|
1d249a96ef | ||
|
f558535e19 | ||
|
243cab5deb | ||
|
4f18161758 | ||
|
087e276736 | ||
|
c1b252bc6d | ||
|
4aa7d1a4d6 | ||
|
facbfcf061 | ||
|
e0d0415d06 | ||
|
ec79ff991a | ||
|
5675787b03 | ||
|
e3306e109b | ||
|
893b45b2de | ||
|
1cce61e186 | ||
|
66336521ed | ||
|
85ee7ec48e | ||
|
307001f472 | ||
|
d9b0c72fc9 | ||
|
a199d34a45 | ||
|
13f874ead7 | ||
|
09a514cd5e | ||
|
8ee3294adf | ||
|
bac7f781b6 | ||
|
623f4d8bc1 | ||
|
dcaf873fec | ||
|
aaabcb8049 | ||
|
3efaa6decc | ||
|
1d37651391 | ||
|
62959ded52 | ||
|
5423c9172b | ||
|
8acd15de63 | ||
|
f7fd37e326 | ||
|
6d6889e3cf | ||
|
8ff3eee874 | ||
|
0b7a277b22 | ||
|
124ec67579 | ||
|
93135664c2 | ||
|
3e4010a0ca | ||
|
6b12178131 | ||
|
9a634e6134 | ||
|
275488384a | ||
|
9a206d6c9d | ||
|
51a96547ef | ||
|
1fb75817aa | ||
|
df34385548 | ||
|
c6ff8d06a0 | ||
|
4dd50e6f4f | ||
|
4867928d57 | ||
|
afa8b1871f | ||
|
216e462841 | ||
|
425ae0f698 | ||
|
8f1b7c28df | ||
|
818480983f | ||
|
b7b08941d5 | ||
|
d37d04ef32 | ||
|
2292f86d7f | ||
|
31bf57b69a | ||
|
d79361b13e | ||
|
7921a93eef | ||
|
a5853ab69a | ||
|
e4965417f7 | ||
|
bc9a9b14a5 | ||
|
421f79c47b | ||
|
cb03ac9664 | ||
|
5b012c10be | ||
|
35b12c7969 | ||
|
e9df9ac570 | ||
|
f14acc3b68 | ||
|
117b04d4a6 | ||
|
0d4af0e4fa | ||
|
43c7194066 | ||
|
144c153844 | ||
|
2d1e5c2654 | ||
|
d70ecee07d | ||
|
fa3c276ce6 | ||
|
7316c149b8 | ||
|
589bb768d9 | ||
|
84119dd331 | ||
|
5c075a359a | ||
|
b48c9b6add | ||
|
a4293a63a7 | ||
|
e60a3bcb30 | ||
|
4ed0c0919f | ||
|
d6b7a98586 | ||
|
3f66256197 | ||
|
7fe47aefc1 | ||
|
0fa485eb7b | ||
|
d1e8ee5e67 | ||
|
ef61316b5f | ||
|
116ebcfc74 | ||
|
493302d38b | ||
|
f10cec8509 | ||
|
02b10e8585 | ||
|
8917b6ddb2 | ||
|
522defba1e | ||
|
e0bd38091a | ||
|
68257b329d | ||
|
009f1cd017 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
sowm
|
||||
sowm.o
|
||||
config.h
|
||||
.ccls-cache
|
||||
src/*.o
|
||||
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2019-2020 Dylan Araps
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
33
LICENSE.md
33
LICENSE.md
@@ -1,33 +0,0 @@
|
||||
MIT/X Consortium License
|
||||
|
||||
- © 2019- Dylan Araps <dylan.araps@gmail.com>
|
||||
- © 2006-2011 Anselm R Garbe <anselm@garbe.us>
|
||||
- © 2007-2011 Peter Hartlich <sgkkr at hartlich dot com>
|
||||
- © 2010-2011 Connor Lane Smith <cls@lubutu.com>
|
||||
- © 2006-2009 Jukka Salmi <jukka at salmi dot ch>
|
||||
- © 2007-2009 Premysl Hruby <dfenze at gmail dot com>
|
||||
- © 2007-2009 Szabolcs Nagy <nszabolcs at gmail dot com>
|
||||
- © 2007-2009 Christof Musik <christof at sendfax dot de>
|
||||
- © 2009 Mate Nagy <mnagy at port70 dot net>
|
||||
- © 2007-2008 Enno Gottox Boland <gottox at s01 dot de>
|
||||
- © 2008 Martin Hurton <martin dot hurton at gmail dot com>
|
||||
- © 2008 Neale Pickett <neale dot woozle dot org>
|
||||
- © 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
37
Makefile
37
Makefile
@@ -1,21 +1,32 @@
|
||||
CFLAGS+= -std=c99 -Wall -Wextra -pedantic -Wno-deprecated-declarations
|
||||
LDADD+= -lX11
|
||||
LDFLAGS=
|
||||
PREFIX?= /usr
|
||||
BINDIR?= $(PREFIX)/bin
|
||||
.POSIX:
|
||||
|
||||
CC ?= gcc
|
||||
PREFIX = /usr/local
|
||||
|
||||
all: config.h sowm
|
||||
ALL_WARN = -Wall -Wextra -pedantic -Wmissing-prototypes -Wstrict-prototypes
|
||||
ALL_CFLAGS = $(CFLAGS) $(CPPFLAGS) -std=c99 $(ALL_WARN)
|
||||
ALL_LDFLAGS = $(LDFLAGS) $(LIBS) -lxcb
|
||||
|
||||
config.h:
|
||||
cp config.def.h config.h
|
||||
CC = cc
|
||||
|
||||
sowm: sowm.o
|
||||
$(CC) $(LDFLAGS) -O3 -o $@ $+ $(LDADD)
|
||||
OBJ = src/event.o src/sowm.o
|
||||
HDR = src/event.h src/globals.h
|
||||
|
||||
install: all
|
||||
install -Dm 755 sowm $(DESTDIR)$(BINDIR)/sowm
|
||||
.c.o:
|
||||
$(CC) $(ALL_CFLAGS) -c -o $@ $<
|
||||
|
||||
sowm: $(OBJ)
|
||||
$(CC) $(ALL_CFLAGS) -o $@ $(OBJ) $(ALL_LDFLAGS)
|
||||
|
||||
$(OBJ): $(HDR)
|
||||
|
||||
install: sowm
|
||||
mkdir -p $(DESTDIR)/bin
|
||||
cp sowm $(DESTDIR)/bin/sowm
|
||||
|
||||
uninstall:
|
||||
rm -f $(DESTDIR)/bin/sowm
|
||||
|
||||
clean:
|
||||
rm -f sowm *.o
|
||||
|
||||
.PHONY: install uninstall clean
|
||||
|
3
README
Normal file
3
README
Normal file
@@ -0,0 +1,3 @@
|
||||
SOWM (Simple Opinionated Window Manager)
|
||||
________________________________________________________________________________
|
||||
|
82
README.md
82
README.md
@@ -1,82 +0,0 @@
|
||||
# sowm
|
||||
|
||||
<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 (*240~ sloc / 24kb compiled!*).
|
||||
|
||||
- Floating only.
|
||||
- Fullscreen toggle.
|
||||
- Window centering.
|
||||
- Mix of mouse and keyboard workflow.
|
||||
- Focus with cursor.
|
||||
- Rounded corners (*[through patch](https://github.com/dylanaraps/sowm/blob/master/patches/sowm-rounded-corners.patch)*)
|
||||
|
||||
<a href="https://user-images.githubusercontent.com/6799467/66687814-8cd9f800-ec73-11e9-97b8-6ae77876bd1b.jpg"><img src="https://user-images.githubusercontent.com/6799467/66687814-8cd9f800-ec73-11e9-97b8-6ae77876bd1b.jpg" width="43%" align="right"></a>
|
||||
|
||||
- Alt-Tab window focusing.
|
||||
- All windows die on exit.
|
||||
- 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
|
||||
|
||||
|
||||
<br>
|
||||
|
||||
## Default Keybindings
|
||||
|
||||
**Window Management**
|
||||
|
||||
| combo | action |
|
||||
| -------------------------- | -----------------------|
|
||||
| `Mouse` | focus under cursor |
|
||||
| `MOD4` + `Left Mouse` | move window |
|
||||
| `MOD4` + `Right Mouse` | resize window |
|
||||
| `MOD4` + `f` | maximize toggle |
|
||||
| `MOD4` + `c` | center window |
|
||||
| `MOD4` + `q` | kill window |
|
||||
| `MOD4` + `1-9` | desktop swap |
|
||||
| `MOD4` + `Shift` +`1-9` | send window to desktop |
|
||||
| `MOD1` + `TAB` (*alt-tab*) | focus cycle |
|
||||
|
||||
**Programs**
|
||||
|
||||
| combo | action | program |
|
||||
| ------------------------ | ---------------- | -------------- |
|
||||
| `MOD4` + `Return` | terminal | `st` |
|
||||
| `MOD4` + `d` | dmenu | `dmenu_run` |
|
||||
| `MOD4` + `p` | scrot | `scr` |
|
||||
| `MOD4` + `w` | wallpaper cycler | `bud` |
|
||||
| `XF86_AudioLowerVolume` | volume down | `amixer` |
|
||||
| `XF86_AudioRaiseVolume` | volume up | `amixer` |
|
||||
| `XF86_AudioMute` | volume toggle | `amixer` |
|
||||
| `XF86_MonBrightnessUp` | brightness up | `bri` |
|
||||
| `XF86_MonBrightnessDown` | brightness down | `bri` |
|
||||
|
||||
|
||||
## Dependencies
|
||||
|
||||
- `xlib` (*usually `libX11`*).
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
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.
|
||||
|
||||
|
||||
## Thanks
|
||||
|
||||
- 2bwm
|
||||
- SmallWM
|
||||
- berry
|
||||
- catwm
|
||||
- dminiwm
|
||||
- dwm
|
||||
- monsterwm
|
||||
- openbox
|
||||
- possumwm
|
||||
- swm
|
||||
- tinywm
|
47
config.def.h
47
config.def.h
@@ -1,47 +0,0 @@
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#define MOD Mod4Mask
|
||||
|
||||
const char* menu[] = {"dmenu_run", 0};
|
||||
const char* term[] = {"st", 0};
|
||||
const char* scrot[] = {"scr", 0};
|
||||
const char* briup[] = {"bri", "10", "+", 0};
|
||||
const char* bridown[] = {"bri", "10", "-", 0};
|
||||
const char* voldown[] = {"amixer", "sset", "Master", "5%-", 0};
|
||||
const char* volup[] = {"amixer", "sset", "Master", "5%+", 0};
|
||||
const char* volmute[] = {"amixer", "sset", "Master", "toggle", 0};
|
||||
const char* colors[] = {"bud", "/home/goldie/Pictures/Wallpapers", 0};
|
||||
|
||||
static struct key keys[] = {
|
||||
{MOD, XK_q, win_kill, {0}},
|
||||
{MOD, XK_c, win_center, {.w = 0}},
|
||||
{MOD, XK_f, win_fs, {0}},
|
||||
{Mod1Mask, XK_Tab, win_next, {0}},
|
||||
|
||||
{MOD, XK_d, run, {.com = menu}},
|
||||
{MOD, XK_w, run, {.com = colors}},
|
||||
{MOD, XK_p, run, {.com = scrot}},
|
||||
{MOD, XK_Return, run, {.com = term}},
|
||||
|
||||
{0, XF86XK_AudioLowerVolume, run, {.com = voldown}},
|
||||
{0, XF86XK_AudioRaiseVolume, run, {.com = volup}},
|
||||
{0, XF86XK_AudioMute, run, {.com = volmute}},
|
||||
{0, XF86XK_MonBrightnessUp, run, {.com = briup}},
|
||||
{0, XF86XK_MonBrightnessDown, run, {.com = bridown}},
|
||||
|
||||
{MOD, XK_1, ws_go, {.i = 1}},
|
||||
{MOD|ShiftMask, XK_1, win_to_ws, {.i = 1}},
|
||||
{MOD, XK_2, ws_go, {.i = 2}},
|
||||
{MOD|ShiftMask, XK_2, win_to_ws, {.i = 2}},
|
||||
{MOD, XK_3, ws_go, {.i = 3}},
|
||||
{MOD|ShiftMask, XK_3, win_to_ws, {.i = 3}},
|
||||
{MOD, XK_4, ws_go, {.i = 4}},
|
||||
{MOD|ShiftMask, XK_4, win_to_ws, {.i = 4}},
|
||||
{MOD, XK_5, ws_go, {.i = 5}},
|
||||
{MOD|ShiftMask, XK_5, win_to_ws, {.i = 5}},
|
||||
{MOD, XK_6, ws_go, {.i = 6}},
|
||||
{MOD|ShiftMask, XK_6, win_to_ws, {.i = 6}},
|
||||
};
|
||||
|
||||
#endif
|
4
design.txt
Normal file
4
design.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
keybindings
|
||||
events
|
||||
actions
|
||||
manager
|
@@ -1,51 +0,0 @@
|
||||
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) {
|
@@ -1,106 +0,0 @@
|
||||
diff --git a/Makefile b/Makefile
|
||||
index 3154a2f..243b744 100644
|
||||
--- a/Makefile
|
||||
+++ b/Makefile
|
||||
@@ -1,5 +1,5 @@
|
||||
CFLAGS+= -std=c99 -Wall -Wextra -pedantic -Wno-deprecated-declarations
|
||||
-LDADD+= -lX11
|
||||
+LDADD+= -lX11 -lXext
|
||||
LDFLAGS=
|
||||
PREFIX?= /usr
|
||||
BINDIR?= $(PREFIX)/bin
|
||||
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 126aca0..5c99c5c 100644
|
||||
--- a/sowm.c
|
||||
+++ b/sowm.c
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/XF86keysym.h>
|
||||
#include <X11/keysym.h>
|
||||
+#include <X11/extensions/shape.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
@@ -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 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));
|
||||
+
|
||||
+ if (mouse.button == 3)
|
||||
+ win_round_corners(mouse.subwindow, ROUND_CORNERS);
|
||||
}
|
||||
|
||||
void key_press(XEvent *e) {
|
||||
@@ -201,9 +206,44 @@ void win_fs() {
|
||||
|
||||
} else
|
||||
XMoveResizeWindow(d, cur, c->wx, c->wy, c->ww, c->wh);
|
||||
+
|
||||
+ win_round_corners(cur, c->f ? 0 : ROUND_CORNERS);
|
||||
}
|
||||
}
|
||||
|
||||
+void win_round_corners(Window w, int rad) {
|
||||
+ unsigned int ww, wh, dia = 2 * rad;
|
||||
+
|
||||
+ win_size(w, &(int){1}, &(int){1}, &ww, &wh);
|
||||
+
|
||||
+ if (ww < dia || wh < dia) return;
|
||||
+
|
||||
+ Pixmap mask = XCreatePixmap(d, w, ww, wh, 1);
|
||||
+
|
||||
+ if (!mask) return;
|
||||
+
|
||||
+ XGCValues xgcv;
|
||||
+ GC shape_gc = XCreateGC(d, mask, 0, &xgcv);
|
||||
+
|
||||
+ if (!shape_gc) {
|
||||
+ XFreePixmap(d, mask);
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ XSetForeground(d, shape_gc, 0);
|
||||
+ XFillRectangle(d, mask, shape_gc, 0, 0, ww, wh);
|
||||
+ XSetForeground(d, shape_gc, 1);
|
||||
+ XFillArc(d, mask, shape_gc, 0, 0, dia, dia, 0, 23040);
|
||||
+ XFillArc(d, mask, shape_gc, ww-dia-1, 0, dia, dia, 0, 23040);
|
||||
+ XFillArc(d, mask, shape_gc, 0, wh-dia-1, dia, dia, 0, 23040);
|
||||
+ XFillArc(d, mask, shape_gc, ww-dia-1, wh-dia-1, dia, dia, 0, 23040);
|
||||
+ XFillRectangle(d, mask, shape_gc, rad, 0, ww-dia, wh);
|
||||
+ XFillRectangle(d, mask, shape_gc, 0, rad, ww, wh-dia);
|
||||
+ XShapeCombineMask(d, w, ShapeBounding, 0, 0, mask, ShapeSet);
|
||||
+ XFreePixmap(d, mask);
|
||||
+ XFreeGC(d, shape_gc);
|
||||
+}
|
||||
+
|
||||
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);
|
||||
win_focus(w);
|
||||
win_add(w);
|
||||
}
|
317
sowm.c
317
sowm.c
@@ -1,317 +0,0 @@
|
||||
// sowm - An itsy bitsy floating window manager.
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/XF86keysym.h>
|
||||
#include <X11/keysym.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
typedef union {
|
||||
const char** com;
|
||||
const int i;
|
||||
const Window w;
|
||||
} Arg;
|
||||
|
||||
struct key {
|
||||
unsigned int mod;
|
||||
KeySym keysym;
|
||||
void (*function)(const Arg arg);
|
||||
const Arg arg;
|
||||
};
|
||||
|
||||
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_press(XEvent *e);
|
||||
static void map_request(XEvent *e);
|
||||
static void notify_destroy(XEvent *e);
|
||||
static void notify_enter(XEvent *e);
|
||||
static void notify_motion(XEvent *e);
|
||||
static void run(const Arg arg);
|
||||
static void win_add(Window w);
|
||||
static void win_center(const Arg arg);
|
||||
static void win_del(Window w);
|
||||
static void win_fs();
|
||||
static void win_kill();
|
||||
static void win_next();
|
||||
static void win_to_ws(const Arg arg);
|
||||
static void ws_go(const Arg arg);
|
||||
static int xerror() { return 0;}
|
||||
|
||||
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 void (*events[LASTEvent])(XEvent *e) = {
|
||||
[ButtonPress] = button_press,
|
||||
[ButtonRelease] = button_release,
|
||||
[ConfigureRequest] = configure_request,
|
||||
[KeyPress] = key_press,
|
||||
[MapRequest] = map_request,
|
||||
[DestroyNotify] = notify_destroy,
|
||||
[EnterNotify] = notify_enter,
|
||||
[MotionNotify] = notify_motion
|
||||
};
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#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]
|
||||
|
||||
#define win_size(W, gx, gy, gw, gh) \
|
||||
XGetGeometry(d, W, &(Window){0}, gx, gy, gw, gh, \
|
||||
&(unsigned int){0}, &(unsigned int){0})
|
||||
|
||||
Window win_current() {
|
||||
XGetInputFocus(d, &cur, (int[]){1});
|
||||
return cur;
|
||||
}
|
||||
|
||||
void notify_destroy(XEvent *e) {
|
||||
win_del(e->xdestroywindow.window);
|
||||
|
||||
if (list) win_focus(win_current() == root ? list->w : cur);
|
||||
}
|
||||
|
||||
void notify_enter(XEvent *e) {
|
||||
while(XCheckTypedEvent(d, EnterNotify, e));
|
||||
|
||||
win_focus(e->xcrossing.window);
|
||||
}
|
||||
|
||||
void notify_motion(XEvent *e) {
|
||||
if (mouse.subwindow == 0) return;
|
||||
|
||||
int xd = e->xbutton.x_root - mouse.x_root;
|
||||
int yd = e->xbutton.y_root - mouse.y_root;
|
||||
|
||||
while(XCheckTypedEvent(d, MotionNotify, e));
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
void key_press(XEvent *e) {
|
||||
KeySym keysym = XKeycodeToKeysym(d, e->xkey.keycode, 0);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void button_press(XEvent *e) {
|
||||
if (e->xbutton.subwindow == 0) return;
|
||||
|
||||
win_size(e->xbutton.subwindow, &wx, &wy, &ww, &wh);
|
||||
XRaiseWindow(d, e->xbutton.subwindow);
|
||||
mouse = e->xbutton;
|
||||
}
|
||||
|
||||
void button_release() {
|
||||
for win if (c->w == mouse.subwindow) c->f = 0;
|
||||
|
||||
mouse.subwindow = 0;
|
||||
}
|
||||
|
||||
void win_add(Window w) {
|
||||
client *c, *t;
|
||||
|
||||
if (!(c = (client *)calloc(1, sizeof(client))))
|
||||
exit(1);
|
||||
|
||||
if (!list) {
|
||||
c->next = c->prev = 0;
|
||||
c->w = w;
|
||||
list = c;
|
||||
|
||||
} else {
|
||||
for (t=list;t->next;t=t->next);
|
||||
|
||||
c->next = 0;
|
||||
c->prev = t;
|
||||
c->w = w;
|
||||
t->next = c;
|
||||
}
|
||||
|
||||
ws_save(ws);
|
||||
}
|
||||
|
||||
void win_del(Window w) {
|
||||
for win if (c->w == w) {
|
||||
if (!c->prev && !c->next) {
|
||||
free(list);
|
||||
list = 0;
|
||||
ws_save(ws);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!c->prev) {
|
||||
list = c->next;
|
||||
c->next->prev = 0;
|
||||
|
||||
} else if (!c->next) {
|
||||
c->prev->next = 0;
|
||||
|
||||
} else {
|
||||
c->prev->next = c->next;
|
||||
c->next->prev = c->prev;
|
||||
}
|
||||
|
||||
free(c);
|
||||
ws_save(ws);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void win_kill() {
|
||||
if (win_current() ^ root) XKillClient(d, cur);
|
||||
}
|
||||
|
||||
void win_center(const Arg arg) {
|
||||
Window w = arg.w ? arg.w : win_current();
|
||||
|
||||
win_size(w, &(int){0}, &(int){0}, &ww, &wh);
|
||||
|
||||
XMoveWindow(d, w, (sw - ww) / 2, (sh - wh) / 2);
|
||||
}
|
||||
|
||||
void win_fs() {
|
||||
win_current();
|
||||
|
||||
for win if (c->w == cur) {
|
||||
if ((c->f = c->f == 0 ? 1 : 0)) {
|
||||
win_size(cur, &c->wx, &c->wy, &c->ww, &c->wh);
|
||||
XMoveResizeWindow(d, cur, 0, 0, sw, sh);
|
||||
|
||||
} else
|
||||
XMoveResizeWindow(d, cur, c->wx, c->wy, c->ww, c->wh);
|
||||
}
|
||||
}
|
||||
|
||||
void win_to_ws(const Arg arg) {
|
||||
int tmp = ws;
|
||||
win_current();
|
||||
|
||||
if (arg.i == tmp) return;
|
||||
|
||||
ws_sel(arg.i);
|
||||
win_add(cur);
|
||||
ws_save(arg.i);
|
||||
|
||||
ws_sel(tmp);
|
||||
win_del(cur);
|
||||
XUnmapWindow(d, cur);
|
||||
ws_save(tmp);
|
||||
|
||||
if (list) win_focus(list->w);
|
||||
}
|
||||
|
||||
void win_next() {
|
||||
win_current();
|
||||
|
||||
for win if (c->w == cur) {
|
||||
c = c->next ? c->next : list;
|
||||
|
||||
win_focus(c->w);
|
||||
XRaiseWindow(d, c->w);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void ws_go(const Arg arg) {
|
||||
int tmp = ws;
|
||||
|
||||
if (arg.i == ws) return;
|
||||
|
||||
ws_save(ws);
|
||||
ws_sel(arg.i);
|
||||
|
||||
if (list) for win XMapWindow(d, c->w);
|
||||
|
||||
ws_sel(tmp);
|
||||
|
||||
if (list) for win XUnmapWindow(d, c->w);
|
||||
|
||||
ws_sel(arg.i);
|
||||
|
||||
if (list) win_focus(list->w);
|
||||
}
|
||||
|
||||
void configure_request(XEvent *e) {
|
||||
XConfigureRequestEvent *ev = &e->xconfigurerequest;
|
||||
|
||||
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
|
||||
});
|
||||
}
|
||||
|
||||
void map_request(XEvent *e) {
|
||||
Window w = e->xmaprequest.window;
|
||||
|
||||
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);
|
||||
win_focus(w);
|
||||
win_add(w);
|
||||
}
|
||||
|
||||
void run(const Arg arg) {
|
||||
if (fork()) return;
|
||||
if (d) close(ConnectionNumber(d));
|
||||
|
||||
setsid();
|
||||
execvp((char*)arg.com[0], (char**)arg.com);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
XEvent ev;
|
||||
|
||||
if (!(d = XOpenDisplay(0))) exit(1);
|
||||
|
||||
signal(SIGCHLD, SIG_IGN);
|
||||
XSetErrorHandler(xerror);
|
||||
|
||||
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));
|
||||
|
||||
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);
|
||||
}
|
125
src/event.c
Normal file
125
src/event.c
Normal file
@@ -0,0 +1,125 @@
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
#include "globals.h"
|
||||
#include "event.h"
|
||||
|
||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
|
||||
static xcb_window_t motion_win;
|
||||
|
||||
void (*events[XCB_NO_OPERATION])(xcb_generic_event_t *) = {
|
||||
[XCB_BUTTON_PRESS] = event_button_press,
|
||||
[XCB_BUTTON_RELEASE] = event_button_release,
|
||||
/* [XCB_CONFIGURE_REQUEST] = event_configure_request, */
|
||||
/* [XCB_KEY_PRESS] = event_key_press, */
|
||||
[XCB_CREATE_NOTIFY] = event_notify_create,
|
||||
/* [XCB_DESTROY_NOTIFY] = event_notify_destroy, */
|
||||
[XCB_ENTER_NOTIFY] = event_notify_enter,
|
||||
[XCB_MOTION_NOTIFY] = event_notify_motion
|
||||
};
|
||||
|
||||
void event_button_press(xcb_generic_event_t *ev) {
|
||||
xcb_button_press_event_t *e = (xcb_button_press_event_t *)ev;
|
||||
xcb_get_geometry_reply_t *geom;
|
||||
uint32_t value;
|
||||
|
||||
if (!e->child) {
|
||||
return;
|
||||
}
|
||||
|
||||
motion_win = e->child;
|
||||
value = XCB_STACK_MODE_ABOVE;
|
||||
|
||||
xcb_configure_window(dpy, e->child,
|
||||
XCB_CONFIG_WINDOW_STACK_MODE, &value);
|
||||
|
||||
geom = xcb_get_geometry_reply(dpy,
|
||||
xcb_get_geometry(dpy, e->child), NULL);
|
||||
|
||||
xcb_warp_pointer(dpy, XCB_NONE, e->child, 0, 0, 0, 0,
|
||||
e->detail != 1 ? geom->width : 1,
|
||||
e->detail != 1 ? geom->height : 1);
|
||||
|
||||
xcb_grab_pointer(dpy, 0, scr->root, XCB_EVENT_MASK_BUTTON_RELEASE |
|
||||
XCB_EVENT_MASK_BUTTON_MOTION | XCB_EVENT_MASK_POINTER_MOTION_HINT,
|
||||
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, scr->root, XCB_NONE,
|
||||
XCB_CURRENT_TIME);
|
||||
}
|
||||
|
||||
void event_button_release(xcb_generic_event_t *ev) {
|
||||
(void)(ev);
|
||||
xcb_ungrab_pointer(dpy, XCB_CURRENT_TIME);
|
||||
motion_win = 0;
|
||||
}
|
||||
|
||||
/* void event_configure_request(xcb_generic_event_t *ev) { */
|
||||
|
||||
/* } */
|
||||
|
||||
/* void event_key_press(xcb_generic_event_t *ev) { */
|
||||
|
||||
/* } */
|
||||
|
||||
void event_notify_create(xcb_generic_event_t *ev) {
|
||||
xcb_create_notify_event_t *e = (xcb_create_notify_event_t *)ev;
|
||||
uint32_t value;
|
||||
|
||||
value = XCB_EVENT_MASK_ENTER_WINDOW |
|
||||
XCB_EVENT_MASK_FOCUS_CHANGE |
|
||||
XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY;
|
||||
|
||||
xcb_change_window_attributes(dpy, e->window, XCB_CW_EVENT_MASK, &value);
|
||||
xcb_map_window(dpy, e->window);
|
||||
|
||||
xcb_set_input_focus(dpy, XCB_INPUT_FOCUS_POINTER_ROOT,
|
||||
e->window, XCB_CURRENT_TIME);
|
||||
}
|
||||
|
||||
/* void event_notify_destroy(xcb_generic_event_t *ev) { */
|
||||
|
||||
/* } */
|
||||
|
||||
void event_notify_enter(xcb_generic_event_t *ev) {
|
||||
xcb_enter_notify_event_t *e = (xcb_enter_notify_event_t *)ev;
|
||||
|
||||
if (!e->event || e->event == scr->root) {
|
||||
return;
|
||||
}
|
||||
|
||||
xcb_set_input_focus(dpy, XCB_INPUT_FOCUS_POINTER_ROOT,
|
||||
e->event, XCB_CURRENT_TIME);
|
||||
}
|
||||
|
||||
void event_notify_motion(xcb_generic_event_t *ev) {
|
||||
xcb_motion_notify_event_t *e = (xcb_motion_notify_event_t *)ev;
|
||||
xcb_query_pointer_reply_t *ptr;
|
||||
xcb_get_geometry_reply_t *geom;
|
||||
uint32_t values[2];
|
||||
|
||||
if (!motion_win || motion_win == scr->root) {
|
||||
return;
|
||||
}
|
||||
|
||||
ptr = xcb_query_pointer_reply(dpy, xcb_query_pointer(dpy, scr->root), 0);
|
||||
geom = xcb_get_geometry_reply(dpy, xcb_get_geometry(dpy, motion_win), NULL);
|
||||
|
||||
/* move */
|
||||
if (e->state & XCB_BUTTON_MASK_1) {
|
||||
values[0] = (ptr->root_x + geom->width > scr->width_in_pixels)?
|
||||
(scr->width_in_pixels - geom->width):ptr->root_x;
|
||||
|
||||
values[1] = (ptr->root_y + geom->height > scr->height_in_pixels)?
|
||||
(scr->height_in_pixels - geom->height):ptr->root_y;
|
||||
|
||||
xcb_configure_window(dpy, motion_win,
|
||||
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, values);
|
||||
|
||||
/* resize */
|
||||
} else if (e->state & XCB_BUTTON_MASK_3) {
|
||||
values[0] = MAX(10, ptr->root_x - geom->x);
|
||||
values[1] = MAX(10, ptr->root_y - geom->y);
|
||||
|
||||
xcb_configure_window(dpy, motion_win,
|
||||
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, values);
|
||||
}
|
||||
}
|
12
src/event.h
Normal file
12
src/event.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
void event_button_press(xcb_generic_event_t *ev);
|
||||
void event_button_release(xcb_generic_event_t *ev);
|
||||
/* void event_configure_request(xcb_generic_event_t *ev); */
|
||||
/* void event_key_press(xcb_generic_event_t *ev); */
|
||||
void event_notify_create(xcb_generic_event_t *ev);
|
||||
/* void event_notify_destroy(xcb_generic_event_t *ev); */
|
||||
void event_notify_enter(xcb_generic_event_t *ev);
|
||||
void event_notify_motion(xcb_generic_event_t *ev);
|
||||
|
||||
extern void (*events[XCB_NO_OPERATION])(xcb_generic_event_t *);
|
11
src/globals.h
Normal file
11
src/globals.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
extern xcb_connection_t *dpy;
|
||||
extern xcb_screen_t *scr;
|
||||
|
||||
struct desktop {
|
||||
xcb_window_t *windows;
|
||||
int num;
|
||||
};
|
||||
|
||||
extern int current_desktop;
|
102
src/sowm.c
Normal file
102
src/sowm.c
Normal file
@@ -0,0 +1,102 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
#include "event.h"
|
||||
#include "vec.h"
|
||||
#include "globals.h"
|
||||
#include "config.h"
|
||||
|
||||
static void init_wm(void);
|
||||
static void init_input(void);
|
||||
static void init_desktops(void);
|
||||
|
||||
xcb_connection_t *dpy;
|
||||
xcb_screen_t *scr;
|
||||
|
||||
struct desktop *desktops;
|
||||
int current_desktop = 0;
|
||||
|
||||
static void init_wm() {
|
||||
uint32_t values;
|
||||
|
||||
dpy = xcb_connect(NULL, NULL);
|
||||
|
||||
if (xcb_connection_has_error(dpy)) {
|
||||
printf("error: Failed to start sowm\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
scr = xcb_setup_roots_iterator(xcb_get_setup(dpy)).data;
|
||||
|
||||
if (!scr) {
|
||||
printf("error: Failed to assign screen number\n");
|
||||
xcb_disconnect(dpy);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
values = XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY;
|
||||
|
||||
xcb_change_window_attributes_checked(dpy, scr->root,
|
||||
XCB_CW_EVENT_MASK, &values);
|
||||
|
||||
xcb_flush(dpy);
|
||||
}
|
||||
|
||||
static void init_input() {
|
||||
xcb_grab_key(dpy, 1, scr->root, SOWM_MOD, XCB_NO_SYMBOL,
|
||||
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
|
||||
|
||||
xcb_grab_button(dpy, 0, scr->root, XCB_EVENT_MASK_BUTTON_PRESS |
|
||||
XCB_EVENT_MASK_BUTTON_RELEASE, XCB_GRAB_MODE_ASYNC,
|
||||
XCB_GRAB_MODE_ASYNC, scr->root, XCB_NONE, 1, SOWM_MOD);
|
||||
|
||||
xcb_grab_button(dpy, 0, scr->root, XCB_EVENT_MASK_BUTTON_PRESS |
|
||||
XCB_EVENT_MASK_BUTTON_RELEASE, XCB_GRAB_MODE_ASYNC,
|
||||
XCB_GRAB_MODE_ASYNC, scr->root, XCB_NONE, 3, SOWM_MOD);
|
||||
|
||||
xcb_flush(dpy);
|
||||
}
|
||||
|
||||
static void init_desktops() {
|
||||
struct desktop new = {0};
|
||||
|
||||
for (int i = 0; i < SOWM_NUM_DESKTOPS; i++) {
|
||||
new.num = i;
|
||||
vec_push_back(desktops, new);
|
||||
}
|
||||
|
||||
/* todo finish usage of desktops */
|
||||
vec_free(desktops);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
xcb_generic_event_t *ev;
|
||||
unsigned int ev_type;
|
||||
|
||||
/* unused */
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
/* we don't want sigchld */
|
||||
signal(SIGCHLD, SIG_IGN);
|
||||
|
||||
init_wm();
|
||||
init_input();
|
||||
init_desktops();
|
||||
|
||||
while ((ev = xcb_wait_for_event(dpy))) {
|
||||
ev_type = ev->response_type & ~0x80;
|
||||
|
||||
if (events[ev_type]) {
|
||||
events[ev_type](ev);
|
||||
xcb_flush(dpy);
|
||||
}
|
||||
|
||||
free(ev);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
175
src/vec.h
Normal file
175
src/vec.h
Normal file
@@ -0,0 +1,175 @@
|
||||
|
||||
/*
|
||||
This is an implementation of a std::vector like growable array, but in plain
|
||||
C89 code. The result is a type safe, easy to use, dynamic array that has a
|
||||
familiar set of operations. Source: https://github.com/eteran/c-vector
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2020 Dylan Araps
|
||||
Copyright (c) 2015 Evan Teran
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef VEC_H_
|
||||
#define VEC_H_
|
||||
|
||||
#include <assert.h> /* for assert */
|
||||
#include <stddef.h> /* for size_t */
|
||||
#include <stdlib.h> /* for malloc/realloc/free */
|
||||
|
||||
/**
|
||||
* @brief vec_set_capacity - For internal use, set capacity variable.
|
||||
* @param vec - the vector
|
||||
* @param size - the new capacity to set
|
||||
* @return void
|
||||
*/
|
||||
#define vec_set_capacity(vec, size) \
|
||||
do { \
|
||||
if (vec) { \
|
||||
((size_t *)(vec))[-1] = (size); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* @brief vec_set_size - For internal use, sets the size variable of the vector
|
||||
* @param vec - the vector
|
||||
* @param size - the new capacity to set
|
||||
* @return void
|
||||
*/
|
||||
#define vec_set_size(vec, size) \
|
||||
do { \
|
||||
if (vec) { \
|
||||
((size_t *)(vec))[-2] = (size); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* @brief vec_capacity - gets the current capacity of the vector
|
||||
* @param vec - the vector
|
||||
* @return the capacity as a size_t
|
||||
*/
|
||||
#define vec_capacity(vec) ((vec) ? ((size_t *)(vec))[-1] : (size_t)0)
|
||||
|
||||
/**
|
||||
* @brief vec_size - gets the current size of the vector
|
||||
* @param vec - the vector
|
||||
* @return the size as a size_t
|
||||
*/
|
||||
#define vec_size(vec) ((vec) ? ((size_t *)(vec))[-2] : (size_t)0)
|
||||
|
||||
/**
|
||||
* @brief vec_empty - returns non-zero if the vector is empty
|
||||
* @param vec - the vector
|
||||
* @return non-zero if empty, zero if non-empty
|
||||
*/
|
||||
#define vec_empty(vec) (vec_size(vec) == 0)
|
||||
|
||||
/**
|
||||
* @brief vec_grow - For internal use, ensure that the vector is >= <count>.
|
||||
* @param vec - the vector
|
||||
* @param size - the new capacity to set
|
||||
* @return void
|
||||
*/
|
||||
#define vec_grow(vec, count) \
|
||||
do { \
|
||||
const size_t vec__sz = (count) * sizeof(*(vec)) + (sizeof(size_t) * 2); \
|
||||
if (!(vec)) { \
|
||||
size_t *vec__p = malloc(vec__sz); \
|
||||
assert(vec__p); \
|
||||
(vec) = (void *)(&vec__p[2]); \
|
||||
vec_set_capacity((vec), (count)); \
|
||||
vec_set_size((vec), 0); \
|
||||
} else { \
|
||||
size_t *vec__p1 = &((size_t *)(vec))[-2]; \
|
||||
size_t *vec__p2 = realloc(vec__p1, (vec__sz)); \
|
||||
assert(vec__p2); \
|
||||
(vec) = (void *)(&vec__p2[2]); \
|
||||
vec_set_capacity((vec), (count)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* @brief vec_pop_back - removes the last element from the vector
|
||||
* @param vec - the vector
|
||||
* @return void
|
||||
*/
|
||||
#define vec_pop_back(vec) \
|
||||
do { \
|
||||
vec_set_size((vec), vec_size(vec) - 1); \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* @brief vec_erase - removes the element at index i from the vector
|
||||
* @param vec - the vector
|
||||
* @param i - index of element to remove
|
||||
* @return void
|
||||
*/
|
||||
#define vec_erase(vec, i) \
|
||||
do { \
|
||||
if (vec) { \
|
||||
const size_t vec__sz = vec_size(vec); \
|
||||
if ((i) < vec__sz) { \
|
||||
vec_set_size((vec), vec__sz - 1); \
|
||||
size_t vec__x; \
|
||||
for (vec__x = (i); vec__x < (vec__sz - 1); ++vec__x) { \
|
||||
(vec)[vec__x] = (vec)[vec__x + 1]; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* @brief vec_free - frees all memory associated with the vector
|
||||
* @param vec - the vector
|
||||
* @return void
|
||||
*/
|
||||
#define vec_free(vec) \
|
||||
do { \
|
||||
if (vec) { \
|
||||
size_t *p1 = &((size_t *)(vec))[-2]; \
|
||||
free(p1); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* @brief vec_end - returns an iterator to one past the last element
|
||||
* @param vec - the vector
|
||||
* @return a pointer to one past the last element (or NULL)
|
||||
*/
|
||||
#define vec_end(vec) ((vec) ? &((vec)[vec_size(vec)]) : NULL)
|
||||
|
||||
/**
|
||||
* @brief vec_push_back - adds an element to the end of the vector
|
||||
* @param vec - the vector
|
||||
* @param value - the value to add
|
||||
* @return void
|
||||
*/
|
||||
#define vec_push_back(vec, value) \
|
||||
do { \
|
||||
size_t vec__cap = vec_capacity(vec); \
|
||||
if (vec__cap <= vec_size(vec)) { \
|
||||
vec_grow((vec), !vec__cap ? vec__cap + 1 : vec__cap * 2); \
|
||||
} \
|
||||
vec[vec_size(vec)] = (value); \
|
||||
vec_set_size((vec), vec_size(vec) + 1); \
|
||||
} while (0)
|
||||
|
||||
#endif /* VEC_H_ */
|
Reference in New Issue
Block a user