~unity-team/platform-api/mir-support

« back to all changes in this revision

Viewing changes to src/mirclient/ubuntu_application_api_mirclient.cpp

  • Committer: Robert Carr
  • Date: 2013-05-13 18:38:18 UTC
  • Revision ID: robert.carr@canonical.com-20130513183818-edg24bzsllyy0opu
Import mirclient impl

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 Canonical Ltd
 
3
 *
 
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.
 
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 Lesser General Public License for more details.
 
12
 *
 
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/>.
 
15
 *
 
16
 * Authored by: Robert Carr <robert.carr@canonical.com>
 
17
 */
 
18
 
 
19
#include <ubuntu/application/ui/ubuntu_application_ui.h>
 
20
#include <mir_toolkit/mir_client_library.h>
 
21
 
 
22
#include <assert.h>
 
23
 
 
24
namespace
 
25
{
 
26
    char const* const socket_file = "/tmp/mir_socket";
 
27
    MirConnection *global_connection = NULL;
 
28
}
 
29
 
 
30
typedef struct {
 
31
    MirSurface *mir_surface;
 
32
    input_event_cb ubuntu_input_cb;
 
33
    void *input_ctx;
 
34
} ubuntu_application_ui_mir_surface;
 
35
 
 
36
    
 
37
void
 
38
ubuntu_application_ui_init(int argc, char**argv)
 
39
{
 
40
    if (global_connection)
 
41
        return;
 
42
    global_connection = mir_connect_sync(socket_file, argc ? argv[0] : "");
 
43
    assert(global_connection);
 
44
}
 
45
 
 
46
StageHint
 
47
ubuntu_application_ui_setup_get_stage_hint()
 
48
{
 
49
    // TODO: Implement ~racarr
 
50
    return MAIN_STAGE_HINT;
 
51
}
 
52
 
 
53
FormFactorHint
 
54
ubuntu_application_ui_setup_get_form_factor_hint()
 
55
{
 
56
    // TODO: Implement ~racarr
 
57
    return DESKTOP_FORM_FACTOR_HINT;
 
58
}
 
59
 
 
60
void
 
61
ubuntu_application_ui_start_a_new_session(SessionCredentials* creds)
 
62
{
 
63
    // TODO: Is this the correct place to call mir_connect_sync?
 
64
    // It seems this is never called by QtUbuntu ~racarr
 
65
}
 
66
 
 
67
EGLNativeDisplayType
 
68
ubuntu_application_ui_get_native_display()
 
69
{
 
70
    return static_cast<EGLNativeDisplayType>(mir_connection_get_egl_native_display(global_connection));
 
71
}
 
72
 
 
73
void
 
74
ubuntu_application_ui_set_clipboard_content(void* data, size_t size)
 
75
{
 
76
    // TODO: Implement ~racarr
 
77
}
 
78
 
 
79
void
 
80
ubuntu_application_ui_get_clipboard_content(void** data, size_t* size)
 
81
{
 
82
    *size = 0;
 
83
    *data = NULL;
 
84
    // TODO: Implement ~racarr
 
85
}
 
86
 
 
87
void
 
88
ubuntu_application_ui_create_display_info(ubuntu_application_ui_physical_display_info* info, size_t index)
 
89
{
 
90
    // TODO: Implement ~racarr
 
91
    // Noop for mirclient?
 
92
}
 
93
 
 
94
void
 
95
ubuntu_application_ui_destroy_display_info(ubuntu_application_ui_physical_display_info info)
 
96
{
 
97
    // TODO: Implement ~racarr
 
98
    // Noop for mirclient?
 
99
}
 
100
 
 
101
int32_t
 
102
ubuntu_application_ui_query_horizontal_resolution(ubuntu_application_ui_physical_display_info info)
 
103
{
 
104
    MirDisplayInfo display_info;
 
105
 
 
106
    assert(global_connection);
 
107
 
 
108
    mir_connection_get_display_info(global_connection, &display_info);
 
109
    return static_cast<int32_t>(display_info.width);
 
110
}
 
111
 
 
112
int32_t
 
113
ubuntu_application_ui_query_vertical_resolution(ubuntu_application_ui_physical_display_info info)
 
114
{
 
115
    MirDisplayInfo display_info;
 
116
    
 
117
    assert(global_connection);
 
118
 
 
119
    mir_connection_get_display_info(global_connection, &display_info);
 
120
    return static_cast<int32_t>(display_info.height);
 
121
}
 
122
 
 
123
float
 
124
ubuntu_application_ui_query_horizontal_dpi(ubuntu_application_ui_physical_display_info info)
 
125
{
 
126
    // TODO: Implement ~racarr
 
127
    return (float)0.0;
 
128
}
 
129
 
 
130
float
 
131
ubuntu_application_ui_query_vertical_dpi(ubuntu_application_ui_physical_display_info info)
 
132
{
 
133
    // TODO: Implement ~racarr
 
134
    return (float)0.0;
 
135
}
 
136
 
 
137
namespace
 
138
{
 
139
 
 
140
static void
 
141
mir_event_to_ubuntu_event(MirEvent const* mir_event, Event& ubuntu_ev)
 
142
{
 
143
    switch (mir_event->type)
 
144
    {
 
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;
 
158
        break;
 
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++)
 
176
        {
 
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;
 
187
        }
 
188
        break;
 
189
    default:
 
190
        break;
 
191
    }
 
192
}
 
193
 
 
194
static void ubuntu_application_ui_mir_handle_event(MirSurface* mir_surface, MirEvent const* mir_ev, void* context)
 
195
{
 
196
    ubuntu_application_ui_mir_surface *surface = static_cast<ubuntu_application_ui_mir_surface*>(context);
 
197
    Event ubuntu_ev;
 
198
    mir_event_to_ubuntu_event(mir_ev, ubuntu_ev);
 
199
    surface->ubuntu_input_cb(surface->input_ctx, &ubuntu_ev);
 
200
}
 
201
}
 
202
 
 
203
void
 
204
ubuntu_application_ui_create_surface(ubuntu_application_ui_surface* out_surface,
 
205
                                     const char* title,
 
206
                                     int width,
 
207
                                     int height,
 
208
                                     SurfaceRole role,
 
209
                                     uint32_t flags,
 
210
                                     input_event_cb cb,
 
211
                                     void* ctx)
 
212
{
 
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, &params);
 
222
    mir_surface_set_event_handler(surface->mir_surface, &event_delegate);
 
223
    assert(surface);
 
224
    *out_surface = static_cast<ubuntu_application_ui_surface>(surface);
 
225
}
 
226
 
 
227
void
 
228
ubuntu_application_ui_request_fullscreen_for_surface(ubuntu_application_ui_surface surface)
 
229
{
 
230
    // TODO: Implement ~racarr
 
231
}
 
232
 
 
233
void
 
234
ubuntu_application_ui_destroy_surface(ubuntu_application_ui_surface s)
 
235
{
 
236
    ubuntu_application_ui_mir_surface *surface = static_cast<ubuntu_application_ui_mir_surface*>(s);
 
237
    mir_surface_release_sync(surface->mir_surface);
 
238
    delete surface;
 
239
}
 
240
 
 
241
EGLNativeWindowType
 
242
ubuntu_application_ui_surface_to_native_window_type(ubuntu_application_ui_surface s)
 
243
{
 
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));
 
246
}
 
247
 
 
248
void
 
249
ubuntu_application_ui_show_surface(ubuntu_application_ui_surface surface)
 
250
{
 
251
    // TODO: Implement ~racarr
 
252
}
 
253
 
 
254
void
 
255
ubuntu_application_ui_hide_surface(ubuntu_application_ui_surface surface)
 
256
{
 
257
    // TODO: Implement ~racarr
 
258
}
 
259
 
 
260
void
 
261
ubuntu_application_ui_move_surface_to(ubuntu_application_ui_surface surface,
 
262
                                      int x, int y)
 
263
{
 
264
    // TODO: Implement ~racarr
 
265
}
 
266
 
 
267
void
 
268
ubuntu_application_ui_resize_surface_to(ubuntu_application_ui_surface surface,
 
269
                                        int w, int h)
 
270
{
 
271
    // TODO: Implement ~racarr
 
272
}