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

Focus last active i3 window #82

Open
vargn opened this issue Oct 8, 2023 · 2 comments
Open

Focus last active i3 window #82

vargn opened this issue Oct 8, 2023 · 2 comments

Comments

@vargn
Copy link

vargn commented Oct 8, 2023

I have follow focus_follows_mouse yes in my i3 config file. So when I launch the bwmenu rofi window and copy the password. The window that will be focused is where my mouse cursor happens to be. Even though I might have previously navigated windows using keybinds. This is a bit annoying as I often have to re-navigate to the window I had active when launching the bwmenu. What should I add to the bwmenu script so that it will focus the last active window and not the window where the mouse cursos is currently placed?

@vargn
Copy link
Author

vargn commented Feb 6, 2024

I can't be the only one with this issue? Please point me in the right direction :)

@LeonGr
Copy link

LeonGr commented Jul 17, 2024

I wrote the following bwmenu wrapper script to deal with this:

#!/bin/bash

# store current mouse location
mouse_location="$(xdotool getmouselocation --shell)"
while IFS= read -r line; do
    declare "$line"
done <<< "$mouse_location"

# store resolution of current monitor
current_monitor_resolution="$(get_focused_monitor_resolution)"
while IFS= read -r line; do
    declare "$line"
done <<< "$current_monitor_resolution"

# mark currently focused window
i3-msg mark "bwmenu-mark"

# move mouse to upper-left of screen
warpd --move '1 1'

# call bwmenu and pass along all given parameters
bwmenu "$@"

# move mouse back to where it was before calling bwmenu
# (modulo resolution of current monitor, since warpd is relative to current monitor)
warpd --move "$((X % WIDTH)) $((Y % HEIGHT))"

# focus on window with mark
i3-msg '[con_mark="bwmenu-mark"] focus'

# remove mark
i3-msg unmark "bwmenu-mark"

It does make some assumptions though:

  • It assumes you're using the 'type all/username/password' functionality instead of copying the password. The problem with copying is that the bwmenu process only exits after the clipboard is cleared, so the script doesn't continue until that happens.
  • The cursor has to be placed somewhere unfocusable. In my case this is https://github.com/polybar/polybar/, at the top of the screen. I use https://github.com/rvaiya/warpd to place the cursor there and then place it back in the original location afterwards.

I hope this works for you or gives you an idea how to fix it for your exact usecase

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants