Ui, project: on screen means active and not suspended; Crafter.Graphics at c006519

A conversation counted as on screen while its window was up and no
close was pending, and a text for the conversation on screen is stored
read and not notified. A window is up behind a lock screen too, behind
another application, minimised, with the display off: a text for the
conversation left open there was marked read unseen, and no
notification told of it.

The compositor says of a window whether it counts as the active one and
whether it is ordinarily being repainted: xdg_toplevel's `activated`
state and, from version 6 of xdg_wm_base, `suspended`. The pinned
library dropped both. Crafter.Graphics c006519, one commit on the pin
before, keeps them on the window (Window::activated, suspended) and
fires onToplevelState when a configure changes either.

Now the window is on screen while it is up, no close is pending, and
the compositor counts it active and has not suspended it: both, since
which of the two a lock screen or another window in front changes is
the compositor's choice. When the compositor's word changes the app
does what it does at a close and at a Show: out of sight Sync is told
that no conversation is open, so a text is stored unread and notified;
in sight again the open conversation is read and its notification
withdrawn. Opened waits for it too: a conversation is read once its
window is on screen in this sense, not because the window was made or
the conversation opened in it. A window that is visible beside the
active one counts as not on screen, and its texts notify until it is
the active one. Under --headless the log has the compositor's word at
each change after the window is made.

Tested: on the bench, the build before against this one on KWin 6.8.0,
a text for the open conversation in each state of the window. Behind
KWin's lock screen, behind another application's window, minimised and
with the display off it was stored read with no notification; it is
stored unread and notified, and the notification goes when the window
is on screen again. KWin reports the window not active behind the other
application, suspended with the display off, and both under the lock
and minimised. A conversation opened while the app has no window and
another application is active gets a window KWin makes the active one,
and is read; one opened in a window that is behind another
application's stays unread until that window is active.
This commit is contained in:
Jorijn van der Graaf 2026-11-17 00:57:08 +01:00
commit 75d1cbdce1
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
3 changed files with 33 additions and 12 deletions

View file

@ -71,6 +71,7 @@ export namespace ImsdMessages::Ui {
deleteSub.reset(); deleteSub.reset();
resizeSub.reset(); resizeSub.reset();
closeSub.reset(); closeSub.reset();
seenSub.reset();
day.reset(); day.reset();
frames.reset(); frames.reset();
canvas.reset(); canvas.reset();
@ -153,15 +154,29 @@ export namespace ImsdMessages::Ui {
return true; return true;
} }
// Whether the window shows the screens: it is up, and no close is // Whether the screens count as seen: the window is up, no close is
// waiting for its Hide. // waiting for its Hide, and the compositor counts it the active
bool OnScreen() const noexcept { return canvas.has_value() && hideIdle == 0; } // window and has not suspended it (the library's Window::activated
// and suspended, xdg_toplevel's states). A window behind a lock
// screen or another application, minimised or with the display
// off, is up all the same.
bool OnScreen() const noexcept { return canvas.has_value() && hideIdle == 0 && canvas->Window().activated && !canvas->Window().suspended; }
// The compositor's word on the window changed. Out of sight, no
// conversation is on screen: a text for the open one is stored
// unread and notified, as after a close. In sight again, the open
// conversation is read, as at a Show.
void SeenChanged() {
if (verbose) Log(std::format("window {}{}", canvas->Window().activated ? "active" : "not active", canvas->Window().suspended ? ", suspended" : ""));
if (OnScreen()) Opened();
else if (sync) sync->SetOpenConversation(std::nullopt);
}
// Creates the window; shows it again after a Hide. // Creates the window; shows it again after a Hide.
void Show() { void Show() {
const bool kept = KeepWindow(); const bool kept = KeepWindow();
if (canvas) { if (canvas) {
if (kept) Opened(); // a close taken back: the kept conversation is on screen again if (kept) Opened(); // a close taken back: the kept conversation is on screen again, if the window is seen
return; return;
} }
canvas.emplace(); canvas.emplace();
@ -277,8 +292,9 @@ export namespace ImsdMessages::Ui {
Dirty(); Dirty();
}); });
closeSub.emplace(&w.onClose, [this] { Close(); }); closeSub.emplace(&w.onClose, [this] { Close(); });
seenSub.emplace(&w.onToplevelState, [this] { SeenChanged(); });
Reload(); Reload();
Opened(); Opened(); // read once the new window counts as seen: now, or at the call that finds it so
if (fresh || (view && view->compose.focused)) ShowCaret(); // the blink a hide stopped if (fresh || (view && view->compose.focused)) ShowCaret(); // the blink a hide stopped
w.Render(); w.Render();
frames->RequestRedraw(); frames->RequestRedraw();
@ -351,10 +367,12 @@ export namespace ImsdMessages::Ui {
ShowCaret(); ShowCaret();
} }
// The conversation the window shows: read, its notification gone, // The conversation the window shows, while the screens count as
// Sync told (a text for it is stored read). // seen (OnScreen): read, its notification gone, Sync told (a text
// for it is stored read). Until then nothing: SeenChanged or the
// next Show calls again.
void Opened() { void Opened() {
if (!view) return; if (!view || !OnScreen()) return;
if (store.MarkRead(view->key) > 0) Reload(); if (store.MarkRead(view->key) > 0) Reload();
if (sync) sync->SetOpenConversation(view->key); if (sync) sync->SetOpenConversation(view->key);
if (onConversationOpened) onConversationOpened(view->key); if (onConversationOpened) onConversationOpened(view->key);
@ -505,7 +523,7 @@ export namespace ImsdMessages::Ui {
// whatever a turn of the wheel did over the empty one. // whatever a turn of the wheel did over the empty one.
view->scroll = ScrollState{}; view->scroll = ScrollState{};
view->stickToBottom = true; view->stickToBottom = true;
if (OnScreen()) Opened(); // hidden, the kept conversation stays unread and keeps its notification: Show opens it if (OnScreen()) Opened(); // not on screen, the kept conversation stays unread and keeps its notification: Show or SeenChanged opens it
} }
} }
// The drafts of the typed addresses that were left follow it too. // The drafts of the typed addresses that were left follow it too.
@ -559,8 +577,9 @@ export namespace ImsdMessages::Ui {
const std::size_t before = view->messages.size(); const std::size_t before = view->messages.size();
view->messages = store.Conversation(view->key); view->messages = store.Conversation(view->key);
if (view->messages.size() > before) view->stickToBottom = true; if (view->messages.size() > before) view->stickToBottom = true;
// Shown texts are read; a conversation kept across a hide is // Texts on screen are read; a conversation kept across a hide
// not on screen, and its new texts stay unread until it is. // or in a window that is not seen is not on screen, and its
// new texts stay unread until it is.
if (OnScreen() && sync && store.MarkRead(view->key) > 0) convs = GroupConversations(store.All()); if (OnScreen() && sync && store.MarkRead(view->key) > 0) convs = GroupConversations(store.All());
} }
Dirty(); Dirty();
@ -1042,5 +1061,6 @@ export namespace ImsdMessages::Ui {
TextInputState lastTextInput; TextInputState lastTextInput;
std::optional<Crafter::EventListener<void>> resizeSub; std::optional<Crafter::EventListener<void>> resizeSub;
std::optional<Crafter::EventListener<void>> closeSub; std::optional<Crafter::EventListener<void>> closeSub;
std::optional<Crafter::EventListener<void>> seenSub;
}; };
} }

View file

@ -240,6 +240,7 @@ export namespace ImsdMessages::Ui {
} }
Crafter::Window& Window() noexcept { return *window; } Crafter::Window& Window() noexcept { return *window; }
const Crafter::Window& Window() const noexcept { return *window; }
Crafter::Font& Font() noexcept { return *font; } Crafter::Font& Font() noexcept { return *font; }
WordWrapper& Wrapper() noexcept { return *wrapper; } WordWrapper& Wrapper() noexcept { return *wrapper; }
float Scale() const noexcept { return window->scale > 0 ? window->scale : 1.0f; } float Scale() const noexcept { return window->scale > 0 ? window->scale : 1.0f; }

View file

@ -85,7 +85,7 @@ extern "C" Configuration CrafterBuildProject(std::span<const std::string_view> a
// The window library. // The window library.
Configuration* graphics = local Configuration* graphics = local
? LocalProject({ .projectFile = "../Crafter/Crafter.Graphics/project.cpp", .args = depArgs }) ? LocalProject({ .projectFile = "../Crafter/Crafter.Graphics/project.cpp", .args = depArgs })
: GitProject({ .source = { .url = "https://forgejo.catcrafts.net/Catcrafts/Crafter.Graphics.git", .commit = "364d2101c973905e4ace263ac2b2085e75de725e" }, .args = depArgs }); : GitProject({ .source = { .url = "https://forgejo.catcrafts.net/Catcrafts/Crafter.Graphics.git", .commit = "c006519fa0b9e294b625527734309f03a5b812a9" }, .args = depArgs });
// imsd-messages-core — numbers, time, the model, word wrap, gestures, // imsd-messages-core — numbers, time, the model, word wrap, gestures,
// the message field's editing, the store and the sync logic: std + // the message field's editing, the store and the sync logic: std +