summaryrefslogtreecommitdiff
path: root/src/libply-splash-core/ply-keyboard.c
blob: ab375f37b738d379512c6a7d8ae67f1d83db5716 (plain)
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
/* ply-keyboard.h - APIs for putting up a keyboard screen
 *
 * Copyright (C) 2009 Red Hat, Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 *
 * Written by: Ray Strode <rstrode@redhat.com>
 */
#include "ply-keyboard.h"

#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <wchar.h>

#include "ply-buffer.h"
#include "ply-event-loop.h"
#include "ply-list.h"
#include "ply-logger.h"
#include "ply-renderer.h"
#include "ply-terminal.h"
#include "ply-utils.h"

#define KEY_CTRL_U ('\100' ^ 'U')
#define KEY_CTRL_W ('\100' ^ 'W')
#define KEY_CTRL_V ('\100' ^ 'V')
#define KEY_ESCAPE ('\100' ^ '[')
#define KEY_RETURN '\n'
#define KEY_BACKSPACE '\177'

#define CSI_SEQUENCE_PREFIX "\033["
#define CSI_SEQUENCE_MINIMUM_LENGTH (strlen (CSI_SEQUENCE_PREFIX) + 1)

#define FUNCTION_KEY_SEQUENCE_PREFIX (CSI_SEQUENCE_PREFIX "[")
#define FUNCTION_KEY_SEQUENCE_MINIMUM_LENGTH (strlen (FUNCTION_KEY_SEQUENCE_PREFIX) + 1)

typedef void (*ply_keyboard_handler_t) (void *);

typedef struct
{
        ply_keyboard_handler_t function;
        void                  *user_data;
} ply_keyboard_closure_t;

typedef enum
{
        PLY_KEYBOARD_PROVIDER_TYPE_TERMINAL,
        PLY_KEYBOARD_PROVIDER_TYPE_RENDERER
} ply_keyboard_provider_type_t;

typedef struct
{
        ply_terminal_t *terminal;
        ply_buffer_t   *key_buffer;
} ply_keyboard_terminal_provider_t;

typedef struct
{
        ply_renderer_t              *renderer;
        ply_renderer_input_source_t *input_source;
} ply_keyboard_renderer_provider_t;

typedef  union
{
        ply_keyboard_renderer_provider_t *if_renderer;
        ply_keyboard_terminal_provider_t *if_terminal;
} ply_keyboard_provider_t;

struct _ply_keyboard
{
        ply_event_loop_t            *loop;

        ply_keyboard_provider_type_t provider_type;
        ply_keyboard_provider_t      provider;

        ply_buffer_t                *line_buffer;

        ply_list_t                  *keyboard_input_handler_list;
        ply_list_t                  *backspace_handler_list;
        ply_list_t                  *escape_handler_list;
        ply_list_t                  *enter_handler_list;

        uint32_t                     is_active : 1;
};

static bool ply_keyboard_watch_for_terminal_input (ply_keyboard_t *keyboard);

ply_keyboard_t *
ply_keyboard_new_for_terminal (ply_terminal_t *terminal)
{
        ply_keyboard_t *keyboard;

        keyboard = calloc (1, sizeof(ply_keyboard_t));
        keyboard->line_buffer = ply_buffer_new ();
        keyboard->keyboard_input_handler_list = ply_list_new ();
        keyboard->backspace_handler_list = ply_list_new ();
        keyboard->escape_handler_list = ply_list_new ();
        keyboard->enter_handler_list = ply_list_new ();
        keyboard->provider_type = PLY_KEYBOARD_PROVIDER_TYPE_TERMINAL;
        keyboard->provider.if_terminal = calloc (1, sizeof(ply_keyboard_terminal_provider_t));
        keyboard->provider.if_terminal->terminal = terminal;
        keyboard->provider.if_terminal->key_buffer = ply_buffer_new ();

        keyboard->loop = ply_event_loop_get_default ();

        return keyboard;
}

ply_keyboard_t *
ply_keyboard_new_for_renderer (ply_renderer_t *renderer)
{
        ply_keyboard_t *keyboard;
        ply_renderer_input_source_t *input_source;

        keyboard = calloc (1, sizeof(ply_keyboard_t));
        keyboard->line_buffer = ply_buffer_new ();
        keyboard->keyboard_input_handler_list = ply_list_new ();
        keyboard->backspace_handler_list = ply_list_new ();
        keyboard->escape_handler_list = ply_list_new ();
        keyboard->enter_handler_list = ply_list_new ();
        keyboard->provider_type = PLY_KEYBOARD_PROVIDER_TYPE_RENDERER;
        keyboard->provider.if_renderer = calloc (1, sizeof(ply_keyboard_renderer_provider_t));
        keyboard->provider.if_renderer->renderer = renderer;

        input_source = ply_renderer_get_input_source (renderer);

        keyboard->provider.if_renderer->input_source = input_source;

        keyboard->loop = ply_event_loop_get_default ();

        return keyboard;
}

static void
process_backspace (ply_keyboard_t *keyboard)
{
        char *bytes;
        size_t size;
        size_t capacity;
        ply_list_node_t *node;

        ply_buffer_borrow_bytes (keyboard->line_buffer, &bytes, &size, &capacity) {
                ply_utf8_string_remove_last_character (&bytes, &size);
        }

        for (node = ply_list_get_first_node (keyboard->backspace_handler_list);
             node; node = ply_list_get_next_node (keyboard->backspace_handler_list, node)) {
                ply_keyboard_closure_t *closure = ply_list_node_get_data (node);
                ply_keyboard_backspace_handler_t backspace_handler =
                        (ply_keyboard_backspace_handler_t) closure->function;
                backspace_handler (closure->user_data);
        }
}

static void
process_line_erase (ply_keyboard_t *keyboard)
{
        size_t size;

        while ((size = ply_buffer_get_size (keyboard->line_buffer)) > 0) {
                process_backspace (keyboard);
        }
}

static void
process_keyboard_input (ply_keyboard_t *keyboard,
                        const char     *keyboard_input,
                        size_t          character_size)
{
        wchar_t key;
        ply_list_node_t *node;

        if (keyboard_input[0] == KEY_ESCAPE && character_size >= 2) {
                /* Escape sequence */
                ply_buffer_append_bytes (keyboard->line_buffer,
                                         keyboard_input, character_size);
        } else if ((ssize_t) mbrtowc (&key, keyboard_input, character_size, NULL) > 0) {
                switch (key) {
                case KEY_CTRL_U:
                case KEY_CTRL_W:
                        ply_trace ("erase line!");
                        process_line_erase (keyboard);
                        return;

                case KEY_CTRL_V:
                        ply_trace ("toggle verbose mode!");
                        ply_toggle_tracing ();
                        ply_trace ("verbose mode toggled!");
                        return;

                case KEY_ESCAPE:
                        ply_trace ("escape key!");
                        for (node = ply_list_get_first_node (keyboard->escape_handler_list);
                             node; node = ply_list_get_next_node (keyboard->escape_handler_list, node)) {
                                ply_keyboard_closure_t *closure = ply_list_node_get_data (node);
                                ply_keyboard_escape_handler_t escape_handler = (ply_keyboard_escape_handler_t) closure->function;
                                escape_handler (closure->user_data);
                        }

                        ply_trace ("end escape key handler");
                        return;

                case KEY_BACKSPACE:
                        ply_trace ("backspace key!");
                        process_backspace (keyboard);
                        return;

                case KEY_RETURN:
                        ply_trace ("return key!");

                        for (node = ply_list_get_first_node (keyboard->enter_handler_list);
                             node; node = ply_list_get_next_node (keyboard->enter_handler_list, node)) {
                                ply_keyboard_closure_t *closure = ply_list_node_get_data (node);
                                ply_keyboard_enter_handler_t enter_handler = (ply_keyboard_enter_handler_t) closure->function;
                                enter_handler (closure->user_data, ply_buffer_get_bytes (keyboard->line_buffer));
                        }
                        ply_buffer_clear (keyboard->line_buffer);
                        return;

                default:
                        ply_buffer_append_bytes (keyboard->line_buffer,
                                                 keyboard_input, character_size);
                        break;
                }
        }

        for (node = ply_list_get_first_node (keyboard->keyboard_input_handler_list);
             node; node = ply_list_get_next_node (keyboard->keyboard_input_handler_list, node)) {
                ply_keyboard_closure_t *closure = ply_list_node_get_data (node);
                ply_keyboard_input_handler_t keyboard_input_handler =
                        (ply_keyboard_input_handler_t) closure->function;

                keyboard_input_handler (closure->user_data,
                                        keyboard_input, character_size);
        }
}

static void
on_key_event (ply_keyboard_t *keyboard,
              ply_buffer_t   *buffer)
{
        const char *bytes;
        size_t size, i;

        bytes = ply_buffer_get_bytes (buffer);
        size = ply_buffer_get_size (buffer);

        i = 0;
        while (i < size) {
                ply_utf8_character_byte_type_t character_byte_type;
                ssize_t character_size;
                char *keyboard_input;
                size_t bytes_left = size - i;

                /* Control Sequence Introducer sequences
                 */
                if (bytes_left >= FUNCTION_KEY_SEQUENCE_MINIMUM_LENGTH &&
                    strncmp (bytes + i, FUNCTION_KEY_SEQUENCE_PREFIX,
                             strlen (FUNCTION_KEY_SEQUENCE_PREFIX)) == 0) {
                        /* Special case - CSI [ after which the next character
                         * is a function key
                         */
                        process_keyboard_input (keyboard, bytes + i, 4);
                        i += 4;
                        continue;
                } else if (bytes_left >= CSI_SEQUENCE_MINIMUM_LENGTH && /* At least CSI + final byte */
                           strncmp (bytes + i, CSI_SEQUENCE_PREFIX,
                                    strlen (CSI_SEQUENCE_PREFIX)) == 0) {
                        ssize_t csi_seq_size;
                        csi_seq_size = 0;
                        for (size_t j = strlen (CSI_SEQUENCE_PREFIX); j < bytes_left; j++) {
                                if ((bytes[i + j] >= 0x40) &&
                                    (bytes[i + j] <= 0x7E)) {
                                        /* Final byte found */
                                        csi_seq_size = j + 1;
                                        break;
                                }
                                /* We presume if we aren't at the final byte, the intermediate
                                 * bytes will be in the range 0x20-0x2F, but we don't validate
                                 * that, since it's not really clear how invalid sequences should
                                 * be handled, and letting them through to the keyboard input
                                 * handlers seems just as reasonable as alternatives.
                                 */
                        }
                        if (csi_seq_size == 0) /* No final byte found */
                                continue;
                        process_keyboard_input (keyboard, bytes + i, csi_seq_size);
                        i += csi_seq_size;
                        continue;
                }

                character_byte_type = ply_utf8_character_get_byte_type (bytes[i]);

                if (PLY_UTF8_CHARACTER_BYTE_TYPE_IS_NOT_LEADING (character_byte_type))
                        break;

                /* If we're at a NUL character walk through it
                 */
                if (character_byte_type == PLY_UTF8_CHARACTER_BYTE_TYPE_END_OF_STRING) {
                        i++;
                        continue;
                }

                character_size = ply_utf8_character_get_size_from_byte_type (character_byte_type);

                if (character_size > bytes_left)
                        break;

                keyboard_input = strndup (bytes + i, character_size);

                process_keyboard_input (keyboard, keyboard_input, character_size);

                i += character_size;

                free (keyboard_input);
        }

        if (i > 0)
                ply_buffer_remove_bytes (buffer, i);
}

static bool
ply_keyboard_watch_for_renderer_input (ply_keyboard_t *keyboard)
{
        assert (keyboard != NULL);

        if (!ply_renderer_open_input_source (keyboard->provider.if_renderer->renderer,
                                             keyboard->provider.if_renderer->input_source))
                return false;

        ply_renderer_set_handler_for_input_source (keyboard->provider.if_renderer->renderer,
                                                   keyboard->provider.if_renderer->input_source,
                                                   (ply_renderer_input_source_handler_t)
                                                   on_key_event,
                                                   keyboard);
        return true;
}

static void
ply_keyboard_stop_watching_for_renderer_input (ply_keyboard_t *keyboard)
{
        ply_renderer_set_handler_for_input_source (keyboard->provider.if_renderer->renderer,
                                                   keyboard->provider.if_renderer->input_source,
                                                   (ply_renderer_input_source_handler_t)
                                                   NULL, NULL);

        ply_renderer_close_input_source (keyboard->provider.if_renderer->renderer,
                                         keyboard->provider.if_renderer->input_source);
}

bool
ply_keyboard_is_active (ply_keyboard_t *keyboard)
{
        return keyboard->is_active;
}

static void
on_terminal_data (ply_keyboard_t *keyboard)
{
        int terminal_fd;

        terminal_fd = ply_terminal_get_fd (keyboard->provider.if_terminal->terminal);
        ply_buffer_append_from_fd (keyboard->provider.if_terminal->key_buffer,
                                   terminal_fd);
        on_key_event (keyboard, keyboard->provider.if_terminal->key_buffer);
}

static bool
ply_keyboard_watch_for_terminal_input (ply_keyboard_t *keyboard)
{
        int terminal_fd;

        assert (keyboard != NULL);

        terminal_fd = ply_terminal_get_fd (keyboard->provider.if_terminal->terminal);

        if (terminal_fd < 0 || !ply_terminal_is_open (keyboard->provider.if_terminal->terminal)) {
                ply_trace ("terminal associated with keyboard isn't open");
                return false;
        }

        ply_terminal_watch_for_input (keyboard->provider.if_terminal->terminal,
                                      (ply_terminal_input_handler_t) on_terminal_data,
                                      keyboard);

        return true;
}

static void
ply_keyboard_stop_watching_for_terminal_input (ply_keyboard_t *keyboard)
{
        ply_terminal_stop_watching_for_input (keyboard->provider.if_terminal->terminal,
                                              (ply_terminal_input_handler_t)
                                              on_terminal_data,
                                              keyboard);
}

bool
ply_keyboard_watch_for_input (ply_keyboard_t *keyboard)
{
        assert (keyboard != NULL);

        if (keyboard->is_active)
                return true;

        switch (keyboard->provider_type) {
        case PLY_KEYBOARD_PROVIDER_TYPE_RENDERER:
                keyboard->is_active = ply_keyboard_watch_for_renderer_input (keyboard);
                break;

        case PLY_KEYBOARD_PROVIDER_TYPE_TERMINAL:
                keyboard->is_active = ply_keyboard_watch_for_terminal_input (keyboard);
                break;
        }

        return keyboard->is_active;
}

void
ply_keyboard_stop_watching_for_input (ply_keyboard_t *keyboard)
{
        assert (keyboard != NULL);

        if (!keyboard->is_active)
                return;

        switch (keyboard->provider_type) {
        case PLY_KEYBOARD_PROVIDER_TYPE_RENDERER:
                ply_keyboard_stop_watching_for_renderer_input (keyboard);
                break;

        case PLY_KEYBOARD_PROVIDER_TYPE_TERMINAL:
                ply_keyboard_stop_watching_for_terminal_input (keyboard);
                break;
        }

        keyboard->is_active = false;
}

void
ply_keyboard_free (ply_keyboard_t *keyboard)
{
        if (keyboard == NULL)
                return;

        ply_keyboard_stop_watching_for_input (keyboard);

        ply_buffer_free (keyboard->line_buffer);

        if (keyboard->provider_type == PLY_KEYBOARD_PROVIDER_TYPE_RENDERER) {
                free (keyboard->provider.if_renderer);
        } else {
                ply_buffer_free (keyboard->provider.if_terminal->key_buffer);
                free (keyboard->provider.if_terminal);
        }

        free (keyboard);
}

static ply_keyboard_closure_t *
ply_keyboard_closure_new (ply_keyboard_handler_t function,
                          void                  *user_data)
{
        ply_keyboard_closure_t *closure = calloc (1, sizeof(ply_keyboard_closure_t));

        closure->function = function;
        closure->user_data = user_data;
        return closure;
}


static void
ply_keyboard_closure_free (ply_keyboard_closure_t *closure)
{
        free (closure);
}

void
ply_keyboard_add_input_handler (ply_keyboard_t              *keyboard,
                                ply_keyboard_input_handler_t input_handler,
                                void                        *user_data)
{
        ply_keyboard_closure_t *closure;

        assert (keyboard != NULL);

        closure = ply_keyboard_closure_new ((ply_keyboard_handler_t) input_handler,
                                            user_data);
        ply_list_append_data (keyboard->keyboard_input_handler_list, closure);
}

void
ply_keyboard_remove_input_handler (ply_keyboard_t              *keyboard,
                                   ply_keyboard_input_handler_t input_handler)
{
        ply_list_node_t *node;

        assert (keyboard != NULL);

        for (node = ply_list_get_first_node (keyboard->keyboard_input_handler_list);
             node; node = ply_list_get_next_node (keyboard->keyboard_input_handler_list, node)) {
                ply_keyboard_closure_t *closure = ply_list_node_get_data (node);
                if ((ply_keyboard_input_handler_t) closure->function == input_handler) {
                        ply_keyboard_closure_free (closure);
                        ply_list_remove_node (keyboard->keyboard_input_handler_list, node);
                        return;
                }
        }
}

void
ply_keyboard_add_backspace_handler (ply_keyboard_t                  *keyboard,
                                    ply_keyboard_backspace_handler_t backspace_handler,
                                    void                            *user_data)
{
        ply_keyboard_closure_t *closure;

        assert (keyboard != NULL);

        closure = ply_keyboard_closure_new ((ply_keyboard_handler_t) backspace_handler,
                                            user_data);
        ply_list_append_data (keyboard->backspace_handler_list, closure);
}


void
ply_keyboard_remove_backspace_handler (ply_keyboard_t                  *keyboard,
                                       ply_keyboard_backspace_handler_t backspace_handler)
{
        ply_list_node_t *node;

        assert (keyboard != NULL);

        for (node = ply_list_get_first_node (keyboard->backspace_handler_list);
             node; node = ply_list_get_next_node (keyboard->backspace_handler_list, node)) {
                ply_keyboard_closure_t *closure = ply_list_node_get_data (node);
                if ((ply_keyboard_backspace_handler_t) closure->function == backspace_handler) {
                        ply_keyboard_closure_free (closure);
                        ply_list_remove_node (keyboard->backspace_handler_list, node);
                        return;
                }
        }
}

void
ply_keyboard_add_escape_handler (ply_keyboard_t               *keyboard,
                                 ply_keyboard_escape_handler_t escape_handler,
                                 void                         *user_data)
{
        ply_keyboard_closure_t *closure;

        assert (keyboard != NULL);

        closure = ply_keyboard_closure_new ((ply_keyboard_handler_t) escape_handler,
                                            user_data);
        ply_list_append_data (keyboard->escape_handler_list, closure);
}


void
ply_keyboard_remove_escape_handler (ply_keyboard_t               *keyboard,
                                    ply_keyboard_escape_handler_t escape_handler)
{
        ply_list_node_t *node;

        assert (keyboard != NULL);

        for (node = ply_list_get_first_node (keyboard->escape_handler_list);
             node; node = ply_list_get_next_node (keyboard->escape_handler_list, node)) {
                ply_keyboard_closure_t *closure = ply_list_node_get_data (node);
                if ((ply_keyboard_escape_handler_t) closure->function == escape_handler) {
                        ply_keyboard_closure_free (closure);
                        ply_list_remove_node (keyboard->escape_handler_list, node);
                        return;
                }
        }
}

void
ply_keyboard_add_enter_handler (ply_keyboard_t              *keyboard,
                                ply_keyboard_enter_handler_t enter_handler,
                                void                        *user_data)
{
        ply_keyboard_closure_t *closure;

        assert (keyboard != NULL);

        closure = ply_keyboard_closure_new ((ply_keyboard_handler_t) enter_handler,
                                            user_data);

        ply_list_append_data (keyboard->enter_handler_list, closure);
}

void
ply_keyboard_remove_enter_handler (ply_keyboard_t              *keyboard,
                                   ply_keyboard_enter_handler_t enter_handler)
{
        ply_list_node_t *node;

        assert (keyboard != NULL);

        for (node = ply_list_get_first_node (keyboard->enter_handler_list);
             node; node = ply_list_get_next_node (keyboard->enter_handler_list, node)) {
                ply_keyboard_closure_t *closure = ply_list_node_get_data (node);
                if ((ply_keyboard_enter_handler_t) closure->function == enter_handler) {
                        ply_keyboard_closure_free (closure);
                        ply_list_remove_node (keyboard->enter_handler_list, node);
                        return;
                }
        }
}

ply_renderer_t *
ply_keyboard_get_renderer (ply_keyboard_t *keyboard)
{
        assert (keyboard != NULL);

        switch (keyboard->provider_type) {
        case PLY_KEYBOARD_PROVIDER_TYPE_RENDERER:
                return keyboard->provider.if_renderer->renderer;

        case PLY_KEYBOARD_PROVIDER_TYPE_TERMINAL:
                return NULL;
        }

        return NULL;
}

bool
ply_keyboard_get_capslock_state (ply_keyboard_t *keyboard)
{
        assert (keyboard != NULL);

        switch (keyboard->provider_type) {
        case PLY_KEYBOARD_PROVIDER_TYPE_RENDERER:
                return ply_renderer_get_capslock_state (keyboard->provider.if_renderer->renderer);


        case PLY_KEYBOARD_PROVIDER_TYPE_TERMINAL:
                return ply_terminal_get_capslock_state (keyboard->provider.if_terminal->terminal);
        }

        return NULL;
}