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

177 lines
5.3 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-12-15 00:30:18 -05:00
, runVPNMenu
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
2022-07-03 01:11:32 -04:00
-- daemons
, runBwDaemon
, runClipManager
2020-04-01 20:17:47 -04:00
) where
2022-06-26 19:27:04 -04:00
import Control.Monad.Reader
import Graphics.X11.Types
import System.Directory (XdgDirectory (..), getXdgDirectory)
2022-06-26 19:27:04 -04:00
import System.IO
import XMonad.Core hiding (spawn)
import XMonad.Internal.Dependency
2022-06-26 19:27:04 -04:00
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-12-15 00:30:18 -05:00
myDmenuVPN :: String
myDmenuVPN = "rofi-evpn"
2021-06-19 00:17:47 -04:00
myDmenuMonitors :: String
myDmenuMonitors = "rofi-autorandr"
myDmenuNetworks :: String
myDmenuNetworks = "networkmanager_dmenu"
2022-07-03 01:11:32 -04:00
myClipboardManager :: String
myClipboardManager = "greenclip"
2021-06-19 00:17:47 -04:00
--------------------------------------------------------------------------------
-- | Other internal functions
spawnDmenuCmd :: String -> [String] -> SometimesX
2022-06-28 23:27:55 -04:00
spawnDmenuCmd n = sometimesExeArgs n "rofi preset" True 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
runDevMenu :: SometimesX
2022-07-02 17:09:21 -04:00
runDevMenu = sometimesIO_ "device manager" "rofi devices" t x
2022-06-28 23:27:55 -04:00
where
t = Only_ $ localExe myDmenuDevices
x = do
c <- io $ getXdgDirectory XdgConfig "rofi/devices.yml"
spawnCmd myDmenuDevices
$ ["-c", c]
++ "--" : themeArgs "#999933"
++ myDmenuMatchingArgs
2020-05-02 00:02:29 -04:00
runBTMenu :: SometimesX
2022-06-28 23:27:55 -04:00
runBTMenu = sometimesExeArgs "bluetooth selector" "rofi bluetooth" False
myDmenuBluetooth $ "-c":themeArgs "#0044bb"
2021-11-29 00:56:16 -05:00
2020-05-02 00:02:29 -04:00
runVPNMenu :: SometimesX
2022-07-02 17:09:21 -04:00
runVPNMenu = sometimesIO_ "VPN selector" "rofi VPN"
2022-06-28 23:27:55 -04:00
(Only_ $ localExe myDmenuVPN) $ spawnCmd myDmenuVPN
$ ["-c"] ++ themeArgs "#007766" ++ myDmenuMatchingArgs
2021-12-15 00:30:18 -05:00
runCmdMenu :: SometimesX
runCmdMenu = spawnDmenuCmd "command menu" ["-show", "run"]
runAppMenu :: SometimesX
runAppMenu = spawnDmenuCmd "app launcher" ["-show", "drun"]
runWinMenu :: SometimesX
runWinMenu = spawnDmenuCmd "window switcher" ["-show", "window"]
runNetMenu :: SometimesX
2022-06-28 23:27:55 -04:00
runNetMenu = sometimesExeArgs "network control menu" "rofi NetworkManager"
True myDmenuNetworks $ themeArgs "#ff3333"
2020-08-17 18:46:02 -04:00
runAutorandrMenu :: SometimesX
2022-06-28 23:27:55 -04:00
runAutorandrMenu = sometimesExeArgs "autorandr menu" "rofi autorandr"
True myDmenuMonitors $ themeArgs "#ff0066"
2022-07-03 01:11:32 -04:00
--------------------------------------------------------------------------------
-- | Password manager
runBwDaemon :: Sometimes (IO ProcessHandle)
runBwDaemon = sometimesIO_ "password manager daemon" "rofi bitwarden" tree cmd
where
tree = Only_ $ localExe myDmenuPasswords
cmd = snd <$> spawnPipeArgs "rofi-bw" ["-d", "3600"]
runBwMenu :: SometimesX
runBwMenu = sometimesIO_ "password manager" "rofi bitwarden"
(Only_ $ IOSometimes_ runBwDaemon) $ spawnCmd myDmenuPasswords
$ ["-c"] ++ themeArgs "#bb6600" ++ myDmenuMatchingArgs
--------------------------------------------------------------------------------
-- | Clipboard
runClipManager :: Sometimes (IO ProcessHandle)
runClipManager = sometimesIO_ "clipboard daemon" "greenclip" tree cmd
where
tree = Only_ $ sysExe myClipboardManager
cmd = snd <$> spawnPipeArgs "greenclip" ["daemon"]
runClipMenu :: SometimesX
runClipMenu = sometimesIO_ "clipboard manager" "rofi greenclip" tree act
where
act = spawnCmd myDmenuCmd args
tree = toAnd (sysExe myDmenuCmd) $ IOSometimes_ runClipManager
args = [ "-modi", "\"clipboard:greenclip print\""
, "-show", "clipboard"
, "-run-command", "'{cmd}'"
] ++ themeArgs "#00c44e"
--------------------------------------------------------------------------------
-- | Shortcut menu
runShowKeys :: Always ([((KeyMask, KeySym), NamedAction)] -> X ())
runShowKeys = Always "keyboard menu" $ Option showKeysDMenu $ Always_
$ FallbackAlone fallback
where
-- TODO this should technically depend on dunst
fallback = const $ spawnNotify
$ defNoteError { body = Just $ Text "could not display keymap" }
showKeysDMenu :: SubfeatureRoot ([((KeyMask, KeySym), NamedAction)] -> X ())
showKeysDMenu = Subfeature
{ sfName = "keyboard shortcut menu"
, sfData = IORoot_ showKeys $ Only_ $ sysExe myDmenuCmd
, sfLevel = Warn
}
showKeys :: [((KeyMask, KeySym), NamedAction)] -> X ()
showKeys kbs = 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"]
++ themeArgs "#7f66ff" ++ myDmenuMatchingArgs