forked from Shinonome/dots-hyprland
overview: make #209 work for any number of ws (within hyprland's limit)
This commit is contained in:
@@ -10,44 +10,16 @@ const { execAsync, exec } = Utils;
|
|||||||
import { setupCursorHoverGrab } from "../../lib/cursorhover.js";
|
import { setupCursorHoverGrab } from "../../lib/cursorhover.js";
|
||||||
import { dumpToWorkspace, swapWorkspace } from "./actions.js";
|
import { dumpToWorkspace, swapWorkspace } from "./actions.js";
|
||||||
|
|
||||||
const OVERVIEW_SCALE = 0.18; // = overview workspace box / screen size
|
const OVERVIEW_SCALE = 0.18;
|
||||||
|
const NUM_OF_WORKSPACE_ROWS = 2;
|
||||||
|
const NUM_OF_WORKSPACE_COLS = 5;
|
||||||
const OVERVIEW_WS_NUM_SCALE = 0.09;
|
const OVERVIEW_WS_NUM_SCALE = 0.09;
|
||||||
|
const NUM_OF_WORKSPACES_SHOWN = NUM_OF_WORKSPACE_COLS * NUM_OF_WORKSPACE_ROWS;
|
||||||
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);
|
||||||
|
|
||||||
function truncateTitle(str) {
|
|
||||||
let lastDash = -1;
|
|
||||||
let found = -1; // 0: em dash, 1: en dash, 2: minus, 3: vertical bar, 4: middle dot
|
|
||||||
for (let i = str.length - 1; i >= 0; i--) {
|
|
||||||
if (str[i] === '—') {
|
|
||||||
found = 0;
|
|
||||||
lastDash = i;
|
|
||||||
}
|
|
||||||
else if (str[i] === '–' && found < 1) {
|
|
||||||
found = 1;
|
|
||||||
lastDash = i;
|
|
||||||
}
|
|
||||||
else if (str[i] === '-' && found < 2) {
|
|
||||||
found = 2;
|
|
||||||
lastDash = i;
|
|
||||||
}
|
|
||||||
else if (str[i] === '|' && found < 3) {
|
|
||||||
found = 3;
|
|
||||||
lastDash = i;
|
|
||||||
}
|
|
||||||
else if (str[i] === '·' && found < 4) {
|
|
||||||
found = 4;
|
|
||||||
lastDash = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (lastDash === -1) return str;
|
|
||||||
return str.substring(0, lastDash);
|
|
||||||
}
|
|
||||||
|
|
||||||
function iconExists(iconName) {
|
function iconExists(iconName) {
|
||||||
let iconTheme = Gtk.IconTheme.get_default();
|
let iconTheme = Gtk.IconTheme.get_default();
|
||||||
return iconTheme.has_icon(iconName);
|
return iconTheme.has_icon(iconName);
|
||||||
@@ -78,8 +50,10 @@ 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';
|
||||||
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;
|
const offset = Math.floor((Hyprland.active.workspace.id - 1) / NUM_OF_WORKSPACES_SHOWN) * NUM_OF_WORKSPACES_SHOWN;
|
||||||
|
const startWorkspace = offset + 1;
|
||||||
|
const endWorkspace = startWorkspace + NUM_OF_WORKSPACES_SHOWN - 1;
|
||||||
for (let i = startWorkspace; i <= endWorkspace; i++) {
|
for (let i = startWorkspace; i <= endWorkspace; i++) {
|
||||||
let button = new Gtk.MenuItem({
|
let button = new Gtk.MenuItem({
|
||||||
label: `Workspace ${i}`
|
label: `Workspace ${i}`
|
||||||
@@ -95,9 +69,14 @@ const ContextMenuWorkspaceArray = ({ label, actionFunc, thisWorkspace }) => Widg
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const client = ({ address, size: [w, h], workspace: { id, name }, class: c, title, xwayland }) => {
|
const Window = ({ address, at: [x, y], size: [w, h], workspace: { id, name }, class: c, title, xwayland }) => {
|
||||||
const revealInfoCondition = (Math.min(w, h) * OVERVIEW_SCALE > 70);
|
const revealInfoCondition = (Math.min(w, h) * OVERVIEW_SCALE > 70);
|
||||||
if (w <= 0 || h <= 0) return null;
|
if (w <= 0 || h <= 0) return null;
|
||||||
|
if (x + w > SCREEN_WIDTH) w = SCREEN_WIDTH - x;
|
||||||
|
if (y + h > SCREEN_HEIGHT) h = SCREEN_HEIGHT - y;
|
||||||
|
if (x < 0) w = x + w; // We only have to handle w/h. Pos determined at put()
|
||||||
|
if (y < 0) h = y + h; // We only have to handle w/h. Pos determined at put()
|
||||||
|
|
||||||
// title = truncateTitle(title);
|
// title = truncateTitle(title);
|
||||||
return Widget.Button({
|
return Widget.Button({
|
||||||
className: 'overview-tasks-window',
|
className: 'overview-tasks-window',
|
||||||
@@ -192,7 +171,7 @@ const client = ({ address, size: [w, h], workspace: { id, name }, class: c, titl
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const workspace = index => {
|
const Workspace = (index) => {
|
||||||
const fixed = Gtk.Fixed.new();
|
const fixed = Gtk.Fixed.new();
|
||||||
const WorkspaceNumber = (index) => Widget.Label({
|
const WorkspaceNumber = (index) => Widget.Label({
|
||||||
className: 'overview-tasks-workspace-number',
|
className: 'overview-tasks-workspace-number',
|
||||||
@@ -206,8 +185,8 @@ const workspace = index => {
|
|||||||
className: 'overview-tasks-workspace',
|
className: 'overview-tasks-workspace',
|
||||||
vpack: 'center',
|
vpack: 'center',
|
||||||
css: `
|
css: `
|
||||||
min-width: ${SCREEN_WIDTH * OVERVIEW_SCALE}px;
|
min-width: ${SCREEN_WIDTH * OVERVIEW_SCALE}px;
|
||||||
min-height: ${SCREEN_HEIGHT * OVERVIEW_SCALE}px;
|
min-height: ${SCREEN_HEIGHT * OVERVIEW_SCALE}px;
|
||||||
`,
|
`,
|
||||||
children: [Widget.EventBox({
|
children: [Widget.EventBox({
|
||||||
hexpand: true,
|
hexpand: true,
|
||||||
@@ -227,33 +206,23 @@ const workspace = index => {
|
|||||||
})],
|
})],
|
||||||
});
|
});
|
||||||
widget.update = (clients) => {
|
widget.update = (clients) => {
|
||||||
clients = clients.filter(({ workspace: { id } }) => id === index);
|
const offset = Math.floor((Hyprland.active.workspace.id - 1) / NUM_OF_WORKSPACES_SHOWN) * NUM_OF_WORKSPACES_SHOWN;
|
||||||
|
clients = clients.filter(({ workspace: { id } }) => (id) === index + offset);
|
||||||
// this is for my monitor layout
|
|
||||||
// shifts clients back by SCREEN_WIDTHpx if necessary
|
|
||||||
clients = clients.map(client => {
|
|
||||||
const [x, y] = client.at;
|
|
||||||
if (x > SCREEN_WIDTH)
|
|
||||||
client.at = [x - SCREEN_WIDTH, y];
|
|
||||||
return client;
|
|
||||||
});
|
|
||||||
|
|
||||||
const children = fixed.get_children();
|
const children = fixed.get_children();
|
||||||
for (let i = 0; i < children.length; i++) {
|
for (let i = 0; i < children.length; i++) {
|
||||||
const child = children[i];
|
const child = children[i];
|
||||||
child.destroy();
|
child.destroy();
|
||||||
}
|
}
|
||||||
fixed.put(WorkspaceNumber(index), 0, 0);
|
fixed.put(WorkspaceNumber(index + offset), 0, 0);
|
||||||
|
|
||||||
for (let i = 0; i < clients.length; i++) {
|
for (let i = 0; i < clients.length; i++) {
|
||||||
const c = clients[i];
|
const c = clients[i];
|
||||||
if (c.mapped) {
|
if (c.mapped) {
|
||||||
fixed.put(client(c), c.at[0] * OVERVIEW_SCALE, c.at[1] * OVERVIEW_SCALE);
|
fixed.put(Window(c), Math.max(0, c.at[0] * OVERVIEW_SCALE), Math.max(0, c.at[1] * OVERVIEW_SCALE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fixed.show_all();
|
fixed.show_all();
|
||||||
};
|
};
|
||||||
return widget;
|
return widget;
|
||||||
@@ -267,36 +236,39 @@ const arr = (s, n) => {
|
|||||||
return array;
|
return array;
|
||||||
};
|
};
|
||||||
|
|
||||||
const OverviewRow = ({ startWorkspace, workspaces, windowName = 'overview' }) => Widget.Box({
|
const OverviewRow = ({ startWorkspace, workspaces, windowName = 'overview' }) => {
|
||||||
children: arr(startWorkspace, workspaces).map(workspace),
|
return Widget.Box({
|
||||||
attribute: {
|
children: arr(startWorkspace, workspaces).map(Workspace),
|
||||||
'update': box => {
|
attribute: {
|
||||||
if (!App.getWindow(windowName).visible) return;
|
update: box => {
|
||||||
execAsync('hyprctl -j clients').then(clients => {
|
if (!App.getWindow(windowName).visible) return;
|
||||||
const json = JSON.parse(clients);
|
execAsync('hyprctl -j clients').then(clients => {
|
||||||
const children = box.get_children();
|
const json = JSON.parse(clients);
|
||||||
for (let i = 0; i < children.length; i++) {
|
const children = box.get_children();
|
||||||
const ch = children[i];
|
for (let i = 0; i < children.length; i++) {
|
||||||
ch.update(json)
|
const ch = children[i];
|
||||||
}
|
ch.update(json)
|
||||||
|
}
|
||||||
|
|
||||||
}).catch(print);
|
}).catch(print);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setup: (box) => box
|
setup: (box) => box
|
||||||
.hook(overviewTick, (box) => box.attribute.update(box))
|
.hook(overviewTick, (box) => box.attribute.update(box))
|
||||||
// .hook(Hyprland, (box, name, data) => { // idk, does this make it lag occasionally?
|
// .hook(Hyprland, (box, name, data) => { // idk, does this make it lag occasionally?
|
||||||
// console.log(name)
|
// console.log(name)
|
||||||
// if (["changefloatingmode", "movewindow"].includes(name))
|
// if (["changefloatingmode", "movewindow"].includes(name))
|
||||||
// box.attribute.update(box);
|
// box.attribute.update(box);
|
||||||
// }, 'event')
|
// }, 'event')
|
||||||
.hook(Hyprland, (box) => box.attribute.update(box), 'client-added')
|
.hook(Hyprland, (box) => box.attribute.update(box), 'client-removed')
|
||||||
.hook(Hyprland, (box) => box.attribute.update(box), 'client-removed')
|
.hook(Hyprland, (box) => box.attribute.update(box), 'client-added')
|
||||||
.hook(App, (box, name, visible) => { // Update on open
|
.hook(Hyprland.active.workspace, (box) => box.attribute.update(box))
|
||||||
if (name == 'overview' && visible) box.attribute.update(box);
|
.hook(App, (box, name, visible) => { // Update on open
|
||||||
})
|
if (name == 'overview' && visible) box.attribute.update(box);
|
||||||
,
|
})
|
||||||
});
|
,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export default () => {
|
export default () => {
|
||||||
@@ -307,18 +279,13 @@ export default () => {
|
|||||||
child: Widget.Box({
|
child: Widget.Box({
|
||||||
vertical: true,
|
vertical: true,
|
||||||
className: 'overview-tasks',
|
className: 'overview-tasks',
|
||||||
children: Array.from({ length: NUM_WS_GROUPS*2 }, (_, index) =>
|
children: Array.from({ length: NUM_OF_WORKSPACE_ROWS }, (_, index) =>
|
||||||
OverviewRow({ startWorkspace: 1 + index * 5, workspaces: 5 })
|
OverviewRow({
|
||||||
|
startWorkspace: 1 + index * NUM_OF_WORKSPACE_COLS,
|
||||||
|
workspaces: NUM_OF_WORKSPACE_COLS
|
||||||
|
})
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user