JUCE + GTK2 not working

Programming applications for making music on Linux.

Moderators: MattKingUSA, khz

Post Reply
User avatar
sadko4u
Established Member
Posts: 986
Joined: Mon Sep 28, 2015 9:03 pm
Has thanked: 2 times
Been thanked: 359 times

JUCE + GTK2 not working

Post by sadko4u »

Hello all!

Currently I'm fighting with the connectivity between JUCE example host and VST plugins that use LV2 interface.
The main problem is that the events sent by juce_VSTPluginFormat.cpp are not delivered to any of GTK widgets. The behaviour is strange: widgets don't receive button-press-event but always receive button-release-event. Sometimes they receive button-press-event, but it depends on the target platform. I've just added printf for debugging.

Here's the code from JUCE:

Code: Select all

    void mouseDown (const MouseEvent& e) override
    {
        ignoreUnused (e);

       #if JUCE_LINUX
        printf("mouseDown event, pluginWindow = %x\n", int(pluginWindow));
        if (pluginWindow == 0)
            return;
        
        toFront (true);

        printf("Pass X event to child\n");
        XEvent ev;
        prepareXEvent (ev, e);
        ev.xbutton.type = ButtonPress;
        translateJuceToXButtonModifiers (e, ev);
        sendEventToChild (ev);

       #elif JUCE_WINDOWS
        toFront (true);
       #endif
    }
But the GTK window doesn't receive them ever, here's the code of the plugin's UI initialization:

Code: Select all

            pWidget                     = gtk_window_new (GTK_WINDOW_TOPLEVEL);
            if (pWidget == NULL)
                return false;

            // Realize GTK window
            if (!gtk_widget_get_realized(pWidget))
            {
                gtk_widget_realize(pWidget);
                g_assert(gtk_widget_get_realized(pWidget));
            }

            lsp_trace("set attributes pWidget=%p", pWidget);
            gchar *title                = g_strdup_printf(LSP_ACRONYM " %s - %s [VST]", m->name, m->description);
            gtk_window_set_title(GTK_WINDOW(pWidget), title);
            gtk_window_set_default_size (GTK_WINDOW (pWidget), 64, 64);
            gtk_container_set_border_width (GTK_CONTAINER (pWidget), 0);
            g_free(title);

            // Get widget
            lsp_trace("create widget hierarchy root=%p", wf->root_widget());
            pUIWidget                   = reinterpret_cast<GtkWidget *>(wf->root_widget());
            gtk_container_add(GTK_CONTAINER(pWidget), pUIWidget);

            // Reparent window
            gdk_display_sync(gdk_display_get_default());
            pParent                     = gdk_window_foreign_new(GdkNativeWindow(uintptr_t(wnd)));
            g_assert(pParent);
            gdk_window_reparent(gtk_widget_get_window(pWidget), pParent, 0, 0);

        // Show window
        lsp_trace("create widget hierarchy pWidget=%p", pWidget);
        gtk_widget_show_all(pWidget);
        gdk_display_sync(gdk_display_get_default());
Actually I don't know how to recieve events sent bu JUCE. Any ideas?

Also the same problem is with AMSynth from where I took the reparent example.
LSP (Linux Studio Plugins) Developer and Maintainer.
nixx
Established Member
Posts: 38
Joined: Sun Oct 28, 2012 3:01 pm

Re: JUCE + GTK2 not working

Post by nixx »

Hi! I found the exact same issues and managed to solve some of them in amsynth.

This is the main commit that fixed mouse-press handling:

https://github.com/amsynth/amsynth/comm ... 4f99772e7c
User avatar
sadko4u
Established Member
Posts: 986
Joined: Mon Sep 28, 2015 9:03 pm
Has thanked: 2 times
Been thanked: 359 times

Re: JUCE + GTK2 not working

Post by sadko4u »

That's interesting, I'll try it ASAP. Great thanks.
LSP (Linux Studio Plugins) Developer and Maintainer.
User avatar
sadko4u
Established Member
Posts: 986
Joined: Mon Sep 28, 2015 9:03 pm
Has thanked: 2 times
Been thanked: 359 times

Re: JUCE + GTK2 not working

Post by sadko4u »

falkTX wrote:Have you reported this upstream to the juce devs?
Or better, a patch for juce...
There's a topic that I've opened:
https://forum.juce.com/t/cant-make-frie ... gtk2/18120

nixx:
Your patch helped. Now I've got my knobs and buttons working. But there is still no feedback from read-only widgets because JUCE Sample Host does not call effEditIdle callback for VST. Also I can't make combo boxes working because can not do any GTK iterations because there is no effEditIdle callback.
Totally bullshit.

Also I get such message while running JUCE Sample Host:

Code: Select all

(Plugin Host:14585): GLib-GObject-CRITICAL **: g_object_get_qdata: assertion 'G_IS_OBJECT (object)' failed

(Plugin Host:14585): GLib-GObject-CRITICAL **: g_object_get_qdata: assertion 'G_IS_OBJECT (object)' failed

(Plugin Host:14585): GLib-GObject-CRITICAL **: g_object_get_qdata: assertion 'G_IS_OBJECT (object)' failed

(Plugin Host:14585): GLib-GObject-CRITICAL **: g_object_get_qdata: assertion 'G_IS_OBJECT (object)' failed
Do you get same messages with amsynth?
LSP (Linux Studio Plugins) Developer and Maintainer.
User avatar
sadko4u
Established Member
Posts: 986
Joined: Mon Sep 28, 2015 9:03 pm
Has thanked: 2 times
Been thanked: 359 times

Re: JUCE + GTK2 not working

Post by sadko4u »

falkTX wrote:I have carla working with juce hosts, and it needs effEditIdle.
Same thing with Nekobi.
Juce does call that. See https://github.com/julianstorer/JUCE/bl ... .cpp#L2047
Hmm, you're right about effEditIdle, but now (probably) GTK timers are not working.
LSP (Linux Studio Plugins) Developer and Maintainer.
User avatar
sadko4u
Established Member
Posts: 986
Joined: Mon Sep 28, 2015 9:03 pm
Has thanked: 2 times
Been thanked: 359 times

Re: JUCE + GTK2 not working

Post by sadko4u »

falkTX wrote:I suppose something needs to make the gtk event loop go. Juce will certainly not do that for you...
gtk_main_iteration is called on every effEditIdle. That doesn't help for JUCE.
LSP (Linux Studio Plugins) Developer and Maintainer.
Post Reply