diff --git a/.config/xmonad/xmonad.hs b/.config/xmonad/xmonad.hs index 8ed53ff..3922524 100644 --- a/.config/xmonad/xmonad.hs +++ b/.config/xmonad/xmonad.hs @@ -26,6 +26,14 @@ import XMonad.Actions.UpdateFocus (focusUnderPointer) import XMonad.Layout.NoBorders import XMonad.Layout.Spacing + +-- MultiMonitorFocusHook +import Control.Monad (when) +import Data.Foldable (find) +import Foreign.C (CInt) +import Data.Maybe (fromMaybe) +import Data.Monoid (All (All)) + --Miscellaneous import qualified XMonad.StackSet as W import qualified Data.Map as M @@ -140,6 +148,33 @@ myManageHook = composeAll , isFullscreen --> doFullFloat] myEventHook = ewmhDesktopsEventHook + + +multiScreenFocusHook :: Event -> X All +multiScreenFocusHook MotionEvent { ev_x = x, ev_y = y } = do + ms <- getScreenForPos x y + let cursorScreenID = W.screen <$> ms + focussedScreenID <- W.screen . W.current . windowset <$> get + when (cursorScreenID /= Just focussedScreenID) $ + maybe (return ()) (windows . W.view . W.tag . W.workspace) ms + return (All True) + where + getScreenForPos :: CInt -> CInt + -> X (Maybe (W.Screen WorkspaceId (Layout Window) Window ScreenId ScreenDetail)) + getScreenForPos x y = do + ws <- windowset <$> get + let screens = W.current ws : W.visible ws + inRects = map (inRect x y . screenRect . W.screenDetail) screens + return $ fst <$> find snd (zip screens inRects) + + inRect :: CInt -> CInt -> Rectangle -> Bool + inRect x y rect = + let l = fromIntegral (rect_x rect) + r = l + fromIntegral (rect_width rect) + t = fromIntegral (rect_y rect) + b = t + fromIntegral (rect_height rect) + in x >= l && x < r && y >= t && y < b + myStartupHook = do spawnOnce "pasystray" spawnOnce "nitrogen --restore &" @@ -190,6 +225,7 @@ myXmobarPP s = def myConfig = def { + rootMask = rootMask def .|. pointerMotionMask, terminal = myTerminal, focusFollowsMouse = myFocusFollowsMouse, clickJustFocuses = myClickJustFocuses, @@ -201,7 +237,7 @@ myConfig = def -- keys = myKeys, layoutHook = smartBorders . spacingWithEdge 10 $ myLayout, manageHook = manageSpawn <+> myManageHook <+> manageHook def, - handleEventHook = myEventHook <+> fullscreenEventHook <+> swallowEventHook (className=?"Alacritty") (return True) , + handleEventHook = myEventHook <+> multiScreenFocusHook <+> fullscreenEventHook <+> swallowEventHook (className=?"Alacritty") (return True), startupHook = myStartupHook }