Make fibonacci patch work

This commit is contained in:
Abanoub 2023-06-21 18:00:11 +03:00
parent 68a17f962e
commit bc10390b25
No known key found for this signature in database
GPG Key ID: A4A10C91692482EC
2 changed files with 74 additions and 0 deletions

View File

@ -24,6 +24,8 @@ static const Layout layouts[] = {
{ "[]=", tile }, { "[]=", tile },
{ "><>", NULL }, /* no layout function means floating behavior */ { "><>", NULL }, /* no layout function means floating behavior */
{ "[M]", monocle }, { "[M]", monocle },
{ "[@]", spiral },
{ "[\\]", dwindle },
}; };
/* monitors */ /* monitors */

72
dwl.c
View File

@ -272,6 +272,8 @@ static void maplayersurfacenotify(struct wl_listener *listener, void *data);
static void mapnotify(struct wl_listener *listener, void *data); static void mapnotify(struct wl_listener *listener, void *data);
static void maximizenotify(struct wl_listener *listener, void *data); static void maximizenotify(struct wl_listener *listener, void *data);
static void monocle(Monitor *m); static void monocle(Monitor *m);
static void dwindle(Monitor *mon);
static void spiral(Monitor *mon);
static void motionabsolute(struct wl_listener *listener, void *data); static void motionabsolute(struct wl_listener *listener, void *data);
static void motionnotify(uint32_t time); static void motionnotify(uint32_t time);
static void motionrelative(struct wl_listener *listener, void *data); static void motionrelative(struct wl_listener *listener, void *data);
@ -1615,6 +1617,76 @@ monocle(Monitor *m)
wlr_scene_node_raise_to_top(&c->scene->node); wlr_scene_node_raise_to_top(&c->scene->node);
} }
void fibonacci(Monitor *mon, int s) {
unsigned int i=0, n=0, nx, ny, nw, nh;
Client *c;
wl_list_for_each(c, &clients, link)
if (VISIBLEON(c, mon) && !c->isfloating)
n++;
if(n == 0)
return;
nx = mon->w.x;
ny = 0;
nw = mon->w.width;
nh = mon->w.height;
wl_list_for_each(c, &clients, link)
if (VISIBLEON(c, mon) && !c->isfloating){
if((i % 2 && nh / 2 > 2 * c->bw)
|| (!(i % 2) && nw / 2 > 2 * c->bw)) {
if(i < n - 1) {
if(i % 2)
nh /= 2;
else
nw /= 2;
if((i % 4) == 2 && !s)
nx += nw;
else if((i % 4) == 3 && !s)
ny += nh;
}
if((i % 4) == 0) {
if(s)
ny += nh;
else
ny -= nh;
}
else if((i % 4) == 1)
nx += nw;
else if((i % 4) == 2)
ny += nh;
else if((i % 4) == 3) {
if(s)
nx += nw;
else
nx -= nw;
}
if(i == 0)
{
if(n != 1)
nw = mon->w.width * mon->mfact;
ny = mon->w.y;
}
else if(i == 1)
nw = mon->w.width - nw;
i++;
}
resize(c, (struct wlr_box){.x = nx, .y = ny,
.width = nw - 2 * c->bw, .height = nh - 2 * c->bw}, 0);
}
}
void
dwindle(Monitor *mon) {
fibonacci(mon, 1);
}
void
spiral(Monitor *mon) {
fibonacci(mon, 0);
}
void void
motionabsolute(struct wl_listener *listener, void *data) motionabsolute(struct wl_listener *listener, void *data)
{ {