Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module System.Taffybar.Widgets.StatusNotifierTray where
- import Control.Monad
- import qualified Data.Vector as V
- import Data.Word
- import Foreign.C.Types (CUChar(..))
- import Foreign.Marshal.Array
- import Foreign.Ptr
- import Foreign.Storable
- import qualified Graphics.UI.Gtk as Gtk
- import StatusNotifier.Host.Service as H
- vectorToCPointer :: V.Vector Word8 -> IO (Ptr CUChar)
- vectorToCPointer v = do
- target <- mallocArray $ V.length v
- V.imapM_ (pokeElemOff target) v
- return $ castPtr target
- sampleBits :: Int
- sampleBits = 8
- hasAlpha :: Bool
- hasAlpha = True
- colorspace :: Gtk.Colorspace
- colorspace = Gtk.ColorspaceRgb
- buildTray :: IO Gtk.Widget
- buildTray = do
- box <- Gtk.hBoxNew False 5
- let updateHandler NewItem info =
- do
- putStrLn "Handling new item"
- pixBuf <- getPixBufFromInfo info
- img <- Gtk.imageNew
- Gtk.imageSetFromPixbuf img pixBuf
- Gtk.widgetShowAll img
- Gtk.boxPackStart box img Gtk.PackNatural 0
- updateHandler _ _ = return ()
- getPixBufFromInfo ItemInfo { iconPixmaps = pixmaps } = do
- let (width, height, pixmap) = V.head pixmaps
- pixelsPerRow = fromIntegral width
- bytesPerPixel = 4
- rowStride = pixelsPerRow * bytesPerPixel
- cPtr <- vectorToCPointer pixmap
- Gtk.pixbufNewFromData cPtr colorspace hasAlpha sampleBits
- (fromIntegral width) (fromIntegral height) rowStride
- join $ H.build H.defaultParams { uniqueIdentifier = "taffybar"
- , handleUpdate = updateHandler
- }
- return $ Gtk.toWidget box
Add Comment
Please, Sign In to add comment