RedBearAK / toshy

Keymapper config to make Linux work like a 'Tosh!
https://toshy.app
GNU General Public License v3.0
349 stars 16 forks source link

Cmd+W not working in terminal #50

Closed nitingarg1000 closed 1 year ago

nitingarg1000 commented 1 year ago

Hi, I installed toshy using the --fancy-pants argument and Cmd, opt etc are working as expected. But inside terminal, I can't seem to map Cmd+W to close tab. When done through terminal preferences, upon pressing Cmd+W the shortcut is listed as Alt+F4 but it doesn't take effect whereas any other dormant shortcut works for close tab. Also, when trying to map Cmd+Q to close window, the shortcut is once again listed as Alt+F4 which could lead to conflict between the close tab and close window shortcuts.

P.S. suggestions for any third-party terminal that works similar to iTerm2 are welcome.

RedBearAK commented 1 year ago

@nitingarg1000

Oh wow, you really went for the fancy-pants argument. Not sure anybody else has done that yet. LOL. I mainly just wrote that in for myself.

I think I know what your problem is. There are "dialog fixes" for certain application windows, to make Cmd+W work in a predictable way. They match on the app class and window title. So when you tried to set the keyboard shortcut while having the Preferences dialog open and leaving Toshy active, Cmd+W got remapped to the shortcut necessary to close that particular dialog, which is Alt+F4 (yes, the same as the Cmd+Q remap).

When you are attempting to set keyboard shortcuts in applications, which is not usually necessary as Kinto or Toshy tries to remap onto existing default shortcuts, it is often a good idea to temporarily disable Toshy (or Kinto) while setting the shortcut in the app. That way, the app will see the keys you actually use, and there is no risk of the keys being remapped to something else.

So, to fix it just reset the keyboard shortcut to what it would normally be, which is Shift+Ctrl+W, and the close window shortcut should be Shift+Ctrl+Q. The config file will take care of remapping to use these mostly standard terminal shortcuts.

In general you should be careful not to change the default shortcuts for most things in most Linux apps, or it may bypass or break the equivalent Toshy shortcut in that app. Take a look at the "General GUI" keymap in the config file to see all the remaps that are active in all GUI apps.

You may or may not find a terminal with fancy features like iTerm2 in Linux. Ubuntu's standard desktop is GNOME, and in GNOME I've always just used GNOME Terminal, which I assume is what you're using.

I would install flatpak and set up the Flathub repo and check out what kind of other terminals can be installed that way.

https://flathub.org/setup

Remember to reboot after setting up Flatpaks, they need to add some paths to your profile.

RedBearAK commented 1 year ago

The general shortcuts are active in all apps, but then groups like terminal apps or file managers have overrides for some shortcuts, or additional shortcuts, and then specific apps also have their own overrides if necessary, or additional shortcut remaps that are not active in any other app window. So there is a hierarchy of general -> specific shortcuts.

If you have an app where some shortcuts are not working the way you would expect them to on the equivalent macOS app, submit an issue about it. The special shortcut Shift+Option+Cmd+I,I (double-tap the "I" key quickly) should show you a dialog with the app class and window title to help with debugging.

RedBearAK commented 1 year ago

I saw this only by email, for some reason it doesn't appear in the Kinto issue where you were posting:

I have installed toshy by using the --fancy-pants argument. I am using the Logitech MX Keys keyboard and option key on my keyboard (second key to the left of space bar) is working as the Cmd key (which is present as the first key to the left of space bar).

Seems like you already figured out how to switch the modifiers, although I'm not sure if you changed the device dictionary entry in the config file to specify it as "Apple", or just switched your keyboard to Windows mode. Either way should work.

nitingarg1000 commented 1 year ago

@RedBearAK

Cmd+W and Cmd+Q are now working inside terminal by setting the shortcuts to their default values. I had earlier changed a few of the terminal shortcuts to match them with macOS shortcuts which caused the problem.

Thanks for the information on how to debug and I'll be sure to submit an issue if I face any major annoyance with a particular app. The experience till now has been pretty smooth (only missing the 3 finger swipe now :) ).

I had deleted that comment from the Kinto issue as I was able to debug upon going over the troubleshooting segment in the toshy repo. I ended up changing the device dictionary entry in the config file.

Edit: There is one minor bug that I'm facing, I'm not able to use Cmd+ctrl+q while inside the terminal to lock screen.

RedBearAK commented 1 year ago

Yeah, leaving the defaults is usually a good idea. I lot of folks who tried to "fix" things before they used Kinto would end up having those sorts of issues. I had someone install Toshy who was remapping modifiers with an ~/.Xmodmap file, so I had to put a routine in my installer to watch out for that.

Edit: There is one minor bug that I'm facing, I'm not able to use Cmd+ctrl+q while inside the terminal to lock screen.

System-wide shortcuts like that are sometimes difficult to make universal, since not every Linux desktop environment uses the same shortcut, or even has a shortcut for it.

In my Fedora 38 GNOME it's set to use Super+L. If you look in the keyboard control panel in the Settings app and search for "lock" it should appear. If it's the same in Ubuntu, we can make a remap for it.

One thing to realize is that the physical Ctrl key on the left stays "left Ctrl" in terminal apps, but becomes the Meta/Super/Win key in all other apps. So anything involving that key often needs a separate remap for use in terminals.

Anyway, it's not as complicated as it sounds, I think we can figure it out. I'll take a look at the config and see what might be there for this already, if anything.

I ended up changing the device dictionary entry in the config file.

Good job figuring that out. I'm still thinking about a more user-friendly way to do it.

RedBearAK commented 1 year ago

@nitingarg1000

You will want to find these two keymaps in your config file and update them to match, if you want to test this out.

Terminals:

keymap("GenTerms overrides: Ubuntu/Fedora", {
    C("LC-RC-Q"):               C("Super-L"),                   # Lock screen (ubuntu/fedora)
    C("LC-Right"):              [bind,C("Super-Page_Up")],      # SL - Change workspace (ubuntu/fedora)
    C("LC-Left"):               [bind,C("Super-Page_Down")],    # SL - Change workspace (ubuntu/fedora)
# }, when = lambda ctx: matchProps(clas=termStr)(ctx) and DISTRO_NAME in ['ubuntu', 'fedora'] )
}, when = lambda ctx: matchProps(lst=terminals_lod)(ctx) and DISTRO_NAME in ['ubuntu', 'fedora'] )

GUI apps:

keymap("GenGUI overrides: Ubuntu", {
    C("Super-RC-Q"):            C("Super-L"),                   # Lock screen (ubuntu)
    C("Super-Right"):          [bind,C("Super-Page_Up")],       # SL - Change workspace (ubuntu)
    C("Super-Left"):           [bind,C("Super-Page_Down")],     # SL - Change workspace (ubuntu)
}, when = lambda ctx: matchProps(not_lst=remotes_lod)(ctx) and DISTRO_NAME == 'ubuntu' )

Then restart Toshy services via the tray icon menu, or the toshy-services-restart command, or the button in the Toshy Preferences app.

Don't touch the keyboard while the services are restarting. There is a rare issue that can happen while the keymapper is starting, if a mod key is down at exactly the wrong time. It can kind of lock up the whole keyboard. Never have figured out where that happens in the keymapper code.

If this works out for you and doesn't cause issues, I'll add it to the default config file. Which would mean you'd retain this if you reinstall Toshy from a new release at some point.

This is assuming the shortcut on Ubuntu is also Super+L for this. Notice how the first keymap uses "LC-RC-Q" for terminals, while the "GUI" keymap uses "Super-RC-Q". The modmaps are different for terminals, for the physical Ctrl key.

nitingarg1000 commented 1 year ago

This works! Thanks for all the help.

RedBearAK commented 1 year ago

@nitingarg1000

This works! Thanks for all the help.

Excellent.

You may wish to check out this somewhat new GTK4-based theme-able terminal app:

https://flathub.org/apps/com.raggesilver.BlackBox

I just saw it in a GNOME weekly update blog and decided to check it out. Seems OK, but I have no idea if it offers any benefit over existing GNOME Terminal app.

Just got finished adding its app class to the terminals list and fixing the tab navigation shortcuts (Shift+Cmd+Braces, the square bracket keys, in case you've never used them).

To get the new changes you'd need to download the zip from the dev_beta branch and reinstall. The installer will preserve any changes you've made inside any of the sets of "slice marks", like the custom device dictionary you modified.

I also had to change the way Cmd+comma works in terminals, so the --fancy-pants option will change the shortcut assigned to Preferences in GNOME Terminal to work with this.

There's actually been several other changes to the config, like supporting the "Mullvad Browser" and LibreWolf as Firefox variants.

nitingarg1000 commented 1 year ago

You may wish to check out this somewhat new GTK4-based theme-able terminal app: https://flathub.org/apps/com.raggesilver.BlackBox

My main motive to look for an iTerm2 like terminal for Ubuntu was for its extra functionality like copying just be selecting, having tab numbers and window numbers displayed in the header etc. Not a fan of themes in terminals.

I'll update the package whenever I next obtain sudo access for any other task. I don't use anything other than Terminal, VS Code or Firefox anyways.

RedBearAK commented 1 year ago

@nitingarg1000

My main motive to look for an iTerm2 like terminal for Ubuntu was for its extra functionality like copying just be selecting, having tab numbers and window numbers displayed in the header etc.

I see. Just ran into something called WezTerm (also on Flathub) that had tab numbers, but doesn't seem to have window numbers, and appears to have no GUI context menu or preferences. Though it does claim to be a multiplexer and have split panes, if you're into that.

I'll update the package whenever I next obtain sudo access for any other task. I don't use anything other than Terminal, VS Code or Firefox anyways.

Might need to check the Toshy FAQ for the methods to keep Firefox and VSCode menu bars from stealing keyboard focus when you use the Alt key. Can be an issue while trying to use multi-cursor in VSCode.

Reopen the issue if you update at some point, or make sure to use a mention (@RedBearAK) in the update, or I may not see a notification about it. 👍🏽

nitingarg1000 commented 1 year ago

I see. Just ran into something called WezTerm (also on Flathub) that had tab numbers, but doesn't seem to have window numbers, and appears to have no GUI context menu or preferences. Though it does claim to be a multiplexer and have split panes, if you're into that.

@RedBearAK Thanks for the suggestion, I'll have a look at this.

Also, not being able to use Cmd+click in Firefox to open links in a new tab.

RedBearAK commented 1 year ago

@nitingarg1000

See the FAQ entry about the keyszer suspend timer. Common problem especially for touchpads. Setting it to zero will bring up the issue of the menu stealing focus that I mentioned earlier.

https://github.com/RedBearAK/toshy#touchpadstrackpads-and-keyszer-suspend-timer

If you're having this issue it will also affect things like Shift+click to select text. Anything involving a modifier and click.

nitingarg1000 commented 1 year ago

@RedBearAK

Thanks! I understand the problem now. Should have gone through FAQs before posting.