Skip to content

Commit edeec63

Browse files
authored
Apply scaling to virtual monitor reported size (#439)
* Apply scaling to virtual monitor reported size * Rename scaled to apply_current_scale
1 parent 17ef49b commit edeec63

2 files changed

Lines changed: 21 additions & 10 deletions

File tree

src/Objects/VirtualMonitor.vala

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class Display.VirtualMonitor : GLib.Object {
5959
}
6060
}
6161

62-
/*
62+
/**
6363
* Used to distinguish two VirtualMonitors from each other.
6464
* We make up and ID by sum all hashes of
6565
* monitors that a VirtualMonitor has.
@@ -83,7 +83,7 @@ public class Display.VirtualMonitor : GLib.Object {
8383

8484
public bool is_active { get; set; default = true; }
8585

86-
/*
86+
/**
8787
* Get the first monitor of the list, handy in non-mirror context.
8888
*/
8989
public Display.Monitor monitor {
@@ -119,23 +119,23 @@ public class Display.VirtualMonitor : GLib.Object {
119119
// mode when the monitor is re-activated
120120
foreach (var mode in monitor.modes) {
121121
if (mode.is_preferred) {
122-
width = mode.width;
123-
height = mode.height;
122+
width = apply_current_scale (mode.width);
123+
height = apply_current_scale (mode.height);
124124
return;
125125
}
126126
}
127127

128128
// Last resort fallback if no preferred mode
129-
width = 1280;
130-
height = 720;
129+
width = apply_current_scale (1280);
130+
height = apply_current_scale (720);
131131
} else if (is_mirror) {
132132
var current_mode = monitors[0].current_mode;
133-
width = current_mode.width;
134-
height = current_mode.height;
133+
width = apply_current_scale (current_mode.width);
134+
height = apply_current_scale (current_mode.height);
135135
} else {
136136
var current_mode = monitor.current_mode;
137-
width = current_mode.width;
138-
height = current_mode.height;
137+
width = apply_current_scale (current_mode.width);
138+
height = apply_current_scale (current_mode.height);
139139
}
140140
}
141141

@@ -211,4 +211,13 @@ public class Display.VirtualMonitor : GLib.Object {
211211

212212
return val.to_string ();
213213
}
214+
215+
/**
216+
* Apply scaling, to avoid gaps between virtual monitors in the configuration
217+
* @param dimension The monitor dimension to scale (width or height) by the current `scale` factor
218+
* @return the dimension scaled then rounded up and converted back to int
219+
*/
220+
private int apply_current_scale (int dimension) {
221+
return (int) Math.ceil (dimension / scale);
222+
}
214223
}

src/Widgets/DisplayWidget.vala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,9 @@ public class Display.DisplayWidget : Gtk.Box {
433433
// Prevent breaking autohide by closing popover
434434
popover.popdown ();
435435

436+
virtual_monitor.get_current_mode_size (out real_height, out real_width);
436437
configuration_changed ();
438+
check_position ();
437439
});
438440

439441
rotation_combobox.set_active ((int) virtual_monitor.transform);

0 commit comments

Comments
 (0)