summaryrefslogtreecommitdiffstats
path: root/src/desktops.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/desktops.hs')
-rw-r--r--src/desktops.hs13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/desktops.hs b/src/desktops.hs
index fd5f99d..9b64e2d 100644
--- a/src/desktops.hs
+++ b/src/desktops.hs
@@ -1,15 +1,16 @@
{-# LANGUAGE LambdaCase #-}
module Main (main) where
+import Data.List (elemIndex)
import Data.Map (Map)
import Data.Maybe (fromMaybe)
-import Graphics.X11.EWMH (getCurrentDesktop, getDesktopNames, setDesktopNames)
+import Graphics.X11.EWMH (getCurrentDesktop, getDesktopNames, setDesktopNames, switchToDesktop)
import Graphics.X11.Extra (withDefaultDisplay)
+import System.Environment (getArgs)
import qualified Data.Aeson as Aeson
import qualified Data.ByteString.Lazy.Char8 as LBS8
import qualified Data.Map.Strict as Map
import qualified Data.Set as Set
-import System.Environment (getArgs)
main :: IO ()
@@ -28,6 +29,7 @@ main =
(x:y:xs) -> (x,y) : pairUp xs
_ -> []
"set" : names -> setWorkspaces names
+ "switch" : name : [] -> switchToWorkspace name
x -> error $ "bad command: " <> show x
getWorkspaces :: IO ()
@@ -68,3 +70,10 @@ renameWorkspaces renames = do
setWorkspaces :: [String] -> IO ()
setWorkspaces = withDefaultDisplay . setDesktopNames
+
+switchToWorkspace :: String -> IO ()
+switchToWorkspace name =
+ withDefaultDisplay $ \dpy -> do
+ names <- fromMaybe [] <$> getDesktopNames dpy
+ let Just i = name `elemIndex` names
+ switchToDesktop dpy (fromIntegral i)