2024-01-30 11:29:07 -05:00
|
|
|
const Bluetooth = await Service.import('bluetooth');
|
|
|
|
const Network = await Service.import('network');
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2024-06-17 21:30:02 -04:00
|
|
|
import Tablet from '../../services/tablet.ts';
|
|
|
|
|
2024-01-30 11:29:07 -05:00
|
|
|
const { Box, Icon, Label, Revealer } = Widget;
|
|
|
|
const { execAsync } = Utils;
|
2023-09-12 14:22:21 -04:00
|
|
|
|
2024-01-13 23:38:31 -05:00
|
|
|
import { SpeakerIcon, MicIcon } from '../misc/audio-icons.ts';
|
|
|
|
import CursorBox from '../misc/cursorbox.ts';
|
|
|
|
import Separator from '../misc/separator.ts';
|
2023-09-12 14:22:21 -04:00
|
|
|
|
2024-01-13 23:38:31 -05:00
|
|
|
import { NetworkMenu } from './network.ts';
|
|
|
|
import { BluetoothMenu } from './bluetooth.ts';
|
2023-12-04 15:39:12 -05:00
|
|
|
|
2024-06-17 21:30:02 -04:00
|
|
|
/* Types */
|
2024-01-22 10:23:32 -05:00
|
|
|
import GObject from 'types/@girs/gobject-2.0/gobject-2.0';
|
2024-01-13 23:38:31 -05:00
|
|
|
import { Variable as Var } from 'types/variable.ts';
|
2024-06-17 21:30:02 -04:00
|
|
|
|
2024-02-21 19:08:55 -05:00
|
|
|
import {
|
|
|
|
BoxGeneric,
|
|
|
|
IconGeneric,
|
|
|
|
LabelGeneric,
|
|
|
|
RevealerGeneric,
|
|
|
|
} from 'global-types';
|
2024-06-17 21:30:02 -04:00
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
type IconTuple = [
|
|
|
|
GObject.Object,
|
2024-06-17 21:30:02 -04:00
|
|
|
(self: IconGeneric, state?: boolean) => void,
|
2024-01-13 11:15:08 -05:00
|
|
|
signal?: string,
|
|
|
|
];
|
2024-06-17 21:30:02 -04:00
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
type IndicatorTuple = [
|
|
|
|
GObject.Object,
|
2024-02-21 19:08:55 -05:00
|
|
|
(self: LabelGeneric) => void,
|
2024-01-13 11:15:08 -05:00
|
|
|
signal?: string,
|
|
|
|
];
|
2024-06-17 21:30:02 -04:00
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
type GridButtonType = {
|
|
|
|
command?(): void
|
|
|
|
secondary_command?(): void
|
2024-02-21 19:08:55 -05:00
|
|
|
on_open?(menu: RevealerGeneric): void
|
2024-01-13 11:15:08 -05:00
|
|
|
icon: string | IconTuple
|
|
|
|
indicator?: IndicatorTuple
|
2024-02-21 19:08:55 -05:00
|
|
|
// @ts-expect-error me is lazy
|
|
|
|
menu?: Widget
|
2024-01-13 11:15:08 -05:00
|
|
|
};
|
|
|
|
|
2024-06-17 21:30:02 -04:00
|
|
|
|
|
|
|
// TODO: do vpn button
|
2023-11-21 01:29:46 -05:00
|
|
|
const SPACING = 28;
|
2024-02-21 19:08:55 -05:00
|
|
|
const ButtonStates = [] as Array<Var<boolean>>;
|
2024-01-13 11:15:08 -05:00
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
const GridButton = ({
|
2023-12-20 03:45:05 -05:00
|
|
|
command = () => {/**/},
|
|
|
|
secondary_command = () => {/**/},
|
2023-12-31 03:08:48 -05:00
|
|
|
on_open = () => {/**/},
|
2023-10-20 23:11:21 -04:00
|
|
|
icon,
|
2023-11-09 02:19:18 -05:00
|
|
|
indicator,
|
|
|
|
menu,
|
2024-01-13 11:15:08 -05:00
|
|
|
}: GridButtonType) => {
|
2023-11-09 02:19:18 -05:00
|
|
|
const Activated = Variable(false);
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-09 02:19:18 -05:00
|
|
|
ButtonStates.push(Activated);
|
2024-01-13 11:15:08 -05:00
|
|
|
let iconWidget = Icon();
|
2023-12-23 01:14:21 -05:00
|
|
|
let indicatorWidget = Label();
|
2023-10-20 23:11:21 -04:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
// Allow setting icon dynamically or statically
|
2023-11-09 02:19:18 -05:00
|
|
|
if (typeof icon === 'string') {
|
2023-12-23 01:14:21 -05:00
|
|
|
iconWidget = Icon({
|
2023-12-20 03:45:05 -05:00
|
|
|
class_name: 'grid-label',
|
2023-11-21 01:29:46 -05:00
|
|
|
icon,
|
2023-12-17 00:01:58 -05:00
|
|
|
setup: (self) => {
|
|
|
|
self.hook(Activated, () => {
|
|
|
|
self.setCss(`color: ${Activated.value ?
|
|
|
|
'rgba(189, 147, 249, 0.8)' :
|
|
|
|
'unset'};`);
|
|
|
|
});
|
|
|
|
},
|
2023-11-09 02:19:18 -05:00
|
|
|
});
|
|
|
|
}
|
2023-12-23 01:14:21 -05:00
|
|
|
else if (Array.isArray(icon)) {
|
|
|
|
iconWidget = Icon({
|
2023-12-20 03:45:05 -05:00
|
|
|
class_name: 'grid-label',
|
2023-12-17 00:01:58 -05:00
|
|
|
setup: (self) => {
|
|
|
|
self
|
|
|
|
.hook(...icon)
|
|
|
|
.hook(Activated, () => {
|
|
|
|
self.setCss(`color: ${Activated.value ?
|
|
|
|
'rgba(189, 147, 249, 0.8)' :
|
|
|
|
'unset'};`);
|
|
|
|
});
|
|
|
|
},
|
2023-11-09 02:19:18 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (indicator) {
|
2023-12-23 01:14:21 -05:00
|
|
|
indicatorWidget = Label({
|
2023-12-20 03:45:05 -05:00
|
|
|
class_name: 'sub-label',
|
2023-11-09 02:19:18 -05:00
|
|
|
justification: 'left',
|
|
|
|
truncate: 'end',
|
2023-12-23 01:14:21 -05:00
|
|
|
max_width_chars: 12,
|
2023-12-17 00:01:58 -05:00
|
|
|
setup: (self) => {
|
|
|
|
self.hook(...indicator);
|
|
|
|
},
|
2023-11-09 02:19:18 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (menu) {
|
|
|
|
menu = Revealer({
|
|
|
|
transition: 'slide_down',
|
|
|
|
child: menu,
|
2023-12-23 01:14:21 -05:00
|
|
|
reveal_child: Activated.bind(),
|
2023-11-09 02:19:18 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const widget = Box({
|
|
|
|
vertical: true,
|
|
|
|
children: [
|
|
|
|
Box({
|
2023-12-20 03:45:05 -05:00
|
|
|
class_name: 'grid-button',
|
2023-11-09 02:19:18 -05:00
|
|
|
children: [
|
2023-10-20 23:11:21 -04:00
|
|
|
|
2023-12-18 23:20:32 -05:00
|
|
|
CursorBox({
|
2023-12-20 03:45:05 -05:00
|
|
|
class_name: 'left-part',
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-12-18 23:20:32 -05:00
|
|
|
on_primary_click_release: () => {
|
2023-11-21 01:29:46 -05:00
|
|
|
if (Activated.value) {
|
2023-12-20 03:45:05 -05:00
|
|
|
secondary_command();
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
command();
|
|
|
|
}
|
2023-11-09 02:19:18 -05:00
|
|
|
},
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-12-23 01:14:21 -05:00
|
|
|
child: iconWidget,
|
2023-11-09 02:19:18 -05:00
|
|
|
}),
|
|
|
|
|
2023-12-18 23:20:32 -05:00
|
|
|
CursorBox({
|
2023-12-20 03:45:05 -05:00
|
|
|
class_name: 'right-part',
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-12-18 23:20:32 -05:00
|
|
|
on_primary_click_release: () => {
|
2023-11-21 01:29:46 -05:00
|
|
|
ButtonStates.forEach((state) => {
|
|
|
|
if (state !== Activated) {
|
2024-02-11 02:18:59 -05:00
|
|
|
state.setValue(false);
|
2023-11-21 01:29:46 -05:00
|
|
|
}
|
2023-11-09 02:19:18 -05:00
|
|
|
});
|
2024-02-11 02:18:59 -05:00
|
|
|
Activated.setValue(!Activated.value);
|
2023-11-09 02:19:18 -05:00
|
|
|
},
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-12-20 03:45:05 -05:00
|
|
|
on_hover: (self) => {
|
2023-11-09 02:19:18 -05:00
|
|
|
if (menu) {
|
2023-12-20 03:45:05 -05:00
|
|
|
const rowMenu =
|
2024-02-21 19:08:55 -05:00
|
|
|
((((self.get_parent() as BoxGeneric)
|
|
|
|
?.get_parent() as BoxGeneric)
|
|
|
|
?.get_parent() as BoxGeneric)
|
|
|
|
?.get_parent() as BoxGeneric)
|
|
|
|
?.children[1] as BoxGeneric;
|
2024-01-13 11:15:08 -05:00
|
|
|
|
|
|
|
const isSetup = (rowMenu
|
2024-02-21 19:08:55 -05:00
|
|
|
.get_children() as Array<BoxGeneric>)
|
2024-01-13 11:15:08 -05:00
|
|
|
.find((ch) => ch === menu);
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
if (!isSetup) {
|
2023-11-09 02:19:18 -05:00
|
|
|
rowMenu.add(menu);
|
|
|
|
rowMenu.show_all();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-09 02:19:18 -05:00
|
|
|
child: Icon({
|
2024-02-26 16:28:54 -05:00
|
|
|
icon: 'down-large-symbolic',
|
2023-12-20 03:45:05 -05:00
|
|
|
class_name: 'grid-chev',
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-12-17 00:01:58 -05:00
|
|
|
setup: (self) => {
|
|
|
|
self.hook(Activated, () => {
|
|
|
|
let deg = 270;
|
|
|
|
|
|
|
|
if (Activated.value) {
|
|
|
|
deg = menu ? 360 : 450;
|
2023-12-31 03:08:48 -05:00
|
|
|
on_open(menu);
|
2023-12-17 00:01:58 -05:00
|
|
|
}
|
|
|
|
self.setCss(`
|
|
|
|
-gtk-icon-transform: rotate(${deg}deg);
|
|
|
|
`);
|
|
|
|
});
|
|
|
|
},
|
2023-11-09 02:19:18 -05:00
|
|
|
}),
|
|
|
|
}),
|
|
|
|
|
|
|
|
],
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
2023-12-23 01:14:21 -05:00
|
|
|
indicatorWidget,
|
2023-11-09 02:19:18 -05:00
|
|
|
],
|
|
|
|
});
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-09 02:19:18 -05:00
|
|
|
return widget;
|
|
|
|
};
|
2023-10-20 23:11:21 -04:00
|
|
|
|
2023-12-23 01:14:21 -05:00
|
|
|
const Row = ({ buttons }) => {
|
2024-01-13 11:15:08 -05:00
|
|
|
const child = Box({
|
|
|
|
class_name: 'button-row',
|
|
|
|
hpack: 'center',
|
|
|
|
});
|
|
|
|
|
2023-11-09 02:19:18 -05:00
|
|
|
const widget = Box({
|
|
|
|
vertical: true,
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-09 02:19:18 -05:00
|
|
|
children: [
|
2024-01-13 11:15:08 -05:00
|
|
|
child,
|
2023-12-05 11:35:40 -05:00
|
|
|
Box({ vertical: true }),
|
2023-11-09 02:19:18 -05:00
|
|
|
],
|
|
|
|
});
|
2023-09-12 14:22:21 -04:00
|
|
|
|
2023-11-09 02:19:18 -05:00
|
|
|
for (let i = 0; i < buttons.length; ++i) {
|
2023-11-21 01:29:46 -05:00
|
|
|
if (i === buttons.length - 1) {
|
2024-01-13 11:15:08 -05:00
|
|
|
child.add(buttons[i]);
|
2023-11-09 02:19:18 -05:00
|
|
|
}
|
|
|
|
else {
|
2024-01-13 11:15:08 -05:00
|
|
|
child.add(buttons[i]);
|
|
|
|
child.add(Separator(SPACING));
|
2023-11-09 02:19:18 -05:00
|
|
|
}
|
|
|
|
}
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-09 02:19:18 -05:00
|
|
|
return widget;
|
|
|
|
};
|
|
|
|
|
|
|
|
const FirstRow = () => Row({
|
|
|
|
buttons: [
|
2023-10-20 23:11:21 -04:00
|
|
|
|
|
|
|
GridButton({
|
|
|
|
command: () => Network.toggleWifi(),
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-12-20 03:45:05 -05:00
|
|
|
secondary_command: () => {
|
2023-12-05 11:35:40 -05:00
|
|
|
// TODO: connection editor
|
2023-10-20 23:11:21 -04:00
|
|
|
},
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
icon: [Network, (self) => {
|
|
|
|
self.icon = Network.wifi?.icon_name;
|
|
|
|
}],
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
indicator: [Network, (self) => {
|
|
|
|
self.label = Network.wifi?.ssid || Network.wired?.internet;
|
|
|
|
}],
|
2023-11-09 02:19:18 -05:00
|
|
|
|
2023-12-04 15:39:12 -05:00
|
|
|
menu: NetworkMenu(),
|
2023-12-31 03:08:48 -05:00
|
|
|
on_open: () => Network.wifi.scan(),
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
|
|
|
|
|
|
|
GridButton({
|
2023-12-05 11:35:40 -05:00
|
|
|
command: () => Bluetooth.toggle(),
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-12-20 03:45:05 -05:00
|
|
|
secondary_command: () => {
|
2023-12-05 11:35:40 -05:00
|
|
|
// TODO: bluetooth connection editor
|
2023-10-20 23:11:21 -04:00
|
|
|
},
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
icon: [Bluetooth, (self) => {
|
|
|
|
if (Bluetooth.enabled) {
|
|
|
|
self.icon = Bluetooth.connected_devices[0] ?
|
|
|
|
Bluetooth.connected_devices[0].icon_name :
|
|
|
|
'bluetooth-active-symbolic';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
self.icon = 'bluetooth-disabled-symbolic';
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
|
|
|
|
indicator: [Bluetooth, (self) => {
|
|
|
|
self.label = Bluetooth.connected_devices[0] ?
|
|
|
|
`${Bluetooth.connected_devices[0]}` :
|
|
|
|
'Disconnected';
|
|
|
|
}, 'notify::connected-devices'],
|
2023-12-05 11:35:40 -05:00
|
|
|
|
|
|
|
menu: BluetoothMenu(),
|
2023-12-31 03:08:48 -05:00
|
|
|
on_open: (menu) => {
|
2023-12-23 01:14:21 -05:00
|
|
|
execAsync(`bluetoothctl scan ${menu.reveal_child ?
|
2023-12-05 11:35:40 -05:00
|
|
|
'on' :
|
2023-12-08 00:01:43 -05:00
|
|
|
'off'}`).catch(print);
|
2023-12-05 11:35:40 -05:00
|
|
|
},
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
|
|
|
|
2024-06-17 21:30:02 -04:00
|
|
|
GridButton({
|
|
|
|
command: () => {
|
|
|
|
execAsync(['lock']).catch(print);
|
|
|
|
},
|
|
|
|
secondary_command: () => App.openWindow('win-powermenu'),
|
|
|
|
icon: 'system-lock-screen-symbolic',
|
|
|
|
}),
|
2023-10-20 23:11:21 -04:00
|
|
|
],
|
2023-09-12 14:22:21 -04:00
|
|
|
});
|
|
|
|
|
2023-11-09 02:19:18 -05:00
|
|
|
const SecondRow = () => Row({
|
|
|
|
buttons: [
|
2023-10-20 23:11:21 -04:00
|
|
|
GridButton({
|
|
|
|
command: () => {
|
2023-11-21 01:29:46 -05:00
|
|
|
execAsync(['pactl', 'set-sink-mute',
|
|
|
|
'@DEFAULT_SINK@', 'toggle']).catch(print);
|
2023-10-20 23:11:21 -04:00
|
|
|
},
|
|
|
|
|
2023-12-20 03:45:05 -05:00
|
|
|
secondary_command: () => {
|
2023-10-20 23:11:21 -04:00
|
|
|
execAsync(['bash', '-c', 'pavucontrol'])
|
|
|
|
.catch(print);
|
|
|
|
},
|
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
icon: [SpeakerIcon, (self) => {
|
|
|
|
self.icon = SpeakerIcon.value;
|
|
|
|
}],
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
|
|
|
|
|
|
|
GridButton({
|
|
|
|
command: () => {
|
2023-11-21 01:29:46 -05:00
|
|
|
execAsync(['pactl', 'set-source-mute',
|
|
|
|
'@DEFAULT_SOURCE@', 'toggle']).catch(print);
|
2023-10-20 23:11:21 -04:00
|
|
|
},
|
|
|
|
|
2023-12-20 03:45:05 -05:00
|
|
|
secondary_command: () => {
|
2023-10-20 23:11:21 -04:00
|
|
|
execAsync(['bash', '-c', 'pavucontrol'])
|
|
|
|
.catch(print);
|
|
|
|
},
|
|
|
|
|
2024-01-13 11:15:08 -05:00
|
|
|
icon: [MicIcon, (self) => {
|
|
|
|
self.icon = MicIcon.value;
|
|
|
|
}],
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
|
|
|
|
|
|
|
GridButton({
|
|
|
|
command: () => {
|
2024-06-17 21:30:02 -04:00
|
|
|
if (Tablet.autorotateState) {
|
|
|
|
Tablet.killAutorotate();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Tablet.startAutorotate();
|
|
|
|
}
|
2023-10-20 23:11:21 -04:00
|
|
|
},
|
2024-06-17 21:30:02 -04:00
|
|
|
|
|
|
|
icon: [Tablet, (self, state) => {
|
|
|
|
self.icon = state ?
|
|
|
|
'screen-rotate-auto-on-symbolic' :
|
|
|
|
'screen-rotate-auto-off-symbolic';
|
|
|
|
}, 'autorotate-toggled'],
|
2023-10-20 23:11:21 -04:00
|
|
|
}),
|
|
|
|
],
|
2023-09-12 14:22:21 -04:00
|
|
|
});
|
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
export default () => Box({
|
2023-12-20 03:45:05 -05:00
|
|
|
class_name: 'button-grid',
|
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: [
|
|
|
|
FirstRow(),
|
2023-11-09 02:19:18 -05:00
|
|
|
Separator(10, { vertical: true }),
|
2023-10-20 23:11:21 -04:00
|
|
|
SecondRow(),
|
|
|
|
],
|
2023-09-12 14:22:21 -04:00
|
|
|
});
|