#!/bin/bash

# omarchy:summary=Tile a floating window
# omarchy:args=[window-address]

# The active window when given no address. This is what the titlebar's tile
# button runs. A dispatch that fails tiled nothing, so it says nothing either.
if [[ -n ${1:-} ]]; then
  hyprctl dispatch "hl.dsp.window.float({ action = \"off\", window = \"address:$1\" })" >/dev/null || exit 1
else
  hyprctl dispatch 'hl.dsp.window.float({ action = "off" })' >/dev/null || exit 1
fi

# A tiled window has no titlebar, so no button to float it again with. The
# first time says which key does, and never again.
HINTED="${XDG_STATE_HOME:-$HOME/.local/state}/omarchy/window-tile-hinted"

if [[ ! -e $HINTED ]] && omarchy-notification-send -g 󱂬 "$(omarchy-i18n window.tiled)" "$(omarchy-i18n window.tiledHint)" >/dev/null; then
  mkdir -p "$(dirname "$HINTED")" && touch "$HINTED"
fi
