Re: [dev] dwm switches view on _NET_ACTIVE_WINDOW

2013-03-09 Thread Andreas Amann
On Sat, Mar 09, 2013 at 10:24:13PM +0100, Markus Teich wrote:
> Am 09.03.2013 21:30, schrieb Andreas Amann:
> > On Mon, Mar 04, 2013 at 11:36:57AM +0100, Markus Teich wrote:
> >> Hi,
> >>
> >> a month ago i started using dwm.
> >> In my rules i send firefox clients to tag 2.
> >> Now, after starting dwm i am on tag 1 and after i started firefox via
> >> dmenu, i automatically get switched to tag 2.
> > 
> > Do you also get switched to tag 2, if you start firefox from a terminal in
> > tag 1?
> 
> Yes and also when opening a new tab in the running firefox from a
> different dwm tag.

In this case you can try the attached patch.  Does this solve the problem?
This patch allows _NET_ACTIVE_WINDOW messages from pagers only.  Unless your
application poses as a pager, it should therefore not cause a switch. 

Andreas

>From 561a22a055d571f533562e217cdfccd8f64794d2 Mon Sep 17 00:00:00 2001
From: Andreas Amann 
Date: Sun, 10 Mar 2013 00:40:15 +
Subject: [PATCH] only allow to switch to new window when requested by a tool

according to http://standards.freedesktop.org/wm-spec the
_NET_ACTIVE_WINDOW message contains in data.l[0] a source indication,
which should be 1 when the request comes from an application, and 2
when it comes from a pager.  We only honour focus change requests, if
they come from a pager.
---
 dwm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/dwm.c b/dwm.c
index bd25d10..2c20478 100644
--- a/dwm.c
+++ b/dwm.c
@@ -542,7 +542,7 @@ clientmessage(XEvent *e) {
 			setfullscreen(c, (cme->data.l[0] == 1 /* _NET_WM_STATE_ADD*/
 			  || (cme->data.l[0] == 2 /* _NET_WM_STATE_TOGGLE */ && !c->isfullscreen)));
 	}
-	else if(cme->message_type == netatom[NetActiveWindow]) {
+	else if(cme->message_type == netatom[NetActiveWindow] && cme->data.l[0] == 2) {
 		if(!ISVISIBLE(c)) {
 			c->mon->seltags ^= 1;
 			c->mon->tagset[c->mon->seltags] = c->tags;
-- 
1.8.1.2



Re: [dev] dwm switches view on _NET_ACTIVE_WINDOW

2013-03-09 Thread Andreas Amann
On Mon, Mar 04, 2013 at 11:36:57AM +0100, Markus Teich wrote:
> Hi,
> 
> a month ago i started using dwm.
> In my rules i send firefox clients to tag 2.
> Now, after starting dwm i am on tag 1 and after i started firefox via
> dmenu, i automatically get switched to tag 2.

Do you also get switched to tag 2, if you start firefox from a terminal in
tag 1?

> Right after starting dwm this is not that much of a problem, but when i
> have some work in progress and use both views (via mod+tab) and then
> start another application, which is not in the current tagset, i loose
> one of my views to the tags of the started application.

Starting an application does normally not cause an _NET_ACTIVE_WINDOW event. 
Does this switching happen for all applications, or only for firefox?

FWIW, i have similar rules for firefox, and I don't see your switching
behaviour.  When I start firefox or any other program with dmenu, all visible
tags and the alternative view stay as they are.

Andreas



Re: [dev] Find window with dmenu

2013-02-12 Thread Andreas Amann
On Tue, Feb 12, 2013 at 10:36:27AM +0100, Thomas Dean wrote:

> all the unwanted windows in the list. See the attached scripts. Does anyone
> know a solution for this? Is there an existing tool that lists all
> "visible" windows along with their id?
> 

the ids of visible windows is stored in the _NET_CLIENT_LIST property of the
root window and can be accessed with "xprop -root _NET_CLIENT_LIST"

The followning script lets you select one with dmenu and then focus it:

#!/bin/bash

declare -i active_id
declare -i win_id

winlist=$(xprop -root _NET_CLIENT_LIST|cut -d "#" -f 2|tr "," " ")
count=$(echo $winlist|wc -w)
active_id=$(xprop -root _NET_ACTIVE_WINDOW|awk -F' ' '{ print $NF }')
foo=$(for i in $winlist; do
win_id="${i}"
if [ $win_id -eq $active_id ]; then 
focustag="*"
else
focustag=" "
fi

win_class=$(xprop -id ${win_id} WM_CLASS | cut -d'"' -f2)
win_title=$(xprop -id ${win_id} WM_NAME | cut -d'=' -f2-)
printf  "%10.10s${focustag}| %60.60s | 0x%7.7x\n" "${win_class}" 
"${win_title}" "${win_id}"
done |sort| dmenu -i -l $count)


if [ $? -eq 0 ]; then
xdotool windowactivate $(echo $foo | awk -F'|' '{ print $NF }')
fi





Re: [dev] Focus previously focused window

2012-12-14 Thread Andreas Amann
On Thu, Dec 13, 2012 at 04:20:13PM -0500, Manolo Martínez wrote:
> Thanks a lot. I will give it a try. I have to ask: how you just come up
> with it, prompted by my question? If so, double thanks.
> 

no, I like to go back deep into the focus history myself ;-) 

I had previously posted the patch in
http://lists.suckless.org/dev/1211/13219.html, and that message also
contains some more explanations.

Andreas



Re: [dev] Focus previously focused window

2012-12-13 Thread Andreas Amann
On Thu, Dec 13, 2012 at 03:04:01PM -0500, Manolo Martínez wrote:
> Hello,
> 
> I was wondering if anyone knows of a patch that provides the means to
> return to the previously focused window (if it exists). That is, for
> example, if I'm
> on window1 and launch a window2, MOD+p (say) would take me back to
> window1.


You can try the attached patch. Alt-Ctrl-j brings you back to the previous
window.  Pressing Alt-Ctrl-j once more, you get to the one before that, and
so on.  With Alt-Ctrl-k you go forward again.

Andreas

# HG changeset patch
# Parent dfd36140a7bcac030bf22a2e81892c0bf3bb52a6
cycle through focus stack

diff --git a/config.def.h b/config.def.h
--- a/config.def.h
+++ b/config.def.h
@@ -60,6 +60,10 @@
{ MODKEY,   XK_b,  togglebar,  {0} },
{ MODKEY,   XK_j,  focusstack, {.i = +1 } },
{ MODKEY,   XK_k,  focusstack, {.i = -1 } },
+   { MODKEY|ShiftMask, XK_j,  cycletiled, {.i = +1 } },
+   { MODKEY|ShiftMask, XK_k,  cycletiled, {.i = -1 } },
+   { MODKEY|ControlMask,   XK_j,  cycleglobal,{.i = +1 } },
+   { MODKEY|ControlMask,   XK_k,  cycleglobal,{.i = -1 } },
{ MODKEY,   XK_i,  incnmaster, {.i = +1 } },
{ MODKEY,   XK_d,  incnmaster, {.i = -1 } },
{ MODKEY,   XK_h,  setmfact,   {.f = -0.05} 
},
diff --git a/dwm.c b/dwm.c
--- a/dwm.c
+++ b/dwm.c
@@ -173,6 +173,8 @@
 static void configurenotify(XEvent *e);
 static void configurerequest(XEvent *e);
 static Monitor *createmon(void);
+static void cycleglobal(const Arg *arg);
+static void cycletiled(const Arg *arg);
 static void destroynotify(XEvent *e);
 static void detach(Client *c);
 static void detachstack(Client *c);
@@ -644,6 +646,61 @@
XSync(dpy, False);
 }
 
+void
+cycleglobal(const Arg *arg)
+{
+   Client *c = selmon->stack, *cn;
+
+   if(!c)
+   return;
+
+   if (c->snext) {
+   unfocus(selmon->sel,False);
+
+   for(cn = c; cn->snext; cn = cn->snext);
+
+   if (arg->i > 0) {
+   if (selmon->sel) {
+   cn->snext = selmon->stack;
+   c = selmon->stack = selmon->stack->snext;
+   cn->snext->snext = NULL;
+   }
+   } else {
+   c = cn;
+   }
+   }
+
+   if(!ISVISIBLE(c)) {
+   c->mon->seltags ^= 1;
+   c->mon->tagset[c->mon->seltags] = c->tags;
+   }
+   focus(c);
+   arrange(c->mon);
+}
+
+void
+cycletiled(const Arg *arg)
+{
+   Client *c = nexttiled(selmon->clients),*cn;
+   if(!selmon->lt[selmon->sellt]->arrange || !c || 
!(cn=nexttiled(c->next)))
+   return;
+
+   if (arg->i > 0) {
+   detach(c);
+   for(; cn->next; cn = cn->next);
+   cn->next = c;
+   c->next = NULL;
+   c = nexttiled(selmon->clients);
+
+   } else {
+   for(c=cn; (cn=nexttiled(cn->next)) != NULL; c=cn);
+   detach(c);
+   attach(c);
+   }
+   focusstack(arg);
+   arrange(c->mon);
+}
+
 Monitor *
 createmon(void) {
Monitor *m;





[dev] [dwm] [patch] cycle through focus stack

2012-11-07 Thread Andreas Amann
Here a patch which adjusts dwm to my personal taste, but maybe others find
it useful as well. 

First, I missed a function in dwm which allows me to quickly go back in the
list of windows in the order in which they were focused. Dwm already records
the focus history, but there was no way to access it explicitly. 

The attached patch introduces a function cycleglobal() which goes back and
forth in the recent focus history.  Pressing Mod-Ctrl-j a couple of times
now takes you back through your recently focused windows.  If you went to
far type Mod-Ctrl-k to go forward again. 

The second function  cycletiled() is mostly useful in tiled layout. 
Essentially Mod-Shift-j now rotates the positions of all windows in tiled
mode clockwise, but leaves the focus in the same spot on the screen.  So if you
start with a layout with four windows A B C D as follows (C has focus)

-
|  ||
|  |B   |
|  ||
|  ||
|   A  |C*  |
|  ||
|  ||
|  |D   |
|--||

the result of pressing  Mod-Shift-j is 

-
|  ||
|  |C   |
|  ||
|  ||
|   B  |D*  |
|  ||
|  ||
|  |A   |
|--||

Now D has focus. 
Mod-Shift-k does the opposite.

Andreas

# HG changeset patch
# Parent dfd36140a7bcac030bf22a2e81892c0bf3bb52a6
cycle through focus stack

diff --git a/config.def.h b/config.def.h
--- a/config.def.h
+++ b/config.def.h
@@ -60,6 +60,10 @@
{ MODKEY,   XK_b,  togglebar,  {0} },
{ MODKEY,   XK_j,  focusstack, {.i = +1 } },
{ MODKEY,   XK_k,  focusstack, {.i = -1 } },
+   { MODKEY|ShiftMask, XK_j,  cycletiled, {.i = +1 } },
+   { MODKEY|ShiftMask, XK_k,  cycletiled, {.i = -1 } },
+   { MODKEY|ControlMask,   XK_j,  cycleglobal,{.i = +1 } },
+   { MODKEY|ControlMask,   XK_k,  cycleglobal,{.i = -1 } },
{ MODKEY,   XK_i,  incnmaster, {.i = +1 } },
{ MODKEY,   XK_d,  incnmaster, {.i = -1 } },
{ MODKEY,   XK_h,  setmfact,   {.f = -0.05} 
},
diff --git a/dwm.c b/dwm.c
--- a/dwm.c
+++ b/dwm.c
@@ -173,6 +173,8 @@
 static void configurenotify(XEvent *e);
 static void configurerequest(XEvent *e);
 static Monitor *createmon(void);
+static void cycleglobal(const Arg *arg);
+static void cycletiled(const Arg *arg);
 static void destroynotify(XEvent *e);
 static void detach(Client *c);
 static void detachstack(Client *c);
@@ -644,6 +646,61 @@
XSync(dpy, False);
 }
 
+void
+cycleglobal(const Arg *arg)
+{
+   Client *c = selmon->stack, *cn;
+
+   if(!c)
+   return;
+
+   if (c->snext) {
+   unfocus(selmon->sel,False);
+
+   for(cn = c; cn->snext; cn = cn->snext);
+
+   if (arg->i > 0) {
+   if (selmon->sel) {
+   cn->snext = selmon->stack;
+   c = selmon->stack = selmon->stack->snext;
+   cn->snext->snext = NULL;
+   }
+   } else {
+   c = cn;
+   }
+   }
+
+   if(!ISVISIBLE(c)) {
+   c->mon->seltags ^= 1;
+   c->mon->tagset[c->mon->seltags] = c->tags;
+   }
+   focus(c);
+   arrange(c->mon);
+}
+
+void
+cycletiled(const Arg *arg)
+{
+   Client *c = nexttiled(selmon->clients),*cn;
+   if(!selmon->lt[selmon->sellt]->arrange || !c || 
!(cn=nexttiled(c->next)))
+   return;
+
+   if (arg->i > 0) {
+   detach(c);
+   for(; cn->next; cn = cn->next);
+   cn->next = c;
+   c->next = NULL;
+   c = nexttiled(selmon->clients);
+
+   } else {
+   for(c=cn; (cn=nexttiled(cn->next)) != NULL; c=cn);
+   detach(c);
+   attach(c);
+   }
+   focusstack(arg);
+   arrange(c->mon);
+}
+
 Monitor *
 createmon(void) {
Monitor *m;


Re: [dev] xid of a current window

2012-03-25 Thread Andreas Amann
On Sun, Mar 25, 2012 at 07:47:36PM +0200, Swiatoslaw Gal wrote:
> > You could use the focused window instead (which was what you
> > originally asked about):
> > 
> > $ xdotool getwindowfocus
> > 48234505
> 
> Yes, this works fine (without any today's patches).
> But the very first answer: XGetInputFocus was _exactly_
> what I was looking for.
> 
> Is there a reason that a _window_manager_ provides EHWHMS...
> whatever support?  This can be done with an external program,
> am I wrong?

The reason why I wrote these patches was that external programs do not work
reliably without support from the WM.  In particular "xdotool
getwindowfocus" is quite frustrating.  See also the "xdotool" manpage
itself:

"getactivewindow: Output the current active window. This command is often
more reliable than getwindowfocus."

Apart from that I agree with Anselm that EWMH is a pain...

Andreas







Re: [dev] xid of a current window

2012-03-25 Thread Andreas Amann

On Sun, Mar 25, 2012 at 04:33:23PM +0300, Ivan Kanakarakis wrote:
> A quick look into the tip of dwm, shows that it is the case for dwm.
> It doesn't set the _NET_ACTIVE_WINDOW property correctly,
> although the atom is there, and included in _NET_SUPPORTED.
> 
> To fix that, one must call (supposing c is
> the Client that holds the current window) :
> 
> XChangeProperty(dpy, root, netatom[NetActiveWindow], XA_WINDOW,
> 32, PropModeReplace, (unsigned char*)&c->window, 1);
> 
> everytime the current window changes.
> also one should delete the property if there is no active window
> (either no window on the screen, or no window focused)

Attached is a patch which does that.  It works for me. 

If you want support for NetActiveWindow, you probably also want support
for NetClientList.  The second patch implements that.

Andreas

# HG changeset patch
# Parent bbfe55c2f7562ea3e428d4c7cbd1d8da0c32f02f

diff --git a/dwm.c b/dwm.c
--- a/dwm.c
+++ b/dwm.c
@@ -499,6 +500,7 @@
cleanupmon(mons);
XSync(dpy, False);
XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
+   XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
 }
 
 void
@@ -858,8 +860,10 @@
XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]);
setfocus(c);
}
-   else
+   else {
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
+   XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
+   }
selmon->sel = c;
drawbars();
 }
@@ -1520,8 +1526,12 @@
 
 void
 setfocus(Client *c) {
-   if(!c->neverfocus)
+   if(!c->neverfocus) {
XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
+   XChangeProperty(dpy, root, netatom[NetActiveWindow],
+   XA_WINDOW, 32, PropModeReplace,
+   (unsigned char *) &(c->win), 1);
+   }
sendevent(c, wmatom[WMTakeFocus]);
 }
 
@@ -1777,8 +1789,10 @@
return;
grabbuttons(c, False);
XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]);
-   if(setfocus)
+   if(setfocus) {
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
+   XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
+   }
 }
 
 void
# HG changeset patch
# Parent bbfe55c2f7562ea3e428d4c7cbd1d8da0c32f02f

diff --git a/dwm.c b/dwm.c
--- a/dwm.c
+++ b/dwm.c
@@ -60,7 +60,7 @@
 enum { ColBorder, ColFG, ColBG, ColLast };  /* color */
 enum { NetSupported, NetWMName, NetWMState,
NetWMFullscreen, NetActiveWindow, NetWMWindowType,
-   NetWMWindowTypeDialog, NetLast }; /* EWMH atoms */
+   NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
 enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms 
*/
 enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
@@ -238,6 +238,7 @@
 static Bool updategeom(void);
 static void updatebarpos(Monitor *m);
 static void updatebars(void);
+static void updateclientlist(void);
 static void updatenumlockmask(void);
 static void updatesizehints(Client *c);
 static void updatestatus(void);
@@ -1157,6 +1161,8 @@
XRaiseWindow(dpy, c->win);
attach(c);
attachstack(c);
+   XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, 
PropModeAppend,
+   (unsigned char *) &(c->win), 1);
XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h); /* 
some windows require this */
setclientstate(c, NormalState);
if (c->mon == selmon)
@@ -1607,6 +1617,7 @@
netatom[NetWMFullscreen] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", 
False);
netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", 
False);
netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, 
"_NET_WM_WINDOW_TYPE_DIALOG", False);
+   netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False);
/* init cursors */
cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
@@ -1629,6 +1640,7 @@
/* EWMH support per view */
XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
PropModeReplace, (unsigned char *) netatom, NetLast);
+   XDeleteProperty(dpy, root, netatom[NetClientList]);
/* select for events */
wa.cursor = cursor[CurNormal];
wa.event_mask = 
SubstructureRedirectMask|SubstructureNotifyMask|ButtonPressMask|PointerMotionMask
@@ -1802,6 +1816,7 @@
}
free(c);
focus(NULL);
+   updateclientlist();
arrange(m);
 }
 
@@ -1848,6 +1863,19 @@
m->by = -bh;
 }
 
+void
+updateclientlist() {
+   Client *c;
+   Monitor *m;
+
+   XDeleteProperty(dpy, root, netatom[NetClientList]);
+   

[dev] [dwm] exit fullscreen correctly

2012-02-23 Thread Andreas Amann
dwm does not always leave the fullscreen mode correctly. 

For example, if you use the mouse to resize a fullscreen client, the boarder
does not get painted, which indicates that internally the isfullscreen flag
is still set.  A similar effect happens if togglefloat (Alt-Shift-Space) is
applied to a fullscreen client. 


The attached patch fixes this. 

Andreas

# HG changeset patch
# Parent 825580c0682efa35ff2e2cd003e552c4af75982b

diff --git a/dwm.c b/dwm.c
--- a/dwm.c
+++ b/dwm.c
@@ -1268,6 +1268,8 @@
togglefloating(NULL);
}
if(!selmon->lt[selmon->sellt]->arrange || c->isfloating)
+   if (c-> isfullscreen)
+   setfullscreen(c,False);
resize(c, nx, ny, c->w, c->h, True);
break;
}
@@ -1403,8 +1405,11 @@
&& (abs(nw - c->w) > snap || abs(nh - c->h) > 
snap))
togglefloating(NULL);
}
-   if(!selmon->lt[selmon->sellt]->arrange || c->isfloating)
+   if(!selmon->lt[selmon->sellt]->arrange || 
c->isfloating) {
+   if (c-> isfullscreen)
+   setfullscreen(c,False);
resize(c, c->x, c->y, nw, nh, True);
+   }
break;
}
} while(ev.type != ButtonRelease);
@@ -1756,6 +1761,10 @@
if(selmon->sel->isfloating)
resize(selmon->sel, selmon->sel->x, selmon->sel->y,
   selmon->sel->w, selmon->sel->h, False);
+   else {
+   if (selmon->sel->isfullscreen)
+   setfullscreen(selmon->sel,False);
+   }
arrange(selmon);
 }
 


Re: [dev] [dwm] about _NET_ACTIVE_WINDOW support

2012-01-15 Thread Andreas Amann
On Sun, Jan 15, 2012 at 06:18:03PM +, Bjartur Thorlacius wrote:
> Should we not patch wmname?
> 

As wmname is a hack for broken apps, they will probably break if you
try to fix it. 

If you only need to set _NET_WM_NAME, you can also try
xprop -root -f _NET_WM_NAME 8s -set _NET_WM_NAME "LG3D"




Re: [dev] [dwm] about _NET_ACTIVE_WINDOW support

2012-01-15 Thread Andreas Amann
On Sun, Jan 15, 2012 at 07:29:13AM +0100, Anselm R Garbe wrote:
> On 15 January 2012 07:27, Anselm R Garbe  wrote:
> > On 15 January 2012 00:26, Ivan Kanakarakis  wrote:
> >> On 15 January 2012 00:52, Andreas Amann  wrote:
> >>> just to ask, do you happen to have the command "wmname LG3D" in your
> >>> startup
> >>> script or anything else which changes _NET_WM_NAME?
> >>>
> >>
> >> I actually do have "wmname LG3D"
> >> I'm not home right now to test, but I'll report once I'm back
> >
> > Bare in mind that the wmname LG3D trick only fixed a bug of the JDK.
> > It is not related to chromium at all.
> 
> correction: s/fixed/works around/

The problem is that Ivan uses wmname to set _NET_WM_NAME to "LG3D". 
Actually chromium does not care about _NET_WM_NAME.  But "wmname" has a
dirty side effect, it sets the _NET_SUPPORTING_WM_CHECK property of the root
window to the window id of the root window.  That is clearly against EWMH
rules and it would be better if wmname would leave _NET_SUPPORTING_WM_CHECK
alone.  I guess Chromium for some reason is smart enough to figure out that
_NET_SUPPORTING_WM_CHECK is not set correctly, and therefore seems to decide
that it cannot trust the wm.  The correct solution is therefore not to use
"wmname".

To address Ivan's other problem with NetActiveWindow, you might consider to
include the attached patch.  It is similar to the patch I sent previously,
but I cut out the NetClientList part.

Andreas

# HG changeset patch
# Parent bbfe55c2f7562ea3e428d4c7cbd1d8da0c32f02f

diff --git a/dwm.c b/dwm.c
--- a/dwm.c
+++ b/dwm.c
@@ -499,6 +500,7 @@
cleanupmon(mons);
XSync(dpy, False);
XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
+   XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
 }
 
 void
@@ -858,8 +860,10 @@
XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]);
setfocus(c);
}
-   else
+   else {
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
+   XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
+   }
selmon->sel = c;
drawbars();
 }
@@ -1520,8 +1526,12 @@
 
 void
 setfocus(Client *c) {
-   if(!c->neverfocus)
+   if(!c->neverfocus) {
XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
+   XChangeProperty(dpy, root, netatom[NetActiveWindow],
+   XA_WINDOW, 32, PropModeReplace,
+   (unsigned char *) &(c->win), 1);
+   }
sendevent(c, wmatom[WMTakeFocus]);
 }
 
@@ -1777,8 +1789,10 @@
return;
grabbuttons(c, False);
XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]);
-   if(setfocus)
+   if(setfocus) {
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
+   XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
+   }
 }
 
 void


Re: [dev] [dwm] about _NET_ACTIVE_WINDOW support

2012-01-14 Thread Andreas Amann
On Mon, Jan 09, 2012 at 04:55:08PM +0200, Ivan Kanakarakis wrote:
> On 9 January 2012 16:34, Ivan Kanakarakis  wrote:
> 
> 
> 
> ow, sorry, cross that out. I misread the question.
> Even with the patch applied, the problem is still there.
> What I meant was, "nope, it doesn't fix it" .
> Sorry for the confusion

just to ask, do you happen to have the command "wmname LG3D" in your startup
script or anything else which changes _NET_WM_NAME?

Apparently that was the culprit in my case.  After taking it out, restarting
X and dwm (with my previous patch applied), the weird focus problem in
chromium has disappeared.

Andreas






Re: [dev] [dwm] about _NET_ACTIVE_WINDOW support

2012-01-08 Thread Andreas Amann
On Sun, Jan 08, 2012 at 01:50:35PM +0200, Ivan Kanakarakis wrote:
> 
> The patch attached to Andreas responce does that
> and also adds support for _NET_CLIENT_LIST

Just to ask, does your other focus problem with Chromium still exist with
that patch applied?

Andreas



Re: [dev] [dwm] about _NET_ACTIVE_WINDOW support

2012-01-08 Thread Andreas Amann
On Sun, Jan 08, 2012 at 12:29:38PM +0100, Anselm R Garbe wrote:
> On 8 January 2012 02:03, Andreas Amann  wrote:
> >
> > I use the attached patch for this. In addition it also maintains a
> > NetClientList, which exposes the list of managed windows in the ewmh
> > recommended way.
> 
> Which kind of program is using this client list?
> 


The attached shell script for example.  I bind it to Alt-W as a quick and dirty
dmenu based windows selector.  For me the quickest way of finding and
focusing a particular window. 

Google shows quite a couple of other programs which seem to use
NetClientlist, but still I think it is not worth the trouble to support it
in mainline dwm.



Andreas


listwin.sh
Description: Bourne shell script


Re: [dev] [dwm] about _NET_ACTIVE_WINDOW support

2012-01-07 Thread Andreas Amann
On Sat, Jan 07, 2012 at 10:20:27PM +0200, Ivan Kanakarakis wrote:
> dwm, when it receives a _NET_ACTIVE_WINDOW message, it transfers focus to
> the client that asked for it, but never sets the root window id to that
> window's id. That is ofcourse a choice - the standard doesn't force one to
> do that, but that makes tools like xdotool and xprop fail on some options
> that people may find usefull. Specifically the following commands:
> 
> $ xprop -root _NET_ACTIVE_WINDOW
> $ xdotool getactivewindow
> 
> To get those working properly, one would need to,
> 
> XChangeProperty(dpy, root, netatom[NetActiveWindow], XA_WINDOW, 32,
> PropModeReplace, (unsigned char *)&c->win, 1);
> 
> everytime a new window is focused. I guess that would go into
> setfocus(Client *c) function or something similar.

I use the attached patch for this. In addition it also maintains a
NetClientList, which exposes the list of managed windows in the ewmh
recommended way.  

Andreas
diff --git a/dwm.c b/dwm.c
--- a/dwm.c
+++ b/dwm.c
@@ -60,7 +60,7 @@
 enum { ColBorder, ColFG, ColBG, ColLast };  /* color */
 enum { NetSupported, NetWMName, NetWMState,
NetWMFullscreen, NetActiveWindow, NetWMWindowType,
-   NetWMWindowTypeDialog, NetLast }; /* EWMH atoms */
+   NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
 enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms 
*/
 enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
@@ -238,6 +238,7 @@
 static Bool updategeom(void);
 static void updatebarpos(Monitor *m);
 static void updatebars(void);
+static void updateclientlist(void);
 static void updatenumlockmask(void);
 static void updatesizehints(Client *c);
 static void updatestatus(void);
@@ -499,6 +500,7 @@
cleanupmon(mons);
XSync(dpy, False);
XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
+   XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
 }
 
 void
@@ -858,8 +860,10 @@
XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]);
setfocus(c);
}
-   else
+   else {
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
+   XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
+   }
selmon->sel = c;
drawbars();
 }
@@ -1157,6 +1161,8 @@
XRaiseWindow(dpy, c->win);
attach(c);
attachstack(c);
+   XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, 
PropModeAppend,
+   (unsigned char *) &(c->win), 1);
XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h); /* 
some windows require this */
setclientstate(c, NormalState);
if (c->mon == selmon)
@@ -1520,8 +1526,12 @@
 
 void
 setfocus(Client *c) {
-   if(!c->neverfocus)
+   if(!c->neverfocus) {
XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
+   XChangeProperty(dpy, root, netatom[NetActiveWindow],
+   XA_WINDOW, 32, PropModeReplace,
+   (unsigned char *) &(c->win), 1);
+   }
sendevent(c, wmatom[WMTakeFocus]);
 }
 
@@ -1607,6 +1617,7 @@
netatom[NetWMFullscreen] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", 
False);
netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", 
False);
netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, 
"_NET_WM_WINDOW_TYPE_DIALOG", False);
+   netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False);
/* init cursors */
cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
@@ -1629,6 +1640,7 @@
/* EWMH support per view */
XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
PropModeReplace, (unsigned char *) netatom, NetLast);
+   XDeleteProperty(dpy, root, netatom[NetClientList]);
/* select for events */
wa.cursor = cursor[CurNormal];
wa.event_mask = 
SubstructureRedirectMask|SubstructureNotifyMask|ButtonPressMask|PointerMotionMask
@@ -1777,8 +1789,10 @@
return;
grabbuttons(c, False);
XSetWindowBorder(dpy, c->win, dc.norm[ColBorder]);
-   if(setfocus)
+   if(setfocus) {
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
+   XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
+   }
 }
 
 void
@@ -1802,6 +1816,7 @@
}
free(c);
focus(NULL);
+   updateclientlist();
arrange(m);
 }
 
@@ -1848,6 +1863,19 @@
m->by = -bh;
 }
 
+void
+updateclientlist() {
+   Client *c;
+   Monitor *m;
+
+   XDeleteProperty(dpy, root, netatom[NetClientList]);
+   for(m = mons; m; m = m->next)
+ 

Re: [dev] [dwm] NetActiveWindow

2011-04-16 Thread Andreas Amann
On Fri, Apr 15, 2011 at 08:07:46AM +, Anselm R Garbe wrote:
> 
> I think the approach has a multi-monitor flaw.
> 
> The code should rather do:
> 
>   if(!ISVISIBLE(c)) {
>   c->mon->seltags ^= 1;
>   c->mon->tagset[c->mon->seltags] = c->tags;
>   }
>   detach(c);
>   attach(c);
>   focus(c);
>   arrange(c->mon);o
> 
> The focus(c) will update selmon propely, so that this should be fine.
> 
> Also, when looking at the above lines and zoom(), we could probably save some
> compressing it into a separate function:
> 
> static void
> pop(Client *c) {
>   detach(c);
>   attach(c);
>   focus(c);
>   arrange(c->mon);
> }
> 

Yes, that makes sense. 

In the meantime I noticed that it is quite difficult to reliably
obtain a list of the window ids of managed clients from the
commandline without some help from dwm. In particular "xprop" shows
also windows which are not managed by dwm, which is quite annoying. Is
there a known way around this?

Apparently, some WMs use the xproperty "_NET_CLIENT_LIST" of the root
window to advertise managed window ids.  Here is a (not very elegant)
patch which makes dwm comply with this convention:

-
diff --git a/dwm.c b/dwm.c
--- a/dwm.c
+++ b/dwm.c
@@ -58,7 +58,7 @@
 enum { CurNormal, CurResize, CurMove, CurLast };/* cursor */
 enum { ColBorder, ColFG, ColBG, ColLast };  /* color */
 enum { NetSupported, NetWMName, NetWMState,
-   NetWMFullscreen, NetActiveWindow, NetLast }; /* EWMH atoms */
+   NetWMFullscreen, NetActiveWindow, NetClientList, NetLast }; /* EWMH 
atoms */
 enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms 
*/
 enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
@@ -232,6 +232,7 @@
 static Bool updategeom(void);
 static void updatebarpos(Monitor *m);
 static void updatebars(void);
+static void updateclientlist(void);
 static void updatenumlockmask(void);
 static void updatesizehints(Client *c);
 static void updatestatus(void);
@@ -1152,6 +1153,8 @@
XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h); /* 
some windows require this */
XMapWindow(dpy, c->win);
setclientstate(c, NormalState);
+   XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, 
PropModeAppend,
+   (unsigned char *) &(c->win), 1);
arrange(c->mon);
 }
 
@@ -1545,6 +1548,7 @@
netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
netatom[NetWMState] = XInternAtom(dpy, "_NET_WM_STATE", False);
netatom[NetWMFullscreen] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", 
False);
+   netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False);
/* init cursors */
cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
@@ -1567,6 +1571,7 @@
/* EWMH support per view */
XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
PropModeReplace, (unsigned char *) netatom, NetLast);
+   XDeleteProperty(dpy, root, netatom[NetClientList]);
/* select for events */
wa.cursor = cursor[CurNormal];
wa.event_mask = 
SubstructureRedirectMask|SubstructureNotifyMask|ButtonPressMask
@@ -1742,6 +1747,7 @@
}
free(c);
focus(NULL);
+   updateclientlist();
arrange(m);
 }
 
@@ -1784,6 +1790,19 @@
m->by = -bh;
 }
 
+void
+updateclientlist() {
+   Client *c;
+   Monitor *m;
+
+   XDeleteProperty(dpy, root, netatom[NetClientList]);
+   for(m = mons; m; m = m->next)
+   for(c = m->clients; c; c = c->next)
+   XChangeProperty(dpy, root, netatom[NetClientList],
+   XA_WINDOW, 32, PropModeAppend,
+   (unsigned char *) &(c->win), 1);
+}
+
 Bool
 updategeom(void) {
Bool dirty = False;
-

With this patch in place the following script now works reliably for me:

-
#!/bin/sh

winlist=$(xprop -root _NET_CLIENT_LIST|cut -d "#" -f 2|tr "," " ")
count=$(echo $winlist|wc -w)
foo=$(for i in $winlist; do
win_id="${i}"
win_class=$(xprop -id ${win_id} WM_CLASS | cut -d'"' -f2)
win_title=$(xprop -id ${win_id} WM_NAME | cut -d'=' -f2-)
printf  "%10.10s | %30.30s | %8.8d\n" "${win_class}" "${win_title}" 
"${win_id}"
done |sort| dmenu -i -l $count)


if [ $? -eq 0 ]; then
xdotool windowactivate $(echo $foo | awk -F'|' '{ print $NF }')
fi

-

It is then also possible to use "winctrl" and similar tools which
depend on _NET_CLIENT_LIST.

While this works great for me, I assume that most people might not
care about _NET_CLIENT_LIST, and this patch should probably not be
mainline material.

Re: [dev] [dwm] NetActiveWindow

2011-04-14 Thread Andreas Amann
On Thu, Apr 14, 2011 at 07:21:57PM +0200, Anselm R Garbe wrote:
> I still don't like the fact to call view() with some Arg from within
> dwm, will need to improve this. Arg arguments were only intended for
> config.h, but I think we can improve this.

Maybe the patch below is useful for this?

Andreas



diff --git a/dwm.c b/dwm.c
--- a/dwm.c
+++ b/dwm.c
@@ -1288,8 +1288,8 @@
}
else if(cme->message_type == netatom[NetActiveWindow]) {
if(!ISVISIBLE(c)) {
-   Arg a = { .ui = c->tags };
-   view(&a); 
+   selmon->seltags ^= 1;
+   selmon->tagset[selmon->seltags] = c -> tags;
}
detach(c);
attach(c);



Re: [dev] [dwm] NetActiveWindow

2011-04-14 Thread Andreas Amann
On Wed, Apr 13, 2011 at 06:08:42PM -0400, Peter John Hartman wrote:
> On Wed, Apr 13, 2011 at 09:28:19PM +0100, Andreas Amann wrote:
> > WARNING: This e-mail has been altered by MIMEDefang.  Following this
> > paragraph are indications of the actual changes made.  For more
> > information about your site's MIMEDefang policy, contact
> > UCC Hostmaster / MIMEDefang Administrator .  For more 
> > information about MIMEDefang, see:
> > 
> > http://www.roaringpenguin.com/mimedefang/enduser.php3
> > 
> > An attachment named listwin.sh was removed from this document as it
> > constituted a security hazard.  If you require this document, please contact
> > the sender and arrange an alternate means of receiving it.
> > One way is to rename it to somename.txt and re-send it. The recipient can 
> > then save the file and rename it to its original name.
> > 
> 
> Can you paste listwin.sh?  
> 

Sure, see below. I also paste the new version of the patch which now only
switches on the tags of the selected window.  Another option would be to tag
the window with the currently visible tags (see what is commented out in the
patch).  I prefer the first option which works great for me, thanks again!

Andreas


diff --git a/dwm.c b/dwm.c
--- a/dwm.c
+++ b/dwm.c
@@ -58,7 +58,7 @@
 enum { CurNormal, CurResize, CurMove, CurLast };/* cursor */
 enum { ColBorder, ColFG, ColBG, ColLast };  /* color */
 enum { NetSupported, NetWMName, NetWMState,
-   NetWMFullscreen, NetLast };  /* EWMH atoms */
+   NetWMFullscreen, NetActiveWindow, NetLast }; /* EWMH atoms */
 enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms 
*/
 enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
@@ -1286,6 +1286,17 @@
arrange(c->mon);
}
}
+   if(c && cme->message_type == netatom[NetActiveWindow]) {
+if (!ISVISIBLE(c)){
+/* c->tags |= c->mon->tagset[c->mon->seltags]; */
+Arg a = {.ui = c->tags};
+view(&a); 
+}
+detach(c);
+attach(c);
+focus(c);
+arrange(c->mon);
+   }
 }
 
 void
@@ -1524,6 +1535,7 @@
wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False);
+netatom[NetActiveWindow] = XInternAtom(dpy, "_NET_ACTIVE_WINDOW", 
False);
wmatom[WMTakeFocus] = XInternAtom(dpy, "WM_TAKE_FOCUS", False);
netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);


-- listwin.sh -

#!/bin/sh

foo=$(for i in $(xdotool search --onlyvisible --classname ".+"); do
win_id="${i}"
win_class=$(xprop -id ${win_id} WM_CLASS | cut -d'"' -f2)
win_title=$(xprop -id ${win_id} _NET_WM_NAME | cut -d'"' -f2)
printf  "%10.10s | %30.30s | %8.8d\n" "${win_class}" "${win_title}" 
"${win_id}"
done |sort| dmenu -i -l 10)
if [ $? -eq 0 ]; then
xdotool windowactivate $(echo $foo | awk -F'|' '{ print $NF }')
fi




Re: [dev] hgweb typically sucks

2011-04-01 Thread Andreas Amann
On Fri, Apr 01, 2011 at 04:32:42PM +0200, pancake wrote:
> we can override those mimetypes to be text/plain so all browsers will 
> display it correctly.
> 


Or try 
https://addons.mozilla.org/en-us/firefox/addon/open-in-browser/



Re: [dev] [dwm] [patch] per-window keyboard layout

2010-10-13 Thread Andreas Amann
Hi Evgeny,

On Tue, 12 Oct 2010 21:19:32 +0300, Evgeny Grablyk  
wrote:
> If you have any comments or suggestions, please share - this is my
> first patch for dwm.

Works well for me. Note however that you cannot switch between tags per
mouse if an alternate layout is activated. The patch below fixes this.

Andreas

diff --git a/dwm.c b/dwm.c
--- a/dwm.c
+++ b/dwm.c
@@ -43,7 +43,7 @@
 
 /* macros */
 #define BUTTONMASK  (ButtonPressMask|ButtonReleaseMask)
-#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask))
+#define CLEANMASK(mask) (mask & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
 #define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH))
 #define ISVISIBLE(C)((C->tags & C->mon->tagset[C->mon->seltags]))
 #define LENGTH(X)   (sizeof X / sizeof X[0])


[dev] [dwm] Fix for border drawing problem

2010-06-29 Thread Andreas Amann
This recent patch 

changeset:   1519:72272822ddf2
user:Anselm R Garbe 
date:Sun May 30 10:02:56 2010 +0100
summary: implemented better fullscreen handling, please test

gives me troubles because the border around the window is not painted for
all clients.  (One particular example is emacs from recent bzr repository.)
The reason seems to be that some clients toggle out of fullscreen, before
they have actually toggled into it.  This confuses dwm apparently because in
this case c->oldbw is sometimes not correctly initialised.

The following patch fixes this for me:


-
diff --git a/dwm.c b/dwm.c
--- a/dwm.c
+++ b/dwm.c
@@ -1124,7 +1124,6 @@
c->y = c->oldy = wa->y + c->mon->wy;
c->w = c->oldw = wa->width;
c->h = c->oldh = wa->height;
-   c->oldbw = wa->border_width;
if(c->w == c->mon->mw && c->h == c->mon->mh) {
c->isfloating = 1;
c->x = c->mon->mx;
@@ -1142,7 +1141,7 @@
   && (c->x + (c->w / 2) < c->mon->wx + c->mon->ww))
? bh : c->mon->my);
c->bw = borderpx;
}
-   wc.border_width = c->bw;
+   wc.border_width = c->oldbw = c->bw;
XConfigureWindow(dpy, w, CWBorderWidth, &wc);
XSetWindowBorder(dpy, w, dc.norm[ColBorder]);
configure(c); /* propagates border_width, if size doesn't change */
-


While this seems to work, a proper way of handling fullscreen is probably by
introducing a simple c->fullscreen flag, which could replace the
c->old{x,y,w,h,bw} stuff?

Andreas




Re: [dev] [dwm] can't toggle tags with mouse

2010-05-27 Thread Andreas Amann
On Thu, May 27, 2010 at 04:35:29PM +0200, orsch...@googlemail.com wrote:
> Ah sorry my fault, accidentally I broke the line down with \.
> 
> Nice your solution is working. :)
> 
> But do you have any idea why toggling via evdev doesn't affect the
> xkb_symbols line?

simply because "xkb_symbols" does not change when you toggle your keyboard
layout dynamically via Alt-shift.  Before and after toggling it contains the
string "+pc+de+pl" which simply says that you can toggle between de and
pl layout, but does not tell you which one is currently active.  Obviously
if you toggle your keyboard using "setxkbmap" directly, then xkb_symbols
changes from "+pc+de" to "+pc+pl".

>From "man setxkbmap" you can see that "setxkbmap -print" is actually
intended to be piped into xkbcomp and not for determining the current state
of the keyboard.




Re: [dev] [dwm] can't toggle tags with mouse

2010-05-27 Thread Andreas Amann
On Thu, May 27, 2010 at 03:25:32PM +0200, orsch...@googlemail.com wrote:
> Hello Andreas,
> 
> your solution is almost working. The only thing that doesn't fit is
> the length of the output. de/pl should only by two letters but in the
> output there are a plenty of blanks before. I assume this happens
> because the eight digits were substituted by only two letters?
> 
> Better understanding:
> 
> xxde where 'x' stands for a blank
> 
> Could that be corrected to use not so much space in the bar?

strange. What is the output of 
  xset -q|sed -ne "2 s/^.*/uk/ p; 2 s/^*/de/ p"
on command line? What is the output of 
  xset -q|head -2
for each layout? 



Re: [dev] [dwm] can't toggle tags with mouse

2010-05-27 Thread Andreas Amann
On Thu, May 27, 2010 at 12:49:59PM +0200, orsch...@googlemail.com wrote:
> Thanks for the hint Andreas. xset -q shows a difference between both
> values. I tried to implement it into my statusbar but as I'm not
> familiar with bash scripting it doesn't work. This is my trial:
> 
> #set statusbar
> while true
> do
> #define keyboard layout
> if [ "$(xset -q | grep "LED mask:" | awk '{ print $10 }')" ==
> "" ] ; then
>   kb = "de"
> else
>   kb = "pl"
> fi
> if acpi -a | grep off-line > /dev/null; then
> xsetroot -name "Bat. $( acpi -b | awk '{ print $4 " " $5 }' |
> tr -d ',' ) | Vol. $(amixer get Master | tail -1 | awk '{ print $5}' |
> tr -d '[]') | $kb | $(date +"%a, %b %d %R")"
> else
> xsetroot -name "Vol. $(amixer get Master | tail -1 | awk '{
> print $5}' | tr -d '[]') | $kb | $(date +"%a, %b %d %R")"
> fi
> sleep 1s
> done &
> 
> Could you help me out please?

The following works for me:
while xsetroot -name "$(xset -q|sed  -ne "2 s/^.*/uk/ p; 2
s/^*/de/ p") | $(date +"%a, %b %d %Y | %H:%M")"
do
sleep 2s
done &

Andreas



Re: [dev] [dwm] can't toggle tags with mouse

2010-05-27 Thread Andreas Amann
On Thu, May 27, 2010 at 09:58:55AM +0100, Anselm R Garbe wrote:
> On 27 May 2010 09:54,   wrote:
> > Oh dear how bad has my english to be since nobody is understanding me 
> > right. *g*
> >
> > Well second approach. Currently I'm using the following code to
> > generate my statusbar:
> >
> > #set statusbar
> > while true
> > do
> >   if acpi -a | grep off-line > /dev/null; then
> >       xsetroot -name "Bat. $( acpi -b | awk '{ print $4 " " $5 }' |
> > tr -d ',' ) | Vol. $(amixer get Master | tail -1 | awk '{ print $5}' |
> > tr -d '[]') | $(date +"%a, %b %d %R")"
> >   else
> >       xsetroot -name "Vol. $(amixer get Master | tail -1 | awk '{
> > print $5}' | tr -d '[]') | $(date +"%a, %b %d %R")"
> >   fi
> >   sleep 1s
> > done &
> >
> > The point is now that I want to extend exactly this statusbar to
> > display the layout I'm using, so either 'de' or 'pl'.
> >
> > So no, I don't want to get rid of it.
> >
> > Please say you understand what I intend. :)
> 
> Sorry I didn't read the full thread.
> 
> I guess
> 
>   setxkbmap -print
> 
> might provide you the info you need to grep to decide if its de or pl.
> 

Just to clarify, Robert uses a setup equivalent to
  setxkbmap -option "grp:alt_shift_toggle" "de,pl"

This means that he toggles between de and pl layout by pressing alt+shift
simultaneously. In this case 
  setxkbmap -print 
gives the same output

xkb_keymap {
xkb_keycodes  { include "evdev+aliases(qwertz)" };
xkb_types { include "complete"  };
xkb_compat{ include "complete"  };
xkb_symbols   { include
"pc+de+pl:2+inet(evdev)+group(alt_shift_toggle)"};
xkb_geometry  { include "pc(pc104)" };
};

independent of which layout is active. 

Btw, the thread started with a valid bug report for dwm in this setup, which
could be fixed via 
diff --git a/dwm.c b/dwm.c
--- a/dwm.c
+++ b/dwm.c
@@ -43,7 +43,7 @@
 /* macros */
 #define D   if(1)
 #define BUTTONMASK  (ButtonPressMask|ButtonReleaseMask)
-#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask))
+#define CLEANMASK(mask) (mask & 
(ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
 #define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= 
(RY) && (Y) < (RY) + (RH))
 #define ISVISIBLE(C)((C->tags & C->mon->tagset[C->mon->seltags]))
 #define LENGTH(X)   (sizeof X / sizeof X[0])

not sure if you want to apply this to mainline dwm? 


Andreas




Re: [dev] [dwm] can't toggle tags with mouse

2010-05-27 Thread Andreas Amann
> you may missunderstand my question.
> 
> I'm looking for a possibility to display the used layout (in my case
> either de or pl) via xsetroot in the statusbar of dwm.
> 
> Do you have any idea how to achieve that?
> 

I also do not know of a direct way to read out the current layout. But here
is an indirect one. If you use again something like 
setxkbmap -option "grp:alt_shift_toggle,grp_led:caps" "de,pl"

then you can do 
xset -q 
and you should see that "LED mask" changes (for me at least) from 
to 1001 as you change between de and pl layout. 
You can then use this fact to script up an appropriate line for xsetroot which
shows "de" or "pl" in your statusbar.


> By the way thanks for the improved version of your patch. I applied it
> and it's still working fine. :)

Nice to hear that it fixed your bug. Since nobody has reported it before, I
conclude that swapping keyboard layouts is uncommon among dwm users, and
probably it is not worth to propose this patch for mainline dwm?



Andreas



Re: [dev] [dwm] can't toggle tags with mouse

2010-05-26 Thread Andreas Amann
On Wed, May 26, 2010 at 01:08:27AM +0200, orsch...@googlemail.com wrote:
> Sorry forgot to add a small request when we're already talking about this 
> issue.
> 
> Is there any way to display the currently used layout via xsetroot in 
> statusbar?
> 

I simply use something like 
setxkbmap -option "grp:alt_shift_toggle,grp_led:caps" "ie,de"
which uses the otherwise unused caps lock led for this.

Btw, I noticed that if you specify more than two keyboards, bits 13 and 14
in XEvent->xbutton->state seem to indicate which layout is currently
selected.  This seems to be consistent with the following macro defined in
/usr/include/X11/extensions/XKB.h :
#define XkbGroupForCoreState(s) (((s)>>13)&0x3)

Rather than including XKB.h and dealing with its macros, the better solution
might be to simply list the allowed modifiers in the CLEANMASK macro as in the
attached patch. This works for any number of keyboard layout and masks out
any other modifiers by default. Arguably the definition of CLEANMASK could
even move to config.def.h for easy tweakability by users. 


Andreas


diff --git a/dwm.c b/dwm.c
--- a/dwm.c
+++ b/dwm.c
@@ -43,7 +43,7 @@
 /* macros */
 #define D   if(1)
 #define BUTTONMASK  (ButtonPressMask|ButtonReleaseMask)
-#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask))
+#define CLEANMASK(mask) (mask & 
(ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask))
 #define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= 
(RY) && (Y) < (RY) + (RH))
 #define ISVISIBLE(C)((C->tags & C->mon->tagset[C->mon->seltags]))
 #define LENGTH(X)   (sizeof X / sizeof X[0])


Re: [dev] [dwm] can't toggle tags with mouse

2010-05-25 Thread Andreas Amann
> Whenever I use the polish layout this effect appears. The german layout on
> the other side still works fine.
> 
> What could that be?
> 


I had a similar problem when switching between uk <-> de layout. The reason
was that when the alternate second keyboard is active,
the bit 13 of XEvent->xbutton->state is switched on.

The following hack fixed it for me, but might not be very portable:


diff --git a/dwm.c b/dwm.c
--- a/dwm.c
+++ b/dwm.c
@@ -43,7 +43,7 @@
 /* macros */
 #define D   if(1)
 #define BUTTONMASK  (ButtonPressMask|ButtonReleaseMask)
-#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask))
+#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask|1L<<13))
 #define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >=
 # (RY) && (Y) < (RY) + (RH))
 #define ISVISIBLE(C)((C->tags &
 # C->mon->tagset[C->mon->seltags]))
 #define LENGTH(X)   (sizeof X / sizeof X[0])






Alternatively you can also add buttons in config.h with bit 13 set in the
event mask. The real fix fight be to rewrite CLEANMASK so that it only lets
through desirable modifiers. 

Andreas