Skip to content

Commit 8bc5224

Browse files
committed
Add time factor when replaying events
1 parent 2e9a506 commit 8bc5224

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/testing.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,23 @@ end
107107
function save_history(wm::XWindowManager, queue::EventQueue{XWindowManager,XCBWindow})
108108
events = Event{WindowRef}[]
109109
windows = XCBWindow[]
110+
previous_time = 0.0
110111
for event in queue.history
111112
i = findfirst(==(event.win), windows)
112113
isnothing(i) && push!(windows, event.win)
113114
winref = WindowRef(something(i, lastindex(windows)))
114-
push!(events, Event(event.type, event.data, event.location, event.time, winref))
115+
Δt = previous_time == 0 ? 0.0 : event.time - previous_time
116+
previous_time = event.time
117+
push!(events, Event(event.type, event.data, event.location, Δt, winref))
115118
end
116119
events
117120
end
118121

119122
# FIXME: Events will be triggered multiple times if an event triggers another. How should we tackle that?
120-
function replay_history(wm::XWindowManager, events::AbstractVector{Event{WindowRef}})
123+
function replay_history(wm::XWindowManager, events::AbstractVector{Event{WindowRef}}; time_factor = 1.0)
121124
windows = Dict{WindowRef,XCBWindow}()
122125
all_windows = xcb_window_t[]
123-
replay_time = nothing
126+
replay_time = time()
124127
for event in events
125128
win = get!(windows, event.win) do
126129
# Assume that window IDs will be ordered chronologically.
@@ -129,9 +132,9 @@ function replay_history(wm::XWindowManager, events::AbstractVector{Event{WindowR
129132
i = event.win.number
130133
wm.windows[all_windows[i]]
131134
end
132-
wait_for(event.time - something(replay_time, event.time))
133-
replay_time = event.time
134-
event = Event(event.type, event.data, event.location, time(), win)
135+
Δt = event.time * time_factor
136+
wait_for(Δt)
137+
event = Event(event.type, event.data, event.location, replay_time + Δt, win)
135138
send_event(wm, event)
136139
end
137140
end

test/runtests.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ function test(; replay_events = !interactive)
7171
ctx = GraphicsContext(win, attributes=[XCB.XCB_GC_FOREGROUND, XCB.XCB_GC_GRAPHICS_EXPOSURES], values=[screen.black_pixel, 0])
7272
attach_graphics_context!(win, ctx)
7373
send = send_event(wm, win)
74+
send = (_ -> sleep(0.01)) send
7475
queue = EventQueue(wm; record_history = true)
7576

7677
if interactive
@@ -113,7 +114,7 @@ function test(; replay_events = !interactive)
113114
ctx = GraphicsContext(win, attributes=[XCB.XCB_GC_FOREGROUND, XCB.XCB_GC_GRAPHICS_EXPOSURES], values=[screen.black_pixel, 0])
114115
attach_graphics_context!(win, ctx)
115116
task = @async main(wm)
116-
replay_history(wm, events)
117+
replay_history(wm, events; time_factor = 0.1)
117118
wait(task)
118119
@test !istaskfailed(task)
119120
isfile("keymap.c") && rm("keymap.c")

0 commit comments

Comments
 (0)