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
53 changes: 53 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,59 @@ All notable changes to PolterType are recorded here. The format is
loosely based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and the project follows [Semantic Versioning](https://semver.org/).

## [Unreleased]

### Added

- **Arabic.** A bundled `ar` layout (Arabic 101, read off the OS rather
than transcribed), a 2.5 M-form dictionary from Ayaspell's stems
with the article forms added, Arabic's long vowels for the
plausibility detector, and a short
stop-word list checked so that none of its words is what an English
stop word types as. macOS maps `Arabic`, `Arabic - PC`,
`Arabic - QWERTY`, `Arabic - AZERTY` and `Arabic - North Africa` to
it; Linux maps `ara`; Windows maps every country's Arabic keyboard
(`ar-SA`, `ar-EG`, …). A lam-alef key puts two code points on screen,
and a correction erases it as two.
- **macOS reads your keyboards from the OS.** The layout backend now
answers `describe_keymaps` with `UCKeyTranslate`, as the Windows one
does with `ToUnicodeEx`, so a variant whose keys differ from the
bundled table — Apple's own Arabic against Arabic 101, Russian
Phonetic against Russian — is corrected on the keys you actually
have.

### Fixed

- **Arabic presentation forms count as Arabic script.** `ﻻ` and the
rest of U+FB50–FDFF and U+FE70–FEFF read as "other script" and
dragged a word's script fit down.
- **`cargo xtask wordlists fetch` finds a `SET` anywhere in the `.aff`,
tab-separated or not,** and no longer parses rules it will not use
for a stems-only dictionary.

- **Hyprland and sway knew only six of the bundled languages by name.**
Those compositors report a keymap's description, and `Polish`,
`Czech`, `Greek`, `Hebrew`, `Turkish`, `Bulgarian`, `Italian`,
`Portuguese` and `Arabic` came back as unknown layouts.
- **A correctly typed Hebrew word is no longer replaced on shape alone.**
Hebrew writes no short vowels, so a word missing from its stems list
scored as one consonant cluster and could lose to its Latin rendering.
Leaving Hebrew or Arabic is now the dictionaries' call: a word in neither
moves only when the other layout's dictionary follows much more of it
than its own, so `microsoft` comes back and `בישראל` stays. On Wikipedia
text about 40 % of out-of-dictionary English returns, and none of the real
words the shape check used to replace is touched by this rule.
- **On Windows, switching between two keyboards of one language now lands
on the keyboard whose table PolterType holds,** rather than on whichever
the OS listed last.
- **Converting a selection now plays the correction chime.** With
`[selection] enabled`, pressing the force-switch hotkey on a selected
passage converted it, pasted it back and put the clipboard back in
complete silence — the chime lived only in the word paths, so a press
that worked looked like one that did nothing. The selection path now
chimes too, on the same "Play a soft chime on correction" setting as
every other path, and stays silent when there was nothing to convert.

## [0.38.2] — hands off first

### Fixed
Expand Down
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ typed on an English layout comes out as `ma;ana` — PolterType fixes the
word the moment it ends and switches the layout with it, so `por la
tarde` lands correctly as typed.*

> **Status: v0.38.2**, out of beta since v0.1.0. Windows, macOS and
> **Status: v0.39.0**, out of beta since v0.1.0. Windows, macOS and
> Linux (Wayland and X11, on the desktops in the table below) all
> correct words end to end, and the spelling-suggestions tooltip
> renders on all three. Installers are **unsigned**, so first launch
Expand All @@ -43,7 +43,7 @@ hotkeys, smart commands, wordlists, and per-app exceptions.*
- **Fast** — pure Rust, no WebView, no perceptible typing latency.
- **Light to run** — single binary, ~20 MB, a tray icon's worth of
CPU and RAM. **The download is not light** — the installers are
about 60–70 MB, nearly all of it the fifteen bundled dictionaries — but
about 60–70 MB, nearly all of it the sixteen bundled dictionaries — but
only the languages your OS has enabled are ever read into memory.
- **Quiet** — tray-only, **zero telemetry**. Exactly one network call
exists, the update check (§ [Staying up to
Expand Down Expand Up @@ -386,24 +386,24 @@ them on the **Commands** pane in Settings.

## Languages

Fifteen layouts ship with the app, each with a full dictionary:
Sixteen layouts ship with the app, each with a full dictionary:

**English (US) · Ukrainian · Russian · German · Spanish · French ·
Polish · Czech · Greek · Hebrew · Turkish · Bulgarian · Italian ·
Portuguese (PT) · Portuguese (BR)**
Portuguese (PT) · Portuguese (BR) · Arabic**

PolterType only loads the ones your OS actually has enabled, so
bundling fifteen costs a two-keyboard user nothing at runtime.
bundling sixteen costs a two-keyboard user nothing at runtime.

**On Windows the bundled table is only a starting point.** A Windows
layout is named after a *language*, but a language is not a keyboard —
**On Windows and macOS the bundled table is only a starting point.** A
layout there is named after a *language*, but a language is not a keyboard —
Bulgarian alone ships in three genuinely different arrangements. Since
v0.14.3 PolterType asks Windows what each of your installed keyboards
actually produces and uses that answer, so variants and even custom
layouts we have never heard of come out right. Linux and macOS read
the bundled tables, and a TOML of your own in
`<config-dir>/poltertype/layouts/` still outranks everything,
everywhere.
layouts we have never heard of come out right; macOS does the same
through `UCKeyTranslate`. Linux reads the bundled tables, and a TOML of
your own in `<config-dir>/poltertype/layouts/` still outranks
everything, everywhere.

Two are worth a footnote rather than a surprise:

Expand All @@ -418,6 +418,11 @@ Two are worth a footnote rather than a surprise:
because expanding its clitic prefixes yields 60 million of them.
Hebrew shares its script with nothing else bundled, so detection
leans on that and the dictionary refines it.
- **Arabic** follows Hebrew for the same reason — its article and
clitic particles are prefixes — and adds the article forms (`ال`,
`بال`, `لل`, …) back to the list. The lam-alef keys (`لا` on `B`) type
two code points, and a key here is one character, so they carry the
single-code-point form `ﻻ`, which looks the same.

**Yours isn't here?** Adding a language is one TOML file and one
wordlist — no Rust required. The walkthrough is
Expand Down
1 change: 1 addition & 0 deletions crates/poltertype-core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const LAYOUTS: &[(&str, &str)] = &[
("it_it", "it-IT"),
("pt_pt", "pt-PT"),
("pt_br", "pt-BR"),
("ar", "ar"),
];

fn main() {
Expand Down
40 changes: 34 additions & 6 deletions crates/poltertype-core/src/engine/switcher/correction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,9 @@ impl SwitcherEngine {
let mut live = live;
let mut click_allowance = pointer_click_allowance;
let mut tail: Vec<KeyEvent> = Vec::new();
// What the keys in `tail` cost beyond one Backspace each, counted
// under the layout in effect when each landed.
let mut tail_extra = 0usize;
let mut resume: Option<KeyEvent> = None;
let mut suspicious = false;

Expand All @@ -276,6 +279,7 @@ impl SwitcherEngine {
&& Instant::now() < deadline
{
let w = self.drain_correction_window(rx, &mut click_allowance);
tail_extra += self.extra_for_events(from, &w.word_keys);
tail.extend(w.word_keys);
suspicious |= w.suspicious;
resume = w.resume;
Expand Down Expand Up @@ -350,6 +354,7 @@ impl SwitcherEngine {
let mut quiet_probes = 0u8;
loop {
let w = self.drain_correction_window(rx, &mut click_allowance);
tail_extra += self.extra_for_events(to, &w.word_keys);
tail.extend(w.word_keys);
suspicious |= w.suspicious;
if let Some(r) = w.resume {
Expand Down Expand Up @@ -450,7 +455,7 @@ impl SwitcherEngine {

let mut held = HeldKeys::acquire(&self.key_gate);
let mut repairs_left = INTRUSION_REPAIRS;
let mut to_delete = backspaces + tail.len() + usize::from(resume.is_some());
let mut to_delete = backspaces + tail.len() + tail_extra + usize::from(resume.is_some());
loop {
// ── Delete: word + boundary + absorbed tail ─────────────
//
Expand All @@ -474,7 +479,7 @@ impl SwitcherEngine {
std::thread::sleep(POST_EMIT_LAG);
let w = self.drain_correction_window(rx, &mut click_allowance);
suspicious |= w.suspicious;
let mut extra = w.word_keys.len();
let mut extra = w.word_keys.len() + self.extra_for_events(to, &w.word_keys);
tail.extend(w.word_keys);
if let Some(r) = w.resume {
if is_submission_scancode(r.scancode) || resume.is_some() {
Expand Down Expand Up @@ -515,7 +520,8 @@ impl SwitcherEngine {
Some(rk) => {
let mut full: Vec<ReplayKey> = rk.to_vec();
full.extend(extra_keys.iter().copied());
emitted = full.len();
emitted = full.len()
+ self.extra_backspaces(to, full.iter().map(|k| (k.scancode, k.shift)));
let sent = self.key_emitter.send_keys(&full);
self.push_echoes(self.key_emitter.take_emitted());
match sent {
Expand Down Expand Up @@ -682,7 +688,7 @@ impl SwitcherEngine {
let w = self.drain_correction_window(rx, &mut click_allowance);
let saw_press = w.saw_user_press;
suspicious |= w.suspicious;
intruders += w.word_keys.len();
intruders += w.word_keys.len() + self.extra_for_events(to, &w.word_keys);
tail.extend(w.word_keys);
if let Some(r) = w.resume {
if is_submission_scancode(r.scancode) || resume.is_some() {
Expand Down Expand Up @@ -999,6 +1005,11 @@ impl SwitcherEngine {
std::thread::sleep(PASTE_SETTLE);
self.restore_clipboard(clipboard, previous.as_deref());

// Text was just replaced on screen as in `apply_correction`; with no
// chime here a press that worked looked like one that did nothing.
if self.settings.snapshot().general.sound_on_correct {
self.audio.play(SoundEvent::Correct);
}
info!(%from, %to, "selection converted");
let _ = self.out_tx.send(SwitcherEvent::Corrected {
from_layout: from,
Expand All @@ -1012,6 +1023,22 @@ impl SwitcherEngine {
}

impl SwitcherEngine {
/// What `keys` cost in Backspaces beyond one each, typed under `layout`.
pub(super) fn extra_backspaces(
&self,
layout: &LayoutId,
keys: impl IntoIterator<Item = (u32, bool)>,
) -> usize {
self.layouts
.get(layout)
.map_or(0, |m| m.extra_backspaces(keys))
}

/// [`Self::extra_backspaces`] for keystrokes off the live stream.
fn extra_for_events(&self, layout: &LayoutId, keys: &[KeyEvent]) -> usize {
self.extra_backspaces(layout, keys.iter().map(|k| (k.scancode, k.modifiers.shift)))
}

/// Wait for the finger to come off the hotkey before anything is
/// emitted — the same fact `apply_correction` waits on, on the one
/// force-switch path that was not waiting on it.
Expand Down Expand Up @@ -1167,7 +1194,7 @@ impl SwitcherEngine {
/// The order has to be the same in every process. `HashMap::keys()`
/// was not, which is harmless while the DB holds exactly the two
/// active layouts and not at all harmless when it does not: a
/// failed `list_active()` loads all fifteen bundled layouts, the
/// failed `list_active()` loads every bundled layout, the
/// force-switch aims at whichever came out first, and the
/// pre-flight refuses it — no keystroke, no word, no explanation.
/// So: what the OS says is switchable, else the DB sorted by name.
Expand Down Expand Up @@ -1259,7 +1286,8 @@ impl SwitcherEngine {
// The word plus, if there is one, the boundary key that closed
// it. A word still being typed has none: nothing follows the
// caret to backspace over or put back.
let mut backspaces = last.keys.len();
let mut backspaces = last.keys.len()
+ self.extra_backspaces(&from, last.keys.iter().map(|k| (k.scancode, k.shift)));
if let Some(b) = last.boundary {
corrected.push(b.ch);
// Enter/Tab excepted, where a re-press would submit the line
Expand Down
12 changes: 10 additions & 2 deletions crates/poltertype-core/src/engine/switcher/decide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,10 @@ impl SwitcherEngine {
self.dismiss_suggestions(None);
// Counting keys rather than rendered chars survives
// scancodes the mapping table cannot render.
self.dispatch_smart_command(cmd, erase_len(cmd, keys.len()), boundary_char);
let typed = keys.len()
+ self
.extra_backspaces(&current_layout, keys.iter().map(|k| (k.scancode, k.shift)));
self.dispatch_smart_command(cmd, erase_len(cmd, typed), boundary_char);
// The trigger text is gone from screen: not re-openable by
// backspace, not matchable again.
buffer.forget_completed();
Expand Down Expand Up @@ -470,7 +473,12 @@ impl SwitcherEngine {
corrected_text: corrected_with_boundary,
// Keys, not rendered chars: under-counting is how
// word heads get left behind.
backspaces: keys.len() + 1,
backspaces: keys.len()
+ self.extra_backspaces(
&current_layout,
keys.iter().map(|k| (k.scancode, k.shift)),
)
+ 1,
reason: v.reason,
}
}
Expand Down
11 changes: 10 additions & 1 deletion crates/poltertype-core/src/engine/switcher/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,16 @@ impl SwitcherEngine {
// delete all of it, retype with the word replaced. The accept
// chord's digit is not on screen: every chord holds Ctrl, Alt or
// Meta, and the engine reads such a keystroke as a shortcut.
let backspaces = pending.keys.len() + pending.trail.len();
let backspaces = pending.keys.len()
+ pending.trail.len()
+ self.extra_backspaces(
&pending.layout,
pending
.keys
.iter()
.chain(pending.trail.iter().map(|t| &t.key))
.map(|k| (k.scancode, k.shift)),
);

// Cross-layout entries replay the original scancodes under the
// switched layout; spelling entries reverse-map the suggestion
Expand Down
Loading
Loading