fix: window title click events preventing window dragging

closes #563
This commit is contained in:
tomasklaen
2023-05-15 12:45:30 +02:00
parent 128c76c3ba
commit 8ad5330a4b
2 changed files with 9 additions and 4 deletions

View File

@@ -318,10 +318,12 @@ cursor = {
on_primary_up = nil,
on_wheel_down = nil,
on_wheel_up = nil,
allow_dragging = false,
-- Called at the beginning of each render
reset_handlers = function()
cursor.on_primary_down, cursor.on_primary_up = nil, nil
cursor.on_wheel_down, cursor.on_wheel_up = nil, nil
cursor.allow_dragging = false
end,
-- Enables pointer key group captures needed by handlers (called at the end of each render)
mbtn_left_enabled = nil,
@@ -330,7 +332,8 @@ cursor = {
local enable_mbtn_left = (cursor.on_primary_down or cursor.on_primary_up) ~= nil
local enable_wheel = (cursor.on_wheel_down or cursor.on_wheel_up) ~= nil
if enable_mbtn_left ~= cursor.mbtn_left_enabled then
mp[(enable_mbtn_left and 'enable' or 'disable') .. '_key_bindings']('mbtn_left')
local flags = cursor.allow_dragging and 'allow-vo-dragging' or nil
mp[(enable_mbtn_left and 'enable' or 'disable') .. '_key_bindings']('mbtn_left', flags)
cursor.mbtn_left_enabled = enable_mbtn_left
end
if enable_wheel ~= cursor.wheel_enabled then

View File

@@ -197,13 +197,15 @@ function TopBar:render()
}
local bx = math.min(max_bx, title_ax + text_width(main_title, opts) + padding * 2)
local by = self.by - bg_margin
local rect = {ax = title_ax, ay = self.ay, bx = self.title_bx, by = self.by}
local title_rect = {ax = title_ax, ay = title_ay, bx = bx, by = by}
if get_point_to_rectangle_proximity(cursor, rect) == 0 then
if options.top_bar_alt_title_place == 'toggle'
and get_point_to_rectangle_proximity(cursor, title_rect) == 0 then
cursor.on_primary_down = function() self:toggle_title() end
cursor.allow_dragging = true
end
ass:rect(title_ax, title_ay, bx, by, {
ass:rect(title_rect.ax, title_rect.ay, title_rect.bx, title_rect.by, {
color = bg, opacity = visibility * options.top_bar_title_opacity, radius = 2,
})
ass:txt(title_ax + padding, self.ay + (self.size / 2), 4, main_title, opts)