packages feed

gtk-sni-tray 0.1.1.0 → 0.1.2.0

raw patch · 4 files changed

+73/−22 lines, 4 filesdep +enclosed-exceptionsdep +filepathdep ~gi-gdkpixbuf

Dependencies added: enclosed-exceptions, filepath

Dependency ranges changed: gi-gdkpixbuf

Files

README.md view
@@ -5,7 +5,7 @@  taffybar -----------It is generally recommeneded that you use this widget through [taffybar](https://github.com/travitch/taffybar) with [this module](https://github.com/travitch/taffybar/blob/master/src/System/Taffybar/SNITray.hs), which will allow you to combine it with other useful widgets, and will give more flexibility in configuration.+It is generally recommeneded that you use this widget through [taffybar](https://github.com/travitch/taffybar) with [this module](https://github.com/travitch/taffybar/blob/master/src/System/Taffybar/Widget/SNITray.hs), which will allow you to combine it with other useful widgets, and will give more flexibility in configuration.  StatusNotifierWatcher --------------------------
app/Main.hs view
@@ -212,8 +212,10 @@   Gtk.main  parser :: Parser (IO ())-parser = buildWindows <$> positionP <*> alignmentP <*> sizeP <*> paddingP <*>-         monitorNumberP <*> logP <*> colorP <*> expandP <*> startWatcherP <*> barLengthP+parser =+  buildWindows <$> positionP <*> alignmentP <*> sizeP <*> paddingP <*>+  monitorNumberP <*> logP <*> colorP <*> expandP <*> startWatcherP <*>+  barLengthP  versionOption :: Parser (a -> a) versionOption = infoOption
gtk-sni-tray.cabal view
@@ -1,11 +1,11 @@--- This file has been generated from package.yaml by hpack version 0.28.2.+-- This file has been generated from package.yaml by hpack version 0.27.0. -- -- see: https://github.com/sol/hpack ----- hash: 5149f18836bd55f1519c1276fc60966cb14c7dac91cf0be093c3fa8d68be6377+-- hash: 915ea56e175e3c6e8042c5e3ca861798e4d4729a1ef716fac80a24fb79f558d4  name:           gtk-sni-tray-version:        0.1.1.0+version:        0.1.2.0 synopsis:       A standalone StatusNotifierItem/AppIndicator tray description:    Please see the README on Github at <https://github.com/IvanMalison/gtk-sni-tray#readme> category:       System@@ -18,6 +18,7 @@ license-file:   LICENSE build-type:     Simple cabal-version:  >= 1.10+ extra-source-files:     ChangeLog.md     README.md@@ -39,9 +40,11 @@     , containers     , dbus >=1.0.0 && <2.0.0     , directory+    , enclosed-exceptions >=1.0.0.1+    , filepath     , gi-dbusmenugtk3     , gi-gdk-    , gi-gdkpixbuf >=2.0.15+    , gi-gdkpixbuf >=2.0.16     , gi-glib     , gi-gtk >=3.0.21     , gtk-strut
src/StatusNotifier/Tray.hs view
@@ -2,6 +2,7 @@ module StatusNotifier.Tray where  import           Control.Concurrent.MVar as MV+import           Control.Exception.Enclosed (catchAny) import           Control.Monad import           Control.Monad.Trans.Class import           Control.Monad.Trans.Maybe@@ -30,6 +31,7 @@ import           StatusNotifier.Host.Service import qualified StatusNotifier.Item.Client as IC import           System.Directory+import           System.FilePath import           System.Log.Logger import           Text.Printf @@ -54,24 +56,46 @@    return themeForIcon -getIconPixbufByName :: IsIconTheme it =>  Int32 -> T.Text -> it -> IO (Maybe Pixbuf)-getIconPixbufByName size name themeForIcon = do-  trayLogger DEBUG "Getting Pixbuf from name"+getIconPixbufByName :: Int32 -> T.Text -> Maybe String -> IO (Maybe Pixbuf)+getIconPixbufByName size name themePath = do+  trayLogger DEBUG $ printf "Getting Pixbuf from name for %s" name+  themeForIcon <- maybe iconThemeGetDefault getThemeWithDefaultFallbacks themePath+   let panelName = T.pack $ printf "%s-panel" name   hasPanelIcon <- iconThemeHasIcon themeForIcon panelName   hasIcon <- iconThemeHasIcon themeForIcon name+   if hasIcon || hasPanelIcon+   then do     let targetName = if hasPanelIcon then panelName else name+    trayLogger DEBUG $ printf "Found icon %s in theme" name     iconThemeLoadIcon themeForIcon targetName size themeLoadFlags+   else do+    trayLogger DEBUG $ printf "Trying to load icon %s as filepath" name     -- Try to load the icon as a filepath     let nameString = T.unpack name     fileExists <- doesFileExist nameString-    if fileExists-    then Just <$> pixbufNewFromFile name-    else return Nothing+    maybeFile <- if fileExists+    then return $ Just nameString+    else fmap join $ sequenceA $ getIconPathFromThemePath nameString <$> themePath+    sequenceA $ pixbufNewFromFile <$> maybeFile +getIconPathFromThemePath :: String -> String -> IO (Maybe String)+getIconPathFromThemePath name themePath = do+  trayLogger DEBUG $ printf+    "Trying to load icon %s as filepath with theme path %s"+    name themePath+  pathExists <- doesDirectoryExist themePath+  if pathExists+  then do+    fileNames <- catchAny (getDirectoryContents themePath) (const $ return [])+    trayLogger DEBUG $ printf+      "Found files in theme path %s" (show fileNames)+    return $ (themePath </>) <$> find (isPrefixOf name) fileNames+  else return Nothing+ getIconPixbufFromByteString :: Int32 -> Int32 -> BS.ByteString -> IO Pixbuf getIconPixbufFromByteString width height byteString = do   trayLogger DEBUG "Getting Pixbuf from bytestring"@@ -161,20 +185,43 @@             case imageSize of               Expand -> do                 image <- Gtk.imageNew+                lastAllocation <- MV.newMVar Nothing+                 let setPixbuf rectangle =                       do                         size <- getSize rectangle-                        pixBuf <- getInfo info serviceName >>= getScaledPixBufFromInfo size-                        Gtk.imageSetFromPixbuf image pixBuf-                        trayLogger INFO $ printf "Setting size to %s" $ show size                          allocation <- Gtk.widgetGetAllocation image                         actualWidth <- Gdk.getRectangleWidth allocation                         actualHeight <- Gdk.getRectangleHeight allocation-                        when (actualWidth /= size || actualHeight /= size) $ do-                             Gtk.widgetSetSizeRequest image size size-                             trayLogger INFO $ printf "Actual width %s" $ show actualWidth-                             Gtk.containerResizeChildren trayBox++                        requestResize <- MV.modifyMVar lastAllocation $ \previous ->+                          let thisTime = Just (size, actualWidth, actualHeight)+                          in return (thisTime, thisTime /= previous)++                        trayLogger DEBUG $+                                   printf "Allocating image size %s, width %s, \+                                           \ height %s, resize %s"+                                   (show size)+                                   (show actualWidth)+                                   (show actualHeight)+                                   (show requestResize)++                        if requestResize && actualWidth /= actualHeight+                        then do+                          trayLogger DEBUG "Requesting resize"+                          Gtk.widgetSetSizeRequest image size size+                          void (Gdk.threadsAddIdle GLib.PRIORITY_DEFAULT $+                                   Gtk.widgetQueueResize image >> return False)+                        else do+                          trayLogger DEBUG "Requesting resize"+                          pixBuf <- getInfo info serviceName >>= getScaledPixBufFromInfo size+                          when (isNothing pixBuf) $+                               trayLogger WARNING $+                                          printf "Got null pixbuf for info %s"+                                          (show info { iconPixmaps = [] })+                          Gtk.imageSetFromPixbuf image pixBuf+                 _ <- Gtk.onWidgetSizeAllocate image setPixbuf                 return image               TrayImageSize size -> do@@ -241,7 +288,6 @@                                       , iconPixmaps = pixmaps                                       } = do         logItemInfo info "Getting pixbuf"-        themeForIcon <- maybe iconThemeGetDefault getThemeWithDefaultFallbacks mpath         let tooSmall (w, h, _) = w < size || h < size             largeEnough = filter (not . tooSmall) pixmaps             orderer (w1, h1, _) (w2, h2, _) =@@ -257,7 +303,7 @@               then Nothing               else Just $ getIconPixbufFromByteString w h p         if null pixmaps-        then getIconPixbufByName size (T.pack name) themeForIcon+        then getIconPixbufByName size (T.pack name) mpath         else sequenceA $ getFromPixmaps selectedPixmap        uiUpdateHandler updateType info =