joewing / jwm

Joe's Window Manager
http://joewing.net/projects/jwm
MIT License
520 stars 84 forks source link

Add backandforth attribute to Desktops tag #558

Closed JCallicoat closed 2 years ago

JCallicoat commented 2 years ago

Hello again! I have been using JWM for the past week as my daily driver and I really love how much functionality is packed into such a small and fast window manager. One thing I have been missing is a feature i3 calls workspace_auto_back_and_forth and xfce calls toggle_workspaces.

The basic idea is that when you try to switch to the currently active desktop using the desktop# action, it will instead switch to the previously active desktop rather than being a no-op. This is very convenient to quickly switch back and forth when working on something between two desktops (e.g., a terminal and a chat application).

For example, if I have a terminal open in desktop 1 and slack open in desktop 2, desktop 1 is currently active, and I have a keybinding like

<Key mask="4" key="#">desktop#</Key>

I can press mod4+2 to switch to desktop 2, and then press mod4+2 again to switch back to desktop 1. It's even more convenient when I am working between, say, desktop 5 and 1 and only need to press mod4+1 to switch back and forth.

This PR adds a backandforth attribute to the Desktops tag to configure this functionality. Possible values are "on" and "off" (the default). If set to "off" (or unset) the current behavior of doing nothing when switching to the currently active desktop is retained. When set to "on", the previously active desktop will be switched to instead.

There are a couple of things I am unsure about:

Note that the checking for current desktop and swapping in the previous desktop needs to be done in ProcessBinding in event.c and not in ChangeDesktop in desktop.c, so that it only applies to our own calls from the desktop# action and is not executed when external pagers or tools like wmctl and xdotool request to change the _NET_CURRENT_DESKTOP property. This unfortunately means the check for currentDesktop == desktop is duplicated in both places, but I do not see a way to avoid that.

joewing commented 2 years ago

Thanks for another great PR! That's a neat feature. backandforth seems like a reasonable thing to call it given that's what it's called elsewhere. I'd almost be tempted to make it the default and maybe not configurable given that it doesn't do anything right now, though I suppose that could be confusing for some.