diff --git a/data/core/init.lua b/data/core/init.lua index 0fa260ed..e5a81f1f 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -1136,6 +1136,8 @@ function core.on_event(type, ...) end elseif type == "mousereleased" then core.root_view:on_mouse_released(...) + elseif type == "mouseleft" then + core.root_view:on_mouse_left() elseif type == "mousewheel" then if not core.root_view:on_mouse_wheel(...) then did_keymap = keymap.on_mouse_wheel(...) diff --git a/data/core/node.lua b/data/core/node.lua index 56e0889a..fee62ba6 100644 --- a/data/core/node.lua +++ b/data/core/node.lua @@ -51,6 +51,15 @@ function Node:on_mouse_released(...) end +function Node:on_mouse_left() + if self.type == "leaf" then + self.active_view:on_mouse_left() + else + self:propagate("on_mouse_left") + end +end + + function Node:consume(node) for k, _ in pairs(self) do self[k] = nil end for k, v in pairs(node) do self[k] = v end @@ -160,8 +169,12 @@ end function Node:set_active_view(view) assert(self.type == "leaf", "Tried to set active view on non-leaf node") + local last_active_view = self.active_view self.active_view = view core.set_active_view(view) + if last_active_view and last_active_view ~= view then + last_active_view:on_mouse_left() + end end diff --git a/data/core/rootview.lua b/data/core/rootview.lua index b6cd95bb..8e32c68c 100644 --- a/data/core/rootview.lua +++ b/data/core/rootview.lua @@ -256,8 +256,13 @@ function RootView:on_mouse_moved(x, y, dx, dy) self.root_node:on_mouse_moved(x, y, dx, dy) + local last_overlapping_node = self.overlapping_node self.overlapping_node = self.root_node:get_child_overlapping_point(x, y) + if last_overlapping_node and last_overlapping_node ~= self.overlapping_node then + last_overlapping_node:on_mouse_left() + end + local div = self.root_node:get_divider_overlapping_point(x, y) local tab_index = self.overlapping_node and self.overlapping_node:get_tab_overlapping_point(x, y) if self.overlapping_node and self.overlapping_node:get_scroll_button_index(x, y) then @@ -272,6 +277,13 @@ function RootView:on_mouse_moved(x, y, dx, dy) end +function RootView:on_mouse_left() + if self.overlapping_node then + self.overlapping_node:on_mouse_left() + end +end + + function RootView:on_file_dropped(filename, x, y) local node = self.root_node:get_child_overlapping_point(x, y) return node and node.active_view:on_file_dropped(filename, x, y) diff --git a/data/core/view.lua b/data/core/view.lua index 18693afa..1f8a9208 100644 --- a/data/core/view.lua +++ b/data/core/view.lua @@ -144,6 +144,12 @@ function View:on_mouse_moved(x, y, dx, dy) end +function View:on_mouse_left() + self.hovered_scrollbar = false + self.hovered_scrollbar_track = false +end + + function View:on_file_dropped(filename, x, y) return false end diff --git a/src/api/system.c b/src/api/system.c index 45231d0b..ff99ce6f 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -161,6 +161,9 @@ top: } else if (e.window.event == SDL_WINDOWEVENT_RESTORED) { lua_pushstring(L, "restored"); return 1; + } else if (e.window.event == SDL_WINDOWEVENT_LEAVE) { + lua_pushstring(L, "mouseleft"); + return 1; } if (e.window.event == SDL_WINDOWEVENT_FOCUS_LOST) { lua_pushstring(L, "focuslost");