2023-11-13 13:19:14 -05:00
|
|
|
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-12-18 23:20:32 -05:00
|
|
|
import { Button, EventBox } from 'resource:///com/github/Aylur/ags/widget.js';
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-09-23 17:06:16 -04:00
|
|
|
import Cairo from 'cairo';
|
2023-12-18 23:20:32 -05:00
|
|
|
const { Gtk, Gdk } = imports.gi;
|
2023-09-23 17:06:16 -04:00
|
|
|
|
2023-10-13 10:25:56 -04:00
|
|
|
import { updateClients } from './clients.js';
|
2023-09-23 17:06:16 -04:00
|
|
|
|
|
|
|
const TARGET = [Gtk.TargetEntry.new('text/plain', Gtk.TargetFlags.SAME_APP, 0)];
|
2024-01-11 10:25:53 -05:00
|
|
|
const display = Gdk.Display.get_default();
|
2023-09-23 17:06:16 -04:00
|
|
|
|
2023-12-23 01:14:21 -05:00
|
|
|
/**
|
|
|
|
* @typedef {import('types/widgets/button').default} Button
|
|
|
|
* @typedef {import('types/widgets/button').ButtonProps} ButtonProps
|
|
|
|
* @typedef {import('types/widgets/eventbox').EventBoxProps=} EventBoxProps
|
|
|
|
* @typedef {import('types/widgets/box').default} Box
|
|
|
|
*/
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-12-23 01:14:21 -05:00
|
|
|
|
|
|
|
/** @param {Button} widget */
|
2023-11-21 01:29:46 -05:00
|
|
|
const createSurfaceFromWidget = (widget) => {
|
2023-10-20 23:11:21 -04:00
|
|
|
const alloc = widget.get_allocation();
|
|
|
|
const surface = new Cairo.ImageSurface(
|
|
|
|
Cairo.Format.ARGB32,
|
|
|
|
alloc.width,
|
|
|
|
alloc.height,
|
|
|
|
);
|
|
|
|
const cr = new Cairo.Context(surface);
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
cr.setSourceRGBA(255, 255, 255, 0);
|
|
|
|
cr.rectangle(0, 0, alloc.width, alloc.height);
|
|
|
|
cr.fill();
|
|
|
|
widget.draw(cr);
|
2023-09-23 17:06:16 -04:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
return surface;
|
2023-11-21 01:29:46 -05:00
|
|
|
};
|
2023-09-23 17:06:16 -04:00
|
|
|
|
2023-09-24 16:29:56 -04:00
|
|
|
let hidden = 0;
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-12-23 01:14:21 -05:00
|
|
|
/** @params {EventBoxProps} props */
|
|
|
|
export const WorkspaceDrop = ({ ...props }) => EventBox({
|
2023-10-20 23:11:21 -04:00
|
|
|
...props,
|
2023-12-17 00:01:58 -05:00
|
|
|
setup: (self) => {
|
|
|
|
self.drag_dest_set(Gtk.DestDefaults.ALL, TARGET, Gdk.DragAction.COPY);
|
2023-09-24 16:30:48 -04:00
|
|
|
|
2023-12-17 00:01:58 -05:00
|
|
|
self.on('drag-data-received', (_, _c, _x, _y, data) => {
|
2023-12-23 01:14:21 -05:00
|
|
|
// @ts-expect-error
|
|
|
|
let id = self.get_parent()?.attribute.id;
|
2023-10-20 23:11:21 -04:00
|
|
|
|
2023-12-17 00:01:58 -05:00
|
|
|
if (id < -1) {
|
2023-12-23 01:14:21 -05:00
|
|
|
// @ts-expect-error
|
|
|
|
id = self.get_parent()?.attribute.name;
|
2023-12-17 00:01:58 -05:00
|
|
|
}
|
2023-10-20 23:11:21 -04:00
|
|
|
|
2023-12-17 00:01:58 -05:00
|
|
|
else if (id === -1) {
|
|
|
|
id = `special:${++hidden}`;
|
|
|
|
}
|
2023-10-20 23:11:21 -04:00
|
|
|
|
2023-12-17 00:01:58 -05:00
|
|
|
else if (id === 1000) {
|
|
|
|
id = 'empty';
|
|
|
|
}
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-12-17 00:01:58 -05:00
|
|
|
Hyprland.sendMessage('dispatch ' +
|
|
|
|
`movetoworkspacesilent ${id},address:${data.get_text()}`)
|
|
|
|
.catch(print);
|
|
|
|
});
|
2023-10-20 23:11:21 -04:00
|
|
|
},
|
2023-09-23 17:06:16 -04:00
|
|
|
});
|
|
|
|
|
2023-12-23 01:14:21 -05:00
|
|
|
/**
|
|
|
|
* @param {ButtonProps & {
|
|
|
|
* address: string
|
|
|
|
* mainBox: Box
|
|
|
|
* }} o
|
|
|
|
*/
|
2023-12-18 23:20:32 -05:00
|
|
|
export const WindowButton = ({
|
|
|
|
address,
|
|
|
|
mainBox,
|
|
|
|
...props
|
2023-12-23 01:14:21 -05:00
|
|
|
}) => Button({
|
2023-10-20 23:11:21 -04:00
|
|
|
...props,
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
setup: (self) => {
|
|
|
|
self.drag_source_set(
|
|
|
|
Gdk.ModifierType.BUTTON1_MASK,
|
|
|
|
TARGET,
|
|
|
|
Gdk.DragAction.COPY,
|
|
|
|
);
|
|
|
|
|
2024-01-11 10:25:53 -05:00
|
|
|
self
|
|
|
|
.on('drag-data-get', (_w, _c, data) => {
|
|
|
|
data.set_text(address, address.length);
|
|
|
|
})
|
2023-10-12 18:10:39 -04:00
|
|
|
|
2024-01-11 10:25:53 -05:00
|
|
|
.on('drag-begin', (_, context) => {
|
|
|
|
Gtk.drag_set_icon_surface(
|
|
|
|
context,
|
|
|
|
createSurfaceFromWidget(self),
|
|
|
|
);
|
|
|
|
// @ts-expect-error
|
|
|
|
self.get_parent()?.set_reveal_child(false);
|
|
|
|
})
|
|
|
|
|
|
|
|
.on('drag-end', () => {
|
|
|
|
self.get_parent()?.destroy();
|
|
|
|
|
|
|
|
updateClients(mainBox);
|
|
|
|
})
|
|
|
|
|
|
|
|
// OnHover
|
|
|
|
.on('enter-notify-event', () => {
|
|
|
|
self.window.set_cursor(Gdk.Cursor.new_from_name(
|
|
|
|
display,
|
|
|
|
'pointer',
|
|
|
|
));
|
|
|
|
self.toggleClassName('hover', true);
|
|
|
|
})
|
|
|
|
|
|
|
|
// OnHoverLost
|
|
|
|
.on('leave-notify-event', () => {
|
|
|
|
self.window.set_cursor(null);
|
|
|
|
self.toggleClassName('hover', false);
|
|
|
|
});
|
2023-10-20 23:11:21 -04:00
|
|
|
},
|
2023-09-23 17:06:16 -04:00
|
|
|
});
|