diff --git a/arbtt.cabal b/arbtt.cabal
--- a/arbtt.cabal
+++ b/arbtt.cabal
@@ -1,5 +1,5 @@
 name:               arbtt
-version:            0.1.3
+version:            0.1.4
 license:            GPL
 license-file:       LICENSE
 category:           Desktop
diff --git a/src/Capture.hs b/src/Capture.hs
--- a/src/Capture.hs
+++ b/src/Capture.hs
@@ -19,7 +19,9 @@
 	p <- getWindowProperty32 dpy a rwin
 	let cwins = maybe [] (map fromIntegral) p
 
-	(fwin,_) <- getInputFocus dpy
+	(fsubwin,_) <- getInputFocus dpy
+	fwin <- followTreeUntil dpy (`elem` cwins) fsubwin
+
 	winData <- mapM (\w -> (,,) (w == fwin) <$> getWindowTitle dpy w <*> getProgramName dpy w) cwins
 
 	it <- fromIntegral `fmap` getXIdleTime dpy
@@ -32,4 +34,13 @@
 
 getProgramName :: Display -> Window -> IO String
 getProgramName dpy w = fmap resName $ getClassHint dpy w
+
+-- | 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 
 
