Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: focus last window #26

Closed
dialuplama opened this issue Feb 2, 2017 · 15 comments
Closed

feature request: focus last window #26

dialuplama opened this issue Feb 2, 2017 · 15 comments

Comments

@dialuplama
Copy link

How about to add waitron command to focus previously focused window.

@tudurom
Copy link
Owner

tudurom commented Feb 2, 2017

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.

@dialuplama
Copy link
Author

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.

@tudurom
Copy link
Owner

tudurom commented Feb 19, 2017

what should happen if the previously focused window is destroyed? should the previously focused window be set to the second previously focused window?

@dialuplama
Copy link
Author

Yes, and if second previously focused window is destroyed it should focus third and so on.

@tudurom
Copy link
Owner

tudurom commented Feb 19, 2017

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.

@n1kolas
Copy link

n1kolas commented Feb 21, 2017

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.

@dialuplama
Copy link
Author

dialuplama commented Feb 22, 2017

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

@tudurom
Copy link
Owner

tudurom commented Feb 22, 2017

Kinda off-topic: should I make a directory inside the repo with example scripts?

@dialuplama
Copy link
Author

Kinda off-topic: should I make a directory inside the repo with example scripts?

It makes sense

@zphixon
Copy link

zphixon commented Feb 23, 2017

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

@allora
Copy link
Contributor

allora commented Mar 6, 2017

Just put in a PR for this #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

@allora
Copy link
Contributor

allora commented Mar 6, 2017

@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.

@dialuplama
Copy link
Author

@allora Could you please also add something like waitron window_focus_last command. The original topic was about it

@allora
Copy link
Contributor

allora commented Mar 8, 2017

@dialuplama I'll do this in a different PR.

@tudurom
Copy link
Owner

tudurom commented Mar 9, 2017

@dialuplama @allora no need for a PR, I implemented the command by myself.

Thank you guys for this quality issue.

@tudurom tudurom closed this as completed Mar 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants