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:
@@ -12,7 +12,7 @@ import { filterNotifications } from 'lib/shared/notifications.js';
|
||||
import Scrollable from 'types/widgets/scrollable.js';
|
||||
import { Attribute, Child } from 'lib/types/widget.js';
|
||||
|
||||
const { displayedTotal, ignore } = options.notifications;
|
||||
const { displayedTotal, ignore, showActionsOnHover } = options.notifications;
|
||||
|
||||
const NotificationCard = (notifs: Notifications, curPage: Variable<number>): Scrollable<Child, Attribute> => {
|
||||
return Widget.Scrollable({
|
||||
@@ -30,8 +30,9 @@ const NotificationCard = (notifs: Notifications, curPage: Variable<number>): Scr
|
||||
curPage.bind('value'),
|
||||
displayedTotal.bind('value'),
|
||||
ignore.bind('value'),
|
||||
showActionsOnHover.bind('value'),
|
||||
],
|
||||
(notifications, currentPage, dispTotal, ignoredNotifs) => {
|
||||
(notifications, currentPage, dispTotal, ignoredNotifs, showActions) => {
|
||||
const filteredNotifications = filterNotifications(notifications, ignoredNotifs);
|
||||
|
||||
const sortedNotifications = filteredNotifications.sort((a, b) => b.time - a.time);
|
||||
@@ -45,7 +46,25 @@ const NotificationCard = (notifs: Notifications, curPage: Variable<number>): Scr
|
||||
return (self.children = sortedNotifications
|
||||
.slice(pageStart, pageEnd)
|
||||
.map((notif: Notification) => {
|
||||
return Widget.Box({
|
||||
const actionsbox =
|
||||
notif.actions.length > 0
|
||||
? Widget.Revealer({
|
||||
transition: 'slide_down',
|
||||
reveal_child: showActions ? false : true,
|
||||
child: Widget.EventBox({
|
||||
child: Actions(notif, notifs),
|
||||
}),
|
||||
})
|
||||
: null;
|
||||
|
||||
return Widget.EventBox({
|
||||
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-content-container',
|
||||
children: [
|
||||
Widget.Box({
|
||||
@@ -60,12 +79,16 @@ const NotificationCard = (notifs: Notifications, curPage: Variable<number>): Scr
|
||||
vertical: true,
|
||||
hexpand: true,
|
||||
class_name: `notification-card-content ${!notifHasImg(notif) ? 'noimg' : ' menu'}`,
|
||||
children: [Header(notif), Body(notif), Actions(notif, notifs)],
|
||||
|
||||
children: actionsbox
|
||||
? [Header(notif), Body(notif), actionsbox]
|
||||
: [Header(notif), Body(notif)],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
CloseButton(notif, notifs),
|
||||
],
|
||||
}),
|
||||
});
|
||||
}));
|
||||
},
|
||||
|
||||
@@ -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),
|
||||
],
|
||||
|
||||
@@ -1211,6 +1211,7 @@ const options = mkOptions(OPTIONS, {
|
||||
displayedTotal: opt(10),
|
||||
monitor: opt(0),
|
||||
active_monitor: opt(true),
|
||||
showActionsOnHover: opt(false),
|
||||
timeout: opt(7000),
|
||||
cache_actions: opt(true),
|
||||
clearDelay: opt(100),
|
||||
|
||||
@@ -39,6 +39,12 @@ export const NotificationSettings = (): Scrollable<Child, Attribute> => {
|
||||
subtitle: 'The ID of the monitor on which to display the notification',
|
||||
type: 'number',
|
||||
}),
|
||||
Option({
|
||||
opt: options.notifications.showActionsOnHover,
|
||||
title: 'Show Actions only on Hover',
|
||||
subtitle: 'Show the action buttons only when hovering over a notification',
|
||||
type: 'boolean',
|
||||
}),
|
||||
Option({
|
||||
opt: options.notifications.active_monitor,
|
||||
title: 'Follow Cursor',
|
||||
|
||||
Reference in New Issue
Block a user