diff --git a/config/ags/bin/launch-app.sh b/config/ags/bin/launch-app.sh new file mode 100755 index 0000000..894ad6e --- /dev/null +++ b/config/ags/bin/launch-app.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +APP="$1" +EXEC="$2" + +if [[ "$APP" == "thunderbird" ]]; then + hyprctl dispatch togglespecialworkspace thunder +elif [[ "$APP" == "dev.alextren.Spot" ]]; then + hyprctl dispatch togglespecialworkspace spot +elif [[ $(hyprctl clients | grep "$APP") != "" ]]; then + hyprctl dispatch focuswindow "^($APP)$" +else + hyprctl dispatch workspace empty + hyprctl dispatch exec "$EXEC" +fi diff --git a/config/ags/js/misc/drag.js b/config/ags/js/misc/drag.js index 19332aa..6b3477c 100644 --- a/config/ags/js/misc/drag.js +++ b/config/ags/js/misc/drag.js @@ -11,10 +11,15 @@ export const Draggable = ({ onHoverLost = w => {}, child = '', children = [], + properties = [[]], ...params }) => { let w = EventBox({ ...params, + properties: [ + ['dragging', false], + ...properties, + ], onHover: box => { box.window.set_cursor(Gdk.Cursor.new_from_name(display, 'grab')); onHover(box); @@ -61,7 +66,9 @@ export const Draggable = ({ box.setStyle('margin-right: ' + Number(offset + startMargin) + 'px; ' + 'margin-left: -' + Number(offset + startMargin) + 'px;'); } - + + box.get_parent()._dragging = Math.abs(offset) > 10; + if (w.window) w.window.set_cursor(Gdk.Cursor.new_from_name(display, 'grabbing')); }, 'drag-update'], @@ -85,6 +92,8 @@ export const Draggable = ({ 'margin-bottom: unset; margin-top: unset; opacity: 1;'); if (w.window) w.window.set_cursor(Gdk.Cursor.new_from_name(display, 'grab')); + + box.get_parent()._dragging = false; } }, 'drag-end'], diff --git a/config/ags/js/notifications/base.js b/config/ags/js/notifications/base.js index d4f4516..a36e6d8 100644 --- a/config/ags/js/notifications/base.js +++ b/config/ags/js/notifications/base.js @@ -1,26 +1,45 @@ const { GLib } = imports.gi; -const { Notifications } = ags.Service; -const { lookUpIcon, timeout } = ags.Utils; +const { Notifications, Applications } = ags.Service; +const { lookUpIcon, timeout, exec } = ags.Utils; const { Box, Icon, Label, Button } = ags.Widget; import { Draggable } from '../misc/drag.js'; import { EventBox } from '../misc/cursorbox.js' +import { closeAll } from '../misc/closer.js'; -// TODO: launch app when click on icon const NotificationIcon = ({ appEntry, appIcon, image }) => { + let iconCmd = () => {}; + + if (Applications.query(appEntry).length > 0) { + let app = Applications.query(appEntry)[0]; + + if (app.app.get_string('StartupWMClass') != null) { + iconCmd = box => { + if (!box.get_parent().get_parent().get_parent().get_parent().get_parent()._dragging) { + exec('bash -c "$AGS_PATH/launch-app.sh ' + app.app.get_string('StartupWMClass') + + ' ' + app.app.get_string('Exec') + '"'); + closeAll(); + } + } + } + } + if (image) { - return Box({ - valign: 'start', - hexpand: false, - className: 'icon img', - style: ` - background-image: url("${image}"); - background-size: contain; - background-repeat: no-repeat; - background-position: center; - min-width: 78px; - min-height: 78px; - `, + return EventBox({ + onPrimaryClickRelease: iconCmd, + child: Box({ + valign: 'start', + hexpand: false, + className: 'icon img', + style: ` + background-image: url("${image}"); + background-size: contain; + background-repeat: no-repeat; + background-position: center; + min-width: 78px; + min-height: 78px; + `, + }), }); } @@ -33,21 +52,24 @@ const NotificationIcon = ({ appEntry, appIcon, image }) => { icon = appEntry; } - return Box({ - valign: 'start', - hexpand: false, - className: 'icon', - style: ` - min-width: 78px; - min-height: 78px; - `, - children: [Icon({ - icon, size: 58, - halign: 'center', - hexpand: true, - valign: 'center', - vexpand: true, - })], + return EventBox({ + onPrimaryClickRelease: iconCmd, + child: Box({ + valign: 'start', + hexpand: false, + className: 'icon', + style: ` + min-width: 78px; + min-height: 78px; + `, + children: [Icon({ + icon, size: 58, + halign: 'center', + hexpand: true, + valign: 'center', + vexpand: true, + })], + }), }); };