X Neural Switcher - Cookbook

Greetings.

I am the author of a program for automatically switching keyboard layouts running under Linux. This program is xneur or X Neural Switcher .

When I started this program, there was nothing sane to replace Punto Swither for linux. Pay attention, I wrote it personally for myself, everything almost always works for me. I put it in the public domain only because the program is useful to people.

In further articles I will analyze existing (and existing) analogues, and explain why they are all what you can’t use, and what a cool program is xneur.

I do the program on the strength of one hour a week, so blaming me for slow development is stupid. I also make money by programming, but not at all connected to linux.

Over the past 6 years, I periodically stumbled upon specific bugs of both Xlib and DE, with which I had to find mutual understanding.

Now I want to talk about cooking xneur, describe the settings and share “little football tricks”.

This part of articles at number 0 is devoted to the simplest - description. You will be surprised how much xneur can do that which Punto cannot do.

For those who have tried for a long time, but not mastered. I am always open to dialogue. If something doesn’t work somewhere, tell me all the necessary information, and I will try to solve your problem.

What is the X Neural Switcher.



X Neural Switcher - a program for automatically switching keyboard layouts, depending on the typed text. Those. when typing, if it is not typed in the layout that you expect, xneur will automatically (or upon request) switch the language to the desired one.

When working in automatic mode, xneur automatically determines the layout of the input text and changes the language for you. In this mode, it is possible to set exception applications in which the automatic mode will be replaced by the manual one.

When working in manual mode, xneur does not track typing, but allows you to automatically change the layout of the last typed word (Pause / Break button), the last typed line (Ctrl + Break key combination), selected text (Shift + Break key combination), and other useful functions.

All the above keyboard shortcuts work in automatic mode. If for some reason you are not satisfied with the preset combinations, you can always change them in the program settings. The program also allows you to create your own keyboard shortcuts to launch any application.

Currently, the program supports eighteen languages: Armenian, Belorussian, Bulgarian, Czech, Georgian, German, Greek, English, Estonian, French, Kazakh, Lithuanian, Latvian, Polish, Moldavian (Romanian), Russian, Spanish, Ukrainian and Uzbek.

For the above languages, the program has heuristic analysis algorithms, but, nevertheless, the program can work with other languages ​​if aspell or myspell dictionaries exist for it.

The main features of the program.


  • Switching. Automatic or manual layout switching. At the same time, xneur is able to self-learn, which is sometimes useful for difficult words that do not fall under either dictionary words or heuristic analysis, for example, padoncuff slang or personally your favorite word distortions.
  • Typography. Xneur can help you turn text into a more refined look. For example, turn “Such” a word into “such,” or turn off Caps that are accidentally turned on, or replace two spaces with a comma, or turn ®, (tm) or © into beautiful ®, ™ or ©.
  • You can specify one layout for all copies of the application, or in each use your own.
  • For standard switching actions, you can assign your own keyboard shortcut. Moreover, you can assign a keyboard shortcut for your scripts or launch applications.
  • You can assign your own key combination to enable a specific layout or switch them in a circle.
  • If you are too lazy to type words completely, you can use the auto-completion. Xneur will remember frequently typed words and complete the incomplete word.
  • You yourself can specify applications in which xneur will work in automatic, manual mode, or will not work at all.
  • If it is so convenient for you, you can configure the sound design of keystrokes or other events, display on-screen or pop-up notifications of switching.
  • When you often have to type the same text, you can try using abbreviation replacement. By typing "pr" and pressing your key combination, you will send to the interlocutor "Hello. All fine :)". It's so lazy to answer stupid questions.
  • Xneur has a diary. At any time, you can see the log of the typed text, broken down by date and by the application in which it was typed. Yes, this is a keylogger option. Then I will tell you how to configure xneur as a keylogger.
  • If you often play full-screen games, you can disable xneur in all full-screen applications.
  • So. ALL xneur features are disabled! Do not like some option - just turn it off.

Thus, if you master the fine-tuning, you will always cook xneur to your liking.

Program installation.


The source code for the latest versions of xneur and gxneur is available at xneur.ru/downloads.

For installation from the source you will need the following packages (I will give you a way to install packages for Ubuntu, but you yourself will understand what needs to be installed):
sudo apt-get install build-essential automake1.9 libtool flex libx11-dev libgstreamer0.10-dev libopenal-dev libpcre3-dev libnotify-dev zlib1g-dev libaspell-dev libxosd-dev libenchant-dev
To build gxneur (the configuration interface) you need to install these packages:
sudo apt-get install libglade2-dev libgtk2.0-dev libgconf2-dev libappindicator-dev

Installation is carried out by a standard set of commands (again, I quote for Ubuntu).
./configure
make 
sudo make install

To uninstall a program installed in this way, you can use the command
sudo make uninstall


Now we will analyze the configuration options for the program, in case you have any packages missing or you just want to disable them.

For reference, you can use ./configure --help.
  • --with-sound [= ARG] Building the program with ARG = [yes | no | gstreamer | openal | aplay] [default = yes]. Those. You can use the following engines to choose from for sound design: Gstreamer (default), OpenAL, or aplay utility.
  • --with-debug Build the program with an internal debug showing in the console the places of memory leaks in the program.
  • --without-keylogger Building a program without keylogger functions (for paranoid)
  • - -with-spell [= ARG] Build the program using the enchant dictionary engine (used in LibreOffice, firefox, etc.) or aspell, or no dictionary support at all. (ARG = [yes | no | enchant | aspell] [default = yes]
  • )
  • --without-xosd Build a program without support for xosd screen notifications.
  • --without-libnotify Build a program without popup support.
  • --without-plugins Build a program without plugin support.

But since I am too lazy to compile the program from the source, I have two PPAs for Ubuntu users.

sudo add-apt-repository ppa:andrew-crew-kuznetsov/xneur-stable
sudo add-apt-repository ppa:andrew-crew-kuznetsov/xneur-unstable

The first repository contains basic releases, the second contains rolling releases (nightly builds).

Description of configuration parameters.


Now we will analyze what will allow us to fine-tune xneur, namely its configuration file.
We will analyze it according to the options. I will give a brief description of each option and explain in which cases it is better to use it.

Version 0.15.0
Describes the current version of the program. For the most part, it doesn’t affect anything at all.

ManualMode No
Manual mode option. If set to Yes, then automatic switching will be disabled everywhere except for applications specified in the corresponding setting.

LogLevel Trace
The level of messages that xneur will dump into the console.
Error is only errors.
Warning - the previous one, plus warnings about problems that do not affect the program.
Log is the previous one, plus a little more.
Debug - previous, plus debugging messages of the program.
Trace is the previous one, plus everything that happens in xneur in general.

ExcludeLanguage de
The option allows multiple use and serves to indicate the layout with which and to which switching will not be carried out.

DefaultXkbGroup 0
Defines the default layout for newly launched applications.

ExcludeApp rdesktop
With this option you can completely exclude the application from processing. Multiple use allowed.

SetAutoApp Gedit
This option defines applications in which the automatic switching mode will be forcibly turned on regardless of the ManualMode option.

SetManualApp Anjuta
This option defines applications in which the manual switching mode will be forcibly turned on regardless of the ManualMode option.

AddBind Action Key
Defines a key for a particular action to switch layouts or other. The Action list is in your configuration file.

AddAction Control Alt f Firefox Browser firefox
Defines a key for performing a custom action.

ReplaceAbbreviation ini Andrey Crew Kuznetsov
Defines a list of abbreviations for replacing abbreviations.

ReplaceAbbreviationIgnoreLayout Yes
Determines whether the current layout should be considered when replacing abbreviations. If set to Yes, the program will replace the abbreviation “yts” and “qw” with “ytsuken”.

PlaySounds No
Turns sound on or off.

SoundVolumePercent 15
Determines the volume level of program sounds as a percentage of the system volume level.

AddSound AutomaticChangeWord Enable /usr/share/xneur/sounds/itemback.wav
This option indicates which action and which sound to use. A list of actions for which you can put a notification is in your configuration file.

EducationMode Yes
It's easy. Whether or not to include self-learning programs for your vocabulary.

LayoutRememberMode Yes
Remember the layout for each window or one layout for all windows? You decide.

LayoutRememberModeForApp Wine
This option forces xneur to force a single layout for all application windows. Everywhere in Wine I have a common layout.

SaveSelectionMode Yes
You selected and changed the text with xneur. If the option is enabled, then the selection will remain after the change, making further switching possible.

RotateLayoutAfterChangeSelectedMode No
Determines whether to switch the system layout if the selected text is corrected.

SendDelay 0
Delay before sending an intercepted keystroke back to the application.

LogSave Yes
Turn on the keylogger, i.e. save the typed text to a file.

LogSize 10000000
Determine the size of the log file (in bytes).

LogMail to_me@mail.ru
If the option is defined, then the log of the typed text will be sent to this email.

LogHostIP 127.0.0.1 A
host that provides email services (mail server for sending, which does not require a username and password). Perhaps the indication is not ip, but a name.

LogPort 25
Port of the mail server.

CorrectIncidentalCaps Yes
An option to correct a random caps.

CorrectTwoCapitalLetter Yes
Option to correct TWO uppercase letters.

CorrectCapitalLetterAfterDot Yes
Corrects a lowercase letter to uppercase after a dot or exclamation point.

CorrectTwoSpaceWithCommaAndSpace Yes
Corrects a double space for a comma.

CorrectTwoMinusWithDash Yes
Corrects the double minus on the dash.

CorrectCWithCopyright Yes
Corrects © to ©

CorrectTMWithTrademark Yes
Corrects (tm) to ™.

CorrectRWithRegistered Yes
Corrects ® to ®.

FlushBufferWhenPressEscape Yes
If this option is enabled, pressing Escape will reset the internal switch buffer.

FlushBufferWhenPressEnter No
If this option is enabled, then when you press Enter, the internal switch buffer will be reset.

DontProcessWhenPressEnter No
The word will not be processed if Enter is pressed, which is convenient in instant messengers.

ShowOSD No
Show on-screen messages. Deprecated

FontOSD - * - * - * - * - * - * - 32 - * - * - * - * - * - * - u
Select a font for on-screen messages. Deprecated

AddOSD XneurStart Enable X Neural Switcher Launched
This option indicates for which action and which screen message to use. A list of actions for which you can put a notification is in your configuration file.

ShowPopup Yes
Show popup messages.

PopupExpireTimeout 1500
Popup message display interval. In this implementation, the display library does not work.

AddPopup XneurStart Enable X Neural Switcher Launched
This option indicates for which action and which pop-up message to use. A list of actions for which you can put a notification is in your configuration file.

CheckOnProcess Yes
Check a word on the fly or after pressing Entrer. I prefer on the fly.

DisableCapsLock Yes
Disable Caps at all.

CorrectSpaceWithPunctuation No
Remove spaces before punctuation.

Autocompletion Yes
Enables word completion.

AddSpaceAfterAutocompletion No
Add a space after auto-completion.

AutocompletionExcludeApp Gnome-terminal
In these applications, auto-completion will be disabled.

TroubleshootBackspace No
Disables auto-switching if Backspace is pressed.

TroubleshootLeftArrow Yes
Disables auto-switching if the left arrow is pressed.

TroubleshootRightArrow Yes
Disables auto-switching if the right arrow is pressed.

TroubleshootUpArrow Yes
Disables auto-switching if the up arrow is pressed.

TroubleshootDownArrow Yes
Disables auto-switching if the down arrow is pressed.

TroubleshootDelete No
Disables auto-switching if Delete is pressed.

TroubleshootSwitch Yes
Disables auto-switching if you switch layout.

TroubleshootFullScreen Yes
Disables auto-switching if the application is in full-screen mode.

CompatibilityWithCompletion Yes A
crutch for compatibility with auto-completion in other applications.

TrackingInput Yes
Disabling this option will lead to a complete failure of the program from intercepting the keyboard.

TrackingMouse Yes
Disabling this option will lead to a complete failure of the program from intercepting the mouse.

DontSendKeyRelease No
Do not send KeyRelease keyboard event. Very specific thing, it is better not to change the value of the option.


What's next?


In the future I plan to talk about:
  • Algorithms xneur.
  • Xneur as a keylogger, with an example of a working config.
  • Well and other interesting things about xlib, programs for linux and all that.


Next parts


X Neural Switcher - The Cookbook (Part 1). Forerunners and Analogs of the
X Neural Switcher - The Cookbook (Part 2). Algorithms

Also popular now: