I've tweaked calmwm to add a function which centers the current window, and
resides it to be a fraction of the current screen size. I've been
running this patch for a while locally and have found it to be useful,
and have not noticed any side effects.

This feature is especially useful when switching monitor configurations
(i.e. docking / undocking a laptop), as it provides a way to force the
active window into a known position and size where it can easily be
located and moved / resized as needed. To my knowledge, no other
function really fulfills this purpose currently.

I am happy to tweak this code as needed based on feedback / testing.

~ Charles


--- calmwm.h.orig       Tue Apr 30 23:43:40 2019
+++ calmwm.h    Tue Apr 30 23:51:50 2019
@@ -396,6 +396,7 @@ void                         client_applysizehints(struct 
client_ctx *);
 void                    client_config(struct client_ctx *);
 struct client_ctx      *client_current(struct screen_ctx *);
 void                    client_cycle(struct screen_ctx *, int);
+void                    client_center(struct client_ctx *);
 void                    client_remove(struct client_ctx *);
 void                    client_draw_border(struct client_ctx *);
 struct client_ctx      *client_find(Window);
@@ -489,6 +490,7 @@ void                         screen_prop_win_draw(struct 
screen_ctx *,
 void                    kbfunc_cwm_status(void *, struct cargs *);
 void                    kbfunc_ptrmove(void *, struct cargs *);
 void                    kbfunc_client_snap(void *, struct cargs *);
+void                    kbfunc_client_center(void *, struct cargs *);
 void                    kbfunc_client_move(void *, struct cargs *);
 void                    kbfunc_client_resize(void *, struct cargs *);
 void                    kbfunc_client_close(void *, struct cargs *);
--- client.c.orig       Tue Apr 30 23:45:04 2019
+++ client.c    Tue Apr 30 23:53:10 2019
@@ -640,6 +640,31 @@ client_close(struct client_ctx *cc)
 }
 
 void
+client_center(struct client_ctx *cc)
+{
+
+       struct screen_ctx       *sc = cc->sc;
+       struct geom              area;
+
+       if (cc->flags & CLIENT_FREEZE)
+               return;
+
+       area = screen_area(sc,
+           cc->geom.x + cc->geom.w / 2,
+           cc->geom.y + cc->geom.h / 2, CWM_GAP);
+
+       cc->geom.w = area.w / 2;
+       cc->geom.h = area.h / 2;
+       cc->geom.x = area.x + area.w * 0.25;
+       cc->geom.y = area.y + area.h * 0.25;
+       client_applysizehints(cc);
+       client_resize(cc, 1);
+
+       /* Make sure the pointer stays within the window. */
+       client_ptr_inbound(cc, 0);
+}
+
+void
 client_setname(struct client_ctx *cc)
 {
        struct winname  *wn;
--- conf.c.orig Tue Apr 30 23:45:04 2019
+++ conf.c      Tue Apr 30 23:53:09 2019
@@ -110,6 +110,7 @@ static const struct {
        { FUNC_CC(window-snap-up-left, client_snap, (CWM_UP_LEFT)) },
        { FUNC_CC(window-snap-down-right, client_snap, (CWM_DOWN_RIGHT)) },
        { FUNC_CC(window-snap-down-left, client_snap, (CWM_DOWN_LEFT)) },
+       { FUNC_CC(window-center, client_center, 0) },
        { FUNC_CC(window-move, client_move, 0) },
        { FUNC_CC(window-move-up, client_move, (CWM_UP)) },
        { FUNC_CC(window-move-down, client_move, (CWM_DOWN)) },
@@ -258,6 +259,7 @@ static const struct {
        { "CMS-j",      "window-resize-down-big" },
        { "CMS-k",      "window-resize-up-big" },
        { "CMS-l",      "window-resize-right-big" },
+       { "MS-space",   "window-center" },
 },
 mouse_binds[] = {
        { "1",          "menu-window" },
--- kbfunc.c.orig       Tue Apr 30 23:45:04 2019
+++ kbfunc.c    Tue Apr 30 23:51:01 2019
@@ -287,6 +287,12 @@ kbfunc_client_resize_mb(void *ctx, struct cargs *cargs
 }
 
 void
+kbfunc_client_center (void *ctx, struct cargs *cargs)
+{
+       client_center(ctx);
+}
+
+void
 kbfunc_client_snap(void *ctx, struct cargs *cargs)
 {
        struct client_ctx       *cc = ctx;


Reply via email to