Flutter Linux Embedder
fl_subsurface.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
6 
7 #include <wayland-client.h>
8 
9 struct _FlSubsurface {
10  GObject parent_instance;
11 
12  // Surface backing the subsurface and the subsurface itself.
13  struct wl_surface* surface;
14  struct wl_subsurface* subsurface;
15 };
16 
17 G_DEFINE_TYPE(FlSubsurface, fl_subsurface, G_TYPE_OBJECT)
18 
19 static void fl_subsurface_dispose(GObject* object) {
20  FlSubsurface* self = FL_SUBSURFACE(object);
21 
22  g_clear_pointer(&self->subsurface, wl_subsurface_destroy);
23  g_clear_pointer(&self->surface, wl_surface_destroy);
24 
25  G_OBJECT_CLASS(fl_subsurface_parent_class)->dispose(object);
26 }
27 
28 static void fl_subsurface_class_init(FlSubsurfaceClass* klass) {
29  G_OBJECT_CLASS(klass)->dispose = fl_subsurface_dispose;
30 }
31 
32 static void fl_subsurface_init(FlSubsurface* self) {}
33 
34 FlSubsurface* fl_subsurface_new(struct wl_compositor* compositor,
35  struct wl_subcompositor* subcompositor,
36  struct wl_surface* parent_surface) {
37  FlSubsurface* self =
38  FL_SUBSURFACE(g_object_new(fl_subsurface_get_type(), nullptr));
39 
40  self->surface = wl_compositor_create_surface(compositor);
41  self->subsurface = wl_subcompositor_get_subsurface(
42  subcompositor, self->surface, parent_surface);
43  wl_subsurface_set_sync(self->subsurface);
44 
45  // Give the subsurface an empty input region so pointer, touch and keyboard
46  // events pass through to the parent (GTK) surface, which handles all input
47  // for the view.
48  struct wl_region* input_region = wl_compositor_create_region(compositor);
49  wl_surface_set_input_region(self->surface, input_region);
50  wl_region_destroy(input_region);
51 
52  return self;
53 }
54 
55 struct wl_surface* fl_subsurface_get_surface(FlSubsurface* self) {
56  g_return_val_if_fail(FL_IS_SUBSURFACE(self), nullptr);
57  return self->surface;
58 }
59 
60 void fl_subsurface_set_position(FlSubsurface* self, gint x, gint y) {
61  g_return_if_fail(FL_IS_SUBSURFACE(self));
62  wl_subsurface_set_position(self->subsurface, x, y);
63 }
G_DEFINE_TYPE(FlBasicMessageChannelResponseHandle, fl_basic_message_channel_response_handle, G_TYPE_OBJECT) static void fl_basic_message_channel_response_handle_dispose(GObject *object)
static void fl_subsurface_init(FlSubsurface *self)
static void fl_subsurface_class_init(FlSubsurfaceClass *klass)
FlSubsurface * fl_subsurface_new(struct wl_compositor *compositor, struct wl_subcompositor *subcompositor, struct wl_surface *parent_surface)
void fl_subsurface_set_position(FlSubsurface *self, gint x, gint y)
static void fl_subsurface_dispose(GObject *object)
struct wl_surface * fl_subsurface_get_surface(FlSubsurface *self)
GObject parent_instance
struct wl_surface * surface
struct wl_subsurface * subsurface