Skip to content

Commit

Permalink
Fix matching of scaled monitors
Browse files Browse the repository at this point in the history
  • Loading branch information
Sawy7 committed Jan 31, 2025
1 parent 74065af commit ff0cb1c
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/components/bar/utils/monitors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { BarLayout, BarLayouts } from 'src/lib/types/options';
type GdkMonitors = {
[key: string]: {
key: string;
width: number;
height: number;
scaleFactor: number;
model: string;
used: boolean;
};
Expand Down Expand Up @@ -61,7 +64,7 @@ export function getGdkMonitors(): GdkMonitors {
const scaleFactor = curMonitor.get_scale_factor();

const key = `${model}_${geometry.width}x${geometry.height}_${scaleFactor}`;
gdkMonitors[i] = { key, model, used: false };
gdkMonitors[i] = { key, width: geometry.width, height: geometry.height, scaleFactor, model, used: false };
}

return gdkMonitors;
Expand Down Expand Up @@ -120,10 +123,14 @@ export const gdkMonitorIdToHyprlandId = (monitor: number, usedHyprlandMonitors:
const isVertical = hypMon?.transform !== undefined ? hypMon.transform % 2 !== 0 : false;

const width = isVertical ? hypMon.height : hypMon.width;
const widthScaled = Math.trunc(width / gdkMonitor.scaleFactor);
const height = isVertical ? hypMon.width : hypMon.height;
const heightScaled = Math.trunc(height / gdkMonitor.scaleFactor);

const hyprlandKey = `${hypMon.model}_${width}x${height}_${hypMon.scale}`;
return gdkMonitor.key.startsWith(hyprlandKey) && !usedHyprlandMonitors.has(hypMon.id) && hypMon.id === monitor;
const hyprlandKeyStart = `${hypMon.model}_${widthScaled}x${heightScaled}`;
return (
gdkMonitor.key.startsWith(hyprlandKeyStart) && !usedHyprlandMonitors.has(hypMon.id) && hypMon.id === monitor
);
});

if (directMatch) {
Expand All @@ -136,10 +143,12 @@ export const gdkMonitorIdToHyprlandId = (monitor: number, usedHyprlandMonitors:
const isVertical = hypMon?.transform !== undefined ? hypMon.transform % 2 !== 0 : false;

const width = isVertical ? hypMon.height : hypMon.width;
const widthScaled = width / gdkMonitor.scaleFactor;
const height = isVertical ? hypMon.width : hypMon.height;
const heightScaled = height / gdkMonitor.scaleFactor;

const hyprlandKey = `${hypMon.model}_${width}x${height}_${hypMon.scale}`;
return gdkMonitor.key.startsWith(hyprlandKey) && !usedHyprlandMonitors.has(hypMon.id);
const hyprlandKeyStart = `${hypMon.model}_${widthScaled}x${heightScaled}`;
return gdkMonitor.key.startsWith(hyprlandKeyStart) && !usedHyprlandMonitors.has(hypMon.id);
});

if (hyprlandMonitor) {
Expand Down

0 comments on commit ff0cb1c

Please sign in to comment.