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

Add backandforth attribute to Desktops tag #558

Merged
merged 1 commit into from
Mar 23, 2022

Conversation

JCallicoat
Copy link
Contributor

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:

  • Having this be configured through an attribute on the Desktops tag doesn't feel like the cleanest solution, but having a whole new tag for it seems like overkill and clutter.
  • I am not sure backandforth is the best name for the attribute, I basically just copied i3's naming because I couldn't think of anything better to express the idea.

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.

This commit adds a backandforth attribute to the Desktops tag.
The accepted values are "on and "off" (the default).

When this attribute is set to "on" trying to change desktops to the
currently active desktop with the desktop# action will change to the
previously active desktop instead.

When it is set to "off" (or not set) the previous behavior of doing
nothing is retained.
@joewing
Copy link
Owner

joewing commented Mar 23, 2022

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.

@joewing joewing merged commit 069e20f into joewing:master Mar 23, 2022
@JCallicoat JCallicoat deleted the desktop_back_and_forth branch March 23, 2022 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants