feat: on hover only show actions if available on notifications (#396)

* feat: on hover only show actions if available on notifications

* feat: on hover only show actions if available on notifications

* fix: make the change configurable

* fix: remove unneeded op
This commit is contained in:
Rubin Bhandari
2024-11-05 12:32:26 +05:45
committed by GitHub
parent b5e91fa2dc
commit b88644833d
4 changed files with 77 additions and 27 deletions

View File

@@ -14,7 +14,8 @@ import Box from 'types/widgets/box.js';
import { Attribute, Child } from 'lib/types/widget.js';
const hyprland = await Service.import('hyprland');
const { position, timeout, cache_actions, monitor, active_monitor, displayedTotal, ignore } = options.notifications;
const { position, timeout, cache_actions, monitor, active_monitor, displayedTotal, ignore, showActionsOnHover } =
options.notifications;
const curMonitor = Variable(monitor.value);
@@ -50,15 +51,32 @@ export default (): Window<Box<Child, Attribute>, unknown> => {
hexpand: true,
setup: (self) => {
Utils.merge(
[notifs.bind('popups'), ignore.bind('value')],
(notifications: Notification[], ignoredNotifs: string[]) => {
[notifs.bind('popups'), ignore.bind('value'), showActionsOnHover.bind('value')],
(notifications: Notification[], ignoredNotifs: string[], showActions: boolean) => {
const filteredNotifications = filterNotifications(notifications, ignoredNotifs);
return (self.children = filteredNotifications.slice(0, displayedTotal.value).map((notif) => {
const actionsbox =
notif.actions.length > 0
? Widget.Revealer({
transition: 'slide_down',
reveal_child: showActions ? false : true,
child: Widget.EventBox({
child: Action(notif, notifs),
}),
})
: null;
return Widget.EventBox({
on_secondary_click: () => {
notifs.CloseNotification(notif.id);
},
on_hover() {
if (actionsbox && showActions) actionsbox.reveal_child = true;
},
on_hover_lost() {
if (actionsbox && showActions) actionsbox.reveal_child = false;
},
child: Widget.Box({
class_name: 'notification-card',
vpack: 'start',
@@ -70,7 +88,9 @@ export default (): Window<Box<Child, Attribute>, unknown> => {
vertical: true,
hexpand: true,
class_name: `notification-card-content ${!notifHasImg(notif) ? 'noimg' : ''}`,
children: [Header(notif), Body(notif), Action(notif, notifs)],
children: actionsbox
? [Header(notif), Body(notif), actionsbox]
: [Header(notif), Body(notif)],
}),
CloseButton(notif, notifs),
],