2023-11-19 20:39:08 -05:00
|
|
|
import { execAsync, timeout } from 'resource:///com/github/Aylur/ags/utils.js';
|
|
|
|
|
2023-11-19 15:00:29 -05:00
|
|
|
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
|
2023-11-19 20:39:08 -05:00
|
|
|
|
2023-11-19 15:00:29 -05:00
|
|
|
import Gtk from 'gi://Gtk';
|
|
|
|
|
|
|
|
|
2023-11-19 20:39:08 -05:00
|
|
|
const releaseAllKeys = () => {
|
|
|
|
const keycodes = Array.from(Array(249).keys());
|
|
|
|
execAsync([
|
|
|
|
'ydotool', 'key',
|
|
|
|
...keycodes.map(keycode => `${keycode}:0`),
|
|
|
|
]).catch(print);
|
|
|
|
};
|
|
|
|
|
|
|
|
const hidden = 340;
|
2023-11-19 15:00:29 -05:00
|
|
|
export default window => {
|
2023-11-19 20:39:08 -05:00
|
|
|
window.child.setCss(`margin-bottom: -${hidden}px;`);
|
2023-11-19 15:00:29 -05:00
|
|
|
const gesture = Gtk.GestureDrag.new(window);
|
|
|
|
|
2023-11-19 20:39:08 -05:00
|
|
|
window.setVisible = state => {
|
|
|
|
if (state) {
|
|
|
|
window.visible = true;
|
|
|
|
window.setSlideDown();
|
|
|
|
window.child.setCss(`
|
|
|
|
transition: margin-bottom 0.7s cubic-bezier(0.36, 0, 0.66, -0.56);
|
|
|
|
margin-bottom: 0px;
|
|
|
|
`);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
timeout(710, () => {
|
|
|
|
if (!Tablet.tabletMode)
|
|
|
|
window.visible = false;
|
|
|
|
});
|
|
|
|
releaseAllKeys();
|
|
|
|
window.setSlideUp();
|
|
|
|
window.child.setCss(`
|
|
|
|
transition: margin-bottom 0.7s cubic-bezier(0.36, 0, 0.66, -0.56);
|
|
|
|
margin-bottom: -${hidden}px;
|
|
|
|
`);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-11-19 15:00:29 -05:00
|
|
|
gesture.signals = [];
|
|
|
|
window.killGestureSigs = () => {
|
|
|
|
gesture.signals.forEach(id => gesture.disconnect(id));
|
|
|
|
gesture.signals = [];
|
|
|
|
};
|
|
|
|
|
|
|
|
window.setSlideUp = () => {
|
|
|
|
window.killGestureSigs();
|
|
|
|
|
|
|
|
// Begin drag
|
|
|
|
gesture.signals.push(
|
|
|
|
gesture.connect('drag-begin', () => {
|
|
|
|
Hyprland.sendMessage('j/cursorpos').then(out => {
|
|
|
|
gesture.startY = JSON.parse(out).y;
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
// Update drag
|
|
|
|
gesture.signals.push(
|
|
|
|
gesture.connect('drag-update', () => {
|
|
|
|
Hyprland.sendMessage('j/cursorpos').then(out => {
|
|
|
|
const currentY = JSON.parse(out).y;
|
|
|
|
const offset = gesture.startY - currentY;
|
|
|
|
|
|
|
|
if (offset < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
window.child.setCss(`
|
2023-11-19 20:39:08 -05:00
|
|
|
margin-bottom: ${offset - hidden}px;
|
2023-11-19 15:00:29 -05:00
|
|
|
`);
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
// End drag
|
|
|
|
gesture.signals.push(
|
|
|
|
gesture.connect('drag-end', () => {
|
|
|
|
window.child.setCss(`
|
|
|
|
transition: margin-bottom 0.5s ease-in-out;
|
2023-11-19 20:39:08 -05:00
|
|
|
margin-bottom: -${hidden}px;
|
2023-11-19 15:00:29 -05:00
|
|
|
`);
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
window.setSlideDown = () => {
|
|
|
|
window.killGestureSigs();
|
|
|
|
|
|
|
|
// Begin drag
|
|
|
|
gesture.signals.push(
|
|
|
|
gesture.connect('drag-begin', () => {
|
|
|
|
Hyprland.sendMessage('j/cursorpos').then(out => {
|
|
|
|
gesture.startY = JSON.parse(out).y;
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
// Update drag
|
|
|
|
gesture.signals.push(
|
|
|
|
gesture.connect('drag-update', () => {
|
|
|
|
Hyprland.sendMessage('j/cursorpos').then(out => {
|
|
|
|
const currentY = JSON.parse(out).y;
|
|
|
|
const offset = gesture.startY - currentY;
|
|
|
|
|
|
|
|
if (offset > 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
window.child.setCss(`
|
|
|
|
margin-bottom: ${offset}px;
|
|
|
|
`);
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
// End drag
|
|
|
|
gesture.signals.push(
|
|
|
|
gesture.connect('drag-end', () => {
|
|
|
|
window.child.setCss(`
|
|
|
|
transition: margin-bottom 0.5s ease-in-out;
|
|
|
|
margin-bottom: 0px;
|
|
|
|
`);
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
return window;
|
|
|
|
};
|