You are not logged in.

#1 2026-07-09 01:19:51

mr_kaddy
Member
Registered: 2025-10-24
Posts: 21

[SOLVED]Changing mouse handedness automatically based on the USB slot

Changing mouse handedness automatically based on the USB slot used

I have a USB Optical mouse and a laptop which has a USB slot on both the left and the right side. Generally, I plug it on the right side and keep the mouse setting Right-Handed but when I plug it on the left side, I prefer changing the setting to left-handed. Since I am using XFCE as my DE, the way to do this is Applications->Settings->Mouse and Touchpad->Buttons and Feedback (change to Left-Handed or Right-Handed).
How do I make this automatic? I assume this can be done if there's a hook which detects a certain device being plugged in and depending on the USB slot it is plugged in to, it changes the setting by toggling an XFCE setting. However, I do not know how to either write such a hook or how to label the exact USB device being used.

Last edited by mr_kaddy (2026-07-11 14:20:56)

Offline

#2 2026-07-09 01:51:57

cryptearth
Member
Registered: 2024-02-03
Posts: 2,272

Re: [SOLVED]Changing mouse handedness automatically based on the USB slot

?! i honestly don't get it: why should it matter how you connect a peripheral?
yes, i general prefer an external mouse over a touchpad, too - but no matter if wired or wireless or which port used i place the mouse at the same side and use it with the same hand
this sounds like an xy-problem

Offline

#3 2026-07-09 02:43:08

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 720

Re: [SOLVED]Changing mouse handedness automatically based on the USB slot

mr_kaddy wrote:

I assume this can be done if there's a hook which detects a certain device being plugged in and depending on the USB slot it is plugged in to

This is correct assumption. You can create udev rule for USB device and perform different actions or set custom properties depending on physical USB port a device is connected to.
USB port can be identified by ID_PATH property.

mr_kaddy wrote:

it changes the setting by toggling an XFCE setting.

I think this should be done on xinput level, i.e. remap mouse buttons with "xinput set-button-map ...".
Proper method to implement this depends on expected behavior, e.g. whether you want to change handedness in realtime.
Should handeness be changed immediately if you unplug the mouse from one port and plug it into another withing the same XFCE session?
The main problem will be to trigger actions in user's graphical session from udev's system level.
Specifically for XFCE, settings can be changed by running xfconf-query. However, it changes permanent settings as well.

Offline

#4 2026-07-09 03:33:18

mr_kaddy
Member
Registered: 2025-10-24
Posts: 21

Re: [SOLVED]Changing mouse handedness automatically based on the USB slot

cryptearth wrote:

?! i honestly don't get it: why should it matter how you connect a peripheral?
yes, i general prefer an external mouse over a touchpad, too - but no matter if wired or wireless or which port used i place the mouse at the same side and use it with the same hand
this sounds like an xy-problem

It's because I generally use my mouse with my right hand for most activities but there are times when I am writing or sketching and I need the right side of my table and right hand free, so I become a left-handed mouse user then.

Offline

#5 2026-07-09 03:39:32

mr_kaddy
Member
Registered: 2025-10-24
Posts: 21

Re: [SOLVED]Changing mouse handedness automatically based on the USB slot

dimich wrote:
mr_kaddy wrote:

I assume this can be done if there's a hook which detects a certain device being plugged in and depending on the USB slot it is plugged in to

This is correct assumption. You can create udev rule for USB device and perform different actions or set custom properties depending on physical USB port a device is connected to.
USB port can be identified by ID_PATH property.

mr_kaddy wrote:

it changes the setting by toggling an XFCE setting.

I think this should be done on xinput level, i.e. remap mouse buttons with "xinput set-button-map ...".
Proper method to implement this depends on expected behavior, e.g. whether you want to change handedness in realtime.
Should handeness be changed immediately if you unplug the mouse from one port and plug it into another withing the same XFCE session?
The main problem will be to trigger actions in user's graphical session from udev's system level.
Specifically for XFCE, settings can be changed by running xfconf-query. However, it changes permanent settings as well.

Thanks for validating my hypothesis. I assume this dense Wiki page is what you mean, right? I will spend some time reading through this.
Yes, I want this to happen in real time. The Ideal behaviour would be: I'm using the mouse normally with my right hand, then I unplug it and plug it into the left USB slot and this automatically triggers the hook in the background without any other action from my side and I am able to use the left-handed mouse. I prefer to change the settings without remapping the mouse buttons, at an XFCE session level, because they are quite easy to understand and modify.

Offline

#6 2026-07-09 04:51:59

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 720

Re: [SOLVED]Changing mouse handedness automatically based on the USB slot

mr_kaddy wrote:

I assume this dense Wiki page is what you mean, right?

Right. First step will be to determine ID_PATH for specific USB port ("left port" in your case).
There are actually several ways to determine it, this is one of them.

Plug the mouse into left port. Run

$ sudo libinput list-devices | less

and find your mouse in 'Device:' line. Note a mouse usually provides multiple subdevices, so you have to find something containing "Mouse" in the name.
E.g. in my case it is

Device:                  HS6209 A4tech 2.4G Wireless Device Mouse
Kernel:                  /dev/input/event19
Id:                      usb:09da:0025
...

Then look at device node path in next "Kernel: " line. In this example it's "/dev/input/event19".
Find ID_PATH in udev properties of the device:

$ udevadm info /dev/input/event19 | grep '^E: ID_PATH='
E: ID_PATH=pci-0000:00:14.0-usb-0:3:1.1

Of course, you'll get some other value. This value should be used in udev rule to identify "left" port:

ACTION=="add|change", SUBSYSTEM=="input", KERNEL=="event[0-9]*" \
    ENV{ID_INPUT_MOUSE}=="1", \
        ENV{ID_PATH}=="pci-0000:00:14.0-usb-0:3:1.1", ...

And now the problem comes down to figure out what to do if matched (RUN+=, SYSTEMD_USER_WANTS+= or something else).

mr_kaddy wrote:

I prefer to change the settings without remapping the mouse buttons, at an XFCE session level, because they are quite easy to understand and modify.

I'm not a XFCE user but as I can see, it keeps left/right handed settings for each mouse separately. If we could somehow rename the mouse so that XFCE would recognize it as different devices depending on the port, that would solve the problem.

Offline

#7 2026-07-09 07:07:14

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,009

Re: [SOLVED]Changing mouse handedness automatically based on the USB slot

Alternatively use a symlink and https://man.archlinux.org/man/xorg.conf … DevicePath in an xorg configlet to https://man.archlinux.org/man/libinput.4#Option~17 declare the mouse from the Leftorium

Online

#8 2026-07-09 18:44:17

cryptearth
Member
Registered: 2024-02-03
Posts: 2,272

Re: [SOLVED]Changing mouse handedness automatically based on the USB slot

mr_kaddy wrote:

but there are times when I am writing or sketching and I need the right side of my table and right hand free, so I become a left-handed mouse user then.

to me this is your XY-problem: you "waste" space on the left of your laptop instead of moving it further to the left so you gain more space on the right ... or get a bigger desk, i guess

don't get me wrong: sure, mankind got all kind of weird solutions to simple problmes - your situation is just one of those - but "i move my mouse over to the left be cause i run out of space on the right" already screams the solution within itself: instead of use obvious free space to the left move over the laptop and thereby shifting that free space from the left of the device "over to its right"
a human is an animal with deep habbits - if your used to use an external mouse to the right and now try to figure out any other solution - you're doing it wrong - the proper solution is to get more space on the right - preferable in a way that doesn't involve either shifting of the laptop or the mouse

but that's just my opinion

Offline

#9 2026-07-09 20:17:52

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,009

Re: [SOLVED]Changing mouse handedness automatically based on the USB slot

"i move my mouse over to the left be cause i run out of space on the right"

I need the right side of my table and right hand free

Online

#10 2026-07-09 21:00:28

cryptearth
Member
Registered: 2024-02-03
Posts: 2,272

Re: [SOLVED]Changing mouse handedness automatically based on the USB slot

seth wrote:

"i move my mouse over to the left be cause i run out of space on the right"

I need the right side of my table and right hand free

mr_kaddy wrote:

times when I am writing or sketching and I need the right side of my table and right hand free

~ try to not get too off-topic: although a few people are capable of it - most of us usually don't use both hands for two completely different tasks AT ONCE - hence TO ME this "need my hand free" requirement is the XY-problem of "just switch between then"

Offline

#11 2026-07-09 23:56:27

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 720

Re: [SOLVED]Changing mouse handedness automatically based on the USB slot

seth wrote:

Alternatively use a symlink and https://man.archlinux.org/man/xorg.conf … DevicePath in an xorg configlet to https://man.archlinux.org/man/libinput.4#Option~17 declare the mouse from the Leftorium

Good idea. Here is how I got it working:

/etc/udev/rules.d/99-mouse-left.rules:

ACTION=="add|change", SUBSYSTEM=="input", KERNEL=="event[0-9]*" \
    ENV{ID_INPUT_MOUSE}=="1", \
        ENV{ID_PATH}=="pci-0000:00:14.0-usb-0:3:1.1", \
            ENV{ID_INPUT.tags}+="LeftHanded"

(replace value ID_PATH compared to with value specific for your system).

/etc/X11/xorg.conf.d/01-pointer.conf:

...
Section "InputClass"
        Identifier "system-pointer lefthanded"
        MatchIsPointer "on"
        MatchTag "LeftHanded"
        Option "LeftHanded" "true"
EndSection

However, when XFCE already has mouse configured, it applies own settings and overrides Xorg settings. Thus XFCE-specific pointer configuration should be removed: "xfconf-query -c pointers -p / -rR" or via Settings Editor GUI.
Thus tuning acceleration or other parameters for particular mouse device should be done via Xorg config, not via XFCE settings.

Last edited by dimich (2026-07-10 00:17:30)

Offline

#12 2026-07-10 14:09:08

mr_kaddy
Member
Registered: 2025-10-24
Posts: 21

Re: [SOLVED]Changing mouse handedness automatically based on the USB slot

seth wrote:

Alternatively use a symlink and https://man.archlinux.org/man/xorg.conf … DevicePath in an xorg configlet to https://man.archlinux.org/man/libinput.4#Option~17 declare the mouse from the Leftorium

I am afraid I don't really understand what you mean here. I understand that the second link gives a certain option which I need to set in a configuration file somewhere and the first option describes said configuration files. But how would that work when I need different configurations as in my case. Could you please help me learn how the udev thing can be made to trigger a certain configuration reload?

Offline

#13 2026-07-10 14:16:20

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,009

Re: [SOLVED]Changing mouse handedness automatically based on the USB slot

Did you try dimich's suggestion (should work equally good and doesn't require a device symlink)
You're not gonna be able to change the device name so if that's all xfce cares about that venue is a dead end, but X11 will auto-add devices and apply configurations to those - re-plugging the mouse to a specific port will trigger the udev rule that will set a tag what will make Xorg apply the configlet that sets the mouse left-handed.

Online

#14 2026-07-10 14:20:02

mr_kaddy
Member
Registered: 2025-10-24
Posts: 21

Re: [SOLVED]Changing mouse handedness automatically based on the USB slot

seth wrote:

Did you try dimich's suggestion (should work equally good and doesn't require a device symlink)
You're not gonna be able to change the device name so if that's all xfce cares about that venue is a dead end, but X11 will auto-add devices and apply configurations to those - re-plugging the mouse to a specific port will trigger the udev rule that will set a tag what will make Xorg apply the configlet that sets the mouse left-handed.

Nope, I thought yours would be simpler, so decided to go for it first. Looking over dimich's suggestion now.

Offline

#15 2026-07-11 14:18:22

mr_kaddy
Member
Registered: 2025-10-24
Posts: 21

Re: [SOLVED]Changing mouse handedness automatically based on the USB slot

I'll dump the exact steps I took to resolve this here and close this thread, in line with @dimich's suggestions.
Start by identifying the id for your mouse by running

$ xinput list
⎡ Virtual core pointer                    	id=2	[master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer              	id=4	[slave  pointer  (2)]
⎜   ↳  USB OPTICAL MOUSE                      	id=6	[slave  pointer  (2)]    <--- this is the one I want
⎜   ↳ <some other mouse> Mouse             	id=7	[slave  pointer  (2)]
⎜   ↳ <laptop touchpad> Touchpad          	id=8	[slave  pointer  (2)]
⎜   ↳ ImPS/2 Logitech Wheel Mouse             	id=16	[slave  pointer  (2)]  (I don't know what's this?!)
⎣ Virtual core keyboard                   	id=3	[master keyboard (2)]
    ↳ Virtual core XTEST keyboard             	id=5	[slave  keyboard (3)]
    ↳ Video Bus                               	id=9	[slave  keyboard (3)]
    ↳ Intel HID events                        	id=10	[slave  keyboard (3)]
    ↳ Power Button                            	id=11	[slave  keyboard (3)]
    ↳ Power Button                            	id=12	[slave  keyboard (3)]
    ↳ Sleep Button                            	id=13	[slave  keyboard (3)]
    ↳ <hotkeys?>                       	id=14	[slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard            	id=15	[slave  keyboard (3)]

Since the id of the mouse I wanted is 6, I list the properties of this particular input device

$ xinput list-props 6
Device ' USB OPTICAL MOUSE':
	Device Enabled (178):	1
	Coordinate Transformation Matrix (180):	1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
	libinput Natural Scrolling Enabled (303):	0
	libinput Natural Scrolling Enabled Default (304):	0
	libinput Scroll Methods Available (305):	0, 0, 1
	libinput Scroll Method Enabled (306):	0, 0, 0
	libinput Scroll Method Enabled Default (307):	0, 0, 0
	libinput Button Scrolling Button (308):	2
	libinput Button Scrolling Button Default (309):	2
	libinput Button Scrolling Button Lock Enabled (310):	0
	libinput Button Scrolling Button Lock Enabled Default (311):	0
	libinput Middle Emulation Enabled (312):	0
	libinput Middle Emulation Enabled Default (313):	0
	libinput Rotation Angle (314):	0.000000
	libinput Rotation Angle Default (315):	0.000000
	libinput Accel Speed (316):	0.000000
	libinput Accel Speed Default (317):	0.000000
	libinput Accel Profiles Available (318):	1, 1, 1
	libinput Accel Profile Enabled (319):	1, 0, 0
	libinput Accel Profile Enabled Default (320):	1, 0, 0
	libinput Accel Custom Fallback Points (321):	<no items>
	libinput Accel Custom Fallback Step (322):	0.000000
	libinput Accel Custom Motion Points (323):	<no items>
	libinput Accel Custom Motion Step (324):	0.000000
	libinput Accel Custom Scroll Points (325):	<no items>
	libinput Accel Custom Scroll Step (326):	0.000000
	libinput Left Handed Enabled (327):	0    <-- This is what needs to be toggled when I switch my USB ports
	libinput Left Handed Enabled Default (328):	0
	libinput Send Events Modes Available (329):	1, 0
	libinput Send Events Mode Enabled (330):	0, 0
	libinput Send Events Mode Enabled Default (331):	0, 0
	Device Node (332):	"/dev/input/event5"    <--- Make a note of this
	Device Product ID (333):	0, 14373
	libinput Drag Lock Buttons (334):	<no items>
	libinput Horizontal Scroll Enabled (335):	1
	libinput Scrolling Pixel Distance (336):	15
	libinput Scrolling Pixel Distance Default (337):	15
	libinput High Resolution Wheel Scroll Enabled (338):	1

Now we use the udev management tool, which is udevadm to identify the USB ports uniquely. Plug the mouse in different USB ports and run the following command to uniquely identify the ports (replace the /dev/input/event5 with whatever shows up above after replugging and running the above command as well)

$ udevadm info /dev/input/event5 | grep ID_PATH 

The grep might match multiple lines but you need the one with just ID_PATH (as opposed to ID_PATH_TAG or something else). In my case, this is pci-0000:00:14.0-usbv2-0:3:1.0 or pci-0000:00:14.0-usbv2-0:1:1.0 depending on the USB port I am plugging my mouse into.

Now you need to update two files. The first file, when it is the communication between the HW port and the tags which are read by Xorg and the second is Xorg using those tags to toggle properties. Use

find

to search for the udev/rules.d directory in /etc/ or /usr/ and to a file named 90-mouse-handedness.rules inside this directory, append the following lines depending on the USB slot you get

ENV{ID_INPUT_MOUSE}=="1", ENV{ID_PATH}=="pci-0000:00:14.0-usb-0:1:1.0", ENV{ID_INPUT.tags}="mouse_left"
ENV{ID_INPUT_MOUSE}=="1", ENV{ID_PATH}=="pci-0000:00:14.0-usb-0:3:1.0", ENV{ID_INPUT.tags}="mouse_right"

Now use

find

again to search for xorg.conf file or xorg.conf.d directory (create a new conf file inside this directory) and append to it

Section "InputClass"
    Identifier "mouse left = left handed"
    MatchIsPointer "on"
    MatchTag       "mouse_left"
    Option         "LeftHanded" "on"
EndSection

Section "InputClass"
    Identifier "mouse right = right handed"
    MatchIsPointer "on"
    MatchTag       "mouse_right"
    Option         "LeftHanded" "off"
EndSection

Once both are run, log out, log back in and run

sudo udevadm control --reload

. Verify with the commands above to check if the libinput Left Handed setting has been toggled to 1 if you plug it in the left USB slot now.

This didn't fix the issue for me permanently, because once I did it again, the settings were back to normal. The reason was that XFCE high-level settings seemed to be overriding X.org's low-level internal settings. To reverse this, either delete the entry for the mouse in the XFCE Pointers settings file

~/.config/xfce4/xfconf/xfce-perchannel-xml/pointers.xml

or reset settings for it using

xfconf-query -c pointers -p /_USB_OPTICAL_MOUSE -r -R

(replace USB_OPTICAL_MOUSE with what XFCE shows you in the previous file for the mouse).

Offline

#16 2026-07-11 14:19:19

mr_kaddy
Member
Registered: 2025-10-24
Posts: 21

Re: [SOLVED]Changing mouse handedness automatically based on the USB slot

Suggestions and improvements to the process I followed are welcome, in case anyone has a better idea which doesn't rely on overriding XFCE settings!

Offline

#17 2026-07-12 05:06:16

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 720

Re: [SOLVED]Changing mouse handedness automatically based on the USB slot

mr_kaddy wrote:

Suggestions and improvements to the process I followed are welcome

Nitpick: right-handed port distinction seems redundant here. LeftHanded property is "off" by default, so no need to set it explicitly.
Of course, if you want to set some other properties specifically for right-handed mouse, second set of rules makes sense.

in case anyone has a better idea which doesn't rely on overriding XFCE settings!

There are some drawbacks in existing stack implementations that don't allow to implement OP feature properly.

  • XFCE has binary value for handness. If XFCE implemented tristate: "right-handed", "left-handed" or "don't change / inherit from lower layer", it would overcome the issue.

  • XFCE identifies devices by name provided by libinput. Libinput in turn takes it from kernel input subsystem. Libinput has poor capabilities for quirks matching rules. It seems impossible to implement the feature properly without hacking libinput or kernel.

Offline

Board footer

Powered by FluxBB