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
|
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
|
2020-03-28 14:44:50 -04:00
|
|
|
|
|
|
|
import Control.Monad.Reader
|
|
|
|
|
|
|
|
import Graphics.X11.Types
|
|
|
|
|
2021-11-07 13:35:08 -05:00
|
|
|
import System.Directory (XdgDirectory (..), getXdgDirectory)
|
2020-03-28 14:44:50 -04:00
|
|
|
import System.IO
|
|
|
|
|
2021-11-07 13:35:08 -05:00
|
|
|
import XMonad.Core hiding (spawn)
|
|
|
|
import XMonad.Internal.Dependency
|
2021-06-20 13:55:31 -04:00
|
|
|
import XMonad.Internal.Notify
|
2020-04-06 00:14:56 -04:00
|
|
|
import XMonad.Internal.Process
|
2020-03-28 14:44:50 -04:00
|
|
|
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
|
|
|
|
2020-03-28 14:44:50 -04:00
|
|
|
myDmenuCmd :: String
|
|
|
|
myDmenuCmd = "rofi"
|
|
|
|
|
2021-06-19 00:17:47 -04:00
|
|
|
myDmenuDevices :: String
|
|
|
|
myDmenuDevices = "rofi-dev"
|
|
|
|
|
|
|
|
myDmenuPasswords :: String
|
|
|
|
myDmenuPasswords = "rofi-bw"
|
|
|
|
|
|
|
|
myDmenuMonitors :: String
|
|
|
|
myDmenuMonitors = "rofi-autorandr"
|
|
|
|
|
|
|
|
myDmenuNetworks :: String
|
|
|
|
myDmenuNetworks = "networkmanager_dmenu"
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
-- | Other internal functions
|
|
|
|
|
|
|
|
spawnDmenuCmd :: [String] -> IO MaybeX
|
|
|
|
spawnDmenuCmd = spawnCmdIfInstalled 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-06-19 00:17:47 -04:00
|
|
|
runDevMenu :: IO MaybeX
|
2021-06-20 17:17:30 -04:00
|
|
|
runDevMenu = runIfInstalled [exe 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-06-19 00:17:47 -04:00
|
|
|
runBwMenu :: IO MaybeX
|
2021-06-20 17:17:30 -04:00
|
|
|
runBwMenu = runIfInstalled [exe myDmenuPasswords] $
|
2021-09-05 12:22:16 -04:00
|
|
|
spawnCmd myDmenuPasswords $ ["-c"] ++ themeArgs "#bb6600" ++ myDmenuMatchingArgs
|
2020-05-02 00:02:29 -04:00
|
|
|
|
2020-03-28 14:44:50 -04:00
|
|
|
runShowKeys :: [((KeyMask, KeySym), NamedAction)] -> NamedAction
|
|
|
|
runShowKeys x = addName "Show Keybindings" $ do
|
2021-06-20 13:55:31 -04:00
|
|
|
s <- io $ runDMenuShowKeys x
|
|
|
|
ifInstalled s
|
|
|
|
$ spawnNotify
|
|
|
|
$ defNoteError { body = Just $ Text "could not display keymap" }
|
|
|
|
|
|
|
|
runDMenuShowKeys :: [((KeyMask, KeySym), NamedAction)] -> IO MaybeX
|
2021-06-20 17:17:30 -04:00
|
|
|
runDMenuShowKeys kbs = runIfInstalled [exe myDmenuCmd] $ io $ do
|
2021-06-20 13:55:31 -04:00
|
|
|
(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
|
2020-03-28 14:44:50 -04:00
|
|
|
|
2021-06-19 00:17:47 -04:00
|
|
|
runCmdMenu :: IO MaybeX
|
2020-07-06 03:06:44 -04:00
|
|
|
runCmdMenu = spawnDmenuCmd ["-show", "run"]
|
2020-03-28 14:44:50 -04:00
|
|
|
|
2021-06-19 00:17:47 -04:00
|
|
|
runAppMenu :: IO MaybeX
|
2020-07-06 03:06:44 -04:00
|
|
|
runAppMenu = spawnDmenuCmd ["-show", "drun"]
|
2020-03-28 14:44:50 -04:00
|
|
|
|
2021-06-19 00:17:47 -04:00
|
|
|
runClipMenu :: IO MaybeX
|
2021-06-22 00:01:07 -04:00
|
|
|
runClipMenu = runIfInstalled [exe myDmenuCmd, exe "greenclip"]
|
|
|
|
$ spawnCmd myDmenuCmd args
|
|
|
|
where
|
|
|
|
args = [ "-modi", "\"clipboard:greenclip print\""
|
|
|
|
, "-show", "clipboard"
|
|
|
|
, "-run-command", "'{cmd}'"
|
|
|
|
] ++ themeArgs "#00c44e"
|
2020-03-28 14:44:50 -04:00
|
|
|
|
2021-06-19 00:17:47 -04:00
|
|
|
runWinMenu :: IO MaybeX
|
2020-07-06 03:06:44 -04:00
|
|
|
runWinMenu = spawnDmenuCmd ["-show", "window"]
|
2020-03-28 14:44:50 -04:00
|
|
|
|
2021-06-19 00:17:47 -04:00
|
|
|
runNetMenu :: IO MaybeX
|
|
|
|
runNetMenu = spawnCmdIfInstalled myDmenuNetworks $ themeArgs "#ff3333"
|
2020-08-17 18:46:02 -04:00
|
|
|
|
2021-06-19 00:17:47 -04:00
|
|
|
runAutorandrMenu :: IO MaybeX
|
|
|
|
runAutorandrMenu = spawnCmdIfInstalled myDmenuMonitors $ themeArgs "#ff0066"
|