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

214 lines
5.8 KiB
Haskell
Raw Normal View History

2020-03-28 18:38:38 -04:00
--------------------------------------------------------------------------------
-- | General commands
2020-04-01 20:17:47 -04:00
module XMonad.Internal.Command.Desktop
( myTerm
, runTerm
, runCalc
, runBrowser
, runEditor
, runFileManager
, runTogglePlay
, runPrevTrack
, runNextTrack
, runStopPlay
, runVolumeDown
, runVolumeUp
, runVolumeMute
, runToggleBluetooth
, runIncBacklight
, runDecBacklight
, runMinBacklight
, runMaxBacklight
, runToggleDPMS
2020-05-28 23:17:17 -04:00
, runToggleEthernet
2020-04-01 20:17:47 -04:00
, runRestart
, runRecompile
, runAreaCapture
, runScreenCapture
, runDesktopCapture
, runCaptureBrowser
2021-02-04 21:46:04 -05:00
, runStartISyncTimer
, runStartISyncService
2020-04-01 20:17:47 -04:00
) where
import Control.Monad (void)
import System.Directory
( createDirectoryIfMissing
, getHomeDirectory
)
import System.Environment
import System.FilePath
2020-03-28 18:38:38 -04:00
import XMonad.Actions.Volume
import XMonad.Core hiding (spawn)
2020-04-01 20:17:47 -04:00
import XMonad.Internal.DBus.IntelBacklight
import XMonad.Internal.DBus.Screensaver
import XMonad.Internal.Notify
import XMonad.Internal.Process
2020-04-01 20:17:47 -04:00
import XMonad.Internal.Shell
2020-03-28 18:38:38 -04:00
import XMonad.Operations
--------------------------------------------------------------------------------
-- | Some nice apps
2020-04-01 20:17:47 -04:00
myTerm :: String
myTerm = "urxvt"
2020-03-28 18:38:38 -04:00
runTerm :: X ()
runTerm = spawn myTerm
runCalc :: X ()
runCalc = spawnCmd myTerm ["-e", "R"]
runBrowser :: X ()
2021-03-15 16:55:03 -04:00
runBrowser = spawn "brave-accel"
2020-03-28 18:38:38 -04:00
runEditor :: X ()
runEditor = spawnCmd "emacsclient"
["-c", "-e", "\"(select-frame-set-input-focus (selected-frame))\""]
runFileManager :: X ()
runFileManager = spawn "pcmanfm"
--------------------------------------------------------------------------------
-- | Multimedia Commands
myMultimediaCtl :: String
myMultimediaCtl = "playerctl"
runTogglePlay :: X ()
runTogglePlay = spawnCmd myMultimediaCtl ["play-pause"]
runPrevTrack :: X ()
runPrevTrack = spawnCmd myMultimediaCtl ["previous"]
runNextTrack :: X ()
runNextTrack = spawnCmd myMultimediaCtl ["next"]
runStopPlay :: X ()
runStopPlay = spawnCmd myMultimediaCtl ["stop"]
2020-05-31 20:56:57 -04:00
volumeChangeSound :: FilePath
volumeChangeSound = "smb_fireball.wav"
2020-03-28 18:38:38 -04:00
runVolumeDown :: X ()
runVolumeDown = spawnSound volumeChangeSound >> void (lowerVolume 2)
2020-03-28 18:38:38 -04:00
runVolumeUp :: X ()
runVolumeUp = spawnSound volumeChangeSound >> void (raiseVolume 2)
2020-03-28 18:38:38 -04:00
runVolumeMute :: X ()
2020-05-31 20:56:57 -04:00
runVolumeMute = void toggleMute >> spawnSound volumeChangeSound
2020-03-28 18:38:38 -04:00
--------------------------------------------------------------------------------
-- | System commands
runToggleBluetooth :: X ()
runToggleBluetooth = spawn
$ "bluetoothctl show | grep -q \"Powered: no\""
#!&& "a=on"
#!|| "a=off"
#!>> fmtCmd "bluetoothctl" ["power", "$a", ">", "/dev/null"]
#!&& fmtNotifyCmd defNoteInfo { body = Just $ Text "bluetooth powered $a" }
runIncBacklight :: X ()
runIncBacklight = io $ void callIncBrightness
runDecBacklight :: X ()
runDecBacklight = io $ void callDecBrightness
runMinBacklight :: X ()
runMinBacklight = io $ void callMinBrightness
runMaxBacklight :: X ()
runMaxBacklight = io $ void callMaxBrightness
runToggleDPMS :: X ()
runToggleDPMS = io $ void callToggle
2020-05-28 23:17:17 -04:00
ethernetIface :: String
ethernetIface = "enp7s0f1"
runToggleEthernet :: X ()
runToggleEthernet = spawn
$ "nmcli -g GENERAL.STATE device show " ++ ethernetIface ++ " | grep -q disconnected"
#!&& "a=connect"
#!|| "a=disconnect"
#!>> fmtCmd "nmcli" ["device", "$a", ethernetIface]
#!&& fmtNotifyCmd defNoteInfo { body = Just $ Text "ethernet \"$a\"ed" }
2021-02-04 21:46:04 -05:00
runStartISyncTimer :: X ()
runStartISyncTimer = spawn
$ "systemctl --user start mbsync.timer"
#!&& fmtNotifyCmd defNoteInfo { body = Just $ Text "Isync timer started" }
#!|| fmtNotifyCmd defNoteError { body = Just $ Text "Isync timer failed to start" }
runStartISyncService :: X ()
runStartISyncService = spawn
$ "systemctl --user start mbsync.service"
#!&& fmtNotifyCmd defNoteInfo { body = Just $ Text "Isync completed" }
#!|| fmtNotifyCmd defNoteError { body = Just $ Text "Isync failed" }
2020-03-28 18:38:38 -04:00
--------------------------------------------------------------------------------
-- | Configuration commands
runRestart :: X ()
runRestart = restart "xmonad" True
runRecompile :: X ()
runRecompile = do
-- assume that the conf directory contains a valid stack project
confDir <- getXMonadDir
spawnAt confDir $ fmtCmd "stack" ["install"]
#!&& fmtNotifyCmd defNoteInfo { body = Just $ Text "compilation succeeded" }
#!|| fmtNotifyCmd defNoteError { body = Just $ Text "compilation failed" }
-- runRecompile :: X ()
-- runRecompile = do
-- -- assume that the conf directory contains a valid stack project
-- -- TODO this is hacky AF
-- confDir <- getXMonadDir
-- spawnCmdAt confDir "stack" ["install"]
2020-04-01 20:17:47 -04:00
--------------------------------------------------------------------------------
-- | Screen capture commands
getCaptureDir :: IO FilePath
getCaptureDir = do
e <- lookupEnv "XDG_DATA_HOME"
parent <- case e of
Nothing -> fallback
Just path
| isRelative path -> fallback
| otherwise -> return path
let fullpath = parent </> "screenshots"
createDirectoryIfMissing True fullpath
return fullpath
where
fallback = (</> ".local/share") <$> getHomeDirectory
2020-04-01 20:17:47 -04:00
runFlameshot :: String -> X ()
runFlameshot mode = do
ssDir <- io getCaptureDir
2020-04-01 20:17:47 -04:00
spawnCmd "flameshot" $ mode : ["-p", ssDir]
-- TODO this will steal focus from the current window (and puts it
-- in the root window?) ...need to fix
runAreaCapture :: X ()
runAreaCapture = runFlameshot "gui"
-- myWindowCap = "screencap -w" --external script
runScreenCapture :: X ()
runScreenCapture = runFlameshot "screen"
runDesktopCapture :: X ()
runDesktopCapture = runFlameshot "full"
runCaptureBrowser :: X ()
runCaptureBrowser = do
dir <- io getCaptureDir
spawnCmd "feh" [dir]