[dev] xid of a current window
How can I get a xid of a focused window? Like with xprop, but without user interaction. Say, I want to write an program that would log the xid of a currently focused window every second. Sincerely, s.
Re: [dev] xid of a current window
On 25 March 2012 13:37, Swiatoslaw Gal wrote: > How can I get a xid of a focused window? Like with xprop, but > without user interaction. Say, I want to write an program > that would log the xid of a currently focused window every second. http://tronche.com/gui/x/xlib/input/XGetInputFocus.html Cheers, Anselm
Re: [dev] xid of a current window
On 25 March 2012 12:42, Anselm R Garbe wrote: > http://tronche.com/gui/x/xlib/input/XGetInputFocus.html Note that a Window is an integer, specifically the window's XID. cls
Re: [dev] xid of a current window
if you don't want to write something of your own, then $ xprop -root _NET_ACTIVE_WINDOW > _NET_ACTIVE_WINDOW(WINDOW): window id # 0x400050 or $ xdotool getactivewindow > 4194384 will work, as long as your wm supports and correctly sets _NET_ACTIVE_WINDOW note that xdotool outputs the id as an int, to get the same with xprop do something like: $ xprop -root _NET_ACTIVE_WINDOW | cut -d# -f2 | xargs printf "%d\n" > 4194384 some apps work with both formats, others require int xwininfo can also give you the window id, and with -int it will be in int form. On 25/03/2012, Connor Lane Smith wrote: > On 25 March 2012 12:42, Anselm R Garbe wrote: >> http://tronche.com/gui/x/xlib/input/XGetInputFocus.html > > Note that a Window is an integer, specifically the window's XID. > > cls > > -- *Ivan c00kiemon5ter V Kanakarakis *
Re: [dev] xid of a current window
-- From Ivan Kanakarakis 25-03-2012 at 15:20 -- > if you don't want to write something of your own, then > > $ xprop -root _NET_ACTIVE_WINDOW > > _NET_ACTIVE_WINDOW(WINDOW): window id # 0x400050 xprop -root shows me the values of the folowing fields: CUT_BUFFER0(STRING) WM_NAME(STRING) _NET_SUPPORTED(ATOM) ESETROOT_PMAP_ID(PIXMAP) _XROOTPMAP_ID(PIXMAP) RESOURCE_MANAGER(STRING) _XKB_RULES_NAMES(STRING) XFree86_VT(INTEGER) XFree86_DDC_EDID1_RAWDATA(INTEGER) > $ xdotool getactivewindow XGetWindowProperty[_NET_ACTIVE_WINDOW] failed (code=1) xdo_get_active_window reported an error > will work, as long as your wm supports and correctly sets _NET_ACTIVE_WINDOW I assume that this is not the case. I am using dwm. Does it matter? s.
Re: [dev] xid of a current window
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) On 25/03/2012, Swiatoslaw Gal wrote: > -- From Ivan Kanakarakis 25-03-2012 at 15:20 -- >> if you don't want to write something of your own, then >> >> $ xprop -root _NET_ACTIVE_WINDOW >> > _NET_ACTIVE_WINDOW(WINDOW): window id # 0x400050 > > xprop -root shows me the values of the folowing fields: > CUT_BUFFER0(STRING) > WM_NAME(STRING) > _NET_SUPPORTED(ATOM) > ESETROOT_PMAP_ID(PIXMAP) > _XROOTPMAP_ID(PIXMAP) > RESOURCE_MANAGER(STRING) > _XKB_RULES_NAMES(STRING) > XFree86_VT(INTEGER) > XFree86_DDC_EDID1_RAWDATA(INTEGER) > >> $ xdotool getactivewindow > XGetWindowProperty[_NET_ACTIVE_WINDOW] failed (code=1) > xdo_get_active_window reported an error > >> will work, as long as your wm supports and correctly sets >> _NET_ACTIVE_WINDOW > I assume that this is not the case. > I am using dwm. Does it matter? > > s. > > -- *Ivan c00kiemon5ter V Kanakarakis *
Re: [dev] xid of a current window
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]); +
Re: [dev] xid of a current window
On 25 March 2012 15:56, Andreas Amann wrote: > 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. Thanks, I applied both patches. Even though I really more and more hat this whole EWMH cruft. Since there was basic EWMH support in dwm, things became more unreadable... Cheers, Anselm
Re: [dev] xid of a current window
> Thanks, I applied both patches. Even though I really more and more hat > this whole EWMH cruft. Since there was basic EWMH support in dwm, > things became more unreadable... Then I start to feel guilty of my question. I've got my answer, and I do not know if anyone really needs _NET_WM_WINDOW_OPACITY to be handled by dwm. Thank you for the answers anyway, s.
Re: [dev] xid of a current window
On Sun, 25 Mar 2012, Swiatoslaw Gal wrote: -- From Ivan Kanakarakis 25-03-2012 at 15:20 -- $ xdotool getactivewindow XGetWindowProperty[_NET_ACTIVE_WINDOW] failed (code=1) xdo_get_active_window reported an error You could use the focused window instead (which was what you originally asked about): $ xdotool getwindowfocus 48234505 dwm doesn't (or didn't? - depending on today's patches) set _NET_ACTIVE_WINDOW, but there's still a focused window. -- Best, Ben
Re: [dev] xid of a current window
> 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? s.
Re: [dev] xid of a current window
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