| 1 | import time |
| 2 | import sokol.sapp |
| 3 | import ui2 |
| 4 | import libvendetta |
| 5 | |
| 6 | // draw runs the app's per-frame work and then the widget's render, with the GL |
| 7 | // context current. A frame that started more than 18 ms after the one before |
| 8 | // missed its 60 Hz slot, so in performance mode the thumbnail and media work |
| 9 | // waits for the next frame. |
| 10 | fn (mut p Player) draw(id string, frame ui2.Rect, scale f64, height f64) { |
| 11 | if id != libvendetta.video_surface_id { |
| 12 | return |
| 13 | } |
| 14 | now := time.ticks() |
| 15 | late_frame := p.last_frame_t0 > 0 && now - p.last_frame_t0 > 18 |
| 16 | p.last_frame_t0 = now |
| 17 | // Sokol registers its X11 display inside its own loop, so the window's |
| 18 | // WM_CLASS can only land on the first frame that has the window to name. |
| 19 | if !p.window_class_set { |
| 20 | p.window_class_set = true |
| 21 | set_window_class() |
| 22 | } |
| 23 | p.drain_events() |
| 24 | p.resume_pending_queue() |
| 25 | p.drain_mpris() |
| 26 | if p.want_fullscreen { |
| 27 | p.want_fullscreen = false |
| 28 | p.toggle_fullscreen() |
| 29 | } |
| 30 | if !(p.low_quality && late_frame) { |
| 31 | if p.thumb_ctx != unsafe { nil } { |
| 32 | p.drain_thumb() |
| 33 | if ui2.refresh_on_demand() && p.preview_state != 0 { |
| 34 | // The thumbnail mpv has no render context, so nothing wakes the |
| 35 | // loop for its replies: this poll is how a capture finishes |
| 36 | // after the pointer has stopped moving. |
| 37 | if p.thumb_wake != 0 { |
| 38 | ui2.cancel_timer(p.thumb_wake) |
| 39 | } |
| 40 | p.thumb_wake = ui2.after(0.1, fn () { |
| 41 | ui2.request_refresh() |
| 42 | }) |
| 43 | } |
| 44 | } |
| 45 | p.drain_media() |
| 46 | } |
| 47 | p.update_preview() |
| 48 | if p.fullscreen && time.ticks() - p.last_motion > 2500 { |
| 49 | sapp.show_mouse(false) |
| 50 | } |
| 51 | p.render(id, frame, scale, height) |
| 52 | } |
| 53 | |