baskerville / bspwm

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

Add bspc command ('focus') to focus the window under pointer #1428

Closed lleonini closed 1 year ago

lleonini commented 1 year ago

Hi, I have created that new command to simply focus the window under the pointer (when one is not using focus_follows_pointer option).

I have a (quite simple) use case that wasn't possible to implement correctly without this patch: I want to close window(s) by SUPER+midle_click on them. I don't want the current focused window to be closed but the window directly under the pointer.

Even trying hard in sxhkdrc I couldn't get it to work properly, consider these attempts:

1) super + button2   bspc node -c => Close the currently focused window (not necessarily under pointer). Practically I was often closing the wrong window because the one under pointer wasn't focused and it's very annoying to click once to focus and once to close

2) super + button2   xdotool click --clearmodifiers 1; bspc node -c => xdotool doesn't work properly because we are already «inside» a click with button2

3) super + @button2   xdotool click --clearmodifiers 1; bspc node -c => Seems to work but there is a race condition if we release SUPER too fast, SUPER can be re-enabled by xdotool (SUPER is stuck even if the key was released), this is the bug described here: https://github.com/jordansissel/xdotool/issues/43

4) super + @button2   xdotool click --clearmodifiers 1; bspc node -c; xdotool keyup Super_L Super_R=> Workaround the problem in 3) but now SUPER is removed even if the key is still pressed on the keyboard, so we can't chain close multiple windows that way or use another SUPER combination

5) With this patch super + button2   bspc focus; bspc node -c

I think this is a useful addition that permits to easily cover some common use cases. Best, Lorenzo

emanuele6 commented 1 year ago

Why though? bspc node pointed -f already exists as a bspwm command, and you can also use many other external programs such as xdotool that you mentioned to do the same thing: e.g. xdotool getmouselocation windowactivate.

  1. With this patch super + button2 bspc focus; bspc node -c

This is just silly, you don't need to focus a window just to close it. You can simply close it directly. Both asking bspwm to do it with bspc node pointed -c, or using an external tool, like xdotool as xdotool getmouselocation windowclose.

lleonini commented 1 year ago

Thank you for these information!