forked from IcebergThings/weston
/
shell.c
4515 lines (3718 loc) · 131 KB
/
shell.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright © 2010-2012 Intel Corporation
* Copyright © 2011-2012 Collabora, Ltd.
* Copyright © 2013 Raspberry Pi Foundation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <linux/input.h>
#include <assert.h>
#include <signal.h>
#include <math.h>
#include <sys/types.h>
#include <sys/time.h>
#include <errno.h>
#include "shell.h"
#include "compositor/weston.h"
#include "weston-rdprail-shell-server-protocol.h"
#include <libweston/config-parser.h>
#include "shared/helpers.h"
#include "shared/timespec-util.h"
#include <libweston-desktop/libweston-desktop.h>
#include <libweston/libweston.h>
#include <libweston/backend.h>
#include <libweston/backend-rdp.h>
struct focus_state {
struct desktop_shell *shell;
struct weston_seat *seat;
struct workspace *ws;
struct weston_surface *keyboard_focus;
struct wl_list link;
struct wl_listener seat_destroy_listener;
struct wl_listener surface_destroy_listener;
};
/*
* Surface stacking and ordering.
*
* This is handled using several linked lists of surfaces, organised into
* ‘layers’. The layers are ordered, and each of the surfaces in one layer are
* above all of the surfaces in the layer below. The set of layers is static and
* in the following order (top-most first):
* • Cursor layer
* • Fullscreen layer
* • Workspace layers
*
* The list of layers may be manipulated to remove whole layers of surfaces from
* display. For example, when locking the screen, all layers except the lock
* layer are removed.
*
* A surface’s layer is modified on configuring the surface, in
* set_surface_type() (which is only called when the surface’s type change is
* _committed_). If a surface’s type changes (e.g. when making a window
* fullscreen) its layer changes too.
*
* In order to allow popup and transient surfaces to be correctly stacked above
* their parent surfaces, each surface tracks both its parent surface, and a
* linked list of its children. When a surface’s layer is updated, so are the
* layers of its children. Note that child surfaces are *not* the same as
* subsurfaces — child/parent surfaces are purely for maintaining stacking
* order.
*
* The children_link list of siblings of a surface (i.e. those surfaces which
* have the same parent) only contains weston_surfaces which have a
* shell_surface. Stacking is not implemented for non-shell_surface
* weston_surfaces. This means that the following implication does *not* hold:
* (shsurf->parent != NULL) ⇒ !wl_list_is_empty(shsurf->children_link)
*/
struct shell_surface {
struct wl_signal destroy_signal;
struct weston_desktop_surface *desktop_surface;
struct weston_view *view;
int32_t last_width, last_height;
struct desktop_shell *shell;
struct shell_surface *parent;
struct wl_list children_list;
struct wl_list children_link;
int32_t saved_x, saved_y;
bool saved_position_valid;
bool saved_rotation_valid;
int unresponsive, grabbed;
uint32_t resize_edges;
struct {
struct weston_transform transform;
struct weston_matrix rotation;
} rotation;
struct {
struct weston_transform transform; /* matrix from x, y */
struct weston_view *black_view;
} fullscreen;
struct weston_output *fullscreen_output;
struct weston_output *output;
struct wl_listener output_destroy_listener;
struct surface_state {
bool fullscreen;
bool maximized;
bool lowered;
} state;
struct {
bool is_set;
int32_t x;
int32_t y;
} xwayland;
int focus_count;
bool destroying;
struct {
bool is_snapped;
bool is_maximized_requested;
int x;
int y;
int width;
int height;
int saved_width;
int saved_height;
int last_grab_x;
int last_grab_y;
} snapped;
struct {
bool is_default_icon_used;
bool is_icon_set;
} icon;
struct wl_listener metadata_listener;
};
struct shell_grab {
struct weston_pointer_grab grab;
struct shell_surface *shsurf;
struct wl_listener shsurf_destroy_listener;
};
struct shell_touch_grab {
struct weston_touch_grab grab;
struct shell_surface *shsurf;
struct wl_listener shsurf_destroy_listener;
struct weston_touch *touch;
};
struct weston_move_grab {
struct shell_grab base;
wl_fixed_t dx, dy;
bool client_initiated;
};
struct weston_touch_move_grab {
struct shell_touch_grab base;
int active;
wl_fixed_t dx, dy;
};
struct rotate_grab {
struct shell_grab base;
struct weston_matrix rotation;
struct {
float x;
float y;
} center;
};
struct shell_seat {
struct weston_seat *seat;
struct desktop_shell *shell;
struct wl_listener seat_destroy_listener;
struct weston_surface *focused_surface;
struct wl_listener caps_changed_listener;
struct wl_listener pointer_focus_listener;
struct wl_listener keyboard_focus_listener;
};
static const struct weston_pointer_grab_interface move_grab_interface;
static void set_unsnap(struct shell_surface *shsurf, int grabX, int grabY);
static struct desktop_shell *
shell_surface_get_shell(struct shell_surface *shsurf);
static void
set_busy_cursor(struct shell_surface *shsurf, struct weston_pointer *pointer);
static void
surface_rotate(struct shell_surface *surface, struct weston_pointer *pointer);
static struct shell_seat *
get_shell_seat(struct weston_seat *seat);
static struct shell_output *
find_shell_output_from_weston_output(struct desktop_shell *shell,
struct weston_output *output);
static void
shell_surface_update_child_surface_layers(struct shell_surface *shsurf);
static void
shell_backend_request_window_activate(void *shell_context, struct weston_seat *seat, struct weston_surface *surface);
#define ICON_STRIDE( W, BPP ) ((((W) * (BPP) + 31) / 32) * 4)
static int cached_tm_mday = -1;
static char *
shell_rdp_log_timestamp(char *buf, size_t len)
{
struct timeval tv;
struct tm *brokendown_time;
char datestr[128];
char timestr[128];
gettimeofday(&tv, NULL);
brokendown_time = localtime(&tv.tv_sec);
if (brokendown_time == NULL) {
snprintf(buf, len, "%s", "[(NULL)localtime] ");
return buf;
}
memset(datestr, 0, sizeof(datestr));
if (brokendown_time->tm_mday != cached_tm_mday) {
strftime(datestr, sizeof(datestr), "Date: %Y-%m-%d %Z\n",
brokendown_time);
cached_tm_mday = brokendown_time->tm_mday;
}
strftime(timestr, sizeof(timestr), "%H:%M:%S", brokendown_time);
/* if datestr is empty it prints only timestr*/
snprintf(buf, len, "%s[%s.%03li]", datestr,
timestr, (tv.tv_usec / 1000));
return buf;
}
void
shell_rdp_debug_print(struct weston_log_scope *scope, bool cont, char *fmt, ...)
{
if (scope && weston_log_scope_is_enabled(scope)) {
va_list ap;
va_start(ap, fmt);
if (cont) {
weston_log_scope_vprintf(scope, fmt, ap);
} else {
char timestr[128];
int len_va;
char *str;
shell_rdp_log_timestamp(timestr, sizeof(timestr));
len_va = vasprintf(&str, fmt, ap);
if (len_va >= 0) {
weston_log_scope_printf(scope, "%s %s",
timestr, str);
free(str);
} else {
const char *oom = "Out of memory";
weston_log_scope_printf(scope, "%s %s",
timestr, oom);
}
}
}
}
void
shell_blend_overlay_icon(struct desktop_shell *shell, pixman_image_t *app_image, pixman_image_t *overlay_image)
{
int app_width, overlay_width;
int app_height, overlay_height;
double overlay_scale_width, overlay_scale_height;
pixman_transform_t transform;
/* can't overlay to itself */
assert(app_image);
assert(overlay_image);
assert(app_image != overlay_image);
app_width = pixman_image_get_width(app_image);
app_height = pixman_image_get_height(app_image);
if (!app_width || !app_height)
return;
overlay_width = pixman_image_get_width(overlay_image);
overlay_height = pixman_image_get_height(overlay_image);
if (!overlay_width || !overlay_height)
return;
overlay_scale_width = 1.0f / (((double)app_width / overlay_width) / 1.75f);
overlay_scale_height = 1.0f / (((double)app_height / overlay_height) / 1.75f);
shell_rdp_debug_verbose(shell, "%s: app %dx%d; overlay %dx%d; scale %4.2fx%4.2f\n",
__func__, app_width, app_height, overlay_width, overlay_height,
overlay_scale_width, overlay_scale_height);
pixman_transform_init_scale(&transform,
pixman_double_to_fixed(overlay_scale_width),
pixman_double_to_fixed(overlay_scale_height));
pixman_image_set_transform(overlay_image, &transform);
pixman_image_set_filter(overlay_image, PIXMAN_FILTER_BILINEAR, NULL, 0);
pixman_image_composite32(PIXMAN_OP_OVER,
overlay_image, /* src */
NULL, /* mask */
app_image, /* dest */
0, 0, /* src_x, src_y */
0, 0, /* mask_x, mask_y */
app_width/2 , app_height/2, /* dest_x, dest_y */
app_width, /* width */
app_height /* height */);
pixman_image_set_filter(overlay_image, PIXMAN_FILTER_NEAREST, NULL, 0);
pixman_image_set_transform(overlay_image, NULL);
}
static void
shell_surface_set_window_icon(struct weston_desktop_surface *desktop_surface,
int32_t width, int32_t height, int32_t bpp,
void *bits, void *user_data)
{
struct shell_surface *shsurf;
struct weston_surface *surface;
const struct weston_xwayland_surface_api *api;
pixman_image_t *image = NULL;
pixman_format_code_t format;
const char *id;
shsurf = weston_desktop_surface_get_user_data(desktop_surface);
if (!shsurf)
return;
surface = weston_desktop_surface_get_surface(desktop_surface);
if (!surface)
return;
if (shsurf->shell->rdprail_api->set_window_icon) {
if (width && height && bpp && bits) {
/* When caller supplied custom image, it's always be used */
switch (bpp) {
case 32:
format = PIXMAN_a8r8g8b8;
break;
default:
shell_rdp_debug_error(shsurf->shell, "shell_surface_set_window_icon(): unsupported bpp: %d\n", bpp);
return;
}
image = pixman_image_create_bits_no_clear(format,
width, height, bits, ICON_STRIDE(width, bpp));
if (image)
shsurf->icon.is_default_icon_used = false;
}
if (!image) {
/* Try .desktop for icon for non-overlay icon */
id = weston_desktop_surface_get_app_id(desktop_surface);
if (id)
image = app_list_load_icon_file(shsurf->shell, id);
if (!image) {
/* If this is X app, query from X */
api = shsurf->shell->xwayland_surface_api;
if (!api) {
api = weston_xwayland_surface_get_api(shsurf->shell->compositor);
shsurf->shell->xwayland_surface_api = api;
}
if (api && api->is_xwayland_surface(surface)) {
/* trigger_set_window_icon calls back this function
with custom icon image obtained from X app. */
if (api->trigger_set_window_icon(surface))
return;
}
}
if (image)
shsurf->icon.is_default_icon_used = false;
}
if (!image) {
/* When caller doens't supply custom image, look for default images */
image = shsurf->shell->image_default_app_icon;
if (image) {
pixman_image_ref(image);
shsurf->icon.is_default_icon_used = true;
}
}
if (!image)
return;
if (shsurf->shell->is_blend_overlay_icon_taskbar &&
shsurf->shell->image_default_app_overlay_icon)
shell_blend_overlay_icon(shsurf->shell,
image,
shsurf->shell->image_default_app_overlay_icon);
shsurf->shell->rdprail_api->set_window_icon(surface, image);
pixman_image_unref(image);
}
}
static int
shell_surface_get_label(struct weston_surface *surface, char *buf, size_t len)
{
const char *t, *c;
struct weston_desktop_surface *desktop_surface =
weston_surface_get_desktop_surface(surface);
struct shell_surface *shsurf =
shsurf = get_shell_surface(surface);
t = weston_desktop_surface_get_title(desktop_surface);
c = weston_desktop_surface_get_app_id(desktop_surface);
return snprintf(buf, len, "%s window%s%s%s%s%s",
shsurf && shsurf->parent ? "child" : "top-level",
t ? " '" : "", t ?: "", t ? "'" : "",
c ? " of " : "", c ?: "");
}
static void
destroy_shell_grab_shsurf(struct wl_listener *listener, void *data)
{
struct shell_grab *grab;
grab = container_of(listener, struct shell_grab,
shsurf_destroy_listener);
grab->shsurf = NULL;
}
struct weston_view *
get_default_view(struct weston_surface *surface)
{
struct shell_surface *shsurf;
struct weston_view *view;
if (!surface || wl_list_empty(&surface->views))
return NULL;
shsurf = get_shell_surface(surface);
if (shsurf)
return shsurf->view;
wl_list_for_each(view, &surface->views, surface_link)
if (weston_view_is_mapped(view))
return view;
return container_of(surface->views.next, struct weston_view, surface_link);
}
static void
shell_grab_start(struct shell_grab *grab,
const struct weston_pointer_grab_interface *interface,
struct shell_surface *shsurf,
struct weston_pointer *pointer,
enum weston_rdprail_shell_cursor cursor)
{
struct desktop_shell *shell = shsurf->shell;
weston_seat_break_desktop_grabs(pointer->seat);
grab->grab.interface = interface;
grab->shsurf = shsurf;
grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf;
wl_signal_add(&shsurf->destroy_signal,
&grab->shsurf_destroy_listener);
shsurf->grabbed = 1;
weston_pointer_start_grab(pointer, &grab->grab);
if (shell->is_localmove_supported &&
(interface == &move_grab_interface) &&
shell->rdprail_api->start_window_move) {
struct weston_size min_size;
struct weston_size max_size;
if (grab->shsurf->snapped.is_snapped) {
set_unsnap(grab->shsurf, wl_fixed_to_int(pointer->grab_x), wl_fixed_to_int(pointer->grab_y));
}
min_size = weston_desktop_surface_get_min_size(shsurf->desktop_surface);
max_size = weston_desktop_surface_get_max_size(shsurf->desktop_surface);
shell->is_localmove_pending = true;
shell->rdprail_api->start_window_move(
weston_desktop_surface_get_surface(shsurf->desktop_surface),
wl_fixed_to_int(pointer->grab_x),
wl_fixed_to_int(pointer->grab_y),
min_size,
max_size);
} else if (grab->shsurf->snapped.is_snapped) {
/** Cancel snap state on anything but a move grab
*/
grab->shsurf->snapped.is_snapped = false;
}
}
static void
shell_grab_end(struct shell_grab *grab)
{
if (grab->shsurf) {
struct desktop_shell* shell = grab->shsurf->shell;
struct weston_surface* surface =
weston_desktop_surface_get_surface(grab->shsurf->desktop_surface);
wl_list_remove(&grab->shsurf_destroy_listener.link);
grab->shsurf->grabbed = 0;
if (shell->is_localmove_supported &&
(grab->grab.interface == &move_grab_interface) &&
shell->rdprail_api->end_window_move) {
grab->shsurf->snapped.last_grab_x = wl_fixed_to_int(grab->grab.pointer->x);
grab->shsurf->snapped.last_grab_y = wl_fixed_to_int(grab->grab.pointer->y);
shell->rdprail_api->end_window_move(surface);
}
if (grab->shsurf->resize_edges) {
grab->shsurf->resize_edges = 0;
} else {
/* This is nessesary to make "double check" on title bar to max/restore
with X applications. When title bar is clicked first time, Xwayland
enters "grab_move" (see where FRAME_STATUS_MOVE), and when left button
is released, grab_move ends. On desktop-shell, when entered grab_move,
the focus is moved to shell "grab_surface" (see desktop-shell/shell.c:
shell_grab_start() where setting focus to shell->grab_surface.
But RDP shell doesn't have expclicit grab surface, thus
focus remains at the window who owned the title bar clicked.
This itself is OK, but when X and Xwayland depends on seeing
focus change when mouse button is released when grab_move ends,
so that they can recognized that mouse button is released *without
receiving explicit mouse message* using weston_pointer_send_button.
thus, here patch pointer's sx/sy to (0,0), and this trigger refocus
at weston_pointer_set_focus even focus isn't changed, and sx/sy will
be updated at weston_pointer_set_focus. */
grab->grab.pointer->sx = 0;
grab->grab.pointer->sy = 0;
}
}
weston_pointer_end_grab(grab->grab.pointer);
}
static void
shell_touch_grab_start(struct shell_touch_grab *grab,
const struct weston_touch_grab_interface *interface,
struct shell_surface *shsurf,
struct weston_touch *touch)
{
weston_seat_break_desktop_grabs(touch->seat);
grab->grab.interface = interface;
grab->shsurf = shsurf;
grab->shsurf_destroy_listener.notify = destroy_shell_grab_shsurf;
wl_signal_add(&shsurf->destroy_signal,
&grab->shsurf_destroy_listener);
grab->touch = touch;
shsurf->grabbed = 1;
weston_touch_start_grab(touch, &grab->grab);
}
static void
shell_touch_grab_end(struct shell_touch_grab *grab)
{
if (grab->shsurf) {
wl_list_remove(&grab->shsurf_destroy_listener.link);
grab->shsurf->grabbed = 0;
}
weston_touch_end_grab(grab->touch);
}
static void
get_output_work_area(struct desktop_shell *shell,
struct weston_output *output,
pixman_rectangle32_t *area)
{
if (!output) {
area->x = 0;
area->y = 0;
area->width = 0;
area->height = 0;
return;
}
struct shell_output *shell_output =
find_shell_output_from_weston_output(shell, output);
if (shell_output) {
*area = shell_output->desktop_workarea;
} else {
area->x = output->x;
area->y = output->y;
area->width = output->width;
area->height = output->height;
}
return;
}
static void
center_on_output(struct weston_view *view,
struct weston_output *output);
static enum weston_keyboard_modifier
get_modifier(char *modifier)
{
if (!modifier)
return 0; // default to no binding-modifier.
if (!strcmp("ctrl", modifier))
return MODIFIER_CTRL;
else if (!strcmp("alt", modifier))
return MODIFIER_ALT;
else if (!strcmp("super", modifier))
return MODIFIER_SUPER;
else if (!strcmp("none", modifier))
return 0;
else
return 0; // default to no binding-modifier.
}
static void
shell_configuration(struct desktop_shell *shell)
{
struct weston_config_section *section;
char *s, *client;
bool allow_zap;
bool is_localmove_supported;
section = weston_config_get_section(wet_get_config(shell->compositor),
"shell", NULL, NULL);
client = wet_get_libexec_path("weston-rdprail-shell");
weston_config_section_get_string(section, "client", &s, client);
free(client);
shell->client = s;
/* default to not allow zap */
weston_config_section_get_bool(section,
"allow-zap", &allow_zap, false);
if (!allow_zap) {
s = getenv("WESTON_RDPRAIL_SHELL_ALLOW_ZAP");
allow_zap = (s && (strcmp(s, "true") == 0));
}
shell->allow_zap = allow_zap;
/* set "none" to default to disable optional key-bindings */
weston_config_section_get_string(section,
"binding-modifier", &s, "none");
shell->binding_modifier = get_modifier(s);
free(s);
weston_config_section_get_bool(section,
"local-move", &is_localmove_supported, false);
shell->is_localmove_supported = is_localmove_supported;
shell->workspaces.num = 1;
}
struct weston_output *
get_default_output(struct weston_compositor *compositor)
{
if (wl_list_empty(&compositor->output_list))
return NULL;
return container_of(compositor->output_list.next,
struct weston_output, link);
}
static struct weston_output *
get_output_containing(struct weston_compositor *compositor, int x, int y)
{
if (wl_list_empty(&compositor->output_list))
return NULL;
struct weston_output *output;
wl_list_for_each(output, &compositor->output_list, link) {
if (x >= output->region.extents.x1 && x < output->region.extents.x2 &&
y >= output->region.extents.y1 && y < output->region.extents.y2) {
return output;
}
}
weston_log("Didn't find output containing (%d, %d), return default\n", x, y);
return get_default_output(compositor);
}
/* no-op func for checking focus surface */
static void
focus_surface_committed(struct weston_surface *es, int32_t sx, int32_t sy)
{
}
static bool
is_focus_surface (struct weston_surface *es)
{
return (es->committed == focus_surface_committed);
}
static bool
is_focus_view (struct weston_view *view)
{
return is_focus_surface (view->surface);
}
static void
focus_state_destroy(struct focus_state *state)
{
wl_list_remove(&state->seat_destroy_listener.link);
wl_list_remove(&state->surface_destroy_listener.link);
free(state);
}
static void
focus_state_seat_destroy(struct wl_listener *listener, void *data)
{
struct focus_state *state = container_of(listener,
struct focus_state,
seat_destroy_listener);
wl_list_remove(&state->link);
focus_state_destroy(state);
}
static void
focus_state_surface_destroy(struct wl_listener *listener, void *data)
{
struct focus_state *state = container_of(listener,
struct focus_state,
surface_destroy_listener);
struct weston_surface *main_surface;
struct weston_view *next;
struct weston_view *view;
main_surface = weston_surface_get_main_surface(state->keyboard_focus);
next = NULL;
wl_list_for_each(view,
&state->ws->layer.view_list.link, layer_link.link) {
if (view->surface == main_surface)
continue;
if (is_focus_view(view))
continue;
if (!get_shell_surface(view->surface))
continue;
next = view;
break;
}
/* if the focus was a sub-surface, activate its main surface */
if (main_surface != state->keyboard_focus)
next = get_default_view(main_surface);
if (next) {
if (state->keyboard_focus) {
wl_list_remove(&state->surface_destroy_listener.link);
wl_list_init(&state->surface_destroy_listener.link);
}
state->keyboard_focus = NULL;
activate(state->shell, next, state->seat,
WESTON_ACTIVATE_FLAG_CONFIGURE);
} else {
wl_list_remove(&state->link);
focus_state_destroy(state);
}
}
static struct focus_state *
focus_state_create(struct desktop_shell *shell, struct weston_seat *seat,
struct workspace *ws)
{
struct focus_state *state;
state = malloc(sizeof *state);
if (state == NULL)
return NULL;
state->shell = shell;
state->keyboard_focus = NULL;
state->ws = ws;
state->seat = seat;
wl_list_insert(&ws->focus_list, &state->link);
state->seat_destroy_listener.notify = focus_state_seat_destroy;
state->surface_destroy_listener.notify = focus_state_surface_destroy;
wl_signal_add(&seat->destroy_signal,
&state->seat_destroy_listener);
wl_list_init(&state->surface_destroy_listener.link);
return state;
}
static struct focus_state *
ensure_focus_state(struct desktop_shell *shell, struct weston_seat *seat)
{
struct workspace *ws = get_current_workspace(shell);
struct focus_state *state;
wl_list_for_each(state, &ws->focus_list, link)
if (state->seat == seat)
break;
if (&state->link == &ws->focus_list)
state = focus_state_create(shell, seat, ws);
return state;
}
static void
focus_state_set_focus(struct focus_state *state,
struct weston_surface *surface)
{
if (state->keyboard_focus) {
wl_list_remove(&state->surface_destroy_listener.link);
wl_list_init(&state->surface_destroy_listener.link);
}
state->keyboard_focus = surface;
if (surface)
wl_signal_add(&surface->destroy_signal,
&state->surface_destroy_listener);
}
static void
drop_focus_state(struct desktop_shell *shell, struct workspace *ws,
struct weston_surface *surface)
{
struct focus_state *state;
wl_list_for_each(state, &ws->focus_list, link)
if (state->keyboard_focus == surface)
focus_state_set_focus(state, NULL);
}
static void
workspace_destroy(struct workspace *ws)
{
struct focus_state *state, *next;
wl_list_for_each_safe(state, next, &ws->focus_list, link)
focus_state_destroy(state);
free(ws);
}
static void
seat_destroyed(struct wl_listener *listener, void *data)
{
struct weston_seat *seat = data;
struct focus_state *state, *next;
struct workspace *ws = container_of(listener,
struct workspace,
seat_destroyed_listener);
wl_list_for_each_safe(state, next, &ws->focus_list, link)
if (state->seat == seat)
wl_list_remove(&state->link);
}
static struct workspace *
workspace_create(struct desktop_shell *shell)
{
struct workspace *ws = malloc(sizeof *ws);
if (ws == NULL)
return NULL;
weston_layer_init(&ws->layer, shell->compositor);
wl_list_init(&ws->focus_list);
wl_list_init(&ws->seat_destroyed_listener.link);
ws->seat_destroyed_listener.notify = seat_destroyed;
return ws;
}
static struct workspace *
get_workspace(struct desktop_shell *shell, unsigned int index)
{
struct workspace **pws = shell->workspaces.array.data;
assert(index < shell->workspaces.num);
pws += index;
return *pws;
}
struct workspace *
get_current_workspace(struct desktop_shell *shell)
{
return get_workspace(shell, shell->workspaces.current);
}
static void
activate_workspace(struct desktop_shell *shell, unsigned int index)
{
struct workspace *ws;
ws = get_workspace(shell, index);
weston_layer_set_position(&ws->layer, WESTON_LAYER_POSITION_NORMAL);
shell->workspaces.current = index;
}
static void
surface_keyboard_focus_lost(struct weston_surface *surface)
{
struct weston_compositor *compositor = surface->compositor;
struct weston_seat *seat;
struct weston_surface *focus;
wl_list_for_each(seat, &compositor->seat_list, link) {
struct weston_keyboard *keyboard =
weston_seat_get_keyboard(seat);
if (!keyboard)
continue;
focus = weston_surface_get_main_surface(keyboard->focus);
if (focus == surface)
weston_keyboard_set_focus(keyboard, NULL);
}
}
static void
touch_move_grab_down(struct weston_touch_grab *grab,
const struct timespec *time,
int touch_id, wl_fixed_t x, wl_fixed_t y)
{
}
static void
touch_move_grab_up(struct weston_touch_grab *grab, const struct timespec *time,
int touch_id)
{
struct weston_touch_move_grab *move =
(struct weston_touch_move_grab *) container_of(
grab, struct shell_touch_grab, grab);
if (touch_id == 0)
move->active = 0;
if (grab->touch->num_tp == 0) {
shell_touch_grab_end(&move->base);
free(move);
}
}
static void
touch_move_grab_motion(struct weston_touch_grab *grab,
const struct timespec *time, int touch_id,
wl_fixed_t x, wl_fixed_t y)
{
struct weston_touch_move_grab *move = (struct weston_touch_move_grab *) grab;
struct shell_surface *shsurf = move->base.shsurf;
struct weston_surface *es;
int dx = wl_fixed_to_int(grab->touch->grab_x + move->dx);
int dy = wl_fixed_to_int(grab->touch->grab_y + move->dy);
if (!shsurf || !move->active)
return;
es = weston_desktop_surface_get_surface(shsurf->desktop_surface);
weston_view_set_position(shsurf->view, dx, dy);
weston_compositor_schedule_repaint(es->compositor);
}
static void