zegervdv / homebrew-zathura

Homebrew formulae to build Zathura on Mac OS X
555 stars 44 forks source link

Zathura auto focus on open #62

Open apexatoll opened 4 years ago

apexatoll commented 4 years ago

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 commented 3 years ago

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

tbsmn commented 3 years ago

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

popohl commented 3 years ago

Same problem here.

dakeryas commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

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

apexatoll commented 1 year ago

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 commented 1 year ago

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.