[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 |
|
---|
[cccc091] | 62 | #define STATE_START 100
|
---|
[7c014d1] | 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 |
|
---|
[024fcc5] | 346 | static console_t *cons_get_active_uspace(void)
|
---|
| 347 | {
|
---|
| 348 | fibril_mutex_lock(&switch_mtx);
|
---|
| 349 |
|
---|
| 350 | console_t *active_uspace = active_console;
|
---|
| 351 | if (active_uspace == kernel_console) {
|
---|
| 352 | active_uspace = prev_console;
|
---|
| 353 | }
|
---|
| 354 | assert(active_uspace != kernel_console);
|
---|
| 355 |
|
---|
| 356 | fibril_mutex_unlock(&switch_mtx);
|
---|
| 357 |
|
---|
| 358 | return active_uspace;
|
---|
| 359 | }
|
---|
| 360 |
|
---|
[7c014d1] | 361 | static ssize_t limit(ssize_t val, ssize_t lo, ssize_t hi)
|
---|
[429acb9] | 362 | {
|
---|
[7c014d1] | 363 | if (val > hi)
|
---|
| 364 | return hi;
|
---|
[1601f3c] | 365 |
|
---|
[7c014d1] | 366 | if (val < lo)
|
---|
| 367 | return lo;
|
---|
[1601f3c] | 368 |
|
---|
[7c014d1] | 369 | return val;
|
---|
[429acb9] | 370 | }
|
---|
| 371 |
|
---|
[7c014d1] | 372 | static void cons_mouse_move(sysarg_t dx, sysarg_t dy)
|
---|
[dc033a1] | 373 | {
|
---|
[7c014d1] | 374 | ssize_t sx = (ssize_t) dx;
|
---|
| 375 | ssize_t sy = (ssize_t) dy;
|
---|
| 376 |
|
---|
| 377 | mouse.x = limit(mouse.x + sx, 0, xres);
|
---|
| 378 | mouse.y = limit(mouse.y + sy, 0, yres);
|
---|
| 379 |
|
---|
| 380 | fb_pointer_update(fb_sess, mouse.x, mouse.y, true);
|
---|
[dc033a1] | 381 | }
|
---|
| 382 |
|
---|
[7c014d1] | 383 | static console_t *cons_find_icon(sysarg_t x, sysarg_t y)
|
---|
[10569b1] | 384 | {
|
---|
[cccc091] | 385 | sysarg_t status_start =
|
---|
| 386 | STATE_START + (xres - 800) / 2 + CONSOLE_MARGIN;
|
---|
[9f1362d4] | 387 |
|
---|
[7c014d1] | 388 | if ((y < STATE_TOP) || (y >= STATE_TOP + STATE_HEIGHT))
|
---|
| 389 | return NULL;
|
---|
[1601f3c] | 390 |
|
---|
[7c014d1] | 391 | if (x < status_start)
|
---|
| 392 | return NULL;
|
---|
[10569b1] | 393 |
|
---|
[7c014d1] | 394 | if (x >= status_start + (STATE_WIDTH + STATE_SPACE) * CONSOLE_COUNT)
|
---|
| 395 | return NULL;
|
---|
| 396 |
|
---|
[cccc091] | 397 | if (((x - status_start) % (STATE_WIDTH + STATE_SPACE)) >= STATE_WIDTH)
|
---|
[7c014d1] | 398 | return NULL;
|
---|
| 399 |
|
---|
| 400 | sysarg_t btn = (x - status_start) / (STATE_WIDTH + STATE_SPACE);
|
---|
| 401 |
|
---|
| 402 | if (btn < CONSOLE_COUNT)
|
---|
| 403 | return consoles + btn;
|
---|
[9f1362d4] | 404 |
|
---|
[7c014d1] | 405 | return NULL;
|
---|
[10569b1] | 406 | }
|
---|
| 407 |
|
---|
[7c014d1] | 408 | /** Handle mouse click
|
---|
| 409 | *
|
---|
| 410 | * @param state Button state (true - pressed, false - depressed)
|
---|
| 411 | *
|
---|
| 412 | */
|
---|
| 413 | static console_t *cons_mouse_button(bool state)
|
---|
[429acb9] | 414 | {
|
---|
[7c014d1] | 415 | if (graphics_state != GRAPHICS_FULL)
|
---|
| 416 | return NULL;
|
---|
[6d5005c] | 417 |
|
---|
[7c014d1] | 418 | if (state) {
|
---|
| 419 | console_t *cons = cons_find_icon(mouse.x, mouse.y);
|
---|
| 420 | if (cons != NULL) {
|
---|
| 421 | mouse.btn_x = mouse.x;
|
---|
| 422 | mouse.btn_y = mouse.y;
|
---|
| 423 | mouse.pressed = true;
|
---|
[10270a8] | 424 | }
|
---|
[76fca31] | 425 |
|
---|
[7c014d1] | 426 | return NULL;
|
---|
[429acb9] | 427 | }
|
---|
[7c014d1] | 428 |
|
---|
| 429 | if ((!state) && (!mouse.pressed))
|
---|
| 430 | return NULL;
|
---|
| 431 |
|
---|
| 432 | console_t *cons = cons_find_icon(mouse.x, mouse.y);
|
---|
| 433 | if (cons == cons_find_icon(mouse.btn_x, mouse.btn_y))
|
---|
| 434 | return cons;
|
---|
| 435 |
|
---|
| 436 | mouse.pressed = false;
|
---|
| 437 | return NULL;
|
---|
[429acb9] | 438 | }
|
---|
[10569b1] | 439 |
|
---|
[854eddd6] | 440 | static void input_events(ipc_callid_t iid, ipc_call_t *icall, void *arg)
|
---|
[51c1b003] | 441 | {
|
---|
[424cd43] | 442 | /* Ignore parameters, the connection is already opened */
|
---|
[1601f3c] | 443 | while (true) {
|
---|
[424cd43] | 444 | ipc_call_t call;
|
---|
| 445 | ipc_callid_t callid = async_get_call(&call);
|
---|
| 446 |
|
---|
[79ae36dd] | 447 | if (!IPC_GET_IMETHOD(call)) {
|
---|
[eaf34f7] | 448 | /* TODO: Handle hangup */
|
---|
[a40dea3] | 449 | async_hangup(input_sess);
|
---|
[eaf34f7] | 450 | return;
|
---|
[79ae36dd] | 451 | }
|
---|
| 452 |
|
---|
[7c014d1] | 453 | kbd_event_type_t type;
|
---|
| 454 | keycode_t key;
|
---|
| 455 | keymod_t mods;
|
---|
| 456 | wchar_t c;
|
---|
| 457 |
|
---|
[79ae36dd] | 458 | switch (IPC_GET_IMETHOD(call)) {
|
---|
[854eddd6] | 459 | case INPUT_EVENT_KEY:
|
---|
[7c014d1] | 460 | type = IPC_GET_ARG1(call);
|
---|
| 461 | key = IPC_GET_ARG2(call);
|
---|
| 462 | mods = IPC_GET_ARG3(call);
|
---|
| 463 | c = IPC_GET_ARG4(call);
|
---|
[fa09449] | 464 |
|
---|
[7c014d1] | 465 | if ((key >= KC_F1) && (key < KC_F1 + CONSOLE_COUNT) &&
|
---|
| 466 | ((mods & KM_CTRL) == 0))
|
---|
| 467 | cons_switch(&consoles[key - KC_F1]);
|
---|
| 468 | else {
|
---|
| 469 | /* Got key press/release event */
|
---|
| 470 | kbd_event_t *event =
|
---|
| 471 | (kbd_event_t *) malloc(sizeof(kbd_event_t));
|
---|
| 472 | if (event == NULL) {
|
---|
| 473 | async_answer_0(callid, ENOMEM);
|
---|
| 474 | break;
|
---|
| 475 | }
|
---|
| 476 |
|
---|
| 477 | link_initialize(&event->link);
|
---|
| 478 | event->type = type;
|
---|
| 479 | event->key = key;
|
---|
| 480 | event->mods = mods;
|
---|
| 481 | event->c = c;
|
---|
| 482 |
|
---|
[e37eddc] | 483 | /*
|
---|
| 484 | * Kernel console does not read events
|
---|
[024fcc5] | 485 | * from us, so we will redirect them
|
---|
| 486 | * to the (last) active userspace console
|
---|
| 487 | * if necessary.
|
---|
| 488 | */
|
---|
| 489 | console_t *target_console = cons_get_active_uspace();
|
---|
[e37eddc] | 490 |
|
---|
[024fcc5] | 491 | prodcons_produce(&target_console->input_pc,
|
---|
| 492 | &event->link);
|
---|
[eaf34f7] | 493 | }
|
---|
[cf28036c] | 494 |
|
---|
[7c014d1] | 495 | async_answer_0(callid, EOK);
|
---|
[eaf34f7] | 496 | break;
|
---|
[854eddd6] | 497 | case INPUT_EVENT_MOVE:
|
---|
[7c014d1] | 498 | cons_mouse_move(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
|
---|
| 499 | async_answer_0(callid, EOK);
|
---|
[854eddd6] | 500 | break;
|
---|
| 501 | case INPUT_EVENT_BUTTON:
|
---|
| 502 | /* Got pointer button press/release event */
|
---|
[9f1362d4] | 503 | if (IPC_GET_ARG1(call) == 1) {
|
---|
[7c014d1] | 504 | console_t *cons =
|
---|
| 505 | cons_mouse_button((bool) IPC_GET_ARG2(call));
|
---|
| 506 | if (cons != NULL)
|
---|
| 507 | cons_switch(cons);
|
---|
[9f51afc] | 508 | }
|
---|
[7c014d1] | 509 | async_answer_0(callid, EOK);
|
---|
[9f51afc] | 510 | break;
|
---|
| 511 | default:
|
---|
[7c014d1] | 512 | async_answer_0(callid, EINVAL);
|
---|
[9f51afc] | 513 | }
|
---|
[7c014d1] | 514 | }
|
---|
| 515 | }
|
---|
[1875a0c] | 516 |
|
---|
[7c014d1] | 517 | /** Process a character from the client (TTY emulation). */
|
---|
| 518 | static void cons_write_char(console_t *cons, wchar_t ch)
|
---|
| 519 | {
|
---|
| 520 | sysarg_t updated = 0;
|
---|
| 521 |
|
---|
| 522 | fibril_mutex_lock(&cons->mtx);
|
---|
| 523 |
|
---|
| 524 | switch (ch) {
|
---|
| 525 | case '\n':
|
---|
| 526 | updated = screenbuffer_newline(cons->frontbuf);
|
---|
| 527 | break;
|
---|
| 528 | case '\r':
|
---|
| 529 | break;
|
---|
| 530 | case '\t':
|
---|
| 531 | updated = screenbuffer_tabstop(cons->frontbuf, 8);
|
---|
| 532 | break;
|
---|
| 533 | case '\b':
|
---|
| 534 | updated = screenbuffer_backspace(cons->frontbuf);
|
---|
| 535 | break;
|
---|
| 536 | default:
|
---|
| 537 | updated = screenbuffer_putchar(cons->frontbuf, ch, true);
|
---|
[9f51afc] | 538 | }
|
---|
[7c014d1] | 539 |
|
---|
| 540 | fibril_mutex_unlock(&cons->mtx);
|
---|
| 541 |
|
---|
| 542 | if (updated > 1)
|
---|
| 543 | cons_update(cons);
|
---|
| 544 | }
|
---|
| 545 |
|
---|
| 546 | static void cons_set_cursor(console_t *cons, sysarg_t col, sysarg_t row)
|
---|
| 547 | {
|
---|
| 548 | fibril_mutex_lock(&cons->mtx);
|
---|
| 549 | screenbuffer_set_cursor(cons->frontbuf, col, row);
|
---|
| 550 | fibril_mutex_unlock(&cons->mtx);
|
---|
| 551 |
|
---|
| 552 | cons_update_cursor(cons);
|
---|
| 553 | }
|
---|
| 554 |
|
---|
| 555 | static void cons_set_cursor_visibility(console_t *cons, bool visible)
|
---|
| 556 | {
|
---|
| 557 | fibril_mutex_lock(&cons->mtx);
|
---|
| 558 | screenbuffer_set_cursor_visibility(cons->frontbuf, visible);
|
---|
| 559 | fibril_mutex_unlock(&cons->mtx);
|
---|
| 560 |
|
---|
| 561 | cons_update_cursor(cons);
|
---|
| 562 | }
|
---|
| 563 |
|
---|
| 564 | static void cons_get_cursor(console_t *cons, ipc_callid_t iid, ipc_call_t *icall)
|
---|
| 565 | {
|
---|
| 566 | sysarg_t col;
|
---|
| 567 | sysarg_t row;
|
---|
| 568 |
|
---|
| 569 | fibril_mutex_lock(&cons->mtx);
|
---|
| 570 | screenbuffer_get_cursor(cons->frontbuf, &col, &row);
|
---|
| 571 | fibril_mutex_unlock(&cons->mtx);
|
---|
| 572 |
|
---|
| 573 | async_answer_2(iid, EOK, col, row);
|
---|
[9f51afc] | 574 | }
|
---|
| 575 |
|
---|
[7c014d1] | 576 | static void cons_write(console_t *cons, ipc_callid_t iid, ipc_call_t *icall)
|
---|
[d2cc7e1] | 577 | {
|
---|
[472c09d] | 578 | void *buf;
|
---|
[171f9a1] | 579 | size_t size;
|
---|
[eda925a] | 580 | int rc = async_data_write_accept(&buf, false, 0, 0, 0, &size);
|
---|
[1601f3c] | 581 |
|
---|
[472c09d] | 582 | if (rc != EOK) {
|
---|
[7c014d1] | 583 | async_answer_0(iid, rc);
|
---|
[424cd43] | 584 | return;
|
---|
| 585 | }
|
---|
[1601f3c] | 586 |
|
---|
[424cd43] | 587 | size_t off = 0;
|
---|
[7c014d1] | 588 | while (off < size)
|
---|
| 589 | cons_write_char(cons, str_decode(buf, &off, size));
|
---|
[424cd43] | 590 |
|
---|
[7c014d1] | 591 | async_answer_1(iid, EOK, size);
|
---|
[424cd43] | 592 | free(buf);
|
---|
[7c014d1] | 593 |
|
---|
| 594 | cons_notify_data(cons);
|
---|
[424cd43] | 595 | }
|
---|
| 596 |
|
---|
[7c014d1] | 597 | static void cons_read(console_t *cons, ipc_callid_t iid, ipc_call_t *icall)
|
---|
[424cd43] | 598 | {
|
---|
| 599 | ipc_callid_t callid;
|
---|
| 600 | size_t size;
|
---|
[0da4e41] | 601 | if (!async_data_read_receive(&callid, &size)) {
|
---|
[ffa2c8ef] | 602 | async_answer_0(callid, EINVAL);
|
---|
[7c014d1] | 603 | async_answer_0(iid, EINVAL);
|
---|
[424cd43] | 604 | return;
|
---|
| 605 | }
|
---|
| 606 |
|
---|
| 607 | char *buf = (char *) malloc(size);
|
---|
| 608 | if (buf == NULL) {
|
---|
[ffa2c8ef] | 609 | async_answer_0(callid, ENOMEM);
|
---|
[7c014d1] | 610 | async_answer_0(iid, ENOMEM);
|
---|
[424cd43] | 611 | return;
|
---|
| 612 | }
|
---|
| 613 |
|
---|
| 614 | size_t pos = 0;
|
---|
[7c014d1] | 615 | while (pos < size) {
|
---|
| 616 | link_t *link = prodcons_consume(&cons->input_pc);
|
---|
| 617 | kbd_event_t *event = list_get_instance(link, kbd_event_t, link);
|
---|
| 618 |
|
---|
| 619 | if (event->type == KEY_PRESS) {
|
---|
| 620 | buf[pos] = event->c;
|
---|
[424cd43] | 621 | pos++;
|
---|
| 622 | }
|
---|
[7c014d1] | 623 |
|
---|
| 624 | free(event);
|
---|
[424cd43] | 625 | }
|
---|
| 626 |
|
---|
[7c014d1] | 627 | (void) async_data_read_finalize(callid, buf, size);
|
---|
| 628 | async_answer_1(iid, EOK, size);
|
---|
| 629 | free(buf);
|
---|
[424cd43] | 630 | }
|
---|
| 631 |
|
---|
[7c014d1] | 632 | static void cons_set_style(console_t *cons, console_style_t style)
|
---|
[424cd43] | 633 | {
|
---|
[7c014d1] | 634 | fibril_mutex_lock(&cons->mtx);
|
---|
| 635 | screenbuffer_set_style(cons->frontbuf, style);
|
---|
| 636 | fibril_mutex_unlock(&cons->mtx);
|
---|
| 637 | }
|
---|
| 638 |
|
---|
| 639 | static void cons_set_color(console_t *cons, console_color_t bgcolor,
|
---|
| 640 | console_color_t fgcolor, console_color_attr_t attr)
|
---|
| 641 | {
|
---|
| 642 | fibril_mutex_lock(&cons->mtx);
|
---|
| 643 | screenbuffer_set_color(cons->frontbuf, bgcolor, fgcolor, attr);
|
---|
| 644 | fibril_mutex_unlock(&cons->mtx);
|
---|
| 645 | }
|
---|
| 646 |
|
---|
| 647 | static void cons_set_rgb_color(console_t *cons, pixel_t bgcolor,
|
---|
| 648 | pixel_t fgcolor)
|
---|
| 649 | {
|
---|
| 650 | fibril_mutex_lock(&cons->mtx);
|
---|
| 651 | screenbuffer_set_rgb_color(cons->frontbuf, bgcolor, fgcolor);
|
---|
| 652 | fibril_mutex_unlock(&cons->mtx);
|
---|
| 653 | }
|
---|
| 654 |
|
---|
| 655 | static void cons_get_event(console_t *cons, ipc_callid_t iid, ipc_call_t *icall)
|
---|
| 656 | {
|
---|
| 657 | link_t *link = prodcons_consume(&cons->input_pc);
|
---|
| 658 | kbd_event_t *event = list_get_instance(link, kbd_event_t, link);
|
---|
[9f1362d4] | 659 |
|
---|
[7c014d1] | 660 | async_answer_4(iid, EOK, event->type, event->key, event->mods, event->c);
|
---|
| 661 | free(event);
|
---|
[d2cc7e1] | 662 | }
|
---|
| 663 |
|
---|
[9934f7d] | 664 | static void client_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
|
---|
[eaf34f7] | 665 | {
|
---|
[424cd43] | 666 | console_t *cons = NULL;
|
---|
[3ad953c] | 667 |
|
---|
[7c014d1] | 668 | for (size_t i = 0; i < CONSOLE_COUNT; i++) {
|
---|
[424cd43] | 669 | if (i == KERNEL_CONSOLE)
|
---|
| 670 | continue;
|
---|
| 671 |
|
---|
[7c014d1] | 672 | if (consoles[i].dsid == (service_id_t) IPC_GET_ARG1(*icall)) {
|
---|
[424cd43] | 673 | cons = &consoles[i];
|
---|
| 674 | break;
|
---|
| 675 | }
|
---|
| 676 | }
|
---|
| 677 |
|
---|
| 678 | if (cons == NULL) {
|
---|
[ffa2c8ef] | 679 | async_answer_0(iid, ENOENT);
|
---|
[eaf34f7] | 680 | return;
|
---|
| 681 | }
|
---|
[424cd43] | 682 |
|
---|
[7c014d1] | 683 | if (atomic_postinc(&cons->refcnt) == 0) {
|
---|
| 684 | cons_set_cursor_visibility(cons, true);
|
---|
| 685 | cons_notify_connect(cons);
|
---|
| 686 | }
|
---|
[10569b1] | 687 |
|
---|
[eaf34f7] | 688 | /* Accept the connection */
|
---|
[ffa2c8ef] | 689 | async_answer_0(iid, EOK);
|
---|
[3ad953c] | 690 |
|
---|
[1601f3c] | 691 | while (true) {
|
---|
[7c014d1] | 692 | ipc_call_t call;
|
---|
| 693 | ipc_callid_t callid = async_get_call(&call);
|
---|
[1601f3c] | 694 |
|
---|
[79ae36dd] | 695 | if (!IPC_GET_IMETHOD(call)) {
|
---|
[7c014d1] | 696 | if (atomic_postdec(&cons->refcnt) == 1)
|
---|
| 697 | cons_notify_disconnect(cons);
|
---|
| 698 |
|
---|
[eaf34f7] | 699 | return;
|
---|
[79ae36dd] | 700 | }
|
---|
| 701 |
|
---|
| 702 | switch (IPC_GET_IMETHOD(call)) {
|
---|
[4198f9c3] | 703 | case VFS_OUT_READ:
|
---|
[424cd43] | 704 | cons_read(cons, callid, &call);
|
---|
[7c014d1] | 705 | break;
|
---|
[4198f9c3] | 706 | case VFS_OUT_WRITE:
|
---|
[424cd43] | 707 | cons_write(cons, callid, &call);
|
---|
[7c014d1] | 708 | break;
|
---|
[4198f9c3] | 709 | case VFS_OUT_SYNC:
|
---|
[7c014d1] | 710 | cons_update(cons);
|
---|
| 711 | async_answer_0(callid, EOK);
|
---|
[424cd43] | 712 | break;
|
---|
[ad123964] | 713 | case CONSOLE_CLEAR:
|
---|
[7c014d1] | 714 | cons_clear(cons);
|
---|
| 715 | async_answer_0(callid, EOK);
|
---|
[eaf34f7] | 716 | break;
|
---|
[ad123964] | 717 | case CONSOLE_GOTO:
|
---|
[7c014d1] | 718 | cons_set_cursor(cons, IPC_GET_ARG1(call), IPC_GET_ARG2(call));
|
---|
| 719 | async_answer_0(callid, EOK);
|
---|
[ad123964] | 720 | break;
|
---|
[19528516] | 721 | case CONSOLE_GET_POS:
|
---|
[7c014d1] | 722 | cons_get_cursor(cons, callid, &call);
|
---|
[19528516] | 723 | break;
|
---|
[424cd43] | 724 | case CONSOLE_GET_SIZE:
|
---|
[7c014d1] | 725 | async_answer_2(callid, EOK, cons->cols, cons->rows);
|
---|
[a9bd960c] | 726 | break;
|
---|
[50cfa6c] | 727 | case CONSOLE_GET_COLOR_CAP:
|
---|
[7c014d1] | 728 | async_answer_1(callid, EOK, cons->ccaps);
|
---|
[50cfa6c] | 729 | break;
|
---|
[a9bd960c] | 730 | case CONSOLE_SET_STYLE:
|
---|
[7c014d1] | 731 | cons_set_style(cons, IPC_GET_ARG1(call));
|
---|
| 732 | async_answer_0(callid, EOK);
|
---|
[9805cde] | 733 | break;
|
---|
| 734 | case CONSOLE_SET_COLOR:
|
---|
[7c014d1] | 735 | cons_set_color(cons, IPC_GET_ARG1(call), IPC_GET_ARG2(call),
|
---|
| 736 | IPC_GET_ARG3(call));
|
---|
| 737 | async_answer_0(callid, EOK);
|
---|
[9805cde] | 738 | break;
|
---|
| 739 | case CONSOLE_SET_RGB_COLOR:
|
---|
[7c014d1] | 740 | cons_set_rgb_color(cons, IPC_GET_ARG1(call), IPC_GET_ARG2(call));
|
---|
| 741 | async_answer_0(callid, EOK);
|
---|
[0c6984e] | 742 | break;
|
---|
[a8b2b5b2] | 743 | case CONSOLE_CURSOR_VISIBILITY:
|
---|
[7c014d1] | 744 | cons_set_cursor_visibility(cons, IPC_GET_ARG1(call));
|
---|
| 745 | async_answer_0(callid, EOK);
|
---|
[a8b2b5b2] | 746 | break;
|
---|
[424cd43] | 747 | case CONSOLE_GET_EVENT:
|
---|
| 748 | cons_get_event(cons, callid, &call);
|
---|
[7c014d1] | 749 | break;
|
---|
| 750 | default:
|
---|
| 751 | async_answer_0(callid, EINVAL);
|
---|
[eaf34f7] | 752 | }
|
---|
| 753 | }
|
---|
| 754 | }
|
---|
| 755 |
|
---|
[7c014d1] | 756 | static async_sess_t *input_connect(const char *svc)
|
---|
[eaf34f7] | 757 | {
|
---|
[a40dea3] | 758 | async_sess_t *sess;
|
---|
[7c014d1] | 759 | service_id_t dsid;
|
---|
[9f1362d4] | 760 |
|
---|
[7c014d1] | 761 | int rc = loc_service_get_id(svc, &dsid, 0);
|
---|
[79ae36dd] | 762 | if (rc == EOK) {
|
---|
[7c014d1] | 763 | sess = loc_service_connect(EXCHANGE_ATOMIC, dsid, 0);
|
---|
[a40dea3] | 764 | if (sess == NULL) {
|
---|
[7c014d1] | 765 | printf("%s: Unable to connect to input service %s\n", NAME,
|
---|
| 766 | svc);
|
---|
[a40dea3] | 767 | return NULL;
|
---|
[79ae36dd] | 768 | }
|
---|
[7c014d1] | 769 | } else
|
---|
[a40dea3] | 770 | return NULL;
|
---|
[9f1362d4] | 771 |
|
---|
[7c014d1] | 772 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
[3015f4d] | 773 | rc = async_connect_to_me(exch, 0, 0, 0, input_events, NULL);
|
---|
[a40dea3] | 774 | async_exchange_end(exch);
|
---|
[7c014d1] | 775 |
|
---|
[700af62] | 776 | if (rc != EOK) {
|
---|
[a40dea3] | 777 | async_hangup(sess);
|
---|
[7c014d1] | 778 | printf("%s: Unable to create callback connection to service %s (%s)\n",
|
---|
| 779 | NAME, svc, str_error(rc));
|
---|
[a40dea3] | 780 | return NULL;
|
---|
[4904de8] | 781 | }
|
---|
[9f1362d4] | 782 |
|
---|
[a40dea3] | 783 | return sess;
|
---|
[700af62] | 784 | }
|
---|
| 785 |
|
---|
[7c014d1] | 786 | static void interrupt_received(ipc_callid_t callid, ipc_call_t *call)
|
---|
| 787 | {
|
---|
| 788 | cons_switch(prev_console);
|
---|
| 789 | }
|
---|
| 790 |
|
---|
| 791 | static async_sess_t *fb_connect(const char *svc)
|
---|
[700af62] | 792 | {
|
---|
[7c014d1] | 793 | async_sess_t *sess;
|
---|
| 794 | service_id_t dsid;
|
---|
| 795 |
|
---|
| 796 | int rc = loc_service_get_id(svc, &dsid, 0);
|
---|
| 797 | if (rc == EOK) {
|
---|
| 798 | sess = loc_service_connect(EXCHANGE_SERIALIZE, dsid, 0);
|
---|
| 799 | if (sess == NULL) {
|
---|
| 800 | printf("%s: Unable to connect to framebuffer service %s\n",
|
---|
| 801 | NAME, svc);
|
---|
| 802 | return NULL;
|
---|
| 803 | }
|
---|
| 804 | } else
|
---|
| 805 | return NULL;
|
---|
| 806 |
|
---|
| 807 | return sess;
|
---|
| 808 | }
|
---|
| 809 |
|
---|
| 810 | static bool console_srv_init(char *input_svc, char *fb_svc)
|
---|
| 811 | {
|
---|
| 812 | /* Avoid double initialization */
|
---|
| 813 | if (graphics_state != GRAPHICS_NONE)
|
---|
| 814 | return false;
|
---|
| 815 |
|
---|
| 816 | /* Connect to input service */
|
---|
| 817 | input_sess = input_connect(input_svc);
|
---|
[a40dea3] | 818 | if (input_sess == NULL)
|
---|
[700af62] | 819 | return false;
|
---|
[79ae36dd] | 820 |
|
---|
[7c014d1] | 821 | /* Connect to framebuffer service */
|
---|
| 822 | fb_sess = fb_connect(fb_svc);
|
---|
| 823 | if (fb_sess == NULL)
|
---|
[79ae36dd] | 824 | return false;
|
---|
[9f1362d4] | 825 |
|
---|
[15f3c3f] | 826 | /* Register server */
|
---|
| 827 | int rc = loc_server_register(NAME, client_connection);
|
---|
[424cd43] | 828 | if (rc < 0) {
|
---|
[7c014d1] | 829 | printf("%s: Unable to register server (%s)\n", NAME,
|
---|
| 830 | str_error(rc));
|
---|
[424cd43] | 831 | return false;
|
---|
| 832 | }
|
---|
[516ff92] | 833 |
|
---|
[7c014d1] | 834 | fb_get_resolution(fb_sess, &xres, &yres);
|
---|
[3993b3d] | 835 |
|
---|
[7c014d1] | 836 | /* Initialize the screen */
|
---|
| 837 | screen_vp = fb_vp_create(fb_sess, 0, 0, xres, yres);
|
---|
[1601f3c] | 838 |
|
---|
[7c014d1] | 839 | if ((xres >= 800) && (yres >= 600)) {
|
---|
| 840 | logo_vp = fb_vp_create(fb_sess, xres - 66, 2, 64, 60);
|
---|
| 841 | logo_img = imgmap_decode_tga((void *) helenos_tga,
|
---|
| 842 | helenos_tga_size, IMGMAP_FLAG_SHARED);
|
---|
| 843 | logo_handle = fb_imagemap_create(fb_sess, logo_img);
|
---|
| 844 |
|
---|
| 845 | nameic_vp = fb_vp_create(fb_sess, 5, 17, 100, 26);
|
---|
| 846 | nameic_img = imgmap_decode_tga((void *) nameic_tga,
|
---|
| 847 | nameic_tga_size, IMGMAP_FLAG_SHARED);
|
---|
| 848 | nameic_handle = fb_imagemap_create(fb_sess, nameic_img);
|
---|
| 849 |
|
---|
| 850 | cons_data_img = imgmap_decode_tga((void *) cons_data_tga,
|
---|
| 851 | cons_data_tga_size, IMGMAP_FLAG_SHARED);
|
---|
| 852 | cons_dis_img = imgmap_decode_tga((void *) cons_dis_tga,
|
---|
| 853 | cons_dis_tga_size, IMGMAP_FLAG_SHARED);
|
---|
| 854 | cons_dis_sel_img = imgmap_decode_tga((void *) cons_dis_sel_tga,
|
---|
| 855 | cons_dis_sel_tga_size, IMGMAP_FLAG_SHARED);
|
---|
| 856 | cons_idle_img = imgmap_decode_tga((void *) cons_idle_tga,
|
---|
| 857 | cons_idle_tga_size, IMGMAP_FLAG_SHARED);
|
---|
| 858 | cons_kernel_img = imgmap_decode_tga((void *) cons_kernel_tga,
|
---|
| 859 | cons_kernel_tga_size, IMGMAP_FLAG_SHARED);
|
---|
| 860 | cons_sel_img = imgmap_decode_tga((void *) cons_sel_tga,
|
---|
| 861 | cons_sel_tga_size, IMGMAP_FLAG_SHARED);
|
---|
| 862 |
|
---|
| 863 | state_icons[CONS_DISCONNECTED] =
|
---|
| 864 | fb_imagemap_create(fb_sess, cons_dis_img);
|
---|
| 865 | state_icons[CONS_DISCONNECTED_SELECTED] =
|
---|
| 866 | fb_imagemap_create(fb_sess, cons_dis_sel_img);
|
---|
| 867 | state_icons[CONS_SELECTED] =
|
---|
| 868 | fb_imagemap_create(fb_sess, cons_sel_img);
|
---|
| 869 | state_icons[CONS_IDLE] =
|
---|
| 870 | fb_imagemap_create(fb_sess, cons_idle_img);
|
---|
| 871 | state_icons[CONS_DATA] =
|
---|
| 872 | fb_imagemap_create(fb_sess, cons_data_img);
|
---|
| 873 | state_icons[CONS_KERNEL] =
|
---|
| 874 | fb_imagemap_create(fb_sess, cons_kernel_img);
|
---|
| 875 |
|
---|
| 876 | anim_1_img = imgmap_decode_tga((void *) anim_1_tga,
|
---|
| 877 | anim_1_tga_size, IMGMAP_FLAG_SHARED);
|
---|
| 878 | anim_2_img = imgmap_decode_tga((void *) anim_2_tga,
|
---|
| 879 | anim_2_tga_size, IMGMAP_FLAG_SHARED);
|
---|
| 880 | anim_3_img = imgmap_decode_tga((void *) anim_3_tga,
|
---|
| 881 | anim_3_tga_size, IMGMAP_FLAG_SHARED);
|
---|
| 882 | anim_4_img = imgmap_decode_tga((void *) anim_4_tga,
|
---|
| 883 | anim_4_tga_size, IMGMAP_FLAG_SHARED);
|
---|
| 884 |
|
---|
| 885 | anim_1 = fb_imagemap_create(fb_sess, anim_1_img);
|
---|
| 886 | anim_2 = fb_imagemap_create(fb_sess, anim_2_img);
|
---|
| 887 | anim_3 = fb_imagemap_create(fb_sess, anim_3_img);
|
---|
| 888 | anim_4 = fb_imagemap_create(fb_sess, anim_4_img);
|
---|
| 889 |
|
---|
| 890 | anim_seq = fb_sequence_create(fb_sess);
|
---|
| 891 | fb_sequence_add_imagemap(fb_sess, anim_seq, anim_1);
|
---|
| 892 | fb_sequence_add_imagemap(fb_sess, anim_seq, anim_2);
|
---|
| 893 | fb_sequence_add_imagemap(fb_sess, anim_seq, anim_3);
|
---|
| 894 | fb_sequence_add_imagemap(fb_sess, anim_seq, anim_4);
|
---|
| 895 |
|
---|
| 896 | console_vp = fb_vp_create(fb_sess, CONSOLE_MARGIN, CONSOLE_TOP,
|
---|
| 897 | xres - 2 * CONSOLE_MARGIN, yres - (CONSOLE_TOP + CONSOLE_MARGIN));
|
---|
| 898 |
|
---|
| 899 | fb_vp_clear(fb_sess, screen_vp);
|
---|
| 900 | fb_vp_imagemap_damage(fb_sess, logo_vp, logo_handle,
|
---|
| 901 | 0, 0, 64, 60);
|
---|
| 902 | fb_vp_imagemap_damage(fb_sess, nameic_vp, nameic_handle,
|
---|
| 903 | 0, 0, 100, 26);
|
---|
| 904 |
|
---|
| 905 | graphics_state = GRAPHICS_FULL;
|
---|
| 906 | } else {
|
---|
| 907 | console_vp = screen_vp;
|
---|
| 908 | graphics_state = GRAPHICS_BASIC;
|
---|
| 909 | }
|
---|
[1601f3c] | 910 |
|
---|
[7c014d1] | 911 | fb_vp_set_style(fb_sess, console_vp, STYLE_NORMAL);
|
---|
| 912 | fb_vp_clear(fb_sess, console_vp);
|
---|
[1601f3c] | 913 |
|
---|
[7c014d1] | 914 | sysarg_t cols;
|
---|
| 915 | sysarg_t rows;
|
---|
| 916 | fb_vp_get_dimensions(fb_sess, console_vp, &cols, &rows);
|
---|
| 917 |
|
---|
| 918 | console_caps_t ccaps;
|
---|
| 919 | fb_vp_get_caps(fb_sess, console_vp, &ccaps);
|
---|
[3ad953c] | 920 |
|
---|
[b7c33b0] | 921 | mouse.x = xres / 2;
|
---|
| 922 | mouse.y = yres / 2;
|
---|
[7c014d1] | 923 | mouse.pressed = false;
|
---|
[3ad953c] | 924 |
|
---|
[424cd43] | 925 | /* Inititalize consoles */
|
---|
[7c014d1] | 926 | for (size_t i = 0; i < CONSOLE_COUNT; i++) {
|
---|
| 927 | consoles[i].index = i;
|
---|
| 928 | atomic_set(&consoles[i].refcnt, 0);
|
---|
| 929 | fibril_mutex_initialize(&consoles[i].mtx);
|
---|
[d03da17] | 930 | prodcons_initialize(&consoles[i].input_pc);
|
---|
[7c014d1] | 931 |
|
---|
| 932 | if (graphics_state == GRAPHICS_FULL) {
|
---|
| 933 | /* Create state buttons */
|
---|
| 934 | consoles[i].state_vp =
|
---|
| 935 | fb_vp_create(fb_sess, STATE_START + (xres - 800) / 2 +
|
---|
| 936 | CONSOLE_MARGIN + i * (STATE_WIDTH + STATE_SPACE),
|
---|
| 937 | STATE_TOP, STATE_WIDTH, STATE_HEIGHT);
|
---|
| 938 | }
|
---|
| 939 |
|
---|
| 940 | if (i == KERNEL_CONSOLE) {
|
---|
| 941 | consoles[i].state = CONS_KERNEL;
|
---|
| 942 | cons_redraw_state(&consoles[i]);
|
---|
| 943 | cons_kernel_sequence_start(&consoles[i]);
|
---|
| 944 | continue;
|
---|
| 945 | }
|
---|
| 946 |
|
---|
| 947 | if (i == 0)
|
---|
| 948 | consoles[i].state = CONS_DISCONNECTED_SELECTED;
|
---|
| 949 | else
|
---|
| 950 | consoles[i].state = CONS_DISCONNECTED;
|
---|
| 951 |
|
---|
| 952 | consoles[i].cols = cols;
|
---|
| 953 | consoles[i].rows = rows;
|
---|
| 954 | consoles[i].ccaps = ccaps;
|
---|
| 955 | consoles[i].frontbuf =
|
---|
| 956 | screenbuffer_create(cols, rows, SCREENBUFFER_FLAG_SHARED);
|
---|
| 957 |
|
---|
| 958 | if (consoles[i].frontbuf == NULL) {
|
---|
| 959 | printf("%s: Unable to allocate frontbuffer %zu\n", NAME, i);
|
---|
| 960 | return false;
|
---|
| 961 | }
|
---|
| 962 |
|
---|
| 963 | consoles[i].fbid = fb_frontbuf_create(fb_sess, consoles[i].frontbuf);
|
---|
| 964 | if (consoles[i].fbid == 0) {
|
---|
| 965 | printf("%s: Unable to create frontbuffer %zu\n", NAME, i);
|
---|
| 966 | return false;
|
---|
| 967 | }
|
---|
| 968 |
|
---|
| 969 | cons_redraw_state(&consoles[i]);
|
---|
| 970 |
|
---|
| 971 | char vc[LOC_NAME_MAXLEN + 1];
|
---|
| 972 | snprintf(vc, LOC_NAME_MAXLEN, "%s/vc%zu", NAMESPACE, i);
|
---|
| 973 |
|
---|
| 974 | if (loc_service_register(vc, &consoles[i].dsid) != EOK) {
|
---|
| 975 | printf("%s: Unable to register device %s\n", NAME, vc);
|
---|
| 976 | return false;
|
---|
[424cd43] | 977 | }
|
---|
| 978 | }
|
---|
| 979 |
|
---|
[3ad953c] | 980 | /* Receive kernel notifications */
|
---|
[007e6efa] | 981 | async_set_interrupt_received(interrupt_received);
|
---|
[7c014d1] | 982 | rc = event_subscribe(EVENT_KCONSOLE, 0);
|
---|
| 983 | if (rc != EOK)
|
---|
| 984 | printf("%s: Failed to register kconsole notifications (%s)\n",
|
---|
| 985 | NAME, str_error(rc));
|
---|
[1601f3c] | 986 |
|
---|
[424cd43] | 987 | return true;
|
---|
| 988 | }
|
---|
| 989 |
|
---|
[47a350f] | 990 | static void usage(void)
|
---|
| 991 | {
|
---|
[7c014d1] | 992 | printf("Usage: console <input_dev> <framebuffer_dev>\n");
|
---|
[47a350f] | 993 | }
|
---|
| 994 |
|
---|
[424cd43] | 995 | int main(int argc, char *argv[])
|
---|
| 996 | {
|
---|
[7c014d1] | 997 | if (argc < 3) {
|
---|
[47a350f] | 998 | usage();
|
---|
| 999 | return -1;
|
---|
| 1000 | }
|
---|
| 1001 |
|
---|
[7c014d1] | 1002 | printf("%s: HelenOS Console service\n", NAME);
|
---|
[424cd43] | 1003 |
|
---|
[7c014d1] | 1004 | if (!console_srv_init(argv[1], argv[2]))
|
---|
[424cd43] | 1005 | return -1;
|
---|
[79ae36dd] | 1006 |
|
---|
[7c014d1] | 1007 | printf("%s: Accepting connections\n", NAME);
|
---|
| 1008 | task_retval(0);
|
---|
[eaf34f7] | 1009 | async_manager();
|
---|
[3ad953c] | 1010 |
|
---|
| 1011 | return 0;
|
---|
[51c1b003] | 1012 | }
|
---|
[516ff92] | 1013 |
|
---|
[ce5bcb4] | 1014 | /** @}
|
---|
| 1015 | */
|
---|