Added support for handling workspace > 10 in ags bar and overview. Added support for navigating and moving workspaces for workspace > 10 using keybinds

This commit is contained in:
midn8hustlr
2024-01-28 01:42:43 +05:30
parent 962e29d406
commit ccdc507f1d
4 changed files with 75 additions and 46 deletions
+32 -16
View File
@@ -8,13 +8,14 @@ import Widget from 'resource:///com/github/Aylur/ags/widget.js';
const { Box, DrawingArea, EventBox } = Widget;
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js';
const NUM_OF_WORKSPACES = 10;
const NUM_WS_GROUPS = 3;
const NUM_OF_WORKSPACES_PER_GROUP = 10;
const dummyWs = Box({ className: 'bar-ws' }); // Not shown. Only for getting size props
const dummyActiveWs = Box({ className: 'bar-ws bar-ws-active' }); // Not shown. Only for getting size props
const dummyOccupiedWs = Box({ className: 'bar-ws bar-ws-occupied' }); // Not shown. Only for getting size props
// Font size = workspace id
const WorkspaceContents = (count = 10) => {
const WorkspaceContents = (offset = 0, count = 10) => {
return DrawingArea({
css: `transition: 90ms cubic-bezier(0.1, 1, 0, 1);`,
attribute: {
@@ -26,8 +27,8 @@ const WorkspaceContents = (count = 10) => {
let workspaceMask = 0;
for (let i = 0; i < workspaces.length; i++) {
const ws = workspaces[i];
if (ws.id <= 0) continue; // Ignore scratchpads
if (ws.id > count) return; // Not rendered
if (ws.id <= offset) continue; // Ignore scratchpads
if (ws.id > offset + count) continue; // Not rendered
if (workspaces[i].windows > 0) {
workspaceMask |= (1 << ws.id);
}
@@ -42,7 +43,7 @@ const WorkspaceContents = (count = 10) => {
},
setup: (area) => area
.hook(Hyprland.active.workspace, (area) =>
area.setCss(`font-size: ${Hyprland.active.workspace.id}px;`)
area.setCss(`font-size: ${(Hyprland.active.workspace.id-1) % NUM_OF_WORKSPACES_PER_GROUP + 1}px;`)
)
.hook(Hyprland, (self) => self.attribute.updateMask(self), 'notify::workspaces')
.hook(Hyprland, (self, name) => self.attribute.toggleMask(self, true, name), 'workspace-added')
@@ -86,12 +87,12 @@ const WorkspaceContents = (count = 10) => {
// Draw workspace numbers
for (let i = 1; i <= count; i++) {
if (area.attribute.workspaceMask & (1 << i)) {
if (area.attribute.workspaceMask & (1 << (i + offset))) {
// Draw bg highlight
cr.setSourceRGBA(occupiedbg.red, occupiedbg.green, occupiedbg.blue, occupiedbg.alpha);
const wsCenterX = -(workspaceRadius) + (workspaceDiameter * i);
const wsCenterY = height / 2;
if (!(area.attribute.workspaceMask & (1 << (i - 1)))) { // Left
if (!(area.attribute.workspaceMask & (1 << (i + offset - 1))) || i == 1) { // Left
cr.arc(wsCenterX, wsCenterY, workspaceRadius, 0.5 * Math.PI, 1.5 * Math.PI);
cr.fill();
}
@@ -99,7 +100,7 @@ const WorkspaceContents = (count = 10) => {
cr.rectangle(wsCenterX - workspaceRadius, wsCenterY - workspaceRadius, workspaceRadius, workspaceRadius * 2)
cr.fill();
}
if (!(area.attribute.workspaceMask & (1 << (i + 1)))) { // Right
if (!(area.attribute.workspaceMask & (1 << (i + offset + 1))) || i == count) { // Right
cr.arc(wsCenterX, wsCenterY, workspaceRadius, -0.5 * Math.PI, 0.5 * Math.PI);
cr.fill();
}
@@ -130,8 +131,14 @@ const WorkspaceContents = (count = 10) => {
cr.fill();
// inner decor
cr.setSourceRGBA(activefg.red, activefg.green, activefg.blue, activefg.alpha);
cr.arc(activeWsCenterX, activeWsCenterY, indicatorRadius * 0.2, 0, 2 * Math.PI);
cr.fill();
//cr.arc(activeWsCenterX, activeWsCenterY, indicatorRadius * 0.2, 0, 2 * Math.PI);
//cr.fill();
layout.set_text(`${Hyprland.active.workspace.id}`, -1);
const [layoutWidthWSActive, layoutHeightWSActive] = layout.get_pixel_size();
const x = activeWsCenterX - (layoutWidthWSActive / 2);
const y = activeWsCenterY - (layoutHeightWSActive / 2);
cr.moveTo(x, y);
PangoCairo.show_layout(cr, layout);
}))
,
})
@@ -142,16 +149,19 @@ export default () => EventBox({
onScrollDown: () => Hyprland.sendMessage(`dispatch workspace +1`),
onMiddleClickRelease: () => App.toggleWindow('overview'),
onSecondaryClickRelease: () => App.toggleWindow('osk'),
attribute: { clicked: false },
attribute: {
clicked: false,
ws_group: 0,
},
child: Box({
homogeneous: true,
className: 'bar-group-margin',
children: [Box({
className: 'bar-group bar-group-standalone bar-group-pad',
css: 'min-width: 2px;',
children: [
WorkspaceContents(10),
]
children: Array.from({ length: NUM_WS_GROUPS }, (_, index) =>
WorkspaceContents(index*NUM_OF_WORKSPACES_PER_GROUP, NUM_OF_WORKSPACES_PER_GROUP)
)
})]
}),
setup: (self) => {
@@ -160,7 +170,7 @@ export default () => EventBox({
if (!self.attribute.clicked) return;
const [_, cursorX, cursorY] = event.get_coords();
const widgetWidth = self.get_allocation().width;
const wsId = Math.ceil(cursorX * NUM_OF_WORKSPACES / widgetWidth);
const wsId = Math.ceil(cursorX * NUM_OF_WORKSPACES_PER_GROUP / widgetWidth) + self.attribute.ws_group*NUM_OF_WORKSPACES_PER_GROUP;
Hyprland.sendMessage(`dispatch workspace ${wsId}`)
})
self.on('button-press-event', (self, event) => {
@@ -168,9 +178,15 @@ export default () => EventBox({
self.attribute.clicked = true;
const [_, cursorX, cursorY] = event.get_coords();
const widgetWidth = self.get_allocation().width;
const wsId = Math.ceil(cursorX * NUM_OF_WORKSPACES / widgetWidth);
const wsId = Math.ceil(cursorX * NUM_OF_WORKSPACES_PER_GROUP / widgetWidth) + self.attribute.ws_group*NUM_OF_WORKSPACES_PER_GROUP;
Hyprland.sendMessage(`dispatch workspace ${wsId}`);
})
self.on('button-release-event', (self) => self.attribute.clicked = false);
self.hook(Hyprland.active.workspace, (self) => {
self.attribute.ws_group = Math.floor((Hyprland.active.workspace.id-1)/NUM_OF_WORKSPACES_PER_GROUP);
for (let i = 0; i < self.child.children[0].children.length; i++) {
self.child.children[0].children[i].set_visible(self.attribute.ws_group == i);
}
});
}
})
@@ -13,6 +13,8 @@ import { dumpToWorkspace, swapWorkspace } from "./actions.js";
const OVERVIEW_SCALE = 0.18; // = overview workspace box / screen size
const OVERVIEW_WS_NUM_SCALE = 0.09;
const OVERVIEW_WS_NUM_MARGIN_SCALE = 0.07;
const NUM_WS_GROUPS = 3;
const NUM_OF_WORKSPACES_PER_GROUP = 10;
const TARGET = [Gtk.TargetEntry.new('text/plain', Gtk.TargetFlags.SAME_APP, 0)];
const overviewTick = Variable(false);
@@ -76,7 +78,9 @@ const ContextMenuWorkspaceArray = ({ label, actionFunc, thisWorkspace }) => Widg
setup: (menuItem) => {
let submenu = new Gtk.Menu();
submenu.className = 'menu';
for (let i = 1; i <= 10; i++) {
const startWorkspace = Math.floor((thisWorkspace-1)/NUM_OF_WORKSPACES_PER_GROUP)*NUM_OF_WORKSPACES_PER_GROUP + 1;
const endWorkspace = startWorkspace + NUM_OF_WORKSPACES_PER_GROUP-1;
for (let i = startWorkspace; i <= endWorkspace; i++) {
let button = new Gtk.MenuItem({
label: `Workspace ${i}`
});
@@ -303,11 +307,18 @@ export default () => {
child: Widget.Box({
vertical: true,
className: 'overview-tasks',
children: [
OverviewRow({ startWorkspace: 1, workspaces: 5 }),
OverviewRow({ startWorkspace: 6, workspaces: 5 }),
]
children: Array.from({ length: NUM_WS_GROUPS*2 }, (_, index) =>
OverviewRow({ startWorkspace: 1 + index * 5, workspaces: 5 })
)
}),
setup: (self) => {
self.hook(Hyprland.active.workspace, (self) => {
const ws_group = Math.floor((Hyprland.active.workspace.id-1)/NUM_OF_WORKSPACES_PER_GROUP);
for (let i = 0; i < overviewRevealer.child.children.length; i++) {
self.child.children[i].set_visible(ws_group == Math.floor(i/2));
}
})
}
});
return overviewRevealer;
};
};