Re: [dwm] clientspertag status message

From: Ritesh Kumar <ritesh_AT_cs.unc.edu>
Date: Thu, 1 Nov 2007 21:53:30 -0400

On 10/31/07, Szabolcs Nagy <nszabolcs_AT_gmail.com> wrote:
>
> On 11/1/07, Ritesh Kumar <ritesh_AT_cs.unc.edu> wrote:
> > Currently changing/toggling tags works correctly, however, the window in
> the
> > new view may or may not be focused :(. Any ideas?
>
> you can either raisefocused() or focus(nexttiled(clients)) depending
> on what client would you like to be active (sel or top)
>
>
> a possible raisefocused:
>
> void
> raisefocused(void) {
> XEvent ev;
> XWindowChanges wc;
>
> drawbar();
> if(!sel)
> return;
> if(sel->isfloating || !(ISTILE))
> XRaiseWindow(dpy, sel->win);
> else {
> wc.sibling = barwin;
> wc.stack_mode = Below;
> XConfigureWindow(dpy, sel->win, CWSibling |
> CWStackMode, &wc);
> }
> XSync(dpy, False);
> while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
> }
>
>
Thanks Szabolcs,

     I know very little about X programming so its hard for me to figure out
your suggestion. However, actually I needed something much simpler.
Dwm remembers your previously focussed windows. Changing view from one tag
to another makes sure that the focussed window on one tag is remembered when
we switch back to that tag. Now in the enhanced monocle layout, I was just
maximizing the selected client and banning the rest of the windows. The
problem was that when switching to a view in which the previously selected
client was not visible anymore, I had to find some visible client to
maximize again. I used nexttiled(clients) to find that client. Of course,
this client may not be the same as the client which the subsequent call to
focus(NULL) (in arrange()) would use for selection. The fix was rather
simple, instead of using nexttiled(clients), I used the same algorithm which
focus() uses to find the next client to select on a view change.
The monocle layout implementation would have been simpler if focus(NULL) was
called in arrange() *before* layout[].arrange(). That would have ensured
that sel was correctly updated before the layout routine did its task. I
would have been able to assume that sel == NULL => no windows to show in
this view.

What do you say Arg? Can you reorder the operations in focus() so that
pancake and I don't have to replicate the "next selected window finding
algorithm" in the layout routine?

Bottomline:
This now implies that that the enhanced monocle basically just always keeps
the currently selected client maximized. If the view is changed and a new
client is selected by dwm for selection, *that* is the window which is
maximized in the enhanced monocle layout.

The new patch (over pancake's nmaster/clientspertag) is here... it differs
in a single line from the patch given in my previous mail (but I am
including the entire patch here for easier comprehension).

What do you think pancake? Any suggestions? Can you include it in your next
patch revision?

diff -r 18756f3d803d config.h
--- a/config.h Tue Oct 30 22:39:33 2007 -0400
+++ b/config.h Wed Oct 31 15:08:00 2007 -0400
@@ -41,6 +41,20 @@ Layout layouts[] = {
 /* Status text */
 char* statusbar[] = { cptstext, inputtext };

+static void custom_focusnext(const char* a)
+{
+ focusnext(NULL);
+ if(cpt == 1)
+ arrange();
+}
+
+static void custom_focusprev(const char* a)
+{
+ focusprev(NULL);
+ if(cpt == 1)
+ arrange();
+}
+
 /* key definitions */
 #define MODKEY Mod1Mask
 #define KEYS \
@@ -54,8 +68,8 @@ Key keys[] = { \
        { MODKEY, XK_s, spawn, "exec
.dwm/audio_toggle.sh" }, \
        { MODKEY, XK_space, setlayout, NULL
}, \
        { MODKEY, XK_b, togglebar, NULL
}, \
- { MODKEY, XK_n, focusnext, NULL
}, \
- { MODKEY, XK_e, focusprev, NULL
}, \
+ { MODKEY, XK_n,
custom_focusnext, NULL }, \
+ { MODKEY, XK_e,
custom_focusprev, NULL }, \
        { MODKEY, XK_h, setmwfact, "-
0.05" }, \
        { MODKEY, XK_o, setmwfact,
"+0.05" }, \
        { MODKEY, XK_m, togglemax, NULL
}, \
diff -r 18756f3d803d nmaster.c
--- a/nmaster.c Tue Oct 30 22:39:33 2007 -0400
+++ b/nmaster.c Thu Nov 01 21:02:32 2007 -0400
@@ -96,12 +96,28 @@ void
 void
 ntile(void) {
        unsigned int i, n, nx, ny, nw, nh, mw, mh, th;
- Client *c;
+ Client *c, *t;

        for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
                n++;

        n = getclientspertag(n);
+
+ if(cpt == 1) { // Scrolling monocle layout
+ if(sel && isvisible(sel))
+ t = sel;
+ else // Find client from selection history
+ for(t = stack; t && !isvisible(t); t = t->snext);
+ for(c = nexttiled(clients); c; c = nexttiled(c->next)){
+ if(c!=t){
+ ban(c);
+ continue;
+ }
+ }
+ if(t)
+ resize(t, wax, way, waw - 2*t->border, wah -
2*t->border, False);
+ return;
+ }

        /* window geoms */
        mh = (n <= nmaster) ? wah / (n > 0 ? n : 1) : wah / nmaster;
Received on Fri Nov 02 2007 - 02:53:33 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:04:12 UTC