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
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
// Types
|
|
|
|
import AgsBox from 'types/widgets/box.js';
|
|
|
|
import AgsButton from 'types/widgets/button.js';
|
|
|
|
import AgsRevealer from 'types/widgets/revealer.js';
|
|
|
|
import { ButtonProps } from 'types/widgets/button.js';
|
|
|
|
import { EventBoxProps } from 'types/widgets/eventbox.js';
|
|
|
|
type WindowButtonType = ButtonProps & {
|
|
|
|
address: string
|
|
|
|
mainBox: AgsBox
|
|
|
|
};
|
2023-10-02 12:06:35 -04:00
|
|
|
|
2023-12-23 01:14:21 -05:00
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
const createSurfaceFromWidget = (widget: AgsButton) => {
|
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
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
export const WorkspaceDrop = ({ ...props }: EventBoxProps) => 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) => {
|
2024-01-13 11:15:08 -05:00
|
|
|
let id = (self.get_parent() as AgsRevealer)?.attribute.id;
|
2023-10-20 23:11:21 -04:00
|
|
|
|
2023-12-17 00:01:58 -05:00
|
|
|
if (id < -1) {
|
2024-01-13 11:15:08 -05:00
|
|
|
id = (self.get_parent() as AgsRevealer)?.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-18 23:20:32 -05:00
|
|
|
export const WindowButton = ({
|
|
|
|
address,
|
|
|
|
mainBox,
|
|
|
|
...props
|
2024-01-13 11:15:08 -05:00
|
|
|
}: WindowButtonType) => 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),
|
|
|
|
);
|
2024-01-13 11:15:08 -05:00
|
|
|
(self.get_parent() as AgsRevealer)?.set_reveal_child(false);
|
2024-01-11 10:25:53 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
.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
|
|
|
});
|