diff --git a/config/astal/components/QuickActions/QuickActions.tsx b/config/astal/components/QuickActions/QuickActions.tsx index 97dc7fb..e4e5bb2 100644 --- a/config/astal/components/QuickActions/QuickActions.tsx +++ b/config/astal/components/QuickActions/QuickActions.tsx @@ -1,44 +1,58 @@ -import { Gtk } from "astal/gtk4"; -import Power from "./modules/Power"; -import Audio from "./modules/Audio/Audio"; -import Bluetooth from "./modules/Bluetooth/Bluetooth"; -import Brightness from "./modules/Brightness/Brightness"; -import Player from "./modules/Player/Player"; -import { BatteryBox } from "./modules/Battery"; -import { exec } from "astal"; -import Network from "./modules/Networking/Network"; +import Audio from './modules/Audio/Audio'; +import { + BatteryBox +} from './modules/Battery'; +import Bluetooth from './modules/Bluetooth/Bluetooth'; +import Brightness from './modules/Brightness/Brightness'; +import { + Gtk +} from 'astal/gtk4'; +import Network from './modules/Networking/Network'; +import Player from './modules/Player/Player'; +import Power from './modules/Power'; +import SysTray from './modules/SysTray'; +import { + exec +} from 'astal'; const QuickActions = () => { - const popover = new Gtk.Popover({ cssClasses: ["quick-actions-wrapper"] }); - popover.set_child(renderQuickActions()); + const popover = new Gtk.Popover( { + 'cssClasses': [ 'quick-actions-wrapper' ] + } ); + + popover.set_child( renderQuickActions() ); + return popover; }; const renderQuickActions = () => { - const user = exec("/bin/sh -c whoami"); - const profile = exec("/bin/fish -c get-profile-picture"); - const cwd = exec("pwd"); + const user = exec( '/bin/sh -c whoami' ); + const profile = exec( '/bin/fish -c get-profile-picture' ); + const cwd = exec( 'pwd' ); const um = Power.UserMenu(); return ( - + um.popup()} - cssClasses={["stealthy-button"]} + cssClasses={[ 'stealthy-button' ]} child={ {um} } @@ -53,6 +67,7 @@ const renderQuickActions = () => { hexpand={false} > + } diff --git a/config/astal/components/QuickActions/modules/Power.tsx b/config/astal/components/QuickActions/modules/Power.tsx index 5402073..b6fef1f 100644 --- a/config/astal/components/QuickActions/modules/Power.tsx +++ b/config/astal/components/QuickActions/modules/Power.tsx @@ -1,48 +1,56 @@ -import { exec } from "astal"; -import { Gtk } from "astal/gtk4"; +import { + exec +} from 'astal'; +import { + Gtk +} from 'astal/gtk4'; const PowerMenu = (): Gtk.Popover => { - const popover = new Gtk.Popover({ cssClasses: ["PowerMenu"] }); + const popover = new Gtk.Popover( { + 'cssClasses': [ 'PowerMenu' ] + } ); const powerMenuBox = () => { return ( ); }; - popover.set_child(powerMenuBox()); + popover.set_child( powerMenuBox() ); + return popover; }; const Power = () => { const pm = PowerMenu(); + return ( ); }; - popover.set_child(powerMenuBox()); + popover.set_child( powerMenuBox() ); + return popover; }; diff --git a/config/astal/components/QuickActions/modules/SysTray.tsx b/config/astal/components/QuickActions/modules/SysTray.tsx new file mode 100644 index 0000000..e0fc4ae --- /dev/null +++ b/config/astal/components/QuickActions/modules/SysTray.tsx @@ -0,0 +1,88 @@ +import AstalTray from 'gi://AstalTray'; +import { + GObject +} from 'astal'; +import { + Gtk +} from 'astal/gtk4'; + +const SYNC = GObject.BindingFlags.SYNC_CREATE; + +const SysTray = () => { + const trayBox = new Gtk.Box( { + 'cssClasses': [ '' ] + } ); + const tray = AstalTray.get_default(); + const trayItems = new Map(); + const trayAddedHandler = tray.connect( 'item-added', ( _, id ) => { + const item = tray.get_item( id ); + const popover = Gtk.PopoverMenu.new_from_model( item.menu_model ); + const icon = new Gtk.Image(); + const button = new Gtk.MenuButton( { + popover, + 'child': icon, + 'cssClasses': [ 'tray-item' ], + } ); + + item.bind_property( + 'gicon', icon, 'gicon', SYNC + ); + popover.insert_action_group( 'dbusmenu', item.action_group ); + item.connect( 'notify::action-group', () => { + popover.insert_action_group( 'dbusmenu', item.action_group ); + } ); + + trayItems.set( id, button ); + trayBox.append( button ); + } ); + const trayRemovedHandler = tray.connect( 'item-removed', ( _, id ) => { + const button = trayItems.get( id ); + + if ( button ) { + trayBox.remove( button ); + button.run_dispose(); + trayItems.delete( id ); + } + } ); + + trayBox.connect( 'destroy', () => { + tray.disconnect( trayAddedHandler ); + tray.disconnect( trayRemovedHandler ); + } ); + + return trayBox; +}; + +const TrayPopover = () => { + const popover = new Gtk.Popover( { + 'cssClasses': [ 'TrayPopover' ] + } ); + + popover.set_child( SysTray() ); + + return popover; +}; + +const SystemTray = () => { + const systray = TrayPopover(); + + return ( +