Skip to content

Commit

Permalink
Merge pull request #220 from Samillion/dev_titlebar_fix
Browse files Browse the repository at this point in the history
fix: if all title bar elements are disabled, don't show osc on hover in top area
  • Loading branch information
Samillion authored Nov 15, 2024
2 parents 8a4b5aa + b49ee55 commit d3e2fc0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
4 changes: 2 additions & 2 deletions docs/USER_OPTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Create `modernz.conf` in your mpv script-opts directory:
| language | en | set language (for available options, see: [Translations](https://github.com/Samillion/ModernZ/blob/main/docs/TRANSLATIONS.md)) |
| font | mpv-osd-symbols | font for the OSC (default: mpv-osd-symbols or the one set in mpv.conf) |
| idlescreen | yes | show mpv logo when idle |
| windowcontrols | auto | show OSC window controls: `"auto"`, `"yes"`, or `"no"` |
| window_top_bar | auto | show OSC window top bar: `"auto"`, `"yes"`, or `"no"` (borderless/fullscreen) |
| showwindowed | yes | show OSC when windowed |
| showfullscreen | yes | show OSC when fullscreen |
| showonpause | yes | show OSC when paused |
Expand Down Expand Up @@ -62,7 +62,7 @@ Create `modernz.conf` in your mpv script-opts directory:
| window_title | no | show window title in borderless/fullscreen mode |
| window_controls | yes | show window controls (close, minimize, maximize) in borderless/fullscreen |
| title_bar_box | no | show title bar as a box instead of a black fade |
| windowcontrols_title | `${media-title}` | same as title but for windowcontrols |
| windowcontrols_title | `${media-title}` | same as title but for window_top_bar |

### Subtitle display settings

Expand Down
6 changes: 3 additions & 3 deletions modernz.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ font=mpv-osd-symbols

# show mpv logo when idle
idlescreen=yes
# show OSC window controls: "auto", "yes", or "no"
windowcontrols=auto
# show OSC window top bar: "auto", "yes", or "no" (borderless/fullscreen)
window_top_bar=auto
# show OSC when windowed
showwindowed=yes
# show OSC when fullscreen
Expand Down Expand Up @@ -75,7 +75,7 @@ window_title=no
window_controls=yes
# show title bar as a box instead of a black fade
title_bar_box=no
# same as title but for windowcontrols
# same as title but for window_top_bar
windowcontrols_title=${media-title}

# Subtitle display settings
Expand Down
28 changes: 17 additions & 11 deletions modernz.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ local user_opts = {
font = "mpv-osd-symbols", -- font for the OSC (default: mpv-osd-symbols or the one set in mpv.conf)

idlescreen = true, -- show mpv logo when idle
windowcontrols = "auto", -- show OSC window controls: "auto", "yes", or "no"
window_top_bar = "auto", -- show OSC window top bar: "auto", "yes", or "no" (borderless/fullscreen)
showwindowed = true, -- show OSC when windowed
showfullscreen = true, -- show OSC when fullscreen
showonpause = true, -- show OSC when paused
Expand Down Expand Up @@ -745,7 +745,7 @@ end

-- WindowControl helpers
local function window_controls_enabled()
local val = user_opts.windowcontrols
local val = user_opts.window_top_bar
if val == "auto" then
return not (state.border and state.title_bar) or state.fullscreen
else
Expand Down Expand Up @@ -1591,7 +1591,9 @@ layouts["modern"] = function ()
lo.layer = 10
lo.alpha[3] = 0

if not user_opts.title_bar_box and (not (state.border and state.title_bar) or state.fullscreen) then
local top_titlebar = window_controls_enabled() and (user_opts.window_title or user_opts.window_controls)

if not user_opts.title_bar_box and (not (state.border and state.title_bar) or state.fullscreen) and top_titlebar then
new_element("title_alpha_bg", "box")
lo = add_layout("title_alpha_bg")
lo.geometry = {x = posX, y = -100, an = 7, w = osc_w, h = -1}
Expand Down Expand Up @@ -1840,15 +1842,17 @@ layouts["modern-image"] = function ()
lo.layer = 10
lo.alpha[3] = 0

if not user_opts.title_bar_box and (not (state.border and state.title_bar) or state.fullscreen) then
local top_titlebar = window_controls_enabled() and (user_opts.window_title or user_opts.window_controls)

if not user_opts.title_bar_box and (not (state.border and state.title_bar) or state.fullscreen) and top_titlebar then
new_element("title_alpha_bg", "box")
lo = add_layout("title_alpha_bg")
lo.geometry = {x = posX, y = -100, an = 7, w = osc_w, h = -1}
lo.style = osc_styles.box_bg
lo.layer = 10
lo.alpha[3] = 0
end

-- Alignment
local refX = osc_w / 2
local refY = posY
Expand Down Expand Up @@ -2811,7 +2815,9 @@ local function process_event(source, what)
)
) then
if user_opts.bottomhover then -- if enabled, only show osc if mouse is hovering at the bottom of the screen (where the UI elements are)
if mouseY > osc_param.playresy - (user_opts.bottomhover_zone or 145) or (not (state.border and state.title_bar) or state.fullscreen) and mouseY < 40 then -- account for scaling options
local top_hover = window_controls_enabled() and (user_opts.window_title or user_opts.window_controls)
if mouseY > osc_param.playresy - (user_opts.bottomhover_zone or 145)
or (not (state.border and state.title_bar) or state.fullscreen) and (mouseY < 40 and top_hover) then
show_osc()
else
state.touchtime = nil
Expand Down Expand Up @@ -3380,11 +3386,11 @@ end)

-- Validate string type user options
local function validate_user_opts()
if user_opts.windowcontrols ~= "auto" and
user_opts.windowcontrols ~= "yes" and
user_opts.windowcontrols ~= "no" then
msg.warn("windowcontrols cannot be '" .. user_opts.windowcontrols .. "'. Ignoring.")
user_opts.windowcontrols = "auto"
if user_opts.window_top_bar ~= "auto" and
user_opts.window_top_bar ~= "yes" and
user_opts.window_top_bar ~= "no" then
msg.warn("window_top_bar cannot be '" .. user_opts.window_top_bar .. "'. Ignoring.")
user_opts.window_top_bar = "auto"
end

if user_opts.seekbarhandlesize < 0.3 then
Expand Down

0 comments on commit d3e2fc0

Please sign in to comment.