Files
kryon/tests/raylib_window_host.zi
T
waozi 0cf2c54b50 Expose the PRIMARY selection and keep in-poll modifier taps for Raylib keys
SystemPrimaryText, SystemPrimaryAvailable and SystemPrimarySet read and set
the X11/Wayland PRIMARY selection through the host. The SDL desktop and
Linux Raylib hosts implement it with SDL's primary selection; the Android,
Canvas, pixmap, terminal and bundle hosts report it unavailable instead of
aliasing the ordinary clipboard. Terminal uses it for selections,
middle-click, Shift+Insert and Paste Selection.

RaylibInputPoll took modifiers only from keys still down or just released,
so a Control press released again within the same poll was lost and a
scripted Control+C reached the app as a plain C. Modifier presses from the
pressed-key queue now apply to the keys after them. raylib_window_test
covers the tap.
2026-11-14 10:53:34 -03:00

198 lines
6.5 KiB
Ziran

#import "raylib_image_decode"
#import "raylib_runtime"
#import "byte_text_linux"
#import "paint_texture"
#import "drawing_props"
#import "geometry"
opens: s32;
closes: s32;
window_ready: bool;
window_width: s32;
window_height: s32;
window_flags: u32;
window_title: [512]u8;
frame_rate: s32;
font_loads: s32;
exit_key: s32;
focused: bool = true;
middle_down: bool;
middle_pressed: bool;
middle_released: bool;
fresh_key: s32;
// A second press in the same poll, after fresh_key.
next_key: s32;
repeated_key: s32;
CopyTitle :: (value: *u8) {
title := TextFromCString(value)
for index: cast(s64)0..title.count - 1 { window_title[index] = title[index] }
window_title[title.count] = 0
}
#program_export
InitWindow :: (width: s32, height: s32, title: *u8) {
opens += 1; window_ready = true
window_width = width; window_height = height; CopyTitle(title)
}
#program_export
SetConfigFlags :: (flags: u32) { window_flags = flags }
#program_export
IsWindowReady :: () -> bool { return window_ready }
#program_export
CloseWindow :: () { closes += 1; window_ready = false }
#program_export
UnloadFont :: (font: RaylibFont) { unused font }
#program_export
UnloadTexture :: (texture: Texture2D) { unused texture }
#program_export
LoadTextureFromImage :: (image: RaylibGlyphImage) -> Texture2D {
return Texture2D.{.id = cast(u32)1, .width = image.width,
.height = image.height, .mipmaps = image.mipmaps, .format = image.format}
}
#program_export
LoadImageFromMemory :: (extension: *u8, bytes: *u8, count: s32) -> RaylibGlyphImage {
unused extension; unused bytes; unused count
return .{}
}
#program_export
LoadImageFromTexture :: (texture: Texture2D) -> RaylibGlyphImage {
unused texture
return .{}
}
#program_export
UnloadImage :: (image: RaylibGlyphImage) { unused image }
#program_export
ImageRotateCW :: (image: *RaylibGlyphImage) { unused image }
#program_export
ImageRotateCCW :: (image: *RaylibGlyphImage) { unused image }
#program_export
ImageFlipHorizontal :: (image: *RaylibGlyphImage) { unused image }
#program_export
ImageFlipVertical :: (image: *RaylibGlyphImage) { unused image }
#program_export
GenTextureMipmaps :: (texture: *Texture2D) { unused texture }
#program_export
rlTexCoord2f :: (x: float32, y: float32) { unused x; unused y }
#program_export
rlNormal3f :: (x: float32, y: float32, z: float32) { unused x; unused y; unused z }
#program_export
SetTextureFilter :: (texture: Texture2D, filter: s32) {
unused texture
unused filter
}
#program_export
UnloadRenderTexture :: (target: HostRaylibRenderTexture) { unused target }
#program_export
SetTargetFPS :: (fps: s32) { frame_rate = fps }
#program_export
SetWindowTitle :: (title: *u8) { CopyTitle(title) }
#program_export
SetExitKey :: (key: s32) { exit_key = key }
#program_export
IsWindowFocused :: () -> bool { return focused }
#program_export
FileExists :: (path: *u8) -> bool { unused path; return false }
#program_export
LoadFileData :: (path: *u8, count: *s32) -> *u8 {
unused path; count.* = 0; return null
}
#program_export
UnloadFileData :: (bytes: *u8) { unused bytes }
#program_export
LoadFontData :: (bytes: *u8, byte_count: s32, pixels: s32,
codepoints: *s32, count: s32, kind: s32, actual: *s32) -> *RaylibGlyphInfo {
unused bytes
unused byte_count
unused pixels
unused codepoints
unused count
unused kind
actual.* = 0
return null
}
#program_export
UnloadFontData :: (glyphs: *RaylibGlyphInfo, count: s32) {
unused glyphs
unused count
}
#program_export
LoadFontEx :: (path: *u8, size: s32, codepoints: *s32, count: s32) -> RaylibFont {
unused path; unused size; unused codepoints; unused count
font_loads += 1
return RaylibFont.{}
}
#program_export
LoadFontFromMemory :: (extension: *u8, bytes: *u8, byte_count: s32, size: s32,
codepoints: *s32, count: s32) -> RaylibFont {
unused extension; unused bytes; unused byte_count; unused size; unused codepoints; unused count
font_loads += 1
return RaylibFont.{}
}
#program_export
WindowShouldClose :: () -> bool { return false }
#program_export
GetMouseX :: () -> s32 { return 17 }
#program_export
GetMouseY :: () -> s32 { return 29 }
#program_export
GetTouchPointCount :: () -> s32 { return 0 }
#program_export
GetTouchPosition :: (index: s32) -> Vector2 { unused index; return Vector2.{} }
#program_export
IsMouseButtonDown :: (button: s32) -> bool { return button == 2 && middle_down }
#program_export
IsMouseButtonPressed :: (button: s32) -> bool { return button == 2 && middle_pressed }
#program_export
IsMouseButtonReleased :: (button: s32) -> bool { return button == 2 && middle_released }
#program_export
GetMouseWheelMove :: () -> float32 { return 0.0 }
#program_export
GetKeyPressed :: () -> s32 { key := fresh_key; fresh_key = next_key; next_key = 0; return key }
#program_export
GetCharPressed :: () -> s32 { return 0 }
// A Dvorak position (scancode 12, I, types c) and a non-Latin one (5, B).
input_polls: s32;
EventWatch :: #type (*void, *void) -> s32 #c_call;
event_watch: EventWatch;
#program_export
SDL_PumpEvents :: () { }
#program_export
SDL_AddEventWatch :: (callback: EventWatch, userdata: *void) { unused userdata; event_watch = callback }
#program_export
SDL_AtomicSet :: (value: *s32, replacement: s32) -> s32 { previous := value.*; value.* = replacement; return previous }
#program_export
PollInputEvents :: () { input_polls += 1 }
SendEvent :: () { unused event_watch(null, null) }
SendPollSentinel :: () { kind: u32 = cast(u32)0x7F00; unused event_watch(null, cast(*void)*kind) }
#program_export
SDL_GetKeyFromScancode :: (scancode: s32) -> s32 {
if scancode == 12 { return 99 }
if scancode == 5 { return 0x441 }
if scancode >= 4 && scancode <= 29 { return scancode - 4 + 97 }
return 0
}
// The GLFW hosts' name for the same two positions and an unnamed key.
layout_c: [2]u8 = .{99, 0};
layout_other: [3]u8 = .{0xd1, 0x81, 0};
layout_name: [2]u8 = .{0, 0};
#program_export
GetKeyName :: (key: s32) -> *u8 {
if key == 73 { return *layout_c[0] }
if key == 66 { return *layout_other[0] }
if key == 90 { return null }
if key >= 65 && key <= 90 { layout_name[0] = cast(u8)(key + 32); return *layout_name[0] }
return null
}
#program_export
IsKeyDown :: (key: s32) -> bool { return key == 65 }
#program_export
IsKeyPressedRepeat :: (key: s32) -> bool { return key == repeated_key && key != 0 }
probe_time: float64 = 2.0;
#program_export
GetTime :: () -> float64 { return probe_time }
#program_export
IsKeyPressed :: (key: s32) -> bool { return key != 0 && key == fresh_key }
#program_export
IsKeyReleased :: (key: s32) -> bool { unused key; return false }