XFCE - The keyboard layout changes automatically

Non release banter
Kulle
Warlord
Warlord
Posts: 501
Joined: 28 Jan 2017, 10:39
Distribution: v4.0 64bit Xfce
Location: Berlin

XFCE - The keyboard layout changes automatically

Post#1 by Kulle » 13 Jan 2023, 14:04

Hi all,

In porteus-v5.0-x86_64.cfg I have registered kmap=de

If I don't shut down but go into standby mode, then the setting changes to us
I then have to use the command setxkbmap de

That's annoying
Can the problem be solved?
Last edited by Rava on 26 Jan 2023, 01:37, edited 1 time in total.
Reason: To clarify I added "XFCE" to the subject title.

ruthmarx
Ronin
Ronin
Posts: 1
Joined: 24 Jan 2023, 14:00
Distribution: None

The keyboard layout changes automatically

Post#2 by ruthmarx » 24 Jan 2023, 14:03

Did you try to deinstall the German keyboard and then install it again?

User avatar
Rava
Contributor
Contributor
Posts: 4606
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.0 x86_64 + 4.0 i586
Location: Forests of Germany

The keyboard layout changes automatically

Post#3 by Rava » 24 Jan 2023, 20:30

Kulle wrote:
13 Jan 2023, 14:04
In porteus-v5.0-x86_64.cfg I have registered kmap=de

If I don't shut down but go into standby mode, then the setting changes to us
I then have to use the command setxkbmap de
Which DE do you use?
(aka post your

Code: Select all

cat /etc/porteus/*
I use XFCE 4.16 V20220925

My setting is via kernel cheatcode in porteus.cfg, but that should make no difference to your porteus-v5.0-x86_64.cfg approach

Slightly off topic:
(though it would be interesting to know when there are conflicting infos in porteus-v5.0-x86_64.cfg and in the boot APPEND line of porteus.cfg - what would happen?
Would one override the other or would the kernel halt the boot and complain?
E.g. have kmap=de in APPEND line of porteus.cfg - and kmap=es in porteus-v5.0-x86_64.cfg.)

Back on topic:

I have

Code: Select all

kmap=de lang=de
via APPEND line of porteus.cfg, and I use Suspend (There is no "standby" option, only Suspend, Hibernate or Hybrid.).
And after suspend, the keyboard is still German (Germany) (no dead keys).
But when I unplug the external keyboard (it is a notebook with internal keyboard that I hardly ever use (the internal keyboard, that is)) and re-plug it, then sometimes the keyboard got reset to en-US, but other times it not gets reset.
Cheers!
Yours Rava

Kulle
Warlord
Warlord
Posts: 501
Joined: 28 Jan 2017, 10:39
Distribution: v4.0 64bit Xfce
Location: Berlin

The keyboard layout changes automatically

Post#4 by Kulle » 25 Jan 2023, 18:03

Hi Rava,
I use Porteus 5.0 Xfce
and in porteus-v5.0-x86_64.cfg file I have: kmap=de lang=de

I run now (for control) in always fresh mode.
But the same problem

After Suspend : Keyboard map changes from "de" to "us"

beny
Full of knowledge
Full of knowledge
Posts: 1664
Joined: 02 Jan 2011, 11:33
Location: italy

The keyboard layout changes automatically

Post#5 by beny » 25 Jan 2023, 18:12

copy this from /usr/share/X11/xorg.conf.d/90-keyboard-layout.conf in /etc/X11/xorg.conf.d/ with your language but you have also /etc/profile.d/lang.csh
/etc/profile.d/lang.sh
you have to change with your language and i think when you resume you have your language keyboard

Kulle
Warlord
Warlord
Posts: 501
Joined: 28 Jan 2017, 10:39
Distribution: v4.0 64bit Xfce
Location: Berlin

The keyboard layout changes automatically

Post#6 by Kulle » 25 Jan 2023, 18:16

Hi Rava, I use 4.16

Code: Select all

guest@porteus:~$ xfce4-panel --version
xfce4-panel 4.16.3 (Xfce 4.16)

User avatar
Rava
Contributor
Contributor
Posts: 4606
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.0 x86_64 + 4.0 i586
Location: Forests of Germany

The keyboard layout changes automatically

Post#7 by Rava » 26 Jan 2023, 01:20

beny wrote:
25 Jan 2023, 18:12
copy this from /usr/share/X11/xorg.conf.d/90-keyboard-layout.conf in /etc/X11/xorg.conf.d/ with your language but you have also /etc/profile.d/lang.csh
/etc/profile.d/lang.sh
I use bash and that should use /etc/profile.d/lang.sh
My lang.sh:

Code: Select all

guest@porteus:~$ grep =en_ /etc/profile.d/lang.sh
export LANG=en_US.UTF-8
#export LANG=en_US.ISO8859-1
I think that results in this:

Code: Select all

guest@porteus:~$ echo $LANG 
en_US.UTF-8
even when I use the kernel cheatcode of kmap=de lang=de
Seems beny once more knows his stuff, and I need to use an updated /etc/profile.d/lang.sh

beny, would this be the correct way:

Code: Select all

#!/bin/sh
# Set the system locale.  (no, we don't have a menu for this ;-)
# For a list of locales which are supported by this machine, type:
#   locale -a

# 'C' is the old Slackware (and UNIX) default, which is 127-bit
# ASCII with a charmap setting of ANSI_X3.4-1968.  These days,
# it's better to use en_US or another modern $LANG setting to
# support extended character sets.
#export LANG=C

# There is also support for UTF-8 locales, but be aware that
# some programs are not yet able to handle UTF-8 and will fail to
# run properly.  In those cases, you can set LANG=C before
# starting them.  Still, I'd avoid UTF unless you actually need it.
export LANG=de_DE.UTF-8

# Another option for en_US:
#export LANG=en_US.ISO8859-1

# One side effect of the newer locales is that the sort order
# is no longer according to ASCII values, so the sort order will
# change in many places.  Since this isn't usually expected and
# can break scripts, we'll stick with traditional ASCII sorting.
# If you'd prefer the sort algorithm that goes with your $LANG
# setting, comment this out.
export LC_COLLATE=C

# End of /etc/profile.d/lang.sh
────────────────────────────────────────────────────────────────────────
Kulle wrote:
25 Jan 2023, 18:16
Hi Rava, I use 4.16
Same here:

Code: Select all

guest@porteus:/$ xfce4-panel --version
xfce4-panel 4.16.3 (Xfce 4.16)

Copyright (c) 2004-2011
	The Xfce development team. All rights reserved.

Please report bugs to <http://bugzilla.xfce.org/>.
Maybe it's my saved and re-loaded at each boot (via my 991-rootcopy.xzm module) /home/guest/.config/xfce4/xfconf/xfce-perchannel-xml/keyboard-layout.xml :

Code: Select all

guest@porteus:~/.config/xfce4/xfconf/xfce-perchannel-xml$ grep de keyboard-layout.xml
    <property name="XkbLayout" type="string" value="de"/>
    <property name="XkbVariant" type="string" value="nodeadkeys"/>
The complete /home/guest/.config/xfce4/xfconf/xfce-perchannel-xml/keyboard-layout.xml :

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>

<channel name="keyboard-layout" version="1.0">
  <property name="Default" type="empty">
    <property name="XkbDisable" type="bool" value="false"/>
    <property name="XkbLayout" type="string" value="de"/>
    <property name="XkbVariant" type="string" value="nodeadkeys"/>
  </property>
</channel><?xml version="1.0" encoding="UTF-8"?>

<channel name="keyboard-layout" version="1.0">
  <property name="Default" type="empty">
    <property name="XkbDisable" type="bool" value="false"/>
    <property name="XkbLayout" type="string" value="de"/>
    <property name="XkbVariant" type="string" value="nodeadkeys"/>
  </property>
</channel>
You can also set that via its settings menu Settings ▷ Keyboard, but recall to somehow save your resulting /home/guest/.config/xfce4/xfconf/xfce-perchannel-xml/keyboard-layout.xml … :
Image
Please be aware that I also removed the default keyboard setting of en_US so that there is only de_DE available and no other layout in the below listing, as you can see in the screenshot.
Cheers!
Yours Rava

Kulle
Warlord
Warlord
Posts: 501
Joined: 28 Jan 2017, 10:39
Distribution: v4.0 64bit Xfce
Location: Berlin

XFCE - The keyboard layout changes automatically

Post#8 by Kulle » 26 Jan 2023, 09:47

Hi Rava and beny,

After Suspend : Keyboard map changes from "de" to "us"
That means there are always small imperfections!

But I'll leave it at that.

I then use the command: setxkbmap de

User avatar
Rava
Contributor
Contributor
Posts: 4606
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.0 x86_64 + 4.0 i586
Location: Forests of Germany

XFCE - The keyboard layout changes automatically

Post#9 by Rava » 26 Jan 2023, 18:40

Kulle wrote:
26 Jan 2023, 09:47
After Suspend : Keyboard map changes from "de" to "us"
That means there are always small imperfections!
Do you use the settings of XFCE -as in - only the DE keymap available as you can see in my screenshot and in the config file I posted?
Kulle wrote:
26 Jan 2023, 09:47
setxkbmap de
I suggest the following:
Create a script to be run as root that handles your suspend. E.g. like so.

Code: Select all

#!/bin/sh
# aliases and functions

function seconds2time () 
{
    local T=$1;
    local D=$((T/60/60/24));
    local H=$((T/60/60%24));
    local M=$((T/60%60));
    local S=$((T%60));
    if [[ ${D} != 0 ]]; then
        if [[ ${D} = 1 ]]; then
            printf '%d day %02d:%02d:%02d' $D $H $M $S;
        else
            printf '%d days %02d:%02d:%02d' $D $H $M $S;
        fi;
    else
        printf '%02d:%02d:%02d' $H $M $S;
    fi
}

function mydate () {
	echo $(date +%d.%m.%Y\ %H:%M:%S) ____________________________________________________________
}

# main
declare -i startepoch=$(date +%s)
mydate
echo loginctl suspend
loginctl suspend
echo $0: sleeping 10 seconds for suspend to finish…
sleep 10s
echo '●●●●● loginctl suspend took '$(seconds2time $(date +%s)-$startepoch)' …'
echo setxkbmap de
setxkbmap de
mydate
It also prints the date/time prior suspend (function mydate)
Calculates and prints the time you spend in suspend (function seconds2time)
Resets your keyboard
Prints date/time prior finishing

when you want none of these extra info and suspend time calculation, then just use this:

Code: Select all

#!/bin/sh
# no aliases nor functions
echo loginctl suspend
loginctl suspend
echo $0: sleeping 10 seconds for suspend to finish…
sleep 10s
echo setxkbmap de
setxkbmap de
Done.

Cave! Put the script into your $PATH, the recommended folder is /usr/local/bin
Make it executable via

Code: Select all

chmod a+x SCRIPT
(when SCRIPT is your scrpt name and you are in the folder where the SCRIPT also sits.

My script that does the suspend for me and also writes even more info than above into /var/log/messages is named suspend-s0 and its file properties are like so:

Code: Select all

root@porteus:/usr/local/bin# ls -l suspend-s0
-rwxr--r-- 1 root root 1610 2022-10-06 05:06 suspend-s0
But your file properties are good enough like in this example:

Code: Select all

root@porteus:/usr/local/bin# ls -l help.yt-dlp 
-rwxr-xr-x 1 root root 2313 2023-01-24 05:39 help.yt-dlp
root@porteus:/usr/local/bin# stat help.yt-dlp |grep 'Access: ('
Access: (0755/-rwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Why is that script owned by root and cannot be edited by guest?
Because of security reasons. The script is in $PATH of all users and in these $PATH I keep all programs and scripts owned by root and while executable by all, only read-only for all others than root gives my system a bit more of security.

Added in 2 minutes 9 seconds:
when guest tries executing the script (s)he gets this error:

Code: Select all

guest@porteus:/$ suspend-s0
bash: /usr/local/bin/suspend-s0: Permission denied
Last edited by Rava on 27 Jan 2023, 03:42, edited 1 time in total.
Reason: fixed syntax error in script code - removed info about it being run only by root (thanks to Ed_P for pointing out both these mistakes)
Cheers!
Yours Rava

beny
Full of knowledge
Full of knowledge
Posts: 1664
Joined: 02 Jan 2011, 11:33
Location: italy

XFCE - The keyboard layout changes automatically

Post#10 by beny » 26 Jan 2023, 20:28

hi i have added glibc-i18n and the copy of the script and i have two keyboard layout that i can choose us and it and after suspend the it layout is ok porteus5

User avatar
Ed_P
Contributor
Contributor
Posts: 7435
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.0 ISO
Location: Western NY, USA

XFCE - The keyboard layout changes automatically

Post#11 by Ed_P » 26 Jan 2023, 23:39

Rava wrote:
26 Jan 2023, 18:42
Make it executable and owned by root, and only executable by root since guest cannot run loginctl suspend.
An impressive script but doesn't need to be run as root. loginctl suspend works for me as guest.

Code: Select all

guest@porteus:~$ date
Thu Jan 26 18:37:10 EST 2023
guest@porteus:~$ loginctl suspend
guest@porteus:~$ date
Thu Jan 26 18:37:40 EST 2023
guest@porteus:~$ 
Your script saved as suspend.sh:

Code: Select all

guest@porteus:~$ chmod +x suspend.sh
guest@porteus:~$ ./suspend.sh
26.01.2023 18:47:22 ____________________________________________________________
loginctl suspend
./suspend.sh: sleeping 10 seconds for suspend to finish…
./suspend.sh: line 33: unexpected EOF while looking for matching `''
./suspend.sh: line 37: syntax error: unexpected end of file
guest@porteus:~$ 
which is just as well, I don't need my kbmap changed. :lol:
Ed

User avatar
Rava
Contributor
Contributor
Posts: 4606
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.0 x86_64 + 4.0 i586
Location: Forests of Germany

XFCE - The keyboard layout changes automatically

Post#12 by Rava » 27 Jan 2023, 03:34

Ed_P wrote:
26 Jan 2023, 23:39
An impressive script but doesn't need to be run as root. loginctl suspend works for me as guest.
Silly me, it was not due to loginctl suspend needing root but the fact that my suspend-s0 script also writes more info into /var/log/messages being the reason why my script needs to be root. :wall:
Thanks for pointing that out.

also the typo why it exits with a syntax error is this:

Code: Select all

echo '●●●●● loginctl suspend took '$(seconds2time $(date +%s)-$startepoch)' …
needs to be this:

Code: Select all

echo '●●●●● loginctl suspend took '$(seconds2time $(date +%s)-$startepoch)' …'
:)
I now edit the above post to change the typo and remove the info about it needing to be run as root.
Cheers!
Yours Rava

Kulle
Warlord
Warlord
Posts: 501
Joined: 28 Jan 2017, 10:39
Distribution: v4.0 64bit Xfce
Location: Berlin

XFCE - The keyboard layout changes automatically

Post#13 by Kulle » 27 Jan 2023, 09:11

Hi Rava,
thank you very much for the script.

But the time is only displayed when I run the script in the terminal.

But I usually run scripts with a double click.
My system is set up that way, I find it more convenient.

I am considering how to receive the ad as a message

User avatar
Rava
Contributor
Contributor
Posts: 4606
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.0 x86_64 + 4.0 i586
Location: Forests of Germany

XFCE - The keyboard layout changes automatically

Post#14 by Rava » 27 Jan 2023, 13:06

Kulle wrote:
27 Jan 2023, 09:11
I am considering how to receive the ad as a message
Using notify-send

Code: Select all

notify-send -i info -t 5000 "Keyboard set" "to DE"
But in that case I would look at the return value of the command or else the popup would print a successful outcome even when the command failed:

Code: Select all

echo setxkbmap de
setxkbmap de
returnval=$?
if [ $returnval -eq 0 ]; then
	notify-send -i info -t 5000 "Keyboard set" "to DE"
else
	notify-send -i error -t 0 "Keyboard setting to" "DE failed"
fi
Or a different style not storing the return value but with a more complex looking code:

Code: Select all

echo setxkbmap de
setxkbmap de && notify-send -i info -t 5000 "Keyboard set" "to DE" || notify-send -i error -t 0 "Keyboard setting to" "DE failed"
Note that -t 5000 is 5 seconds, while -t 0 means: indefinitely.
In case of an error I would recommend the popup to be displayed indefinitely for you to manually acknowledge.
Cheers!
Yours Rava

User avatar
Ed_P
Contributor
Contributor
Posts: 7435
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 5.0 ISO
Location: Western NY, USA

XFCE - The keyboard layout changes automatically

Post#15 by Ed_P » 27 Jan 2023, 14:38

Kulle wrote:
27 Jan 2023, 09:11
But the time is only displayed when I run the script in the terminal.

But I usually run scripts with a double click.
My system is set up that way, I find it more convenient.
Add "read" to the end of the script. The message will be available until you click on the window and press Enter. Another option is to add "sleep 30" to the end of the script to have the message available for 30 seconds after the suspend ends then the window closes. Obviously the time duration is your choice.
Ed

Post Reply