Closed dialuplama closed 7 years ago
Why would you use it? I'm pretty curious.
I've been thinking of adding a config key for focusing the previously focused window after the currently focused window is closed.
Why would you use it? I'm pretty curious.
Well, most of the windows managers and even terminal multiplexers allows you to quick switch between the current and previously focused window. It's really efficiently in my opinion.
I've been thinking of adding a config key for focusing the previously focused window after the currently focused window is closed.
Yes! This is also what I wanted to ask. Because when you close some window and don't use sloppy focus you need to do extra move to set focus. It's annoying sometimes.
what should happen if the previously focused window is destroyed? should the previously focused window be set to the second previously focused window?
Yes, and if second previously focused window is destroyed it should focus third and so on.
well, because that would be pretty complicated because windowchef stores the focused window in a variable and that would be replaced by a stack, it would be simpler to write a script using wew
from wmutils that listens to window creation and focus events and keeps a stack in a text file. I'm still thinking if I should really implement this as a feature or not.
Just an idea: maybe this can use the functions introduced by the cardinal focus feature. When the window gets closed the window closest to it gets focused. I'm not sure if there's that much benefit in having the focus specifically on the last focused window, which would make implementation a bit more difficult - as you would have to keep history.
it would be simpler to write a script using wew from wmutils that listens to window creation and focus events and keeps a stack in a text file.
So here is script. Maybe it will be useful for someone. It stores focused windows in file and focus previously focused window after currently focused window is closed or unmapped (and it will be ignore to focus unmapped windows so it will be work with groups)
#! /bin/sh
wlist="/tmp/.wlist"
[ -e $wlist ] && rm $wlist
wew -m 2097152 | while IFS=: read ev wid; do
case $ev in
# Focus in event. Write wid to the window list
9)
echo $wid >> $wlist
;;
# Destroy event. Delete wid from the window list
17)
grep -v $wid $wlist > $wlist.tmp
mv $wlist.tmp $wlist
;;
# Unmap event. Focus last wid from the window list. Ignore unmapped windows.
18)
for id in $(tac $wlist); do
wattr m $id && [ "$wid" != "$id" ] && waitron window_focus $id && break
done
;;
esac
done
In additional to focus last focused window, you should bind following script to some hotkey. For example alt + grave
. Also it will be not ignore unmapped windows. But it can be changed.
#! /bin/sh
wlist="/tmp/.wlist"
for id in $(tac $wlist); do
[ "$(pfw)" != "$id" ] && mapw -m $id && waitron window_focus $id && break
done
Kinda off-topic: should I make a directory inside the repo with example scripts?
Kinda off-topic: should I make a directory inside the repo with example scripts?
It makes sense
would be simpler to write a script using wew from wmutils that listens to window creation and focus events and keeps a stack
Here you go. It seems to work pretty well so far, I haven't had any glaring issues in the ten minutes or so that I've been using it.
I would've used bash but I'm not great at it.
Edit: I just saw @dialuplama's solution. I'd probably use that over this, but we'll see where it takes me.
Edit2: There are a few edge cases that I didn't consider. Definitely go with the shell script, my version needs some work...
Just put in a PR for this https://github.com/tudurom/windowchef/pull/29
EDIT: Also this change would allow a "toggle last focused" to work. I didn't expose it in the PR, but I don't see it being much work to add. Additionally, it would also be possible to wrap the "toggle last focused on unmapped or window destroy/close" in a config var. I am just lazy and didn't... :P
@n1kolas Its certainly possible for some of the distance checks used by the cardinal focuser to pick the nearest window to the closed one.. Not sure if that's really useful.
@allora Could you please also add something like waitron window_focus_last
command. The original topic was about it
@dialuplama I'll do this in a different PR.
@dialuplama @allora no need for a PR, I implemented the command by myself.
Thank you guys for this quality issue.
How about to add waitron command to focus previously focused window.