[gtk/wip/chergert/quartz4u] stub out cairo/draw context



commit b9e6914c04c999b31acf33c601312e139038209e
Author: Christian Hergert <chergert redhat com>
Date:   Mon Apr 27 16:33:53 2020 -0700

    stub out cairo/draw context

 gdk/macos/gdkmacoscairocontext-private.h |  38 +++++++
 gdk/macos/gdkmacoscairocontext.c         | 104 ++++++++++++++++++
 gdk/macos/gdkmacosdisplay.c              |   3 +
 gdk/macos/gdkmacossurface-private.h      |  30 +++--
 gdk/macos/gdkmacossurface.c              |  49 +++++++++
 gdk/macos/gdkmacostoplevelsurface.c      | 182 ++++++++++++++++++++++++++++++-
 gdk/macos/meson.build                    |   1 +
 7 files changed, 389 insertions(+), 18 deletions(-)
---
diff --git a/gdk/macos/gdkmacoscairocontext-private.h b/gdk/macos/gdkmacoscairocontext-private.h
new file mode 100644
index 0000000000..1afede8591
--- /dev/null
+++ b/gdk/macos/gdkmacoscairocontext-private.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright © 2020 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#ifndef __GDK_MACOS_CAIRO_CONTEXT_PRIVATE_H__
+#define __GDK_MACOS_CAIRO_CONTEXT_PRIVATE_H__
+
+#include "gdkcairocontextprivate.h"
+
+G_BEGIN_DECLS
+
+typedef struct _GdkMacosCairoContext      GdkMacosCairoContext;
+typedef struct _GdkMacosCairoContextClass GdkMacosCairoContextClass;
+
+#define GDK_TYPE_MACOS_CAIRO_CONTEXT       (_gdk_macos_cairo_context_get_type())
+#define GDK_MACOS_CAIRO_CONTEXT(object)    (G_TYPE_CHECK_INSTANCE_CAST ((object), 
GDK_TYPE_MACOS_CAIRO_CONTEXT, GdkMacosCairoContext))
+#define GDK_IS_MACOS_CAIRO_CONTEXT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), 
GDK_TYPE_MACOS_CAIRO_CONTEXT))
+
+GType _gdk_macos_cairo_context_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* __GDK_MACOS_CAIRO_CONTEXT_PRIVATE_H__ */
diff --git a/gdk/macos/gdkmacoscairocontext.c b/gdk/macos/gdkmacoscairocontext.c
new file mode 100644
index 0000000000..bb8aecba84
--- /dev/null
+++ b/gdk/macos/gdkmacoscairocontext.c
@@ -0,0 +1,104 @@
+/*
+ * Copyright © 2020 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#include "config.h"
+
+#include "gdkconfig.h"
+
+#include "gdkmacoscairocontext-private.h"
+
+struct _GdkMacosCairoContext
+{
+  GdkCairoContext parent_instance;
+};
+
+struct _GdkMacosCairoContextClass
+{
+  GdkCairoContextClass parent_class;
+};
+
+G_DEFINE_TYPE (GdkMacosCairoContext, _gdk_macos_cairo_context, GDK_TYPE_CAIRO_CONTEXT)
+
+static cairo_t *
+_gdk_macos_cairo_context_cairo_create (GdkCairoContext *cairo_context)
+{
+  GdkMacosCairoContext *self = (GdkMacosCairoContext *)cairo_context;
+
+  g_assert (GDK_IS_MACOS_CAIRO_CONTEXT (self));
+
+  return NULL;
+}
+
+static void
+_gdk_macos_cairo_context_begin_frame (GdkDrawContext *draw_context,
+                                      cairo_region_t *region)
+{
+  GdkMacosCairoContext *self = (GdkMacosCairoContext *)draw_context;
+
+  g_assert (GDK_IS_MACOS_CAIRO_CONTEXT (self));
+
+}
+
+static void
+_gdk_macos_cairo_context_end_frame (GdkDrawContext *draw_context,
+                                   cairo_region_t  *painted)
+{
+  GdkMacosCairoContext *self = (GdkMacosCairoContext *)draw_context;
+
+  g_assert (GDK_IS_MACOS_CAIRO_CONTEXT (self));
+
+}
+
+static void
+_gdk_macos_cairo_context_surface_resized (GdkDrawContext *draw_context)
+{
+  GdkMacosCairoContext *self = (GdkMacosCairoContext *)draw_context;
+
+  g_assert (GDK_IS_MACOS_CAIRO_CONTEXT (self));
+
+}
+
+static void
+_gdk_macos_cairo_context_dispose (GObject *object)
+{
+  GdkMacosCairoContext *self = (GdkMacosCairoContext *)object;
+
+  G_OBJECT_CLASS (_gdk_macos_cairo_context_parent_class)->dispose (object);
+}
+
+static void
+_gdk_macos_cairo_context_class_init (GdkMacosCairoContextClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GdkCairoContextClass *cairo_context_class = GDK_CAIRO_CONTEXT_CLASS (klass);
+  GdkDrawContextClass *draw_context_class = GDK_DRAW_CONTEXT_CLASS (klass);
+
+  object_class->dispose = _gdk_macos_cairo_context_dispose;
+
+  draw_context_class->begin_frame = _gdk_macos_cairo_context_begin_frame;
+  draw_context_class->end_frame = _gdk_macos_cairo_context_end_frame;
+  draw_context_class->surface_resized = _gdk_macos_cairo_context_surface_resized;
+
+  cairo_context_class->cairo_create = _gdk_macos_cairo_context_cairo_create;
+}
+
+static void
+_gdk_macos_cairo_context_init (GdkMacosCairoContext *self)
+{
+}
diff --git a/gdk/macos/gdkmacosdisplay.c b/gdk/macos/gdkmacosdisplay.c
index 342e299ba5..660f34ed66 100644
--- a/gdk/macos/gdkmacosdisplay.c
+++ b/gdk/macos/gdkmacosdisplay.c
@@ -22,6 +22,7 @@
 #include <AppKit/AppKit.h>
 #include <gdk/gdk.h>
 
+#include "gdkmacoscairocontext-private.h"
 #include "gdkdisplayprivate.h"
 #include "gdkmacoseventsource-private.h"
 #include "gdkmacosdisplay-private.h"
@@ -321,6 +322,8 @@ gdk_macos_display_class_init (GdkMacosDisplayClass *klass)
 
   object_class->finalize = gdk_macos_display_finalize;
 
+  display_class->cairo_context_type = GDK_TYPE_MACOS_CAIRO_CONTEXT;
+
   display_class->beep = gdk_macos_display_beep;
   display_class->create_surface = gdk_macos_display_create_surface;
   display_class->event_data_copy = gdk_macos_display_event_data_copy;
diff --git a/gdk/macos/gdkmacossurface-private.h b/gdk/macos/gdkmacossurface-private.h
index 24262585c0..01b5a6bdfb 100644
--- a/gdk/macos/gdkmacossurface-private.h
+++ b/gdk/macos/gdkmacossurface-private.h
@@ -37,18 +37,24 @@ struct _GdkMacosSurfaceClass
   GdkSurfaceClass parent_class;
 };
 
-GdkMacosSurface *_gdk_macos_surface_new        (GdkMacosDisplay *display,
-                                                GdkSurfaceType   surface_type,
-                                                GdkSurface      *parent,
-                                                int              x,
-                                                int              y,
-                                                int              width,
-                                                int              height);
-void             _gdk_macos_surface_get_shadow (GdkMacosSurface *self,
-                                                gint            *top,
-                                                gint            *right,
-                                                gint            *bottom,
-                                                gint            *left);
+GdkMacosSurface *_gdk_macos_surface_new            (GdkMacosDisplay *display,
+                                                    GdkSurfaceType   surface_type,
+                                                    GdkSurface      *parent,
+                                                    int              x,
+                                                    int              y,
+                                                    int              width,
+                                                    int              height);
+const char      *_gdk_macos_surface_get_title      (GdkMacosSurface *self);
+void             _gdk_macos_surface_set_title      (GdkMacosSurface *self,
+                                                    const gchar     *title);
+void             _gdk_macos_surface_get_shadow     (GdkMacosSurface *self,
+                                                    gint            *top,
+                                                    gint            *right,
+                                                    gint            *bottom,
+                                                    gint            *left);
+gboolean         _gdk_macos_surface_get_modal_hint (GdkMacosSurface *self);
+void             _gdk_macos_surface_set_modal_hint (GdkMacosSurface *self,
+                                                    gboolean         modal_hint);
 
 G_END_DECLS
 
diff --git a/gdk/macos/gdkmacossurface.c b/gdk/macos/gdkmacossurface.c
index 359de74059..7c799464eb 100644
--- a/gdk/macos/gdkmacossurface.c
+++ b/gdk/macos/gdkmacossurface.c
@@ -31,10 +31,14 @@
 
 typedef struct
 {
+  char *title;
+
   gint shadow_top;
   gint shadow_right;
   gint shadow_bottom;
   gint shadow_left;
+
+  guint modal_hint : 1;
 } GdkMacosSurfacePrivate;
 
 G_DEFINE_TYPE_WITH_PRIVATE (GdkMacosSurface, gdk_macos_surface, GDK_TYPE_SURFACE)
@@ -43,6 +47,9 @@ static void
 gdk_macos_surface_finalize (GObject *object)
 {
   GdkMacosSurface *self = (GdkMacosSurface *)object;
+  GdkMacosSurfacePrivate *priv = gdk_macos_surface_get_instance_private (self);
+
+  g_clear_pointer (&priv->title, g_free);
 
   G_OBJECT_CLASS (gdk_macos_surface_parent_class)->finalize (object);
 }
@@ -110,3 +117,45 @@ _gdk_macos_surface_get_shadow (GdkMacosSurface *self,
   if (right)
     *right = priv->shadow_right;
 }
+
+const char *
+_gdk_macos_surface_get_title (GdkMacosSurface *self)
+{
+  GdkMacosSurfacePrivate *priv = gdk_macos_surface_get_instance_private (self);
+
+  return priv->title;
+}
+
+void
+_gdk_macos_surface_set_title (GdkMacosSurface *self,
+                              const gchar     *title)
+{
+  GdkMacosSurfacePrivate *priv = gdk_macos_surface_get_instance_private (self);
+
+  if (g_strcmp0 (priv->title, title) != 0)
+    {
+      g_free (priv->title);
+      priv->title = g_strdup (title);
+    }
+}
+
+gboolean
+_gdk_macos_surface_get_modal_hint (GdkMacosSurface *self)
+{
+  GdkMacosSurfacePrivate *priv = gdk_macos_surface_get_instance_private (self);
+
+  g_return_val_if_fail (GDK_IS_MACOS_SURFACE (self), FALSE);
+
+  return priv->modal_hint;
+}
+
+void
+_gdk_macos_surface_set_modal_hint (GdkMacosSurface *self,
+                                   gboolean         modal_hint)
+{
+  GdkMacosSurfacePrivate *priv = gdk_macos_surface_get_instance_private (self);
+
+  g_return_if_fail (GDK_IS_MACOS_SURFACE (self));
+
+  priv->modal_hint = !!modal_hint;
+}
diff --git a/gdk/macos/gdkmacostoplevelsurface.c b/gdk/macos/gdkmacostoplevelsurface.c
index c19747ab31..f2c691fd7b 100644
--- a/gdk/macos/gdkmacostoplevelsurface.c
+++ b/gdk/macos/gdkmacostoplevelsurface.c
@@ -19,13 +19,20 @@
 
 #include "config.h"
 
-#include "gdktoplevelprivate.h"
+#import "GdkMacosWindow.h"
 
+#include "gdktoplevelprivate.h"
 #include "gdkmacostoplevelsurface-private.h"
+#include "gdkmacosutils-private.h"
 
 struct _GdkMacosToplevelSurface
 {
-  GdkMacosSurface parent_instance;
+  GdkMacosSurface  parent_instance;
+
+  GdkMacosSurface *transient_for;
+  NSWindow        *window;
+
+  guint            decorated : 1;
 };
 
 struct _GdkMacosToplevelSurfaceClass
@@ -38,28 +45,191 @@ toplevel_iface_init (GdkToplevelInterface *iface)
 {
 }
 
+enum {
+  PROP_0,
+  LAST_PROP
+};
+
 G_DEFINE_TYPE_WITH_CODE (GdkMacosToplevelSurface, _gdk_macos_toplevel_surface, GDK_TYPE_MACOS_SURFACE,
                          G_IMPLEMENT_INTERFACE (GDK_TYPE_TOPLEVEL, toplevel_iface_init))
 
 static void
-_gdk_macos_toplevel_surface_finalize (GObject *object)
+_gdk_macos_toplevel_surface_set_transient_for (GdkMacosToplevelSurface *self,
+                                               GdkMacosSurface         *parent)
+{
+  g_assert (GDK_IS_MACOS_TOPLEVEL_SURFACE (self));
+  g_assert (!parent || GDK_IS_MACOS_SURFACE (parent));
+
+  g_set_object (&self->transient_for, parent);
+}
+
+static void
+_gdk_macos_toplevel_surface_set_decorated (GdkMacosToplevelSurface *self,
+                                           gboolean                 decorated)
 {
-  G_OBJECT_CLASS (_gdk_macos_toplevel_surface_parent_class)->finalize (object);
+  g_assert (GDK_IS_MACOS_TOPLEVEL_SURFACE (self));
+
+  decorated = !!decorated;
+
+  if (decorated != self->decorated)
+    {
+      self->decorated = decorated;
+      [self->window setHasShadow:decorated ? YES : NO];
+    }
+}
+
+static void
+_gdk_macos_toplevel_surface_destroy (GdkSurface *surface,
+                                     gboolean    foreign_destroy)
+{
+  GdkMacosToplevelSurface *self = (GdkMacosToplevelSurface *)surface;
+
+  if (self->window != NULL)
+    {
+      GDK_BEGIN_MACOS_ALLOC_POOL;
+
+      GdkMacosWindow *window = g_steal_pointer (&self->window);
+
+      if (window != NULL)
+        [window close];
+
+      GDK_END_MACOS_ALLOC_POOL;
+    }
+
+  g_clear_object (&self->transient_for);
+
+  GDK_SURFACE_CLASS (_gdk_macos_toplevel_surface_parent_class)->destroy (surface, foreign_destroy);
+}
+
+static void
+_gdk_macos_toplevel_surface_get_property (GObject    *object,
+                                          guint       prop_id,
+                                          GValue     *value,
+                                          GParamSpec *pspec)
+{
+  GdkSurface *surface = GDK_SURFACE (object);
+  GdkMacosSurface *base = GDK_MACOS_SURFACE (surface);
+  GdkMacosToplevelSurface *toplevel = GDK_MACOS_TOPLEVEL_SURFACE (base);
+
+  switch (prop_id)
+    {
+    case LAST_PROP + GDK_TOPLEVEL_PROP_STATE:
+      g_value_set_flags (value, surface->state);
+      break;
+
+    case LAST_PROP + GDK_TOPLEVEL_PROP_TITLE:
+      g_value_set_string (value, _gdk_macos_surface_get_title (base));
+      break;
+
+    case LAST_PROP + GDK_TOPLEVEL_PROP_STARTUP_ID:
+      g_value_set_string (value, "");
+      break;
+
+    case LAST_PROP + GDK_TOPLEVEL_PROP_TRANSIENT_FOR:
+      g_value_set_object (value, toplevel->transient_for);
+      break;
+
+    case LAST_PROP + GDK_TOPLEVEL_PROP_MODAL:
+      g_value_set_boolean (value, _gdk_macos_surface_get_modal_hint (base));
+      break;
+
+    case LAST_PROP + GDK_TOPLEVEL_PROP_ICON_LIST:
+      g_value_set_pointer (value, NULL);
+      break;
+
+    case LAST_PROP + GDK_TOPLEVEL_PROP_DECORATED:
+      g_value_set_boolean (value, toplevel->decorated);
+      break;
+
+    case LAST_PROP + GDK_TOPLEVEL_PROP_DELETABLE:
+      break;
+
+    case LAST_PROP + GDK_TOPLEVEL_PROP_FULLSCREEN_MODE:
+      g_value_set_enum (value, surface->fullscreen_mode);
+      break;
+
+    case LAST_PROP + GDK_TOPLEVEL_PROP_SHORTCUTS_INHIBITED:
+      g_value_set_boolean (value, surface->shortcuts_inhibited);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+_gdk_macos_toplevel_surface_set_property (GObject      *object,
+                                          guint         prop_id,
+                                          const GValue *value,
+                                          GParamSpec   *pspec)
+{
+  GdkSurface *surface = GDK_SURFACE (object);
+  GdkMacosSurface *base = GDK_MACOS_SURFACE (surface);
+  GdkMacosToplevelSurface *toplevel = GDK_MACOS_TOPLEVEL_SURFACE (base);
+
+  switch (prop_id)
+    {
+    case LAST_PROP + GDK_TOPLEVEL_PROP_TITLE:
+      _gdk_macos_surface_set_title (base, g_value_get_string (value));
+      g_object_notify_by_pspec (G_OBJECT (surface), pspec);
+      break;
+
+    case LAST_PROP + GDK_TOPLEVEL_PROP_STARTUP_ID:
+      break;
+
+    case LAST_PROP + GDK_TOPLEVEL_PROP_TRANSIENT_FOR:
+      _gdk_macos_toplevel_surface_set_transient_for (toplevel, g_value_get_object (value));
+      g_object_notify_by_pspec (G_OBJECT (surface), pspec);
+      break;
+
+    case LAST_PROP + GDK_TOPLEVEL_PROP_MODAL:
+      _gdk_macos_surface_set_modal_hint (base, g_value_get_boolean (value));
+      g_object_notify_by_pspec (G_OBJECT (surface), pspec);
+      break;
+
+    case LAST_PROP + GDK_TOPLEVEL_PROP_ICON_LIST:
+      break;
+
+    case LAST_PROP + GDK_TOPLEVEL_PROP_DECORATED:
+      _gdk_macos_toplevel_surface_set_decorated (toplevel, g_value_get_boolean (value));
+      break;
+
+    case LAST_PROP + GDK_TOPLEVEL_PROP_DELETABLE:
+      break;
+
+    case LAST_PROP + GDK_TOPLEVEL_PROP_FULLSCREEN_MODE:
+      surface->fullscreen_mode = g_value_get_enum (value);
+      g_object_notify_by_pspec (G_OBJECT (surface), pspec);
+      break;
+
+    case LAST_PROP + GDK_TOPLEVEL_PROP_SHORTCUTS_INHIBITED:
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
 }
 
 static void
 _gdk_macos_toplevel_surface_class_init (GdkMacosToplevelSurfaceClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GdkSurfaceClass *surface_class = GDK_SURFACE_CLASS (klass);
+
+  object_class->get_property = _gdk_macos_toplevel_surface_get_property;
+  object_class->set_property = _gdk_macos_toplevel_surface_set_property;
 
-  object_class->finalize = _gdk_macos_toplevel_surface_finalize;
+  surface_class->destroy = _gdk_macos_toplevel_surface_destroy;
 
-  gdk_toplevel_install_properties (object_class, 1);
+  gdk_toplevel_install_properties (object_class, LAST_PROP);
 }
 
 static void
 _gdk_macos_toplevel_surface_init (GdkMacosToplevelSurface *self)
 {
+  self->decorated = TRUE;
 }
 
 GdkMacosSurface *
diff --git a/gdk/macos/meson.build b/gdk/macos/meson.build
index c46a7bfced..292b484f6e 100644
--- a/gdk/macos/meson.build
+++ b/gdk/macos/meson.build
@@ -1,5 +1,6 @@
 gdk_macos_sources = files([
   'GdkMacosWindow.c',
+  'gdkmacoscairocontext.c',
   'gdkmacosdevice.c',
   'gdkmacosdisplay.c',
   'gdkmacosdragsurface.c',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]