1 Commits

Author SHA1 Message Date
Dylan Araps
7215a4915d sowm: Rounded corners 2020-02-21 18:12:32 +02:00
5 changed files with 63 additions and 45 deletions

View File

@@ -4,13 +4,13 @@ PREFIX ?= /usr
BINDIR ?= $(PREFIX)/bin
CC ?= gcc
all: sowm
all: config.h sowm
config.h:
cp config.def.h config.h
sowm: sowm.c sowm.h config.h Makefile
$(CC) -O3 $(CFLAGS) -o $@ $< -lX11 $(LDFLAGS)
sowm:
$(CC) -O3 $(CFLAGS) -o sowm sowm.c -lX11 -lXext $(LDFLAGS)
install: all
install -Dm755 sowm $(DESTDIR)$(BINDIR)/sowm
@@ -20,5 +20,3 @@ uninstall:
clean:
rm -f sowm *.o
.PHONY: all install uninstall clean

View File

@@ -1,8 +1,8 @@
# sowm (*~~Simple~~ Shitty Opinionated Window Manager*)
# sowm (*Simple Opinionated Window Manager*)
<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 (*220~ sloc!*).
An itsy bitsy floating window manager (*220~ sloc / 24kb compiled!*).
- Floating only.
- Fullscreen toggle.
@@ -38,8 +38,8 @@ Patches available here: https://github.com/dylanaraps/sowm/pulls
| `MOD4` + `f` | maximize toggle |
| `MOD4` + `c` | center window |
| `MOD4` + `q` | kill window |
| `MOD4` + `1-6` | desktop swap |
| `MOD4` + `Shift` +`1-6` | send window to desktop |
| `MOD4` + `1-9` | desktop swap |
| `MOD4` + `Shift` +`1-9` | send window to desktop |
| `MOD1` + `TAB` (*alt-tab*) | focus cycle |
**Programs**
@@ -71,28 +71,17 @@ Patches available here: https://github.com/dylanaraps/sowm/pulls
4) (Optional) Apply patch with `git apply patches/patch-name`
- In case of applying multiple patches, it has to be done **manually**.
If you are using GDM, save the following to `/usr/share/xsessions/sowm.desktop`. It is still recommended to start `sowm` from `.xinitrc` or through
[your own xinit implementation](https://github.com/dylanaraps/bin/blob/dfd9a9ff4555efb1cc966f8473339f37d13698ba/x).
```
[Desktop Entry]
Name=sowm
Comment=This session runs sowm as desktop manager
Exec=sowm
Type=Application
```
## Thanks
- [2bwm](https://github.com/venam/2bwm)
- [SmallWM](https://github.com/adamnew123456/SmallWM)
- [berry](https://github.com/JLErvin/berry)
- [catwm](https://github.com/pyknite/catwm)
- [dminiwm](https://github.com/moetunes/dminiwm)
- [dwm](https://dwm.suckless.org)
- [monsterwm](https://github.com/c00kiemon5ter/monsterwm)
- [openbox](https://github.com/danakj/openbox)
- [possum-wm](https://github.com/duckinator/possum-wm)
- [swm](https://github.com/dcat/swm)
- [tinywm](http://incise.org/tinywm.html)
- 2bwm
- SmallWM
- berry
- catwm
- dminiwm
- dwm
- monsterwm
- openbox
- possumwm
- swm
- tinywm

View File

@@ -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};

56
sowm.c
View File

@@ -4,6 +4,7 @@
#include <X11/XF86keysym.h>
#include <X11/keysym.h>
#include <X11/XKBlib.h>
#include <X11/extensions/shape.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
@@ -24,7 +25,6 @@ static void (*events[LASTEvent])(XEvent *e) = {
[ConfigureRequest] = configure_request,
[KeyPress] = key_press,
[MapRequest] = map_request,
[MappingNotify] = mapping_notify,
[DestroyNotify] = notify_destroy,
[EnterNotify] = notify_enter,
[MotionNotify] = notify_motion
@@ -62,6 +62,9 @@ void notify_motion(XEvent *e) {
wy + (mouse.button == 1 ? yd : 0),
MAX(1, ww + (mouse.button == 3 ? xd : 0)),
MAX(1, wh + (mouse.button == 3 ? yd : 0)));
if (mouse.button == 3)
win_round_corners(mouse.subwindow, ROUND_CORNERS);
}
void key_press(XEvent *e) {
@@ -143,6 +146,41 @@ void win_fs(const Arg arg) {
} else {
XMoveResizeWindow(d, cur->w, cur->wx, cur->wy, cur->ww, cur->wh);
}
win_round_corners(cur->w, cur->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) {
@@ -206,6 +244,8 @@ void configure_request(XEvent *e) {
.sibling = ev->above,
.stack_mode = ev->detail
});
win_round_corners(ev->window, ROUND_CORNERS);
}
void map_request(XEvent *e) {
@@ -218,19 +258,11 @@ void map_request(XEvent *e) {
if (wx + wy == 0) win_center((Arg){0});
win_round_corners(w, ROUND_CORNERS);
XMapWindow(d, w);
win_focus(list->prev);
}
void mapping_notify(XEvent *e) {
XMappingEvent *ev = &e->xmapping;
if (ev->request == MappingKeyboard || ev->request == MappingModifier) {
XRefreshKeyboardMapping(ev);
input_grab(root);
}
}
void run(const Arg arg) {
if (fork()) return;
if (d) close(ConnectionNumber(d));
@@ -250,8 +282,6 @@ void input_grab(Window root) {
== XKeysymToKeycode(d, 0xff7f))
numlock = (1 << i);
XUngrabKey(d, AnyKey, AnyModifier, root);
for (i = 0; i < sizeof(keys)/sizeof(*keys); i++)
if ((code = XKeysymToKeycode(d, keys[i].keysym)))
for (j = 0; j < sizeof(modifiers)/sizeof(*modifiers); j++)
@@ -284,6 +314,6 @@ int main(void) {
XDefineCursor(d, root, XCreateFontCursor(d, 68));
input_grab(root);
while (1 && !XNextEvent(d, &ev)) // 1 && will forever be here.
while (1 && !XNextEvent(d, &ev))
if (events[ev.type]) events[ev.type](&ev);
}

2
sowm.h
View File

@@ -39,7 +39,6 @@ void configure_request(XEvent *e);
void input_grab(Window root);
void key_press(XEvent *e);
void map_request(XEvent *e);
void mapping_notify(XEvent *e);
void notify_destroy(XEvent *e);
void notify_enter(XEvent *e);
void notify_motion(XEvent *e);
@@ -52,6 +51,7 @@ void win_focus(client *c);
void win_kill(const Arg arg);
void win_prev(const Arg arg);
void win_next(const Arg arg);
void win_round_corners(Window w, int rad);
void win_to_ws(const Arg arg);
void ws_go(const Arg arg);