| [51c1b003] | 1 | /*
|
|---|
| [7c014d1] | 2 | * Copyright (c) 2011 Martin Decky
|
|---|
| [51c1b003] | 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 | */
|
|---|
| [ce5bcb4] | 28 |
|
|---|
| [231a60a] | 29 | /** @addtogroup console
|
|---|
| [1601f3c] | 30 | * @{
|
|---|
| [ce5bcb4] | 31 | */
|
|---|
| 32 | /** @file
|
|---|
| 33 | */
|
|---|
| 34 |
|
|---|
| [7c014d1] | 35 | #include <async.h>
|
|---|
| 36 | #include <stdio.h>
|
|---|
| 37 | #include <adt/prodcons.h>
|
|---|
| [5f88293] | 38 | #include <ipc/input.h>
|
|---|
| [7c014d1] | 39 | #include <ipc/console.h>
|
|---|
| 40 | #include <ipc/vfs.h>
|
|---|
| [51c1b003] | 41 | #include <errno.h>
|
|---|
| [30db06c] | 42 | #include <str_error.h>
|
|---|
| [15f3c3f] | 43 | #include <loc.h>
|
|---|
| [7c014d1] | 44 | #include <event.h>
|
|---|
| 45 | #include <io/keycode.h>
|
|---|
| 46 | #include <screenbuffer.h>
|
|---|
| 47 | #include <fb.h>
|
|---|
| 48 | #include <imgmap.h>
|
|---|
| 49 | #include <align.h>
|
|---|
| 50 | #include <malloc.h>
|
|---|
| 51 | #include <as.h>
|
|---|
| [1e4cada] | 52 | #include <fibril_synch.h>
|
|---|
| [7c014d1] | 53 | #include "images.h"
|
|---|
| [9805cde] | 54 | #include "console.h"
|
|---|
| [369a5f8] | 55 |
|
|---|
| [1313ee9] | 56 | #define NAME "console"
|
|---|
| 57 | #define NAMESPACE "term"
|
|---|
| [79ae36dd] | 58 |
|
|---|
| [7c014d1] | 59 | #define CONSOLE_TOP 66
|
|---|
| 60 | #define CONSOLE_MARGIN 12
|
|---|
| 61 |
|
|---|
| 62 | #define STATE_START 110
|
|---|
| 63 | #define STATE_TOP 8
|
|---|
| 64 | #define STATE_SPACE 4
|
|---|
| 65 | #define STATE_WIDTH 48
|
|---|
| 66 | #define STATE_HEIGHT 48
|
|---|
| 67 |
|
|---|
| 68 | typedef enum {
|
|---|
| 69 | CONS_DISCONNECTED = 0,
|
|---|
| 70 | CONS_DISCONNECTED_SELECTED,
|
|---|
| 71 | CONS_SELECTED,
|
|---|
| 72 | CONS_IDLE,
|
|---|
| 73 | CONS_DATA,
|
|---|
| 74 | CONS_KERNEL,
|
|---|
| 75 | CONS_LAST
|
|---|
| 76 | } console_state_t;
|
|---|
| [3993b3d] | 77 |
|
|---|
| [79460ae] | 78 | typedef struct {
|
|---|
| [7c014d1] | 79 | atomic_t refcnt; /**< Connection reference count */
|
|---|
| 80 | prodcons_t input_pc; /**< Incoming keyboard events */
|
|---|
| 81 |
|
|---|
| 82 | fibril_mutex_t mtx; /**< Lock protecting mutable fields */
|
|---|
| 83 |
|
|---|
| 84 | size_t index; /**< Console index */
|
|---|
| 85 | console_state_t state; /**< Console state */
|
|---|
| 86 | service_id_t dsid; /**< Service handle */
|
|---|
| 87 |
|
|---|
| 88 | vp_handle_t state_vp; /**< State icon viewport */
|
|---|
| 89 | sysarg_t cols; /**< Number of columns */
|
|---|
| 90 | sysarg_t rows; /**< Number of rows */
|
|---|
| 91 | console_caps_t ccaps; /**< Console capabilities */
|
|---|
| 92 |
|
|---|
| 93 | screenbuffer_t *frontbuf; /**< Front buffer */
|
|---|
| 94 | frontbuf_handle_t fbid; /**< Front buffer handle */
|
|---|
| [424cd43] | 95 | } console_t;
|
|---|
| [79460ae] | 96 |
|
|---|
| [7c014d1] | 97 | typedef enum {
|
|---|
| 98 | GRAPHICS_NONE = 0,
|
|---|
| 99 | GRAPHICS_BASIC = 1,
|
|---|
| 100 | GRAPHICS_FULL = 2
|
|---|
| 101 | } graphics_state_t;
|
|---|
| 102 |
|
|---|
| 103 | /** Current console state */
|
|---|
| 104 | static graphics_state_t graphics_state = GRAPHICS_NONE;
|
|---|
| 105 |
|
|---|
| 106 | /** State icons */
|
|---|
| 107 | static imagemap_handle_t state_icons[CONS_LAST];
|
|---|
| 108 |
|
|---|
| 109 | /** Session to the input server */
|
|---|
| 110 | static async_sess_t *input_sess;
|
|---|
| 111 |
|
|---|
| 112 | /** Session to the framebuffer server */
|
|---|
| 113 | static async_sess_t *fb_sess;
|
|---|
| 114 |
|
|---|
| 115 | /** Framebuffer resolution */
|
|---|
| 116 | static sysarg_t xres;
|
|---|
| 117 | static sysarg_t yres;
|
|---|
| 118 |
|
|---|
| [1601f3c] | 119 | /** Array of data for virtual consoles */
|
|---|
| [424cd43] | 120 | static console_t consoles[CONSOLE_COUNT];
|
|---|
| 121 |
|
|---|
| [7c014d1] | 122 | /** Mutex for console switching */
|
|---|
| 123 | static FIBRIL_MUTEX_INITIALIZE(switch_mtx);
|
|---|
| 124 |
|
|---|
| [424cd43] | 125 | static console_t *prev_console = &consoles[0];
|
|---|
| [7c014d1] | 126 | static console_t *active_console = &consoles[0];
|
|---|
| [424cd43] | 127 | static console_t *kernel_console = &consoles[KERNEL_CONSOLE];
|
|---|
| [1601f3c] | 128 |
|
|---|
| [7c014d1] | 129 | static imgmap_t *logo_img;
|
|---|
| 130 | static imgmap_t *nameic_img;
|
|---|
| [d2cc7e1] | 131 |
|
|---|
| [7c014d1] | 132 | static imgmap_t *anim_1_img;
|
|---|
| 133 | static imgmap_t *anim_2_img;
|
|---|
| 134 | static imgmap_t *anim_3_img;
|
|---|
| 135 | static imgmap_t *anim_4_img;
|
|---|
| [d2cc7e1] | 136 |
|
|---|
| [7c014d1] | 137 | static imagemap_handle_t anim_1;
|
|---|
| 138 | static imagemap_handle_t anim_2;
|
|---|
| 139 | static imagemap_handle_t anim_3;
|
|---|
| 140 | static imagemap_handle_t anim_4;
|
|---|
| [429acb9] | 141 |
|
|---|
| [7c014d1] | 142 | static sequence_handle_t anim_seq;
|
|---|
| [a40dea3] | 143 |
|
|---|
| [7c014d1] | 144 | static imgmap_t *cons_data_img;
|
|---|
| 145 | static imgmap_t *cons_dis_img;
|
|---|
| 146 | static imgmap_t *cons_dis_sel_img;
|
|---|
| 147 | static imgmap_t *cons_idle_img;
|
|---|
| 148 | static imgmap_t *cons_kernel_img;
|
|---|
| 149 | static imgmap_t *cons_sel_img;
|
|---|
| [a40dea3] | 150 |
|
|---|
| [7c014d1] | 151 | static vp_handle_t logo_vp;
|
|---|
| 152 | static imagemap_handle_t logo_handle;
|
|---|
| [a40dea3] | 153 |
|
|---|
| [7c014d1] | 154 | static vp_handle_t nameic_vp;
|
|---|
| 155 | static imagemap_handle_t nameic_handle;
|
|---|
| [8c6337d] | 156 |
|
|---|
| [7c014d1] | 157 | static vp_handle_t screen_vp;
|
|---|
| 158 | static vp_handle_t console_vp;
|
|---|
| [424cd43] | 159 |
|
|---|
| [7c014d1] | 160 | struct {
|
|---|
| 161 | sysarg_t x;
|
|---|
| 162 | sysarg_t y;
|
|---|
| 163 |
|
|---|
| 164 | sysarg_t btn_x;
|
|---|
| 165 | sysarg_t btn_y;
|
|---|
| 166 |
|
|---|
| 167 | bool pressed;
|
|---|
| 168 | } mouse;
|
|---|
| [429acb9] | 169 |
|
|---|
| [7c014d1] | 170 | static void cons_redraw_state(console_t *cons)
|
|---|
| [10270a8] | 171 | {
|
|---|
| [7c014d1] | 172 | if (graphics_state == GRAPHICS_FULL) {
|
|---|
| 173 | fibril_mutex_lock(&cons->mtx);
|
|---|
| 174 |
|
|---|
| 175 | fb_vp_imagemap_damage(fb_sess, cons->state_vp,
|
|---|
| 176 | state_icons[cons->state], 0, 0, STATE_WIDTH, STATE_HEIGHT);
|
|---|
| 177 |
|
|---|
| 178 | if ((cons->state != CONS_DISCONNECTED) &&
|
|---|
| 179 | (cons->state != CONS_KERNEL) &&
|
|---|
| 180 | (cons->state != CONS_DISCONNECTED_SELECTED)) {
|
|---|
| 181 | char data[5];
|
|---|
| 182 | snprintf(data, 5, "%zu", cons->index + 1);
|
|---|
| 183 |
|
|---|
| 184 | for (size_t i = 0; data[i] != 0; i++)
|
|---|
| 185 | fb_vp_putchar(fb_sess, cons->state_vp, i + 2, 1, data[i]);
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | fibril_mutex_unlock(&cons->mtx);
|
|---|
| 189 | }
|
|---|
| [10270a8] | 190 | }
|
|---|
| 191 |
|
|---|
| [7c014d1] | 192 | static void cons_kernel_sequence_start(console_t *cons)
|
|---|
| [10270a8] | 193 | {
|
|---|
| [7c014d1] | 194 | if (graphics_state == GRAPHICS_FULL) {
|
|---|
| 195 | fibril_mutex_lock(&cons->mtx);
|
|---|
| 196 |
|
|---|
| 197 | fb_vp_sequence_start(fb_sess, cons->state_vp, anim_seq);
|
|---|
| 198 | fb_vp_imagemap_damage(fb_sess, cons->state_vp,
|
|---|
| 199 | state_icons[cons->state], 0, 0, STATE_WIDTH, STATE_HEIGHT);
|
|---|
| 200 |
|
|---|
| 201 | fibril_mutex_unlock(&cons->mtx);
|
|---|
| 202 | }
|
|---|
| [10270a8] | 203 | }
|
|---|
| 204 |
|
|---|
| [7c014d1] | 205 | static void cons_update_state(console_t *cons, console_state_t state)
|
|---|
| [ccd1a14] | 206 | {
|
|---|
| [7c014d1] | 207 | bool update = false;
|
|---|
| 208 |
|
|---|
| 209 | fibril_mutex_lock(&cons->mtx);
|
|---|
| 210 |
|
|---|
| 211 | if (cons->state != state) {
|
|---|
| 212 | cons->state = state;
|
|---|
| 213 | update = true;
|
|---|
| [a40dea3] | 214 | }
|
|---|
| 215 |
|
|---|
| [7c014d1] | 216 | fibril_mutex_unlock(&cons->mtx);
|
|---|
| 217 |
|
|---|
| 218 | if (update)
|
|---|
| 219 | cons_redraw_state(cons);
|
|---|
| [ccd1a14] | 220 | }
|
|---|
| 221 |
|
|---|
| [7c014d1] | 222 | static void cons_notify_data(console_t *cons)
|
|---|
| [ccd1a14] | 223 | {
|
|---|
| [7c014d1] | 224 | fibril_mutex_lock(&switch_mtx);
|
|---|
| [a40dea3] | 225 |
|
|---|
| [7c014d1] | 226 | if (cons != active_console)
|
|---|
| 227 | cons_update_state(cons, CONS_DATA);
|
|---|
| 228 |
|
|---|
| 229 | fibril_mutex_unlock(&switch_mtx);
|
|---|
| [ccd1a14] | 230 | }
|
|---|
| 231 |
|
|---|
| [7c014d1] | 232 | static void cons_notify_connect(console_t *cons)
|
|---|
| [429acb9] | 233 | {
|
|---|
| [7c014d1] | 234 | fibril_mutex_lock(&switch_mtx);
|
|---|
| 235 |
|
|---|
| 236 | if (cons == active_console)
|
|---|
| 237 | cons_update_state(cons, CONS_SELECTED);
|
|---|
| 238 | else
|
|---|
| 239 | cons_update_state(cons, CONS_IDLE);
|
|---|
| 240 |
|
|---|
| 241 | fibril_mutex_unlock(&switch_mtx);
|
|---|
| [429acb9] | 242 | }
|
|---|
| 243 |
|
|---|
| [7c014d1] | 244 | static void cons_notify_disconnect(console_t *cons)
|
|---|
| [429acb9] | 245 | {
|
|---|
| [7c014d1] | 246 | fibril_mutex_lock(&switch_mtx);
|
|---|
| 247 |
|
|---|
| 248 | if (cons == active_console)
|
|---|
| 249 | cons_update_state(cons, CONS_DISCONNECTED_SELECTED);
|
|---|
| 250 | else
|
|---|
| 251 | cons_update_state(cons, CONS_DISCONNECTED);
|
|---|
| 252 |
|
|---|
| 253 | fibril_mutex_unlock(&switch_mtx);
|
|---|
| [9805cde] | 254 | }
|
|---|
| 255 |
|
|---|
| [7c014d1] | 256 | static void cons_update(console_t *cons)
|
|---|
| [9805cde] | 257 | {
|
|---|
| [7c014d1] | 258 | fibril_mutex_lock(&switch_mtx);
|
|---|
| 259 | fibril_mutex_lock(&cons->mtx);
|
|---|
| 260 |
|
|---|
| 261 | if ((cons == active_console) && (active_console != kernel_console)) {
|
|---|
| 262 | fb_vp_update(fb_sess, console_vp, cons->fbid);
|
|---|
| 263 | fb_vp_cursor_update(fb_sess, console_vp, cons->fbid);
|
|---|
| 264 | }
|
|---|
| 265 |
|
|---|
| 266 | fibril_mutex_unlock(&cons->mtx);
|
|---|
| 267 | fibril_mutex_unlock(&switch_mtx);
|
|---|
| [9805cde] | 268 | }
|
|---|
| 269 |
|
|---|
| [7c014d1] | 270 | static void cons_update_cursor(console_t *cons)
|
|---|
| [9805cde] | 271 | {
|
|---|
| [7c014d1] | 272 | fibril_mutex_lock(&switch_mtx);
|
|---|
| 273 | fibril_mutex_lock(&cons->mtx);
|
|---|
| 274 |
|
|---|
| 275 | if ((cons == active_console) && (active_console != kernel_console))
|
|---|
| 276 | fb_vp_cursor_update(fb_sess, console_vp, cons->fbid);
|
|---|
| 277 |
|
|---|
| 278 | fibril_mutex_unlock(&cons->mtx);
|
|---|
| 279 | fibril_mutex_unlock(&switch_mtx);
|
|---|
| [429acb9] | 280 | }
|
|---|
| 281 |
|
|---|
| [7c014d1] | 282 | static void cons_clear(console_t *cons)
|
|---|
| [50cfa6c] | 283 | {
|
|---|
| [7c014d1] | 284 | fibril_mutex_lock(&cons->mtx);
|
|---|
| 285 | screenbuffer_clear(cons->frontbuf);
|
|---|
| 286 | fibril_mutex_unlock(&cons->mtx);
|
|---|
| [9f1362d4] | 287 |
|
|---|
| [7c014d1] | 288 | cons_update(cons);
|
|---|
| [50cfa6c] | 289 | }
|
|---|
| 290 |
|
|---|
| [7c014d1] | 291 | static void cons_damage_all(console_t *cons)
|
|---|
| [d2cc7e1] | 292 | {
|
|---|
| [7c014d1] | 293 | fibril_mutex_lock(&switch_mtx);
|
|---|
| 294 | fibril_mutex_lock(&cons->mtx);
|
|---|
| 295 |
|
|---|
| 296 | if ((cons == active_console) && (active_console != kernel_console)) {
|
|---|
| 297 | fb_vp_damage(fb_sess, console_vp, cons->fbid, 0, 0, cons->cols,
|
|---|
| 298 | cons->rows);
|
|---|
| 299 | fb_vp_cursor_update(fb_sess, console_vp, cons->fbid);
|
|---|
| [dc033a1] | 300 | }
|
|---|
| [7c014d1] | 301 |
|
|---|
| 302 | fibril_mutex_unlock(&cons->mtx);
|
|---|
| 303 | fibril_mutex_unlock(&switch_mtx);
|
|---|
| [d2cc7e1] | 304 | }
|
|---|
| 305 |
|
|---|
| [7c014d1] | 306 | static void cons_switch(console_t *cons)
|
|---|
| [d2cc7e1] | 307 | {
|
|---|
| [7c014d1] | 308 | fibril_mutex_lock(&switch_mtx);
|
|---|
| 309 |
|
|---|
| 310 | if (cons == active_console) {
|
|---|
| 311 | fibril_mutex_unlock(&switch_mtx);
|
|---|
| 312 | return;
|
|---|
| 313 | }
|
|---|
| 314 |
|
|---|
| 315 | if (cons == kernel_console) {
|
|---|
| 316 | fb_yield(fb_sess);
|
|---|
| 317 | if (!console_kcon()) {
|
|---|
| 318 | fb_claim(fb_sess);
|
|---|
| 319 | fibril_mutex_unlock(&switch_mtx);
|
|---|
| 320 | return;
|
|---|
| 321 | }
|
|---|
| [d2cc7e1] | 322 | }
|
|---|
| [7c014d1] | 323 |
|
|---|
| 324 | if (active_console == kernel_console)
|
|---|
| 325 | fb_claim(fb_sess);
|
|---|
| 326 |
|
|---|
| 327 | prev_console = active_console;
|
|---|
| 328 | active_console = cons;
|
|---|
| 329 |
|
|---|
| 330 | if (prev_console->state == CONS_DISCONNECTED_SELECTED)
|
|---|
| 331 | cons_update_state(prev_console, CONS_DISCONNECTED);
|
|---|
| 332 | else
|
|---|
| 333 | cons_update_state(prev_console, CONS_IDLE);
|
|---|
| 334 |
|
|---|
| 335 | if ((cons->state == CONS_DISCONNECTED) ||
|
|---|
| 336 | (cons->state == CONS_DISCONNECTED_SELECTED))
|
|---|
| 337 | cons_update_state(cons, CONS_DISCONNECTED_SELECTED);
|
|---|
| 338 | else
|
|---|
| 339 | cons_update_state(cons, CONS_SELECTED);
|
|---|
| 340 |
|
|---|
| 341 | fibril_mutex_unlock(&switch_mtx);
|
|---|
| 342 |
|
|---|
| 343 | cons_damage_all(cons);
|
|---|
| [d2cc7e1] | 344 | }
|
|---|
| 345 |
|
|---|
| [7c014d1] | 346 | static ssize_t limit(ssize_t val, ssize_t lo, ssize_t hi)
|
|---|
| [429acb9] | 347 | {
|
|---|
| [7c014d1] | 348 | if (val > hi)
|
|---|
| 349 | return hi;
|
|---|
| [1601f3c] | 350 |
|
|---|
| [7c014d1] | 351 | if (val < lo)
|
|---|
| 352 | return lo;
|
|---|
| [1601f3c] | 353 |
|
|---|
| [7c014d1] | 354 | return val;
|
|---|
| [429acb9] | 355 | }
|
|---|
| 356 |
|
|---|
| [7c014d1] | 357 | static void cons_mouse_move(sysarg_t dx, sysarg_t dy)
|
|---|
| [dc033a1] | 358 | {
|
|---|
| [7c014d1] | 359 | ssize_t sx = (ssize_t) dx;
|
|---|
| 360 | ssize_t sy = (ssize_t) dy;
|
|---|
| 361 |
|
|---|
| 362 | mouse.x = limit(mouse.x + sx, 0, xres);
|
|---|
| 363 | mouse.y = limit(mouse.y + sy, 0, yres);
|
|---|
| 364 |
|
|---|
| 365 | fb_pointer_update(fb_sess, mouse.x, mouse.y, true);
|
|---|
| [dc033a1] | 366 | }
|
|---|
| 367 |
|
|---|
| [7c014d1] | 368 | static console_t *cons_find_icon(sysarg_t x, sysarg_t y)
|
|---|
| [10569b1] | 369 | {
|
|---|
| [7c014d1] | 370 | sysarg_t status_start = STATE_START + (xres - 800) / 2;
|
|---|
| [9f1362d4] | 371 |
|
|---|
| [7c014d1] | 372 | if ((y < STATE_TOP) || (y >= STATE_TOP + STATE_HEIGHT))
|
|---|
| 373 | return NULL;
|
|---|
| [1601f3c] | 374 |
|
|---|
| [7c014d1] | 375 | if (x < status_start)
|
|---|
| 376 | return NULL;
|
|---|
| [10569b1] | 377 |
|
|---|
| [7c014d1] | 378 | if (x >= status_start + (STATE_WIDTH + STATE_SPACE) * CONSOLE_COUNT)
|
|---|
| 379 | return NULL;
|
|---|
| 380 |
|
|---|
| 381 | if (((x - status_start) % (STATE_WIDTH + STATE_SPACE)) < STATE_SPACE)
|
|---|
| 382 | return NULL;
|
|---|
| 383 |
|
|---|
| 384 | sysarg_t btn = (x - status_start) / (STATE_WIDTH + STATE_SPACE);
|
|---|
| 385 |
|
|---|
| 386 | if (btn < CONSOLE_COUNT)
|
|---|
| 387 | return consoles + btn;
|
|---|
| [9f1362d4] | 388 |
|
|---|
| [7c014d1] | 389 | return NULL;
|
|---|
| [10569b1] | 390 | }
|
|---|
| 391 |
|
|---|
| [7c014d1] | 392 | /** Handle mouse click
|
|---|
| 393 | *
|
|---|
| 394 | * @param state Button state (true - pressed, false - depressed)
|
|---|
| 395 | *
|
|---|
| 396 | */
|
|---|
| 397 | static console_t *cons_mouse_button(bool state)
|
|---|
| [429acb9] | 398 | {
|
|---|
| [7c014d1] | 399 | if (graphics_state != GRAPHICS_FULL)
|
|---|
| 400 | return NULL;
|
|---|
| [6d5005c] | 401 |
|
|---|
| [7c014d1] | 402 | if (state) {
|
|---|
| 403 | console_t *cons = cons_find_icon(mouse.x, mouse.y);
|
|---|
| 404 | if (cons != NULL) {
|
|---|
| 405 | mouse.btn_x = mouse.x;
|
|---|
| 406 | mouse.btn_y = mouse.y;
|
|---|
| 407 | mouse.pressed = true;
|
|---|
| [10270a8] | 408 | }
|
|---|
| [76fca31] | 409 |
|
|---|
| [7c014d1] | 410 | return NULL;
|
|---|
| [429acb9] | 411 | }
|
|---|
| [7c014d1] | 412 |
|
|---|
| 413 | if ((!state) && (!mouse.pressed))
|
|---|
| 414 | return NULL;
|
|---|
| 415 |
|
|---|
| 416 | console_t *cons = cons_find_icon(mouse.x, mouse.y);
|
|---|
| 417 | if (cons == cons_find_icon(mouse.btn_x, mouse.btn_y))
|
|---|
| 418 | return cons;
|
|---|
| 419 |
|
|---|
| 420 | mouse.pressed = false;
|
|---|
| 421 | return NULL;
|
|---|
| [429acb9] | 422 | }
|
|---|
| [10569b1] | 423 |
|
|---|
| [854eddd6] | 424 | static void input_events(ipc_callid_t iid, ipc_call_t *icall, void *arg)
|
|---|
| [51c1b003] | 425 | {
|
|---|
| [424cd43] | 426 | /* Ignore parameters, the connection is already opened */
|
|---|
| [1601f3c] | 427 | while (true) {
|
|---|
| [424cd43] | 428 | ipc_call_t call;
|
|---|
| 429 | ipc_callid_t callid = async_get_call(&call);
|
|---|
| 430 |
|
|---|
| [79ae36dd] | 431 | if (!IPC_GET_IMETHOD(call)) {
|
|---|
| [eaf34f7] | 432 | /* TODO: Handle hangup */
|
|---|
| [a40dea3] | 433 | async_hangup(input_sess);
|
|---|
| [eaf34f7] | 434 | return;
|
|---|
| [79ae36dd] | 435 | }
|
|---|
| 436 |
|
|---|
| [7c014d1] | 437 | kbd_event_type_t type;
|
|---|
| 438 | keycode_t key;
|
|---|
| 439 | keymod_t mods;
|
|---|
| 440 | wchar_t c;
|
|---|
| 441 |
|
|---|
| [79ae36dd] | 442 | switch (IPC_GET_IMETHOD(call)) {
|
|---|
| [854eddd6] | 443 | case INPUT_EVENT_KEY:
|
|---|
| [7c014d1] | 444 | type = IPC_GET_ARG1(call);
|
|---|
| 445 | key = IPC_GET_ARG2(call);
|
|---|
| 446 | mods = IPC_GET_ARG3(call);
|
|---|
| 447 | c = IPC_GET_ARG4(call);
|
|---|
| [fa09449] | 448 |
|
|---|
| [7c014d1] | 449 | if ((key >= KC_F1) && (key < KC_F1 + CONSOLE_COUNT) &&
|
|---|
| 450 | ((mods & KM_CTRL) == 0))
|
|---|
| 451 | cons_switch(&consoles[key - KC_F1]);
|
|---|
| 452 | else {
|
|---|
| 453 | /* Got key press/release event */
|
|---|
| 454 | kbd_event_t *event =
|
|---|
| 455 | (kbd_event_t *) malloc(sizeof(kbd_event_t));
|
|---|
| 456 | if (event == NULL) {
|
|---|
| 457 | async_answer_0(callid, ENOMEM);
|
|---|
| 458 | break;
|
|---|
| 459 | }
|
|---|
| 460 |
|
|---|
| 461 | link_initialize(&event->link);
|
|---|
| 462 | event->type = type;
|
|---|
| 463 | event->key = key;
|
|---|
| 464 | event->mods = mods;
|
|---|
| 465 | event->c = c;
|
|---|
| 466 |
|
|---|
| 467 | prodcons_produce(&active_console->input_pc, &event->link);
|
|---|
| [eaf34f7] | 468 | }
|
|---|
| [cf28036c] | 469 |
|
|---|
| [7c014d1] | 470 | async_answer_0(callid, EOK);
|
|---|
| [eaf34f7] | 471 | break;
|
|---|
| [854eddd6] | 472 | case INPUT_EVENT_MOVE:
|
|---|
| [7c014d1] | 473 | cons_mouse_move(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
|
|---|
| 474 | async_answer_0(callid, EOK);
|
|---|
| [854eddd6] | 475 | break;
|
|---|
| 476 | case INPUT_EVENT_BUTTON:
|
|---|
| 477 | /* Got pointer button press/release event */
|
|---|
| [9f1362d4] | 478 | if (IPC_GET_ARG1(call) == 1) {
|
|---|
| [7c014d1] | 479 | console_t *cons =
|
|---|
| 480 | cons_mouse_button((bool) IPC_GET_ARG2(call));
|
|---|
| 481 | if (cons != NULL)
|
|---|
| 482 | cons_switch(cons);
|
|---|
| [9f51afc] | 483 | }
|
|---|
| [7c014d1] | 484 | async_answer_0(callid, EOK);
|
|---|
| [9f51afc] | 485 | break;
|
|---|
| 486 | default:
|
|---|
| [7c014d1] | 487 | async_answer_0(callid, EINVAL);
|
|---|
| [9f51afc] | 488 | }
|
|---|
| [7c014d1] | 489 | }
|
|---|
| 490 | }
|
|---|
| [1875a0c] | 491 |
|
|---|
| [7c014d1] | 492 | /** Process a character from the client (TTY emulation). */
|
|---|
| 493 | static void cons_write_char(console_t *cons, wchar_t ch)
|
|---|
| 494 | {
|
|---|
| 495 | sysarg_t updated = 0;
|
|---|
| 496 |
|
|---|
| 497 | fibril_mutex_lock(&cons->mtx);
|
|---|
| 498 |
|
|---|
| 499 | switch (ch) {
|
|---|
| 500 | case '\n':
|
|---|
| 501 | updated = screenbuffer_newline(cons->frontbuf);
|
|---|
| 502 | break;
|
|---|
| 503 | case '\r':
|
|---|
| 504 | break;
|
|---|
| 505 | case '\t':
|
|---|
| 506 | updated = screenbuffer_tabstop(cons->frontbuf, 8);
|
|---|
| 507 | break;
|
|---|
| 508 | case '\b':
|
|---|
| 509 | updated = screenbuffer_backspace(cons->frontbuf);
|
|---|
| 510 | break;
|
|---|
| 511 | default:
|
|---|
| 512 | updated = screenbuffer_putchar(cons->frontbuf, ch, true);
|
|---|
| [9f51afc] | 513 | }
|
|---|
| [7c014d1] | 514 |
|
|---|
| 515 | fibril_mutex_unlock(&cons->mtx);
|
|---|
| 516 |
|
|---|
| 517 | if (updated > 1)
|
|---|
| 518 | cons_update(cons);
|
|---|
| 519 | }
|
|---|
| 520 |
|
|---|
| 521 | static void cons_set_cursor(console_t *cons, sysarg_t col, sysarg_t row)
|
|---|
| 522 | {
|
|---|
| 523 | fibril_mutex_lock(&cons->mtx);
|
|---|
| 524 | screenbuffer_set_cursor(cons->frontbuf, col, row);
|
|---|
| 525 | fibril_mutex_unlock(&cons->mtx);
|
|---|
| 526 |
|
|---|
| 527 | cons_update_cursor(cons);
|
|---|
| 528 | }
|
|---|
| 529 |
|
|---|
| 530 | static void cons_set_cursor_visibility(console_t *cons, bool visible)
|
|---|
| 531 | {
|
|---|
| 532 | fibril_mutex_lock(&cons->mtx);
|
|---|
| 533 | screenbuffer_set_cursor_visibility(cons->frontbuf, visible);
|
|---|
| 534 | fibril_mutex_unlock(&cons->mtx);
|
|---|
| 535 |
|
|---|
| 536 | cons_update_cursor(cons);
|
|---|
| 537 | }
|
|---|
| 538 |
|
|---|
| 539 | static void cons_get_cursor(console_t *cons, ipc_callid_t iid, ipc_call_t *icall)
|
|---|
| 540 | {
|
|---|
| 541 | sysarg_t col;
|
|---|
| 542 | sysarg_t row;
|
|---|
| 543 |
|
|---|
| 544 | fibril_mutex_lock(&cons->mtx);
|
|---|
| 545 | screenbuffer_get_cursor(cons->frontbuf, &col, &row);
|
|---|
| 546 | fibril_mutex_unlock(&cons->mtx);
|
|---|
| 547 |
|
|---|
| 548 | async_answer_2(iid, EOK, col, row);
|
|---|
| [9f51afc] | 549 | }
|
|---|
| 550 |
|
|---|
| [7c014d1] | 551 | static void cons_write(console_t *cons, ipc_callid_t iid, ipc_call_t *icall)
|
|---|
| [d2cc7e1] | 552 | {
|
|---|
| [472c09d] | 553 | void *buf;
|
|---|
| [171f9a1] | 554 | size_t size;
|
|---|
| [eda925a] | 555 | int rc = async_data_write_accept(&buf, false, 0, 0, 0, &size);
|
|---|
| [1601f3c] | 556 |
|
|---|
| [472c09d] | 557 | if (rc != EOK) {
|
|---|
| [7c014d1] | 558 | async_answer_0(iid, rc);
|
|---|
| [424cd43] | 559 | return;
|
|---|
| 560 | }
|
|---|
| [1601f3c] | 561 |
|
|---|
| [424cd43] | 562 | size_t off = 0;
|
|---|
| [7c014d1] | 563 | while (off < size)
|
|---|
| 564 | cons_write_char(cons, str_decode(buf, &off, size));
|
|---|
| [424cd43] | 565 |
|
|---|
| [7c014d1] | 566 | async_answer_1(iid, EOK, size);
|
|---|
| [424cd43] | 567 | free(buf);
|
|---|
| [7c014d1] | 568 |
|
|---|
| 569 | cons_notify_data(cons);
|
|---|
| [424cd43] | 570 | }
|
|---|
| 571 |
|
|---|
| [7c014d1] | 572 | static void cons_read(console_t *cons, ipc_callid_t iid, ipc_call_t *icall)
|
|---|
| [424cd43] | 573 | {
|
|---|
| 574 | ipc_callid_t callid;
|
|---|
| 575 | size_t size;
|
|---|
| [0da4e41] | 576 | if (!async_data_read_receive(&callid, &size)) {
|
|---|
| [ffa2c8ef] | 577 | async_answer_0(callid, EINVAL);
|
|---|
| [7c014d1] | 578 | async_answer_0(iid, EINVAL);
|
|---|
| [424cd43] | 579 | return;
|
|---|
| 580 | }
|
|---|
| 581 |
|
|---|
| 582 | char *buf = (char *) malloc(size);
|
|---|
| 583 | if (buf == NULL) {
|
|---|
| [ffa2c8ef] | 584 | async_answer_0(callid, ENOMEM);
|
|---|
| [7c014d1] | 585 | async_answer_0(iid, ENOMEM);
|
|---|
| [424cd43] | 586 | return;
|
|---|
| 587 | }
|
|---|
| 588 |
|
|---|
| 589 | size_t pos = 0;
|
|---|
| [7c014d1] | 590 | while (pos < size) {
|
|---|
| 591 | link_t *link = prodcons_consume(&cons->input_pc);
|
|---|
| 592 | kbd_event_t *event = list_get_instance(link, kbd_event_t, link);
|
|---|
| 593 |
|
|---|
| 594 | if (event->type == KEY_PRESS) {
|
|---|
| 595 | buf[pos] = event->c;
|
|---|
| [424cd43] | 596 | pos++;
|
|---|
| 597 | }
|
|---|
| [7c014d1] | 598 |
|
|---|
| 599 | free(event);
|
|---|
| [424cd43] | 600 | }
|
|---|
| 601 |
|
|---|
| [7c014d1] | 602 | (void) async_data_read_finalize(callid, buf, size);
|
|---|
| 603 | async_answer_1(iid, EOK, size);
|
|---|
| 604 | free(buf);
|
|---|
| [424cd43] | 605 | }
|
|---|
| 606 |
|
|---|
| [7c014d1] | 607 | static void cons_set_style(console_t *cons, console_style_t style)
|
|---|
| [424cd43] | 608 | {
|
|---|
| [7c014d1] | 609 | fibril_mutex_lock(&cons->mtx);
|
|---|
| 610 | screenbuffer_set_style(cons->frontbuf, style);
|
|---|
| 611 | fibril_mutex_unlock(&cons->mtx);
|
|---|
| 612 | }
|
|---|
| 613 |
|
|---|
| 614 | static void cons_set_color(console_t *cons, console_color_t bgcolor,
|
|---|
| 615 | console_color_t fgcolor, console_color_attr_t attr)
|
|---|
| 616 | {
|
|---|
| 617 | fibril_mutex_lock(&cons->mtx);
|
|---|
| 618 | screenbuffer_set_color(cons->frontbuf, bgcolor, fgcolor, attr);
|
|---|
| 619 | fibril_mutex_unlock(&cons->mtx);
|
|---|
| 620 | }
|
|---|
| 621 |
|
|---|
| 622 | static void cons_set_rgb_color(console_t *cons, pixel_t bgcolor,
|
|---|
| 623 | pixel_t fgcolor)
|
|---|
| 624 | {
|
|---|
| 625 | fibril_mutex_lock(&cons->mtx);
|
|---|
| 626 | screenbuffer_set_rgb_color(cons->frontbuf, bgcolor, fgcolor);
|
|---|
| 627 | fibril_mutex_unlock(&cons->mtx);
|
|---|
| 628 | }
|
|---|
| 629 |
|
|---|
| 630 | static void cons_get_event(console_t *cons, ipc_callid_t iid, ipc_call_t *icall)
|
|---|
| 631 | {
|
|---|
| 632 | link_t *link = prodcons_consume(&cons->input_pc);
|
|---|
| 633 | kbd_event_t *event = list_get_instance(link, kbd_event_t, link);
|
|---|
| [9f1362d4] | 634 |
|
|---|
| [7c014d1] | 635 | async_answer_4(iid, EOK, event->type, event->key, event->mods, event->c);
|
|---|
| 636 | free(event);
|
|---|
| [d2cc7e1] | 637 | }
|
|---|
| 638 |
|
|---|
| [9934f7d] | 639 | static void client_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
|
|---|
| [eaf34f7] | 640 | {
|
|---|
| [424cd43] | 641 | console_t *cons = NULL;
|
|---|
| [3ad953c] | 642 |
|
|---|
| [7c014d1] | 643 | for (size_t i = 0; i < CONSOLE_COUNT; i++) {
|
|---|
| [424cd43] | 644 | if (i == KERNEL_CONSOLE)
|
|---|
| 645 | continue;
|
|---|
| 646 |
|
|---|
| [7c014d1] | 647 | if (consoles[i].dsid == (service_id_t) IPC_GET_ARG1(*icall)) {
|
|---|
| [424cd43] | 648 | cons = &consoles[i];
|
|---|
| 649 | break;
|
|---|
| 650 | }
|
|---|
| 651 | }
|
|---|
| 652 |
|
|---|
| 653 | if (cons == NULL) {
|
|---|
| [ffa2c8ef] | 654 | async_answer_0(iid, ENOENT);
|
|---|
| [eaf34f7] | 655 | return;
|
|---|
| 656 | }
|
|---|
| [424cd43] | 657 |
|
|---|
| [7c014d1] | 658 | if (atomic_postinc(&cons->refcnt) == 0) {
|
|---|
| 659 | cons_set_cursor_visibility(cons, true);
|
|---|
| 660 | cons_notify_connect(cons);
|
|---|
| 661 | }
|
|---|
| [10569b1] | 662 |
|
|---|
| [eaf34f7] | 663 | /* Accept the connection */
|
|---|
| [ffa2c8ef] | 664 | async_answer_0(iid, EOK);
|
|---|
| [3ad953c] | 665 |
|
|---|
| [1601f3c] | 666 | while (true) {
|
|---|
| [7c014d1] | 667 | ipc_call_t call;
|
|---|
| 668 | ipc_callid_t callid = async_get_call(&call);
|
|---|
| [1601f3c] | 669 |
|
|---|
| [79ae36dd] | 670 | if (!IPC_GET_IMETHOD(call)) {
|
|---|
| [7c014d1] | 671 | if (atomic_postdec(&cons->refcnt) == 1)
|
|---|
| 672 | cons_notify_disconnect(cons);
|
|---|
| 673 |
|
|---|
| [eaf34f7] | 674 | return;
|
|---|
| [79ae36dd] | 675 | }
|
|---|
| 676 |
|
|---|
| 677 | switch (IPC_GET_IMETHOD(call)) {
|
|---|
| [4198f9c3] | 678 | case VFS_OUT_READ:
|
|---|
| [424cd43] | 679 | cons_read(cons, callid, &call);
|
|---|
| [7c014d1] | 680 | break;
|
|---|
| [4198f9c3] | 681 | case VFS_OUT_WRITE:
|
|---|
| [424cd43] | 682 | cons_write(cons, callid, &call);
|
|---|
| [7c014d1] | 683 | break;
|
|---|
| [4198f9c3] | 684 | case VFS_OUT_SYNC:
|
|---|
| [7c014d1] | 685 | cons_update(cons);
|
|---|
| 686 | async_answer_0(callid, EOK);
|
|---|
| [424cd43] | 687 | break;
|
|---|
| [ad123964] | 688 | case CONSOLE_CLEAR:
|
|---|
| [7c014d1] | 689 | cons_clear(cons);
|
|---|
| 690 | async_answer_0(callid, EOK);
|
|---|
| [eaf34f7] | 691 | break;
|
|---|
| [ad123964] | 692 | case CONSOLE_GOTO:
|
|---|
| [7c014d1] | 693 | cons_set_cursor(cons, IPC_GET_ARG1(call), IPC_GET_ARG2(call));
|
|---|
| 694 | async_answer_0(callid, EOK);
|
|---|
| [ad123964] | 695 | break;
|
|---|
| [19528516] | 696 | case CONSOLE_GET_POS:
|
|---|
| [7c014d1] | 697 | cons_get_cursor(cons, callid, &call);
|
|---|
| [19528516] | 698 | break;
|
|---|
| [424cd43] | 699 | case CONSOLE_GET_SIZE:
|
|---|
| [7c014d1] | 700 | async_answer_2(callid, EOK, cons->cols, cons->rows);
|
|---|
| [a9bd960c] | 701 | break;
|
|---|
| [50cfa6c] | 702 | case CONSOLE_GET_COLOR_CAP:
|
|---|
| [7c014d1] | 703 | async_answer_1(callid, EOK, cons->ccaps);
|
|---|
| [50cfa6c] | 704 | break;
|
|---|
| [a9bd960c] | 705 | case CONSOLE_SET_STYLE:
|
|---|
| [7c014d1] | 706 | cons_set_style(cons, IPC_GET_ARG1(call));
|
|---|
| 707 | async_answer_0(callid, EOK);
|
|---|
| [9805cde] | 708 | break;
|
|---|
| 709 | case CONSOLE_SET_COLOR:
|
|---|
| [7c014d1] | 710 | cons_set_color(cons, IPC_GET_ARG1(call), IPC_GET_ARG2(call),
|
|---|
| 711 | IPC_GET_ARG3(call));
|
|---|
| 712 | async_answer_0(callid, EOK);
|
|---|
| [9805cde] | 713 | break;
|
|---|
| 714 | case CONSOLE_SET_RGB_COLOR:
|
|---|
| [7c014d1] | 715 | cons_set_rgb_color(cons, IPC_GET_ARG1(call), IPC_GET_ARG2(call));
|
|---|
| 716 | async_answer_0(callid, EOK);
|
|---|
| [0c6984e] | 717 | break;
|
|---|
| [a8b2b5b2] | 718 | case CONSOLE_CURSOR_VISIBILITY:
|
|---|
| [7c014d1] | 719 | cons_set_cursor_visibility(cons, IPC_GET_ARG1(call));
|
|---|
| 720 | async_answer_0(callid, EOK);
|
|---|
| [a8b2b5b2] | 721 | break;
|
|---|
| [424cd43] | 722 | case CONSOLE_GET_EVENT:
|
|---|
| 723 | cons_get_event(cons, callid, &call);
|
|---|
| [7c014d1] | 724 | break;
|
|---|
| 725 | default:
|
|---|
| 726 | async_answer_0(callid, EINVAL);
|
|---|
| [eaf34f7] | 727 | }
|
|---|
| 728 | }
|
|---|
| 729 | }
|
|---|
| 730 |
|
|---|
| [7c014d1] | 731 | static async_sess_t *input_connect(const char *svc)
|
|---|
| [eaf34f7] | 732 | {
|
|---|
| [a40dea3] | 733 | async_sess_t *sess;
|
|---|
| [7c014d1] | 734 | service_id_t dsid;
|
|---|
| [9f1362d4] | 735 |
|
|---|
| [7c014d1] | 736 | int rc = loc_service_get_id(svc, &dsid, 0);
|
|---|
| [79ae36dd] | 737 | if (rc == EOK) {
|
|---|
| [7c014d1] | 738 | sess = loc_service_connect(EXCHANGE_ATOMIC, dsid, 0);
|
|---|
| [a40dea3] | 739 | if (sess == NULL) {
|
|---|
| [7c014d1] | 740 | printf("%s: Unable to connect to input service %s\n", NAME,
|
|---|
| 741 | svc);
|
|---|
| [a40dea3] | 742 | return NULL;
|
|---|
| [79ae36dd] | 743 | }
|
|---|
| [7c014d1] | 744 | } else
|
|---|
| [a40dea3] | 745 | return NULL;
|
|---|
| [9f1362d4] | 746 |
|
|---|
| [7c014d1] | 747 | async_exch_t *exch = async_exchange_begin(sess);
|
|---|
| [3015f4d] | 748 | rc = async_connect_to_me(exch, 0, 0, 0, input_events, NULL);
|
|---|
| [a40dea3] | 749 | async_exchange_end(exch);
|
|---|
| [7c014d1] | 750 |
|
|---|
| [700af62] | 751 | if (rc != EOK) {
|
|---|
| [a40dea3] | 752 | async_hangup(sess);
|
|---|
| [7c014d1] | 753 | printf("%s: Unable to create callback connection to service %s (%s)\n",
|
|---|
| 754 | NAME, svc, str_error(rc));
|
|---|
| [a40dea3] | 755 | return NULL;
|
|---|
| [4904de8] | 756 | }
|
|---|
| [9f1362d4] | 757 |
|
|---|
| [a40dea3] | 758 | return sess;
|
|---|
| [700af62] | 759 | }
|
|---|
| 760 |
|
|---|
| [7c014d1] | 761 | static void interrupt_received(ipc_callid_t callid, ipc_call_t *call)
|
|---|
| 762 | {
|
|---|
| 763 | cons_switch(prev_console);
|
|---|
| 764 | }
|
|---|
| 765 |
|
|---|
| 766 | static async_sess_t *fb_connect(const char *svc)
|
|---|
| [700af62] | 767 | {
|
|---|
| [7c014d1] | 768 | async_sess_t *sess;
|
|---|
| 769 | service_id_t dsid;
|
|---|
| 770 |
|
|---|
| 771 | int rc = loc_service_get_id(svc, &dsid, 0);
|
|---|
| 772 | if (rc == EOK) {
|
|---|
| 773 | sess = loc_service_connect(EXCHANGE_SERIALIZE, dsid, 0);
|
|---|
| 774 | if (sess == NULL) {
|
|---|
| 775 | printf("%s: Unable to connect to framebuffer service %s\n",
|
|---|
| 776 | NAME, svc);
|
|---|
| 777 | return NULL;
|
|---|
| 778 | }
|
|---|
| 779 | } else
|
|---|
| 780 | return NULL;
|
|---|
| 781 |
|
|---|
| 782 | return sess;
|
|---|
| 783 | }
|
|---|
| 784 |
|
|---|
| 785 | static bool console_srv_init(char *input_svc, char *fb_svc)
|
|---|
| 786 | {
|
|---|
| 787 | /* Avoid double initialization */
|
|---|
| 788 | if (graphics_state != GRAPHICS_NONE)
|
|---|
| 789 | return false;
|
|---|
| 790 |
|
|---|
| 791 | /* Connect to input service */
|
|---|
| 792 | input_sess = input_connect(input_svc);
|
|---|
| [a40dea3] | 793 | if (input_sess == NULL)
|
|---|
| [700af62] | 794 | return false;
|
|---|
| [79ae36dd] | 795 |
|
|---|
| [7c014d1] | 796 | /* Connect to framebuffer service */
|
|---|
| 797 | fb_sess = fb_connect(fb_svc);
|
|---|
| 798 | if (fb_sess == NULL)
|
|---|
| [79ae36dd] | 799 | return false;
|
|---|
| [9f1362d4] | 800 |
|
|---|
| [15f3c3f] | 801 | /* Register server */
|
|---|
| 802 | int rc = loc_server_register(NAME, client_connection);
|
|---|
| [424cd43] | 803 | if (rc < 0) {
|
|---|
| [7c014d1] | 804 | printf("%s: Unable to register server (%s)\n", NAME,
|
|---|
| 805 | str_error(rc));
|
|---|
| [424cd43] | 806 | return false;
|
|---|
| 807 | }
|
|---|
| [516ff92] | 808 |
|
|---|
| [7c014d1] | 809 | fb_get_resolution(fb_sess, &xres, &yres);
|
|---|
| [3993b3d] | 810 |
|
|---|
| [7c014d1] | 811 | /* Initialize the screen */
|
|---|
| 812 | screen_vp = fb_vp_create(fb_sess, 0, 0, xres, yres);
|
|---|
| [1601f3c] | 813 |
|
|---|
| [7c014d1] | 814 | if ((xres >= 800) && (yres >= 600)) {
|
|---|
| 815 | logo_vp = fb_vp_create(fb_sess, xres - 66, 2, 64, 60);
|
|---|
| 816 | logo_img = imgmap_decode_tga((void *) helenos_tga,
|
|---|
| 817 | helenos_tga_size, IMGMAP_FLAG_SHARED);
|
|---|
| 818 | logo_handle = fb_imagemap_create(fb_sess, logo_img);
|
|---|
| 819 |
|
|---|
| 820 | nameic_vp = fb_vp_create(fb_sess, 5, 17, 100, 26);
|
|---|
| 821 | nameic_img = imgmap_decode_tga((void *) nameic_tga,
|
|---|
| 822 | nameic_tga_size, IMGMAP_FLAG_SHARED);
|
|---|
| 823 | nameic_handle = fb_imagemap_create(fb_sess, nameic_img);
|
|---|
| 824 |
|
|---|
| 825 | cons_data_img = imgmap_decode_tga((void *) cons_data_tga,
|
|---|
| 826 | cons_data_tga_size, IMGMAP_FLAG_SHARED);
|
|---|
| 827 | cons_dis_img = imgmap_decode_tga((void *) cons_dis_tga,
|
|---|
| 828 | cons_dis_tga_size, IMGMAP_FLAG_SHARED);
|
|---|
| 829 | cons_dis_sel_img = imgmap_decode_tga((void *) cons_dis_sel_tga,
|
|---|
| 830 | cons_dis_sel_tga_size, IMGMAP_FLAG_SHARED);
|
|---|
| 831 | cons_idle_img = imgmap_decode_tga((void *) cons_idle_tga,
|
|---|
| 832 | cons_idle_tga_size, IMGMAP_FLAG_SHARED);
|
|---|
| 833 | cons_kernel_img = imgmap_decode_tga((void *) cons_kernel_tga,
|
|---|
| 834 | cons_kernel_tga_size, IMGMAP_FLAG_SHARED);
|
|---|
| 835 | cons_sel_img = imgmap_decode_tga((void *) cons_sel_tga,
|
|---|
| 836 | cons_sel_tga_size, IMGMAP_FLAG_SHARED);
|
|---|
| 837 |
|
|---|
| 838 | state_icons[CONS_DISCONNECTED] =
|
|---|
| 839 | fb_imagemap_create(fb_sess, cons_dis_img);
|
|---|
| 840 | state_icons[CONS_DISCONNECTED_SELECTED] =
|
|---|
| 841 | fb_imagemap_create(fb_sess, cons_dis_sel_img);
|
|---|
| 842 | state_icons[CONS_SELECTED] =
|
|---|
| 843 | fb_imagemap_create(fb_sess, cons_sel_img);
|
|---|
| 844 | state_icons[CONS_IDLE] =
|
|---|
| 845 | fb_imagemap_create(fb_sess, cons_idle_img);
|
|---|
| 846 | state_icons[CONS_DATA] =
|
|---|
| 847 | fb_imagemap_create(fb_sess, cons_data_img);
|
|---|
| 848 | state_icons[CONS_KERNEL] =
|
|---|
| 849 | fb_imagemap_create(fb_sess, cons_kernel_img);
|
|---|
| 850 |
|
|---|
| 851 | anim_1_img = imgmap_decode_tga((void *) anim_1_tga,
|
|---|
| 852 | anim_1_tga_size, IMGMAP_FLAG_SHARED);
|
|---|
| 853 | anim_2_img = imgmap_decode_tga((void *) anim_2_tga,
|
|---|
| 854 | anim_2_tga_size, IMGMAP_FLAG_SHARED);
|
|---|
| 855 | anim_3_img = imgmap_decode_tga((void *) anim_3_tga,
|
|---|
| 856 | anim_3_tga_size, IMGMAP_FLAG_SHARED);
|
|---|
| 857 | anim_4_img = imgmap_decode_tga((void *) anim_4_tga,
|
|---|
| 858 | anim_4_tga_size, IMGMAP_FLAG_SHARED);
|
|---|
| 859 |
|
|---|
| 860 | anim_1 = fb_imagemap_create(fb_sess, anim_1_img);
|
|---|
| 861 | anim_2 = fb_imagemap_create(fb_sess, anim_2_img);
|
|---|
| 862 | anim_3 = fb_imagemap_create(fb_sess, anim_3_img);
|
|---|
| 863 | anim_4 = fb_imagemap_create(fb_sess, anim_4_img);
|
|---|
| 864 |
|
|---|
| 865 | anim_seq = fb_sequence_create(fb_sess);
|
|---|
| 866 | fb_sequence_add_imagemap(fb_sess, anim_seq, anim_1);
|
|---|
| 867 | fb_sequence_add_imagemap(fb_sess, anim_seq, anim_2);
|
|---|
| 868 | fb_sequence_add_imagemap(fb_sess, anim_seq, anim_3);
|
|---|
| 869 | fb_sequence_add_imagemap(fb_sess, anim_seq, anim_4);
|
|---|
| 870 |
|
|---|
| 871 | console_vp = fb_vp_create(fb_sess, CONSOLE_MARGIN, CONSOLE_TOP,
|
|---|
| 872 | xres - 2 * CONSOLE_MARGIN, yres - (CONSOLE_TOP + CONSOLE_MARGIN));
|
|---|
| 873 |
|
|---|
| 874 | fb_vp_clear(fb_sess, screen_vp);
|
|---|
| 875 | fb_vp_imagemap_damage(fb_sess, logo_vp, logo_handle,
|
|---|
| 876 | 0, 0, 64, 60);
|
|---|
| 877 | fb_vp_imagemap_damage(fb_sess, nameic_vp, nameic_handle,
|
|---|
| 878 | 0, 0, 100, 26);
|
|---|
| 879 |
|
|---|
| 880 | graphics_state = GRAPHICS_FULL;
|
|---|
| 881 | } else {
|
|---|
| 882 | console_vp = screen_vp;
|
|---|
| 883 | graphics_state = GRAPHICS_BASIC;
|
|---|
| 884 | }
|
|---|
| [1601f3c] | 885 |
|
|---|
| [7c014d1] | 886 | fb_vp_set_style(fb_sess, console_vp, STYLE_NORMAL);
|
|---|
| 887 | fb_vp_clear(fb_sess, console_vp);
|
|---|
| [1601f3c] | 888 |
|
|---|
| [7c014d1] | 889 | sysarg_t cols;
|
|---|
| 890 | sysarg_t rows;
|
|---|
| 891 | fb_vp_get_dimensions(fb_sess, console_vp, &cols, &rows);
|
|---|
| 892 |
|
|---|
| 893 | console_caps_t ccaps;
|
|---|
| 894 | fb_vp_get_caps(fb_sess, console_vp, &ccaps);
|
|---|
| [3ad953c] | 895 |
|
|---|
| [b7c33b0] | 896 | mouse.x = xres / 2;
|
|---|
| 897 | mouse.y = yres / 2;
|
|---|
| [7c014d1] | 898 | mouse.pressed = false;
|
|---|
| [3ad953c] | 899 |
|
|---|
| [424cd43] | 900 | /* Inititalize consoles */
|
|---|
| [7c014d1] | 901 | for (size_t i = 0; i < CONSOLE_COUNT; i++) {
|
|---|
| 902 | consoles[i].index = i;
|
|---|
| 903 | atomic_set(&consoles[i].refcnt, 0);
|
|---|
| 904 | fibril_mutex_initialize(&consoles[i].mtx);
|
|---|
| 905 |
|
|---|
| 906 | if (graphics_state == GRAPHICS_FULL) {
|
|---|
| 907 | /* Create state buttons */
|
|---|
| 908 | consoles[i].state_vp =
|
|---|
| 909 | fb_vp_create(fb_sess, STATE_START + (xres - 800) / 2 +
|
|---|
| 910 | CONSOLE_MARGIN + i * (STATE_WIDTH + STATE_SPACE),
|
|---|
| 911 | STATE_TOP, STATE_WIDTH, STATE_HEIGHT);
|
|---|
| 912 | }
|
|---|
| 913 |
|
|---|
| 914 | if (i == KERNEL_CONSOLE) {
|
|---|
| 915 | consoles[i].state = CONS_KERNEL;
|
|---|
| 916 | cons_redraw_state(&consoles[i]);
|
|---|
| 917 | cons_kernel_sequence_start(&consoles[i]);
|
|---|
| 918 | continue;
|
|---|
| 919 | }
|
|---|
| 920 |
|
|---|
| 921 | if (i == 0)
|
|---|
| 922 | consoles[i].state = CONS_DISCONNECTED_SELECTED;
|
|---|
| 923 | else
|
|---|
| 924 | consoles[i].state = CONS_DISCONNECTED;
|
|---|
| 925 |
|
|---|
| 926 | consoles[i].cols = cols;
|
|---|
| 927 | consoles[i].rows = rows;
|
|---|
| 928 | consoles[i].ccaps = ccaps;
|
|---|
| 929 | consoles[i].frontbuf =
|
|---|
| 930 | screenbuffer_create(cols, rows, SCREENBUFFER_FLAG_SHARED);
|
|---|
| 931 |
|
|---|
| 932 | if (consoles[i].frontbuf == NULL) {
|
|---|
| 933 | printf("%s: Unable to allocate frontbuffer %zu\n", NAME, i);
|
|---|
| 934 | return false;
|
|---|
| 935 | }
|
|---|
| 936 |
|
|---|
| 937 | consoles[i].fbid = fb_frontbuf_create(fb_sess, consoles[i].frontbuf);
|
|---|
| 938 | if (consoles[i].fbid == 0) {
|
|---|
| 939 | printf("%s: Unable to create frontbuffer %zu\n", NAME, i);
|
|---|
| 940 | return false;
|
|---|
| 941 | }
|
|---|
| 942 |
|
|---|
| 943 | prodcons_initialize(&consoles[i].input_pc);
|
|---|
| 944 | cons_redraw_state(&consoles[i]);
|
|---|
| 945 |
|
|---|
| 946 | char vc[LOC_NAME_MAXLEN + 1];
|
|---|
| 947 | snprintf(vc, LOC_NAME_MAXLEN, "%s/vc%zu", NAMESPACE, i);
|
|---|
| 948 |
|
|---|
| 949 | if (loc_service_register(vc, &consoles[i].dsid) != EOK) {
|
|---|
| 950 | printf("%s: Unable to register device %s\n", NAME, vc);
|
|---|
| 951 | return false;
|
|---|
| [424cd43] | 952 | }
|
|---|
| 953 | }
|
|---|
| 954 |
|
|---|
| [3ad953c] | 955 | /* Receive kernel notifications */
|
|---|
| [007e6efa] | 956 | async_set_interrupt_received(interrupt_received);
|
|---|
| [7c014d1] | 957 | rc = event_subscribe(EVENT_KCONSOLE, 0);
|
|---|
| 958 | if (rc != EOK)
|
|---|
| 959 | printf("%s: Failed to register kconsole notifications (%s)\n",
|
|---|
| 960 | NAME, str_error(rc));
|
|---|
| [1601f3c] | 961 |
|
|---|
| [424cd43] | 962 | return true;
|
|---|
| 963 | }
|
|---|
| 964 |
|
|---|
| [47a350f] | 965 | static void usage(void)
|
|---|
| 966 | {
|
|---|
| [7c014d1] | 967 | printf("Usage: console <input_dev> <framebuffer_dev>\n");
|
|---|
| [47a350f] | 968 | }
|
|---|
| 969 |
|
|---|
| [424cd43] | 970 | int main(int argc, char *argv[])
|
|---|
| 971 | {
|
|---|
| [7c014d1] | 972 | if (argc < 3) {
|
|---|
| [47a350f] | 973 | usage();
|
|---|
| 974 | return -1;
|
|---|
| 975 | }
|
|---|
| 976 |
|
|---|
| [7c014d1] | 977 | printf("%s: HelenOS Console service\n", NAME);
|
|---|
| [424cd43] | 978 |
|
|---|
| [7c014d1] | 979 | if (!console_srv_init(argv[1], argv[2]))
|
|---|
| [424cd43] | 980 | return -1;
|
|---|
| [79ae36dd] | 981 |
|
|---|
| [7c014d1] | 982 | printf("%s: Accepting connections\n", NAME);
|
|---|
| 983 | task_retval(0);
|
|---|
| [eaf34f7] | 984 | async_manager();
|
|---|
| [3ad953c] | 985 |
|
|---|
| 986 | return 0;
|
|---|
| [51c1b003] | 987 | }
|
|---|
| [516ff92] | 988 |
|
|---|
| [ce5bcb4] | 989 | /** @}
|
|---|
| 990 | */
|
|---|