* Let the workspace layout test's Lua assertions fail the suite
Lua 5.5's standalone interpreter exits 0 when the script that raised the error came in on stdin, and exits 1 for the same error in a script file. The block here was piped in through a heredoc, so every assertion in it reported as passing however wrong the value was: changing the expected layout to one the toggle never writes still left the file green.
* Add a floating mode to the workspace layout cycle
Super + L cycled a workspace between dwindle and scrolling. It now carries on into floating, where every window on the workspace floats.
Floating cannot be a third `layout` on the workspace rule. Hyprland has no layout by that name and accepts one anyway: `hl.workspace_rule({ layout = "floating" })` returns ok and silently leaves the workspace on dwindle, exactly as a misspelt name does. So the mode floats the windows themselves, through the same `float` dispatcher SUPER + T uses.
Ending the mode has to tile the windows the mode floated and only those, so each one is tagged with `omarchy-mode-floated`. A window already floating when the mode reaches it -- an app with a float rule of its own, a dialog, one popped out with SUPER + T -- is left unclaimed and is still floating when the mode ends. The tag lives on the window rather than in a table here: it dies with the window, follows it between workspaces, and survives the config reload that plugging in a monitor performs, none of which a table on this side would do. A pinned window is left alone entirely, because tiling one unpins it as well.
Windows arrive on a workspace three ways and a window rule only covers one of them, so the mode watches events: window.open for what opens there, window.move_to_workspace for what is carried in, and the same event for what is carried back out, which gives up the floating the mode gave it rather than staying floating on a workspace that tiles. Every tiled window is claimed before any of them is floated, because floating one member of a group floats the rest, and claiming as it went would find those already floating and leave them stranded.
The mode is read back from the saved file rather than from the compositor. Hyprland reports a workspace's tiled layout and floating is not one, so a floating workspace still answers dwindle or scrolling; trusting that answer would skip a step of the cycle. A file saved before floating existed names a layout rather than a mode and falls through to what Hyprland reports, so the cycle keeps working and the next press rewrites it.
Two faults in the old script had to go first, because saving the mode makes both persistent. Named workspaces report a negative id, which passed the `^-?[0-9]+$` guard, and Hyprland reads a leading "-" as a selector relative to the current workspace: pressing Super + L on a named workspace reconfigured workspace 1 instead, and would now save a file that did it again at every login. And the saved state was written under $HOME/.local/state while the Hyprland side reads XDG_STATE_HOME, which also had to reach package.path: the loader lists that directory but loads the files by module name, so a state home anywhere else listed the saved layouts and then loaded same-named ones from the home directory.
Saving is checked too. The mode reaching the compositor and the mode reaching disk are separate things that can fail separately, and a save that failed silently would leave the next press reading a file that never got written, cycling between two modes and never reaching the third.
The guard against named workspaces stops new files being written, but an earlier version already wrote them, and they go on being loaded at every login. A migration removes the saved layouts named for a negative id.
The keyword fallback is gone. `hyprctl keyword` refuses a Lua configuration outright -- "keyword can't work with non-legacy parsers. Use eval." -- and exits 0 while doing so, so as a fallback it neither worked nor reported that it had not. A failed apply now says so and saves nothing, rather than announcing a layout the screen does not show and restoring it at the next login.
Co-Authored-By: Codex XHigh <noreply@openai.com>
* Add titlebars, edge snapping, and a window Shelf to floating workspaces
Floating workspaces become a traditional desktop that works with every
theme. Windows get themed titlebars from the omarchy-hyprland-titlebars
plugin, which is loaded only while something floats. Dragging a titlebar
to the left or right edge snaps the window to that half, and dragging it
to the top or double-clicking maximizes it. The window floating mode
places is sized, centered, and cascaded, and floating workspaces focus
on click.
Super + M, or the minus button, sets a window aside on the Shelf, which
works from any workspace and restores the window onto the current one
in that workspace's layout. Float All Workspaces makes floating the
default while Super + L still sets a single workspace's layout.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* Bring resize on border to tiling too
* Fix floating mode cleanup, fullscreen windows, and failed Shelf notes
Turning Float All Workspaces off with no workspace layouts left behind
started nothing to give the floated windows back. A window fullscreen
when its workspace began floating now floats once it leaves fullscreen.
A window whose Shelf note cannot be saved stays where it is, and the
titlebars read the theme from where omarchy-theme-set writes it.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* Place the Shelf on the bar once, instead of on every minimize
Putting it back on each minimize kept a Shelf the user moved where they
put it, but re-added one they had removed. A migration places it once for
existing bars; Super + Alt + M opens the Shelf either way.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Raise titlebars off the window background
A titlebar in the theme's background color ran into the window under it.
It takes the theme's lighter background, the raised surface every theme
defines, and the selection color on themes that make the two the same.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Drop minimizing and edge snapping from floating workspaces
A floating workspace is now titlebars with maximize and close, and nothing
else. The Shelf (its bar widget, panel, commands, notes, Super + M and
Super + Alt + M) goes with the minimize button, and the titlebar plugin's
edge snapping is left off, along with the shell's snap preview.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Stop describing the titlebar package as snapping
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Name web app windows in their launchers
Chromium names a web app window after its URL, and titles it with the page
title or just the domain. StartupWMClass ties the window to its launcher,
so the titlebar plugin can show the launcher's Name instead: WhatsApp
rather than web.whatsapp.com. New web apps, the shipped ones, and existing
launchers (through a migration) all carry it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Drop the titlebar package comment from the base list
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Show the workspace layout in the bar and cycle it on click
The focused workspace's mark is a square for dwindle, a triangle for
scrolling, and a circle for floating, and clicking it cycles the layout
as Super + L does. Both layout toggles ask the bar to read the new mode.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Show scrolling as a circle and floating as a triangle
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Move the look of the desktop to Trigger > Appearance
Menu Bar, Battery Percentage, Workspace Layout, Window Gaps, Animations,
and 1-Window Ratio change how the desktop looks rather than switching a
behavior, so they leave Trigger > Toggle for their own menu.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Choose a default workspace layout instead of floating everything
Trigger > Appearance > Workspace Layout sets the layout of every workspace
without one of its own: Tiling, Scrolling, or Floating. A tiled default
is Hyprland's own layout, and a floating one is the floating mode. It
replaces Float All Workspaces, which also overrode and set aside the
layouts workspaces had been given with Super + L.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Title the workspace layout menu Default Workspace Layout
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Use the animation icon for Appearance > Animations
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Open clipboard history from Trigger
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Leave edge resizing to looknfeel on floating workspaces
looknfeel now resizes from borders everywhere, so floating workspaces
only need to switch pointer focus to click.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Convert saved workspace layout rules to modes
Released versions saved a workspace's layout as a plain workspace rule,
which names no mode, so a floating default would override a workspace
set to scrolling, and the bar and Super + L would misread it. A migration
rewrites those files as modes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Cycle workspace layouts backwards with Super + Alt + L
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Test the Trigger > Appearance split and Clipboard History placement
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Decode escaped web app URLs before naming their windows
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Describe the workspace widget's layout mark and click
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Let a workspace cycled onto the default follow it again
Once Super + L gave a workspace a layout of its own, it kept it for good,
so a later change of the default never reached it. Cycling onto the
default layout now forgets the workspace's own instead of saving it.
Without a saved default, the default is Hyprland's own layout, which
the user's looknfeel may have set.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: David Heinemeier Hansson <david@hey.com>
Co-authored-by: Codex XHigh <noreply@openai.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
247 lines
7.8 KiB
Bash
Executable File
247 lines
7.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# omarchy:summary=Create a desktop launcher for a web app
|
|
# omarchy:args=[name url icon-url-or-name [custom-exec] [mime-types]]
|
|
|
|
set -e
|
|
|
|
ICON_DIR="$HOME/.local/share/icons/hicolor/256x256/apps"
|
|
|
|
safe_icon_name() {
|
|
printf '%s\n' "$1" \
|
|
| tr '[:upper:]' '[:lower:]' \
|
|
| sed 's/[^[:alnum:]]\+/-/g; s/^-//; s/-$//'
|
|
}
|
|
|
|
require_plain_name() {
|
|
# The name becomes a filename. A slash would turn it into directory levels, so
|
|
# the launcher lands somewhere omarchy-webapp-remove cannot address and the app
|
|
# is stuck in the launcher; a leading ../ leaves the applications directory
|
|
# altogether. Refuse rather than silently renaming what the user typed -- most
|
|
# often it is a URL entered in the name field.
|
|
if [[ $1 == */* ]]; then
|
|
echo "App name cannot contain '/': $1"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
icon_name_from_ref() {
|
|
local ref="$1"
|
|
local name
|
|
name=$(basename "$ref")
|
|
|
|
if [[ $name == *.* ]]; then
|
|
safe_icon_name "${name%.*}"
|
|
else
|
|
printf '%s\n' "$name"
|
|
fi
|
|
}
|
|
|
|
install_user_icon() {
|
|
local source="$1"
|
|
local name="$2"
|
|
local ext="${source##*.}"
|
|
|
|
[[ $ext == "$source" ]] && ext="png"
|
|
mkdir -p "$ICON_DIR"
|
|
cp "$source" "$ICON_DIR/$name.$ext"
|
|
gtk-update-icon-cache "$HOME/.local/share/icons/hicolor" &>/dev/null || true
|
|
printf '%s\n' "$name"
|
|
}
|
|
|
|
download_icon() {
|
|
curl -fsSL --max-time 10 -o "$2" "$1" 2>/dev/null &&
|
|
[[ -s $2 && $(file -b --mime-type "$2") == image/* ]]
|
|
}
|
|
|
|
# Chromium --app= treats javascript:, file:, and data: as a document to
|
|
# run. Prefix schemeless input with https as before, then refuse anything
|
|
# that is not http(s).
|
|
normalize_webapp_url() {
|
|
local url=$1
|
|
if [[ ! $url =~ ^[a-zA-Z][a-zA-Z0-9+.-]*: ]]; then
|
|
url="https://$url"
|
|
fi
|
|
printf '%s' "$url"
|
|
}
|
|
|
|
# Raw whitespace must be percent-encoded in a URL. Refuse it before serializing
|
|
# the desktop entry; before Exec argument quoting, it also split browser flags
|
|
# and additional URLs into separate arguments. Schemes are case-insensitive.
|
|
require_http_url() {
|
|
local url=$1
|
|
|
|
if [[ $url =~ [[:space:]] ]]; then
|
|
echo "Error: web app URL must not contain whitespace." >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [[ ! ${url,,} =~ ^https?:// ]]; then
|
|
echo "Error: web app URL must be http or https." >&2
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
fetch_site_icon() {
|
|
local site_url="$1" dest="$2"
|
|
local origin page icon_url
|
|
origin=$(sed -E 's|^(https?://[^/]+).*|\1|' <<<"$site_url")
|
|
|
|
# Prefer the site's own high-res icon (apple-touch-icon is typically 180px+),
|
|
# then the well-known path, then Google's favicon service as a last resort.
|
|
page=$(curl -fsSL --max-time 5 "$site_url" 2>/dev/null | head -c 100000 | tr '\n' ' ')
|
|
icon_url=$(grep -oiE "<link[^>]*rel=[\"'][^\"']*apple-touch-icon[^\"']*[\"'][^>]*>" <<<"$page" |
|
|
grep -oiE "href=[\"'][^\"']+" | head -1 | sed -E "s/^href=[\"']//")
|
|
|
|
case $icon_url in
|
|
http://* | https://*) ;;
|
|
//*) icon_url="https:$icon_url" ;;
|
|
/*) icon_url="$origin$icon_url" ;;
|
|
?*) icon_url="$origin/$icon_url" ;;
|
|
esac
|
|
|
|
{ [[ -n $icon_url ]] && download_icon "$icon_url" "$dest"; } ||
|
|
download_icon "$origin/apple-touch-icon.png" "$dest" ||
|
|
download_icon "https://www.google.com/s2/favicons?domain=${site_url}&sz=256" "$dest"
|
|
}
|
|
|
|
desktop_string_escape() {
|
|
# Desktop Entry "string" value (freedesktop Desktop Entry Spec, "Value types"):
|
|
# a raw newline would start a new key line and let a value inject a second
|
|
# Exec=. Escape backslash first, then tab/CR/LF and a leading space. Every value
|
|
# written into the .desktop file passes through here.
|
|
#
|
|
# Parameter expansion rather than sed: GNU sed's N auto-prints the pattern space
|
|
# and exits at end of input, so a `:a;N;$!ba` slurp skips every following s///
|
|
# for a value with no newline in it - which is every value except the injection
|
|
# attempt this exists to stop.
|
|
local value="$1"
|
|
|
|
value=${value//\\/\\\\}
|
|
value=${value//$'\t'/\\t}
|
|
value=${value//$'\r'/\\r}
|
|
value=${value//$'\n'/\\n}
|
|
[[ $value == " "* ]] && value="\\s${value# }"
|
|
|
|
printf '%s' "$value"
|
|
}
|
|
|
|
desktop_exec_arg() {
|
|
# One Exec argument, double-quoted per the freedesktop Exec spec: inside quotes
|
|
# " ` $ \ take a backslash and a literal % becomes %%. Only the default Exec's
|
|
# URL needs this; $CUSTOM_EXEC stays a whole command line (file-syntax only).
|
|
local escaped
|
|
escaped=$(printf '%s' "$1" \
|
|
| sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' -e 's/`/\\`/g' -e 's/\$/\\$/g' -e 's/%/%%/g')
|
|
printf '"%s"' "$escaped"
|
|
}
|
|
|
|
if (( $# < 3 )); then
|
|
echo -e "\e[32mLet's create a new web app you can start with the app launcher.\n\e[0m"
|
|
APP_NAME=$(gum input --prompt "Name> " --placeholder "My favorite web app")
|
|
require_plain_name "$APP_NAME"
|
|
APP_URL=$(gum input --prompt "URL> " --placeholder "https://example.com")
|
|
APP_URL=$(normalize_webapp_url "$APP_URL")
|
|
require_http_url "$APP_URL"
|
|
|
|
# Try to fetch the site's icon automatically first.
|
|
mkdir -p "$ICON_DIR"
|
|
ICON_VALUE=$(safe_icon_name "$APP_NAME")
|
|
if fetch_site_icon "$APP_URL" "$ICON_DIR/$ICON_VALUE.png"; then
|
|
gtk-update-icon-cache "$HOME/.local/share/icons/hicolor" &>/dev/null || true
|
|
ICON_REF="$ICON_VALUE"
|
|
else
|
|
ICON_REF=$(gum input --prompt "Icon URL/name> " --placeholder "Could not fetch favicon automatically. Enter PNG icon URL or icon name")
|
|
fi
|
|
|
|
CUSTOM_EXEC=""
|
|
MIME_TYPES=""
|
|
INTERACTIVE_MODE=true
|
|
else
|
|
APP_NAME="$1"
|
|
APP_URL=$(normalize_webapp_url "$2")
|
|
require_http_url "$APP_URL"
|
|
ICON_REF="$3"
|
|
CUSTOM_EXEC="$4" # Optional custom exec command
|
|
MIME_TYPES="$5" # Optional mime types
|
|
INTERACTIVE_MODE=false
|
|
fi
|
|
|
|
# Ensure valid execution
|
|
if [[ -z $APP_NAME || -z $APP_URL ]]; then
|
|
echo "You must set app name and app URL!"
|
|
exit 1
|
|
fi
|
|
|
|
require_plain_name "$APP_NAME"
|
|
|
|
if [[ -z $ICON_REF ]]; then
|
|
ICON_VALUE=$(safe_icon_name "$APP_NAME")
|
|
mkdir -p "$ICON_DIR"
|
|
if ! fetch_site_icon "$APP_URL" "$ICON_DIR/$ICON_VALUE.png"; then
|
|
echo "Error: Failed to download icon."
|
|
exit 1
|
|
fi
|
|
gtk-update-icon-cache "$HOME/.local/share/icons/hicolor" &>/dev/null || true
|
|
elif [[ $ICON_REF =~ ^https?:// ]]; then
|
|
ICON_VALUE=$(safe_icon_name "$APP_NAME")
|
|
mkdir -p "$ICON_DIR"
|
|
if ! download_icon "$ICON_REF" "$ICON_DIR/$ICON_VALUE.png"; then
|
|
echo "Error: Failed to download icon."
|
|
exit 1
|
|
fi
|
|
gtk-update-icon-cache "$HOME/.local/share/icons/hicolor" &>/dev/null || true
|
|
elif [[ -f $ICON_REF ]]; then
|
|
ICON_VALUE=$(install_user_icon "$ICON_REF" "$(safe_icon_name "$APP_NAME")")
|
|
else
|
|
# Bundled Omarchy icons are package-owned under /usr/share/icons/hicolor.
|
|
# Accept either "HEY" or the historical "HEY.png" argument form.
|
|
ICON_VALUE=$(icon_name_from_ref "$ICON_REF")
|
|
fi
|
|
|
|
# Default Exec quotes the URL as one Exec-spec argument; the whole line then gets
|
|
# the file-syntax escaping below (unescaped first at read time per spec, so the
|
|
# layers compose). $CUSTOM_EXEC is a full command line, so it gets file-syntax only.
|
|
if [[ -n $CUSTOM_EXEC ]]; then
|
|
EXEC_COMMAND=$CUSTOM_EXEC
|
|
else
|
|
EXEC_COMMAND="omarchy-launch-webapp $(desktop_exec_arg "$APP_URL")"
|
|
fi
|
|
|
|
# Create application .desktop file
|
|
DESKTOP_DIR="$HOME/.local/share/applications"
|
|
DESKTOP_FILE="$DESKTOP_DIR/$APP_NAME.desktop"
|
|
mkdir -p "$DESKTOP_DIR"
|
|
|
|
name_field=$(desktop_string_escape "$APP_NAME")
|
|
exec_field=$(desktop_string_escape "$EXEC_COMMAND")
|
|
icon_field=$(desktop_string_escape "$ICON_VALUE")
|
|
|
|
cat >"$DESKTOP_FILE" <<EOF
|
|
[Desktop Entry]
|
|
Version=1.0
|
|
Name=$name_field
|
|
Comment=$name_field
|
|
Exec=$exec_field
|
|
Terminal=false
|
|
Type=Application
|
|
Icon=$icon_field
|
|
StartupNotify=true
|
|
EOF
|
|
|
|
# Add mime types if provided
|
|
if [[ -n $MIME_TYPES ]]; then
|
|
printf 'MimeType=%s\n' "$(desktop_string_escape "$MIME_TYPES")" >>"$DESKTOP_FILE"
|
|
fi
|
|
|
|
# Floating titlebars name the window after this entry rather than its page title.
|
|
if [[ -z $CUSTOM_EXEC ]]; then
|
|
printf 'StartupWMClass=%s\n' "$(desktop_string_escape "$(omarchy-webapp-window-class "$APP_URL")")" >>"$DESKTOP_FILE"
|
|
fi
|
|
|
|
chmod +x "$DESKTOP_FILE"
|
|
|
|
if [[ $INTERACTIVE_MODE == "true" ]]; then
|
|
echo -e "You can now find $APP_NAME using the app launcher (SUPER + SPACE)\n"
|
|
fi
|