2
* Copyright (C) 2013 Canonical Ltd
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU Lesser General Public License version 3 as
6
* published by the Free Software Foundation.
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 Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Robert Carr <robert.carr@canonical.com>
19
#include <ubuntu/application/ui/ubuntu_application_ui.h>
20
#include <mir_toolkit/mir_client_library.h>
26
char const* const socket_file = "/tmp/mir_socket";
27
MirConnection *global_connection = NULL;
31
MirSurface *mir_surface;
32
input_event_cb ubuntu_input_cb;
34
} ubuntu_application_ui_mir_surface;
38
ubuntu_application_ui_init(int argc, char**argv)
40
if (global_connection)
42
global_connection = mir_connect_sync(socket_file, argc ? argv[0] : "");
43
assert(global_connection);
47
ubuntu_application_ui_setup_get_stage_hint()
49
// TODO: Implement ~racarr
50
return MAIN_STAGE_HINT;
54
ubuntu_application_ui_setup_get_form_factor_hint()
56
// TODO: Implement ~racarr
57
return DESKTOP_FORM_FACTOR_HINT;
61
ubuntu_application_ui_start_a_new_session(SessionCredentials* creds)
63
// TODO: Is this the correct place to call mir_connect_sync?
64
// It seems this is never called by QtUbuntu ~racarr
68
ubuntu_application_ui_get_native_display()
70
return static_cast<EGLNativeDisplayType>(mir_connection_get_egl_native_display(global_connection));
74
ubuntu_application_ui_set_clipboard_content(void* data, size_t size)
76
// TODO: Implement ~racarr
80
ubuntu_application_ui_get_clipboard_content(void** data, size_t* size)
84
// TODO: Implement ~racarr
88
ubuntu_application_ui_create_display_info(ubuntu_application_ui_physical_display_info* info, size_t index)
90
// TODO: Implement ~racarr
91
// Noop for mirclient?
95
ubuntu_application_ui_destroy_display_info(ubuntu_application_ui_physical_display_info info)
97
// TODO: Implement ~racarr
98
// Noop for mirclient?
102
ubuntu_application_ui_query_horizontal_resolution(ubuntu_application_ui_physical_display_info info)
104
MirDisplayInfo display_info;
106
assert(global_connection);
108
mir_connection_get_display_info(global_connection, &display_info);
109
return static_cast<int32_t>(display_info.width);
113
ubuntu_application_ui_query_vertical_resolution(ubuntu_application_ui_physical_display_info info)
115
MirDisplayInfo display_info;
117
assert(global_connection);
119
mir_connection_get_display_info(global_connection, &display_info);
120
return static_cast<int32_t>(display_info.height);
124
ubuntu_application_ui_query_horizontal_dpi(ubuntu_application_ui_physical_display_info info)
126
// TODO: Implement ~racarr
131
ubuntu_application_ui_query_vertical_dpi(ubuntu_application_ui_physical_display_info info)
133
// TODO: Implement ~racarr
141
mir_event_to_ubuntu_event(MirEvent const* mir_event, Event& ubuntu_ev)
143
switch (mir_event->type)
145
case mir_event_type_key:
146
ubuntu_ev.type = KEY_EVENT_TYPE;
147
ubuntu_ev.device_id = mir_event->key.device_id;
148
ubuntu_ev.source_id = mir_event->key.source_id;
149
ubuntu_ev.action = mir_event->key.action;
150
ubuntu_ev.flags = mir_event->key.flags;
151
ubuntu_ev.meta_state = mir_event->key.modifiers;
152
ubuntu_ev.details.key.key_code = mir_event->key.key_code;
153
ubuntu_ev.details.key.scan_code = mir_event->key.scan_code;
154
ubuntu_ev.details.key.repeat_count = mir_event->key.repeat_count;
155
ubuntu_ev.details.key.down_time = mir_event->key.down_time;
156
ubuntu_ev.details.key.event_time = mir_event->key.event_time;
157
ubuntu_ev.details.key.is_system_key = mir_event->key.is_system_key;
159
case mir_event_type_motion:
160
ubuntu_ev.type = MOTION_EVENT_TYPE;
161
ubuntu_ev.device_id = mir_event->motion.device_id;
162
ubuntu_ev.source_id = mir_event->motion.source_id;
163
ubuntu_ev.action = mir_event->motion.action;
164
ubuntu_ev.flags = mir_event->motion.flags;
165
ubuntu_ev.meta_state = mir_event->motion.modifiers;
166
ubuntu_ev.details.motion.edge_flags = mir_event->motion.edge_flags;
167
ubuntu_ev.details.motion.button_state = mir_event->motion.button_state;
168
ubuntu_ev.details.motion.x_offset = mir_event->motion.x_offset;
169
ubuntu_ev.details.motion.y_offset = mir_event->motion.y_offset;
170
ubuntu_ev.details.motion.x_precision = mir_event->motion.x_precision;
171
ubuntu_ev.details.motion.y_precision = mir_event->motion.y_precision;
172
ubuntu_ev.details.motion.down_time = mir_event->motion.down_time;
173
ubuntu_ev.details.motion.event_time = mir_event->motion.event_time;
174
ubuntu_ev.details.motion.pointer_count = mir_event->motion.pointer_count;
175
for (int i = 0; i < mir_event->motion.pointer_count; i++)
177
ubuntu_ev.details.motion.pointer_coordinates[i].id = mir_event->motion.pointer_coordinates[i].id;
178
ubuntu_ev.details.motion.pointer_coordinates[i].x = mir_event->motion.pointer_coordinates[i].x;
179
ubuntu_ev.details.motion.pointer_coordinates[i].raw_x = mir_event->motion.pointer_coordinates[i].raw_x;
180
ubuntu_ev.details.motion.pointer_coordinates[i].y = mir_event->motion.pointer_coordinates[i].y;
181
ubuntu_ev.details.motion.pointer_coordinates[i].raw_y = mir_event->motion.pointer_coordinates[i].raw_y;
182
ubuntu_ev.details.motion.pointer_coordinates[i].touch_major = mir_event->motion.pointer_coordinates[i].touch_major;
183
ubuntu_ev.details.motion.pointer_coordinates[i].touch_minor = mir_event->motion.pointer_coordinates[i].touch_minor;
184
ubuntu_ev.details.motion.pointer_coordinates[i].size = mir_event->motion.pointer_coordinates[i].size;
185
ubuntu_ev.details.motion.pointer_coordinates[i].pressure = mir_event->motion.pointer_coordinates[i].pressure;
186
ubuntu_ev.details.motion.pointer_coordinates[i].orientation = mir_event->motion.pointer_coordinates[i].orientation;
194
static void ubuntu_application_ui_mir_handle_event(MirSurface* mir_surface, MirEvent const* mir_ev, void* context)
196
ubuntu_application_ui_mir_surface *surface = static_cast<ubuntu_application_ui_mir_surface*>(context);
198
mir_event_to_ubuntu_event(mir_ev, ubuntu_ev);
199
surface->ubuntu_input_cb(surface->input_ctx, &ubuntu_ev);
204
ubuntu_application_ui_create_surface(ubuntu_application_ui_surface* out_surface,
213
assert(global_connection);
214
MirDisplayInfo display_info;
215
mir_connection_get_display_info(global_connection, &display_info);
216
MirSurfaceParameters params = { title, width, height, display_info.supported_pixel_format[0], mir_buffer_usage_hardware};
217
ubuntu_application_ui_mir_surface *surface = new ubuntu_application_ui_mir_surface;
218
surface->ubuntu_input_cb = cb;
219
surface->input_ctx = ctx;
220
MirEventDelegate event_delegate = { ubuntu_application_ui_mir_handle_event, surface };
221
surface->mir_surface = mir_connection_create_surface_sync(global_connection, ¶ms);
222
mir_surface_set_event_handler(surface->mir_surface, &event_delegate);
224
*out_surface = static_cast<ubuntu_application_ui_surface>(surface);
228
ubuntu_application_ui_request_fullscreen_for_surface(ubuntu_application_ui_surface surface)
230
// TODO: Implement ~racarr
234
ubuntu_application_ui_destroy_surface(ubuntu_application_ui_surface s)
236
ubuntu_application_ui_mir_surface *surface = static_cast<ubuntu_application_ui_mir_surface*>(s);
237
mir_surface_release_sync(surface->mir_surface);
242
ubuntu_application_ui_surface_to_native_window_type(ubuntu_application_ui_surface s)
244
ubuntu_application_ui_mir_surface *surface = static_cast<ubuntu_application_ui_mir_surface*>(s);
245
return reinterpret_cast<EGLNativeWindowType>(mir_surface_get_egl_native_window(surface->mir_surface));
249
ubuntu_application_ui_show_surface(ubuntu_application_ui_surface surface)
251
// TODO: Implement ~racarr
255
ubuntu_application_ui_hide_surface(ubuntu_application_ui_surface surface)
257
// TODO: Implement ~racarr
261
ubuntu_application_ui_move_surface_to(ubuntu_application_ui_surface surface,
264
// TODO: Implement ~racarr
268
ubuntu_application_ui_resize_surface_to(ubuntu_application_ui_surface surface,
271
// TODO: Implement ~racarr