import time import sokol.sapp import ui2 import libvendetta // draw runs the app's per-frame work and then the widget's render, with the GL // context current. A frame that started more than 18 ms after the one before // missed its 60 Hz slot, so in performance mode the thumbnail and media work // waits for the next frame. fn (mut p Player) draw(id string, frame ui2.Rect, scale f64, height f64) { if id != libvendetta.video_surface_id { return } now := time.ticks() late_frame := p.last_frame_t0 > 0 && now - p.last_frame_t0 > 18 p.last_frame_t0 = now // Sokol registers its X11 display inside its own loop, so the window's // WM_CLASS can only land on the first frame that has the window to name. if !p.window_class_set { p.window_class_set = true set_window_class() } p.drain_events() p.resume_pending_queue() p.drain_mpris() if p.want_fullscreen { p.want_fullscreen = false p.toggle_fullscreen() } if !(p.low_quality && late_frame) { if p.thumb_ctx != unsafe { nil } { p.drain_thumb() if ui2.refresh_on_demand() && p.preview_state != 0 { // The thumbnail mpv has no render context, so nothing wakes the // loop for its replies: this poll is how a capture finishes // after the pointer has stopped moving. if p.thumb_wake != 0 { ui2.cancel_timer(p.thumb_wake) } p.thumb_wake = ui2.after(0.1, fn () { ui2.request_refresh() }) } } p.drain_media() } p.update_preview() if p.fullscreen && time.ticks() - p.last_motion > 2500 { sapp.show_mouse(false) } p.render(id, frame, scale, height) }