From 556c9b2fbce9b0a9bc440233566076b91fcd951d Mon Sep 17 00:00:00 2001 From: NiseVoid Date: Thu, 14 May 2020 19:39:34 +0200 Subject: [PATCH] Center floating windows when tiling --- config.h | 2 +- customfuncs.c | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/config.h b/config.h index 0a6370e..3a9fd3b 100644 --- a/config.h +++ b/config.h @@ -42,7 +42,7 @@ static const int resizehints = 0; /* 1 means respect size hints in tiled resi static const Layout layouts[] = { /* symbol arrange function */ - { "t", tile }, /* first entry is default */ + { "t", centerfloattile }, /* first entry is default */ { "f", NULL }, /* no layout function means floating behavior */ { "m", monocle }, }; diff --git a/customfuncs.c b/customfuncs.c index 8f7bd42..3eac50f 100644 --- a/customfuncs.c +++ b/customfuncs.c @@ -1,3 +1,15 @@ +void centerfloattile(Monitor *m) { + if (!m->sel) return; + + if (m->sel->isfloating && !m->sel->isfullscreen && !m->sel->isfixed && m->sel->x == 0 && m->sel->y == 0) { + int x = (m->mw - m->sel->w) / 2; + int y = (m->mh - m->sel->h) / 2; + resize(m->sel, x, y, m->sel->w, m->sel->h, 0); + } + + tile(m); +} + void togglefullscreen() { if (selmon->sel == 0) { return;