Skip to content

Commit f76af50

Browse files
committed
mouse scrolling / defer grab focus until first exposure
1 parent adeb692 commit f76af50

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

src/lwtk/Application.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ createClosures = function(app)
343343
window:_handleFocusIn(...)
344344
elseif event == "FOCUS_OUT" then
345345
window:_handleFocusOut(...)
346+
elseif event == "SCROLL" then
347+
window:_handleMouseScroll(...)
346348
elseif event == "CLOSE" then
347349
window:_handleClose()
348350
elseif event == "MAP" then

src/lwtk/Component.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,20 @@ function Component:_processMouseLeave(x, y)
422422
call("onMouseLeave", self, x, y)
423423
end
424424

425+
function Component:_processMouseScroll(dx, dy)
426+
local comp = self
427+
while true do
428+
local onMouseScroll = comp.onMouseScroll
429+
if onMouseScroll and onMouseScroll(comp, dx, dy) then
430+
return true
431+
end
432+
comp = getParent[comp]
433+
if not comp then
434+
return false
435+
end
436+
end
437+
end
438+
425439
function Component:_processMouseDown(mx, my, button, modState)
426440
local onMouseDown = self.onMouseDown
427441
if onMouseDown then

src/lwtk/MouseDispatcher.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ function MouseDispatcher:_processMouseMove(mouseEntered, mx, my)
126126
processMouseMove(self, mouseEntered, mx, my)
127127
end
128128

129+
function MouseDispatcher:_processMouseScroll(dx, dy)
130+
local hChild = self.mouseHoverChild
131+
if hChild and hChild ~= self then
132+
hChild:_processMouseScroll(dx, dy)
133+
end
134+
end
135+
129136
function MouseDispatcher:_processMouseLeave(mx, my)
130137
self.mouseX = mx
131138
self.mouseY = my

src/lwtk/Window.lua

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ function Window:_handleConfigure(x, y, w, h)
381381
end
382382

383383
function Window:_handleExpose(x, y, w, h, count)
384+
if self._grabFocus then
385+
self.view:grabFocus()
386+
self._grabFocus = nil
387+
end
384388
self.exposedArea:addRect(x, y, w, h)
385389
if count == 0 then
386390
self.fullRedisplayOutstanding = false
@@ -421,6 +425,10 @@ function Window:_handleMouseMove(mx, my)
421425
self:_processMouseMove(self.mouseEntered, mx, my)
422426
end
423427

428+
function Window:_handleMouseScroll(dx, dy)
429+
self:_processMouseScroll(dx, dy)
430+
end
431+
424432
function Window:_handleMouseLeave(mx, my)
425433
self.mouseX = mx
426434
self.mouseY = my
@@ -479,10 +487,6 @@ end
479487

480488
function Window:_handleMap()
481489
self.mapped = true
482-
if self._grabFocus then
483-
self.view:grabFocus()
484-
self._grabFocus = nil
485-
end
486490
end
487491

488492
function Window:requestClose()

0 commit comments

Comments
 (0)