Should arbtt still be working with i3 window manager?

JOKer joker at someserver.de
Tue Apr 24 00:58:45 CEST 2012


On 23/04/12 14:50, Joachim Breitner wrote:
> Dear JOKer,
> 
> Am Montag, den 23.04.2012, 01:01 +0200 schrieb JOKer:
>> I've read in the release notes of 0.4.1, that arbtt should be/has been
>> usable with i3:
>>> In the absence of _NET_CLIENT_LIST, look for application windows as
>>> children of the root windows. This should work for users of window
>>> managers like i3 without EWHM support.
>>
>> If this should still be the case, I'd like to know what I'm doing wrong.
>> I'm only getting output like this from arbtt-dump:
>> TimeLogEntry {tlTime = 2012-04-22 22:30:16.254658 UTC, tlRate = 60000,
>> tlData = CaptureData {cWindows = [], cLastActivity = 581}}
>> TimeLogEntry {tlTime = 2012-04-22 22:31:16.265074 UTC, tlRate = 60000,
>> tlData = CaptureData {cWindows = [], cLastActivity = 47}}
>>
>> If not, is there a way to make it work again (other than hacking EWHM
>> support into i3)? I'd really like to try this program.
> 
> Hmm, looking at the code I don’t think this works any more. I’m happy to
> add working support for i3, as long as someone provides me with a
> patch :-)
> 
> The patch that should have added this functionality is
> 
> [Be smarter when figuring out what window is active
> Joachim Breitner <mail at joachim-breitner.de>**20090928181800
>  Ignore-this: 83d2e4798327b65d9678d8dc64c071f7
>  
>  Thanks to CJ van den Berg for the investigation.
> ] hunk ./src/Capture.hs 22
> -       (fwin,_) <- getInputFocus dpy
> +       (fsubwin,_) <- getInputFocus dpy
> +       fwin <- followTreeUntil dpy (`elem` cwins) fsubwin
> +
> hunk ./src/Capture.hs 38
> +-- | Follows the tree of windows up until the condition is met or the window is
> +-- a direct child of the root.
> +followTreeUntil :: Display -> (Window -> Bool) -> Window -> IO Window [_$_]
> +followTreeUntil dpy cond = go
> +  where go w | cond w    = return w
> +             | otherwise = do (r,p,_) <- queryTree dpy w
> +                             if r == p then return w
> +                                       else go p [_$_]
> +
> 
> And this probably broke it:
> 
> [Fix possible cause for crashes
> Joachim Breitner <mail at joachim-breitner.de>**20091008173228
>  Ignore-this: f051cdb62c622e441b69946343ab8aab
> ] hunk ./src/Capture.hs 38
> --- | Follows the tree of windows up until the condition is met or the window is
> --- a direct child of the root.
> +-- | Follows the tree of windows up until the condition is met or the root
> +-- window is reached.
> hunk ./src/Capture.hs 44
> -	                      if r == p then return w
> +	                      if p == 0 then return w
> 
> But I don’t recall why the original code crashed...
> 
> Greetings,
> Joachim
> 

Hi Joachim,
thanks for the pointer. I've tried to figure it out and came to (a
hacky) solution. It is definitely not a proper patch, but I'll post it
anyway for reference.

First of all I really don't know haskell, x11 protocol and not even how
to compile that program properly, but debian packages help a lot with
the third part. So please excuse me, if this is ugly from the language
view - I really can't tell.

Now to my solution. The problem is, that i3 does not support
_NET_CLIENT_LIST and because of that, no windows will be found and this
means, nothing will ever get written to the log file if I interpreted
that code line correctly:
winData <- forM wins $ \w -> (,,)
This is why I created a new list with just the focused window in it,
since that window will always be found. This means, the tagging cannot
be as powerful, but most of the tagging is done on the active window
anyway. This part could probably even be commited, if done properly (if
list.empty() then list = [fwin]) but as I said, my haskell is not good
enough for this.

After I got it "working" I still needed to change the followTreeUntil
function. Your commit concerning the crash fix in followTreeUntil makes
a difference in just "i3" as window name and "[i3 con] container for
0x1237112" when reverted. Since i3 can have many containers in each
other, I check for this string in the title and stop at the window right
before it. This might not be very efficient and also adds another
dependency, but it makes the program useable.

So thanks again for the prompt reply and have a nice day,
JOKer

Index: arbtt-0.6.2/src/Capture/X11.hs
===================================================================
--- arbtt-0.6.2.orig/src/Capture/X11.hs 2012-04-07 16:29:41.000000000 +0200
+++ arbtt-0.6.2/src/Capture/X11.hs  2012-04-24 00:04:45.730446886 +0200
@@ -1,6 +1,7 @@
 module Capture.X11 where

 import Data
+import Data.List.Utils
 import Graphics.X11
 import Graphics.X11.Xlib.Extras
 import Control.Monad
@@ -45,7 +46,7 @@
         (fsubwin,_) <- getInputFocus dpy
         fwin <- followTreeUntil dpy (`elem` wins) fsubwin

-        winData <- forM wins $ \w -> (,,)
+        winData <- forM [fwin] $ \w -> (,,)
             (w == fwin) <$>
             (T.pack <$> getWindowTitle dpy w) <*>
             (T.pack <$> getProgramName dpy w)
@@ -68,7 +69,10 @@
   where go w | cond w    = return w
              | otherwise = do (r,p,_) <- queryTree dpy w
                               if p == 0 then return w
-                                        else go p
+                                        else do
+                                          title <- getWindowTitle dpy p
+                                          if startswith "[i3 con]"
title == True then return w
+
else go p

 -- | better than fetchName from X11, as it supports _NET_WM_NAME and
unicode
 --
Index: arbtt-0.6.2/arbtt.cabal
===================================================================
--- arbtt-0.6.2.orig/arbtt.cabal    2012-04-23 20:12:06.034237419 +0200
+++ arbtt-0.6.2/arbtt.cabal 2012-04-23 23:48:38.462432372 +0200
@@ -31,7 +31,7 @@
     hs-source-dirs:     src
     build-depends:
         base == 4.5.*, filepath, directory, mtl, time, utf8-string,
-        bytestring, binary, deepseq
+        bytestring, binary, deepseq, MissingH
     other-modules:
         Data
         Data.MyText




More information about the arbtt mailing list