gdk: Allow display subclasses to override the type used for windows

We want to have different window types for different displays, so we can
write code like this:

  #if GDK_WINDOWING_X11
    if (GDK_IS_X11_WINDOW (window))
      {
        /* do x11 stuff */
      }
    else
  #endif
  #if GDK_WINDOWING_WAYLAND
    if (GDK_IS_WAYLAND_WINDOW (window))
      {
        /* do wayland stuff */
      }
    else
  #endif
      {
        /* do stuff for unsupported system */
    }

This requires different GdkWindow types and we currently don't have
that, as only the GdkWindowImpl differs. With this method, every backend
defines a custom type that's just a simple subclass of GdkWindow. This
way GdkWindow behaves like all the other types (visuals, screens,
displays) and we can write code like the above.
This commit is contained in:
Benjamin Otte 2010-12-21 03:13:55 +01:00 committed by Matthias Clasen
parent 3036922b3d
commit af7afbbe06
2 changed files with 4 additions and 1 deletions

View File

@ -186,6 +186,7 @@ gdk_display_class_init (GdkDisplayClass *class)
object_class->dispose = gdk_display_dispose;
class->get_app_launch_context = gdk_display_real_get_app_launch_context;
class->window_type = GDK_TYPE_WINDOW;
/**
* GdkDisplay::opened:
@ -2501,7 +2502,7 @@ _gdk_display_create_window_impl (GdkDisplay *display,
GdkWindow *
_gdk_display_create_window (GdkDisplay *display)
{
return g_object_new (GDK_TYPE_WINDOW, NULL);
return g_object_new (GDK_DISPLAY_GET_CLASS (display)->window_type, NULL);
}
/**

View File

@ -115,6 +115,8 @@ struct _GdkDisplayClass
{
GObjectClass parent_class;
GType window_type; /* type for native windows for this display, set in class_init */
G_CONST_RETURN gchar * (*get_name) (GdkDisplay *display);
gint (*get_n_screens) (GdkDisplay *display);
GdkScreen * (*get_screen) (GdkDisplay *display,