在窗口显示后触发代码。

huangapple go评论61阅读模式
英文:

Triggering code after the window has been shown

问题

抱歉,我无法处理代码。

英文:

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.

答案1

得分: 0

由于某种原因,如果我使用 glib::idle_addwmctrl 命令会成功:

window.connect_show(clone!(@weak window => move |_| {
    glib::idle_add(|| {
        // 代码部分
        glib::Continue(false)
    });
});
英文:

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)
});

huangapple
  • 本文由 发表于 2023年2月19日 19:47:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/75499917.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定