From d63332b533b390e7e68f8f1fc2432958c4d36a4f Mon Sep 17 00:00:00 2001 From: Aylur Date: Tue, 15 Oct 2024 01:26:40 +0200 Subject: update examples --- examples/js/.gitignore | 3 ++ examples/js/simple-bar/app.ts | 7 +++- examples/js/simple-bar/widget/Bar.tsx | 4 ++- examples/lua/simple-bar/init.lua | 7 +++- examples/lua/simple-bar/widget/Bar.lua | 12 ++++--- examples/py/.gitignore | 2 -- examples/py/simple-bar/app.py | 20 ++++++----- examples/py/simple-bar/versions.py | 3 +- examples/py/simple-bar/widget/Bar.py | 8 +++-- examples/vala/simple-bar/app.in.vala | 11 +++--- examples/vala/simple-bar/flake.lock | 62 -------------------------------- examples/vala/simple-bar/flake.nix | 3 +- examples/vala/simple-bar/meson.build | 3 +- examples/vala/simple-bar/widget/Bar.vala | 4 +-- 14 files changed, 56 insertions(+), 93 deletions(-) delete mode 100644 examples/vala/simple-bar/flake.lock (limited to 'examples') diff --git a/examples/js/.gitignore b/examples/js/.gitignore index b0d983b..261d669 100644 --- a/examples/js/.gitignore +++ b/examples/js/.gitignore @@ -1,3 +1,6 @@ @girs/ tsconfig.json env.d.ts +dist/ +package.json +package-lock.json diff --git a/examples/js/simple-bar/app.ts b/examples/js/simple-bar/app.ts index 05f043a..4b7ea48 100644 --- a/examples/js/simple-bar/app.ts +++ b/examples/js/simple-bar/app.ts @@ -1,8 +1,13 @@ -import { App } from "astal" +import { App } from "astal/gtk3" import style from "./style.scss" import Bar from "./widget/Bar" App.start({ css: style, + instanceName: "js", + requestHandler(request, res) { + print(request) + res("ok") + }, main: () => App.get_monitors().map(Bar), }) diff --git a/examples/js/simple-bar/widget/Bar.tsx b/examples/js/simple-bar/widget/Bar.tsx index 644e835..efc065a 100644 --- a/examples/js/simple-bar/widget/Bar.tsx +++ b/examples/js/simple-bar/widget/Bar.tsx @@ -1,4 +1,6 @@ -import { App, Variable, Astal, Gtk, Gdk, GLib, bind } from "astal" +import { App } from "astal/gtk3" +import { Variable, GLib, bind } from "astal" +import { Astal, Gtk, Gdk } from "astal/gtk3" import Hyprland from "gi://AstalHyprland" import Mpris from "gi://AstalMpris" import Battery from "gi://AstalBattery" diff --git a/examples/lua/simple-bar/init.lua b/examples/lua/simple-bar/init.lua index aecf7a6..8c412fb 100644 --- a/examples/lua/simple-bar/init.lua +++ b/examples/lua/simple-bar/init.lua @@ -1,5 +1,5 @@ local astal = require("astal") -local App = astal.App +local App = require("astal.gtk3.app") local Bar = require("widget.Bar") local src = require("lib").src @@ -10,7 +10,12 @@ local css = "/tmp/style.css" astal.exec("sass " .. scss .. " " .. css) App:start({ + instance_name = "lua", css = css, + request_handler = function(msg, res) + print(msg) + res("ok") + end, main = function() for _, mon in pairs(App.monitors) do Bar(mon) diff --git a/examples/lua/simple-bar/widget/Bar.lua b/examples/lua/simple-bar/widget/Bar.lua index d340cba..bf230bb 100644 --- a/examples/lua/simple-bar/widget/Bar.lua +++ b/examples/lua/simple-bar/widget/Bar.lua @@ -1,9 +1,9 @@ local astal = require("astal") -local App = astal.App -local Widget = astal.Widget +local App = require("astal.gtk3.app") +local Widget = require("astal.gtk3.widget") local Variable = astal.Variable -local Gdk = astal.Gdk -local GLib = astal.GLib +local Gdk = astal.require("Gdk", "3.0") +local GLib = astal.require("GLib") local bind = astal.bind local Mpris = astal.require("AstalMpris") local Battery = astal.require("AstalBattery") @@ -170,10 +170,12 @@ local function Time(format) end return function(gdkmonitor) + local WindowAnchor = astal.require("Astal", "3.0").WindowAnchor + return Widget.Window({ class_name = "Bar", gdkmonitor = gdkmonitor, - anchor = astal.Astal.WindowAnchor.TOP + astal.Astal.WindowAnchor.LEFT + astal.Astal.WindowAnchor.RIGHT, + anchor = WindowAnchor.TOP + WindowAnchor.LEFT + WindowAnchor.RIGHT, exclusivity = "EXCLUSIVE", Widget.CenterBox({ diff --git a/examples/py/.gitignore b/examples/py/.gitignore index b0bff8b..c18dd8d 100644 --- a/examples/py/.gitignore +++ b/examples/py/.gitignore @@ -1,3 +1 @@ -pygobject-stubs/ -*.pyi __pycache__/ diff --git a/examples/py/simple-bar/app.py b/examples/py/simple-bar/app.py index f5a8a80..17b6782 100755 --- a/examples/py/simple-bar/app.py +++ b/examples/py/simple-bar/app.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 import sys import versions -from gi.repository import Astal, Gio +from gi.repository import AstalIO, Astal, Gio from widget.Bar import Bar from pathlib import Path @@ -10,23 +10,27 @@ css = "/tmp/style.css" class App(Astal.Application): - def do_request(self, msg: str, conn: Gio.SocketConnection) -> None: + def do_astal_application_request( + self, msg: str, conn: Gio.SocketConnection + ) -> None: print(msg) - Astal.write_sock(conn, "hello") + AstalIO.write_sock(conn, "hello") def do_activate(self) -> None: self.hold() - Astal.Process.execv(["sass", scss, css]) + AstalIO.Process.execv(["sass", scss, css]) self.apply_css(css, True) + print("hello") for mon in self.get_monitors(): self.add_window(Bar(mon)) -instance_name = "simple-bar" +instance_name = "python" app = App(instance_name=instance_name) if __name__ == "__main__": - if app.acquire_socket(): + try: + print(app.acquire_socket()) app.run(None) - else: - print(Astal.Application.send_message(instance_name, "".join(sys.argv[1:]))) + except Exception as e: + print(AstalIO.send_message(instance_name, "".join(sys.argv[1:]))) diff --git a/examples/py/simple-bar/versions.py b/examples/py/simple-bar/versions.py index a8a1ab8..0e57708 100644 --- a/examples/py/simple-bar/versions.py +++ b/examples/py/simple-bar/versions.py @@ -1,6 +1,7 @@ import gi -gi.require_version("Astal", "0.1") +gi.require_version("AstalIO", "0.1") +gi.require_version("Astal", "3.0") gi.require_version("Gtk", "3.0") gi.require_version("Gdk", "3.0") gi.require_version("Gio", "2.0") diff --git a/examples/py/simple-bar/widget/Bar.py b/examples/py/simple-bar/widget/Bar.py index 89581f1..3b09dce 100644 --- a/examples/py/simple-bar/widget/Bar.py +++ b/examples/py/simple-bar/widget/Bar.py @@ -1,5 +1,6 @@ import math from gi.repository import ( + AstalIO, Astal, Gtk, Gdk, @@ -125,8 +126,8 @@ class SysTray(Gtk.Box): app.add_icons(theme) menu = item.create_menu() - btn = Astal.Button() - icon = Astal.Icon() + btn = Astal.Button(visible=True) + icon = Astal.Icon(visible=True) def on_clicked(btn): if menu: @@ -143,6 +144,7 @@ class SysTray(Gtk.Box): item.bind_property("gicon", icon, "gicon", SYNC) self.add(btn) self.items[id] = btn + self.show_all() def remove_item(self, _: Tray.Tray, id: str): if id in self.items: @@ -203,7 +205,7 @@ class Time(Astal.Label): def __init__(self, format="%H:%M - %A %e."): super().__init__() self.format = format - self.interval = Astal.Time.interval(1000, self.sync) + self.interval = AstalIO.Time.interval(1000, self.sync) self.connect("destroy", self.interval.cancel) Astal.widget_set_class_names(self, ["Time"]) diff --git a/examples/vala/simple-bar/app.in.vala b/examples/vala/simple-bar/app.in.vala index aece979..b04a1fa 100644 --- a/examples/vala/simple-bar/app.in.vala +++ b/examples/vala/simple-bar/app.in.vala @@ -3,7 +3,7 @@ class App : Astal.Application { public override void request (string msg, SocketConnection conn) { print(@"$msg\n"); - Astal.write_sock.begin(conn, "hello"); + AstalIO.write_sock.begin(conn, "ok"); } public override void activate () { @@ -14,16 +14,17 @@ class App : Astal.Application { } public static void main(string[] args) { - var instance_name = "simple-bar"; + var instance_name = "vala"; App.instance = new App() { instance_name = instance_name }; - if (App.instance.acquire_socket()) { + try { + App.instance.acquire_socket(); App.instance.run(null); - } else { - print(Astal.Application.send_message(instance_name, string.joinv(" ", args))); + } catch (Error err) { + print(AstalIO.send_message(instance_name, string.joinv(" ", args))); } } } diff --git a/examples/vala/simple-bar/flake.lock b/examples/vala/simple-bar/flake.lock deleted file mode 100644 index 06f572f..0000000 --- a/examples/vala/simple-bar/flake.lock +++ /dev/null @@ -1,62 +0,0 @@ -{ - "nodes": { - "astal": { - "inputs": { - "nixpkgs": "nixpkgs" - }, - "locked": { - "lastModified": 1727022015, - "narHash": "sha256-ka7aRbReUE6ImjQV8KabMHoojUgb3gtn1/9drMFTtBk=", - "owner": "aylur", - "repo": "astal", - "rev": "8cab7d039e2cf783033a5f1f26cf8be42b0d158e", - "type": "github" - }, - "original": { - "owner": "aylur", - "repo": "astal", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1716293225, - "narHash": "sha256-pU9ViBVE3XYb70xZx+jK6SEVphvt7xMTbm6yDIF4xPs=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "3eaeaeb6b1e08a016380c279f8846e0bd8808916", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_2": { - "locked": { - "lastModified": 1726937504, - "narHash": "sha256-bvGoiQBvponpZh8ClUcmJ6QnsNKw0EMrCQJARK3bI1c=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "9357f4f23713673f310988025d9dc261c20e70c6", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "astal": "astal", - "nixpkgs": "nixpkgs_2" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/examples/vala/simple-bar/flake.nix b/examples/vala/simple-bar/flake.nix index 78bfb62..d13c649 100644 --- a/examples/vala/simple-bar/flake.nix +++ b/examples/vala/simple-bar/flake.nix @@ -27,7 +27,8 @@ ]; buildInputs = [ - astal.packages.${system}.astal + astal.packages.${system}.io + astal.packages.${system}.astal3 astal.packages.${system}.battery astal.packages.${system}.wireplumber astal.packages.${system}.network diff --git a/examples/vala/simple-bar/meson.build b/examples/vala/simple-bar/meson.build index d0ef209..10f5dd2 100644 --- a/examples/vala/simple-bar/meson.build +++ b/examples/vala/simple-bar/meson.build @@ -8,7 +8,8 @@ pkgconfig_deps = [ dependency('gobject-2.0'), dependency('gtk+-3.0'), dependency('libnm'), - dependency('astal-0.1'), + dependency('astal-io-0.1'), + dependency('astal-3.0'), dependency('astal-battery-0.1'), dependency('astal-wireplumber-0.1'), dependency('astal-network-0.1'), diff --git a/examples/vala/simple-bar/widget/Bar.vala b/examples/vala/simple-bar/widget/Bar.vala index 6e99327..17db831 100644 --- a/examples/vala/simple-bar/widget/Bar.vala +++ b/examples/vala/simple-bar/widget/Bar.vala @@ -191,7 +191,7 @@ class Battery : Gtk.Box { class Time : Astal.Label { string format; - Astal.Time interval; + AstalIO.Time interval; void sync() { label = new DateTime.now_local().format(format); @@ -199,7 +199,7 @@ class Time : Astal.Label { public Time(string format = "%H:%M - %A %e.") { this.format = format; - interval = Astal.Time.interval(1000, null); + interval = AstalIO.Time.interval(1000, null); interval.now.connect(sync); destroy.connect(interval.cancel); Astal.widget_set_class_names(this, {"Time"}); -- cgit v1.2.3 From 1a1c8a605c8011056a07d69b15153bcdec4c0ceb Mon Sep 17 00:00:00 2001 From: Kevin Date: Mon, 14 Oct 2024 11:56:20 -0300 Subject: notifications lua example --- examples/lua/notification-popups/README.md | 14 +++ examples/lua/notification-popups/init.lua | 21 ++++ examples/lua/notification-popups/lib.lua | 52 +++++++++ examples/lua/notification-popups/style.scss | 69 ++++++++++++ .../notification-popups/widget/notifications.lua | 125 +++++++++++++++++++++ 5 files changed, 281 insertions(+) create mode 100644 examples/lua/notification-popups/README.md create mode 100644 examples/lua/notification-popups/init.lua create mode 100644 examples/lua/notification-popups/lib.lua create mode 100644 examples/lua/notification-popups/style.scss create mode 100644 examples/lua/notification-popups/widget/notifications.lua (limited to 'examples') diff --git a/examples/lua/notification-popups/README.md b/examples/lua/notification-popups/README.md new file mode 100644 index 0000000..bcc6bba --- /dev/null +++ b/examples/lua/notification-popups/README.md @@ -0,0 +1,14 @@ +# Simple Bar Example + +![simple-bar](https://github.com/user-attachments/assets/a306c864-56b7-44c4-8820-81f424f32b9b) + +A simple bar for Hyprland using + +- [Audio library](https://aylur.github.io/astal/guide/libraries/audio). +- [Battery library](https://aylur.github.io/astal/guide/libraries/battery). +- [Hyprland library](https://aylur.github.io/astal/guide/libraries/hyprland). +- [Mpris library](https://aylur.github.io/astal/guide/libraries/mpris). +- [Network library](https://aylur.github.io/astal/guide/libraries/network). +- [Tray library](https://aylur.github.io/astal/guide/libraries/tray). +- [WirePlumber library](https://aylur.github.io/astal/guide/libraries/wireplumber). +- [dart-sass](https://sass-lang.com/dart-sass/) as the css precompiler diff --git a/examples/lua/notification-popups/init.lua b/examples/lua/notification-popups/init.lua new file mode 100644 index 0000000..ffa910c --- /dev/null +++ b/examples/lua/notification-popups/init.lua @@ -0,0 +1,21 @@ +local astal = require("astal") +local Notify = astal.require("Notify") +local timeout = astal.timeout +local App = astal.App + +local Notifications = require("widget.notifications") +local src = require("lib").src + +local scss = src("style.scss") +local css = "/tmp/style.css" + +astal.exec("sass " .. scss .. " " .. css) + +App:start({ + css = css, + main = function() + for _, mon in pairs(App.monitors) do + Notifications(mon) + end + end, +}) diff --git a/examples/lua/notification-popups/lib.lua b/examples/lua/notification-popups/lib.lua new file mode 100644 index 0000000..2ae71a9 --- /dev/null +++ b/examples/lua/notification-popups/lib.lua @@ -0,0 +1,52 @@ +local Variable = require("astal").Variable +local astal = require("astal") +local Gtk = astal.Gtk + +local M = {} + +function M.src(path) + local str = debug.getinfo(2, "S").source:sub(2) + local src = str:match("(.*/)") or str:match("(.*\\)") or "./" + return src .. path +end + +---@generic T, R +---@param arr T[] +---@param func fun(T, integer): R +---@return R[] +function M.map(arr, func) + local new_arr = {} + for i, v in ipairs(arr) do + new_arr[i] = func(v, i) + end + return new_arr +end + +---@param name string +---@param size? 16 | 32 | 64 | 128 | 256 | 512 | number +function M.lookup_icon(name, size) + if not name or #name == 0 then + return + end + size = size or 256 + + local theme = Gtk.IconTheme.get_default() + local icon_info, path + + for _, n in ipairs({ + name, + string.lower(name), + string.upper(name), + }) do + icon_info = theme:lookup_icon(n, size, "USE_BUILTIN") + + if icon_info then + return icon_info + end + end + return false +end + +M.date = Variable(""):poll(1000, "date") + +return M diff --git a/examples/lua/notification-popups/style.scss b/examples/lua/notification-popups/style.scss new file mode 100644 index 0000000..8eb764a --- /dev/null +++ b/examples/lua/notification-popups/style.scss @@ -0,0 +1,69 @@ +$bg: #212223; +$fg: #f1f1f1; +$accent: #378df7; +$radius: 7px; + +window.notification-popups { + box.notifications { + padding: 0.5em; + } +} + +.icon { + min-width: 68px; + min-height: 68px; + margin-right: 1em; +} + +.icon { + icon { + font-size: 58px; + margin: 5px; + color: $fg; + } + box { + min-width: 68px; + min-height: 68px; + border-radius: $radius; + background-size: contain; + background-repeat: no-repeat; + background-position: center; + } +} + +.notification { + min-width: 350px; + border-radius: 11px; + padding: 1em; + margin: 0.5em; + border: 1px solid transparentize($fg, 0.9); + background-color: $bg; + + &.critical { + border: 1px solid $accent; + } + + .title { + color: $fg; + font-size: 1.4em; + } + + .body { + color: transparentize($fg, 0.4); + } + + .actions { + .action-button { + margin: 0 0.4em; + margin-top: 0.8em; + + &:first-child { + margin-left: 0; + } + + &:last-child { + margin-right: 0; + } + } + } +} diff --git a/examples/lua/notification-popups/widget/notifications.lua b/examples/lua/notification-popups/widget/notifications.lua new file mode 100644 index 0000000..4704c22 --- /dev/null +++ b/examples/lua/notification-popups/widget/notifications.lua @@ -0,0 +1,125 @@ +local astal = require("astal") +local Widget = astal.Widget +local GLib = astal.GLib +local bind = astal.bind +local timeout = astal.timeout + +local map = require("lib").map +local lookup_icon = require("lib").lookup_icon + +local Notifd = astal.require("AstalNotifd") +local notifd = Notifd.get_default() + +local NOTIFICATION_TIMEOUTMS = 5000 + +local function NotificationIcon(n) + local icon = "dialog-information-symbolic" + + if n.app_icon and GLib.file_test(n.app_icon, "EXISTS") then + return Widget.Box({ css = string.format('background-image: url("%s");', n.app_icon) }) + elseif n.app_icon and lookup_icon(n.app_icon) then + icon = n.app_icon + elseif n.app_name and lookup_icon(n.app_name) then + icon = n.app_name + end + + return Widget.Icon({ + icon = icon, + }) +end + +local function Notification(n) + local icon = Widget.Box({ + valign = "START", + class_name = "icon", + NotificationIcon(n), + }) + + local title = Widget.Label({ + class_name = "title", + xalign = 0, + justify = "LEFT", + hexpand = true, + max_width_chars = 24, + wrap = true, + ellipsize = "END", + use_markup = true, + label = n.summary, + }) + + local body = Widget.Label({ + class_name = "body", + hexpand = true, + use_markup = true, + xalign = 0, + justify = "LEFT", + wrap = true, + label = n.body, + }) + + local actions = Widget.Box({ + class_name = "actions", + map(n.actions, function(action) + return Widget.Button({ + on_click_release = function() + return n:invoke(action.id) + end, + class_name = "action-button", + hexpand = true, + label = action.label, + }) + end), + }) + return Widget.EventBox({ + Widget.Box({ + class_name = "notification", + orientation = "VERTICAL", + Widget.Box({ + icon, + Widget.Box({ + orientation = "VERTICAL", + title, + body, + }), + }), + actions, + }), + }) +end + +return function(gdkmonitor) + local n_list = {} + + local list = Widget.Box({ + orientation = "VERTICAL", + setup = function(self) + self:hook(notifd, "notified", function(_, id) + local n = notifd:get_notification(id) + n_list[id] = Notification(n) + self:add(n_list[id]) + local timeout_ms = n.expire_timeout > 0 and n.expire_timeout or NOTIFICATION_TIMEOUTMS + timeout(timeout_ms, function() + return n:dismiss() + end) + end) + self:hook(notifd, "resolved", function(_, id) + if n_list[id] then + n_list[id]:destroy() + n_list[id] = nil + end + end) + end, + }) + + return Widget.Window({ + namespace = "notifications", + gdkmonitor = gdkmonitor, + anchor = astal.Astal.WindowAnchor.TOP, + layer = "OVERLAY", + class_name = "notification-popups", + visible = bind(list, "children"):as(function(v) + return v and #v > 0 + end), + list, + }) +end -- cgit v1.2.3 From 236487001ab2a6c9c8e87e5db0ced9e5ab3ed791 Mon Sep 17 00:00:00 2001 From: Kevin Date: Tue, 15 Oct 2024 02:57:27 -0300 Subject: revert example-lua commit --- examples/lua/notification-popups/README.md | 14 --- examples/lua/notification-popups/init.lua | 21 ---- examples/lua/notification-popups/lib.lua | 52 --------- examples/lua/notification-popups/style.scss | 69 ------------ .../notification-popups/widget/notifications.lua | 125 --------------------- 5 files changed, 281 deletions(-) delete mode 100644 examples/lua/notification-popups/README.md delete mode 100644 examples/lua/notification-popups/init.lua delete mode 100644 examples/lua/notification-popups/lib.lua delete mode 100644 examples/lua/notification-popups/style.scss delete mode 100644 examples/lua/notification-popups/widget/notifications.lua (limited to 'examples') diff --git a/examples/lua/notification-popups/README.md b/examples/lua/notification-popups/README.md deleted file mode 100644 index bcc6bba..0000000 --- a/examples/lua/notification-popups/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# Simple Bar Example - -![simple-bar](https://github.com/user-attachments/assets/a306c864-56b7-44c4-8820-81f424f32b9b) - -A simple bar for Hyprland using - -- [Audio library](https://aylur.github.io/astal/guide/libraries/audio). -- [Battery library](https://aylur.github.io/astal/guide/libraries/battery). -- [Hyprland library](https://aylur.github.io/astal/guide/libraries/hyprland). -- [Mpris library](https://aylur.github.io/astal/guide/libraries/mpris). -- [Network library](https://aylur.github.io/astal/guide/libraries/network). -- [Tray library](https://aylur.github.io/astal/guide/libraries/tray). -- [WirePlumber library](https://aylur.github.io/astal/guide/libraries/wireplumber). -- [dart-sass](https://sass-lang.com/dart-sass/) as the css precompiler diff --git a/examples/lua/notification-popups/init.lua b/examples/lua/notification-popups/init.lua deleted file mode 100644 index ffa910c..0000000 --- a/examples/lua/notification-popups/init.lua +++ /dev/null @@ -1,21 +0,0 @@ -local astal = require("astal") -local Notify = astal.require("Notify") -local timeout = astal.timeout -local App = astal.App - -local Notifications = require("widget.notifications") -local src = require("lib").src - -local scss = src("style.scss") -local css = "/tmp/style.css" - -astal.exec("sass " .. scss .. " " .. css) - -App:start({ - css = css, - main = function() - for _, mon in pairs(App.monitors) do - Notifications(mon) - end - end, -}) diff --git a/examples/lua/notification-popups/lib.lua b/examples/lua/notification-popups/lib.lua deleted file mode 100644 index 2ae71a9..0000000 --- a/examples/lua/notification-popups/lib.lua +++ /dev/null @@ -1,52 +0,0 @@ -local Variable = require("astal").Variable -local astal = require("astal") -local Gtk = astal.Gtk - -local M = {} - -function M.src(path) - local str = debug.getinfo(2, "S").source:sub(2) - local src = str:match("(.*/)") or str:match("(.*\\)") or "./" - return src .. path -end - ----@generic T, R ----@param arr T[] ----@param func fun(T, integer): R ----@return R[] -function M.map(arr, func) - local new_arr = {} - for i, v in ipairs(arr) do - new_arr[i] = func(v, i) - end - return new_arr -end - ----@param name string ----@param size? 16 | 32 | 64 | 128 | 256 | 512 | number -function M.lookup_icon(name, size) - if not name or #name == 0 then - return - end - size = size or 256 - - local theme = Gtk.IconTheme.get_default() - local icon_info, path - - for _, n in ipairs({ - name, - string.lower(name), - string.upper(name), - }) do - icon_info = theme:lookup_icon(n, size, "USE_BUILTIN") - - if icon_info then - return icon_info - end - end - return false -end - -M.date = Variable(""):poll(1000, "date") - -return M diff --git a/examples/lua/notification-popups/style.scss b/examples/lua/notification-popups/style.scss deleted file mode 100644 index 8eb764a..0000000 --- a/examples/lua/notification-popups/style.scss +++ /dev/null @@ -1,69 +0,0 @@ -$bg: #212223; -$fg: #f1f1f1; -$accent: #378df7; -$radius: 7px; - -window.notification-popups { - box.notifications { - padding: 0.5em; - } -} - -.icon { - min-width: 68px; - min-height: 68px; - margin-right: 1em; -} - -.icon { - icon { - font-size: 58px; - margin: 5px; - color: $fg; - } - box { - min-width: 68px; - min-height: 68px; - border-radius: $radius; - background-size: contain; - background-repeat: no-repeat; - background-position: center; - } -} - -.notification { - min-width: 350px; - border-radius: 11px; - padding: 1em; - margin: 0.5em; - border: 1px solid transparentize($fg, 0.9); - background-color: $bg; - - &.critical { - border: 1px solid $accent; - } - - .title { - color: $fg; - font-size: 1.4em; - } - - .body { - color: transparentize($fg, 0.4); - } - - .actions { - .action-button { - margin: 0 0.4em; - margin-top: 0.8em; - - &:first-child { - margin-left: 0; - } - - &:last-child { - margin-right: 0; - } - } - } -} diff --git a/examples/lua/notification-popups/widget/notifications.lua b/examples/lua/notification-popups/widget/notifications.lua deleted file mode 100644 index 4704c22..0000000 --- a/examples/lua/notification-popups/widget/notifications.lua +++ /dev/null @@ -1,125 +0,0 @@ -local astal = require("astal") -local Widget = astal.Widget -local GLib = astal.GLib -local bind = astal.bind -local timeout = astal.timeout - -local map = require("lib").map -local lookup_icon = require("lib").lookup_icon - -local Notifd = astal.require("AstalNotifd") -local notifd = Notifd.get_default() - -local NOTIFICATION_TIMEOUTMS = 5000 - -local function NotificationIcon(n) - local icon = "dialog-information-symbolic" - - if n.app_icon and GLib.file_test(n.app_icon, "EXISTS") then - return Widget.Box({ css = string.format('background-image: url("%s");', n.app_icon) }) - elseif n.app_icon and lookup_icon(n.app_icon) then - icon = n.app_icon - elseif n.app_name and lookup_icon(n.app_name) then - icon = n.app_name - end - - return Widget.Icon({ - icon = icon, - }) -end - -local function Notification(n) - local icon = Widget.Box({ - valign = "START", - class_name = "icon", - NotificationIcon(n), - }) - - local title = Widget.Label({ - class_name = "title", - xalign = 0, - justify = "LEFT", - hexpand = true, - max_width_chars = 24, - wrap = true, - ellipsize = "END", - use_markup = true, - label = n.summary, - }) - - local body = Widget.Label({ - class_name = "body", - hexpand = true, - use_markup = true, - xalign = 0, - justify = "LEFT", - wrap = true, - label = n.body, - }) - - local actions = Widget.Box({ - class_name = "actions", - map(n.actions, function(action) - return Widget.Button({ - on_click_release = function() - return n:invoke(action.id) - end, - class_name = "action-button", - hexpand = true, - label = action.label, - }) - end), - }) - return Widget.EventBox({ - Widget.Box({ - class_name = "notification", - orientation = "VERTICAL", - Widget.Box({ - icon, - Widget.Box({ - orientation = "VERTICAL", - title, - body, - }), - }), - actions, - }), - }) -end - -return function(gdkmonitor) - local n_list = {} - - local list = Widget.Box({ - orientation = "VERTICAL", - setup = function(self) - self:hook(notifd, "notified", function(_, id) - local n = notifd:get_notification(id) - n_list[id] = Notification(n) - self:add(n_list[id]) - local timeout_ms = n.expire_timeout > 0 and n.expire_timeout or NOTIFICATION_TIMEOUTMS - timeout(timeout_ms, function() - return n:dismiss() - end) - end) - self:hook(notifd, "resolved", function(_, id) - if n_list[id] then - n_list[id]:destroy() - n_list[id] = nil - end - end) - end, - }) - - return Widget.Window({ - namespace = "notifications", - gdkmonitor = gdkmonitor, - anchor = astal.Astal.WindowAnchor.TOP, - layer = "OVERLAY", - class_name = "notification-popups", - visible = bind(list, "children"):as(function(v) - return v and #v > 0 - end), - list, - }) -end -- cgit v1.2.3