packages feed

greenclip 3.0.2 → 3.1.0

raw patch · 4 files changed

+34/−18 lines, 4 filesdep ~base

Dependency ranges changed: base

Files

README.md view
@@ -18,6 +18,8 @@   + Integrated with [rofi](https://github.com/DaveDavenport/rofi)   + Permanently set some selections to added at the end (set `staticHistoryPath = your/file/with/static/entries` in the config file)   + Merge X Primary selection with clipboard selection (set `usePrimarySelectionAsInput = True` in the config file)+  + Blacklist some applications (see `I want to blacklist some applications !` in the FAQ section)+  + Copy small images  ## Installation 
greenclip.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack  name:           greenclip-version:        3.0.2+version:        3.1.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@@ -25,7 +25,7 @@       src   ghc-options: -Wall -O3   build-depends:-      base >= 4 && < 4.11.0.0+      base >= 4 && < 5     , protolude     , exceptions     , bytestring
src/Clipboard.hs view
@@ -8,6 +8,7 @@ module Clipboard where  import           Protolude                hiding ((<&>))+import           Unsafe                   (unsafeIndex)  import           Graphics.X11.Xlib import           Graphics.X11.Xlib.Extras@@ -44,6 +45,8 @@   , defaultClipboard :: Atom   , primaryClipboard :: Atom   , selectionTarget  :: Atom+  , mimesPriorities  :: [Atom]+  , defaultMime      :: Atom } deriving (Show)  @@ -86,7 +89,7 @@             _ <- peek prop_return >>= xFree             return $ actual_type == incr -getSupportedMimes :: XorgContext -> Atom -> IO [Text]+getSupportedMimes :: XorgContext -> Atom -> IO [Atom] getSupportedMimes ctx@XorgContext{..} clipboard =     alloca $ \actual_type_return ->     alloca $ \actual_format_return ->@@ -110,8 +113,8 @@                     actual_format <- peek actual_format_return <&> fromIntegral :: IO Atom                     nitems        <- peek nitems_return <&> fromIntegral                     getprop prop_ptr nitems actual_format-        let atoms = filter (/= 0) $ fromMaybe mempty ret2-        fmap (fmap toS) (getAtomNames display atoms)+        return $ fromMaybe mempty ret2+   where     getprop prop_ptr nitems actual_format         | actual_format == 0    = return Nothing -- Property not found@@ -132,10 +135,9 @@ getSelection :: XorgContext -> Atom -> IO (Maybe Selection) getSelection ctx@XorgContext{..} clipboard = do   mimes <- getSupportedMimes ctx clipboard-  let selectedMime = chooseSelectionType mimes+  let targetMime = chooseSelectionType mimes -  target <- internAtom display (toS selectedMime) True-  xConvertSelection display clipboard target selectionTarget ownWindow currentTime+  xConvertSelection display clipboard targetMime selectionTarget ownWindow currentTime   waitNotify ctx   isIncremental <- isIncrementalTransfert ctx   clipboardContent <- if isIncremental@@ -148,20 +150,19 @@   else do     windowName <- windowNameOfClipboardOwner ctx clipboard     return $ Just Selection { appName = windowName-                            , selection = mimeToSelectionType selectedMime clipboardContent+                            , selection = mimeToSelectionType targetMime clipboardContent                             }   where-   priorities = ["image/png", "image/jpeg", "image/bmp", "UTF8_STRING", "TEXT"]-    chooseSelectionType mimes =-     let selectedMime = msum $ (\mime -> find (== mime) mimes) <$> priorities-     in fromMaybe "UTF8_STRING" selectedMime+     let selectedMime = msum $ (\mime -> find (== mime) mimes) <$> mimesPriorities+     in fromMaybe defaultMime selectedMime -   mimeToSelectionType "image/png" selContent  = PNG selContent-   mimeToSelectionType "image/jpeg" selContent = JPEG selContent-   mimeToSelectionType "image/bmp" selContent  = BITMAP selContent-   mimeToSelectionType _ selContent            = UTF8 (T.strip $ toS selContent)+   mimeToSelectionType mimeTarget selContent =+     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 (T.strip $ toS selContent)     -- getContentIncrementally acc = do    --   _ <- xDeleteProperty display ownWindow selectionTarget@@ -182,12 +183,16 @@      clipboard <- internAtom display "CLIPBOARD" False     selTarget <- internAtom display "GREENCLIP" False+    priorities <- traverse (\atomName -> internAtom display atomName True) ["image/png", "image/jpeg", "image/bmp", "UTF8_STRING", "TEXT"]+    defaultM <- internAtom display "UTF8_STRING" True     return XorgContext {         display = display       , ownWindow = window       , defaultClipboard = clipboard       , primaryClipboard = pRIMARY       , selectionTarget = selTarget+      , mimesPriorities = priorities+      , defaultMime = defaultM     }  destroyXorgContext :: XorgContext -> IO ()
src/Main.hs view
@@ -21,6 +21,7 @@ import           Lens.Micro import           Lens.Micro.Mtl import qualified System.Directory      as Dir+import           System.Posix.Files    (setFileMode) import           System.Environment    (lookupEnv) import           System.IO             (IOMode (..), hClose, hGetContents,                                         openFile)@@ -103,8 +104,16 @@           maxLen <- view $ to maxHistoryLength           return $ V.splitAt maxLen . V.cons selection $ V.filter (\ori -> Clip.selection ori /= Clip.selection selection) history ++setHistoryFilePermission :: (MonadIO m, MonadReader Config m) => m ()+setHistoryFilePermission = do+  storePath <- view $ to (toS . historyPath)+  fileExist <- liftIO $ Dir.doesFileExist storePath+  when (not fileExist) (storeHistory mempty)+  liftIO $ setFileMode storePath 0o600+ runDaemon:: (MonadIO m, MonadCatch m, MonadReader Config m) => m ()-runDaemon = forever $ go `catchAll` handleError+runDaemon = setHistoryFilePermission >> (forever $ go `catchAll` handleError)   where     _0_5sec :: Int     _0_5sec = 5 * 100000