Skip to content

ReaderFooter: document position is not used - #14076

Merged
hius07 merged 7 commits into
koreader:masterfrom
hius07:footer-no-doc-pos
Aug 17, 2025
Merged

hius07 merged 7 commits into
koreader:masterfrom
hius07:footer-no-doc-pos

Conversation

@hius07

@hius07 hius07 commented Jul 21, 2025 •

Copy link
Copy Markdown
Member

The footer does not use "document position".
No need to have separate code paths for "page" and "scroll" view modes.
Removed duplicated code and code execution when building and showing the footer.
Closes #14065.

Despite of the above optimization, the footer text generator is still executed 3 times when opening an epub book, but looks like this cannot be fixed with the current architecture.


This change is Reviewable

@hius07

hius07 commented Jul 21, 2025 •

Copy link
Copy Markdown
Member Author

if self.settings.disabled then
-- footer feature is completely disabled, stop initialization now
self:disableFooter()
return
end

function ReaderFooter:disableFooter()
self.onReaderReady = function() end
self.resetLayout = function() end
self.updateFooterPage = function() end
self.updateFooterPos = function() end
self.mode = self.mode_list.off
self.view.footer_visible = false
end

This ancient method is used in unit tests only. Currently the footer cannot be disabled in the UI.
I think the method is not needed anymore.
(I remember long ago the footer could be turned on/off in the bottom config menu, maybe this method was used there)

@Frenzie

Frenzie commented Jul 21, 2025

Copy link
Copy Markdown
Member

It sounds useful, but if it seems redundant I guess it is. :-))

@hius07

hius07 commented Jul 21, 2025

Copy link
Copy Markdown
Member Author

On the other hand, I tried to set disabled = true manually in settings.reader.lua.
It actually works fine, shows the book text in full screen, removes the footer and its upper menu.
Let it be (without the UI setting) for alt status bar lovers.

@Frenzie

Frenzie commented Jul 21, 2025

Copy link
Copy Markdown
Member

Sounds good.

end
end,
page_progress = function(footer)
if footer.pageno then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure there is always a pageno ? (or/and a self.view.state.page to which it is set in :init() - edit: that you just removed :). Sure there won't be some event processing ordering that could have at some points pageno still being nil ?
Our footer stuff is so brittle, that I'm just uneasy removing these safeguards :)
But trusting you.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the main point of investigation: to get the moment when pageno appears. I'm pretty sure it exists when calling the generators.
Also, look at the old code: this if is not a safeguard, it just switches to use position that definitely doesn't exist. The code path with position never happened.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the usage of self.view.state.page because the page is set in

function ReaderPaging:onReadSettings(config)
self.page_positions = config:readSetting("page_positions") or {}
self:_gotoPage(config:readSetting("last_page") or 1)

and the footer is drawn later in the "ReaderReady" handler.

Comment on lines -2316 to +2269
if not self.initial_pageno then
self.initial_pageno = pageno
end
self.initial_pageno = self.initial_pageno or pageno

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I'm sometimes tempted to write as you just did - but the 3 lines make it clearer, and avoid an assignment, which must be more costly than just a if check, dunno if Luajit would optimize it.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've read that this notation is recommended by the Lua creators, and it is optimized by the interpreter, the assignment is done when needed only.

Comment on lines 2286 to +2291
function ReaderFooter:onPosUpdate(pos, pageno)
self.position = pos
self.doc_height = self.ui.document.info.doc_height
if pageno then
self.pageno = pageno
if not self.initial_pageno then
self.initial_pageno = pageno
end
self.pages = self.ui.document:getPageCount()
self.ui.doc_settings:saveSetting("doc_pages", self.pages) -- for Book information
end
self:updateFooterPos()
self.pageno = pageno
self.initial_pageno = self.initial_pageno or pageno
self.pages = self.ui.document:getPageCount()
self.ui.doc_settings:saveSetting("doc_pages", self.pages) -- for Book information
self:onUpdateFooter()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, are we sure we always get pageno passed ?
I'm no longer confortable with all this, but I remember in the past I had been bothered by the different onPosUpdate/onPageUpdate (may be not in ReaderFooter, but elsewhere) and I'd rather not touch them if I don't have to :))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "PosUpdate" event is sent by ReaderRolling only, and it always passes the target page number as the second arg.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pleased to confirm that the above questions were the first/main questions that I have asked to myself and have investigated through the massive print-debugging.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And, as I sadly mentioned in the first post, our footer architecture is not best optimized, some methods are called twice or more to draw the footer.

@hius07

hius07 commented Jul 21, 2025

Copy link
Copy Markdown
Member Author

If the release is coming soon, we can postpone this.

@Frenzie

Frenzie commented Jul 21, 2025

Copy link
Copy Markdown
Member

Depends a bit on the weather. It looks fairly outdoorsy the rest of the week. In any event, it won't be tomorrow.

Screenshot_2025-07-21-20-39-15-55_ad5adcf628c7098b9d20d28f2b3c52f8

@hius07

hius07 commented Jul 22, 2025

Copy link
Copy Markdown
Member Author

Avoid one more duplication.

@hius07
hius07 merged commit 7d40045 into koreader:master Aug 17, 2025
@hius07
hius07 deleted the footer-no-doc-pos branch August 17, 2025 04:42
@hius07 hius07 added this to the 2025.10 milestone Aug 17, 2025
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Status bar: current position instead of a page

3 participants