Coder Social home page Coder Social logo

Comments (2)

qRoC avatar qRoC commented on July 26, 2024

Ok, I remove label from bad space, and add to created.
But windows from old web moved to first space on main display. how I can reassign windows to spaces? Only remove and create rules again?

from yabai.

qRoC avatar qRoC commented on July 26, 2024

Script for display_added, display_removed events, and in yabairc:

#!/bin/bash

function find_free_space() {
  yabai -m query --spaces | jq -e '[.[] | select (.label == "" and ."is-native-fullscreen" == false)][0].index'
}

function has_space() {
  yabai -m query --spaces | jq -e --arg label "$1" '.[] | select(.label == $label)' > /dev/null 2>&1
}

function has_bad_space() {
  # # https://github.com/koekeishiya/yabai/issues/1853
  yabai -m query --spaces --space "$1" > /dev/null 2>&1
}

function setup_space() {
    has_space $1
    if [ $? -eq 0 ]; then
        echo "space $1 already exists"
        return
    fi

    # unlabel bad space
    has_bad_space $1
    if [ $? -eq 0 ]; then
        echo "space $1 is bad, remove label"
        yabai -m space $1 --label
    fi

    # find free space or create a new one
    idx=$(find_free_space)
    if [ $? -ne 0 ]; then
      echo "create new space for $1"
      yabai -m space --create
      idx=$(find_free_space)
    else
      echo "use existing space $idx for $1"
    fi

    yabai -m space "$idx" --label "$1"
}

echo "Setup spaces"

setup_space media
setup_space support
setup_space chats
setup_space web
setup_space work
setup_space tmp

echo "Normalizing spaces"

# when there are more than one display
if [ "$(yabai -m query --displays | jq -r '. | length')" -gt 1 ]; then
  IFS=' ' read -r -a indexes <<< $(yabai -m query --displays | jq -r 'sort_by(.frame.y) | "\(.[0].index) \(.[1].index)"')

  # 'web' and 'chats' spaces are on the top display
  yabai -m space web --display "${indexes[0]}"
  yabai -m space chats --display "${indexes[0]}"

  yabai -m space media --display "${indexes[1]}"
  yabai -m space support --display "${indexes[1]}"
  yabai -m space work --display "${indexes[1]}"
  yabai -m space tmp --display "${indexes[1]}"

  # all fullscreen windows are on the main display
  IFS=' ' read -r -a fullscreen <<< $(yabai -m query --spaces | jq -r '[.[] | select (."is-native-fullscreen" == true) | .index] | join(" ")')
  for i in "${fullscreen[@]}"; do
    yabai -m space "$i" --display "${indexes[1]}"
  done
fi

# Destroy not used spaces
IFS=' ' read -r -a not_used <<< $(yabai -m query --spaces | jq -r '[.[] | select (.label == "" and ."is-native-fullscreen" == false) | .index] | join(" ")')
for i in "${not_used[@]}"; do
  echo "Destroying not used space $i"
  yabai -m space "$i" --destroy
done

# TODO: need remove and add rules for spaces

from yabai.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.