From 80f14d8fb92068552b258c65069f3fee405c23bc Mon Sep 17 00:00:00 2001 From: diviocity Date: Sun, 1 Nov 2026 19:05:47 +0100 Subject: [PATCH] add settings menu, new icons, overlay opacity customisation --- AGENTS.md | 51 +- assets/icons/page_advanced.png | Bin 0 -> 1343 bytes assets/icons/page_appearance.png | Bin 0 -> 1471 bytes assets/icons/page_audio.png | Bin 0 -> 139 bytes assets/icons/page_interface.png | Bin 0 -> 214 bytes assets/icons/page_playback.png | Bin 0 -> 981 bytes assets/icons/page_subtitles.png | Bin 0 -> 396 bytes assets/icons/page_video.png | Bin 0 -> 566 bytes ...24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg | 1 + ...24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg | 1 + ...24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg | 1 + ...24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg | 1 + ...24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg | 1 + ...24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg | 1 + ...24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg | 1 + scripts/make_pngs.sh | 12 +- src/main.v | 4 + src/player.v | 280 +++------ src/settings.v | 4 +- src/settings_view.v | 534 ++++++++++++++++++ src/theme.v | 10 + src/view.v | 128 +++-- 22 files changed, 764 insertions(+), 266 deletions(-) create mode 100644 assets/icons/page_advanced.png create mode 100644 assets/icons/page_appearance.png create mode 100644 assets/icons/page_audio.png create mode 100644 assets/icons/page_interface.png create mode 100644 assets/icons/page_playback.png create mode 100644 assets/icons/page_subtitles.png create mode 100644 assets/icons/page_video.png create mode 100644 scripts/icons/equalizer_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg create mode 100644 scripts/icons/movie_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg create mode 100644 scripts/icons/palette_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg create mode 100644 scripts/icons/play_circle_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg create mode 100644 scripts/icons/settings_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg create mode 100644 scripts/icons/subtitles_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg create mode 100644 scripts/icons/tune_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg create mode 100644 src/settings_view.v diff --git a/AGENTS.md b/AGENTS.md index 1ddc135..ea49112 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -22,6 +22,7 @@ than deliberate, that is said too. | `src/media.v` | queues, playlists, file dialog, open paths, thumbnail state machine, media worker | | `src/theme.v` | theme struct, TOML themes, live editor, colour pickers | | `src/settings.v` | settings/queue persistence, precedence | +| `src/settings_view.v` | the settings dialog (`ui2.settings` in a modal) | | `src/presets.v` | named bundles of mpv options | | `src/surface.v` | the per-frame hook (drains, budget, preview) | | `src/mpris_d_mpris.v` | D-Bus service (only with `-d mpris`) | @@ -816,7 +817,7 @@ mpv), Android `[auto, audiotrack, null]`. Everything the widget provides plus: track/chapter/device lists, `ao`, delay/aspect/rotate/zoom/deinterlace/hwdec/UI-scale, the mpv-flag mirrors the menus show as toggles, AB loop values, dialogs (`speed_text`, -`max_volume`, `url_open`, the mpv-option dialog, the preset/queue/playlist +`url_open`, the mpv-option dialog, the preset/queue/playlist name dialogs), fullscreen and per-mode menu-bar and overlay memories (`windowed_overlay=false`, `fullscreen_overlay=true`, `windowed_menu_hidden`, `fullscreen_menu_hidden=true`), the preview state machine fields @@ -834,14 +835,14 @@ queue_timer, stats_wake), notices, `open_mode` (`ask`/`play`/`queue`), Every window event string goes through `handle(event)` then `settings_changed()`. Routing order (first match wins): -1. `vd_*` → the widget's own `handle` (strip controls). +1. `vd_*` → the widget's own `handle` (strip controls). While the settings + dialog is open, `handle_settings` is offered the event next. 2. `pointer:...` while the queue sidebar is shown → `ui2.reorder_update` against `queue_config()`; a returned step is applied (`queue_apply_step`). Other pointer events return. 3. `handle_media(event)` — the menu event families of track/chapter/device/ aspect/rotate/playlist (below). -4. The dialog events (`playback_speed_custom`, `speed_cancel/apply`, - `volume_max_custom`, `max_volume_*`). +4. The dialog events (`playback_speed_custom`, `speed_cancel/apply`). 5. Prefix families: `playback_speed:`, `queue_rm_`, `theme:`, `theme_edit:`, `theme_delete:`, `open_mode:`, `ui_scale:`, `queue_load:`, `queue_delete:`, `playlist_load:`, `playlist_append:`, @@ -885,7 +886,7 @@ custom speed, mpv option, preset name, URL, queue name, playlist name); Escape closes that dialog and nothing else sees the key. Then `fullscreen && escape` exits fullscreen. The map (mpc-qt-flavoured): -`f` fullscreen · `space` pause (10) · `left/right` seek ±5 (18) · +`ctrl+,` settings · `f` fullscreen · `space` pause (10) · `left/right` seek ±5 (18) · `shift+left/right` ±30 (70/71) · `page_up/page_down` playlist steps · `,`/`.` frame-back-step/frame-step (72/73) · `up/down` volume ±5 clamped to `max_volume` (12) + `mpris_on_volume` · `m` mute (16) · `v` subtitles · @@ -904,25 +905,35 @@ just wakes the worker). `menus()` builds seven bars from live state; every change that alters them rebuilds them via `ui2.set_menu_bar(p.menus())` (property observers, -handlers, dialog applies). File, View, Playback, Audio, Video, Subtitles and -Options as described in §7.4's tables; the Options bar is the -"how the pipeline runs" home: Presets submenu, the raw mpv options configured -through the dialog or `--mpv-opt` (skipping the 14 already-mirrored ones — -`mirrored_mpv_options`: audio-exclusive, audio-pitch-correction, +handlers, dialog applies). The bars hold actions; persistent options live in +the settings dialog (below), whose rows reuse the §7.4 events, so those +handlers and shortcuts remain without a menu row. Options holds Settings... +and the lists a dialog row cannot carry: Presets, the raw mpv options +configured through the dialog or `--mpv-opt` (skipping the 14 already-mirrored +ones — `mirrored_mpv_options`: audio-exclusive, audio-pitch-correction, blend-subtitles, correct-downscaling, deband, deinterlace, dither, framedrop, hwdec, interpolation, linear-downscaling, sigmoid-upscaling, vd-lavc-fast, -video-sync — the menu check rows already cover exactly those), **Wait for -vsync timing** (the render-call knob), Sync mode submenu -(audio/display-resample/display-vdrop), Interpolation, Picture quality -submenu, Frame dropping submenu, Fast video decoding, Deinterlace, Hardware -decoding, Exclusive audio output, the media-controls rows (`$if mpris`), -Theme submenu. +video-sync — the settings rows cover exactly those) and the Theme submenu. The mpv flag toggles deliberately write the **opposite of what mpv reports** and leave the state to the observed properties — nothing writes these options at start (until the user clicks, mpv's own defaults rule); the observer walks each write back once the core takes it. +The **settings dialog** (`src/settings_view.v`, Options > Settings...) is a +`ui2.settings` view in a `ui2.modal_view`, because ui2 owns one native window. +It stores no options: `settings_values` reads the player on every build, and +`apply_setting` sends each change through the event its menu row uses (switch +keys are the events, dropdown keys their prefixes), so the mpv flag rows keep +§14.6's observed truth. The slider and number rows have no event: slider height +writes `p.cfg.slider_h`, max volume calls `set_max_volume`, speed sends +`playback_speed:`. The Appearance page's Theme editor button closes the dialog +and opens the sidebar. Page icons are `assets/icons/page_.png` +(`libvendetta.bundled_icon`, resolved on first open, none without a bundle), +which needs ui2's page icons to accept a path. The view builds only while open, keys reach +`settings_key_event` first, and `over_panel` keeps the wheel and right-click +from the player. + ### 7.7 Notices A stack of up to 4 toasts (`Notice{text, serial, wake}`), dwelt 4 s each @@ -996,7 +1007,7 @@ A **second, hidden mpv instance** (`thumb_ctx`) answers hover requests: `vo=null`, `ao=null`, `audio=no`, `pause=yes`, `config=no`, `screenshot-format=jpeg`. Only created when the preview is enabled (`--no-preview` or the saved setting keeps a whole second mpv core out of low-end machines -entirely; View > Hover preview turning it on later builds the instance). +entirely; Settings > Interface turning it on later builds the instance). Per-file, `load_thumb_file` opens the playing file once (loadfile replace, 210); links are never previewed (no duration to seek to, and the instance @@ -1121,6 +1132,10 @@ the sidebar's coordinate system, origin `content_top`), and every accepted change lands in both the row's field and the live theme (`set_theme_color_row` → `theme_editor_preview` folds all parseable fields into `p.theme`, palette, menus, mpv colours — the whole window previews while you drag). +`overlay_opacity` is the one non-colour value: the editor's slider sets it, and +it fills the panels over the video (dialogs, settings, statistics, the seek +preview). The scrims stay 0.45. Files carry it as `[opacity] overlay`, and a +file without it keeps 0.8. Save writes the current values as a fresh `[colors]` TOML under the edited name, validates like every other name field, and makes it current. @@ -1404,7 +1419,7 @@ All under `/vendetta/`: | `queues/.json` | JSON array of strings | Queue > Save queue... | | `playlists/.m3u` | m3u (`#EXTM3U` + plain entries) | Playlists > Save playlist... | | `presets/.json` | JSON `map[string]string` of mpv options | Options > Presets > Save | -| `themes/.toml` | `[colors]` table, hex per key | Theme editor > Save | +| `themes/.toml` | `[colors]` table, hex per key; `[opacity] overlay` | Theme editor > Save | Name fields share one rule: non-empty, no `/`, no `\`, no `..`. diff --git a/assets/icons/page_advanced.png b/assets/icons/page_advanced.png new file mode 100644 index 0000000000000000000000000000000000000000..26a7ca9e67d4244c8efb5cd54e1f097307ee1dc6 GIT binary patch literal 1343 zcmeAS@N?(olHy`uVBq!ia0y~yU~m9o4rT@hhPm4t-!L#RUJURFaeegS!zda~A@F>! z(_RJ!hFK*+e!&b5tE#JJ&D^!~)=kFmKbWMY678+je_hVtiQD>NqUeg!Y2zth|(XnQB0Z%@h+>&HK@X}3(`c=C|b_e9L*)82=T=Jg7sp7*PH+idq` zhTbAsv&Ad5e)G$xyVcv7!q;#?ev$?L5?EF+Rp^M$m-zW(rRi- z-QuB^nUpwf>C(4pH|0`OXTP02b=&*uv+=V#VxFC`w7K{B!lXj@ zo-l;y7}zZyvCLLWJTWkYBBx|IeKoz$#PzS zJ@K3y-X5#zuj+i~c%=P+nIz9^8wUALadY2Gx3Qj^$nxO#k9 z*)6$rA~DPK>U2$2cLBRu?Te4Itlao#vQ^(pPGKp{K!=~jJ;^sFEKmB_5XR%LC%52^ z6aTX1J{7k-e;;(VS$vu6sp?!?_n!}QT;wl**4lfa@6EX_>}RH&a9#UA=zv?){y%!P ztEL@l;+z}*ZRL+sp|#bBMFT zZ%ylp!@K?;mDoBft!PK`H`S+~_Dh}Rjpq*feER3v+vQF?=8MGCKmKbLkhec8|KI2L z(dp|iP5d`acClKvQngK(kt+K>aSj3dx>?n{S)c2ko_KFx-^#ksZS$or@42_5R$HIU zE&ZCdd(P|Yw`;Af7rc<~TU1}!_3vfWq|(34CmfFiy*4+|Wnf@n@O1TaS?83{1OQNO BO-uj) literal 0 HcmV?d00001 diff --git a/assets/icons/page_appearance.png b/assets/icons/page_appearance.png new file mode 100644 index 0000000000000000000000000000000000000000..38158a77fcbbd79eeb7bd830b5300c255427a7a7 GIT binary patch literal 1471 zcmeAS@N?(olHy`uVBq!ia0y~yU~m9o4rT@hhPm4t-!L#R2?Y3rxITLEVHAyq06YYY z+~YnnFfgny3GxeOU^NJmTd&4?mA6 z`z6S~{g#H*h4+@ycP&J&zExp4c$vF9T~uf8Om*hmDUSb~o2Q%naA3c&=JlMsZAW5W z#cnQo!FIE4vhC-5>rD%_>b_4>@DV?-{^8c69&h@y-Jf(#ys|uTL-dl&L;GZY?w2@L z{q94?o7q}mp-#Gr&m@bLRxWrHY3IMxH}!qMGX@5x^`0({ zArXh)PX8G%zud~m$Kd-IaXR!G_55s{a|CVoB<})|#^tp}Ct>#=#FIb-b z?Ch!bU1{evHJ*5gi|&4Q$Ykmn?bL4W&!-h4-?8d=YsPcDjM`%H_;$EXhz}rGbRfo~(u>prW&)E&P zN>{A&G;B>&UT~AaBCG1c@hF#d3&M;#upH=<--sLm3{0|L3 zooMy{)Xd4?R^Z_D?3{g%l;30JyaUOPTScCnO`n~&#p>Lj$sL>uHcwC48$V~1c-nFN zn8Plw_Q=QYp6fGs>d(BiKCb^loto#|FE?gye;-u!Uy)JA#EpFi!{j$#Qp1fHm&j=y zJjTKxZ-0^D;rX1FBKh7At-K6>3b_;xa4^Jc9{(h*&ERprvq8a_q2ZA{ivu$|gGb+% zy=#*GEMIWaILqelC;xplL5J3t{rzqDZ?^UN70M1_n=8KbLh*2~7ZQFDyy` literal 0 HcmV?d00001 diff --git a/assets/icons/page_interface.png b/assets/icons/page_interface.png new file mode 100644 index 0000000000000000000000000000000000000000..6921d8c280a9304561f730653e6642ab0c05fa10 GIT binary patch literal 214 zcmeAS@N?(olHy`uVBq!ia0y~yU~m9o7G?$ph6wkZw+svnq5(c3u8&@Pz(ku52kv2D zU|=f=@(X4NU0rni@w-pcqZt?&vOHZJLp+WrCrGebI7UT1dJw#zg@?z1E9iiaimZnN zS{ literal 0 HcmV?d00001 diff --git a/assets/icons/page_playback.png b/assets/icons/page_playback.png new file mode 100644 index 0000000000000000000000000000000000000000..cabc8eea0428f942a2da5f8d0ed9276a03ded56b GIT binary patch literal 981 zcmeAS@N?(olHy`uVBq!ia0y~yU~m9o4rT@hhPm4t-!L#Rng;lUxITLEVHA-X0{ic| zTQV>(q?H8u1v5yxW_Qh8%H%TrhH%3pf$q=zjBziX$MCIOFQ|R*j;87BcUBhWT5s;& zUK1Pfti62q7m?7E_w^F19y7c7I?tH>Z`v)}>r$MZzx7V#vgE7mTauG?)2VX*C!w~d z;k>FZHOyYURbRGt>MPcaP6h_Xm!2+;ArXh)PQM;@$U&g3T|kkACt_nWuXfp*6$@@? zi>*qU|Gl2&VMXGkw~NaEZQp&r+^;NMeK*7ZpQkHK*57;ddFzX~vx|9t_cnBHo56T^ zeFMAmT8|~BB2$j6Enr#M`65@SqS{^E=<-$FCyQ-Q_~y&ce=qOg$ktv_qoemou-*N} zpA45X*RL1#9PL+6sW`&&SbGhprCgzrm#ELlPaU=H4_nMO%xcX<5 ze0EG?fBvkpsnvD5f{RaNR(#w;i6Fmw{`2muHe5B`mQZ_G@rKJRhJ@_7nI6_Gw|N*N ztatM`9#cHAiG`v1cS&RB^Wqa?2M#_IygK2r{=w}G4}P?$UC3z)-p6q6ocIaOI7i7_ ztPJAQkFd<$&#C9Q_oiBmFw?e++8Y~mRMKI(|`?GIo5w;AToUht9ii<40f z6TiPg@Tr2sVji+;92;0R9gj@ru;6`qO)+EFQq#L3nz?`9&1+6x_+nj&?9`y5&jPxu zKTL_2E?Lc?<fvUyu{rheqm+S>TKUN;rnIEjFY&&|($FYJ8dx}(1TuL~D*85kILc)B=- zL>zuQ?IvHdf`F^*omFLyxo=l}{vUtyg1Ect#D#_>Ge5ITtd@JA<|klq#$C}#GE&*u z@a%EU2_BCM?apRYHs~Dv>FalvSwvMR=VfJstk9cS7Iu{YJ*J~fVrw)4W_hjGN=*th zc=NH5Q7nSv&-VxHEXU#_*Y3Zv{^_CvKgwQ2{&)QFP4(CNgWI{J#19H``sp=^ah__L zXCGg1Ri*aKlv&+ux@x);s*;Dd(Po_x~5xO5A2(U|{fc^>bP0 Hl+XkKLPyyS literal 0 HcmV?d00001 diff --git a/assets/icons/page_video.png b/assets/icons/page_video.png new file mode 100644 index 0000000000000000000000000000000000000000..8bcdc1e7274e165518b10024af7e9c2b5b38b406 GIT binary patch literal 566 zcmeAS@N?(olHy`uVBq!ia0y~yU~m9o4rT@hhPm4t-!L#RYz*)TaeegS!_Y#y_m=-- zU|_H+3GxeOU^KKA4Q2OJHVSaL`9tP$*3|tDfxqn!eEc9%khkEcJllhLtEOZ>l09Ox z@ztHP^XKO0z87}Baothhe|0nWQ3eKvU!E?GArXh)PP;DDWFX+$+{EfAc(5t<&0g_; z{|}p_U2QlakuFnv8Cv-`KOxz}?$qZgW9*j#w#Z1*$-y6?bo_^DK z;%7a>go(=&m_+tOZ|V7eZ0flC}#IIVD40>(QW z$|H}38#StlEMwU0(dZD+z$CJOfmP$jtb~7^2?sf+&F2W4b6{o1{q^Q^8dhw3v3IRd x{5I>2zyCI}D9QStx@{>tzpm79#{FkJg$;Yv@?yR3F)%PNc)I$ztaD0e0szfXMfCsx literal 0 HcmV?d00001 diff --git a/scripts/icons/equalizer_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg b/scripts/icons/equalizer_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg new file mode 100644 index 0000000..d627578 --- /dev/null +++ b/scripts/icons/equalizer_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/scripts/icons/movie_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg b/scripts/icons/movie_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg new file mode 100644 index 0000000..d48deca --- /dev/null +++ b/scripts/icons/movie_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/scripts/icons/palette_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg b/scripts/icons/palette_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg new file mode 100644 index 0000000..fe10bfa --- /dev/null +++ b/scripts/icons/palette_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/scripts/icons/play_circle_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg b/scripts/icons/play_circle_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg new file mode 100644 index 0000000..e199514 --- /dev/null +++ b/scripts/icons/play_circle_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/scripts/icons/settings_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg b/scripts/icons/settings_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg new file mode 100644 index 0000000..6b11c10 --- /dev/null +++ b/scripts/icons/settings_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/scripts/icons/subtitles_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg b/scripts/icons/subtitles_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg new file mode 100644 index 0000000..33050a4 --- /dev/null +++ b/scripts/icons/subtitles_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/scripts/icons/tune_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg b/scripts/icons/tune_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg new file mode 100644 index 0000000..e3ef053 --- /dev/null +++ b/scripts/icons/tune_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/scripts/make_pngs.sh b/scripts/make_pngs.sh index 64d4a87..59a4e22 100755 --- a/scripts/make_pngs.sh +++ b/scripts/make_pngs.sh @@ -12,7 +12,8 @@ # vinix-dark palette (text_main, #ffffff, for every strip icon today). The # colour step exists because the exports carry their own #e3e3e3 fill: raster # colorization makes the bundle conform to the palette no matter what colour -# the export tool is pointed at. +# the export tool is pointed at. The page_ entries are the settings dialog's +# navigation, in the palette's text_muted. # # ImageMagick is the rasterizer for now; it renders the 24 px viewBox # straight at 64 px (density 96 * 64/24 = 256), which is what the buttons and @@ -30,7 +31,14 @@ replay_30 replay30 #ffffff forward_30 forward30 #ffffff volume_up volume_up #ffffff volume_mute volume_mute #ffffff -volume_off volume_off #ffffff' +volume_off volume_off #ffffff +tune page_interface #e2e8f0 +palette page_appearance #e2e8f0 +play_circle page_playback #e2e8f0 +movie page_video #e2e8f0 +equalizer page_audio #e2e8f0 +subtitles page_subtitles #e2e8f0 +settings page_advanced #e2e8f0' if command -v magick >/dev/null 2>&1; then rasterizer=magick diff --git a/src/main.v b/src/main.v index 26fae34..ecd891d 100644 --- a/src/main.v +++ b/src/main.v @@ -335,6 +335,10 @@ fn main() { if (ev.code == .left_alt || ev.code == .right_alt) && !ev.repeat { player.set_menu_hidden(!player.menu_hidden()) } + if player.settings_open { + player.settings_key_event(ev) + return + } // The queue sidebar's rows move with Alt and the arrows (or Home / // End), the same move a drag performs. The key is consumed so the // plain-key handlers (the arrows seek and step the volume) never see diff --git a/src/player.v b/src/player.v index 5a220e7..8e6ab92 100644 --- a/src/player.v +++ b/src/player.v @@ -151,7 +151,7 @@ mut: zoom f64 deinterlace bool hwdec bool - // The pinned UI scale (View > UI scale). 0 follows the platform, which on + // The pinned UI scale (Settings > Appearance). 0 follows the platform, which on // Android means the phone-sized default in ui_scale_automatic. ui_scale f64 // mpv flags the menus show as toggles. They mirror the observed @@ -177,8 +177,6 @@ mut: ab_a f64 = -1 ab_b f64 = -1 loop bool - max_volume_open bool - max_volume_text string custom_open bool // The File > Open URL... dialog: what is typed here is a link by // construction, so it rides the same open path as the picker's files @@ -232,11 +230,16 @@ mut: // The theme editor panel: the theme the edits start from, the fields' // texts, and each colour row's chooser. theme_editor_open bool - theme_edit_base Theme - theme_edit_name string - theme_edit_texts map[string]string - theme_pickers map[string]ThemePicker - low_quality bool + // The settings dialog; its values live in the player, see settings_view.v. + settings_open bool + settings_state ui2.SettingsState + settings_icons map[string]string + theme_edit_base Theme + theme_edit_name string + theme_edit_opacity f64 + theme_edit_texts map[string]string + theme_pickers map[string]ThemePicker + low_quality bool // The window title's two halves, each the Options bar's own check row: // the playback status is the '(paused)' suffix while the file is paused, // and the playing file's name follows the app name after ' - '. @@ -813,6 +816,9 @@ fn (mut p Player) handle(event string) { p.Player.handle(event) return } + if p.settings_open && p.handle_settings(event) { + return + } $if debug_cadence ? { if event.starts_with('queue_') { eprintln('CAD queue ${event} len=${p.queue.len} pos=${p.playlist_index}') @@ -841,32 +847,6 @@ fn (mut p Player) handle(event string) { p.custom_open = false return } - 'volume_max_custom' { - p.max_volume_text = '${p.max_volume:.0f}' - p.max_volume_open = true - return - } - 'max_volume_cancel' { - p.max_volume_open = false - return - } - 'max_volume_apply' { - v := ui2.text('max_volume_input').trim_space().f64() - if v > 0 && v <= 1000 { - p.max_volume = v - if p.volume > p.max_volume { - p.volume = p.max_volume - mpv.set_double_async(p.mpv_ctx, 12, 'volume', p.volume) - } - p.max_volume_open = false - p.clear_notices() - p.settings_changed() - ui2.set_menu_bar(p.menus()) - } else { - p.notify('Max volume must be between 1 and 1000.') - } - return - } 'speed_apply' { speed := ui2.text('speed_input').trim_space().f64() if speed >= 0.01 && speed <= 100 { @@ -934,6 +914,12 @@ fn (mut p Player) handle(event string) { p.save_theme_from_editor() return } + if event == 'theme_overlay_opacity' { + p.theme_edit_opacity = ui2.slider_value(event) + p.theme_editor_preview() + ui2.request_refresh() + return + } if event == 'theme_name_input' { p.theme_edit_name = ui2.text(event) return @@ -1197,6 +1183,12 @@ fn (mut p Player) handle(event string) { p.set_show_stats(!p.show_stats) ui2.set_menu_bar(p.menus()) } + 'open_settings' { + p.set_settings_open(true) + } + 'settings_close' { + p.set_settings_open(false) + } 'view_preview' { p.set_show_preview(!p.show_preview) ui2.set_menu_bar(p.menus()) @@ -1314,13 +1306,21 @@ fn (mut p Player) handle_key(key string) { eprintln('CAD key: [${key}] te=${p.theme_editor_open} co=${p.custom_open} mo=${p.mpv_option_open} po=${p.preset_name_open} fs=${p.fullscreen}') } // While the theme editor is open its fields get the keys, so none of the - // shortcuts apply; Escape closes the editor. + // shortcuts apply; Escape closes the editor, and so does t when no field + // would take the letter. if p.theme_editor_open { - if key == 'escape' { + if key == 'escape' || (key == 't' && ui2.focused_id().len == 0) { p.handle('view_theme_editor') } return } + // The settings dialog's fields get the keys the same way. + if p.settings_open { + if key == 'escape' { + p.set_settings_open(false) + } + return + } // While the speed dialog is open its text field gets the keys, so none of the // shortcuts apply; Escape closes the dialog. if p.custom_open { @@ -1435,6 +1435,9 @@ fn (mut p Player) handle_key(key string) { 'ctrl+w' { p.close_file() } + 'ctrl+,' { + p.set_settings_open(true) + } 'ctrl+=' { p.zoom_by(0.25) } @@ -2049,14 +2052,6 @@ fn (p &Player) menus() []ui2.Menu { speeds << ui2.menu_check_item('playback_speed:${s}', title, math.abs(p.speed - s) < 0.01) } speeds << ui2.menu_item('playback_speed_custom', 'Custom...') - speeds << ui2.menu_separator() - speeds << ui2.menu_check_item('audio_pitch_correction', 'Correct audio pitch at speed changes', p.pitch_correction) - - sync_mode_items := [ - ui2.menu_check_item('video_sync:audio', 'Audio sync (default)', p.video_sync == 'audio'), - ui2.menu_check_item('video_sync:display-resample', 'Display resample', p.video_sync == 'display-resample'), - ui2.menu_check_item('video_sync:display-vdrop', 'Display resample, drop late frames', p.video_sync == 'display-vdrop'), - ] mut devices := []ui2.MenuItem{} for device in p.devices { @@ -2084,23 +2079,6 @@ fn (p &Player) menus() []ui2.Menu { title: 'Delay +0.1 s' shortcut: 'h' } - mut servers := []ui2.MenuItem{} - for server in audio_server_names() { - title := match server { - 'auto' { 'Auto (mpv chooses)' } - 'pipewire' { 'PipeWire' } - 'pulse' { 'PulseAudio' } - 'alsa' { 'ALSA' } - 'jack' { 'JACK' } - 'sdl' { 'SDL' } - 'wasapi' { 'WASAPI' } - 'avfoundation' { 'AVFoundation' } - 'null' { 'Null (no audio)' } - else { server } - } - servers << ui2.menu_check_item('ao_server:${server}', title, p.ao == server) - } - audio_items << ui2.submenu('Audio server', servers) audio_items << ui2.submenu('Output device', devices) audio_items << ui2.menu_separator() audio_items << ui2.MenuItem{ @@ -2113,8 +2091,6 @@ fn (p &Player) menus() []ui2.Menu { title: 'Volume down' shortcut: 'down' } - audio_items << ui2.menu_separator() - audio_items << ui2.menu_item('volume_max_custom', 'Set max volume...') mut aspects := []ui2.MenuItem{} for option in [['no', 'Default'], ['16:9', '16:9'], ['4:3', '4:3'], ['2.35:1', '2.35:1']] { @@ -2178,11 +2154,6 @@ fn (p &Player) menus() []ui2.Menu { ui2.menu_item_with_shortcut('file_open', 'Open...', 'cmd+o'), ui2.menu_item_with_shortcut('open_url', 'Open URL...', 'cmd+u'), ui2.menu_item_with_shortcut('file_close', 'Close', 'cmd+w'), - ui2.submenu('Default open', [ - ui2.menu_check_item('open_mode:ask', 'Ask', p.open_mode == 'ask'), - ui2.menu_check_item('open_mode:play', 'Play now', p.open_mode == 'play'), - ui2.menu_check_item('open_mode:queue', 'Add to queue', p.open_mode == 'queue'), - ]), ui2.menu_separator(), ui2.MenuItem{ id: 'screenshot' @@ -2200,58 +2171,18 @@ fn (p &Player) menus() []ui2.Menu { checked: p.fullscreen shortcut: 'f' }, - ui2.MenuItem{ - id: 'overlay_mode' - title: 'Overlay mode' - checked: if p.fullscreen { - p.fullscreen_overlay - } else { - p.windowed_overlay - } - shortcut: 'o' - }, ui2.MenuItem{ id: 'view_statistics' title: 'Statistics' checked: p.show_stats shortcut: 'i' }, - ui2.MenuItem{ - id: 'view_preview' - title: 'Hover preview' - checked: p.show_preview - }, ui2.MenuItem{ id: 'view_queue' title: 'Queue' checked: p.show_queue shortcut: 'q' }, - ui2.MenuItem{ - id: 'view_theme_editor' - title: 'Theme editor' - checked: p.theme_editor_open - shortcut: 't' - }, - ui2.submenu('UI scale', [ - ui2.menu_check_item('ui_scale:0', 'Automatic', p.ui_scale == 0), - ui2.menu_check_item('ui_scale:1', '1x', p.ui_scale == 1), - ui2.menu_check_item('ui_scale:1.5', '1.5x', p.ui_scale == 1.5), - ui2.menu_check_item('ui_scale:2', '2x', p.ui_scale == 2), - ui2.menu_check_item('ui_scale:2.5', '2.5x', p.ui_scale == 2.5), - ui2.menu_check_item('ui_scale:3', '3x', p.ui_scale == 3), - ]), - ui2.menu_check_item('view_smooth_bar', 'Smooth seek bar', p.smooth_bar), - // Performance mode is the redraw budget's backstop: it takes - // the continuous redraw away until it is turned off, so the - // row greys out while it runs. - ui2.MenuItem{ - id: 'view_continuous' - title: 'Continuous redraw' - checked: p.continuous - enabled: !p.low_quality - }, - ui2.menu_check_item('view_low_quality', 'Performance mode', p.low_quality), ] }, // One bar each for what a player works on, so a dropdown stays under @@ -2289,36 +2220,38 @@ fn (p &Player) menus() []ui2.Menu { checked: p.ab_a >= 0 && p.ab_b >= 0 shortcut: 'shift+l' }, - ui2.MenuItem{ - id: 'seek_back_30' - title: 'Seek back 30 s' - shortcut: 'shift+left' - } - ui2.MenuItem{ - id: 'seek_forward_30' - title: 'Seek forward 30 s' - shortcut: 'shift+right' - }, - ui2.MenuItem{ - id: 'seek_back_5' - title: 'Seek back 5 s' - shortcut: 'left' - }, - ui2.MenuItem{ - id: 'seek_forward_5' - title: 'Seek forward 5 s' - shortcut: 'right' - }, - ui2.MenuItem{ - id: 'frame_back' - title: 'Frame back' - shortcut: ',' - } - ui2.MenuItem{ - id: 'frame_step' - title: 'Frame forward' - shortcut: '.' - }, + ui2.submenu('Seek', [ + ui2.MenuItem{ + id: 'seek_back_30' + title: 'Seek back 30 s' + shortcut: 'shift+left' + } + ui2.MenuItem{ + id: 'seek_forward_30' + title: 'Seek forward 30 s' + shortcut: 'shift+right' + }, + ui2.MenuItem{ + id: 'seek_back_5' + title: 'Seek back 5 s' + shortcut: 'left' + }, + ui2.MenuItem{ + id: 'seek_forward_5' + title: 'Seek forward 5 s' + shortcut: 'right' + }, + ui2.MenuItem{ + id: 'frame_back' + title: 'Frame back' + shortcut: ',' + } + ui2.MenuItem{ + id: 'frame_step' + title: 'Frame forward' + shortcut: '.' + }, + ]), ui2.menu_separator(), ui2.submenu('Speed', speeds), ui2.menu_separator(), @@ -2339,69 +2272,27 @@ fn (p &Player) menus() []ui2.Menu { title: 'Subtitles' items: sub_items }, - // Options is the "how the pipeline runs" bar: any raw mpv option plus - // every playback-quality flag vendetta mirrors, instead of scattering - // them across the media-oriented bars. + // Options leads to the settings dialog, which holds every persistent + // option; what stays here are the lists a dialog row cannot carry: the + // presets, the raw mpv options and theme management. ui2.Menu{ title: 'Options' items: [ - // Presets bundle the whole Options bar under a name, so the - // submenu leads the fine-grained rows. + ui2.MenuItem{ + id: 'open_settings' + title: 'Settings...' + shortcut: 'ctrl+,' + }, + ui2.menu_separator(), ui2.submenu('Presets', p.preset_menu_items()), ...p.mpv_menu_items(), ui2.menu_separator(), - // Vsync pacing as vendetta's render call sees it: waiting inside - // the render for mpv's target display time is mpv's default - // presentation behaviour, --no-block-target-time switches it - // off, and the menu does the same for this session. - ui2.menu_check_item('render_wait_vsync', 'Wait for vsync timing', p.cfg.block_target_time), - ui2.submenu('Sync mode', sync_mode_items), - ui2.menu_separator(), - ui2.menu_check_item('video_interpolation', 'Interpolation', p.interpolation), - ui2.submenu('Picture quality', [ - ui2.menu_check_item('quality_deband', 'Deband', p.deband), - ui2.menu_check_item('quality_dither', 'Dither', p.dither), - ui2.menu_check_item('quality_correct_down', 'Correct downscaling', p.correct_downscaling), - ui2.menu_check_item('quality_linear_down', 'Linear light downscaling', p.linear_downscaling), - ui2.menu_check_item('quality_sigmoid_up', 'Sigmoid upscaling', p.sigmoid_upscaling), - ui2.menu_check_item('quality_blend_subs', 'Blend subtitles into video', p.blend_subtitles), - ]), - ui2.submenu('Frame dropping', [ - ui2.menu_check_item('framedrop:no', 'Off', p.framedrop == 'no'), - ui2.menu_check_item('framedrop:vo', 'Display stage', p.framedrop == 'vo'), - ui2.menu_check_item('framedrop:decoder', 'Decoder stage', p.framedrop == 'decoder'), - ui2.menu_check_item('framedrop:decoder+vo', 'Both stages', p.framedrop == 'decoder+vo'), - ]), - ui2.menu_check_item('video_fast_decode', 'Fast video decoding', p.fast_decode), - ui2.menu_check_item('video_deinterlace', 'Deinterlace', p.deinterlace), - ui2.menu_check_item('video_hwdec', 'Hardware decoding', p.hwdec), - ui2.menu_check_item('audio_exclusive', 'Exclusive audio output', p.audio_exclusive), - ui2.menu_separator(), - // The window title's composition, title-local state rather - // than mpv options: '(paused)' and the file name. - ui2.menu_check_item('title_status', 'Show playback status', p.show_playback_status), - ui2.menu_check_item('title_filename', 'Show filename in window title', p.show_title_filename), - ...p.media_controls_menu_items(), ui2.submenu('Theme', p.theme_menu_items()), ] }, ] } -// media_controls_menu_items is the Options row for the desktop media controls. -// Only a -d mpris build offers it, so the default menu has no dead row. -fn (p &Player) media_controls_menu_items() []ui2.MenuItem { - $if mpris ? { - return [ - ui2.menu_separator(), - ui2.menu_check_item('media_controls', 'Desktop media controls', p.media_controls), - ui2.menu_separator(), - ] - } $else { - return [ui2.menu_separator()] - } -} - // theme_menu_items lists the themes as check items, with the one the window // uses checked, then the editor's load and delete submenus, shaped like the // queue loader and deleter they follow. @@ -2441,6 +2332,17 @@ fn (mut p Player) wheel_volume(dy f64) { ui2.set_menu_bar(p.menus()) } +// set_max_volume moves the volume ceiling, pulling the volume under it. +fn (mut p Player) set_max_volume(v f64) { + p.max_volume = v + if p.volume > p.max_volume { + p.volume = p.max_volume + mpv.set_double_async(p.mpv_ctx, 12, 'volume', p.volume) + } + p.settings_changed() + ui2.set_menu_bar(p.menus()) +} + // mouse_button turns a right-button press over the video into play/pause. // Left and middle clicks pass through to the controls untouched. fn (mut p Player) mouse_button(button int, down bool, x f64, y f64) { diff --git a/src/settings.v b/src/settings.v index 9ad168b..3cafd0a 100644 --- a/src/settings.v +++ b/src/settings.v @@ -253,7 +253,7 @@ fn (mut p Player) apply_settings(s Settings) { p.hwdec = s.hwdec p.deinterlace = s.deinterlace p.ui_scale = s.ui_scale - // The scale pins before the window opens; View > UI scale flips it live. + // The scale pins before the window opens; the settings dialog flips it live. p.apply_ui_scale() p.sub_visible = s.sub_visible p.aspect = s.aspect @@ -271,7 +271,7 @@ fn (mut p Player) apply_settings(s Settings) { p.open_mode = s.open_mode p.low_quality = s.low_quality // The continuous redraw needs no start-up work either: the window opens - // with the saved policy and View > Continuous redraw flips it live. + // with the saved policy and the settings dialog flips it live. p.continuous = s.continuous // The smooth bar needs no start-up work: its glide arms itself from the // first time-pos report, and the chain dies on a pause by itself. diff --git a/src/settings_view.v b/src/settings_view.v new file mode 100644 index 0000000..c1bde5c --- /dev/null +++ b/src/settings_view.v @@ -0,0 +1,534 @@ +module main + +import math +import ui2 +import libvendetta + +// The settings dialog: ui2 owns one native window, so this is a ui2.settings +// view in a modal over the player. It holds no copy of the options. Every build +// reads the values from the player, and a change goes through the same event +// the menus send, so the mpv flag rows follow the observed properties as they +// do in the menus (and walk back if mpv refuses a write). + +const settings_id = 'app_settings' +const settings_w = 760.0 +const settings_h = 540.0 +const settings_margin = 24.0 + +// The number rows' width, enough for the speed's two decimals beside its steppers. +const settings_number_w = 130.0 + +// The number and slider rows have no menu event to reuse. +// The theme editor's row sends the event its key and menu row used. +const setting_theme_editor = 'view_theme_editor' +const setting_slider_height = 'slider_height' +const setting_max_volume = 'max_volume' +const setting_speed = 'speed' + +// The pages with an icon in assets/icons, as page_.png. +const settings_icon_pages = ['interface', 'appearance', 'playback', 'video', 'audio', 'subtitles', + 'advanced'] + +// The menu's fixed scale steps; 0 is automatic. +const setting_ui_scales = ['0', '1', '1.5', '2', '2.5', '3'] + +// toggle_item is a switch row. Its key is the menu event that flips the option. +fn toggle_item(key string, title string) ui2.SettingItem { + return ui2.SettingItem{ + key: key + title: title + kind: .switch + } +} + +// settings_scale_value is the option matching the current UI scale, '' for a +// scale the steps do not offer. +fn (p &Player) settings_scale_value() string { + for scale in setting_ui_scales { + if p.ui_scale == scale.f64() { + return scale + } + } + return '' +} + +// settings_pages lays the options out. Dropdown keys are the prefixes of their +// menu events. +fn (p &Player) settings_pages() []ui2.SettingPage { + mut themes := []ui2.SettingOption{} + for name in available_themes() { + themes << ui2.SettingOption{ + value: name + } + } + mut audio_servers := []ui2.SettingOption{} + for server in audio_server_names() { + audio_servers << ui2.SettingOption{ + value: server + } + } + mut interface_items := [ + toggle_item('overlay_mode', 'Overlay mode'), + toggle_item('view_smooth_bar', 'Smooth seek bar'), + toggle_item('view_preview', 'Seek bar hover preview'), + toggle_item('title_status', 'Show playback status in the window title'), + toggle_item('title_filename', 'Show filename in the window title'), + ] + $if mpris ? { + interface_items << toggle_item('media_controls', 'Desktop media controls') + } + return [ + ui2.SettingPage{ + id: 'interface' + title: 'Interface' + icon: p.settings_icons['interface'] + resettable: false + groups: [ui2.SettingGroup{ + items: interface_items + }] + }, + ui2.SettingPage{ + id: 'appearance' + title: 'Appearance' + icon: p.settings_icons['appearance'] + resettable: false + groups: [ + ui2.SettingGroup{ + items: [ + ui2.SettingItem{ + key: 'theme' + title: 'Theme' + kind: .dropdown + options: themes + }, + ui2.SettingItem{ + key: setting_theme_editor + title: 'Theme editor' + description: 'Opens in a sidebar, so the window previews your colours.' + kind: .button + button_text: 'Open' + }, + ui2.SettingItem{ + key: 'ui_scale' + title: 'UI scale' + kind: .dropdown + options: [ + ui2.SettingOption{ + value: '0' + label: 'Automatic' + }, + ui2.SettingOption{ + value: '1' + label: '1x' + }, + ui2.SettingOption{ + value: '1.5' + label: '1.5x' + }, + ui2.SettingOption{ + value: '2' + label: '2x' + }, + ui2.SettingOption{ + value: '2.5' + label: '2.5x' + }, + ui2.SettingOption{ + value: '3' + label: '3x' + }, + ] + }, + ui2.SettingItem{ + key: setting_slider_height + title: 'Seek and volume bar height' + kind: .slider + min: 1.0 + max: 30.0 + unit: ' px' + }, + ] + }, + ] + }, + ui2.SettingPage{ + id: 'playback' + title: 'Playback' + icon: p.settings_icons['playback'] + resettable: false + groups: [ + ui2.SettingGroup{ + items: [ + ui2.SettingItem{ + key: 'open_mode' + title: 'When opening files' + kind: .dropdown + options: [ + ui2.SettingOption{ + value: 'ask' + label: 'Ask' + }, + ui2.SettingOption{ + value: 'play' + label: 'Play now' + }, + ui2.SettingOption{ + value: 'queue' + label: 'Add to queue' + }, + ] + }, + toggle_item('playback_loop', 'Loop file'), + toggle_item('playback_loop_playlist', 'Loop playlist'), + ui2.SettingItem{ + key: setting_max_volume + title: 'Max volume' + kind: .number + min: 1.0 + max: 1000.0 + precision: 0 + field_width: settings_number_w + }, + ui2.SettingItem{ + key: setting_speed + title: 'Speed' + kind: .number + min: 0.01 + max: 100.0 + step: 0.25 + precision: 2 + field_width: settings_number_w + }, + ] + }, + ] + }, + ui2.SettingPage{ + id: 'video' + title: 'Video' + icon: p.settings_icons['video'] + resettable: false + groups: [ + ui2.SettingGroup{ + items: [ + toggle_item('video_hwdec', 'Hardware decoding'), + toggle_item('video_deinterlace', 'Deinterlace'), + toggle_item('video_fast_decode', 'Fast video decoding'), + toggle_item('video_interpolation', 'Interpolation'), + ] + }, + ui2.SettingGroup{ + title: 'Picture quality' + items: [ + toggle_item('quality_deband', 'Deband'), + toggle_item('quality_dither', 'Dither'), + toggle_item('quality_correct_down', 'Correct downscaling'), + toggle_item('quality_linear_down', 'Linear light downscaling'), + toggle_item('quality_sigmoid_up', 'Sigmoid upscaling'), + ] + }, + ] + }, + ui2.SettingPage{ + id: 'audio' + title: 'Audio' + icon: p.settings_icons['audio'] + resettable: false + groups: [ + ui2.SettingGroup{ + items: [ + ui2.SettingItem{ + key: 'ao_server' + title: 'Audio server' + kind: .dropdown + options: audio_servers + }, + toggle_item('audio_exclusive', 'Exclusive audio output'), + toggle_item('audio_pitch_correction', 'Correct audio pitch at speed changes'), + ] + }, + ] + }, + ui2.SettingPage{ + id: 'subtitles' + title: 'Subtitles' + icon: p.settings_icons['subtitles'] + resettable: false + groups: [ + ui2.SettingGroup{ + items: [ + toggle_item('subs_visible', 'Show subtitles'), + toggle_item('quality_blend_subs', 'Blend subtitles into video'), + ] + }, + ] + }, + ui2.SettingPage{ + id: 'advanced' + title: 'Advanced' + icon: p.settings_icons['advanced'] + resettable: false + groups: [ + ui2.SettingGroup{ + items: [ + ui2.SettingItem{ + // Performance mode takes the continuous redraw away. + ...toggle_item('view_continuous', 'Continuous redraw') + disabled: p.low_quality + }, + toggle_item('view_low_quality', 'Performance mode'), + toggle_item('render_wait_vsync', 'Wait for vsync timing'), + ui2.SettingItem{ + key: 'video_sync' + title: 'Sync mode' + kind: .dropdown + options: [ + ui2.SettingOption{ + value: 'audio' + label: 'Audio sync (default)' + }, + ui2.SettingOption{ + value: 'display-resample' + label: 'Display resample' + }, + ui2.SettingOption{ + value: 'display-vdrop' + label: 'Display resample, drop late frames' + }, + ] + }, + ui2.SettingItem{ + key: 'framedrop' + title: 'Frame dropping' + kind: .dropdown + options: [ + ui2.SettingOption{ + value: 'no' + label: 'Off' + }, + ui2.SettingOption{ + value: 'vo' + label: 'Display stage' + }, + ui2.SettingOption{ + value: 'decoder' + label: 'Decoder stage' + }, + ui2.SettingOption{ + value: 'decoder+vo' + label: 'Both stages' + }, + ] + }, + ] + }, + ] + }, + ] +} + +// settings_values reads every row's value from the player. +fn (p &Player) settings_values() map[string]ui2.SettingValue { + mut values := map[string]ui2.SettingValue{} + toggles := { + 'overlay_mode': if p.fullscreen { + p.fullscreen_overlay + } else { + p.windowed_overlay + } + 'view_smooth_bar': p.smooth_bar + 'title_status': p.show_playback_status + 'title_filename': p.show_title_filename + 'subs_visible': p.sub_visible + 'view_preview': p.show_preview + 'media_controls': p.media_controls + 'playback_loop': p.loop + 'playback_loop_playlist': p.loop_playlist + 'video_hwdec': p.hwdec + 'video_deinterlace': p.deinterlace + 'video_fast_decode': p.fast_decode + 'video_interpolation': p.interpolation + 'quality_deband': p.deband + 'quality_dither': p.dither + 'quality_correct_down': p.correct_downscaling + 'quality_linear_down': p.linear_downscaling + 'quality_sigmoid_up': p.sigmoid_upscaling + 'quality_blend_subs': p.blend_subtitles + 'audio_exclusive': p.audio_exclusive + 'audio_pitch_correction': p.pitch_correction + 'view_continuous': p.continuous + 'view_low_quality': p.low_quality + 'render_wait_vsync': p.cfg.block_target_time + } + for key, on in toggles { + values[key] = ui2.SettingValue(on) + } + values['open_mode'] = ui2.SettingValue(p.open_mode) + values['theme'] = ui2.SettingValue(p.theme_name) + values['video_sync'] = ui2.SettingValue(p.video_sync) + values['framedrop'] = ui2.SettingValue(p.framedrop) + values['ao_server'] = ui2.SettingValue(p.ao) + values['ui_scale'] = ui2.SettingValue(p.settings_scale_value()) + values[setting_slider_height] = ui2.SettingValue(p.cfg.slider_h) + values[setting_max_volume] = ui2.SettingValue(p.max_volume) + values[setting_speed] = ui2.SettingValue(p.speed) + return values +} + +// settings_theme maps the app theme onto ui2's component colours, so the dialog +// follows theme changes and the live editor. +fn (p &Player) settings_theme() ui2.ComponentTheme { + return ui2.ComponentTheme{ + ...ui2.component_theme(true) + background: p.theme.bg_dark + foreground: p.theme.text_main + // Buttons fill with muted and dropdowns with background: one colour for both. + muted: p.theme.bg_dark + muted_foreground: p.theme.text_muted + border: p.theme.menu_border + primary: p.theme.btn_primary + primary_foreground: p.theme.text_main + } +} + +// settings_frame is the dialog's size in a window of the given bounds. +fn settings_frame(b ui2.Rect) ui2.Rect { + return ui2.rect(0, 0, math.max(math.min(settings_w, b.width - settings_margin * 2), 0.0), + math.max(math.min(settings_h, b.height - settings_margin * 2), 0.0)) +} + +fn (p &Player) settings_config() ui2.SettingsConfig { + return ui2.SettingsConfig{ + id: settings_id + frame: settings_frame(ui2.bounds()) + pages: p.settings_pages() + values: p.settings_values() + state: p.settings_state + group_variant: .outline + nav_width: 200 + // The smallest ui2 offers, the nearest to the app's own 11 to 13 pt text. + size: .small + transparent: true + theme: p.settings_theme() + } +} + +// apply_setting hands one changed row to the handler its menu row uses. +fn (mut p Player) apply_setting(change ui2.SettingChange) { + value := change.value + match value { + bool { + p.handle(change.key) + } + string { + p.handle('${change.key}:${value}') + } + f64 { + match change.key { + setting_slider_height { + p.cfg.slider_h = value + } + setting_max_volume { + p.set_max_volume(value) + } + setting_speed { + p.handle('playback_speed:${value}') + } + else {} + } + } + } +} + +// take_settings_step stores what the dialog decoded, then rebuilds and does +// what has to wait for the new tree. +fn (mut p Player) take_settings_step(step ui2.SettingsStep) { + p.settings_state = step.state + for change in step.changes { + p.apply_setting(change) + } + // The editor is a sidebar, which the dialog's scrim would cover. + if step.action == setting_theme_editor { + p.set_settings_open(false) + if !p.theme_editor_open { + p.handle(setting_theme_editor) + } + return + } + p.settings_changed() + ui2.refresh() + if step.sync_id.len > 0 && ui2.text(step.sync_id) != step.sync_text { + ui2.set_text(step.sync_id, step.sync_text) + } + if step.focus.len > 0 { + ui2.focus(step.focus) + } + if step.scroll { + ui2.scroll_to_offset(step.scroll_id, step.scroll_to) + } +} + +// handle_settings offers a window event to the open dialog and reports whether +// it took it. +fn (mut p Player) handle_settings(event string) bool { + step := ui2.settings_update(p.settings_config(), event, ui2.SettingsInput{ + text: ui2.text + number: ui2.slider_value + }) or { return false } + p.take_settings_step(step) + return true +} + +// settings_key_event offers a key to the open dialog: Ctrl+F goes to the search +// field, and what the dialog does not use falls to handle_key's guard. +fn (mut p Player) settings_key_event(event ui2.KeyEvent) { + if event.ctrl && event.code == .f && !event.alt && !event.shift { + ui2.consume_key() + ui2.focus(ui2.settings_search_field_id(settings_id)) + return + } + step := ui2.settings_key(p.settings_config(), ui2.focused_id(), event) or { return } + ui2.consume_key() + p.take_settings_step(step) +} + +// set_settings_open shows or hides the dialog. The selected page survives a +// close; the search does not. The page icons resolve on the first open. +fn (mut p Player) set_settings_open(open bool) { + if open && p.settings_icons.len == 0 { + for page in settings_icon_pages { + p.settings_icons[page] = libvendetta.bundled_icon('page_${page}') + } + } + p.settings_open = open + p.settings_state = ui2.SettingsState{ + ...p.settings_state + query: '' + menu: '' + } + ui2.request_refresh() +} + +// settings_dialog is the modal around the view. The view only builds while the +// dialog is open, so it costs playback's rebuilds nothing. +fn (p &Player) settings_dialog(b ui2.Rect) !ui2.Element { + frame := settings_frame(b) + return ui2.modal_view(ui2.ModalViewConfig{ + id: 'settings_dialog' + frame: b + open: true + dismiss_action_id: 'settings_close' + overlay_box: ui2.BoxStyle{ + bg: p.theme.overlay_bg + opacity: 0.45 + } + content_width: frame.width + content_height: frame.height + content_box: ui2.BoxStyle{ + bg: p.theme.bg_dark + opacity: p.theme.overlay_opacity + radius: 8 + } + content: ui2.settings(p.settings_config())! + }) +} diff --git a/src/theme.v b/src/theme.v index fcd5326..b482baf 100644 --- a/src/theme.v +++ b/src/theme.v @@ -1,4 +1,5 @@ import os +import math import toml import strconv import ui2 @@ -96,6 +97,9 @@ mut: osd_border u32 sub_text u32 sub_border u32 + // How much of the video the panels floating over it hide, 0 to 1: dialogs, + // settings, the statistics popup and the seek preview. + overlay_opacity f64 = 0.8 } // default_theme is the theme that is compiled into vendetta. @@ -177,6 +181,9 @@ fn load_theme(name string) Theme { eprintln('vendetta: theme ${name}: ${err}') return theme } + if opacity := doc.value_opt('opacity.overlay') { + theme.overlay_opacity = math.clamp(opacity.f64(), 0.0, 1.0) + } colors := doc.value_opt('colors') or { eprintln('vendetta: theme ${name} has no [colors] table') return theme @@ -435,6 +442,7 @@ fn (mut p Player) open_theme_editor(name string) { base := if name.len > 0 { load_theme(name) } else { default_theme() } p.theme_edit_base = base p.theme_edit_name = name + p.theme_edit_opacity = base.overlay_opacity p.theme_edit_texts = map[string]string{} for key in color_keys { p.theme_edit_texts[key] = hex_text(theme_color_of(base, key)) @@ -545,6 +553,7 @@ fn (mut p Player) theme_editor_preview() { theme.set_color(key, c) } } + theme.overlay_opacity = p.theme_edit_opacity p.theme = theme p.palette = palette_of(theme) // The bar and its panels draw from ui2's globals every frame. @@ -566,6 +575,7 @@ fn (mut p Player) save_theme_from_editor() { for key in color_keys { text += '${key} = 0x${theme_color_of(p.theme, key):06x}\n' } + text += '\n[opacity]\noverlay = ${p.theme.overlay_opacity:.2f}\n' os.mkdir_all(theme_dir(), os.MkdirParams{}) or {} os.write_file(os.join_path(theme_dir(), '${clean}.toml'), text) or { p.notify('Could not save the theme: ${err}') diff --git a/src/view.v b/src/view.v index e1dbc55..099c4c7 100644 --- a/src/view.v +++ b/src/view.v @@ -18,6 +18,15 @@ const queue_list_id = 'queue_list' // queue_row_h is one queue row's height inside the reorder container. const queue_row_h = 24.0 +// The reorder container's spacing, which the rows' width follows. +const queue_row_gap = 2.0 +const queue_list_padding = 4.0 +// The remove button's side, inset equally from the row's top and right edges. +const queue_rm_size = 18.0 +const queue_rm_inset = 3.0 +// ui2 keeps rows this far clear of its scroller. +const queue_scroller_w = 6.0 + // stats_body turns the observed playback statistics into the popup's text. // A value of 0 means mpv reports nothing (no file, or the property is not // tracked), which is shown as a dash. @@ -89,6 +98,9 @@ fn (p &Player) stats_popup_rect() ui2.Rect { // there. fn (p &Player) over_panel(x f64, y f64) bool { b := ui2.bounds() + if p.settings_open { + return true + } if p.theme_editor_open && x < theme_editor_w { return true } @@ -149,7 +161,7 @@ fn (mut p Player) view() ui2.Element { } children << ui2.view('stats_popup', p.stats_popup_rect(), ui2.BoxStyle{ bg: p.theme.bg_dark - opacity: 0.8 + opacity: p.theme.overlay_opacity radius: 8 }, stat_items) } @@ -261,11 +273,40 @@ fn (mut p Player) view() ui2.Element { } editor_items << ui2.scrollable(ui2.ScrollableConfig{ id: 'theme_rows' - frame: ui2.rect(0, 92, 348, b.height - 140) + frame: ui2.rect(0, 92, 348, b.height - 172) stack: .column children: rows background: p.theme.bg_dark }) or { ui2.label('', '', ui2.rect(0, 0, 0, 0), editor_text) } + // The panels' opacity sits under the pane: the colour pickers place + // themselves from the rows' fixed top. + editor_items << ui2.label('theme_opacity_label', 'Overlay opacity', ui2.rect(12, b.height - 72, + 104, 24), ui2.TextStyle{ + ...editor_text + valign: .middle + }) + editor_items << ui2.slider(ui2.SliderConfig{ + id: 'theme_overlay_opacity' + frame: ui2.rect(120, b.height - 72, 170, 24) + min: 0 + max: 1 + step: 0.05 + value: p.theme_edit_opacity + padding: 8 + value_track: true + style: ui2.SliderStyle{ + track_color: p.theme.slider_track + value_track_color: p.theme.slider_value + thumb_color: p.theme.slider_value + thumb_size: 14 + } + }) + editor_items << ui2.label('theme_opacity_value', '${int(math.round(p.theme_edit_opacity * 100))}%', + ui2.rect(292, b.height - 72, 44, 24), ui2.TextStyle{ + ...editor_text + valign: .middle + align: .right + }) editor_items << ui2.button('theme_save', 'Save', ui2.rect(12, b.height - 40, 158, 28), ui2.BoxStyle{ bg: p.theme.btn_secondary radius: 6 @@ -353,46 +394,6 @@ fn (mut p Player) view() ui2.Element { size: 11 valign: .middle } - // Max volume dialog: sets the upper bound of the volume slider. - max_volume_body := [ - ui2.label('', 'Max volume (1 to 1000)', ui2.rect(12, 10, 296, 14), queue_header), - ui2.text_input(ui2.TextInputConfig{ - id: 'max_volume_input' - frame: ui2.rect(12, 34, 296, 28) - text: p.max_volume_text - multiline: false - submit_id: 'max_volume_apply' - box: ui2.BoxStyle{ - bg: p.theme.field_bg - radius: 6 - } - text_style: ui2.TextStyle{ - color: p.theme.text_main - } - }) or { ui2.label('', '', ui2.rect(12, 34, 296, 28), queue_body_text) }, - ui2.button('max_volume_apply', 'Apply', ui2.rect(12, 70, 86, 22), dialog_button, dialog_button_text), - ui2.button('max_volume_cancel', 'Cancel', ui2.rect(106, 70, 86, 22), dialog_button, dialog_button_text), - ] - children << ui2.modal_view(ui2.ModalViewConfig{ - id: 'max_volume_dialog' - frame: b - open: p.max_volume_open - dismiss_action_id: 'max_volume_cancel' - overlay_box: ui2.BoxStyle{ - bg: p.theme.overlay_bg - opacity: 0.45 - } - content_width: 320 - content_height: 106 - content_box: ui2.BoxStyle{ - bg: p.theme.bg_dark - opacity: 0.8 - radius: 8 - } - content: ui2.view('', ui2.rect(0, 0, 320, 106), ui2.BoxStyle{ - transparent: true - }, max_volume_body) - }) or { ui2.label('', '', ui2.rect(0, 0, 0, 0), label_text) } // Save-queue dialog: names the current queue, saved under // ~/.config/vendetta/queues/.json. Same panel style; the input is a // black inset on the dark card. @@ -428,7 +429,7 @@ fn (mut p Player) view() ui2.Element { content_height: 106 content_box: ui2.BoxStyle{ bg: p.theme.bg_dark - opacity: 0.8 + opacity: p.theme.overlay_opacity radius: 8 } content: ui2.view('', ui2.rect(0, 0, 320, 106), ui2.BoxStyle{ @@ -471,7 +472,7 @@ fn (mut p Player) view() ui2.Element { content_height: 106 content_box: ui2.BoxStyle{ bg: p.theme.bg_dark - opacity: 0.8 + opacity: p.theme.overlay_opacity radius: 8 } content: ui2.view('', ui2.rect(0, 0, 320, 106), ui2.BoxStyle{ @@ -513,7 +514,7 @@ fn (mut p Player) view() ui2.Element { content_height: 106 content_box: ui2.BoxStyle{ bg: p.theme.bg_dark - opacity: 0.8 + opacity: p.theme.overlay_opacity radius: 8 } content: ui2.view('', ui2.rect(0, 0, 320, 106), ui2.BoxStyle{ @@ -571,7 +572,7 @@ fn (mut p Player) view() ui2.Element { content_height: 158 content_box: ui2.BoxStyle{ bg: p.theme.bg_dark - opacity: 0.8 + opacity: p.theme.overlay_opacity radius: 8 } content: ui2.view('', ui2.rect(0, 0, 320, 158), ui2.BoxStyle{ @@ -615,7 +616,7 @@ fn (mut p Player) view() ui2.Element { content_height: 106 content_box: ui2.BoxStyle{ bg: p.theme.bg_dark - opacity: 0.8 + opacity: p.theme.overlay_opacity radius: 8 } content: ui2.view('', ui2.rect(0, 0, 320, 106), ui2.BoxStyle{ @@ -649,7 +650,7 @@ fn (mut p Player) view() ui2.Element { content_height: 100 content_box: ui2.BoxStyle{ bg: p.theme.bg_dark - opacity: 0.8 + opacity: p.theme.overlay_opacity radius: 8 } content: ui2.view('', ui2.rect(0, 0, 320, 100), ui2.BoxStyle{ @@ -682,12 +683,18 @@ fn (mut p Player) view() ui2.Element { y := bar.seek.y - thumb_h - 24 children << ui2.view('seek_preview_box', ui2.rect(x - 3, y - 3, thumb_w + 6, thumb_h + 24), ui2.BoxStyle{ bg: p.theme.bg_dark - opacity: 0.8 + opacity: p.theme.overlay_opacity radius: 4 }, []) children << ui2.image('seek_preview', p.preview_show_path, ui2.rect(x, y, thumb_w, thumb_h)) children << ui2.label('seek_preview_time', libvendetta.fmt_time(p.preview_show_time), ui2.rect(x, y + thumb_h + 2, thumb_w, 16), preview_text) } + if p.settings_open { + children << p.settings_dialog(b) or { + eprintln('vendetta: settings: ${err}') + ui2.label('', '', ui2.rect(0, 0, 0, 0), label_text) + } + } $if render_stats_probe ? { build_ms := f64(time.sys_mono_now() - build_t0) / 1e6 eprintln('probe view_build ${build_ms:.1f}ms') @@ -716,8 +723,8 @@ fn (p &Player) queue_config() ui2.ReorderConfig { state: p.queue_state // A hair between the tiles, and enough padding that the lifted row's // shadow does not clip at the sidebar's edge. - gap: 2 - padding: 4 + gap: queue_row_gap + padding: queue_list_padding // The scroll offset the reveal computations start from; the on_scroll // handler feeds it back. offset: p.queue_scroll @@ -738,6 +745,17 @@ fn (p &Player) queue_config() ui2.ReorderConfig { } } +// queue_row_w is the width the container gives a row's content: the panel less +// its padding, the grip it draws ahead of the row and, once the rows outgrow the +// panel, its scroller. +fn (p &Player) queue_row_w() f64 { + count := f64(p.queue_keys.len) + length := queue_list_padding * 2 + count * queue_row_h + (count - 1) * queue_row_gap + scroller := if length > p.queue_frame.height + 0.5 { queue_scroller_w } else { 0.0 } + grip := math.round(ui2.component_metrics(.small).height / 2) + return p.queue_frame.width - queue_list_padding * 2 - grip - scroller +} + // queue_row builds one entry the container wraps: the grip it draws ahead of // the row carries the drag, and the row itself holds the name and the remove // button. Only the row's height matters in its frame — the container @@ -766,12 +784,12 @@ fn (p &Player) queue_row(index int, key string) ui2.Element { valign: .middle } } + rm_x := p.queue_row_w() - queue_rm_size - queue_rm_inset row := ui2.view('queue_row_${key}', ui2.rect(0, 0, 0, queue_row_h), ui2.BoxStyle{ - bg: p.theme.bg_surface - radius: 5 + transparent: true }, [ - ui2.label('', display, ui2.rect(6, 0, 280, queue_row_h), text), - ui2.button('queue_rm_${key}', '✕', ui2.rect(290, 3, 18, 18), ui2.BoxStyle{ + ui2.label('', display, ui2.rect(6, 0, rm_x - 10, queue_row_h), text), + ui2.button('queue_rm_${key}', '✕', ui2.rect(rm_x, queue_rm_inset, queue_rm_size, queue_rm_size), ui2.BoxStyle{ bg: p.theme.btn_secondary radius: 4 }, ui2.TextStyle{ -- 2.56.1