From 45a4aac3d3d9d815a384e854af001294bf3fbe6f Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Tue, 7 Feb 2023 01:01:05 +0100 Subject: [PATCH] Notification: Fence the *display* update in an attempt to avoid upsetting some boards... (#10083) Re: https://github.com/koreader/koreader/issues/9806#issuecomment-1416827447 Depends on https://github.com/koreader/koreader-base/pull/1576 Includes assorted cosmetics tweaks related to duplicate `setDirty` calls when instantiating widgets that already have an `onShow` handler doing it. (I left widgets doing it in `update` instead of `init` alone, on the assumption that callers *may* be relying on that behavior when updating widgets at runtime. This might actually never matter, and it certainly didn't for ScreenSaverWidget, which is why I removed it from there ;p). --- base | 2 +- frontend/apps/reader/modules/readerfont.lua | 4 +- frontend/apps/reader/modules/readerview.lua | 4 +- frontend/ui/widget/buttondialogtitle.lua | 4 +- frontend/ui/widget/configdialog.lua | 1 - frontend/ui/widget/confirmbox.lua | 6 +-- frontend/ui/widget/datetimewidget.lua | 3 -- frontend/ui/widget/dictquicklookup.lua | 4 -- frontend/ui/widget/infomessage.lua | 6 +-- frontend/ui/widget/keyboardlayoutdialog.lua | 2 +- frontend/ui/widget/multiconfirmbox.lua | 2 +- frontend/ui/widget/naturallightwidget.lua | 1 - frontend/ui/widget/notification.lua | 43 +++++++++++++-------- frontend/ui/widget/qrmessage.lua | 2 +- frontend/ui/widget/screensaverwidget.lua | 3 -- frontend/ui/widget/textviewer.lua | 5 +-- frontend/ui/widget/toggleswitch.lua | 2 +- frontend/ui/widget/virtualkeyboard.lua | 10 +++-- plugins/opds.koplugin/opdscatalog.lua | 2 +- plugins/vocabbuilder.koplugin/main.lua | 6 +-- 20 files changed, 54 insertions(+), 58 deletions(-) diff --git a/base b/base index 97995c2ce..e23fd2715 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit 97995c2ce333fbb4fbba737b20fa92b43a914405 +Subproject commit e23fd271508970ef4bb79d2de69a9b9525f65195 diff --git a/frontend/apps/reader/modules/readerfont.lua b/frontend/apps/reader/modules/readerfont.lua index 29e2b0c08..d6ea6a45b 100644 --- a/frontend/apps/reader/modules/readerfont.lua +++ b/frontend/apps/reader/modules/readerfont.lua @@ -430,14 +430,14 @@ end function ReaderFont:onIncreaseFontSize(ges) local delta_int = self:gesToFontSize(ges) - Notification:notify(_("Increasing font size…"), true) + Notification:notify(_("Increasing font size…"), nil, true) self:onChangeSize(delta_int) return true end function ReaderFont:onDecreaseFontSize(ges) local delta_int = self:gesToFontSize(ges) - Notification:notify(_("Decreasing font size…"), true) + Notification:notify(_("Decreasing font size…"), nil, true) self:onChangeSize(-delta_int) return true end diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index 91ff0ffed..bc2696432 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -1154,9 +1154,7 @@ function ReaderView:onToggleReadingOrder() self.inverse_reading_order = not self.inverse_reading_order self:setupTouchZones() local is_rtl = self.inverse_reading_order ~= BD.mirroredUILayout() -- mirrored reading - UIManager:show(Notification:new{ - text = is_rtl and _("RTL page turning.") or _("LTR page turning."), - }) + Notification:notify(is_rtl and _("RTL page turning.") or _("LTR page turning.")) return true end diff --git a/frontend/ui/widget/buttondialogtitle.lua b/frontend/ui/widget/buttondialogtitle.lua index 3a72a80e3..ac8426362 100644 --- a/frontend/ui/widget/buttondialogtitle.lua +++ b/frontend/ui/widget/buttondialogtitle.lua @@ -107,7 +107,7 @@ end function ButtonDialogTitle:onShow() UIManager:setDirty(self, function() - return "ui", self[1][1].dimen + return "ui", self[1][1].dimen -- i.e., MovableContainer end) end @@ -132,7 +132,7 @@ end function ButtonDialogTitle:paintTo(...) InputContainer.paintTo(self, ...) - self.dimen = self[1][1].dimen -- FrameContainer + self.dimen = self[1][1].dimen end return ButtonDialogTitle diff --git a/frontend/ui/widget/configdialog.lua b/frontend/ui/widget/configdialog.lua index 1e4feaaf2..724ee7427 100644 --- a/frontend/ui/widget/configdialog.lua +++ b/frontend/ui/widget/configdialog.lua @@ -611,7 +611,6 @@ function ConfigOption:init() num_buttons = #self.options[c].values, position = self.options[c].default_pos, callback = function(arg) - if arg == "-" or arg == "+" then Notification:setNotifySource(Notification.SOURCE_BOTTOM_MENU_FINE) self.config:onConfigFineTuneChoose(self.options[c].values, self.options[c].name, diff --git a/frontend/ui/widget/confirmbox.lua b/frontend/ui/widget/confirmbox.lua index 378efb4b4..656319187 100644 --- a/frontend/ui/widget/confirmbox.lua +++ b/frontend/ui/widget/confirmbox.lua @@ -185,7 +185,7 @@ end function ConfirmBox:onShow() UIManager:setDirty(self, function() - return "ui", self[1][1].dimen + return "ui", self.movable.dimen end) if self.flush_events_on_show then -- Discard queued and upcoming input events to avoid accidental dismissal @@ -195,7 +195,7 @@ end function ConfirmBox:onCloseWidget() UIManager:setDirty(nil, function() - return "ui", self[1][1].dimen + return "ui", self.movable.dimen end) end @@ -207,7 +207,7 @@ function ConfirmBox:onClose() end function ConfirmBox:onTapClose(arg, ges) - if ges.pos:notIntersectWith(self[1][1].dimen) then + if ges.pos:notIntersectWith(self.movable.dimen) then self:onClose() end -- Don't let it propagate to underlying widgets diff --git a/frontend/ui/widget/datetimewidget.lua b/frontend/ui/widget/datetimewidget.lua index 59ad73c21..f35c529b4 100644 --- a/frontend/ui/widget/datetimewidget.lua +++ b/frontend/ui/widget/datetimewidget.lua @@ -394,9 +394,6 @@ function DateTimeWidget:createLayout() } } self:refocusWidget() - UIManager:setDirty(self, function() - return "ui", self.date_frame.dimen - end) end function DateTimeWidget:update(year, month, day, hour, min, sec) diff --git a/frontend/ui/widget/dictquicklookup.lua b/frontend/ui/widget/dictquicklookup.lua index 575862bc0..9ffada6b8 100644 --- a/frontend/ui/widget/dictquicklookup.lua +++ b/frontend/ui/widget/dictquicklookup.lua @@ -712,10 +712,6 @@ function DictQuickLookup:init() -- We're a new window table.insert(DictQuickLookup.window_list, self) - - UIManager:setDirty(self, function() - return "partial", self.dict_frame.dimen - end) end -- Whether currently DictQuickLookup is working without a document. diff --git a/frontend/ui/widget/infomessage.lua b/frontend/ui/widget/infomessage.lua index e9f8a2e5f..0c4aaec75 100644 --- a/frontend/ui/widget/infomessage.lua +++ b/frontend/ui/widget/infomessage.lua @@ -213,7 +213,7 @@ function InfoMessage:onCloseWidget() end UIManager:setDirty(nil, function() - return "ui", self[1][1].dimen + return "ui", self.movable.dimen end) end @@ -231,7 +231,7 @@ function InfoMessage:onShow() end -- set our region to be dirty, so UImanager will call our paintTo() UIManager:setDirty(self, function() - return "ui", self[1][1].dimen + return "ui", self.movable.dimen end) if self.flush_events_on_show then -- Discard queued and upcoming input events to avoid accidental dismissal @@ -254,7 +254,7 @@ end function InfoMessage:getVisibleArea() if not self.invisible then - return self[1][1].dimen + return self.movable.dimen end end diff --git a/frontend/ui/widget/keyboardlayoutdialog.lua b/frontend/ui/widget/keyboardlayoutdialog.lua index f3eb9791d..0c66393d3 100644 --- a/frontend/ui/widget/keyboardlayoutdialog.lua +++ b/frontend/ui/widget/keyboardlayoutdialog.lua @@ -180,7 +180,7 @@ end function KeyboardLayoutDialog:onCloseWidget() UIManager:setDirty(nil, function() - return "ui", self[1][1].dimen + return "ui", self.movable.dimen end) end diff --git a/frontend/ui/widget/multiconfirmbox.lua b/frontend/ui/widget/multiconfirmbox.lua index e261ff000..569a60a86 100644 --- a/frontend/ui/widget/multiconfirmbox.lua +++ b/frontend/ui/widget/multiconfirmbox.lua @@ -147,7 +147,7 @@ end function MultiConfirmBox:onShow() UIManager:setDirty(self, function() - return "ui", self[1][1].dimen + return "ui", self[1][1].dimen -- i.e., MovableContainer end) end diff --git a/frontend/ui/widget/naturallightwidget.lua b/frontend/ui/widget/naturallightwidget.lua index c90272727..397a5da64 100644 --- a/frontend/ui/widget/naturallightwidget.lua +++ b/frontend/ui/widget/naturallightwidget.lua @@ -329,7 +329,6 @@ function NaturalLightWidget:createMainContent(width, height) table.insert(self.fl_container, vertical_group) -- Reset container height to what it actually contains self.fl_container.dimen.h = vertical_group:getSize().h - UIManager:setDirty(self, "ui") return self.fl_container end diff --git a/frontend/ui/widget/notification.lua b/frontend/ui/widget/notification.lua index a0e8fd706..c927e3f75 100644 --- a/frontend/ui/widget/notification.lua +++ b/frontend/ui/widget/notification.lua @@ -23,22 +23,30 @@ local Input = Device.input local band = bit.band -- The following constants are positions in a bitfield -local SOURCE_BOTTOM_MENU_ICON = 0x0001 -- icons in bottom menu -local SOURCE_BOTTOM_MENU_TOGGLE = 0x0002 -- toggles in bottom menu -local SOURCE_BOTTOM_MENU_FINE = 0x0004 -- toggles with fine-tuning ("increase", "+" etc) -local SOURCE_BOTTOM_MENU_MORE = 0x0008 -- three dots in bottom menu +local SOURCE_BOTTOM_MENU_ICON = 0x0001 -- icons in bottom menu +local SOURCE_BOTTOM_MENU_TOGGLE = 0x0002 -- toggles in bottom menu +local SOURCE_BOTTOM_MENU_FINE = 0x0004 -- toggles with fine-tuning ("increase", "+" etc) +local SOURCE_BOTTOM_MENU_MORE = 0x0008 -- three dots in bottom menu local SOURCE_BOTTOM_MENU_PROGRESS = 0x0010 -- progress indicator on bottom menu -local SOURCE_DISPATCHER = 0x0020 -- dispatcher -local SOURCE_OTHER = 0x0040 -- all other sources (e.g. keyboard) +local SOURCE_DISPATCHER = 0x0020 -- dispatcher +local SOURCE_OTHER = 0x0040 -- all other sources (e.g. keyboard) -- All bottom menu bits -local SOURCE_BOTTOM_MENU = SOURCE_BOTTOM_MENU_ICON + SOURCE_BOTTOM_MENU_TOGGLE + SOURCE_BOTTOM_MENU_FINE + - SOURCE_BOTTOM_MENU_MORE + SOURCE_BOTTOM_MENU_PROGRESS +local SOURCE_BOTTOM_MENU = SOURCE_BOTTOM_MENU_ICON + + SOURCE_BOTTOM_MENU_TOGGLE + + SOURCE_BOTTOM_MENU_FINE + + SOURCE_BOTTOM_MENU_MORE + + SOURCE_BOTTOM_MENU_PROGRESS -- these values can be changed here -local SOURCE_SOME = SOURCE_BOTTOM_MENU_FINE + SOURCE_DISPATCHER -local SOURCE_DEFAULT = SOURCE_SOME + SOURCE_BOTTOM_MENU_MORE + SOURCE_BOTTOM_MENU_PROGRESS -local SOURCE_ALL = SOURCE_BOTTOM_MENU + SOURCE_DISPATCHER + SOURCE_OTHER +local SOURCE_SOME = SOURCE_BOTTOM_MENU_FINE + + SOURCE_DISPATCHER +local SOURCE_DEFAULT = SOURCE_SOME + + SOURCE_BOTTOM_MENU_MORE + + SOURCE_BOTTOM_MENU_PROGRESS +local SOURCE_ALL = SOURCE_BOTTOM_MENU + + SOURCE_DISPATCHER + + SOURCE_OTHER local Notification = InputContainer:extend{ face = Font:getFace("x_smallinfofont"), @@ -140,10 +148,11 @@ function Notification:getNotifySource() return self.notify_source end --- show popups if `self.notify_source` is not masked by the setting `notification_sources_to_show_mask` -function Notification:notify(arg, refresh_after) +-- Display a notification popup if `source` or `self.notify_source` is not masked by the `notification_sources_to_show_mask` setting +function Notification:notify(arg, source, refresh_after) + source = source or self.notify_source local mask = G_reader_settings:readSetting("notification_sources_to_show_mask") or self.SOURCE_DEFAULT - if self.notify_source and band(mask, self.notify_source) ~= 0 then + if source and band(mask, self.notify_source) ~= 0 then UIManager:show(Notification:new{ text = arg, }) @@ -186,9 +195,11 @@ function Notification:onCloseWidget() end function Notification:onShow() - -- triggered by the UIManager after we got successfully shown (not yet painted) + -- NOTE: We use the elusive "[ui]" mode solely for the sake of NTX boards flagged as unreliable, + -- in the hope that this will save them from an EPDC race that might make them horribly crash. + -- c.f., https://github.com/koreader/koreader/issues/9806#issuecomment-1416827447 UIManager:setDirty(self, function() - return "ui", self.frame.dimen + return "[ui]", self.frame.dimen end) if self.timeout then UIManager:scheduleIn(self.timeout, function() UIManager:close(self) end) diff --git a/frontend/ui/widget/qrmessage.lua b/frontend/ui/widget/qrmessage.lua index 328df8627..606aa1357 100644 --- a/frontend/ui/widget/qrmessage.lua +++ b/frontend/ui/widget/qrmessage.lua @@ -81,7 +81,7 @@ end function QRMessage:onCloseWidget() UIManager:setDirty(nil, function() - return "ui", self[1][1].dimen + return "ui", self[1][1].dimen -- i.e., frame end) end diff --git a/frontend/ui/widget/screensaverwidget.lua b/frontend/ui/widget/screensaverwidget.lua index aa817a5b0..f86e691aa 100644 --- a/frontend/ui/widget/screensaverwidget.lua +++ b/frontend/ui/widget/screensaverwidget.lua @@ -50,9 +50,6 @@ function ScreenSaverWidget:update() } self.dithered = true self[1] = self.main_frame - UIManager:setDirty(self, function() - return "full", self.main_frame.dimen - end) end function ScreenSaverWidget:onShow() diff --git a/frontend/ui/widget/textviewer.lua b/frontend/ui/widget/textviewer.lua index 324a98d0a..fa7055287 100644 --- a/frontend/ui/widget/textviewer.lua +++ b/frontend/ui/widget/textviewer.lua @@ -279,9 +279,6 @@ function TextViewer:init() dimen = self.region, self.movable, } - UIManager:setDirty(self, function() - return "partial", self.frame.dimen - end) end function TextViewer:onCloseWidget() @@ -292,7 +289,7 @@ end function TextViewer:onShow() UIManager:setDirty(self, function() - return "ui", self.frame.dimen + return "partial", self.frame.dimen end) return true end diff --git a/frontend/ui/widget/toggleswitch.lua b/frontend/ui/widget/toggleswitch.lua index a92abc521..85ecd6af4 100644 --- a/frontend/ui/widget/toggleswitch.lua +++ b/frontend/ui/widget/toggleswitch.lua @@ -229,7 +229,7 @@ function ToggleSwitch:onTapSelect(arg, gev) end) UIManager:tickAfterNext(function() - Notification:setNotifySource(Notification.SOURCE_OTHER) -- only allow events, if they are activated + Notification:resetNotifySource() end) end return true diff --git a/frontend/ui/widget/virtualkeyboard.lua b/frontend/ui/widget/virtualkeyboard.lua index 4ebead564..4c87313cd 100644 --- a/frontend/ui/widget/virtualkeyboard.lua +++ b/frontend/ui/widget/virtualkeyboard.lua @@ -347,7 +347,7 @@ function VirtualKey:update_keyboard(want_flash, want_a2) -- We flash the *full* keyboard when we release a hold. if want_flash then UIManager:setDirty(self.keyboard, function() - return "flashui", self.keyboard[1][1].dimen + return "flashui", self.keyboard[1][1].dimen -- i.e., keyboard_frame end) else local refresh_type = "ui" @@ -506,7 +506,7 @@ end function VirtualKeyPopup:onCloseWidget() self:free() UIManager:setDirty(nil, function() - return "ui", self[1][1].dimen + return "ui", self[1][1].dimen -- i.e., keyboard_frame end) end @@ -747,7 +747,7 @@ function VirtualKeyPopup:init() self[1] = position_container UIManager:show(self) - + -- Ensure the post-paint refresh will be able to grab updated coordinates from keyboard_frame by using a refresh function UIManager:setDirty(self, function() return "ui", keyboard_frame.dimen end) @@ -923,7 +923,7 @@ function VirtualKeyboard:_refresh(want_flash, fullscreen) return end UIManager:setDirty(self, function() - return refresh_type, self[1][1].dimen + return refresh_type, self[1][1].dimen -- i.e., keyboard_frame end) end @@ -1040,6 +1040,8 @@ function VirtualKeyboard:addKeys() dimen = Screen:getSize(), keyboard_frame, } + -- Beware, this won't be updated post-paint, so the coordinates will stay at (0, 0) + -- (i.e., only the size is accurate, not the position). self.dimen = keyboard_frame:getSize() end diff --git a/plugins/opds.koplugin/opdscatalog.lua b/plugins/opds.koplugin/opdscatalog.lua index 5c8a2f208..555ce5e34 100644 --- a/plugins/opds.koplugin/opdscatalog.lua +++ b/plugins/opds.koplugin/opdscatalog.lua @@ -51,7 +51,7 @@ end function OPDSCatalog:onShow() UIManager:setDirty(self, function() - return "ui", self[1].dimen + return "ui", self[1].dimen -- i.e., FrameContainer end) end diff --git a/plugins/vocabbuilder.koplugin/main.lua b/plugins/vocabbuilder.koplugin/main.lua index aabfc689c..13f34d588 100644 --- a/plugins/vocabbuilder.koplugin/main.lua +++ b/plugins/vocabbuilder.koplugin/main.lua @@ -389,7 +389,7 @@ end function MenuDialog:onShow() UIManager:setDirty(self, function() - return "flashui", self[1][1].dimen + return "flashui", self[1][1].dimen -- i.e., FrameContainer end) end @@ -435,7 +435,7 @@ function MenuDialog:onConfigChoose(values, name, event, args, position) self:onChangeContextStatus(args, position) end end - UIManager:setDirty(nil, "ui", nil, true) + UIManager:setDirty(nil, "ui") end) end @@ -622,7 +622,7 @@ end function WordInfoDialog:onShow() UIManager:setDirty(self, function() - return "flashui", self[1][1].dimen + return "flashui", self[1][1].dimen -- i.e., MovableContainer end) end