nixos-configs/modules/ags/config/ts/quick-settings/toggle-button.ts

67 lines
2 KiB
TypeScript
Raw Normal View History

const Mpris = await Service.import('mpris');
2024-01-13 11:15:08 -05:00
const { CenterBox, Icon, ToggleButton } = Widget;
2024-01-13 11:15:08 -05:00
const { Gdk } = imports.gi;
const display = Gdk.Display.get_default();
2024-02-21 19:08:55 -05:00
// Types
import { RevealerGeneric } from 'global-types';
2024-01-13 11:15:08 -05:00
2024-02-21 19:08:55 -05:00
export default (rev: RevealerGeneric) => {
2024-01-13 11:15:08 -05:00
const child = Icon({
icon: 'down-large-symbolic',
2024-01-13 11:15:08 -05:00
class_name: 'arrow',
css: '-gtk-icon-transform: rotate(180deg);',
});
const button = CenterBox({
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()) {
child
.setCss('-gtk-icon-transform: rotate(0deg);');
rev.reveal_child = true;
}
else {
child
.setCss('-gtk-icon-transform: rotate(180deg);');
rev.reveal_child = false;
}
})
// OnHover
.on('enter-notify-event', () => {
2024-01-22 10:23:32 -05:00
if (!display) {
return;
}
2024-01-13 11:15:08 -05:00
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,
}),
});
return button;
};