Skip to content

Commit 6c62026

Browse files
fix: window shadows on Windows (#1403)
1 parent bae2a2f commit 6c62026

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

crates/rnote-ui/src/env.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,45 @@ fn macos_is_in_app_bundle(canonicalized_exec_dir: impl AsRef<Path>) -> bool {
124124
}
125125
})
126126
}
127+
128+
#[cfg(target_os = "windows")]
129+
/// Workaround for windows for shadow that intercept mouse events outside of the
130+
/// actual window. See https://github.com/flxzt/rnote/issues/1372
131+
///
132+
/// Taken from gaphor
133+
/// See commment from https://github.com/gaphor/gaphor/blob/a7b35712b166a38b78933a79613eab330f7bd885/gaphor/ui/styling-windows.css
134+
/// and https://gitlab.gnome.org/GNOME/gtk/-/issues/6255#note_1952796
135+
pub fn window_styling_workaround() -> anyhow::Result<()> {
136+
use gtk4::{gdk, style_context_add_provider_for_display};
137+
138+
// gtk needs to be initialized for the style provider to work
139+
gtk4::init()?;
140+
141+
let default_display = gdk::Display::default();
142+
let style_provider = gtk4::CssProvider::new();
143+
style_provider.load_from_string(
144+
"
145+
.csd {
146+
box-shadow: 0 3px 9px 1px alpha(black, 0.35),
147+
0 0 0 1px alpha(black, 0.18);
148+
}
149+
150+
.csd:backdrop {
151+
box-shadow: 0 3px 9px 1px transparent,
152+
0 2px 6px 2px alpha(black, 1),
153+
0 0 0 1px alpha(black, 0.06);
154+
}",
155+
);
156+
157+
match default_display {
158+
Some(display) => {
159+
style_context_add_provider_for_display(
160+
&display,
161+
&style_provider,
162+
gtk4::STYLE_PROVIDER_PRIORITY_APPLICATION,
163+
);
164+
Ok(())
165+
}
166+
None => Err(anyhow::anyhow!("Could not find a default display")),
167+
}
168+
}

crates/rnote-ui/src/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ fn main() -> glib::ExitCode {
8383
}
8484

8585
let app = RnApp::new();
86+
87+
// window specific workaround for shadow that intercept mouse clicks outside the window
88+
// See issue https://github.com/flxzt/rnote/issues/1372
89+
#[cfg(target_os = "windows")]
90+
{
91+
if let Err(e) = env::window_styling_workaround() {
92+
eprintln!("failed to setup custom css for windows, Err: {e:?}");
93+
}
94+
}
8695
app.run()
8796
}
8897

0 commit comments

Comments
 (0)