[Git][wxwidgets/wxwidgets][master] Avoid initializing GTK if it has already been done

2 views
Skip to first unread message

Vadim Zeitlin (@_VZ_)

unread,
Aug 22, 2026, 12:57:36 PM (5 days ago) Aug 22
to wx-commi...@googlegroups.com

Vadim Zeitlin pushed to branch master at wxWidgets / wxWidgets

Commits:

  • 5f92a3ab
    by Paul Cornett at 2026-08-22T09:23:33-07:00
    Avoid initializing GTK if it has already been done
    

1 changed file:

Changes:

  • src/gtk/app.cpp
    ... ... @@ -521,49 +521,46 @@ bool wxApp::Initialize(int& argc_, wxChar **argv_)
    521 521
             );
    
    522 522
         }
    
    523 523
     
    
    524
    -    bool init_result;
    
    525
    -
    
    526
    -    // Prevent gtk_init_check() from changing the locale automatically for
    
    527
    -    // consistency with the other ports that don't do it. If necessary,
    
    528
    -    // wxApp::SetCLocale() may be explicitly called.
    
    529
    -    //
    
    530
    -    // Note that this function generates a warning if it's called more than
    
    531
    -    // once, so avoid them.
    
    532
    -    static bool s_gtkLocalDisabled = false;
    
    533
    -    if ( !s_gtkLocalDisabled )
    
    524
    +    const GType widgetType = GTK_TYPE_WIDGET;
    
    525
    +    // Check for possibility that GTK is already initialized
    
    526
    +    bool init_result = g_type_class_peek(widgetType) != nullptr;
    
    527
    +
    
    528
    +    if (!init_result)
    
    534 529
         {
    
    535
    -        s_gtkLocalDisabled = true;
    
    530
    +        // Prevent gtk_init_check() from changing the locale automatically for
    
    531
    +        // consistency with the other ports that don't do it. If necessary,
    
    532
    +        // wxApp::SetCLocale() may be explicitly called.
    
    536 533
             gtk_disable_setlocale();
    
    537
    -    }
    
    538 534
     
    
    539 535
     #if defined(__WXGTK4__)
    
    540
    -    init_result = gtk_init_check() != 0;
    
    536
    +        init_result = gtk_init_check() != 0;
    
    541 537
     #else
    
    542
    -    auto argvA = wxInitData::Get().argvA;
    
    538
    +        auto argvA = wxInitData::Get().argvA;
    
    543 539
     
    
    544
    -    int argcGTK = argc_;
    
    545
    -    init_result = gtk_init_check( &argcGTK, &argvA ) != 0;
    
    540
    +        int argcGTK = argc_;
    
    541
    +        init_result = gtk_init_check( &argcGTK, &argvA ) != 0;
    
    546 542
     
    
    547
    -    if ( argcGTK != argc_ )
    
    548
    -    {
    
    549
    -        // we have to drop the parameters which were consumed by GTK+
    
    550
    -        for ( int i = 0; i < argcGTK; i++ )
    
    543
    +        if ( argcGTK != argc_ )
    
    551 544
             {
    
    552
    -            while ( strcmp(wxConvUTF8.cWX2MB(argv_[i]), argvA[i]) != 0 )
    
    545
    +            // we have to drop the parameters which were consumed by GTK+
    
    546
    +            for ( int i = 0; i < argcGTK; i++ )
    
    553 547
                 {
    
    554
    -                free(argv_[i]);
    
    555
    -                memmove(argv_ + i, argv_ + i + 1, (argc_ - i)*sizeof(*argv_));
    
    548
    +                while ( strcmp(wxConvUTF8.cWX2MB(argv_[i]), argvA[i]) != 0 )
    
    549
    +                {
    
    550
    +                    free(argv_[i]);
    
    551
    +                    memmove(argv_ + i, argv_ + i + 1, (argc_ - i)*sizeof(*argv_));
    
    552
    +                }
    
    556 553
                 }
    
    557
    -        }
    
    558 554
     
    
    559
    -        argc_ = argcGTK;
    
    560
    -        argv_[argc_] = nullptr;
    
    555
    +            argc_ = argcGTK;
    
    556
    +            argv_[argc_] = nullptr;
    
    561 557
     
    
    562
    -        this->argc = argc_;
    
    563
    -        this->argv.Init(argc_, argv_);
    
    564
    -    }
    
    565
    -    //else: gtk_init() didn't modify our parameters
    
    558
    +            this->argc = argc_;
    
    559
    +            this->argv.Init(argc_, argv_);
    
    560
    +        }
    
    561
    +        //else: gtk_init() didn't modify our parameters
    
    566 562
     #endif
    
    563
    +    }
    
    567 564
     
    
    568 565
         if ( !init_result )
    
    569 566
         {
    
    ... ... @@ -583,7 +580,6 @@ bool wxApp::Initialize(int& argc_, wxChar **argv_)
    583 580
     #endif
    
    584 581
     
    
    585 582
         // make sure GtkWidget type is loaded, signal emission hooks need it
    
    586
    -    const GType widgetType = GTK_TYPE_WIDGET;
    
    587 583
         g_type_class_ref(widgetType);
    
    588 584
     
    
    589 585
         // focus in/out hooks used for generating wxEVT_ACTIVATE_APP
    


View it on GitLab.
You're receiving this email because of your account on gitlab.com. Manage all notifications · Help Notification message regarding https://gitlab.com/wxwidgets/wxwidgets/-/commit/5f92a3ab5887096881bca0f6aa779945b1a27181 at 1787417853

Reply all
Reply to author
Forward
0 new messages