2022-12-26 14:45:49 -05:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
2020-03-28 18:38:38 -04:00
|
|
|
--------------------------------------------------------------------------------
|
2022-12-30 14:58:23 -05:00
|
|
|
-- General commands
|
2020-03-28 18:38:38 -04:00
|
|
|
|
2020-04-01 20:17:47 -04:00
|
|
|
module XMonad.Internal.Command.Desktop
|
|
|
|
( myTerm
|
2022-07-03 01:11:32 -04:00
|
|
|
, playSound
|
|
|
|
-- commands
|
2020-04-01 20:17:47 -04:00
|
|
|
, runTerm
|
2021-06-17 01:17:59 -04:00
|
|
|
, runTMux
|
2020-04-01 20:17:47 -04:00
|
|
|
, runCalc
|
|
|
|
, runBrowser
|
|
|
|
, runEditor
|
|
|
|
, runFileManager
|
|
|
|
, runTogglePlay
|
|
|
|
, runPrevTrack
|
|
|
|
, runNextTrack
|
|
|
|
, runStopPlay
|
|
|
|
, runVolumeDown
|
|
|
|
, runVolumeUp
|
|
|
|
, runVolumeMute
|
|
|
|
, runToggleBluetooth
|
2020-05-28 23:17:17 -04:00
|
|
|
, runToggleEthernet
|
2020-04-01 20:17:47 -04:00
|
|
|
, runRestart
|
|
|
|
, runRecompile
|
|
|
|
, runAreaCapture
|
|
|
|
, runScreenCapture
|
|
|
|
, runDesktopCapture
|
2020-05-03 00:04:35 -04:00
|
|
|
, runCaptureBrowser
|
2021-10-24 13:30:30 -04:00
|
|
|
, runNotificationClose
|
|
|
|
, runNotificationCloseAll
|
|
|
|
, runNotificationHistory
|
|
|
|
, runNotificationContext
|
2022-07-03 01:11:32 -04:00
|
|
|
-- daemons
|
|
|
|
, runNetAppDaemon
|
2022-07-09 01:02:37 -04:00
|
|
|
-- packages
|
|
|
|
, networkManagerPkgs
|
2022-12-30 14:58:23 -05:00
|
|
|
)
|
|
|
|
where
|
|
|
|
|
|
|
|
import DBus
|
|
|
|
import Data.Internal.DBus
|
|
|
|
import Data.Internal.Dependency
|
|
|
|
import RIO
|
|
|
|
import RIO.FilePath
|
|
|
|
import qualified RIO.Process as P
|
|
|
|
import qualified RIO.Text as T
|
|
|
|
import System.Directory
|
|
|
|
import System.Environment
|
|
|
|
import System.Posix.User
|
|
|
|
import XMonad.Actions.Volume
|
|
|
|
import XMonad.Core hiding (spawn)
|
|
|
|
import XMonad.Internal.DBus.Common
|
|
|
|
import XMonad.Internal.Notify
|
|
|
|
import XMonad.Internal.Shell as S
|
|
|
|
import XMonad.Operations
|
2020-03-28 18:38:38 -04:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
2022-12-30 14:58:23 -05:00
|
|
|
-- My Executables
|
2020-03-28 18:38:38 -04:00
|
|
|
|
2022-12-26 14:45:49 -05:00
|
|
|
myTerm :: FilePath
|
2020-04-01 20:17:47 -04:00
|
|
|
myTerm = "urxvt"
|
|
|
|
|
2022-12-26 14:45:49 -05:00
|
|
|
myCalc :: FilePath
|
2022-07-09 01:02:37 -04:00
|
|
|
myCalc = "bc"
|
|
|
|
|
2022-12-26 14:45:49 -05:00
|
|
|
myBrowser :: FilePath
|
2022-09-04 15:08:05 -04:00
|
|
|
myBrowser = "brave"
|
2021-06-19 00:17:47 -04:00
|
|
|
|
2022-12-26 14:45:49 -05:00
|
|
|
myEditor :: FilePath
|
2021-06-19 00:17:47 -04:00
|
|
|
myEditor = "emacsclient"
|
|
|
|
|
2022-12-26 14:45:49 -05:00
|
|
|
myEditorServer :: FilePath
|
2022-07-08 18:17:41 -04:00
|
|
|
myEditorServer = "emacs"
|
|
|
|
|
2022-12-26 14:45:49 -05:00
|
|
|
myMultimediaCtl :: FilePath
|
2021-06-19 00:17:47 -04:00
|
|
|
myMultimediaCtl = "playerctl"
|
|
|
|
|
2022-12-26 14:45:49 -05:00
|
|
|
myBluetooth :: FilePath
|
2021-06-19 00:17:47 -04:00
|
|
|
myBluetooth = "bluetoothctl"
|
|
|
|
|
2022-12-26 14:45:49 -05:00
|
|
|
myCapture :: FilePath
|
2021-06-19 00:17:47 -04:00
|
|
|
myCapture = "flameshot"
|
|
|
|
|
2022-12-26 14:45:49 -05:00
|
|
|
myImageBrowser :: FilePath
|
2021-06-19 00:17:47 -04:00
|
|
|
myImageBrowser = "feh"
|
|
|
|
|
2022-12-26 14:45:49 -05:00
|
|
|
myNotificationCtrl :: FilePath
|
2021-10-24 13:30:30 -04:00
|
|
|
myNotificationCtrl = "dunstctl"
|
|
|
|
|
2022-07-09 01:02:37 -04:00
|
|
|
--------------------------------------------------------------------------------
|
2022-12-30 14:58:23 -05:00
|
|
|
-- Packages
|
2022-07-09 01:02:37 -04:00
|
|
|
|
|
|
|
myTermPkgs :: [Fulfillment]
|
2022-12-30 14:58:23 -05:00
|
|
|
myTermPkgs =
|
|
|
|
[ Package Official "rxvt-unicode"
|
|
|
|
, Package Official "urxvt-perls"
|
|
|
|
]
|
2022-07-09 01:02:37 -04:00
|
|
|
|
|
|
|
myEditorPkgs :: [Fulfillment]
|
2022-07-09 14:59:42 -04:00
|
|
|
myEditorPkgs = [Package Official "emacs-nativecomp"]
|
2022-07-09 01:02:37 -04:00
|
|
|
|
|
|
|
notifyPkgs :: [Fulfillment]
|
2022-07-09 14:59:42 -04:00
|
|
|
notifyPkgs = [Package Official "dunst"]
|
2022-07-09 01:02:37 -04:00
|
|
|
|
|
|
|
bluetoothPkgs :: [Fulfillment]
|
2022-07-09 14:59:42 -04:00
|
|
|
bluetoothPkgs = [Package Official "bluez-utils"]
|
2022-07-09 01:02:37 -04:00
|
|
|
|
|
|
|
networkManagerPkgs :: [Fulfillment]
|
2022-07-09 14:59:42 -04:00
|
|
|
networkManagerPkgs = [Package Official "networkmanager"]
|
2022-07-09 01:02:37 -04:00
|
|
|
|
2021-06-19 00:17:47 -04:00
|
|
|
--------------------------------------------------------------------------------
|
2022-12-30 14:58:23 -05:00
|
|
|
-- Misc constants
|
2021-06-19 00:17:47 -04:00
|
|
|
|
|
|
|
volumeChangeSound :: FilePath
|
|
|
|
volumeChangeSound = "smb_fireball.wav"
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
2022-12-30 14:58:23 -05:00
|
|
|
-- Some nice apps
|
2021-06-19 00:17:47 -04:00
|
|
|
|
2022-06-21 00:56:42 -04:00
|
|
|
runTerm :: SometimesX
|
2022-07-09 01:02:37 -04:00
|
|
|
runTerm = sometimesExe "terminal" "urxvt" myTermPkgs True myTerm
|
2021-06-19 00:17:47 -04:00
|
|
|
|
2022-06-21 00:56:42 -04:00
|
|
|
runTMux :: SometimesX
|
2022-07-02 17:09:21 -04:00
|
|
|
runTMux = sometimesIO_ "terminal multiplexer" "tmux" deps act
|
2021-06-17 01:17:59 -04:00
|
|
|
where
|
2022-12-30 14:58:23 -05:00
|
|
|
deps =
|
|
|
|
listToAnds (socketExists "tmux" [] socketName) $
|
|
|
|
fmap (sysExe myTermPkgs) [myTerm, "tmux", "bash"]
|
|
|
|
act =
|
|
|
|
S.spawn $
|
|
|
|
fmtCmd "tmux" ["has-session"]
|
|
|
|
#!&& fmtCmd myTerm ["-e", "bash", "-c", singleQuote c]
|
|
|
|
#!|| fmtNotifyCmd defNoteError {body = Just $ Text msg}
|
2021-06-17 01:17:59 -04:00
|
|
|
c = "exec tmux attach-session -d"
|
|
|
|
msg = "could not connect to tmux session"
|
2022-07-07 23:22:48 -04:00
|
|
|
socketName = do
|
|
|
|
u <- getEffectiveUserID
|
|
|
|
t <- getTemporaryDirectory
|
|
|
|
return $ t </> "tmux-" ++ show u </> "default"
|
|
|
|
|
2022-06-21 00:56:42 -04:00
|
|
|
runCalc :: SometimesX
|
2022-07-21 22:51:00 -04:00
|
|
|
runCalc = sometimesIO_ "calculator" "bc" deps act
|
2022-06-21 00:56:42 -04:00
|
|
|
where
|
2022-07-09 14:59:42 -04:00
|
|
|
deps = toAnd_ (sysExe myTermPkgs myTerm) (sysExe [Package Official "bc"] myCalc)
|
2022-12-26 14:45:49 -05:00
|
|
|
act = spawnCmd myTerm ["-e", T.pack myCalc, "-l"]
|
2020-03-28 18:38:38 -04:00
|
|
|
|
2022-06-21 00:56:42 -04:00
|
|
|
runBrowser :: SometimesX
|
2022-12-30 14:58:23 -05:00
|
|
|
runBrowser =
|
|
|
|
sometimesExe
|
|
|
|
"web browser"
|
|
|
|
"brave"
|
|
|
|
[Package AUR "brave-bin"]
|
|
|
|
False
|
|
|
|
myBrowser
|
2020-03-28 18:38:38 -04:00
|
|
|
|
2022-06-21 00:56:42 -04:00
|
|
|
runEditor :: SometimesX
|
2022-07-07 23:22:48 -04:00
|
|
|
runEditor = sometimesIO_ "text editor" "emacs" tree cmd
|
|
|
|
where
|
2022-12-30 14:58:23 -05:00
|
|
|
cmd =
|
|
|
|
spawnCmd
|
|
|
|
myEditor
|
|
|
|
["-c", "-e", doubleQuote "(select-frame-set-input-focus (selected-frame))"]
|
2022-07-09 01:02:37 -04:00
|
|
|
-- NOTE 1: we could test if the emacs socket exists, but it won't come up
|
2022-07-08 18:17:41 -04:00
|
|
|
-- before xmonad starts, so just check to see if the process has started
|
2022-12-26 14:45:49 -05:00
|
|
|
tree = toAnd_ (sysExe myEditorPkgs myEditor) $ process [] $ T.pack myEditorServer
|
2020-03-28 18:38:38 -04:00
|
|
|
|
2022-06-21 00:56:42 -04:00
|
|
|
runFileManager :: SometimesX
|
2022-12-30 14:58:23 -05:00
|
|
|
runFileManager =
|
|
|
|
sometimesExe
|
|
|
|
"file browser"
|
|
|
|
"pcmanfm"
|
|
|
|
[Package Official "pcmanfm"]
|
|
|
|
True
|
|
|
|
"pcmanfm"
|
2020-03-28 18:38:38 -04:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
2022-12-30 14:58:23 -05:00
|
|
|
-- Multimedia Commands
|
2020-03-28 18:38:38 -04:00
|
|
|
|
2022-12-26 14:45:49 -05:00
|
|
|
runMultimediaIfInstalled :: T.Text -> T.Text -> SometimesX
|
2022-12-30 14:58:23 -05:00
|
|
|
runMultimediaIfInstalled n cmd =
|
|
|
|
sometimesExeArgs
|
|
|
|
(T.append n " multimedia control")
|
|
|
|
"playerctl"
|
|
|
|
[Package Official "playerctl"]
|
|
|
|
True
|
|
|
|
myMultimediaCtl
|
|
|
|
[cmd]
|
2020-03-28 18:38:38 -04:00
|
|
|
|
2022-06-21 00:56:42 -04:00
|
|
|
runTogglePlay :: SometimesX
|
2021-11-20 19:35:24 -05:00
|
|
|
runTogglePlay = runMultimediaIfInstalled "play/pause" "play-pause"
|
2020-03-28 18:38:38 -04:00
|
|
|
|
2022-06-21 00:56:42 -04:00
|
|
|
runPrevTrack :: SometimesX
|
2021-11-20 19:35:24 -05:00
|
|
|
runPrevTrack = runMultimediaIfInstalled "previous track" "previous"
|
2020-03-28 18:38:38 -04:00
|
|
|
|
2022-06-21 00:56:42 -04:00
|
|
|
runNextTrack :: SometimesX
|
2021-11-20 19:35:24 -05:00
|
|
|
runNextTrack = runMultimediaIfInstalled "next track" "next"
|
2020-03-28 18:38:38 -04:00
|
|
|
|
2022-06-21 00:56:42 -04:00
|
|
|
runStopPlay :: SometimesX
|
2021-11-20 19:35:24 -05:00
|
|
|
runStopPlay = runMultimediaIfInstalled "stop playback" "stop"
|
2020-03-28 18:38:38 -04:00
|
|
|
|
2021-11-20 01:15:04 -05:00
|
|
|
--------------------------------------------------------------------------------
|
2022-12-30 14:58:23 -05:00
|
|
|
-- Volume Commands
|
2021-11-20 01:15:04 -05:00
|
|
|
|
|
|
|
soundDir :: FilePath
|
|
|
|
soundDir = "sound"
|
|
|
|
|
|
|
|
playSound :: MonadIO m => FilePath -> m ()
|
|
|
|
playSound file = do
|
2022-03-05 18:18:16 -05:00
|
|
|
-- manually look up directories to avoid the X monad
|
|
|
|
p <- io $ (</> soundDir </> file) . cfgDir <$> getDirectories
|
2021-11-20 01:15:04 -05:00
|
|
|
-- paplay seems to have less latency than aplay
|
2022-12-26 14:45:49 -05:00
|
|
|
spawnCmd "paplay" [T.pack p]
|
2020-05-31 20:56:57 -04:00
|
|
|
|
2022-12-26 14:45:49 -05:00
|
|
|
featureSound :: T.Text -> FilePath -> X () -> X () -> SometimesX
|
2021-11-20 19:35:24 -05:00
|
|
|
featureSound n file pre post =
|
2022-12-30 14:58:23 -05:00
|
|
|
sometimesIO_ (T.unwords ["volume", n, " control"]) "paplay" tree $
|
|
|
|
pre >> playSound file >> post
|
2022-07-09 01:02:37 -04:00
|
|
|
where
|
2022-08-08 15:00:07 -04:00
|
|
|
-- ASSUME pulseaudio pulls in libpulse as a dep; pulseaudio itself is needed
|
|
|
|
-- to play sound (duh) but libpulse is the package with the paplay binary
|
|
|
|
tree = Only_ $ sysExe [Package Official "pulseaudio"] "paplay"
|
2020-03-28 18:38:38 -04:00
|
|
|
|
2022-06-21 00:56:42 -04:00
|
|
|
runVolumeDown :: SometimesX
|
2021-11-20 19:35:24 -05:00
|
|
|
runVolumeDown = featureSound "up" volumeChangeSound (return ()) $ void (lowerVolume 2)
|
2021-11-20 01:15:04 -05:00
|
|
|
|
2022-06-21 00:56:42 -04:00
|
|
|
runVolumeUp :: SometimesX
|
2021-11-20 19:35:24 -05:00
|
|
|
runVolumeUp = featureSound "down" volumeChangeSound (return ()) $ void (raiseVolume 2)
|
2021-11-20 01:15:04 -05:00
|
|
|
|
2022-06-21 00:56:42 -04:00
|
|
|
runVolumeMute :: SometimesX
|
2021-11-20 19:35:24 -05:00
|
|
|
runVolumeMute = featureSound "mute" volumeChangeSound (void toggleMute) $ return ()
|
2020-03-28 18:38:38 -04:00
|
|
|
|
2021-10-24 13:30:30 -04:00
|
|
|
--------------------------------------------------------------------------------
|
2022-12-30 14:58:23 -05:00
|
|
|
-- Notification control
|
2021-10-24 13:30:30 -04:00
|
|
|
|
2022-12-26 14:45:49 -05:00
|
|
|
runNotificationCmd :: T.Text -> T.Text -> Maybe SesClient -> SometimesX
|
2022-07-07 23:22:48 -04:00
|
|
|
runNotificationCmd n arg cl =
|
2022-12-26 14:45:49 -05:00
|
|
|
sometimesDBus cl (T.unwords [n, "control"]) "dunstctl" tree cmd
|
2022-07-03 01:11:32 -04:00
|
|
|
where
|
2022-07-07 23:22:48 -04:00
|
|
|
cmd _ = spawnCmd myNotificationCtrl [arg]
|
2022-12-30 14:58:23 -05:00
|
|
|
tree =
|
|
|
|
toAnd_ (DBusIO $ sysExe notifyPkgs myNotificationCtrl) $
|
|
|
|
Endpoint [] notifyBus notifyPath (interfaceName_ "org.dunstproject.cmd0") $
|
|
|
|
Method_ $
|
|
|
|
memberName_ "NotificationAction"
|
2021-10-24 13:30:30 -04:00
|
|
|
|
2022-07-09 17:08:10 -04:00
|
|
|
runNotificationClose :: Maybe SesClient -> SometimesX
|
2021-11-20 19:35:24 -05:00
|
|
|
runNotificationClose = runNotificationCmd "close notification" "close"
|
2021-10-24 13:30:30 -04:00
|
|
|
|
2022-07-09 17:08:10 -04:00
|
|
|
runNotificationCloseAll :: Maybe SesClient -> SometimesX
|
2021-11-20 19:35:24 -05:00
|
|
|
runNotificationCloseAll =
|
|
|
|
runNotificationCmd "close all notifications" "close-all"
|
2021-10-24 13:30:30 -04:00
|
|
|
|
2022-07-09 17:08:10 -04:00
|
|
|
runNotificationHistory :: Maybe SesClient -> SometimesX
|
2021-11-20 19:35:24 -05:00
|
|
|
runNotificationHistory =
|
|
|
|
runNotificationCmd "see notification history" "history-pop"
|
2021-10-24 13:30:30 -04:00
|
|
|
|
2022-07-09 17:08:10 -04:00
|
|
|
runNotificationContext :: Maybe SesClient -> SometimesX
|
2021-11-20 19:35:24 -05:00
|
|
|
runNotificationContext =
|
|
|
|
runNotificationCmd "open notification context" "context"
|
2021-10-24 13:30:30 -04:00
|
|
|
|
2020-03-28 18:38:38 -04:00
|
|
|
--------------------------------------------------------------------------------
|
2022-12-30 14:58:23 -05:00
|
|
|
-- System commands
|
2020-03-28 18:38:38 -04:00
|
|
|
|
2022-07-03 01:11:32 -04:00
|
|
|
-- this is required for some vpn's to work properly with network-manager
|
2022-12-29 12:01:40 -05:00
|
|
|
runNetAppDaemon :: Maybe SysClient -> Sometimes (FIO (P.Process () () ()))
|
2022-12-30 14:58:23 -05:00
|
|
|
runNetAppDaemon cl =
|
|
|
|
Sometimes
|
|
|
|
"network applet"
|
|
|
|
xpfVPN
|
|
|
|
[Subfeature (DBusRoot_ cmd tree cl) "NM-applet"]
|
2022-07-03 01:11:32 -04:00
|
|
|
where
|
2022-07-09 01:02:37 -04:00
|
|
|
tree = toAnd_ app $ Bus networkManagerPkgs networkManagerBus
|
2022-07-09 14:59:42 -04:00
|
|
|
app = DBusIO $ sysExe [Package Official "network-manager-applet"] "nm-applet"
|
2022-12-29 12:01:40 -05:00
|
|
|
cmd _ = P.proc "nm-applet" [] (P.startProcess . P.setCreateGroup True)
|
2022-07-03 01:11:32 -04:00
|
|
|
|
2022-07-09 17:08:10 -04:00
|
|
|
runToggleBluetooth :: Maybe SysClient -> SometimesX
|
2022-12-30 14:58:23 -05:00
|
|
|
runToggleBluetooth cl =
|
|
|
|
Sometimes
|
|
|
|
"bluetooth toggle"
|
|
|
|
xpfBluetooth
|
|
|
|
[Subfeature (DBusRoot_ cmd tree cl) "bluetoothctl"]
|
2022-07-07 19:20:21 -04:00
|
|
|
where
|
2022-07-09 01:02:37 -04:00
|
|
|
tree = And_ (Only_ $ DBusIO $ sysExe bluetoothPkgs myBluetooth) (Only_ $ Bus [] btBus)
|
2022-12-30 14:58:23 -05:00
|
|
|
cmd _ =
|
|
|
|
S.spawn $
|
|
|
|
fmtCmd myBluetooth ["show"]
|
|
|
|
#!| "grep -q \"Powered: no\""
|
|
|
|
#!&& "a=on"
|
|
|
|
#!|| "a=off"
|
|
|
|
#!>> fmtCmd myBluetooth ["power", "$a", ">", "/dev/null"]
|
|
|
|
#!&& fmtNotifyCmd defNoteInfo {body = Just $ Text "bluetooth powered $a"}
|
2020-03-28 18:38:38 -04:00
|
|
|
|
2022-06-21 00:56:42 -04:00
|
|
|
runToggleEthernet :: SometimesX
|
2022-12-30 14:58:23 -05:00
|
|
|
runToggleEthernet =
|
|
|
|
Sometimes
|
|
|
|
"ethernet toggle"
|
|
|
|
xpfEthernet
|
|
|
|
[Subfeature root "nmcli"]
|
2022-07-07 19:20:21 -04:00
|
|
|
where
|
2022-12-30 14:58:23 -05:00
|
|
|
root =
|
|
|
|
IORoot cmd $
|
|
|
|
And1 (Only readEthernet) $
|
|
|
|
Only_ $
|
|
|
|
sysExe networkManagerPkgs "nmcli"
|
2022-07-07 19:20:21 -04:00
|
|
|
-- TODO make this less noisy
|
2022-12-30 14:58:23 -05:00
|
|
|
cmd iface =
|
|
|
|
S.spawn $
|
|
|
|
fmtCmd "nmcli" ["-g", "GENERAL.STATE", "device", "show", iface]
|
|
|
|
#!| "grep -q disconnected"
|
|
|
|
#!&& "a=connect"
|
|
|
|
#!|| "a=disconnect"
|
|
|
|
#!>> fmtCmd "nmcli" ["device", "$a", iface]
|
|
|
|
#!&& fmtNotifyCmd defNoteInfo {body = Just $ Text "ethernet \"$a\"ed"}
|
2020-05-28 23:17:17 -04:00
|
|
|
|
2020-03-28 18:38:38 -04:00
|
|
|
--------------------------------------------------------------------------------
|
2022-12-30 14:58:23 -05:00
|
|
|
-- Configuration commands
|
2020-03-28 18:38:38 -04:00
|
|
|
|
|
|
|
runRestart :: X ()
|
|
|
|
runRestart = restart "xmonad" True
|
|
|
|
|
2022-08-30 00:21:21 -04:00
|
|
|
-- TODO only recompile the VM binary if we have virtualbox enabled
|
2020-03-28 18:38:38 -04:00
|
|
|
runRecompile :: X ()
|
|
|
|
runRecompile = do
|
|
|
|
-- assume that the conf directory contains a valid stack project
|
2022-03-05 18:18:16 -05:00
|
|
|
confDir <- asks (cfgDir . directories)
|
2022-12-30 14:58:23 -05:00
|
|
|
spawn $
|
|
|
|
fmtCmd "cd" [T.pack confDir]
|
|
|
|
#!&& fmtCmd "stack" ["install"]
|
|
|
|
#!&& fmtNotifyCmd defNoteInfo {body = Just $ Text "compilation succeeded"}
|
|
|
|
#!|| fmtNotifyCmd defNoteError {body = Just $ Text "compilation failed"}
|
2020-04-06 00:14:56 -04:00
|
|
|
|
2020-04-01 20:17:47 -04:00
|
|
|
--------------------------------------------------------------------------------
|
2022-12-30 14:58:23 -05:00
|
|
|
-- Screen capture commands
|
2020-04-01 20:17:47 -04:00
|
|
|
|
2020-05-03 00:04:35 -04:00
|
|
|
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
|
|
|
|
2022-12-26 14:45:49 -05:00
|
|
|
runFlameshot :: T.Text -> T.Text -> Maybe SesClient -> SometimesX
|
|
|
|
runFlameshot n mode cl = sometimesDBus cl n (T.pack myCapture) tree cmd
|
2022-07-07 23:22:48 -04:00
|
|
|
where
|
|
|
|
cmd _ = spawnCmd myCapture [mode]
|
2022-12-30 14:58:23 -05:00
|
|
|
tree =
|
|
|
|
toAnd_ (DBusIO $ sysExe [Package Official "flameshot"] myCapture) $
|
|
|
|
Bus [] $
|
|
|
|
busName_ "org.flameshot.Flameshot"
|
2020-04-01 20:17:47 -04:00
|
|
|
|
|
|
|
-- TODO this will steal focus from the current window (and puts it
|
|
|
|
-- in the root window?) ...need to fix
|
2022-07-09 17:08:10 -04:00
|
|
|
runAreaCapture :: Maybe SesClient -> SometimesX
|
2021-11-20 19:35:24 -05:00
|
|
|
runAreaCapture = runFlameshot "screen area capture" "gui"
|
2020-04-01 20:17:47 -04:00
|
|
|
|
|
|
|
-- myWindowCap = "screencap -w" --external script
|
|
|
|
|
2022-07-09 17:08:10 -04:00
|
|
|
runDesktopCapture :: Maybe SesClient -> SometimesX
|
2021-11-20 19:35:24 -05:00
|
|
|
runDesktopCapture = runFlameshot "fullscreen capture" "full"
|
2020-05-03 00:04:35 -04:00
|
|
|
|
2022-07-09 17:08:10 -04:00
|
|
|
runScreenCapture :: Maybe SesClient -> SometimesX
|
2021-11-20 19:35:24 -05:00
|
|
|
runScreenCapture = runFlameshot "screen capture" "screen"
|
2021-06-19 00:54:01 -04:00
|
|
|
|
2022-06-21 00:56:42 -04:00
|
|
|
runCaptureBrowser :: SometimesX
|
2022-12-30 14:58:23 -05:00
|
|
|
runCaptureBrowser = sometimesIO_
|
|
|
|
"screen capture browser"
|
|
|
|
"feh"
|
|
|
|
(Only_ $ sysExe [Package Official "feh"] myImageBrowser)
|
|
|
|
$ do
|
|
|
|
dir <- io getCaptureDir
|
|
|
|
spawnCmd myImageBrowser [T.pack dir]
|