Multiple callbacks in Key using when
See original GitHub issueI’m trying to assign multiple functions to a single key depending on whether the window is floating or tiled:
Key([mod, mod3], "h",
lazy.window.move_floating(-32, 0).when(when_floating=True),
lazy.layout.shuffle_left().when(when_floating=False),
desc="Move window to the left"),
Key([mod, mod3], "l",
lazy.window.move_floating(32, 0).when(when_floating=True),
lazy.layout.shuffle_right().when(when_floating=False),
desc="Move window to the right"),
Key([mod, mod3], "j",
lazy.window.move_floating(0, 32).when(when_floating=True),
lazy.layout.shuffle_down().when(when_floating=False),
desc="Move window down"),
Key([mod, mod3], "k",
lazy.window.move_floating(0, -32).when(when_floating=True),
lazy.layout.shuffle_up().when(when_floating=False),
desc="Move window up"),
There are two problems:
- It runs the first callback only, the second is never run.
- It’s ignoring the when condition: It runs the
move_floating
command for both tiled and floating windows.
Am I doing something wrong? Is there a cleaner way to do this?
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Multiple callbacks in Key using when · Issue #2847 · qtile/qtile
I'm trying to assign multiple functions to a single key depending on whether the window is floating or tiled: Key([mod, mod3], "h", lazy.window....
Read more >How to collect multiple callbacks to call once a task is done
What I do is use a "Collector" where callbacks can be stored for a given key. The first request to store a callback...
Read more >Advanced Callbacks | Dash for Python Documentation | Plotly
If a Dash app has multiple callbacks, the dash-renderer requests callbacks to be executed based on whether or not they can be immediately...
Read more >Callbacks in JavaScript - Medium
There are two types of callbacks. A callback passed to a function f can be invoked synchronously before f returns, or it can...
Read more >Mastering Hard Parts of JavaScript: Callbacks II
multiMap will return an object whose keys match the elements in the array of values. The corresponding values that are assigned to the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If I understand correctly, this is what you suggest:
when_floating == True
=> apply rule to tiled and floating windowswhen_floating == False
=> apply rule to tiled windows onlywhen_floating == "only"
=> apply rule to floating windows onlyI think this is still very confusing. Something like this makes more sense to me and doesn’t require a new value:
Default behavior => Apply rule to all windows (This is already the case, since the current definition of
when_floating
defaults toTrue
)when_floating == True
=> Apply rule to floating windows only.when_floating == False
=> Apply rule to tiled windows only.Currently there is no reason for anyone to use
when_floating = True
in their config, since it does nothing, that’s the default behavior. With this change both True and False are meaningful.OK, so I was able to reproduce too, and then got confused because the code looked fine, but then I discovered that
when_floating
isn’t “limit this to when the current window is floating” but rather “also call this when the current window is floating”. This means that we’re actually seeing the intended behaviour. I can see why this would be desired, but it obviously isn’t being communicated clearly enough in the docs!To get the behaviour that you’re after we’ll need a way to specify only floating, perhaps by letting
when_floating
accept the string"only"
in addition toTrue
orFalse
, and then not executing the call when the current window is tiled. If I’ve got this all right, would you like to take a stab at implementing that? Otherwise I am also happy to do so!