Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions bin/rice-switch
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ gui_menu() {
current="$(current_rice)"

local rice_names=() plain_rows="" rofi_rows="" active=""
local gutter_on='<span font="JetBrainsMono Nerd Font 8" alpha="80%">● </span>'
# alpha 1%: Pango's alpha range starts at 1, so 0% is not a valid value
local gutter_off='<span font="JetBrainsMono Nerd Font 8" alpha="1%">● </span>'
for d in "$DOTFILES_DIR"/rices/*/; do
[[ -d "$d" ]] || continue
local rname title subtitle
Expand All @@ -103,8 +106,13 @@ gui_menu() {
[[ "$rname" == "$current" ]] && active="${#rice_names[@]}"
rice_names+=("$rname")
plain_rows+="$title${subtitle:+ — $subtitle}"$'\n'
rofi_rows+="<span weight=\"600\">$(markup_escape "$title")</span>"
[[ -n "$subtitle" ]] && rofi_rows+=$'\n'"<span size=\"small\" alpha=\"55%\">$(markup_escape "$subtitle")</span>"
# A leading column holds a dot for the current rice. Both lines start
# with the same monospace glyph (invisible where unused), so the name
# and the subtitle stay aligned whatever the proportional font does.
local dot="$gutter_off"
[[ "$rname" == "$current" ]] && dot="$gutter_on"
rofi_rows+="$dot<span weight=\"600\">$(markup_escape "$title")</span>"
[[ -n "$subtitle" ]] && rofi_rows+=$'\n'"$gutter_off<span size=\"small\" alpha=\"55%\">$(markup_escape "$subtitle")</span>"
rofi_rows+=$'\x1f'
done

Expand All @@ -121,7 +129,7 @@ gui_menu() {
# separated by \x1f instead of newlines
local args=(-dmenu -i -no-custom -format i -markup-rows -sep $'\x1f' -eh 2
-l "${#rice_names[@]}" -p "󰍉" -theme "$theme"
-mesg "Current: $(markup_escape "$current") · ↵ switch and log out · esc cancel")
-mesg "Switching logs you out · ↵ switch · esc cancel")
[[ -n "$active" ]] && args+=(-a "$active" -selected-row "$active")
choice=$(printf '%s' "$rofi_rows" | rofi "${args[@]}") || return 0
elif command -v fuzzel >/dev/null 2>&1; then
Expand Down
80 changes: 48 additions & 32 deletions common/rofi/rice-switch.rasi
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* Rice switcher (bin/rice-switch): frosted panel in the style of macOS Spotlight.
* Translucent enough for the compositor's blur, opaque enough to read without it.
* Only the accent comes from the palette (colors.rasi). */
@import "colors.rasi"
/* Rice switcher (bin/rice-switch): a frosted row list in the style of macOS.
* Neutral glass on purpose; translucent enough for the compositor's blur and
* opaque enough to read without it. */

configuration {
show-icons: false;
Expand All @@ -11,15 +10,15 @@ configuration {
}

* {
font: "Inter 11";
font: "Inter 10.5";

glass: rgba(28, 28, 32, 70%);
stroke: rgba(255, 255, 255, 13%);
glass: rgba(30, 30, 34, 66%);
stroke: rgba(255, 255, 255, 14%);
hairline: rgba(255, 255, 255, 7%);
field: rgba(255, 255, 255, 8%);
text: rgba(255, 255, 255, 92%);
text-dim: rgba(235, 235, 245, 50%);
text-dim: rgba(235, 235, 245, 52%);
hover: rgba(255, 255, 255, 10%);
accent: @selected-fg;

background-color: transparent;
text-color: @text;
Expand All @@ -29,36 +28,54 @@ window {
transparency: "real";
location: center;
anchor: center;
width: 520px;
padding: 8px;
width: 540px;
padding: 20px 14px 14px 14px;
border: 1px;
border-color: @stroke;
border-radius: 18px;
border-radius: 24px;
background-color: @glass;
}

mainbox {
spacing: 6px;
children: [ "inputbar", "listview", "message" ];
spacing: 12px;
children: [ "header", "listview", "message" ];
}

header {
orientation: horizontal;
expand: false;
spacing: 16px;
padding: 0 6px;
children: [ "textbox-title", "inputbar" ];
}

textbox-title {
expand: true;
str: "Switch Desktop";
font: "Inter Display Semi-Bold 16";
vertical-align: 0.5;
horizontal-align: 0.0;
text-color: @text;
}

inputbar {
padding: 10px 12px 12px 12px;
spacing: 12px;
border: 0 0 1px 0;
border-color: @hairline;
expand: false;
width: 200px;
padding: 7px 12px;
spacing: 8px;
border-radius: 10px;
background-color: @field;
children: [ "prompt", "entry" ];
}

prompt {
font: "JetBrainsMono Nerd Font 15";
font: "JetBrainsMono Nerd Font 11";
text-color: @text-dim;
vertical-align: 0.5;
}

entry {
font: "Inter Display 15";
placeholder: "Switch rice";
placeholder: "Search";
placeholder-color: @text-dim;
cursor: text;
vertical-align: 0.5;
Expand All @@ -71,12 +88,14 @@ listview {
cycle: true;
scrollbar: false;
spacing: 2px;
padding: 2px 0;
padding: 8px 0 0 0;
border: 1px 0 0 0;
border-color: @hairline;
}

element {
padding: 8px 12px;
border-radius: 11px;
padding: 9px 14px;
border-radius: 12px;
cursor: pointer;
}

Expand All @@ -88,22 +107,19 @@ element selected.active {
element-text {
text-color: inherit;
vertical-align: 0.5;
highlight: bold;
cursor: pointer;
}

element normal.active,
element selected.active,
element alternate.active {
text-color: @accent;
}

message {
padding: 8px 12px 4px 12px;
padding: 10px 0 2px 0;
border: 1px 0 0 0;
border-color: @hairline;
}

/* the footer; textbox-title above sets its own colour and alignment */
textbox {
font: "Inter 9.5";
font: "Inter 9";
text-color: @text-dim;
horizontal-align: 0.5;
}
6 changes: 4 additions & 2 deletions tests/rice-switch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# 3. A chosen row still reaches the switch.
# 4. Empty or path-like rice names are rejected.
# 5. Menu content: one two-line row per rice (DISPLAY_NAME, then COMPOSITOR ·
# SHELL_NAME), the current rice marked active, an out-of-range index
# ignored, theme fallback.
# SHELL_NAME), a dot and the active mark on the current rice, an
# out-of-range index ignored, theme fallback.
set -euo pipefail

REPO="$(cd "$(dirname "$0")/.." && pwd)"
Expand Down Expand Up @@ -83,6 +83,8 @@ rices="$(find "$REPO/rices" -mindepth 1 -maxdepth 1 -type d | wc -l)"
[[ "$rows" -eq "$rices" ]] || fail "expected $rices rows, got $rows"
grep -qF '<span weight="600">end4</span>' "$TMP/rofi.stdin" || fail "end4 row has no plain title: $(cat "$TMP/rofi.stdin")"
grep -qF '>Hyprland · end4-pC Material 3</span>' "$TMP/rofi.stdin" || fail "end4 row has no subtitle"
[[ "$(grep -o 'alpha="80%">●' "$TMP/rofi.stdin" | wc -l)" -eq 1 ]] || fail "expected one visible dot, for the current rice"
grep -qF 'alpha="80%">● </span><span weight="600">end4</span>' "$TMP/rofi.stdin" || fail "the dot is not on the end4 row"
end4_index="$(find "$REPO/rices" -mindepth 1 -maxdepth 1 -type d -printf '%f\n' | LC_ALL=C sort | grep -nx end4 | cut -d: -f1)"
grep -A1 -x -- '-a' "$TMP/rofi.args" | tail -n1 | grep -qx "$((end4_index - 1))" || fail "current rice not marked active: $(cat "$TMP/rofi.args")"
grep -A1 -x -- '-theme' "$TMP/rofi.args" | tail -n1 | grep -q 'rice-switch.rasi$' || fail "rice-switch.rasi not used"
Expand Down
Loading