Skip to content

Commit

Permalink
hold notif to copy (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
end-4 committed Feb 2, 2024
1 parent b1759bf commit 8589654
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 32 deletions.
74 changes: 47 additions & 27 deletions .config/ags/lib/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,32 @@ export default ({
},
onMiddleClick: (self) => {
destroyWithAnims();
},
setup: (self) => {
self.on("button-press-event", () => {
wholeThing.attribute.held = true;
notificationContent.toggleClassName(`${isPopup ? 'popup-' : ''}notif-clicked-${notifObject.urgency}`, true);
Utils.timeout(800, () => {
if (wholeThing.attribute.held) {
Utils.execAsync(['wl-copy', `${notifObject.body}`])
notifTextSummary.label = notifObject.summary + " (copied)";
Utils.timeout(3000, () => notifTextSummary.label = notifObject.summary)
}
})
}).on("button-release-event", () => {
wholeThing.attribute.held = false;
notificationContent.toggleClassName(`${isPopup ? 'popup-' : ''}notif-clicked-${notifObject.urgency}`, false);
})
}
});
const wholeThing = Revealer({
attribute: {
'id': notifObject.id,
'close': undefined,
'hovered': false,
'dragging': false,
'destroyWithAnims': () => destroyWithAnims,
'dragging': false,
'held': false,
'hovered': false,
'id': notifObject.id,
},
revealChild: false,
transition: 'slide_down',
Expand Down Expand Up @@ -205,30 +222,32 @@ export default ({
notifTime = 'Yesterday';
else
notifTime = messageTime.format('%d/%m');
const notifTextSummary = Label({
xalign: 0,
className: 'txt-small txt-semibold titlefont',
justify: Gtk.Justification.LEFT,
hexpand: true,
maxWidthChars: 24,
truncate: 'end',
ellipsize: 3,
useMarkup: notifObject.summary.startsWith('<'),
label: notifObject.summary,
});
const notifTextBody = Label({
vpack: 'center',
justification: 'right',
className: 'txt-smaller txt-semibold',
label: notifTime,
});
const notifText = Box({
valign: Gtk.Align.CENTER,
vertical: true,
hexpand: true,
children: [
Box({
children: [
Label({
xalign: 0,
className: 'txt-small txt-semibold titlefont',
justify: Gtk.Justification.LEFT,
hexpand: true,
maxWidthChars: 24,
truncate: 'end',
ellipsize: 3,
useMarkup: notifObject.summary.startsWith('<'),
label: notifObject.summary,
}),
Label({
vpack: 'center',
justification: 'right',
className: 'txt-smaller txt-semibold',
label: notifTime,
}),
notifTextSummary,
notifTextBody,
]
}),
notifTextPreview,
Expand Down Expand Up @@ -313,6 +332,7 @@ export default ({
.hook(gesture, self => {
var offset_x = gesture.get_offset()[1];
var offset_y = gesture.get_offset()[2];
// Which dir?
if (initDirVertical == -1) {
if (Math.abs(offset_y) > MOVE_THRESHOLD)
initDirVertical = 1;
Expand All @@ -321,7 +341,7 @@ export default ({
initDirX = (offset_x > 0 ? 1 : -1);
}
}

// Horizontal drag
if (initDirVertical == 0 && offset_x > MOVE_THRESHOLD) {
if (initDirX < 0)
self.setCss(`margin-left: 0px; margin-right: 0px;`);
Expand All @@ -342,12 +362,12 @@ export default ({
`);
}
}

wholeThing.attribute.dragging = Math.abs(offset_x) > 10;

if (widget.window)
widget.window.set_cursor(Gdk.Cursor.new_from_name(display, 'grabbing'));

// Update dragging
wholeThing.attribute.dragging = Math.abs(offset_x) > MOVE_THRESHOLD;
if (Math.abs(offset_x) > MOVE_THRESHOLD ||
Math.abs(offset_y) > MOVE_THRESHOLD) wholeThing.attribute.held = false;
widget.window?.set_cursor(Gdk.Cursor.new_from_name(display, 'grabbing'));
// Vertical drag
if (initDirVertical == 1 && offset_y > MOVE_THRESHOLD && !expanded) {
notifTextPreview.revealChild = false;
notifTextExpanded.revealChild = true;
Expand Down
32 changes: 27 additions & 5 deletions .config/ags/scss/_notifications.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ $notif_surface: $t_background;
padding-right: $rounding_small + 0.545rem;
}

.notif-clicked-low {
background-color: mix($l_l_t_surfaceVariant, $t_onSurfaceVariant, 85%);
}

.notif-clicked-normal {
background-color: mix($l_l_t_surfaceVariant, $t_onSurfaceVariant, 85%);
}

.notif-clicked-critical {
background-color: mix($secondaryContainer, $onSecondaryContainer, 95%);
}

.popup-notif-low {
@include notif-rounding;
min-width: 30.682rem;
Expand Down Expand Up @@ -55,6 +67,18 @@ $notif_surface: $t_background;
padding-right: $rounding_small + 0.545rem;
}

.popup-notif-clicked-low {
background-color: mix($notif_surface, $onBackground, 94%);
}

.popup-notif-clicked-normal {
background-color: mix($notif_surface, $onBackground, 94%);
}

.popup-notif-clicked-critical {
background-color: mix($secondaryContainer, $onSecondaryContainer, 96%);
}

.notif-body-low {
color: mix($onSurfaceVariant, $surfaceVariant, 67%);
}
Expand Down Expand Up @@ -138,10 +162,8 @@ $notif_surface: $t_background;

.osd-notif {
@include notif-rounding;
background-color: transparentize(
$background,
$transparentize_surface_amount_subtract_surface
);
background-color: transparentize($background,
$transparentize_surface_amount_subtract_surface );
min-width: 30.682rem;
}

Expand Down Expand Up @@ -217,4 +239,4 @@ $notif_surface: $t_background;

.notif-action-critical:active {
background-color: mix($t_onSecondaryContainer, $t_secondaryContainer, 23%);
}
}

0 comments on commit 8589654

Please sign in to comment.