From 5ec741e90d96ad8653c3083edf0a5c6122ba7e3a Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Sun, 16 Jun 2019 17:40:08 +0200 Subject: [PATCH] workaround the GTK2 GLWidget bug on Windows --- CMakeLists.txt | 4 ++++ Makefile | 2 +- libs/gtkutil/window.cpp | 10 ++++++++++ libs/uilib/uilib.cpp | 10 ++++++++++ radiant/groupdialog.cpp | 15 +++++++++++++++ radiant/mainframe.cpp | 18 ++++++++++++++++++ radiant/texwindow.cpp | 6 ++++++ radiant/texwindow.h | 4 ++++ 8 files changed, 68 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2811bc3f..4cbf3658 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -138,6 +138,10 @@ endif () if (BUILD_RADIANT) set(GTK_TARGET 2 CACHE STRING "GTK target") add_definitions(-DGTK_TARGET=${GTK_TARGET}) + + if (GTK_TARGET EQUAL 2 AND WIN32) + add_definitions(-DWORKAROUND_WINDOWS_GTK2_GLWIDGET=1) + endif () endif () #----------------------------------------------------------------------- diff --git a/Makefile b/Makefile index e8a1c5b0..85049a8b 100644 --- a/Makefile +++ b/Makefile @@ -200,7 +200,7 @@ ifeq ($(OS),Linux) else ifeq ($(OS),Win32) - CPPFLAGS_COMMON += -DWIN32 -D_WIN32 -D_inline=inline + CPPFLAGS_COMMON += -DWIN32 -D_WIN32 -D_inline=inline -DWORKAROUND_WINDOWS_GTK2_GLWIDGET=1 CFLAGS_COMMON += -mms-bitfields LDFLAGS_DLL = -Wl,--add-stdcall-alias LIBS_COMMON = -lws2_32 -luser32 -lgdi32 -lole32 diff --git a/libs/gtkutil/window.cpp b/libs/gtkutil/window.cpp index 11b6efeb..4c453660 100644 --- a/libs/gtkutil/window.cpp +++ b/libs/gtkutil/window.cpp @@ -28,6 +28,16 @@ inline void CHECK_RESTORE( ui::Widget w ){ if ( gpointer_to_int( g_object_get_data( G_OBJECT( w ), "was_mapped" ) ) != 0 ) { + +#ifdef WORKAROUND_WINDOWS_GTK2_GLWIDGET + /* workaround for gtk 2.24 issue: not displayed glwidget after toggle */ + GtkWidget* glwidget = GTK_WIDGET( g_object_get_data( G_OBJECT( w ), "glwidget" ) ); + if ( glwidget ){ + gtk_widget_hide( glwidget ); + gtk_widget_show( glwidget ); + } +#endif // WORKAROUND_WINDOWS_GTK2_GLWIDGET + w.show(); } } diff --git a/libs/uilib/uilib.cpp b/libs/uilib/uilib.cpp index 1f4acb1f..8812911e 100644 --- a/libs/uilib/uilib.cpp +++ b/libs/uilib/uilib.cpp @@ -87,6 +87,16 @@ namespace ui { void IWidget::visible(bool shown) { if (shown) { + +#ifdef WORKAROUND_WINDOWS_GTK2_GLWIDGET + /* workaround for gtk 2.24 issue: not displayed glwidget after toggle */ + GtkWidget* glwidget = GTK_WIDGET( g_object_get_data( G_OBJECT( this ), "glwidget" ) ); + if ( glwidget ){ + gtk_widget_hide( glwidget ); + gtk_widget_show( glwidget ); + } +#endif // WORKAROUND_WINDOWS_GTK2_GLWIDGET + this.show(); } else { this.hide(); diff --git a/radiant/groupdialog.cpp b/radiant/groupdialog.cpp index 1be74bf7..f6d9c4be 100644 --- a/radiant/groupdialog.cpp +++ b/radiant/groupdialog.cpp @@ -169,9 +169,24 @@ void GroupDialog_setPage( ui::Widget page ){ gtk_notebook_set_current_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gint( g_current_page ) ); } +#ifdef WORKAROUND_WINDOWS_GTK2_GLWIDGET +void GroupDialog_cycle(); +#endif // WORKAROUND_WINDOWS_GTK2_GLWIDGET + void GroupDialog_showPage( ui::Widget page ){ if ( GroupDialog_getPage() == page ) { GroupDialog_ToggleShow(); + +#ifdef WORKAROUND_WINDOWS_GTK2_GLWIDGET + /* workaround for gtk 2.24 issue: not displayed glwidget after toggle */ + /* this is very ugly: cycle to next tab then return to current tab immediately to force the refresh + * this fixes the drawing of texture tab when window is restored and current tab is texture tab + * this is called for nothing when windows is minimized and called for nothing when current tab + * is not texture tab, hopefully it's a workaround that would disappear with gtk 3 */ + GroupDialog_cycle(); + GroupDialog_setPage( page ); +#endif // WORKAROUND_WINDOWS_GTK2_GLWIDGET + } else { diff --git a/radiant/mainframe.cpp b/radiant/mainframe.cpp index d84fe69f..6fadba47 100644 --- a/radiant/mainframe.cpp +++ b/radiant/mainframe.cpp @@ -101,6 +101,12 @@ #include "referencecache.h" #include "texwindow.h" +#ifdef WORKAROUND_WINDOWS_GTK2_GLWIDGET +/* workaround for gtk 2.24 issue: not displayed glwidget after toggle */ +#define WORKAROUND_GOBJECT_SET_GLWIDGET(window, widget) g_object_set_data( G_OBJECT( window ), "glwidget", G_OBJECT( widget ) ) +#else +#define WORKAROUND_GOBJECT_SET_GLWIDGET(window, widget) +#endif struct layout_globals_t { @@ -3091,6 +3097,8 @@ void MainFrame::Create(){ } CamWnd_setParent( *m_pCamWnd, window ); + WORKAROUND_GOBJECT_SET_GLWIDGET( window, CamWnd_getWidget( *m_pCamWnd ) ); + g_floating_windows.push_back( window ); } @@ -3110,6 +3118,8 @@ void MainFrame::Create(){ } XY_Top_Shown_Construct( window ); + WORKAROUND_GOBJECT_SET_GLWIDGET( window, m_pXYWnd->GetWidget() ); + g_floating_windows.push_back( window ); } @@ -3129,6 +3139,8 @@ void MainFrame::Create(){ XZ_Front_Shown_Construct( window ); + WORKAROUND_GOBJECT_SET_GLWIDGET( window, m_pXZWnd->GetWidget() ); + g_floating_windows.push_back( window ); } @@ -3148,12 +3160,16 @@ void MainFrame::Create(){ YZ_Side_Shown_Construct( window ); + WORKAROUND_GOBJECT_SET_GLWIDGET( window, m_pYZWnd->GetWidget() ); + g_floating_windows.push_back( window ); } { auto frame = create_framed_widget( TextureBrowser_constructWindow( GroupDialog_getWindow() ) ); g_page_textures = GroupDialog_addPage( "Textures", frame, TextureBrowserExportTitleCaller() ); + + WORKAROUND_GOBJECT_SET_GLWIDGET( GroupDialog_getWindow(), TextureBrowser_getGLWidget() ); } GroupDialog_show(); @@ -3187,6 +3203,8 @@ void MainFrame::Create(){ { auto frame = create_framed_widget( TextureBrowser_constructWindow( window ) ); g_page_textures = GroupDialog_addPage( "Textures", frame, TextureBrowserExportTitleCaller() ); + + WORKAROUND_GOBJECT_SET_GLWIDGET( window, TextureBrowser_getGLWidget() ); } } diff --git a/radiant/texwindow.cpp b/radiant/texwindow.cpp index 87094456..fee615cf 100644 --- a/radiant/texwindow.cpp +++ b/radiant/texwindow.cpp @@ -2703,3 +2703,9 @@ void TextureBrowser_Destroy(){ Textures_setModeChangedNotify( Callback() ); } + +#if WORKAROUND_WINDOWS_GTK2_GLWIDGET +ui::GLArea TextureBrowser_getGLWidget(){ + return GlobalTextureBrowser().m_gl_widget; +} +#endif // WORKAROUND_WINDOWS_GTK2_GLWIDGET diff --git a/radiant/texwindow.h b/radiant/texwindow.h index 2d5125e4..80aa5e4d 100644 --- a/radiant/texwindow.h +++ b/radiant/texwindow.h @@ -56,4 +56,8 @@ void TextureBrowser_addShadersRealiseCallback( const SignalHandler& handler ); void TextureBrowser_RefreshShaders(); +#ifdef WORKAROUND_WINDOWS_GTK2_GLWIDGET +ui::GLArea TextureBrowser_getGLWidget(); +#endif // WORKAROUND_WINDOWS_GTK2_GLWIDGET + #endif -- 2.39.2