[XMonad] Add the ability to select chrome tabs to window go

This commit is contained in:
Ivan Malison 2017-03-31 22:36:15 -07:00
parent 36020f301e
commit 24e59e3035
No known key found for this signature in database
GPG Key ID: 62530EFBE99DC2F8

View File

@ -9,6 +9,7 @@ import Control.Monad.Trans.Maybe
import Data.Aeson import Data.Aeson
import qualified Data.ByteString.Lazy as B import qualified Data.ByteString.Lazy as B
import Data.List import Data.List
import Data.List.Split
import qualified Data.Map as M import qualified Data.Map as M
import Data.Maybe import Data.Maybe
import qualified Data.MultiMap as MM import qualified Data.MultiMap as MM
@ -57,6 +58,7 @@ import XMonad.Util.Minimize
import XMonad.Util.NamedScratchpad import XMonad.Util.NamedScratchpad
(NamedScratchpad(NS), nonFloating, namedScratchpadAction) (NamedScratchpad(NS), nonFloating, namedScratchpadAction)
import XMonad.Util.NamedWindows (getName) import XMonad.Util.NamedWindows (getName)
import XMonad.Util.Run
main = main =
xmonad . docks . pagerHints . ewmh $ xmonad . docks . pagerHints . ewmh $
@ -322,20 +324,67 @@ myDecorateName ws w = do
return $ printf "%-20s%-40s %+30s" classTitle (take 40 name) return $ printf "%-20s%-40s %+30s" classTitle (take 40 name)
"in " ++ workspaceToName (W.tag ws) "in " ++ workspaceToName (W.tag ws)
data ChromeInfo = ChromeInfo { tabId :: Int
, tabUri :: String
, tabTitle :: String
} deriving (Eq, Show)
getChromeTabInfo = do
output <- runProcessWithInput "chromix-too" ["ls"] ""
return $ M.fromList $ map parseChromixLine $ lines output
where parseChromixLine line =
case splitOn " " line of
tid:uri:rest -> let ttl = concat rest in
(printf "%s - %s" tid ttl :: String,
ChromeInfo { tabId = read tid
, tabUri = uri
, tabTitle = ttl
})
selectChromeTab WindowBringerConfig { menuCommand = cmd
, menuArgs = args
} =
liftIO getChromeTabInfo >>= void . DM.menuMapArgs cmd args
chromeTabAction doSplit action selected =
case selected of
Left wid -> action wid
Right ChromeInfo { tabId = tid } ->
liftIO $ do
let command = if doSplit then
"split_tab_by_id.sh"
else
"focus_tab_by_id.sh"
_ <- io $ runProcessWithInput command [show tid] ""
return ()
-- This needs access to X in order to unminimize, which means that it can't be -- This needs access to X in order to unminimize, which means that it can't be
-- done with the existing window bringer interface -- done with the existing window bringer interface
myWindowAct c@WindowBringerConfig { menuCommand = cmd myWindowAct c@WindowBringerConfig { menuCommand = cmd
, menuArgs = args , menuArgs = args
} action = } action =
do do
visible <- visibleWindows visible <- visibleWindows
windowMap' c { windowFilter = not . flip elem visible } >>= ws <- windowMap' c { windowFilter = not . flip elem visible }
DM.menuMapArgs cmd args >>= flip whenJust action chromeTabs <- liftIO getChromeTabInfo
let options = M.union (M.map Left ws) (M.map Right chromeTabs)
selection <- DM.menuMapArgs cmd args options
whenJust selection action
doBringWindow window =
maximizeWindow window >> windows (W.focusWindow window . bringWindow window)
myBringWindow window = myWindowAction = andDeactivateFull . maybeUnminimizeAfter .
maximizeWindow window >> (windows $ W.focusWindow window . bringWindow window) myWindowAct myWindowBringerConfig
myGoToWindow =
myWindowAction $ chromeTabAction False $ windows . greedyFocusWindow
myBringWindow = myWindowAction $ chromeTabAction True doBringWindow
myReplaceWindow =
swapMinimizeStateAfter $ myWindowAct myWindowBringerConfig $
chromeTabAction True (windows . swapFocusedWith)
-- Dynamic Workspace Renaming -- Dynamic Workspace Renaming
@ -660,18 +709,14 @@ addKeys conf@XConfig { modMask = modm } =
-- Window manipulation -- Window manipulation
, ((modm, xK_g), andDeactivateFull . maybeUnminimizeAfter $ , ((modm, xK_g), myGoToWindow)
myWindowAct myWindowBringerConfig $ windows . greedyFocusWindow) , ((modm, xK_b), myBringWindow)
, ((modm .|. shiftMask, xK_g), andDeactivateFull . sameClassOnly $ , ((modm .|. shiftMask, xK_b), myReplaceWindow)
actionMenu myWindowBringerConfig greedyFocusWindow)
, ((modm, xK_b), andDeactivateFull $ myWindowAct myWindowBringerConfig myBringWindow)
, ((modm .|. shiftMask, xK_b),
swapMinimizeStateAfter $ myWindowAct myWindowBringerConfig $ windows . swapFocusedWith)
, ((modm .|. controlMask, xK_space), goFullscreen) , ((modm .|. controlMask, xK_space), goFullscreen)
, ((modm, xK_m), withFocused minimizeWindow) , ((modm, xK_m), withFocused minimizeWindow)
, ((modm .|. shiftMask, xK_m), , ((modm .|. shiftMask, xK_m),
deactivateFullOr $ withLastMinimized maximizeWindowAndFocus) deactivateFullOr $ withLastMinimized maximizeWindowAndFocus)
, ((modm, xK_x), addHiddenWorkspace "NSP" >> (windows $ W.shift "NSP")) , ((modm, xK_x), addHiddenWorkspace "NSP" >> windows (W.shift "NSP"))
, ((modalt, xK_space), deactivateFullOr restoreOrMinimizeOtherClasses) , ((modalt, xK_space), deactivateFullOr restoreOrMinimizeOtherClasses)
, ((modalt, xK_Return), deactivateFullAnd restoreAllMinimized) , ((modalt, xK_Return), deactivateFullAnd restoreAllMinimized)