glfw: properly fire initial window resize

on mac os custom os scaling is used, thus the initial viewport is wrong. #29
This commit is contained in:
Bixilon 2023-08-31 21:00:02 +02:00 committed by Moritz Zwerger
parent a197fa90d9
commit b5f6f0777c
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 143 additions and 139 deletions

View File

@ -13,7 +13,6 @@
package de.bixilon.minosoft.gui.rendering
import de.bixilon.kotlinglm.vec2.Vec2i
import de.bixilon.kutil.exception.ExceptionUtil.ignoreAll
import de.bixilon.kutil.latch.AbstractLatch
import de.bixilon.kutil.latch.ParentLatch
@ -23,7 +22,6 @@ import de.bixilon.kutil.primitive.BooleanUtil.decide
import de.bixilon.kutil.reflection.ReflectionUtil.forceSet
import de.bixilon.kutil.unit.UnitFormatter.formatNanos
import de.bixilon.minosoft.gui.rendering.RenderUtil.pause
import de.bixilon.minosoft.gui.rendering.events.ResizeWindowEvent
import de.bixilon.minosoft.gui.rendering.font.manager.FontManager
import de.bixilon.minosoft.gui.rendering.input.key.DebugKeyBindings
import de.bixilon.minosoft.gui.rendering.input.key.DefaultKeyBindings
@ -132,7 +130,7 @@ object RenderLoader {
}
connection.events.fire(ResizeWindowEvent(this, previousSize = Vec2i(0, 0), size = window.size))
window.postInit()
textures.dynamicTextures.activate()
textures.staticTextures.activate()

View File

@ -64,6 +64,8 @@ interface BaseWindow {
maxSize = DEFAULT_MAXIMUM_WINDOW_SIZE
}
fun postInit()
fun destroy()
fun close()

View File

@ -55,8 +55,8 @@ import java.nio.ByteBuffer
class GLFWWindow(
private val context: RenderContext,
private val eventMaster: AbstractEventMaster = context.connection,
private val context: RenderContext,
private val eventMaster: AbstractEventMaster = context.connection,
) : BaseWindow {
private var mousePosition = Vec2d.EMPTY
private var skipNextMouseEvent = true
@ -245,6 +245,10 @@ class GLFWWindow(
}
}
override fun postInit() {
fireGLFWEvent(ResizeWindowEvent(context, previousSize = Vec2i(0, 0), size = unscalePosition(size)))
}
override fun destroy() {
glfwFreeCallbacks(window)
glfwDestroyWindow(window)
@ -444,143 +448,143 @@ class GLFWWindow(
}
val KEY_CODE_MAPPING = mapOf(
GLFW_KEY_UNKNOWN to KeyCodes.KEY_UNKNOWN,
GLFW_KEY_SPACE to KeyCodes.KEY_SPACE,
GLFW_KEY_APOSTROPHE to KeyCodes.KEY_APOSTROPHE,
GLFW_KEY_COMMA to KeyCodes.KEY_COMMA,
GLFW_KEY_MINUS to KeyCodes.KEY_MINUS,
GLFW_KEY_PERIOD to KeyCodes.KEY_PERIOD,
GLFW_KEY_SLASH to KeyCodes.KEY_SLASH,
GLFW_KEY_0 to KeyCodes.KEY_0,
GLFW_KEY_1 to KeyCodes.KEY_1,
GLFW_KEY_2 to KeyCodes.KEY_2,
GLFW_KEY_3 to KeyCodes.KEY_3,
GLFW_KEY_4 to KeyCodes.KEY_4,
GLFW_KEY_5 to KeyCodes.KEY_5,
GLFW_KEY_6 to KeyCodes.KEY_6,
GLFW_KEY_7 to KeyCodes.KEY_7,
GLFW_KEY_8 to KeyCodes.KEY_8,
GLFW_KEY_9 to KeyCodes.KEY_9,
GLFW_KEY_SEMICOLON to KeyCodes.KEY_SEMICOLON,
GLFW_KEY_EQUAL to KeyCodes.KEY_EQUAL,
GLFW_KEY_A to KeyCodes.KEY_A,
GLFW_KEY_B to KeyCodes.KEY_B,
GLFW_KEY_C to KeyCodes.KEY_C,
GLFW_KEY_D to KeyCodes.KEY_D,
GLFW_KEY_E to KeyCodes.KEY_E,
GLFW_KEY_F to KeyCodes.KEY_F,
GLFW_KEY_G to KeyCodes.KEY_G,
GLFW_KEY_H to KeyCodes.KEY_H,
GLFW_KEY_I to KeyCodes.KEY_I,
GLFW_KEY_J to KeyCodes.KEY_J,
GLFW_KEY_K to KeyCodes.KEY_K,
GLFW_KEY_L to KeyCodes.KEY_L,
GLFW_KEY_M to KeyCodes.KEY_M,
GLFW_KEY_N to KeyCodes.KEY_N,
GLFW_KEY_O to KeyCodes.KEY_O,
GLFW_KEY_P to KeyCodes.KEY_P,
GLFW_KEY_Q to KeyCodes.KEY_Q,
GLFW_KEY_R to KeyCodes.KEY_R,
GLFW_KEY_S to KeyCodes.KEY_S,
GLFW_KEY_T to KeyCodes.KEY_T,
GLFW_KEY_U to KeyCodes.KEY_U,
GLFW_KEY_V to KeyCodes.KEY_V,
GLFW_KEY_W to KeyCodes.KEY_W,
GLFW_KEY_X to KeyCodes.KEY_X,
GLFW_KEY_Y to KeyCodes.KEY_Y,
GLFW_KEY_Z to KeyCodes.KEY_Z,
GLFW_KEY_LEFT_BRACKET to KeyCodes.KEY_LEFT_BRACKET,
GLFW_KEY_BACKSLASH to KeyCodes.KEY_BACKSLASH,
GLFW_KEY_RIGHT_BRACKET to KeyCodes.KEY_RIGHT_BRACKET,
GLFW_KEY_GRAVE_ACCENT to KeyCodes.KEY_GRAVE_ACCENT,
GLFW_KEY_WORLD_1 to KeyCodes.KEY_WORLD_1,
GLFW_KEY_WORLD_2 to KeyCodes.KEY_WORLD_2,
GLFW_KEY_UNKNOWN to KeyCodes.KEY_UNKNOWN,
GLFW_KEY_SPACE to KeyCodes.KEY_SPACE,
GLFW_KEY_APOSTROPHE to KeyCodes.KEY_APOSTROPHE,
GLFW_KEY_COMMA to KeyCodes.KEY_COMMA,
GLFW_KEY_MINUS to KeyCodes.KEY_MINUS,
GLFW_KEY_PERIOD to KeyCodes.KEY_PERIOD,
GLFW_KEY_SLASH to KeyCodes.KEY_SLASH,
GLFW_KEY_0 to KeyCodes.KEY_0,
GLFW_KEY_1 to KeyCodes.KEY_1,
GLFW_KEY_2 to KeyCodes.KEY_2,
GLFW_KEY_3 to KeyCodes.KEY_3,
GLFW_KEY_4 to KeyCodes.KEY_4,
GLFW_KEY_5 to KeyCodes.KEY_5,
GLFW_KEY_6 to KeyCodes.KEY_6,
GLFW_KEY_7 to KeyCodes.KEY_7,
GLFW_KEY_8 to KeyCodes.KEY_8,
GLFW_KEY_9 to KeyCodes.KEY_9,
GLFW_KEY_SEMICOLON to KeyCodes.KEY_SEMICOLON,
GLFW_KEY_EQUAL to KeyCodes.KEY_EQUAL,
GLFW_KEY_A to KeyCodes.KEY_A,
GLFW_KEY_B to KeyCodes.KEY_B,
GLFW_KEY_C to KeyCodes.KEY_C,
GLFW_KEY_D to KeyCodes.KEY_D,
GLFW_KEY_E to KeyCodes.KEY_E,
GLFW_KEY_F to KeyCodes.KEY_F,
GLFW_KEY_G to KeyCodes.KEY_G,
GLFW_KEY_H to KeyCodes.KEY_H,
GLFW_KEY_I to KeyCodes.KEY_I,
GLFW_KEY_J to KeyCodes.KEY_J,
GLFW_KEY_K to KeyCodes.KEY_K,
GLFW_KEY_L to KeyCodes.KEY_L,
GLFW_KEY_M to KeyCodes.KEY_M,
GLFW_KEY_N to KeyCodes.KEY_N,
GLFW_KEY_O to KeyCodes.KEY_O,
GLFW_KEY_P to KeyCodes.KEY_P,
GLFW_KEY_Q to KeyCodes.KEY_Q,
GLFW_KEY_R to KeyCodes.KEY_R,
GLFW_KEY_S to KeyCodes.KEY_S,
GLFW_KEY_T to KeyCodes.KEY_T,
GLFW_KEY_U to KeyCodes.KEY_U,
GLFW_KEY_V to KeyCodes.KEY_V,
GLFW_KEY_W to KeyCodes.KEY_W,
GLFW_KEY_X to KeyCodes.KEY_X,
GLFW_KEY_Y to KeyCodes.KEY_Y,
GLFW_KEY_Z to KeyCodes.KEY_Z,
GLFW_KEY_LEFT_BRACKET to KeyCodes.KEY_LEFT_BRACKET,
GLFW_KEY_BACKSLASH to KeyCodes.KEY_BACKSLASH,
GLFW_KEY_RIGHT_BRACKET to KeyCodes.KEY_RIGHT_BRACKET,
GLFW_KEY_GRAVE_ACCENT to KeyCodes.KEY_GRAVE_ACCENT,
GLFW_KEY_WORLD_1 to KeyCodes.KEY_WORLD_1,
GLFW_KEY_WORLD_2 to KeyCodes.KEY_WORLD_2,
GLFW_KEY_ESCAPE to KeyCodes.KEY_ESCAPE,
GLFW_KEY_ENTER to KeyCodes.KEY_ENTER,
GLFW_KEY_TAB to KeyCodes.KEY_TAB,
GLFW_KEY_BACKSPACE to KeyCodes.KEY_BACKSPACE,
GLFW_KEY_INSERT to KeyCodes.KEY_INSERT,
GLFW_KEY_DELETE to KeyCodes.KEY_DELETE,
GLFW_KEY_RIGHT to KeyCodes.KEY_RIGHT,
GLFW_KEY_LEFT to KeyCodes.KEY_LEFT,
GLFW_KEY_DOWN to KeyCodes.KEY_DOWN,
GLFW_KEY_UP to KeyCodes.KEY_UP,
GLFW_KEY_PAGE_UP to KeyCodes.KEY_PAGE_UP,
GLFW_KEY_PAGE_DOWN to KeyCodes.KEY_PAGE_DOWN,
GLFW_KEY_HOME to KeyCodes.KEY_HOME,
GLFW_KEY_END to KeyCodes.KEY_END,
GLFW_KEY_CAPS_LOCK to KeyCodes.KEY_CAPS_LOCK,
GLFW_KEY_SCROLL_LOCK to KeyCodes.KEY_SCROLL_LOCK,
GLFW_KEY_NUM_LOCK to KeyCodes.KEY_NUM_LOCK,
GLFW_KEY_PRINT_SCREEN to KeyCodes.KEY_PRINT_SCREEN,
GLFW_KEY_PAUSE to KeyCodes.KEY_PAUSE,
GLFW_KEY_F1 to KeyCodes.KEY_F1,
GLFW_KEY_F2 to KeyCodes.KEY_F2,
GLFW_KEY_F3 to KeyCodes.KEY_F3,
GLFW_KEY_F4 to KeyCodes.KEY_F4,
GLFW_KEY_F5 to KeyCodes.KEY_F5,
GLFW_KEY_F6 to KeyCodes.KEY_F6,
GLFW_KEY_F7 to KeyCodes.KEY_F7,
GLFW_KEY_F8 to KeyCodes.KEY_F8,
GLFW_KEY_F9 to KeyCodes.KEY_F9,
GLFW_KEY_F10 to KeyCodes.KEY_F10,
GLFW_KEY_F11 to KeyCodes.KEY_F11,
GLFW_KEY_F12 to KeyCodes.KEY_F12,
GLFW_KEY_F13 to KeyCodes.KEY_F13,
GLFW_KEY_F14 to KeyCodes.KEY_F14,
GLFW_KEY_F15 to KeyCodes.KEY_F15,
GLFW_KEY_F16 to KeyCodes.KEY_F16,
GLFW_KEY_F17 to KeyCodes.KEY_F17,
GLFW_KEY_F18 to KeyCodes.KEY_F18,
GLFW_KEY_F19 to KeyCodes.KEY_F19,
GLFW_KEY_F20 to KeyCodes.KEY_F20,
GLFW_KEY_F21 to KeyCodes.KEY_F21,
GLFW_KEY_F22 to KeyCodes.KEY_F22,
GLFW_KEY_F23 to KeyCodes.KEY_F23,
GLFW_KEY_F24 to KeyCodes.KEY_F24,
GLFW_KEY_F25 to KeyCodes.KEY_F25,
GLFW_KEY_KP_0 to KeyCodes.KEY_KP_0,
GLFW_KEY_KP_1 to KeyCodes.KEY_KP_1,
GLFW_KEY_KP_2 to KeyCodes.KEY_KP_2,
GLFW_KEY_KP_3 to KeyCodes.KEY_KP_3,
GLFW_KEY_KP_4 to KeyCodes.KEY_KP_4,
GLFW_KEY_KP_5 to KeyCodes.KEY_KP_5,
GLFW_KEY_KP_6 to KeyCodes.KEY_KP_6,
GLFW_KEY_KP_7 to KeyCodes.KEY_KP_7,
GLFW_KEY_KP_8 to KeyCodes.KEY_KP_8,
GLFW_KEY_KP_9 to KeyCodes.KEY_KP_9,
GLFW_KEY_KP_DECIMAL to KeyCodes.KEY_KP_DECIMAL,
GLFW_KEY_KP_DIVIDE to KeyCodes.KEY_KP_DIVIDE,
GLFW_KEY_KP_MULTIPLY to KeyCodes.KEY_KP_MULTIPLY,
GLFW_KEY_KP_SUBTRACT to KeyCodes.KEY_KP_SUBTRACT,
GLFW_KEY_KP_ADD to KeyCodes.KEY_KP_ADD,
GLFW_KEY_KP_ENTER to KeyCodes.KEY_KP_ENTER,
GLFW_KEY_KP_EQUAL to KeyCodes.KEY_KP_EQUAL,
GLFW_KEY_LEFT_SHIFT to KeyCodes.KEY_LEFT_SHIFT,
GLFW_KEY_LEFT_CONTROL to KeyCodes.KEY_LEFT_CONTROL,
GLFW_KEY_LEFT_ALT to KeyCodes.KEY_LEFT_ALT,
GLFW_KEY_LEFT_SUPER to KeyCodes.KEY_LEFT_SUPER,
GLFW_KEY_RIGHT_SHIFT to KeyCodes.KEY_RIGHT_SHIFT,
GLFW_KEY_RIGHT_CONTROL to KeyCodes.KEY_RIGHT_CONTROL,
GLFW_KEY_RIGHT_ALT to KeyCodes.KEY_RIGHT_ALT,
GLFW_KEY_RIGHT_SUPER to KeyCodes.KEY_RIGHT_SUPER,
GLFW_KEY_MENU to KeyCodes.KEY_MENU,
GLFW_KEY_LAST to KeyCodes.KEY_LAST,
GLFW_KEY_ESCAPE to KeyCodes.KEY_ESCAPE,
GLFW_KEY_ENTER to KeyCodes.KEY_ENTER,
GLFW_KEY_TAB to KeyCodes.KEY_TAB,
GLFW_KEY_BACKSPACE to KeyCodes.KEY_BACKSPACE,
GLFW_KEY_INSERT to KeyCodes.KEY_INSERT,
GLFW_KEY_DELETE to KeyCodes.KEY_DELETE,
GLFW_KEY_RIGHT to KeyCodes.KEY_RIGHT,
GLFW_KEY_LEFT to KeyCodes.KEY_LEFT,
GLFW_KEY_DOWN to KeyCodes.KEY_DOWN,
GLFW_KEY_UP to KeyCodes.KEY_UP,
GLFW_KEY_PAGE_UP to KeyCodes.KEY_PAGE_UP,
GLFW_KEY_PAGE_DOWN to KeyCodes.KEY_PAGE_DOWN,
GLFW_KEY_HOME to KeyCodes.KEY_HOME,
GLFW_KEY_END to KeyCodes.KEY_END,
GLFW_KEY_CAPS_LOCK to KeyCodes.KEY_CAPS_LOCK,
GLFW_KEY_SCROLL_LOCK to KeyCodes.KEY_SCROLL_LOCK,
GLFW_KEY_NUM_LOCK to KeyCodes.KEY_NUM_LOCK,
GLFW_KEY_PRINT_SCREEN to KeyCodes.KEY_PRINT_SCREEN,
GLFW_KEY_PAUSE to KeyCodes.KEY_PAUSE,
GLFW_KEY_F1 to KeyCodes.KEY_F1,
GLFW_KEY_F2 to KeyCodes.KEY_F2,
GLFW_KEY_F3 to KeyCodes.KEY_F3,
GLFW_KEY_F4 to KeyCodes.KEY_F4,
GLFW_KEY_F5 to KeyCodes.KEY_F5,
GLFW_KEY_F6 to KeyCodes.KEY_F6,
GLFW_KEY_F7 to KeyCodes.KEY_F7,
GLFW_KEY_F8 to KeyCodes.KEY_F8,
GLFW_KEY_F9 to KeyCodes.KEY_F9,
GLFW_KEY_F10 to KeyCodes.KEY_F10,
GLFW_KEY_F11 to KeyCodes.KEY_F11,
GLFW_KEY_F12 to KeyCodes.KEY_F12,
GLFW_KEY_F13 to KeyCodes.KEY_F13,
GLFW_KEY_F14 to KeyCodes.KEY_F14,
GLFW_KEY_F15 to KeyCodes.KEY_F15,
GLFW_KEY_F16 to KeyCodes.KEY_F16,
GLFW_KEY_F17 to KeyCodes.KEY_F17,
GLFW_KEY_F18 to KeyCodes.KEY_F18,
GLFW_KEY_F19 to KeyCodes.KEY_F19,
GLFW_KEY_F20 to KeyCodes.KEY_F20,
GLFW_KEY_F21 to KeyCodes.KEY_F21,
GLFW_KEY_F22 to KeyCodes.KEY_F22,
GLFW_KEY_F23 to KeyCodes.KEY_F23,
GLFW_KEY_F24 to KeyCodes.KEY_F24,
GLFW_KEY_F25 to KeyCodes.KEY_F25,
GLFW_KEY_KP_0 to KeyCodes.KEY_KP_0,
GLFW_KEY_KP_1 to KeyCodes.KEY_KP_1,
GLFW_KEY_KP_2 to KeyCodes.KEY_KP_2,
GLFW_KEY_KP_3 to KeyCodes.KEY_KP_3,
GLFW_KEY_KP_4 to KeyCodes.KEY_KP_4,
GLFW_KEY_KP_5 to KeyCodes.KEY_KP_5,
GLFW_KEY_KP_6 to KeyCodes.KEY_KP_6,
GLFW_KEY_KP_7 to KeyCodes.KEY_KP_7,
GLFW_KEY_KP_8 to KeyCodes.KEY_KP_8,
GLFW_KEY_KP_9 to KeyCodes.KEY_KP_9,
GLFW_KEY_KP_DECIMAL to KeyCodes.KEY_KP_DECIMAL,
GLFW_KEY_KP_DIVIDE to KeyCodes.KEY_KP_DIVIDE,
GLFW_KEY_KP_MULTIPLY to KeyCodes.KEY_KP_MULTIPLY,
GLFW_KEY_KP_SUBTRACT to KeyCodes.KEY_KP_SUBTRACT,
GLFW_KEY_KP_ADD to KeyCodes.KEY_KP_ADD,
GLFW_KEY_KP_ENTER to KeyCodes.KEY_KP_ENTER,
GLFW_KEY_KP_EQUAL to KeyCodes.KEY_KP_EQUAL,
GLFW_KEY_LEFT_SHIFT to KeyCodes.KEY_LEFT_SHIFT,
GLFW_KEY_LEFT_CONTROL to KeyCodes.KEY_LEFT_CONTROL,
GLFW_KEY_LEFT_ALT to KeyCodes.KEY_LEFT_ALT,
GLFW_KEY_LEFT_SUPER to KeyCodes.KEY_LEFT_SUPER,
GLFW_KEY_RIGHT_SHIFT to KeyCodes.KEY_RIGHT_SHIFT,
GLFW_KEY_RIGHT_CONTROL to KeyCodes.KEY_RIGHT_CONTROL,
GLFW_KEY_RIGHT_ALT to KeyCodes.KEY_RIGHT_ALT,
GLFW_KEY_RIGHT_SUPER to KeyCodes.KEY_RIGHT_SUPER,
GLFW_KEY_MENU to KeyCodes.KEY_MENU,
GLFW_KEY_LAST to KeyCodes.KEY_LAST,
GLFW_MOUSE_BUTTON_1 to KeyCodes.MOUSE_BUTTON_1,
GLFW_MOUSE_BUTTON_2 to KeyCodes.MOUSE_BUTTON_2,
GLFW_MOUSE_BUTTON_3 to KeyCodes.MOUSE_BUTTON_3,
GLFW_MOUSE_BUTTON_4 to KeyCodes.MOUSE_BUTTON_4,
GLFW_MOUSE_BUTTON_5 to KeyCodes.MOUSE_BUTTON_5,
GLFW_MOUSE_BUTTON_6 to KeyCodes.MOUSE_BUTTON_6,
GLFW_MOUSE_BUTTON_7 to KeyCodes.MOUSE_BUTTON_7,
GLFW_MOUSE_BUTTON_8 to KeyCodes.MOUSE_BUTTON_8,
GLFW_MOUSE_BUTTON_LAST to KeyCodes.MOUSE_BUTTON_LAST,
GLFW_MOUSE_BUTTON_LEFT to KeyCodes.MOUSE_BUTTON_LEFT,
GLFW_MOUSE_BUTTON_RIGHT to KeyCodes.MOUSE_BUTTON_RIGHT,
GLFW_MOUSE_BUTTON_MIDDLE to KeyCodes.MOUSE_BUTTON_MIDDLE,
GLFW_MOUSE_BUTTON_1 to KeyCodes.MOUSE_BUTTON_1,
GLFW_MOUSE_BUTTON_2 to KeyCodes.MOUSE_BUTTON_2,
GLFW_MOUSE_BUTTON_3 to KeyCodes.MOUSE_BUTTON_3,
GLFW_MOUSE_BUTTON_4 to KeyCodes.MOUSE_BUTTON_4,
GLFW_MOUSE_BUTTON_5 to KeyCodes.MOUSE_BUTTON_5,
GLFW_MOUSE_BUTTON_6 to KeyCodes.MOUSE_BUTTON_6,
GLFW_MOUSE_BUTTON_7 to KeyCodes.MOUSE_BUTTON_7,
GLFW_MOUSE_BUTTON_8 to KeyCodes.MOUSE_BUTTON_8,
GLFW_MOUSE_BUTTON_LAST to KeyCodes.MOUSE_BUTTON_LAST,
GLFW_MOUSE_BUTTON_LEFT to KeyCodes.MOUSE_BUTTON_LEFT,
GLFW_MOUSE_BUTTON_RIGHT to KeyCodes.MOUSE_BUTTON_RIGHT,
GLFW_MOUSE_BUTTON_MIDDLE to KeyCodes.MOUSE_BUTTON_MIDDLE,
)
val CursorModes.glfw: Int