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 #if MIR_CLIENT_VERSION >= MIR_VERSION_NUMBER(3, 4, 0)
57  static auto for_tip(MirConnection* connection,
58  int width,
59  int height,
60  MirPixelFormat format,
61  MirSurface* parent,
62  MirRectangle* rect,
63  MirEdgeAttachment edge) -> SurfaceSpec
64  {
65  return SurfaceSpec{mir_connection_create_spec_for_tip(connection, width, height, format, parent, rect, edge)};
66  }
67 #endif
68 
69  static auto for_dialog(MirConnection* connection,
70  int width,
71  int height,
72  MirPixelFormat format)-> SurfaceSpec
73  {
74  return SurfaceSpec{mir_connection_create_spec_for_dialog(connection, width, height, format)};
75  }
76 
77  static auto for_dialog(MirConnection* connection,
78  int width,
79  int height,
80  MirPixelFormat format,
81  MirSurface* parent) -> SurfaceSpec
82  {
83  return for_dialog(connection, width, height, format).set_parent(parent);
84  }
85 
86  static auto for_changes(MirConnection* connection) -> SurfaceSpec
87  {
88  return SurfaceSpec{mir_connection_create_spec_for_changes(connection)};
89  }
90 
91  auto set_buffer_usage(MirBufferUsage usage) -> SurfaceSpec&
92  {
93  mir_surface_spec_set_buffer_usage(*this, usage);
94  return *this;
95  }
96 
97  auto set_type(MirSurfaceType type) -> SurfaceSpec&
98  {
99  mir_surface_spec_set_type(*this, type);
100  return *this;
101  }
102 
103  auto set_min_size(int min_width, int min_height) -> SurfaceSpec&
104  {
105  mir_surface_spec_set_min_width(*this, min_width);
106  mir_surface_spec_set_min_height(*this, min_height);
107  return *this;
108  }
109 
110  auto set_max_size(int max_width, int max_height) -> SurfaceSpec&
111  {
112  mir_surface_spec_set_max_width(*this, max_width);
113  mir_surface_spec_set_max_height(*this, max_height);
114  return *this;
115  }
116 
117  auto set_size_inc(int width_inc, int height_inc) -> SurfaceSpec&
118  {
119  mir_surface_spec_set_width_increment(*this, width_inc);
120  mir_surface_spec_set_height_increment(*this, height_inc);
121  return *this;
122  }
123 
124  auto set_size(int width, int height) -> SurfaceSpec&
125  {
126  mir_surface_spec_set_width(*this, width);
127  mir_surface_spec_set_height(*this, height);
128  return *this;
129  }
130 
131  auto set_name(char const* name) -> SurfaceSpec&
132  {
133  mir_surface_spec_set_name(*this, name);
134  return *this;
135  }
136 
137  auto set_event_handler(mir_surface_event_callback callback, void* context) -> SurfaceSpec&
138  {
139  mir_surface_spec_set_event_handler(*this, callback, context);
140  return *this;
141  }
142 
143 #if MIR_CLIENT_VERSION >= MIR_VERSION_NUMBER(3, 4, 0)
144  auto set_placement(const MirRectangle* rect,
145  MirPlacementGravity rect_gravity,
146  MirPlacementGravity surface_gravity,
147  MirPlacementHints placement_hints,
148  int offset_dx,
149  int offset_dy) -> SurfaceSpec&
150  {
151  mir_surface_spec_set_placement(*this, rect, rect_gravity, surface_gravity, placement_hints, offset_dx, offset_dy);
152  return *this;
153  }
154 #endif
155 
156  auto set_parent(MirSurface* parent) -> SurfaceSpec&
157  {
158  mir_surface_spec_set_parent(*this, parent);
159  return *this;
160  }
161 
162  template<typename Context>
163  void create_surface(void (*callback)(MirSurface*, Context*), Context* context) const
164  {
165  mir_surface_create(*this, reinterpret_cast<mir_surface_callback>(callback), context);
166  }
167 
168  auto create_surface() const -> Surface
169  {
170  return Surface{mir_surface_create_sync(*this)};
171  }
172 
173  void apply_to(MirSurface* surface) const
174  {
175  mir_surface_apply_spec(surface, *this);
176  }
177 
178  operator MirSurfaceSpec*() const { return self.get(); }
179 
180 private:
181  static void deleter(MirSurfaceSpec* spec) { mir_surface_spec_release(spec); }
182  std::shared_ptr<MirSurfaceSpec> self;
183 };
184 }
185 }
186 
187 #endif //MIRAL_TOOLKIT_SURFACE_SPEC_H_H
auto set_event_handler(mir_surface_event_callback callback, void *context) -> SurfaceSpec &
Definition: surface_spec.h:137
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:117
auto set_size(int width, int height) -> SurfaceSpec &
Definition: surface_spec.h:124
auto set_parent(MirSurface *parent) -> SurfaceSpec &
Definition: surface_spec.h:156
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:131
static auto for_dialog(MirConnection *connection, int width, int height, MirPixelFormat format, MirSurface *parent) -> SurfaceSpec
Definition: surface_spec.h:77
SurfaceSpec(MirSurfaceSpec *spec)
Definition: surface_spec.h:38
static auto for_changes(MirConnection *connection) -> SurfaceSpec
Definition: surface_spec.h:86
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:144
auto set_max_size(int max_width, int max_height) -> SurfaceSpec &
Definition: surface_spec.h:110
auto set_min_size(int min_width, int min_height) -> SurfaceSpec &
Definition: surface_spec.h:103
Handle class for MirSurfaceSpec - provides automatic reference counting, method chaining.
Definition: surface_spec.h:35
auto create_surface() const -> Surface
Definition: surface_spec.h:168
static auto for_dialog(MirConnection *connection, int width, int height, MirPixelFormat format) -> SurfaceSpec
Definition: surface_spec.h:69
auto set_type(MirSurfaceType type) -> SurfaceSpec &
Definition: surface_spec.h:97
void create_surface(void(*callback)(MirSurface *, Context *), Context *context) const
Definition: surface_spec.h:163
auto set_buffer_usage(MirBufferUsage usage) -> SurfaceSpec &
Definition: surface_spec.h:91
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
static auto for_tip(MirConnection *connection, int width, int height, MirPixelFormat format, MirSurface *parent, MirRectangle *rect, MirEdgeAttachment edge) -> SurfaceSpec
Definition: surface_spec.h:57
void apply_to(MirSurface *surface) const
Definition: surface_spec.h:173

Copyright © 2016 Canonical Ltd.
Generated on Tue Dec 20 16:03:55 UTC 2016