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-21 01:29:46 -05:00
|
|
|
import { execAsync, timeout } from 'resource:///com/github/Aylur/ags/utils.js';
|
|
|
|
|
2023-12-21 01:25:59 -05:00
|
|
|
const { Gtk } = imports.gi;
|
2023-11-19 15:00:29 -05:00
|
|
|
|
2024-01-13 23:38:31 -05:00
|
|
|
import Tablet from '../../services/tablet.ts';
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
const KEY_N = 249;
|
|
|
|
const HIDDEN_MARGIN = 340;
|
|
|
|
const ANIM_DURATION = 700;
|
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
// Types
|
2024-01-29 20:56:56 -05:00
|
|
|
import { BoxGeneric } from 'global-types';
|
2024-01-13 11:15:08 -05:00
|
|
|
|
2023-11-19 15:00:29 -05:00
|
|
|
|
2023-11-19 20:39:08 -05:00
|
|
|
const releaseAllKeys = () => {
|
2023-11-21 01:29:46 -05:00
|
|
|
const keycodes = Array.from(Array(KEY_N).keys());
|
|
|
|
|
2023-11-19 20:39:08 -05:00
|
|
|
execAsync([
|
|
|
|
'ydotool', 'key',
|
2023-11-21 01:29:46 -05:00
|
|
|
...keycodes.map((keycode) => `${keycode}:0`),
|
2023-11-19 20:39:08 -05:00
|
|
|
]).catch(print);
|
|
|
|
};
|
|
|
|
|
2024-01-29 20:56:56 -05:00
|
|
|
export default (window) => {
|
2023-11-19 15:00:29 -05:00
|
|
|
const gesture = Gtk.GestureDrag.new(window);
|
2024-01-29 20:56:56 -05:00
|
|
|
const child = window.child as BoxGeneric;
|
2024-01-13 11:15:08 -05:00
|
|
|
|
|
|
|
child.setCss(`margin-bottom: -${HIDDEN_MARGIN}px;`);
|
2023-11-19 15:00:29 -05:00
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
let signals = [] as Array<number>;
|
2023-11-19 15:00:29 -05:00
|
|
|
|
2023-12-21 01:25:59 -05:00
|
|
|
window.attribute = {
|
2024-01-22 10:23:32 -05:00
|
|
|
startY: null,
|
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
setVisible: (state: boolean) => {
|
2023-12-21 01:25:59 -05:00
|
|
|
if (state) {
|
|
|
|
window.visible = true;
|
|
|
|
window.attribute.setSlideDown();
|
2023-11-19 15:00:29 -05:00
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
child.setCss(`
|
2023-12-21 01:25:59 -05:00
|
|
|
transition: margin-bottom 0.7s
|
|
|
|
cubic-bezier(0.36, 0, 0.66, -0.56);
|
|
|
|
margin-bottom: 0px;
|
|
|
|
`);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
timeout(ANIM_DURATION + 10, () => {
|
|
|
|
if (!Tablet.tabletMode) {
|
|
|
|
window.visible = false;
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-11-19 15:00:29 -05:00
|
|
|
});
|
2023-12-21 01:25:59 -05:00
|
|
|
releaseAllKeys();
|
|
|
|
window.attribute.setSlideUp();
|
2023-11-19 15:00:29 -05:00
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
child.setCss(`
|
2023-12-21 01:25:59 -05:00
|
|
|
transition: margin-bottom 0.7s
|
|
|
|
cubic-bezier(0.36, 0, 0.66, -0.56);
|
2023-11-21 01:29:46 -05:00
|
|
|
margin-bottom: -${HIDDEN_MARGIN}px;
|
2023-11-19 15:00:29 -05:00
|
|
|
`);
|
2023-12-21 01:25:59 -05:00
|
|
|
}
|
|
|
|
},
|
2023-11-19 15:00:29 -05:00
|
|
|
|
2023-12-21 01:25:59 -05:00
|
|
|
killGestureSigs: () => {
|
|
|
|
signals.forEach((id) => {
|
|
|
|
gesture.disconnect(id);
|
|
|
|
});
|
|
|
|
signals = [];
|
2024-01-22 10:23:32 -05:00
|
|
|
window.attribute.startY = null;
|
2023-12-21 01:25:59 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
setSlideUp: () => {
|
|
|
|
window.attribute.killGestureSigs();
|
|
|
|
|
|
|
|
// Begin drag
|
|
|
|
signals.push(
|
|
|
|
gesture.connect('drag-begin', () => {
|
|
|
|
Hyprland.sendMessage('j/cursorpos').then((out) => {
|
2024-01-22 10:23:32 -05:00
|
|
|
window.attribute.startY = JSON.parse(out).y;
|
2023-12-21 01:25:59 -05:00
|
|
|
});
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
// Update drag
|
|
|
|
signals.push(
|
|
|
|
gesture.connect('drag-update', () => {
|
|
|
|
Hyprland.sendMessage('j/cursorpos').then((out) => {
|
|
|
|
const currentY = JSON.parse(out).y;
|
2024-01-22 10:23:32 -05:00
|
|
|
const offset = window.attribute.startY - currentY;
|
2023-12-21 01:25:59 -05:00
|
|
|
|
|
|
|
if (offset < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-29 20:56:56 -05:00
|
|
|
(window.child as BoxGeneric).setCss(`
|
2023-12-21 01:25:59 -05:00
|
|
|
margin-bottom: ${offset - HIDDEN_MARGIN}px;
|
|
|
|
`);
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
// End drag
|
|
|
|
signals.push(
|
|
|
|
gesture.connect('drag-end', () => {
|
2024-01-29 20:56:56 -05:00
|
|
|
(window.child as BoxGeneric).setCss(`
|
2023-12-21 01:25:59 -05:00
|
|
|
transition: margin-bottom 0.5s ease-in-out;
|
|
|
|
margin-bottom: -${HIDDEN_MARGIN}px;
|
2023-11-19 15:00:29 -05:00
|
|
|
`);
|
2023-12-21 01:25:59 -05:00
|
|
|
}),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
setSlideDown: () => {
|
|
|
|
window.attribute.killGestureSigs();
|
|
|
|
|
|
|
|
// Begin drag
|
|
|
|
signals.push(
|
|
|
|
gesture.connect('drag-begin', () => {
|
|
|
|
Hyprland.sendMessage('j/cursorpos').then((out) => {
|
2024-01-22 10:23:32 -05:00
|
|
|
window.attribute.startY = JSON.parse(out).y;
|
2023-12-21 01:25:59 -05:00
|
|
|
});
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
// Update drag
|
|
|
|
signals.push(
|
|
|
|
gesture.connect('drag-update', () => {
|
|
|
|
Hyprland.sendMessage('j/cursorpos').then((out) => {
|
|
|
|
const currentY = JSON.parse(out).y;
|
2024-01-22 10:23:32 -05:00
|
|
|
const offset = window.attribute.startY - currentY;
|
2023-12-21 01:25:59 -05:00
|
|
|
|
|
|
|
if (offset > 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-29 20:56:56 -05:00
|
|
|
(window.child as BoxGeneric).setCss(`
|
2023-12-21 01:25:59 -05:00
|
|
|
margin-bottom: ${offset}px;
|
|
|
|
`);
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
|
|
|
|
// End drag
|
|
|
|
signals.push(
|
|
|
|
gesture.connect('drag-end', () => {
|
2024-01-29 20:56:56 -05:00
|
|
|
(window.child as BoxGeneric).setCss(`
|
2023-12-21 01:25:59 -05:00
|
|
|
transition: margin-bottom 0.5s ease-in-out;
|
|
|
|
margin-bottom: 0px;
|
|
|
|
`);
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
},
|
2023-11-19 15:00:29 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
return window;
|
|
|
|
};
|