Skip to content

Commit

Permalink
Modified keyboard layout handling
Browse files Browse the repository at this point in the history
Removed qubes-changed-keyboard-layout script; it is replaced by simply setting
VM property keyboard-layout.

references QubesOS/qubes-issues#1396
references QubesOS/qubes-issues#4294
  • Loading branch information
marmarta committed Jun 22, 2020
1 parent bf3dfb2 commit 9037533
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 143 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ install-rh-agent: appvm install-common
$(DESTDIR)/$(SYSLIBDIR)/systemd/system/qubes-gui-agent.service
install -m 0644 -D appvm-scripts/etc/sysconfig/desktop \
$(DESTDIR)/etc/sysconfig/desktop
install -m 0755 -D appvm-scripts/etc/X11/xinit/xinitrc.d/qubes-keymap.sh \
$(DESTDIR)/etc/X11/xinit/xinitrc.d/qubes-keymap.sh
install -D appvm-scripts/etc/X11/xinit/xinitrc.d/20qt-x11-no-mitshm.sh \
$(DESTDIR)/etc/X11/xinit/xinitrc.d/20qt-x11-no-mitshm.sh
install -D appvm-scripts/etc/X11/xinit/xinitrc.d/20qt-gnome-desktop-session-id.sh \
Expand All @@ -109,8 +107,6 @@ install-xfce:

install-debian: appvm install-common install-pulseaudio
install -d $(DESTDIR)/etc/X11/Xsession.d
install -m 0755 appvm-scripts/etc/X11/xinit/xinitrc.d/qubes-keymap.sh \
$(DESTDIR)/etc/X11/Xsession.d/90qubes-keymap
install -m 0644 appvm-scripts/etc/X11/Xsession.d/* $(DESTDIR)/etc/X11/Xsession.d/
install -d $(DESTDIR)/etc/xdg
install -m 0644 appvm-scripts/etc/xdg-debian/* $(DESTDIR)/etc/xdg
Expand Down Expand Up @@ -180,12 +176,16 @@ endif
$(DESTDIR)/etc/xdg/autostart/qubes-icon-sender.desktop
install -m 0644 -D appvm-scripts/etc/xdgautostart/qubes-qrexec-fork-server.desktop \
$(DESTDIR)/etc/xdg/autostart/qubes-qrexec-fork-server.desktop
install -m 0644 -D appvm-scripts/etc/xdgautostart/qubes-keymap.desktop \
$(DESTDIR)/etc/xdg/autostart/qubes-keymap.desktop
install -D -m 0644 appvm-scripts/usr/lib/sysctl.d/30-qubes-gui-agent.conf \
$(DESTDIR)/usr/lib/sysctl.d/30-qubes-gui-agent.conf
install -D -m 0644 appvm-scripts/lib/udev/rules.d/70-master-of-seat.rules \
$(DESTDIR)/$(SYSLIBDIR)/udev/rules.d/70-master-of-seat.rules
install -D appvm-scripts/usr/lib/qubes/qubes-gui-agent-pre.sh \
$(DESTDIR)/usr/lib/qubes/qubes-gui-agent-pre.sh
install -D appvm-scripts/usr/lib/qubes/qubes-keymap.sh \
$(DESTDIR)/usr/lib/qubes/qubes-keymap.sh
ifeq ($(shell lsb_release -is), Debian)
install -D -m 0644 appvm-scripts/etc/pam.d/qubes-gui-agent.debian \
$(DESTDIR)/etc/pam.d/qubes-gui-agent
Expand Down
11 changes: 11 additions & 0 deletions appvm-scripts/etc/xdgautostart/qubes-keymap.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Desktop Entry]
Version=1.0
Encoding=UTF-8
Name=Keyboard Layout Daemon for Qubes
Exec=/usr/lib/qubes/qubes-keymap.sh
Terminal=false
Type=Application
Categories=
GenericName=
X-GNOME-Autostart-Phase=Initialization
OnlyShowIn=X-QUBES;
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

# This file may be also executed by qubes-change-keyboard-layout

QUBES_KEYMAP="$(/usr/bin/qubesdb-read /keyboard-layout)"
QUBES_USER_KEYMAP="$(cat "$HOME/.config/qubes-keyboard-layout.rc" 2> /dev/null)"

set_keyboard_layout() {
KEYMAP="$1"
# Default value
Expand All @@ -30,10 +27,15 @@ set_keyboard_layout() {
done
}

QUBES_KEYMAP="$(/usr/bin/qubesdb-read /keyboard-layout)"

if [ -n "$QUBES_KEYMAP" ]; then
set_keyboard_layout "$QUBES_KEYMAP"
set_keyboard_layout "$QUBES_KEYMAP"
fi

if [ -n "$QUBES_USER_KEYMAP" ]; then
set_keyboard_layout "$QUBES_USER_KEYMAP"
fi
while qubesdb-watch /keyboard-layout ; do
QUBES_KEYMAP="$(/usr/bin/qubesdb-read /keyboard-layout)"
if [ -n "$QUBES_KEYMAP" ]; then
set_keyboard_layout "$QUBES_KEYMAP"
fi
done
134 changes: 3 additions & 131 deletions appvm-scripts/usrbin/qubes-change-keyboard-layout
Original file line number Diff line number Diff line change
@@ -1,133 +1,5 @@
#!/usr/bin/python3
import re
import subprocess
import os
import sys
import getopt

variant_re = re.compile(r" *([^ ]*) *([^ ]*): (.*)")

#apply the keyboard layout choice
def apply_choice(choice):
if choice == "none":
# Reset user defined keyboard settings
try:
fp = open(vm_layout, 'w')
fp.write("")
fp.close()
subprocess.check_call(['gsettings', 'reset', 'org.gnome.libgnomekbd.keyboard', 'layouts'])
except:
pass
elif choice != "":
try:
file = open(vm_layout, 'w')
file.write(choice)
file.close()
subprocess.check_call(['gsettings', 'set', 'org.gnome.libgnomekbd.keyboard', 'layouts', "['%s']" % choice])
except:
pass
if os.path.exists('/etc/X11/xinit/xinitrc.d/qubes-keymap.sh'):
# Fedora
subprocess.check_call(['/etc/X11/xinit/xinitrc.d/qubes-keymap.sh'])
elif os.path.exists('/etc/X11/Xsession.d/90qubes-keymap'):
# Debian
subprocess.check_call(['/etc/X11/Xsession.d/90qubes-keymap'])


#check for cmd line parameters
usage = "Usage: qubes-change-keyboard-layout [-h] [--help] [--layout=<keyboard-layout>]"
cmd_param_layout = ""
try:
opts, args = getopt.getopt(sys.argv[1:], "h", ["help", "layout="])
except getopt.GetoptError:
print(usage)
sys.exit()
for opt, arg in opts:
if opt in ("-h", "--help"):
print(usage)
sys.exit()
elif opt in ("-l", "--layout"):
cmd_param_layout = arg

#get the current userset layout
vm_layout = "%s/.config/qubes-keyboard-layout.rc" % os.getenv("HOME")
cur_user_layout = ""
if os.path.isfile(vm_layout):
try:
fp = open(vm_layout,'r')
cur_user_layout = fp.read().strip()
fp.close()
except IOError:
pass

#In case command lines were passed (do not show gui)
if cmd_param_layout != "":
apply_choice(cmd_param_layout)
sys.exit()


# get the list of all xkb layouts
xkb_rules_base = "/usr/share/X11/xkb/rules/base.lst"

layouts = []
xkb_rules = open( xkb_rules_base)

l = xkb_rules.readline()
while not (l.startswith("!") and l.startswith("! layout")):
l = xkb_rules.readline()

#layouts section starts

l = xkb_rules.readline().strip()
while l.strip() != "":
pair = re.split("\s+", l, maxsplit=1)
layouts.append(pair)
l = xkb_rules.readline().strip()

while not (l.startswith("!") and l.startswith("! variant")):
l = xkb_rules.readline()

while l.strip() != "":
m = variant_re.match(l.strip())
if m:
layouts.append(("%s+%s" % (m.group(2), m.group(1)), m.group(3)))
l = xkb_rules.readline().strip()

xkb_rules.close()

layouts.sort(key=lambda x: x[1])

# create list dialog
zenity_cmd = ['zenity', '--list', '--text', "Choose desired keyboard layout.", '--radiolist']
zenity_cmd.append( "--title='Keyboard Layout'")
zenity_cmd.append("--height=500")
zenity_cmd.append("--width=350")
zenity_cmd.append('--column')
zenity_cmd.append("")
zenity_cmd.append('--column')
zenity_cmd.append("Code")
zenity_cmd.append('--column')
zenity_cmd.append("Full name")

if cur_user_layout == "":
zenity_cmd.append("TRUE")
else:
zenity_cmd.append("FALSE")

zenity_cmd.append("none")
zenity_cmd.append("Qubes default layout")

for l in layouts:
if l[0] == cur_user_layout:
zenity_cmd.append("TRUE")
else:
zenity_cmd.append("FALSE")
zenity_cmd.append(l[0])
zenity_cmd.append(l[1])

p = subprocess.Popen(zenity_cmd, stdout=subprocess.PIPE)
choice = p.communicate()[0]
choice = choice.decode().strip()
apply_choice(choice)
#!/bin/sh

echo 'This program is deprecated; set qube property keyboard_layout instead.' >&2

exit 1
2 changes: 2 additions & 0 deletions debian/qubes-gui-agent.install
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ etc/qubes-rpc/qubes.SetMonitorLayout
etc/qubes/post-install.d/20-qubes-guivm-gui-agent.sh
etc/xdg/autostart/qubes-icon-sender.desktop
etc/xdg/autostart/qubes-qrexec-fork-server.desktop
etc/xdg/autostart/qubes-keymap.desktop
etc/xdg/Trolltech.conf
etc/xdg/Xresources
etc/xdg/fonts.conf
Expand All @@ -23,5 +24,6 @@ usr/lib/qubes/icon-sender
usr/lib/sysctl.d/30-qubes-gui-agent.conf
usr/lib/tmpfiles.d/*
usr/lib/qubes/qubes-gui-agent-pre.sh
usr/lib/qubes/qubes-keymap.sh
usr/share/glib-2.0/schemas/20_qubes-gui-vm.gschema.override
var/log/qubes
3 changes: 2 additions & 1 deletion rpm_spec/gui-agent.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ rm -f %{name}-%{version}
%config /etc/pam.d/qubes-gui-agent
%config /etc/security/limits.d/90-qubes-gui.conf
%config /etc/xdg/Trolltech.conf
/etc/X11/xinit/xinitrc.d/qubes-keymap.sh
/etc/X11/xinit/xinitrc.d/20qt-x11-no-mitshm.sh
/etc/X11/xinit/xinitrc.d/20qt-gnome-desktop-session-id.sh
/etc/X11/xinit/xinitrc.d/50-guivm-windows-prefix.sh
Expand All @@ -176,10 +175,12 @@ rm -f %{name}-%{version}
/usr/lib/tmpfiles.d/qubes-session.conf
/usr/lib/sysctl.d/30-qubes-gui-agent.conf
/usr/lib/qubes/qubes-gui-agent-pre.sh
/usr/lib/qubes/qubes-keymap.sh
%{_datadir}/glib-2.0/schemas/20_qubes-gui-vm.gschema.override
/usr/lib/qubes/icon-sender
/etc/xdg/autostart/qubes-icon-sender.desktop
/etc/xdg/autostart/qubes-qrexec-fork-server.desktop
/etc/xdg/autostart/qubes-keymap.desktop
%dir /var/log/qubes

%files -n pulseaudio-qubes
Expand Down

0 comments on commit 9037533

Please sign in to comment.