workaround the GTK2 GLWidget bug on Windows 133/head
authorThomas Debesse <dev@illwieckz.net>
Sun, 16 Jun 2019 15:40:08 +0000 (17:40 +0200)
committerThomas Debesse <dev@illwieckz.net>
Tue, 18 Jun 2019 21:39:26 +0000 (23:39 +0200)
CMakeLists.txt
Makefile
libs/gtkutil/window.cpp
libs/uilib/uilib.cpp
radiant/groupdialog.cpp
radiant/mainframe.cpp
radiant/texwindow.cpp
radiant/texwindow.h

index 2811bc3..4cbf365 100644 (file)
@@ -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 ()
 
 #-----------------------------------------------------------------------
index e8a1c5b..85049a8 100644 (file)
--- 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
index 11b6efe..4c45366 100644 (file)
 
 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();
        }
 }
index 1f4acb1..8812911 100644 (file)
@@ -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();
index 1be74bf..f6d9c4b 100644 (file)
@@ -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
        {
index d84fe69..6fadba4 100644 (file)
 #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() );
                }
        }
 
index 8709445..fee615c 100644 (file)
@@ -2703,3 +2703,9 @@ void TextureBrowser_Destroy(){
 
        Textures_setModeChangedNotify( Callback<void()>() );
 }
+
+#if WORKAROUND_WINDOWS_GTK2_GLWIDGET
+ui::GLArea TextureBrowser_getGLWidget(){
+       return GlobalTextureBrowser().m_gl_widget;
+}
+#endif // WORKAROUND_WINDOWS_GTK2_GLWIDGET
index 2d5125e..80aa5e4 100644 (file)
@@ -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