diff options
| author | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-01-16 16:35:37 +1100 |
|---|---|---|
| committer | 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> | 2025-01-16 16:35:37 +1100 |
| commit | 02fd2e97f2c8a53bf2344e6fa8b14769cb15ee38 (patch) | |
| tree | 5e2a56becf6ba6961995e541ce9688224f704773 /src/modules | |
| parent | popupwindow: switch to class (diff) | |
| download | caelestia-shell-02fd2e97f2c8a53bf2344e6fa8b14769cb15ee38.tar.gz caelestia-shell-02fd2e97f2c8a53bf2344e6fa8b14769cb15ee38.tar.bz2 caelestia-shell-02fd2e97f2c8a53bf2344e6fa8b14769cb15ee38.zip | |
refactor: move ts to src
Also move popupwindow to own file
Diffstat (limited to '')
| -rw-r--r-- | src/modules/bar.tsx (renamed from modules/bar.tsx) | 2 | ||||
| -rw-r--r-- | src/modules/launcher.tsx (renamed from modules/launcher.tsx) | 5 | ||||
| -rw-r--r-- | src/modules/notifications.tsx | 57 | ||||
| -rw-r--r-- | src/modules/notifpopups.tsx | 49 | ||||
| -rw-r--r-- | src/modules/osds.tsx (renamed from modules/osds.tsx) | 4 |
5 files changed, 112 insertions, 5 deletions
diff --git a/modules/bar.tsx b/src/modules/bar.tsx index 5ed309e..b56d94a 100644 --- a/modules/bar.tsx +++ b/src/modules/bar.tsx @@ -7,7 +7,7 @@ import AstalNetwork from "gi://AstalNetwork"; import AstalNotifd from "gi://AstalNotifd"; import AstalTray from "gi://AstalTray"; import AstalWp01 from "gi://AstalWp"; -import { bar as config } from "../config"; +import { bar as config } from "../../config"; import type { Monitor } from "../services/monitors"; import Players from "../services/players"; import Updates from "../services/updates"; diff --git a/modules/launcher.tsx b/src/modules/launcher.tsx index 966cdfd..2fc6eef 100644 --- a/modules/launcher.tsx +++ b/src/modules/launcher.tsx @@ -3,12 +3,13 @@ import { Astal, Gtk, Widget } from "astal/gtk3"; import fuzzysort from "fuzzysort"; import type AstalApps from "gi://AstalApps"; import AstalHyprland from "gi://AstalHyprland"; -import { launcher as config } from "../config"; +import { launcher as config } from "../../config"; import { Apps } from "../services/apps"; import Math, { type HistoryItem } from "../services/math"; import { getAppCategoryIcon } from "../utils/icons"; import { launch } from "../utils/system"; -import { PopupWindow, setupCustomTooltip } from "../utils/widgets"; +import { setupCustomTooltip } from "../utils/widgets"; +import PopupWindow from "../widgets/popupwindow"; type Mode = "apps" | "files" | "math"; diff --git a/src/modules/notifications.tsx b/src/modules/notifications.tsx new file mode 100644 index 0000000..66188a1 --- /dev/null +++ b/src/modules/notifications.tsx @@ -0,0 +1,57 @@ +import { Gtk } from "astal/gtk3"; +import AstalNotifd from "gi://AstalNotifd"; +import { PopupWindow, setupChildClickthrough } from "../utils/widgets"; + +const List = () => ( + <box + vertical + valign={Gtk.Align.START} + className="list" + setup={self => { + const notifd = AstalNotifd.get_default(); + const map = new Map<number, NotifPopup>(); + self.hook(notifd, "notified", (self, id) => { + const notification = notifd.get_notification(id); + + const popup = (<NotifPopup notification={notification} />) as NotifPopup; + popup.connect("destroy", () => map.get(notification.id) === popup && map.delete(notification.id)); + map.get(notification.id)?.destroyWithAnims(); + map.set(notification.id, popup); + + self.add( + <eventbox + // Dismiss on middle click + onClick={(_, event) => event.button === Astal.MouseButton.MIDDLE && notification.dismiss()} + // Close on hover lost + onHoverLost={() => popup.destroyWithAnims()} + > + {popup} + </eventbox> + ); + + // Limit number of popups + if (config.maxPopups > 0 && self.children.length > config.maxPopups) + map.values().next().value?.destroyWithAnims(); + }); + self.hook(notifd, "resolved", (_, id) => map.get(id)?.destroyWithAnims()); + + // Change input region to child region so can click through empty space + setupChildClickthrough(self); + }} + /> +); + +export default class Notifications extends PopupWindow { + constructor() { + super({ + name: "notifications", + child: ( + <box> + <List /> + </box> + ), + }); + + setupChildClickthrough(self); + } +} diff --git a/src/modules/notifpopups.tsx b/src/modules/notifpopups.tsx new file mode 100644 index 0000000..5da3092 --- /dev/null +++ b/src/modules/notifpopups.tsx @@ -0,0 +1,49 @@ +import { Astal, Gtk } from "astal/gtk3"; +import AstalNotifd from "gi://AstalNotifd"; +import { notifpopups as config } from "../../config"; +import { setupChildClickthrough } from "../utils/widgets"; +import Notification from "../widgets/notification"; + +export default () => ( + <window + namespace="caelestia-notifpopups" + anchor={Astal.WindowAnchor.TOP | Astal.WindowAnchor.RIGHT | Astal.WindowAnchor.BOTTOM} + > + <box + vertical + valign={Gtk.Align.START} + className="notifpopups" + setup={self => { + const notifd = AstalNotifd.get_default(); + const map = new Map<number, Notification>(); + self.hook(notifd, "notified", (self, id) => { + const notification = notifd.get_notification(id); + + const popup = (<Notification popup notification={notification} />) as Notification; + popup.connect("destroy", () => map.get(notification.id) === popup && map.delete(notification.id)); + map.get(notification.id)?.destroyWithAnims(); + map.set(notification.id, popup); + + self.add( + <eventbox + // Dismiss on middle click + onClick={(_, event) => event.button === Astal.MouseButton.MIDDLE && notification.dismiss()} + // Close on hover lost + onHoverLost={() => popup.destroyWithAnims()} + > + {popup} + </eventbox> + ); + + // Limit number of popups + if (config.maxPopups > 0 && self.children.length > config.maxPopups) + map.values().next().value?.destroyWithAnims(); + }); + self.hook(notifd, "resolved", (_, id) => map.get(id)?.destroyWithAnims()); + + // Change input region to child region so can click through empty space + setupChildClickthrough(self); + }} + /> + </window> +); diff --git a/modules/osds.tsx b/src/modules/osds.tsx index b6e1333..a87fcc3 100644 --- a/modules/osds.tsx +++ b/src/modules/osds.tsx @@ -5,9 +5,9 @@ import AstalWp from "gi://AstalWp"; import Cairo from "gi://cairo"; import Pango from "gi://Pango"; import PangoCairo from "gi://PangoCairo"; -import { osds as config } from "../config"; +import { osds as config } from "../../config"; import Monitors, { type Monitor } from "../services/monitors"; -import { PopupWindow } from "../utils/widgets"; +import PopupWindow from "../widgets/popupwindow"; const getStyle = (context: Gtk.StyleContext, prop: string) => context.get_property(prop, Gtk.StateFlags.NORMAL); const getNumStyle = (context: Gtk.StyleContext, prop: string) => getStyle(context, prop) as number; |