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);
@ -61,7 +66,9 @@ export const Draggable = ({
box.setStyle('margin-right: ' + Number(offset + startMargin) + 'px; ' + box.setStyle('margin-right: ' + Number(offset + startMargin) + 'px; ' +
'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,26 +1,45 @@
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({
valign: 'start', onPrimaryClickRelease: iconCmd,
hexpand: false, child: Box({
className: 'icon img', valign: 'start',
style: ` hexpand: false,
background-image: url("${image}"); className: 'icon img',
background-size: contain; style: `
background-repeat: no-repeat; background-image: url("${image}");
background-position: center; background-size: contain;
min-width: 78px; background-repeat: no-repeat;
min-height: 78px; background-position: center;
`, min-width: 78px;
min-height: 78px;
`,
}),
}); });
} }
@ -33,21 +52,24 @@ const NotificationIcon = ({ appEntry, appIcon, image }) => {
icon = appEntry; icon = appEntry;
} }
return Box({ return EventBox({
valign: 'start', onPrimaryClickRelease: iconCmd,
hexpand: false, child: Box({
className: 'icon', valign: 'start',
style: ` hexpand: false,
min-width: 78px; className: 'icon',
min-height: 78px; style: `
`, min-width: 78px;
children: [Icon({ min-height: 78px;
icon, size: 58, `,
halign: 'center', children: [Icon({
hexpand: true, icon, size: 58,
valign: 'center', halign: 'center',
vexpand: true, hexpand: true,
})], valign: 'center',
vexpand: true,
})],
}),
}); });
}; };