koekeishiya / skhd

Simple hotkey daemon for macOS
MIT License
6.07k stars 204 forks source link

Adding mouse button support #269

Open lokxii opened 1 year ago

lokxii commented 1 year ago

Merged conflicts of #248

This pull request adds mouse button support on top of existing functionality in response to #195 and #245. A mouse button is made to treat as a key in config file such that writing (non-modifier) key + mouse combination not supported. It is however possible to do for example shift + alt - mouse_left.
A total of 32 keywords are added to correspond to what Carbon supports.
It is possible to use -k flag to synthesize a mouse click. However it is intentionally made to click at coordinates (-1, -1) to prevent clicking any elements on screen.

kzvi commented 1 year ago

I get this compiler warning which seems important:

In file included from src/skhd.c:39:
src/synthesize.c:76:24: warning: result of comparison of constant -1 with expression of type 'uint8_t' (aka 'unsigned char') is always false [-Wtautological-constant-out-of-range-compare]
    if (hotkey->button == -1) {
        ~~~~~~~~~~~~~~ ^  ~~
lokxii commented 1 year ago

thx for pointing it out. Probably I just filtered away warnings and somehow testing was fine (or test not thorough enough)

koekeishiya commented 1 year ago

I think in cases like this it would be more appropriate to use UINT8_MAX instead of -1 to signal intent (even though -1 will have the same binary representation when stored in a uint8_t). I do think the compare with -1 is undefined behaviour unless explicitly casted to an unsigned type, and even if it is not, using the hex representation (0xFF) would be more appropriate.

There probably won't be further code changes to this repo, so it's not like I want or expect these changes to be done; just a note.

rickalex21 commented 8 months ago

There's no mouse button support? I was looking to do a middle click. I did not know that. 🤔

palkx commented 8 months ago

@9tin9tin9 are there any updates on this? It would be very helpful to have this feature implemented. If this is blocked by something, can we resolve this? Thanks!

lokxii commented 8 months ago

I don't think koekeishiya will merge this into master. So if you want to use this feature, maybe you can download and install skhd from my fork.

I won't be maintaining / adding new features besides merging from master because I personally is not a mouse user. However, if you have feature request about mouse hotkeys, I may consider implementing it.

palkx commented 8 months ago

Yes, I find this pretty useful. For example, when you have a mouse with additional keys you can map those keys to switch between workspaces. On the Apple mouse, you can do this simply with gestures. @koekeishiya is it possible to merge this PR?