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.
119 lines
6.4 KiB
Ziran
119 lines
6.4 KiB
Ziran
#import "frame_snapshot"
|
|
#import "session"
|
|
#import "input_protocol"
|
|
Runtime :: #import "raylib_runtime";
|
|
Probe :: #import "raylib_window_host";
|
|
SelectionProbe :: #import "raylib_selection_host";
|
|
Text :: #import "byte_text_linux";
|
|
|
|
#if !#defined(_WIN32) && !#defined(__APPLE__) {
|
|
test_libc :: #system_library "libc";
|
|
TestPipeRaw :: (ends: *s32) -> s32 #foreign test_libc "pipe";
|
|
TestWriteRaw :: (fd: s32, data: *u8, count: u64) -> s64 #foreign test_libc "write";
|
|
}
|
|
|
|
#program_export
|
|
main :: () -> s32 {
|
|
if Runtime.OpenRaylib(0, 200) || Runtime.OpenRaylib(320, -1) ||
|
|
Runtime.OpenRaylib(320, 200, "bad\x00title") || Probe.opens != 0 { return 1 }
|
|
if !Runtime.OpenRaylib(320, 200, "Document", cast(u32)12) ||
|
|
Probe.opens != 1 || Probe.window_width != 320 || Probe.window_height != 200 ||
|
|
Probe.window_flags != cast(u32)12 || Text.TextFromCString(*Probe.window_title[0]) != "Document" {
|
|
return 2
|
|
}
|
|
Runtime.RaylibExitKey(0)
|
|
if Probe.exit_key != 0 || !Runtime.RaylibFrameRate(30) || Probe.frame_rate != 30 ||
|
|
Runtime.RaylibFrameRate(-1) || Runtime.RaylibFrameRate(1001) || Probe.frame_rate != 30 { return 3 }
|
|
if !Runtime.RaylibSetTitle("One 一") ||
|
|
Text.TextFromCString(*Probe.window_title[0]) != "One 一" ||
|
|
Runtime.RaylibSetTitle("bad\x00title") ||
|
|
Text.TextFromCString(*Probe.window_title[0]) != "One 一" { return 4 }
|
|
if Runtime.LoadTypefaceFile("Missing", "/missing/typeface.ttf", null, 0) ||
|
|
Probe.font_loads != 0 { return 13 }
|
|
Probe.middle_pressed = true; Probe.middle_released = true
|
|
Probe.fresh_key = 65; Probe.repeated_key = 263
|
|
if !Runtime.PollRaylib() { return 5 }
|
|
input_session := SessionOpen()
|
|
if !Runtime.RaylibFrameInputBegin(input_session) { return 15 }
|
|
first_input := CaptureFrameInput(input_session)
|
|
if first_input.elapsed_ms != 2000 || first_input.delta_ms != 0 ||
|
|
first_input.sequence != cast(u64)1 || first_input.keys[65] != cast(u8)3 { return 16 }
|
|
FrameInputEnd(input_session)
|
|
pointer := Runtime.PollPointer(); middle := Runtime.PollMiddlePointer()
|
|
if pointer.x != 17.0 || pointer.y != 29.0 ||
|
|
!middle.pressed || !middle.released || middle.down { return 6 }
|
|
if Runtime.RaylibLayoutKey(73) != 67 || Runtime.RaylibLayoutKey(66) != 66 ||
|
|
Runtime.RaylibLayoutKey(65) != 65 || Runtime.RaylibLayoutKey(263) != 263 ||
|
|
Runtime.RaylibLayoutKey(0) != 0 { return 23 }
|
|
#if #defined(_WIN32) || #defined(__APPLE__) {
|
|
if Runtime.RaylibLayoutKey(90) != 90 { return 24 }
|
|
}
|
|
#if #defined(_WIN32) || #defined(__APPLE__) {
|
|
none: [0]s32
|
|
if Runtime.RaylibWaitForActivity(none[:], 0) != Runtime.RaylibActivityUnsupported { return 25 }
|
|
} else {
|
|
pipes: [2]s32
|
|
if TestPipeRaw(*pipes[0]) != 0 { return 25 }
|
|
watched: [3]s32 = .{-1, pipes[0], pipes[1]}
|
|
watched[2] = -1
|
|
// Input from before the first wait may be queued; waking must not read it.
|
|
if Runtime.RaylibWaitForActivity(watched[:], 0) != Runtime.RaylibActivityInput { return 26 }
|
|
if Runtime.RaylibWaitForActivity(watched[:], 6) != Runtime.RaylibActivityNone { return 26 }
|
|
Probe.SendPollSentinel()
|
|
if Runtime.RaylibWaitForActivity(watched[:], 0) != Runtime.RaylibActivityNone { return 26 }
|
|
Probe.SendEvent()
|
|
if Runtime.RaylibWaitForActivity(watched[:], 1000) != Runtime.RaylibActivityInput || Probe.input_polls != 0 { return 27 }
|
|
byte: [1]u8 = .{1}
|
|
if TestWriteRaw(pipes[1], *byte[0], cast(u64)1) != cast(s64)1 ||
|
|
Runtime.RaylibWaitForActivity(watched[:], 1000) != Runtime.RaylibActivityDescriptor { return 28 }
|
|
}
|
|
// The poll queued the fresh press and the OS repeat in order.
|
|
key, modifiers := Runtime.RaylibInputTake(input_session)
|
|
repeated, repeated_modifiers := Runtime.RaylibInputTake(input_session)
|
|
after, after_modifiers := Runtime.RaylibInputTake(input_session)
|
|
if key != 65 || repeated != 263 || after != 0 ||
|
|
!Runtime.RaylibKeyDown(65) || Runtime.RaylibKeyDown(512) ||
|
|
Runtime.RaylibKeyDown(0) || !Runtime.RaylibFocused() { return 7 }
|
|
Probe.middle_pressed = false; Probe.middle_released = false
|
|
Probe.probe_time = 1.0
|
|
Probe.middle_down = true; Probe.repeated_key = 0; Probe.focused = false
|
|
if !Runtime.PollRaylib() || !Runtime.PollMiddlePointer().down ||
|
|
Runtime.PollMiddlePointer().pressed || Runtime.PollMiddlePointer().released ||
|
|
Runtime.RaylibFocused() { return 8 }
|
|
key, modifiers = Runtime.RaylibInputTake(input_session)
|
|
if key != 0 { return 8 }
|
|
if !Runtime.RaylibFrameInputBegin(input_session) { return 17 }
|
|
second_input := CaptureFrameInput(input_session)
|
|
if second_input.elapsed_ms != 2000 || second_input.delta_ms != 0 ||
|
|
second_input.sequence != cast(u64)2 || second_input.keys[65] != cast(u8)FrameKeyReleased ||
|
|
first_input.keys[65] != cast(u8)3 { return 18 }
|
|
FrameInputEnd(input_session)
|
|
Probe.focused = true; Probe.probe_time = 2.25; Probe.fresh_key = 65
|
|
if !Runtime.PollRaylib() || !Runtime.RaylibFrameInputBegin(input_session) { return 20 }
|
|
regained_input := CaptureFrameInput(input_session)
|
|
if regained_input.elapsed_ms != 2250 || regained_input.delta_ms != 250 ||
|
|
regained_input.keys[65] != cast(u8)FrameKeyHeld { return 21 }
|
|
FrameInputEnd(input_session)
|
|
key, modifiers = Runtime.RaylibInputTake(input_session)
|
|
while key != 0 { key, modifiers = Runtime.RaylibInputTake(input_session) }
|
|
// Control pressed and released inside one poll, as a script's quickest
|
|
// Control+B tap is, still applies to the key pressed after it.
|
|
Probe.fresh_key = 341; Probe.next_key = 66
|
|
if !Runtime.PollRaylib() { return 29 }
|
|
key, modifiers = Runtime.RaylibInputTake(input_session)
|
|
if key != 66 || (modifiers & KeyModifierControl) == 0 { return 29 }
|
|
Runtime.WindowQuitHost()
|
|
if Runtime.PollRaylib() { return 9 }
|
|
Runtime.CloseRaylib()
|
|
if Runtime.RaylibFrameInputBegin(input_session) { return 19 }
|
|
if Probe.closes != 1 || Probe.window_ready { return 10 }
|
|
if !Runtime.OpenRaylib() || Probe.opens != 2 || Probe.window_width != 960 ||
|
|
Probe.window_height != 600 || Probe.window_flags != cast(u32)4 ||
|
|
Text.TextFromCString(*Probe.window_title[0]) != "Probe Window" ||
|
|
Runtime.PollMiddlePointer().down || !Runtime.PollRaylib() { return 11 }
|
|
Runtime.CloseRaylib()
|
|
if Probe.closes != 2 { return 12 }
|
|
if SelectionProbe.selection_effects != 0 { return 14 }
|
|
return 0
|
|
}
|