~eliasnaur/gio-patches

app/internal/window: cleanup X11 initialization v1 PROPOSED

Denis Bernard: 1
 app/internal/window: cleanup X11 initialization

 1 files changed, 15 insertions(+), 23 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~eliasnaur/gio-patches/patches/9024/mbox | git am -3
Learn more about email & git

[PATCH] app/internal/window: cleanup X11 initialization Export this patch

Removed redundant XSelectInput and XChangeWindowAttributes as well as
obsolete screen parameter in x11DetectUIScale.

Signed-off-by: Denis Bernard <db047h@gmail.com>
---
 app/internal/window/os_x11.go | 38 ++++++++++++++---------------------
 1 file changed, 15 insertions(+), 23 deletions(-)

diff --git a/app/internal/window/os_x11.go b/app/internal/window/os_x11.go
index f82f17d..d820360 100644
--- a/app/internal/window/os_x11.go
+++ b/app/internal/window/os_x11.go
@@ -478,30 +478,26 @@ func newX11Window(gioWin Callbacks, opts *Options) error {
 		return errors.New("x11: cannot connect to the X server")
 	}
 
-	root := C.XDefaultRootWindow(dpy)
-	screen := C.XDefaultScreen(dpy)
-	ppsp := x11DetectUIScale(dpy, screen)
+	ppsp := x11DetectUIScale(dpy)
 	cfg := config{pxPerDp: ppsp, pxPerSp: ppsp}
+	swa := C.XSetWindowAttributes{
+		event_mask: C.ExposureMask | C.FocusChangeMask | // update
+			C.KeyPressMask | C.KeyReleaseMask | // keyboard
+			C.ButtonPressMask | C.ButtonReleaseMask | // mouse clicks
+			C.PointerMotionMask | // mouse movement
+			C.StructureNotifyMask, // resize
+		background_pixmap: C.None,
+		override_redirect: C.False,
+	}
+	win := C.XCreateWindow(dpy, C.XDefaultRootWindow(dpy),
+		0, 0, C.uint(cfg.Px(opts.Width)), C.uint(cfg.Px(opts.Height)),
+		0, C.CopyFromParent, C.InputOutput, nil,
+		C.CWEventMask|C.CWBackPixmap|C.CWOverrideRedirect, &swa)
 	var (
-		swa C.XSetWindowAttributes
 		xim C.XIM
 		xic C.XIC
 	)
-	swa.event_mask = C.ExposureMask | C.PointerMotionMask | C.KeyPressMask
-	swa.background_pixmap = C.None
-	win := C.XCreateWindow(dpy, root,
-		0, 0, C.uint(cfg.Px(opts.Width)), C.uint(cfg.Px(opts.Height)), 0,
-		C.CopyFromParent, C.InputOutput,
-		nil, C.CWEventMask|C.CWBackPixmap,
-		&swa)
 	C.gio_x11_init_ime(dpy, win, &xim, &xic)
-	C.XSelectInput(dpy, win, 0|
-		C.ExposureMask|C.FocusChangeMask| // update
-		C.KeyPressMask|C.KeyReleaseMask| // keyboard
-		C.ButtonPressMask|C.ButtonReleaseMask| // mouse clicks
-		C.PointerMotionMask| // mouse movement
-		C.StructureNotifyMask, // resize
-	)
 
 	w := &x11Window{
 		w: gioWin, x: dpy, xw: win,
@@ -514,10 +510,6 @@ func newX11Window(gioWin Callbacks, opts *Options) error {
 	w.notify.read = pipe[0]
 	w.notify.write = pipe[1]
 
-	var xattr C.XSetWindowAttributes
-	xattr.override_redirect = C.False
-	C.XChangeWindowAttributes(dpy, win, C.CWOverrideRedirect, &xattr)
-
 	var hints C.XWMHints
 	hints.input = C.True
 	hints.flags = C.InputHint
@@ -548,7 +540,7 @@ func newX11Window(gioWin Callbacks, opts *Options) error {
 }
 
 // detectUIScale reports the system UI scale, or 1.0 if it fails.
-func x11DetectUIScale(dpy *C.Display, screen C.int) float32 {
+func x11DetectUIScale(dpy *C.Display) float32 {
 	// default fixed DPI value used in most desktop UI toolkits
 	const defaultDesktopDPI = 96
 	var scale float32 = 1.0
-- 
2.17.1
Thank you, merged.
View this thread in the archives