question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple callbacks in Key using when

See original GitHub issue

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.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:closed
  • Created 2 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
karthinkcommented, Oct 11, 2021

If I understand correctly, this is what you suggest:

when_floating == True => apply rule to tiled and floating windows when_floating == False => apply rule to tiled windows only when_floating == "only" => apply rule to floating windows only

I 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 to True) 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.

1reaction
m-colcommented, Oct 9, 2021

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 to True or False, 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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found