me

/

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

added options to the window's title and X11 atoms

diviocity committed last Nov 1 · 7e6522537fe1056f8c1c4e91d4832122e7f8f2e9 View patch
Unverified signature 4 files changed +107 -33
src/main.v +4 -1

@@ -272,9 +272,12 @@ fn main() {

272272 mpv.observe_property(player.mpv_ctx, obs_mpris_volume, 'volume', mpv.format_double)

273273 mpv.observe_property(player.mpv_ctx, obs_mpris_loop, 'loop-file', mpv.format_string)

274274 mpv.observe_property(player.mpv_ctx, obs_mpris_loop_playlist, 'loop-playlist', mpv.format_string)

275- mpv.observe_property(player.mpv_ctx, obs_media_title, 'media-title', mpv.format_string)

276275 mpv.observe_property(player.mpv_ctx, obs_media_artist, 'metadata/by-key/artist', mpv.format_string)

277276 }

277+ // The window title carries the playing file's name, so media-title is

278+ // observed in every build (the mpris build's xesam:title reads the same

279+ // mirror that update_window_title consumes).

280+ mpv.observe_property(player.mpv_ctx, obs_media_title, 'media-title', mpv.format_string)

278281 // Playback statistics for the popup; each reports its own property change.

279282 mpv.observe_property(player.mpv_ctx, obs_fps, 'fps', mpv.format_double)

280283 mpv.observe_property(player.mpv_ctx, obs_vf_fps, 'estimated-vf-fps', mpv.format_double)

src/player.v +55 -0

@@ -237,6 +237,14 @@ mut:

237237 theme_edit_texts map[string]string

238238 theme_pickers map[string]ThemePicker

239239 low_quality bool

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

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

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

243+ show_playback_status bool = true

244+ show_title_filename bool = true

245+ // The WM_CLASS write ran: sokol's X11 display exists only after its loop

246+ // opens the window, and the write is once-per-session work.

247+ window_class_set bool

240248 // The window's redraw policy: with it on, ui2 repaints the retained tree

241249 // every vsync and rebuilds on ask, so the seek bar glides and hovers

242250 // answer within a frame. It is the View menu's Continuous redraw row, and

@@ -337,6 +345,32 @@ mut:

337345 playlist_index int

338346}

339347

348+// update_window_title mirrors what mpv plays into the window title, in the

349+// form 'Vendetta (paused) - filename': the pause suffix appears under the

350+// Options bar's Show playback status row while playback is paused, and the

351+// name is the file's own name for a local file or mpv's media-title for a

352+// stream, shown under the Show filename row. With both rows off the title

353+// stays plain 'Vendetta'. The media-title and pause property events run it,

354+// so a file change and a pause flip repaint the title out of the mirrors the

355+// observers already hold; neither call needs its own mpv read.

356+fn (mut p Player) update_window_title() {

357+ name := if !p.has_file {

358+ ''

359+ } else if p.current_kind == .file && p.current_path.len > 0 {

360+ os.file_name(p.current_path)

361+ } else {

362+ p.media_title

363+ }

364+ mut title := 'Vendetta'

365+ if p.show_playback_status && p.paused {

366+ title += ' (paused)'

367+ }

368+ if p.show_title_filename && name.len > 0 {

369+ title += ' - ' + name

370+ }

371+ apply_window_title(title)

372+}

373+

340374// on_mpv_event follows the events the menus and lists show. The widget has

341375// already taken the playback state from each one.

342376fn (mut p Player) on_mpv_event(ev voidptr) {

@@ -411,6 +445,7 @@ fn (mut p Player) apply_app_property(ev voidptr) {

411445 }

412446 p.paused = v

413447 p.mpris_push()

448+ p.update_window_title()

414449 ui2.set_menu_bar(p.menus())

415450 }

416451 }

@@ -560,6 +595,7 @@ fn (mut p Player) apply_app_property(ev voidptr) {

560595 if v := mpv.property_string(ev) {

561596 p.media_title = v

562597 p.mpris_push()

598+ p.update_window_title()

563599 }

564600 }

565601 'metadata/by-key/artist' {

@@ -1169,6 +1205,16 @@ fn (mut p Player) handle(event string) {

11691205 p.smooth_bar = !p.smooth_bar

11701206 ui2.set_menu_bar(p.menus())

11711207 }

1208+ 'title_status' {

1209+ p.show_playback_status = !p.show_playback_status

1210+ p.update_window_title()

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

1212+ }

1213+ 'title_filename' {

1214+ p.show_title_filename = !p.show_title_filename

1215+ p.update_window_title()

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

1217+ }

11721218 'view_continuous' {

11731219 p.set_continuous(!p.continuous)

11741220 ui2.set_menu_bar(p.menus())

@@ -1593,6 +1639,10 @@ fn (mut p Player) close_file() {

15931639 p.pos = 0

15941640 p.clear_next = true

15951641 p.drop_shown_thumb()

1642+ // The stop clears mpv's mirrors asynchronously; the title has nothing to

1643+ // wait on here, regardless of whether media-title's own event lands.

1644+ p.media_title = ''

1645+ p.update_window_title()

15961646}

15971647

15981648fn (p &Player) has_track(kind string) bool {

@@ -2326,6 +2376,11 @@ fn (p &Player) menus() []ui2.Menu {

23262376 ui2.menu_check_item('video_deinterlace', 'Deinterlace', p.deinterlace),

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

23282378 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),

23292384 ...p.media_controls_menu_items(),

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

23312386 ]

src/settings.v +42 -32

@@ -44,11 +44,15 @@ pub mut:

4444 // The smooth seek bar: the player carries the bar forward at playback speed

4545 // between mpv's position reports and redraws the window at the display rate

4646 // while it plays.

47- smooth_bar bool

48- theme string = default_theme_name

49- preset string

50- media_controls bool

51- mpv_opts map[string]string

47+ smooth_bar bool

48+ // The window title's two halves, shown while set (both default on):

49+ // '(paused)' while playback is paused, then the playing file's name.

50+ show_playback_status bool = true

51+ show_title_filename bool = true

52+ theme string = default_theme_name

53+ preset string

54+ media_controls bool

55+ mpv_opts map[string]string

5256}

5357

5458// config_base is the directory vendetta's state lives under — the tree whose

@@ -152,33 +156,35 @@ fn (p &Player) save_queue_state() {

152156// collect_settings snapshots the persisted state out of the player.

153157fn (p &Player) collect_settings() Settings {

154158 return Settings{

155- volume: p.volume

156- max_volume: p.max_volume

157- muted: p.muted

158- speed: p.speed

159- ao: p.ao

160- loop_file: p.loop

161- loop_playlist: p.loop_playlist

162- hwdec: p.hwdec

163- deinterlace: p.deinterlace

164- ui_scale: p.ui_scale

165- sub_visible: p.sub_visible

166- aspect: p.aspect

167- rotate: p.rotate

168- zoom: p.zoom

169- windowed_overlay: p.windowed_overlay

170- fullscreen_overlay: p.fullscreen_overlay

171- show_stats: p.show_stats

172- show_queue: p.show_queue

173- show_preview: p.show_preview

174- open_mode: p.open_mode

175- low_quality: p.low_quality

176- continuous: p.continuous

177- smooth_bar: p.smooth_bar

178- theme: p.theme_name

179- preset: p.preset_name

180- media_controls: p.media_controls

181- mpv_opts: p.mpv_opts

159+ volume: p.volume

160+ max_volume: p.max_volume

161+ muted: p.muted

162+ speed: p.speed

163+ ao: p.ao

164+ loop_file: p.loop

165+ loop_playlist: p.loop_playlist

166+ hwdec: p.hwdec

167+ deinterlace: p.deinterlace

168+ ui_scale: p.ui_scale

169+ sub_visible: p.sub_visible

170+ aspect: p.aspect

171+ rotate: p.rotate

172+ zoom: p.zoom

173+ windowed_overlay: p.windowed_overlay

174+ fullscreen_overlay: p.fullscreen_overlay

175+ show_stats: p.show_stats

176+ show_queue: p.show_queue

177+ show_preview: p.show_preview

178+ open_mode: p.open_mode

179+ low_quality: p.low_quality

180+ continuous: p.continuous

181+ smooth_bar: p.smooth_bar

182+ show_playback_status: p.show_playback_status

183+ show_title_filename: p.show_title_filename

184+ theme: p.theme_name

185+ preset: p.preset_name

186+ media_controls: p.media_controls

187+ mpv_opts: p.mpv_opts

182188 }

183189}

184190

@@ -266,6 +272,10 @@ fn (mut p Player) apply_settings(s Settings) {

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

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

268274 p.smooth_bar = s.smooth_bar

275+ // The title needs none either: the two rows only reshape what the

276+ // property events write, and the window opens before anything plays.

277+ p.show_playback_status = s.show_playback_status

278+ p.show_title_filename = s.show_title_filename

269279 // The desktop media controls start here, before the menu bar is built,

270280 // so the Options check row reflects them from the first build.

271281 p.media_controls = s.media_controls

src/surface.v +6 -0

@@ -14,6 +14,12 @@ fn (mut p Player) draw(id string, frame ui2.Rect, scale f64, height f64) {

1414 now := time.ticks()

1515 late_frame := p.last_frame_t0 > 0 && now - p.last_frame_t0 > 18

1616 p.last_frame_t0 = now

17+ // Sokol registers its X11 display inside its own loop, so the window's

18+ // WM_CLASS can only land on the first frame that has the window to name.

19+ if !p.window_class_set {

20+ p.window_class_set = true

21+ set_window_class()

22+ }

1723 p.drain_events()

1824 p.resume_pending_queue()

1925 p.drain_mpris()