-
-
Notifications
You must be signed in to change notification settings - Fork 103
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
add sketchybar docs #81
Conversation
17ac33a
to
0f73c0f
Compare
I’ll update this PR tomorrow based on the changes to #80 . |
docs/goodness.adoc
Outdated
# ~/.config/sketchybar/sketchybarrc | ||
|
||
# Add AeroSpace workspace event | ||
sketchybar --add event aerospace_change bobko.aerospace.WorkspaceFocus |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be added directly when you create a space. See my example below
sketchybar --add event aerospace_change bobko.aerospace.WorkspaceFocus | ||
|
||
# Add Workspaces | ||
for sid in $(aerospace list-workspaces); do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could extend this to show how to deal with multiple screens. Here is my config:
#!/bin/bash
SPACE_ICONS=("1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14" "15")
sid=0
monitors_count=$(aerospace list-monitors | wc -l)
workspaces=$(aerospace list-workspaces)
for sid in $workspaces; do
if [ "$sid" -lt 5 ] || [ "$monitors_count" -eq 1 ]; then
display=1
else
display=2
fi
padding_right=0
if [ "$sid" -eq 8 ] || [ "$sid" -eq 4 ]; then
padding_right=8
fi
sketchybar --add item space.$sid left \
--add event aerospace_change bobko.aerospace.focusedWorkspaceChanged \
--subscribe space.$sid aerospace_change \
--set space.$sid \
associated_display=$display \
icon=${SPACE_ICONS[$((sid-1))]} \
icon.padding_left=16 \
icon.padding_right=$padding_right \
icon.highlight_color=$DRACULA_GREEN \
click_script="aerospace workspace $sid" \
script="$PLUGIN_DIR/aerospace.sh $sid"
sketchybar --trigger aerospace_change
done
aerospace.sh:
#!/bin/bash
SID=$1
visible_workspaces=$(aerospace list-workspaces --visible)
visible=$(echo "$visible_workspaces" | grep -q "$SID" && echo "on" || echo "off")
sketchybar --set $NAME icon.highlight=$visible label.highlight=$visible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was intentionally keeping the config as simple as possible and adapted the default sketchybar config. I think such elaborate configs are better suited to the sketchybar showcase github discussion as to not bloat this document.
0f73c0f
to
8ac4220
Compare
Updated, should work now with #80 changes. |
And it gets me that the workspace switching feedback isn't immediate. I mean, AeroSpace command is fast, why is feedback switch slow then? That's super suspicious. I also tried to explicitly invoke |
@nikitabobko a small delay is I guess because of using |
But @MatthiasGrandl says that sketchybar was fast when we were passing Now AeroSpace still sends the That all doesn't add up. It all makes me think that the problem is somewhere in sketchybar |
I also experimented with this a bit more. I tried adding a second sketchybar event that fires when the notification is received. That event queries the active workspace and adds it to its payload. this way the aerospace command only needs to be executed once instead of once per workspace. It seems to help somewhat, but still not as responsive as the initial |
The problem is not caused by sketchybar. Try running sh -c 'time aerospace list-workspaces --focused' it returns real 0m0.061s
user 0m0.003s
sys 0m0.002s which is already slow if you compare it to a sketchybar query. This might be due to the slow socket IPC used in AeroSpace vs the orders of magnitude faster mach IPC used in sketchybar. (Edit: yabai querys are actually as fast as sketchybar querys while using sockets, so it must be something else) Additionally, there is another problem with the IPC AeroSpace uses, namely it is blocked if the main thread is congested. This will happen when many AX api calls are made, because this is a blocking API and will thus drastically increase response latency. To test this you can use the provided snippet to try and call the sketchybar --add event aerospace_change bobko.aerospace.focusedWorkspaceChanged
sketchybar --add item test left --set test script='time aerospace list-workspaces --focused' --subscribe test aerospace_change resulting in: real 0m0.173s
user 0m0.004s
sys 0m0.003s Which is the raw time it takes to call the aerospace command and has nothing to do with sketchybar, as you can verify by manually triggering the sketchybar --trigger aerospace_change resulting in the same latency as sh -c 'time aerospace list-workspaces --focused' |
@FelixKratz I can confirm. I replaced Update: sketchybar --add item space.$sid left \
--subscribe space.$sid aerospace_change \
--set space.$sid \
background.color=0x44ffffff \
background.corner_radius=5 \
background.height=20 \
background.drawing=off \
label="$sid" \
click_script="aerospace workspace $sid" \
script="$PLUGIN_DIR/aerospace.sh $sid" This code runs |
You could easily set it up to only execute the aerospace command once, but still ~150ms of command latency during a workspace change is definitely noticeable. |
jup that's what I did. it definitely helps, but still not nice. |
I updated my config to run only once this script: #!/bin/bash
workspaces=$(aerospace list-workspaces)
visible_workspaces=$(aerospace list-workspaces --visible)
for sid in $workspaces; do
NAME="space.$sid"
visible=$(echo "$visible_workspaces" | grep -q "$sid" && echo "on" || echo "off")
sketchybar --set $NAME icon.highlight=$visible label.highlight=$visible
done Now it works better but still the lag from |
Thanks for the comments! I change my mind. I now agree that query commands need to be optimized -> #104
Can you please write how you did that? I'm not fluent in sketchybar. |
@nikitabobko I did it like this: # Add AeroSpace workspace event
sketchybar --add event aerospace_change bobko.aerospace.focusedWorkspaceChanged \
--add item ev left \
--subscribe ev aerospace_change \
--set ev script='sketchybar --trigger aerospace FOCUSED="$(aerospace list-workspaces --focused)"' \
--add event aerospace aerospace then you have access to the |
The most elegant way to provide this information would be to add the space change event info to the payload of the distributed notification. Since the AX api is used, it will never be possible to sandbox this app (AX and Sandbox are incompatible by nature), so passing a non-null payload is no constraint. But if thats not possible, I would also do it as @MatthiasGrandl showed, creating a (invisible) dummy item that annotates the event from aerospace with the required info and forwards it to all other items: sketchybar --add event aerospace_raw bobko.aerospace.focusedWorkspaceChanged \
--add event aerospace_change \
--add item ev left \
--set ev updates=on drawing=off \
script='sketchybar --trigger aerospace_change FOCUSED="$(aerospace list-workspaces --focused)"' \
--subscribe ev aerospace_raw The space items would now subscribe to the annotated |
Jup that was my approach in the PR #80 , but we changed it due to the sandboxing concerns. |
Most probably it's true. But I still don't want to use It's some obscure non-composable Apple API, but I want to keep AeroSpace close to UNIX foundations. I don't see any standard ways to send I haven't used Frankly speaking, I didn't want to include the patch that uses My opinion is close to "religious", but it's what it is right now. I might change it later |
I adapted the PR and merged it Thanks! |
This has another benefit, where you will be able to provide environment variables to scripts. Once this is included, the superior implementation would be to call the |
I've dropped NSDistributedNotification in favor of The process has access to |
Sounds good to me! |
Co-authored-by: Nikita Bobko <[email protected]> closes nikitabobko#81
Disclaimer: I am not super familiar/comfortable with Asciidoc.
This is a sample integration for Sketchybar. It should be equivalent to the default Sketchybar Mission Control module.
Depends on #80 to work.