fix: configure window in the idle time, so it stays in sync and prevents crash
This commit is contained in:
parent
195470c4e0
commit
d5e042e822
2 changed files with 89 additions and 81 deletions
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -210,50 +210,11 @@ 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 :)");
|
||||||
revealer.set_reveal_child(true);
|
let resize = glib::clone!(@weak window => move || {
|
||||||
let s = window.surface().expect("Failed to get Surface for Window");
|
revealer.set_reveal_child(true);
|
||||||
let height = s.height() * s.scale_factor();
|
|
||||||
|
|
||||||
if let Some((display, _surface)) = x::get_window_x11(&window) {
|
|
||||||
let monitor = display
|
|
||||||
.primary_monitor()
|
|
||||||
.expect("Failed to get Monitor");
|
|
||||||
let Rectangle {
|
|
||||||
x: _monitor_x,
|
|
||||||
y: monitor_y,
|
|
||||||
width: _monitor_width,
|
|
||||||
height: monitor_height,
|
|
||||||
} = monitor.geometry();
|
|
||||||
// dbg!(monitor_width);
|
|
||||||
// dbg!(monitor_height);
|
|
||||||
// dbg!(width);
|
|
||||||
// dbg!(height);
|
|
||||||
let w_conf = xproto::ConfigureWindowAux::default()
|
|
||||||
.y((monitor_y + monitor_height - height).clamp(0, monitor_y + monitor_height - 1));
|
|
||||||
let conn = X11_CONN.get().expect("Failed to get X11_CONN");
|
|
||||||
|
|
||||||
let x11surface = gdk4_x11::X11Surface::xid(
|
|
||||||
&s.clone().downcast::<X11Surface>()
|
|
||||||
.expect("Failed to downcast Surface to X11Surface"),
|
|
||||||
);
|
|
||||||
conn.configure_window(
|
|
||||||
x11surface.try_into().expect("Failed to convert XID"),
|
|
||||||
&w_conf,
|
|
||||||
)
|
|
||||||
.expect("failed to configure window...");
|
|
||||||
conn.flush().expect("failed to flush");
|
|
||||||
|
|
||||||
} else {
|
|
||||||
println!("failed to get X11 window");
|
|
||||||
}
|
|
||||||
|
|
||||||
}));
|
|
||||||
|
|
||||||
revealer.connect_child_revealed_notify(glib::clone!(@weak window => move |r| {
|
|
||||||
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");
|
||||||
// dbg!(r.is_child_revealed());
|
let height = s.height() * s.scale_factor();
|
||||||
let height = 4;
|
|
||||||
if let Some((display, _surface)) = x::get_window_x11(&window) {
|
if let Some((display, _surface)) = x::get_window_x11(&window) {
|
||||||
let monitor = display
|
let monitor = display
|
||||||
.primary_monitor()
|
.primary_monitor()
|
||||||
|
|
@ -280,54 +241,101 @@ impl Window {
|
||||||
x11surface.try_into().expect("Failed to convert XID"),
|
x11surface.try_into().expect("Failed to convert XID"),
|
||||||
&w_conf,
|
&w_conf,
|
||||||
)
|
)
|
||||||
.expect("failed to configure window...");
|
.expect("failed to configure window...");
|
||||||
conn.flush().expect("failed to flush");
|
conn.flush().expect("failed to flush");
|
||||||
|
|
||||||
} 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| {
|
||||||
|
if !r.is_child_revealed() {
|
||||||
|
let s = window.surface().expect("Failed to get Surface for Window");
|
||||||
|
let resize = glib::clone!(@weak s => move || {
|
||||||
|
// dbg!(r.is_child_revealed());
|
||||||
|
let height = 4;
|
||||||
|
if let Some((display, _surface)) = x::get_window_x11(&window) {
|
||||||
|
let monitor = display
|
||||||
|
.primary_monitor()
|
||||||
|
.expect("Failed to get Monitor");
|
||||||
|
let Rectangle {
|
||||||
|
x: _monitor_x,
|
||||||
|
y: monitor_y,
|
||||||
|
width: _monitor_width,
|
||||||
|
height: monitor_height,
|
||||||
|
} = monitor.geometry();
|
||||||
|
// dbg!(monitor_width);
|
||||||
|
// dbg!(monitor_height);
|
||||||
|
// dbg!(width);
|
||||||
|
// dbg!(height);
|
||||||
|
let w_conf = xproto::ConfigureWindowAux::default()
|
||||||
|
.y((monitor_y + monitor_height - height).clamp(0, monitor_y + monitor_height - 1));
|
||||||
|
let conn = X11_CONN.get().expect("Failed to get X11_CONN");
|
||||||
|
|
||||||
|
let x11surface = gdk4_x11::X11Surface::xid(
|
||||||
|
&s.clone().downcast::<X11Surface>()
|
||||||
|
.expect("Failed to downcast Surface to X11Surface"),
|
||||||
|
);
|
||||||
|
conn.configure_window(
|
||||||
|
x11surface.try_into().expect("Failed to convert XID"),
|
||||||
|
&w_conf,
|
||||||
|
)
|
||||||
|
.expect("failed to configure window...");
|
||||||
|
conn.flush().expect("failed to flush");
|
||||||
|
|
||||||
|
} else {
|
||||||
|
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| {
|
||||||
if let Some((display, _surface)) = x::get_window_x11(&window) {
|
let resize = glib::clone!(@weak s => move || {
|
||||||
let width = s.width() * s.scale_factor();
|
if let Some((display, _surface)) = x::get_window_x11(&window) {
|
||||||
// let height = s.height() * s.scale_factor();
|
let width = s.width() * s.scale_factor();
|
||||||
// hide by default
|
// let height = s.height() * s.scale_factor();
|
||||||
let height = 4;
|
// hide by default
|
||||||
let monitor = display
|
let height = 4;
|
||||||
.primary_monitor()
|
let monitor = display
|
||||||
.expect("Failed to get Monitor");
|
.primary_monitor()
|
||||||
let Rectangle {
|
.expect("Failed to get Monitor");
|
||||||
x: monitor_x,
|
let Rectangle {
|
||||||
y: monitor_y,
|
x: monitor_x,
|
||||||
width: monitor_width,
|
y: monitor_y,
|
||||||
height: monitor_height,
|
width: monitor_width,
|
||||||
} = monitor.geometry();
|
height: monitor_height,
|
||||||
// dbg!(monitor_width);
|
} = monitor.geometry();
|
||||||
// dbg!(monitor_height);
|
// dbg!(monitor_width);
|
||||||
// dbg!(width);
|
// dbg!(monitor_height);
|
||||||
// dbg!(heightt - 1);
|
// dbg!(width);
|
||||||
let w_conf = xproto::ConfigureWindowAux::default()
|
// dbg!(heightt - 1);
|
||||||
.x((monitor_x + monitor_width / 2 - width / 2).clamp(0, monitor_x + monitor_width - 1))
|
let w_conf = xproto::ConfigureWindowAux::default()
|
||||||
.y((monitor_y + monitor_height - height).clamp(0, monitor_y + monitor_height - 1));
|
.x((monitor_x + monitor_width / 2 - width / 2).clamp(0, monitor_x + monitor_width - 1))
|
||||||
let conn = X11_CONN.get().expect("Failed to get X11_CONN");
|
.y((monitor_y + monitor_height - height).clamp(0, monitor_y + monitor_height - 1));
|
||||||
|
let conn = X11_CONN.get().expect("Failed to get X11_CONN");
|
||||||
|
|
||||||
let x11surface = gdk4_x11::X11Surface::xid(
|
let x11surface = gdk4_x11::X11Surface::xid(
|
||||||
&s.clone().downcast::<X11Surface>()
|
&s.clone().downcast::<X11Surface>()
|
||||||
.expect("Failed to downcast Surface to X11Surface"),
|
.expect("Failed to downcast Surface to X11Surface"),
|
||||||
);
|
);
|
||||||
conn.configure_window(
|
conn.configure_window(
|
||||||
x11surface.try_into().expect("Failed to convert XID"),
|
x11surface.try_into().expect("Failed to convert XID"),
|
||||||
&w_conf,
|
&w_conf,
|
||||||
)
|
)
|
||||||
.expect("failed to configure window...");
|
.expect("failed to configure window...");
|
||||||
conn.flush().expect("failed to flush");
|
conn.flush().expect("failed to flush");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
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());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue