me

/

vendetta Public
17 commits 0 issues 0 pull requests 1 contributor Discussions Projects Snippets LOC history Platform CI

add settings menu, new icons, overlay opacity customisation

diviocity committed last Nov 1 · 80f14d8fb92068552b258c65069f3fee405c23bc View patch
Unverified signature 22 files changed +764 -266
AGENTS.md +33 -18

@@ -22,6 +22,7 @@ than deliberate, that is said too.

2222| `src/media.v` | queues, playlists, file dialog, open paths, thumbnail state machine, media worker |

2323| `src/theme.v` | theme struct, TOML themes, live editor, colour pickers |

2424| `src/settings.v` | settings/queue persistence, precedence |

25+| `src/settings_view.v` | the settings dialog (`ui2.settings` in a modal) |

2526| `src/presets.v` | named bundles of mpv options |

2627| `src/surface.v` | the per-frame hook (drains, budget, preview) |

2728| `src/mpris_d_mpris.v` | D-Bus service (only with `-d mpris`) |

@@ -816,7 +817,7 @@ mpv), Android `[auto, audiotrack, null]`.

816817Everything the widget provides plus: track/chapter/device lists, `ao`,

817818delay/aspect/rotate/zoom/deinterlace/hwdec/UI-scale, the mpv-flag mirrors the

818819menus show as toggles, AB loop values, dialogs (`speed_text`,

819-`max_volume`, `url_open`, the mpv-option dialog, the preset/queue/playlist

820+`url_open`, the mpv-option dialog, the preset/queue/playlist

820821name dialogs), fullscreen and per-mode menu-bar and overlay memories

821822(`windowed_overlay=false`, `fullscreen_overlay=true`, `windowed_menu_hidden`,

822823`fullscreen_menu_hidden=true`), the preview state machine fields

@@ -834,14 +835,14 @@ queue_timer, stats_wake), notices, `open_mode` (`ask`/`play`/`queue`),

834835Every window event string goes through `handle(event)` then

835836`settings_changed()`. Routing order (first match wins):

836837

837-1. `vd_*` → the widget's own `handle` (strip controls).

838+1. `vd_*` → the widget's own `handle` (strip controls). While the settings

839+ dialog is open, `handle_settings` is offered the event next.

8388402. `pointer:...` while the queue sidebar is shown → `ui2.reorder_update`

839841 against `queue_config()`; a returned step is applied

840842 (`queue_apply_step`). Other pointer events return.

8418433. `handle_media(event)` — the menu event families of track/chapter/device/

842844 aspect/rotate/playlist (below).

843-4. The dialog events (`playback_speed_custom`, `speed_cancel/apply`,

844- `volume_max_custom`, `max_volume_*`).

845+4. The dialog events (`playback_speed_custom`, `speed_cancel/apply`).

8458465. Prefix families: `playback_speed:`, `queue_rm_<key>`, `theme:`,

846847 `theme_edit:`, `theme_delete:`, `open_mode:`, `ui_scale:`,

847848 `queue_load:`, `queue_delete:`, `playlist_load:`, `playlist_append:`,

@@ -885,7 +886,7 @@ custom speed, mpv option, preset name, URL, queue name, playlist name);

885886Escape closes that dialog and nothing else sees the key. Then

886887`fullscreen && escape` exits fullscreen. The map (mpc-qt-flavoured):

887888

888-`f` fullscreen · `space` pause (10) · `left/right` seek ±5 (18) ·

889+`ctrl+,` settings · `f` fullscreen · `space` pause (10) · `left/right` seek ±5 (18) ·

889890`shift+left/right` ±30 (70/71) · `page_up/page_down` playlist steps ·

890891`,`/`.` frame-back-step/frame-step (72/73) · `up/down` volume ±5 clamped to

891892`max_volume` (12) + `mpris_on_volume` · `m` mute (16) · `v` subtitles ·

@@ -904,25 +905,35 @@ just wakes the worker).

904905

905906`menus()` builds seven bars from live state; every change that alters them

906907rebuilds them via `ui2.set_menu_bar(p.menus())` (property observers,

907-handlers, dialog applies). File, View, Playback, Audio, Video, Subtitles and

908-Options as described in §7.4's tables; the Options bar is the

909-"how the pipeline runs" home: Presets submenu, the raw mpv options configured

910-through the dialog or `--mpv-opt` (skipping the 14 already-mirrored ones —

911-`mirrored_mpv_options`: audio-exclusive, audio-pitch-correction,

908+handlers, dialog applies). The bars hold actions; persistent options live in

909+the settings dialog (below), whose rows reuse the §7.4 events, so those

910+handlers and shortcuts remain without a menu row. Options holds Settings...

911+and the lists a dialog row cannot carry: Presets, the raw mpv options

912+configured through the dialog or `--mpv-opt` (skipping the 14 already-mirrored

913+ones — `mirrored_mpv_options`: audio-exclusive, audio-pitch-correction,

912914blend-subtitles, correct-downscaling, deband, deinterlace, dither, framedrop,

913915hwdec, interpolation, linear-downscaling, sigmoid-upscaling, vd-lavc-fast,

914-video-sync — the menu check rows already cover exactly those), **Wait for

915-vsync timing** (the render-call knob), Sync mode submenu

916-(audio/display-resample/display-vdrop), Interpolation, Picture quality

917-submenu, Frame dropping submenu, Fast video decoding, Deinterlace, Hardware

918-decoding, Exclusive audio output, the media-controls rows (`$if mpris`),

919-Theme submenu.

916+video-sync — the settings rows cover exactly those) and the Theme submenu.

920917

921918The mpv flag toggles deliberately write the **opposite of what mpv reports**

922919and leave the state to the observed properties — nothing writes these

923920options at start (until the user clicks, mpv's own defaults rule); the

924921observer walks each write back once the core takes it.

925922

923+The **settings dialog** (`src/settings_view.v`, Options > Settings...) is a

924+`ui2.settings` view in a `ui2.modal_view`, because ui2 owns one native window.

925+It stores no options: `settings_values` reads the player on every build, and

926+`apply_setting` sends each change through the event its menu row uses (switch

927+keys are the events, dropdown keys their prefixes), so the mpv flag rows keep

928+§14.6's observed truth. The slider and number rows have no event: slider height

929+writes `p.cfg.slider_h`, max volume calls `set_max_volume`, speed sends

930+`playback_speed:`. The Appearance page's Theme editor button closes the dialog

931+and opens the sidebar. Page icons are `assets/icons/page_<page>.png`

932+(`libvendetta.bundled_icon`, resolved on first open, none without a bundle),

933+which needs ui2's page icons to accept a path. The view builds only while open, keys reach

934+`settings_key_event` first, and `over_panel` keeps the wheel and right-click

935+from the player.

936+

926937### 7.7 Notices

927938

928939A 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:

9961007`vo=null`, `ao=null`, `audio=no`, `pause=yes`, `config=no`,

9971008`screenshot-format=jpeg`. Only created when the preview is enabled (`--no-preview`

9981009or the saved setting keeps a whole second mpv core out of low-end machines

999-entirely; View > Hover preview turning it on later builds the instance).

1010+entirely; Settings > Interface turning it on later builds the instance).

10001011

10011012Per-file, `load_thumb_file` opens the playing file once (loadfile replace,

10021013210); 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

11211132change lands in both the row's field and the live theme (`set_theme_color_row`

11221133→ `theme_editor_preview` folds all parseable fields into `p.theme`,

11231134palette, menus, mpv colours — the whole window previews while you drag).

1135+`overlay_opacity` is the one non-colour value: the editor's slider sets it, and

1136+it fills the panels over the video (dialogs, settings, statistics, the seek

1137+preview). The scrims stay 0.45. Files carry it as `[opacity] overlay`, and a

1138+file without it keeps 0.8.

11241139Save writes the current values as a fresh `[colors]` TOML under the edited

11251140name, validates like every other name field, and makes it current.

11261141

@@ -1404,7 +1419,7 @@ All under `<config_base>/vendetta/`:

14041419| `queues/<name>.json` | JSON array of strings | Queue > Save queue... |

14051420| `playlists/<name>.m3u` | m3u (`#EXTM3U` + plain entries) | Playlists > Save playlist... |

14061421| `presets/<name>.json` | JSON `map[string]string` of mpv options | Options > Presets > Save |

1407-| `themes/<name>.toml` | `[colors]` table, hex per key | Theme editor > Save |

1422+| `themes/<name>.toml` | `[colors]` table, hex per key; `[opacity] overlay` | Theme editor > Save |

14081423

14091424Name fields share one rule: non-empty, no `/`, no `\`, no `..`.

14101425

assets/icons/page_advanced.png new file +0 -0
Binary file not shown.
assets/icons/page_appearance.png new file +0 -0
Binary file not shown.
assets/icons/page_audio.png new file +0 -0
Binary file not shown.
assets/icons/page_interface.png new file +0 -0
Binary file not shown.
assets/icons/page_playback.png new file +0 -0
Binary file not shown.
assets/icons/page_subtitles.png new file +0 -0
Binary file not shown.
assets/icons/page_video.png new file +0 -0
Binary file not shown.
scripts/icons/equalizer_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg new file +1 -0

@@ -0,0 +1 @@

1+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" height="24px" width="24px" fill="#e3e3e3"><path d="M4,20V12H8v8H4Zm6,0V4h4V20H10Zm6,0V9h4V20H16Z"/></svg>

scripts/icons/movie_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg new file +1 -0

@@ -0,0 +1 @@

1+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" height="24px" width="24px" fill="#e3e3e3"><path d="M4,4L6,8H9L7,4H9l2,4h3L12,4h2l2,4h3L17,4h3q0.83,0 1.41,0.59Q22,5.18 22,6V18q0,0.82-0.59,1.41T20,20H4q-0.82,0-1.41-0.59T2,18V6Q2,5.18 2.59,4.59T4,4Z"/></svg>

scripts/icons/palette_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg new file +1 -0

@@ -0,0 +1 @@

1+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" height="24px" width="24px" fill="#e3e3e3"><path d="M12,22q-2.05,0-3.88-0.79Q6.3,20.43 4.94,19.06Q3.58,17.7 2.79,15.88T2,12Q2,9.92 2.81,8.1q0.81-1.83 2.2-3.17Q6.4,3.57 8.25,2.79T12.2,2q2,0 3.78,0.69t3.11,1.9t2.13,2.88Q22,9.13 22,11.05q0,2.88-1.75,4.41T16,17H14.15q-0.22,0-0.31,0.13T13.75,17.4q0,0.3 0.38,0.86t0.38,1.29q0,1.25-0.69,1.85T12,22ZM7.58,12.58Q8,12.15 8,11.5T7.58,10.43T6.5,10T5.43,10.43T5,11.5t0.43,1.07T6.5,13t1.08-0.43Zm3-4Q11,8.15 11,7.5T10.58,6.43T9.5,6T8.43,6.43T8,7.5T8.43,8.57T9.5,9t1.08-0.43Zm5,0Q16,8.15 16,7.5T15.58,6.43T14.5,6T13.43,6.43T13,7.5t0.43,1.07T14.5,9t1.08-0.43Zm3,4Q19,12.15 19,11.5t-0.43-1.08T17.5,10t-1.07,0.42T16,11.5t0.43,1.07T17.5,13t1.07-0.43Z"/></svg>

scripts/icons/play_circle_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg new file +1 -0

@@ -0,0 +1 @@

1+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" height="24px" width="24px" fill="#e3e3e3"><path d="M9.5,16.5l7-4.5l-7-4.5v9ZM12,22q-2.07,0-3.9-0.79q-1.82-0.79-3.17-2.14Q3.58,17.73 2.79,15.9T2,12Q2,9.92 2.79,8.1Q3.58,6.27 4.93,4.93Q6.28,3.57 8.1,2.79Q9.93,2 12,2t3.9,0.79t3.17,2.14q1.35,1.35 2.14,3.17Q22,9.92 22,12t-0.79,3.9t-2.14,3.17q-1.35,1.35-3.17,2.14T12,22Z"/></svg>

scripts/icons/settings_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg new file +1 -0

@@ -0,0 +1 @@

1+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" height="24px" width="24px" fill="#e3e3e3"><path d="M9.25,22l-0.4-3.2q-0.32-0.13-0.61-0.3T7.68,18.13L4.7,19.38L1.95,14.63l2.58-1.95Q4.5,12.5 4.5,12.34q0-0.16 0-0.34t0-0.34t0.03-0.34L1.95,9.38L4.7,4.63L7.68,5.88Q7.95,5.68 8.25,5.5t0.6-0.3L9.25,2h5.5l0.4,3.2q0.33,0.13 0.61,0.3t0.56,0.38L19.3,4.63l2.75,4.75l-2.57,1.95q0.02,0.18 0.02,0.34t0,0.34t0,0.34t-0.05,0.34l2.57,1.95l-2.75,4.75l-2.95-1.25q-0.27,0.2-0.57,0.38t-0.6,0.3L14.75,22H9.25Zm2.8-6.5q1.45,0 2.47-1.03T15.55,12T14.53,9.52T12.05,8.5q-1.47,0-2.49,1.02T8.55,12t1.01,2.47t2.49,1.03Z"/></svg>

scripts/icons/subtitles_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg new file +1 -0

@@ -0,0 +1 @@

1+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" height="24px" width="24px" fill="#e3e3e3"><path d="M4,20q-0.82,0-1.41-0.59T2,18V6Q2,5.18 2.59,4.59T4,4H20q0.83,0 1.41,0.59Q22,5.18 22,6V18q0,0.82-0.59,1.41T20,20H4Zm2-4h8V14H6v2Zm10,0h2V14H16v2ZM6,12H8V10H6v2Zm4,0h8V10H10v2Z"/></svg>

scripts/icons/tune_24dp_E3E3E3_FILL1_wght400_GRAD0_opsz24.svg new file +1 -0

@@ -0,0 +1 @@

1+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" height="24px" width="24px" fill="#e3e3e3"><path d="M11,21V15h2v2h8v2H13v2H11ZM3,19V17H9v2H3Zm4-4V13H3V11H7V9H9v6H7Zm4-2V11H21v2H11Zm4-4V3h2V5h4V7H17V9H15ZM3,7V5H13V7H3Z"/></svg>

scripts/make_pngs.sh +10 -2

@@ -12,7 +12,8 @@

1212# vinix-dark palette (text_main, #ffffff, for every strip icon today). The

1313# colour step exists because the exports carry their own #e3e3e3 fill: raster

1414# colorization makes the bundle conform to the palette no matter what colour

15-# the export tool is pointed at.

15+# the export tool is pointed at. The page_ entries are the settings dialog's

16+# navigation, in the palette's text_muted.

1617#

1718# ImageMagick is the rasterizer for now; it renders the 24 px viewBox

1819# straight at 64 px (density 96 * 64/24 = 256), which is what the buttons and

@@ -30,7 +31,14 @@ replay_30 replay30 #ffffff

3031forward_30 forward30 #ffffff

3132volume_up volume_up #ffffff

3233volume_mute volume_mute #ffffff

33-volume_off volume_off #ffffff'

34+volume_off volume_off #ffffff

35+tune page_interface #e2e8f0

36+palette page_appearance #e2e8f0

37+play_circle page_playback #e2e8f0

38+movie page_video #e2e8f0

39+equalizer page_audio #e2e8f0

40+subtitles page_subtitles #e2e8f0

41+settings page_advanced #e2e8f0'

3442

3543if command -v magick >/dev/null 2>&1; then

3644 rasterizer=magick

src/main.v +4 -0

@@ -335,6 +335,10 @@ fn main() {

335335 if (ev.code == .left_alt || ev.code == .right_alt) && !ev.repeat {

336336 player.set_menu_hidden(!player.menu_hidden())

337337 }

338+ if player.settings_open {

339+ player.settings_key_event(ev)

340+ return

341+ }

338342 // The queue sidebar's rows move with Alt and the arrows (or Home /

339343 // End), the same move a drag performs. The key is consumed so the

340344 // plain-key handlers (the arrows seek and step the volume) never see

src/player.v +91 -189

@@ -151,7 +151,7 @@ mut:

151151 zoom f64

152152 deinterlace bool

153153 hwdec bool

154- // The pinned UI scale (View > UI scale). 0 follows the platform, which on

154+ // The pinned UI scale (Settings > Appearance). 0 follows the platform, which on

155155 // Android means the phone-sized default in ui_scale_automatic.

156156 ui_scale f64

157157 // mpv flags the menus show as toggles. They mirror the observed

@@ -177,8 +177,6 @@ mut:

177177 ab_a f64 = -1

178178 ab_b f64 = -1

179179 loop bool

180- max_volume_open bool

181- max_volume_text string

182180 custom_open bool

183181 // The File > Open URL... dialog: what is typed here is a link by

184182 // construction, so it rides the same open path as the picker's files

@@ -232,11 +230,16 @@ mut:

232230 // The theme editor panel: the theme the edits start from, the fields'

233231 // texts, and each colour row's chooser.

234232 theme_editor_open bool

235- theme_edit_base Theme

236- theme_edit_name string

237- theme_edit_texts map[string]string

238- theme_pickers map[string]ThemePicker

239- low_quality bool

233+ // The settings dialog; its values live in the player, see settings_view.v.

234+ settings_open bool

235+ settings_state ui2.SettingsState

236+ settings_icons map[string]string

237+ theme_edit_base Theme

238+ theme_edit_name string

239+ theme_edit_opacity f64

240+ theme_edit_texts map[string]string

241+ theme_pickers map[string]ThemePicker

242+ low_quality bool

240243 // The window title's two halves, each the Options bar's own check row:

241244 // the playback status is the '(paused)' suffix while the file is paused,

242245 // and the playing file's name follows the app name after ' - '.

@@ -813,6 +816,9 @@ fn (mut p Player) handle(event string) {

813816 p.Player.handle(event)

814817 return

815818 }

819+ if p.settings_open && p.handle_settings(event) {

820+ return

821+ }

816822 $if debug_cadence ? {

817823 if event.starts_with('queue_') {

818824 eprintln('CAD queue ${event} len=${p.queue.len} pos=${p.playlist_index}')

@@ -841,32 +847,6 @@ fn (mut p Player) handle(event string) {

841847 p.custom_open = false

842848 return

843849 }

844- 'volume_max_custom' {

845- p.max_volume_text = '${p.max_volume:.0f}'

846- p.max_volume_open = true

847- return

848- }

849- 'max_volume_cancel' {

850- p.max_volume_open = false

851- return

852- }

853- 'max_volume_apply' {

854- v := ui2.text('max_volume_input').trim_space().f64()

855- if v > 0 && v <= 1000 {

856- p.max_volume = v

857- if p.volume > p.max_volume {

858- p.volume = p.max_volume

859- mpv.set_double_async(p.mpv_ctx, 12, 'volume', p.volume)

860- }

861- p.max_volume_open = false

862- p.clear_notices()

863- p.settings_changed()

864- ui2.set_menu_bar(p.menus())

865- } else {

866- p.notify('Max volume must be between 1 and 1000.')

867- }

868- return

869- }

870850 'speed_apply' {

871851 speed := ui2.text('speed_input').trim_space().f64()

872852 if speed >= 0.01 && speed <= 100 {

@@ -934,6 +914,12 @@ fn (mut p Player) handle(event string) {

934914 p.save_theme_from_editor()

935915 return

936916 }

917+ if event == 'theme_overlay_opacity' {

918+ p.theme_edit_opacity = ui2.slider_value(event)

919+ p.theme_editor_preview()

920+ ui2.request_refresh()

921+ return

922+ }

937923 if event == 'theme_name_input' {

938924 p.theme_edit_name = ui2.text(event)

939925 return

@@ -1197,6 +1183,12 @@ fn (mut p Player) handle(event string) {

11971183 p.set_show_stats(!p.show_stats)

11981184 ui2.set_menu_bar(p.menus())

11991185 }

1186+ 'open_settings' {

1187+ p.set_settings_open(true)

1188+ }

1189+ 'settings_close' {

1190+ p.set_settings_open(false)

1191+ }

12001192 'view_preview' {

12011193 p.set_show_preview(!p.show_preview)

12021194 ui2.set_menu_bar(p.menus())

@@ -1314,13 +1306,21 @@ fn (mut p Player) handle_key(key string) {

13141306 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}')

13151307 }

13161308 // While the theme editor is open its fields get the keys, so none of the

1317- // shortcuts apply; Escape closes the editor.

1309+ // shortcuts apply; Escape closes the editor, and so does t when no field

1310+ // would take the letter.

13181311 if p.theme_editor_open {

1319- if key == 'escape' {

1312+ if key == 'escape' || (key == 't' && ui2.focused_id().len == 0) {

13201313 p.handle('view_theme_editor')

13211314 }

13221315 return

13231316 }

1317+ // The settings dialog's fields get the keys the same way.

1318+ if p.settings_open {

1319+ if key == 'escape' {

1320+ p.set_settings_open(false)

1321+ }

1322+ return

1323+ }

13241324 // While the speed dialog is open its text field gets the keys, so none of the

13251325 // shortcuts apply; Escape closes the dialog.

13261326 if p.custom_open {

@@ -1435,6 +1435,9 @@ fn (mut p Player) handle_key(key string) {

14351435 'ctrl+w' {

14361436 p.close_file()

14371437 }

1438+ 'ctrl+,' {

1439+ p.set_settings_open(true)

1440+ }

14381441 'ctrl+=' {

14391442 p.zoom_by(0.25)

14401443 }

@@ -2049,14 +2052,6 @@ fn (p &Player) menus() []ui2.Menu {

20492052 speeds << ui2.menu_check_item('playback_speed:${s}', title, math.abs(p.speed - s) < 0.01)

20502053 }

20512054 speeds << ui2.menu_item('playback_speed_custom', 'Custom...')

2052- speeds << ui2.menu_separator()

2053- speeds << ui2.menu_check_item('audio_pitch_correction', 'Correct audio pitch at speed changes', p.pitch_correction)

2054-

2055- sync_mode_items := [

2056- ui2.menu_check_item('video_sync:audio', 'Audio sync (default)', p.video_sync == 'audio'),

2057- ui2.menu_check_item('video_sync:display-resample', 'Display resample', p.video_sync == 'display-resample'),

2058- ui2.menu_check_item('video_sync:display-vdrop', 'Display resample, drop late frames', p.video_sync == 'display-vdrop'),

2059- ]

20602055

20612056 mut devices := []ui2.MenuItem{}

20622057 for device in p.devices {

@@ -2084,23 +2079,6 @@ fn (p &Player) menus() []ui2.Menu {

20842079 title: 'Delay +0.1 s'

20852080 shortcut: 'h'

20862081 }

2087- mut servers := []ui2.MenuItem{}

2088- for server in audio_server_names() {

2089- title := match server {

2090- 'auto' { 'Auto (mpv chooses)' }

2091- 'pipewire' { 'PipeWire' }

2092- 'pulse' { 'PulseAudio' }

2093- 'alsa' { 'ALSA' }

2094- 'jack' { 'JACK' }

2095- 'sdl' { 'SDL' }

2096- 'wasapi' { 'WASAPI' }

2097- 'avfoundation' { 'AVFoundation' }

2098- 'null' { 'Null (no audio)' }

2099- else { server }

2100- }

2101- servers << ui2.menu_check_item('ao_server:${server}', title, p.ao == server)

2102- }

2103- audio_items << ui2.submenu('Audio server', servers)

21042082 audio_items << ui2.submenu('Output device', devices)

21052083 audio_items << ui2.menu_separator()

21062084 audio_items << ui2.MenuItem{

@@ -2113,8 +2091,6 @@ fn (p &Player) menus() []ui2.Menu {

21132091 title: 'Volume down'

21142092 shortcut: 'down'

21152093 }

2116- audio_items << ui2.menu_separator()

2117- audio_items << ui2.menu_item('volume_max_custom', 'Set max volume...')

21182094

21192095 mut aspects := []ui2.MenuItem{}

21202096 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 {

21782154 ui2.menu_item_with_shortcut('file_open', 'Open...', 'cmd+o'),

21792155 ui2.menu_item_with_shortcut('open_url', 'Open URL...', 'cmd+u'),

21802156 ui2.menu_item_with_shortcut('file_close', 'Close', 'cmd+w'),

2181- ui2.submenu('Default open', [

2182- ui2.menu_check_item('open_mode:ask', 'Ask', p.open_mode == 'ask'),

2183- ui2.menu_check_item('open_mode:play', 'Play now', p.open_mode == 'play'),

2184- ui2.menu_check_item('open_mode:queue', 'Add to queue', p.open_mode == 'queue'),

2185- ]),

21862157 ui2.menu_separator(),

21872158 ui2.MenuItem{

21882159 id: 'screenshot'

@@ -2200,58 +2171,18 @@ fn (p &Player) menus() []ui2.Menu {

22002171 checked: p.fullscreen

22012172 shortcut: 'f'

22022173 },

2203- ui2.MenuItem{

2204- id: 'overlay_mode'

2205- title: 'Overlay mode'

2206- checked: if p.fullscreen {

2207- p.fullscreen_overlay

2208- } else {

2209- p.windowed_overlay

2210- }

2211- shortcut: 'o'

2212- },

22132174 ui2.MenuItem{

22142175 id: 'view_statistics'

22152176 title: 'Statistics'

22162177 checked: p.show_stats

22172178 shortcut: 'i'

22182179 },

2219- ui2.MenuItem{

2220- id: 'view_preview'

2221- title: 'Hover preview'

2222- checked: p.show_preview

2223- },

22242180 ui2.MenuItem{

22252181 id: 'view_queue'

22262182 title: 'Queue'

22272183 checked: p.show_queue

22282184 shortcut: 'q'

22292185 },

2230- ui2.MenuItem{

2231- id: 'view_theme_editor'

2232- title: 'Theme editor'

2233- checked: p.theme_editor_open

2234- shortcut: 't'

2235- },

2236- ui2.submenu('UI scale', [

2237- ui2.menu_check_item('ui_scale:0', 'Automatic', p.ui_scale == 0),

2238- ui2.menu_check_item('ui_scale:1', '1x', p.ui_scale == 1),

2239- ui2.menu_check_item('ui_scale:1.5', '1.5x', p.ui_scale == 1.5),

2240- ui2.menu_check_item('ui_scale:2', '2x', p.ui_scale == 2),

2241- ui2.menu_check_item('ui_scale:2.5', '2.5x', p.ui_scale == 2.5),

2242- ui2.menu_check_item('ui_scale:3', '3x', p.ui_scale == 3),

2243- ]),

2244- ui2.menu_check_item('view_smooth_bar', 'Smooth seek bar', p.smooth_bar),

2245- // Performance mode is the redraw budget's backstop: it takes

2246- // the continuous redraw away until it is turned off, so the

2247- // row greys out while it runs.

2248- ui2.MenuItem{

2249- id: 'view_continuous'

2250- title: 'Continuous redraw'

2251- checked: p.continuous

2252- enabled: !p.low_quality

2253- },

2254- ui2.menu_check_item('view_low_quality', 'Performance mode', p.low_quality),

22552186 ]

22562187 },

22572188 // One bar each for what a player works on, so a dropdown stays under

@@ -2289,36 +2220,38 @@ fn (p &Player) menus() []ui2.Menu {

22892220 checked: p.ab_a >= 0 && p.ab_b >= 0

22902221 shortcut: 'shift+l'

22912222 },

2292- ui2.MenuItem{

2293- id: 'seek_back_30'

2294- title: 'Seek back 30 s'

2295- shortcut: 'shift+left'

2296- }

2297- ui2.MenuItem{

2298- id: 'seek_forward_30'

2299- title: 'Seek forward 30 s'

2300- shortcut: 'shift+right'

2301- },

2302- ui2.MenuItem{

2303- id: 'seek_back_5'

2304- title: 'Seek back 5 s'

2305- shortcut: 'left'

2306- },

2307- ui2.MenuItem{

2308- id: 'seek_forward_5'

2309- title: 'Seek forward 5 s'

2310- shortcut: 'right'

2311- },

2312- ui2.MenuItem{

2313- id: 'frame_back'

2314- title: 'Frame back'

2315- shortcut: ','

2316- }

2317- ui2.MenuItem{

2318- id: 'frame_step'

2319- title: 'Frame forward'

2320- shortcut: '.'

2321- },

2223+ ui2.submenu('Seek', [

2224+ ui2.MenuItem{

2225+ id: 'seek_back_30'

2226+ title: 'Seek back 30 s'

2227+ shortcut: 'shift+left'

2228+ }

2229+ ui2.MenuItem{

2230+ id: 'seek_forward_30'

2231+ title: 'Seek forward 30 s'

2232+ shortcut: 'shift+right'

2233+ },

2234+ ui2.MenuItem{

2235+ id: 'seek_back_5'

2236+ title: 'Seek back 5 s'

2237+ shortcut: 'left'

2238+ },

2239+ ui2.MenuItem{

2240+ id: 'seek_forward_5'

2241+ title: 'Seek forward 5 s'

2242+ shortcut: 'right'

2243+ },

2244+ ui2.MenuItem{

2245+ id: 'frame_back'

2246+ title: 'Frame back'

2247+ shortcut: ','

2248+ }

2249+ ui2.MenuItem{

2250+ id: 'frame_step'

2251+ title: 'Frame forward'

2252+ shortcut: '.'

2253+ },

2254+ ]),

23222255 ui2.menu_separator(),

23232256 ui2.submenu('Speed', speeds),

23242257 ui2.menu_separator(),

@@ -2339,69 +2272,27 @@ fn (p &Player) menus() []ui2.Menu {

23392272 title: 'Subtitles'

23402273 items: sub_items

23412274 },

2342- // Options is the "how the pipeline runs" bar: any raw mpv option plus

2343- // every playback-quality flag vendetta mirrors, instead of scattering

2344- // them across the media-oriented bars.

2275+ // Options leads to the settings dialog, which holds every persistent

2276+ // option; what stays here are the lists a dialog row cannot carry: the

2277+ // presets, the raw mpv options and theme management.

23452278 ui2.Menu{

23462279 title: 'Options'

23472280 items: [

2348- // Presets bundle the whole Options bar under a name, so the

2349- // submenu leads the fine-grained rows.

2281+ ui2.MenuItem{

2282+ id: 'open_settings'

2283+ title: 'Settings...'

2284+ shortcut: 'ctrl+,'

2285+ },

2286+ ui2.menu_separator(),

23502287 ui2.submenu('Presets', p.preset_menu_items()),

23512288 ...p.mpv_menu_items(),

23522289 ui2.menu_separator(),

2353- // Vsync pacing as vendetta's render call sees it: waiting inside

2354- // the render for mpv's target display time is mpv's default

2355- // presentation behaviour, --no-block-target-time switches it

2356- // off, and the menu does the same for this session.

2357- ui2.menu_check_item('render_wait_vsync', 'Wait for vsync timing', p.cfg.block_target_time),

2358- ui2.submenu('Sync mode', sync_mode_items),

2359- ui2.menu_separator(),

2360- ui2.menu_check_item('video_interpolation', 'Interpolation', p.interpolation),

2361- ui2.submenu('Picture quality', [

2362- ui2.menu_check_item('quality_deband', 'Deband', p.deband),

2363- ui2.menu_check_item('quality_dither', 'Dither', p.dither),

2364- ui2.menu_check_item('quality_correct_down', 'Correct downscaling', p.correct_downscaling),

2365- ui2.menu_check_item('quality_linear_down', 'Linear light downscaling', p.linear_downscaling),

2366- ui2.menu_check_item('quality_sigmoid_up', 'Sigmoid upscaling', p.sigmoid_upscaling),

2367- ui2.menu_check_item('quality_blend_subs', 'Blend subtitles into video', p.blend_subtitles),

2368- ]),

2369- ui2.submenu('Frame dropping', [

2370- ui2.menu_check_item('framedrop:no', 'Off', p.framedrop == 'no'),

2371- ui2.menu_check_item('framedrop:vo', 'Display stage', p.framedrop == 'vo'),

2372- ui2.menu_check_item('framedrop:decoder', 'Decoder stage', p.framedrop == 'decoder'),

2373- ui2.menu_check_item('framedrop:decoder+vo', 'Both stages', p.framedrop == 'decoder+vo'),

2374- ]),

2375- ui2.menu_check_item('video_fast_decode', 'Fast video decoding', p.fast_decode),

2376- ui2.menu_check_item('video_deinterlace', 'Deinterlace', p.deinterlace),

2377- ui2.menu_check_item('video_hwdec', 'Hardware decoding', p.hwdec),

2378- ui2.menu_check_item('audio_exclusive', 'Exclusive audio output', p.audio_exclusive),

2379- ui2.menu_separator(),

2380- // The window title's composition, title-local state rather

2381- // than mpv options: '(paused)' and the file name.

2382- ui2.menu_check_item('title_status', 'Show playback status', p.show_playback_status),

2383- ui2.menu_check_item('title_filename', 'Show filename in window title', p.show_title_filename),

2384- ...p.media_controls_menu_items(),

23852290 ui2.submenu('Theme', p.theme_menu_items()),

23862291 ]

23872292 },

23882293 ]

23892294}

23902295

2391-// media_controls_menu_items is the Options row for the desktop media controls.

2392-// Only a -d mpris build offers it, so the default menu has no dead row.

2393-fn (p &Player) media_controls_menu_items() []ui2.MenuItem {

2394- $if mpris ? {

2395- return [

2396- ui2.menu_separator(),

2397- ui2.menu_check_item('media_controls', 'Desktop media controls', p.media_controls),

2398- ui2.menu_separator(),

2399- ]

2400- } $else {

2401- return [ui2.menu_separator()]

2402- }

2403-}

2404-

24052296// theme_menu_items lists the themes as check items, with the one the window

24062297// uses checked, then the editor's load and delete submenus, shaped like the

24072298// queue loader and deleter they follow.

@@ -2441,6 +2332,17 @@ fn (mut p Player) wheel_volume(dy f64) {

24412332 ui2.set_menu_bar(p.menus())

24422333}

24432334

2335+// set_max_volume moves the volume ceiling, pulling the volume under it.

2336+fn (mut p Player) set_max_volume(v f64) {

2337+ p.max_volume = v

2338+ if p.volume > p.max_volume {

2339+ p.volume = p.max_volume

2340+ mpv.set_double_async(p.mpv_ctx, 12, 'volume', p.volume)

2341+ }

2342+ p.settings_changed()

2343+ ui2.set_menu_bar(p.menus())

2344+}

2345+

24442346// mouse_button turns a right-button press over the video into play/pause.

24452347// Left and middle clicks pass through to the controls untouched.

24462348fn (mut p Player) mouse_button(button int, down bool, x f64, y f64) {

src/settings.v +2 -2

@@ -253,7 +253,7 @@ fn (mut p Player) apply_settings(s Settings) {

253253 p.hwdec = s.hwdec

254254 p.deinterlace = s.deinterlace

255255 p.ui_scale = s.ui_scale

256- // The scale pins before the window opens; View > UI scale flips it live.

256+ // The scale pins before the window opens; the settings dialog flips it live.

257257 p.apply_ui_scale()

258258 p.sub_visible = s.sub_visible

259259 p.aspect = s.aspect

@@ -271,7 +271,7 @@ fn (mut p Player) apply_settings(s Settings) {

271271 p.open_mode = s.open_mode

272272 p.low_quality = s.low_quality

273273 // The continuous redraw needs no start-up work either: the window opens

274- // with the saved policy and View > Continuous redraw flips it live.

274+ // with the saved policy and the settings dialog flips it live.

275275 p.continuous = s.continuous

276276 // The smooth bar needs no start-up work: its glide arms itself from the

277277 // first time-pos report, and the chain dies on a pause by itself.

src/settings_view.v new file +534 -0

@@ -0,0 +1,534 @@

1+module main

2+

3+import math

4+import ui2

5+import libvendetta

6+

7+// The settings dialog: ui2 owns one native window, so this is a ui2.settings

8+// view in a modal over the player. It holds no copy of the options. Every build

9+// reads the values from the player, and a change goes through the same event

10+// the menus send, so the mpv flag rows follow the observed properties as they

11+// do in the menus (and walk back if mpv refuses a write).

12+

13+const settings_id = 'app_settings'

14+const settings_w = 760.0

15+const settings_h = 540.0

16+const settings_margin = 24.0

17+

18+// The number rows' width, enough for the speed's two decimals beside its steppers.

19+const settings_number_w = 130.0

20+

21+// The number and slider rows have no menu event to reuse.

22+// The theme editor's row sends the event its key and menu row used.

23+const setting_theme_editor = 'view_theme_editor'

24+const setting_slider_height = 'slider_height'

25+const setting_max_volume = 'max_volume'

26+const setting_speed = 'speed'

27+

28+// The pages with an icon in assets/icons, as page_<name>.png.

29+const settings_icon_pages = ['interface', 'appearance', 'playback', 'video', 'audio', 'subtitles',

30+ 'advanced']

31+

32+// The menu's fixed scale steps; 0 is automatic.

33+const setting_ui_scales = ['0', '1', '1.5', '2', '2.5', '3']

34+

35+// toggle_item is a switch row. Its key is the menu event that flips the option.

36+fn toggle_item(key string, title string) ui2.SettingItem {

37+ return ui2.SettingItem{

38+ key: key

39+ title: title

40+ kind: .switch

41+ }

42+}

43+

44+// settings_scale_value is the option matching the current UI scale, '' for a

45+// scale the steps do not offer.

46+fn (p &Player) settings_scale_value() string {

47+ for scale in setting_ui_scales {

48+ if p.ui_scale == scale.f64() {

49+ return scale

50+ }

51+ }

52+ return ''

53+}

54+

55+// settings_pages lays the options out. Dropdown keys are the prefixes of their

56+// menu events.

57+fn (p &Player) settings_pages() []ui2.SettingPage {

58+ mut themes := []ui2.SettingOption{}

59+ for name in available_themes() {

60+ themes << ui2.SettingOption{

61+ value: name

62+ }

63+ }

64+ mut audio_servers := []ui2.SettingOption{}

65+ for server in audio_server_names() {

66+ audio_servers << ui2.SettingOption{

67+ value: server

68+ }

69+ }

70+ mut interface_items := [

71+ toggle_item('overlay_mode', 'Overlay mode'),

72+ toggle_item('view_smooth_bar', 'Smooth seek bar'),

73+ toggle_item('view_preview', 'Seek bar hover preview'),

74+ toggle_item('title_status', 'Show playback status in the window title'),

75+ toggle_item('title_filename', 'Show filename in the window title'),

76+ ]

77+ $if mpris ? {

78+ interface_items << toggle_item('media_controls', 'Desktop media controls')

79+ }

80+ return [

81+ ui2.SettingPage{

82+ id: 'interface'

83+ title: 'Interface'

84+ icon: p.settings_icons['interface']

85+ resettable: false

86+ groups: [ui2.SettingGroup{

87+ items: interface_items

88+ }]

89+ },

90+ ui2.SettingPage{

91+ id: 'appearance'

92+ title: 'Appearance'

93+ icon: p.settings_icons['appearance']

94+ resettable: false

95+ groups: [

96+ ui2.SettingGroup{

97+ items: [

98+ ui2.SettingItem{

99+ key: 'theme'

100+ title: 'Theme'

101+ kind: .dropdown

102+ options: themes

103+ },

104+ ui2.SettingItem{

105+ key: setting_theme_editor

106+ title: 'Theme editor'

107+ description: 'Opens in a sidebar, so the window previews your colours.'

108+ kind: .button

109+ button_text: 'Open'

110+ },

111+ ui2.SettingItem{

112+ key: 'ui_scale'

113+ title: 'UI scale'

114+ kind: .dropdown

115+ options: [

116+ ui2.SettingOption{

117+ value: '0'

118+ label: 'Automatic'

119+ },

120+ ui2.SettingOption{

121+ value: '1'

122+ label: '1x'

123+ },

124+ ui2.SettingOption{

125+ value: '1.5'

126+ label: '1.5x'

127+ },

128+ ui2.SettingOption{

129+ value: '2'

130+ label: '2x'

131+ },

132+ ui2.SettingOption{

133+ value: '2.5'

134+ label: '2.5x'

135+ },

136+ ui2.SettingOption{

137+ value: '3'

138+ label: '3x'

139+ },

140+ ]

141+ },

142+ ui2.SettingItem{

143+ key: setting_slider_height

144+ title: 'Seek and volume bar height'

145+ kind: .slider

146+ min: 1.0

147+ max: 30.0

148+ unit: ' px'

149+ },

150+ ]

151+ },

152+ ]

153+ },

154+ ui2.SettingPage{

155+ id: 'playback'

156+ title: 'Playback'

157+ icon: p.settings_icons['playback']

158+ resettable: false

159+ groups: [

160+ ui2.SettingGroup{

161+ items: [

162+ ui2.SettingItem{

163+ key: 'open_mode'

164+ title: 'When opening files'

165+ kind: .dropdown

166+ options: [

167+ ui2.SettingOption{

168+ value: 'ask'

169+ label: 'Ask'

170+ },

171+ ui2.SettingOption{

172+ value: 'play'

173+ label: 'Play now'

174+ },

175+ ui2.SettingOption{

176+ value: 'queue'

177+ label: 'Add to queue'

178+ },

179+ ]

180+ },

181+ toggle_item('playback_loop', 'Loop file'),

182+ toggle_item('playback_loop_playlist', 'Loop playlist'),

183+ ui2.SettingItem{

184+ key: setting_max_volume

185+ title: 'Max volume'

186+ kind: .number

187+ min: 1.0

188+ max: 1000.0

189+ precision: 0

190+ field_width: settings_number_w

191+ },

192+ ui2.SettingItem{

193+ key: setting_speed

194+ title: 'Speed'

195+ kind: .number

196+ min: 0.01

197+ max: 100.0

198+ step: 0.25

199+ precision: 2

200+ field_width: settings_number_w

201+ },

202+ ]

203+ },

204+ ]

205+ },

206+ ui2.SettingPage{

207+ id: 'video'

208+ title: 'Video'

209+ icon: p.settings_icons['video']

210+ resettable: false

211+ groups: [

212+ ui2.SettingGroup{

213+ items: [

214+ toggle_item('video_hwdec', 'Hardware decoding'),

215+ toggle_item('video_deinterlace', 'Deinterlace'),

216+ toggle_item('video_fast_decode', 'Fast video decoding'),

217+ toggle_item('video_interpolation', 'Interpolation'),

218+ ]

219+ },

220+ ui2.SettingGroup{

221+ title: 'Picture quality'

222+ items: [

223+ toggle_item('quality_deband', 'Deband'),

224+ toggle_item('quality_dither', 'Dither'),

225+ toggle_item('quality_correct_down', 'Correct downscaling'),

226+ toggle_item('quality_linear_down', 'Linear light downscaling'),

227+ toggle_item('quality_sigmoid_up', 'Sigmoid upscaling'),

228+ ]

229+ },

230+ ]

231+ },

232+ ui2.SettingPage{

233+ id: 'audio'

234+ title: 'Audio'

235+ icon: p.settings_icons['audio']

236+ resettable: false

237+ groups: [

238+ ui2.SettingGroup{

239+ items: [

240+ ui2.SettingItem{

241+ key: 'ao_server'

242+ title: 'Audio server'

243+ kind: .dropdown

244+ options: audio_servers

245+ },

246+ toggle_item('audio_exclusive', 'Exclusive audio output'),

247+ toggle_item('audio_pitch_correction', 'Correct audio pitch at speed changes'),

248+ ]

249+ },

250+ ]

251+ },

252+ ui2.SettingPage{

253+ id: 'subtitles'

254+ title: 'Subtitles'

255+ icon: p.settings_icons['subtitles']

256+ resettable: false

257+ groups: [

258+ ui2.SettingGroup{

259+ items: [

260+ toggle_item('subs_visible', 'Show subtitles'),

261+ toggle_item('quality_blend_subs', 'Blend subtitles into video'),

262+ ]

263+ },

264+ ]

265+ },

266+ ui2.SettingPage{

267+ id: 'advanced'

268+ title: 'Advanced'

269+ icon: p.settings_icons['advanced']

270+ resettable: false

271+ groups: [

272+ ui2.SettingGroup{

273+ items: [

274+ ui2.SettingItem{

275+ // Performance mode takes the continuous redraw away.

276+ ...toggle_item('view_continuous', 'Continuous redraw')

277+ disabled: p.low_quality

278+ },

279+ toggle_item('view_low_quality', 'Performance mode'),

280+ toggle_item('render_wait_vsync', 'Wait for vsync timing'),

281+ ui2.SettingItem{

282+ key: 'video_sync'

283+ title: 'Sync mode'

284+ kind: .dropdown

285+ options: [

286+ ui2.SettingOption{

287+ value: 'audio'

288+ label: 'Audio sync (default)'

289+ },

290+ ui2.SettingOption{

291+ value: 'display-resample'

292+ label: 'Display resample'

293+ },

294+ ui2.SettingOption{

295+ value: 'display-vdrop'

296+ label: 'Display resample, drop late frames'

297+ },

298+ ]

299+ },

300+ ui2.SettingItem{

301+ key: 'framedrop'

302+ title: 'Frame dropping'

303+ kind: .dropdown

304+ options: [

305+ ui2.SettingOption{

306+ value: 'no'

307+ label: 'Off'

308+ },

309+ ui2.SettingOption{

310+ value: 'vo'

311+ label: 'Display stage'

312+ },

313+ ui2.SettingOption{

314+ value: 'decoder'

315+ label: 'Decoder stage'

316+ },

317+ ui2.SettingOption{

318+ value: 'decoder+vo'

319+ label: 'Both stages'

320+ },

321+ ]

322+ },

323+ ]

324+ },

325+ ]

326+ },

327+ ]

328+}

329+

330+// settings_values reads every row's value from the player.

331+fn (p &Player) settings_values() map[string]ui2.SettingValue {

332+ mut values := map[string]ui2.SettingValue{}

333+ toggles := {

334+ 'overlay_mode': if p.fullscreen {

335+ p.fullscreen_overlay

336+ } else {

337+ p.windowed_overlay

338+ }

339+ 'view_smooth_bar': p.smooth_bar

340+ 'title_status': p.show_playback_status

341+ 'title_filename': p.show_title_filename

342+ 'subs_visible': p.sub_visible

343+ 'view_preview': p.show_preview

344+ 'media_controls': p.media_controls

345+ 'playback_loop': p.loop

346+ 'playback_loop_playlist': p.loop_playlist

347+ 'video_hwdec': p.hwdec

348+ 'video_deinterlace': p.deinterlace

349+ 'video_fast_decode': p.fast_decode

350+ 'video_interpolation': p.interpolation

351+ 'quality_deband': p.deband

352+ 'quality_dither': p.dither

353+ 'quality_correct_down': p.correct_downscaling

354+ 'quality_linear_down': p.linear_downscaling

355+ 'quality_sigmoid_up': p.sigmoid_upscaling

356+ 'quality_blend_subs': p.blend_subtitles

357+ 'audio_exclusive': p.audio_exclusive

358+ 'audio_pitch_correction': p.pitch_correction

359+ 'view_continuous': p.continuous

360+ 'view_low_quality': p.low_quality

361+ 'render_wait_vsync': p.cfg.block_target_time

362+ }

363+ for key, on in toggles {

364+ values[key] = ui2.SettingValue(on)

365+ }

366+ values['open_mode'] = ui2.SettingValue(p.open_mode)

367+ values['theme'] = ui2.SettingValue(p.theme_name)

368+ values['video_sync'] = ui2.SettingValue(p.video_sync)

369+ values['framedrop'] = ui2.SettingValue(p.framedrop)

370+ values['ao_server'] = ui2.SettingValue(p.ao)

371+ values['ui_scale'] = ui2.SettingValue(p.settings_scale_value())

372+ values[setting_slider_height] = ui2.SettingValue(p.cfg.slider_h)

373+ values[setting_max_volume] = ui2.SettingValue(p.max_volume)

374+ values[setting_speed] = ui2.SettingValue(p.speed)

375+ return values

376+}

377+

378+// settings_theme maps the app theme onto ui2's component colours, so the dialog

379+// follows theme changes and the live editor.

380+fn (p &Player) settings_theme() ui2.ComponentTheme {

381+ return ui2.ComponentTheme{

382+ ...ui2.component_theme(true)

383+ background: p.theme.bg_dark

384+ foreground: p.theme.text_main

385+ // Buttons fill with muted and dropdowns with background: one colour for both.

386+ muted: p.theme.bg_dark

387+ muted_foreground: p.theme.text_muted

388+ border: p.theme.menu_border

389+ primary: p.theme.btn_primary

390+ primary_foreground: p.theme.text_main

391+ }

392+}

393+

394+// settings_frame is the dialog's size in a window of the given bounds.

395+fn settings_frame(b ui2.Rect) ui2.Rect {

396+ return ui2.rect(0, 0, math.max(math.min(settings_w, b.width - settings_margin * 2), 0.0),

397+ math.max(math.min(settings_h, b.height - settings_margin * 2), 0.0))

398+}

399+

400+fn (p &Player) settings_config() ui2.SettingsConfig {

401+ return ui2.SettingsConfig{

402+ id: settings_id

403+ frame: settings_frame(ui2.bounds())

404+ pages: p.settings_pages()

405+ values: p.settings_values()

406+ state: p.settings_state

407+ group_variant: .outline

408+ nav_width: 200

409+ // The smallest ui2 offers, the nearest to the app's own 11 to 13 pt text.

410+ size: .small

411+ transparent: true

412+ theme: p.settings_theme()

413+ }

414+}

415+

416+// apply_setting hands one changed row to the handler its menu row uses.

417+fn (mut p Player) apply_setting(change ui2.SettingChange) {

418+ value := change.value

419+ match value {

420+ bool {

421+ p.handle(change.key)

422+ }

423+ string {

424+ p.handle('${change.key}:${value}')

425+ }

426+ f64 {

427+ match change.key {

428+ setting_slider_height {

429+ p.cfg.slider_h = value

430+ }

431+ setting_max_volume {

432+ p.set_max_volume(value)

433+ }

434+ setting_speed {

435+ p.handle('playback_speed:${value}')

436+ }

437+ else {}

438+ }

439+ }

440+ }

441+}

442+

443+// take_settings_step stores what the dialog decoded, then rebuilds and does

444+// what has to wait for the new tree.

445+fn (mut p Player) take_settings_step(step ui2.SettingsStep) {

446+ p.settings_state = step.state

447+ for change in step.changes {

448+ p.apply_setting(change)

449+ }

450+ // The editor is a sidebar, which the dialog's scrim would cover.

451+ if step.action == setting_theme_editor {

452+ p.set_settings_open(false)

453+ if !p.theme_editor_open {

454+ p.handle(setting_theme_editor)

455+ }

456+ return

457+ }

458+ p.settings_changed()

459+ ui2.refresh()

460+ if step.sync_id.len > 0 && ui2.text(step.sync_id) != step.sync_text {

461+ ui2.set_text(step.sync_id, step.sync_text)

462+ }

463+ if step.focus.len > 0 {

464+ ui2.focus(step.focus)

465+ }

466+ if step.scroll {

467+ ui2.scroll_to_offset(step.scroll_id, step.scroll_to)

468+ }

469+}

470+

471+// handle_settings offers a window event to the open dialog and reports whether

472+// it took it.

473+fn (mut p Player) handle_settings(event string) bool {

474+ step := ui2.settings_update(p.settings_config(), event, ui2.SettingsInput{

475+ text: ui2.text

476+ number: ui2.slider_value

477+ }) or { return false }

478+ p.take_settings_step(step)

479+ return true

480+}

481+

482+// settings_key_event offers a key to the open dialog: Ctrl+F goes to the search

483+// field, and what the dialog does not use falls to handle_key's guard.

484+fn (mut p Player) settings_key_event(event ui2.KeyEvent) {

485+ if event.ctrl && event.code == .f && !event.alt && !event.shift {

486+ ui2.consume_key()

487+ ui2.focus(ui2.settings_search_field_id(settings_id))

488+ return

489+ }

490+ step := ui2.settings_key(p.settings_config(), ui2.focused_id(), event) or { return }

491+ ui2.consume_key()

492+ p.take_settings_step(step)

493+}

494+

495+// set_settings_open shows or hides the dialog. The selected page survives a

496+// close; the search does not. The page icons resolve on the first open.

497+fn (mut p Player) set_settings_open(open bool) {

498+ if open && p.settings_icons.len == 0 {

499+ for page in settings_icon_pages {

500+ p.settings_icons[page] = libvendetta.bundled_icon('page_${page}')

501+ }

502+ }

503+ p.settings_open = open

504+ p.settings_state = ui2.SettingsState{

505+ ...p.settings_state

506+ query: ''

507+ menu: ''

508+ }

509+ ui2.request_refresh()

510+}

511+

512+// settings_dialog is the modal around the view. The view only builds while the

513+// dialog is open, so it costs playback's rebuilds nothing.

514+fn (p &Player) settings_dialog(b ui2.Rect) !ui2.Element {

515+ frame := settings_frame(b)

516+ return ui2.modal_view(ui2.ModalViewConfig{

517+ id: 'settings_dialog'

518+ frame: b

519+ open: true

520+ dismiss_action_id: 'settings_close'

521+ overlay_box: ui2.BoxStyle{

522+ bg: p.theme.overlay_bg

523+ opacity: 0.45

524+ }

525+ content_width: frame.width

526+ content_height: frame.height

527+ content_box: ui2.BoxStyle{

528+ bg: p.theme.bg_dark

529+ opacity: p.theme.overlay_opacity

530+ radius: 8

531+ }

532+ content: ui2.settings(p.settings_config())!

533+ })

534+}

src/theme.v +10 -0

@@ -1,4 +1,5 @@

11import os

2+import math

23import toml

34import strconv

45import ui2

@@ -96,6 +97,9 @@ mut:

9697 osd_border u32

9798 sub_text u32

9899 sub_border u32

100+ // How much of the video the panels floating over it hide, 0 to 1: dialogs,

101+ // settings, the statistics popup and the seek preview.

102+ overlay_opacity f64 = 0.8

99103}

100104

101105// default_theme is the theme that is compiled into vendetta.

@@ -177,6 +181,9 @@ fn load_theme(name string) Theme {

177181 eprintln('vendetta: theme ${name}: ${err}')

178182 return theme

179183 }

184+ if opacity := doc.value_opt('opacity.overlay') {

185+ theme.overlay_opacity = math.clamp(opacity.f64(), 0.0, 1.0)

186+ }

180187 colors := doc.value_opt('colors') or {

181188 eprintln('vendetta: theme ${name} has no [colors] table')

182189 return theme

@@ -435,6 +442,7 @@ fn (mut p Player) open_theme_editor(name string) {

435442 base := if name.len > 0 { load_theme(name) } else { default_theme() }

436443 p.theme_edit_base = base

437444 p.theme_edit_name = name

445+ p.theme_edit_opacity = base.overlay_opacity

438446 p.theme_edit_texts = map[string]string{}

439447 for key in color_keys {

440448 p.theme_edit_texts[key] = hex_text(theme_color_of(base, key))

@@ -545,6 +553,7 @@ fn (mut p Player) theme_editor_preview() {

545553 theme.set_color(key, c)

546554 }

547555 }

556+ theme.overlay_opacity = p.theme_edit_opacity

548557 p.theme = theme

549558 p.palette = palette_of(theme)

550559 // The bar and its panels draw from ui2's globals every frame.

@@ -566,6 +575,7 @@ fn (mut p Player) save_theme_from_editor() {

566575 for key in color_keys {

567576 text += '${key} = 0x${theme_color_of(p.theme, key):06x}\n'

568577 }

578+ text += '\n[opacity]\noverlay = ${p.theme.overlay_opacity:.2f}\n'

569579 os.mkdir_all(theme_dir(), os.MkdirParams{}) or {}

570580 os.write_file(os.join_path(theme_dir(), '${clean}.toml'), text) or {

571581 p.notify('Could not save the theme: ${err}')

src/view.v +73 -55

@@ -18,6 +18,15 @@ const queue_list_id = 'queue_list'

1818// queue_row_h is one queue row's height inside the reorder container.

1919const queue_row_h = 24.0

2020

21+// The reorder container's spacing, which the rows' width follows.

22+const queue_row_gap = 2.0

23+const queue_list_padding = 4.0

24+// The remove button's side, inset equally from the row's top and right edges.

25+const queue_rm_size = 18.0

26+const queue_rm_inset = 3.0

27+// ui2 keeps rows this far clear of its scroller.

28+const queue_scroller_w = 6.0

29+

2130// stats_body turns the observed playback statistics into the popup's text.

2231// A value of 0 means mpv reports nothing (no file, or the property is not

2332// tracked), which is shown as a dash.

@@ -89,6 +98,9 @@ fn (p &Player) stats_popup_rect() ui2.Rect {

8998// there.

9099fn (p &Player) over_panel(x f64, y f64) bool {

91100 b := ui2.bounds()

101+ if p.settings_open {

102+ return true

103+ }

92104 if p.theme_editor_open && x < theme_editor_w {

93105 return true

94106 }

@@ -149,7 +161,7 @@ fn (mut p Player) view() ui2.Element {

149161 }

150162 children << ui2.view('stats_popup', p.stats_popup_rect(), ui2.BoxStyle{

151163 bg: p.theme.bg_dark

152- opacity: 0.8

164+ opacity: p.theme.overlay_opacity

153165 radius: 8

154166 }, stat_items)

155167 }

@@ -261,11 +273,40 @@ fn (mut p Player) view() ui2.Element {

261273 }

262274 editor_items << ui2.scrollable(ui2.ScrollableConfig{

263275 id: 'theme_rows'

264- frame: ui2.rect(0, 92, 348, b.height - 140)

276+ frame: ui2.rect(0, 92, 348, b.height - 172)

265277 stack: .column

266278 children: rows

267279 background: p.theme.bg_dark

268280 }) or { ui2.label('', '', ui2.rect(0, 0, 0, 0), editor_text) }

281+ // The panels' opacity sits under the pane: the colour pickers place

282+ // themselves from the rows' fixed top.

283+ editor_items << ui2.label('theme_opacity_label', 'Overlay opacity', ui2.rect(12, b.height - 72,

284+ 104, 24), ui2.TextStyle{

285+ ...editor_text

286+ valign: .middle

287+ })

288+ editor_items << ui2.slider(ui2.SliderConfig{

289+ id: 'theme_overlay_opacity'

290+ frame: ui2.rect(120, b.height - 72, 170, 24)

291+ min: 0

292+ max: 1

293+ step: 0.05

294+ value: p.theme_edit_opacity

295+ padding: 8

296+ value_track: true

297+ style: ui2.SliderStyle{

298+ track_color: p.theme.slider_track

299+ value_track_color: p.theme.slider_value

300+ thumb_color: p.theme.slider_value

301+ thumb_size: 14

302+ }

303+ })

304+ editor_items << ui2.label('theme_opacity_value', '${int(math.round(p.theme_edit_opacity * 100))}%',

305+ ui2.rect(292, b.height - 72, 44, 24), ui2.TextStyle{

306+ ...editor_text

307+ valign: .middle

308+ align: .right

309+ })

269310 editor_items << ui2.button('theme_save', 'Save', ui2.rect(12, b.height - 40, 158, 28), ui2.BoxStyle{

270311 bg: p.theme.btn_secondary

271312 radius: 6

@@ -353,46 +394,6 @@ fn (mut p Player) view() ui2.Element {

353394 size: 11

354395 valign: .middle

355396 }

356- // Max volume dialog: sets the upper bound of the volume slider.

357- max_volume_body := [

358- ui2.label('', 'Max volume (1 to 1000)', ui2.rect(12, 10, 296, 14), queue_header),

359- ui2.text_input(ui2.TextInputConfig{

360- id: 'max_volume_input'

361- frame: ui2.rect(12, 34, 296, 28)

362- text: p.max_volume_text

363- multiline: false

364- submit_id: 'max_volume_apply'

365- box: ui2.BoxStyle{

366- bg: p.theme.field_bg

367- radius: 6

368- }

369- text_style: ui2.TextStyle{

370- color: p.theme.text_main

371- }

372- }) or { ui2.label('', '', ui2.rect(12, 34, 296, 28), queue_body_text) },

373- ui2.button('max_volume_apply', 'Apply', ui2.rect(12, 70, 86, 22), dialog_button, dialog_button_text),

374- ui2.button('max_volume_cancel', 'Cancel', ui2.rect(106, 70, 86, 22), dialog_button, dialog_button_text),

375- ]

376- children << ui2.modal_view(ui2.ModalViewConfig{

377- id: 'max_volume_dialog'

378- frame: b

379- open: p.max_volume_open

380- dismiss_action_id: 'max_volume_cancel'

381- overlay_box: ui2.BoxStyle{

382- bg: p.theme.overlay_bg

383- opacity: 0.45

384- }

385- content_width: 320

386- content_height: 106

387- content_box: ui2.BoxStyle{

388- bg: p.theme.bg_dark

389- opacity: 0.8

390- radius: 8

391- }

392- content: ui2.view('', ui2.rect(0, 0, 320, 106), ui2.BoxStyle{

393- transparent: true

394- }, max_volume_body)

395- }) or { ui2.label('', '', ui2.rect(0, 0, 0, 0), label_text) }

396397 // Save-queue dialog: names the current queue, saved under

397398 // ~/.config/vendetta/queues/<name>.json. Same panel style; the input is a

398399 // black inset on the dark card.

@@ -428,7 +429,7 @@ fn (mut p Player) view() ui2.Element {

428429 content_height: 106

429430 content_box: ui2.BoxStyle{

430431 bg: p.theme.bg_dark

431- opacity: 0.8

432+ opacity: p.theme.overlay_opacity

432433 radius: 8

433434 }

434435 content: ui2.view('', ui2.rect(0, 0, 320, 106), ui2.BoxStyle{

@@ -471,7 +472,7 @@ fn (mut p Player) view() ui2.Element {

471472 content_height: 106

472473 content_box: ui2.BoxStyle{

473474 bg: p.theme.bg_dark

474- opacity: 0.8

475+ opacity: p.theme.overlay_opacity

475476 radius: 8

476477 }

477478 content: ui2.view('', ui2.rect(0, 0, 320, 106), ui2.BoxStyle{

@@ -513,7 +514,7 @@ fn (mut p Player) view() ui2.Element {

513514 content_height: 106

514515 content_box: ui2.BoxStyle{

515516 bg: p.theme.bg_dark

516- opacity: 0.8

517+ opacity: p.theme.overlay_opacity

517518 radius: 8

518519 }

519520 content: ui2.view('', ui2.rect(0, 0, 320, 106), ui2.BoxStyle{

@@ -571,7 +572,7 @@ fn (mut p Player) view() ui2.Element {

571572 content_height: 158

572573 content_box: ui2.BoxStyle{

573574 bg: p.theme.bg_dark

574- opacity: 0.8

575+ opacity: p.theme.overlay_opacity

575576 radius: 8

576577 }

577578 content: ui2.view('', ui2.rect(0, 0, 320, 158), ui2.BoxStyle{

@@ -615,7 +616,7 @@ fn (mut p Player) view() ui2.Element {

615616 content_height: 106

616617 content_box: ui2.BoxStyle{

617618 bg: p.theme.bg_dark

618- opacity: 0.8

619+ opacity: p.theme.overlay_opacity

619620 radius: 8

620621 }

621622 content: ui2.view('', ui2.rect(0, 0, 320, 106), ui2.BoxStyle{

@@ -649,7 +650,7 @@ fn (mut p Player) view() ui2.Element {

649650 content_height: 100

650651 content_box: ui2.BoxStyle{

651652 bg: p.theme.bg_dark

652- opacity: 0.8

653+ opacity: p.theme.overlay_opacity

653654 radius: 8

654655 }

655656 content: ui2.view('', ui2.rect(0, 0, 320, 100), ui2.BoxStyle{

@@ -682,12 +683,18 @@ fn (mut p Player) view() ui2.Element {

682683 y := bar.seek.y - thumb_h - 24

683684 children << ui2.view('seek_preview_box', ui2.rect(x - 3, y - 3, thumb_w + 6, thumb_h + 24), ui2.BoxStyle{

684685 bg: p.theme.bg_dark

685- opacity: 0.8

686+ opacity: p.theme.overlay_opacity

686687 radius: 4

687688 }, [])

688689 children << ui2.image('seek_preview', p.preview_show_path, ui2.rect(x, y, thumb_w, thumb_h))

689690 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)

690691 }

692+ if p.settings_open {

693+ children << p.settings_dialog(b) or {

694+ eprintln('vendetta: settings: ${err}')

695+ ui2.label('', '', ui2.rect(0, 0, 0, 0), label_text)

696+ }

697+ }

691698 $if render_stats_probe ? {

692699 build_ms := f64(time.sys_mono_now() - build_t0) / 1e6

693700 eprintln('probe view_build ${build_ms:.1f}ms')

@@ -716,8 +723,8 @@ fn (p &Player) queue_config() ui2.ReorderConfig {

716723 state: p.queue_state

717724 // A hair between the tiles, and enough padding that the lifted row's

718725 // shadow does not clip at the sidebar's edge.

719- gap: 2

720- padding: 4

726+ gap: queue_row_gap

727+ padding: queue_list_padding

721728 // The scroll offset the reveal computations start from; the on_scroll

722729 // handler feeds it back.

723730 offset: p.queue_scroll

@@ -738,6 +745,17 @@ fn (p &Player) queue_config() ui2.ReorderConfig {

738745 }

739746}

740747

748+// queue_row_w is the width the container gives a row's content: the panel less

749+// its padding, the grip it draws ahead of the row and, once the rows outgrow the

750+// panel, its scroller.

751+fn (p &Player) queue_row_w() f64 {

752+ count := f64(p.queue_keys.len)

753+ length := queue_list_padding * 2 + count * queue_row_h + (count - 1) * queue_row_gap

754+ scroller := if length > p.queue_frame.height + 0.5 { queue_scroller_w } else { 0.0 }

755+ grip := math.round(ui2.component_metrics(.small).height / 2)

756+ return p.queue_frame.width - queue_list_padding * 2 - grip - scroller

757+}

758+

741759// queue_row builds one entry the container wraps: the grip it draws ahead of

742760// the row carries the drag, and the row itself holds the name and the remove

743761// 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 {

766784 valign: .middle

767785 }

768786 }

787+ rm_x := p.queue_row_w() - queue_rm_size - queue_rm_inset

769788 row := ui2.view('queue_row_${key}', ui2.rect(0, 0, 0, queue_row_h), ui2.BoxStyle{

770- bg: p.theme.bg_surface

771- radius: 5

789+ transparent: true

772790 }, [

773- ui2.label('', display, ui2.rect(6, 0, 280, queue_row_h), text),

774- ui2.button('queue_rm_${key}', '✕', ui2.rect(290, 3, 18, 18), ui2.BoxStyle{

791+ ui2.label('', display, ui2.rect(6, 0, rm_x - 10, queue_row_h), text),

792+ ui2.button('queue_rm_${key}', '✕', ui2.rect(rm_x, queue_rm_inset, queue_rm_size, queue_rm_size), ui2.BoxStyle{

775793 bg: p.theme.btn_secondary

776794 radius: 4

777795 }, ui2.TextStyle{