greenclip 3.3.0 → 3.4.0
raw patch · 4 files changed
+30/−27 lines, 4 files
Files
- README.md +1/−1
- greenclip.cabal +1/−1
- src/Clipboard.hs +20/−18
- src/Main.hs +8/−7
README.md view
@@ -25,7 +25,7 @@ 1. It's a static binary so drop it anywhere in your $PATH env -```wget https://github.com/erebe/greenclip/releases/download/3.2/greenclip```+```wget https://github.com/erebe/greenclip/releases/download/3.3/greenclip``` Alternatively if you are using Archlinux you can install the package from AUR
greenclip.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack name: greenclip-version: 3.3.0+version: 3.4.0 synopsis: Simple clipboard manager to be integrated with rofi description: Simple clipboard manager to be integrated with rofi - Please see README.md category: Linux Desktop
src/Clipboard.hs view
@@ -8,18 +8,18 @@ module Clipboard where import Protolude hiding ((<&>))-import Unsafe (unsafeIndex)+import Protolude.Unsafe (unsafeIndex)+import qualified Protolude.Conv as StrConvOld import Graphics.X11.Xlib import Graphics.X11.Xlib.Extras -import Control.Concurrent (threadDelay) import Data.Binary (Binary) import qualified Data.ByteString as B import Lens.Micro import System.Directory (setCurrentDirectory)-import System.IO (hClose, stderr, stdin, stdout)+import System.IO (hClose) import System.Posix.Process (forkProcess) import Data.ByteString (unpack)@@ -52,7 +52,7 @@ test :: IO () test = bracket getXorgContext destroyXorgContext $ \ctx -> do- ret <- getPrimarySelection ctx+ ret <- getPrimarySelection ctx True print $! ret return () @@ -123,17 +123,19 @@ return $ Just retval -getClipboardSelection :: XorgContext -> IO (Maybe Selection)-getClipboardSelection ctx@XorgContext{..} =- getSelection ctx defaultClipboard+getClipboardSelection :: XorgContext -> Bool -> IO (Maybe Selection)+getClipboardSelection ctx@XorgContext{..} enableImage =+ getSelection ctx enableImage defaultClipboard -getPrimarySelection :: XorgContext -> IO (Maybe Selection)-getPrimarySelection ctx@XorgContext{..} =- getSelection ctx primaryClipboard+getPrimarySelection :: XorgContext -> Bool -> IO (Maybe Selection)+getPrimarySelection ctx@XorgContext{..} enableImage =+ getSelection ctx enableImage primaryClipboard -getSelection :: XorgContext -> Atom -> IO (Maybe Selection)-getSelection ctx@XorgContext{..} clipboard = do- mimes <- getSupportedMimes ctx clipboard+getSelection :: XorgContext -> Bool -> Atom -> IO (Maybe Selection)+getSelection ctx@XorgContext{..} enableImage clipboard = do+ mimes <- if enableImage + then getSupportedMimes ctx clipboard + else return [defaultMime] let targetMime = chooseSelectionType mimes xConvertSelection display clipboard targetMime selectionTarget ownWindow currentTime@@ -161,7 +163,7 @@ if mimeTarget == unsafeIndex mimesPriorities 0 then PNG selContent else if mimeTarget == unsafeIndex mimesPriorities 1 then JPEG selContent else if mimeTarget == unsafeIndex mimesPriorities 2 then BITMAP selContent- else UTF8 $ toS selContent+ else UTF8 $ decodeUtf8 selContent -- getContentIncrementally acc = do -- _ <- xDeleteProperty display ownWindow selectionTarget@@ -182,7 +184,7 @@ clipboard <- internAtom display "CLIPBOARD" False selTarget <- internAtom display "GREENCLIP" False- priorities <- traverse (\atomName -> internAtom display atomName False) ["image/png", "image/jpeg", "image/bmp", "UTF8_STRING", "TEXT"]+ priorities <- traverse (\atomName -> internAtom display atomName False) ["image/png", "image/jpeg", "image/bmp", "UTF8_STRING", "TEXT"] defaultM <- internAtom display "UTF8_STRING" False return XorgContext { display = display@@ -239,7 +241,7 @@ getContent (PNG bytes) = bytes getContent (JPEG bytes) = bytes getContent (BITMAP bytes) = bytes-getContent (UTF8 txt) = toS txt+getContent (UTF8 txt) = encodeUtf8 txt advertiseSelection :: XorgContext -> Selection -> IO () advertiseSelection ctx@XorgContext{..} sel = allocaXEvent (go [defaultClipboard, primaryClipboard])@@ -265,12 +267,12 @@ handleRequest :: XorgContext -> SelectionType -> Window -> Atom -> Text -> IO Atom handleRequest XorgContext{..} sel requestorWindow selection "TARGETS" = do targets <- internAtom display "TARGETS" True- target <- internAtom display (toS $ selectionTypeToMime sel) True+ target <- internAtom display (StrConvOld.toS $ selectionTypeToMime sel) True changeProperty32 display requestorWindow selection aTOM propModeReplace [fromIntegral targets, fromIntegral target] return selection handleRequest XorgContext{..} sel req prop targetStr =- if targetStr == toS (selectionTypeToMime sel)+ if targetStr == decodeUtf8 (selectionTypeToMime sel) then do target <- internAtom display (toS targetStr) True void $ withArrayLen (byteStringToCUChars $ getContent sel) $ \len bytes ->
src/Main.hs view
@@ -9,12 +9,12 @@ module Main where -import Protolude hiding (readFile, to, (<&>), (&))+import Protolude hiding (readFile, to, (<&>), (&), toS)+import Protolude.Conv (toS) import Control.Monad.Catch (MonadCatch, catchAll) import Data.Binary (decodeFile, encode) import qualified Data.ByteString as B-import Data.Hashable (hash) import Data.List (dropWhileEnd) import qualified Data.Text as T import Data.Vector (Vector)@@ -24,8 +24,7 @@ import qualified System.Directory as Dir import System.Posix.Files (setFileMode) import System.Environment (lookupEnv)-import System.IO (IOMode (..), hClose, hGetContents,- openFile)+import System.IO (hClose, hGetContents) import System.Timeout (timeout) import System.Wordexp.Simple (wordexp) @@ -42,6 +41,7 @@ , usePrimarySelectionAsInput :: Bool , blacklistedApps :: [Text] , trimSpaceFromSelection :: Bool+ , enableImageSupport :: Bool } deriving (Show, Read) type ClipHistory = Vector Clip.Selection@@ -133,11 +133,12 @@ go = do history <- getHistory usePrimary <- view $ to usePrimarySelectionAsInput+ enableImage <- view $ to enableImageSupport cfg <- ask liftIO $ bracket Clip.getXorgContext Clip.destroyXorgContext $ \x11Context -> do- let getSelections = (getSelectionFrom (Clip.getClipboardSelection x11Context), Nothing)- : [(getSelectionFrom (Clip.getPrimarySelection x11Context), Nothing) | usePrimary]+ let getSelections = (getSelectionFrom (Clip.getClipboardSelection x11Context enableImage), Nothing)+ : [(getSelectionFrom (Clip.getPrimarySelection x11Context enableImage), Nothing) | usePrimary] void $ runReaderT (innerloop getSelections history) cfg getSelection [] = return ([], Nothing)@@ -250,7 +251,7 @@ } where- defaultConfig = Config 50 "~/.cache/greenclip.history" "~/.cache/greenclip.staticHistory" "/tmp/greenclip/" False [] True+ defaultConfig = Config 50 "~/.cache/greenclip.history" "~/.cache/greenclip.staticHistory" "/tmp/greenclip/" False [] True True expandHomeDir str = (toS . fromMaybe (toS str) . listToMaybe <$> wordexp (toS str)) `catchAll` (\_ -> return $ toS str)