From 14752e16770724a6a2c8202396fa96c060861a4b Mon Sep 17 00:00:00 2001 From: Michal Minář Date: Sat, 11 Feb 2017 16:28:57 +0100 Subject: keys: Super+v - insert plain text from clipboard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Improved layouts for Gothic and Witcher games. Added stylish-haskell config file Signed-off-by: Michal Minář --- src/XMonad/Local/Actions.hs | 71 +++++++++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 18 deletions(-) (limited to 'src/XMonad/Local/Actions.hs') diff --git a/src/XMonad/Local/Actions.hs b/src/XMonad/Local/Actions.hs index 4bc8d7b..71549a1 100644 --- a/src/XMonad/Local/Actions.hs +++ b/src/XMonad/Local/Actions.hs @@ -1,34 +1,39 @@ {-# LANGUAGE DoAndIfThenElse #-} +{-# LANGUAGE UnicodeSyntax #-} module XMonad.Local.Actions where -import Control.Monad -import Data.Maybe -import System.Posix.Directory -import System.Posix.Env -import System.Posix.Signals (Signal, signalProcess) +import Codec.Binary.UTF8.String +import Control.Monad +import Data.Maybe +import System.IO +import System.Posix.Directory +import System.Posix.Env +import System.Posix.Signals (Signal, signalProcess) +import System.Process (runInteractiveProcess) -import XMonad -import qualified XMonad.Actions.TopicSpace as TS +import XMonad +import qualified XMonad.Actions.TopicSpace as TS +import qualified XMonad.Util.Paste as Paste import qualified XMonad.Util.WindowProperties as WP -- local modules ************************************************************** -import qualified XMonad.Local.Config as Local +import qualified XMonad.Local.Config as Local -- launch applications ******************************************************** -spawnExplorer :: X () -spawnExplorer = do +spawnExplorer ∷ X () +spawnExplorer = do cwd <- liftIO getWorkingDirectory pth <- liftIO $ getEnvDefault "HOME" cwd spawnExplorerIn pth - -spawnExplorerIn :: String -> X () + +spawnExplorerIn ∷ String → X () spawnExplorerIn dir = spawn $ Local.explorer ++ " --no-desktop --browser " ++ dir -spawnShell :: Maybe String -> X() +spawnShell ∷ Maybe String → X() spawnShell = spawnShellIn "" -spawnShellIn :: TS.Dir -> Maybe String -> X() +spawnShellIn ∷ TS.Dir → Maybe String → X() spawnShellIn dir command = do t <- asks (terminal . config) spawn $ cmd' t @@ -39,18 +44,18 @@ spawnShellIn dir command = do cmd' t | dir == "" = t ++ run command | otherwise = "cd " ++ dir ++ " && " ++ t ++ run command -spawnTmux :: String -> X() +spawnTmux ∷ String → X() spawnTmux project = spawnShell $ Just ("tmux -c 'tmuxinator " ++ project ++ "'") -killWindowPID :: Signal -> Window -> X() +killWindowPID ∷ Signal → Window → X() killWindowPID s w = do pid <- WP.getProp32s "_NET_WM_PID" w when (isJust pid) (liftIO $ mapM_ (signalProcess s . fromIntegral) (fromJust pid)) -signalCurrentWindow :: Signal -> X() +signalCurrentWindow ∷ Signal → X() signalCurrentWindow s = withFocused (killWindowPID s) -mateRun :: X () +mateRun ∷ X () mateRun = withDisplay $ \dpy -> do rw <- asks theRoot mate_panel <- getAtom "_MATE_PANEL_ACTION" @@ -61,3 +66,33 @@ mateRun = withDisplay $ \dpy -> do setClientMessageEvent e rw mate_panel 32 panel_run 0 sendEvent dpy rw False structureNotifyMask e sync dpy False + +clipboardManager ∷ String +clipboardManager = "/usr/bin/clipit" + +runProcessAndLogError ∷ MonadIO m ⇒ FilePath → [String] → String → m (Maybe String) +runProcessAndLogError cmd args input = io $ do + (pin, pout, perr, _) <- runInteractiveProcess (encodeString cmd) (map encodeString args) Nothing Nothing + hPutStr pin input + hClose pin + output <- hGetContents pout + when (output == output) $ return () + err <- hGetContents perr + when (err == err) $ return () + hClose pout + hClose perr + unless (null err) $ hPrint stderr $ "failed to run " ++ clipboardManager ++ ": " ++ err + -- no need to waitForProcess, we ignore SIGCHLD + return $ Just output + +getClipboardText ∷ X (Maybe String) +getClipboardText = catchX + (runProcessAndLogError clipboardManager ["-c"] "") + (io $ return Nothing) + +pasteTextFromClipboard ∷ X () +pasteTextFromClipboard = do + t <- getClipboardText + case t of + Just text -> catchX (Paste.pasteString text) (io $ return ()) + Nothing -> io (return ()) -- cgit