meta-wayland-surface.h 12.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * Copyright (C) 2013 Red Hat, Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program 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
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */

#ifndef META_WAYLAND_SURFACE_H
#define META_WAYLAND_SURFACE_H

23 24
#include <cairo.h>
#include <glib.h>
25 26 27
#include <wayland-server.h>
#include <xkbcommon/xkbcommon.h>

28
#include "backends/meta-monitor-manager-private.h"
29
#include "clutter/clutter.h"
30
#include "compositor/meta-shaped-texture-private.h"
31 32 33 34
#include "compositor/meta-surface-actor.h"
#include "meta/meta-cursor-tracker.h"
#include "wayland/meta-wayland-pointer-constraints.h"
#include "wayland/meta-wayland-types.h"
35 36

typedef struct _MetaWaylandPendingState MetaWaylandPendingState;
37

38 39 40 41 42 43
#define META_TYPE_WAYLAND_SURFACE (meta_wayland_surface_get_type ())
G_DECLARE_FINAL_TYPE (MetaWaylandSurface,
                      meta_wayland_surface,
                      META, WAYLAND_SURFACE,
                      GObject);

44 45 46 47
#define META_TYPE_WAYLAND_SURFACE_ROLE (meta_wayland_surface_role_get_type ())
G_DECLARE_DERIVABLE_TYPE (MetaWaylandSurfaceRole, meta_wayland_surface_role,
                          META, WAYLAND_SURFACE_ROLE, GObject);

48 49 50 51 52 53
#define META_TYPE_WAYLAND_PENDING_STATE (meta_wayland_pending_state_get_type ())
G_DECLARE_FINAL_TYPE (MetaWaylandPendingState,
                      meta_wayland_pending_state,
                      META, WAYLAND_PENDING_STATE,
                      GObject);

54 55 56 57 58
struct _MetaWaylandSurfaceRoleClass
{
  GObjectClass parent_class;

  void (*assigned) (MetaWaylandSurfaceRole *surface_role);
59 60
  void (*pre_commit) (MetaWaylandSurfaceRole  *surface_role,
                      MetaWaylandPendingState *pending);
61 62
  void (*commit) (MetaWaylandSurfaceRole  *surface_role,
                  MetaWaylandPendingState *pending);
63 64
  gboolean (*is_on_logical_monitor) (MetaWaylandSurfaceRole *surface_role,
                                     MetaLogicalMonitor     *logical_monitor);
65
  MetaWaylandSurface * (*get_toplevel) (MetaWaylandSurfaceRole *surface_role);
66 67
};

68 69 70 71 72
struct _MetaWaylandSerial {
  gboolean set;
  uint32_t value;
};

73
struct _MetaWaylandPendingState
74
{
75 76
  GObject parent;

77 78 79
  /* wl_surface.attach */
  gboolean newly_attached;
  MetaWaylandBuffer *buffer;
80
  gulong buffer_destroy_handler_id;
81 82
  int32_t dx;
  int32_t dy;
83

84 85
  int scale;

86
  /* wl_surface.damage */
87 88 89
  cairo_region_t *surface_damage;
  /* wl_surface.damage_buffer */
  cairo_region_t *buffer_damage;
90 91

  cairo_region_t *input_region;
92
  gboolean input_region_set;
93
  cairo_region_t *opaque_region;
94
  gboolean opaque_region_set;
95 96 97

  /* wl_surface.frame */
  struct wl_list frame_callback_list;
98

99 100
  MetaRectangle new_geometry;
  gboolean has_new_geometry;
101 102 103 104 105 106 107 108

  /* pending min/max size in window geometry coordinates */
  gboolean has_new_min_size;
  int new_min_width;
  int new_min_height;
  gboolean has_new_max_size;
  int new_max_width;
  int new_max_height;
109 110 111

  gboolean has_new_buffer_transform;
  MetaMonitorTransform buffer_transform;
112 113 114 115 116
  gboolean has_new_viewport_src_rect;
  ClutterRect viewport_src_rect;
  gboolean has_new_viewport_dst_size;
  int viewport_dst_width;
  int viewport_dst_height;
117
};
118

119 120 121 122 123 124 125 126 127 128 129 130
struct _MetaWaylandDragDestFuncs
{
  void (* focus_in)  (MetaWaylandDataDevice *data_device,
                      MetaWaylandSurface    *surface,
                      MetaWaylandDataOffer  *offer);
  void (* focus_out) (MetaWaylandDataDevice *data_device,
                      MetaWaylandSurface    *surface);
  void (* motion)    (MetaWaylandDataDevice *data_device,
                      MetaWaylandSurface    *surface,
                      const ClutterEvent    *event);
  void (* drop)      (MetaWaylandDataDevice *data_device,
                      MetaWaylandSurface    *surface);
131 132
  void (* update)    (MetaWaylandDataDevice *data_device,
                      MetaWaylandSurface    *surface);
133 134
};

135 136
struct _MetaWaylandSurface
{
137 138
  GObject parent;

139
  /* Generic stuff */
140 141
  struct wl_resource *resource;
  MetaWaylandCompositor *compositor;
142
  MetaWaylandSurfaceRole *role;
143
  MetaWindow *window;
144 145
  cairo_region_t *input_region;
  cairo_region_t *opaque_region;
146 147 148
  int scale;
  int32_t offset_x, offset_y;
  GList *subsurfaces;
149
  GHashTable *outputs_to_destroy_notify_id;
150
  MetaMonitorTransform buffer_transform;
151

152 153 154 155 156 157 158 159 160
  /* Buffer reference state. */
  struct {
    MetaWaylandBuffer *buffer;
    unsigned int use_count;
  } buffer_ref;

  /* Buffer renderer state. */
  gboolean buffer_held;

161 162 163 164 165
  /* List of pending frame callbacks that needs to stay queued longer than one
   * commit sequence, such as when it has not yet been assigned a role.
   */
  struct wl_list pending_frame_callback_list;

166 167 168 169 170
  /* Intermediate state for when no role has been assigned. */
  struct {
    MetaWaylandBuffer *buffer;
  } unassigned;

171 172 173 174
  struct {
    const MetaWaylandDragDestFuncs *funcs;
  } dnd;

175
  /* All the pending state that wl_surface.commit will apply. */
176
  MetaWaylandPendingState *pending;
177

178 179
  /* Extension resources. */
  struct wl_resource *wl_subsurface;
180

181
  /* wl_subsurface stuff. */
182 183 184
  struct {
    MetaWaylandSurface *parent;
    struct wl_listener parent_destroy_listener;
185

186 187 188
    int x;
    int y;

189 190 191 192 193 194 195 196
    /* When the surface is synchronous, its state will be applied
     * when the parent is committed. This is done by moving the
     * "real" pending state below to here when this surface is
     * committed and in synchronous mode.
     *
     * When the parent surface is committed, we apply the pending
     * state here.
     */
197
    gboolean synchronous;
198
    MetaWaylandPendingState *pending;
199

200 201 202
    int32_t pending_x;
    int32_t pending_y;
    gboolean pending_pos;
203
    GSList *pending_placement_ops;
204
  } sub;
205

206 207 208 209 210 211 212 213 214 215 216 217 218
  /* wp_viewport */
  struct {
    struct wl_resource *resource;
    gulong destroy_handler_id;

    gboolean has_src_rect;
    ClutterRect src_rect;

    gboolean has_dst_size;
    int dst_width;
    int dst_height;
  } viewport;

219 220
  /* table of seats for which shortcuts are inhibited */
  GHashTable *shortcut_inhibited_seats;
221 222
};

223
void                meta_wayland_shell_init     (MetaWaylandCompositor *compositor);
224 225

MetaWaylandSurface *meta_wayland_surface_create (MetaWaylandCompositor *compositor,
226 227 228
                                                 struct wl_client      *client,
                                                 struct wl_resource    *compositor_resource,
                                                 guint32                id);
229

230 231 232 233 234
void                meta_wayland_surface_apply_pending_state (MetaWaylandSurface      *surface,
                                                              MetaWaylandPendingState *pending);

gboolean            meta_wayland_surface_is_effectively_synchronized (MetaWaylandSurface *surface);

235
gboolean            meta_wayland_surface_assign_role (MetaWaylandSurface *surface,
236 237 238
                                                      GType               role_type,
                                                      const char         *first_property_name,
                                                      ...);
239

240 241 242 243 244 245
MetaWaylandBuffer  *meta_wayland_surface_get_buffer (MetaWaylandSurface *surface);

void                meta_wayland_surface_ref_buffer_use_count (MetaWaylandSurface *surface);

void                meta_wayland_surface_unref_buffer_use_count (MetaWaylandSurface *surface);

246 247
void                meta_wayland_surface_set_window (MetaWaylandSurface *surface,
                                                     MetaWindow         *window);
248

249
void                meta_wayland_surface_configure_notify (MetaWaylandSurface *surface,
250 251
                                                           int                 new_x,
                                                           int                 new_y,
252 253 254
                                                           int                 width,
                                                           int                 height,
                                                           MetaWaylandSerial  *sent_serial);
255

256 257
void                meta_wayland_surface_ping (MetaWaylandSurface *surface,
                                               guint32             serial);
258
void                meta_wayland_surface_delete (MetaWaylandSurface *surface);
259

260 261 262 263 264 265 266
/* Drag dest functions */
void                meta_wayland_surface_drag_dest_focus_in  (MetaWaylandSurface   *surface,
                                                              MetaWaylandDataOffer *offer);
void                meta_wayland_surface_drag_dest_motion    (MetaWaylandSurface   *surface,
                                                              const ClutterEvent   *event);
void                meta_wayland_surface_drag_dest_focus_out (MetaWaylandSurface   *surface);
void                meta_wayland_surface_drag_dest_drop      (MetaWaylandSurface   *surface);
267
void                meta_wayland_surface_drag_dest_update    (MetaWaylandSurface   *surface);
268

269 270
void                meta_wayland_surface_update_outputs (MetaWaylandSurface *surface);

271 272
MetaWaylandSurface *meta_wayland_surface_get_toplevel (MetaWaylandSurface *surface);

273 274
MetaWindow *        meta_wayland_surface_get_toplevel_window (MetaWaylandSurface *surface);

275 276 277
void                meta_wayland_surface_cache_pending_frame_callbacks (MetaWaylandSurface      *surface,
                                                                        MetaWaylandPendingState *pending);

278 279
void                meta_wayland_surface_queue_pending_frame_callbacks (MetaWaylandSurface *surface);

280 281 282
void                meta_wayland_surface_queue_pending_state_frame_callbacks (MetaWaylandSurface      *surface,
                                                                              MetaWaylandPendingState *pending);

283 284 285 286 287 288
void                meta_wayland_surface_get_relative_coordinates (MetaWaylandSurface *surface,
                                                                   float               abs_x,
                                                                   float               abs_y,
                                                                   float              *sx,
                                                                   float              *sy);

289 290 291 292 293 294
void                meta_wayland_surface_get_absolute_coordinates (MetaWaylandSurface *surface,
                                                                   float               sx,
                                                                   float               sy,
                                                                   float              *x,
                                                                   float              *y);

295 296
MetaWaylandSurface * meta_wayland_surface_role_get_surface (MetaWaylandSurfaceRole *role);

297 298
cairo_region_t *    meta_wayland_surface_calculate_input_region (MetaWaylandSurface *surface);

299

300 301 302 303 304 305 306
void                meta_wayland_surface_destroy_window (MetaWaylandSurface *surface);

gboolean            meta_wayland_surface_begin_grab_op (MetaWaylandSurface *surface,
                                                        MetaWaylandSeat    *seat,
                                                        MetaGrabOp          grab_op,
                                                        gfloat              x,
                                                        gfloat              y);
307 308 309 310

void                meta_wayland_surface_window_managed (MetaWaylandSurface *surface,
                                                         MetaWindow         *window);

311 312 313 314 315 316 317 318 319
void                meta_wayland_surface_inhibit_shortcuts (MetaWaylandSurface *surface,
                                                            MetaWaylandSeat    *seat);

void                meta_wayland_surface_restore_shortcuts (MetaWaylandSurface *surface,
                                                            MetaWaylandSeat    *seat);

gboolean            meta_wayland_surface_is_shortcuts_inhibited (MetaWaylandSurface *surface,
                                                                 MetaWaylandSeat    *seat);

320 321
MetaSurfaceActor *  meta_wayland_surface_get_actor (MetaWaylandSurface *surface);

322 323
void                meta_wayland_surface_notify_geometry_changed (MetaWaylandSurface *surface);

324 325 326
int                 meta_wayland_surface_get_width (MetaWaylandSurface *surface);
int                 meta_wayland_surface_get_height (MetaWaylandSurface *surface);

327
#endif