如何获取最大化窗口的大小而不显示它?

发布于 2024-12-29 23:07:57 字数 859 浏览 0 评论 0原文

我试图确定最大化窗口的大小,以便我可以将窗口大小设置为接近它的值。但是,如果不先显示最大化窗口,我不知道如何做到这一点。有没有办法在窗口显示之前发出 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若有似无的小暗淡 2025-01-05 23:07:57

不,这是不可能的,因为在窗口管理器映射窗口之前,实际大小是未知的。但你可以做的是获取屏幕尺寸:

width=gdk_screen_width();
height=gdk_screen_height();
gtk_widget_set_size_request(window, width/2, height/2);

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:

width=gdk_screen_width();
height=gdk_screen_height();
gtk_widget_set_size_request(window, width/2, height/2);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文