From 7e6522537fe1056f8c1c4e91d4832122e7f8f2e9 Mon Sep 17 00:00:00 2001 From: diviocity Date: Sun, 1 Nov 2026 00:00:21 +0100 Subject: [PATCH] added options to the window's title and X11 atoms --- src/main.v | 5 +++- src/player.v | 55 +++++++++++++++++++++++++++++++++++++ src/settings.v | 74 ++++++++++++++++++++++++++++---------------------- src/surface.v | 6 ++++ 4 files changed, 107 insertions(+), 33 deletions(-) diff --git a/src/main.v b/src/main.v index 78f6900..0e959e4 100644 --- a/src/main.v +++ b/src/main.v @@ -272,9 +272,12 @@ fn main() { mpv.observe_property(player.mpv_ctx, obs_mpris_volume, 'volume', mpv.format_double) mpv.observe_property(player.mpv_ctx, obs_mpris_loop, 'loop-file', mpv.format_string) mpv.observe_property(player.mpv_ctx, obs_mpris_loop_playlist, 'loop-playlist', mpv.format_string) - mpv.observe_property(player.mpv_ctx, obs_media_title, 'media-title', mpv.format_string) mpv.observe_property(player.mpv_ctx, obs_media_artist, 'metadata/by-key/artist', mpv.format_string) } + // The window title carries the playing file's name, so media-title is + // observed in every build (the mpris build's xesam:title reads the same + // mirror that update_window_title consumes). + mpv.observe_property(player.mpv_ctx, obs_media_title, 'media-title', mpv.format_string) // Playback statistics for the popup; each reports its own property change. mpv.observe_property(player.mpv_ctx, obs_fps, 'fps', mpv.format_double) mpv.observe_property(player.mpv_ctx, obs_vf_fps, 'estimated-vf-fps', mpv.format_double) diff --git a/src/player.v b/src/player.v index 07e97f1..b517f6a 100644 --- a/src/player.v +++ b/src/player.v @@ -237,6 +237,14 @@ mut: 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 ' - '. + show_playback_status bool = true + show_title_filename bool = true + // The WM_CLASS write ran: sokol's X11 display exists only after its loop + // opens the window, and the write is once-per-session work. + window_class_set bool // The window's redraw policy: with it on, ui2 repaints the retained tree // every vsync and rebuilds on ask, so the seek bar glides and hovers // answer within a frame. It is the View menu's Continuous redraw row, and @@ -337,6 +345,32 @@ mut: playlist_index int } +// update_window_title mirrors what mpv plays into the window title, in the +// form 'Vendetta (paused) - filename': the pause suffix appears under the +// Options bar's Show playback status row while playback is paused, and the +// name is the file's own name for a local file or mpv's media-title for a +// stream, shown under the Show filename row. With both rows off the title +// stays plain 'Vendetta'. The media-title and pause property events run it, +// so a file change and a pause flip repaint the title out of the mirrors the +// observers already hold; neither call needs its own mpv read. +fn (mut p Player) update_window_title() { + name := if !p.has_file { + '' + } else if p.current_kind == .file && p.current_path.len > 0 { + os.file_name(p.current_path) + } else { + p.media_title + } + mut title := 'Vendetta' + if p.show_playback_status && p.paused { + title += ' (paused)' + } + if p.show_title_filename && name.len > 0 { + title += ' - ' + name + } + apply_window_title(title) +} + // on_mpv_event follows the events the menus and lists show. The widget has // already taken the playback state from each one. fn (mut p Player) on_mpv_event(ev voidptr) { @@ -411,6 +445,7 @@ fn (mut p Player) apply_app_property(ev voidptr) { } p.paused = v p.mpris_push() + p.update_window_title() ui2.set_menu_bar(p.menus()) } } @@ -560,6 +595,7 @@ fn (mut p Player) apply_app_property(ev voidptr) { if v := mpv.property_string(ev) { p.media_title = v p.mpris_push() + p.update_window_title() } } 'metadata/by-key/artist' { @@ -1169,6 +1205,16 @@ fn (mut p Player) handle(event string) { p.smooth_bar = !p.smooth_bar ui2.set_menu_bar(p.menus()) } + 'title_status' { + p.show_playback_status = !p.show_playback_status + p.update_window_title() + ui2.set_menu_bar(p.menus()) + } + 'title_filename' { + p.show_title_filename = !p.show_title_filename + p.update_window_title() + ui2.set_menu_bar(p.menus()) + } 'view_continuous' { p.set_continuous(!p.continuous) ui2.set_menu_bar(p.menus()) @@ -1593,6 +1639,10 @@ fn (mut p Player) close_file() { p.pos = 0 p.clear_next = true p.drop_shown_thumb() + // The stop clears mpv's mirrors asynchronously; the title has nothing to + // wait on here, regardless of whether media-title's own event lands. + p.media_title = '' + p.update_window_title() } fn (p &Player) has_track(kind string) bool { @@ -2326,6 +2376,11 @@ fn (p &Player) menus() []ui2.Menu { 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()), ] diff --git a/src/settings.v b/src/settings.v index 75c0fd5..15768f0 100644 --- a/src/settings.v +++ b/src/settings.v @@ -44,11 +44,15 @@ pub mut: // The smooth seek bar: the player carries the bar forward at playback speed // between mpv's position reports and redraws the window at the display rate // while it plays. - smooth_bar bool - theme string = default_theme_name - preset string - media_controls bool - mpv_opts map[string]string + smooth_bar bool + // The window title's two halves, shown while set (both default on): + // '(paused)' while playback is paused, then the playing file's name. + show_playback_status bool = true + show_title_filename bool = true + theme string = default_theme_name + preset string + media_controls bool + mpv_opts map[string]string } // config_base is the directory vendetta's state lives under — the tree whose @@ -152,33 +156,35 @@ fn (p &Player) save_queue_state() { // collect_settings snapshots the persisted state out of the player. fn (p &Player) collect_settings() Settings { return Settings{ - volume: p.volume - max_volume: p.max_volume - muted: p.muted - speed: p.speed - ao: p.ao - loop_file: p.loop - loop_playlist: p.loop_playlist - hwdec: p.hwdec - deinterlace: p.deinterlace - ui_scale: p.ui_scale - sub_visible: p.sub_visible - aspect: p.aspect - rotate: p.rotate - zoom: p.zoom - windowed_overlay: p.windowed_overlay - fullscreen_overlay: p.fullscreen_overlay - show_stats: p.show_stats - show_queue: p.show_queue - show_preview: p.show_preview - open_mode: p.open_mode - low_quality: p.low_quality - continuous: p.continuous - smooth_bar: p.smooth_bar - theme: p.theme_name - preset: p.preset_name - media_controls: p.media_controls - mpv_opts: p.mpv_opts + volume: p.volume + max_volume: p.max_volume + muted: p.muted + speed: p.speed + ao: p.ao + loop_file: p.loop + loop_playlist: p.loop_playlist + hwdec: p.hwdec + deinterlace: p.deinterlace + ui_scale: p.ui_scale + sub_visible: p.sub_visible + aspect: p.aspect + rotate: p.rotate + zoom: p.zoom + windowed_overlay: p.windowed_overlay + fullscreen_overlay: p.fullscreen_overlay + show_stats: p.show_stats + show_queue: p.show_queue + show_preview: p.show_preview + open_mode: p.open_mode + low_quality: p.low_quality + continuous: p.continuous + smooth_bar: p.smooth_bar + show_playback_status: p.show_playback_status + show_title_filename: p.show_title_filename + theme: p.theme_name + preset: p.preset_name + media_controls: p.media_controls + mpv_opts: p.mpv_opts } } @@ -266,6 +272,10 @@ fn (mut p Player) apply_settings(s Settings) { // 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. p.smooth_bar = s.smooth_bar + // The title needs none either: the two rows only reshape what the + // property events write, and the window opens before anything plays. + p.show_playback_status = s.show_playback_status + p.show_title_filename = s.show_title_filename // The desktop media controls start here, before the menu bar is built, // so the Options check row reflects them from the first build. p.media_controls = s.media_controls diff --git a/src/surface.v b/src/surface.v index 5f2fd0c..fdd0e64 100644 --- a/src/surface.v +++ b/src/surface.v @@ -14,6 +14,12 @@ fn (mut p Player) draw(id string, frame ui2.Rect, scale f64, height f64) { now := time.ticks() late_frame := p.last_frame_t0 > 0 && now - p.last_frame_t0 > 18 p.last_frame_t0 = now + // Sokol registers its X11 display inside its own loop, so the window's + // WM_CLASS can only land on the first frame that has the window to name. + if !p.window_class_set { + p.window_class_set = true + set_window_class() + } p.drain_events() p.resume_pending_queue() p.drain_mpris() -- 2.56.1