The officially official Devuan Forum!

You are not logged in.

#1 2017-10-06 12:39:21

GNUser
Member
Registered: 2017-03-16
Posts: 133

alternative to ibus? ibus suffers from vanishing characters [SOLVED]

I often use ibus to type in other languages. Especially when writing emails, I tend to edit a lot as I go along. The trouble is that in many applications when I click on the screen to move the cursor somewhere, if I'm using ibus then the last character I typed simply disappears.

For example, in mate-terminal, thunderbird, and pluma, if I type this (for example):

ho ho ho

Then click somewhere on the screen, the text turns into this:

ho ho h

Have any of you found a way to type in other languages--with or without ibus--without being affected by this?

I have considered using a keyboard layout with dead keys as a workaround, but I don't like having to type the diacritic before the letter.

--------------
My setup:
- Devuan Jessie with MATE
- ibus 1.5.9-1
- ibus packages installed: ibus, ibus-gtk, ibus-gtk3, ibus-m17n, ibus-qt4

Last edited by GNUser (2017-10-08 01:16:02)

Offline

#2 2017-10-11 17:07:44

GNUser
Member
Registered: 2017-03-16
Posts: 133

Re: alternative to ibus? ibus suffers from vanishing characters [SOLVED]

I couldn't find anything suitable, so I rolled my own alternative to ibus. It's a simple bash script that allows typing diacritic either before or after the letter, user's choice. The script does not use "preedit text", so no characters ever disappear.

Getting the dependencies:

sudo apt-get install xvkbd python3 && sudo pip3 install pynput

You also need to install yad, which is not in the Devuan Jessie repositories but is easy to find (e.g., by clicking on your architecture at the bottom of this page).

pynput didn't work for me at first because one of its dependencies, the "six" module, was outdated. So, to be safe:

sudo pip3 install --upgrade six

Well, here's the script. It should "just work" once you have all the dependencies. You only need to alter it if you want to add or change the special characters section.

#!/bin/bash

# International keyboard (alternative to ibus for x11)
# Author: Bruno "GNUser" Dantas
# License: GPLv3
# Dependencies: xvkbd, python3, yad, pynput module

#
# NOTE:
# You can customize the two-character triggers and corresponding unicode characters in the "fun stuff" section.
# Otherwise, no need to change anything in this script for it to work :)
# You can either run it in the background (e.g., by starting it with a keyboard shortcut) or, 
# to see what it's doing, run it in a terminal.
#

# setup pipe
pipe=/tmp/international
rm -f $pipe
mkfifo $pipe
exec 3<>$pipe

# create and start keylogger (that feeds its output into this script via pipe)
# to troubleshoot the keylogger: 
# 1. copy the python code below into a file foo
# 2. comment out the three fifo lines, uncomment the print line in log_it function
# 3. in a terminal: python3 /path/to/foo
# 4. type stuff outside the terminal and watch terminal
echo "
from pynput import keyboard
from pynput import mouse
import os

fifo_write = open('$pipe', 'w')

def log_it(output):
	fifo_write.write(output + '\n')
	fifo_write.flush()
	#print(output)

# get initial capslock state
exit_code = os.system('''xset q 2>/dev/null | grep -q -E 'Caps Lock: +on' ''')
if exit_code == 0:
	capslock_in_effect = True
else:
	capslock_in_effect = False

# this function runs each time a key is pressed:
def on_press(key): 
	global capslock_in_effect
	output = str(key)
	if output == 'Key.caps_lock': # if capslock pressed, toggle capslock state
		capslock_in_effect = not capslock_in_effect
	if not output.startswith('Key'): # special keys start with 'Key' and can be logged as-is
		output = output[1:-1] # remove quotes around character
		if capslock_in_effect:
			output = output.swapcase()
	if not output.startswith('Key.shift'): # don't log shift keys (e.g., while loop expects a~ not aKey.shift~)
		log_it(output)

# this function runs each time a mouse button is pressed:
def on_click(x, y, button, pressed):
	button = str(button)
	if pressed and button == 'Button.left':
		log_it('Key.mousebutton_left')

# start listening
with mouse.Listener(on_click=on_click) as listener:
	with keyboard.Listener(on_press=on_press) as listener:
		listener.join()
" >/tmp/tiny-keylogger
python3 /tmp/tiny-keylogger &

# shutdown function
echo "$(basename $0)" >/tmp/scriptname
terminator()
{
	pkill -f International # kill taskbar icon					 
	pkill -f tiny-keylogger # kill keylogger
	pkill -KILL "$(cat /tmp/scriptname)" # kill this script		 
}
trap terminator TERM

# panel icon
export -f terminator
yad --notification --image='accessories-character-map' --text='International Keyboard' --no-middle --menu="Stop!bash -c terminator" --command='' &

# fun stuff
magic()
{
	xvkbd -xsendevent -text "\b\b\[U$1]" # send two backspaces then desired unicode character
}

while read current_char; do
	echo "${previous_char}${current_char}" # for debugging while running in terminal
	case "${previous_char}${current_char}" in
	  # Portuguese
		'A`') magic 00C0;;
		'a`') magic 00E0;;
		"A'") magic 00C1;;
		"a'") magic 00E1;;
		'A^') magic 00C2;;
		'a^') magic 00E2;;
		'A~') magic 00C3;;
		'a~') magic 00E3;;
		"E'") magic 00C9;;
		"e'") magic 00E9;;
		'E^') magic 00CA;;
		'e^') magic 00EA;;
		"I'") magic 00CD;;
		"i'") magic 00ED;;
		'O`') magic 00D2;;
		'o`') magic 00F2;;
		"O'") magic 00D3;;
		"o'") magic 00F3;;
		'O^') magic 00D4;;
		'o^') magic 00F4;;
		'O~') magic 00D5;;
		'o~') magic 00F5;;
		"U'") magic 00DA;;
		"u'") magic 00FA;;
		'U;') magic 00DC;;
		'u;') magic 00FC;;
		'C;') magic 00C7;;
		'c;') magic 00E7;;
	  # Esperanto
		'Cx') magic 0108;;
		'CX') magic 0108;;
		'cx') magic 0109;;
		'Gx') magic 011C;;
		'GX') magic 011C;;
		'gx') magic 011D;;
		'Hx') magic 0124;;
		'HX') magic 0124;;
		'hx') magic 0125;;
		'Jx') magic 0134;;
		'JX') magic 0134;;
		'jx') magic 0135;;
		'Sx') magic 015C;;
		'SX') magic 015C;;
		'sx') magic 015D;;
		'Ux') magic 016C;;
		'UX') magic 016C;;
		'ux') magic 016D;;
	esac
	previous_char=$current_char
done <&3

Last edited by GNUser (Yesterday 19:49:50)

Offline

Board footer