Mercurial > games > semicongine
diff semiconginev2/rendering/platform/linux.nim @ 1256:bfb75c934f4e
add: window focus handling, improve window api a bit
author | sam <sam@basx.dev> |
---|---|
date | Sun, 28 Jul 2024 17:33:41 +0700 |
parents | b0f4c8ccd49a |
children |
line wrap: on
line diff
--- a/semiconginev2/rendering/platform/linux.nim Sun Jul 28 00:17:34 2024 +0700 +++ b/semiconginev2/rendering/platform/linux.nim Sun Jul 28 17:33:41 2024 +0700 @@ -81,7 +81,7 @@ # foregroundColor, backgroundColor ) checkXlibResult XSetStandardProperties(display, window, title, "window", 0, nil, 0, nil) - checkXlibResult XSelectInput(display, window, PointerMotionMask or ButtonPressMask or ButtonReleaseMask or KeyPressMask or KeyReleaseMask or ExposureMask) + checkXlibResult XSelectInput(display, window, PointerMotionMask or ButtonPressMask or ButtonReleaseMask or KeyPressMask or KeyReleaseMask or ExposureMask or FocusChangeMask) checkXlibResult XMapWindow(display, window) deleteMessage = XInternAtom(display, "WM_DELETE_WINDOW", XBool(false)) @@ -97,7 +97,7 @@ proc SetTitle*(window: NativeWindow, title: string) = checkXlibResult XSetStandardProperties(window.display, window.window, title, "window", 0, nil, 0, nil) -proc Fullscreen*(window: var NativeWindow, enable: bool) = +proc SetFullscreen*(window: var NativeWindow, enable: bool) = var wm_state = window.display.XInternAtom("_NET_WM_STATE", 0) wm_fullscreen = window.display.XInternAtom("_NET_WM_STATE_FULLSCREEN", 0) @@ -127,13 +127,13 @@ ) checkXlibResult window.display.XFlush() -proc HideSystemCursor*(window: NativeWindow) = - checkXlibResult XDefineCursor(window.display, window.window, window.emptyCursor) - checkXlibResult window.display.XFlush() - -proc ShowSystemCursor*(window: NativeWindow) = - checkXlibResult XUndefineCursor(window.display, window.window) - checkXlibResult window.display.XFlush() +proc ShowSystemCursor*(window: NativeWindow, value: bool) = + if value == true: + checkXlibResult XUndefineCursor(window.display, window.window) + checkXlibResult window.display.XFlush() + else: + checkXlibResult XDefineCursor(window.display, window.window, window.emptyCursor) + checkXlibResult window.display.XFlush() proc Destroy*(window: NativeWindow) = checkXlibResult window.display.XFreeCursor(window.emptyCursor) @@ -175,6 +175,10 @@ of MotionNotify: let motion = cast[PXMotionEvent](addr(event)) result.add Event(eventType: MouseMoved, x: motion.x, y: motion.y) + of FocusIn: + result.add Event(eventType: GotFocus) + of FocusOut: + result.add Event(eventType: LostFocus) of ConfigureNotify, Expose: result.add Event(eventType: ResizedWindow) else: