Skip to content

Commit

Permalink
console.lua: hide the cursor when unfocused
Browse files Browse the repository at this point in the history
This is commonly done to understand whether a window is focused. This
explicitly checks if focused is false instead of unavailable to not
break the cursor where focused is unimplemented like on --vo=drm.

The cursor is taller than the input text so it is made transparent
instead of completely removing it so that the log doesn't move up and
down while toggling focus. Alternatively, cheight = opts.font_size * 8
can be changed to 7.
  • Loading branch information
guidocella authored and sfan5 committed Jan 1, 2024
1 parent 731378d commit 28b21e4
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion player/lua/console.lua
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@ function update()
-- horizontal borders.
local cheight = opts.font_size * 8
local cglyph = '{\\r' ..
'\\1a&H44&\\3a&H44&\\4a&H99&' ..
(mp.get_property_native('focused') == false
and '\\alpha&HFF&' or '\\1a&H44&\\3a&H44&\\4a&H99&') ..
'\\1c&Heeeeee&\\3c&Heeeeee&\\4c&H000000&' ..
'\\xbord0.5\\ybord0\\xshad0\\yshad1\\p4\\pbo24}' ..
'm 0 0 l 1 0 l 1 ' .. cheight .. ' l 0 ' .. cheight ..
Expand Down Expand Up @@ -1317,6 +1318,7 @@ end)
mp.observe_property('osd-width', 'native', update)
mp.observe_property('osd-height', 'native', update)
mp.observe_property('display-hidpi-scale', 'native', update)
mp.observe_property('focused', nil, update)

-- Enable log messages. In silent mode, mpv will queue log messages in a buffer
-- until enable_messages is called again without the silent: prefix.
Expand Down

0 comments on commit 28b21e4

Please sign in to comment.