mirror of
https://github.com/mpv-player/mpv.git
synced 2025-12-28 05:33:14 +00:00
TOOLS/lua: add script that pauses playback when minimizing the window
Uses functionality that was added a month ago for exactly this purpose. Fixes #1237.
This commit is contained in:
22
TOOLS/lua/pause-when-minimize.lua
Normal file
22
TOOLS/lua/pause-when-minimize.lua
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
-- This script pauses playback when minimizing the window, and resumes playback
|
||||||
|
-- if it's brought back again. If the player was already paused when minimizing,
|
||||||
|
-- then try not to mess with the pause state.
|
||||||
|
|
||||||
|
-- Note: currently works with X11 only.
|
||||||
|
|
||||||
|
local did_minimize = false
|
||||||
|
|
||||||
|
mp.observe_property("window-minimized", "bool", function(name, value)
|
||||||
|
local pause = mp.get_property_native("pause")
|
||||||
|
if value == true then
|
||||||
|
if pause == false then
|
||||||
|
mp.set_property_native("pause", true)
|
||||||
|
did_minimize = true
|
||||||
|
end
|
||||||
|
elseif value == false then
|
||||||
|
if did_minimize and (pause == true) then
|
||||||
|
mp.set_property_native("pause", false)
|
||||||
|
end
|
||||||
|
did_minimize = false
|
||||||
|
end
|
||||||
|
end)
|
||||||
Reference in New Issue
Block a user