Xorg.conf

From LinuxReviews
Jump to: navigation, search

I finally figured out how to do this, by modifying xorg.conf

Install the following two packages, to make sure you have the correct driver. The "joystick" utility is a command line tool that is used to display information on which buttons are being used

EASY

Code:

sudo aptitude install joystick xserver-xorg-input-joystick

Then, we edit /etc/X11/xorg.conf. First, add this section: Code:

Section "InputDevice"
	Identifier	"Joystick"
	Driver	"joystick"
	Option "Device" "/dev/input/js0"
	Option "SendCoreEvents" "true"
EndSection

then add the following line in the ServerLayout section Code:

Section "ServerLayout"
#other stuff....
	Inputdevice	"Joystick"
#...
EndSection

This will pick some default values, and moving your joystick will move the mouse ^.^ If you hit some buttons, they might translate into mouse buttons. (mine does on the default settings) However, they might not translate into a very usable button layout.

MORE ADVANCED In order to tweak the buttons to how we want them, we need the joystick utility (strictly speaking, this can also be done using systemsettings, or the gnome configuration utility)

from a console, run Code:

 jstest /dev/input/js0

Make it as wide as possible, or else it's a bit more difficult to read. It simply prints out the current buttons being pressed. Play around with it a bit.

if you view the joystick manpage, it has a lot of very helpful tips, and a lot of useful commands. Here's the more useful stuff Code:

Option "SendCoreEvents" "true"
Option "MapAxis1"     "mode=relative axis=+1.5X deadzone=30"
Option "MapButton7" "button=1" #left click
Option "MapButton7" "key=23" #tab

Quick rundown: "SendCoreEvents" tells the driver to send the events (buttons and whatnot) to the X server as a pointer/keyboard device. This is what actually allows the joystick to be a "mouse".

"MapAxis<number>" specifies which stick you want to work with. Each physical stick will have two: one for X, and one for Y. "mode" specifies how the cursor will react when you use the stick. Relative means it will move from it's last position, at a speed proportional to how far you're tilting the stick. Accellerated works the same, but speeds up the longer you hold it.

the axis differs for each mode. I'll explain for relative: it essentially specifies the top speed of the cursor (not tilting as far makes it go slower). Specifying a negative inverts the direction (eg: tilt left, send cursor right), The axis also expects you to specify which direction.X and Y are easy to figure out: X is horizontal, Y is vertical. The manpage does not explain the other two options: ZX and ZY. These are scrolling. This will come in very handy if you're planning on doing web surfing with a joystick mouse. Lastly, the deadzone specifies a zone to ignore input from. Sort of a tolerance. A new or high precision joystick will function well with a low deadzone. A older, sloppy joystick might need a higher one. (the default is 1000). If you plan on using the push-joystick button (like PS2 controllers) don't set this too low, or you'll move the cursor while trying to click it.

"MapButton<number>" specifies what X will simulate when you hit a button on the joystick. Here's the useful ones for simulating a mouse: Button=

  • 1: simulate mouse left click
  • 2: simulate right click
  • 3: middle click/wheel click
  • 4: mouse wheel up
  • 5: mouse wheel down (these two might be backwards)

To simulate a keyboard key, or other special ones, run the command "modmap -pk". To get a specific one, try "modmap -pk |grep -i "<key-name-here>", and insert your own term of "space", "backspace", "up," etc. The, use Code:

 Option "MapButton7" "key=<integer>"

where the integer is the one relating to the key you wish to press. (it's the leftmost column on the command output)

Hopefully this helps everyone out. If I missed anything you think would be useful, let me know, and I'll see what I can do about filling it in. Be sure to visit the man page. It's very helpful, and pretty friendly for a manpage.

Now, here's my Xorg section, specific for a Saitek 880 Dual Analog controller. It's set up quite like a PS2 controller, but with a couple other buttons. Code:

Section "InputDevice"
	Identifier	"saitek"
	Driver		"joystick"
	# I want this layout to be specific to the one controller
	# I have others that use different layouts, that I want to have different setups
	# So, for device, just make sure that we specify the joystick we want

	Option "Device" "/dev/input/by-id/usb-SAITEK_P880-joystick"
	#Option "Device" "/dev/input/js0"

	# This allows the joystick to masquerade as a mouse
	Option "SendCoreEvents" "true"
	
	#Left Stick
	#This one is my main pointer controller. I have it go slightly faster than default (1), 
	#because i don't mind not going full boar on the stick.
	Option "MapAxis1"     "mode=relative axis=+1.5X deadzone=30"
	Option "MapAxis2"     "mode=relative axis=+1.5Y deadzone=30"

	#Right Stick 
	# This is for quick, short mouse movements. Not overly useful, because 
#the smaller the radius, the less useful as a pointer it becomes. However, the bigger the radius, the less precise. 
#Absolute isn't entirely useful to control the pointer, save for edge cases.
# However, if one were to set this to ZY and ZX axes, the absolute is good for scrolling.
	Option "MapAxis3"     "mode=absolute axis=400Y deadzone=30"
	Option "MapAxis4"     "mode=absolute axis=400X deadzone=30"
	
	## Directional Pad
	# The d-pad on this controller is set to be an "joystick", 
	# because it has a swap-axes button that allows the main (1 & 2)
	# axes to swap with the d-pad (5 &6), so that you can play with whatever is more comfortable to you.
	# It also has the downside of making it hard to set up as the keys Up, Down, Left, and Right 
	# This one is set to scroll. Since it's a D-pad, we only have on/off, so accellerated allows us to scroll faster and faster the longer we hold the button.
	Option "MapAxis5"     "mode=accelerated axis=+1ZX deadzone=30"
	Option "MapAxis6"     "mode=accelerated axis=+1ZY deadzone=30"

	## Buttons!
	##Buttons 1-6 
	# I haven't set these up yet, but they're waiting for me to do something with them
	Option "MapButton1" "none"
	Option "MapButton2" "none"
	Option "MapButton3" "none"
	Option "MapButton4" "none"
	Option "MapButton5" "none"
	Option "MapButton6" "none"
	
	##	Button 7, Left Shoulder. Feels comfortable, this.
	Option "MapButton7" "button=1" #left click

	##	Button 8, Right Shoulder
	Option "MapButton8" "button=3" #middle click

	##	9,10 Left and Right Joystick button
	# These are the buttons that are activeted when you push down
	# on the sticks. I find them very aggravating to use.
	Option "MapButton9" "none"
	Option "MapButton10" "none"

	#Button 11, red S
	# With the saitek drivers on windows, this is supposed to be a "shift"
	# key. However, linux just reads it as a button. I find it more useful this way
	Option "MapButton11" "button=2" #right click
	
	## Button 12, Digital
	#This button has a hardware effect: swapping axes 1&2 with 5&6
	# As such, it's not useful to capture unless we want that behaviour on our button. 
	#Other joysticks might have similar gotchyas, so keep an eye out for keys like this
	#It might, however, to be useful to disable things, which you can do as such:
	#Option "MapButton12" "disable-all"
	#Option "MapButton12" "disable-mouse" #disables pointer control
	#Option "MapButton12" "disable-keys" #Disables keystroke simulations.
EndSection

Personal tools
hardware tests
Categories
Privacy policy
linux events
ipv6
Networking
IPv6

Search:

linux newz | random page | poetry | free blog