fix: work around mpv's cycle window-maximized quirks

closes #203
This commit is contained in:
tomasklaen
2022-09-19 12:28:17 +02:00
parent bc79205951
commit b610b6cda5

View File

@@ -2884,7 +2884,7 @@ end
--[[ TopBarButton ]] --[[ TopBarButton ]]
---@alias TopBarButtonProps {icon: string; background: string; anchor_id?: string; command: string} ---@alias TopBarButtonProps {icon: string; background: string; anchor_id?: string; command: string|fun()}
---@class TopBarButton : Element ---@class TopBarButton : Element
local TopBarButton = class(Element) local TopBarButton = class(Element)
@@ -2900,7 +2900,9 @@ function TopBarButton:init(id, props)
self.command = props.command self.command = props.command
end end
function TopBarButton:on_mbtn_left_down() mp.command(self.command) end function TopBarButton:on_mbtn_left_down()
mp.command(type(self.command) == 'function' and self.command() or self.command)
end
function TopBarButton:render() function TopBarButton:render()
local visibility = self:get_visibility() local visibility = self:get_visibility()
@@ -2935,10 +2937,16 @@ function TopBar:init()
self.size_min_override = options.timeline_start_hidden and 0 or nil self.size_min_override = options.timeline_start_hidden and 0 or nil
self.top_border = options.timeline_border self.top_border = options.timeline_border
local function decide_maximized_command()
return state.border
and (state.fullscreen and 'set fullscreen no;cycle window-maximized' or 'cycle window-maximized')
or 'set window-maximized no;cycle fullscreen'
end
-- Order aligns from right to left -- Order aligns from right to left
self.buttons = { self.buttons = {
TopBarButton:new('tb_close', {icon = 'close', background = '2311e8', command = 'quit'}), TopBarButton:new('tb_close', {icon = 'close', background = '2311e8', command = 'quit'}),
TopBarButton:new('tb_max', {icon = 'crop_square', background = '222222', command = 'cycle window-maximized'}), TopBarButton:new('tb_max', {icon = 'crop_square', background = '222222', command = decide_maximized_command}),
TopBarButton:new('tb_min', {icon = 'minimize', background = '222222', command = 'cycle window-minimized'}), TopBarButton:new('tb_min', {icon = 'minimize', background = '222222', command = 'cycle window-minimized'}),
} }
end end