Virtual desktop underlay for Wayland and X11
git clone https://github.com/m-col/xanadu
Files | Refs | Readme | License

Commit 37a8d79c3ff8e92f2af04e7218277599cf7c0dfe
Parent: 64d2df5c26ba41d52e9206d21f4604afe16de63e
Author: mcol <mcol@posteo.net>
Date: 2021-11-02 18:16:59 +0000
Committer: mcol <mcol@posteo.net>
Committed: 2021-11-02 18:16:59 +0000

Add user custom CSS

style.css Added

@@ -0,0 +1,3 @@
+* {
+    background-color: transparent;
+}

src/Style.hs Modified

@@ -4,17 +4,44 @@
     initStyle
 ) where
 
+import Control.Monad (when)
+import System.Directory (doesFileExist, getHomeDirectory)
+import System.Environment (lookupEnv)
+import System.FilePath ((</>))
+
+import qualified GI.Gio as Gio
 import qualified GI.Gtk as Gtk
 
 initStyle :: Gtk.ApplicationWindow -> IO ()
 initStyle win = do
+    setTheme win
     addCSS win
 
-addCSS :: Gtk.ApplicationWindow -> IO ()
-addCSS win = do
+setTheme :: Gtk.ApplicationWindow -> IO ()
+setTheme win = do
     screen <- Gtk.windowGetScreen win
     settings <- Gtk.settingsGetForScreen screen
     Gtk.setSettingsGtkApplicationPreferDarkTheme settings True
+
+getConfigDir :: IO FilePath
+getConfigDir = do
+    fromEnv <- lookupEnv "XDG_CONFIG_HOME"
+    case fromEnv of
+        Nothing -> (<> "/.config/xanadu") <$> getHomeDirectory
+        Just "" -> (<> "/.config/xanadu") <$> getHomeDirectory
+        Just path -> return $ path </> "/xanadu"
+
+addCSS :: Gtk.ApplicationWindow -> IO ()
+addCSS win = do
+    screen <- Gtk.windowGetScreen win
     cssProvider <- Gtk.cssProviderNew
-    Gtk.cssProviderLoadFromData cssProvider "* { background-color: transparent; }"
     Gtk.styleContextAddProviderForScreen screen cssProvider 800
+
+    -- Default CSS
+    Gtk.cssProviderLoadFromData cssProvider "* { background-color: transparent; }"
+
+    -- Custom CSS
+    configDir <- getConfigDir
+    let file = configDir </> "style.css"
+    hasFile <- doesFileExist file
+    when hasFile $ Gtk.cssProviderLoadFromFile cssProvider =<< Gio.fileNewForPath file