diff options
author | Aylur <[email protected]> | 2024-09-08 02:58:03 +0200 |
---|---|---|
committer | Aylur <[email protected]> | 2024-09-08 02:58:03 +0200 |
commit | 81f26551103e785fa974e054b2b3357725deb419 (patch) | |
tree | 97c64b806493fb27c693a4b342c30d5fe95b987f /examples | |
parent | 4407152c0884546ee57919687443201341ae5d84 (diff) |
example: add Tray to js Bar
Diffstat (limited to 'examples')
-rw-r--r-- | examples/js/simple-bar/widget/Bar.tsx | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/examples/js/simple-bar/widget/Bar.tsx b/examples/js/simple-bar/widget/Bar.tsx index 2b25258..d1bf2ec 100644 --- a/examples/js/simple-bar/widget/Bar.tsx +++ b/examples/js/simple-bar/widget/Bar.tsx @@ -1,9 +1,45 @@ -import { Variable, Astal, Gtk, Gdk, GLib, bind } from "astal" +import { App, Variable, Astal, Gtk, Gdk, GLib, bind } from "astal" import Hyprland from "gi://AstalHyprland" import Mpris from "gi://AstalMpris" import Battery from "gi://AstalBattery" import Wp from "gi://AstalWp" import Network from "gi://AstalNetwork" +import Tray from "gi://AstalTray" + +function SysTray() { + const tray = Tray.get_default() + + return <box> + {bind(tray, "items").as(items => items.map(item => { + if (item.iconThemePath) + App.add_icons(item.iconThemePath) + + const menu = item.create_menu() + + return <button + tooltipMarkup={bind(item, "tooltipMarkup")} + onDestroy={() => menu?.destroy()} + onClickRelease={self => { + menu?.popup_at_widget(self, Gdk.Gravity.SOUTH, Gdk.Gravity.NORTH, null) + }}> + <icon + setup={self => { + if (item.iconName) self.icon = item.iconName + if (item.iconPixbuf) self.pixbuf = item.iconPixbuf + + self.hook(item, "notify::icon-name", () => { + self.icon = item.iconName + }) + + self.hook(item, "notify::icon-pixbuf", () => { + self.pixbuf = item.iconPixbuf + }) + }} + /> + </button> + }))} + </box> +} function Wifi() { const { wifi } = Network.get_default() @@ -120,6 +156,7 @@ export default function Bar(monitor: Gdk.Monitor) { <Media /> </box> <box hexpand halign={Gtk.Align.END} > + <SysTray /> <Wifi /> <AudioSlider /> <BatteryLevel /> |