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 18, 2025
1 parent 88609f7 commit 03047e2
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 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,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 = Math.trunc(width/gdkMonitor.scaleFactor);

Check failure on line 126 in src/components/bar/utils/monitors.ts

View workflow job for this annotation

GitHub Actions / code_quality

Replace `/` with `·/·`
const height = isVertical ? hypMon.width : hypMon.height;
const heightScaled = Math.trunc(height/gdkMonitor.scaleFactor);

Check failure on line 128 in src/components/bar/utils/monitors.ts

View workflow job for this annotation

GitHub Actions / code_quality

Replace `/` with `·/·`

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;

Check failure on line 131 in src/components/bar/utils/monitors.ts

View workflow job for this annotation

GitHub Actions / code_quality

Replace `gdkMonitor.key.startsWith(hyprlandKeyStart)·&&·!usedHyprlandMonitors.has(hypMon.id)·&&·hypMon.id·===·monitor` with `(⏎············gdkMonitor.key.startsWith(hyprlandKeyStart)·&&·!usedHyprlandMonitors.has(hypMon.id)·&&·hypMon.id·===·monitor⏎········)`
});

if (directMatch) {
Expand All @@ -136,10 +141,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;

Check failure on line 144 in src/components/bar/utils/monitors.ts

View workflow job for this annotation

GitHub Actions / code_quality

Replace `/` with `·/·`
const height = isVertical ? hypMon.width : hypMon.height;
const heightScaled = height/gdkMonitor.scaleFactor;

Check failure on line 146 in src/components/bar/utils/monitors.ts

View workflow job for this annotation

GitHub Actions / code_quality

Replace `/` with `·/·`

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 03047e2

Please sign in to comment.