![在xmonad中,如何绑定键盘快捷键来聚焦特定应用程序?](https://linux22.com/image/109426/%E5%9C%A8xmonad%E4%B8%AD%EF%BC%8C%E5%A6%82%E4%BD%95%E7%BB%91%E5%AE%9A%E9%94%AE%E7%9B%98%E5%BF%AB%E6%8D%B7%E9%94%AE%E6%9D%A5%E8%81%9A%E7%84%A6%E7%89%B9%E5%AE%9A%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F%EF%BC%9F.png)
例如,我想绑定Mod+ Shift+m将我带到类名为“Emacs”的窗口,这样我就可以立即切换到该应用程序,无论我在哪个工作区以及我正在关注哪个窗口。
答案1
https://stackoverflow.com/a/50427647/1663462
module WindowFinder where
import XMonad
import qualified XMonad.StackSet as W
import Control.Monad
import Data.Bool (bool)
findWindows :: String -> X [Window]
findWindows name = do
withWindowSet $ (\ws -> do
forM (W.allWindows ws)
(\w -> do
s <- withDisplay $ \d -> fmap resClass . liftIO $ getClassHint d w
return $ bool [] [w] (s == name) :: X [Window]
) >>= return . join
)
导入上述模块后,您可以设置以下键绑定:
, ((modm, xK_c), do
win' <- findWindows "Chromium"
when (length win' > 0)
(windows $ W.focusWindow $ head win')
)