Added Power menu and show only the workspaces allocated to monitor

This commit is contained in:
Jas Singh
2024-06-09 18:40:51 -07:00
parent 3579e563b8
commit d695d9aa67
25 changed files with 784 additions and 383 deletions

View File

@@ -0,0 +1,137 @@
export const Padding = (name) => Widget.EventBox({
hexpand: true,
vexpand: true,
can_focus: false,
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: 200,
setup: self => self.hook(App, (_, wname, visible) => {
if (wname === name)
self.reveal_child = visible
}),
}),
)
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),
),
),
})
export default ({
name,
child,
layout = "center",
transition,
exclusivity = "ignore",
...props
}) => Widget.Window({
name,
class_names: [name, "popup-window"],
setup: w => w.keybind("Escape", () => App.closeWindow(name)),
visible: true,
keymode: "on-demand",
exclusivity,
layer: "top",
anchor: ["top", "bottom", "right", "left"],
child: Layout(name, child, transition)[layout](),
...props,
})

4
modules/menus/main.js Normal file
View File

@@ -0,0 +1,4 @@
import PowerMenu from "./power/index.js";
import Verification from "./power/verification.js";
export default [PowerMenu(), Verification()];

View File

@@ -0,0 +1,54 @@
const powerOptions = {
sleep: "systemctl suspend",
reboot: "systemctl reboot",
logout: "pkill Hyprland",
shutdown: "shutdown now",
};
class PowerMenu extends Service {
static {
Service.register(
this,
{},
{
title: ["string"],
cmd: ["string"],
},
);
}
#title = "";
#cmd = "";
get title() {
return this.#title;
}
action(action) {
[this.#cmd, this.#title] = {
sleep: [powerOptions.sleep, "Sleep"],
reboot: [powerOptions.reboot, "Reboot"],
logout: [powerOptions.logout, "Log Out"],
shutdown: [powerOptions.shutdown, "Shutdown"],
}[action];
this.notify("cmd");
this.notify("title");
this.emit("changed");
App.closeWindow("powermenu");
App.openWindow("verification");
}
shutdown = () => {
this.action("shutdown");
};
exec = () => {
App.closeWindow("verification");
Utils.exec(this.#cmd);
};
}
const powermenu = new PowerMenu();
Object.assign(globalThis, { powermenu });
export default powermenu;

View File

@@ -0,0 +1,37 @@
import PopupWindow from "../PopupWindow.js";
import powermenu from "./helpers/actions.js";
import icons from "../../icons/index.js";
const SysButton = (action, label) =>
Widget.Button({
class_name: `widget-button powermenu-button-${action}`,
on_clicked: () => powermenu.action(action),
child: Widget.Box({
vertical: true,
class_name: "system-button widget-button",
children: [
Widget.Icon({
class_name: `system-button_icon ${action}`,
icon: icons.powermenu[action],
}),
Widget.Label({
class_name: `system-button_label ${action}`,
label,
}),
],
}),
});
export default () =>
PopupWindow({
name: "powermenu",
transition: "crossfade",
child: Widget.Box({
class_name: "powermenu horizontal",
children: [
SysButton("shutdown", "SHUTDOWN"),
SysButton("logout", "LOG OUT"),
SysButton("reboot", "REBOOT"),
SysButton("sleep", "SLEEP"),
],
}),
});

View File

@@ -0,0 +1,48 @@
import PopupWindow from "../PopupWindow.js";
import powermenu from "./helpers/actions.js";
export default () =>
PopupWindow({
name: "verification",
transition: "crossfade",
child: Widget.Box({
class_name: "verification",
vertical: true,
children: [
Widget.Box({
class_name: "text-box",
vertical: true,
children: [
Widget.Label({
class_name: "title",
label: powermenu.bind("title"),
}),
Widget.Label({
class_name: "desc",
label: "Are you sure?",
}),
],
}),
Widget.Box({
class_name: "buttons horizontal",
vexpand: true,
vpack: "end",
homogeneous: true,
children: [
Widget.Button({
child: Widget.Label("No"),
on_clicked: () => App.toggleWindow("verification"),
setup: (self) =>
self.hook(App, (_, name, visible) => {
if (name === "verification" && visible) self.grab_focus();
}),
}),
Widget.Button({
child: Widget.Label("Yes"),
on_clicked: powermenu.exec,
}),
],
}),
],
}),
});