Add setGDKx11Property.hs

This commit is contained in:
千住柱間 2025-11-09 05:15:47 +00:00
commit 6ec1e5f4ce

49
setGDKx11Property.hs Normal file
View file

@ -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