Merge pull request #3414 from myk002/myk_scroll_to_focus

scroll mouse wheel to focus window under cursor
develop
Myk 2023-05-25 17:18:52 -07:00 committed by GitHub
commit 2efeead96e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 10 deletions

@ -62,6 +62,7 @@ changelog.txt uses a syntax similar to RST, with a few special sequences:
- `overlay`: added links to the quickstart guide and the control panel on the DF title screen - `overlay`: added links to the quickstart guide and the control panel on the DF title screen
- Window behavior: non-resizable windows now allow dragging by their frame edges by default - Window behavior: non-resizable windows now allow dragging by their frame edges by default
- `gui/autodump`: fort-mode keybinding: Ctrl-H - `gui/autodump`: fort-mode keybinding: Ctrl-H
- Window behavior: if you have multiple DFHack tool windows open, scrolling the mouse wheel while over an unfocused window will focus it and raise it to the top
## Documentation ## Documentation

@ -4240,11 +4240,11 @@ input skips all unfocused ZScreens under that ZScreen and is passed directly to
the first non-ZScreen viewscreen. There are class attributes that can be set to the first non-ZScreen viewscreen. There are class attributes that can be set to
control what kind of unhandled input is passed to the lower layers. control what kind of unhandled input is passed to the lower layers.
If multiple ZScreens are visible and the player left or right clicks on a If multiple ZScreens are visible and the player scrolls or left/right clicks on
visible element of a non-focused ZScreen, that ZScreen will be given focus. This a visible element of a non-focused ZScreen, that ZScreen will be given focus.
allows multiple DFHack GUI tools to be usable at the same time. If the mouse is This allows multiple DFHack GUI tools to be usable at the same time. If the
clicked away from the ZScreen widgets, that ZScreen loses focus. If no ZScreen mouse is clicked away from the ZScreen widgets, that ZScreen loses focus. If no
has focus, all input is passed directly through to the first underlying ZScreen has focus, all input is passed directly through to the first underlying
non-ZScreen viewscreen. non-ZScreen viewscreen.
For a ZScreen with keyboard focus, if :kbd:`Esc` or the right mouse button is For a ZScreen with keyboard focus, if :kbd:`Esc` or the right mouse button is

@ -787,7 +787,10 @@ end
function ZScreen:onInput(keys) function ZScreen:onInput(keys)
local has_mouse = self:isMouseOver() local has_mouse = self:isMouseOver()
if not self:hasFocus() then if not self:hasFocus() then
if (keys._MOUSE_L_DOWN or keys._MOUSE_R_DOWN) and has_mouse then if has_mouse and
(keys._MOUSE_L_DOWN or keys._MOUSE_R_DOWN or
keys.CONTEXT_SCROLL_UP or keys.CONTEXT_SCROLL_DOWN or
keys.CONTEXT_SCROLL_PAGEUP or keys.CONTEXT_SCROLL_PAGEDOWN) then
self:raise() self:raise()
else else
self:sendInputToParent(keys) self:sendInputToParent(keys)
@ -818,6 +821,10 @@ function ZScreen:onInput(keys)
end end
local passit = self.pass_pause and keys.D_PAUSE local passit = self.pass_pause and keys.D_PAUSE
if not passit and self.pass_mouse_clicks then if not passit and self.pass_mouse_clicks then
if keys.CONTEXT_SCROLL_UP or keys.CONTEXT_SCROLL_DOWN or
keys.CONTEXT_SCROLL_PAGEUP or keys.CONTEXT_SCROLL_PAGEDOWN then
passit = true
else
for key in pairs(MOUSE_KEYS) do for key in pairs(MOUSE_KEYS) do
if keys[key] then if keys[key] then
passit = true passit = true
@ -825,6 +832,7 @@ function ZScreen:onInput(keys)
end end
end end
end end
end
if not passit and self.pass_movement_keys then if not passit and self.pass_movement_keys then
passit = require('gui.dwarfmode').getMapKey(keys) passit = require('gui.dwarfmode').getMapKey(keys)
end end