-
-
Notifications
You must be signed in to change notification settings - Fork 647
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
Opacity toggle for focused window #503
Comments
I could be wrong, but it also seems like the |
I don't think it makes sense to toggle opacity on/off for specific windows. I think it might be appropriate to add a I think an alternative solution, as you mentioned, is to make sure that topmost windows are always kept at 100% opacity, unless specifically told otherwise (using the window rules system). |
I tried the first approach to force the opacity, but I get:
However, I agree that the second solution feels cleaner! Is there a way to target every topmost windows directly from the config? I couldn't figure out how to achieve this. |
@koekeishiya I think I am kind of stuck here. I trigger the script below to:
Whenever I remove the rule, the opacity is stuck at Am I doing anything wrong here? #! /usr/bin/env zsh
# get the app name, title, and id of the focused window
app=$(yabai -m query --windows --window | jq -re .app)
title=$(yabai -m query --windows --window | jq -re .title)
id=$(yabai -m query --windows --window | jq -re .id)
topmost=$(yabai -m query --windows --window | jq -re .topmost)
# temporarily create (or remove) a rule to manage its opacity
if [[ "$topmost" = 0 ]]; then
yabai -m rule --add app="${app}" title="${title}" label="${id}" opacity=1.0
echo 'rule added'
else
yabai -m rule --remove "${id}"
echo 'rule removed'
fi
# toggle floating and topmost layer
yabai -m window --toggle float
yabai -m window --toggle topmost |
Implemented the first suggestion; new command to set the opacity of a window:
Opacity can also be changed by invoking new rules for the same window, after an initial opacity was set previously. The opacity command will also override any opacity that was set previously through a rule or by the focus change in yabai. Current window opacity is also returned as an attribute 'opacity' in window queries. |
This is amazing, @koekeishiya ! Thanks a lot for the addition! |
Just wanted to thank you as well. It's amazing how powerful this is. I wanted a better Slack client that didn't eat all my RAM so I found Ripcord. But then it bothered me a bit so I wanted to give it some opacity and I stumbled upon this issue. So with this script I got Ripcord to have opacity when it sits topmost and isn't focused. Unfocused: https://i.kzen.pro/2020-06-30/15-13-42--FXrnH.png Focused: https://i.kzen.pro/2020-06-30/15-19-40--stzBE.png
#!/bin/bash
# /Users/me/windowmanager/ripcord_opacity
RIPCORD_PID=$(yabai -m query --windows | jq -r '.[] | select(.app == "Ripcord").pid' | uniq)
RIPCORD_ID=$(yabai -m query --windows | jq -r '.[] | select((.app == "Ripcord") and (.topmost == 1)).id' | uniq)
if [ -z "$RIPCORD_PID" ] || [ -z "$RIPCORD_ID" ]; then
# Ripcord isn't open or isn't topmost
exit 0
fi
if ! yabai -m query --windows \
| jq -er "map(select((.pid == $RIPCORD_PID) and (.focused == 1))) | length >= 1" > /dev/null
then
# Ripcord hasn't any focused windows
# Set opacity to 0.6
yabai -m window $RIPCORD_ID --opacity 0.6
exit 0
fi
# Ripcord is focused, fallback to default opacity settings
yabai -m window $RIPCORD_ID --opacity 0.0
exit 0 |
I was actually planning on making something like this for mpv when I play videos on the side, but didn't get around to it yet. |
Love that script @RobinHoutevelts. Here's a version for all topmost floating windows: #! /usr/bin/env zsh
function topmost_opacity {
{
windows="$(yabai -m query --windows)"
# selectively blacklist apps here, e.g., Alfred
query='.topmost == 1 and .focused == 0 and .app != "Alfred"'
jq -n --argjson windows "${windows}" "\$windows[] | select((${query}) | not).id" |
xargs -I{} yabai -m window {} --opacity 1.0
jq -n --argjson windows "${windows}" "\$windows[] | select(${query}).id" |
xargs -I{} yabai -m window {} --opacity 0.9
} 2>/dev/null
} yabai -m signal --add event=application_front_switched action="${functions[topmost_opacity]}"
yabai -m signal --add event=window_focused action="${functions[topmost_opacity]}" |
Really helpful, and thank you @dominiklohmann. Update: |
After the removal of window borders I decided to go back to an opacity-based focus.
Is there any way to toggle the opacity of a focused window? Something like:
yabai -m window --toggle opacity
It would be particularly useful when paired with pip or sticky mode: with
window_opacity on
in the config, cycling between different windows would keep the pip/sticky on top with a decreased opacity.This can cause some clutter depending on the content of the window that's underneath the floating one:
The text was updated successfully, but these errors were encountered: