fix: gdk layout crash

This commit is contained in:
Ashley Wulber 2021-12-23 23:56:58 -05:00
parent fb95442a0b
commit 253b0a518e

View file

@ -213,7 +213,7 @@ impl Window {
let resize = glib::clone!(@weak window => move || { let resize = glib::clone!(@weak window => move || {
let s = window.surface().expect("Failed to get Surface for Window"); let s = window.surface().expect("Failed to get Surface for Window");
revealer.set_reveal_child(true); revealer.set_reveal_child(true);
let height = s.height() * s.scale_factor(); let height = window.height();
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
@ -228,7 +228,7 @@ impl Window {
// dbg!(monitor_width); // dbg!(monitor_width);
// dbg!(monitor_height); // dbg!(monitor_height);
// dbg!(width); // dbg!(width);
// dbg!(height); dbg!(height);
let w_conf = xproto::ConfigureWindowAux::default() let w_conf = xproto::ConfigureWindowAux::default()
.y((monitor_y + monitor_height - height).clamp(0, monitor_y + monitor_height - 1)); .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 conn = X11_CONN.get().expect("Failed to get X11_CONN");
@ -242,9 +242,8 @@ impl Window {
&w_conf, &w_conf,
) )
.expect("failed to configure window..."); .expect("failed to configure window...");
conn.flush().expect("failed to flush");let frame_clock = s.frame_clock().unwrap(); conn.flush().expect("failed to flush");
frame_clock.request_phase(gdk4::FrameClockPhase::FLUSH_EVENTS); } else { s.request_layout();
println!("failed to get X11 window");
} }
}); });
glib::source::idle_add_local_once(resize); glib::source::idle_add_local_once(resize);
@ -270,7 +269,7 @@ impl Window {
// dbg!(monitor_width); // dbg!(monitor_width);
// dbg!(monitor_height); // dbg!(monitor_height);
// dbg!(width); // dbg!(width);
// dbg!(height); dbg!(height);
let w_conf = xproto::ConfigureWindowAux::default() let w_conf = xproto::ConfigureWindowAux::default()
.y((monitor_y + monitor_height - height).clamp(0, monitor_y + monitor_height - 1)); .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 conn = X11_CONN.get().expect("Failed to get X11_CONN");
@ -285,9 +284,7 @@ impl Window {
) )
.expect("failed to configure window..."); .expect("failed to configure window...");
conn.flush().expect("failed to flush"); conn.flush().expect("failed to flush");
s.queue_render(); s.request_layout();
let frame_clock = s.frame_clock().unwrap();
frame_clock.request_phase(gdk4::FrameClockPhase::FLUSH_EVENTS);
} else { } else {
println!("failed to get X11 window"); println!("failed to get X11 window");
} }
@ -300,40 +297,39 @@ impl 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 || { 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 = window.width();
// let height = s.height() * s.scale_factor(); // let height = s.height() * s.scale_factor();
// hide by default // hide by default
let height = 4; let height = 4;
let monitor = display let monitor = display
.primary_monitor() .primary_monitor()
.expect("Failed to get Monitor"); .expect("Failed to get Monitor");
let Rectangle { let Rectangle {
x: monitor_x, x: monitor_x,
y: monitor_y, y: monitor_y,
width: monitor_width, width: monitor_width,
height: monitor_height, height: monitor_height,
} = monitor.geometry(); } = monitor.geometry();
// dbg!(monitor_width); // dbg!(monitor_width);
// dbg!(monitor_height); // dbg!(monitor_height);
// dbg!(width); // dbg!(width);
// dbg!(heightt - 1); // dbg!(heightt - 1);
let w_conf = xproto::ConfigureWindowAux::default() let w_conf = xproto::ConfigureWindowAux::default()
.x((monitor_x + monitor_width / 2 - width / 2).clamp(0, monitor_x + monitor_width - 1)) .x((monitor_x + monitor_width / 2 - width / 2).clamp(0, monitor_x + monitor_width - 1))
.y((monitor_y + monitor_height - height).clamp(0, monitor_y + monitor_height - 1)); .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 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");
let frame_clock = s.frame_clock().unwrap(); s.request_layout();
frame_clock.request_phase(gdk4::FrameClockPhase::FLUSH_EVENTS);
} else { } else {
println!("failed to get X11 window"); println!("failed to get X11 window");
} }