tolga9009 / sidewinderd

Linux support for Microsoft SideWinder X4 / X6 and Logitech G103 / G105 / G710+.
http://cevel.net
Other
151 stars 26 forks source link

Binding macro keys to shell commands #15

Open emmiegit opened 8 years ago

emmiegit commented 8 years ago

Is it possible to have a key binding run a shell command? This way a macro key could be used to, for example, start a batch job, run a program in a certain configuration, etc.

tolga9009 commented 8 years ago

It should be possible to achieve that by using System Settings > Keyboard > Shortcut (in GNOME, might be different in KDE) and attach a custom command to a key combination of your choice. Just make sure your script is set as executable (chmod +x). In sidewinderd, you can then attach that key combination to a macro key.

emmiegit commented 8 years ago

Hmm, that's true, but that's a bit indirect and wastes a binding. (Though I suppose there are some bindings you'll never use, like <C-M-S-F1>). I think it would be a nice feature for the sidewinder daemon to be able to run commands on behalf of the calling user to run programs. Do you think that's a good idea?

tolga9009 commented 8 years ago

It's some kind of reinventing the wheel. It might "waste" a key bind (you can bind anything you want, even unrealistic shortcuts like Ctrl + Super + Alt + L) , but it's already been done by other devs and the code is already available. And chances are high, if you already have a desktop environment installed, you don't even have to download additional software.

Problem is, this adds another layer of complexity to the driver. Users would need to decide, whether to bind a script or record a macro. While recording a macro is pretty much straight forward, binding a script would need manual editing - like writing the script by hand in the first place. But then again, if you'd already need to write scripts and bind them to keys manually, why not do it using a proven, stable software?

I think there is no right or wrong, whether feature xyz is a good idea or not. When I'm unsure about a feature, I like to refer to the vendor's official drivers: they really implement the very basic stuff (macros, assigning keys etc.). On the other hand, Windows users don't use scripts excessively as Linux users, so this might have impacted their design decision.

I will leave this open for further discussion, I want to decide on this, once we got session daemons implemented (planned for 0.5.0), as this feature will also arise questions about user permissions and security aswell. I would also like to know, whether KDE and XFCE allow the same shortcut feature, as GNOME allows it.

emmiegit commented 8 years ago

I think that's a sensible decision. The process of creating a keybind is pretty solid as-is, so we' would have to think of a good way to add scripting without making the process convoluted or confusing. In my view, since binding to a script is not really thing one can just do on-the-fly (since it would involve typing the full name of the script or command), it perhaps may be better implemented as a command line tool or modification to the configuration file.

Speaking of the vendor's official drivers, that's actually where I came up with this idea. Logitech has this interface for the G710+ on Windows, and one of the things you can do with a G key is to run an application when it's pressed. In terms of basing features off of those in the Windows driver, I like that sidewinderd is frugal: the GUI sometimes feels like typical bloatware that comes with hardware on Windows.

arunce commented 8 years ago

It's the same for KDE.

tolga9009 commented 7 years ago

Hi there,

I've thought about this idea again. First of all, I wanted to let you know, that @cmaster11 created a fork for this. You can find his branch here: https://github.com/cmaster11/sidewinderd. His idea was to use a new element in XML files called "CommandEvent", which lets sidewinderd execute that command. In my opinion, that's a very good way to solve this.

My concerns are more about security. Think about the following scenario: you have a macro, and malicious code (or a user) modifies your macro files to execute a command, which tries to delete everything it can. So, next time you press one of your G-Keys, that command will get executed. Even if you're not running sidewinderd as root (which currently doesn't work by design anyway), it will still delete most of your /home/user directory; data, that's important to you. This kind of malicious code wouldn't even need root access, as the sidewinderd macro files are readable and writable by your configured user (aka your desktop user). Means, even malicious macros in office documents could do this.

Still, I'm not your mom and will let you - ladies and gentlemen - decide, whether you want this or not (knowing the security risks). Per default, this feature will be disabled and you will need to explicitly enable it using configuration file. I will take a similar direction, @cmaster11 already took.

Cheers, Tolga

emmiegit commented 7 years ago

You could do some SSH-like sanity checks that ensures the file is owned by the calling user and not writable by others. Then if the permissions are bad it simply refuses to execute them.

While this wouldn't prevent malicious code running as your user from injecting evil macros, if they're running as the target user anyways, they may as well rm -rf $HOME instead of changing macro files. If somebody can run arbitrary shell commands they've already won.

kolgza commented 5 years ago

I'm still wondering what the most sensible way to accomplish this would be.