From cf408a4223af52b50d3a9a5a053b5e51293634c207302e9067d982635411a974 Mon Sep 17 00:00:00 2001 From: Stanislav Brabec Date: Fri, 26 Jan 2018 16:15:35 +0000 Subject: [PATCH] Accepting request 563909 from home:sbrabec:branches:kbd-numlock - Move initial NumLock handling from systemd back to kbd: * Add kbdsettings service written by Thomas Blume (boo#1010880, kbdsettings, kbdsettings.service, numlockbios.c, update sysconfig.console and sysconfig.keyboard). * Exclude numlockbios support for non x86 platforms (kbdsettings-nox86.patch). - Drop references to KEYTABLE and COMPOSETABLE (boo#1010880#c32, boo#1010880#c54, sysconfig.keyboard.del, README.SUSE, drop kbd.fillup). - Fix paths in kbd.pl. OBS-URL: https://build.opensuse.org/request/show/563909 OBS-URL: https://build.opensuse.org/package/show/Base:System/kbd?expand=0&rev=105 --- README.SUSE | 29 ++++++++------------- kbd.changes | 14 +++++++++++ kbd.fillup | 29 --------------------- kbd.pl | 6 ++--- kbd.spec | 56 +++++++++++++++++++++++++++++++++++------ kbdsettings | 50 ++++++++++++++++++++++++++++++++++++ kbdsettings-nox86.patch | 42 +++++++++++++++++++++++++++++++ kbdsettings.service | 14 +++++++++++ numlockbios.c | 52 ++++++++++++++++++++++++++++++++++++++ sysconfig.console | 40 ++++++++++++++++++++++++++++- sysconfig.keyboard | 9 ++++--- 11 files changed, 280 insertions(+), 61 deletions(-) delete mode 100644 kbd.fillup create mode 100644 kbdsettings create mode 100644 kbdsettings-nox86.patch create mode 100644 kbdsettings.service create mode 100644 numlockbios.c diff --git a/README.SUSE b/README.SUSE index e47377b..4e2bb20 100644 --- a/README.SUSE +++ b/README.SUSE @@ -1,16 +1,17 @@ Handling of composition of characters -========================================= +===================================== + Most of the fonts have much more characters than you can reach directly -through the keyboard. To access all of them you may use showconsolefont, -deduce the decimal code and enter it by holding down and entering +through the keyboard. To access all of them you may use showconsolefont, +deduce the decimal code and enter it by holding down and entering the code via the keypad. There's a much better way, though: Most characters may be entered via composition. Many characters are just consisting of a standard character with some sort of accent or change. Such characters can be composed by composition. Just press the key, let it go again, enter the accent and then the letter. Some examples: (Assuming Iso-Latin-1/9 character set:) - " a => ä - , c => ç + " a => ä + , c => ç | S => $ Support for composition is unfortunately not contained in most keymaps. @@ -18,21 +19,16 @@ Most lack two things: (a) The key is not mapped (b) The compose tables are not included -The kbd setup scripts uses another /etc/sysconfig/keyboard variable to -determine which compose tables should be loaded and whether the compose key -should be mapped: COMPOSETABLE. -For all words listed there, loadkeys will be called with the argument -compose.word. (Except for clear which sets a flag to clear the compose -table.) Look at the compose.* files in /usr/share/kbd/keymaps/include/: +Look at the compose.* files in /usr/share/kbd/keymaps/include/: (a) You find there two files for having the key mapped. -(b) You find there compose tables which are suitable for different +(b) You find there compose tables which are suitable for different character sets. ad (a): winkeys: The compose key will be mapped on the W*n menu key shiftctrl: The compose key will be mapped to Shift Ctrl. You can use both, if you like. -ad (b): latin, latinX, latin1.add, 8859_X: Contains the compose - combinations suitable for the respective character set. +ad (b): latin, latinX, latin1.add, 8859_X: Contains the compose + combinations suitable for the respective character set. Many people will want to use latin1 or latin1.add. Just using latin is also sort of an acceptable compromise for many Latin character sets. @@ -40,10 +36,7 @@ ad (b): latin, latinX, latin1.add, 8859_X: Contains the compose If you want the combination of more than one table, you have to create a file which includes what you want. -Example: (/etc/sysconfig/keyboard) -COMPOSETABLE="clear winkeys shiftctrl latin1.add" - -Please keep in mind, that all these settings only affect the console, +Please keep in mind, that all these settings only affect the console, i.e. text mode. Your SuSE team diff --git a/kbd.changes b/kbd.changes index f6254f7..5c42057 100644 --- a/kbd.changes +++ b/kbd.changes @@ -1,3 +1,17 @@ +------------------------------------------------------------------- +Fri Jan 12 17:39:18 CET 2018 - sbrabec@suse.com + +- Move initial NumLock handling from systemd back to kbd: + * Add kbdsettings service written by Thomas Blume (boo#1010880, + kbdsettings, kbdsettings.service, numlockbios.c, + update sysconfig.console and sysconfig.keyboard). + * Exclude numlockbios support for non x86 platforms + (kbdsettings-nox86.patch). +- Drop references to KEYTABLE and COMPOSETABLE (boo#1010880#c32, + boo#1010880#c54, sysconfig.keyboard.del, README.SUSE, + drop kbd.fillup). +- Fix paths in kbd.pl. + ------------------------------------------------------------------- Wed Dec 6 13:30:49 UTC 2017 - fbui@suse.com diff --git a/kbd.fillup b/kbd.fillup deleted file mode 100644 index e4db3a8..0000000 --- a/kbd.fillup +++ /dev/null @@ -1,29 +0,0 @@ -# -# Compose tables to be loaded. -# Compose tables are good for producing characters, which can not -# be directly input from your keyboard, such as characters with -# accents, currency signs, ... -# Please read /usr/share/doc/packages/kbd/README.SUSE for an -# explanation. -# You may leave this variable empty (default compose table from kernel -# or KEYTABLE will be used then -- most keyboard maps don't have a -# compose table, though) -# More than one compose table can be given. For a selection of possible -# tables see /usr/share/kbd/keymaps/include/compose.* -# You can give more than one compose table, but only the last one will -# determine the compose combinations. -# The word "clear" has a special meaning: -# Your compose table will be cleared, before more compose symbols are -# added. -# The files compose.winkeys and shiftctrl may be used to map the -# key to the W*n menu key and Shift-Ctrl, respectively, -# on a PC keyboard. -# A typical setting for Latin1 users (with a PC keyboard) may be -# COMPOSETABLE="clear winkeys shiftctrl latin1.add" -# For latin2, this would be -# COMPOSETABLE="clear winkeys shiftctrl latin2" -# A typical setting for sb. with a character set, where a matching -# compose table is missing (but with a PC keyboard), would be -# COMPOSETABLE="winkeys shiftctrl" -# -COMPOSETABLE="clear winkeys shiftctrl latin1.add" diff --git a/kbd.pl b/kbd.pl index a6d7db5..621f651 100644 --- a/kbd.pl +++ b/kbd.pl @@ -3,8 +3,8 @@ # simple script to switch the keyboard language # (c) 2014 jw@owncloud.om -my $sysconffile = '/etc/sysconfig/keyboard'; -my $mapdir = '/usr/share/kbd/keymaps/i386'; +my $sysconffile = '/etc/vconsole.conf'; +my $mapdir = '/usr/share/kbd/keymaps/xkb'; my $version = '1.0'; @@ -74,7 +74,7 @@ $what = "$what.map.gz" if $m->{"$what.map.gz"}; die "$what: keymap not found.\n Try $0 -h\n" unless $m->{$what}; -write_sysconf($sysconffile, { 'KEYTABLE' => $what } ); +write_sysconf($sysconffile, { 'KEYMAP' => $what } ); # system("kbd_mode -u"); # switch to unicode. Should be the default anyway. system("loadkeys $what"); # now set the keymap. diff --git a/kbd.spec b/kbd.spec index 96f3297..31f9667 100644 --- a/kbd.spec +++ b/kbd.spec @@ -1,7 +1,7 @@ # # spec file for package kbd # -# Copyright (c) 2017 SUSE LINUX GmbH, Nuernberg, Germany. +# Copyright (c) 2018 SUSE LINUX GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -35,7 +35,6 @@ Source1: kbd_fonts.tar.bz2 Source2: suse-add.tar.bz2 Source3: README.SUSE Source4: vlock.pamd -Source5: kbd.fillup Source8: sysconfig.console Source9: sysconfig.keyboard Source11: fbtest.c @@ -43,6 +42,9 @@ Source12: fbtest.8 Source13: guess_encoding.pl Source14: kbd.pl Source15: cz-map.patch +Source20: kbdsettings +Source21: kbdsettings.service +Source22: numlockbios.c Source42: convert-kbd-mac.sed Source43: repack_kbd.sh Source44: xml2lst.pl @@ -61,6 +63,8 @@ Patch12: kbd-2.0.2-fix-bashisms.patch # Patch13: adds xkb and legacy keymaps subdirs to loadkyes search path # (openSUSE FATE#318355, sle FATE#318426) Patch13: kbd-1.15.5-loadkeys-search-path.patch +# PATCH-FEATURE-OPENSUSE kbdsettings-nox86.patch sbrabec@suse.cz -- Disable "bios" option for NumLock settings on non x86 platforms. +Patch14: kbdsettings-nox86.patch BuildRequires: automake BuildRequires: bison BuildRequires: check-devel @@ -102,8 +106,13 @@ Please note that %{name}-legacy is not helpful without kbd. %prep %setup -q -a 1 -a 2 -n kbd-%{version} +cp -fp %{SOURCE8} . +cp -fp %{SOURCE9} . cp -fp %{SOURCE44} . cp -fp %{SOURCE45} . +cp -fp %{SOURCE20} . +cp -fp %{SOURCE21} . +cp -fp %{SOURCE22} . %patch0 -p1 %patch2 %patch3 @@ -116,6 +125,9 @@ cp -fp %{SOURCE45} . %patch11 %patch12 -p1 %patch13 -p1 +%ifnarch %{ix86} x86_64 +%patch14 -p0 +%endif %build for i in `find data/keymaps/mac -type f` ; do @@ -140,7 +152,10 @@ popd --localedir=%{_datadir}/locale \ --enable-optional-progs make %{?_smp_mflags} -gcc %{optflags} -o fbtest $RPM_SOURCE_DIR/fbtest.c +gcc %{optflags} -o fbtest $RPM_SOURCE_DIR/fbtest.c +%ifarch %{ix86} x86_64 +gcc %{optflags} -o numlockbios $RPM_SOURCE_DIR/numlockbios.c +%endif # fix lat2-16.psfu (bnc#340579) font=data/consolefonts/lat2a-16.psfu ./src/psfxtable -i $font -it data/unimaps/lat2u.uni \ @@ -241,9 +256,8 @@ done ) FILLUP_DIR=%{buildroot}%{_fillupdir} mkdir -p $FILLUP_DIR -install -m 644 %{SOURCE8} $FILLUP_DIR/sysconfig.console -install -m 644 %{SOURCE9} $FILLUP_DIR/sysconfig.keyboard -cat %{SOURCE5} >> $FILLUP_DIR/sysconfig.keyboard +install -m 644 sysconfig.console $FILLUP_DIR/sysconfig.console +install -m 644 sysconfig.keyboard $FILLUP_DIR/sysconfig.keyboard %ifnarch %{ix86} x86_64 rm -f %{buildroot}%{_mandir}/man8/resizecons.8* %endif @@ -251,7 +265,11 @@ cat %{SOURCE5} >> $FILLUP_DIR/sysconfig.keyboard rm -f %{buildroot}%{_mandir}/man8/getkeycodes.8* rm -f %{buildroot}%{_mandir}/man8/setkeycodes.8* %endif -install -m 755 fbtest %{buildroot}%{_sbindir} +install -m 755 fbtest %{buildroot}%{_sbindir} +%ifarch %{ix86} x86_64 +install -d %{buildroot}%{_libexecdir}/%{name} +install -m 755 numlockbios %{buildroot}%{_libexecdir}/%{name} +%endif install -d %{buildroot}%{_sysconfdir}/pam.d install -m 644 %{SOURCE4} %{buildroot}%{_sysconfdir}/pam.d/vlock install -m 644 %{SOURCE12} %{buildroot}%{_mandir}/man8/ @@ -341,14 +359,32 @@ mkdir -p %{buildroot}%{_datadir}/systemd sh ./genmap4systemd.sh %{buildroot}%{kbd}/keymaps/xkb \ > %{buildroot}%{_datadir}/systemd/kbd-model-map.xkb-generated +install -m0755 kbdsettings %{buildroot}%{_sbindir}/ +install -d %{buildroot}%{_prefix}/lib/systemd/system +install -m0644 kbdsettings.service %{buildroot}%{_prefix}/lib/systemd/system + %find_lang %{name} +%pre +%{service_add_pre kbdsettings.service} + %post %{fillup_only -n console} %{fillup_only -n keyboard} +# Variables deleted before Leap 15 and SLE 15 +%{remove_and_set -n keyboard KEYTABLE COMPOSETABLE} +%ifnarch %{ix86} x86_64 +# "bios" was accepted but ingnored on non-x86 platforms up to Leap 42.* and SLE 12.* +sed -i 's/^KBD_NUMLOCK="bios"/KBD_NUMLOCK="no"/' /etc/sysconfig/keyboard +%endif +%{service_add_post kbdsettings.service} %{?regenerate_initrd_post} +%preun +%{service_del_preun kbdsettings.service} + %postun +%{service_del_postun kbdsettings.service} %{?regenerate_initrd_post} %posttrans @@ -448,6 +484,10 @@ sh ./genmap4systemd.sh %{buildroot}%{kbd}/keymaps/xkb \ %{_bindir}/spawn_console %{_bindir}/spawn_login %{_bindir}/vlock +%ifarch %{ix86} x86_64 +%dir %{_libexecdir}/%{name} +%{_libexecdir}/%{name}/numlockbios +%endif %{_mandir}/man1/* %{_mandir}/man5/keymaps.5%{ext_man} %ifnarch %{sparc} m68k @@ -472,7 +512,9 @@ sh ./genmap4systemd.sh %{buildroot}%{kbd}/keymaps/xkb \ %{_mandir}/man8/vcstime.8%{ext_man} %config(noreplace) %{_sysconfdir}/pam.d/vlock %dir %{_datadir}/systemd +%{_prefix}/lib/systemd/system/kbdsettings.service %{_datadir}/systemd/kbd-model-map.xkb-generated +%{_sbindir}/kbdsettings %files legacy %{kbd}/keymaps/legacy diff --git a/kbdsettings b/kbdsettings new file mode 100644 index 0000000..5b944af --- /dev/null +++ b/kbdsettings @@ -0,0 +1,50 @@ +#! /bin/sh + +. /etc/sysconfig/keyboard + +[ $KBD_DELAY ] && /usr/bin/kbdrate -s -d $KBD_DELAY +[ $KBD_RATE ] && /usr/bin/kbdrate -s -r $KBD_RATE + +for i in NUM SCR CAPS; do + conf=$(eval echo KBD_${i}LOCK) + [ -z ${!conf} ] && continue + param=$(echo ${i,,} | sed 's/scr/scroll/') + + for tty in ${KBD_TTY:-tty1 tty2 tty3 tty4 tty5 tty6}; do + case "${!conf}" in + yes) + if [ $param = "num" ]; then + touch /run/numlock-on + fi + /usr/bin/setleds -D +$param < /dev/$tty + ;; + no) + if [ $param = "num" ]; then + rm -f /run/numlock-on + fi + /usr/bin/setleds -D -$param < /dev/$tty + ;; + bios) + bios=$(/usr/lib/kbd/numlockbios 2>/dev/null) + if [ $param = "num" ]; then + if [ "$bios" = "on" ]; then + touch /run/numlock-on + /usr/bin/setleds -D +$param < /dev/$tty + elif [ "$bios" = "off" -o "$bios" = "unknown" ]; then + rm -f /run/numlock-on + /usr/bin/setleds -D -$param < /dev/$tty + fi + else + echo "Value ${!conf} invalid for $conf" + fi + ;; + *) + echo "error: unknown value ${!conf} in $conf" + ;; + esac + done +done + +if [ "$KBD_DISABLE_CAPS_LOCK" = "yes" ]; then + /usr/bin/dumpkeys | sed 's/ *58 *= *Caps_Lock/ 58 = Control/' | /usr/bin/loadkeys -q - +fi diff --git a/kbdsettings-nox86.patch b/kbdsettings-nox86.patch new file mode 100644 index 0000000..0ac070d --- /dev/null +++ b/kbdsettings-nox86.patch @@ -0,0 +1,42 @@ +--- kbdsettings ++++ kbdsettings +@@ -24,20 +24,6 @@ + fi + /usr/bin/setleds -D -$param < /dev/$tty + ;; +- bios) +- bios=$(/usr/lib/kbd/numlockbios 2>/dev/null) +- if [ $param = "num" ]; then +- if [ "$bios" = "on" ]; then +- touch /run/numlock-on +- /usr/bin/setleds -D +$param < /dev/$tty +- elif [ "$bios" = "off" -o "$bios" = "unknown" ]; then +- rm -f /run/numlock-on +- /usr/bin/setleds -D -$param < /dev/$tty +- fi +- else +- echo "Value ${!conf} invalid for $conf" +- fi +- ;; + *) + echo "error: unknown value ${!conf} in $conf" + ;; +--- sysconfig.keyboard ++++ sysconfig.keyboard +@@ -15,12 +15,12 @@ + # Keyboard repeat rate (2.0 - 30.0) + KBD_RATE="" + +-## Type: list(bios,yes,no) +-## Default: bios ++## Type: yesno ++## Default: no + # +-# NumLock on? ("yes" or "no" or "bios" for BIOS setting) ++# NumLock on? ("yes" or "no") + # This setting may interfere with GNOME /org/gnome/settings-daemon/peripherals/keyboard/remember-numlock-state DConf key. +-KBD_NUMLOCK="bios" ++KBD_NUMLOCK="no" + + ## Type: yesno + ## Default: no diff --git a/kbdsettings.service b/kbdsettings.service new file mode 100644 index 0000000..c40d8c0 --- /dev/null +++ b/kbdsettings.service @@ -0,0 +1,14 @@ +[Unit] +Description=Apply settings from /etc/sysconfig/keyboard +After=basic.target +After=systemd-vconsole-setup.service +PartOf=systemd-vconsole-setup.service +ConditionPathExists=/dev/tty0 + +[Service] +Type=oneshot +ExecStart=/usr/sbin/kbdsettings +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target diff --git a/numlockbios.c b/numlockbios.c new file mode 100644 index 0000000..6f7f263 --- /dev/null +++ b/numlockbios.c @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +int main() { + +#define BIOS_DATA_AREA 0x400 +#define BDA_KEYBOARD_STATUS_FLAGS_4 0x97 +#define BDA_KSF4_NUMLOCK_MASK 0x02 + +int fdmem; +char c; +errno=0; + +fdmem = open("/dev/mem", O_RDONLY); + +if (fdmem < 0) { + fprintf(stderr, "Couldn't open /dev/mem; %s\n", strerror(errno)); + goto finish; +} + +if (lseek(fdmem, BIOS_DATA_AREA + BDA_KEYBOARD_STATUS_FLAGS_4, SEEK_SET) == (off_t) -1) { + fprintf(stderr, "Failed to seek /dev/mem: %s\n", strerror(errno)); + goto finish; +} + +if (read (fdmem, &c, sizeof(char)) == -1) { + fprintf(stderr, "Failed to read /dev/mem: %s\n", strerror(errno)); + goto finish; +} + +if (c & BDA_KSF4_NUMLOCK_MASK) + printf("on\n"); + else + printf("off\n"); + +finish: + close(fdmem); + + if (errno) + { + printf("unknown\n"); + exit(EXIT_FAILURE); + } + +return 0; +} diff --git a/sysconfig.console b/sysconfig.console index 08ba553..ba874a2 100644 --- a/sysconfig.console +++ b/sysconfig.console @@ -1,5 +1,44 @@ ## Path: Hardware/Console ## Description: Text console settings (see also Hardware/Keyboard) +# + +## Type: string +## Default: "" +# +# Console settings. +# Note: The KBD_TTY setting from Hardware/Keyboard (sysconfig/keyboard) +# also applies for the settings here. +# +# Load this console font on bootup: +# (/usr/share/kbd/consolefonts/) +# +CONSOLE_FONT="" + +## Type: string +## Default: "" +# +# Some fonts come without a unicode map. +# (.psfu fonts supposedly have it, others often not.) +# You can then specify the unicode mapping of your font +# explicitly. (/usr/share/kbd/unimaps/) +# Normally not needed. +# +CONSOLE_UNICODEMAP="" + +## Type: string +## Default: "" +# +# Most programs output 8 bit characters, so you need a table to +# translate those characters into unicode. That one can be specified +# here. (/usr/share/kbd/consoletrans/) +# (Note: If your console is in utf-8 mode you don't need this.) +# If your code does not use a unicode mapping at all (because you +# e.g. explicitly specified UNICODEMAP="none") you may circumvent +# the translation via unicode, but load a map which directly maps +# 8 bit output of your program to a font position. +# +CONSOLE_SCREENMAP="" + ## Type: string ## Default: "" # @@ -8,4 +47,3 @@ # Normally not needed (automatically handled by setfont). # CONSOLE_MAGIC="" - diff --git a/sysconfig.keyboard b/sysconfig.keyboard index 3882436..0dbb31f 100644 --- a/sysconfig.keyboard +++ b/sysconfig.keyboard @@ -1,5 +1,8 @@ ## Path: Hardware/Keyboard -## Description: Keyboard settings +## Description: Keyboard settings for the text console +## ServiceRestart: kbdsettings +# + ## Type: integer ## Default: # @@ -15,8 +18,8 @@ KBD_RATE="" ## Type: list(bios,yes,no) ## Default: bios # -# NumLock on? ("yes" or "no" or empty or "bios" for BIOS setting) -# This setting may interfere with GNOME /desktop/gnome/peripherals/keyboard/remember_numlock_state GConf key. +# NumLock on? ("yes" or "no" or "bios" for BIOS setting) +# This setting may interfere with GNOME /org/gnome/settings-daemon/peripherals/keyboard/remember-numlock-state DConf key. KBD_NUMLOCK="bios" ## Type: yesno