Giter Club home page Giter Club logo

gnome-shell-quick-lang-switch's Introduction

Gnome-shell: Quick language Switch extension

A X11/Wayland extension to quickly switch keyboard language layouts, that bypass the switcher popup and preserves the focus of the active window/widget.

Install

Install it from Gnome-extensions site, or directly from GitHub with this command:

git clone https://github.com/ankostis/gnome-shell-quick-lang-switch ~/.local/share/gnome-shell/extensions/[email protected]

and then ensure it is enabled:

gnome-extensions info [email protected]
gnome-extensions enable [email protected]

If the 1st command above reports that extension does not exist, logout and re-login (required for Wayland).

Rational

The language switcher popup by default takes ~0.7sec to appear, meaning that roughly 2-4 strokes are lost till the switch completes. This affects heavily users typing languages with non-latin based alphabets (e.g. Greek, Cyrilic, Arabic, Japanese), particularly when writting technical documents.

Furthermore, the popup messes with the focus of the active window/widget, (eg. IntelliJ's search popup gets closed, the active widget loses focus when the screen is shared, etc).

Hence the many relevant questions on the web:

Since gsettings cannot reliably switch keyboard layouts both on X and Wayland, some of the recipes above suggest binding a "custom keyboard shortcut" to a bash-script performing the switch through dbus command, which bypasses the popup.

Unfortunately since Gnome-shell v41 (e.g. pushed downstream to Debian unstable "SID" roughly on Sept 2021) dbus no longer allows calling method org.gnome.Shell.Eval with arbitrary code, due to security concerns. The workaround to keep using dbus is to use a custom eval method, but this extension cuts to the chase.

Furthemore, since the extension does not define a custom-shortcut, all keyboard customizations with gnome-tweak-tool/setxkbmap in X11 or Wayland still work fine, on all Gnome versions.

Improvements

A better solution would be to modify the original ui/status/keyboard.js code to skip the switcher-popup based on some new boolen preference (e.g. settable from Tweaks ), as requested by gnome-shell#2945 issue.

If you want to switch between multiple layouts immediately, ie. without cycling through them, there is now (June 2023) Osamu Aoki's extension.

TIP: to facilitate typing while switching language, you may assign the "Switch to next/previous input source" keyboard shortcut to a single keystroke, like [SysRq/Print] or [CapsLock] keys. Screenshot of Gnome Tweaks tool to enable [CapsLock] as language switcher

Release instructions

  1. Test the code:

    • Follow the extension's logs with: journalctl -fg 'quick.

    • Install the extension locally:

      cd ~/.local/share/gnome-shell/extensions
      ln -s <your-project-folder> quick-lang-switch@loca

      Note: Unfortunately testing the extension under Wayland in a nested gnome-shell, as gnome-shell docs suggest, does not work for the language switch key, because it is consumed by the outer shell; you must re-login to reload your changes.

    • Cycle with 3+ layouts installed.

    • Enable, disable, re-enable extension and check that both the switcher popup and the immediate cycling work fine in each state.

    • Check both Xorg and Wayland.

  2. Discover the latest version present in the Gnome-extensions site (link above).

  3. Populate the Changes section, below, for the discovered version + 1.

  4. git tag -sm '<msg>' <latest-release + 1>

  5. git push origin main --tag

  6. Archive the extension & include the commit-id as a zip-comment (the -z option sets the git-hash as zip's comment):

    git rev-parse HEAD | zip ../gnome-shell-quick-lang-switch-$(git describe).zip -z *
  7. Upload it in https://extensions.gnome.org/upload/

  8. Convert the tag into a GitHub release and attach the archive as an asset.

Changes

31 Jul 2023, v8: cycle-backward, fix restoring switcher popup

  • FEAT: bind also switch-input-source-backward (fix #4. thanks to Yevhen Popok, @PotatoXPC)
  • FIX: previously, disabling the extension and reinstating the switcher popup would brake repeated cycling, making it impossible to cycle further than the immediate next layout, not without first releasing keys and re-pressing them.
    • FIX: this could possibly also fix #5 crashing when disabling the extensein (can't be sure, couldn't reproduce).
  • refact: refetch sourceManager on each cycie-call, in case it has changed (instead of storing it in a global var on initialization).
  • doc: comments describe new method's provenance
  • doc: enhance README from user feedback & SO; mention similar extension by Osamu Aoki, better for multiple layouts.
  • DOC: add LICENSE file AGPL.
  • DOC: describe implementation provenance and challenges in comments.

6 Apr 2023, v7: <= gnome-44

  • version: 3.28, 3.30, 3.34, 3.32, 3.36, 3.38, 40, 41, 42, 43, 44
  • thanks to Oleg Arefyev's PR#9.

23 Oct 2022, v6: <= gnome-43

version: 3.28, 3.30, 3.34, 3.32, 3.36, 3.38, 40, 41, 42, 43

27 May 2022, v5: <= gnome-42

version: 3.28, 3.30, 3.34, 3.32, 3.36, 3.38, 40, 41, 42

2 Nov 2021, v4: <= gnome-41

version: 3.28, 3.30, 3.34, 3.32, 3.36, 3.38, 40, 41

22 Oct 2021, v3: gnome-40 & 41

version: 40, 41

21 Oct 2021, v1: re-bind switch-input-source shortcut to direct switch

It re-binds the 'switch-input-source' shortcut:

  • when enabled, the shortcut delegates to the direct-switching method InputSourceManager._modifiersSwitcher, and
  • when disabled, it the shortcut is restored to the original InputSourceManager._switchInputSource method. Note, it won't reset it to any previous monkeypatches.

gnome-shell-quick-lang-switch's People

Contributors

ankostis avatar thesaintdiratof avatar imareo avatar potatoxpc avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.