Download raw body.
cwm(1) warp pointer to prev when you close a window (PATCH)
I assume the comments I included in my patch below explain what it does.
As I've warned on these lists several times, please note that I'm not a
C expert, so expect stupidity in my patches. :-)
Rationale
While I've always preferred MouseFocus (or its "sloppy" variants),
there's two details that bother me about this policy, and which makes me
opt for ClickToFocus with many window managers. The first has already
been taken into account in cwm(1), which is that when minimizing a
window it doesn't lose focus if the mouse falls outside its frame and
covers a second window. The patch below comes to solve the second
annoying MouseFocus default behaviour, that is when you close (delete or
kill) a window, the focus goes to the window where the mouse pointer
lands. This random behavior forces you to manually focus on the
previous window, which wastes time and distracts from what you're doing.
As far as I know only fvwm2 (ports version) and openbox can be
configured to pass the focus to the previous window in the stack when
the current client is killed (which is the default behaviour of
ClickToFocus.)
There's just one objection someone might have about this change. This
behavior isn't ideal when closing the window by clicking on an dialog
button or application menu. Even when you don't move the mouse with
your hand the pointer will jump. Since cwm has no titlebar with buttons
this will probably not bother you too much. It's a matter of weighing
which of the two problems is less bothersome. Those who prefer to use
the keyboard rather than the mouse, like me, will probably be inclined
to accept this change.
Ideally, to make everyone happy, in a second patch, we could see how to
capture the ButtonRelease mouse event and use client_set_active() with a
conditional. I've tried figuring out how to do this but I've been
unsuccessful. I'd appreaciate some clue from someone who understands of
how to accomplish this.
Index: client.c
===================================================================
RCS file: /cvs/xenocara/app/cwm/client.c,v
diff -u -p -r1.267 client.c
--- client.c 22 Mar 2023 08:27:36 -0000 1.267
+++ client.c 20 Jul 2025 12:02:18 -0000
@@ -210,6 +210,7 @@ client_remove(struct client_ctx *cc)
{
struct screen_ctx *sc = cc->sc;
struct winname *wn;
+ struct client_ctx *prevcc;
TAILQ_REMOVE(&sc->clientq, cc, entry);
@@ -230,6 +231,22 @@ client_remove(struct client_ctx *cc)
free(cc->res_class);
free(cc->res_name);
free(cc);
+
+ /*
+ * Warp pointer to previous window in stack when a window is
+ * closed.
+ */
+ if (TAILQ_EMPTY(&sc->clientq))
+ return;
+
+ prevcc = TAILQ_FIRST(&sc->clientq);
+
+ /* Avoid windows with skip client flag or from other groups */
+ if ((prevcc->flags & (CLIENT_SKIP_CYCLE)) &&
+ ! (prevcc->flags & CWM_CYCLE_INGROUP))
+ return;
+
+ client_ptr_warp(prevcc);
}
void
--
Walter
cwm(1) warp pointer to prev when you close a window (PATCH)