sdl

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 9 Imported by: 3 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

meui-sdl

The SDL3 window/input layer for MeUI, extracted from mobilegles.

window.go             Window state, event queue, run loop
sdl3_window.go        SDL3 loading, primary window/context
sdl3_multiwindow.go   multi-window creation and presentation
sdl_window.go         legacy SDL2 path
clipboard.go          SDL clipboard
cursor.go             system cursors
textinput.go          IME/text-input geometry
safearea.go           safe-area query
hooks.go              renderer/GL hooks installed by a backend

The package owns no GL drawing. A renderer installs the context hooks:

InvalidateGLStateCache
ApplyBaseContextState
FlushBatches
GLFinish
GLGetIntegerv
LoadGL3Functions
LoadGLFunctions
SetScreenSize

This is the first stage of the split: the code now builds as its own module, but mobilegles still carries a copy of the window layer while the GL backend is rewired. Once that switch is complete, the duplicate is deleted.

MIT.

Documentation

Index

Constants

View Source
const (
	SDL_HITTEST_NORMAL         uint32 = 0
	SDL_HITTEST_DRAGGABLE      uint32 = 1
	SDL_HITTEST_RESIZE_TOPLEFT uint32 = 2
	// …through SDL_HITTEST_RESIZE_LEFT = 9
	SDL_HITTEST_RESIZE_LEFT uint32 = 9
)

SDL_HitTestResult values (SDL_video.h).

View Source
const (
	EdgeNone  uint32 = 0
	EdgeTop   uint32 = 1 << 0
	EdgeBot   uint32 = 1 << 1
	EdgeLeft  uint32 = 1 << 2
	EdgeRight uint32 = 1 << 3
)

Edge zone masks (window-relative resize borders).

View Source
const (
	// SDL_INIT_VIDEO from SDL3 SDL_init.h (0x20 — 0x2 is not a valid
	// SDL3 subsystem flag; it only "worked" because SDL3 initializes
	// video on demand at window creation).
	SDL3_INIT_VIDEO uint64 = 0x00000020

	// SDL3 window flags — VERIFIED against /usr/include/SDL3/SDL_video.h
	// (SDL2's values differ: 0x4 is OCCLUDED, 0x10 is BORDERLESS!)
	SDL3_WINDOW_OPENGL     uint64 = 0x00000002
	SDL3_WINDOW_OCCLUDED   uint64 = 0x00000004
	SDL3_WINDOW_HIDDEN     uint64 = 0x00000008
	SDL3_WINDOW_BORDERLESS uint64 = 0x00000010
	SDL3_WINDOW_RESIZABLE  uint64 = 0x00000020
	// SDL_WINDOW_TRANSPARENT (SDL_video.h 0x40000000): window with a
	// transparent buffer — required for rounded window corners on
	// X11/XWayland (compositor needed).
	SDL3_WINDOW_TRANSPARENT uint64 = 0x40000000

	// SDL3 event type enum (SDL_EventType) — values verified against
	// /usr/include/SDL3/SDL_events.h. Sequential enums are written out
	// explicitly; NOTE: window events start at 0x202 and keyboard text
	// events differ from SDL2 (TEXT_INPUT=0x303 here, 0x303 was
	// SDL2's TEXT_EDITING-adjacent numbering).
	SDL3_EVENT_QUIT                uint32 = 0x100
	SDL3_EVENT_APP_TERMINATING     uint32 = 0x101
	SDL3_EVENT_APP_LOW_MEMORY      uint32 = 0x102
	SDL3_EVENT_APP_WILL_BACKGROUND uint32 = 0x103
	SDL3_EVENT_APP_DID_BACKGROUND  uint32 = 0x104
	SDL3_EVENT_APP_WILL_FOREGROUND uint32 = 0x105
	SDL3_EVENT_APP_DID_FOREGROUND  uint32 = 0x106
	SDL3_EVENT_DISPLAY_ORIENTATION uint32 = 0x151

	// Window events (SDL_EVENT_WINDOW_*)
	SDL3_EVENT_WINDOW_SHOWN                 uint32 = 0x202
	SDL3_EVENT_WINDOW_HIDDEN                uint32 = 0x203
	SDL3_EVENT_WINDOW_EXPOSED               uint32 = 0x204
	SDL3_EVENT_WINDOW_MOVED                 uint32 = 0x205
	SDL3_EVENT_WINDOW_RESIZED               uint32 = 0x206
	SDL3_EVENT_WINDOW_PIXEL_SIZE_CHANGED    uint32 = 0x207
	SDL3_EVENT_WINDOW_METAL_VIEW_RESIZED    uint32 = 0x208
	SDL3_EVENT_WINDOW_MINIMIZED             uint32 = 0x209
	SDL3_EVENT_WINDOW_MAXIMIZED             uint32 = 0x20A
	SDL3_EVENT_WINDOW_RESTORED              uint32 = 0x20B
	SDL3_EVENT_WINDOW_MOUSE_ENTER           uint32 = 0x20C
	SDL3_EVENT_WINDOW_MOUSE_LEAVE           uint32 = 0x20D
	SDL3_EVENT_WINDOW_FOCUS_GAINED          uint32 = 0x20E
	SDL3_EVENT_WINDOW_FOCUS_LOST            uint32 = 0x20F
	SDL3_EVENT_WINDOW_CLOSE_REQUESTED       uint32 = 0x210
	SDL3_EVENT_WINDOW_HIT_TEST              uint32 = 0x211
	SDL3_EVENT_WINDOW_ICCPROF_CHANGED       uint32 = 0x212
	SDL3_EVENT_WINDOW_DISPLAY_CHANGED       uint32 = 0x213
	SDL3_EVENT_WINDOW_DISPLAY_SCALE_CHANGED uint32 = 0x214
	SDL3_EVENT_WINDOW_SAFE_AREA_CHANGED     uint32 = 0x215
	SDL3_EVENT_WINDOW_OCCLUDED              uint32 = 0x216
	SDL3_EVENT_WINDOW_ENTER_FULLSCREEN      uint32 = 0x217
	SDL3_EVENT_WINDOW_LEAVE_FULLSCREEN      uint32 = 0x218
	SDL3_EVENT_WINDOW_DESTROYED             uint32 = 0x219
	SDL3_EVENT_WINDOW_HDR_STATE_CHANGED     uint32 = 0x21A

	// Keyboard events (SDL_EVENT_KEY_*, SDL_EVENT_TEXT_*)
	SDL3_EVENT_KEY_DOWN                uint32 = 0x300
	SDL3_EVENT_KEY_UP                  uint32 = 0x301
	SDL3_EVENT_TEXT_EDITING            uint32 = 0x302 // IME composition in progress
	SDL3_EVENT_TEXT_INPUT              uint32 = 0x303 // committed text
	SDL3_EVENT_KEYMAP_CHANGED          uint32 = 0x304
	SDL3_EVENT_KEYBOARD_ADDED          uint32 = 0x305
	SDL3_EVENT_KEYBOARD_REMOVED        uint32 = 0x306
	SDL3_EVENT_TEXT_EDITING_CANDIDATES uint32 = 0x307
	SDL3_EVENT_SCREEN_KEYBOARD_SHOWN   uint32 = 0x308
	SDL3_EVENT_SCREEN_KEYBOARD_HIDDEN  uint32 = 0x309

	// Mouse events (SDL_EVENT_MOUSE_*)
	SDL3_EVENT_MOUSE_MOTION      uint32 = 0x400
	SDL3_EVENT_MOUSE_BUTTON_DOWN uint32 = 0x401
	SDL3_EVENT_MOUSE_BUTTON_UP   uint32 = 0x402
	SDL3_EVENT_MOUSE_WHEEL       uint32 = 0x403
	SDL3_EVENT_MOUSE_ADDED       uint32 = 0x404
	SDL3_EVENT_MOUSE_REMOVED     uint32 = 0x405

	// Joystick events (SDL_EVENT_JOYSTICK_*)
	SDL3_EVENT_JOYSTICK_AXIS        uint32 = 0x600
	SDL3_EVENT_JOYSTICK_BALL        uint32 = 0x601
	SDL3_EVENT_JOYSTICK_HAT         uint32 = 0x602
	SDL3_EVENT_JOYSTICK_BUTTON_DOWN uint32 = 0x603
	SDL3_EVENT_JOYSTICK_BUTTON_UP   uint32 = 0x604

	// Touch events (SDL_EVENT_FINGER_*)
	SDL3_EVENT_FINGER_DOWN     uint32 = 0x700
	SDL3_EVENT_FINGER_UP       uint32 = 0x701
	SDL3_EVENT_FINGER_MOTION   uint32 = 0x702
	SDL3_EVENT_FINGER_CANCELED uint32 = 0x703

	// Drop events (SDL_EVENT_DROP_*)
	SDL3_EVENT_DROP_FILE     uint32 = 0x1000
	SDL3_EVENT_DROP_TEXT     uint32 = 0x1001
	SDL3_EVENT_DROP_BEGIN    uint32 = 0x1002
	SDL3_EVENT_DROP_COMPLETE uint32 = 0x1003
	SDL3_EVENT_DROP_POSITION uint32 = 0x1004

	// SDL_EVENT_SENSOR_UPDATE (SDL_events.h). Sensors are NOT window events:
	// the pump hands them to the handler installed with SetSensorHandler
	// instead of routing them to a window.
	SDL3_EVENT_SENSOR_UPDATE uint32 = 0x1200

	// SDL3 SDL_GLAttr enum values (VERIFIED against SDL3 headers —
	// SDL2-era guesses silently set GREEN_SIZE/BLUE_SIZE instead!).
	SDL3_GL_CONTEXT_MAJOR_VERSION uint32 = 17
	SDL3_GL_CONTEXT_MINOR_VERSION uint32 = 18
	SDL3_GL_CONTEXT_PROFILE_MASK  uint32 = 20 // SDL_GL_CONTEXT_PROFILE_MASK

	// SDL_GLprofile (SDL_video.h): the value for SDL_GL_CONTEXT_PROFILE_MASK.
	// Android has OpenGL ES only, so it must ask for the ES profile; the
	// desktop path leaves the default (desktop GL). int32 because that is the
	// value type SDL_GL_SetAttribute takes (the attr itself is uint32).
	SDL3_GL_CONTEXT_PROFILE_ES int32 = 0x0004

	// SDL_WINDOW_FULLSCREEN (SDL_video.h). On Android the surface belongs to
	// the activity and SDL's video driver owns the geometry, so the desktop
	// BORDERLESS/RESIZABLE pair is meaningless there.
	SDL3_WINDOW_FULLSCREEN uint64 = 0x0000000000000001

	// SDL_GL attribute names (SDL_GL_Attr enum values)
	SDL3_GL_MULTISAMPLEBUFFERS uint32 = 0xD
	SDL3_GL_MULTISAMPLESAMPLES uint32 = 0xE
)
View Source
const (
	SDL3_KMOD_LSHIFT uint16 = 0x001
	SDL3_KMOD_RSHIFT uint16 = 0x002
	SDL3_KMOD_LCTRL  uint16 = 0x040
	SDL3_KMOD_RCTRL  uint16 = 0x080
	SDL3_KMOD_LALT   uint16 = 0x100
	SDL3_KMOD_RALT   uint16 = 0x200
	SDL3_KMOD_LGUI   uint16 = 0x400
	SDL3_KMOD_RGUI   uint16 = 0x800
	// The LOCKS. Not held-key modifiers: CapsLock stays on until pressed again, and NumLock decides
	// whether the keypad's 1 is a '1' or an End. They are separate bits in SDL3's SDL_Keymod and they
	// were missing here, so a keypad key could not be interpreted at all.
	SDL3_KMOD_NUM    uint16 = 0x1000
	SDL3_KMOD_CAPS   uint16 = 0x2000
	SDL3_KMOD_SCROLL uint16 = 0x4000
)

SDL3 SDL_Keymod bit values.

View Source
const (
	SDL3_SCANCODE_A            int32 = 4
	SDL3_SCANCODE_B            int32 = 5
	SDL3_SCANCODE_C            int32 = 6
	SDL3_SCANCODE_D            int32 = 7
	SDL3_SCANCODE_E            int32 = 8
	SDL3_SCANCODE_F            int32 = 9
	SDL3_SCANCODE_G            int32 = 10
	SDL3_SCANCODE_H            int32 = 11
	SDL3_SCANCODE_I            int32 = 12
	SDL3_SCANCODE_J            int32 = 13
	SDL3_SCANCODE_K            int32 = 14
	SDL3_SCANCODE_L            int32 = 15
	SDL3_SCANCODE_M            int32 = 16
	SDL3_SCANCODE_N            int32 = 17
	SDL3_SCANCODE_O            int32 = 18
	SDL3_SCANCODE_P            int32 = 19
	SDL3_SCANCODE_Q            int32 = 20
	SDL3_SCANCODE_R            int32 = 21
	SDL3_SCANCODE_S            int32 = 22
	SDL3_SCANCODE_T            int32 = 23
	SDL3_SCANCODE_U            int32 = 24
	SDL3_SCANCODE_V            int32 = 25
	SDL3_SCANCODE_W            int32 = 26
	SDL3_SCANCODE_X            int32 = 27
	SDL3_SCANCODE_Y            int32 = 28
	SDL3_SCANCODE_Z            int32 = 29
	SDL3_SCANCODE_0            int32 = 39
	SDL3_SCANCODE_1            int32 = 30
	SDL3_SCANCODE_2            int32 = 31
	SDL3_SCANCODE_3            int32 = 32
	SDL3_SCANCODE_4            int32 = 33
	SDL3_SCANCODE_5            int32 = 34
	SDL3_SCANCODE_6            int32 = 35
	SDL3_SCANCODE_7            int32 = 36
	SDL3_SCANCODE_8            int32 = 37
	SDL3_SCANCODE_9            int32 = 38
	SDL3_SCANCODE_F1           int32 = 58
	SDL3_SCANCODE_F2           int32 = 59
	SDL3_SCANCODE_F3           int32 = 60
	SDL3_SCANCODE_F4           int32 = 61
	SDL3_SCANCODE_F5           int32 = 62
	SDL3_SCANCODE_F6           int32 = 63
	SDL3_SCANCODE_F7           int32 = 64
	SDL3_SCANCODE_F8           int32 = 65
	SDL3_SCANCODE_F9           int32 = 66
	SDL3_SCANCODE_F10          int32 = 67
	SDL3_SCANCODE_F11          int32 = 68
	SDL3_SCANCODE_F12          int32 = 69
	SDL3_SCANCODE_RETURN       int32 = 40
	SDL3_SCANCODE_ESCAPE       int32 = 41
	SDL3_SCANCODE_BACKSPACE    int32 = 42
	SDL3_SCANCODE_TAB          int32 = 43
	SDL3_SCANCODE_SPACE        int32 = 44
	SDL3_SCANCODE_MINUS        int32 = 45
	SDL3_SCANCODE_EQUAL        int32 = 46
	SDL3_SCANCODE_LEFTBRACKET  int32 = 47
	SDL3_SCANCODE_RIGHTBRACKET int32 = 48
	SDL3_SCANCODE_BACKSLASH    int32 = 49
	SDL3_SCANCODE_SEMICOLON    int32 = 51
	SDL3_SCANCODE_APOSTROPHE   int32 = 52
	SDL3_SCANCODE_GRAVE        int32 = 53
	SDL3_SCANCODE_COMMA        int32 = 54
	SDL3_SCANCODE_PERIOD       int32 = 55
	SDL3_SCANCODE_SLASH        int32 = 56
	SDL3_SCANCODE_UP           int32 = 82
	SDL3_SCANCODE_DOWN         int32 = 81
	SDL3_SCANCODE_LEFT         int32 = 80
	SDL3_SCANCODE_RIGHT        int32 = 79
	SDL3_SCANCODE_INSERT       int32 = 73
	SDL3_SCANCODE_HOME         int32 = 74
	SDL3_SCANCODE_PAGEUP       int32 = 75
	SDL3_SCANCODE_DELETE       int32 = 76
	SDL3_SCANCODE_END          int32 = 77
	SDL3_SCANCODE_PAGEDOWN     int32 = 78
	SDL3_SCANCODE_PAUSE        int32 = 72
	SDL3_SCANCODE_KP_1         int32 = 89
	SDL3_SCANCODE_KP_2         int32 = 90
	SDL3_SCANCODE_KP_3         int32 = 91
	SDL3_SCANCODE_KP_4         int32 = 92
	SDL3_SCANCODE_KP_5         int32 = 93
	SDL3_SCANCODE_KP_6         int32 = 94
	SDL3_SCANCODE_KP_7         int32 = 95
	SDL3_SCANCODE_KP_8         int32 = 96
	SDL3_SCANCODE_KP_9         int32 = 97
	SDL3_SCANCODE_KP_0         int32 = 98
	SDL3_SCANCODE_KP_PERIOD    int32 = 99
	SDL3_SCANCODE_KP_DIVIDE    int32 = 84
	SDL3_SCANCODE_KP_MULTIPLY  int32 = 85
	SDL3_SCANCODE_KP_MINUS     int32 = 86
	SDL3_SCANCODE_KP_PLUS      int32 = 87
	SDL3_SCANCODE_KP_ENTER     int32 = 88
	SDL3_SCANCODE_KP_EQUALS    int32 = 103
	SDL3_SCANCODE_KP_COMMA     int32 = 133
	SDL3_SCANCODE_LSHIFT       int32 = 225
	SDL3_SCANCODE_RSHIFT       int32 = 229
	SDL3_SCANCODE_LCTRL        int32 = 224
	SDL3_SCANCODE_RCTRL        int32 = 228
	SDL3_SCANCODE_LALT         int32 = 226
	SDL3_SCANCODE_RALT         int32 = 230
	SDL3_SCANCODE_LGUI         int32 = 227
	SDL3_SCANCODE_RGUI         int32 = 231
)

SDL3 SDL_Scancode values, GENERATED FROM THE INSTALLED HEADERS rather than typed by hand.

Every value here was printed by compiling against /usr/include/SDL3 and running the program, because a hand-typed scancode is exactly the sort of thing that is wrong by one and nobody notices. Regenerate with the probe in MIGRATION.md M47 after an SDL upgrade — a scancode that moves silently changes which key every shortcut in every app is bound to.

View Source
const (
	SDL_INIT_VIDEO               = 0x00000020
	SDL_WINDOW_OPENGL            = 0x00000002
	SDL_WINDOW_SHOWN             = 0x00000004
	SDL_KEYDOWN                  = 0x300
	SDL_KEYUP                    = 0x301
	SDL_MOUSEMOTION              = 0x400
	SDL_MOUSEBUTTONDOWN          = 0x401
	SDL_MOUSEBUTTONUP            = 0x402
	SDL_QUIT                     = 0x100
	SDL_WINDOWEVENT              = 0x200
	SDL_GL_CONTEXT_MAJOR_VERSION = 0x1
	SDL_GL_CONTEXT_MINOR_VERSION = 0x2
	SDL_GL_CONTEXT_PROFILE_MASK  = 0x3
	SDL_GL_CONTEXT_PROFILE_ES    = 0x2
)
View Source
const (
	ButtonLeft   = 1
	ButtonRight  = 2
	ButtonMiddle = 3
)

Mouse buttons

View Source
const (
	ModNone  KeyMod = 0
	ModShift KeyMod = 1 << 0
	ModCtrl  KeyMod = 1 << 1
	ModAlt   KeyMod = 1 << 2
	ModMeta  KeyMod = 1 << 3
	// The KEYPAD, named. The toolkit had NO keypad constants at all, so every keypad key arrived as a bare
	// scancode and no widget could bind one. These are the USB HID usage IDs, which is what SDL3 reports.
	// The keypad DIGITS agree between SDL3 and HID (89-99), which is why they passed through
	// correctly for years. The OPERATORS are not in SDL's scancode set at all, so their HID usages come
	// from the USB HID table — and the first version of these constants was written from memory and was
	// wrong for four of the six: `TestTheWholeKeyboardMapsToDistinctToolkitKeycodes` caught it as four
	// keys collapsing onto one, which is precisely the "the wrong character appeared" symptom.
	KeypadSlash    Keycode = 75  // 0x4B
	KeypadAsterisk Keycode = 85  // 0x55
	KeypadMinus    Keycode = 78  // 0x4E
	KeypadPlus     Keycode = 87  // 0x57
	KeypadEnter    Keycode = 88  // 0x58
	KeypadPercent  Keycode = 104 // 0x68
	KeypadDot      Keycode = 99
	Keypad0        Keycode = 98
	Keypad1        Keycode = 89
	Keypad2        Keycode = 90
	Keypad3        Keycode = 91
	Keypad4        Keycode = 92
	Keypad5        Keycode = 93
	Keypad6        Keycode = 94
	Keypad7        Keycode = 95
	Keypad8        Keycode = 96
	Keypad9        Keycode = 97
	KeypadEquals   Keycode = 103 // 0x67
	KeypadComma    Keycode = 126 // 0x7E

	// The PUNCTUATION of the main row. SDL3 and HID agree on all of them (47-56), so nothing has to be
	// remapped — they simply had no NAME, and a key the toolkit cannot name arrives as KeyUnknown,
	// which no widget can bind (and which is why Ctrl+/ , Ctrl+[ and Ctrl+\ were dead in the editor).
	// These are the USB HID usage IDs, which is what SDL3 reports.
	KeyOpenBracket  Keycode = 47 // [{
	KeyCloseBracket Keycode = 48 // ]}
	KeyBackslash    Keycode = 49 // \|
	KeySemicolon    Keycode = 51 // ;:
	KeyApostrophe   Keycode = 52 // '"
	KeyGrave        Keycode = 53 // `~
	KeyComma        Keycode = 54 // ,<
	KeyPeriod       Keycode = 55 // .>
	KeySlash        Keycode = 56 // /?
	KeyMinus        Keycode = 45 // -_
	KeyEqual        Keycode = 46 // =+

	// The NAVIGATION cluster, named. SDL3 numbers these 73-78 while USB HID numbers them in the 199-214
	// block, so they are the keys where the two schemes diverge — and where the bare pass-through
	// delivered a number that means nothing. A text box's Delete key was arriving as 76.
	KeyInsert   Keycode = 210
	KeyHome     Keycode = 199
	KeyPageUp   Keycode = 211
	KeyDelete   Keycode = 212
	KeyEnd      Keycode = 213
	KeyPageDown Keycode = 214
	KeyPause    Keycode = 215

	// The FUNCTION keys, named. HID F1-F12 are 58-69, which coincides with SDL3's numbering, so these were
	// never wrong — but they were unnamed, so a binding had to write a literal.
	KeyF1  Keycode = 58
	KeyF2  Keycode = 59
	KeyF3  Keycode = 60
	KeyF4  Keycode = 61
	KeyF5  Keycode = 62
	KeyF6  Keycode = 63
	KeyF7  Keycode = 64
	KeyF8  Keycode = 65
	KeyF9  Keycode = 66
	KeyF10 Keycode = 67
	KeyF11 Keycode = 68
	KeyF12 Keycode = 69

	// ModCaps, ModNum and ModScroll are LOCKS, not modifiers: they stay on while other keys are released.
	//
	// They are here because the keypad DEPENDS on them — keypad 1 is '1' with NumLock on and End with it
	// off — and a toolkit that cannot report the lock state cannot tell those two apart. ModCaps was
	// declared here long before anything ever SET it: the pump decoded only the four held modifiers, so
	// the constant was exported, re-exported through platform, and promised a capability the toolkit did
	// not deliver. `TestTheLockKeyStateIsCarried` is what caught that.
	ModCaps   KeyMod = 1 << 4
	ModNum    KeyMod = 1 << 5
	ModScroll KeyMod = 1 << 6
)
View Source
const (
	// SDL3 SDL_GLAttr enum value 21 (VERIFIED against SDL3 headers —
	// the SDL2-era value 0x5 is DOUBLEBUFFER in SDL3, so context
	// sharing was NEVER enabled and secondary contexts had no shared
	// programs/VBOs/atlas — all their draws were invalid garbage).
	SDL3_GL_SHARE_WITH_CURRENT_CONTEXT uint32 = 21
)

SDL3_GL_SetAttribute values not needed elsewhere.

View Source
const SDL3_HINT_ANDROID_TRAP_BACK_BUTTON = "SDL_ANDROID_TRAP_BACK_BUTTON"

SDL_HINT_ANDROID_TRAP_BACK_BUTTON: "1" makes the Android back gesture arrive as a key press instead of the system closing the app.

SDL's default is "0" — "Back button will be handled as usual for system" — which means the app is closed and can never participate in its own navigation. With it trapped, the press shows up as SDL_SCANCODE_AC_BACK, which this package turns into EventBack so the window can offer it to the app and close only if nothing handles it.

Harmless on desktop: no SDL backend reads it there.

View Source
const SDL3_HINT_VIDEO_FORCE_EGL = "SDL_VIDEO_FORCE_EGL"

SDL_HINT_VIDEO_FORCE_EGL: "0" selects GLX on X11/XWayland. EGL multi-window MakeCurrent/swap is broken in SDL3 on XWayland (SDL#9072, SDL#10023) — GLX is the classic working pattern.

View Source
const SDL3_PIXELFORMAT_ARGB8888 uint32 = 0x16362004

SDL_PIXELFORMAT_ARGB8888 from SDL3's SDL_pixels.h.

View Source
const SDL3_WINDOW_MAXIMIZED uint64 = 0x0000000000000080

SDL3_WINDOW_MAXIMIZED — SDL_video.h: #define SDL_WINDOW_MAXIMIZED SDL_UINT64_C(0x0000000000000080)

View Source
const SDL3_WINDOW_OCCLUDED_MULTI uint64 = 0x0000000000000004

SDL window flags.

Variables

View Source
var (
	SDL3_StartTextInput   func(win unsafe.Pointer)
	SDL3_PushEvent        func(ev uintptr) int32
	SDL3_StopTextInput    func(win unsafe.Pointer)
	SDL3_SetClipboardText func(text uintptr) int32
	SDL3_GetClipboardText func() uintptr
	SDL3_free             func(ptr uintptr)
)
View Source
var (
	InvalidateGLStateCache = func() {}
	ApplyBaseContextState  = func() {}
	FlushBatches           = func() {}
	GLFinish               = func() {}
	GLGetIntegerv          = func(pname uint32, data uintptr) {}
	LoadGL3Functions       = func() {}
	LoadGLFunctions        = func() {}
	SetScreenSize          = func(width, height float32) {}
)

The SDL layer owns the window and GL context, but not the renderer. The GL backend installs these hooks so context creation, switches and presents can keep its state and batches coherent without this package importing a renderer.

View Source
var (
	SDL3_GL_SetAttributeMulti     func(attr uint32, value int32)
	SDL3_GetWindowID              func(win unsafe.Pointer) uint32
	SDL3_GL_MakeCurrentMulti      func(win unsafe.Pointer, ctx unsafe.Pointer) bool
	SDL3_GL_SwapWindowMulti       func(win unsafe.Pointer) bool
	SDL3_SetWindowTitleMulti      func(win unsafe.Pointer, title uintptr)
	SDL3_GetWindowSizeMulti       func(win unsafe.Pointer, w, h *int32)
	SDL3_SetWindowSizeMulti       func(win unsafe.Pointer, w, h int32)
	SDL3_SetWindowFullscreenMulti func(win unsafe.Pointer, fullscreen bool) bool
	SDL3_GetErrorMulti            func() uintptr
	SDL3_SetWindowIcon            func(win unsafe.Pointer, icon unsafe.Pointer) bool
	SDL3_CreateSurfaceFrom        func(w, h int32, format uint32, pixels unsafe.Pointer, pitch int32) unsafe.Pointer
	SDL3_DestroySurface           func(surface unsafe.Pointer)
)

SDL3 window functions only used by multi-window paths.

View Source
var (
	SDL3_GL_SetSwapIntervalMulti func(interval int) bool
	SDL3_GetWindowFlagsMulti     func(win unsafe.Pointer) uint64
	SDL3_ShowWindowMulti         func(win unsafe.Pointer)
	SDL3_RaiseWindowMulti        func(win unsafe.Pointer)
	SDL3_SetHintMulti            func(name, value uintptr) bool
)
View Source
var (
	SDL3_MinimizeWindow func(win unsafe.Pointer) bool
	SDL3_MaximizeWindow func(win unsafe.Pointer) bool
	SDL3_RestoreWindow  func(win unsafe.Pointer) bool
)

minimize/restore/maximize entry points for the WindowFrame buttons.

View Source
var (
	SDL3_GetWindowProperties func(win unsafe.Pointer) uint32
	SDL3_GetPointerProperty  func(props uint32, name uintptr, def uintptr) uintptr
)
View Source
var (
	SDL3_Init               func(uint64) int32
	SDL3_Quit               func()
	SDL3_CreateWindow       func(title uintptr, w int32, h int32, flags uint64) unsafe.Pointer
	SDL3_DestroyWindow      func(unsafe.Pointer)
	SDL3_PollEvent          func(event unsafe.Pointer) bool
	SDL3_AddEventWatch      func(filter uintptr, userdata uintptr) bool
	SDL3_SetEventFilter     func(filter uintptr, userdata uintptr)
	SDL3_GL_CreateContext   func(unsafe.Pointer) unsafe.Pointer
	SDL3_GL_MakeCurrent     func(unsafe.Pointer, unsafe.Pointer)
	SDL3_GL_SwapWindow      func(unsafe.Pointer)
	SDL3_GL_SetAttribute    func(uint32, int32)
	SDL3_GL_GetProcAddress  func(name uintptr) uintptr
	SDL3_CreateSystemCursor func(cursorType int32) unsafe.Pointer
	SDL3_SetCursor          func(cursor unsafe.Pointer)
	// SDL_GetModState returns the CURRENT modifier state. A wheel event carries no
	// modifier field of its own (SDL_MouseWheelEvent has none), so this is the only
	// way to know whether shift or ctrl was held when the wheel turned.
	SDL3_GetModState func() uint16
)
View Source
var (
	SDL_Init              func(uint32) int32
	SDL_Quit              func()
	SDL_CreateWindow      func(uintptr, int32, int32, int32, int32, uint32) unsafe.Pointer
	SDL_DestroyWindow     func(unsafe.Pointer)
	SDL_PollEvent         func(unsafe.Pointer) int32
	SDL_GL_CreateContext  func(unsafe.Pointer) unsafe.Pointer
	SDL_GL_MakeCurrent    func(unsafe.Pointer, unsafe.Pointer)
	SDL_GL_SwapWindow     func(unsafe.Pointer)
	SDL_GL_SetAttribute   func(uint32, int32)
	SDL_GL_GetProcAddress func(uintptr) uintptr
)
View Source
var SDL3_GetCurrentVideoDriver func() uintptr

SDL3_GetCurrentVideoDriver reports the active video backend name.

View Source
var SDL3_GetGlobalMouseState func(x, y *float32) uint32

SDL3_GetGlobalMouseState reports the asynchronous desktop-relative cursor position (immune to window-position feedback, unlike the window-relative motion events).

View Source
var SDL3_GetMouseState func(x, y *float32) uint32

SDL3_GetMouseState reports live button state; the hit-test uses it to tell real presses (button down) from cursor-update calls.

View Source
var SDL3_GetTextInputArea func(win unsafe.Pointer, rect unsafe.Pointer, cursor *int32) bool

SDL3_GetTextInputArea is registered with the rest of the SDL3 entry points.

View Source
var SDL3_GetWindowPositionMulti func(win unsafe.Pointer, x, y *int32)
View Source
var SDL3_GetWindowSafeArea func(win unsafe.Pointer, rect unsafe.Pointer) bool

SDL3_GetWindowSafeArea is registered with the rest of the SDL3 entry points.

View Source
var SDL3_GetWindowSizeInPixelsMulti func(win unsafe.Pointer, w, h *int32)
View Source
var SDL3_SetTextInputArea func(win unsafe.Pointer, rect unsafe.Pointer, cursor int32) bool

SDL3_SetTextInputArea is registered with the rest of the SDL3 entry points.

View Source
var (
	SDL3_SetWindowHitTest func(win unsafe.Pointer, callback uintptr, data unsafe.Pointer) bool
)
View Source
var SDL3_SetWindowPositionMulti func(win unsafe.Pointer, x, y int32)

MoveSDLWin places the window's top-left corner (left/top resize).

View Source
var SDL3_ShowWindowFunc func(unsafe.Pointer)

SDL3_ShowWindow makes a window visible

View Source
var SDL3_SyncWindow func(win unsafe.Pointer) bool

MoveResizeSDLWin moves+resizes in one atomic X11 request. Returns false when the atomic path is unavailable (caller falls back to the split MoveSDLWinBy + ResizeWindow path). SDL3_SyncWindow blocks until SDL has finalised pending window state. It is the way out of a lagging size query: SDL can deliver a resize event before its own cached size catches up, and while that is true the probe agrees with the stale cache while the event holds the truth - the state in which a vertical resize leaves the seam's size unchanged and the frame is drawn at the old height.

View Source
var SwapEGL func()

SwapEGL is set by the Android backend to redirect SwapWindow to eglSwapBuffers.

Functions

func AppEventWatchAvailable

func AppEventWatchAvailable() bool

AppEventWatchAvailable reports whether the SDL symbol and a callback pointer exist. Used by the Android smoke app to distinguish "not loaded" from "SDL refused the watch".

func AppEventWatchInstalled

func AppEventWatchInstalled() bool

AppEventWatchInstalled reports whether SDL accepted the lifecycle/orientation event watch. It exists for diagnostics on devices where the watch cannot be installed before the event loop starts.

func CreateSDLWindowMulti

func CreateSDLWindowMulti(title string, width, height int32) (*sdlWin, error)

CreateSDLWindowMulti opens a new OS window with its own GL context sharing the primary renderer state. Must be called with the GL thread locked (callers run inside InitWindow-style setup on the locked thread). Returns the registry handle.

func DestroySDLWin

func DestroySDLWin(h *sdlWin)

DestroySDLWin removes a window from the registry and destroys it. The caller must not use the handle afterwards.

func EdgeZone

func EdgeZone(x, y, w, h float32) uint32

EdgeZone classifies a window-relative point against the resize border (6px). Returns an Edge* bitmask, 0 when not on an edge. MUST stay in sync with widgets.FrameEdgeSize (the frame hit-test).

func EffectiveSize

func EffectiveSize(w *Window) (int32, int32)

EffectiveSize returns the size to render and lay out at. Three cases:

  • our requests are newer than the last ack, or very recent: trust the optimistic cache (SDL can only report lagging values mid-drag; adopting them rewinds every frame → jitter/flash);
  • quiet (no requests for >1s): converge to ground truth. The LIVE PROBE is checked FIRST — during drags, ConfigureNotify events are processed later than requests are sent, so the newest-recorded ack can carry a mid-drag size a few px behind the final request while still looking "newer". Adopting it 1s after release reverts the cache below the real window → the post-drag flash strip. SDL's own cache (the probe) is pumped synchronously and is authoritative once quiet. The ack is only used when the probe AGREES with the cache but the ack differs (SDL's cache lagging its own event — the maximize case, where event data was observed fresher than the cache).

External resizes (maximize button, WM actions) issue no request through us, so ground truth is adopted after the quiet period, including missed resize events.

func Error

func Error() string

Error returns SDL's last error string.

func GLProcAddress

func GLProcAddress(name string) uintptr

GLProcAddress returns an OpenGL entry point from the current context.

func GetClipboardText

func GetClipboardText() string

GetClipboardText reads the system clipboard (SDL3). Empty string when unavailable.

func GetGL3ProcAddress

func GetGL3ProcAddress(name string) uintptr

func GetGLProcAddress

func GetGLProcAddress(name string) uintptr

GetGLProcAddress retrieves an OpenGL function pointer from the SDL context

func GlobalMousePos

func GlobalMousePos() (float32, float32)

GlobalMousePos returns the desktop-relative cursor position. Used for manual window moves so the drag math can't feed back on itself while the window is moving underneath the cursor.

func Init

func Init() error

Init is a compatibility entry point; the SDL library is loaded and the video subsystem initialized by the first InitWindow call.

func InitWindowError

func InitWindowError() error

InitWindowError reports why the platform window could not be created, or nil when it was. It answers for the most recent InitWindow call.

func KnownCursorNames

func KnownCursorNames() []string

KnownCursorNames returns the logical cursor names this backend maps to a system cursor. meui/platform asserts its constructors against this list.

func MakeCurrentSDLWin

func MakeCurrentSDLWin(h *sdlWin) bool

MakeCurrentSDLWin binds a window's GL context on this thread. Falls back to the primary window's context on the legacy path. MakeCurrentSDLWin binds the window's context and reports success. Returns false when the bind failed — callers must NOT draw/swap for the window this frame (mismatched context+drawable hangs XWayland).

func MaximizeSDLWin

func MaximizeSDLWin(h *sdlWin)

func MinimizeSDLWin

func MinimizeSDLWin(h *sdlWin)

MinimizeSDLWin / MaximizeSDLWin / RestoreSDLWin drive the window state from the custom title bar buttons.

func MouseLeftDown

func MouseLeftDown() bool

MouseLeftDown reports whether the left button is currently held. Ground truth for hit-test press detection (motion calls have the button up; a call coinciding with a press has it down). Returns false when SDL is unavailable (tests, tools).

func MoveResizeSDLWin

func MoveResizeSDLWin(w *Window, x, y, width, height int32) bool

MoveResizeSDLWin moves and resizes a window through SDL.

This used to issue XConfigureWindow + XSync directly, which paired origin and size in one request - but the GLX drawable follows the X window LAZILY, so a frame rendered at the new size could land on a surface that had not caught up. With GL's origin at the bottom left that offsets the whole frame vertically by the resize delta, which is the reported corruption on vertical resizes and on maximise. SDL's own calls keep its drawable in step with the window, so the raw-X11 path is gone.

func MoveSDLWinBy

func MoveSDLWinBy(w *Window, x, y int32)

MoveSDLWinBy repositions the window (used by left/top resize so the grabbed corner follows the mouse).

func NoteResizeAck

func NoteResizeAck(w *Window, width, height int32)

NoteResizeAck records a ConfigureNotify-acked size for request/ack matching. It does NOT touch the cached size — EffectiveSize decides.

func PrimarySDLWinHandle

func PrimarySDLWinHandle() *sdlWin

PrimarySDLWinHandle returns the legacy primary window's handle (nil before the first window exists). Multi-window features fall back to it so the first window gets chrome too.

func PrimarySDLWindowPointer

func PrimarySDLWindowPointer() unsafe.Pointer

PrimarySDLWindowPointer returns the raw SDL_Window* for the primary window, or nil when there is none.

The platform adapter needs it to PARENT a native dialog: SDL_ShowOpenFileDialog takes the owning window, and on mobile it is required rather than optional. The handle's own win field is unexported, so this is the accessor.

func ProcessEvents

func ProcessEvents(win *Window)

ProcessEvents polls all event sources and dispatches events to window state. Only the designated pump owner drives the global SDL queue — with multiple windows each on its own thread, SDL_PollEvent must be called from exactly one place (events are routed by windowID).

func ProcessEventsAndDispatch

func ProcessEventsAndDispatch(win *Window)

ProcessEventsAndDispatch polls event sources and dispatches to window state.

func ProcessSDL3Events

func ProcessSDL3Events(win *Window)

ProcessSDL3Events drains SDL for the legacy single-window path.

func ProcessSDLEvents

func ProcessSDLEvents(win *Window)

func PumpAll

func PumpAll()

PumpAll drains the platform event queue once, routing each event to the window that owns it.

func PumpEvents

func PumpEvents(fallback *Window)

PumpEvents polls the platform event sources and routes each event to the window that owns it (multi-window) or to the given window (legacy). Returns after all pending events are drained.

func QuerySDLWinSize

func QuerySDLWinSize(h *sdlWin) (int32, int32)

QuerySDLWinSize returns the window's TRUE size in screen pixels (display scaling can make it differ from the requested size) and records it on the handle.

func RaiseSDLWindow

func RaiseSDLWindow(h *sdlWin)

RaiseSDLWindow brings the window to the front.

func ResetSizeProbe

func ResetSizeProbe()

ResetSizeProbe makes the next SizeProbe print unconditionally, so two reads in one frame (before and after the clear that sets the viewport) can be told apart.

func ResizeSDLWin

func ResizeSDLWin(h *sdlWin, w, hgt int32)

ResizeSDLWin sets a window's pixel size (manual edge-resize drag).

func ResizeWindow

func ResizeWindow(w *Window, width, height int32)

ResizeWindow resizes a mobilegles window's OS surface and updates the logical size.

func RestoreSDLWin

func RestoreSDLWin(h *sdlWin)

func RunHeadlessDemo

func RunHeadlessDemo(win *Window)

RunHeadlessDemo runs the headless demo with simulated input.

func SDL3PushEvent

func SDL3PushEvent(buf []byte)

SDL3PushEvent pushes a raw 64-byte SDL3 event into the SDL queue (test/diagnostic injection).

func SDL3_ShowWindow

func SDL3_ShowWindow(window unsafe.Pointer)

func SetAppEventHandler

func SetAppEventHandler(fn func(Event))

SetAppEventHandler installs the receiver for lifecycle/orientation events.

func SetClipboardText

func SetClipboardText(text string)

SetClipboardText puts text on the system clipboard (SDL3).

func SetCursorByName

func SetCursorByName(name string)

SetCursorByName applies a system cursor by logical name. Names match the platform.Cursor constructors: "" / "arrow" (default), "text", "pointing", "move", "resizeH", "resizeV", "resizeLD", "resizeRD", "crosshair", "wait", "notAllowed". Unknown names and missing SDL entry points are silent no-ops.

func SetFullscreen

func SetFullscreen(w *Window, fullscreen bool)

SetFullscreen toggles fullscreen on a mobilegles window.

func SetFullscreenSDLWin

func SetFullscreenSDLWin(h *sdlWin, fullscreen bool)

SetFullscreenSDLWin toggles desktop-resolution fullscreen.

func SetSDLWinHitTestHandler

func SetSDLWinHitTestHandler(h *sdlWin, fn frameHitFn)

SetSDLWinHitTestHandler installs a Go classifier for the window's chrome regions. fn returns an SDL_HITTEST_* value.

func SetSDLWinTitle

func SetSDLWinTitle(h *sdlWin, title string)

SetSDLWinTitle updates a window's OS title text.

func SetSensorHandler

func SetSensorHandler(fn func(sensorID uint32, values [6]float32))

SetSensorHandler installs the receiver for sensor updates, or clears it with nil. The pump calls it on the UI thread, in the same pass as every other event, so a sensor sample arrives through the same serialized path as input — no polling goroutine and no second thread touching SDL.

func SetSwapInterval0

func SetSwapInterval0()

SetSwapInterval0 sets interval 0 on the currently bound context.

func SetWindowHitHandler

func SetWindowHitHandler(w *Window, fn func(x, y int32) uint32)

SetWindowHitHandler installs a chrome classifier on a mobilegles Window (convenience over SetSDLWinHitTestHandler). Falls back to the primary window's handle on the legacy single-window path.

func SetWindowSizeSDLWin

func SetWindowSizeSDLWin(w *Window, width, height int32) bool

SetWindowSizeSDLWin asks the OS for a new window SIZE without moving it. The request comes back through SDL_EVENT_WINDOW_RESIZED, so the whole resize path runs — drawable, viewport, projection and the toolkit's EventResize — exactly as it does when a user drags an edge. A host that wants to set a size programmatically (and a test that wants to exercise a real resize without a pointer) needs this; MoveResizeSDLWin also moves.

func Shutdown

func Shutdown()

Shutdown tears down SDL cleanly (window + subsystems). Call after the last window closes — e.g. windowed test harnesses before the process exits. Safe to call when SDL was never initialized.

func SizeProbe

func SizeProbe(w *Window)

func SwapSDL3Window

func SwapSDL3Window()

func SwapSDLWin

func SwapSDLWin(h *sdlWin)

SwapSDLWin presents a window's back buffer.

The one XWayland safeguard this needs is swap interval 0: a vsync'd swap waits for the compositor's frame callback, which never arrives for a fully occluded/unmapped window — an infinite block that froze the whole composite loop. Forcing interval 0 on the context (below) removes that hazard at its source.

It deliberately does NOT skip the present when SDL reports the window OCCLUDED. That flag is advisory and on XWayland it is sticky: once the window manager or compositor reports a window covered, it can stay set after the window is uncovered again. Skipping the swap turns the flag into a frozen window: the app keeps clearing and drawing into a back buffer that is never presented, so the window keeps showing its last presented frame, and a later resize exposes the never-presented buffer as undefined memory (garbage from any previous frame) in the newly exposed area. Covering a window with another one is therefore enough to freeze it permanently — reported as "all the other windows stop working and the Analysis window is the only one that works".

func SwapSDLWindow

func SwapSDLWindow()

func SwapWindow

func SwapWindow()

SwapWindow swaps the window buffer (SDL3, SDL2, or EGL).

func ToggleMaximizeSDLWin

func ToggleMaximizeSDLWin(h *sdlWin)

ToggleMaximizeSDLWin maximizes the window, or restores it when it is already maximized (title-bar maximize button behavior).

func VideoDriver

func VideoDriver() string

VideoDriver returns the active SDL video backend ("x11", "wayland", ...) — cached after the first query. Empty when SDL is unavailable (tests, tools).

func WindowMaximized

func WindowMaximized(w *Window) bool

WindowMaximized reports whether the OS window is maximized.

func WindowPos

func WindowPos(w *Window) (int32, int32)

WindowPos returns the window's top-left position in screen coords.

func WindowSize

func WindowSize(w *Window) (int32, int32)

WindowSize returns the window's TRUE current pixel size — ground truth for layout (queried live; resize events can lag/misreport).

Types

type Event

type Event struct {
	Type EventType

	// Window
	Width, Height int32 // for EventResize

	// Mouse
	X, Y           float32
	DX, DY         float32 // relative motion
	Button         int     // ButtonLeft/Right/Middle
	WheelX, WheelY float32

	// Keyboard
	Key Keycode
	Mod KeyMod
	// Repeat is set on a key-down that the OS generated by auto-repeat, not by a fresh press. It is
	// SEPARATE from the key deliberately: a widget that acts on a key press must not act again every time
	// the user holds it, and a widget that wants the repeats (a text field, a scrub slider) needs to know
	// which is which. Nothing in the tree set this before — platform.Event declared and documented a
	// Repeat field that no pump ever filled.
	Repeat bool
	Rune   rune // decoded character for EventTextInput

	// Text editing (IME composition): the in-progress text, and the IME's selection inside it
	// (byte offsets). TEXT_INPUT is the commit; this is what to show until then.
	Text       string
	CompStart  int
	CompLength int

	// Touch
	TouchID int64
	Touches []Touch

	// Joystick
	JoystickID int
	Axis       int
	Value      float32
	Hat        int

	// Display orientation (EventOrientationChanged): SDL_ORIENTATION_* value.
	Orientation int

	// Misc
	Files []string
}

Event represents an input event

type EventQueue

type EventQueue struct {
	// contains filtered or unexported fields
}

EventQueue is the central hub for event processing. Sources push events to it; the app polls from it.

func NewEventQueue

func NewEventQueue() *EventQueue

NewEventQueue creates an event queue with a 256-event ring buffer.

func (*EventQueue) Poll

func (q *EventQueue) Poll() Event

Poll returns the next event, or EventNone if the queue is empty.

func (*EventQueue) PollSources

func (q *EventQueue) PollSources()

PollSources drains all registered sources and queues their events.

func (*EventQueue) PushEvent

func (q *EventQueue) PushEvent(e Event)

PushEvent adds a synthetic event (e.g., from tests).

func (*EventQueue) RegisterSource

func (q *EventQueue) RegisterSource(src EventSource)

RegisterSource adds an event source. Sources are polled in registration order.

type EventSource

type EventSource interface {
	Poll() []Event
	Name() string
}

EventSource is the interface for any input device or event producer. Each source produces typed Event values via Poll(). Sources are registered on EventQueue and polled automatically.

type EventType

type EventType int

EventType represents different event types

const (
	EventNone               EventType = iota
	EventQuit                         // window close requested
	EventTextEditing                  // IME composition in progress (not committed)
	EventResize                       // window resized (Width, Height)
	EventMouseDown                    // mouse button pressed
	EventMouseUp                      // mouse button released
	EventMouseMove                    // mouse moved
	EventMouseWheel                   // scroll wheel (WheelX, WheelY)
	EventKeyDown                      // physical key pressed
	EventKeyUp                        // physical key released
	EventTextInput                    // UTF-8 character input (Rune)
	EventTouchDown                    // finger touched screen (TouchID, X, Y)
	EventTouchUp                      // finger lifted
	EventTouchMove                    // finger moved
	EventTouchCancel                  // touch cancelled
	EventBack                         // the OS asked to go back (Android back gesture/button)
	EventJoystickAxis                 // joystick axis (JoystickID, Axis, Value)
	EventJoystickButtonDown           // joystick button pressed
	EventJoystickButtonUp             // joystick button released
	EventJoystickHat                  // joystick hat moved (JoystickID, Hat, Value)
	EventFocusGained                  // window/app gained focus
	EventFocusLost                    // window/app lost focus
	EventAppPause                     // mobile: app backgrounded
	EventAppResume                    // mobile: app foregrounded
	EventAppLowMemory                 // mobile: the OS is low on memory
	EventAppTerminating               // mobile: the OS is terminating the app
	EventOrientationChanged           // display orientation changed (Orientation)
	EventFileDrop                     // file dropped on window (Files)
)

type KeyMod

type KeyMod int

KeyMod represents modifier key flags

func (KeyMod) AltDown

func (m KeyMod) AltDown() bool

func (KeyMod) ControlDown

func (m KeyMod) ControlDown() bool

func (KeyMod) MetaDown

func (m KeyMod) MetaDown() bool

func (KeyMod) OptionDown

func (m KeyMod) OptionDown() bool

OptionDown is an alias for AltDown. "Option" is the Mac keyboard name for the Alt key; meui code uses both names.

func (KeyMod) ShiftDown

func (m KeyMod) ShiftDown() bool

Modifiers helper methods (unison compatibility).

type Keycode

type Keycode int

Keycode uses USB HID scancode values (subset)

const (
	KeyUnknown    Keycode = 0
	KeyEnter      Keycode = 40
	KeyEscape     Keycode = 41
	KeyBackspace  Keycode = 42
	KeyTab        Keycode = 43
	KeySpace      Keycode = 44
	KeyLeftShift  Keycode = 225
	KeyRightShift Keycode = 229
	KeyLeftCtrl   Keycode = 224
	KeyRightCtrl  Keycode = 228
	KeyLeftAlt    Keycode = 226
	KeyRightAlt   Keycode = 230
	KeyLeftMeta   Keycode = 227
	KeyRightMeta  Keycode = 231
	KeyUp         Keycode = 200
	KeyDown       Keycode = 208
	KeyLeft       Keycode = 203
	KeyRight      Keycode = 205
	KeyA          Keycode = 4
	KeyB          Keycode = 5
	KeyC          Keycode = 6
	KeyD          Keycode = 7
	KeyE          Keycode = 8
	KeyF          Keycode = 9
	KeyG          Keycode = 10
	KeyH          Keycode = 11
	KeyI          Keycode = 12
	KeyJ          Keycode = 13
	KeyK          Keycode = 14
	KeyL          Keycode = 15
	KeyM          Keycode = 16
	KeyN          Keycode = 17
	KeyO          Keycode = 18
	KeyP          Keycode = 19
	KeyQ          Keycode = 20
	KeyR          Keycode = 21
	KeyS          Keycode = 22
	KeyT          Keycode = 23
	KeyU          Keycode = 24
	KeyV          Keycode = 25
	KeyW          Keycode = 26
	KeyX          Keycode = 27
	KeyY          Keycode = 28
	KeyZ          Keycode = 29
	Key0          Keycode = 39
	Key1          Keycode = 30
	Key2          Keycode = 31
	Key3          Keycode = 32
	Key4          Keycode = 33
	Key5          Keycode = 34
	Key6          Keycode = 35
	Key7          Keycode = 36
	Key8          Keycode = 37
	Key9          Keycode = 38
)

type Touch

type Touch struct {
	ID       int64
	X, Y     float32
	Pressure float32
}

Touch represents a single touch point

type Window

type Window struct {

	// OwnsEventPump: this window's RunFrame drives the global SDL pump
	// (exactly one window per process).
	OwnsEventPump bool
	// contains filtered or unexported fields
}

Window represents a platform window

func GetMainWindow

func GetMainWindow() *Window

GetMainWindow returns the main window instance

func InitWindow

func InitWindow(width, height int32) *Window

InitWindow initializes the main window

func OpenWindowNamed

func OpenWindowNamed(title string, width, height int32) (*Window, error)

OpenWindowNamed opens an ADDITIONAL OS window with its own GL context (sharing the primary renderer state) bound to a fresh mobilegles Window. The renderer must already be initialized (call InitRenderer after the first window exists). Events are routed to this window by SDL windowID; Swap presents this window's buffer.

The window+context are created ON THE PRIMARY'S THREAD via a render task: SDL's share attribute shares with the context current on the CALLING thread, so creation must happen where ctx1 is current. The new context is then bound on THIS (the caller's) thread — its permanent home for the frame loop.

func OpenWindowNamedInline

func OpenWindowNamedInline(title string, width, height int32) (*Window, error)

OpenWindowNamedInline creates an ADDITIONAL window directly on the calling thread, instead of queueing the work onto the primary's task queue and waiting for it the way OpenWindowNamed does.

It must be called on the UI thread, with the primary context current there — which is where App.CreateWindow runs (from main). OpenWindowNamed cannot be used from that thread: it blocks on a task that only that same thread could drain, so it deadlocks. Creating inline also keeps the new context on the UI thread, which is what lets every window be painted from one thread.

func (*Window) Close

func (w *Window) Close()

Close closes the window

func (*Window) Destroy

func (w *Window) Destroy()

Destroy tears down this window's OS surface and GL context and removes it from the registry. Must be called on the window's OWN thread (its context is current there) — i.e., from the window's frame-loop goroutine after the loop exits. A window closed without Destroy leaks its SDL surface and keeps receiving routed events.

func (*Window) Events

func (w *Window) Events() *EventQueue

Events returns the event queue.

func (*Window) Height

func (w *Window) Height() int32

Height returns window height

func (*Window) KeyPressed

func (w *Window) KeyPressed(key int) bool

KeyPressed returns true if the specified key is pressed

func (*Window) MakeCurrent

func (w *Window) MakeCurrent() bool

MakeCurrent binds THIS window's GL context, via osHandle() for the same reason Swap does. Returns false when the bind failed — the caller must skip drawing/swap for this window.

func (*Window) Maximize

func (w *Window) Maximize()

func (*Window) Maximized

func (w *Window) Maximized() bool

Maximized reports whether the OS window is currently maximized.

func (*Window) Minimize

func (w *Window) Minimize()

Minimize/Maximize/Restore drive the OS window state (title-bar buttons).

func (*Window) MouseButtonPressed

func (w *Window) MouseButtonPressed(button int) bool

MouseButtonPressed returns true if the specified mouse button is pressed

func (*Window) MousePos

func (w *Window) MousePos() (float32, float32)

MousePos returns the current mouse position

func (*Window) Poll

func (w *Window) Poll() Event

func (*Window) PollEvents

func (w *Window) PollEvents(handler func(Event)) bool

PollEvents drains all queued events, dispatches to window state, and calls handler for each event. Returns true if any were processed.

func (*Window) PushEvent

func (w *Window) PushEvent(e Event)

PushEvent adds a synthetic event to the window's event queue.

func (*Window) Raise

func (w *Window) Raise()

Raise brings the window to the front of the stacking order.

func (*Window) RegisterTask

func (w *Window) RegisterTask(f func())

RegisterTask queues f to run once on the render thread at the start of the next frame — the safe way to defer work (e.g. opening a new window) out of an event callback.

func (*Window) Restore

func (w *Window) Restore()

func (*Window) RunFrameTasks

func (w *Window) RunFrameTasks()

RunFrameTasks drains per-window deferred tasks and registered event sources — called by render loops that do NOT own the global SDL pump (the dedicated pump goroutine routes SDL events by windowID). RunFrameTasks drains per-window deferred tasks, registered event sources, and — when this window owns the SDL pump — the platform event queue (routed to per-window queues by windowID).

func (*Window) RunPendingTasks

func (w *Window) RunPendingTasks()

RunPendingTasks executes and clears queued render-thread tasks.

func (*Window) SafeArea

func (w *Window) SafeArea() (x, y, width, height int32, ok bool)

SafeArea reports the region of the window that is NOT covered by system UI — a notch, a status bar, a gesture bar, a rounded corner. It is in window coordinates.

ok is false when SDL cannot say (no window, or a platform that does not report one), and the caller must then treat the WHOLE window as safe. That is the right default: insetting on a guess moves content on every device that did not need it.

func (*Window) SetIcon

func (w *Window) SetIcon(pixels []uint32, width, height int) bool

SetIcon sets the window icon shown by the window manager and the taskbar. pixels are 0xAARRGGBB, TOP-DOWN, straight (unpremultiplied) alpha, as SDL_PIXELFORMAT_ARGB8888 expects; the caller owns the slice only for the duration of the call (SDL copies the surface).

It returns false when SDL has no window yet or the pixel buffer is short.

func (*Window) SetSize

func (w *Window) SetSize(width, height int32)

SetSize updates the window's logical size (called on resize events so drawing and hit-test geometry track the real OS window size).

func (*Window) SetTextInput

func (w *Window) SetTextInput(active bool, x, y, width, height int32)

SetTextInput turns text input on or off for this window and says where the text is being edited.

area is in window coordinates. A zero area is passed through: on desktop the area is advisory, and on mobile the caller is responsible for having a real one, which is why the seam's callers compute it from the focused widget.

func (*Window) SetTitle

func (w *Window) SetTitle(title string)

SetTitle updates the OS title bar text.

func (*Window) ShouldClose

func (w *Window) ShouldClose() bool

ShouldClose returns whether the window should close

func (*Window) Swap

func (w *Window) Swap()

Swap presents THIS window's back buffer.

It must go through osHandle(), not w.sdl: the PRIMARY window's handle lives in primaryHandle, so testing w.sdl alone sent the primary down the legacy SwapWindow() path, which presents a process-global window rather than its own. In a multi-window session that meant the primary's frames were never presented to the primary's surface — it kept showing one stale frame while other windows presented correctly. (The same nil-w.sdl trap made SetTitle/Raise/window-state no-ops until they were routed through osHandle too.)

func (*Window) TextInputArea

func (w *Window) TextInputArea() (x, y, width, height int32, ok bool)

TextInputArea reports the window's current text-input area as SDL has it, for diagnostics. It returns false when SDL cannot be asked.

func (*Window) ToggleMaximize

func (w *Window) ToggleMaximize()

ToggleMaximize maximizes the window, or restores it when already maximized (title-bar maximize-button semantics).

func (*Window) Width

func (w *Window) Width() int32

Width returns window width

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL