fix: configure window in the idle time, so it stays in sync and prevents crash

This commit is contained in:
Ashley Wulber 2021-12-23 13:49:11 -05:00
parent 195470c4e0
commit d5e042e822
2 changed files with 89 additions and 81 deletions

View file

@ -135,10 +135,10 @@ fn main() {
.call_method(Some(DEST), PATH, Some(DEST), "WindowFocus", &((e,))) .call_method(Some(DEST), PATH, Some(DEST), "WindowFocus", &((e,)))
.await .await
.expect("Failed to focus selected window"); .expect("Failed to focus selected window");
dbg!(_activate_window);
} }
Event::RefreshFromCache => { Event::RefreshFromCache => {
//TODO refresh the model from cached_results (required after DnD for example) //TODO refresh the model from cached_results (required after DnD for example)
// alternatively dnd source could be changed depending on the context?
} }
Event::WindowList(mut results) => { Event::WindowList(mut results) => {
// sort to make comparison with cache easier // sort to make comparison with cache easier

View file

@ -210,6 +210,7 @@ impl Window {
//TODO clean up duplicated code //TODO clean up duplicated code
cursor_event_controller.connect_enter(glib::clone!(@weak revealer, @weak window => move |_evc, _x, _y| { cursor_event_controller.connect_enter(glib::clone!(@weak revealer, @weak window => move |_evc, _x, _y| {
// dbg!("hello, mouse entered me :)"); // dbg!("hello, mouse entered me :)");
let resize = glib::clone!(@weak window => move || {
revealer.set_reveal_child(true); revealer.set_reveal_child(true);
let s = window.surface().expect("Failed to get Surface for Window"); let s = window.surface().expect("Failed to get Surface for Window");
let height = s.height() * s.scale_factor(); let height = s.height() * s.scale_factor();
@ -246,12 +247,14 @@ impl Window {
} else { } else {
println!("failed to get X11 window"); println!("failed to get X11 window");
} }
});
glib::source::idle_add_local_once(resize);
})); }));
revealer.connect_child_revealed_notify(glib::clone!(@weak window => move |r| { revealer.connect_child_revealed_notify(glib::clone!(@weak window => move |r| {
if !r.is_child_revealed() { if !r.is_child_revealed() {
let s = window.surface().expect("Failed to get Surface for Window"); let s = window.surface().expect("Failed to get Surface for Window");
let resize = glib::clone!(@weak s => move || {
// dbg!(r.is_child_revealed()); // dbg!(r.is_child_revealed());
let height = 4; let height = 4;
if let Some((display, _surface)) = x::get_window_x11(&window) { if let Some((display, _surface)) = x::get_window_x11(&window) {
@ -286,11 +289,14 @@ impl Window {
} else { } else {
println!("failed to get X11 window"); println!("failed to get X11 window");
} }
});
glib::source::idle_add_local_once(resize);
} }
})); }));
let s = window.surface().expect("Failed to get Surface for Window"); let s = window.surface().expect("Failed to get Surface for Window");
let surface_resize_handler = glib::clone!(@weak window => move |s: &Surface| { let surface_resize_handler = glib::clone!(@weak window => move |s: &Surface| {
let resize = glib::clone!(@weak s => move || {
if let Some((display, _surface)) = x::get_window_x11(&window) { if let Some((display, _surface)) = x::get_window_x11(&window) {
let width = s.width() * s.scale_factor(); let width = s.width() * s.scale_factor();
// let height = s.height() * s.scale_factor(); // let height = s.height() * s.scale_factor();
@ -329,6 +335,8 @@ impl Window {
println!("failed to get X11 window"); println!("failed to get X11 window");
} }
}); });
glib::source::idle_add_local_once(resize);
});
s.connect_height_notify(surface_resize_handler.clone()); s.connect_height_notify(surface_resize_handler.clone());
s.connect_width_notify(surface_resize_handler.clone()); s.connect_width_notify(surface_resize_handler.clone());
s.connect_scale_factor_notify(surface_resize_handler); s.connect_scale_factor_notify(surface_resize_handler);