Skip to content

Instantly share code, notes, and snippets.

@detuur
Last active September 14, 2018 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save detuur/7ea3609b8826d0e6f6bbc730d54a963c to your computer and use it in GitHub Desktop.
Save detuur/7ea3609b8826d0e6f6bbc730d54a963c to your computer and use it in GitHub Desktop.
This script minimises and pauses the window when the boss key (default 'b') is pressed. (old version)

The new version is cross-platform and fixes the 2-second time lag this one has. If the new version causes issues this one might still work for you.

-- This script minimises and pauses the window when
-- the boss key (default 'b') is pressed.
-- Can be overwriten in input.conf as follows:
-- KEY script-binding boss-key
utils = require 'mp.utils'
function boss_key()
mp.set_property_native("pause", true)
minimize_win32()
end
function minimize_win32()
local res = utils.subprocess({
args = {'powershell', '-NoProfile', '-Command', [[& {
# Get mpv's PID
$bosspid = (gwmi win32_process | ? processid -eq $pid).parentprocessid
# Set function signature
$signature='[DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);'
# Call Add-Type to compile code
$showWindowAsync = Add-Type -memberDefinition $signature -name "Win32ShowWindowAsync" -namespace Win32Functions -passThru
# Minimize mpv
$showWindowAsync::ShowWindowAsync((Get-Process -id $bosspid).MainWindowHandle, 2)
}]]},
cancellable = false,
})
end
mp.add_key_binding('b', 'boss-key', boss_key)
@detuur
Copy link
Author

detuur commented Jan 29, 2018

Call out to desktop Linux users for code that works there.

@57op
Copy link

57op commented Mar 20, 2018

For gnu/linux users, supposing you're running xorg and have the xdotool package, it will be:
utils.subprocess({ args = { 'xdotool', 'getactivewindow', 'windowminimize' }, cancellable = false })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment