20
20
#define MIR_CLIENT_WINDOW_SPEC_H
22
22
#include <mir/client/window.h>
23
#include <mir/client/detail/mir_forward_compatibility.h>
25
24
#include <mir_toolkit/mir_connection.h>
27
#if MIR_CLIENT_VERSION < MIR_VERSION_NUMBER(3, 5, 0)
28
#include <mir_toolkit/mir_surface.h>
30
25
#include <mir_toolkit/mir_window.h>
26
#include <mir_toolkit/version.h>
27
#include <mir_toolkit/rs/mir_render_surface.h>
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;
62
#if MIR_CLIENT_VERSION >= MIR_VERSION_NUMBER(3, 4, 0)
63
auto const mir_window_spec_set_placement = mir_surface_spec_set_placement;
75
39
explicit WindowSpec(MirWindowSpec* spec) : self{spec, deleter} {}
77
static auto for_normal_window(MirConnection* connection, int width, int height, MirPixelFormat format) -> WindowSpec
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)};
82
auto spec = WindowSpec{mir_create_normal_window_spec(connection, width, height)};
83
mir_window_spec_set_pixel_format(spec, format);
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
91
43
return WindowSpec{mir_create_normal_window_spec(connection, width, height)};
95
46
static auto for_menu(MirConnection* connection,
98
MirPixelFormat format,
100
50
MirRectangle* rect,
101
51
MirEdgeAttachment edge) -> WindowSpec
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)};
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);
112
57
static auto for_tip(MirConnection* connection,
115
MirPixelFormat format,
116
60
MirWindow* parent,
117
61
MirRectangle* rect,
118
62
MirEdgeAttachment edge) -> WindowSpec
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)};
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);
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)
136
.set_type(mir_window_type_tip);
140
68
static auto for_dialog(MirConnection* connection,
143
MirPixelFormat format)-> WindowSpec
70
int height)-> WindowSpec
145
#if MIR_CLIENT_VERSION < MIR_VERSION_NUMBER(3, 5, 0)
146
return WindowSpec{mir_connection_create_spec_for_dialog(connection, width, height, format)};
148
72
auto spec = WindowSpec{mir_create_dialog_window_spec(connection, width, height)};
149
mir_window_spec_set_pixel_format(spec, format);
154
76
static auto for_dialog(MirConnection* connection,
157
MirPixelFormat format,
158
79
MirWindow* parent) -> WindowSpec
160
return for_dialog(connection, width, height, format).set_parent(parent);
81
return for_dialog(connection, width, height).set_parent(parent);
163
84
static auto for_input_method(MirConnection* connection, int width, int height, MirWindow* parent)
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)}
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)
174
87
.set_parent(parent);
178
91
static auto for_satellite(MirConnection* connection, int width, int height, MirWindow* parent)
93
#if MIR_CLIENT_API_VERSION >= MIR_VERSION_NUMBER(0, 27, 0)
94
return WindowSpec{mir_create_satellite_window_spec(connection, width, height, parent)};
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);
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()
189
108
static auto for_gloss(MirConnection* connection, int width, int height)
110
#if MIR_CLIENT_API_VERSION >= MIR_VERSION_NUMBER(0, 27, 0)
111
return WindowSpec{mir_create_gloss_window_spec(connection, width, height)};
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);
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()
199
124
static auto for_changes(MirConnection* connection) -> WindowSpec