[gtk/present-toplevel: 6/54] surface: Implement GdkPopup
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/present-toplevel: 6/54] surface: Implement GdkPopup
- Date: Sun, 1 Mar 2020 19:34:12 +0000 (UTC)
commit fb34e9146a7eea9782cc66abb3935a8d5dbb7f5b
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Feb 29 09:34:11 2020 -0500
surface: Implement GdkPopup
This is not quite right, and only temporary, since
it makes GDK_IS_POPUP (surface) true for every surface.
Eventually, the implementation will be moved to the
backends.
gdk/gdkpopup.c | 5 +++-
gdk/gdkpopup.h | 2 +-
gdk/gdksurface.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 87 insertions(+), 3 deletions(-)
---
diff --git a/gdk/gdkpopup.c b/gdk/gdkpopup.c
index 8960ae8214..3847596600 100644
--- a/gdk/gdkpopup.c
+++ b/gdk/gdkpopup.c
@@ -31,7 +31,10 @@
*/
-G_DEFINE_INTERFACE (GdkPopup, gdk_popup, GDK_TYPE_SURFACE)
+/* FIXME: this can't have GdkSurface as a prerequisite
+ * as long as GdkSurface implements this interface itself
+ */
+G_DEFINE_INTERFACE (GdkPopup, gdk_popup, G_TYPE_OBJECT)
static gboolean
gdk_popup_default_present (GdkPopup *popup,
diff --git a/gdk/gdkpopup.h b/gdk/gdkpopup.h
index a94be145a5..5f3a15bb37 100644
--- a/gdk/gdkpopup.h
+++ b/gdk/gdkpopup.h
@@ -32,7 +32,7 @@ G_BEGIN_DECLS
#define GDK_TYPE_POPUP (gdk_popup_get_type ())
GDK_AVAILABLE_IN_ALL
-G_DECLARE_INTERFACE (GdkPopup, gdk_popup, GDK, POPUP, GdkSurface)
+G_DECLARE_INTERFACE (GdkPopup, gdk_popup, GDK, POPUP, GObject)
GDK_AVAILABLE_IN_ALL
gboolean gdk_popup_present (GdkPopup *popup,
diff --git a/gdk/gdksurface.c b/gdk/gdksurface.c
index 76aedf90a2..c2fba480a9 100644
--- a/gdk/gdksurface.c
+++ b/gdk/gdksurface.c
@@ -38,6 +38,7 @@
#include "gdkframeclockidleprivate.h"
#include "gdkmarshalers.h"
#include "gdkglcontextprivate.h"
+#include "gdkpopupprivate.h"
#include "gdk-private.h"
#include <math.h>
@@ -112,7 +113,11 @@ static void gdk_surface_set_frame_clock (GdkSurface *surface,
static guint signals[LAST_SIGNAL] = { 0 };
static GParamSpec *properties[LAST_PROP] = { NULL, };
-G_DEFINE_ABSTRACT_TYPE (GdkSurface, gdk_surface, G_TYPE_OBJECT)
+static void gdk_surface_popup_init (GdkPopupInterface *iface);
+
+G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GdkSurface, gdk_surface, G_TYPE_OBJECT,
+ G_IMPLEMENT_INTERFACE (GDK_TYPE_POPUP,
+ gdk_surface_popup_init))
static gboolean
gdk_surface_real_beep (GdkSurface *surface)
@@ -2137,6 +2142,82 @@ gdk_surface_get_popup_rect_anchor (GdkSurface *surface)
return surface->popup.rect_anchor;
}
+static gboolean
+gdk_popup_surface_present (GdkPopup *popup,
+ int width,
+ int height,
+ GdkPopupLayout *layout)
+{
+ GdkSurface *surface = GDK_SURFACE (popup);
+
+ g_return_val_if_fail (surface->surface_type == GDK_SURFACE_POPUP, FALSE);
+
+ return gdk_surface_present_popup (surface, width, height, layout);
+}
+
+static GdkGravity
+gdk_popup_surface_get_surface_anchor (GdkPopup *popup)
+{
+ GdkSurface *surface = GDK_SURFACE (popup);
+
+ g_return_val_if_fail (surface->surface_type == GDK_SURFACE_POPUP, GDK_GRAVITY_STATIC);
+
+ return gdk_surface_get_popup_surface_anchor (surface);
+}
+
+static GdkGravity
+gdk_popup_surface_get_rect_anchor (GdkPopup *popup)
+{
+ GdkSurface *surface = GDK_SURFACE (popup);
+
+ g_return_val_if_fail (surface->surface_type == GDK_SURFACE_POPUP, GDK_GRAVITY_STATIC);
+
+ return gdk_surface_get_popup_rect_anchor (surface);
+}
+
+static GdkSurface *
+gdk_popup_surface_get_parent (GdkPopup *popup)
+{
+ GdkSurface *surface = GDK_SURFACE (popup);
+
+ g_return_val_if_fail (surface->surface_type == GDK_SURFACE_POPUP, NULL);
+
+ return gdk_surface_get_parent (surface);
+}
+
+static void
+gdk_popup_surface_get_position (GdkPopup *popup,
+ int *x,
+ int *y)
+{
+ GdkSurface *surface = GDK_SURFACE (popup);
+
+ g_return_if_fail (surface->surface_type == GDK_SURFACE_POPUP);
+
+ gdk_surface_get_position (surface, x, y);
+}
+
+static gboolean
+gdk_popup_surface_get_autohide (GdkPopup *popup)
+{
+ GdkSurface *surface = GDK_SURFACE (popup);
+
+ g_return_val_if_fail (surface->surface_type == GDK_SURFACE_POPUP, FALSE);
+
+ return surface->autohide;
+}
+
+static void
+gdk_surface_popup_init (GdkPopupInterface *iface)
+{
+ iface->present = gdk_popup_surface_present;
+ iface->get_surface_anchor = gdk_popup_surface_get_surface_anchor;
+ iface->get_rect_anchor = gdk_popup_surface_get_rect_anchor;
+ iface->get_parent = gdk_popup_surface_get_parent;
+ iface->get_position = gdk_popup_surface_get_position;
+ iface->get_autohide = gdk_popup_surface_get_autohide;
+}
+
static void
gdk_surface_set_cursor_internal (GdkSurface *surface,
GdkDevice *device,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]