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; const { Box, DrawingArea, EventBox } = Widget;
import Hyprland from 'resource:///com/github/Aylur/ags/service/hyprland.js'; 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 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 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 const dummyOccupiedWs = Box({ className: 'bar-ws bar-ws-occupied' }); // Not shown. Only for getting size props
// Font size = workspace id // Font size = workspace id
const WorkspaceContents = (count = 10) => { const WorkspaceContents = (offset = 0, count = 10) => {
return DrawingArea({ return DrawingArea({
css: `transition: 90ms cubic-bezier(0.1, 1, 0, 1);`, css: `transition: 90ms cubic-bezier(0.1, 1, 0, 1);`,
attribute: { attribute: {
@@ -26,8 +27,8 @@ const WorkspaceContents = (count = 10) => {
let workspaceMask = 0; let workspaceMask = 0;
for (let i = 0; i < workspaces.length; i++) { for (let i = 0; i < workspaces.length; i++) {
const ws = workspaces[i]; const ws = workspaces[i];
if (ws.id <= 0) continue; // Ignore scratchpads if (ws.id <= offset) continue; // Ignore scratchpads
if (ws.id > count) return; // Not rendered if (ws.id > offset + count) continue; // Not rendered
if (workspaces[i].windows > 0) { if (workspaces[i].windows > 0) {
workspaceMask |= (1 << ws.id); workspaceMask |= (1 << ws.id);
} }
@@ -42,7 +43,7 @@ const WorkspaceContents = (count = 10) => {
}, },
setup: (area) => area setup: (area) => area
.hook(Hyprland.active.workspace, (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) => 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, true, name), 'workspace-added')
@@ -86,12 +87,12 @@ const WorkspaceContents = (count = 10) => {
// Draw workspace numbers // Draw workspace numbers
for (let i = 1; i <= count; i++) { for (let i = 1; i <= count; i++) {
if (area.attribute.workspaceMask & (1 << i)) { if (area.attribute.workspaceMask & (1 << (i + offset))) {
// Draw bg highlight // Draw bg highlight
cr.setSourceRGBA(occupiedbg.red, occupiedbg.green, occupiedbg.blue, occupiedbg.alpha); cr.setSourceRGBA(occupiedbg.red, occupiedbg.green, occupiedbg.blue, occupiedbg.alpha);
const wsCenterX = -(workspaceRadius) + (workspaceDiameter * i); const wsCenterX = -(workspaceRadius) + (workspaceDiameter * i);
const wsCenterY = height / 2; 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.arc(wsCenterX, wsCenterY, workspaceRadius, 0.5 * Math.PI, 1.5 * Math.PI);
cr.fill(); cr.fill();
} }
@@ -99,7 +100,7 @@ const WorkspaceContents = (count = 10) => {
cr.rectangle(wsCenterX - workspaceRadius, wsCenterY - workspaceRadius, workspaceRadius, workspaceRadius * 2) cr.rectangle(wsCenterX - workspaceRadius, wsCenterY - workspaceRadius, workspaceRadius, workspaceRadius * 2)
cr.fill(); 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.arc(wsCenterX, wsCenterY, workspaceRadius, -0.5 * Math.PI, 0.5 * Math.PI);
cr.fill(); cr.fill();
} }
@@ -130,8 +131,14 @@ const WorkspaceContents = (count = 10) => {
cr.fill(); cr.fill();
// inner decor // inner decor
cr.setSourceRGBA(activefg.red, activefg.green, activefg.blue, activefg.alpha); cr.setSourceRGBA(activefg.red, activefg.green, activefg.blue, activefg.alpha);
cr.arc(activeWsCenterX, activeWsCenterY, indicatorRadius * 0.2, 0, 2 * Math.PI); //cr.arc(activeWsCenterX, activeWsCenterY, indicatorRadius * 0.2, 0, 2 * Math.PI);
cr.fill(); //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`), onScrollDown: () => Hyprland.sendMessage(`dispatch workspace +1`),
onMiddleClickRelease: () => App.toggleWindow('overview'), onMiddleClickRelease: () => App.toggleWindow('overview'),
onSecondaryClickRelease: () => App.toggleWindow('osk'), onSecondaryClickRelease: () => App.toggleWindow('osk'),
attribute: { clicked: false }, attribute: {
clicked: false,
ws_group: 0,
},
child: Box({ child: Box({
homogeneous: true, homogeneous: true,
className: 'bar-group-margin', className: 'bar-group-margin',
children: [Box({ children: [Box({
className: 'bar-group bar-group-standalone bar-group-pad', className: 'bar-group bar-group-standalone bar-group-pad',
css: 'min-width: 2px;', css: 'min-width: 2px;',
children: [ children: Array.from({ length: NUM_WS_GROUPS }, (_, index) =>
WorkspaceContents(10), WorkspaceContents(index*NUM_OF_WORKSPACES_PER_GROUP, NUM_OF_WORKSPACES_PER_GROUP)
] )
})] })]
}), }),
setup: (self) => { setup: (self) => {
@@ -160,7 +170,7 @@ export default () => EventBox({
if (!self.attribute.clicked) return; if (!self.attribute.clicked) return;
const [_, cursorX, cursorY] = event.get_coords(); const [_, cursorX, cursorY] = event.get_coords();
const widgetWidth = self.get_allocation().width; 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}`) Hyprland.sendMessage(`dispatch workspace ${wsId}`)
}) })
self.on('button-press-event', (self, event) => { self.on('button-press-event', (self, event) => {
@@ -168,9 +178,15 @@ export default () => EventBox({
self.attribute.clicked = true; self.attribute.clicked = true;
const [_, cursorX, cursorY] = event.get_coords(); const [_, cursorX, cursorY] = event.get_coords();
const widgetWidth = self.get_allocation().width; 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}`); Hyprland.sendMessage(`dispatch workspace ${wsId}`);
}) })
self.on('button-release-event', (self) => self.attribute.clicked = false); 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_SCALE = 0.18; // = overview workspace box / screen size
const OVERVIEW_WS_NUM_SCALE = 0.09; const OVERVIEW_WS_NUM_SCALE = 0.09;
const OVERVIEW_WS_NUM_MARGIN_SCALE = 0.07; 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 TARGET = [Gtk.TargetEntry.new('text/plain', Gtk.TargetFlags.SAME_APP, 0)];
const overviewTick = Variable(false); const overviewTick = Variable(false);
@@ -76,7 +78,9 @@ const ContextMenuWorkspaceArray = ({ label, actionFunc, thisWorkspace }) => Widg
setup: (menuItem) => { setup: (menuItem) => {
let submenu = new Gtk.Menu(); let submenu = new Gtk.Menu();
submenu.className = '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({ let button = new Gtk.MenuItem({
label: `Workspace ${i}` label: `Workspace ${i}`
}); });
@@ -303,11 +307,18 @@ export default () => {
child: Widget.Box({ child: Widget.Box({
vertical: true, vertical: true,
className: 'overview-tasks', className: 'overview-tasks',
children: [ children: Array.from({ length: NUM_WS_GROUPS*2 }, (_, index) =>
OverviewRow({ startWorkspace: 1, workspaces: 5 }), OverviewRow({ startWorkspace: 1 + index * 5, workspaces: 5 })
OverviewRow({ startWorkspace: 6, 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; return overviewRevealer;
}; };
+20 -20
View File
@@ -150,32 +150,32 @@ bind = Super, D, fullscreen, 1
bind = Super_Alt, F, fakefullscreen, 0 bind = Super_Alt, F, fakefullscreen, 0
# Switching # Switching
bind = Super, 1, workspace, 1 bind = Super, 1, exec, ~/.config/hypr/workspace_action.sh workspace 1
bind = Super, 2, workspace, 2 bind = Super, 2, exec, ~/.config/hypr/workspace_action.sh workspace 2
bind = Super, 3, workspace, 3 bind = Super, 3, exec, ~/.config/hypr/workspace_action.sh workspace 3
bind = Super, 4, workspace, 4 bind = Super, 4, exec, ~/.config/hypr/workspace_action.sh workspace 4
bind = Super, 5, workspace, 5 bind = Super, 5, exec, ~/.config/hypr/workspace_action.sh workspace 5
bind = Super, 6, workspace, 6 bind = Super, 6, exec, ~/.config/hypr/workspace_action.sh workspace 6
bind = Super, 7, workspace, 7 bind = Super, 7, exec, ~/.config/hypr/workspace_action.sh workspace 7
bind = Super, 8, workspace, 8 bind = Super, 8, exec, ~/.config/hypr/workspace_action.sh workspace 8
bind = Super, 9, workspace, 9 bind = Super, 9, exec, ~/.config/hypr/workspace_action.sh workspace 9
bind = Super, 0, workspace, 10 bind = Super, 0, exec, ~/.config/hypr/workspace_action.sh workspace 10
bind = Super, S, togglespecialworkspace, bind = Super, S, togglespecialworkspace,
bind = Control+Super, S, togglespecialworkspace, bind = Control+Super, S, togglespecialworkspace,
bind = Alt, Tab, cyclenext bind = Alt, Tab, cyclenext
bind = Alt, Tab, bringactivetotop, # bring it to the top bind = Alt, Tab, bringactivetotop, # bring it to the top
# Move window to workspace Super + Alt + [0-9] # Move window to workspace Super + Alt + [0-9]
bind = Super+Alt, 1, movetoworkspacesilent, 1 bind = Super+Alt, 1, exec, ~/.config/hypr/workspace_action.sh movetoworkspace 1
bind = Super+Alt, 2, movetoworkspacesilent, 2 bind = Super+Alt, 2, exec, ~/.config/hypr/workspace_action.sh movetoworkspace 2
bind = Super+Alt, 3, movetoworkspacesilent, 3 bind = Super+Alt, 3, exec, ~/.config/hypr/workspace_action.sh movetoworkspace 3
bind = Super+Alt, 4, movetoworkspacesilent, 4 bind = Super+Alt, 4, exec, ~/.config/hypr/workspace_action.sh movetoworkspace 4
bind = Super+Alt, 5, movetoworkspacesilent, 5 bind = Super+Alt, 5, exec, ~/.config/hypr/workspace_action.sh movetoworkspace 5
bind = Super+Alt, 6, movetoworkspacesilent, 6 bind = Super+Alt, 6, exec, ~/.config/hypr/workspace_action.sh movetoworkspace 6
bind = Super+Alt, 7, movetoworkspacesilent, 7 bind = Super+Alt, 7, exec, ~/.config/hypr/workspace_action.sh movetoworkspace 7
bind = Super+Alt, 8, movetoworkspacesilent, 8 bind = Super+Alt, 8, exec, ~/.config/hypr/workspace_action.sh movetoworkspace 8
bind = Super+Alt, 9, movetoworkspacesilent, 9 bind = Super+Alt, 9, exec, ~/.config/hypr/workspace_action.sh movetoworkspace 9
bind = Super+Alt, 0, movetoworkspacesilent, 10 bind = Super+Alt, 0, exec, ~/.config/hypr/workspace_action.sh movetoworkspace 10
bind = Control+Shift+Super, Up, movetoworkspacesilent, special bind = Control+Shift+Super, Up, movetoworkspacesilent, special
bind = Super+Alt, S, movetoworkspacesilent, special bind = Super+Alt, S, movetoworkspacesilent, special
+2
View File
@@ -0,0 +1,2 @@
#!/bin/bash
hyprctl dispatch $1 $((((`hyprctl activeworkspace -j | jq -r .id` - 1) / 10) * 10 + $2))