PDA

View Full Version : Xmodmap and setxkbmap



prussell
14-May-2015, 17:18
Hi Forums!
I mistakenly posted this on the OpenSUSE forums, so I'll attempt to reproduce the thread flow here:

I have bought a new keyboard to help my RSI, it's like an ergonomic keyboard and I need to swap Left arrow cursor with Delete to get normal usage.

Running xmodmap queries yields:


:~> xmodmap -pke | grep Del
keycode 91 = KP_Delete KP_Decimal KP_Delete KP_Decimal
keycode 119 = Delete NoSymbol Delete

~> xmodmap -pke | grep Left
keycode 23 = Tab ISO_Left_Tab Tab ISO_Left_Tab
keycode 83 = KP_Left KP_4 KP_Left KP_4
keycode 113 = Left NoSymbol Left


I found that by adding to a new file ~/.Xmodmap



keycode 113=Delete
keycode 119=Left

The problem was fixed. However, it's not persistent, so to try to sort this, I added to my ~/.bashrc


xmodmap /user/prussell/.Xmodmap

This is a partial fix, because I have to open a terminal session to activate it! More to the point, I know now, xmodmap is deprecated. In short, can anyone tell me where and how to achieve the sample simple bindings for SUSE Enterprise desktop, using the more modern setxkbmap on X11?

My version of Linux is : SUSE Linux Enterprise Desktop, x86 & x86-64
I use a UK keyboard layout, and this is the 104 key version.


Thanks!

mikewillis
14-May-2015, 18:48
My version of Linux is : SUSE Linux Enterprise Desktop, x86 & x86-64


Which version of SUSE Linux Enterprise Desktop? If you're not sure


$ cat /etc/*release*

prussell
14-May-2015, 20:18
Hi Mike

Thanks for your reply.



NAME="SLED"
VERSION="12"
VERSION_ID="12"
PRETTY_NAME="SUSE Linux Enterprise Desktop 12"
ID="sled"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:suse:sled:12"
SUSE Linux Enterprise Desktop 12 (x86_64)
VERSION = 12
PATCHLEVEL = 0


I hope that helps!

prussell
14-May-2015, 21:19
Following this

http://unix.stackexchange.com/questions/65507/use-setxkbmap-to-swap-the-left-shift-and-left-control

Pablo;s entry. I tried this



Partial modifier_keys
xkb_symbols "swap_del_left" {
replace key <DELE> { [ Left ] };
replace key <LEFT> { [ Delete ] };
};


Ran it from here:


setxkbmap -I/home/prussell/.xkb/keymap/mykbd $DISPLAY


No luck though!

mikewillis
14-May-2015, 22:30
Following this

http://unix.stackexchange.com/questions/65507/use-setxkbmap-to-swap-the-left-shift-and-left-control

Pablo;s entry. I tried this



Partial modifier_keys
xkb_symbols "swap_del_left" {
replace key <DELE> { [ Left ] };
replace key <LEFT> { [ Delete ] };
};


Ran it from here:


setxkbmap -I/home/prussell/.xkb/keymap/mykbd $DISPLAY


No luck though!

That setxkbmap command for loading the map doesn't appear in the page you link to. What's in that page you link to works fine for me if I use xkbcomp to load the map.



mike@Unknown:~> cat ~/.xkb/keymap/mykbd
xkb_keymap {
xkb_keycodes { include "evdev+aliases(qwerty)" };
xkb_types { include "complete" };
xkb_compat { include "complete" };
xkb_symbols { include "pc+gb+us:2+inet(evdev)+terminate(ctrl_alt_bksp)+te rminate(ctrl_alt_bksp)+myswap(swap_del_left)" };
xkb_geometry { include "pc(pc105)" };
mike@Unknown:~> cat ~/.xkb/symbols/myswap
Partial modifier_keys
xkb_symbols "swap_del_left" {
replace key <DELE> { [ Left ] };
replace key <LEFT> { [ Delete ] };
};
mike@Unknown:~> xkbcomp -I${HOME}/.xkb ${HOME}/.xkb/keymap/mykbd $DISPLAY


Can't just figure out how to (effectively) run it automatically at login. Calling it from a .desktop file in ~/.config/autostart/ doesnt work, nor does putting the command in to a script preceded by 'sleep 10' then calling that from a .desktop file in ~/.config/autostart/

prussell
15-May-2015, 11:31
Thanks, Mike!

I'll try that a bit later today, and will let you know my results. Ref, firing this thing up at start-up: is there not some kind of start-up package in Suse?

Best, Paul

prussell
15-May-2015, 12:02
Thanks, Mike!

I'll try that a bit later today, and will let you know my results. Ref, firing this thing up at start-up: is there not some kind of start-up package in Suse?

Best, Paul

That works! Thanks! Now all that remains is how to make it fire on login!

mikewillis
15-May-2015, 13:21
Ref, firing this thing up at start-up: is there not some kind of start-up package in Suse?


Well GNOME has the facility to start applications at log in* and what it does behind the scenes is put a copy of the relevant application's .desktop file in ~/.config/autostart/ But like I said, calling the xkbcomp command from a .desktop file in there has no effect. It gets run, just doesn't have an effect.


* On SLED 12 run gnome-tweak-tool** and look in 'Startup Applications'. Clicking the + sign gets you a list of applications you can add unhelpfully listed in no apparent order with no apparent way to search the list. There's no way to manually specify something to run, like was provided in GNOME 2, you can only select from the list.

** Run it from command line or pressing Alt-F2, or find 'Tweak Tool' in GNOME Control Centre. You won't find it in the Applications menu or the Activities Overview search because SUSE have deliberately made it not show up there in SLED 12. You will find something called 'GNOME Configuration Tool' though, SUSE didn't hide that even though it's gconf-editor which is of almost zero use given that in GNOME 3 almost everything uses dconf. SUSE have also deliberately hidden dconf-editor in the same way as gnome-tweak-tool despite that being vastly more useful than gconf-editor.

malcolmlewis
15-May-2015, 14:32
On Fri 15 May 2015 12:24:02 PM CDT, mikewillis wrote:


prussell;27897 Wrote:
>
> Ref, firing this thing up at start-up: is there not some kind of
> start-up package in Suse?
>

Well GNOME has the facility to start applications at log in* and what it
does behind the scenes is put a copy of the relevant application's
..desktop file in ~/.config/autostart/ But like I said, calling the
xkbcomp command from a .desktop file in there has no effect. It gets
run, just doesn't have an effect.


* On SLED 12 run gnome-tweak-tool** and look in 'Startup Applications'.
Clicking the + sign gets you a list of applications you can add
unhelpfully listed in no apparent order with no apparent way to search
the list. There's no way to manually specify something to run, like was
provided in GNOME 2, you can only select from the list.

** Run it from command line or pressing Alt-F2, or find 'Tweak Tool' in
GNOME Control Centre. You won't find it in the Applications menu or the
Activities Overview search because SUSE have deliberately made it not
show up there in SLED 12. You will find something called 'GNOME
Configuration Tool' though, SUSE didn't hide that even though it's
gconf-editor which is of almost zero use given that in GNOME 3 almost
everything uses dconf. SUSE have also deliberately hidden dconf-editor
in the same way as gnome-tweak-tool despite that being vastly more
useful than gconf-editor.




Hi
Create a systemd service file and run it systemwide....

--
Cheers Malcolm °¿° LFCS, SUSE Knowledge Partner (Linux Counter #276890)
SUSE Linux Enterprise Desktop 12 GNOME 3.10.1 Kernel 3.12.39-47-default
If you find this post helpful and are logged into the web interface,
please show your appreciation and click on the star below... Thanks!

prussell
16-May-2015, 18:08
Well, thanks for trying for me, Mike :) I sure appreciate it!

I've bodged a temporary solution with a few desktop shortcuts which run xmodmaps. This is working, and I;ve other fish to fry right now.

Regards the way Linux seems to be going-- during scouting for a solution to my problem, I'm surprised that xmodmap is deprecated, as I found that easy to use. Though i'm sure there's a reason for this, it;s replacement is difficult to fathom out.

I tried all manner of things, I put scripts inside my init.d folders, but couldn't get this to work. Did I read somewhere that init.d after.local doesn't work anymore?
The point I'd make is this: I,m new to Linux, and am a Java programmer from a Windows background. The only Linux skills I have I gleaned years ago during my college days. Deprecating parts of the system and then hiding others makes life tough for newbs like me. I love the product though:=unlike Open Suse and about five other distros, it installed on my Nofen silent PC without hitch. Everything works, including the VGA, Bluetooth, wifi, twin monitors. I can tell you, it's very different story from when I last tried to install Linux! Happy bunny, but wish Suse hadn't hidden so much.

mikewillis
16-May-2015, 21:36
Depreciation is not unique to the Linux world.

Simply dropping scripts in to init.d isn't going to achieve anything. You'd need to write them as services and enable them. In any case SLED 12 uses systemd for the init system to the way to get stuff running at boot is to create a unit file and put it in /etc/systemd/system/

Dropping the line

echo "i ran" > /dev/shm/$(basename $0)
in to /etc/init.d/after.local shows it does get called during boot. I don't know exactly when in the boot process it get called. The comments in it are unhelpfully vague even in the context of sysvinit and I suspect whatever their meaning is supposed to be is no longer true with systemd. (I know for a fact that systemd makes the comments in boot.local about when it gets run false.)


It seems like it would be possible to get xkbcomp to work when run from the init system by calling a suitable script. The script would need more than just the xkbcomp command in it. E.g If I log in as root via ssh I can set the keyboard map with


$ XAUTHORITY=$(ps --no-headers $(pidof Xorg) | awk '{print $11}') xkbcomp -I/home/mike/.xkb /home/mike/.xkb/keymap/mykbd :0

You'd have to make craft the dependencies in the systemd unit file to ensure the script didn't run until after X was up and running.

Amusing you only want the mod for your own user it's easier to do it within the context of your own user though.



mike@Unknown:~> cat .config/autostart/modkeybdmap.desktop
[Desktop Entry]
Name=My keyboard map mod
Exec=/home/mike/bin/modkeyboardmap
Type=Application
mike@Unknown:~> cat /home/mike/bin/modkeyboardmap
#!/bin/bash
sleep 10
xkbcomp -I${HOME}/.xkb ${HOME}/.xkb/keymap/mykbd $DISPLAY
mike@Unknown-:~>
You need to make modkeyboardmap executable

mike@Unknown-:~> chmod u+x~/bin/modkeyboardmap
I could have sworn I tried this the other day and it didn't work. But it's consistently working for me now.