From de0cdb96b20393814d03278b698d75cf3ac17efb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?=
Date: Wed, 2 Sep 2026 15:03:42 +0200
Subject: [PATCH] Cleanup
---
dn/kit-browser.cpp | 21 +++++++++------------
dn/kit-chrome.cpp | 6 +++---
dn/kit-chrome.hpp | 2 +-
dn/kit-viewer.cpp | 11 +++--------
dn/kit.cpp | 44 ++++++++++++++++++++++++++++++++------------
dn/kit.hpp | 21 +++++++++++----------
dn/sheet.cpp | 7 +++++++
dn/window.cpp | 35 +++++++++++++----------------------
8 files changed, 79 insertions(+), 68 deletions(-)
diff --git a/dn/kit-browser.cpp b/dn/kit-browser.cpp
index 35f2c27..be663ac 100644
--- a/dn/kit-browser.cpp
+++ b/dn/kit-browser.cpp
@@ -2143,7 +2143,7 @@ pack_standin_icons(Browser &b)
void
pack_toolbar_icons(Browser &b)
{
- const int px = max(16, int(lround(kIconPts * b.kit_.dpr_)));
+ const int px = b.kit_.icon_px();
for (const Spec &spec : kItems) {
const ActionDef &d = action_def(spec.action);
b.kit_.pack_icon(action_icon(d, false), px);
@@ -2646,9 +2646,13 @@ Browser::prepare(Kit &kit)
pack_standin_icons(*this);
if (!this->show_names_)
return;
+
for (const File &f : this->files_) {
- if (f.cell.empty() || f.cap.h <= 0)
+ // Exactly the band paint() draws, asked the same way, so that the cache
+ // is warm for what is about to be drawn and for nothing else.
+ if (!thumb_in_band(*this, f, 0.f) || f.cap.h <= 0)
continue;
+
Label lab;
lab.text = f.cap_text;
lab.wrap = true;
@@ -2673,9 +2677,7 @@ Browser::paint(Kit &kit) const
const Colour frame = kit.colours_[ColourFrame];
for (int i = 0; i < int(this->files_.size()); ++i) {
const File &f = this->files_[size_t(i)];
- if (f.cell.w <= 0)
- continue;
- if (f.cell.bottom() < this->r.y || f.cell.y > this->r.bottom())
+ if (!thumb_in_band(*this, f, 0.f))
continue;
const int tw = f.tile.w > 0 ? f.tile.w : th;
const int thp = f.tile.h > 0 ? f.tile.h : th;
@@ -2754,7 +2756,7 @@ make_browser_page(
if (page->toolbar)
page->toolbar->actor = page->actor;
if (page->app_menu)
- page->app_menu->build(page->menu_tree, page->actor);
+ page->app_menu->build(kit, page->menu_tree, page->actor);
b->places_dirty_ = true;
b->page_ = page.get();
if (out)
@@ -2865,14 +2867,9 @@ Browser::set_screen_profile(
this->screen_icc_ = std::move(screen_icc);
this->screen_profile_ = std::move(profile);
this->kit_.bake_colours(this->cmm_.get(), this->screen_profile_.get());
- if (this->kit_.renderer_) {
- const Colour well = this->kit_.colours_[ColourWell];
- const Colour tile = this->kit_.colours_[ColourToolbarBottom];
- this->kit_.renderer_->set_well_colour(well.r, well.g, well.b);
- this->kit_.renderer_->set_checker_colour(tile.r, tile.g, tile.b);
+ if (this->kit_.renderer_)
this->kit_.renderer_->set_transfer(
profile_transfer(this->screen_profile_.get()));
- }
if (reload_thumbs) {
invalidate_thumbs(*this);
enqueue_thumbs(*this);
diff --git a/dn/kit-chrome.cpp b/dn/kit-chrome.cpp
index 9a3fd57..51ccbd4 100644
--- a/dn/kit-chrome.cpp
+++ b/dn/kit-chrome.cpp
@@ -54,9 +54,9 @@ Sidebar::key(Kit &kit, const Key &ev)
// --- Context menu ------------------------------------------------------------
void
-ContextMenu::fill_items(const QUrl &url)
+ContextMenu::fill_items(Kit &kit, const QUrl &url)
{
- clear();
+ clear(kit);
this->min_w = 200.f;
// Open With and Move to Trash are filesystem operations on a real file.
@@ -125,7 +125,7 @@ void
ContextMenu::show(Kit &kit, const QUrl &url, Rect anchor, bool kbd)
{
kit.forget_tree(this);
- fill_items(url);
+ fill_items(kit, url);
bool any = false;
if (this->col) {
for (const auto &k : this->col->kids) {
diff --git a/dn/kit-chrome.hpp b/dn/kit-chrome.hpp
index ecd3a8a..e041824 100644
--- a/dn/kit-chrome.hpp
+++ b/dn/kit-chrome.hpp
@@ -44,7 +44,7 @@ struct ContextMenu : Menu {
void show(Kit &kit, const QUrl &url, Rect anchor, bool kbd);
private:
- void fill_items(const QUrl &url);
+ void fill_items(Kit &kit, const QUrl &url);
};
void dialog_about(Kit &kit, Dialog &dialog);
diff --git a/dn/kit-viewer.cpp b/dn/kit-viewer.cpp
index c16b31e..dd88fec 100644
--- a/dn/kit-viewer.cpp
+++ b/dn/kit-viewer.cpp
@@ -388,7 +388,7 @@ struct Viewer::Worker {
static void
pack_toolbar_icons(Viewer &v)
{
- const int px = max(16, int(lround(kIconPts * v.kit_.dpr_)));
+ const int px = v.kit_.icon_px();
for (const Spec &spec : kItems) {
const ActionDef &d = action_def(spec.action);
v.kit_.pack_icon(action_icon(d, false), px);
@@ -1885,7 +1885,7 @@ make_viewer_page(Kit &kit, const HostActions &host, Viewer **out)
if (page->toolbar)
page->toolbar->actor = page->actor;
if (page->app_menu)
- page->app_menu->build(page->menu_tree, page->actor);
+ page->app_menu->build(kit, page->menu_tree, page->actor);
v->page_ = page.get();
if (out)
*out = v;
@@ -2025,15 +2025,10 @@ Viewer::set_screen_profile(
this->screen_profile_ = std::move(profile);
this->screen_profile_fallback_ = fallback;
this->kit_.bake_colours(this->cmm_.get(), this->screen_profile_.get());
- if (this->kit_.renderer_) {
- const Colour well = this->kit_.colours_[ColourWell];
- const Colour tile = this->kit_.colours_[ColourToolbarBottom];
- this->kit_.renderer_->set_well_colour(well.r, well.g, well.b);
- this->kit_.renderer_->set_checker_colour(tile.r, tile.g, tile.b);
+ if (this->kit_.renderer_)
this->kit_.renderer_->set_transfer(this->enable_cms_
? profile_transfer(this->screen_profile_.get())
: dawn::Transfer::Srgb);
- }
if (reload) {
this->restore_view_ = {true, this->scale_, this->pan_x_, this->pan_y_,
this->orientation_, this->angle_, this->view_locked_};
diff --git a/dn/kit.cpp b/dn/kit.cpp
index 5959071..cad79ab 100644
--- a/dn/kit.cpp
+++ b/dn/kit.cpp
@@ -697,7 +697,7 @@ void
Button::measure(Kit &kit, int, int)
{
const int px = kit.px(kFramePadX + this->pad_x);
- const int icon = kit.px(kIconPts);
+ const int icon = kit.icon_px();
int cw = 0;
int ch = kit.text_height(QStringLiteral("Ag"), 0, false);
if (this->icon) {
@@ -734,7 +734,7 @@ Button::paint(Kit &kit) const
kit.draw_border(
this->r, col(kit.colours_[ColourDivider]), kit.hairline());
const int px = kit.px(kFramePadX + this->pad_x);
- const int icon = kit.px(kIconPts);
+ const int icon = kit.icon_px();
const float ink_a = (this->enabled_ ? 1.f : 0.375f) *
(this->dim ? 0.5f : 1.f) * kit.ink_alpha();
if (this->icon)
@@ -2372,7 +2372,7 @@ menu_cols(const Kit &kit, const MenuItem &m)
{
MenuCols c;
c.accel_w = m.accel_col > 0 ? m.accel_col : m.accel_width(kit);
- c.chevron = m.sub ? kit.px(kIconPts) : 0;
+ c.chevron = m.sub ? kit.icon_px() : 0;
c.label_x = kit.px(kFramePadX * 2.f + kIconPts);
c.accel_x = m.r.w - kit.px(kFramePadX) - c.chevron - c.accel_w;
c.avail = max(1, c.accel_x - kit.px(kFramePadX) - c.label_x);
@@ -2720,18 +2720,24 @@ Menu::add_sep()
}
void
-Menu::clear()
+Menu::clear(Kit &kit)
{
+ // A sub is on the popup stack for as long as it is open, so dropping it
+ // here would leave kit.popups_ walking freed memory every frame.
+ for (auto &sub : this->subs_) {
+ if (sub)
+ sub->close(kit);
+ }
this->subs_.clear();
if (this->col)
this->col->erase_children();
}
void
-Menu::build(span