baskerville / bspwm

A tiling window manager based on binary space partitioning
BSD 2-Clause "Simplified" License
7.61k stars 420 forks source link

node selector behaves differently in query vs node focus #1460

Closed ShinyZero0 closed 11 months ago

ShinyZero0 commented 11 months ago

this works:

bspc node -f $(bspc query -N -n .local.floating)

this doesn't:

bspc node -f .local.floating

version 0.9.10

emanuele6 commented 11 months ago

Node selectors do not behave differently.

.local.floating is not a valid node selector, as it is missing a node descriptor; it is just a list of node modifiers.

The -n/-d/-m options for the query -N/query -D/query -M commands will accept either a node/desktop/monitor selector, or a list of node/desktop/monitor modifiers. If you specify a selector, it will constrain result the only the node/desktop/monitor specified by that selector; if you just specify a modifier, it will constrain results to any node/desktop/monitor that matches those modifiers.

A node selector will only specify one node, with bspc query -N -n .local.floating, you are getting the IDs of all the nodes that match those modifiers.

In fact, your bspc node -f $(bspc query -N -n .local.floating) command will have a few problems if there are more than one match or no matches.

If you use an actual node selector, it will work with node too; for example, you can use the any node descriptor to get the "first" node that matches the given modifiers (the first node that would show up in the ouptut of bspc query -N):

bspc node any.floating.local -f
# or:  bspc node -f any.floating.local

Note that, when you use a selector for node -f, you almost always want to specify .!hidden otherwise, if there is a floating node in the focused desktop, that is hidden, and happens to be the "first" .local.floating node, your command will fail because hidden nodes are not focusable, even though there is another focusable node that matches those modifiers.

Also note, that if you are writing a hotkey to focus a floating window, it is better to use next or prev instead of any, so that if you press the binding multiple times, you will focus another floating window instead of the same one again. (next focuses the "first" node that matches the given modifiers, starting from after the focused node, unlike any that always starts from the root node of the first non-free desktop; prev is similar, but matches the first node looking going backwards starting from the focused node).

Example sxhkd hotkeys:

# focus or cycle floating windows
super + {_,shift + }g
    bspc node '{next,prev}.!hidden.local.floating' -f
# focus or cycle tiled (or pseudo_tiled) windows
super + {_,shift + }c
    bspc node '{next,prev}.!hidden.local.!floating.!fullscreen.window' -f

Perhaps you were thinking .local.floating was a node selector because the manual says that the -n option of the query commands accepts node selectors; that was a documentation bug that has since been fixed on the git repository, now the documentation says that -n accepts either a node selector (NODE_SEL) or a list of node modifiers (NODE_MODIFIERS).

ShinyZero0 commented 11 months ago

Oh now i get it, thank you for this explanation.