Skip to content

Commit

Permalink
ags: only load widgets when their services are ready
Browse files Browse the repository at this point in the history
  • Loading branch information
fufexan committed Dec 28, 2023
1 parent 2c22921 commit 633e41c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 35 deletions.
19 changes: 7 additions & 12 deletions home/services/ags/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,11 @@ function addWindows(windows) {
windows.forEach((win) => App.addWindow(win));
}

//timeout to wait for Hyprland service to be fully
//initialized. Maybe connect to Hyprland signal like
//notify::worksapces for more consistant results?
Utils.timeout(100, () =>
addWindows(
[
Bar(),
Music(),
Osd(),
SystemMenu(),
],
)
addWindows(
[
Bar(),
Music(),
Osd(),
SystemMenu(),
],
);
21 changes: 13 additions & 8 deletions home/services/ags/windows/bar/modules/workspaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,20 @@ export default () =>
child: Widget.Box({
className: "workspaces module",

children: makeWorkspaces(),

// The Hyprland service is ready later than ags is done parsing the config,
// so only build the widget when we receive a signal from it.
setup: (self) => {
self.lastFocused = Hyprland.active.workspace.id;
self.biggestId = getLastWorkspaceId();
self
.hook(Hyprland.active.workspace, focusedSwitch)
.hook(Hyprland, added, "workspace-added")
.hook(Hyprland, removed, "workspace-removed");
const connID = Hyprland.connect("notify::workspaces", () => {
Hyprland.disconnect(connID);

self.children = makeWorkspaces();
self.lastFocused = Hyprland.active.workspace.id;
self.biggestId = getLastWorkspaceId();
self
.hook(Hyprland.active.workspace, focusedSwitch)
.hook(Hyprland, added, "workspace-added")
.hook(Hyprland, removed, "workspace-removed");
});
},
}),
});
23 changes: 12 additions & 11 deletions home/services/ags/windows/system-menu/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ import PopupWindow from "../../utils/popup_window.js";

import Toggles from "./toggles.js";
import PowerProfiles from "./powerprofiles.js";
// import Sliders from "./sliders.js";
import Sliders from "./sliders.js";
import BatteryInfo from "./battery_info.js";

const SystemMenuBox = () => Widget.Box({
className: "system-menu",
vertical: true,
const SystemMenuBox = () =>
Widget.Box({
className: "system-menu",
vertical: true,

children: [
Toggles(),
PowerProfiles(),
// Sliders(),
BatteryInfo(),
],
});
children: [
Toggles(),
PowerProfiles(),
Sliders(),
BatteryInfo(),
],
});

export default () =>
PopupWindow({
Expand Down
15 changes: 11 additions & 4 deletions home/services/ags/windows/system-menu/sliders.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,15 @@ export default () =>
className: "sliders",
vertical: true,

children: [
Slider(vol()),
Slider(brightness()),
],
// The Audio service is ready later than ags is done parsing the config,
// so only build the widget when we receive a signal from it.
setup: (self) => {
const connID = Audio.connect("notify::speaker", () => {
Audio.disconnect(connID);
self.children = [
Slider(vol()),
Slider(brightness()),
];
});
},
});

0 comments on commit 633e41c

Please sign in to comment.