FelixKratz / SketchyBar

A highly customizable macOS status bar replacement
https://felixkratz.github.io/SketchyBar/
GNU General Public License v3.0
5.62k stars 86 forks source link

Background image #327

Closed santilococo closed 1 year ago

santilococo commented 1 year ago

Hello, I want to set an icon on the top right corner of the space icon when the space has apps inside it.

Something like this:

image

I tried this on your plugins/yabai.sh windows_on_spaces() function:

![full_dot](https://user-images.githubusercontent.com/27114158/218441620-eb662f4d-86cb-40be-8d8c-534f0d61f64a.png)

windows_on_spaces () {
  CURRENT_SPACES="$(yabai -m query --displays | jq -r '.[].spaces | @sh')"

  args=()
  while read -r line
  do
    for space in $line
    do
      apps=$(yabai -m query --windows --space $space | jq -r ".[].app")
      if [ "$apps" != "" ]; then
        args+=(--set space.$space background.image="/Users/slococo/Desktop/full_dot.png" background.drawing=on)
      fi
    done
  done <<< "$CURRENT_SPACES"

  sketchybar -m "${args[@]}"
}

Where full_dot.png is:

full_dot

But it doesn't seem to work. Do you know if I'm doing something wrong?

image

(1, 2 and 10 have apps)

Thanks.

FelixKratz commented 1 year ago

I think it is just hilariously large and thus you cant see it because the circle area begins offscreen, try setting background.image.scale=0.1.

It would probably be easier to use a font symbol for that in the icon or label and give it an offset.

santilococo commented 1 year ago

Thanks a lot!

santilococo commented 1 year ago

Hello Felix, I currently have this (with two background images):

image

But maybe it is not very efficient to read the image every time, isn't it?

I want to ask how can I do it with an icon or label as you recommended. I read the docs but didn't see anything that could help me.

Thanks.

FelixKratz commented 1 year ago

Here is an example how to do something like this with the icon/label:

When creating the spaces like this:

SPACE_ICONS=("1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14" "15")

sid=0
spaces=()
for i in "${!SPACE_ICONS[@]}"
do
  sid=$(($i+1))

  space=(
    associated_space=$sid
    icon=${SPACE_ICONS[i]}
    icon.padding_left=10
    label.font="Hack Nerd Font:Regular:8"
    label.y_offset=8
    padding_left=2
    padding_right=2
    icon.highlight_color=$RED
    script='sketchybar --set $NAME icon.highlight=$SELECTED'
  )

  sketchybar --add space space.$sid left    \
             --set space.$sid "${space[@]}"
done

we set the label to have a small font and set a y_offset for it. The space script now only changes the highlight of the icon.

Next, in the function where we check wether there are windows on a space or not we can populate the label with an arbitrary font symbol:

windows_on_spaces () {
  CURRENT_SPACES="$(yabai -m query --displays | jq -r '.[].spaces | @sh')"

  args=()
  while read -r line
  do
    for space in $line
    do
      icon_strip=" "
      apps=$(yabai -m query --windows --space $space | jq -r ".[].app")
      if [ "$apps" != "" ]; then
        args+=(--set space.$space label=⬤)
      else
        args+=(--set space.$space label=◯)
      fi
    done
  done <<< "$CURRENT_SPACES"

  sketchybar -m "${args[@]}"
}

The result will look like this, but can be adopted to whatever you wish for (you could swap the role of the icon and label if you want to have the indication on the left of the space for example):

Screenshot 2023-02-14 at 22 26 06
santilococo commented 1 year ago

Thanks a lot! That's exactly what I wanted.