英文:
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_add
,wmctrl
命令会成功:
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)
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论