downstream: Multiseat support for drm/wayland backends
[profile/ivi/weston-ivi-shell.git] / src / compositor-rdp.c
1 /*
2  * Copyright © 2013 Hardening <rdp.effort@gmail.com>
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and
5  * its documentation for any purpose is hereby granted without fee, provided
6  * that the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation, and that the name of the copyright holders not be used in
9  * advertising or publicity pertaining to distribution of the software
10  * without specific, written prior permission.  The copyright holders make
11  * no representations about the suitability of this software for any
12  * purpose.  It is provided "as is" without express or implied warranty.
13  *
14  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16  * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17  * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19  * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21  */
22
23 #include "config.h"
24
25 #include <stdlib.h>
26 #include <string.h>
27 #include <errno.h>
28 #include <linux/input.h>
29
30 #if HAVE_FREERDP_VERSION_H
31 #include <freerdp/version.h>
32 #else
33 /* assume it's a early 1.1 version */
34 #define FREERDP_VERSION_MAJOR 1
35 #define FREERDP_VERSION_MINOR 1
36 #endif
37
38 #include <freerdp/freerdp.h>
39 #include <freerdp/listener.h>
40 #include <freerdp/update.h>
41 #include <freerdp/input.h>
42 #include <freerdp/codec/color.h>
43 #include <freerdp/codec/rfx.h>
44 #include <freerdp/codec/nsc.h>
45 #include <freerdp/locale/keyboard.h>
46 #include <winpr/input.h>
47
48 #include "compositor.h"
49 #include "../shared/str-util.h"
50 #include "pixman-renderer.h"
51
52 #define MAX_FREERDP_FDS 32
53 #define DEFAULT_AXIS_STEP_DISTANCE wl_fixed_from_int(10)
54 #define RDP_MODE_FREQ 60 * 1000
55
56 struct rdp_compositor_config {
57         int width;
58         int height;
59         char *bind_address;
60         int port;
61         char *rdp_key;
62         char *server_cert;
63         char *server_key;
64         int env_socket;
65         int no_clients_resize;
66 };
67
68 struct rdp_output;
69
70 struct rdp_compositor {
71         struct weston_compositor base;
72
73         freerdp_listener *listener;
74         struct wl_event_source *listener_events[MAX_FREERDP_FDS];
75         struct rdp_output *output;
76
77         char *server_cert;
78         char *server_key;
79         char *rdp_key;
80         int tls_enabled;
81         int no_clients_resize;
82 };
83
84 enum peer_item_flags {
85         RDP_PEER_ACTIVATED      = (1 << 0),
86         RDP_PEER_OUTPUT_ENABLED = (1 << 1),
87 };
88
89 struct rdp_peers_item {
90         int flags;
91         freerdp_peer *peer;
92         struct weston_seat seat;
93
94         struct wl_list link;
95 };
96
97 struct rdp_output {
98         struct weston_output base;
99         struct wl_event_source *finish_frame_timer;
100         pixman_image_t *shadow_surface;
101
102         struct wl_list peers;
103 };
104
105 struct rdp_peer_context {
106         rdpContext _p;
107
108         struct rdp_compositor *rdpCompositor;
109         struct wl_event_source *events[MAX_FREERDP_FDS];
110         RFX_CONTEXT *rfx_context;
111         wStream *encode_stream;
112         RFX_RECT *rfx_rects;
113         NSC_CONTEXT *nsc_context;
114
115         struct rdp_peers_item item;
116 };
117 typedef struct rdp_peer_context RdpPeerContext;
118
119 static void
120 rdp_compositor_config_init(struct rdp_compositor_config *config) {
121         config->width = 640;
122         config->height = 480;
123         config->bind_address = NULL;
124         config->port = 3389;
125         config->rdp_key = NULL;
126         config->server_cert = NULL;
127         config->server_key = NULL;
128         config->env_socket = 0;
129         config->no_clients_resize = 0;
130 }
131
132 static void
133 rdp_peer_refresh_rfx(pixman_region32_t *damage, pixman_image_t *image, freerdp_peer *peer)
134 {
135         int width, height, nrects, i;
136         pixman_box32_t *region, *rects;
137         uint32_t *ptr;
138         RFX_RECT *rfxRect;
139         rdpUpdate *update = peer->update;
140         SURFACE_BITS_COMMAND *cmd = &update->surface_bits_command;
141         RdpPeerContext *context = (RdpPeerContext *)peer->context;
142
143         Stream_Clear(context->encode_stream);
144         Stream_SetPosition(context->encode_stream, 0);
145
146         width = (damage->extents.x2 - damage->extents.x1);
147         height = (damage->extents.y2 - damage->extents.y1);
148
149         cmd->destLeft = damage->extents.x1;
150         cmd->destTop = damage->extents.y1;
151         cmd->destRight = damage->extents.x2;
152         cmd->destBottom = damage->extents.y2;
153         cmd->bpp = 32;
154         cmd->codecID = peer->settings->RemoteFxCodecId;
155         cmd->width = width;
156         cmd->height = height;
157
158         ptr = pixman_image_get_data(image) + damage->extents.x1 +
159                                 damage->extents.y1 * (pixman_image_get_stride(image) / sizeof(uint32_t));
160
161         rects = pixman_region32_rectangles(damage, &nrects);
162         context->rfx_rects = realloc(context->rfx_rects, nrects * sizeof *rfxRect);
163
164         for (i = 0; i < nrects; i++) {
165                 region = &rects[i];
166                 rfxRect = &context->rfx_rects[i];
167
168                 rfxRect->x = (region->x1 - damage->extents.x1);
169                 rfxRect->y = (region->y1 - damage->extents.y1);
170                 rfxRect->width = (region->x2 - region->x1);
171                 rfxRect->height = (region->y2 - region->y1);
172         }
173
174         rfx_compose_message(context->rfx_context, context->encode_stream, context->rfx_rects, nrects,
175                         (BYTE *)ptr, width, height,
176                         pixman_image_get_stride(image)
177         );
178
179         cmd->bitmapDataLength = Stream_GetPosition(context->encode_stream);
180         cmd->bitmapData = Stream_Buffer(context->encode_stream);
181
182         update->SurfaceBits(update->context, cmd);
183 }
184
185
186 static void
187 rdp_peer_refresh_nsc(pixman_region32_t *damage, pixman_image_t *image, freerdp_peer *peer)
188 {
189         int width, height;
190         uint32_t *ptr;
191         rdpUpdate *update = peer->update;
192         SURFACE_BITS_COMMAND *cmd = &update->surface_bits_command;
193         RdpPeerContext *context = (RdpPeerContext *)peer->context;
194
195         Stream_Clear(context->encode_stream);
196         Stream_SetPosition(context->encode_stream, 0);
197
198         width = (damage->extents.x2 - damage->extents.x1);
199         height = (damage->extents.y2 - damage->extents.y1);
200
201         cmd->destLeft = damage->extents.x1;
202         cmd->destTop = damage->extents.y1;
203         cmd->destRight = damage->extents.x2;
204         cmd->destBottom = damage->extents.y2;
205         cmd->bpp = 32;
206         cmd->codecID = peer->settings->NSCodecId;
207         cmd->width = width;
208         cmd->height = height;
209
210         ptr = pixman_image_get_data(image) + damage->extents.x1 +
211                                 damage->extents.y1 * (pixman_image_get_stride(image) / sizeof(uint32_t));
212
213         nsc_compose_message(context->nsc_context, context->encode_stream, (BYTE *)ptr,
214                         cmd->width,     cmd->height,
215                         pixman_image_get_stride(image));
216         cmd->bitmapDataLength = Stream_GetPosition(context->encode_stream);
217         cmd->bitmapData = Stream_Buffer(context->encode_stream);
218         update->SurfaceBits(update->context, cmd);
219 }
220
221 static void
222 pixman_image_flipped_subrect(const pixman_box32_t *rect, pixman_image_t *img, BYTE *dest) {
223         int stride = pixman_image_get_stride(img);
224         int h;
225         int toCopy = (rect->x2 - rect->x1) * 4;
226         int height = (rect->y2 - rect->y1);
227         const BYTE *src = (const BYTE *)pixman_image_get_data(img);
228         src += ((rect->y2-1) * stride) + (rect->x1 * 4);
229
230         for (h = 0; h < height; h++, src -= stride, dest += toCopy)
231                    memcpy(dest, src, toCopy);
232 }
233
234 static void
235 rdp_peer_refresh_raw(pixman_region32_t *region, pixman_image_t *image, freerdp_peer *peer)
236 {
237         rdpUpdate *update = peer->update;
238         SURFACE_BITS_COMMAND *cmd = &update->surface_bits_command;
239         SURFACE_FRAME_MARKER *marker = &update->surface_frame_marker;
240         pixman_box32_t *rect, subrect;
241         int nrects, i;
242         int heightIncrement, remainingHeight, top;
243
244         rect = pixman_region32_rectangles(region, &nrects);
245         if (!nrects)
246                 return;
247
248         marker->frameId++;
249         marker->frameAction = SURFACECMD_FRAMEACTION_BEGIN;
250         update->SurfaceFrameMarker(peer->context, marker);
251
252         cmd->bpp = 32;
253         cmd->codecID = 0;
254
255         for (i = 0; i < nrects; i++, rect++) {
256                 /*weston_log("rect(%d,%d, %d,%d)\n", rect->x1, rect->y1, rect->x2, rect->y2);*/
257                 cmd->destLeft = rect->x1;
258                 cmd->destRight = rect->x2;
259                 cmd->width = rect->x2 - rect->x1;
260
261                 heightIncrement = peer->settings->MultifragMaxRequestSize / (16 + cmd->width * 4);
262                 remainingHeight = rect->y2 - rect->y1;
263                 top = rect->y1;
264
265                 subrect.x1 = rect->x1;
266                 subrect.x2 = rect->x2;
267
268                 while (remainingHeight) {
269                            cmd->height = (remainingHeight > heightIncrement) ? heightIncrement : remainingHeight;
270                            cmd->destTop = top;
271                            cmd->destBottom = top + cmd->height;
272                            cmd->bitmapDataLength = cmd->width * cmd->height * 4;
273                            cmd->bitmapData = (BYTE *)realloc(cmd->bitmapData, cmd->bitmapDataLength);
274
275                            subrect.y1 = top;
276                            subrect.y2 = top + cmd->height;
277                            pixman_image_flipped_subrect(&subrect, image, cmd->bitmapData);
278
279                            /*weston_log("*  sending (%d,%d, %d,%d)\n", subrect.x1, subrect.y1, subrect.x2, subrect.y2); */
280                            update->SurfaceBits(peer->context, cmd);
281
282                            remainingHeight -= cmd->height;
283                            top += cmd->height;
284                 }
285         }
286
287         marker->frameAction = SURFACECMD_FRAMEACTION_END;
288         update->SurfaceFrameMarker(peer->context, marker);
289 }
290
291 static void
292 rdp_peer_refresh_region(pixman_region32_t *region, freerdp_peer *peer)
293 {
294         RdpPeerContext *context = (RdpPeerContext *)peer->context;
295         struct rdp_output *output = context->rdpCompositor->output;
296         rdpSettings *settings = peer->settings;
297
298         if (settings->RemoteFxCodec)
299                 rdp_peer_refresh_rfx(region, output->shadow_surface, peer);
300         else if (settings->NSCodec)
301                 rdp_peer_refresh_nsc(region, output->shadow_surface, peer);
302         else
303                 rdp_peer_refresh_raw(region, output->shadow_surface, peer);
304 }
305
306 static void
307 rdp_output_start_repaint_loop(struct weston_output *output)
308 {
309         uint32_t msec;
310         struct timeval tv;
311
312         gettimeofday(&tv, NULL);
313         msec = tv.tv_sec * 1000 + tv.tv_usec / 1000;
314         weston_output_finish_frame(output, msec);
315 }
316
317 static int
318 rdp_output_repaint(struct weston_output *output_base, pixman_region32_t *damage)
319 {
320         struct rdp_output *output = container_of(output_base, struct rdp_output, base);
321         struct weston_compositor *ec = output->base.compositor;
322         struct rdp_peers_item *outputPeer;
323
324         pixman_renderer_output_set_buffer(output_base, output->shadow_surface);
325         ec->renderer->repaint_output(&output->base, damage);
326
327         if (pixman_region32_not_empty(damage)) {
328                 wl_list_for_each(outputPeer, &output->peers, link) {
329                         if ((outputPeer->flags & RDP_PEER_ACTIVATED) &&
330                                         (outputPeer->flags & RDP_PEER_OUTPUT_ENABLED))
331                         {
332                                 rdp_peer_refresh_region(damage, outputPeer->peer);
333                         }
334                 }
335         }
336
337         pixman_region32_subtract(&ec->primary_plane.damage,
338                                  &ec->primary_plane.damage, damage);
339
340         wl_event_source_timer_update(output->finish_frame_timer, 16);
341         return 0;
342 }
343
344 static void
345 rdp_output_destroy(struct weston_output *output_base)
346 {
347         struct rdp_output *output = (struct rdp_output *)output_base;
348
349         wl_event_source_remove(output->finish_frame_timer);
350         free(output);
351 }
352
353 static int
354 finish_frame_handler(void *data)
355 {
356         rdp_output_start_repaint_loop(data);
357
358         return 1;
359 }
360
361 static struct weston_mode *
362 rdp_insert_new_mode(struct weston_output *output, int width, int height, int rate) {
363         struct weston_mode *ret;
364         ret = zalloc(sizeof *ret);
365         if (!ret)
366                 return NULL;
367         ret->width = width;
368         ret->height = height;
369         ret->refresh = rate;
370         wl_list_insert(&output->mode_list, &ret->link);
371         return ret;
372 }
373
374 static struct weston_mode *
375 ensure_matching_mode(struct weston_output *output, struct weston_mode *target) {
376         struct weston_mode *local;
377
378         wl_list_for_each(local, &output->mode_list, link) {
379                 if ((local->width == target->width) && (local->height == target->height))
380                         return local;
381         }
382
383         return rdp_insert_new_mode(output, target->width, target->height, RDP_MODE_FREQ);
384 }
385
386 static int
387 rdp_switch_mode(struct weston_output *output, struct weston_mode *target_mode) {
388         struct rdp_output *rdpOutput = container_of(output, struct rdp_output, base);
389         struct rdp_peers_item *rdpPeer;
390         rdpSettings *settings;
391         pixman_image_t *new_shadow_buffer;
392         struct weston_mode *local_mode;
393
394         local_mode = ensure_matching_mode(output, target_mode);
395         if (!local_mode) {
396                 weston_log("mode %dx%d not available\n", target_mode->width, target_mode->height);
397                 return -ENOENT;
398         }
399
400         if (local_mode == output->current_mode)
401                 return 0;
402
403         output->current_mode->flags &= ~WL_OUTPUT_MODE_CURRENT;
404
405         output->current_mode = local_mode;
406         output->current_mode->flags |= WL_OUTPUT_MODE_CURRENT;
407
408         pixman_renderer_output_destroy(output);
409         pixman_renderer_output_create(output);
410
411         new_shadow_buffer = pixman_image_create_bits(PIXMAN_x8r8g8b8, target_mode->width,
412                         target_mode->height, 0, target_mode->width * 4);
413         pixman_image_composite32(PIXMAN_OP_SRC, rdpOutput->shadow_surface, 0, new_shadow_buffer,
414                         0, 0, 0, 0, 0, 0, target_mode->width, target_mode->height);
415         pixman_image_unref(rdpOutput->shadow_surface);
416         rdpOutput->shadow_surface = new_shadow_buffer;
417
418         wl_list_for_each(rdpPeer, &rdpOutput->peers, link) {
419                 settings = rdpPeer->peer->settings;
420                 if (settings->DesktopWidth == (UINT32)target_mode->width &&
421                                 settings->DesktopHeight == (UINT32)target_mode->height)
422                         continue;
423
424                 if (!settings->DesktopResize) {
425                         /* too bad this peer does not support desktop resize */
426                         rdpPeer->peer->Close(rdpPeer->peer);
427                 } else {
428                         settings->DesktopWidth = target_mode->width;
429                         settings->DesktopHeight = target_mode->height;
430                         rdpPeer->peer->update->DesktopResize(rdpPeer->peer->context);
431                 }
432         }
433         return 0;
434 }
435
436 static int
437 rdp_compositor_create_output(struct rdp_compositor *c, int width, int height)
438 {
439         struct rdp_output *output;
440         struct wl_event_loop *loop;
441         struct weston_mode *currentMode;
442         struct weston_mode initMode;
443
444         output = zalloc(sizeof *output);
445         if (output == NULL)
446                 return -1;
447
448         wl_list_init(&output->peers);
449         wl_list_init(&output->base.mode_list);
450
451         initMode.flags = WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
452         initMode.width = width;
453         initMode.height = height;
454         initMode.refresh = RDP_MODE_FREQ;
455
456         currentMode = ensure_matching_mode(&output->base, &initMode);
457         if (!currentMode)
458                 goto out_free_output;
459
460         output->base.current_mode = output->base.native_mode = currentMode;
461         weston_output_init(&output->base, &c->base, 0, 0, width, height,
462                            WL_OUTPUT_TRANSFORM_NORMAL, 1);
463
464         output->base.make = "weston";
465         output->base.model = "rdp";
466         output->shadow_surface = pixman_image_create_bits(PIXMAN_x8r8g8b8,
467                         width, height,
468                     NULL,
469                     width * 4);
470         if (output->shadow_surface == NULL) {
471                 weston_log("Failed to create surface for frame buffer.\n");
472                 goto out_output;
473         }
474
475         if (pixman_renderer_output_create(&output->base) < 0)
476                 goto out_shadow_surface;
477
478         loop = wl_display_get_event_loop(c->base.wl_display);
479         output->finish_frame_timer = wl_event_loop_add_timer(loop, finish_frame_handler, output);
480
481         output->base.start_repaint_loop = rdp_output_start_repaint_loop;
482         output->base.repaint = rdp_output_repaint;
483         output->base.destroy = rdp_output_destroy;
484         output->base.assign_planes = NULL;
485         output->base.set_backlight = NULL;
486         output->base.set_dpms = NULL;
487         output->base.switch_mode = rdp_switch_mode;
488         c->output = output;
489
490         wl_list_insert(c->base.output_list.prev, &output->base.link);
491         return 0;
492
493 out_shadow_surface:
494         pixman_image_unref(output->shadow_surface);
495 out_output:
496         weston_output_destroy(&output->base);
497 out_free_output:
498         free(output);
499         return -1;
500 }
501
502 static void
503 rdp_restore(struct weston_compositor *ec)
504 {
505 }
506
507 static void
508 rdp_destroy(struct weston_compositor *ec)
509 {
510         weston_compositor_shutdown(ec);
511
512         free(ec);
513 }
514
515 static
516 int rdp_listener_activity(int fd, uint32_t mask, void *data) {
517         freerdp_listener* instance = (freerdp_listener *)data;
518
519         if (!(mask & WL_EVENT_READABLE))
520                 return 0;
521         if (!instance->CheckFileDescriptor(instance))
522         {
523                 weston_log("failed to check FreeRDP file descriptor\n");
524                 return -1;
525         }
526         return 0;
527 }
528
529 static
530 int rdp_implant_listener(struct rdp_compositor *c, freerdp_listener* instance) {
531         int i, fd;
532         int rcount = 0;
533         void* rfds[MAX_FREERDP_FDS];
534         struct wl_event_loop *loop;
535
536         if (!instance->GetFileDescriptor(instance, rfds, &rcount)) {
537                 weston_log("Failed to get FreeRDP file descriptor\n");
538                 return -1;
539         }
540
541         loop = wl_display_get_event_loop(c->base.wl_display);
542         for (i = 0; i < rcount; i++) {
543                 fd = (int)(long)(rfds[i]);
544                 c->listener_events[i] = wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE,
545                                 rdp_listener_activity, instance);
546         }
547
548         for( ; i < MAX_FREERDP_FDS; i++)
549                 c->listener_events[i] = 0;
550         return 0;
551 }
552
553
554 static void
555 rdp_peer_context_new(freerdp_peer* client, RdpPeerContext* context)
556 {
557         context->item.peer = client;
558         context->item.flags = RDP_PEER_OUTPUT_ENABLED;
559
560 #if FREERDP_VERSION_MAJOR == 1 && FREERDP_VERSION_MINOR == 1
561         context->rfx_context = rfx_context_new();
562 #else
563         context->rfx_context = rfx_context_new(TRUE);
564 #endif
565         context->rfx_context->mode = RLGR3;
566         context->rfx_context->width = client->settings->DesktopWidth;
567         context->rfx_context->height = client->settings->DesktopHeight;
568         rfx_context_set_pixel_format(context->rfx_context, RDP_PIXEL_FORMAT_B8G8R8A8);
569
570         context->nsc_context = nsc_context_new();
571         nsc_context_set_pixel_format(context->nsc_context, RDP_PIXEL_FORMAT_B8G8R8A8);
572
573         context->encode_stream = Stream_New(NULL, 65536);
574 }
575
576 static void
577 rdp_peer_context_free(freerdp_peer* client, RdpPeerContext* context)
578 {
579         int i;
580         if (!context)
581                 return;
582
583         wl_list_remove(&context->item.link);
584         for(i = 0; i < MAX_FREERDP_FDS; i++) {
585                 if (context->events[i])
586                         wl_event_source_remove(context->events[i]);
587         }
588
589         if (context->item.flags & RDP_PEER_ACTIVATED) {
590                 weston_seat_release_keyboard(&context->item.seat);
591                 weston_seat_release_pointer(&context->item.seat);
592                 weston_seat_release(&context->item.seat);
593         }
594         Stream_Free(context->encode_stream, TRUE);
595         nsc_context_free(context->nsc_context);
596         rfx_context_free(context->rfx_context);
597         free(context->rfx_rects);
598 }
599
600
601 static int
602 rdp_client_activity(int fd, uint32_t mask, void *data) {
603         freerdp_peer* client = (freerdp_peer *)data;
604
605         if (!client->CheckFileDescriptor(client)) {
606                 weston_log("unable to checkDescriptor for %p\n", client);
607                 goto out_clean;
608         }
609         return 0;
610
611 out_clean:
612         freerdp_peer_context_free(client);
613         freerdp_peer_free(client);
614         return 0;
615 }
616
617 static BOOL
618 xf_peer_capabilities(freerdp_peer* client)
619 {
620         return TRUE;
621 }
622
623 struct rdp_to_xkb_keyboard_layout {
624         UINT32 rdpLayoutCode;
625         const char *xkbLayout;
626         const char *xkbVariant;
627 };
628
629 /* table reversed from
630         https://github.com/awakecoding/FreeRDP/blob/master/libfreerdp/locale/xkb_layout_ids.c#L811 */
631 static
632 struct rdp_to_xkb_keyboard_layout rdp_keyboards[] = {
633         {KBD_ARABIC_101, "ara", 0},
634         {KBD_BULGARIAN, 0, 0},
635         {KBD_CHINESE_TRADITIONAL_US, 0},
636         {KBD_CZECH, "cz", 0},
637         {KBD_CZECH_PROGRAMMERS, "cz", "bksl"},
638         {KBD_CZECH_QWERTY, "cz", "qwerty"},
639         {KBD_DANISH, "dk", 0},
640         {KBD_GERMAN, "de", 0},
641         {KBD_GERMAN_NEO, "de", "neo"},
642         {KBD_GERMAN_IBM, "de", "qwerty"},
643         {KBD_GREEK, "gr", 0},
644         {KBD_GREEK_220, "gr", "simple"},
645         {KBD_GREEK_319, "gr", "extended"},
646         {KBD_GREEK_POLYTONIC, "gr", "polytonic"},
647         {KBD_US, "us", 0},
648         {KBD_US_ENGLISH_TABLE_FOR_IBM_ARABIC_238_L, "ara", "buckwalter"},
649         {KBD_SPANISH, "es", 0},
650         {KBD_SPANISH_VARIATION, "es", "nodeadkeys"},
651         {KBD_FINNISH, "fi", 0},
652         {KBD_FRENCH, "fr", 0},
653         {KBD_HEBREW, "il", 0},
654         {KBD_HUNGARIAN, "hu", 0},
655         {KBD_HUNGARIAN_101_KEY, "hu", "standard"},
656         {KBD_ICELANDIC, "is", 0},
657         {KBD_ITALIAN, "it", 0},
658         {KBD_ITALIAN_142, "it", "nodeadkeys"},
659         {KBD_JAPANESE, "jp", 0},
660         {KBD_JAPANESE_INPUT_SYSTEM_MS_IME2002, "jp", "kana"},
661         {KBD_KOREAN, "kr", 0},
662         {KBD_KOREAN_INPUT_SYSTEM_IME_2000, "kr", "kr104"},
663         {KBD_DUTCH, "nl", 0},
664         {KBD_NORWEGIAN, "no", 0},
665         {KBD_POLISH_PROGRAMMERS, "pl", 0},
666         {KBD_POLISH_214, "pl", "qwertz"},
667         // {KBD_PORTUGUESE_BRAZILIAN_ABN0416, 0},
668         {KBD_ROMANIAN, "ro", 0},
669         {KBD_RUSSIAN, "ru", 0},
670         {KBD_RUSSIAN_TYPEWRITER, "ru", "typewriter"},
671         {KBD_CROATIAN, "hr", 0},
672         {KBD_SLOVAK, "sk", 0},
673         {KBD_SLOVAK_QWERTY, "sk", "qwerty"},
674         {KBD_ALBANIAN, 0, 0},
675         {KBD_SWEDISH, "se", 0},
676         {KBD_THAI_KEDMANEE, "th", 0},
677         {KBD_THAI_KEDMANEE_NON_SHIFTLOCK, "th", "tis"},
678         {KBD_TURKISH_Q, "tr", 0},
679         {KBD_TURKISH_F, "tr", "f"},
680         {KBD_URDU, "in", "urd-phonetic3"},
681         {KBD_UKRAINIAN, "ua", 0},
682         {KBD_BELARUSIAN, "by", 0},
683         {KBD_SLOVENIAN, "si", 0},
684         {KBD_ESTONIAN, "ee", 0},
685         {KBD_LATVIAN, "lv", 0},
686         {KBD_LITHUANIAN_IBM, "lt", "ibm"},
687         {KBD_FARSI, "af", 0},
688         {KBD_VIETNAMESE, "vn", 0},
689         {KBD_ARMENIAN_EASTERN, "am", 0},
690         {KBD_AZERI_LATIN, 0, 0},
691         {KBD_FYRO_MACEDONIAN, "mk", 0},
692         {KBD_GEORGIAN, "ge", 0},
693         {KBD_FAEROESE, 0, 0},
694         {KBD_DEVANAGARI_INSCRIPT, 0, 0},
695         {KBD_MALTESE_47_KEY, 0, 0},
696         {KBD_NORWEGIAN_WITH_SAMI, "no", "smi"},
697         {KBD_KAZAKH, "kz", 0},
698         {KBD_KYRGYZ_CYRILLIC, "kg", "phonetic"},
699         {KBD_TATAR, "ru", "tt"},
700         {KBD_BENGALI, "bd", 0},
701         {KBD_BENGALI_INSCRIPT, "bd", "probhat"},
702         {KBD_PUNJABI, 0, 0},
703         {KBD_GUJARATI, "in", "guj"},
704         {KBD_TAMIL, "in", "tam"},
705         {KBD_TELUGU, "in", "tel"},
706         {KBD_KANNADA, "in", "kan"},
707         {KBD_MALAYALAM, "in", "mal"},
708         {KBD_HINDI_TRADITIONAL, "in", 0},
709         {KBD_MARATHI, 0, 0},
710         {KBD_MONGOLIAN_CYRILLIC, "mn", 0},
711         {KBD_UNITED_KINGDOM_EXTENDED, "gb", "intl"},
712         {KBD_SYRIAC, "syc", 0},
713         {KBD_SYRIAC_PHONETIC, "syc", "syc_phonetic"},
714         {KBD_NEPALI, "np", 0},
715         {KBD_PASHTO, "af", "ps"},
716         {KBD_DIVEHI_PHONETIC, 0, 0},
717         {KBD_LUXEMBOURGISH, 0, 0},
718         {KBD_MAORI, "mao", 0},
719         {KBD_CHINESE_SIMPLIFIED_US, 0, 0},
720         {KBD_SWISS_GERMAN, "ch", "de_nodeadkeys"},
721         {KBD_UNITED_KINGDOM, "gb", 0},
722         {KBD_LATIN_AMERICAN, "latam", 0},
723         {KBD_BELGIAN_FRENCH, "be", 0},
724         {KBD_BELGIAN_PERIOD, "be", "oss_sundeadkeys"},
725         {KBD_PORTUGUESE, "pt", 0},
726         {KBD_SERBIAN_LATIN, "rs", 0},
727         {KBD_AZERI_CYRILLIC, "az", "cyrillic"},
728         {KBD_SWEDISH_WITH_SAMI, "se", "smi"},
729         {KBD_UZBEK_CYRILLIC, "af", "uz"},
730         {KBD_INUKTITUT_LATIN, "ca", "ike"},
731         {KBD_CANADIAN_FRENCH_LEGACY, "ca", "fr-legacy"},
732         {KBD_SERBIAN_CYRILLIC, "rs", 0},
733         {KBD_CANADIAN_FRENCH, "ca", "fr-legacy"},
734         {KBD_SWISS_FRENCH, "ch", "fr"},
735         {KBD_BOSNIAN, "ba", 0},
736         {KBD_IRISH, 0, 0},
737         {KBD_BOSNIAN_CYRILLIC, "ba", "us"},
738         {KBD_UNITED_STATES_DVORAK, "us", "dvorak"},
739         {KBD_PORTUGUESE_BRAZILIAN_ABNT2, "br", "nativo"},
740         {KBD_CANADIAN_MULTILINGUAL_STANDARD, "ca", "multix"},
741         {KBD_GAELIC, "ie", "CloGaelach"},
742
743         {0x00000000, 0, 0},
744 };
745
746 /* taken from 2.2.7.1.6 Input Capability Set (TS_INPUT_CAPABILITYSET) */
747 static char *rdp_keyboard_types[] = {
748         "",     /* 0: unused */
749         "", /* 1: IBM PC/XT or compatible (83-key) keyboard */
750         "", /* 2: Olivetti "ICO" (102-key) keyboard */
751         "", /* 3: IBM PC/AT (84-key) or similar keyboard */
752         "pc102",/* 4: IBM enhanced (101- or 102-key) keyboard */
753         "", /* 5: Nokia 1050 and similar keyboards */
754         "",     /* 6: Nokia 9140 and similar keyboards */
755         ""      /* 7: Japanese keyboard */
756 };
757
758 static BOOL
759 xf_peer_post_connect(freerdp_peer* client)
760 {
761         RdpPeerContext *peerCtx;
762         struct rdp_compositor *c;
763         struct rdp_output *output;
764         rdpSettings *settings;
765         rdpPointerUpdate *pointer;
766         struct xkb_context *xkbContext;
767         struct xkb_rule_names xkbRuleNames;
768         struct xkb_keymap *keymap;
769         int i;
770         pixman_box32_t box;
771         pixman_region32_t damage;
772
773
774         peerCtx = (RdpPeerContext *)client->context;
775         c = peerCtx->rdpCompositor;
776         output = c->output;
777         settings = client->settings;
778
779         if (!settings->SurfaceCommandsEnabled) {
780                 weston_log("client doesn't support required SurfaceCommands\n");
781                 return FALSE;
782         }
783
784         if (output->base.width != (int)settings->DesktopWidth ||
785                         output->base.height != (int)settings->DesktopHeight)
786         {
787                 if (c->no_clients_resize) {
788                         /* RDP peers don't dictate their resolution to weston */
789                         if (!settings->DesktopResize) {
790                                 /* peer does not support desktop resize */
791                                 weston_log("%s: client doesn't support resizing, closing connection\n", __FUNCTION__);
792                                 return FALSE;
793                         } else {
794                                 settings->DesktopWidth = output->base.width;
795                                 settings->DesktopHeight = output->base.height;
796                                 client->update->DesktopResize(client->context);
797                         }
798                 } else {
799                         /* ask weston to adjust size */
800                         struct weston_mode new_mode;
801                         struct weston_mode *target_mode;
802                         new_mode.width = (int)settings->DesktopWidth;
803                         new_mode.height = (int)settings->DesktopHeight;
804                         target_mode = ensure_matching_mode(&output->base, &new_mode);
805                         if (!target_mode) {
806                                 weston_log("client mode not found\n");
807                                 return FALSE;
808                         }
809                         weston_output_switch_mode(&output->base, target_mode, 1, WESTON_MODE_SWITCH_SET_NATIVE);
810                         output->base.width = new_mode.width;
811                         output->base.height = new_mode.height;
812                 }
813         }
814
815         weston_log("kbd_layout:%x kbd_type:%x kbd_subType:%x kbd_functionKeys:%x\n",
816                         settings->KeyboardLayout, settings->KeyboardType, settings->KeyboardSubType,
817                         settings->KeyboardFunctionKey);
818
819         memset(&xkbRuleNames, 0, sizeof(xkbRuleNames));
820         if (settings->KeyboardType <= 7)
821                 xkbRuleNames.model = rdp_keyboard_types[settings->KeyboardType];
822         for(i = 0; rdp_keyboards[i].rdpLayoutCode; i++) {
823                 if (rdp_keyboards[i].rdpLayoutCode == settings->KeyboardLayout) {
824                         xkbRuleNames.layout = rdp_keyboards[i].xkbLayout;
825                         xkbRuleNames.variant = rdp_keyboards[i].xkbVariant;
826                         weston_log("%s: matching layout=%s variant=%s\n", __FUNCTION__,
827                                         xkbRuleNames.layout, xkbRuleNames.variant);
828                         break;
829                 }
830         }
831
832         keymap = NULL;
833         if (xkbRuleNames.layout) {
834                 xkbContext = xkb_context_new(0);
835                 if (!xkbContext) {
836                         weston_log("unable to create a xkb_context\n");
837                         return FALSE;
838                 }
839
840                 keymap = xkb_keymap_new_from_names(xkbContext, &xkbRuleNames, 0);
841         }
842         weston_seat_init_keyboard(&peerCtx->item.seat, keymap);
843         weston_seat_init_pointer(&peerCtx->item.seat);
844
845         peerCtx->item.flags |= RDP_PEER_ACTIVATED;
846
847         /* disable pointer on the client side */
848         pointer = client->update->pointer;
849         pointer->pointer_system.type = SYSPTR_NULL;
850         pointer->PointerSystem(client->context, &pointer->pointer_system);
851
852         /* sends a full refresh */
853         box.x1 = 0;
854         box.y1 = 0;
855         box.x2 = output->base.width;
856         box.y2 = output->base.height;
857         pixman_region32_init_with_extents(&damage, &box);
858
859         rdp_peer_refresh_region(&damage, client);
860
861         pixman_region32_fini(&damage);
862
863         return TRUE;
864 }
865
866 static BOOL
867 xf_peer_activate(freerdp_peer *client)
868 {
869         RdpPeerContext *context = (RdpPeerContext *)client->context;
870         rfx_context_reset(context->rfx_context);
871         return TRUE;
872 }
873
874 static void
875 xf_mouseEvent(rdpInput *input, UINT16 flags, UINT16 x, UINT16 y) {
876         wl_fixed_t wl_x, wl_y, axis;
877         RdpPeerContext *peerContext = (RdpPeerContext *)input->context;
878         struct rdp_output *output;
879         uint32_t button = 0;
880
881         if (flags & PTR_FLAGS_MOVE) {
882                 output = peerContext->rdpCompositor->output;
883                 if (x < output->base.width && y < output->base.height) {
884                         wl_x = wl_fixed_from_int((int)x);
885                         wl_y = wl_fixed_from_int((int)y);
886                         notify_motion_absolute(&peerContext->item.seat, weston_compositor_get_time(),
887                                         wl_x, wl_y);
888                 }
889         }
890
891         if (flags & PTR_FLAGS_BUTTON1)
892                 button = BTN_LEFT;
893         else if (flags & PTR_FLAGS_BUTTON2)
894                 button = BTN_RIGHT;
895         else if (flags & PTR_FLAGS_BUTTON3)
896                 button = BTN_MIDDLE;
897
898         if (button) {
899                 notify_button(&peerContext->item.seat, weston_compositor_get_time(), button,
900                         (flags & PTR_FLAGS_DOWN) ? WL_POINTER_BUTTON_STATE_PRESSED : WL_POINTER_BUTTON_STATE_RELEASED
901                 );
902         }
903
904         if (flags & PTR_FLAGS_WHEEL) {
905                 /* DEFAULT_AXIS_STEP_DISTANCE is stolen from compositor-x11.c
906                  * The RDP specs says the lower bits of flags contains the "the number of rotation
907                  * units the mouse wheel was rotated".
908                  *
909                  * http://blogs.msdn.com/b/oldnewthing/archive/2013/01/23/10387366.aspx explains the 120 value
910                  */
911                 axis = (DEFAULT_AXIS_STEP_DISTANCE * (flags & 0xff)) / 120;
912                 if (flags & PTR_FLAGS_WHEEL_NEGATIVE)
913                         axis = -axis;
914
915                 notify_axis(&peerContext->item.seat, weston_compositor_get_time(),
916                                             WL_POINTER_AXIS_VERTICAL_SCROLL,
917                                             axis);
918         }
919 }
920
921 static void
922 xf_extendedMouseEvent(rdpInput *input, UINT16 flags, UINT16 x, UINT16 y) {
923         wl_fixed_t wl_x, wl_y;
924         RdpPeerContext *peerContext = (RdpPeerContext *)input->context;
925         struct rdp_output *output;
926
927         output = peerContext->rdpCompositor->output;
928         if (x < output->base.width && y < output->base.height) {
929                 wl_x = wl_fixed_from_int((int)x);
930                 wl_y = wl_fixed_from_int((int)y);
931                 notify_motion_absolute(&peerContext->item.seat, weston_compositor_get_time(),
932                                 wl_x, wl_y);
933         }
934 }
935
936
937 static void
938 xf_input_synchronize_event(rdpInput *input, UINT32 flags)
939 {
940         freerdp_peer *client = input->context->peer;
941         RdpPeerContext *peerCtx = (RdpPeerContext *)input->context;
942         struct rdp_output *output = peerCtx->rdpCompositor->output;
943         pixman_box32_t box;
944         pixman_region32_t damage;
945
946         /* sends a full refresh */
947         box.x1 = 0;
948         box.y1 = 0;
949         box.x2 = output->base.width;
950         box.y2 = output->base.height;
951         pixman_region32_init_with_extents(&damage, &box);
952
953         rdp_peer_refresh_region(&damage, client);
954
955         pixman_region32_fini(&damage);
956 }
957
958
959 static void
960 xf_input_keyboard_event(rdpInput *input, UINT16 flags, UINT16 code)
961 {
962         uint32_t scan_code, vk_code, full_code;
963         enum wl_keyboard_key_state keyState;
964         RdpPeerContext *peerContext = (RdpPeerContext *)input->context;
965         int notify = 0;
966
967         if (flags & KBD_FLAGS_DOWN) {
968                 keyState = WL_KEYBOARD_KEY_STATE_PRESSED;
969                 notify = 1;
970         } else if (flags & KBD_FLAGS_RELEASE) {
971                 keyState = WL_KEYBOARD_KEY_STATE_RELEASED;
972                 notify = 1;
973         }
974
975         if (notify) {
976                 full_code = code;
977                 if (flags & KBD_FLAGS_EXTENDED)
978                         full_code |= KBD_FLAGS_EXTENDED;
979
980                 vk_code = GetVirtualKeyCodeFromVirtualScanCode(full_code, 4);
981                 if(flags & KBD_FLAGS_EXTENDED)
982                         vk_code |= KBDEXT;
983
984                 scan_code = GetKeycodeFromVirtualKeyCode(vk_code, KEYCODE_TYPE_EVDEV);
985
986                 /*weston_log("code=%x ext=%d vk_code=%x scan_code=%x\n", code, (flags & KBD_FLAGS_EXTENDED) ? 1 : 0,
987                                 vk_code, scan_code);*/
988                 notify_key(&peerContext->item.seat, weston_compositor_get_time(),
989                                         scan_code - 8, keyState, STATE_UPDATE_AUTOMATIC);
990         }
991 }
992
993 static void
994 xf_input_unicode_keyboard_event(rdpInput *input, UINT16 flags, UINT16 code)
995 {
996         weston_log("Client sent a unicode keyboard event (flags:0x%X code:0x%X)\n", flags, code);
997 }
998
999
1000 static void
1001 xf_suppress_output(rdpContext *context, BYTE allow, RECTANGLE_16 *area) {
1002         RdpPeerContext *peerContext = (RdpPeerContext *)context;
1003         if (allow)
1004                 peerContext->item.flags |= RDP_PEER_OUTPUT_ENABLED;
1005         else
1006                 peerContext->item.flags &= (~RDP_PEER_OUTPUT_ENABLED);
1007 }
1008
1009 static int
1010 rdp_peer_init(freerdp_peer *client, struct rdp_compositor *c)
1011 {
1012         int rcount = 0;
1013         void *rfds[MAX_FREERDP_FDS];
1014         int i, fd;
1015         struct wl_event_loop *loop;
1016         rdpSettings     *settings;
1017         rdpInput *input;
1018         RdpPeerContext *peerCtx;
1019         char seat_name[32];
1020
1021         client->ContextSize = sizeof(RdpPeerContext);
1022         client->ContextNew = (psPeerContextNew)rdp_peer_context_new;
1023         client->ContextFree = (psPeerContextFree)rdp_peer_context_free;
1024         freerdp_peer_context_new(client);
1025
1026         peerCtx = (RdpPeerContext *) client->context;
1027         peerCtx->rdpCompositor = c;
1028
1029         settings = client->settings;
1030         settings->RdpKeyFile = c->rdp_key;
1031         if (c->tls_enabled) {
1032                 settings->CertificateFile = c->server_cert;
1033                 settings->PrivateKeyFile = c->server_key;
1034         } else {
1035                 settings->TlsSecurity = FALSE;
1036         }
1037
1038         settings->NlaSecurity = FALSE;
1039
1040         client->Capabilities = xf_peer_capabilities;
1041         client->PostConnect = xf_peer_post_connect;
1042         client->Activate = xf_peer_activate;
1043
1044         client->update->SuppressOutput = xf_suppress_output;
1045
1046         input = client->input;
1047         input->SynchronizeEvent = xf_input_synchronize_event;
1048         input->MouseEvent = xf_mouseEvent;
1049         input->ExtendedMouseEvent = xf_extendedMouseEvent;
1050         input->KeyboardEvent = xf_input_keyboard_event;
1051         input->UnicodeKeyboardEvent = xf_input_unicode_keyboard_event;
1052
1053         if (snprintf(seat_name, 32, "rdp:%d:%s", client->sockfd, client->hostname) >= 32)
1054                 seat_name[31] = '\0';
1055
1056         weston_seat_init(&peerCtx->item.seat, &c->base, seat_name);
1057
1058         client->Initialize(client);
1059
1060         if (!client->GetFileDescriptor(client, rfds, &rcount)) {
1061                 weston_log("unable to retrieve client fds\n");
1062                 return -1;
1063         }
1064
1065         loop = wl_display_get_event_loop(c->base.wl_display);
1066         for(i = 0; i < rcount; i++) {
1067                 fd = (int)(long)(rfds[i]);
1068
1069                 peerCtx->events[i] = wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE,
1070                                 rdp_client_activity, client);
1071         }
1072         for ( ; i < MAX_FREERDP_FDS; i++)
1073                 peerCtx->events[i] = 0;
1074
1075         wl_list_insert(&c->output->peers, &peerCtx->item.link);
1076         return 0;
1077 }
1078
1079
1080 static void
1081 rdp_incoming_peer(freerdp_listener *instance, freerdp_peer *client)
1082 {
1083         struct rdp_compositor *c = (struct rdp_compositor *)instance->param4;
1084         if (rdp_peer_init(client, c) < 0)
1085                 return;
1086 }
1087
1088 static struct weston_compositor *
1089 rdp_compositor_create(struct wl_display *display,
1090                 struct rdp_compositor_config *config,
1091                 int *argc, char *argv[], struct weston_config *wconfig)
1092 {
1093         struct rdp_compositor *c;
1094         char *fd_str;
1095         int fd;
1096
1097         c = zalloc(sizeof *c);
1098         if (c == NULL)
1099                 return NULL;
1100
1101         if (weston_compositor_init(&c->base, display, argc, argv, wconfig) < 0)
1102                 goto err_free;
1103
1104         c->base.destroy = rdp_destroy;
1105         c->base.restore = rdp_restore;
1106         c->rdp_key = config->rdp_key ? strdup(config->rdp_key) : NULL;
1107         c->no_clients_resize = config->no_clients_resize;
1108
1109         /* activate TLS only if certificate/key are available */
1110         if (config->server_cert && config->server_key) {
1111                 weston_log("TLS support activated\n");
1112                 c->server_cert = strdup(config->server_cert);
1113                 c->server_key = strdup(config->server_key);
1114                 if (!c->server_cert || !c->server_key)
1115                         goto err_free_strings;
1116                 c->tls_enabled = 1;
1117         }
1118
1119         if (pixman_renderer_init(&c->base) < 0)
1120                 goto err_compositor;
1121
1122         if (rdp_compositor_create_output(c, config->width, config->height) < 0)
1123                 goto err_compositor;
1124
1125         c->base.capabilities |= WESTON_CAP_ARBITRARY_MODES;
1126
1127         if(!config->env_socket) {
1128                 c->listener = freerdp_listener_new();
1129                 c->listener->PeerAccepted = rdp_incoming_peer;
1130                 c->listener->param4 = c;
1131                 if (!c->listener->Open(c->listener, config->bind_address, config->port)) {
1132                         weston_log("unable to bind rdp socket\n");
1133                         goto err_listener;
1134                 }
1135
1136                 if (rdp_implant_listener(c, c->listener) < 0)
1137                         goto err_compositor;
1138         } else {
1139                 /* get the socket from RDP_FD var */
1140                 fd_str = getenv("RDP_FD");
1141                 if (!fd_str) {
1142                         weston_log("RDP_FD env variable not set");
1143                         goto err_output;
1144                 }
1145
1146                 if (!weston_strtoi(fd_str, NULL, 10, &fd))
1147                         fd = -1;
1148                 if (rdp_peer_init(freerdp_peer_new(fd), c))
1149                         goto err_output;
1150         }
1151
1152         return &c->base;
1153
1154 err_listener:
1155         freerdp_listener_free(c->listener);
1156 err_output:
1157         weston_output_destroy(&c->output->base);
1158 err_compositor:
1159         weston_compositor_shutdown(&c->base);
1160 err_free_strings:
1161         if (c->rdp_key)
1162                 free(c->rdp_key);
1163         if (c->server_cert)
1164                 free(c->server_cert);
1165         if (c->server_key)
1166                 free(c->server_key);
1167 err_free:
1168         free(c);
1169         return NULL;
1170 }
1171
1172 WL_EXPORT struct weston_compositor *
1173 backend_init(struct wl_display *display, int *argc, char *argv[],
1174              struct weston_config *wconfig)
1175 {
1176         struct rdp_compositor_config config;
1177         rdp_compositor_config_init(&config);
1178         int major, minor, revision;
1179
1180         freerdp_get_version(&major, &minor, &revision);
1181         weston_log("using FreeRDP version %d.%d.%d\n", major, minor, revision);
1182
1183         const struct weston_option rdp_options[] = {
1184                 { WESTON_OPTION_BOOLEAN, "env-socket", 0, &config.env_socket },
1185                 { WESTON_OPTION_INTEGER, "width", 0, &config.width },
1186                 { WESTON_OPTION_INTEGER, "height", 0, &config.height },
1187                 { WESTON_OPTION_STRING,  "address", 0, &config.bind_address },
1188                 { WESTON_OPTION_INTEGER, "port", 0, &config.port },
1189                 { WESTON_OPTION_BOOLEAN, "no-clients-resize", 0, &config.no_clients_resize },
1190                 { WESTON_OPTION_STRING,  "rdp4-key", 0, &config.rdp_key },
1191                 { WESTON_OPTION_STRING,  "rdp-tls-cert", 0, &config.server_cert },
1192                 { WESTON_OPTION_STRING,  "rdp-tls-key", 0, &config.server_key }
1193         };
1194
1195         parse_options(rdp_options, ARRAY_LENGTH(rdp_options), argc, argv);
1196         return rdp_compositor_create(display, &config, argc, argv, wconfig);
1197 }