xmonad-config/lib/XMonad/Internal/Command/DMenu.hs

129 lines
3.8 KiB
Haskell
Raw Normal View History

2020-04-01 22:06:00 -04:00
--------------------------------------------------------------------------------
-- | Dmenu (Rofi) Commands
2020-04-01 20:17:47 -04:00
module XMonad.Internal.Command.DMenu
( runCmdMenu
, runAppMenu
, runClipMenu
, runWinMenu
, runNetMenu
, runDevMenu
2020-05-02 00:02:29 -04:00
, runBwMenu
2021-11-29 00:56:16 -05:00
, runBTMenu
2020-04-01 20:17:47 -04:00
, runShowKeys
2020-08-17 18:46:02 -04:00
, runAutorandrMenu
2020-04-01 20:17:47 -04:00
) where
import Control.Monad.Reader
import Graphics.X11.Types
import System.Directory (XdgDirectory (..), getXdgDirectory)
import System.IO
import XMonad.Core hiding (spawn)
import XMonad.Internal.Dependency
import XMonad.Internal.Notify
import XMonad.Internal.Process
2021-11-21 10:26:28 -05:00
import XMonad.Internal.Shell
import XMonad.Util.NamedActions
2020-04-01 22:06:00 -04:00
--------------------------------------------------------------------------------
2021-06-19 00:17:47 -04:00
-- | DMenu executables
2020-04-01 22:06:00 -04:00
myDmenuCmd :: String
myDmenuCmd = "rofi"
2021-06-19 00:17:47 -04:00
myDmenuDevices :: String
myDmenuDevices = "rofi-dev"
myDmenuPasswords :: String
myDmenuPasswords = "rofi-bw"
2021-11-29 00:56:16 -05:00
myDmenuBluetooth :: String
myDmenuBluetooth = "rofi-bt"
2021-06-19 00:17:47 -04:00
myDmenuMonitors :: String
myDmenuMonitors = "rofi-autorandr"
myDmenuNetworks :: String
myDmenuNetworks = "networkmanager_dmenu"
--------------------------------------------------------------------------------
-- | Other internal functions
spawnDmenuCmd :: String -> [String] -> FeatureX
2021-11-21 10:26:28 -05:00
spawnDmenuCmd n = featureExeArgs n myDmenuCmd
2020-04-01 22:06:00 -04:00
2020-08-15 17:00:13 -04:00
themeArgs :: String -> [String]
themeArgs hexColor =
[ "-theme-str"
, "'#element.selected.normal { background-color: " ++ hexColor ++ "; }'"
]
myDmenuMatchingArgs :: [String]
myDmenuMatchingArgs = ["-i"] -- case insensitivity
2020-04-01 22:06:00 -04:00
--------------------------------------------------------------------------------
-- | Exported Commands
2021-11-20 01:15:04 -05:00
runDevMenu :: FeatureX
2021-11-21 10:26:28 -05:00
runDevMenu = featureDefault "device manager" [Executable myDmenuDevices] $ do
2021-06-19 00:17:47 -04:00
c <- io $ getXdgDirectory XdgConfig "rofi/devices.yml"
spawnCmd myDmenuDevices
$ ["-c", c]
++ "--" : themeArgs "#999933"
++ myDmenuMatchingArgs
2020-05-02 00:02:29 -04:00
2021-11-29 00:56:16 -05:00
runBTMenu :: FeatureX
runBTMenu = featureExeArgs "bluetooth selector" myDmenuBluetooth
$ "-c":themeArgs "#0044bb"
2021-11-20 01:15:04 -05:00
runBwMenu :: FeatureX
2021-11-21 10:26:28 -05:00
runBwMenu = featureDefault "password manager" [Executable myDmenuPasswords] $
spawnCmd myDmenuPasswords $ ["-c"] ++ themeArgs "#bb6600" ++ myDmenuMatchingArgs
2020-05-02 00:02:29 -04:00
2021-11-20 01:15:04 -05:00
-- TODO this is weirdly inverted
runShowKeys :: [((KeyMask, KeySym), NamedAction)] -> NamedAction
runShowKeys x = addName "Show Keybindings" $ do
2021-11-20 01:15:04 -05:00
s <- io $ evalFeature $ runDMenuShowKeys x
2021-11-21 10:26:28 -05:00
ifSatisfied s
$ spawnNotify
$ defNoteError { body = Just $ Text "could not display keymap" }
2021-11-20 01:15:04 -05:00
runDMenuShowKeys :: [((KeyMask, KeySym), NamedAction)] -> FeatureX
runDMenuShowKeys kbs =
2021-11-21 10:26:28 -05:00
featureDefault "keyboard shortcut menu" [Executable myDmenuCmd] $ io $ do
(h, _, _, _) <- createProcess' $ (shell' cmd) { std_in = CreatePipe }
forM_ h $ \h' -> hPutStr h' (unlines $ showKm kbs) >> hClose h'
where
cmd = fmtCmd myDmenuCmd $ ["-dmenu", "-p", "commands"]
2021-09-06 00:30:06 -04:00
++ themeArgs "#7f66ff" ++ myDmenuMatchingArgs
2021-11-20 01:15:04 -05:00
runCmdMenu :: FeatureX
runCmdMenu = spawnDmenuCmd "command menu" ["-show", "run"]
2021-11-20 01:15:04 -05:00
runAppMenu :: FeatureX
runAppMenu = spawnDmenuCmd "app launcher" ["-show", "drun"]
2021-11-20 01:15:04 -05:00
runClipMenu :: FeatureX
runClipMenu =
2021-11-21 10:26:28 -05:00
featureDefault "clipboard manager" [Executable myDmenuCmd, Executable "greenclip"]
2021-06-22 00:01:07 -04:00
$ spawnCmd myDmenuCmd args
where
args = [ "-modi", "\"clipboard:greenclip print\""
, "-show", "clipboard"
, "-run-command", "'{cmd}'"
] ++ themeArgs "#00c44e"
2021-11-20 01:15:04 -05:00
runWinMenu :: FeatureX
runWinMenu = spawnDmenuCmd "window switcher" ["-show", "window"]
2021-11-20 01:15:04 -05:00
runNetMenu :: FeatureX
runNetMenu =
2021-11-21 10:26:28 -05:00
featureExeArgs "network control menu" myDmenuNetworks $ themeArgs "#ff3333"
2020-08-17 18:46:02 -04:00
2021-11-20 01:15:04 -05:00
runAutorandrMenu :: FeatureX
runAutorandrMenu =
2021-11-21 10:26:28 -05:00
featureExeArgs "autorandr menu" myDmenuMonitors $ themeArgs "#ff0066"