| 1 | /*
|
|---|
| 2 | * Copyright (c) 2019 Jiri Svoboda
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup display
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 | /**
|
|---|
| 33 | * @file Display server seat
|
|---|
| 34 | */
|
|---|
| 35 |
|
|---|
| 36 | #include <adt/list.h>
|
|---|
| 37 | #include <errno.h>
|
|---|
| 38 | #include <stdlib.h>
|
|---|
| 39 | #include "client.h"
|
|---|
| 40 | #include "display.h"
|
|---|
| 41 | #include "seat.h"
|
|---|
| 42 | #include "window.h"
|
|---|
| 43 |
|
|---|
| 44 | /** Create seat.
|
|---|
| 45 | *
|
|---|
| 46 | * @param display Parent display
|
|---|
| 47 | * @param rseat Place to store pointer to new seat.
|
|---|
| 48 | * @return EOK on success, ENOMEM if out of memory
|
|---|
| 49 | */
|
|---|
| 50 | errno_t ds_seat_create(ds_display_t *display, ds_seat_t **rseat)
|
|---|
| 51 | {
|
|---|
| 52 | ds_seat_t *seat;
|
|---|
| 53 |
|
|---|
| 54 | seat = calloc(1, sizeof(ds_seat_t));
|
|---|
| 55 | if (seat == NULL)
|
|---|
| 56 | return ENOMEM;
|
|---|
| 57 |
|
|---|
| 58 | ds_display_add_seat(display, seat);
|
|---|
| 59 |
|
|---|
| 60 | *rseat = seat;
|
|---|
| 61 | return EOK;
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | /** Destroy seat.
|
|---|
| 65 | *
|
|---|
| 66 | * @param seat Seat
|
|---|
| 67 | */
|
|---|
| 68 | void ds_seat_destroy(ds_seat_t *seat)
|
|---|
| 69 | {
|
|---|
| 70 | ds_display_remove_seat(seat);
|
|---|
| 71 | free(seat);
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | void ds_seat_set_focus(ds_seat_t *seat, ds_window_t *wnd)
|
|---|
| 75 | {
|
|---|
| 76 | seat->focus = wnd;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | void ds_seat_evac_focus(ds_seat_t *seat, ds_window_t *wnd)
|
|---|
| 80 | {
|
|---|
| 81 | ds_window_t *nwnd;
|
|---|
| 82 |
|
|---|
| 83 | if (seat->focus == wnd) {
|
|---|
| 84 | /* Focus a different window. XXX Delegate to WM */
|
|---|
| 85 | nwnd = ds_display_next_window(wnd);
|
|---|
| 86 | if (nwnd == NULL)
|
|---|
| 87 | nwnd = ds_display_first_window(wnd->display);
|
|---|
| 88 | if (nwnd == wnd)
|
|---|
| 89 | nwnd = NULL;
|
|---|
| 90 |
|
|---|
| 91 | ds_seat_set_focus(seat, nwnd);
|
|---|
| 92 | }
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | /** Post keyboard event to the seat's focused window.
|
|---|
| 96 | *
|
|---|
| 97 | * @param seat Seat
|
|---|
| 98 | * @param event Event
|
|---|
| 99 | *
|
|---|
| 100 | * @return EOK on success or an error code
|
|---|
| 101 | */
|
|---|
| 102 | errno_t ds_seat_post_kbd_event(ds_seat_t *seat, kbd_event_t *event)
|
|---|
| 103 | {
|
|---|
| 104 | ds_window_t *dwindow = seat->focus;
|
|---|
| 105 |
|
|---|
| 106 | if (dwindow == NULL)
|
|---|
| 107 | return EOK;
|
|---|
| 108 |
|
|---|
| 109 | return ds_client_post_kbd_event(dwindow->client, dwindow, event);
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | /** @}
|
|---|
| 113 | */
|
|---|