3

I'm currently having an issue trying to map the side buttons on my Razer Naga, I'm running Elementary OS but from what I understand that's a Ubuntu and I should add that this is all very new to me too!

There are 12 buttons on the side of the Naga, which are currently mapped 1-12. There is an option to change these to the Numpad mappings (configurable by a physical switch on the mouse itself) which would solve my problem but inadvertently causes my right clicks to fail 60% of the time.

I should also mention that I am experiencing the same situation across two entirely different machines but with the same physical mouse.

My ultimate goal is to bind at least 3 of the buttons (1-3) to something else, let's say F1, F2 and F3 for argument's sake.

So far, I've done a lot of Googling, but one key difference I notice when other people have solved this is the difference in my xinput output:

⎡ Virtual core pointer                    id=2     [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer          id=4     [slave  pointer  (2)]
⎜   ↳ SynPS/2 Synaptics TouchPad          id=12    [slave  pointer  (2)]
⎜   ↳ Razer Razer Naga                    id=14    [slave  pointer  (2)]
⎜   ↳ Razer Razer Naga                    id=13    [slave  pointer  (2)]
⎣ Virtual core keyboard                   id=3     [master keyboard (2)]
   ↳ Virtual core XTEST keyboard          id=5     [slave  keyboard (3)]
   ↳ Power Button                         id=6     [slave  keyboard (3)]
   ↳ Video Bus                            id=7     [slave  keyboard (3)]
   ↳ Power Button                         id=8     [slave  keyboard (3)]
   ↳ Lenovo EasyCamera                    id=9     [slave  keyboard (3)]
   ↳ Ideapad extra buttons                id=10    [slave  keyboard (3)]
   ↳ AT Translated Set 2 keyboard         id=11    [slave  keyboard (3)]

In other people's output, I noticed that there is one "Razer Naga" present in the pointer section and one in the keyboard section. As you can see in mine there are two listed, only in the pointer section.

Other resolutions have suggested running a script to replace the keymappings for the keyboard entry, which won't work for me, I think.

I tried using xev to show the output of what happens when I press one of these buttons but it didn't really help me. Here's an example of me clicking the left mouse button:

ButtonRelease event, serial 37, synthetic NO, window 0x3a00001,
  root 0x9d, subw 0x3a00002, time 16486037, (24,50), root:(618,357),
  state 0x100, button 1, same_screen YES

Now the mysterious "1" button on the side:

KeyPress event, serial 37, synthetic NO, window 0x3a00001,
  root 0x9d, subw 0x3a00002, time 16536943, (31,58), root:(625,365),
  state 0x0, keycode 10 (keysym 0x31, 1), same_screen YES,
  XLookupString gives 1 bytes: (31) "1"
  XmbLookupString gives 1 bytes: (31) "1"
  XFilterEvent returns: False

KeyRelease event, serial 37, synthetic NO, window 0x3a00001, root 0x9d, subw 0x3a00002, time 16537199, (31,58), root:(625,365), state 0x0, keycode 10 (keysym 0x31, 1), same_screen YES, XLookupString gives 1 bytes: (31) "1" XFilterEvent returns: False

At this point I don't really know where to proceed (I don't even know which of the two devices listed in xinput is the one mapped to the buttons), so any advice or pointers would be greatly appreciated!

1 Answers1

2

I do not fully understand the situation (not that you didn't explained it well), but I came across the Naga mapping issue and after finding no solution in the web I decided to give it a try and actually got it working.

The thing is that maybe my solution works for you too even if your system marks the device as a pointer instead of a keyboard. Give it a try and let me know!.

My solution is probably not the best but it surely worked for me. I wrote a little daemon in C++ and put it into a github repository that you can download and install from here

The idea is to implement these three steps:

  1. Silence the device so the buttons "do nothing" using:

    $xinput set-int-prop <id> "Device Enabled" 8 0

    Where is the id of the keypad as seen with xinput (maybe 13 in your case?)

  2. Catch the event triggered by the button pressing. I did this by grabbing the raw input from the event device node . Using C++, some sys linux libraries and input.h. You can look how to do this in google (I cannot post more than two links, but in the reddit link you have the link with a page explaining this). The good part about this approach is that you can catch the data from any device as long as xinput sees it (it does not matter if xinput thinks it is a pointer, as long as it has buttons and xinput has an id for it I believe that this approach will work, but do not quote me on this).

  3. Use C++ system() calls and xdotool (which you can install from the official ubuntu repositories) to emulate key pressings (note that a system() calls allows you to run any sort of system utility or custom script). See the man page of xdotool for more information, but the best part is that using xdotool with "--window getactivewindow" the emulated key pressings occurs in the currently focused window!

It is explained a bit further here: http://www.reddit.com/r/razer/comments/37yc3y/tutorial_remapping_naga_side_keyboard_numpad_in/

I recommend you checking out the github repository, as it has information about everything that I did. And the source code (which is only about 100 lines) is very easily extrapolated to other devices or situations. If you have a Naga and ubuntu you probably just have to use the installer and everything will be automatically set up.

In the case of the person making the question, with a bit of luck specifying manually in the file "nagastart.sh" the ID of the keypad device should do the work. Just changing one line. (currently the script searches for a Naga under keyboard devices).

I hope this is enough information, if not I'll be glad to explain anything I can about it. (Which is not very much)

By the way, It is not very foolproof, so if you install it using a wrong device id you will get unexpected behavior (like the mouse clicks doing funny things if the keypad is id=13 and you put id=14), but do not worry. Just open a terminal and killall naga. In order to remove all the changes run

 $sudo rm /usr/local/bin/naga ~/.config/autostart/naga.desktop /usr/local/bin/nagastart.sh

Good luck!

  • 1
    Welcome to U&L. We strongly prefer it to have the actual steps taken to solve a problem included there, of course with proper attribution and a link to the original post for additional detail. In that way, if the link becomes invalid, your answer doesn't automatically lose most of its value. – Anthon May 31 '15 at 18:01
  • You appear to have written the linked article so it should be fairly straightforward for you to summarise it here. Please. – Chris Davies May 31 '15 at 18:25
  • 1
    Of course, sorry for the inconvinience, I understand. Let me know if something is wrong. – apocatarsis May 31 '15 at 21:53