nixos-configs/modules/ags/config/ts/quick-settings/slider-box.ts

162 lines
5.5 KiB
TypeScript
Raw Normal View History

const Audio = await Service.import('audio');
const { Box, Slider, Icon } = Widget;
const { Gdk } = imports.gi;
const display = Gdk.Display.get_default();
import Brightness from '../../services/brightness.ts';
import { SpeakerIcon } from '../misc/audio-icons.ts';
export default () => Box({
2023-12-23 01:14:21 -05:00
class_name: 'slider-box',
vertical: true,
2023-11-06 18:37:23 -05:00
hpack: 'center',
children: [
Box({
2023-12-23 01:14:21 -05:00
class_name: 'slider',
2023-11-06 18:37:23 -05:00
vpack: 'start',
hpack: 'center',
children: [
Icon({
size: 26,
2023-12-23 01:14:21 -05:00
class_name: 'slider-label',
icon: SpeakerIcon.bind(),
}),
Slider({
2023-11-16 15:02:00 -05:00
vpack: 'center',
max: 0.999,
draw_value: false,
2023-12-23 01:14:21 -05:00
on_change: ({ value }) => {
if (Audio.speaker) {
Audio.speaker.volume = value;
}
},
setup: (self) => {
self
.hook(Audio, () => {
2023-12-23 01:14:21 -05:00
self.value = Audio.speaker?.volume || 0;
}, 'speaker-changed')
// OnClick
.on('button-press-event', () => {
2024-01-22 10:23:32 -05:00
if (!display) {
return;
}
self.window.set_cursor(Gdk.Cursor.new_from_name(
display,
'grabbing',
));
})
// OnRelease
.on('button-release-event', () => {
2024-01-22 10:23:32 -05:00
if (!display) {
return;
}
self.window.set_cursor(Gdk.Cursor.new_from_name(
display,
'pointer',
));
})
// OnHover
.on('enter-notify-event', () => {
2024-01-22 10:23:32 -05:00
if (!display) {
return;
}
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);
});
},
}),
],
}),
Box({
2023-12-23 01:14:21 -05:00
class_name: 'slider',
2023-11-06 18:37:23 -05:00
vpack: 'start',
hpack: 'center',
children: [
Icon({
2023-12-23 01:14:21 -05:00
class_name: 'slider-label',
icon: Brightness.bind('screenIcon'),
}),
2023-11-16 15:02:00 -05:00
Slider({
vpack: 'center',
draw_value: false,
2023-12-23 01:14:21 -05:00
on_change: ({ value }) => {
Brightness.screen = value;
},
setup: (self) => {
self
.hook(Brightness, () => {
self.value = Brightness.screen;
}, 'screen')
// OnClick
.on('button-press-event', () => {
2024-01-22 10:23:32 -05:00
if (!display) {
return;
}
self.window.set_cursor(Gdk.Cursor.new_from_name(
display,
'grabbing',
));
})
// OnRelease
.on('button-release-event', () => {
2024-01-22 10:23:32 -05:00
if (!display) {
return;
}
self.window.set_cursor(Gdk.Cursor.new_from_name(
display,
'pointer',
));
})
// OnHover
.on('enter-notify-event', () => {
2024-01-22 10:23:32 -05:00
if (!display) {
return;
}
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);
});
},
}),
],
}),
],
});