~eliasnaur/gio-patches

app/internal/window: fully remove direct pointer arithmetic in x11 driver v1 PROPOSED

Thank you. I'm going to squash this with your previous pointer arithmetic
change.
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/9008/mbox | git am -3
Learn more about email & git

[PATCH] app/internal/window: fully remove direct pointer arithmetic in x11 driver Export this patch

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

diff --git a/app/internal/window/os_x11.go b/app/internal/window/os_x11.go
index e176849..7b81a76 100644
--- a/app/internal/window/os_x11.go
+++ b/app/internal/window/os_x11.go
@@ -12,8 +12,6 @@ package window
 #include <X11/Xatom.h>
 #include <X11/Xutil.h>
 #include <X11/Xresource.h>
-#define GIO_FIELD_OFFSET(typ, field) const int gio_##typ##_##field##_off = offsetof(typ, field)
-GIO_FIELD_OFFSET(XClientMessageEvent, data);
 
 void gio_x11_init_ime(Display *dpy, Window win, XIM *xim, XIC *xic) {
 	// adjust locale temporarily for XOpenIM
@@ -323,7 +321,8 @@ func (h *x11EventHandler) handleEvents() bool {
 			w.height = int(cevt.height)
 			// redraw will be done by a later expose event
 		case C.ClientMessage: // extensions
-			switch GetClientDataLong(xev)[0] {
+			cevt := (*C.XClientMessageEvent)(unsafe.Pointer(xev))
+			switch *(*C.long)(unsafe.Pointer(&cevt.data)) {
 			case C.long(w.evDelWindow):
 				w.dead = true
 				return false
@@ -379,12 +378,6 @@ func x11SpecialKeySymToRune(s C.KeySym) (rune, bool) {
 	return n, true
 }
 
-// GetClientDataLong returns a XClientMessageEvent.data.l field.
-func GetClientDataLong(e *C.XEvent) [5]C.long {
-	ptr := (*[5]C.long)(unsafe.Pointer(uintptr(unsafe.Pointer(e)) + uintptr(C.gio_XClientMessageEvent_data_off)))
-	return *ptr
-}
-
 var (
 	x11Threads sync.Once
 )
-- 
2.17.1
Thank you. I'm going to squash this with your previous pointer arithmetic
change.
View this thread in the archives