Toggle Matchbox Keyboard

I added a “launchbar” icon in the taskbar, to act as a toggle switch, so touching the icon started matchbox and touching it again closed matchbox. That seems to be what you’re looking for.

Looking at my notes this is what I did, and it should still work since matchbox-keyboard hasn’t been updated in a long time.

All the keyboard layouts provided in the install are located at /usr/share/matchbox-keyboard. You’ll see a list of .xml files, choose the one closest to what you need, the file names are somewhat descriptive. The .xml file you choose can also be edited to customize the characters, spacing, size, key location, etc. for the keyboard. If you copy that file of choice to your home directory that is the keyboard file it will use, you won’t have to specify a layout when starting matchbox-keyboard, and you can edit that user file and leave the original .xml files unchanged in case you need to back up or start over.

First create a .matchbox directory

mkdir ~/.matchbox

Then copy your .xml file of choice to that directory, in this example I used the US keyboard

cp /usr/share/matchbox-keyboard/keyboard-us.xml ~/.matchbox/keyboard.xml

After that all your .xml keyboard edits will be done in ~/.matchbox/keyboard.xml

nano ~/.matchbox/keyboard.xml

Now that you have a default keyboard file in place to make startup and editing easier you’ll need to create a bash script that will either toggle the keyboard on or off each time the script is run. I use a “scripts” directory to hold all my bash scripts, but you can put it wherever you like.

nano ~/toggle-matchbox.sh

#!/bin/bash
#This script toggles the virtual keyboard on or off
PID=`pidof matchbox-keyboard`
if [ ! -e $PID ]; then
killall matchbox-keyboard
else
matchbox-keyboard &
fi

Don’t forget to make it executable.

Now you’ll need to create a desktop file, this will add it to the menu, and allow you to add it to the launchbar so you can start/stop the keyboard with a single touch of the icon in the taskbar. Edit the path to your “toggle” shell script as needed.

sudo nano /usr/share/raspi-ui-overrides/applications/toggle-matchbox.desktop

[Desktop Entry]
Name=Toggle Matchbox Keyboard
Comment=Toggle Matchbox Keyboard
Exec=/home/pi/toggle-matchbox.sh
Type=Application
Icon=matchbox-keyboard.png
Categories=Panel;Utility;MB
X-MB-INPUT-MECHANSIM=True

Now you need to add it to the “Launchbar” for a one touch start/stop. You can use the Desktop GUI to add a button to the launchbar, but sometimes the Pi doesn’t update the menu in a timely manner after you’ve made changes, and you can’t add it to the launchbar until it shows up in the menu if you’re using the GUI. So I just went ahead and added the “toggle matchbox” button manually.

I did that by adding an entry to the launchbar plugin, so open the lxpanel file for editing

nano ~/.config/lxpanel-pi/LXDE/panels/panel

Scroll down the file till you see the section for the launchbar plugin. You can see I currently have 4 buttons in the launchbar

Plugin {
type=launchbar
Config {
Button {
id=/usr/share/raspi-ui-overrides/applications/pcmanfm.desktop
}
Button {
id=/usr/share/raspi-ui-overrides/applications/lxterminal.desktop
}
Button {
id=/usr/share/applications/iceweasel.desktop
}
Button {
id=/usr/share/raspi-ui-overrides/applications/galculator.desktop
}
}
}

Add the new button entry to the launchbar plugin. I added mine to the top of the “button” list so it would show up next to the “Menu” button. If you want the toggle button to appear to the right add it at the bottom of the list, or even somewhere in the middle of the list.
This is what the file looked like after adding the button.

Plugin {
type=launchbar
Config {
Button {
id=/usr/share/raspi-ui-overrides/applications/toggle-matchbox.desktop
}
Button {
id=/usr/share/raspi-ui-overrides/applications/pcmanfm.desktop
}
Button {
id=/usr/share/raspi-ui-overrides/applications/lxterminal.desktop
}
Button {
id=/usr/share/applications/iceweasel.desktop
}
Button {
id=/usr/share/raspi-ui-overrides/applications/galculator.desktop
}
}
}

Now restart lxpanel and you should see the new “button” in the launchbar. Touch it to open the keyboard, touch it again to close.

lxpanelctl restart

As I said in the beginning I’m using notes and my memory for this since I’m not currently using matchbox-keyboard. But everything appears to be correct, and I usually keep good notes when adding things, so it should work fine. Maybe it will help you out in finding a solution.

Source: https://www.raspberrypi.org/forums/viewtopic.php?t=112515

Calibrate Waveshare 5″ Resistive Touchscreen (and 7.9″ Capacitive)

config.txt
max_usb_current=1
hdmi_group=2
hdmi_mode=87
hdmi_cvt 800 480 60 6 0 0 0
hdmi_drive=1

# install calibrator and evdev (allows multiple keyboards mice treated as separate device)
sudo apt install xinput-calibrator xserver-xorg-input-evdev

# make evdev higher number than libinput
sudo mv /usr/share/X11/xorg.conf.d/10-evdev.conf /usr/share/X11/xorg.conf.d/45-evdev.conf

# list devices
xinput

# view calibration option
xinput --list-props <deviceid>

# calibrate
xinput_calibrator

# copy paste the result like below to /usr/share/X11/xorg.conf.d/99-calibration.conf:
Section "InputClass"
Identifier "calibration"
MatchProduct "BYZHYYZHY By ZH851"
Option "Calibration" "182 3859 277 3944"
Option "SwapAxes" "0"
EndSection

# checkĀ  the values
DISPLAY=:0 xinput list-props "BYZHYYZHY By ZH851"

# manual set values
DISPLAY=:0 xinput set-prop "BYZHYYZHY By ZH851" "Evdev Axis Calibration" 200, 3800, 275, 3850

ALTERNATIVE (using libinput):
# check calibration values
xinput_calibrator -v
DEBUG: Found that 'BYZHYYZHY By ZH851' is a sysfs name.
DEBUG: Adding click 0 (X=129, Y=86)
DEBUG: Adding click 1 (X=655, Y=96)
DEBUG: Adding click 2 (X=133, Y=406)
DEBUG: Adding click 3 (X=669, Y=401)

# check screen resolution
xrandr | grep current
Screen 0: minimum 800 x 480, current 800 x 480, maximum 800 x 480

# calculate values
a = (screen_width * 6 / 8) / (click_3_X - click_0_X)
c = ((screen_width / 8) - (a * click_0_X)) / screen_width
e = (screen_height * 6 / 8) / (click_3_Y - click_0_Y)
f = ((screen_height / 8) - (e * click_0_Y)) / screen_height

a = (800 * 6 / 8) / (669 - 129) = 1.1111
c = ((800 / 8) - (1.1111 * 129)) / 800 = -0.0542
e = (480 * 6 / 8) / (401 - 86) = 1.1429
f = ((480 / 8) - (1.1429 * 86)) / 480 = -0.0798

# test new values
xinput set-prop "BYZHYYZHY By ZH851" "libinput Calibration Matrix" a, 0.0, c, 0.0, e, f, 0.0, 0.0, 1.0

xinput set-prop "BYZHYYZHY By ZH851" "libinput Calibration Matrix" 1.1111, 0.0, -0.0542, 0.0, 1.1429, -0.0798, 0.0, 0.0, 1.0

# if calculation incorrect, reset and repeat calculation above
xinput set-prop "BYZHYYZHY By ZH851" "libinput Calibration Matrix" 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0

# make changes permanent to /usr/share/X11/xorg.conf.d/99-calibration.conf:
Section "InputClass"
Identifier "calibration"
MatchProduct "BYZHYYZHY By ZH851"
Option "TransformationMatrix" "1.1111 0.0 -0.0542 0.0 1.1429 -0.0798 0.0 0.0 1.0"
EndSection

For 7.9″ Capacitive Screen:

add this lines to /boot/config.txt:
#disable these settings below
#display_auto_detect=1
#dtoverlay=vc4-kms-v3d
#max_framebuffers=2
max_usb_current=1

hdmi_group=2
hdmi_mode=87
hdmi_timings=400 0 100 10 140 1280 10 20 20 2 0 0 0 60 0 43000000 3
display_rotate=3 # 1 - 90deg, 2 - 180deg, 3 - 270deg

Rotate 0 degree:
xinput set-prop "WaveShare WaveShare" "libinput Calibration Matrix" 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0

Rotate 90 degree:
xinput set-prop "WaveShare WaveShare" "libinput Calibration Matrix" 0.0, 1.0, 0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 1.0

Rotate 270 degree:
xinput set-prop "WaveShare WaveShare" "libinput Calibration Matrix" 0.0, -1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0

# make changes permanent to /usr/share/X11/xorg.conf.d/99-calibration.conf:
Section "InputClass"
Identifier "calibration"
MatchProduct "WaveShare WaveShare"
Option "TransformationMatrix" "0.0 -1.0 1.0 1.0 0.0 0.0 0.0 0.0 1.0"
EndSection

Source:
https://www.waveshare.com/wiki/5inch_HDMI_LCD_(B)
https://www.waveshare.com/wiki/7.9inch_HDMI_LCD
https://wiki.archlinux.org/index.php/Talk:Calibrating_Touchscreen