Questions about incomplete type
errors have already been asked here often, but all of the solutions provided there do not help in my case. Adding a forward declaration makes no sense, as GdkSurface
has been forward declared already in the Gdk headers. Including the appropriate headers has already been done. Following the error producing code portion + includes.
#include <gdkmm/display.h>
#include <gdkmm/surface.h>
extern "C" {
#include <gdk/x11/gdkx.h>
#include <gdk/gdk.h>
}
extern "C" {
void surface_move(Gdk::Surface* psurface, int x, int y) {
#ifdef GDK_WINDOWING_X11
GdkSurface* surface = psurface->gobj();
GdkSurface *impl = GDK_X11_SURFACE(surface);
XMoveWindow(GDK_SURFACE_XDISPLAY (surface), GDK_SURFACE_XID (surface), x * impl->surface_scale, y * impl->surface_scale);
#endif
}
}
Here are the complete errors:
src/utils.cpp: In function ‘void Gdk::surface_move(Gdk::Surface*, int, int)’:
src/utils.cpp:9:83: error: invalid use of incomplete type ‘GdkSurface {aka struct _GdkSurface}’
(GDK_SURFACE_XDISPLAY (surface), GDK_SURFACE_XID (surface), x * impl->surface_scale, y * impl->surface_scale);
^~
In file included from /home/user/.local/built/include/gtk-4.0/gdk/gdkapplaunchcontext.h:29:0,
from /home/user/.local/built/include/gtk-4.0/gdk/gdk.h:30,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/enums.h:29,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/event.h:29,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/display.h:30,
from ./include/libgdp/utils.hpp:3,
from src/utils.cpp:1:
/home/user/.local/built/include/gtk-4.0/gdk/gdktypes.h:97:16: note: forward declaration of ‘GdkSurface {aka struct _GdkSurface}’
typedef struct _GdkSurface GdkSurface;
^~~~~~~~~~~
src/utils.cpp:9:108: error: invalid use of incomplete type ‘GdkSurface {aka struct _GdkSurface}’
rface), GDK_SURFACE_XID (surface), x * impl->surface_scale, y * impl->surface_scale);
^~
In file included from /home/user/.local/built/include/gtk-4.0/gdk/gdkapplaunchcontext.h:29:0,
from /home/user/.local/built/include/gtk-4.0/gdk/gdk.h:30,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/enums.h:29,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/event.h:29,
from /home/user/.local/built/include/gtkmm-4.0/gdkmm/display.h:30,
from ./include/libgdp/utils.hpp:3,
from src/utils.cpp:1:
/home/user/.local/built/include/gtk-4.0/gdk/gdktypes.h:97:16: note: forward declaration of ‘GdkSurface {aka struct _GdkSurface}’
typedef struct _GdkSurface GdkSurface;
^~~~~~~~~~~
I built Gdk, Gtk, Gdkmm and Gtkmm with JHbuild.
It seems this type is private to GDK by design (only a forward declaration is provided). From the GDK4 documentation:
The
GdkSurface
struct
contains only private fields and should not be accessed directly.
See here for the header in which it is defined (which is not distributed). This is why you get these errors, all you have is a forward declaration to pass around pointers and references. All access to data members is forbidden.
To solve this, you have to use functions that work on surfaces (that are public), such as gdk_surface_get_scale_factor
or something similar instead of trying to access data members directly.