diff --git a/style.scss b/style.scss index e92e9e3..6db84a2 100644 --- a/style.scss +++ b/style.scss @@ -1,6 +1,7 @@ -// https://gitlab.gnome.org/GNOME/gtk/-/blob/gtk-3-24/gtk/theme/Adwaita/_colors-public.scss -$fg-color: #{"@theme_fg_color"}; -$bg-color: #{"@theme_bg_color"}; +@use "../../.cache/wal/colors.scss" as wal; + +$fg-color: wal.$foreground; +$bg-color: rgba(wal.$background, 0.8); window.Bar { background: transparent; @@ -23,6 +24,7 @@ window.Bar { button { border-radius: 8px; margin: 2px; + transition: all 0.2s ease-in-out; } .workspaces { @@ -34,8 +36,12 @@ window.Bar { background: transparent; &.active { - background: #{"@theme_selected_bg_color"}; - color: #{"@theme_selected_fg_color"}; + background: wal.$color2; + color: wal.$background; + } + + &:hover:not(.active) { + background: rgba(wal.$color2, 0.2); } } } @@ -49,6 +55,10 @@ window.Bar { padding: 0 8px; min-height: 24px; + &:hover { + background: rgba(wal.$foreground, 0.1); + } + .media-art { border-radius: 4px; -gtk-icon-size: 32px; @@ -56,7 +66,7 @@ window.Bar { } .system-tray { - background: rgba(150, 150, 150, 0.15); // Unified background for the tray + background: rgba(wal.$color8, 0.3); // Unified background for the tray border-radius: 8px; padding: 0 4px; // Reduced vertical padding margin: 2px; @@ -68,24 +78,120 @@ window.Bar { border: none; box-shadow: none; + &:hover { + background: rgba(wal.$foreground, 0.1); + border-radius: 6px; + } + image { -gtk-icon-size: 16px; } } } + .control-btn { + padding: 2px 8px; + min-height: 24px; + + &:hover { + background: rgba(wal.$foreground, 0.1); + } + + image { + -gtk-icon-size: 16px; + } + } + .controls-container { - .control-btn { - padding: 2px 8px; - min-height: 24px; - - image { - -gtk-icon-size: 16px; - } - } - .power-btn { - color: #ff5555; // Distinctive color for power button + color: wal.$color1; // Distinctive color for power button } } } + +.wallpaper-btn { + padding: 0; + border-radius: 8px; + background: transparent; + transition: all 0.2s ease-in-out; + + &:hover { + background: rgba(wal.$foreground, 0.1); + } + + picture { + border-radius: 8px; + } +} + +window.PowerMenu { + background: transparent; + + .power-menu-container { + background: $bg-color; + border-radius: 16px; + padding: 32px; + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5); + + .power-menu-btn { + padding: 24px; + border-radius: 12px; + background: transparent; + min-width: 120px; + transition: all 0.2s ease-in-out; + + &:hover { + background: rgba(wal.$foreground, 0.1); + } + + .power-menu-icon { + -gtk-icon-size: 48px; + } + + .power-menu-label { + font-size: 1.2em; + font-weight: bold; + } + } + } +} + +.quick-settings-menu { + padding: 12px; + min-width: 280px; + + .qs-title { + font-weight: bold; + font-size: 1.1em; + margin-bottom: 4px; + color: wal.$foreground; + opacity: 0.8; + } + + .qs-item { + background: rgba(150, 150, 150, 0.1); + border-radius: 8px; + padding: 8px 12px; + + .qs-icon { + -gtk-icon-size: 20px; + } + + .qs-icon-btn { + background: transparent; + border: none; + box-shadow: none; + padding: 4px; + border-radius: 100%; + transition: all 0.2s ease-in-out; + + &:hover { + background: rgba(wal.$foreground, 0.1); + } + } + } + + slider { + transition: all 0.2s ease-in-out; + } +} diff --git a/theme.ts b/theme.ts new file mode 100644 index 0000000..b90b85c --- /dev/null +++ b/theme.ts @@ -0,0 +1,105 @@ +import app from "ags/gtk4/app" +import { execAsync } from "ags/process" +import GLib from "gi://GLib?version=2.0" +import Gio from "gi://Gio?version=2.0" + +const HOME = GLib.getenv("HOME") || "" +const WALLPAPER_DIR = `${HOME}/wallpapers` + +/** + * Get a list of all wallpapers in the default wallpapers directory. + */ +export async function getWallpapers(): Promise { + try { + const dir = Gio.File.new_for_path(WALLPAPER_DIR) + const iter = dir.enumerate_children( + "standard::name", + Gio.FileQueryInfoFlags.NONE, + null, + ) + let info + const files: string[] = [] + while ((info = iter.next_file(null))) { + const name = info.get_name() + if (name.match(/\.(jpg|jpeg|png|gif)$/i)) { + files.push(`${WALLPAPER_DIR}/${name}`) + } + } + files.sort() + return files + } catch (error) { + console.error("Failed to read wallpapers directory:", error) + return [] + } +} + +/** + * Restore the last set wallpaper. + */ +export async function restoreTheme() { + try { + const out = await execAsync(["cat", `${HOME}/.cache/wal/wal`]) + const wallpaperPath = out.trim() + if (wallpaperPath) { + console.log(`Restoring theme for wallpaper: ${wallpaperPath}`) + await setTheme(wallpaperPath) + } + } catch { + console.log("No previous wallpaper found to restore.") + } +} + +/** + * Set the wallpaper using hyprpaper, generate colors with pywal, + * and reload the AGS theme. + */ +export async function setTheme(wallpaperPath: string) { + console.log(`Setting theme for wallpaper: ${wallpaperPath}`) + + // 1. Set wallpaper with hyprpaper + try { + // Preload the wallpaper first + await execAsync(["hyprctl", "hyprpaper", "preload", wallpaperPath]).catch( + () => {}, + ) + + const out = await execAsync("hyprctl monitors -j") + const monitors = JSON.parse(out) + for (const mon of monitors) { + await execAsync([ + "hyprctl", + "hyprpaper", + "wallpaper", + `${mon.name},${wallpaperPath}`, + ]) + } + } catch (error) { + console.error("Failed to set wallpaper via hyprpaper:", error) + } + + // 2. Generate colors with pywal16 + try { + // -q: quiet, -i: image, -n: skip setting wallpaper (hyprpaper does it) + await execAsync(`wal -q -n -i "${wallpaperPath}"`) + } catch (error) { + console.error("Failed to generate colors with pywal:", error) + } + + // 3. Re-compile and apply AGS styles + try { + const agsDir = `${HOME}/.config/ags` + const scss = `${agsDir}/style.scss` + const css = `/tmp/ags-compiled-style.css` + + // Compile SCSS to CSS using the sass CLI + await execAsync(`sass ${scss} ${css}`) + + // Reset any previously applied CSS and apply the new one + app.reset_css() + app.apply_css(css) + + console.log("AGS theme successfully updated!") + } catch (error) { + console.error("Failed to recompile and apply AGS styles:", error) + } +} diff --git a/widget/Bar.tsx b/widget/Bar.tsx index 9934f3e..a44fda1 100644 --- a/widget/Bar.tsx +++ b/widget/Bar.tsx @@ -4,6 +4,7 @@ import Workspaces from "./Workspaces" import { Clock, SysTray } from "./System" import Media from "./Media" import Controls from "./Controls" +import ThemeSwitcher from "./ThemeSwitcher" function Left() { return ( @@ -27,7 +28,7 @@ function Center() { ) } -function Right() { +function Right({ gdkmonitor }: { gdkmonitor: Gdk.Monitor }) { return ( + - + ) } @@ -47,7 +49,7 @@ export default function Bar(gdkmonitor: Gdk.Monitor) { return (
- + ) diff --git a/widget/Controls.tsx b/widget/Controls.tsx index 26df74c..0c22c8f 100644 --- a/widget/Controls.tsx +++ b/widget/Controls.tsx @@ -1,32 +1,29 @@ import { Gtk } from "ags/gtk4" +import app from "ags/gtk4/app" +import QuickSettings from "./QuickSettings" -export function SettingsButton() { - return ( - - ) -} - -export function PowerButton() { +export function PowerButton({ gdkmonitor }: { gdkmonitor: any }) { return ( ) } -export default function Controls() { +export default function Controls({ gdkmonitor }: { gdkmonitor: any }) { return ( - - - + + + ) } diff --git a/widget/Media.tsx b/widget/Media.tsx index fc99a96..58dc37b 100644 --- a/widget/Media.tsx +++ b/widget/Media.tsx @@ -4,6 +4,7 @@ import { createBinding, With, onCleanup } from "ags" export default function Media() { const mpris = AstalMpris.Mpris.get_default() + let lastPlaying: string | null = null return ( @@ -18,31 +19,24 @@ export default function Media() { { const updateVisibility = () => { - let hasPlaying = false - for (const player of players) { - if ( - player.playback_status === - AstalMpris.PlaybackStatus.PLAYING - ) { - hasPlaying = true - break - } + const activePlayer = players.find( + (p) => + p.playback_status === AstalMpris.PlaybackStatus.PLAYING, + ) + + if (activePlayer) { + lastPlaying = activePlayer.bus_name } - let first = true + const targetPlayer = + activePlayer || + players.find((p) => p.bus_name === lastPlaying) || + players[0] + let child = box.get_first_child() for (const player of players) { if (!child) break - - if (hasPlaying) { - child.set_visible( - player.playback_status === - AstalMpris.PlaybackStatus.PLAYING, - ) - } else { - child.set_visible(first) - first = false - } + child.set_visible(player === targetPlayer) child = child.get_next_sibling() } } @@ -58,35 +52,98 @@ export default function Media() { players.forEach((p, i) => { try { p.disconnect(connections[i]) - } catch (e) {} + } catch {} }) }) }} > - {players.map((player) => ( - - ))} + {players.map((player) => { + const playbackIcon = createBinding( + player, + "playback-status", + )((s: any) => + s === AstalMpris.PlaybackStatus.PLAYING + ? "media-playback-pause-symbolic" + : "media-playback-start-symbolic", + ) + + return ( + + + {/* Fallback to an icon if cover-art is empty */} + + + + + + + + + + + + + + + + + + ) + })} ) }} diff --git a/widget/System.tsx b/widget/System.tsx index 145ed8c..27c2f82 100644 --- a/widget/System.tsx +++ b/widget/System.tsx @@ -19,7 +19,9 @@ export function Clock() { ) diff --git a/widget/Workspaces.tsx b/widget/Workspaces.tsx index c345610..3dbdafc 100644 --- a/widget/Workspaces.tsx +++ b/widget/Workspaces.tsx @@ -1,4 +1,3 @@ -import { Gtk } from "ags/gtk4" import { execAsync } from "ags/process" import { createPoll } from "ags/time"