fix(ags): use app.launch method

This commit is contained in:
matt1432 2023-12-21 01:25:59 -05:00
parent 0a2dc94fdf
commit c72e78e02e
9 changed files with 229 additions and 166 deletions

View file

@ -92,9 +92,7 @@ const Applauncher = ({ window_name = 'applauncher' } = {}) => {
if (appList[0]) { if (appList[0]) {
App.closeWindow(window_name); App.closeWindow(window_name);
Hyprland.sendMessage(`dispatch exec sh -c appList[0].launch();
${appList[0].executable}`);
++appList[0].frequency;
} }
}, },

View file

@ -69,10 +69,10 @@ const NotificationIcon = (notif) => {
`focuswindow ^(${wmClass})`); `focuswindow ^(${wmClass})`);
} }
else { else {
Hyprland.sendMessage('[[BATCH]] ' + Hyprland.sendMessage('dispatch workspace empty')
'dispatch workspace empty; ' + .then(() => {
`dispatch exec sh -c ${app.executable} app.launch();
`); });
} }
}); });
} }

View file

@ -2,7 +2,7 @@ import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
import { execAsync, timeout } from 'resource:///com/github/Aylur/ags/utils.js'; import { execAsync, timeout } from 'resource:///com/github/Aylur/ags/utils.js';
import Gtk from 'gi://Gtk'; const { Gtk } = imports.gi;
import Tablet from '../../services/tablet.js'; import Tablet from '../../services/tablet.js';
@ -20,124 +20,138 @@ const releaseAllKeys = () => {
]).catch(print); ]).catch(print);
}; };
/** @param {import('types/widgets/window').default} window */
export default (window) => { export default (window) => {
// @ts-expect-error
window.child.setCss(`margin-bottom: -${HIDDEN_MARGIN}px;`); window.child.setCss(`margin-bottom: -${HIDDEN_MARGIN}px;`);
const gesture = Gtk.GestureDrag.new(window); const gesture = Gtk.GestureDrag.new(window);
window.setVisible = (state) => { let signals = [];
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(ANIM_DURATION + 10, () => {
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_MARGIN}px;
`);
}
};
gesture.signals = []; window.attribute = {
window.killGestureSigs = () => { /** @param {boolean} state */
gesture.signals.forEach((id) => { setVisible: (state) => {
gesture.disconnect(id); if (state) {
}); window.visible = true;
gesture.signals = []; window.attribute.setSlideDown();
};
window.setSlideUp = () => { // @ts-expect-error
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 - HIDDEN_MARGIN}px;
`);
});
}),
);
// End drag
gesture.signals.push(
gesture.connect('drag-end', () => {
window.child.setCss(` window.child.setCss(`
transition: margin-bottom 0.5s ease-in-out; transition: margin-bottom 0.7s
margin-bottom: -${HIDDEN_MARGIN}px; cubic-bezier(0.36, 0, 0.66, -0.56);
`);
}),
);
};
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; margin-bottom: 0px;
`); `);
}), }
); else {
timeout(ANIM_DURATION + 10, () => {
if (!Tablet.tabletMode) {
window.visible = false;
}
});
releaseAllKeys();
window.attribute.setSlideUp();
// @ts-expect-error
window.child.setCss(`
transition: margin-bottom 0.7s
cubic-bezier(0.36, 0, 0.66, -0.56);
margin-bottom: -${HIDDEN_MARGIN}px;
`);
}
},
killGestureSigs: () => {
signals.forEach((id) => {
gesture.disconnect(id);
});
signals = [];
},
setSlideUp: () => {
window.attribute.killGestureSigs();
// Begin drag
signals.push(
gesture.connect('drag-begin', () => {
Hyprland.sendMessage('j/cursorpos').then((out) => {
gesture.startY = JSON.parse(out).y;
});
}),
);
// Update drag
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;
}
// @ts-expect-error
window.child.setCss(`
margin-bottom: ${offset - HIDDEN_MARGIN}px;
`);
});
}),
);
// End drag
signals.push(
gesture.connect('drag-end', () => {
// @ts-expect-error
window.child.setCss(`
transition: margin-bottom 0.5s ease-in-out;
margin-bottom: -${HIDDEN_MARGIN}px;
`);
}),
);
},
setSlideDown: () => {
window.attribute.killGestureSigs();
// Begin drag
signals.push(
gesture.connect('drag-begin', () => {
Hyprland.sendMessage('j/cursorpos').then((out) => {
gesture.startY = JSON.parse(out).y;
});
}),
);
// Update drag
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;
}
// @ts-expect-error
window.child.setCss(`
margin-bottom: ${offset}px;
`);
});
}),
);
// End drag
signals.push(
gesture.connect('drag-end', () => {
// @ts-expect-error
window.child.setCss(`
transition: margin-bottom 0.5s ease-in-out;
margin-bottom: 0px;
`);
}),
);
},
}; };
return window; return window;

View file

@ -13,6 +13,7 @@ const COLOR = 'rgba(0, 0, 0, 0.3)';
const SPACING = 4; const SPACING = 4;
/** @param {import('types/widgets/window').default} window */
export default (window) => Box({ export default (window) => Box({
vertical: true, vertical: true,
children: [ children: [
@ -26,6 +27,7 @@ export default (window) => Box({
center_widget: CenterBox({ center_widget: CenterBox({
class_name: 'thingy', class_name: 'thingy',
css: `background: ${COLOR};`, css: `background: ${COLOR};`,
center_widget: Box({ center_widget: Box({
hpack: 'center', hpack: 'center',
class_name: 'settings', class_name: 'settings',
@ -41,8 +43,10 @@ export default (window) => Box({
self.on('toggled', () => { self.on('toggled', () => {
self.toggleClassName( self.toggleClassName(
'toggled', 'toggled',
// @ts-expect-error
self.get_active(), self.get_active(),
); );
// @ts-expect-error
window.exclusivity = self.get_active() ? window.exclusivity = self.get_active() ?
'exclusive' : 'exclusive' :
'normal'; 'normal';
@ -70,26 +74,33 @@ export default (window) => Box({
hpack: 'start', hpack: 'start',
vertical: true, vertical: true,
children: keyboardJson.keys.map((row, rowIndex) => Box({ children: keyboardJson.keys.map((row, rowIndex) => {
vertical: true, const keys = [];
children: [ row.forEach((key, keyIndex) => {
Box({ if (keyIndex < L_KEY_PER_ROW[rowIndex]) {
class_name: 'row', keys.push(Key(key));
}
});
children: [ return Box({
Separator(SPACING), vertical: true,
...row.map((key, keyIndex) => {
return keyIndex < L_KEY_PER_ROW[rowIndex] ?
Key(key) :
null;
}),
],
}),
Separator(SPACING, { vertical: true }), children: [
], Box({
})), class_name: 'row',
children: [
Separator(SPACING),
...keys,
],
}),
Separator(SPACING, { vertical: true }),
],
});
}),
}), }),
center_widget: Box({ center_widget: Box({
@ -105,24 +116,30 @@ export default (window) => Box({
hpack: 'end', hpack: 'end',
vertical: true, vertical: true,
children: keyboardJson.keys.map((row, rowIndex) => Box({ children: keyboardJson.keys.map((row, rowIndex) => {
vertical: true, const keys = [];
children: [ row.forEach((key, keyIndex) => {
Box({ if (keyIndex >= L_KEY_PER_ROW[rowIndex]) {
hpack: 'end', keys.push(Key(key));
class_name: 'row', }
});
children: row.map((key, keyIndex) => { return Box({
return keyIndex >= L_KEY_PER_ROW[rowIndex] ? vertical: true,
Key(key) :
null; children: [
Box({
hpack: 'end',
class_name: 'row',
children: keys,
}), }),
}),
Separator(SPACING, { vertical: true }), Separator(SPACING, { vertical: true }),
], ],
})), });
}),
}), }),
}), }),
], ],

View file

@ -4,7 +4,7 @@ import Brightness from '../../services/brightness.js';
import { Box, EventBox, Label } from 'resource:///com/github/Aylur/ags/widget.js'; import { Box, EventBox, Label } from 'resource:///com/github/Aylur/ags/widget.js';
import { execAsync } from 'resource:///com/github/Aylur/ags/utils.js'; import { execAsync } from 'resource:///com/github/Aylur/ags/utils.js';
import Gtk from 'gi://Gtk'; const { Gtk } = imports.gi;
import Separator from '../misc/separator.js'; import Separator from '../misc/separator.js';
@ -44,6 +44,7 @@ const LALT_CODE = 56;
const LCTRL_CODE = 29; const LCTRL_CODE = 29;
/** @param {Object} key */
const ModKey = (key) => { const ModKey = (key) => {
let Mod; let Mod;
@ -79,16 +80,20 @@ const ModKey = (key) => {
const button = EventBox({ const button = EventBox({
cursor: 'pointer', cursor: 'pointer',
class_name: 'key', class_name: 'key',
onPrimaryClickRelease: (self) => { on_primary_click_release: (self) => {
console.log('mod toggled'); console.log('mod toggled');
execAsync(`ydotool key ${key.keycode}:${Mod.value ? 0 : 1}`); execAsync(`ydotool key ${key.keycode}:${Mod.value ? 0 : 1}`);
// @ts-expect-error
self.child.toggleClassName('active', !Mod.value); self.child.toggleClassName('active', !Mod.value);
Mod.value = !Mod.value; Mod.value = !Mod.value;
}, },
setup: (self) => { setup: (self) => {
self.hook(NormalClick, () => { self.hook(NormalClick, () => {
Mod.value = false; Mod.value = false;
// @ts-expect-error
self.child.toggleClassName('active', false); self.child.toggleClassName('active', false);
execAsync(`ydotool key ${key.keycode}:0`); execAsync(`ydotool key ${key.keycode}:0`);
}); });
@ -107,6 +112,7 @@ const ModKey = (key) => {
}); });
}; };
/** @param {Object} key */
const RegularKey = (key) => { const RegularKey = (key) => {
const widget = EventBox({ const widget = EventBox({
cursor: 'pointer', cursor: 'pointer',
@ -198,6 +204,7 @@ const RegularKey = (key) => {
}); });
}; };
/** @param {Object} key */
export default (key) => key.keytype === 'normal' ? export default (key) => key.keytype === 'normal' ?
RegularKey(key) : RegularKey(key) :
ModKey(key); ModKey(key);

View file

@ -19,7 +19,7 @@ export default () => {
setup: (self) => { setup: (self) => {
self self
.hook(Tablet, (_, state) => { .hook(Tablet, (_, state) => {
self.setVisible(state); self.attribute.setVisible(state);
}, 'osk-toggled') }, 'osk-toggled')
.hook(Tablet, () => { .hook(Tablet, () => {

View file

@ -3,13 +3,13 @@ import { Box, Icon, ProgressBar } from 'resource:///com/github/Aylur/ags/widget.
const Y_POS = 80; const Y_POS = 80;
export default ({ stack, icon, info } = {}) => { export default ({ stack, icon, info }) => {
let connectFunc; let connectFunc;
const osd = Box({ const osd = Box({
css: `margin-bottom: ${Y_POS}px;`, css: `margin-bottom: ${Y_POS}px;`,
children: [Box({ children: [Box({
className: 'osd', class_name: 'osd',
children: [ children: [
Icon({ Icon({
hpack: 'start', hpack: 'start',
@ -27,15 +27,21 @@ export default ({ stack, icon, info } = {}) => {
// Handle requests to show the OSD // Handle requests to show the OSD
// Different wether it's a bar or static // Different wether it's a bar or static
if (info.logic) { if (info.logic) {
/**
* @param {import('types/widgets/box').default} self
* @returns {Promise<void>}
*/
connectFunc = (self) => new Promise((r) => { connectFunc = (self) => new Promise((r) => {
info.logic(self); info.logic(self);
// @ts-expect-error
r(); r();
}).then(() => stack.popup(osd)); }).then(() => stack.attribute.popup(osd));
} }
else { else {
connectFunc = () => stack.popup(osd); connectFunc = () => stack.attribute.popup(osd);
} }
// @ts-expect-error
osd.children[0].children[1].hook(info.mod, connectFunc, info.signal); osd.children[0].children[1].hook(info.mod, connectFunc, info.signal);
return osd; return osd;

View file

@ -19,19 +19,22 @@ const HIDE_DELAY = 2000;
const OSDs = () => { const OSDs = () => {
const stack = Stack({ const stack = Stack({
transition: 'over_up_down', transition: 'over_up_down',
transitionDuration: 200, transition_duration: 200,
attribute: {
popup: () => {/**/},
},
}); });
stack.items = OSDList.map((osd, i) => [`${i}`, osd(stack)]); stack.items = OSDList.map((osd, i) => [`${i}`, osd(stack)]);
stack.popup = () => { /**/ };
// Delay popup method so it // Delay popup method so it
// doesn't show any OSDs at launch // doesn't show any OSDs at launch
timeout(1000, () => { timeout(1000, () => {
let count = 0; let count = 0;
stack.popup = (osd) => { /** @param {import('types/widgets/box').default} osd */
stack.attribute.popup = (osd) => {
++count; ++count;
stack.set_visible_child(osd); stack.set_visible_child(osd);
App.openWindow('osd'); App.openWindow('osd');

View file

@ -10,18 +10,26 @@ import { MicIcon } from '../misc/audio-icons.js';
const AUDIO_MAX = 1.5; const AUDIO_MAX = 1.5;
const ShowSpeaker = Variable(true); const ShowSpeaker = Variable(true);
globalThis.showSpeaker = () => { globalThis.showSpeaker = () => {
ShowSpeaker.value = !ShowSpeaker.value; ShowSpeaker.value = !ShowSpeaker.value;
}; };
/**
* @typedef {import('types/widgets/stack').default} Stack
* @typedef {import('types/widgets/progressbar').default} ProgressBar
*/
/** @param {Stack} stack */
export const SpeakerOSD = (stack) => OSD({ export const SpeakerOSD = (stack) => OSD({
stack, stack,
icon: { binds: [['icon', SpeakerIcon, 'value']] }, icon: { icon: SpeakerIcon.bind() },
info: { info: {
mod: ShowSpeaker, mod: ShowSpeaker,
/** @param {ProgressBar} self */
logic: (self) => { logic: (self) => {
if (!Audio.speaker) { if (!Audio.speaker) {
return; return;
@ -31,29 +39,35 @@ export const SpeakerOSD = (stack) => OSD({
Audio.speaker.volume / AUDIO_MAX : Audio.speaker.volume / AUDIO_MAX :
0; 0;
self.sensitive = !Audio.speaker?.stream.isMuted; self.sensitive = !Audio.speaker?.stream.is_muted;
}, },
}, },
}); });
/** @param {Stack} stack */
export const ScreenBrightnessOSD = (stack) => OSD({ export const ScreenBrightnessOSD = (stack) => OSD({
stack, stack,
icon: { binds: [['icon', Brightness, 'screen-icon']] }, icon: { icon: Brightness.bind('screenIcon') },
info: { info: {
mod: Brightness, mod: Brightness,
signal: 'screen', signal: 'screen',
/** @param {ProgressBar} self */
logic: (self) => { logic: (self) => {
self.value = Brightness.screen; self.value = Brightness.screen;
}, },
}, },
}); });
/** @param {Stack} stack */
export const KbdBrightnessOSD = (stack) => OSD({ export const KbdBrightnessOSD = (stack) => OSD({
stack, stack,
icon: 'keyboard-brightness-symbolic', icon: 'keyboard-brightness-symbolic',
info: { info: {
mod: Brightness, mod: Brightness,
signal: 'kbd', signal: 'kbd',
/** @param {ProgressBar} self */
logic: (self) => { logic: (self) => {
if (!self.value) { if (!self.value) {
self.value = Brightness.kbd / 2; self.value = Brightness.kbd / 2;
@ -66,26 +80,30 @@ export const KbdBrightnessOSD = (stack) => OSD({
}, },
}); });
/** @param {Stack} stack */
export const MicOSD = (stack) => OSD({ export const MicOSD = (stack) => OSD({
stack, stack,
icon: { binds: [['icon', MicIcon, 'value']] }, icon: { icon: MicIcon.bind() },
info: { info: {
mod: Audio, mod: Audio,
signal: 'microphone-changed', signal: 'microphone-changed',
/** @param {ProgressBar} self */
logic: (self) => { logic: (self) => {
if (!Audio.microphone) { if (!Audio.microphone) {
return; return;
} }
self.value = Audio.microphone ? Audio.microphone.volume : 0; self.value = Audio.microphone ? Audio.microphone.volume : 0;
self.sensitive = !Audio.microphone?.stream.isMuted; self.sensitive = !Audio.microphone?.stream.is_muted;
}, },
}, },
}); });
/** @param {Stack} stack */
export const CapsLockOSD = (stack) => OSD({ export const CapsLockOSD = (stack) => OSD({
stack, stack,
icon: { binds: [['icon', Brightness, 'caps-icon']] }, icon: { icon: Brightness.bind('capsIcon') },
info: { info: {
mod: Brightness, mod: Brightness,
signal: 'caps', signal: 'caps',