nixos-configs/devices/wim/config/ags/js/quick-settings/toggle-button.js

59 lines
2 KiB
JavaScript
Raw Normal View History

import App from 'resource:///com/github/Aylur/ags/app.js';
import Mpris from 'resource:///com/github/Aylur/ags/service/mpris.js';
2023-11-16 15:02:00 -05:00
import { CenterBox, Icon, ToggleButton } from 'resource:///com/github/Aylur/ags/widget.js';
2023-10-18 11:53:49 -04:00
const { Gdk } = imports.gi;
const display = Gdk.Display.get_default();
2023-10-18 11:53:49 -04:00
2023-12-23 01:14:21 -05:00
/** @param {import('types/widgets/revealer').default} rev */
export default (rev) => CenterBox({
2023-11-16 15:02:00 -05:00
center_widget: ToggleButton({
setup: (self) => {
// Open at startup if there are players
const id = Mpris.connect('changed', () => {
self.set_active(Mpris.players.length > 0);
Mpris.disconnect(id);
});
self
.on('toggled', () => {
if (self.get_active()) {
self.child
2023-12-23 01:14:21 -05:00
// @ts-expect-error
?.setCss('-gtk-icon-transform: rotate(0deg);');
rev.reveal_child = true;
}
else {
self.child
2023-12-23 01:14:21 -05:00
// @ts-expect-error
?.setCss('-gtk-icon-transform: rotate(180deg);');
rev.reveal_child = false;
}
})
// 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);
});
},
child: Icon({
icon: `${App.configDir}/icons/down-large.svg`,
2023-12-23 01:14:21 -05:00
class_name: 'arrow',
css: '-gtk-icon-transform: rotate(180deg);',
}),
}),
});