Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Downloader more stable on Mac. #80

Merged
merged 1 commit into from
Jan 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Make Downloader more stable on Mac.
Fixes crash when using Show/HideWithEffect and keeps focus on the
downloader window even when a popup is being shown.

Fixes #54
jpd236 committed Nov 25, 2019
commit b984286cec37cbd37fbb4d5d0f8ddcb96f0e4b1b
11 changes: 7 additions & 4 deletions scripts/download/gui/popup.lua
Original file line number Diff line number Diff line change
@@ -7,9 +7,9 @@ local function PopupWindow(parent)
-- A borderless dialog
local self = wx.wxDialog(
parent, wx.wxID_ANY, '', wx.wxDefaultPosition, wx.wxDefaultSize,
wx.wxFRAME_NO_TASKBAR + wx.wxFRAME_FLOAT_ON_PARENT + wx.wxWS_EX_TRANSIENT
wx.wxFRAME_NO_TASKBAR + wx.wxFRAME_FLOAT_ON_PARENT + wx.wxWS_EX_TRANSIENT
)

-- wxWindow:Fit is simply SetSize(GetBestSize()), but we need to adjust
-- both position and size
function self:Fit()
@@ -48,10 +48,13 @@ local function PopupWindow(parent)
function self:Popup(effect, timeout)
-- Move to the best position based on the current mouse pointer
self:Fit()
if effect then
if effect and effect ~= wx.wxSHOW_EFFECT_NONE then
self:ShowWithEffect(effect, timeout or 0)
else
self:Show()
-- On Mac, Show() causes focus to move to the popup.
-- Unclear why this is inconsistent between platforms, but since the
-- effect isn't supported anyway, this works fine.
self:ShowWithoutActivating()
end

-- Destroy the popup when the mouse leaves the parent window.
20 changes: 14 additions & 6 deletions scripts/download/gui/puzzle_grid.lua
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ local function TextGrid(parent, x_gap, y_gap)
-- @param col the column (0-indexed)
-- @param row the row (0-indexed)
-- @param[opt] data Custom item data for hyperlinked text.
-- @param[opt] is_span If true, don't factor into grid size.
-- @param[opt] is_span If true, don't factor into grid size.
-- This can be used for headers, etc. that cross multiple cells.
function self:Add(text, col, row, data, is_span)
local item = {col, row, text, data}
@@ -49,7 +49,7 @@ local function TextGrid(parent, x_gap, y_gap)
self.item_width,
self.item_height
end

--- Override wxWindow::Fit to set a better min size
function self:Fit()
-- Find the rectangle of the bottom-right most item.
@@ -276,6 +276,14 @@ local function PuzzleGrid(parent, x_gap, y_gap)
local popup
--- Show a popup and underline on hover
function self:OnHover(puzzle)
-- Effects cause crashes on Mac when rapidly showing/hiding popups.
local effect
if wx.__WXMAC__ then
effect = wx.wxSHOW_EFFECT_NONE
else
effect = wx.wxSHOW_EFFECT_BLEND
end

-- Destroy popup
if puzzle then
if not popup then
@@ -288,9 +296,9 @@ local function PuzzleGrid(parent, x_gap, y_gap)
end
-- Show it
popup:set_puzzle(puzzle)
popup:Popup(wx.wxSHOW_EFFECT_BLEND, 100)
popup:Popup(effect, 100)
elseif popup then
popup:HideWithEffect(wx.wxSHOW_EFFECT_BLEND, 100)
popup:HideWithEffect(effect, 100)
popup:Destroy()
end
end
@@ -331,7 +339,7 @@ local function PuzzleGrid(parent, x_gap, y_gap)
self:PopupMenu(menu)
end
end)

-- Cleanup when we are destroyed
self:Connect(self:GetId(), wx.wxEVT_DESTROY, function(evt)
for _, filename in ipairs(filenames) do
@@ -421,4 +429,4 @@ return setmetatable({
Month = Month,
List = List,
TextGrid = TextGrid,
}, { __call = PuzzleGrid })
}, { __call = PuzzleGrid })