refactor(ags): change some cursor code

This commit is contained in:
matt1432 2023-09-11 19:28:22 -04:00
parent 5f59cd56d2
commit 55577e48a2
5 changed files with 128 additions and 144 deletions

View file

@ -19,7 +19,7 @@ export const Separator = width => ags.Widget.Box({
import Gdk from 'gi://Gdk'; import Gdk from 'gi://Gdk';
const display = Gdk.Display.get_default(); const display = Gdk.Display.get_default();
export const EventBox = ({ ...params }) => ags.Widget.EventBox({ export const EventBox = ({ reset = true, ...params }) => ags.Widget.EventBox({
...params, ...params,
onHover: box => { onHover: box => {
if (! box.child.sensitive || ! box.sensitive) { if (! box.child.sensitive || ! box.sensitive) {
@ -30,6 +30,7 @@ export const EventBox = ({ ...params }) => ags.Widget.EventBox({
} }
}, },
onHoverLost: box => { onHoverLost: box => {
if (reset)
box.window.set_cursor(null); box.window.set_cursor(null);
}, },
}); });

View file

@ -64,6 +64,7 @@ export const Draggable = ({
w.window.set_cursor(Gdk.Cursor.new_from_name(display, 'grab')); w.window.set_cursor(Gdk.Cursor.new_from_name(display, 'grab'));
} }
}, 'drag-end'], }, 'drag-end'],
], ],
}); });

View file

@ -1,9 +1,10 @@
const { GLib } = imports.gi; const { GLib } = imports.gi;
const { Notifications } = ags.Service; const { Notifications } = ags.Service;
const { lookUpIcon, timeout } = ags.Utils; const { lookUpIcon, timeout } = ags.Utils;
const { Box, Icon, Label, EventBox, Button } = ags.Widget; const { Box, Icon, Label, Button } = ags.Widget;
import { Draggable } from '../misc/drag.js'; import { Draggable } from '../misc/drag.js';
import { EventBox } from '../common.js'
const NotificationIcon = ({ appEntry, appIcon, image }) => { const NotificationIcon = ({ appEntry, appIcon, image }) => {
if (image) { if (image) {
@ -53,25 +54,6 @@ export default ({ id, summary, body, actions, urgency, time, ...icon }) => Dragg
maxOffset: 200, maxOffset: 200,
command: () => Notifications.close(id), command: () => Notifications.close(id),
/// Port of Aylur's notification
properties: [['hovered', false]],
addOnHover: w => {
if (w._hovered) {
return;
}
timeout(300, () => w._hovered = true);
},
addOnHoverLost: w => {
if (!w._hovered) {
return;
}
w._hovered = false;
Notifications.dismiss(id);
},
///
child: Box({ child: Box({
className: `notification ${urgency}`, className: `notification ${urgency}`,
vexpand: false, vexpand: false,
@ -106,12 +88,15 @@ export default ({ id, summary, body, actions, urgency, time, ...icon }) => Dragg
valign: 'start', valign: 'start',
label: GLib.DateTime.new_from_unix_local(time).format('%H:%M'), label: GLib.DateTime.new_from_unix_local(time).format('%H:%M'),
}), }),
Button({ EventBox({
reset: false,
child: Button({
className: 'close-button', className: 'close-button',
valign: 'start', valign: 'start',
onClicked: () => Notifications.close(id), onClicked: () => Notifications.close(id),
child: Icon('window-close-symbolic'), child: Icon('window-close-symbolic'),
}), }),
}),
], ],
}), }),
Label({ Label({

View file

@ -16,10 +16,9 @@ $background-color_10: rgba(238, 238, 238, 0.5);
} }
.notification { .notification {
>box { >box {
padding: 9px;
all: unset; all: unset;
box-shadow: 0 0 4.5px 0 rgba(0, 0, 0, 0.4); box-shadow: 0 0 4.5px 0 rgba(0, 0, 0, 0.4);
margin: 9px; margin: 9px 9px 0 9px;
border: 2px solid $contrastbg; border: 2px solid $contrastbg;
border-radius: 15px; border-radius: 15px;
background-color: $bg; background-color: $bg;
@ -178,4 +177,3 @@ $background-color_10: rgba(238, 238, 238, 0.5);
} }
} }
} }

View file

@ -262,10 +262,9 @@ tooltip {
box-shadow: inset 0 0 0.5em 0 #e67090; } box-shadow: inset 0 0 0.5em 0 #e67090; }
.notification > box { .notification > box {
padding: 9px;
all: unset; all: unset;
box-shadow: 0 0 4.5px 0 rgba(0, 0, 0, 0.4); box-shadow: 0 0 4.5px 0 rgba(0, 0, 0, 0.4);
margin: 9px; margin: 9px 9px 0 9px;
border: 2px solid rgba(189, 147, 249, 0.8); border: 2px solid rgba(189, 147, 249, 0.8);
border-radius: 15px; border-radius: 15px;
background-color: rgba(40, 42, 54, 0.8); background-color: rgba(40, 42, 54, 0.8);