feat(ags): add clicking on notif icon to launch app

This commit is contained in:
matt1432 2023-09-15 15:49:43 -04:00
parent 23ed97ea7b
commit 3d7a45bc51
3 changed files with 77 additions and 31 deletions

15
config/ags/bin/launch-app.sh Executable file
View file

@ -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

View file

@ -11,10 +11,15 @@ export const Draggable = ({
onHoverLost = w => {}, onHoverLost = w => {},
child = '', child = '',
children = [], children = [],
properties = [[]],
...params ...params
}) => { }) => {
let w = EventBox({ let w = EventBox({
...params, ...params,
properties: [
['dragging', false],
...properties,
],
onHover: box => { onHover: box => {
box.window.set_cursor(Gdk.Cursor.new_from_name(display, 'grab')); box.window.set_cursor(Gdk.Cursor.new_from_name(display, 'grab'));
onHover(box); onHover(box);
@ -62,6 +67,8 @@ export const Draggable = ({
'margin-left: -' + Number(offset + startMargin) + 'px;'); 'margin-left: -' + Number(offset + startMargin) + 'px;');
} }
box.get_parent()._dragging = Math.abs(offset) > 10;
if (w.window) if (w.window)
w.window.set_cursor(Gdk.Cursor.new_from_name(display, 'grabbing')); w.window.set_cursor(Gdk.Cursor.new_from_name(display, 'grabbing'));
}, 'drag-update'], }, 'drag-update'],
@ -85,6 +92,8 @@ export const Draggable = ({
'margin-bottom: unset; margin-top: unset; opacity: 1;'); 'margin-bottom: unset; margin-top: unset; opacity: 1;');
if (w.window) if (w.window)
w.window.set_cursor(Gdk.Cursor.new_from_name(display, 'grab')); w.window.set_cursor(Gdk.Cursor.new_from_name(display, 'grab'));
box.get_parent()._dragging = false;
} }
}, 'drag-end'], }, 'drag-end'],

View file

@ -1,15 +1,33 @@
const { GLib } = imports.gi; const { GLib } = imports.gi;
const { Notifications } = ags.Service; const { Notifications, Applications } = ags.Service;
const { lookUpIcon, timeout } = ags.Utils; const { lookUpIcon, timeout, exec } = ags.Utils;
const { Box, Icon, Label, 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 '../misc/cursorbox.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 }) => { 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) { if (image) {
return Box({ return EventBox({
onPrimaryClickRelease: iconCmd,
child: Box({
valign: 'start', valign: 'start',
hexpand: false, hexpand: false,
className: 'icon img', className: 'icon img',
@ -21,6 +39,7 @@ const NotificationIcon = ({ appEntry, appIcon, image }) => {
min-width: 78px; min-width: 78px;
min-height: 78px; min-height: 78px;
`, `,
}),
}); });
} }
@ -33,7 +52,9 @@ const NotificationIcon = ({ appEntry, appIcon, image }) => {
icon = appEntry; icon = appEntry;
} }
return Box({ return EventBox({
onPrimaryClickRelease: iconCmd,
child: Box({
valign: 'start', valign: 'start',
hexpand: false, hexpand: false,
className: 'icon', className: 'icon',
@ -48,6 +69,7 @@ const NotificationIcon = ({ appEntry, appIcon, image }) => {
valign: 'center', valign: 'center',
vexpand: true, vexpand: true,
})], })],
}),
}); });
}; };