如何获取最大化窗口的大小而不显示它?
我试图确定最大化窗口的大小,以便我可以将窗口大小设置为接近它的值。但是,如果不先显示最大化窗口,我不知道如何做到这一点。有没有办法在窗口显示之前发出 gtk_window_maximize 生成的信号?
以下是我迄今为止的尝试。问题是在调整大小之前我可以看到最大化窗口的闪烁。
#include <gtk/gtk.h>
int signal_id;
void resize(GtkWindow *window, GdkEvent *event, gpointer data)
{
gint width, height;
g_signal_handler_disconnect(G_OBJECT(window), signal_id);
gtk_window_get_size(window, &width, &height);
gtk_window_resize(window, width - 10, height - 10);
}
int main(int argc, char *argv[])
{
GtkWidget *window;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
signal_id = g_signal_connect(G_OBJECT(window), "configure-event", G_CALLBACK(resize), NULL);
gtk_window_maximize(GTK_WINDOW(window));
gtk_widget_show_all(GTK_WIDGET(window));
gtk_main();
return 0;
}
I am trying to determine the size of a maximized window so I can set the window size to a value close to it. However, I don't know how to do that without first showing the maximized window. Is there a way to emit the signal generated by gtk_window_maximize before the window is displayed?
Below is my attempt so far. The problem is that I can see a flash of the maximized window before the resizing takes place.
#include <gtk/gtk.h>
int signal_id;
void resize(GtkWindow *window, GdkEvent *event, gpointer data)
{
gint width, height;
g_signal_handler_disconnect(G_OBJECT(window), signal_id);
gtk_window_get_size(window, &width, &height);
gtk_window_resize(window, width - 10, height - 10);
}
int main(int argc, char *argv[])
{
GtkWidget *window;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
signal_id = g_signal_connect(G_OBJECT(window), "configure-event", G_CALLBACK(resize), NULL);
gtk_window_maximize(GTK_WINDOW(window));
gtk_widget_show_all(GTK_WIDGET(window));
gtk_main();
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,这是不可能的,因为在窗口管理器映射窗口之前,实际大小是未知的。但你可以做的是获取屏幕尺寸:
No it is not possible, because until the window manager maps the window, the actual size is not known. But what you can do is get the screen size: