~gerboland/miral/release-patched

« back to all changes in this revision

Viewing changes to include/miral/toolkit/window_spec.h

  • Committer: Bileto Bot
  • Date: 2017-01-27 03:02:13 UTC
  • mfrom: (330.2.167 miral0)
  • Revision ID: ci-train-bot@canonical.com-20170127030213-q62prxw1xh7kasbu
* New upstream release 1.1.0 (https://launchpad.net/miral/+milestone/1.1)
  - ABI summary:
    . miral ABI unchanged at 2
  - Enhancements:
    . Compatibility with Mir 0.26 and update API to use the new Mir types and
      enums.
    . Logging of exceptions added to --window-management-trace
    . Rename WindowManagementPolicy::place_new_surface => place_new_window"
  - Bugs fixed:
    . top-level window is not raised along with its child (LP: #1658085)
    . miral-shell depends on default cursor theme being installed
      (LP: #1658159)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 * Authored by: Alan Griffiths <alan@octopull.co.uk>
17
17
 */
18
18
 
19
 
#ifndef MIRAL_TOOLKIT_SURFACE_SPEC_H
20
 
#define MIRAL_TOOLKIT_SURFACE_SPEC_H
 
19
#ifndef MIRAL_TOOLKIT_WINDOW_SPEC_H
 
20
#define MIRAL_TOOLKIT_WINDOW_SPEC_H
21
21
 
22
 
#include <miral/toolkit/surface.h>
 
22
#include <miral/toolkit/window.h>
 
23
#include <miral/detail/mir_forward_compatibility.h>
23
24
 
24
25
#include <mir_toolkit/mir_surface.h>
25
26
#include <mir_toolkit/mir_connection.h>
31
32
{
32
33
namespace toolkit
33
34
{
34
 
/// Handle class for MirSurfaceSpec - provides automatic reference counting, method chaining.
35
 
class SurfaceSpec
 
35
/// Handle class for MirWindowSpec - provides automatic reference counting, method chaining.
 
36
class WindowSpec
36
37
{
37
38
public:
38
 
    explicit SurfaceSpec(MirSurfaceSpec* spec) : self{spec, deleter} {}
 
39
    explicit WindowSpec(MirWindowSpec* spec) : self{spec, deleter} {}
39
40
 
40
 
    static auto for_normal_surface(MirConnection* connection, int width, int height, MirPixelFormat format) -> SurfaceSpec
 
41
    static auto for_normal_surface(MirConnection* connection, int width, int height, MirPixelFormat format) -> WindowSpec
41
42
    {
42
 
        return SurfaceSpec{mir_connection_create_spec_for_normal_surface(connection, width, height, format)};
 
43
#if MIR_CLIENT_VERSION <= MIR_VERSION_NUMBER(3, 4, 0)
 
44
        return WindowSpec{mir_connection_create_spec_for_normal_surface(connection, width, height, format)};
 
45
#else
 
46
        auto spec = WindowSpec{mir_create_normal_window_spec(connection, width, height)};
 
47
        mir_window_spec_set_pixel_format(spec, format);
 
48
        return spec;
 
49
#endif
43
50
    }
44
51
 
45
52
    static auto for_menu(MirConnection* connection,
46
53
                         int width,
47
54
                         int height,
48
55
                         MirPixelFormat format,
49
 
                         MirSurface* parent,
 
56
                         MirWindow* parent,
50
57
                         MirRectangle* rect,
51
 
                         MirEdgeAttachment edge) -> SurfaceSpec
 
58
                         MirEdgeAttachment edge) -> WindowSpec
52
59
    {
53
 
        return SurfaceSpec{mir_connection_create_spec_for_menu(connection, width, height, format, parent, rect, edge)};
 
60
#if MIR_CLIENT_VERSION <= MIR_VERSION_NUMBER(3, 4, 0)
 
61
        return WindowSpec{mir_connection_create_spec_for_menu(connection, width, height, format, parent, rect, edge)};
 
62
#else
 
63
        auto spec = WindowSpec{mir_create_menu_window_spec(connection, width, height, parent, rect, edge)};
 
64
        mir_window_spec_set_pixel_format(spec, format);
 
65
        return spec;
 
66
#endif
54
67
    }
55
68
 
56
69
#if MIR_CLIENT_VERSION >= MIR_VERSION_NUMBER(3, 4, 0)
58
71
                        int width,
59
72
                        int height,
60
73
                        MirPixelFormat format,
61
 
                        MirSurface* parent,
 
74
                        MirWindow* parent,
62
75
                        MirRectangle* rect,
63
 
                        MirEdgeAttachment edge) -> SurfaceSpec
 
76
                        MirEdgeAttachment edge) -> WindowSpec
64
77
    {
65
 
        return SurfaceSpec{mir_connection_create_spec_for_tip(connection, width, height, format, parent, rect, edge)};
 
78
#if MIR_CLIENT_VERSION <= MIR_VERSION_NUMBER(3, 4, 0)
 
79
        return WindowSpec{mir_connection_create_spec_for_tip(connection, width, height, format, parent, rect, edge)};
 
80
#else
 
81
        auto spec = WindowSpec{mir_create_tip_window_spec(connection, width, height, parent, rect, edge)};
 
82
        mir_window_spec_set_pixel_format(spec, format);
 
83
        return spec;
 
84
#endif
66
85
    }
67
86
#endif
68
87
 
69
88
    static auto for_dialog(MirConnection* connection,
70
89
                           int width,
71
90
                           int height,
72
 
                           MirPixelFormat format)-> SurfaceSpec
 
91
                           MirPixelFormat format)-> WindowSpec
73
92
    {
74
 
        return SurfaceSpec{mir_connection_create_spec_for_dialog(connection, width, height, format)};
 
93
#if MIR_CLIENT_VERSION <= MIR_VERSION_NUMBER(3, 4, 0)
 
94
        return WindowSpec{mir_connection_create_spec_for_dialog(connection, width, height, format)};
 
95
#else
 
96
        auto spec = WindowSpec{mir_create_dialog_window_spec(connection, width, height)};
 
97
        mir_window_spec_set_pixel_format(spec, format);
 
98
        return spec;
 
99
#endif
75
100
    }
76
101
 
77
102
    static auto for_dialog(MirConnection* connection,
78
103
                           int width,
79
104
                           int height,
80
105
                           MirPixelFormat format,
81
 
                           MirSurface* parent) -> SurfaceSpec
 
106
                           MirWindow* parent) -> WindowSpec
82
107
    {
83
108
        return for_dialog(connection, width, height, format).set_parent(parent);
84
109
    }
85
110
 
86
 
    static auto for_changes(MirConnection* connection) -> SurfaceSpec
 
111
    static auto for_changes(MirConnection* connection) -> WindowSpec
87
112
    {
88
 
        return SurfaceSpec{mir_connection_create_spec_for_changes(connection)};
 
113
#if MIR_CLIENT_VERSION <= MIR_VERSION_NUMBER(3, 4, 0)
 
114
        return WindowSpec{mir_connection_create_spec_for_changes(connection)};
 
115
#else
 
116
        return WindowSpec{mir_create_window_spec(connection)};
 
117
#endif
89
118
    }
90
119
 
91
 
    auto set_buffer_usage(MirBufferUsage usage) -> SurfaceSpec&
 
120
    auto set_buffer_usage(MirBufferUsage usage) -> WindowSpec&
92
121
    {
 
122
#if MIR_CLIENT_VERSION <= MIR_VERSION_NUMBER(3, 4, 0)
93
123
        mir_surface_spec_set_buffer_usage(*this, usage);
 
124
#else
 
125
        mir_window_spec_set_buffer_usage(*this, usage);
 
126
#endif
94
127
        return *this;
95
128
    }
96
129
 
97
 
    auto set_type(MirSurfaceType type) -> SurfaceSpec&
 
130
    auto set_type(MirWindowType type) -> WindowSpec&
98
131
    {
 
132
#if MIR_CLIENT_VERSION <= MIR_VERSION_NUMBER(3, 4, 0)
99
133
        mir_surface_spec_set_type(*this, type);
 
134
#else
 
135
        mir_window_spec_set_type(*this, type);
 
136
#endif
100
137
        return *this;
101
138
    }
102
139
 
103
 
    auto set_min_size(int min_width, int min_height) -> SurfaceSpec&
 
140
    auto set_min_size(int min_width, int min_height) -> WindowSpec&
104
141
    {
 
142
#if MIR_CLIENT_VERSION <= MIR_VERSION_NUMBER(3, 4, 0)
105
143
        mir_surface_spec_set_min_width(*this, min_width);
106
144
        mir_surface_spec_set_min_height(*this, min_height);
 
145
#else
 
146
        mir_window_spec_set_min_width(*this, min_width);
 
147
        mir_window_spec_set_min_height(*this, min_height);
 
148
#endif
107
149
        return *this;
108
150
    }
109
151
 
110
 
    auto set_max_size(int max_width, int max_height) -> SurfaceSpec&
 
152
    auto set_max_size(int max_width, int max_height) -> WindowSpec&
111
153
    {
 
154
#if MIR_CLIENT_VERSION <= MIR_VERSION_NUMBER(3, 4, 0)
112
155
        mir_surface_spec_set_max_width(*this, max_width);
113
156
        mir_surface_spec_set_max_height(*this, max_height);
 
157
#else
 
158
        mir_window_spec_set_max_width(*this, max_width);
 
159
        mir_window_spec_set_max_height(*this, max_height);
 
160
#endif
114
161
        return *this;
115
162
    }
116
163
 
117
 
    auto set_size_inc(int width_inc, int height_inc) -> SurfaceSpec&
 
164
    auto set_size_inc(int width_inc, int height_inc) -> WindowSpec&
118
165
    {
 
166
#if MIR_CLIENT_VERSION <= MIR_VERSION_NUMBER(3, 4, 0)
119
167
        mir_surface_spec_set_width_increment(*this, width_inc);
120
168
        mir_surface_spec_set_height_increment(*this, height_inc);
 
169
#else
 
170
        mir_window_spec_set_width_increment(*this, width_inc);
 
171
        mir_window_spec_set_height_increment(*this, height_inc);
 
172
#endif
121
173
        return *this;
122
174
    }
123
175
 
124
 
    auto set_size(int width, int height) -> SurfaceSpec&
 
176
    auto set_size(int width, int height) -> WindowSpec&
125
177
    {
 
178
#if MIR_CLIENT_VERSION <= MIR_VERSION_NUMBER(3, 4, 0)
126
179
        mir_surface_spec_set_width(*this, width);
127
180
        mir_surface_spec_set_height(*this, height);
 
181
#else
 
182
        mir_window_spec_set_width(*this, width);
 
183
        mir_window_spec_set_height(*this, height);
 
184
#endif
128
185
        return *this;
129
186
    }
130
187
 
131
 
    auto set_name(char const* name) -> SurfaceSpec&
 
188
    auto set_name(char const* name) -> WindowSpec&
132
189
    {
 
190
#if MIR_CLIENT_VERSION <= MIR_VERSION_NUMBER(3, 4, 0)
133
191
        mir_surface_spec_set_name(*this, name);
 
192
#else
 
193
        mir_window_spec_set_name(*this, name);
 
194
#endif
134
195
        return *this;
135
196
    }
136
197
 
137
 
    auto set_event_handler(mir_surface_event_callback callback, void* context) -> SurfaceSpec&
 
198
#if MIR_CLIENT_VERSION <= MIR_VERSION_NUMBER(3, 4, 0)
 
199
    auto set_event_handler(mir_surface_event_callback callback, void* context) -> WindowSpec&
138
200
    {
139
201
        mir_surface_spec_set_event_handler(*this, callback, context);
140
202
        return *this;
141
203
    }
 
204
#else
 
205
    auto set_event_handler(MirWindowEventCallback callback, void* context) -> WindowSpec&
 
206
    {
 
207
        mir_window_spec_set_event_handler(*this, callback, context);
 
208
        return *this;
 
209
    }
 
210
#endif
142
211
 
143
212
#if MIR_CLIENT_VERSION >= MIR_VERSION_NUMBER(3, 4, 0)
144
213
    auto set_placement(const MirRectangle* rect,
146
215
                       MirPlacementGravity surface_gravity,
147
216
                       MirPlacementHints   placement_hints,
148
217
                       int                 offset_dx,
149
 
                       int                 offset_dy) -> SurfaceSpec&
 
218
                       int                 offset_dy) -> WindowSpec&
150
219
    {
 
220
#if MIR_CLIENT_VERSION <= MIR_VERSION_NUMBER(3, 4, 0)
151
221
        mir_surface_spec_set_placement(*this, rect, rect_gravity, surface_gravity, placement_hints, offset_dx, offset_dy);
 
222
#else
 
223
        mir_window_spec_set_placement(*this, rect, rect_gravity, surface_gravity, placement_hints, offset_dx, offset_dy);
 
224
#endif
152
225
        return *this;
153
226
    }
154
227
#endif
155
228
 
156
 
    auto set_parent(MirSurface* parent) -> SurfaceSpec&
 
229
    auto set_parent(MirWindow* parent) -> WindowSpec&
157
230
    {
 
231
#if MIR_CLIENT_VERSION <= MIR_VERSION_NUMBER(3, 4, 0)
158
232
        mir_surface_spec_set_parent(*this, parent);
 
233
#else
 
234
        mir_window_spec_set_parent(*this, parent);
 
235
#endif
159
236
        return *this;
160
237
    }
161
238
 
162
239
    template<typename Context>
163
 
    void create_surface(void (*callback)(MirSurface*, Context*), Context* context) const
 
240
    void create_surface(void (*callback)(MirWindow*, Context*), Context* context) const
164
241
    {
 
242
#if MIR_CLIENT_VERSION <= MIR_VERSION_NUMBER(3, 4, 0)
165
243
        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
 
    {
 
244
#else
 
245
        mir_create_window(*this, reinterpret_cast<MirWindowCallback>(callback), context);
 
246
#endif
 
247
    }
 
248
 
 
249
    auto create_surface() const -> Window
 
250
    {
 
251
#if MIR_CLIENT_VERSION <= MIR_VERSION_NUMBER(3, 4, 0)
 
252
        return Window{mir_surface_create_sync(*this)};
 
253
#else
 
254
        return Window{mir_create_window_sync(*this)};
 
255
#endif
 
256
    }
 
257
 
 
258
    void apply_to(MirWindow* surface) const
 
259
    {
 
260
#if MIR_CLIENT_VERSION <= MIR_VERSION_NUMBER(3, 4, 0)
175
261
        mir_surface_apply_spec(surface, *this);
 
262
#else
 
263
        mir_window_apply_spec(surface, *this);
 
264
#endif
176
265
    }
177
266
 
178
 
    operator MirSurfaceSpec*() const { return self.get(); }
 
267
    operator MirWindowSpec*() const { return self.get(); }
179
268
 
180
269
private:
181
 
    static void deleter(MirSurfaceSpec* spec) { mir_surface_spec_release(spec); }
182
 
    std::shared_ptr<MirSurfaceSpec> self;
 
270
#if MIR_CLIENT_VERSION <= MIR_VERSION_NUMBER(3, 4, 0)
 
271
    static void deleter(MirWindowSpec* spec) { mir_surface_spec_release(spec); }
 
272
#else
 
273
    static void deleter(MirWindowSpec* spec) { mir_window_spec_release(spec); }
 
274
#endif
 
275
    std::shared_ptr<MirWindowSpec> self;
183
276
};
184
277
}
185
278
}
186
279
 
187
 
#endif //MIRAL_TOOLKIT_SURFACE_SPEC_H_H
 
280
#endif //MIRAL_TOOLKIT_WINDOW_SPEC_H_H