Mercurial > games > semicongine
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 1255:2b5ca798f6d6 | 1256:bfb75c934f4e |
|---|---|
| 79 0, # CWOverrideRedirect, | 79 0, # CWOverrideRedirect, |
| 80 addr attrs, | 80 addr attrs, |
| 81 # foregroundColor, backgroundColor | 81 # foregroundColor, backgroundColor |
| 82 ) | 82 ) |
| 83 checkXlibResult XSetStandardProperties(display, window, title, "window", 0, nil, 0, nil) | 83 checkXlibResult XSetStandardProperties(display, window, title, "window", 0, nil, 0, nil) |
| 84 checkXlibResult XSelectInput(display, window, PointerMotionMask or ButtonPressMask or ButtonReleaseMask or KeyPressMask or KeyReleaseMask or ExposureMask) | 84 checkXlibResult XSelectInput(display, window, PointerMotionMask or ButtonPressMask or ButtonReleaseMask or KeyPressMask or KeyReleaseMask or ExposureMask or FocusChangeMask) |
| 85 checkXlibResult XMapWindow(display, window) | 85 checkXlibResult XMapWindow(display, window) |
| 86 | 86 |
| 87 deleteMessage = XInternAtom(display, "WM_DELETE_WINDOW", XBool(false)) | 87 deleteMessage = XInternAtom(display, "WM_DELETE_WINDOW", XBool(false)) |
| 88 checkXlibResult XSetWMProtocols(display, window, addr(deleteMessage), 1) | 88 checkXlibResult XSetWMProtocols(display, window, addr(deleteMessage), 1) |
| 89 | 89 |
| 95 return NativeWindow(display: display, window: window, emptyCursor: empty_cursor) | 95 return NativeWindow(display: display, window: window, emptyCursor: empty_cursor) |
| 96 | 96 |
| 97 proc SetTitle*(window: NativeWindow, title: string) = | 97 proc SetTitle*(window: NativeWindow, title: string) = |
| 98 checkXlibResult XSetStandardProperties(window.display, window.window, title, "window", 0, nil, 0, nil) | 98 checkXlibResult XSetStandardProperties(window.display, window.window, title, "window", 0, nil, 0, nil) |
| 99 | 99 |
| 100 proc Fullscreen*(window: var NativeWindow, enable: bool) = | 100 proc SetFullscreen*(window: var NativeWindow, enable: bool) = |
| 101 var | 101 var |
| 102 wm_state = window.display.XInternAtom("_NET_WM_STATE", 0) | 102 wm_state = window.display.XInternAtom("_NET_WM_STATE", 0) |
| 103 wm_fullscreen = window.display.XInternAtom("_NET_WM_STATE_FULLSCREEN", 0) | 103 wm_fullscreen = window.display.XInternAtom("_NET_WM_STATE_FULLSCREEN", 0) |
| 104 var | 104 var |
| 105 xev: XEvent | 105 xev: XEvent |
| 125 SubstructureRedirectMask or SubstructureNotifyMask, | 125 SubstructureRedirectMask or SubstructureNotifyMask, |
| 126 addr xev | 126 addr xev |
| 127 ) | 127 ) |
| 128 checkXlibResult window.display.XFlush() | 128 checkXlibResult window.display.XFlush() |
| 129 | 129 |
| 130 proc HideSystemCursor*(window: NativeWindow) = | 130 proc ShowSystemCursor*(window: NativeWindow, value: bool) = |
| 131 checkXlibResult XDefineCursor(window.display, window.window, window.emptyCursor) | 131 if value == true: |
| 132 checkXlibResult window.display.XFlush() | 132 checkXlibResult XUndefineCursor(window.display, window.window) |
| 133 | 133 checkXlibResult window.display.XFlush() |
| 134 proc ShowSystemCursor*(window: NativeWindow) = | 134 else: |
| 135 checkXlibResult XUndefineCursor(window.display, window.window) | 135 checkXlibResult XDefineCursor(window.display, window.window, window.emptyCursor) |
| 136 checkXlibResult window.display.XFlush() | 136 checkXlibResult window.display.XFlush() |
| 137 | 137 |
| 138 proc Destroy*(window: NativeWindow) = | 138 proc Destroy*(window: NativeWindow) = |
| 139 checkXlibResult window.display.XFreeCursor(window.emptyCursor) | 139 checkXlibResult window.display.XFreeCursor(window.emptyCursor) |
| 140 checkXlibResult window.display.XDestroyWindow(window.window) | 140 checkXlibResult window.display.XDestroyWindow(window.window) |
| 141 discard window.display.XCloseDisplay() # always returns 0 | 141 discard window.display.XCloseDisplay() # always returns 0 |
| 173 let button = int(cast[PXButtonEvent](addr(event)).button) | 173 let button = int(cast[PXButtonEvent](addr(event)).button) |
| 174 result.add Event(eventType: MouseReleased, button: MouseButtonTypeMap.getOrDefault(button, MouseButton.UNKNOWN)) | 174 result.add Event(eventType: MouseReleased, button: MouseButtonTypeMap.getOrDefault(button, MouseButton.UNKNOWN)) |
| 175 of MotionNotify: | 175 of MotionNotify: |
| 176 let motion = cast[PXMotionEvent](addr(event)) | 176 let motion = cast[PXMotionEvent](addr(event)) |
| 177 result.add Event(eventType: MouseMoved, x: motion.x, y: motion.y) | 177 result.add Event(eventType: MouseMoved, x: motion.x, y: motion.y) |
| 178 of FocusIn: | |
| 179 result.add Event(eventType: GotFocus) | |
| 180 of FocusOut: | |
| 181 result.add Event(eventType: LostFocus) | |
| 178 of ConfigureNotify, Expose: | 182 of ConfigureNotify, Expose: |
| 179 result.add Event(eventType: ResizedWindow) | 183 result.add Event(eventType: ResizedWindow) |
| 180 else: | 184 else: |
| 181 discard | 185 discard |
| 182 | 186 |
