autocomplete at desktop level

Solution 1:

The solution to your request is Input Method.

What you have described is something familiar to most CJK language users. Let's review how input method works in current Linux systems.

The Input Method system

Here's a simple architecture for a common input method system:

NOTE: I snapshot this image from The X Input Method Protocol. Some of the arrows are irrelevant to following discussion.

Historically, XIM (the X Input Method protocol) was the only protocol. It's overly complex and lacks some desired features. So it's mostly abandoned, though compatibility is still provided by popular toolkits like GTK, Qt.

A modern input method system contains several parts:

  1. Client-side library support

    • typically implemented as a module loaded by toolkits (e.g. for GTK, see /usr/lib/x86_64-linux-gnu/gtk-3.0/3.0.0/immodules/)
  2. Input method server
  3. X server

How do these parts fit together?

A user types a key. X server receives the hardware event from evdev interface, composes a XEvent and sends to the application under keyboard focus. The application toolkit (GTK, Qt) input method module intercepts the event and passed the info to input method server. The input method server figures what the user may want and passes some text back to the IM module.

Now, let's talk about the architecture of the IM server.
An IM server typically consists of two parts:

  1. An IM framework which handles platform specific intricacies and provides a nice interface to IM engine and toolkit IM modules. It provides the IPC mechanisms used by the IM module, server and engine.
  2. Various IM engines do the actual work of transforming user-typed keys to desired text. IM engines can be shared libraries loaded by the IM server or independent processes communicating to the IM server.
  3. Auxiliary input method configuration programs provides friendly user interface for customizing the IM server and engine behaviors.

All in all, what an IM does is to transform what you type to something different and optionally provide predictions.

An example

We use ibus-pinyin here to type some Chinese characters.

The romanization of 汉语拼音 is han yu pin yin. At, first you need to type all these letters to get the four Chinese characters. But after a few times, you just need to type the four initial characters h y p y to get the Chinese character.

In the ibus-pinyin case, han yu pin yin is shortened to h y p y.
More advanced IM engines utilize statistical learning techniques to provide better prediction. Nothing can stop you from writing a English input method engine to provide a typing boost.

As a bonus, all toolkits have input method support except some plain old X programs. So this is a quite universal solution.


Thanks to Anders F. U. Kiær. Features / Typing-Booster | Fedora Project Wiki should be the answer

Solution 2:

Take a look at my script, TextSuggest.

In action:

Imgur

Installation:

Install the following packages:

  • xdotool
  • xclip
  • suckless-tools (for dmenu)

Then assign 2 keyboard shortcuts:

  • one to `python3 /path/to/TextSuggest.py --noselect
  • the other to python3 /path/to/TextSuggest.py

The first one will simply provide a searchable list of all words. Use the second when you have some text selected, and want to get suggestions/completions for it.

The accepted suggestions are stored as history (and are then suggested first) in the file ~/.textsuggest_history.txt.

You can define custom words and expansions/aliases at ~/.Custom_Words.txt.

Solution 3:

Take a look at Autokey. It might fit your needs. C/P from their site:

AutoKey is a desktop automation utility for Linux and X11. It allows you to manage collection of scripts and phrases, and assign abbreviations and hotkeys to these. This allows you to execute a script or insert text on demand in whatever program you are using.