mattydebie / bitwarden-rofi

Wrapper for Bitwarden https://github.com/bitwarden/cli and Rofi
GNU General Public License v3.0
346 stars 56 forks source link

Focus last active i3 window #82

Open vargn opened 11 months ago

vargn commented 11 months ago

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 commented 7 months ago

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

LeonGr commented 1 month ago

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:

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