Using GTK 3.24, I’m receiving a different pointer to my user_data
in the focus-in-event
than what I put in when connecting the signal:
// focusData is a member struct
g_signal_connect(widget, "focus-in-event", G_CALLBACK(focus_in_event), &focusData);
std::cout << "Connect: focusData is " << &focusData << std::endl;
My focus-in function looks like this:
static gboolean focus_in_event(GtkWidget* self, GdkEventFocus event, gpointer user_data)
{
DialogFocusData* focusData = (DialogFocusData*)user_data;
std::cout << "FocusIn: focusData is " << user_data << std::endl;
return false;
}
This setup has worked fine with the focus
signal, where I can cast the user_data
pointer to a pointer to my DialogFocusData
struct and it’s always pointing at the address I put in when connecting the signal.
But when doing this with the focus-in-event
, the pointer address of user_data
never is the address I put in during connecting the signal and is surprisingly changing after some events:
// Connecting the signal to some GtkWidgets, note how all pointer addresses are the same
Connect: focusData is 0x55555591c568
Connect: focusData is 0x55555591c568
Connect: focusData is 0x55555591c568
Connect: focusData is 0x55555591c568
Connect: focusData is 0x55555591c568
Connect: focusData is 0x55555591c568
// focus_in_event is called, note how the addresses never match and sometimes change
FocusIn: focusData is 0x555555a83b90
FocusIn: focusData is 0x555555a83b90
FocusIn: focusData is 0x555555c8cfe0
FocusIn: focusData is 0x555555c8cfe0
FocusIn: focusData is 0x555555c8cfe0
FocusIn: focusData is 0x555555c8cfe0
FocusIn: focusData is 0x555555c8cfe0
FocusIn: focusData is 0x555555b8ea90
FocusIn: focusData is 0x555555b8ea90
Is there anything special with the focus-in-event
that reserves the user_data
pointer?