mfwm

A tiling fork of dylanaraps sowm.
git clone git://depsterr.com/git/mfwm
Log | Files | Refs | README | LICENSE

commit 6f6b77783e888188342ef4124b9c237870bfadfa
parent 986c2866cc55b52afbd0e306096844237bf8bbad
Author: depsterr <depsterr@protonmail.com>
Date:   Tue, 16 Jun 2020 02:09:10 +0000

got dwm like behaviour working. fibonaci next

Diffstat:
MMakefile | 2+-
Msowm.c | 118++++++++++++++++++++++++++++++++++++++++---------------------------------------
Msowm.h | 4+++-
3 files changed, 64 insertions(+), 60 deletions(-)

diff --git a/Makefile b/Makefile @@ -12,7 +12,7 @@ config.h: sowm: $(CC) -O3 $(CFLAGS) -o sowm sowm.c -lX11 $(LDFLAGS) -install: all +install: clean all install -Dm755 sowm $(DESTDIR)$(BINDIR)/sowm uninstall: diff --git a/sowm.c b/sowm.c @@ -7,6 +7,7 @@ #include <stdlib.h> #include <signal.h> #include <unistd.h> +#include <stdio.h> #include "sowm.h" @@ -14,8 +15,8 @@ static client *list = {0}, *ws_list[10] = {0}, *cur; static int ws = 1, sw, sh, wx, wy, numlock = 0; static unsigned int ww, wh; -const int gappx = 10; -const float mfact = 0.5; +const int g = 10; +static float fact = 0.5f; static Display *d; static XButtonEvent mouse; @@ -95,6 +96,7 @@ void win_add(Window w) { c->w = w; + /* client_focus(c) */ if (list) { list->prev->next = c; c->prev = list->prev; @@ -106,6 +108,8 @@ void win_add(Window w) { } ws_save(ws); + + organize(); } void win_del(Window w) { @@ -120,18 +124,22 @@ void win_del(Window w) { if (x->prev) x->prev->next = x->next; free(x); + + organize(); + ws_save(ws); } void win_kill(const Arg arg) { - if (cur) XKillClient(d, cur->w); + if (cur) { + XKillClient(d, cur->w); + } } void win_center(const Arg arg) { if (!cur) return; - win_size(cur->w, &(int){0}, &(int){0}, &ww, &wh); - XMoveWindow(d, cur->w, (sw - ww) / 2, (sh - wh) / 2); + XMoveResizeWindow(d, cur->w, sw / 4, sh / 4, sw / 2, sh / 2); } void win_fs(const Arg arg) { @@ -217,7 +225,7 @@ void map_request(XEvent *e) { win_add(w); cur = list->prev; - if (wx + wy == 0) win_center((Arg){0}); + if (wx + wy == 0) organize(); XMapWindow(d, w); win_focus(list->prev); @@ -278,69 +286,63 @@ int main(void) { if (events[ev.type]) events[ev.type](&ev); } +void change_fact(const Arg arg) { + fact += arg.f; + if (fact > 0.9f) + fact = 0.9f; + else if (fact < 0.1f) + fact = 0.1f; + organize(); +} + void client_focus(const Arg arg) { + if (!list) + return; - if (list) { - list->prev->next = cur; - cur->prev = list->prev; - list->prev = cur; - cur->next = list; - } else { - list = cur; - list->prev = list->next = list; - } + if (cur == list) + cur = cur->next; + + cur->prev->next = cur->next; + cur->next->prev = cur->prev; + + list->prev->next = cur; + cur->prev = list->prev; + list->prev = cur; + cur->next = list; + + list = cur; + + organize(); ws_save(ws); -} -void organize(const Arg arg) { +} - if (!list) +void organize() { + if(!list) return; int n = 0; - for win n++; + client* c = list; + client* cl = list->prev; + + for (; c && c != cl;c = c->next) n++; + + int nx; + nx = sw * fact; - if (!n) + if (n == 0) { + XMoveResizeWindow(d, list->w, g, g, sw - (2*g), sh - (2*g)); return; + } else { + XMoveResizeWindow(d, list->w, g, g, nx - (1.5*g), sh - (2*g)); + } + + int p = (sh - g) / n; - int i, nx, ny, nw, nh; - - nx = wx; - ny = 0; - nw = ww - gappx; - nh = wh - gappx; - - i = 0; - - for win { - if (i % 2) { - if(i < n - 1) { - if(i % 2) - nh /= 2; - else - nw /= 2; - } - if((i % 4) == 0) { - ny += nh; - } - else if((i % 4) == 1) - nx += nw; - else if((i % 4) == 2) - ny += nh; - else if((i % 4) == 3) { - nx += nw; - } - if(i == 0) - { - if(n != 1) - nw = mfact; - ny = wy; - } - else if(i == 1) - nw = ww - nw - gappx; - i++; - } - XMoveResizeWindow(d, c->w, nx + gappx, ny + gappx, nw - gappx, nh - gappx); + c = list->next; + for (int i = 0; i < n; i++) { + XMoveResizeWindow(d, c->w, nx + (g / 2), g + i * p, sw - (nx + (1.5 * g)), p - g); + c = c->next; } } diff --git a/sowm.h b/sowm.h @@ -17,6 +17,7 @@ typedef struct { const char** com; const int i; const Window w; + const float f; } Arg; struct key { @@ -37,13 +38,14 @@ void button_press(XEvent *e); void button_release(XEvent *e); void client_focus(const Arg arg); void configure_request(XEvent *e); +void change_fact(const Arg arg); void input_grab(Window root); void key_press(XEvent *e); void map_request(XEvent *e); void notify_destroy(XEvent *e); void notify_enter(XEvent *e); void notify_motion(XEvent *e); -void organize(const Arg arg); +void organize(); void run(const Arg arg); void win_add(Window w); void win_center(const Arg arg);