AstroSnail / apexctl

(Apache-2.0) Control SteelSeries Apex keyboards on GNU/Linux!
Apache License 2.0
28 stars 3 forks source link

Apex Raw - Ubuntu 18.04 LTS #4

Closed mabasic closed 4 years ago

mabasic commented 4 years ago

Hello,

thank you for creating this thingy :)

Going to contribute here with my feedback on making this work for Steelseries Apex Raw and Ubuntu 18.04 LTS.

I ran this command to install dependencies:

sudo apt install libhidapi-dev pkgconf

It said that I already had libhidapi-dev installed and it only installed pkgconf (pkgconf_0.9.12-6_amd64.deb). After that I ran make and got this error:

cc -std=c99 -Werror=all -Wextra -Wpedantic -Os $(pkgconf --cflags hidapi-libusb) -DENABLE_CMD_PROBE=1 -DENABLE_DATA_PRINT=0 -s $(pkgconf --libs hidapi-libusb)  apexctl.c   -o apexctl
/tmp/cciXZ1b7.o: In function `usb_setup':
apexctl.c:(.text+0x1a2): undefined reference to `hid_init'
apexctl.c:(.text+0x1bf): undefined reference to `hid_open'
/tmp/cciXZ1b7.o: In function `usb_cleanup':
apexctl.c:(.text+0x202): undefined reference to `hid_close'
apexctl.c:(.text+0x208): undefined reference to `hid_exit'
/tmp/cciXZ1b7.o: In function `usb_put':
apexctl.c:(.text+0x210): undefined reference to `hid_send_feature_report'
collect2: error: ld returned 1 exit status
<builtin>: recipe for target 'apexctl' failed
make: *** [apexctl] Error 1

Any ideas?

I tried searching online and found something related to header files being included in wrong order or something like that. My C is very rusty, but I'm hoping to remember it.

AstroSnail commented 4 years ago

Hi, thanks for the feedback, I think I know what the issue is. I've pushed a commit that should fix it, give it a try and tell me if it worked. :)

mabasic commented 4 years ago

Thanks for a quick response.

It worked sort of :)

I've managed to run the make command. It returned no errors and it created a file apexctl in the repo directory.

I have then followed the readme:

Copy the apexctl binary to /usr/local/sbin/.

Copy config/00-apex.hwdb to /etc/udev/hwdb.d/ and rename it to your preference. Then run udevadm hwdb --update or systemd-hwdb update. To apply immediately, run udevadm trigger.

Copy config/00-apexctl.rules to /etc/udev/rules.d/ and rename it to your preference.

If you use X11, copy config/00-apex.conf to /etc/X11/xorg.conf.d/ and rename it to your preference.

This last line I did not do since I think that Ubuntu 18.04 uses xorg and not x11. My knowledge here is limited.

Then I ran apexctl keys on and opened Gnome Settings to test the MX and M keys and try to map them to something.

1st run. After opening Gnome settings and navigating to Devices->Keyboard->Keyboard shortcuts the program stopped responding. I killed the process manually, but my CPU now acts crazy. One core gets pinned to 100% for some period of time and then it changes the core and starts again. I've taken a screenshot of top. See image.

Screenshot from 2020-01-06 12-58-41

2nd run. Without restarting the PC I opened Gnome Settings again and tried to do the same thing as before. This time it worked, except these keys:

It does not detect these keys.

Going to restart the PC and test again.

P.S. Before I restart here is the CPU history:

Screenshot from 2020-01-06 13-16-46

Update

After restarting the PC, CPU is still acting same. Going to revert the actions one by one.

Update 2

I found the culprit. It was pwrstatd a daemon from CyperPower which monitored my UPS. After killing the process and uninstalling it my CPU went back to normal. Now I can't confirm if the CPU pinning was happening before I run some of the command before or after, but I am almost sure that it did not happen before.

I'll will give it another go tomorrow and report back.

Are you open to a PR which will automate copying the files above and running commands?

P.S. Any ides why the keys mentioned above don't work?

AstroSnail commented 4 years ago

When I said X11 I did actually mean Xorg, apologies, I've pushed an update that clarifies the idea. However, the file is non-essential anyways, so you shouldn't need to worry about it.

As for the non-working keys, I'm not immediately sure of what's wrong. If you could run xev | fgrep keycode, press the keys which don't work, and give me the output, that might give me some insight. (don't forget to install xev if you don't have it, a quick search tells me it's in the x11-utils package for ubuntu)

mabasic commented 4 years ago

Ok, tested everything with the latest code from master branch and I can confirm that all my MX and M keys are detected and working.

At first two attempts the Gnome Settings froze while trying to map keys, but after that it just worked.

P.S. I tried to follow the last line If you use Xorg, copy config/00-apex.conf to /etc/X11/xorg.conf.d/ and rename it to your preference. but I got:

cp: cannot create regular file '/etc/X11/xorg.conf.d/': Not a directory

Thank you!

AstroSnail commented 4 years ago

It seems Ubuntu does not ship /etc/X11/xorg.conf.d/ by default. You'll have to create the directory yourself, copy the file into it, and Xorg will automatically read it when it starts up again.

Glad to know it's working now. :)

mabasic commented 4 years ago

What does that file exactly do, since this seems to be working without it?

AstroSnail commented 4 years ago

The file informs Xorg of the model of the keyboard, which is apparently used for nothing else than setting the XKB geometry. I don't know of any program which makes use of this feature of XKB, but it exists and apparently the Apex 300 model comes preinstalled with Xorg on Arch. One day I might design models for the other Apex keyboards and submit them to Xorg so that the model is correct on all keyboards for whatever mystery program uses it.

As I said, it's not essential.

mabasic commented 4 years ago

Cool. Thanks for explaining. 👍

merlin5153 commented 4 years ago

thanks for this mate. just curious as to how to change what keys are mapped to for example setting the MX5 to F24?

AstroSnail commented 4 years ago

@merlin5153 It's actually quite tough to do that. I recently changed the mappings so that the user doesn't have to do quite as much manual configuration (which also makes the automated installation pretty trivial).

If you really want to set your own mappings, you have a few choices.

One is a very quick hack that will probably work in a pinch. Simply configure your hotkey daemon to respond to pressing MX5 (currently the symbol it emits is XF86KbdBrightnessUp) by running something like xdotool key F24.

Another is finding a keysym map in /usr/share/X11/xkb/symbols/ that has all the symbols you want. For example, in my system, fujitsu_vndr/us has all the F-keys up to F32, and is based on the regular us layout. This would make it almost ideal, but it has the caveat that the default evdev keycodes only go up to F24, and the fujitsu keycodes map a lot of keys differently which could make your keyboard unusable. (the keycode configurations are in /usr/share/X11/xkb/keycodes/) On top of that, you'll have to edit the config/00-apex.hwdb file in ApexCtl before you install it, so that udev correctly maps the scancodes of the extra keys that the keyboard sends into the keycodes which map to F13-F24. If you change the keys you want to f13 through f24 it should work with the evdev keycodes. (see an old version of the file) After that, it should be a simple case of making sure you remember to give the right options to setxkbmap. (or correctly setting up whatever your keyboard configuration tool is)

Lastly, you can go fully custom. This was what ApexCtl used to do before I made the mapping changes. If you look at this old commit, you'll find a config/steelseries file and extra installation instructions in the README. Instead of relying on keysym maps already present in your system, ApexCtl shipped with one you would install yourself, typically somewhere in your home directory tree. Please note there is a bug in this setup, where the media keys (at the right edge of my Apex) do not work at all. Additionally, at the end of the README are tips for even further customization to give you complete control over the mapping from keycodes to symbols. This is a very advanced approach that will probably take a lot of time to get working properly, so it isn't for everyone, which is why I decided to change it. I might bring back detailed instructions and support files later in case you want to try this out.

merlin5153 commented 4 years ago

I’m actually really new to linux and want to use my Mx keys for various functions for my games and MX5 was my push to talk. I have it working as a push to talk but with it being assigned to brightness I get the icon showing up on my screen which is annoying. I’ll have a read on your suggestions in the morning when I wake up

AstroSnail commented 4 years ago

Ah, that's unfortunate. I imagine a lot of these XF86* symbols will interfere with the system. Unfortunately the default configuration rules don't leave very much room for extra keys.

I might be able to help you on this specific situation though. In the config/00-apex.hwdb file you'll find the udev configuration that maps scancodes to keycodes. Before you install it, if you swap the number to the right of KEYBOARD_KEY_0700ec= with, for example, the one below it, the MX5 key will now send XF86Reply, which hopefully doesn't cause any unwanted icons. You can try swapping numbers around until you find a setup that you like.

merlin5153 commented 4 years ago

Thank you very much mate

merlin5153 commented 4 years ago

that worked out perfectly mate thank you so much

AstroSnail commented 4 years ago

You're welcome. :)

Just to let you know, I've pushed those extra instructions and files for advanced configuration. If you ever want to give it a try, it's all there. The default installation is unchanged.

mabasic commented 4 years ago

I just got the time to mess around with this more and I have more questions :)

  1. I tried mapping keys using Gnome Settings -> Devices -> Keyboard and it detects the keys, but then it does nothing.
  2. I tried the advanced configuration but then everything got messed up. Like M9 was disabling the touchpad or enabling it. I even don't have a touchpad. :) Then I tried to uninstall everything that I had done to that moment and still my keyboard had the keys enabled. So I rerun sudo make install and now everything is where I started from.

My question is: Can I map keys using Gnome Settings Devices Keyboard, or do I have to use some other software?

I want to be able to let's say map MX1 to open the terminal (currently super+T) or in the future run custom command line by pressing M6 without it triggering other things.

I am very new to this so explain it to me like a child :)

P.S. Loving the sudo make install and sudo make uninstall scripts. Much easier.

AstroSnail commented 4 years ago

I am not familliar with Gnome Settings Devices Keyboard, so I don't know for sure. From what I can quickly find, you should be able to set custom keyboard shortcuts with it. If it can detect the keys, maybe you can set a shortcut that makes MX1 open the terminal? If it doesn't work at all, you can try using specific software for keyboard shortcuts, such as sxhkd or xbindkeys. You can use xev | fgrep keysym to find out what exactly the keys are sending to help you configure them.

The advanced configuration is also probably causing problems with Gnome Settings Devices Keyboard. When you install the extra 00-apex.hwdb file but don't configure the keyboard, you get exactly what you described. (M9 toggles the touchpad) The advanced configuration does not take into account the system's usual mappings, because it expects you to use different rules, which come with ApexCtl. If Gnome Settings Devices Keyboard isn't able to use the new rules then I think the only solution (short of not using Gnome) is to use Xmodmap as the old (Haskell) ApexCtl used to have. I should be able to make an Xmodmap file that works with the current ApexCtl if the need arises.

AstroSnail commented 4 years ago

I've pushed an update that adds an Xmodmap file which can be applied to the default configuration. It should help fix any issues with the system thinking you want to raise the keyboard brightness or toggle the touchpad. If the provided instructions don't work try installing it to /etc/X11/Xmodmap instead, and tell me so that I can change the instructions.

mabasic commented 4 years ago

I can confirm than copying the file and running xmodmap manually works, but I can't figure out a file where to place the command to load on startup.

cp config/extra/Xmodmap ~/.Xmodmap
xmodmap ~/.Xmodmap

Manually running the command works, but after relogin it does not. I have tried placing it in:

Then I have tried adding it to the startup programs, but it simply does not run for some reason.

I have tried placing it in /etc/X11/Xmodmap but it does nothing.

AstroSnail commented 4 years ago

I did some research, and found Startup Applications for Ubuntu. If this is what you mean by "startup programs" and adding xmodmap ~/.Xmodmap to it doesn't work then maybe you can try the other solutions in the link; if it isn't then perhaps you can try it to see if it works.

mabasic commented 4 years ago

I added it, but it just does not run. Running xmodmap ~/.Xmodmap manually works.

Going to close this issue since the driver works on Ubuntu.