mirror of
https://github.com/tuxdotrs/tpanel.git
synced 2025-10-10 21:01:54 +05:30
Compare commits
3 Commits
416f2004af
...
main
Author | SHA1 | Date | |
---|---|---|---|
0c7610355f | |||
![]() |
0c1ac689cf | ||
98203af3e4
|
@@ -34,5 +34,5 @@ environment.systemPackages = [ inputs.tpanel.packages.${system}.default ];
|
|||||||
# Add this in your HomeManager config
|
# Add this in your HomeManager config
|
||||||
home.packages = [ inputs.tpanel.packages.${system}.default ];
|
home.packages = [ inputs.tpanel.packages.${system}.default ];
|
||||||
```
|
```
|
||||||
## Ooutdated Screenshot
|
## Outdated Screenshot
|
||||||

|

|
||||||
|
50
widgets/notifications/manager.ts
Normal file
50
widgets/notifications/manager.ts
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import GLib from "gi://GLib";
|
||||||
|
|
||||||
|
type TimeoutManager = {
|
||||||
|
setupTimeout: () => void;
|
||||||
|
clearTimeout: () => void;
|
||||||
|
handleHover: () => void;
|
||||||
|
handleHoverLost: () => void;
|
||||||
|
cleanup: () => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const createTimeoutManager = (
|
||||||
|
dismissCallback: () => void,
|
||||||
|
timeoutDelay: number,
|
||||||
|
): TimeoutManager => {
|
||||||
|
let isHovered = false;
|
||||||
|
let timeoutId: number | null = null;
|
||||||
|
|
||||||
|
const clearTimeout = () => {
|
||||||
|
if (timeoutId !== null) {
|
||||||
|
GLib.source_remove(timeoutId);
|
||||||
|
timeoutId = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const setupTimeout = () => {
|
||||||
|
clearTimeout();
|
||||||
|
|
||||||
|
if (!isHovered) {
|
||||||
|
timeoutId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, timeoutDelay, () => {
|
||||||
|
clearTimeout();
|
||||||
|
dismissCallback();
|
||||||
|
return GLib.SOURCE_REMOVE;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
setupTimeout,
|
||||||
|
clearTimeout,
|
||||||
|
handleHover: () => {
|
||||||
|
isHovered = true;
|
||||||
|
clearTimeout();
|
||||||
|
},
|
||||||
|
handleHoverLost: () => {
|
||||||
|
isHovered = false;
|
||||||
|
setupTimeout();
|
||||||
|
},
|
||||||
|
cleanup: clearTimeout,
|
||||||
|
};
|
||||||
|
};
|
@@ -3,6 +3,8 @@ import Adw from "gi://Adw";
|
|||||||
import AstalNotifd from "gi://AstalNotifd";
|
import AstalNotifd from "gi://AstalNotifd";
|
||||||
import GLib from "gi://GLib";
|
import GLib from "gi://GLib";
|
||||||
import Pango from "gi://Pango";
|
import Pango from "gi://Pango";
|
||||||
|
import { createTimeoutManager } from "./manager";
|
||||||
|
import { onCleanup, onMount } from "ags";
|
||||||
|
|
||||||
const isIcon = (icon?: string | null) => {
|
const isIcon = (icon?: string | null) => {
|
||||||
const iconTheme = Gtk.IconTheme.get_for_display(Gdk.Display.get_default()!);
|
const iconTheme = Gtk.IconTheme.get_for_display(Gdk.Display.get_default()!);
|
||||||
@@ -33,7 +35,20 @@ const urgency = (n: AstalNotifd.Notification) => {
|
|||||||
const { VERTICAL } = Gtk.Orientation;
|
const { VERTICAL } = Gtk.Orientation;
|
||||||
const { START, END, CENTER } = Gtk.Align;
|
const { START, END, CENTER } = Gtk.Align;
|
||||||
|
|
||||||
|
// Keep track of notification validity
|
||||||
|
const TIMEOUT_DELAY = 3000;
|
||||||
|
|
||||||
export const Notification = ({ n }: { n: AstalNotifd.Notification }) => {
|
export const Notification = ({ n }: { n: AstalNotifd.Notification }) => {
|
||||||
|
const timeoutManager = createTimeoutManager(() => n.dismiss(), TIMEOUT_DELAY);
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
timeoutManager.setupTimeout();
|
||||||
|
});
|
||||||
|
|
||||||
|
onCleanup(() => {
|
||||||
|
timeoutManager.cleanup();
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Adw.Clamp maximumSize={400}>
|
<Adw.Clamp maximumSize={400}>
|
||||||
<box
|
<box
|
||||||
@@ -42,6 +57,11 @@ export const Notification = ({ n }: { n: AstalNotifd.Notification }) => {
|
|||||||
orientation={VERTICAL}
|
orientation={VERTICAL}
|
||||||
spacing={20}
|
spacing={20}
|
||||||
>
|
>
|
||||||
|
<Gtk.EventControllerMotion
|
||||||
|
onEnter={() => timeoutManager.handleHover()}
|
||||||
|
onLeave={() => timeoutManager.handleHoverLost()}
|
||||||
|
/>
|
||||||
|
|
||||||
<box class="header" spacing={10}>
|
<box class="header" spacing={10}>
|
||||||
{(n.appIcon || isIcon(n.desktopEntry)) && (
|
{(n.appIcon || isIcon(n.desktopEntry)) && (
|
||||||
<image
|
<image
|
||||||
|
Reference in New Issue
Block a user