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