From 6ec1e5f4cea1efb76ad24b77f767bb249b4a4d20 Mon Sep 17 00:00:00 2001 From: hashirama Date: Sun, 9 Nov 2025 05:15:47 +0000 Subject: [PATCH] Add setGDKx11Property.hs --- setGDKx11Property.hs | 49 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 setGDKx11Property.hs diff --git a/setGDKx11Property.hs b/setGDKx11Property.hs new file mode 100644 index 0000000..a89957b --- /dev/null +++ b/setGDKx11Property.hs @@ -0,0 +1,49 @@ +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE OverloadedLabels #-} +{-# LANGUAGE ImplicitParams #-} + +import Data.GI.Base +import qualified GI.Gtk as Gtk +import qualified GI.Gdk as Gdk +import qualified GI.GdkX11 as GdkX11 +import GI.Gio +import Control.Monad (void) + +main :: IO () +main = do + app <- new Gtk.Application [#applicationId := "org.example.test"] + on app #activate $ do + win <- new Gtk.ApplicationWindow + [ #application := app + , #title := "Dialog Window" + , #defaultWidth := 100 + , #defaultHeight := 40 + , #resizable := False + , #decorated := False + ] + Gtk.widgetShow win + + mSurface <- #getSurface win + case mSurface of + Just surface -> do + -- get X11 surface and display + x11Surface <- castTo GdkX11.X11Surface surface + display <- Gdk.surfaceGetDisplay surface + x11Display <- castTo GdkX11.X11Display display + + case (x11Display, x11Surface) of + (Just d, Just s) -> do + -- retrieve atoms via GDK X11 + atomDialog <- GdkX11.x11GetXatomByNameForDisplay d "_NET_WM_WINDOW_TYPE_DIALOG" + atomType <- GdkX11.x11GetXatomByNameForDisplay d "_NET_WM_WINDOW_TYPE" + + -- set window type using UTF8 property (technically still a string, but fine for WM hints) + GdkX11.x11SurfaceSetUtf8Property + s + "_NET_WM_WINDOW_TYPE" + (Just "_NET_WM_WINDOW_TYPE_DIALOG") + + _ -> putStrLn "Not running under X11." + Nothing -> pure () + + void $ applicationRun app Nothing