~mir-team/miral/release

« back to all changes in this revision

Viewing changes to include/mir/client/window_spec.h

  • Committer: Bileto Bot
  • Date: 2017-06-21 08:34:34 UTC
  • mfrom: (360.1.1 miral-release)
  • Revision ID: ci-train-bot@canonical.com-20170621083434-e7ftkyg5qr2fzsao
* New upstream release 1.4.0 (https://launchpad.net/miral/+milestone/1.4.0)
  - ABI summary:
    . miral ABI unchanged at 2
  - Enhancements:
    . Support for passing messages to enable Drag & Drop
    . Support for client requested move
    . Port to the undeprecated Mir APIs
    . Added "--cursor-theme" option when configuring a cursor theme
    . Drop support for Mir versions before 0.26
  - Bugs fixed:

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#define MIR_CLIENT_WINDOW_SPEC_H
21
21
 
22
22
#include <mir/client/window.h>
23
 
#include <mir/client/detail/mir_forward_compatibility.h>
24
23
 
25
24
#include <mir_toolkit/mir_connection.h>
26
 
 
27
 
#if MIR_CLIENT_VERSION < MIR_VERSION_NUMBER(3, 5, 0)
28
 
#include <mir_toolkit/mir_surface.h>
29
 
#else
30
25
#include <mir_toolkit/mir_window.h>
31
 
#endif
 
26
#include <mir_toolkit/version.h>
 
27
#include <mir_toolkit/rs/mir_render_surface.h>
32
28
 
33
29
#include <memory>
34
30
 
35
 
// Forward compatibility hacks for earlier Mir versions
36
 
#if MIR_CLIENT_VERSION < MIR_VERSION_NUMBER(3, 5, 0)
37
 
using MirWindowCallback = mir_surface_callback;
38
 
using MirWindowEventCallback = mir_surface_event_callback;
39
 
auto const mir_create_window_spec               = mir_connection_create_spec_for_changes;
40
 
auto const mir_window_spec_set_event_handler    = mir_surface_spec_set_event_handler;
41
 
auto const mir_window_spec_set_name             = mir_surface_spec_set_name;
42
 
auto const mir_window_spec_set_width            = mir_surface_spec_set_width;
43
 
auto const mir_window_spec_set_height           = mir_surface_spec_set_height;
44
 
auto const mir_window_spec_set_width_increment  = mir_surface_spec_set_width_increment;
45
 
auto const mir_window_spec_set_height_increment = mir_surface_spec_set_height_increment;
46
 
auto const mir_window_spec_set_buffer_usage     = mir_surface_spec_set_buffer_usage;
47
 
auto const mir_window_spec_set_pixel_format     = mir_surface_spec_set_pixel_format;
48
 
auto const mir_window_spec_set_type             = mir_surface_spec_set_type;
49
 
auto const mir_window_spec_set_shell_chrome     = mir_surface_spec_set_shell_chrome;
50
 
auto const mir_window_spec_set_min_width        = mir_surface_spec_set_min_width;
51
 
auto const mir_window_spec_set_min_height       = mir_surface_spec_set_min_height;
52
 
auto const mir_window_spec_set_max_width        = mir_surface_spec_set_max_width;
53
 
auto const mir_window_spec_set_max_height       = mir_surface_spec_set_max_height;
54
 
auto const mir_window_spec_set_parent           = mir_surface_spec_set_parent;
55
 
auto const mir_window_spec_set_state            = mir_surface_spec_set_state;
56
 
auto const mir_window_spec_set_fullscreen_on_output = mir_surface_spec_set_fullscreen_on_output;
57
 
auto const mir_create_window                    = mir_surface_create;
58
 
auto const mir_create_window_sync               = mir_surface_create_sync;
59
 
auto const mir_window_apply_spec                = mir_surface_apply_spec;
60
 
auto const mir_window_spec_release              = mir_surface_spec_release;
61
 
 
62
 
#if MIR_CLIENT_VERSION >= MIR_VERSION_NUMBER(3, 4, 0)
63
 
auto const mir_window_spec_set_placement        = mir_surface_spec_set_placement;
64
 
#endif
65
 
#endif
66
 
 
67
31
namespace mir
68
32
{
69
33
namespace client
74
38
public:
75
39
    explicit WindowSpec(MirWindowSpec* spec) : self{spec, deleter} {}
76
40
 
77
 
    static auto for_normal_window(MirConnection* connection, int width, int height, MirPixelFormat format) -> WindowSpec
78
 
    {
79
 
#if MIR_CLIENT_VERSION <= MIR_VERSION_NUMBER(3, 4, 0)
80
 
        return WindowSpec{mir_connection_create_spec_for_normal_surface(connection, width, height, format)};
81
 
#else
82
 
        auto spec = WindowSpec{mir_create_normal_window_spec(connection, width, height)};
83
 
        mir_window_spec_set_pixel_format(spec, format);
84
 
        return spec;
85
 
#endif
86
 
    }
87
 
 
88
 
#if MIR_CLIENT_VERSION > MIR_VERSION_NUMBER(3, 4, 0)
89
41
    static auto for_normal_window(MirConnection* connection, int width, int height) -> WindowSpec
90
42
    {
91
43
        return WindowSpec{mir_create_normal_window_spec(connection, width, height)};
92
44
    }
93
 
#endif
94
45
 
95
46
    static auto for_menu(MirConnection* connection,
96
47
                         int width,
97
48
                         int height,
98
 
                         MirPixelFormat format,
99
49
                         MirWindow* parent,
100
50
                         MirRectangle* rect,
101
51
                         MirEdgeAttachment edge) -> WindowSpec
102
52
    {
103
 
#if MIR_CLIENT_VERSION < MIR_VERSION_NUMBER(3, 5, 0)
104
 
        return WindowSpec{mir_connection_create_spec_for_menu(connection, width, height, format, parent, rect, edge)};
105
 
#else
106
53
        auto spec = WindowSpec{mir_create_menu_window_spec(connection, width, height, parent, rect, edge)};
107
 
        mir_window_spec_set_pixel_format(spec, format);
108
54
        return spec;
109
 
#endif
110
55
    }
111
56
 
112
57
    static auto for_tip(MirConnection* connection,
113
58
                        int width,
114
59
                        int height,
115
 
                        MirPixelFormat format,
116
60
                        MirWindow* parent,
117
61
                        MirRectangle* rect,
118
62
                        MirEdgeAttachment edge) -> WindowSpec
119
63
    {
120
 
#if MIR_CLIENT_VERSION >= MIR_VERSION_NUMBER(3, 4, 0)
121
 
#if MIR_CLIENT_VERSION < MIR_VERSION_NUMBER(3, 5, 0)
122
 
        return WindowSpec{mir_connection_create_spec_for_tip(connection, width, height, format, parent, rect, edge)};
123
 
#else
124
64
        auto spec = WindowSpec{mir_create_tip_window_spec(connection, width, height, parent, rect, edge)};
125
 
        mir_window_spec_set_pixel_format(spec, format);
126
65
        return spec;
127
 
#endif
128
 
#else
129
 
        (void)rect;
130
 
        (void)edge;
131
 
        return WindowSpec{mir_create_surface_spec(connection)}
132
 
            .set_buffer_usage(mir_buffer_usage_hardware) // Required protobuf field for create_window()
133
 
            .set_pixel_format(format)  // Required protobuf field for create_window()
134
 
            .set_size(width, height)
135
 
            .set_parent(parent)
136
 
            .set_type(mir_window_type_tip);
137
 
#endif
138
66
    }
139
67
 
140
68
    static auto for_dialog(MirConnection* connection,
141
69
                           int width,
142
 
                           int height,
143
 
                           MirPixelFormat format)-> WindowSpec
 
70
                           int height)-> WindowSpec
144
71
    {
145
 
#if MIR_CLIENT_VERSION < MIR_VERSION_NUMBER(3, 5, 0)
146
 
        return WindowSpec{mir_connection_create_spec_for_dialog(connection, width, height, format)};
147
 
#else
148
72
        auto spec = WindowSpec{mir_create_dialog_window_spec(connection, width, height)};
149
 
        mir_window_spec_set_pixel_format(spec, format);
150
73
        return spec;
151
 
#endif
152
74
    }
153
75
 
154
76
    static auto for_dialog(MirConnection* connection,
155
77
                           int width,
156
78
                           int height,
157
 
                           MirPixelFormat format,
158
79
                           MirWindow* parent) -> WindowSpec
159
80
    {
160
 
        return for_dialog(connection, width, height, format).set_parent(parent);
 
81
        return for_dialog(connection, width, height).set_parent(parent);
161
82
    }
162
83
 
163
84
    static auto for_input_method(MirConnection* connection, int width, int height, MirWindow* parent)
164
85
    {
165
 
#if MIR_CLIENT_VERSION >= MIR_VERSION_NUMBER(3, 5, 0)
166
86
        auto spec = WindowSpec{mir_create_input_method_window_spec(connection, width, height)}
167
 
#else
168
 
        auto spec = WindowSpec{mir_create_surface_spec(connection)}
169
 
            .set_buffer_usage(mir_buffer_usage_hardware) // Required protobuf field for create_window()
170
 
            .set_pixel_format(mir_pixel_format_invalid)  // Required protobuf field for create_window()
171
 
            .set_size(width, height)
172
 
            .set_type(mir_window_type_inputmethod)
173
 
#endif
174
87
            .set_parent(parent);
175
88
        return spec;
176
89
    }
177
90
 
178
91
    static auto for_satellite(MirConnection* connection, int width, int height, MirWindow* parent)
179
92
    {
 
93
#if MIR_CLIENT_API_VERSION >= MIR_VERSION_NUMBER(0, 27, 0)
 
94
        return WindowSpec{mir_create_satellite_window_spec(connection, width, height, parent)};
 
95
#else
180
96
        // There's no mir_create_satellite_window_spec()
181
 
        return WindowSpec{mir_create_window_spec(connection)}
182
 
            .set_buffer_usage(mir_buffer_usage_hardware) // Required protobuf field for create_window()
183
 
            .set_pixel_format(mir_pixel_format_invalid)  // Required protobuf field for create_window()
 
97
        auto spec = WindowSpec{mir_create_window_spec(connection)}
184
98
            .set_size(width, height)
185
99
            .set_type(mir_window_type_satellite)
186
100
            .set_parent(parent);
 
101
 
 
102
        mir_window_spec_set_buffer_usage(spec, mir_buffer_usage_hardware); // Required protobuf field for create_window()
 
103
        mir_window_spec_set_pixel_format(spec, mir_pixel_format_invalid);  // Required protobuf field for create_window()
 
104
        return spec;
 
105
#endif
187
106
    }
188
107
 
189
108
    static auto for_gloss(MirConnection* connection, int width, int height)
190
109
    {
 
110
#if MIR_CLIENT_API_VERSION >= MIR_VERSION_NUMBER(0, 27, 0)
 
111
        return WindowSpec{mir_create_gloss_window_spec(connection, width, height)};
 
112
#else
191
113
        // There's no mir_create_gloss_window_spec()
192
 
        return WindowSpec{mir_create_window_spec(connection)}
193
 
            .set_buffer_usage(mir_buffer_usage_hardware) // Required protobuf field for create_window()
194
 
            .set_pixel_format(mir_pixel_format_invalid)  // Required protobuf field for create_window()
 
114
        auto spec = WindowSpec{mir_create_window_spec(connection)}
195
115
            .set_size(width, height)
196
116
            .set_type(mir_window_type_gloss);
 
117
 
 
118
        mir_window_spec_set_buffer_usage(spec, mir_buffer_usage_hardware); // Required protobuf field for create_window()
 
119
        mir_window_spec_set_pixel_format(spec, mir_pixel_format_invalid);  // Required protobuf field for create_window()
 
120
        return spec;
 
121
#endif
197
122
    }
198
123
 
199
124
    static auto for_changes(MirConnection* connection) -> WindowSpec
201
126
        return WindowSpec{mir_create_window_spec(connection)};
202
127
    }
203
128
 
204
 
    auto set_buffer_usage(MirBufferUsage usage) -> WindowSpec&
205
 
    {
206
 
        mir_window_spec_set_buffer_usage(*this, usage);
207
 
        return *this;
208
 
    }
209
 
 
210
 
    auto set_pixel_format(MirPixelFormat format) -> WindowSpec&
211
 
    {
212
 
        mir_window_spec_set_pixel_format(*this, format);
213
 
        return *this;
214
 
    }
215
 
 
216
129
    auto set_type(MirWindowType type) -> WindowSpec&
217
130
    {
218
131
        mir_window_spec_set_type(*this, type);
271
184
        return *this;
272
185
    }
273
186
 
274
 
#if MIR_CLIENT_VERSION >= MIR_VERSION_NUMBER(3, 4, 0)
275
187
    auto set_placement(const MirRectangle* rect,
276
188
                       MirPlacementGravity rect_gravity,
277
189
                       MirPlacementGravity surface_gravity,
282
194
        mir_window_spec_set_placement(*this, rect, rect_gravity, surface_gravity, placement_hints, offset_dx, offset_dy);
283
195
        return *this;
284
196
    }
285
 
#else
286
 
    auto set_placement(const MirRectangle* /*rect*/,
287
 
                       MirPlacementGravity /*rect_gravity*/,
288
 
                       MirPlacementGravity /*surface_gravity*/,
289
 
                       MirPlacementHints   /*placement_hints*/,
290
 
                       int                 /*offset_dx*/,
291
 
                       int                 /*offset_dy*/) -> WindowSpec&
292
 
    {
293
 
        return *this;
294
 
    }
295
 
#endif
296
197
 
297
198
    auto set_parent(MirWindow* parent) -> WindowSpec&
298
199
    {
306
207
        return *this;
307
208
    }
308
209
 
 
210
    auto add_surface(MirRenderSurface* surface, int width, int height, int displacement_x, int displacement_y)
 
211
    -> WindowSpec&
 
212
    {
 
213
#if MIR_CLIENT_API_VERSION < MIR_VERSION_NUMBER(0, 27, 0)
 
214
#pragma GCC diagnostic push
 
215
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
 
216
#endif
 
217
        mir_window_spec_add_render_surface(*this, surface, width, height, displacement_x, displacement_y);
 
218
#if MIR_CLIENT_API_VERSION < MIR_VERSION_NUMBER(0, 27, 0)
 
219
#pragma GCC diagnostic pop
 
220
#endif
 
221
        return *this;
 
222
    }
 
223
 
309
224
    template<typename Context>
310
225
    void create_window(void (* callback)(MirWindow*, Context*), Context* context) const
311
226
    {