workspace update
This commit is contained in:
1 parent
85a55d1e3b
commit
59266aea28
2 files changed
+152
-61
No files matched your search
+90
-35
@@ -10,7 +10,7 @@ import { OpenSettings } from "apps/settings/main.ts";
|
||||
import { enableClickThrough } from "./misc/clickthrough.js";
|
||||
import { RoundedCorner } from "./misc/cairo_roundedcorner.js";
|
||||
import { Client, Workspace } from "types/service/hyprland.js";
|
||||
import Button from "types/widgets/button.js";
|
||||
const { Box, Button, EventBox } = Widget;
|
||||
import Icon from "types/widgets/icon.js";
|
||||
import { FileEnumerator, FileInfo } from "types/@girs/gio-2.0/gio-2.0.cjs";
|
||||
const mpris = await Service.import("mpris");
|
||||
@@ -94,44 +94,99 @@ function getIconNameFromClass(windowClass: string) {
|
||||
const dispatch = (ws: string) => hyprland.messageAsync(`dispatch workspace ${ws}`).catch(print);
|
||||
|
||||
function Workspaces() {
|
||||
const activeId = hyprland.active.workspace.bind("id");
|
||||
let workspaceButtons = new Map();
|
||||
return EventBox({
|
||||
onScrollUp: () => dispatch("+1"),
|
||||
onScrollDown: () => dispatch("-1"),
|
||||
className: "workspaces",
|
||||
child: Box({
|
||||
className: "outer-workspace",
|
||||
children: Array.from({ length: 9 }, (_, i) => i + 1).map(
|
||||
(i, index, array) =>
|
||||
Box({
|
||||
attribute: i,
|
||||
className:
|
||||
index === 0
|
||||
? "workspace first"
|
||||
: index === array.length - 1
|
||||
? "workspace last"
|
||||
: "workspace",
|
||||
})
|
||||
),
|
||||
}).hook(hyprland, (self) => {
|
||||
let previousWorkspace = {};
|
||||
previousWorkspace.className = "";
|
||||
self.children.forEach((box, index, array) => {
|
||||
const isActive = hyprland.active.workspace.id === box.attribute;
|
||||
const isOccupied = hyprland.workspaces.some(
|
||||
(item) => item.id === box.attribute
|
||||
);
|
||||
let buttonClassName;
|
||||
if (isActive) {
|
||||
buttonClassName = "focused";
|
||||
box.className = "workspace focused";
|
||||
} else if (isOccupied) {
|
||||
buttonClassName = "occupied";
|
||||
box.className = "workspace occupied";
|
||||
} else {
|
||||
buttonClassName = "normal";
|
||||
box.className = "workspace normal";
|
||||
}
|
||||
|
||||
function createWorkspaceButton(id: Number) {
|
||||
const button = Widget.Button({
|
||||
on_clicked: () => dispatch(`${id}`),
|
||||
child: Widget.Label(`${id}`),
|
||||
class_name: activeId.as((i) => `${i === id ? "active" : ""}`)
|
||||
});
|
||||
return button;
|
||||
}
|
||||
if (isOccupied || isActive) {
|
||||
if (index === 0) box.toggleClassName("occupied-start", true);
|
||||
else if (
|
||||
index === 8 &&
|
||||
previousWorkspace.className.indexOf("occupied-start") === -1
|
||||
)
|
||||
box.toggleClassName("occupied-single", true);
|
||||
else if (
|
||||
index === 8 &&
|
||||
previousWorkspace.className.indexOf("occupied-middle") === -1
|
||||
)
|
||||
box.toggleClassName("occupied-end", true);
|
||||
else if (
|
||||
previousWorkspace.className.indexOf("occupied-start") !== -1
|
||||
) {
|
||||
box.toggleClassName("occupied-end", true);
|
||||
} else if (
|
||||
previousWorkspace.className.indexOf("occupied-end") !== -1
|
||||
) {
|
||||
previousWorkspace.toggleClassName("occupied-middle", true);
|
||||
previousWorkspace.toggleClassName("occupied-end", false);
|
||||
box.toggleClassName("occupied-end", true);
|
||||
} else {
|
||||
box.toggleClassName("occupied-start", true);
|
||||
}
|
||||
} else {
|
||||
if (previousWorkspace.className.indexOf("occupied-start") !== -1) {
|
||||
previousWorkspace.toggleClassName("occupied-start", false);
|
||||
previousWorkspace.toggleClassName("occupied-single", true);
|
||||
}
|
||||
}
|
||||
|
||||
function updateWorkspaceButtons(workspaces: Workspace[]): Array<Button<any, any>> {
|
||||
workspaces.sort((a, b) => a.id - b.id);
|
||||
if (index === 0) {
|
||||
box.toggleClassName("first", true);
|
||||
} else if (index === array.length - 1) {
|
||||
box.toggleClassName("last", true);
|
||||
}
|
||||
|
||||
const updatedButtons = new Map();
|
||||
box.child = Button({
|
||||
className: buttonClassName,
|
||||
label: box.attribute.toString(),
|
||||
onClicked: () => dispatch(box.attribute),
|
||||
setup: (self) => {
|
||||
if (index === 0) {
|
||||
self.toggleClassName("first", true);
|
||||
} else if (index === array.length - 1) {
|
||||
self.toggleClassName("last", true);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
workspaces.forEach(({ id }) => {
|
||||
if (workspaceButtons.has(id)) {
|
||||
updatedButtons.set(id, workspaceButtons.get(id));
|
||||
} else {
|
||||
updatedButtons.set(id, createWorkspaceButton(id));
|
||||
}
|
||||
});
|
||||
if (workspaceButtons != updatedButtons) workspaceButtons = updatedButtons;
|
||||
|
||||
return Array.from(workspaceButtons.values());
|
||||
}
|
||||
|
||||
const workspaceButtonsArray = hyprland.bind("workspaces").as(updateWorkspaceButtons);
|
||||
|
||||
return Widget.EventBox({
|
||||
onScrollUp: () => dispatch("+1"),
|
||||
onScrollDown: () => dispatch("-1"),
|
||||
child: Widget.Box({
|
||||
children: workspaceButtonsArray,
|
||||
class_name: "workspaces"
|
||||
})
|
||||
// Pass current workspace attributes as previousWorkspace
|
||||
previousWorkspace = box;
|
||||
});
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+62
-26
@@ -104,44 +104,80 @@ separator {
|
||||
* Workspaces
|
||||
* ----------------------------------------------------- */
|
||||
|
||||
.workspaces {
|
||||
border-radius: 16px;
|
||||
font-weight: bold;
|
||||
font-style: normal;
|
||||
font-size: 16px;
|
||||
color: @onSurface;
|
||||
background: @surfaceContainer;
|
||||
.outer-workspace {
|
||||
background-color: @surfaceContainerHigh;
|
||||
border-radius: 20px;
|
||||
}
|
||||
|
||||
.workspaces * {
|
||||
transition: all 0.35s ease-in-out;
|
||||
transition-property: background-color, color, min-width;
|
||||
.workspace {
|
||||
background-color: @surfaceVariant;
|
||||
/* padding: 0; */
|
||||
}
|
||||
|
||||
.workspaces button {
|
||||
padding: 0px 5px;
|
||||
margin: 4px 3px;
|
||||
border-radius: 16px;
|
||||
border: 0px;
|
||||
.workspace button {
|
||||
background-color: transparent;
|
||||
padding-left: 4px;
|
||||
padding-right: 4px;
|
||||
}
|
||||
|
||||
.workspaces button label {
|
||||
color: @onSurfaceVariant;
|
||||
font-weight: bold;
|
||||
.workspace.first {
|
||||
border-radius: 20px 0 0 20px;
|
||||
}
|
||||
.workspace.last {
|
||||
border-radius: 0 20px 20px 0;
|
||||
}
|
||||
|
||||
.workspaces button:hover {
|
||||
color: @onSurface;
|
||||
background-color: mix(@onSurface, @surface, 0.85);
|
||||
.workspace.normal,
|
||||
.workspace button.normal {
|
||||
background-color: transparent;
|
||||
color: @surfaceDim;
|
||||
}
|
||||
|
||||
.workspaces button.active {
|
||||
background: @secondaryContainer;
|
||||
min-width: 40px;
|
||||
.workspace button.normal:hover {
|
||||
border-radius: 20px;
|
||||
background-color: @secondary;
|
||||
color: @surfaceDim;
|
||||
}
|
||||
|
||||
.workspaces button.active label {
|
||||
color: @onSecondaryContainer;
|
||||
.workspace button.focused {
|
||||
background-color: @secondary;
|
||||
color: @background;
|
||||
font-weight: bold;
|
||||
padding-left: 4px;
|
||||
padding-right: 4px;
|
||||
border-radius: 20px;
|
||||
}
|
||||
|
||||
.workspace button.focused:hover {
|
||||
border-radius: 20px;
|
||||
color: @primary;
|
||||
background-color: mix(@onSurface, @surface, 0.85);
|
||||
}
|
||||
|
||||
.workspace button.occupied {
|
||||
color: @primary;
|
||||
}
|
||||
|
||||
.workspaces button.occupied:hover {
|
||||
border-radius: 20px;
|
||||
background-color: mix(@onSurface, @surface, 0.85);
|
||||
color: @surfaceDim;
|
||||
}
|
||||
|
||||
.workspace.occupied-single {
|
||||
border-radius: 20px;
|
||||
}
|
||||
|
||||
.workspace.occupied-start {
|
||||
border-radius: 20px 0 0 20px;
|
||||
}
|
||||
|
||||
.workspace.occupied-middle {
|
||||
border-radius: 0px;
|
||||
}
|
||||
|
||||
.workspace.occupied-end {
|
||||
border-radius: 0px 20px 20px 0px;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------
|
||||
|
||||
Reference in new issue
Block a user