bakkeby / dwm-flexipatch

A dwm build with preprocessor directives to decide which patches to include during build time
MIT License
1.15k stars 235 forks source link

Patch request: sendmoncenter (with savefloats support) #402

Closed ysl2 closed 10 months ago

ysl2 commented 10 months ago

https://dwm.suckless.org/patches/sendmoncenter/

I tried to directly patch this, but it cannot work well with savefloats patch.

If I directly enable the savefloats patch, and patch the sendmoncenter above:

When sending a tiling client to another monitor, then togglefloat it, the client cannot be in center.

NOTE: I also enabled the alwayscenter patch.

bakkeby commented 10 months ago

The sendmoncenter patch naturally assumes that the client is floating.

I suppose you could try something like this:

@@ -1418,6 +1418,8 @@ sendmon(Client *c, Monitor *m)
     detachstack(c);
     c->mon = m;
     c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */
+    c->x = m->mx + (m->mw - WIDTH(c)) / 2;
+    c->y = m->my + (m->mh - HEIGHT(c)) / 2;
+    c->sfx = m->mx + (m->mw - c->sfw - 2 * c->bw) / 2;
+    c->sfy = m->my + (m->mh - c->sfh - 2 * c->bw) / 2;
     attach(c);
     attachstack(c);
     focus(NULL);

I suspect that there are many edge cases though that may not work well.

ysl2 commented 10 months ago

Thank you for instruction, however this seems not work ...

bakkeby commented 10 months ago

I tried this and it seemed to work for me

diff --git a/dwm.c b/dwm.c
index c3c6292..8b0a262 100644
--- a/dwm.c
+++ b/dwm.c
@@ -3383,6 +3383,10 @@ sendmon(Client *c, Monitor *m)
        #else
        c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */
        #endif // EMPTYVIEW_PATCH
+       c->x = m->mx + (m->mw - WIDTH(c)) / 2;
+       c->y = m->my + (m->mh - HEIGHT(c)) / 2;
+       c->sfx = m->mx + (m->mw - c->sfw - 2 * c->bw) / 2;
+       c->sfy = m->my + (m->mh - c->sfh - 2 * c->bw) / 2;
        #if ATTACHABOVE_PATCH || ATTACHASIDE_PATCH || ATTACHBELOW_PATCH || ATTACHBOTTOM_PATCH
        attachx(c);
        #else
ysl2 commented 10 months ago

Ah, I patched this in wrong place. After correction by following your newest reply, it works! Thank you bakkeby!!! :-)