From 4aa99210a8073c735073155f83e63b18abea187e Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Sat, 27 Jul 2024 23:18:05 +0545 Subject: [PATCH] updates --- config/ags/.prettierrc | 1 + config/ags/apps/settings/network.ts | 7 +- config/ags/main.ts | 8 +- config/ags/modules/bar.ts | 132 ++++++----------- config/ags/modules/cheatsheet.ts | 11 +- config/ags/modules/notificationPopups.ts | 2 +- config/ags/modules/popups.ts | 158 +++++++++++++++++++++ config/ags/modules/sideleft/applauncher.ts | 2 +- config/ags/modules/sideleft/cliphist.ts | 98 +++++++++---- config/ags/modules/sideleft/main.ts | 7 + config/ags/modules/sideright/system.ts | 38 ++--- config/ags/scripts/backlight.sh | 88 ------------ config/ags/scripts/cliphist.sh | 27 +++- config/ags/scripts/dark-theme.sh | 11 +- config/ags/scripts/system.sh | 10 +- config/ags/services/backlight.ts | 52 +++++++ config/ags/services/battery_warning.ts | 35 +++++ config/ags/style.css | 157 ++++++++++++-------- config/ags/variables.ts | 15 +- 19 files changed, 537 insertions(+), 322 deletions(-) create mode 100644 config/ags/modules/popups.ts delete mode 100755 config/ags/scripts/backlight.sh create mode 100644 config/ags/services/backlight.ts create mode 100644 config/ags/services/battery_warning.ts diff --git a/config/ags/.prettierrc b/config/ags/.prettierrc index d4b187fb..a300ade4 100644 --- a/config/ags/.prettierrc +++ b/config/ags/.prettierrc @@ -9,3 +9,4 @@ "endOfLine": "auto", "printWidth": 120 } + \ No newline at end of file diff --git a/config/ags/apps/settings/network.ts b/config/ags/apps/settings/network.ts index 3fc96608..e1fd8e2f 100644 --- a/config/ags/apps/settings/network.ts +++ b/config/ags/apps/settings/network.ts @@ -54,9 +54,12 @@ const saved_networks: VariableType = Variable([], { }); function WifiScan() { - network.wifi.scan(); + try { + network.wifi?.scan(); + } catch (error) { + print(error) + } // await Utils.execAsync("nmcli device wifi rescan").catch(print) - return undefined; } const WifiNetwork = (access_point: AccessPoint) => { diff --git a/config/ags/main.ts b/config/ags/main.ts index df2c7410..3ee3e343 100644 --- a/config/ags/main.ts +++ b/config/ags/main.ts @@ -10,6 +10,8 @@ import {} from "apps/settings/main.ts"; import {} from "apps/emoji/main.ts"; import { cheatsheet } from "modules/cheatsheet.ts"; import Window from "types/widgets/window"; +import { popups } from "modules/popups.ts"; +import { start_battery_warning_service } from "services/battery_warning.ts"; const GLib = imports.gi.GLib; const range = (length: number, start = 1) => Array.from({ length }, (_, i) => i + start); @@ -27,8 +29,8 @@ const Windows = () => [ forMonitors(BarCornerTopLeft), forMonitors(BarCornerTopRight), sideright, - cheatsheet, - sideleft + sideleft, + forMonitors(popups) ]; const CLOSE_ANIM_TIME = 210; @@ -64,3 +66,5 @@ Utils.monitorFile(`${GLib.get_home_dir()}/.cache/material/colors.json`, ReloadCS Utils.monitorFile(`${GLib.get_home_dir()}/.config/gtk-3.0/gtk.css`, ReloadGtkCSS); forMonitorsAsync(Bar); ReloadGtkCSS(); + +start_battery_warning_service() diff --git a/config/ags/modules/bar.ts b/config/ags/modules/bar.ts index cd41410e..2e6175a2 100644 --- a/config/ags/modules/bar.ts +++ b/config/ags/modules/bar.ts @@ -20,6 +20,7 @@ import { MaterialIcon } from "icons.js"; import config from "services/configuration.ts"; import { toggleAppsWindow, toggleMediaWindow } from "./sideleft/main.js"; + function checkKeymap() { const layout = Utils.execAsync(`hyprctl devices -j | jq -r '.keyboards[] | select(.main == true) | .active_keymap' | tail -n1 | cut -c1-2 | tr 'A-Z' 'a-z'`) .then(out => { return out }) @@ -94,99 +95,44 @@ function getIconNameFromClass(windowClass: string) { const dispatch = (ws: string) => hyprland.messageAsync(`dispatch workspace ${ws}`).catch(print); function Workspaces() { - return EventBox({ + const activeId = hyprland.active.workspace.bind("id"); + let workspaceButtons = new Map(); + + function createWorkspaceButton(id: Number) { + const button = Widget.Button({ + on_clicked: () => dispatch(`${id}`), + child: Widget.Label(`${id}`), + class_name: activeId.as((i) => `${i === id ? "active" : ""}`) + }); + return button; + } + + function updateWorkspaceButtons(workspaces: Workspace[]): Array> { + workspaces.sort((a, b) => a.id - b.id); + + const updatedButtons = new Map(); + + workspaces.forEach(({ id }) => { + if (workspaceButtons.has(id)) { + updatedButtons.set(id, workspaceButtons.get(id)); + } else { + updatedButtons.set(id, createWorkspaceButton(id)); + } + }); + if (workspaceButtons != updatedButtons) workspaceButtons = updatedButtons; + + return Array.from(workspaceButtons.values()); + } + + const workspaceButtonsArray = hyprland.bind("workspaces").as(updateWorkspaceButtons); + + return Widget.EventBox({ onScrollUp: () => dispatch("+1"), onScrollDown: () => dispatch("-1"), - className: "workspaces", - child: Box({ - className: "outer-workspace", - children: Array.from({ length: 9 }, (_, i) => i + 1).map( - (i, index, array) => - Box({ - attribute: i, - className: - index === 0 - ? "workspace first" - : index === array.length - 1 - ? "workspace last" - : "workspace", - }) - ), - }).hook(hyprland, (self) => { - let previousWorkspace = {}; - previousWorkspace.className = ""; - self.children.forEach((box, index, array) => { - const isActive = hyprland.active.workspace.id === box.attribute; - const isOccupied = hyprland.workspaces.some( - (item) => item.id === box.attribute - ); - let buttonClassName; - if (isActive) { - buttonClassName = "focused"; - box.className = "workspace focused"; - } else if (isOccupied) { - buttonClassName = "occupied"; - box.className = "workspace occupied"; - } else { - buttonClassName = "normal"; - box.className = "workspace normal"; - } - - if (isOccupied || isActive) { - if (index === 0) box.toggleClassName("occupied-start", true); - else if ( - index === 8 && - previousWorkspace.className.indexOf("occupied-start") === -1 - ) - box.toggleClassName("occupied-single", true); - else if ( - index === 8 && - previousWorkspace.className.indexOf("occupied-middle") === -1 - ) - box.toggleClassName("occupied-end", true); - else if ( - previousWorkspace.className.indexOf("occupied-start") !== -1 - ) { - box.toggleClassName("occupied-end", true); - } else if ( - previousWorkspace.className.indexOf("occupied-end") !== -1 - ) { - previousWorkspace.toggleClassName("occupied-middle", true); - previousWorkspace.toggleClassName("occupied-end", false); - box.toggleClassName("occupied-end", true); - } else { - box.toggleClassName("occupied-start", true); - } - } else { - if (previousWorkspace.className.indexOf("occupied-start") !== -1) { - previousWorkspace.toggleClassName("occupied-start", false); - previousWorkspace.toggleClassName("occupied-single", true); - } - } - - if (index === 0) { - box.toggleClassName("first", true); - } else if (index === array.length - 1) { - box.toggleClassName("last", true); - } - - box.child = Button({ - className: buttonClassName, - label: isActive ? `•` : box.attribute.toString(), - onClicked: () => dispatch(box.attribute), - setup: (self) => { - if (index === 0) { - self.toggleClassName("first", true); - } else if (index === array.length - 1) { - self.toggleClassName("last", true); - } - }, - }); - - // Pass current workspace attributes as previousWorkspace - previousWorkspace = box; - }); - }), + child: Widget.Box({ + children: workspaceButtonsArray, + class_name: "workspaces" + }) }); } @@ -263,6 +209,7 @@ function BatteryLabel() { self.hook(battery, () => { self.children[0].label = getClosestBatteryLevel(battery.percent, battery.charging); self.visible = (battery.percent < 100 && battery.available) || config.config.always_show_battery; + self.toggleClassName("critical", battery.percent < 15); }); self.hook(config, () => { if (config.config.always_show_battery) { @@ -275,6 +222,7 @@ function BatteryLabel() { }); } + function SysTray() { return Widget.Box({ class_name: "tray", @@ -562,7 +510,7 @@ function Right() { class_name: "modules-right", hpack: "end", spacing: 8, - children: [volumeIndicator(), KeyboardLayout(), BatteryLabel(), SysTray(), Applets(), Clock(), OpenSideBar()] + children: [/*Recorder,*/ volumeIndicator(), KeyboardLayout(), BatteryLabel(), SysTray(), Applets(), Clock(), OpenSideBar()] }); } diff --git a/config/ags/modules/cheatsheet.ts b/config/ags/modules/cheatsheet.ts index dc03e19a..5f4e1fc5 100644 --- a/config/ags/modules/cheatsheet.ts +++ b/config/ags/modules/cheatsheet.ts @@ -23,15 +23,20 @@ const icons = { $mainmod: "" }; +const replace = { + slash: "/", + period: ".", + escape: "Esc" +}; + const category_icons = { actions: "accessibility_new", applications: "apps", windows: "select_window", workspaces: "overview_key", misc: "construction", - plugins: "extension" + tools: "build" }; - const CheatSheet = () => Widget.FlowBox({ attribute: { @@ -90,7 +95,7 @@ const CheatSheet = () => else key_box.pack_start( Widget.Label({ - label: key.charAt(0).toUpperCase() + key.slice(1), + label: replace[key.toLowerCase()] || key.charAt(0).toUpperCase() + key.slice(1), class_name: "key", hpack: "start", vpack: "center" diff --git a/config/ags/modules/notificationPopups.ts b/config/ags/modules/notificationPopups.ts index 729ba877..25d23499 100644 --- a/config/ags/modules/notificationPopups.ts +++ b/config/ags/modules/notificationPopups.ts @@ -73,7 +73,7 @@ export const Notification = (notification: NotificationType, dismiss = true) => }), Widget.Label({ class_name: "notification-time", - label: GLib.DateTime.new_from_unix_local(notification.time).format("%H:%M") + label: GLib.DateTime.new_from_unix_local(notification.time).format("%I:%M %P") }), Widget.Button({ class_name: "standard_icon_button notification-close", diff --git a/config/ags/modules/popups.ts b/config/ags/modules/popups.ts new file mode 100644 index 00000000..c7c28454 --- /dev/null +++ b/config/ags/modules/popups.ts @@ -0,0 +1,158 @@ +const audio = await Service.import("audio"); +import backlight_service from "services/backlight.ts"; +import { MaterialIcon } from "icons.ts"; +import Gtk from "types/@girs/gtk-3.0/gtk-3.0"; +import Revealer from "types/widgets/revealer"; +import Box from "types/widgets/box"; +import Slider from "types/widgets/slider"; +import { Binding } from "types/service"; + +const brightnessIcons = [ + "brightness_1", + "brightness_2", + "brightness_3", + "brightness_4", + "brightness_5", + "brightness_6", + "brightness_7" +]; + +function getBrightnessIcon(brightness: number): string { + const totalIcons = brightnessIcons.length; + const maxBrightness = 1; + const ratio = 1.6; + + let thresholds: number[] = []; + for (let i = 0; i < totalIcons; i++) { + const threshold = maxBrightness / Math.pow(ratio, totalIcons - i - 1); + thresholds.push(threshold); + } + + for (let i = 0; i < totalIcons; i++) { + if (brightness < thresholds[i]) { + return brightnessIcons[i]; + } + } + + return brightnessIcons[totalIcons - 1]; +} + +type popup_on_change = ((self: Slider) => void) | undefined; +type popup_setup = + | (( + self: Revealer< + Box, unknown>, + { + count: number; + } + > + ) => void) + | undefined; + +const default_popup = ( + icon: Gtk.Widget, + value: number | Binding, + on_change?: popup_on_change, + setup?: popup_setup +) => + Widget.Revealer({ + transition_duration: 200, + transition: "slide_up", + child: Widget.Revealer({ + reveal_child: false, + transition_duration: 190, + transition: "crossfade", + child: Widget.Box({ + class_name: "popup", + children: [ + icon, + Widget.Slider({ + min: 0, + max: 100, + draw_value: false, + class_name: "popup_slider", + value: value, + on_change: on_change + }) + ] + }), + attribute: { count: 0 }, + setup: setup + }), + setup: (self) => { + self.child.connect("notify::child-revealed", () => { + self.reveal_child = self.child.child_revealed; + }); + self.child.connect("notify::reveal-child", () => { + if (self.child.reveal_child) self.reveal_child = true; + }); + } + }); + +const backlight_popup = () => + default_popup( + MaterialIcon("brightness_1").hook(backlight_service, (self) => { + self.label = getBrightnessIcon(backlight_service.screen_value); + }), + backlight_service.bind("screen_value").as((n) => n * 100), + (self) => { + backlight_service.screen_value = self.value / 100; + }, + (self) => { + backlight_service.connect("screen-changed", (_) => { + self.attribute.count++; + if (self.attribute.count > 0) self.reveal_child = true; + Utils.timeout(1500, () => { + self.attribute.count--; + if (self.attribute.count <= 0) self.reveal_child = false; + }); + }); + } + ); + +const volume_popup = () => + default_popup( + MaterialIcon("volume_off", "20px").hook(audio.speaker, (self) => { + const vol = audio.speaker.volume * 100; + const icon = [ + [101, "sound_detection_loud_sound"], + [67, "volume_up"], + [34, "volume_down"], + [1, "volume_mute"], + [0, "volume_off"] + ].find(([threshold]) => Number(threshold) <= vol)?.[1]; + if (audio.speaker.is_muted) self.label = "volume_off"; + else self.label = String(icon!); + }), + audio.speaker.bind("volume").as((volume) => Math.floor(volume * 100)), + (self) => { + audio.speaker.volume = self.value / 100; + }, + (self) => { + audio.speaker.connect("notify::volume", (_) => { + self.attribute.count++; + if (self.attribute.count > 0) self.reveal_child = true; + Utils.timeout(1500, () => { + self.attribute.count--; + if (self.attribute.count <= 0) self.reveal_child = false; + }); + }); + } + ); + +export const popups = (monitor = 0) => { + const _volume_popup = volume_popup(); + const _backlight_popup = backlight_popup(); + return Widget.Window({ + monitor, + name: `popups${monitor}`, + child: Widget.Box({ + css: "min-height: 1px; min-width: 1px;", + vertical: true, + children: [_backlight_popup, _volume_popup] + }), + class_name: "popups", + anchor: ["bottom"], + visible: true + }); +}; diff --git a/config/ags/modules/sideleft/applauncher.ts b/config/ags/modules/sideleft/applauncher.ts index 454d5624..9e0577d7 100644 --- a/config/ags/modules/sideleft/applauncher.ts +++ b/config/ags/modules/sideleft/applauncher.ts @@ -75,7 +75,7 @@ function AppItem(app: Application): Box { button.connect("clicked", () => { clickCount++; - if (clickCount === 1) { + if (clickCount === 2) { incrementLaunchCount(app.name); App.closeWindow(WINDOW_NAME); app.launch(); diff --git a/config/ags/modules/sideleft/cliphist.ts b/config/ags/modules/sideleft/cliphist.ts index 8437cb60..2ac575d4 100644 --- a/config/ags/modules/sideleft/cliphist.ts +++ b/config/ags/modules/sideleft/cliphist.ts @@ -4,6 +4,7 @@ const GLib = imports.gi.GLib; import Box from "types/widgets/box"; import { WINDOW_NAME } from "modules/sideleft/main"; +// Function to get clipboard history async function getClipboardHistory() { try { const process = new Gio.Subprocess({ @@ -21,6 +22,7 @@ async function getClipboardHistory() { } } +// Function to clear clipboard history async function clearClipboardHistory() { try { const process = new Gio.Subprocess({ @@ -35,32 +37,46 @@ async function clearClipboardHistory() { } } +// Function to show image preview +async function showImagePreview(id, format, width, height) { + try { + const file = await Utils.execAsync(`${App.configDir}/scripts/cliphist.sh --save-by-id ${id}`); + const _widthPx = Number(width); + const heightPx = Number(height); + const maxWidth = 400; + const widthPx = (_widthPx / heightPx) * 150; + + let css = `background-image: url("${file}");`; + + if (widthPx > maxWidth) { + const newHeightPx = (150 / widthPx) * maxWidth; + css += `min-height: ${newHeightPx}px; min-width: ${maxWidth}px;`; + } else { + css += `min-height: 150px; min-width: ${widthPx}px;`; + } + + return css; + } catch (error) { + // Handle error silently or log to a file if needed + return ''; + } +} + +// Function to create a clipboard history item function ClipHistItem(entry) { - const [id, ...content] = entry.split("\t"); + const [id, ..._content] = entry.split("\t"); + const content = _content.join(" ").trim(); + const matches = content.match(/\[\[ binary data (\d+) (KiB|MiB) (\w+) (\d+)x(\d+) \]\]/); + let _show_image = false; + let clickCount = 0; const button = Widget.Button({ class_name: "clip_container", child: Widget.Box({ children: [ - Widget.Label({ - label: id, - class_name: "clip_id", - xalign: 0, - vpack: "center" - }), - Widget.Label({ - label: "・", - class_name: "dot_divider", - xalign: 0, - vpack: "center" - }), - Widget.Label({ - label: content.join(" ").trim(), - class_name: "clip_label", - xalign: 0, - vpack: "center", - truncate: "end" - }) + Widget.Label({ label: id, class_name: "clip_id", xalign: 0, vpack: "center" }), + Widget.Label({ label: "・", class_name: "dot_divider", xalign: 0, vpack: "center" }), + Widget.Label({ label: content, class_name: "clip_label", xalign: 0, vpack: "center", truncate: "end" }) ] }) }); @@ -68,9 +84,9 @@ function ClipHistItem(entry) { button.connect("clicked", async () => { try { clickCount++; - if (clickCount === 1) { + if (clickCount === 2) { App.closeWindow(WINDOW_NAME); - Utils.execAsync(`${App.configDir}/scripts/cliphist.sh --copy-by-id ${id}`); + await Utils.execAsync(`${App.configDir}/scripts/cliphist.sh --copy-by-id ${id}`); clickCount = 0; } } catch (error) { @@ -82,8 +98,32 @@ function ClipHistItem(entry) { clickCount = 0; }); + if (matches) { + const format = matches[3]; + const width = matches[4]; + const height = matches[5]; + if (format === "png") { + button.toggleClassName("with_image", true); + button.connect("clicked", async () => { + if (!_show_image) { + const css = await showImagePreview(id, format, width, height); + const box = button.child; + box.children[2].destroy(); // Remove text label + const icon = Widget.Box({ + vpack: "center", + css: css, + class_name: "preview" + }); + // @ts-expect-error + box.children = [...box.children, icon]; + _show_image = true; + } + }); + } + } + return Widget.Box({ - attribute: { content: content.join(" ").trim() }, + attribute: { content: content }, orientation: Gtk.Orientation.VERTICAL, children: [ button, @@ -95,6 +135,7 @@ function ClipHistItem(entry) { }); } +// Main export function for clipboard history widget export const cliphist = () => { const list = Widget.Box({ vertical: true, vexpand: true }); const loadingIndicator = Widget.Label({ @@ -111,13 +152,11 @@ export const cliphist = () => { if (entries.length > 0) { list.children = entries.map(ClipHistItem); } - } catch (error) { - list.children = [Widget.Label ({ + list.children = [Widget.Label({ label: "Error loading history", class_name: "error_loading" - }) - ]; + })]; } } @@ -146,10 +185,7 @@ export const cliphist = () => { const searchBox = Widget.Box({ orientation: Gtk.Orientation.HORIZONTAL, - children: [ - entry, - clearButton - ] + children: [entry, clearButton] }); return Widget.Box({ diff --git a/config/ags/modules/sideleft/main.ts b/config/ags/modules/sideleft/main.ts index e4a24659..8d381964 100644 --- a/config/ags/modules/sideleft/main.ts +++ b/config/ags/modules/sideleft/main.ts @@ -30,8 +30,15 @@ export function toggleClipsWindow() { shown.setValue("clips"); } } +export function toggleChatsWindow() { + if (shown.value == "gemini" && sideleft.visible) App.closeWindow(WINDOW_NAME); else { + App.openWindow(WINDOW_NAME); + shown.setValue("gemini"); + } +} globalThis.toggleClipsWindow = toggleClipsWindow; +globalThis.toggleChatsWindow = toggleChatsWindow; globalThis.toggleMediaWindow = toggleMediaWindow; globalThis.toggleAppsWindow = toggleAppsWindow; diff --git a/config/ags/modules/sideright/system.ts b/config/ags/modules/sideright/system.ts index a7a17d1d..3797fa58 100644 --- a/config/ags/modules/sideright/system.ts +++ b/config/ags/modules/sideright/system.ts @@ -1,6 +1,15 @@ -import { cpu_cores, cpu_name, kernel_name, amount_of_ram, gpu_name, cur_uptime } from "variables"; +import { + cpu_cores, + cpu_name, + kernel_name, + amount_of_ram, + gpu_name, + cur_uptime, + current_brightness +} from "variables.ts"; import Gtk from "gi://Gtk?version=3.0"; import { Variable as VariableType } from "types/variable"; +import backlight_service from "services/backlight.ts"; type InfoType = { cpu: string; @@ -60,28 +69,6 @@ const usage = Variable( } ); -function checkBacklight() { - const get = Utils.execAsync(`${App.configDir}/scripts/backlight.sh --get`) - .then((out) => Number(out.trim())) - .catch(print); - return get; -} - -function checkBrightness() { - const get = Utils.execAsync(`${App.configDir}/scripts/brightness.sh --get`) - .then((out) => Number(out.trim())) - .catch(print); - return get; -} - -const current_backlight = Variable(100, { - poll: [500, checkBacklight] -}); - -const current_brightness = Variable(100, { - poll: [500, checkBrightness] -}); - const Usage = (name: string, var_name: keyof InfoType, class_name: string | undefined) => { const usage_progress_bar = Widget.ProgressBar({ class_name: "usage_bar", @@ -145,10 +132,9 @@ export function SystemBox() { draw_value: false, class_name: "system_scale backlight", // @ts-ignore - value: current_backlight.bind(), + value: backlight_service.bind("screen_value").as(n => n * 100), on_change: (self) => { - current_backlight.setValue(Number(self.value)); - Utils.execAsync(`${App.configDir}/scripts/backlight.sh --smooth ${self.value}`).catch(print); + backlight_service.screen_value = self.value / 100; }, tooltip_markup: "Backlight" }); diff --git a/config/ags/scripts/backlight.sh b/config/ags/scripts/backlight.sh deleted file mode 100755 index c9846b5e..00000000 --- a/config/ags/scripts/backlight.sh +++ /dev/null @@ -1,88 +0,0 @@ -#!/bin/bash -LOCKFILE=/tmp/smooth_backlight.lock -BRIGHTNESS=/tmp/set_backlight -smooth() { - if [ -n "$1" ]; then - rounded_value=$(echo "scale=0; $1/1" | bc) - echo $rounded_value > $BRIGHTNESS - else - echo "Not enough arguments" - exit 1 - fi - - if [ -e "$LOCKFILE" ] && kill -0 "$(cat $LOCKFILE)"; then - echo "locked" - exit 0 - fi - - trap "rm -f $LOCKFILE; exit" INT TERM EXIT - echo $$ > "$LOCKFILE" - - smooth_brightness() { - local max_brightness=$(brightnessctl m) - local step=$((max_brightness / 100)) - - while true; do - local target_brightness=$(cat $BRIGHTNESS) - local current_brightness=$(brightnessctl g) - target_brightness=$(echo "$max_brightness * $target_brightness / 100" | bc) - - if [ $current_brightness -eq $target_brightness ]; then - exit 0 - fi - while [ $current_brightness -ne $target_brightness ]; do - if [ $current_brightness -lt $target_brightness ]; then - current_brightness=$((current_brightness + step)) - else - current_brightness=$((current_brightness - step)) - fi - - brightnessctl s $current_brightness > /dev/null 2>&1 - sleep 0.001 - - local new_target_brightness=$(cat $BRIGHTNESS) - new_target_brightness=$(echo "$max_brightness * $new_target_brightness / 100" | bc) - if [ $new_target_brightness -ne $target_brightness ]; then - target_brightness=$new_target_brightness - break - fi - done - - done - } - - smooth_brightness - - rm -f "$LOCKFILE" - trap - INT TERM EXIT -} - -set() { - if [ -n "$1" ]; then - brightnessctl s $1 - else - echo "Not enough arguments" - exit 1 - fi -} - -get() { - if [ -e "$LOCKFILE" ] && kill -0 "$(cat $LOCKFILE)"; then - local target_brightness=$(cat $BRIGHTNESS) - echo $target_brightness - exit 0 - fi - brightness=$(brightnessctl g) - max_brightness=$(brightnessctl m) - percentage=$((100 * brightness / max_brightness)) - - echo "$percentage" -} - -if [[ "$1" == "--smooth" ]]; then - smooth $2 - elif [[ "$1" == "--set" ]]; then - set $2 - elif [[ "$1" == "--get" ]]; then - get -fi diff --git a/config/ags/scripts/cliphist.sh b/config/ags/scripts/cliphist.sh index 79ee6613..601e0590 100755 --- a/config/ags/scripts/cliphist.sh +++ b/config/ags/scripts/cliphist.sh @@ -1,11 +1,7 @@ #!/bin/bash get() { - clip_list=$(cliphist list) - - while IFS= read -r line; do - echo "$line" | iconv -t UTF-8 - done <<<"$clip_list" + cliphist list | iconv -f ISO-8859-1 -t UTF-8 -c } copy_by_id() { @@ -13,8 +9,29 @@ copy_by_id() { cliphist decode $id | wl-copy } +save_cache_file() { + id=$1 + + output_file="/tmp/ags/cliphist/$id.png" + + if [[ ! -f "$output_file" ]]; then + mkdir -p "/tmp/ags/cliphist/" + cliphist decode "$id" >"$output_file" + fi + + echo $output_file +} + +clear_tmp() { + rm "/tmp/ags/cliphist/*" +} + if [[ "$1" == "--get" ]]; then get elif [[ "$1" == "--copy-by-id" ]]; then { copy_by_id "$2"; } +elif [[ "$1" == "--save-by-id" ]]; then + { save_cache_file "$2"; } +elif [[ "$1" == "--clear-cache" ]]; then + clear_tmp fi diff --git a/config/ags/scripts/dark-theme.sh b/config/ags/scripts/dark-theme.sh index f273b132..c8de00ff 100755 --- a/config/ags/scripts/dark-theme.sh +++ b/config/ags/scripts/dark-theme.sh @@ -9,11 +9,11 @@ toggle() { if [ "$VALUE" == "dark" ]; then python -O $GENERATOR -R --color-scheme light --scheme $GENERATION_SCHEME - echo "light" > $FILE - + echo "light" >$FILE + elif [ "$VALUE" == "light" ]; then python -O $GENERATOR -R --color-scheme dark --scheme $GENERATION_SCHEME - echo "dark" > $FILE + echo "dark" >$FILE else echo "Unknown value: $VALUE" fi @@ -21,12 +21,11 @@ toggle() { set() { python -O $GENERATOR -R --color-scheme $1 --scheme $GENERATION_SCHEME - echo $1 > $FILE + echo $1 >$FILE } if [[ "$1" == "--toggle" ]]; then toggle - elif [[ "$1" == "--set" ]]; then +elif [[ "$1" == "--set" ]]; then set $2 fi - diff --git a/config/ags/scripts/system.sh b/config/ags/scripts/system.sh index 5d4c4529..e1bc7c97 100755 --- a/config/ags/scripts/system.sh +++ b/config/ags/scripts/system.sh @@ -42,7 +42,15 @@ get_os() { } get_uptime() { - uptime -p | sed -e 's/up //' -e 's/ hours\{0,1\}/h/g' -e 's/ minutes\{0,1\}/min/g' -e 's/ days\{0,1\}/d/g' -e 's/ seconds\{0,1\}/sec/g' -e 's/ //g' -e 's/,/, /' + uptime -p | sed -e 's/up //' \ + -e 's/ hours\{0,1\}/h/g' \ + -e 's/ minutes\{0,1\}/min/g' \ + -e 's/ days\{0,1\}/d/g' \ + -e 's/ seconds\{0,1\}/sec/g' \ + -e 's/,/, /g' \ + -e 's/ */ /g' \ + -e 's/^ //g' \ + -e 's/ $//g' } if [[ "$1" == "--cpu-usage" ]]; then diff --git a/config/ags/services/backlight.ts b/config/ags/services/backlight.ts new file mode 100644 index 00000000..c2568f97 --- /dev/null +++ b/config/ags/services/backlight.ts @@ -0,0 +1,52 @@ +class BrightnessService extends Service { + static { + Service.register( + this, + { + "screen-changed": ["float"] + }, + { + "screen-value": ["float", "rw"] + } + ); + } + + #interface = Utils.exec("sh -c 'ls -w1 /sys/class/backlight | head -1'"); + + #screenValue = 0; + #max = Number(Utils.exec("brightnessctl max")); + #brightness_file = `/sys/class/backlight/${this.#interface}/brightness`; + + get screen_value() { + return this.#screenValue; + } + + set screen_value(percent) { + if (percent < 0) percent = 0; + + if (percent > 1) percent = 1; + + Utils.execAsync(`brightnessctl set ${percent * 100}% -q`); + } + + constructor() { + super(); + + Utils.monitorFile(this.#brightness_file, () => this.#onChange()); + + this.#onChange(); + } + + async #onChange() { + this.#screenValue = Number(await Utils.readFileAsync(this.#brightness_file)) / this.#max; + + this.emit("changed"); + this.notify("screen-value"); + + this.emit("screen-changed", this.#screenValue); + } +} + +const service = new BrightnessService(); + +export default service; diff --git a/config/ags/services/battery_warning.ts b/config/ags/services/battery_warning.ts new file mode 100644 index 00000000..4011074a --- /dev/null +++ b/config/ags/services/battery_warning.ts @@ -0,0 +1,35 @@ +const battery = await Service.import("battery"); + +const battery_messages = { + warnLevels: [15, 5], + warnTitles: ["Low battery", "Very low battery"], + warnMessages: ["Plug in the charger", "You there?"] +}; + +let battery_warned = false; + +async function battery_notification() { + const percent = battery.percent; + const charging = battery.charging; + if (charging) { + battery_warned = false; + return; + } + for (let i = battery_messages.warnLevels.length - 1; i >= 0; i--) { + if (percent <= battery_messages.warnLevels[i] && !charging && !battery_warned) { + battery_warned = true; + Utils.execAsync([ + "bash", + "-c", + `notify-send "${battery_messages.warnTitles[i]}" "${battery_messages.warnMessages[i]}" -u critical &` + ]).catch(print); + break; + } + } +} + +export async function start_battery_warning_service() { + Utils.timeout(1, () => { + battery.connect("changed", () => battery_notification().catch(print)); + }); +} diff --git a/config/ags/style.css b/config/ags/style.css index 9268a427..de5e7b3c 100644 --- a/config/ags/style.css +++ b/config/ags/style.css @@ -104,80 +104,44 @@ separator { * Workspaces * ----------------------------------------------------- */ -.outer-workspace { - background-color: @surfaceContainerHigh; - border-radius: 20px; +.workspaces { + border-radius: 16px; + font-weight: bold; + font-style: normal; + font-size: 16px; + color: @onSurface; + background: @surfaceContainer; } -.workspace { - background-color: @surfaceVariant; - /* padding: 0; */ +.workspaces * { + transition: all 0.35s ease-in-out; + transition-property: background-color, color, min-width; } -.workspace button { - background-color: transparent; - padding-left: 8px; - padding-right: 8px; +.workspaces button { + padding: 0px 5px; + margin: 4px 3px; + border-radius: 16px; + border: 0px; } -.workspace.first { - border-radius: 20px 0 0 20px; -} -.workspace.last { - border-radius: 0 20px 20px 0; +.workspaces button label { + color: @onSurfaceVariant; + font-weight: bold; } -.workspace.normal, -.workspace button.normal { - background-color: transparent; - color: @surfaceDim; +.workspaces button:hover { + color: @onSurface; + background-color: mix(@onSurface, @surface, 0.85); } -.workspace button.normal:hover { - border-radius: 20px; - background-color: @primary; - color: @surfaceDim; +.workspaces button.active { + background: @secondaryContainer; + min-width: 40px; } -.workspace button.focused { - background-color: @outline; - color: @secondary; - font-weight: bold; - padding-left: 8px; - padding-right: 8px; - border-radius: 20px; -} - -.workspace button.focused:hover { - border-radius: 20px; - color: @primary; - background-color: mix(@onSurface, @surface, 0.85); -} - -.workspace button.occupied { - color: @primary; -} - -.workspaces button.occupied:hover { - border-radius: 20px; - background-color: mix(@onSurface, @surface, 0.85); - color: @surfaceDim; -} - -.workspace.occupied-single { - border-radius: 20px; -} - -.workspace.occupied-start { - border-radius: 20px 0 0 20px; -} - -.workspace.occupied-middle { - border-radius: 0px; -} - -.workspace.occupied-end { - border-radius: 0px 20px 20px 0px; +.workspaces button.active label { + color: @onSecondaryContainer; } /* ----------------------------------------------------- @@ -352,6 +316,13 @@ window.notification-popups box.notifications { font-feature-settings: "tnum"; } +.clip_container .preview { + background-size: cover; + background-position: center; + background-repeat: no-repeat; + border-radius: 8px; +} + .clip_container .dot_divider { font-weight: 900; font-size: 12px; @@ -370,6 +341,10 @@ window.notification-popups box.notifications { font-weight: normal; } +.clip_container.with_image .clip_label { + color: @tertiary; +} + .clear_history_button { background-color: @surfaceContainerHigh; color: @onSurface; @@ -439,6 +414,14 @@ window.notification-popups box.notifications { color: @onSurface; } +.battery.critical { + background-color: @error; +} + +.battery.critical label, .battery.critical .icon { + color: @onError; +} + .bar_applets { background-color: @surfaceContainer; border-radius: 100px; @@ -1578,6 +1561,56 @@ switch:checked:active slider { } +/* ----------------------------------------------------- + * Popups + * ----------------------------------------------------- */ +.popups { + background-color: transparent; +} + +.popups .popup { + background-color: @surfaceContainer; + margin-bottom: 14px; + padding: 4px; + border-radius: 14px; +} + +.popup_slider { + min-width: 150px; +} + +.popup .icon { + margin-left: 4px; +} + +.popup_slider slider { + color: @onPrimary; + background-color: @primary; + background-size: 20px 20px; + min-width: 5px; + min-height: 14px; + border-radius: 100px; + padding: 0px; + background-repeat: no-repeat; + background-position: center; + margin-left: 0px; + margin-right: 0px; + margin-top: -16px; + margin-bottom: -16px; + box-shadow: -4px 0px 0px 1px @surfaceContainer, 4px 0px 0px 1px @surfaceContainer; +} + +.popup_slider trough { + background-color: @secondaryContainer; + min-height: 10px; + margin-right: 4px; +} + +.popup_slider highlight { + border-radius: 100px 0px 0px 100px; + background-color: @primary; +} + /* ----------------------------------------------------- * Material * ----------------------------------------------------- */ diff --git a/config/ags/variables.ts b/config/ags/variables.ts index 17590b4b..e45fee79 100644 --- a/config/ags/variables.ts +++ b/config/ags/variables.ts @@ -60,7 +60,7 @@ export type WeatherJson = { export const theme = Variable("dark"); export const main_color = Variable("#000000"); -export const current_wallpaper = Variable(`${GLib.get_home_dir()}/Pictures/wallpapers/1.jpg`); +export const current_wallpaper = Variable(`${GLib.get_home_dir()}/Pictures/wallpapers/default.png`); // @ts-expect-error export const weather: VariableType = Variable({ no_data: true }); const reload = () => { @@ -73,7 +73,7 @@ const reload = () => { }) .catch(print); } -Utils.interval(100, reload); +Utils.interval(150, reload); configuration.connect("changed", reload) export const idle_inhibitor = Variable(false); @@ -105,6 +105,17 @@ export const generation_scheme_file = `${GLib.get_home_dir()}/dotfiles/.settings export const color_scheme_file = `${GLib.get_home_dir()}/dotfiles/.settings/color-scheme`; export const wallpaper_cache_file = `${GLib.get_home_dir()}/.cache/current_wallpaper`; +function checkBrightness() { + const get = Utils.execAsync(`${App.configDir}/scripts/brightness.sh --get`) + .then((out) => Number(out.trim())) + .catch(print); + return get; +} + +export const current_brightness = Variable(100, { + poll: [500, checkBrightness] +}); + function readFiles() { Utils.readFileAsync(custom_color_file) .then((out) => {