From b6b061b1729b72a36fd1c5f0585c6d7b39a16013 Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Fri, 2 Feb 2024 19:23:05 +0700 Subject: [PATCH] hold notif to copy (#224) --- .config/ags/lib/notification.js | 74 ++++++++++++++++++---------- .config/ags/scss/_notifications.scss | 32 ++++++++++-- 2 files changed, 74 insertions(+), 32 deletions(-) diff --git a/.config/ags/lib/notification.js b/.config/ags/lib/notification.js index 1189b62fa..8d3a8b43c 100644 --- a/.config/ags/lib/notification.js +++ b/.config/ags/lib/notification.js @@ -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', @@ -205,6 +222,23 @@ 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, @@ -212,23 +246,8 @@ export default ({ 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, @@ -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; @@ -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;`); @@ -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; diff --git a/.config/ags/scss/_notifications.scss b/.config/ags/scss/_notifications.scss index 24357c0b4..a5de8e7c5 100644 --- a/.config/ags/scss/_notifications.scss +++ b/.config/ags/scss/_notifications.scss @@ -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; @@ -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%); } @@ -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; } @@ -217,4 +239,4 @@ $notif_surface: $t_background; .notif-action-critical:active { background-color: mix($t_onSecondaryContainer, $t_secondaryContainer, 23%); -} +} \ No newline at end of file