From 7b52b34edb5d9c0dd3523787b7a627c1d147cb25 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Sun, 3 May 2020 00:04:35 -0400 Subject: [PATCH] ENH change screenshot directory to xdg_data ADD browse screen captures --- bin/xmonad.hs | 1 + lib/XMonad/Internal/Command/Desktop.hs | 32 +++++++++++++++++++++----- my-xmonad.cabal | 1 + 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/bin/xmonad.hs b/bin/xmonad.hs index af3cf54..3deb2cf 100644 --- a/bin/xmonad.hs +++ b/bin/xmonad.hs @@ -396,6 +396,7 @@ mkKeys ts c = , ("M-C-s", "capture area", runAreaCapture) , ("M-C-S-s", "capture screen", runScreenCapture) , ("M-C-d", "capture desktop", runDesktopCapture) + , ("M-C-b", "browse captures", runCaptureBrowser) -- , ("M-C-S-s", "capture focused window", spawn myWindowCap) ] ++ diff --git a/lib/XMonad/Internal/Command/Desktop.hs b/lib/XMonad/Internal/Command/Desktop.hs index 28c9535..5cc2ebc 100644 --- a/lib/XMonad/Internal/Command/Desktop.hs +++ b/lib/XMonad/Internal/Command/Desktop.hs @@ -26,11 +26,17 @@ module XMonad.Internal.Command.Desktop , runAreaCapture , runScreenCapture , runDesktopCapture + , runCaptureBrowser ) where import Control.Monad (void) -import System.Directory (getHomeDirectory) +import System.Directory + ( createDirectoryIfMissing + , getHomeDirectory + ) +import System.Environment +import System.FilePath import XMonad.Actions.Volume import XMonad.Core hiding (spawn) @@ -140,14 +146,23 @@ runRecompile = do -------------------------------------------------------------------------------- -- | Screen capture commands -getScreenshotDir :: IO FilePath -getScreenshotDir = do - h <- getHomeDirectory - return $ h ++ "/Pictures/screenshots" +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 runFlameshot :: String -> X () runFlameshot mode = do - ssDir <- io getScreenshotDir + ssDir <- io getCaptureDir spawnCmd "flameshot" $ mode : ["-p", ssDir] -- TODO this will steal focus from the current window (and puts it @@ -162,3 +177,8 @@ runScreenCapture = runFlameshot "screen" runDesktopCapture :: X () runDesktopCapture = runFlameshot "full" + +runCaptureBrowser :: X () +runCaptureBrowser = do + dir <- io getCaptureDir + spawnCmd "geeqie" [dir] diff --git a/my-xmonad.cabal b/my-xmonad.cabal index 0435012..aeb2f45 100644 --- a/my-xmonad.cabal +++ b/my-xmonad.cabal @@ -37,6 +37,7 @@ library , text >= 1.2.3.1 , directory >= 1.3.3.0 , process >= 1.6.5.0 + , filepath >= 1.4.2.1 , xmobar , xmonad-extras >= 0.15.2 , xmonad >= 0.13