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

Zathura auto focus on open #62

Open
apexatoll opened this issue Oct 21, 2020 · 9 comments
Open

Zathura auto focus on open #62

apexatoll opened this issue Oct 21, 2020 · 9 comments

Comments

@apexatoll
Copy link

I've just set up zathura as my default file viewer to open PDF files from the terminal on OS X. However zathura opens the file in the background meaning that I have to cmd tab a couple of times to focus on the window. Is there anything i can set in the zathura rc to enable auto focus on the newly opened window? Zathura was installed via homebrew

@zegervdv
Copy link
Owner

zegervdv commented Jan 6, 2021

You can try if the new osx integrations fix your issue, see #38 for instructions on how to install

@tbsmn
Copy link

tbsmn commented Jan 28, 2021

I have the same problem I can confirm #38 is not fixing the issue.

@popohl
Copy link

popohl commented May 6, 2021

Same problem here.

@dakeryas
Copy link
Contributor

dakeryas commented Feb 2, 2023

This is not a direct zathura fix, but it makes zathura completely usable if you're using the yabai tiling window manager for OSX. The idea is to focus the last zathura window created when the event=window_created is triggered for apps of type zathura.

The following signal

yabai -m signal --add app="^zathura$" event=window_created action="~/.config/yabai/focus_last_window_id.zsh zathura"

with the following ~/.config/yabai/focus_last_window_id.zsh ZSH script

#!/usr/bin/env zsh

function last_window_id(){
    local app=$1
    id=$(yabai -m query --windows | jq -e "map(select(.app==\"$app\")) | .[0] | .id") && echo $id
}

function focus_last_window_id(){
    local app=$1
    id=$(last_window_id $app) && yabai -m window --focus $id
}

focus_last_window_id $@

works perfectly for me.

@sohaiberrabii
Copy link

Adding this command to yabairc also works perferctly for me:

yabai -m signal --add app="zathura" event=window_created \
    action="yabai -m window last --focus"

@dakeryas
Copy link
Contributor

dakeryas commented Feb 6, 2023

@sohaiberrabii

I can't remember why I didn't go with your simpler action! I guess focusing on the last window is a bit more fragile than the last "zathura" window of my script (with the jq select filter), but probably good enough for 99% of the cases! No issues with multiple monitors (I have struggled getting consistent behaviour with them at times)?

EDIT: @sohaiberrabii I have folded back to my script that specifically selects the zathura app. Otherwise, I would randomly get focused on other windows (I don't fully understand yabai's flickering that seem to refocus on other windows in some conditions; I have tried playing around with the value of window_origin_display but not getting something consistent).

@jessebot
Copy link

I don't use yabai. I use rectangle. Has anyone made this work for rectangle? 🤔 Otherwise I might just give yabai a shot 😊

@apexatoll
Copy link
Author

I'm using Yabai - that is a fantastic shout on adding a custom event to refocus

In fact it reminds me I'm probably not using Yabai to its fullest capibailities

@dakeryas
Copy link
Contributor

I don't use yabai. I use rectangle. Has anyone made this work for rectangle? 🤔 Otherwise I might just give yabai a shot 😊

I also use Rectangle, it's not redundant at the moment for me because some windows get stacked with Yabai but are not accessible unless I half the front window thanks to Rectangle!

Yabai might be overkill if you just need Zathura to focus, but I don't see how you could emulate Yabai's signals and rules without... Yabai.

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

7 participants