-
Notifications
You must be signed in to change notification settings - Fork 2
/
HaikuSeat.cpp
657 lines (615 loc) · 20.9 KB
/
HaikuSeat.cpp
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
#include "HaikuSeat.h"
#include "HaikuCompositor.h"
#include "HaikuXdgSurface.h"
#include "HaikuXdgToplevel.h"
#include "HaikuDataDeviceManager.h"
#include "WaylandKeycodes.h"
#include "XkbKeymap.h"
#include <SupportDefs.h>
#include <Application.h>
#include <Window.h>
#include <View.h>
#include <Cursor.h>
#include <Autolock.h>
#include "AppKitPtrs.h"
#include <stdio.h>
#include <algorithm>
extern const struct wl_interface wl_seat_interface;
enum {
SEAT_VERSION = 8,
};
static HaikuSeatGlobal *sHaikuSeat = NULL;
uint32_t FromHaikuKeyCode(uint32 haikuKey)
{
uint32_t wlKey;
switch (haikuKey) {
case 0x01: wlKey = KEY_ESC; break;
case 0x02: wlKey = KEY_F1; break;
case 0x03: wlKey = KEY_F2; break;
case 0x04: wlKey = KEY_F3; break;
case 0x05: wlKey = KEY_F4; break;
case 0x06: wlKey = KEY_F5; break;
case 0x07: wlKey = KEY_F6; break;
case 0x08: wlKey = KEY_F7; break;
case 0x09: wlKey = KEY_F8; break;
case 0x0a: wlKey = KEY_F9; break;
case 0x0b: wlKey = KEY_F10; break;
case 0x0c: wlKey = KEY_F11; break;
case 0x0d: wlKey = KEY_F12; break;
case 0x0e: wlKey = KEY_SYSRQ; break;
case 0x0f: wlKey = KEY_SCROLLLOCK; break;
case 0x10: wlKey = KEY_PAUSE; break;
case 0x11: wlKey = KEY_GRAVE; break;
case 0x12: wlKey = KEY_1; break;
case 0x13: wlKey = KEY_2; break;
case 0x14: wlKey = KEY_3; break;
case 0x15: wlKey = KEY_4; break;
case 0x16: wlKey = KEY_5; break;
case 0x17: wlKey = KEY_6; break;
case 0x18: wlKey = KEY_7; break;
case 0x19: wlKey = KEY_8; break;
case 0x1a: wlKey = KEY_9; break;
case 0x1b: wlKey = KEY_0; break;
case 0x1c: wlKey = KEY_MINUS; break;
case 0x1d: wlKey = KEY_EQUAL; break;
case 0x1e: wlKey = KEY_BACKSPACE; break;
case 0x1f: wlKey = KEY_INSERT; break;
case 0x20: wlKey = KEY_HOME; break;
case 0x21: wlKey = KEY_PAGEUP; break;
case 0x22: wlKey = KEY_NUMLOCK; break;
case 0x23: wlKey = KEY_KPSLASH; break;
case 0x24: wlKey = KEY_KPASTERISK; break;
case 0x25: wlKey = KEY_KPMINUS; break;
case 0x26: wlKey = KEY_TAB; break;
case 0x27: wlKey = KEY_Q; break;
case 0x28: wlKey = KEY_W; break;
case 0x29: wlKey = KEY_E; break;
case 0x2a: wlKey = KEY_R; break;
case 0x2b: wlKey = KEY_T; break;
case 0x2c: wlKey = KEY_Y; break;
case 0x2d: wlKey = KEY_U; break;
case 0x2e: wlKey = KEY_I; break;
case 0x2f: wlKey = KEY_O; break;
case 0x30: wlKey = KEY_P; break;
case 0x31: wlKey = KEY_LEFTBRACE; break;
case 0x32: wlKey = KEY_RIGHTBRACE; break;
case 0x33: wlKey = KEY_BACKSLASH; break;
case 0x34: wlKey = KEY_DELETE; break;
case 0x35: wlKey = KEY_END; break;
case 0x36: wlKey = KEY_PAGEDOWN; break;
case 0x37: wlKey = KEY_KP7; break;
case 0x38: wlKey = KEY_KP8; break;
case 0x39: wlKey = KEY_KP9; break;
case 0x3a: wlKey = KEY_KPPLUS; break;
case 0x3b: wlKey = KEY_CAPSLOCK; break;
case 0x3c: wlKey = KEY_A; break;
case 0x3d: wlKey = KEY_S; break;
case 0x3e: wlKey = KEY_D; break;
case 0x3f: wlKey = KEY_F; break;
case 0x40: wlKey = KEY_G; break;
case 0x41: wlKey = KEY_H; break;
case 0x42: wlKey = KEY_J; break;
case 0x43: wlKey = KEY_K; break;
case 0x44: wlKey = KEY_L; break;
case 0x45: wlKey = KEY_SEMICOLON; break;
case 0x46: wlKey = KEY_APOSTROPHE; break;
case 0x47: wlKey = KEY_ENTER; break;
case 0x48: wlKey = KEY_KP4; break;
case 0x49: wlKey = KEY_KP5; break;
case 0x4a: wlKey = KEY_KP6; break;
case 0x4b: wlKey = KEY_LEFTSHIFT; break;
case 0x4c: wlKey = KEY_Z; break;
case 0x4d: wlKey = KEY_X; break;
case 0x4e: wlKey = KEY_C; break;
case 0x4f: wlKey = KEY_V; break;
case 0x50: wlKey = KEY_B; break;
case 0x51: wlKey = KEY_N; break;
case 0x52: wlKey = KEY_M; break;
case 0x53: wlKey = KEY_COMMA; break;
case 0x54: wlKey = KEY_DOT; break;
case 0x55: wlKey = KEY_SLASH; break;
case 0x56: wlKey = KEY_RIGHTSHIFT; break;
case 0x57: wlKey = KEY_UP; break;
case 0x58: wlKey = KEY_KP1; break;
case 0x59: wlKey = KEY_KP2; break;
case 0x5a: wlKey = KEY_KP3; break;
case 0x5b: wlKey = KEY_KPENTER; break;
case 0x5c: wlKey = KEY_LEFTCTRL; break;
case 0x5d: wlKey = KEY_LEFTALT; break;
case 0x5e: wlKey = KEY_SPACE; break;
case 0x5f: wlKey = KEY_RIGHTALT; break;
case 0x60: wlKey = KEY_RIGHTCTRL; break;
case 0x61: wlKey = KEY_LEFT; break;
case 0x62: wlKey = KEY_DOWN; break;
case 0x63: wlKey = KEY_RIGHT; break;
case 0x64: wlKey = KEY_KP0; break;
case 0x65: wlKey = KEY_KPDOT; break;
case 0x66: wlKey = KEY_LEFTMETA; break;
case 0x67: wlKey = KEY_RIGHTMETA; break;
case 0x68: wlKey = KEY_COMPOSE; break;
case 0x69: wlKey = KEY_102ND; break;
case 0x6a: wlKey = KEY_YEN; break;
case 0x6b: wlKey = KEY_RO; break;
default:
//fprintf(stderr, "[!] unknown key: %#x\n", haikuKey);
wlKey = 0;
}
return wlKey;
}
static uint32_t FromHaikuMouseBtnCode(uint32 haikuBtn)
{
uint32_t wlBtn;
switch (haikuBtn) {
case 0: wlBtn = BTN_LEFT; break;
case 1: wlBtn = BTN_RIGHT; break;
case 2: wlBtn = BTN_MIDDLE; break;
case 3: wlBtn = BTN_FORWARD; break;
case 4: wlBtn = BTN_BACK; break;
default: wlBtn = 0;
}
return wlBtn;
}
static uint32_t FromHaikuModifiers(uint32 haikuModifiers)
{
uint32_t wlModifiers = 0;
if (B_SHIFT_KEY & haikuModifiers) wlModifiers |= (1 << 0);
if (B_COMMAND_KEY & haikuModifiers) wlModifiers |= (1 << 2);
if (B_CONTROL_KEY & haikuModifiers) wlModifiers |= (1 << 3) | (1 << 18);
if (B_CAPS_LOCK & haikuModifiers) wlModifiers |= (1 << 1);
if (B_NUM_LOCK & haikuModifiers) wlModifiers |= (1 << 4);
return wlModifiers;
}
class SurfaceCursorHook: public HaikuSurface::Hook {
public:
BPoint fHotspot;
void HandleCommit() final;
};
void SurfaceCursorHook::HandleCommit()
{
BBitmap *bitmap = Base()->Bitmap();
if (bitmap != NULL) {
BCursor cursor(bitmap, fHotspot);
AppKitPtrs::LockedPtr(be_app)->SetCursor(&cursor);
} else {
be_app->SetCursor(B_CURSOR_SYSTEM_DEFAULT, true);
}
}
//#pragma mark - HaikuPointer
HaikuPointer::~HaikuPointer()
{
fGlobal->fPointerIfaces.Remove(this);
}
void HaikuPointer::HandleSetCursor(uint32_t serial, struct wl_resource *_surface, int32_t hotspot_x, int32_t hotspot_y)
{
HaikuSurface *surface = HaikuSurface::FromResource(_surface);
if (surface != NULL) {
SurfaceCursorHook *hook = new SurfaceCursorHook();
hook->fHotspot = BPoint(hotspot_x, hotspot_y);
surface->SetHook(hook);
}
}
HaikuKeyboard::~HaikuKeyboard()
{
fGlobal->fKeyboardIfaces.Remove(this);
}
//#pragma mark - HaikuSeat
HaikuSeatGlobal *HaikuSeatGlobal::Create(struct wl_display *display)
{
ObjectDeleter<HaikuSeatGlobal> global(new(std::nothrow) HaikuSeatGlobal());
if (!global.IsSet()) return NULL;
if (!global->Init(display, &wl_seat_interface, SEAT_VERSION)) return NULL;
sHaikuSeat = global.Get();
return global.Detach();
}
void HaikuSeatGlobal::Bind(struct wl_client *wl_client, uint32_t version, uint32_t id)
{
HaikuSeat *seat = new(std::nothrow) HaikuSeat(this);
if (seat == NULL) {
wl_client_post_no_memory(wl_client);
return;
}
if (!seat->Init(wl_client, version, id)) {
return;
}
seat->SendCapabilities(WlSeat::capabilityPointer | WlSeat::capabilityKeyboard);
}
uint32_t HaikuSeatGlobal::NextSerial()
{
return (uint32_t)atomic_add((int32*)&fSerial, 1);
}
void HaikuSeatGlobal::SetPointerFocus(HaikuSurface *surface, const BMessage &msg, TrackId trackId)
{
if (surface == NULL) trackId = trackNone;
if (fPointerFocus == surface && fTrack.id == trackId) {
return;
}
if (fPointerFocus != NULL) {
switch (fTrack.id) {
case trackClient:
for (HaikuPointer *pointer = fPointerIfaces.First(); pointer != NULL; pointer = fPointerIfaces.GetNext(pointer)) {
if (pointer->Client() != fPointerFocus->Client()) continue;
pointer->SendLeave(NextSerial(), fPointerFocus->ToResource());
pointer->SendFrame();
}
break;
case trackDrag:
fDataDevice->SendLeave();
break;
}
}
if (surface == NULL) {
fTrack.captured = false;
fTrack.inside = false;
}
if (fPointerFocus != surface) {
if (surface == NULL || msg.FindInt32("buttons", (int32*)&fOldMouseBtns) < B_OK) fOldMouseBtns = 0;
}
fPointerFocus = surface;
fTrack.id = trackId;
if (fPointerFocus != NULL) {
BPoint where;
if (msg.WasDropped()) {
where = msg.DropPoint();
AppKitPtrs::LockedPtr(fPointerFocus->View())->ConvertFromScreen(&where);
} else if (msg.FindPoint("be:view_where", &where) < B_OK) where = B_ORIGIN;
switch (fTrack.id) {
case trackClient:
for (HaikuPointer *pointer = fPointerIfaces.First(); pointer != NULL; pointer = fPointerIfaces.GetNext(pointer)) {
if (pointer->Client() != surface->Client()) continue;
pointer->SendEnter(NextSerial(), surface->ToResource(), wl_fixed_from_double(where.x), wl_fixed_from_double(where.y));
pointer->SendFrame();
}
break;
case trackDrag: {
BMessage data;
msg.FindMessage("be:drag_message", &data);
HaikuDataOffer *dataOffer = HaikuDataOffer::Create(fDataDevice, data);
fDataDevice->SendEnter(NextSerial(), fPointerFocus->ToResource(), wl_fixed_from_double(where.x), wl_fixed_from_double(where.y), dataOffer->ToResource());
break;
}
}
}
}
void HaikuSeatGlobal::SetPointerFocus(HaikuSurface *surface, bool setFocus, const BMessage &msg, TrackId trackId)
{
if (setFocus) {
SetPointerFocus(surface, msg, trackId);
} else if (fPointerFocus == surface) {
SetPointerFocus(NULL, msg, trackId);
}
}
void HaikuSeatGlobal::SetKeyboardFocus(HaikuSurface *surface, bool setFocus)
{
if (setFocus) {
if (fKeyboardFocus != surface) {
if (fKeyboardFocus != NULL) {
if (fTextInput != NULL) {
fTextInput->Leave(fKeyboardFocus);
}
for (HaikuKeyboard *keyboard = fKeyboardIfaces.First(); keyboard != NULL; keyboard = fKeyboardIfaces.GetNext(keyboard)) {
if (keyboard->Client() != fKeyboardFocus->Client()) continue;
keyboard->SendLeave(NextSerial(), fKeyboardFocus->ToResource());
}
}
fKeyboardFocus = surface;
struct wl_array keys{};
for (HaikuKeyboard *keyboard = fKeyboardIfaces.First(); keyboard != NULL; keyboard = fKeyboardIfaces.GetNext(keyboard)) {
if (keyboard->Client() != surface->Client()) continue;
keyboard->SendEnter(NextSerial(), surface->ToResource(), &keys);
}
if (fTextInput != NULL) {
fTextInput->Enter(surface);
}
}
} else if (fKeyboardFocus == surface) {
if (fTextInput != NULL) {
fTextInput->Leave(surface);
}
for (HaikuKeyboard *keyboard = fKeyboardIfaces.First(); keyboard != NULL; keyboard = fKeyboardIfaces.GetNext(keyboard)) {
if (keyboard->Client() != fKeyboardFocus->Client()) continue;
keyboard->SendLeave(NextSerial(), fKeyboardFocus->ToResource());
}
fKeyboardFocus = NULL;
}
}
void HaikuSeatGlobal::DoTrack(TrackId id, const TrackInfo &info)
{
if (fTrack.id != trackClient || fOldMouseBtns == 0 || fPointerFocus == NULL) return;
SetPointerFocus(fPointerFocus, BMessage(), id);
fTrack.info = info;
switch (id) {
case trackResize: {
auto geometry = fPointerFocus->XdgSurface()->Geometry();
fTrack.wndWidth = geometry.width;
fTrack.wndHeight = geometry.height;
break;
}
}
}
bool HaikuSeatGlobal::MessageReceived(HaikuSurface *surface, BMessage *msg)
{
if (msg->WasDropped()) {
fprintf(stderr, "WasDropped, (fPointerFocus == surface: %d, fTrack.id == trackDrag: %d)\n", fPointerFocus == surface, fTrack.id == trackDrag);
if (fPointerFocus == surface && fTrack.id == trackDrag) {
fDataDevice->SendDrop();
fTrack.captured = false;
SetPointerFocus(surface, true, *msg, trackClient);
}
return true;
}
if (msg->what == B_MOUSE_MOVED) {
int32 transit;
msg->FindInt32("be:transit", &transit);
if (!fTrack.captured) {
switch (transit) {
case B_ENTERED_VIEW:
case B_INSIDE_VIEW: {
BPoint where;
msg->FindPoint("be:view_where", &where);
bool isDrag = msg->HasMessage("be:drag_message");
SetPointerFocus(surface, true, *msg, isDrag ? trackDrag : trackClient);
fTrack.captured = isDrag;
break;
}
case B_EXITED_VIEW:
SetPointerFocus(surface, false, BMessage());
break;
}
}
if (fPointerFocus == surface) {
switch (transit) {
case B_ENTERED_VIEW:
case B_INSIDE_VIEW:
fTrack.inside = true;
break;
case B_EXITED_VIEW:
case B_OUTSIDE_VIEW:
fTrack.inside = false;
if (fTrack.id == trackDrag) {
fTrack.captured = false;
SetPointerFocus(surface, false, BMessage());
}
break;
}
}
}
switch (msg->what) {
case B_KEY_DOWN:
case B_KEY_UP:
case B_UNMAPPED_KEY_DOWN:
case B_UNMAPPED_KEY_UP: {
if (fKeyboardFocus != surface) return false;
int32 key;
msg->FindInt32("key", &key);
uint32_t state = (msg->what == B_KEY_UP || msg->what == B_UNMAPPED_KEY_UP) ? WlKeyboard::keyStateReleased : WlKeyboard::keyStatePressed;
uint32_t wlKey = FromHaikuKeyCode(key);
for (HaikuKeyboard *keyboard = fKeyboardIfaces.First(); keyboard != NULL; keyboard = fKeyboardIfaces.GetNext(keyboard)) {
if (keyboard->Client() != fKeyboardFocus->Client()) continue;
keyboard->SendKey(NextSerial(), system_time()/1000, wlKey, state);
}
return true;
}
case B_MODIFIERS_CHANGED: {
if (fKeyboardFocus != surface) return false;
uint32 modifiers;
if (msg->FindInt32("modifiers", (int32*)&modifiers) < B_OK) modifiers = 0;
for (HaikuKeyboard *keyboard = fKeyboardIfaces.First(); keyboard != NULL; keyboard = fKeyboardIfaces.GetNext(keyboard)) {
if (keyboard->Client() != fKeyboardFocus->Client()) continue;
keyboard->SendModifiers(NextSerial(), FromHaikuModifiers(modifiers), 0, 0, 0);
}
return true;
}
case B_MOUSE_WHEEL_CHANGED: {
if (fPointerFocus != surface) return false;
bigtime_t when;
float dx, dy;
if (msg->FindInt64("when", &when) < B_OK) when = system_time();
if (msg->FindFloat("be:wheel_delta_x", &dx) < B_OK) dx = 0;
if (msg->FindFloat("be:wheel_delta_y", &dy) < B_OK) dy = 0;
if (dx != 0) {
for (HaikuPointer *pointer = fPointerIfaces.First(); pointer != NULL; pointer = fPointerIfaces.GetNext(pointer)) {
if (pointer->Client() != fPointerFocus->Client()) continue;
pointer->SendAxisSource(WlPointer::axisSourceWheel);
pointer->SendAxis(when/1000, WlPointer::axisHorizontalScroll, wl_fixed_from_double(dx*10.0));
pointer->SendAxisDiscrete(WlPointer::axisHorizontalScroll, dx);
}
}
if (dy != 0) {
for (HaikuPointer *pointer = fPointerIfaces.First(); pointer != NULL; pointer = fPointerIfaces.GetNext(pointer)) {
if (pointer->Client() != fPointerFocus->Client()) continue;
pointer->SendAxisSource(WlPointer::axisSourceWheel);
pointer->SendAxis(when/1000, WlPointer::axisVerticalScroll, wl_fixed_from_double(dy*10.0));
pointer->SendAxisDiscrete(WlPointer::axisVerticalScroll, dy);
}
}
for (HaikuPointer *pointer = fPointerIfaces.First(); pointer != NULL; pointer = fPointerIfaces.GetNext(pointer)) {
if (pointer->Client() != fPointerFocus->Client()) continue;
pointer->SendFrame();
}
return true;
}
case B_MOUSE_DOWN: {
if (fPointerFocus != surface) return false;
bigtime_t when;
BPoint where;
uint32 btns;
msg->FindInt64("when", &when);
msg->FindPoint("be:view_where", &where);
msg->FindInt32("buttons", (int32*)&btns);
uint32 oldBtns = fOldMouseBtns;
if (oldBtns == 0 && btns != 0) {
fTrack.captured = true;
fTrack.origin = where;
AppKitPtrs::LockedPtr(surface->View())->SetMouseEventMask(B_POINTER_EVENTS);
}
fOldMouseBtns = btns;
switch (fTrack.id) {
case trackNone:
case trackClient: {
uint32 btnsDown = btns & (~oldBtns);
for (uint32 i = 0; i < 32; i++) {
if (((1 << i) & btnsDown) != 0) {
for (HaikuPointer *pointer = fPointerIfaces.First(); pointer != NULL; pointer = fPointerIfaces.GetNext(pointer)) {
if (pointer->Client() != fPointerFocus->Client()) continue;
pointer->SendButton(NextSerial(), when/1000, FromHaikuMouseBtnCode(i), WlPointer::buttonStatePressed);
}
}
}
for (HaikuPointer *pointer = fPointerIfaces.First(); pointer != NULL; pointer = fPointerIfaces.GetNext(pointer)) {
if (pointer->Client() != fPointerFocus->Client()) continue;
pointer->SendFrame();
}
break;
}
}
return true;
}
case B_MOUSE_UP: {
if (fPointerFocus != surface) return false;
bigtime_t when;
uint32 btns;
msg->FindInt64("when", &when);
msg->FindInt32("buttons", (int32*)&btns);
uint32 oldBtns = fOldMouseBtns;
switch (fTrack.id) {
case trackNone:
case trackClient: {
uint32 btnsUp = oldBtns & (~btns);
for (uint32 i = 0; i < 32; i++) {
if (((1 << i) & btnsUp) != 0) {
for (HaikuPointer *pointer = fPointerIfaces.First(); pointer != NULL; pointer = fPointerIfaces.GetNext(pointer)) {
if (pointer->Client() != fPointerFocus->Client()) continue;
pointer->SendButton(NextSerial(), when/1000, FromHaikuMouseBtnCode(i), WlPointer::buttonStateReleased);
}
}
}
for (HaikuPointer *pointer = fPointerIfaces.First(); pointer != NULL; pointer = fPointerIfaces.GetNext(pointer)) {
if (pointer->Client() != fPointerFocus->Client()) continue;
pointer->SendFrame();
}
break;
}
}
if (oldBtns != 0 && btns == 0 && fTrack.id != trackDrag) {
fTrack.captured = false;
}
if (!fTrack.captured) {
SetPointerFocus(surface, fTrack.inside, *msg);
}
fOldMouseBtns = btns;
return true;
}
case B_MOUSE_MOVED: {
if (fPointerFocus != surface) return false;
bigtime_t when;
BPoint where;
uint32 btns;
msg->FindInt64("when", &when);
msg->FindPoint("be:view_where", &where);
switch (fTrack.id) {
case trackNone:
case trackClient: {
for (HaikuPointer *pointer = fPointerIfaces.First(); pointer != NULL; pointer = fPointerIfaces.GetNext(pointer)) {
if (pointer->Client() != fPointerFocus->Client()) continue;
pointer->SendMotion(when / 1000, wl_fixed_from_double(where.x), wl_fixed_from_double(where.y));
pointer->SendFrame();
}
break;
}
case trackDrag: {
fDataDevice->SendMotion(when / 1000, wl_fixed_from_double(where.x), wl_fixed_from_double(where.y));
break;
}
case trackMove: {
fPointerFocus->View()->Window()->MoveBy(where.x - fTrack.origin.x, where.y - fTrack.origin.y);
break;
}
case trackResize: {
switch (fTrack.info.resizeEdge) {
case XdgToplevel::resizeEdgeTopLeft: {
HaikuXdgSurface *xdgSurface = fPointerFocus->XdgSurface();
HaikuXdgSurface::GeometryInfo oldGeometry = xdgSurface->Geometry();
if (!xdgSurface->SetConfigurePending()) true;
fPointerFocus->View()->Window()->MoveBy(where.x - fTrack.origin.x, where.y - fTrack.origin.y);
struct wl_array array{};
xdgSurface->Toplevel()->SendConfigure(fTrack.wndWidth - (where.x - fTrack.origin.x), fTrack.wndHeight - (where.y - fTrack.origin.y), &array);
fTrack.wndWidth -= where.x - fTrack.origin.x;
fTrack.wndHeight -= where.y - fTrack.origin.y;
xdgSurface->SendConfigure(xdgSurface->NextSerial());
break;
}
case XdgToplevel::resizeEdgeBottomRight: {
HaikuXdgSurface *xdgSurface = fPointerFocus->XdgSurface();
HaikuXdgSurface::GeometryInfo oldGeometry = xdgSurface->Geometry();
if (!xdgSurface->SetConfigurePending()) true;
int32_t minWidth, minHeight;
int32_t maxWidth, maxHeight;
xdgSurface->Toplevel()->MinSize(minWidth, minHeight);
xdgSurface->Toplevel()->MaxSize(maxWidth, maxHeight);
if (maxWidth == 0) maxWidth = INT32_MAX;
if (maxHeight == 0) maxHeight = INT32_MAX;
int32_t newWidth = std::min<int32_t>(std::max<int32_t>(fTrack.wndWidth + (where.x - fTrack.origin.x), minWidth), maxWidth);
int32_t newHeight = std::min<int32_t>(std::max<int32_t>(fTrack.wndHeight + (where.y - fTrack.origin.y), minHeight), maxHeight);
struct wl_array array{};
xdgSurface->Toplevel()->SendConfigure(newWidth, newHeight, &array);
xdgSurface->SendConfigure(xdgSurface->NextSerial());
}
}
break;
}
}
return true;
}
}
if (fTextInput != NULL && fTextInput->MessageReceived(surface, msg)) {
return true;
}
return false;
}
void HaikuSeatGlobal::UpdateKeymap()
{
int fd;
if (ProduceXkbKeymap(fd) < B_OK) {
fprintf(stderr, "[!] ProduceXkbKeymap failed\n");
return;
}
FileDescriptorCloser fdCloser(fd);
struct stat st{};
fstat(fd, &st);
for (HaikuKeyboard *keyboard = fKeyboardIfaces.First(); keyboard != NULL; keyboard = fKeyboardIfaces.GetNext(keyboard)) {
keyboard->SendKeymap(WlKeyboard::keymapFormatXkbV1, fd, st.st_size);
}
}
void HaikuSeat::HandleGetPointer(uint32_t id)
{
HaikuPointer *pointer = new(std::nothrow) HaikuPointer(fGlobal);
if (pointer == NULL) {
wl_client_post_no_memory(Client());
return;
}
if (!pointer->Init(Client(), Version(), id)) {
return;
}
fGlobal->fPointerIfaces.Insert(pointer);
}
void HaikuSeat::HandleGetKeyboard(uint32_t id)
{
HaikuKeyboard *keyboard = new(std::nothrow) HaikuKeyboard(fGlobal);
if (keyboard == NULL) {
wl_client_post_no_memory(Client());
return;
}
if (!keyboard->Init(Client(), Version(), id)) {
return;
}
fGlobal->fKeyboardIfaces.Insert(keyboard);
fGlobal->UpdateKeymap();
}
void HaikuSeat::HandleGetTouch(uint32_t id)
{
abort();
}
HaikuSeatGlobal *HaikuGetSeat(struct wl_client *wl_client)
{
return sHaikuSeat;
}