Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow use of linux Super key for shortcuts #2524

Closed
brotherJ4mes opened this issue Nov 9, 2024 · 9 comments · Fixed by #2543
Closed

allow use of linux Super key for shortcuts #2524

brotherJ4mes opened this issue Nov 9, 2024 · 9 comments · Fixed by #2543

Comments

@brotherJ4mes
Copy link

I love everything about Min. Great functionality; very sleek.

I can easily find how to set custom shortcuts on the settings page but as far as I can tell, the only recognized modifiers are "ctrl" and "alt" (which map to "mod" and "option", respectively in the settings.json file)

I attempted to write in "super" as a short cut (e.g. super+t for new tab) but it didn't seem to register.

I also tried "meta" since that's how the super key is recognized in Vivaldi and "m" which is used for super in Chromium.

Is using the Super key currently possible in Min?

Would it be feasible to implement?

Could one develop a userscript to make it work or are modifiers too "low level"?

@PalmerAL
Copy link
Collaborator

PalmerAL commented Dec 1, 2024

I looked at this a little bit, and I'm not sure what would be needed to support this. Internally, Min has two separate keyboard event handlers, depending on which part of the UI you're in:

The first is Mousetrap - I think the Linux super key would be equivalent to the Windows key, but that apparently isn't supported, and it wasn't added because "Unfortunately this means it is not going to be a simple thing to add to the core library since the windows key is not treated as meta, shift, ctrl, or alt" (ccampbell/mousetrap#81)

The usage of Mousetrap is mostly just a leftover legacy thing - it would make sense to refactor everything to use the Electron input system, which we also use in some places. If we did that, then these docs apply: https://www.electronjs.org/docs/latest/api/web-contents#event-before-input-event

That page doesn't mention the super key specifically, but the linked keyboardEvent.metaKey docs say:

Returns a boolean value that is true if the Meta key (on Mac keyboards, the ⌘ Command key; on Windows keyboards, the Windows key (⊞)) was active when the key event was generated.

Which seems to contradict what the Mousetrap issue says.

I only have Apple keyboards to test this on (so nothing with a super key), but if you have time, could you try this?
Inside this function, add console.log(input): https://github.com/minbrowser/min/blob/master/js/keybindings.js#L121

Then, while the keyboard focus is in the browser UI (like the searchbar, not a webpage), try pressing super+any key, copy the resulting input object from the devtools, and paste it here.

@brotherJ4mes
Copy link
Author

brotherJ4mes commented Dec 5, 2024

Thanks for your detailed response!

I'm not sure I follow 100% of what you said about Mousetrap vs Electron but it sounds like there's hope maybe.

I'd be happy to try what you suggest...

I edited the initialize function of the script as you suggested but I can't get min to compile possibly b/c my npm is out of date. (I installed npm via Rocky repos).

I have a separate machine that runs Ubuntu so hopefully it will work there. (Will try again and update soon)

  1. Does it matter where in the function I put the console.log(input) call?
  2. I assume "console" implies that the info we're looking for will get written to stdout after calling npm run start and following your directions?

@brotherJ4mes
Copy link
Author

Okay so I was able to update npm and now I can run in development node but still stuck without getting much output. (I put the console.log(input) command below the webviews.bindEvent call --line 122)

Min works fine (using npm run start from within source code dir) but I don't see much output. I also see NO output when actually using shortcuts... even ones that definitely work like ctrl+t (in that case the shortcut works and additional tab appears but no additional output is printed to the terminal running Min.)

I thought maybe my assumption was wrong about printing to stdout so I also checked recursively for modified files using find to no avail.

@PalmerAL
Copy link
Collaborator

PalmerAL commented Dec 7, 2024

Does it matter where in the function I put the console.log(input) call?

Nope.

I assume "console" implies that the info we're looking for will get written to stdout after calling npm run start and following your directions?

You'll need to look for developer > inspect browser > console in the application menu. Sorry for not mentioning that.

@brotherJ4mes
Copy link
Author

Got it, thanks!

If I try to use a Meta like shortcut in the Min searchbar nothing prints to the console but the same is true for shortcuts that are actively working for me (ctrl+T to open a new tab).

However, if I shift focus off the search bar and press, say, Meta+T and then release the following is printed to the console:

{type: 'keyDown', key: 'Meta', code: 'MetaLeft', isAutoRepeat: false, isComposing: false, …}
bundle.js:9407 
{type: 'keyDown', key: 't', code: 'KeyT', isAutoRepeat: false, isComposing: false, …}
bundle.js:9407 
{type: 'keyUp', key: 't', code: 'KeyT', isAutoRepeat: false, isComposing: false, …}
bundle.js:9407 
{type: 'keyUp', key: 'Meta', code: 'MetaLeft', isAutoRepeat: false, isComposing: false, …}

There's also the option to expand each of these lines for key down/up like:

{type: 'keyDown', key: 'Meta', code: 'MetaLeft', isAutoRepeat: false, isComposing: false, …}
alt: false
code: "MetaLeft"
control: false
isAutoRepeat: false
isComposing: false
key: "Meta"
location: 1
meta: falsemodifiers: (2) ['left', 'numlock']
shift: false
type: "keyDown"
_modifiers: 3072
[[Prototype]]: Object

Which then have the option to be expanded further so let me know if any of that info is helpful too or if there are any other tests I could try.

@PalmerAL
Copy link
Collaborator

Thanks!

I've created a branch here with what I think is the correct mapping, can you try it? https://github.com/minbrowser/min/tree/linux-super-key

I think the right combination is:

  • Mac: "mod" maps to "Meta", "super" also maps to "Meta"
  • Linux: "mod" maps to "Ctrl", "super" maps to "Meta"
  • Windows: "mod" maps to "Ctrl", "super" maps to "Meta" but is displayed in the UI as "win"

(does that sound right?)

@brotherJ4mes
Copy link
Author

I just checked out the new branch and it worked!

Specifically if I assign "super+t" in the shortcuts and then restart Min, that shortcut now works.

This totally resolves my request (many thanks) but just for your reference, I'm finding that "mod" is not an accepted shortcut. If I type that for a shortcut and restart Min it seems to default back to whatever the previous shortcut was. This is a non-issue for me as I can still simply use "Ctrl" directly (instead of "mod") which works fine and appears to be the default for most shortcuts when running Min under Linux.

Please let me know if you need any other tests/info from me and thanks again for making the needed changes to get this to work!
(feel free to close otherwise)

@brotherJ4mes
Copy link
Author

Edit: I see now that in settings.json the string "mod" is listed repeatedly in the shortcuts so maybe that's what you were referring to. (whereas in the above post, I meant what I was actually typing on the settings page of the Min browser)

@PalmerAL
Copy link
Collaborator

Oh, right, I forgot that we actually display "mod" in the UI as either command or ctrl, depending on your OS.

I've created a PR #2543; I'll merge it in a bit assuming there are no comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants