osc: use custom symbols for window controls

I was recently informed that unicode has official symbols for
window controls, and I put together a change to use them, which
worked, as long as a suitable font was installed. However, it's
not that hard to get a normal system that lacks an appropriate
font, and libass wants to print warnings if the symbols aren't
in the default font, which will almost always be true.

So, I gave up and added the symbols to the custom osd font that
we already have. This ensures they are always available, and
that they are aligned consistently on all platforms.

I took the symbols from the `symbola` font, as this has a suitable
licence and the symbols look nice enough.

Symbola Licence:

    Fonts are free for any use; they may be opened, edited,
    modified, regenerated, packaged and redistributed.

Finally, as we now have access to an un-maximize symbol, I added
logic to use it when the window is maximized.
This commit is contained in:
Philip Langdale 2019-12-10 14:57:13 -08:00 committed by Philip Langdale
parent 59cdfe50b2
commit db3754d8d6
7 changed files with 120 additions and 11 deletions

View File

@ -22,7 +22,7 @@ OS2Version: 3
OS2_WeightWidthSlopeOnly: 0
OS2_UseTypoMetrics: 0
CreationTime: 1408646554
ModificationTime: 1492879730
ModificationTime: 1576096543
PfmFamily: 81
TTFWeight: 400
TTFWidth: 5

View File

@ -0,0 +1,15 @@
StartChar: uniE112
Encoding: 57618 57618 30
Width: 768
VWidth: 1176
Flags: HW
LayerCount: 2
Fore
SplineSet
512 40 m 1
0 40 l 1
0 168 l 1
512 168 l 1
512 40 l 1
EndSplineSet
EndChar

View File

@ -0,0 +1,20 @@
StartChar: uniE113
Encoding: 57619 57619 31
Width: 622
VWidth: 1178
Flags: HW
LayerCount: 2
Fore
SplineSet
768 42 m 5
0 42 l 5
0 746 l 5
768 746 l 5
768 42 l 5
704 106 m 5
704 618 l 5
64 618 l 5
64 106 l 5
704 106 l 5
EndSplineSet
EndChar

View File

@ -0,0 +1,31 @@
StartChar: uniE114
Encoding: 57620 57620 32
Width: 896
VWidth: 1178
Flags: HW
LayerCount: 2
Fore
SplineSet
768 298 m 1
576 298 l 1
576 42 l 1
0 42 l 1
0 490 l 1
192 490 l 1
192 746 l 1
768 746 l 1
768 298 l 1
704 362 m 1
704 618 l 1
256 618 l 1
256 490 l 1
576 490 l 1
576 362 l 1
704 362 l 1
512 106 m 1
512 362 l 1
64 362 l 1
64 106 l 1
512 106 l 1
EndSplineSet
EndChar

View File

@ -0,0 +1,27 @@
StartChar: uniE115
Encoding: 57621 57621 33
Width: 844
VWidth: 1112
Flags: HW
LayerCount: 2
Fore
SplineSet
671 40 m 1
575 40 l 1
335 277 l 1
98 40 l 1
-1 40 l 1
-1 136 l 1
236 376 l 1
-1 613 l 1
-1 712 l 1
98 712 l 1
335 475 l 1
575 712 l 1
671 712 l 1
671 613 l 1
434 376 l 1
671 139 l 1
671 40 l 1
EndSplineSet
EndChar

View File

@ -103,7 +103,8 @@ local osc_styles = {
timePosBar = "{\\blur0\\bord".. user_opts.tooltipborder .."\\1c&HFFFFFF\\3c&H000000\\fs30}",
vidtitleBar = "{\\blur0\\bord0\\1c&HFFFFFF\\3c&HFFFFFF\\fs18\\q2}",
wcButtons = "{\\1c&HFFFFFF\\fs24}",
wcButtons = "{\\1c&HFFFFFF\\fs24\\fnmpv-osd-symbols}",
wcTitle = "{\\1c&HFFFFFF\\fs24}",
wcBar = "{\\1c&H000000}",
}
@ -134,6 +135,7 @@ local state = {
dmx_cache = 0,
using_video_margins = false,
border = true,
maximized = false,
}
local window_control_box_width = 80
@ -1040,33 +1042,41 @@ function window_controls(topbar)
local third_geo =
{x = controlbox_left + 55, y = button_y, an = 4, w = 25, h = 25}
-- Close
-- Window control buttons use symbols in the custom mpv osd font
-- because the official unicode codepoints are sufficiently
-- exotic that a system might lack an installed font with them,
-- and libass will complain that they are not present in the
-- default font, even if another font with them is available.
-- Close: 🗙
ne = new_element("close", "button")
ne.content = "\226\152\146"
ne.content = "\238\132\149"
ne.eventresponder["mbtn_left_up"] =
function () mp.commandv("quit") end
lo = add_layout("close")
lo.geometry = alignment == "left" and first_geo or third_geo
lo.style = osc_styles.wcButtons
-- Minimize
-- Minimize: 🗕
ne = new_element("minimize", "button")
ne.content = "\226\154\128"
ne.content = "\238\132\146"
ne.eventresponder["mbtn_left_up"] =
function () mp.commandv("cycle", "window-minimized") end
lo = add_layout("minimize")
lo.geometry = alignment == "left" and second_geo or first_geo
lo.style = osc_styles.wcButtons
-- Maximize
-- Maximize: 🗖 /🗗
ne = new_element("maximize", "button")
ne.content = "\226\150\163"
if state.maximized then
ne.content = "\238\132\148"
else
ne.content = "\238\132\147"
end
ne.eventresponder["mbtn_left_up"] =
function () mp.commandv("cycle", "window-maximized") end
lo = add_layout("maximize")
lo.geometry = alignment == "left" and third_geo or second_geo
-- At least with default Ubuntu fonts, this symbol is differently aligned
lo.geometry.y = lo.geometry.y - 2
lo.style = osc_styles.wcButtons
-- deadzone below window controls
@ -1097,7 +1107,7 @@ function window_controls(topbar)
lo.geometry =
{ x = titlebox_left, y = wc_geo.y - 3, an = 1, w = titlebox_w, h = wc_geo.h }
lo.style = string.format("%s{\\clip(%f,%f,%f,%f)}",
osc_styles.wcButtons,
osc_styles.wcTitle,
titlebox_left, wc_geo.y - wc_geo.h, titlebox_w, wc_geo.y + wc_geo.h)
end
@ -2500,6 +2510,12 @@ mp.observe_property("border", "bool",
request_init()
end
)
mp.observe_property("window-maximized", "bool",
function(name, val)
state.maximized = val
request_init()
end
)
mp.observe_property("idle-active", "bool",
function(name, val)
state.idle = val

Binary file not shown.