首页 > 解决方案 > C++。gtk_window_resize 不调整窗口大小

问题描述

我有类(称为BorderWindow),实际上是环绕的GtkWidget。此类表示特定应用程序窗口周围的边框(例如,可以说终端窗口)。在BorderWindow构造函数内部,我创建了计时器,因此每隔一个BorderWindow::ClockTick函数就会被调用一次。
在这个函数内部,边框大小(实际上是GtkWidget)与绑定应用程序的窗口(在我们的例子中为终端)进行比较,如果不同gtk_window_resize则调用。但是,如果我打电话,那么gtk_window_get_size它会返回旧值。

gboolean BorderWindow::ClockTick(gpointer data)
{
auto that = reinterpret_cast<BorderWindow*>(data);

int x = 0, y = 0;
GtkWindow* pWindow = GTK_WINDOW(that->m_borderWindowHandle);
gtk_window_get_size(pWindow, &x, &y);
DUMPER_INFO("curr size: %dx%d; new size: %dx%d", x, y, that->m_windowRect.width, that->m_windowRect.height); // added for debug
if(x != that->m_windowRect.width || y != that->m_windowRect.height)
{
    gtk_window_resize(pWindow, that->m_windowRect.width, that->m_windowRect.height);
    that->CreateBorder();
    GtkWindow* pWindow = GTK_WINDOW(that->m_borderWindowHandle); // added for debug
    gtk_window_get_size(pWindow, &x, &y); // added for debug
    DUMPER_INFO("after resize: %dx%d", x, y); // added for debug
}

gtk_window_get_position(pWindow, &x, &y);
if(x != that->m_windowRect.x || y != that->m_windowRect.y)
{
    gtk_window_move(pWindow, that->m_windowRect.x, that->m_windowRect.y);
}
gdk_window_invalidate_rect(gtk_widget_get_window(that->m_borderWindowHandle), nullptr, FALSE);
that->m_highlightFrame = !that->m_highlightFrame;

return TRUE;
}

这是调试输出

20-05-19 11:24:40.294 [139856177248000] INFO 1537 %% - 静态 gboolean LinuxBorderWindow::ClockTick(gpointer):当前大小:734x540;新尺寸:1024x706

20-05-19 11:24:40.295 [139856177248000] INFO 1537 %% - 静态 gboolean LinuxBorderWindow::ClockTick(gpointer):调整大小后:734x540

如您所见,窗口没有调整大小。此代码片段适用于 xfce 和 Unity DE,但不适用于 GNOME(和 GNOME 经典版)。谁能解释我做错了什么以及如何调整 GNOME DE 的窗口大小?谢谢。

标签: c++gtkgnome

解决方案


推荐阅读