Added volume sliders and a list of all input/output devices.

This commit is contained in:
Jas Singh
2024-06-13 01:18:41 -07:00
parent 9619f90e4f
commit 26d2fcde0e
6 changed files with 373 additions and 179 deletions

View File

@@ -1,153 +1,57 @@
const hyprland = await Service.import("hyprland");
export const Padding = (name) =>
Widget.EventBox({
hexpand: true,
vexpand: true,
can_focus: false,
can_focus: true,
child: Widget.Box(),
setup: (w) => w.on("button-press-event", () => App.toggleWindow(name)),
});
const PopupRevealer = (name, child, transition = "slide_down") =>
Widget.Box(
{ css: "padding: 1px;" },
Widget.Revealer({
transition,
child: Widget.Box({
class_name: "window-content",
child,
}),
transitionDuration: 400,
setup: (self) =>
self.hook(App, (_, wname, visible) => {
if (wname === name) self.reveal_child = visible;
}),
}),
);
const moveBoxToCursor = (self, minWidth, minHeight, child) => {
function getAllMethods(object) {
return Object.getOwnPropertyNames(object).filter(function (property) {
return typeof object[property] == "function";
});
}
globalMousePos.connect("changed", ({ value }) => {
console.log(child.get_allocated_height());
console.log(child.get_allocated_width());
let monWidth = hyprland.monitors[hyprland.active.monitor.id].width;
let monHeight = hyprland.monitors[hyprland.active.monitor.id].height;
const Layout = (name, child, transition) => ({
center: () =>
Widget.CenterBox(
{},
Padding(name),
Widget.CenterBox(
{ vertical: true },
Padding(name),
PopupRevealer(name, child, transition),
Padding(name),
),
Padding(name),
),
top: () =>
Widget.CenterBox(
{},
Padding(name),
Widget.Box(
{ vertical: true },
PopupRevealer(name, child, transition),
Padding(name),
),
Padding(name),
),
"top-right": () =>
Widget.Box(
{},
Padding(name),
Widget.Box(
{
hexpand: false,
vertical: true,
},
PopupRevealer(name, child, transition),
Padding(name),
),
),
"top-center": () =>
Widget.Box(
{},
Padding(name),
Widget.Box(
{
hexpand: false,
vertical: true,
},
PopupRevealer(name, child, transition),
Padding(name),
),
Padding(name),
),
"top-left": () =>
Widget.Box(
{},
Widget.Box(
{
hexpand: false,
vertical: true,
},
PopupRevealer(name, child, transition),
Padding(name),
),
Padding(name),
),
"bottom-left": () =>
Widget.Box(
{},
Widget.Box(
{
hexpand: false,
vertical: true,
},
Padding(name),
PopupRevealer(name, child, transition),
),
Padding(name),
),
"bottom-center": () =>
Widget.Box(
{},
Padding(name),
Widget.Box(
{
hexpand: false,
vertical: true,
},
Padding(name),
PopupRevealer(name, child, transition),
),
Padding(name),
),
"bottom-right": () =>
Widget.Box(
{},
Padding(name),
Widget.Box(
{
hexpand: false,
vertical: true,
},
Padding(name),
PopupRevealer(name, child, transition),
),
),
"anywhere": () =>
Widget.Box(
{},
Padding(name),
Widget.Box(
{
hexpand: false,
vertical: true,
},
Padding(name),
PopupRevealer(name, child, transition),
),
),
});
// If monitor is vertical (transform = 1 || 3) swap height and width
if (hyprland.monitors[hyprland.active.monitor.id].transform % 2 !== 0) {
[monWidth, monHeight] = [monHeight, monWidth];
}
let marginRight = monWidth - value[0] - minWidth / 2;
let marginLeft = monWidth - minWidth - marginRight;
if (marginRight < 0) {
marginRight = 13;
marginLeft = monWidth - minWidth - 13;
} else if (marginRight < 13) {
marginRight = 13;
marginLeft = monWidth - minWidth - 13;
}
const marginTop = 40;
const marginBottom = monHeight + minHeight - marginTop;
self.set_margin_left(marginLeft);
self.set_margin_right(marginRight);
self.set_margin_top(marginTop);
self.set_margin_bottom(marginBottom);
});
};
export default ({
name,
child,
layout = "center",
transition,
minWidth = 400,
minHeight = 200,
exclusivity = "ignore",
...props
}) =>
@@ -160,6 +64,21 @@ export default ({
exclusivity,
layer: "top",
anchor: ["top", "bottom", "right", "left"],
child,//: Layout(name, child, transition)[layout](),
child: Widget.EventBox({
on_primary_click: () => App.closeWindow(name),
child: Widget.EventBox({
on_primary_click: () => {
return true;
},
setup: (self) => {
moveBoxToCursor(self, minWidth, minHeight, child);
},
child: Widget.Box({
class_name: "dropdown-menu-container",
can_focus: true,
children: [Padding(name), child],
}),
}),
}),
...props,
});