MirAL
surface_spec.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2016 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Alan Griffiths <alan@octopull.co.uk>
17  */
18 
19 #ifndef MIRAL_TOOLKIT_SURFACE_SPEC_H
20 #define MIRAL_TOOLKIT_SURFACE_SPEC_H
21 
22 #include <miral/toolkit/surface.h>
23 
24 #include <mir_toolkit/mir_surface.h>
25 #include <mir_toolkit/mir_connection.h>
26 #include <mir_toolkit/version.h>
27 
28 #include <memory>
29 
30 namespace miral
31 {
32 namespace toolkit
33 {
36 {
37 public:
38  explicit SurfaceSpec(MirSurfaceSpec* spec) : self{spec, deleter} {}
39 
40  static auto for_normal_surface(MirConnection* connection, int width, int height, MirPixelFormat format) -> SurfaceSpec
41  {
42  return SurfaceSpec{mir_connection_create_spec_for_normal_surface(connection, width, height, format)};
43  }
44 
45  static auto for_menu(MirConnection* connection,
46  int width,
47  int height,
48  MirPixelFormat format,
49  MirSurface* parent,
50  MirRectangle* rect,
51  MirEdgeAttachment edge) -> SurfaceSpec
52  {
53  return SurfaceSpec{mir_connection_create_spec_for_menu(connection, width, height, format, parent, rect, edge)};
54  }
55 
56  static auto for_changes(MirConnection* connection) -> SurfaceSpec
57  {
58  return SurfaceSpec{mir_connection_create_spec_for_changes(connection)};
59  }
60 
61  auto set_buffer_usage(MirBufferUsage usage) -> SurfaceSpec&
62  {
63  mir_surface_spec_set_buffer_usage(*this, usage);
64  return *this;
65  }
66 
67  auto set_type(MirSurfaceType type) -> SurfaceSpec&
68  {
69  mir_surface_spec_set_type(*this, type);
70  return *this;
71  }
72 
73  auto set_min_size(int min_width, int min_height) -> SurfaceSpec&
74  {
75  mir_surface_spec_set_min_width(*this, min_width);
76  mir_surface_spec_set_min_height(*this, min_height);
77  return *this;
78  }
79 
80  auto set_max_size(int max_width, int max_height) -> SurfaceSpec&
81  {
82  mir_surface_spec_set_max_width(*this, max_width);
83  mir_surface_spec_set_max_height(*this, max_height);
84  return *this;
85  }
86 
87  auto set_size_inc(int width_inc, int height_inc) -> SurfaceSpec&
88  {
89  mir_surface_spec_set_width_increment(*this, width_inc);
90  mir_surface_spec_set_height_increment(*this, height_inc);
91  return *this;
92  }
93 
94  auto set_size(int width, int height) -> SurfaceSpec&
95  {
96  mir_surface_spec_set_width(*this, width);
97  mir_surface_spec_set_height(*this, height);
98  return *this;
99  }
100 
101  auto set_name(char const* name) -> SurfaceSpec&
102  {
103  mir_surface_spec_set_name(*this, name);
104  return *this;
105  }
106 
107  auto set_event_handler(mir_surface_event_callback callback, void* context) -> SurfaceSpec&
108  {
109  mir_surface_spec_set_event_handler(*this, callback, context);
110  return *this;
111  }
112 
113 #if MIR_CLIENT_VERSION >= MIR_VERSION_NUMBER(3, 4, 0)
114  auto set_placement(const MirRectangle* rect,
115  MirPlacementGravity rect_gravity,
116  MirPlacementGravity surface_gravity,
117  MirPlacementHints placement_hints,
118  int offset_dx,
119  int offset_dy) -> SurfaceSpec&
120  {
121  mir_surface_spec_set_placement(*this, rect, rect_gravity, surface_gravity, placement_hints, offset_dx, offset_dy);
122  return *this;
123  }
124 #endif
125 
126  template<typename Context>
127  void create_surface(void (*callback)(MirSurface*, Context*), Context* context) const
128  {
129  mir_surface_create(*this, reinterpret_cast<mir_surface_callback>(callback), context);
130  }
131 
132  auto create_surface() const -> Surface
133  {
134  return Surface{mir_surface_create_sync(*this)};
135  }
136 
137  void apply_to(MirSurface* surface) const
138  {
139  mir_surface_apply_spec(surface, *this);
140  }
141 
142  operator MirSurfaceSpec*() const { return self.get(); }
143 
144 private:
145  static void deleter(MirSurfaceSpec* spec) { mir_surface_spec_release(spec); }
146  std::shared_ptr<MirSurfaceSpec> self;
147 };
148 }
149 }
150 
151 #endif //MIRAL_TOOLKIT_SURFACE_SPEC_H_H
auto set_event_handler(mir_surface_event_callback callback, void *context) -> SurfaceSpec &
Definition: surface_spec.h:107
Handle class for MirSurface - provides automatic reference counting.
Definition: surface.h:31
auto set_size_inc(int width_inc, int height_inc) -> SurfaceSpec &
Definition: surface_spec.h:87
auto set_size(int width, int height) -> SurfaceSpec &
Definition: surface_spec.h:94
static auto for_normal_surface(MirConnection *connection, int width, int height, MirPixelFormat format) -> SurfaceSpec
Definition: surface_spec.h:40
auto set_name(char const *name) -> SurfaceSpec &
Definition: surface_spec.h:101
void create_surface(void(*callback)(MirSurface *, Context *), Context *context) const
Definition: surface_spec.h:127
SurfaceSpec(MirSurfaceSpec *spec)
Definition: surface_spec.h:38
void apply_to(MirSurface *surface) const
Definition: surface_spec.h:137
static auto for_changes(MirConnection *connection) -> SurfaceSpec
Definition: surface_spec.h:56
auto set_placement(const MirRectangle *rect, MirPlacementGravity rect_gravity, MirPlacementGravity surface_gravity, MirPlacementHints placement_hints, int offset_dx, int offset_dy) -> SurfaceSpec &
Definition: surface_spec.h:114
auto set_max_size(int max_width, int max_height) -> SurfaceSpec &
Definition: surface_spec.h:80
auto set_min_size(int min_width, int min_height) -> SurfaceSpec &
Definition: surface_spec.h:73
Handle class for MirSurfaceSpec - provides automatic reference counting, method chaining.
Definition: surface_spec.h:35
auto create_surface() const -> Surface
Definition: surface_spec.h:132
auto set_type(MirSurfaceType type) -> SurfaceSpec &
Definition: surface_spec.h:67
auto set_buffer_usage(MirBufferUsage usage) -> SurfaceSpec &
Definition: surface_spec.h:61
static auto for_menu(MirConnection *connection, int width, int height, MirPixelFormat format, MirSurface *parent, MirRectangle *rect, MirEdgeAttachment edge) -> SurfaceSpec
Definition: surface_spec.h:45
Mir Abstraction Layer.
Definition: active_outputs.h:27

Copyright © 2016 Canonical Ltd.
Generated on Fri Sep 30 13:21:55 UTC 2016