Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions Docs/decisions/0002-autocomplete.md
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,12 @@ KWin offers `zwp_input_method_v1` only to the program it started (`lokalbot --kw

Where: `LinuxWindows/crates/lokalbot-platform/src/autocomplete/input_method/kwin_helper.rs` (`run`, `same_user`, `content_v3`, `Helper::event`).

### On KDE Plasma the ghost is an overlay pill, never preedit

KWin passes `zwp_input_method_context_v1.preedit_string` on to apps over `zwp_text_input_v3`, which has no commit-on-reset string, and Chromium, Electron, Firefox and Thunderbird commit active preedit into the document on mousedown or blur before telling KWin the field is gone ([#562](https://github.com/stevyhacker/LokalBot/issues/562)). Clearing preedit on deactivate arrives too late, so the KWin route draws the suggestion on a click-through `zwp_input_panel_v1` overlay surface that KWin anchors under the focused field's cursor rectangle, and sends the field only an empty preedit, to make a quiet field report its text. The pill's pixels live in an anonymous `memfd`, so the helper still writes no file but its socket. GTK and native Qt discard preedit on focus loss, so a live check needs a field that commits it on blur, as the browsers do.

Where: `LinuxWindows/crates/lokalbot-platform/src/autocomplete/input_method/overlay_pill.rs`, `kwin_helper.rs` (`Helper::show`, `Helper::nudge`), `input_method.rs` (`Core::with_overlay_ghost`), `tests/live_input_method.rs` (`commit_on_blur`).

## Consequences

- Every privacy check (grants, app and site exclusions, secure, code and private-window fields, the field's owner on Wayland) runs before any text is read and fails closed; typed text and server errors are never logged, and a withdrawn grant, edited source or changed privacy setting ends whatever it shaped, up to the accept key.
Expand Down
1 change: 1 addition & 0 deletions LinuxWindows/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions LinuxWindows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,9 @@ comes from reading Omarchy's repository; it has not been tried on Omarchy. See

Wayland lets no ordinary app take a key from another app, show text at its caret or type into it, so LokalBot
takes part as an input method there, the way language input tools do. It sees the text around the caret, and
shows a suggestion inline in the field, in the app's own text style with its usual underline for text not yet
entered. What it sees and keeps is in [PRIVACY.md](../PRIVACY.md).
shows a suggestion inline in the field on Sway, Hyprland and GNOME, or in a click-through overlay pill under the
caret on KDE Plasma (so browsers and mail apps that commit active IME preedit on blur never insert an unaccepted
suggestion). What it sees and keeps is in [PRIVACY.md](../PRIVACY.md).

| Desktop | How | Tried on |
| --- | --- | --- |
Expand All @@ -266,8 +267,8 @@ nothing. After an update, log out and back in once so Plasma starts the new help
| App | Sway | GNOME | KDE Plasma |
| --- | --- | --- | --- |
| GTK 3 and GTK 4 | Suggestions, accepts and Esc, run here | Suggestions, accepts and Esc, run here | GTK 3: suggestions, accepts and Esc, run here. GTK 4: a suggestion and its accept, run here |
| Firefox 159 (Wayland) | Suggestions, accepts and Esc, run here | Stays quiet without the Window Calls extension, which names the app. Works with a stand-in for it, run here; the extension itself has not been tried | Not run |
| Chrome 156 (Wayland) | Suggestions, accepts and Esc, run here, with no flags | As Firefox | Not run |
| Firefox 159 (Wayland) | Suggestions, accepts and Esc, run here | Stays quiet without the Window Calls extension, which names the app. Works with a stand-in for it, run here; the extension itself has not been tried | Suggestions, accepts, Esc and focus loss without committing, run here |
| Chrome 156 (Wayland) | Suggestions, accepts and Esc, run here, with no flags | As Firefox | Suggestions, accepts, Esc and focus loss without committing, run here |
| Older Chromium and Electron | From their documentation, they need `--enable-wayland-ime` before they use an input method at all. Not run | Same | Same |
| Qt 6 | From its documentation, it has text-input-v3. Not run | Same | A suggestion and its accept, run here |
| Qt 5 (Kate) | No input method reaches it, so no suggestions; typing is unaffected. Run here | Not run | KWin gives Qt 5 its own text input protocol, so it works: a suggestion and its accept, run here |
Expand Down
16 changes: 13 additions & 3 deletions LinuxWindows/crates/lokalbot-app/src/autocomplete/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -748,11 +748,12 @@ impl Autocomplete {
{
session.remaining = shown.clone();
}
let dark = self.appearance(cx).dark;
log::debug!(
"autocomplete: showing {} characters in the field",
shown.chars().count()
);
inline.show(&field, &shown);
inline.show_styled(&field, &shown, emphasis.chars().count(), dark);
self.inline_shown = true;
self.set_keys_active(true);
return;
Expand Down Expand Up @@ -887,6 +888,7 @@ impl Autocomplete {
}
return;
};
let dark = self.appearance(cx).dark;
let (Some(session), Some(current)) = (self.session.as_mut(), self.current.as_ref()) else {
return;
};
Expand All @@ -901,9 +903,17 @@ impl Autocomplete {
}
session.accept(&plan.chunk, &plan.edit.text, plan.edit.backward);
if let Some(inline) = &self.inline {
let (drawn, _) = drawn_ghost(session, &self.session_kind, &settings);
let (drawn, next_emphasis) = drawn_ghost(session, &self.session_kind, &settings);
let next = inline_text(&drawn, false).unwrap_or_default();
inline.accept(&current.field, &around.0, &around.1, &plan.edit, &next);
inline.accept_styled(
&current.field,
&around.0,
&around.1,
&plan.edit,
&next,
next_emphasis.chars().count(),
dark,
);
}
self.session_after = drop_graphemes(&self.session_after, plan.edit.forward);
crate::bridge::send(
Expand Down
2 changes: 2 additions & 0 deletions LinuxWindows/crates/lokalbot-platform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ png = "0.18"
async-io = "2"
# Autocomplete's spell check over the system's Hunspell dictionaries.
spellbook = "=0.4.2"
# Autocomplete's overlay pill on KDE Plasma (`zwp_input_panel_v1`).
cosmic-text = "0.19"

[target.'cfg(windows)'.dependencies]
tray-icon = { version = "0.26", default-features = false }
Expand Down
Loading
Loading