2023-09-23 17:06:16 -04:00
|
|
|
const { Gtk, Gdk } = imports.gi;
|
|
|
|
const { EventBox } = ags.Widget;
|
|
|
|
const { execAsync } = ags.Utils;
|
|
|
|
const { getWindow } = ags.App;
|
|
|
|
import Cairo from 'cairo';
|
|
|
|
|
|
|
|
import { Button } from '../misc/cursorbox.js';
|
|
|
|
|
|
|
|
|
|
|
|
const TARGET = [Gtk.TargetEntry.new('text/plain', Gtk.TargetFlags.SAME_APP, 0)];
|
|
|
|
|
|
|
|
function createSurfaceFromWidget(widget) {
|
|
|
|
const alloc = widget.get_allocation();
|
|
|
|
const surface = new Cairo.ImageSurface(
|
|
|
|
Cairo.Format.ARGB32,
|
|
|
|
alloc.width,
|
|
|
|
alloc.height,
|
|
|
|
);
|
|
|
|
const cr = new Cairo.Context(surface);
|
|
|
|
cr.setSourceRGBA(255, 255, 255, 0);
|
|
|
|
cr.rectangle(0, 0, alloc.width, alloc.height);
|
|
|
|
cr.fill();
|
|
|
|
widget.draw(cr);
|
|
|
|
|
|
|
|
return surface;
|
|
|
|
};
|
|
|
|
|
2023-09-24 16:29:56 -04:00
|
|
|
let hidden = 0;
|
|
|
|
export const WorkspaceDrop = params => EventBox({
|
2023-09-23 17:06:16 -04:00
|
|
|
...params,
|
2023-09-23 21:34:49 -04:00
|
|
|
//tooltipText: `Workspace: ${id}`,
|
2023-09-24 16:30:48 -04:00
|
|
|
connections: [['drag-data-received', (eventbox, _c, _x, _y, data) => {
|
2023-09-24 16:29:56 -04:00
|
|
|
let id = eventbox.get_parent()._id;
|
2023-09-24 16:30:48 -04:00
|
|
|
|
|
|
|
if (id < -1) {
|
2023-09-24 16:29:56 -04:00
|
|
|
id = eventbox.get_parent()._name;
|
2023-09-24 16:30:48 -04:00
|
|
|
}
|
|
|
|
else if (id === -1) {
|
2023-09-24 16:29:56 -04:00
|
|
|
id = `special:${++hidden}`;
|
2023-09-24 16:30:48 -04:00
|
|
|
}
|
|
|
|
else if (id === 1000) {
|
2023-09-23 21:34:49 -04:00
|
|
|
id = "empty";
|
2023-09-24 16:30:48 -04:00
|
|
|
}
|
2023-09-24 16:29:56 -04:00
|
|
|
execAsync(`hyprctl dispatch movetoworkspacesilent ${id},address:${data.get_text()}`)
|
|
|
|
.catch(print);
|
|
|
|
}]],
|
|
|
|
setup: eventbox => {
|
2023-09-23 17:06:16 -04:00
|
|
|
eventbox.drag_dest_set(Gtk.DestDefaults.ALL, TARGET, Gdk.DragAction.COPY);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export const WindowButton = ({address, ...params} = {}) => Button({
|
|
|
|
...params,
|
|
|
|
setup: button => {
|
|
|
|
button.drag_source_set(Gdk.ModifierType.BUTTON1_MASK, TARGET, Gdk.DragAction.COPY);
|
|
|
|
button.connect('drag-data-get', (_w, _c, data) => {
|
|
|
|
data.set_text(address, address.length);
|
|
|
|
});
|
|
|
|
button.connect('drag-begin', (_, context) => {
|
|
|
|
Gtk.drag_set_icon_surface(context, createSurfaceFromWidget(button));
|
|
|
|
button.get_parent().revealChild = false;
|
|
|
|
});
|
|
|
|
button.connect('drag-end', () => {
|
|
|
|
button.get_parent().destroy();
|
2023-09-27 22:20:21 -04:00
|
|
|
let mainBox = getWindow('overview').child.children[0].child;
|
2023-09-23 18:41:05 -04:00
|
|
|
mainBox._updateClients(mainBox);
|
2023-09-23 17:06:16 -04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|