Check GTK version in header files

174 views
Skip to first unread message

Prashant

unread,
Sep 9, 2017, 5:34:48 AM9/9/17
to wx-dev
Hi,

I Need to define "GdkEventSequence" which was added to gtk in GTK 3.4. It is used to generate some of the gestures which are currently not available in GtkGesture (introduced in GTK 3.14). So, I tried to perform the check GTK_CHECK_VERSION(3,14,0) :

#if GTK_CHECK_VERSION(3, 14, 0) 
typedef struct _GdkEventSequence GdkEventSequence;
#endif // GTK_CHECK_VERSION(3, 14, 0)

which gives me the following error:

../include/wx/gtk/window.h:359:5: warning: "GTK_CHECK_VERSION" is not defined [-Wundef]
 #if GTK_CHECK_VERSION(3,14,0)
     ^
../include/wx/gtk/window.h:359:22: error: missing binary operator before token "("
 #if GTK_CHECK_VERSION(3,14,0)

GTK_CHECK_VERSION works fine in .cpp files but not in .h files. 

whar needs to be done to know the exact GTK version in header files ?

Thanks
Prashant.



Prashant

unread,
Sep 9, 2017, 6:05:39 AM9/9/17
to wx-dev
Problem was resolved after including <gtk/gtk.h> in include/wx/gtk/window.h. But Is it the best way to do this ?

Vadim Zeitlin

unread,
Sep 9, 2017, 8:35:18 AM9/9/17
to wx-...@googlegroups.com
On Sat, 9 Sep 2017 03:05:39 -0700 (PDT) Prashant wrote:

P> Problem was resolved after including <gtk/gtk.h> in
P> include/wx/gtk/window.h. But Is it the best way to do this ?

No, we try to avoid including GTK+ headers from public wx headers (and
wx/gtk/window.h is public, as it's included from the public wx/window.h).

P> On Saturday, September 9, 2017 at 3:04:48 PM UTC+5:30, Prashant wrote:
P> >
P> > I Need to define "GdkEventSequence" which was added to gtk in GTK 3.4. It
P> > is used to generate some of the gestures which are currently not available
P> > in GtkGesture (introduced in GTK 3.14). So, I tried to perform the check
P> > GTK_CHECK_VERSION(3,14,0) :
P> >
P> > #if GTK_CHECK_VERSION(3, 14, 0)
P> > typedef struct _GdkEventSequence GdkEventSequence;
P> > #endif // GTK_CHECK_VERSION(3, 14, 0)

The simplest thing to do is to just remove GTK_CHECK_VERSION() check. Even
if the symbol doesn't exist in the previous GTK+ versions, there is no harm
in always defining a typedef. Just use GTK_CHECK_VERSION(), as well as the
runtime check for GTK+ version, before actually using it.

P> > whar needs to be done to know the exact GTK version in header files ?

If you really, really need to check GTK+ version in public headers, the
only solution is to test for the version in configure and define the
corresponding __WXGTKxy__ symbol (see the existing __WXGTK210__ etc). But
you don't really need it here.

Regards,
VZ

Prashant Kumar

unread,
Sep 9, 2017, 10:12:53 AM9/9/17
to wx-...@googlegroups.com
This is the build error produced by travis-ci , compile on gtk-2.0 :

In file included from ./include/wx/window.h:1963:0,

from ./include/wx/wx.h:38,

from ./include/wx/wxprec.h:42:

./include/wx/gtk/window.h:365:5: error: ‘GdkEventSequence’ does not name a type

GdkEventSequence* m_touchSequence;

^

make: *** [.pch/wxprec_coredll/wx/wxprec.h.gch] Error 1

As you can see there is a member variable of type GdkEventSequence* .
 
so, I guess I need to define __wxGTK314__ and use it to include/exclude this member variable

Thanks
Prashant.

 Regards,
VZ

Vadim Zeitlin

unread,
Sep 9, 2017, 10:39:16 AM9/9/17
to wx-...@googlegroups.com
On Sat, 9 Sep 2017 19:42:10 +0530 Prashant Kumar wrote:

PK> This is the build error produced by travis-ci
PK> <https://travis-ci.org/wxWidgets/wxWidgets/jobs/273508444> , compile on
PK> gtk-2.0 :

But you don't have the typedef in the header, do you?

PK> so, I guess I need to define __wxGTK314__ and use it to include/exclude
PK> this member variable

No, you can just add the line

typedef struct _GdkEventSequence GdkEventSequence;

to the header. When using GTK+ 3.14 this is going to declare it in exactly
the same way as GTK+ itself does, while with the earlier version it
wouldn't matter as it's not going to be used anyhow.

You should take "m_touchSequence" definition inside #ifdef __WXGTK3__
guard however, just to avoid having a variable which is never used with
GTK+ 2 (unless all this code is already GTK+ 3-specific?).

Regards,
VZ

Prashant Kumar

unread,
Sep 9, 2017, 11:38:17 AM9/9/17
to wx-...@googlegroups.com
I got your point now. Thanks a lot

Prashant.
 
 
 

 Regards,
VZ

Reply all
Reply to author
Forward
0 new messages