efl

Форк
0
/
elput_input.c 
939 строк · 24.1 Кб
1
/* this file contains code copied from weston; the copyright notice is below */
2
/*
3
 * Copyright © 2013 Intel Corporation
4
 *
5
 * Permission is hereby granted, free of charge, to any person obtaining
6
 * a copy of this software and associated documentation files (the
7
 * "Software"), to deal in the Software without restriction, including
8
 * without limitation the rights to use, copy, modify, merge, publish,
9
 * distribute, sublicense, and/or sell copies of the Software, and to
10
 * permit persons to whom the Software is furnished to do so, subject to
11
 * the following conditions:
12
 *
13
 * The above copyright notice and this permission notice (including the
14
 * next paragraph) shall be included in all copies or substantial
15
 * portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
 * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
 * SOFTWARE.
25
 */
26

27
#include "elput_private.h"
28
#include <libudev.h>
29

30
static int
31
_cb_open_restricted(const char *path, int flags, void *data)
32
{
33
   Elput_Manager *em = data;
34
   int ret = -1;
35
   Elput_Async_Open *ao;
36
   int p[2];
37

38
   if (!em->input.thread)
39
     return em->interface->open(em, path, flags);
40
   if (!em->interface->open_async) return ret;
41
   if (ecore_thread_check(em->input.thread)) return ret;
42
   ao = calloc(1, sizeof(Elput_Async_Open));
43
   if (!ao) return ret;
44
   if (pipe2(p, O_CLOEXEC) < 0)
45
     {
46
        free(ao);
47
        return ret;
48
     }
49
   ao->manager = em;
50
   ao->path = strdup(path);
51
   ao->flags = flags;
52
   em->input.pipe = p[1];
53
   ecore_thread_feedback(em->input.thread, ao);
54
   while (!ecore_thread_check(em->input.thread))
55
     {
56
        int avail, fd;
57
        fd_set rfds, wfds, exfds;
58
        struct timeval tv, *t;
59

60
        FD_ZERO(&rfds);
61
        FD_ZERO(&wfds);
62
        FD_ZERO(&exfds);
63
        FD_SET(p[0], &rfds);
64
        tv.tv_sec = 0;
65
        tv.tv_usec = 300;
66
        t = &tv;
67
        avail = select(p[0] + 1, &rfds, &wfds, &exfds, t);
68
        if (avail > 0)
69
          {
70
             if (read(p[0], &fd, sizeof(int)) < 1)
71
               ret = -1;
72
             else
73
               ret = fd;
74
             break;
75
          }
76
        if (avail < 0) break;
77
     }
78
   close(p[0]);
79
   return ret;
80
}
81

82
static void
83
_cb_close_restricted(int fd, void *data)
84
{
85
   Elput_Manager *em;
86

87
   em = data;
88
   elput_manager_close(em, fd);
89
}
90

91
const struct libinput_interface _input_interface =
92
{
93
   _cb_open_restricted,
94
   _cb_close_restricted,
95
};
96

97
static Elput_Seat *
98
_udev_seat_create(Elput_Manager *em, const char *name)
99
{
100
   Elput_Seat *eseat;
101

102
   eseat = calloc(1, sizeof(Elput_Seat));
103
   if (!eseat) return NULL;
104

105
   eseat->manager = em;
106
   eseat->refs = 1;
107

108
   eseat->name = eina_stringshare_add(name);
109
   em->input.seats = eina_list_append(em->input.seats, eseat);
110

111
   return eseat;
112
}
113

114
void
115
_udev_seat_destroy(Elput_Seat *eseat)
116
{
117
   Elput_Device *edev;
118

119
   eseat->refs--;
120
   if (eseat->refs) return;
121

122
   EINA_LIST_FREE(eseat->devices, edev)
123
     _evdev_device_destroy(edev);
124

125
   if (eseat->kbd) _evdev_keyboard_destroy(eseat->kbd);
126
   eseat->kbd = NULL;
127
   if (eseat->ptr) _evdev_pointer_destroy(eseat->ptr);
128
   eseat->ptr = NULL;
129
   if (eseat->touch) _evdev_touch_destroy(eseat->touch);
130
   eseat->touch = NULL;
131
   if (eseat->manager->input.seats)
132
     eseat->manager->input.seats = eina_list_remove(eseat->manager->input.seats, eseat);
133
   if (eseat->refs) return;
134

135
   eina_stringshare_del(eseat->name);
136
   free(eseat);
137
}
138

139
static Elput_Seat *
140
_udev_seat_named_get(Elput_Manager *em, const char *name)
141
{
142
   Elput_Seat *eseat;
143
   Eina_List *l;
144

145
   if (!name) name = "seat0";
146

147
   EINA_LIST_FOREACH(em->input.seats, l, eseat)
148
     if (!strcmp(eseat->name, name)) return eseat;
149

150
   eseat = _udev_seat_create(em, name);
151
   if (!eseat) return NULL;
152

153
   return eseat;
154
}
155

156
static Elput_Seat *
157
_udev_seat_get(Elput_Manager *em, struct libinput_device *device)
158
{
159
   struct libinput_seat *lseat;
160
   const char *name;
161

162
   lseat = libinput_device_get_seat(device);
163
   name = libinput_seat_get_physical_name(lseat);
164

165
   return _udev_seat_named_get(em, name);
166
}
167

168
static void
169
_device_event_cb_free(void *data EINA_UNUSED, void *event)
170
{
171
   Elput_Event_Device_Change *ev;
172

173
   ev = event;
174

175
   ev->device->refs--;
176
   if (ev->type == ELPUT_DEVICE_REMOVED)
177
     {
178
        Elput_Seat *seat;
179

180
        seat = ev->device->seat;
181
        if (seat)
182
          seat->devices = eina_list_remove(seat->devices, ev->device);
183

184
        _evdev_device_destroy(ev->device);
185
     }
186

187
   free(ev);
188
}
189

190
static void
191
_device_event_send(Elput_Device *edev, Elput_Device_Change_Type type)
192
{
193
   Elput_Event_Device_Change *ev;
194

195
   ev = calloc(1, sizeof(Elput_Event_Device_Change));
196
   if (!ev) return;
197

198
   ev->device = edev;
199
   ev->type = type;
200
   edev->refs++;
201

202
   ecore_event_add(ELPUT_EVENT_DEVICE_CHANGE, ev, _device_event_cb_free, NULL);
203
}
204

205
static void
206
_device_add(Elput_Manager *em, struct libinput_device *dev)
207
{
208
   Elput_Seat *eseat;
209
   Elput_Device *edev;
210

211
   eseat = _udev_seat_get(em, dev);
212
   if (!eseat) return;
213

214
   edev = _evdev_device_create(eseat, dev);
215
   if (!edev) return;
216

217
   eseat->devices = eina_list_append(eseat->devices, edev);
218

219
   DBG("Input Device Added: %s", libinput_device_get_name(dev));
220

221
   if (edev->caps & ELPUT_DEVICE_CAPS_KEYBOARD)
222
     DBG("\tDevice added as Keyboard device");
223

224
   if (edev->caps & ELPUT_DEVICE_CAPS_POINTER)
225
     {
226
        DBG("\tDevice added as Pointer device");
227
        switch (em->input.rotation)
228
          {
229
           case 0:
230
             edev->swap = EINA_FALSE;
231
             edev->invert_x = EINA_FALSE;
232
             edev->invert_y = EINA_FALSE;
233
             break;
234
           case 90:
235
             edev->swap = EINA_TRUE;
236
             edev->invert_x = EINA_FALSE;
237
             edev->invert_y = EINA_TRUE;
238
             break;
239
           case 180:
240
             edev->swap = EINA_FALSE;
241
             edev->invert_x = EINA_TRUE;
242
             edev->invert_y = EINA_TRUE;
243
             break;
244
           case 270:
245
             edev->swap = EINA_TRUE;
246
             edev->invert_x = EINA_TRUE;
247
             edev->invert_y = EINA_FALSE;
248
             break;
249
           default:
250
             break;
251
          }
252
     }
253

254
   if (edev->caps & ELPUT_DEVICE_CAPS_TOUCH)
255
     {
256
        DBG("\tDevice added as Touch device");
257
     }
258

259
   _device_event_send(edev, ELPUT_DEVICE_ADDED);
260
}
261

262
static void
263
_device_remove(Elput_Manager *em EINA_UNUSED, struct libinput_device *device)
264
{
265
   Elput_Device *edev;
266

267
   edev = libinput_device_get_user_data(device);
268
   if (!edev) return;
269

270
   DBG("Input Device Removed: %s", libinput_device_get_name(device));
271

272
   _device_event_send(edev, ELPUT_DEVICE_REMOVED);
273
}
274

275
static int
276
_udev_process_event(struct libinput_event *event)
277
{
278
   Elput_Manager *em;
279
   struct libinput *lib;
280
   struct libinput_device *dev;
281
   int ret = 1;
282

283
   lib = libinput_event_get_context(event);
284
   dev = libinput_event_get_device(event);
285
   em = libinput_get_user_data(lib);
286

287
   switch (libinput_event_get_type(event))
288
     {
289
      case LIBINPUT_EVENT_DEVICE_ADDED:
290
        _device_add(em, dev);
291
        break;
292
      case LIBINPUT_EVENT_DEVICE_REMOVED:
293
        _device_remove(em, dev);
294
        break;
295
      default:
296
        ret = 0;
297
        break;
298
     }
299

300
   return ret;
301
}
302

303
static void
304
_process_event(Elput_Manager *em, struct libinput_event *event)
305
{
306
   if (_udev_process_event(event)) return;
307
   if (!em->only_gesture_events)
308
     {
309
        if (_evdev_event_process(event)) return;
310
     }
311
   if (_gesture_event_process(event)) return;
312
}
313

314
static void
315
_process_events(Elput_Manager *em)
316
{
317
   struct libinput_event *event;
318
   Elput_Input *ei;
319

320
   ei = &em->input;
321
   while ((ei->lib) && (event = libinput_get_event(ei->lib)))
322
     {
323
        _process_event(em, event);
324
        libinput_event_destroy(event);
325
     }
326
}
327

328
static Eina_Bool
329
_cb_input_dispatch(void *data, Ecore_Fd_Handler *hdlr EINA_UNUSED)
330
{
331
   Elput_Manager *em;
332

333
   em = data;
334

335
   if ((em->input.lib) && (libinput_dispatch(em->input.lib) != 0))
336
     WRN("libinput failed to dispatch events");
337

338
   _process_events(em);
339

340
   return EINA_TRUE;
341
}
342

343
static void
344
_elput_input_init_cancel(void *data, Ecore_Thread *eth EINA_UNUSED)
345
{
346
   Elput_Manager *manager;
347

348
   manager = data;
349
   manager->input.thread = NULL;
350
   if (manager->input.current_pending)
351
     {
352
        eldbus_pending_cancel(manager->input.current_pending);
353
        if (manager->input.pipe >= 0)
354
          close(manager->input.pipe);
355
     }
356
   if (manager->del)
357
     elput_manager_disconnect(manager);
358
}
359

360
static void
361
_elput_input_init_end(void *data, Ecore_Thread *eth EINA_UNUSED)
362
{
363
   Elput_Manager *manager;
364

365
   manager = data;
366
   manager->input.thread = NULL;
367
   if (!manager->input.lib) return;
368

369
   manager->input.hdlr =
370
     ecore_main_fd_handler_add(libinput_get_fd(manager->input.lib),
371
                               ECORE_FD_READ, _cb_input_dispatch,
372
                               manager, NULL, NULL);
373

374
   if (manager->input.hdlr)
375
      _process_events(manager);
376
   else
377
     {
378
        ERR("Could not create input fd handler");
379
        libinput_unref(manager->input.lib);
380
        manager->input.lib = NULL;
381
     }
382

383
   if ((manager->pending_ptr_x) || (manager->pending_ptr_y))
384
     {
385
        elput_input_pointer_xy_set(manager, NULL, manager->pending_ptr_x,
386
                                   manager->pending_ptr_y);
387
        manager->pending_ptr_x = 0;
388
        manager->pending_ptr_y = 0;
389
     }
390
}
391

392
static void
393
_elput_input_init_notify(void *data EINA_UNUSED, Ecore_Thread *eth EINA_UNUSED, void *msg_data)
394
{
395
   Elput_Async_Open *ao;
396

397
   ao = msg_data;
398
   ao->manager->interface->open_async(ao->manager, ao->path, ao->flags);
399
   free(ao->path);
400
   free(ao);
401
}
402

403
static void
404
_elput_input_init_thread(void *data, Ecore_Thread *eth EINA_UNUSED)
405
{
406
   Elput_Manager *manager;
407
   struct udev *udev;
408

409
   manager = data;
410
   udev = udev_new();
411

412
   manager->input.lib =
413
     libinput_udev_create_context(&_input_interface, manager, udev);
414
   if (!manager->input.lib)
415
     {
416
        ERR("libinput could not create udev context");
417
        return;
418
     }
419
   udev_unref(udev);
420

421
   if (libinput_udev_assign_seat(manager->input.lib, manager->seat))
422
     {
423
        ERR("libinput could not assign udev seat");
424
        libinput_unref(manager->input.lib);
425
        manager->input.lib = NULL;
426
     }
427
}
428

429
void
430
_elput_input_enable(Elput_Manager *manager)
431
{
432
   if (!manager->input.hdlr)
433
     {
434
        manager->input.hdlr =
435
          ecore_main_fd_handler_add(libinput_get_fd(manager->input.lib),
436
                                    ECORE_FD_READ, _cb_input_dispatch,
437
                                    &manager->input, NULL, NULL);
438
     }
439

440
   if (manager->input.suspended)
441
     {
442
        if (libinput_resume(manager->input.lib) != 0) return;
443
        manager->input.suspended = EINA_FALSE;
444
        _process_events(manager);
445
     }
446
}
447

448
void
449
_elput_input_disable(Elput_Manager *manager)
450
{
451
   Elput_Seat *seat;
452
   Eina_List *l;
453

454
   EINA_LIST_FOREACH(manager->input.seats, l, seat)
455
     seat->pending_motion = 1;
456
   if (manager->input.lib) libinput_suspend(manager->input.lib);
457
   _process_events(manager);
458
   manager->input.suspended = EINA_TRUE;
459
}
460

461
EAPI Eina_Bool
462
elput_input_init(Elput_Manager *manager)
463
{
464
   EINA_SAFETY_ON_NULL_RETURN_VAL(manager, EINA_FALSE);
465
   EINA_SAFETY_ON_TRUE_RETURN_VAL(!!manager->input.hdlr, EINA_TRUE);
466

467
   memset(&manager->input, 0, sizeof(Elput_Input));
468
   manager->input.thread =
469
     ecore_thread_feedback_run(_elput_input_init_thread,
470
                               _elput_input_init_notify,
471
                               _elput_input_init_end,
472
                               _elput_input_init_cancel, manager, 1);
473
   return !!manager->input.thread;
474
}
475

476
EAPI void
477
elput_input_shutdown(Elput_Manager *manager)
478
{
479
   Elput_Seat *seat;
480
   Eina_List *l, *ll;
481

482
   EINA_SAFETY_ON_NULL_RETURN(manager);
483

484
   ecore_main_fd_handler_del(manager->input.hdlr);
485

486
   EINA_LIST_FOREACH_SAFE(manager->input.seats, l, ll, seat)
487
     _udev_seat_destroy(seat);
488

489
   if (manager->input.thread)
490
     ecore_thread_cancel(manager->input.thread);
491
   else
492
     {
493
        libinput_unref(manager->input.lib);
494
        manager->input.lib = NULL;
495
     }
496
}
497

498
EAPI void
499
elput_input_pointer_xy_get(Elput_Manager *manager, const char *seat, int *x, int *y)
500
{
501
   Elput_Seat *eseat;
502
   Eina_List *l;
503

504
   if (x) *x = 0;
505
   if (y) *y = 0;
506

507
   EINA_SAFETY_ON_NULL_RETURN(manager);
508

509
   /* if no seat name is passed in, just use default seat name */
510
   if (!seat) seat = "seat0";
511

512
   EINA_LIST_FOREACH(manager->input.seats, l, eseat)
513
     {
514
        if (!eina_streq(eseat->name, seat)) continue;
515
        if (x) *x = eseat->pointer.x;
516
        if (y) *y = eseat->pointer.y;
517
        return;
518
     }
519
}
520

521
EAPI void
522
elput_input_pointer_xy_set(Elput_Manager *manager, const char *seat, int x, int y)
523
{
524
   Elput_Seat *eseat;
525
   Elput_Device *edev;
526
   Eina_List *l, *ll;
527

528
   EINA_SAFETY_ON_NULL_RETURN(manager);
529

530
   /* if no seat name is passed in, just use default seat name */
531
   if (!seat) seat = "seat0";
532

533
   if (eina_list_count(manager->input.seats) < 1)
534
     {
535
        manager->pending_ptr_x = x;
536
        manager->pending_ptr_y = y;
537
        return;
538
     }
539

540
   EINA_LIST_FOREACH(manager->input.seats, l, eseat)
541
     {
542
        if (!eseat->ptr) continue;
543
        if ((eseat->name) && (strcmp(eseat->name, seat)))
544
          continue;
545

546
        eseat->pointer.x = x;
547
        eseat->pointer.y = y;
548
        eseat->ptr->timestamp = ecore_loop_time_get();
549

550
        EINA_LIST_FOREACH(eseat->devices, ll, edev)
551
          {
552
             if (!libinput_device_has_capability(edev->device,
553
                                                 LIBINPUT_DEVICE_CAP_POINTER))
554
               continue;
555

556
             _evdev_pointer_motion_send(edev);
557
             break;
558
          }
559
     }
560
}
561

562
EAPI Eina_Bool
563
elput_input_pointer_left_handed_set(Elput_Manager *manager, const char *seat, Eina_Bool left)
564
{
565
   Elput_Seat *eseat;
566
   Elput_Device *edev;
567
   Eina_List *l, *ll;
568

569
   EINA_SAFETY_ON_NULL_RETURN_VAL(manager, EINA_FALSE);
570

571
   /* if no seat name is passed in, just use default seat name */
572
   if (!seat) seat = "seat0";
573

574
   EINA_LIST_FOREACH(manager->input.seats, l, eseat)
575
     {
576
        if ((eseat->name) && (strcmp(eseat->name, seat)))
577
          continue;
578

579
        EINA_LIST_FOREACH(eseat->devices, ll, edev)
580
          {
581
             if (!libinput_device_has_capability(edev->device,
582
                                                 LIBINPUT_DEVICE_CAP_POINTER))
583
               continue;
584

585
             if (edev->left_handed == left) continue;
586

587
             if (libinput_device_config_left_handed_set(edev->device,
588
                                                        (int)left) !=
589
                 LIBINPUT_CONFIG_STATUS_SUCCESS)
590
               {
591
                  WRN("Failed to set left handed mode for device: %s",
592
                      libinput_device_get_name(edev->device));
593
                  continue;
594
               }
595
             else
596
               edev->left_handed = !!left;
597
          }
598
     }
599

600
   return EINA_TRUE;
601
}
602

603
EAPI void
604
elput_input_pointer_max_set(Elput_Manager *manager, int maxw, int maxh)
605
{
606
   EINA_SAFETY_ON_NULL_RETURN(manager);
607
   manager->input.pointer_w = maxw;
608
   manager->input.pointer_h = maxh;
609
}
610

611
EAPI Eina_Bool
612
elput_input_pointer_rotation_set(Elput_Manager *manager, int rotation)
613
{
614
   Elput_Seat *eseat;
615
   Elput_Device *edev;
616
   Eina_List *l, *ll;
617

618
   EINA_SAFETY_ON_NULL_RETURN_VAL(manager, EINA_FALSE);
619

620
   if ((rotation % 90 != 0) || (rotation / 90 > 3) || (rotation < 0))
621
     return EINA_FALSE;
622

623
   manager->input.rotation = rotation;
624

625
   EINA_LIST_FOREACH(manager->input.seats, l, eseat)
626
     {
627
        EINA_LIST_FOREACH(eseat->devices, ll, edev)
628
          {
629
             if (!(edev->caps & ELPUT_DEVICE_CAPS_POINTER)) continue;
630

631
             switch (rotation)
632
               {
633
                case 0:
634
                  edev->swap = EINA_FALSE;
635
                  edev->invert_x = EINA_FALSE;
636
                  edev->invert_y = EINA_FALSE;
637
                  break;
638
                case 90:
639
                  edev->swap = EINA_TRUE;
640
                  edev->invert_x = EINA_FALSE;
641
                  edev->invert_y = EINA_TRUE;
642
                  break;
643
                case 180:
644
                  edev->swap = EINA_FALSE;
645
                  edev->invert_x = EINA_TRUE;
646
                  edev->invert_y = EINA_TRUE;
647
                  break;
648
                case 270:
649
                  edev->swap = EINA_TRUE;
650
                  edev->invert_x = EINA_TRUE;
651
                  edev->invert_y = EINA_FALSE;
652
                  break;
653
                default:
654
                  break;
655
               }
656
          }
657
     }
658

659
   return EINA_TRUE;
660
}
661

662
EAPI void
663
elput_input_devices_calibrate(Elput_Manager *manager, int w, int h)
664
{
665
   Elput_Seat *eseat;
666
   Elput_Device *edev;
667
   Eina_List *l, *ll;
668

669
   EINA_SAFETY_ON_NULL_RETURN(manager);
670

671
   manager->output_w = w;
672
   manager->output_h = h;
673

674
   EINA_LIST_FOREACH(manager->input.seats, l, eseat)
675
     {
676
        EINA_LIST_FOREACH(eseat->devices, ll, edev)
677
          {
678
             edev->ow = w;
679
             edev->oh = h;
680
             _evdev_device_calibrate(edev);
681
          }
682
     }
683
}
684

685
EAPI Eina_Bool
686
elput_input_key_remap_enable(Elput_Manager *manager, Eina_Bool enable)
687
{
688
   Elput_Seat *eseat;
689
   Elput_Device *edev;
690
   Eina_List *l, *ll;
691

692
   EINA_SAFETY_ON_NULL_RETURN_VAL(manager, EINA_FALSE);
693

694
   EINA_LIST_FOREACH(manager->input.seats, l, eseat)
695
     {
696
        EINA_LIST_FOREACH(eseat->devices, ll, edev)
697
          {
698
             if (!(edev->caps & ELPUT_DEVICE_CAPS_KEYBOARD)) continue;
699

700
             edev->key_remap = enable;
701
             if ((!enable) && (edev->key_remap_hash))
702
               {
703
                  eina_hash_free(edev->key_remap_hash);
704
                  edev->key_remap_hash = NULL;
705
               }
706
          }
707
     }
708

709
   return EINA_TRUE;
710
}
711

712
EAPI Eina_Bool
713
elput_input_key_remap_set(Elput_Manager *manager, int *from_keys, int *to_keys, int num)
714
{
715
   Elput_Seat *eseat;
716
   Elput_Device *edev;
717
   Eina_List *l, *ll;
718
   int i = 0;
719

720
   EINA_SAFETY_ON_NULL_RETURN_VAL(manager, EINA_FALSE);
721
   EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
722
   EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
723
   EINA_SAFETY_ON_TRUE_RETURN_VAL((num <= 0), EINA_FALSE);
724

725
   EINA_LIST_FOREACH(manager->input.seats, l, eseat)
726
     {
727
        EINA_LIST_FOREACH(eseat->devices, ll, edev)
728
          {
729
             if (!(edev->caps & ELPUT_DEVICE_CAPS_KEYBOARD)) continue;
730

731
             if (!edev->key_remap) continue;
732
             if (!edev->key_remap_hash)
733
               edev->key_remap_hash = eina_hash_int32_new(NULL);
734
             if (!edev->key_remap_hash) continue;
735

736
             for (i = 0; i < num; i++)
737
               {
738
                  if ((!from_keys[i]) || (!to_keys[i]))
739
                    continue;
740
               }
741

742
             for (i = 0; i < num; i++)
743
               eina_hash_add(edev->key_remap_hash, &from_keys[i],
744
                             (void *)(intptr_t)to_keys[i]);
745
          }
746
     }
747

748
   return EINA_TRUE;
749
}
750

751
EAPI void
752
elput_input_keyboard_info_set(Elput_Manager *manager, void *context, void *keymap, int group)
753
{
754
   Eina_List *l;
755
   Elput_Seat *seat;
756

757
   EINA_SAFETY_ON_NULL_RETURN(manager);
758
   EINA_SAFETY_ON_FALSE_RETURN((!!context) == (!!keymap));
759

760
   if ((manager->cached.context == context) &&
761
       (manager->cached.keymap == keymap))
762
     return;
763
   if (context) xkb_context_ref(context);
764
   if (keymap) xkb_keymap_ref(keymap);
765
   if (manager->cached.context) xkb_context_unref(manager->cached.context);
766
   if (manager->cached.keymap) xkb_keymap_unref(manager->cached.keymap);
767
   manager->cached.context = context;
768
   manager->cached.keymap = keymap;
769
   manager->cached.group = group;
770
   EINA_LIST_FOREACH(manager->input.seats, l, seat)
771
     _keyboard_keymap_update(seat);
772
}
773

774
EAPI void
775
elput_input_keyboard_group_set(Elput_Manager *manager, int group)
776
{
777
   Eina_List *l;
778
   Elput_Seat *seat;
779
   EINA_SAFETY_ON_NULL_RETURN(manager);
780

781
   if (manager->cached.group == group) return;
782
   manager->cached.group = group;
783
   EINA_LIST_FOREACH(manager->input.seats, l, seat)
784
     _keyboard_group_update(seat);
785
}
786

787
EAPI void
788
elput_input_pointer_accel_profile_set(Elput_Manager *manager, const char *seat, uint32_t profile)
789
{
790
   Elput_Seat *eseat;
791
   Elput_Device *edev;
792
   Eina_List *l, *ll;
793

794
   EINA_SAFETY_ON_NULL_RETURN(manager);
795

796
   /* if no seat name is passed in, just use default seat name */
797
   if (!seat) seat = "seat0";
798

799
   EINA_LIST_FOREACH(manager->input.seats, l, eseat)
800
     {
801
        if ((eseat->name) && (strcmp(eseat->name, seat)))
802
          continue;
803

804
        EINA_LIST_FOREACH(eseat->devices, ll, edev)
805
          {
806
             if (!libinput_device_has_capability(edev->device,
807
                                                 LIBINPUT_DEVICE_CAP_POINTER))
808
               continue;
809

810
             if (libinput_device_config_accel_set_profile(edev->device,
811
                                                          profile) !=
812
                 LIBINPUT_CONFIG_STATUS_SUCCESS)
813
               {
814
                  WRN("Failed to set acceleration profile for device: %s",
815
                      libinput_device_get_name(edev->device));
816
                  continue;
817
               }
818
          }
819
     }
820
}
821

822
EAPI void
823
elput_input_pointer_accel_speed_set(Elput_Manager *manager, const char *seat, double speed)
824
{
825
   Elput_Seat *eseat;
826
   Elput_Device *edev;
827
   Eina_List *l, *ll;
828

829
   EINA_SAFETY_ON_NULL_RETURN(manager);
830

831
   /* if no seat name is passed in, just use default seat name */
832
   if (!seat) seat = "seat0";
833

834
   EINA_LIST_FOREACH(manager->input.seats, l, eseat)
835
     {
836
        if ((eseat->name) && (strcmp(eseat->name, seat)))
837
          continue;
838

839
        EINA_LIST_FOREACH(eseat->devices, ll, edev)
840
          {
841
             if (!libinput_device_has_capability(edev->device,
842
                                                 LIBINPUT_DEVICE_CAP_POINTER))
843
               continue;
844

845
             if (!libinput_device_config_accel_is_available(edev->device))
846
               continue;
847

848
             if (libinput_device_config_accel_set_speed(edev->device,
849
                                                        speed) !=
850
                 LIBINPUT_CONFIG_STATUS_SUCCESS)
851
               {
852
                  WRN("Failed to set acceleration speed for device: %s",
853
                      libinput_device_get_name(edev->device));
854
                  continue;
855
               }
856
          }
857
     }
858
}
859

860
EAPI void
861
elput_input_touch_tap_to_click_enabled_set(Elput_Manager *manager, const char *seat, Eina_Bool enabled)
862
{
863
   Elput_Seat *eseat;
864
   Elput_Device *edev;
865
   Eina_List *l, *ll;
866
   enum libinput_config_tap_state state;
867

868
   EINA_SAFETY_ON_NULL_RETURN(manager);
869

870
   state = enabled ? LIBINPUT_CONFIG_TAP_ENABLED : LIBINPUT_CONFIG_TAP_DISABLED;
871

872
   /* if no seat name is passed in, just use default seat name */
873
   if (!seat) seat = "seat0";
874

875
   EINA_LIST_FOREACH(manager->input.seats, l, eseat)
876
     {
877
        if ((eseat->name) && (strcmp(eseat->name, seat)))
878
          continue;
879

880
        EINA_LIST_FOREACH(eseat->devices, ll, edev)
881
          {
882
             if (!libinput_device_has_capability(edev->device,
883
                                                 LIBINPUT_DEVICE_CAP_POINTER))
884
               continue;
885

886
             if (libinput_device_config_tap_set_enabled(edev->device, state)
887
                 != LIBINPUT_CONFIG_STATUS_SUCCESS)
888
               {
889
                  WRN("Failed to %s tap-to-click on device: %s",
890
                      enabled ? "enable" : "disable",
891
                      libinput_device_get_name(edev->device));
892
                  continue;
893
               }
894
          }
895
     }
896
}
897

898
EAPI Elput_Seat *
899
elput_device_seat_get(const Elput_Device *dev)
900
{
901
   EINA_SAFETY_ON_NULL_RETURN_VAL(dev, NULL);
902
   return dev->seat;
903
}
904

905
EAPI Elput_Device_Caps
906
elput_device_caps_get(const Elput_Device *dev)
907
{
908
   EINA_SAFETY_ON_NULL_RETURN_VAL(dev, 0);
909
   return dev->caps;
910
}
911

912
EAPI Eina_Stringshare *
913
elput_device_output_name_get(Elput_Device *device)
914
{
915
   EINA_SAFETY_ON_NULL_RETURN_VAL(device, NULL);
916

917
   return device->output_name;
918
}
919

920
EAPI const Eina_List *
921
elput_seat_devices_get(const Elput_Seat *seat)
922
{
923
   EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
924
   return seat->devices;
925
}
926

927
EAPI Eina_Stringshare *
928
elput_seat_name_get(const Elput_Seat *seat)
929
{
930
   EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
931
   return seat->name;
932
}
933

934
EAPI Elput_Manager *
935
elput_seat_manager_get(const Elput_Seat *seat)
936
{
937
   EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
938
   return seat->manager;
939
}
940

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.