Skip to content

Commit f56791c

Browse files
authored
Fix OSD positioning on rotated displays (#181)
Anchor to bottom instead of top edge to avoid issues with window.allocated_height() returning 0 during initialization. The top_margin parameter still works the same way - 0.85 means 85% from top (15% from bottom with bottom anchoring). Improves on b14eba7 which fixed visibility but had positioning issues.
1 parent c029d5f commit f56791c

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/server/osd_window.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ impl SwayosdWindow {
4343

4444
window.set_exclusive_zone(-1);
4545
window.set_layer(gtk_layer_shell::Layer::Overlay);
46-
window.set_anchor(gtk_layer_shell::Edge::Top, true);
46+
// Anchor to bottom edge for better reliability with rotated/transformed displays
47+
window.set_anchor(gtk_layer_shell::Edge::Bottom, true);
4748

4849
// Set up the widgets
4950
window.set_width_request(250);
@@ -67,10 +68,12 @@ impl SwayosdWindow {
6768
// Monitor scale factor is not always correct
6869
// Transform monitor height into coordinate system of window
6970
let mon_height = monitor.geometry().height() / window.scale_factor();
70-
// Calculate new margin
71-
let bottom = mon_height - window.allocated_height();
72-
let margin = (bottom as f32 * get_top_margin()).round() as i32;
73-
window.set_margin(gtk_layer_shell::Edge::Top, margin);
71+
// Calculate margin from bottom while preserving top_margin semantics:
72+
// top_margin=0.85 means window should be at 85% from top, which equals
73+
// 15% from bottom. By anchoring to bottom, we avoid issues with
74+
// window.allocated_height() being 0 or incorrect during initialization.
75+
let margin = (mon_height as f32 * (1.0 - get_top_margin())).round() as i32;
76+
window.set_margin(gtk_layer_shell::Edge::Bottom, margin);
7477
};
7578

7679
// Set the window margin

0 commit comments

Comments
 (0)