Fix overview widget for multi monitors (#1049)

This commit is contained in:
end-4
2025-02-15 16:27:09 +01:00
committed by GitHub
@@ -21,8 +21,9 @@ const NUM_OF_WORKSPACES_SHOWN = userOptions.overview.numOfCols * userOptions.ove
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);
const overviewMonitor = Variable(0);
export default (overviewMonitor = 0) => { export default () => {
const clientMap = new Map(); const clientMap = new Map();
const ContextMenuWorkspaceArray = ({ label, actionFunc, thisWorkspace }) => Widget.MenuItem({ const ContextMenuWorkspaceArray = ({ label, actionFunc, thisWorkspace }) => Widget.MenuItem({
label: `${label}`, label: `${label}`,
@@ -64,11 +65,14 @@ export default (overviewMonitor = 0) => {
if (monitors.length - 1 < monitor) { if (monitors.length - 1 < monitor) {
monitor = monitors.length - 1; monitor = monitors.length - 1;
} }
// Properly scale for multi monitors
w *= monitors[overviewMonitor.value].width / monitors[monitor].width;
h *= monitors[overviewMonitor.value].height / monitors[monitor].height;
// Truncate if offscreen // Truncate if offscreen
if (x + w > monitors[monitor].width) w = monitors[monitor].width - x; if (x + w > monitors[overviewMonitor.value].width) w = monitors[overviewMonitor.value].width - x;
if (y + h > monitors[monitor].height) h = monitors[monitor].height - y; if (y + h > monitors[overviewMonitor.value].height) h = monitors[overviewMonitor.value].height - y;
if(c.length == 0) c = initialClass; if (c.length == 0) c = initialClass;
const iconName = substitute(c); const iconName = substitute(c);
const appIcon = iconExists(iconName) ? Widget.Icon({ const appIcon = iconExists(iconName) ? Widget.Icon({
icon: iconName, icon: iconName,
@@ -148,10 +152,10 @@ export default (overviewMonitor = 0) => {
maxWidthChars: 1, // Doesn't matter what number maxWidthChars: 1, // Doesn't matter what number
truncate: 'end', truncate: 'end',
className: `margin-top-5 ${xwayland ? 'txt txt-italic' : 'txt'}`, className: `margin-top-5 ${xwayland ? 'txt txt-italic' : 'txt'}`,
css: ` css: overviewMonitor.bind().as(monitor => `
font-size: ${Math.min(monitors[monitor].width, monitors[monitor].height) * userOptions.overview.scale / 14.6}px; font-size: ${Math.min(monitors[monitor].width, monitors[monitor].height) * userOptions.overview.scale / 14.6}px;
margin: 0px ${Math.min(monitors[monitor].width, monitors[monitor].height) * userOptions.overview.scale / 10}px; margin: 0px ${Math.min(monitors[monitor].width, monitors[monitor].height) * userOptions.overview.scale / 10}px;
`, `),
// If the title is too short, include the class // If the title is too short, include the class
label: (title.length <= 1 ? `${c}: ${title}` : title), label: (title.length <= 1 ? `${c}: ${title}` : title),
}) })
@@ -220,10 +224,10 @@ export default (overviewMonitor = 0) => {
const WorkspaceNumber = ({ index, ...rest }) => Widget.Label({ const WorkspaceNumber = ({ index, ...rest }) => Widget.Label({
className: 'overview-tasks-workspace-number', className: 'overview-tasks-workspace-number',
label: `${index}`, label: `${index}`,
css: ` css: overviewMonitor.bind().as(monitor => `
margin: ${Math.min(monitors[overviewMonitor].width, monitors[overviewMonitor].height) * userOptions.overview.scale * userOptions.overview.wsNumMarginScale}px; margin: ${Math.min(monitors[monitor].width, monitors[monitor].height) * userOptions.overview.scale * userOptions.overview.wsNumMarginScale}px;
font-size: ${monitors[overviewMonitor].height * userOptions.overview.scale * userOptions.overview.wsNumScale}px; font-size: ${monitors[monitor].height * userOptions.overview.scale * userOptions.overview.wsNumScale}px;
`, `),
setup: (self) => self.hook(Hyprland.active.workspace, (self) => { setup: (self) => self.hook(Hyprland.active.workspace, (self) => {
// Update when going to new ws group // Update when going to new ws group
const currentGroup = Math.floor((Hyprland.active.workspace.id - 1) / NUM_OF_WORKSPACES_SHOWN); const currentGroup = Math.floor((Hyprland.active.workspace.id - 1) / NUM_OF_WORKSPACES_SHOWN);
@@ -235,10 +239,10 @@ export default (overviewMonitor = 0) => {
className: 'overview-tasks-workspace', className: 'overview-tasks-workspace',
vpack: 'center', vpack: 'center',
// Rounding and adding 1px to minimum width/height to work around scaling inaccuracy: // Rounding and adding 1px to minimum width/height to work around scaling inaccuracy:
css: ` css: overviewMonitor.bind().as(monitor => `
min-width: ${1 + Math.round(monitors[overviewMonitor].width * userOptions.overview.scale)}px; min-width: ${1 + Math.round(monitors[monitor].width * userOptions.overview.scale)}px;
min-height: ${1 + Math.round(monitors[overviewMonitor].height * userOptions.overview.scale)}px; min-height: ${1 + Math.round(monitors[monitor].height * userOptions.overview.scale)}px;
`, `),
children: [Widget.EventBox({ children: [Widget.EventBox({
hexpand: true, hexpand: true,
onPrimaryClick: () => { onPrimaryClick: () => {
@@ -410,7 +414,10 @@ export default (overviewMonitor = 0) => {
} }
}) })
.hook(App, (box, name, visible) => { // Update on open .hook(App, (box, name, visible) => { // Update on open
if (name == 'overview' && visible) box.attribute.update(box); if (name == 'overview' && visible) {
overviewMonitor.value = Hyprland.active.monitor.id;
box.attribute.update(box);
}
}) })
}, },
}); });