Debian Codegraph @

src/StatusNotifier/TransparentWindow.hs

raw
1 {-# LANGUAGE OverloadedLabels #-}
2 {-# LANGUAGE GADTs #-}
3 {-# LANGUAGE FlexibleContexts #-}
4 -----------------------------------------------------------------------------
5 -- |
6 -- Module : StatusNotifier.TransparentWindow
7 -- Copyright : (c) Ivan A. Malison
8 -- License : BSD3-style (see LICENSE)
9 --
10 -- Maintainer : Ivan A. Malison
11 -- Stability : unstable
12 -- Portability : unportable
13 --
14 -- Make a window transparent. Approach adapted from python code from
15 -- https://stackoverflow.com/questions/3908565/how-to-make-gtk-window-background-transparent/33294727#33294727
16 -----------------------------------------------------------------------------
17 module StatusNotifier.TransparentWindow where
18
19 import Control.Monad.IO.Class
20 import Control.Monad.Trans.Reader
21 import Data.GI.Base
22 import Foreign.Ptr (castPtr)
23 import GI.Cairo hiding (OperatorOver, OperatorSource)
24 import GI.Cairo.Render
25 import GI.Cairo.Render.Connector
26 import qualified GI.Gdk as Gdk
27 import qualified GI.Gtk as Gtk
28
29 makeWindowTransparent :: MonadIO m => Gtk.Window -> m ()
30 makeWindowTransparent window = do
31 screen <- Gtk.widgetGetScreen window
32 visual <- Gdk.screenGetRgbaVisual screen
33 Gtk.widgetSetVisual window visual
34 Gtk.setWidgetAppPaintable window True
35 _ <- Gtk.onWidgetDraw window transparentDraw
36 return ()
37
38 transparentDraw :: Gtk.WidgetDrawCallback
39 transparentDraw context = do
40 rGBA <- Gdk.newZeroRGBA
41 Gdk.setRGBAAlpha rGBA 0.0
42 Gdk.setRGBABlue rGBA 1.0
43 Gdk.setRGBARed rGBA 1.0
44 Gdk.setRGBAGreen rGBA 1.0
45 Gdk.cairoSetSourceRgba context rGBA
46 flip renderWithContext context $ do
47 setOperator OperatorSource
48 paint
49 setOperator OperatorOver
50 return False