You are not logged in.
I hope this is in the right section and doesn't belong under the Games subforum. While I'm doing this specifically for a game, I think it's a generic X issue that I'm making rather than something specific to Minecraft.
I normally use KDE as my DE with Caps and Esc swapped in the System Settings. Yesterday I read about running games on their own X Server, partly to prevent a crashing game potentially taking out the entirety of my primary X server. I put together a script that uses xinit to start the game on a new X display and all seemed to be working fine (well except that I cannot use the keyboard in the game menus - but I suspect that's a game bug for now as the login form before, and the game after, it works fine).
This is the script I'm using
x-minecraft.sh
#!/bin/bash
DISPLAY=:1.0
xinit /usr/bin/minecraft -- :1However Minecraft makes a large use of Esc, which I'm used to having under my little finger, but which isn't there on this new X as KDE isn't running here. So I'm trying to configure this new X to swap the keybindings as it begins, but don't seem to be achieving anything.
Firstly, I tried using xmodmap and set the following config file which I found here:
~/set-esc-caps:
keycode 66 = Caps_Lock
keycode 9 = Escape
remove Lock = Caps_Lock
add Lock = Escape
keycode 9 = Caps_Lock
keycode 66 = Escapeand created a new xinitrc (I wasn't sure whether I needed to prefix #!/bin/bash so I tried both)
~/.xinitrc:
xmodmap ~/swap-esc-capsI also tried adding the contents of swap-esc-caps to /etc/X11/xinit/.Xmodmap but no change.
Next I tried adding the following XkbOptions line to my xorg.conf file
/etc/X11/xorg.conf
...snip...
Section "InputDevice"
# generated from default
Identifier "Keyboard0"
Driver "kbd"
Option "XkbOptions" "caps:swapescape"
EndSection
...snip...I tried both of these (separately) using tty2 and running the command manually at the prompt, no rebooting or logging out between runs as I believe xinit should make a fresh call the previous 2 files when executed, regardless that my 1st X server is still running.
As neither of these worked, I tried running these 3 commands manually, checking the new X between each but the problem still exists, Caps Lock lights up the keyboard and makes me type capitals rather than what I'd prefer it did.
DISPLAY=:1.0 && xinit /usr/bin/minecraft -- :1 &
setxkbmap -display :1.0 -option caps:swapescape
xmodmap ~/swap-esc-caps -display :1.0I feel I'm missing something stupid, does anyone please have any ideas where I need to be focussing my investigation?
Oh, finally - when I run xinit the new X opens over the first non-logged in tty - so tty2 in normal usage, or tty3 if that's logged in...etc. Does anyone know why that might be too?
Thanks in advance, and please ask if I've forgotten to include something.
Offline
Oh, finally - when I run xinit the new X opens over the first non-logged in tty - so tty2 in normal usage, or tty3 if that's logged in...etc. Does anyone know why that might be too?
That's exactly what it is supposed to do. If you want it to start on a specific tty you can specify that in the options to Xorg like the following to run on tty7:
xinit -- vt7As for the rest, it's not really clear how you're starting the game in the second session. You're passing it as a parameter to xinit, but you haven't shown where in your xinitrc this parameter is used. If I were doing this I'd set up xinitrc something like the following:
case $1 in
games)
xmodmap ~/swap-esc-caps &
$2
;;
*)
#commands to start KDE, or your "normal" setup
;;
esacThen to launch your mincraft session, from a tty just enter:
xinit games minecraft -- :1 vt7Also this way, this could be reused for any game that would be run in a similar manner by changing the command to "xinit games <othergame> -- :1 vt7"
Note: you should not have to manually set the DISPLAY variable - in fact I'd advise against it.
Last edited by Trilby (2013-01-04 22:34:21)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
That's exactly what it is supposed to do. If you want it to start on a specific tty you can specify that in the options to Xorg like the following to run on tty7:
xinit -- vt7
Ah, that makes sense. I guess I'm so used to logging into KDM on tty1 and having the X spawn on Ctrl-Alt-F7 (is that vt7?), that I'm expecting an xinit run on tty2 to naturally spawn at Ctrl-Alt-F8 (vt8?) rather than over tty3.
As for the rest, it's not really clear how you're starting the game in the second session. You're passing it as a parameter to xinit, but you haven't shown where in your xinitrc this parameter is used.
I'm not quite sure what you're asking here - I've given all the files I've modified or attempted to modify so far. As soon as I run x-minecraft.sh in a terminal inside the KDE session, using a shortcut in the launcher or on tty2 the screen is instantly redirected to the new X server and displays the Minecraft login. I've not had to modify xinitrc previously, even for starting KDE as I use the systemd method from the Wiki - systemctl enable kdm.service. Before today I did not have an ~/.xinitrc file (which is why I'm not sure if it needs the shebang at the start - I saw that in the /etc/skel/.initrc when I was looking through the wiki page) so what I'm saying boils down to I'm not sure where the parameter is being used; I've not defined it manually anywhere and yet it seems to be working as intended if I wasn't being particular with my keybindings too.
If I were doing this I'd set up xinitrc something like the following:
case $1 in games) xmodmap ~/swap-esc-caps & $2 ;; *) #commands to start KDE, or your "normal" setup ;; esac
Would it be possible to do this with no commands in the default case and not mess up anything relating to systemd starting kdm.service? I'll give this a trial tomorrow - I think I'm risking creating more hassle for myself if I continue messing with X whilst tired!
Offline
Ah, that's how it worked for you: the system-wide default xinitrc executes the parameters passed, so that's how minecraft is launched.
To answer your last question, I've never used KDM, but if what you have done so far didn't interfere with anything, neither should my xinitrc example. To play it extra safe you could do the following instead:
case $1 in
games)
xmodmap ~/swap-esc-caps &
shift
$@
;;
*)
exec sh /etc/X11/xinit/xinitrc $@
;;
esacI made two changes here. If anyting other than "games" is passed as the first parameter, this just passes everything on to the default xinitrc - this way it could not interfer with anything KDM would normally do. The other change is to allow parameters to be passed to the game, so you could do things like the following:
xinit games minecraft -parameter-to-open /my/saved/game -- :1 vt8
xinit games minecraft -- :2 vt9
xinit games other-game -with-parameter -- :1 vt8I don't know if minecraft or other such games would use command line parameters, but this xinitrc makes it possible to pass them if they do.
Last edited by Trilby (2013-01-05 00:22:13)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Just something I think I should add there Trilby. I think that for the game to be launched, you need to pass the full path to the xinit command.
Edit: I guess that is unless the "games)" the '$@' should be '$2'
Last edited by WonderWoofy (2013-01-05 00:29:57)
Offline
Why? I don't have full paths to anything in my xinitrc.
EDIT: If they are not somewhere in $PATH then of course you would need to include the full path. But if they are executable from the command line, then they are from xinitrc.
Last edited by Trilby (2013-01-05 00:30:06)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Should that $@ be $2 then?
Offline
Nope, the $@ ensures that any additional parameters are passed to the game. This was, for example, if minecraft accepted command line parameters they could be passed as in my examples.
If there are no additional parameters passed to the game, there would be no $2 after the "shift".
Example:
$ xinit games minecraft --parameter-to-minecraft -- :1 vt8
The "-- :1 vt8" is removed and sent to the X server, this leaves "xinit games minecraft --parameter-to-minecraft".
Xinit sources xinitrc which received the immediately-above-quoted command line. The case $1 matches "games", Xmodmap is launched and backgrounded, then the "shift" shifts the command line parameters from $@="games minecraft --parameter-to-minecraft" to $@="minecraft --parameter-to-minecraft". The next line expands that variable and minecraft is called with it's parameter.
Last edited by Trilby (2013-01-05 00:36:28)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Ah, sorry I didn't see that shift. I think I need to learn to read better... or at least more carefully. I totally missed that and then assumed that you simply didn't let up on the shift key fast enough.
Ok... move along... nothing to see here.
Edit: ... and learn to type better.
Last edited by WonderWoofy (2013-01-05 00:39:48)
Offline
Hurrah progress! Here's my current updated script and xinitrc:
x-minecraft.sh
#!/bin/bash
xinit games /usr/bin/minecraft -- :1 vt8~/.xinitrc
#!/bin/bash
case $1 in
games)
xmodmap ~/swap-esc-caps &
shift
$@
;;
*)
exec sh /etc/X11/xinit/xinitrc $@
;;
esacThe Esc key now works as I was hoping for it to, enabling and disabling the Caps Lock light on my keyboard and toggling the case of typed text too. However, the Caps Lock key performs the exact same actions, which suggests that my xmodmap is wrong.
I checked xmodmap -pk for the codes inside my KDE session, but I can't be positive these are the correct way around right now - I may have accidentally run an xmodmap inside my KDE session at some point, and I'm not sure what effect the KDE setting switch has on the output either. I'll have to test when I wake up:
[0:55] doug at platinum in ~
☺ % xmodmap -pk | grep Caps
9 0xffe5 (Caps_Lock) 0x0000 (NoSymbol) 0xffe5 (Caps_Lock)
[0:55] doug at platinum in ~
☺ % xmodmap -pk | grep Esc
66 0xff1b (Escape) 0x0000 (NoSymbol) 0xff1b (Escape)Additionally, this is the output from xev for the two button presses:
KeyRelease event, serial 40, synthetic NO, window 0x5600001,
root 0x295, subw 0x0, time 15020727, (450,470), root:(452,525),
state 0x10, keycode 66 (keysym 0xff1b, Escape), same_screen YES,
XLookupString gives 1 bytes: (1b) "
XFilterEvent returns: False
KeyPress event, serial 40, synthetic NO, window 0x5600001,
root 0x295, subw 0x0, time 15022055, (450,469), root:(452,524),
state 0x10, keycode 9 (keysym 0xffe5, Caps_Lock), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: FalseI've tried swap-esc-caps with the following two contents, both produced the same action. Removing games from the xinit line reverts back to the previous behaviour so I'm pretty confident it's the xmodmap line in the switch statement. Can you see any glaring errors?
keycode 66 = Caps_Lock
keycode 9 = Escape
remove Lock = Caps_Lock
add Lock = Escape
keycode 9 = Caps_Lock
keycode 66 = Escaperemove Lock = Caps_Lock
keysym Escape = Caps_Lock
keysym Caps_Lock = Escape
add Lock = Caps_LockI don't know if minecraft or other such games would use command line parameters, but this xinitrc makes it possible to pass them if they do.
Minecraft uses a shell script in /usr/bin/ to run that contains the required JVM command line parameters. I'm unsure of any extra ones that would need to be passed manually, but as you previously mentioned - the new xinitrc method is expandable to future games too, and I'm going to need to run a custom xorg.conf once I have my second monitor configured too so it's definitely the best choice.
/usr/bin/minecraft
#!/bin/sh
# fix for users of special IM modules
unset XMODIFIERS GTK_IM_MODULE QT_IM_MODULE
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$JAVA_HOME/lib/amd64/:$JAVA_HOME/lib/i386/:$JAVA_HOME/jre/lib/amd64/:$JAVA_HOME/jre/lib/i386/" exec java -Xmx6144M -Xms2048M -cp /usr/share/minecraft/minecraft.jar net.minecraft.LauncherFrame $@Last edited by el3ctrik (2013-01-05 01:08:29)
Offline
I don't know why removeing the lock doens't seem to work for you, but when I needed similar functionality, I used to use "clear Lock" or possibly "clear lock" (not sure if case sensitive, or if it is capitalized or not.
Offline