0

I'm using gtk-rs. I want to trigger some code after the window has been shown (has displayed on the screen):

window.connect_show(clone!(@weak window => move |_| {
    let command = format!("sleep 0.1; wmctrl -r \"CSS\" -e 1,640,100,680,768");
    println!("2");
    run_command(&command);
}));

println!("1");
window.show();
println!("3");

This will print: 1, 2, 3. Meaning that connect_show is triggering right before window.show();

This won't let the command wmctrl -r \"CSS\" -e 1,640,100,680,768" reposition and resize the window. A delay is needed to accomplish that:

"sleep 0.1; wmctrl -r \"CSS\" -e 1,640,100,680,768"

Is there another way to make the command work without having to use sleep 0.1?

Here is the whole code.

cafce25
  • 15,907
  • 4
  • 25
  • 31
alexchenco
  • 53,565
  • 76
  • 241
  • 413
  • 1
    I would try connecting to the "realize" signal here, since you're really asking your window manager to reposition/resize the underlying surface – nielsdg Feb 19 '23 at 12:48
  • @nielsdg For some reason, if I change `connect_changed` to `connect_realize`, the `println!()` follows the same order, but the `wmctrl -r \"CSS\" -e 1,640,100,680,768` command doesn't work anymore (even with `sleep`.). https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=33edff36d1ba99a4a5db0440e9d7a663 – alexchenco Feb 19 '23 at 13:43

1 Answers1

0

For some reason, the wmctrl commands is successful if I use glib::idle_add:

window.connect_show(clone!(@weak window => move |_| {
    glib::idle_add(|| {
        // the code
    glib::Continue(false)
});
alexchenco
  • 53,565
  • 76
  • 241
  • 413