2 * kmscon - Dummy Session
4 * Copyright (c) 2012 David Herrmann <dh.herrmann@googlemail.com>
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files
8 * (the "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 #include "kmscon_dummy.h"
34 #include "kmscon_seat.h"
35 #include "shl_dlist.h"
38 #define LOG_SUBSYSTEM "dummy"
41 struct shl_dlist list;
42 struct uterm_display *disp;
46 struct kmscon_session *session;
47 struct shl_dlist displays;
51 static void dummy_redraw(struct kmscon_dummy *dummy, struct display *d)
53 struct uterm_mode *mode;
56 mode = uterm_display_get_current(d->disp);
57 w = uterm_mode_get_width(mode);
58 h = uterm_mode_get_height(mode);
60 uterm_display_fill(d->disp, 0, 0, 0, 0, 0, w, h);
61 uterm_display_swap(d->disp, false);
64 static int dummy_session_event(struct kmscon_session *session,
65 struct kmscon_session_event *ev, void *data)
67 struct kmscon_dummy *dummy = data;
69 struct shl_dlist *iter;
72 case KMSCON_SESSION_DISPLAY_NEW:
73 d = malloc(sizeof(*d));
75 log_error("cannot allocate memory for new display");
78 memset(d, 0, sizeof(*d));
80 shl_dlist_link_tail(&dummy->displays, &d->list);
82 dummy_redraw(dummy, d);
84 case KMSCON_SESSION_DISPLAY_GONE:
85 shl_dlist_for_each(iter, &dummy->displays) {
86 d = shl_dlist_entry(iter, struct display, list);
87 if (d->disp != ev->disp)
90 shl_dlist_unlink(&d->list);
95 case KMSCON_SESSION_ACTIVATE:
97 shl_dlist_for_each(iter, &dummy->displays) {
98 d = shl_dlist_entry(iter, struct display, list);
99 dummy_redraw(dummy, d);
102 case KMSCON_SESSION_DEACTIVATE:
103 dummy->active = false;
105 case KMSCON_SESSION_UNREGISTER:
106 while (!shl_dlist_empty(&dummy->displays)) {
107 d = shl_dlist_entry(dummy->displays.prev,
108 struct display, list);
109 shl_dlist_unlink(&d->list);
120 int kmscon_dummy_register(struct kmscon_session **out,
121 struct kmscon_seat *seat)
123 struct kmscon_dummy *dummy;
129 dummy = malloc(sizeof(*dummy));
132 memset(dummy, 0, sizeof(*dummy));
133 shl_dlist_init(&dummy->displays);
135 ret = kmscon_seat_register_session(seat, &dummy->session,
136 dummy_session_event, dummy);
138 log_error("cannot register session for dummy: %d", ret);
142 *out = dummy->session;
143 log_debug("new dummy object %p", dummy);