diff --git a/.config/ags/scripts/hyprland/workspace_action.sh b/.config/ags/scripts/hyprland/workspace_action.sh index adfc19e7..8f390cf6 100755 --- a/.config/ags/scripts/hyprland/workspace_action.sh +++ b/.config/ags/scripts/hyprland/workspace_action.sh @@ -1,2 +1,2 @@ #!/bin/bash -hyprctl dispatch $1 $((((`hyprctl activeworkspace -j | jq -r .id` - 1) / 10) * 10 + $2)) +hyprctl dispatch "$1" $(((($(hyprctl activeworkspace -j | gojq -r .id) - 1) / 10) * 10 + $2)) diff --git a/.config/ags/widgets/bar/workspaces_hyprland.js b/.config/ags/widgets/bar/workspaces_hyprland.js index 757d622a..87353da6 100644 --- a/.config/ags/widgets/bar/workspaces_hyprland.js +++ b/.config/ags/widgets/bar/workspaces_hyprland.js @@ -4,37 +4,37 @@ const Cairo = imports.cairo; const Pango = imports.gi.Pango; const PangoCairo = imports.gi.PangoCairo; import App from 'resource:///com/github/Aylur/ags/app.js'; +import * as Utils from 'resource:///com/github/Aylur/ags/utils.js' 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_WS_GROUPS = 3; -const NUM_OF_WORKSPACES_PER_GROUP = 10; +const NUM_OF_WORKSPACES_SHOWN = 10; // Limit = 53 I think 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 = (offset = 0, count = 10) => { +const WorkspaceContents = (count = 10) => { return DrawingArea({ - css: `transition: 90ms cubic-bezier(0.1, 1, 0, 1);`, + // css: `transition: 90ms cubic-bezier(0.1, 1, 0, 1);`, attribute: { initialized: false, workspaceMask: 0, updateMask: (self) => { - if (self.attribute.initialized) return; // We only need this to run once + const offset = Math.floor((Hyprland.active.workspace.id - 1) / count) * NUM_OF_WORKSPACES_SHOWN; + // if (self.attribute.initialized) return; // We only need this to run once const workspaces = Hyprland.workspaces; let workspaceMask = 0; for (let i = 0; i < workspaces.length; i++) { const ws = workspaces[i]; - if (ws.id <= offset) continue; // Ignore scratchpads - if (ws.id > offset + count) continue; // Not rendered - if (workspaces[i].windows > 0) { - workspaceMask |= (1 << ws.id); - } + if (ws.id <= offset || ws.id > offset + count) continue; // Out of range, ignore + if (workspaces[i].windows > 0) + workspaceMask |= (1 << (ws.id - offset)); } + // console.log('Mask:', workspaceMask.toString(2)); self.attribute.workspaceMask = workspaceMask; - self.attribute.initialized = true; + // self.attribute.initialized = true; }, toggleMask: (self, occupied, name) => { if (occupied) self.attribute.workspaceMask |= (1 << parseInt(name)); @@ -42,13 +42,17 @@ const WorkspaceContents = (offset = 0, count = 10) => { }, }, setup: (area) => area - .hook(Hyprland.active.workspace, (area) => - area.setCss(`font-size: ${(Hyprland.active.workspace.id-1) % NUM_OF_WORKSPACES_PER_GROUP + 1}px;`) - ) + .hook(Hyprland.active.workspace, (self) => { + self.setCss(`font-size: ${(Hyprland.active.workspace.id - 1) % count + 1}px;`); + self.attribute.updateMask(self); + self.queue_draw(); + }) .hook(Hyprland, (self) => self.attribute.updateMask(self), 'notify::workspaces') .hook(Hyprland, (self, name) => self.attribute.toggleMask(self, true, name), 'workspace-added') .hook(Hyprland, (self, name) => self.attribute.toggleMask(self, false, name), 'workspace-removed') .on('draw', Lang.bind(area, (area, cr) => { + const offset = Math.floor((Hyprland.active.workspace.id - 1) / count) * NUM_OF_WORKSPACES_SHOWN; + const allocation = area.get_allocation(); const { width, height } = allocation; @@ -87,12 +91,12 @@ const WorkspaceContents = (offset = 0, count = 10) => { // Draw workspace numbers for (let i = 1; i <= count; i++) { - if (area.attribute.workspaceMask & (1 << (i + offset))) { + if (area.attribute.workspaceMask & (1 << i)) { // 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 + offset - 1))) || i == 1) { // Left + if (!(area.attribute.workspaceMask & (1 << (i - 1)))) { // Left cr.arc(wsCenterX, wsCenterY, workspaceRadius, 0.5 * Math.PI, 1.5 * Math.PI); cr.fill(); } @@ -100,7 +104,7 @@ const WorkspaceContents = (offset = 0, count = 10) => { cr.rectangle(wsCenterX - workspaceRadius, wsCenterY - workspaceRadius, workspaceRadius, workspaceRadius * 2) cr.fill(); } - if (!(area.attribute.workspaceMask & (1 << (i + offset + 1))) || i == count) { // Right + if (!(area.attribute.workspaceMask & (1 << (i + 1)))) { // Right cr.arc(wsCenterX, wsCenterY, workspaceRadius, -0.5 * Math.PI, 0.5 * Math.PI); cr.fill(); } @@ -114,12 +118,12 @@ const WorkspaceContents = (offset = 0, count = 10) => { } else cr.setSourceRGBA(wsfg.red, wsfg.green, wsfg.blue, wsfg.alpha); - layout.set_text(`${i}`, -1); + + layout.set_text(`${i + offset}`, -1); const [layoutWidth, layoutHeight] = layout.get_pixel_size(); const x = -workspaceRadius + (workspaceDiameter * i) - (layoutWidth / 2); const y = (height - layoutHeight) / 2; cr.moveTo(x, y); - // cr.showText(text); PangoCairo.show_layout(cr, layout); cr.stroke(); } @@ -131,14 +135,8 @@ const WorkspaceContents = (offset = 0, 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(); - 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); + cr.arc(activeWsCenterX, activeWsCenterY, indicatorRadius * 0.2, 0, 2 * Math.PI); + cr.fill(); })) , }) @@ -150,8 +148,8 @@ export default () => EventBox({ onMiddleClickRelease: () => App.toggleWindow('overview'), onSecondaryClickRelease: () => App.toggleWindow('osk'), attribute: { - clicked: false, - ws_group: 0, + clicked: false, + ws_group: 0, }, child: Box({ homogeneous: true, @@ -159,9 +157,7 @@ export default () => EventBox({ children: [Box({ className: 'bar-group bar-group-standalone bar-group-pad', css: 'min-width: 2px;', - children: Array.from({ length: NUM_WS_GROUPS }, (_, index) => - WorkspaceContents(index*NUM_OF_WORKSPACES_PER_GROUP, NUM_OF_WORKSPACES_PER_GROUP) - ) + children: [WorkspaceContents(NUM_OF_WORKSPACES_SHOWN)], })] }), setup: (self) => { @@ -170,23 +166,19 @@ 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_PER_GROUP / widgetWidth) + self.attribute.ws_group*NUM_OF_WORKSPACES_PER_GROUP; - Hyprland.sendMessage(`dispatch workspace ${wsId}`) + const wsId = Math.ceil(cursorX * NUM_OF_WORKSPACES_SHOWN / widgetWidth); + Utils.execAsync([`${App.configDir}/scripts/hyprland/workspace_action.sh`, 'workspace', `${wsId}`]); }) self.on('button-press-event', (self, event) => { if (!(event.get_button()[1] === 1)) return; // We're only interested in left-click here self.attribute.clicked = true; const [_, cursorX, cursorY] = event.get_coords(); const widgetWidth = self.get_allocation().width; - 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}`); + // 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}`); + const wsId = Math.ceil(cursorX * NUM_OF_WORKSPACES_SHOWN / widgetWidth); + Utils.execAsync([`${App.configDir}/scripts/hyprland/workspace_action.sh`, '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); - } - }); } })