Changes in uspace/srv/hid/console/console.c [2f90b46:111d2d6] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hid/console/console.c
r2f90b46 r111d2d6 36 36 #include <stdio.h> 37 37 #include <adt/prodcons.h> 38 #include <i pc/input.h>38 #include <io/input.h> 39 39 #include <ipc/console.h> 40 40 #include <ipc/vfs.h> … … 43 43 #include <loc.h> 44 44 #include <event.h> 45 #include <io/kbd_event.h> 45 46 #include <io/keycode.h> 46 #include < screenbuffer.h>47 #include < fb.h>48 #include <i mgmap.h>47 #include <io/chargrid.h> 48 #include <io/console.h> 49 #include <io/output.h> 49 50 #include <align.h> 50 51 #include <malloc.h> 51 52 #include <as.h> 52 53 #include <fibril_synch.h> 53 #include "images.h"54 54 #include "console.h" 55 55 … … 57 57 #define NAMESPACE "term" 58 58 59 #define CONSOLE_TOP 66 60 #define CONSOLE_MARGIN 12 61 62 #define STATE_START 100 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; 59 #define UTF8_CHAR_BUFFER_SIZE (STR_BOUNDS(1) + 1) 77 60 78 61 typedef struct { 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 */ 62 atomic_t refcnt; /**< Connection reference count */ 63 prodcons_t input_pc; /**< Incoming keyboard events */ 64 65 /** 66 * Not yet sent bytes of last char event. 67 */ 68 char char_remains[UTF8_CHAR_BUFFER_SIZE]; 69 size_t char_remains_len; /**< Number of not yet sent bytes. */ 70 71 fibril_mutex_t mtx; /**< Lock protecting mutable fields */ 72 73 size_t index; /**< Console index */ 74 service_id_t dsid; /**< Service handle */ 75 76 sysarg_t cols; /**< Number of columns */ 77 sysarg_t rows; /**< Number of rows */ 78 console_caps_t ccaps; /**< Console capabilities */ 79 80 chargrid_t *frontbuf; /**< Front buffer */ 81 frontbuf_handle_t fbid; /**< Front buffer handle */ 95 82 } console_t; 96 83 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; 84 /** Input server proxy */ 85 static input_t *input; 86 87 /** Session to the output server */ 88 static async_sess_t *output_sess; 89 90 /** Output dimensions */ 91 static sysarg_t cols; 92 static sysarg_t rows; 118 93 119 94 /** Array of data for virtual consoles */ … … 127 102 static console_t *kernel_console = &consoles[KERNEL_CONSOLE]; 128 103 129 static imgmap_t *logo_img; 130 static imgmap_t *nameic_img; 131 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; 136 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; 141 142 static sequence_handle_t anim_seq; 143 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; 150 151 static vp_handle_t logo_vp; 152 static imagemap_handle_t logo_handle; 153 154 static vp_handle_t nameic_vp; 155 static imagemap_handle_t nameic_handle; 156 157 static vp_handle_t screen_vp; 158 static vp_handle_t console_vp; 159 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; 169 170 static void cons_redraw_state(console_t *cons) 171 { 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 } 190 } 191 192 static void cons_kernel_sequence_start(console_t *cons) 193 { 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 } 203 } 204 205 static void cons_update_state(console_t *cons, console_state_t state) 206 { 207 bool update = false; 208 209 fibril_mutex_lock(&cons->mtx); 210 211 if (cons->state != state) { 212 cons->state = state; 213 update = true; 214 } 215 216 fibril_mutex_unlock(&cons->mtx); 217 218 if (update) 219 cons_redraw_state(cons); 220 } 221 222 static void cons_notify_data(console_t *cons) 104 static int input_ev_key(input_t *, kbd_event_type_t, keycode_t, keymod_t, wchar_t); 105 static int input_ev_move(input_t *, int, int); 106 static int input_ev_abs_move(input_t *, unsigned, unsigned, unsigned, unsigned); 107 static int input_ev_button(input_t *, int, int); 108 109 static input_ev_ops_t input_ev_ops = { 110 .key = input_ev_key, 111 .move = input_ev_move, 112 .abs_move = input_ev_abs_move, 113 .button = input_ev_button 114 }; 115 116 static void cons_update(console_t *cons) 223 117 { 224 118 fibril_mutex_lock(&switch_mtx); 225 226 if (cons != active_console) 227 cons_update_state(cons, CONS_DATA); 228 119 fibril_mutex_lock(&cons->mtx); 120 121 if ((cons == active_console) && (active_console != kernel_console)) { 122 output_update(output_sess, cons->fbid); 123 output_cursor_update(output_sess, cons->fbid); 124 } 125 126 fibril_mutex_unlock(&cons->mtx); 229 127 fibril_mutex_unlock(&switch_mtx); 230 128 } 231 129 232 static void cons_ notify_connect(console_t *cons)130 static void cons_update_cursor(console_t *cons) 233 131 { 234 132 fibril_mutex_lock(&switch_mtx); 235 236 if (cons == active_console)237 cons_update_state(cons, CONS_SELECTED);238 else239 cons_update_state(cons, CONS_IDLE);240 133 fibril_mutex_lock(&cons->mtx); 134 135 if ((cons == active_console) && (active_console != kernel_console)) 136 output_cursor_update(output_sess, cons->fbid); 137 138 fibril_mutex_unlock(&cons->mtx); 241 139 fibril_mutex_unlock(&switch_mtx); 242 140 } 243 141 244 static void cons_notify_disconnect(console_t *cons) 142 static void cons_clear(console_t *cons) 143 { 144 fibril_mutex_lock(&cons->mtx); 145 chargrid_clear(cons->frontbuf); 146 fibril_mutex_unlock(&cons->mtx); 147 148 cons_update(cons); 149 } 150 151 static void cons_damage(console_t *cons) 245 152 { 246 153 fibril_mutex_lock(&switch_mtx); 247 248 if (cons == active_console)249 cons_update_state(cons, CONS_DISCONNECTED_SELECTED);250 else251 cons_update_state(cons, CONS_DISCONNECTED);252 253 fibril_mutex_unlock(&switch_mtx);254 }255 256 static void cons_update(console_t *cons)257 {258 fibril_mutex_lock(&switch_mtx);259 154 fibril_mutex_lock(&cons->mtx); 260 155 261 156 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); 268 } 269 270 static void cons_update_cursor(console_t *cons) 271 { 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); 280 } 281 282 static void cons_clear(console_t *cons) 283 { 284 fibril_mutex_lock(&cons->mtx); 285 screenbuffer_clear(cons->frontbuf); 286 fibril_mutex_unlock(&cons->mtx); 287 288 cons_update(cons); 289 } 290 291 static void cons_damage_all(console_t *cons) 292 { 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, 157 output_damage(output_sess, cons->fbid, 0, 0, cons->cols, 298 158 cons->rows); 299 fb_vp_cursor_update(fb_sess, console_vp, cons->fbid);159 output_cursor_update(output_sess, cons->fbid); 300 160 } 301 161 … … 314 174 315 175 if (cons == kernel_console) { 316 fb_yield(fb_sess);176 output_yield(output_sess); 317 177 if (!console_kcon()) { 318 fb_claim(fb_sess);178 output_claim(output_sess); 319 179 fibril_mutex_unlock(&switch_mtx); 320 180 return; … … 323 183 324 184 if (active_console == kernel_console) 325 fb_claim(fb_sess);185 output_claim(output_sess); 326 186 327 187 prev_console = active_console; 328 188 active_console = cons; 329 189 330 if (prev_console->state == CONS_DISCONNECTED_SELECTED)331 cons_update_state(prev_console, CONS_DISCONNECTED);332 else333 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 else339 cons_update_state(cons, CONS_SELECTED);340 341 190 fibril_mutex_unlock(&switch_mtx); 342 191 343 cons_damage _all(cons);192 cons_damage(cons); 344 193 } 345 194 … … 347 196 { 348 197 fibril_mutex_lock(&switch_mtx); 349 198 350 199 console_t *active_uspace = active_console; 351 if (active_uspace == kernel_console) {200 if (active_uspace == kernel_console) 352 201 active_uspace = prev_console; 353 }202 354 203 assert(active_uspace != kernel_console); 355 204 356 205 fibril_mutex_unlock(&switch_mtx); 357 206 358 207 return active_uspace; 359 208 } 360 209 361 static ssize_t limit(ssize_t val, ssize_t lo, ssize_t hi) 362 { 363 if (val > hi) 364 return hi; 365 366 if (val < lo) 367 return lo; 368 369 return val; 370 } 371 372 static void cons_mouse_move(sysarg_t dx, sysarg_t dy) 373 { 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); 381 } 382 383 static console_t *cons_find_icon(sysarg_t x, sysarg_t y) 384 { 385 sysarg_t status_start = 386 STATE_START + (xres - 800) / 2 + CONSOLE_MARGIN; 387 388 if ((y < STATE_TOP) || (y >= STATE_TOP + STATE_HEIGHT)) 389 return NULL; 390 391 if (x < status_start) 392 return NULL; 393 394 if (x >= status_start + (STATE_WIDTH + STATE_SPACE) * CONSOLE_COUNT) 395 return NULL; 396 397 if (((x - status_start) % (STATE_WIDTH + STATE_SPACE)) >= STATE_WIDTH) 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; 404 405 return NULL; 406 } 407 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) 414 { 415 if (graphics_state != GRAPHICS_FULL) 416 return NULL; 417 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; 424 } 425 426 return NULL; 427 } 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; 438 } 439 440 static void input_events(ipc_callid_t iid, ipc_call_t *icall, void *arg) 441 { 442 /* Ignore parameters, the connection is already opened */ 443 while (true) { 444 ipc_call_t call; 445 ipc_callid_t callid = async_get_call(&call); 446 447 if (!IPC_GET_IMETHOD(call)) { 448 /* TODO: Handle hangup */ 449 async_hangup(input_sess); 450 return; 451 } 452 453 kbd_event_type_t type; 454 keycode_t key; 455 keymod_t mods; 456 wchar_t c; 457 458 switch (IPC_GET_IMETHOD(call)) { 459 case INPUT_EVENT_KEY: 460 type = IPC_GET_ARG1(call); 461 key = IPC_GET_ARG2(call); 462 mods = IPC_GET_ARG3(call); 463 c = IPC_GET_ARG4(call); 464 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 483 /* 484 * Kernel console does not read events 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(); 490 491 prodcons_produce(&target_console->input_pc, 492 &event->link); 493 } 494 495 async_answer_0(callid, EOK); 496 break; 497 case INPUT_EVENT_MOVE: 498 cons_mouse_move(IPC_GET_ARG1(call), IPC_GET_ARG2(call)); 499 async_answer_0(callid, EOK); 500 break; 501 case INPUT_EVENT_BUTTON: 502 /* Got pointer button press/release event */ 503 if (IPC_GET_ARG1(call) == 1) { 504 console_t *cons = 505 cons_mouse_button((bool) IPC_GET_ARG2(call)); 506 if (cons != NULL) 507 cons_switch(cons); 508 } 509 async_answer_0(callid, EOK); 510 break; 511 default: 512 async_answer_0(callid, EINVAL); 513 } 514 } 210 static int input_ev_key(input_t *input, kbd_event_type_t type, keycode_t key, 211 keymod_t mods, wchar_t c) 212 { 213 if ((key >= KC_F1) && (key < KC_F1 + CONSOLE_COUNT) && 214 ((mods & KM_CTRL) == 0)) { 215 cons_switch(&consoles[key - KC_F1]); 216 } else { 217 /* Got key press/release event */ 218 kbd_event_t *event = 219 (kbd_event_t *) malloc(sizeof(kbd_event_t)); 220 if (event == NULL) { 221 return ENOMEM; 222 } 223 224 link_initialize(&event->link); 225 event->type = type; 226 event->key = key; 227 event->mods = mods; 228 event->c = c; 229 230 /* 231 * Kernel console does not read events 232 * from us, so we will redirect them 233 * to the (last) active userspace console 234 * if necessary. 235 */ 236 console_t *target_console = cons_get_active_uspace(); 237 238 prodcons_produce(&target_console->input_pc, 239 &event->link); 240 } 241 242 return EOK; 243 } 244 245 static int input_ev_move(input_t *input, int dx, int dy) 246 { 247 return EOK; 248 } 249 250 static int input_ev_abs_move(input_t *input, unsigned x , unsigned y, 251 unsigned max_x, unsigned max_y) 252 { 253 return EOK; 254 } 255 256 static int input_ev_button(input_t *input, int bnum, int bpress) 257 { 258 return EOK; 515 259 } 516 260 … … 524 268 switch (ch) { 525 269 case '\n': 526 updated = screenbuffer_newline(cons->frontbuf);270 updated = chargrid_newline(cons->frontbuf); 527 271 break; 528 272 case '\r': 529 273 break; 530 274 case '\t': 531 updated = screenbuffer_tabstop(cons->frontbuf, 8);275 updated = chargrid_tabstop(cons->frontbuf, 8); 532 276 break; 533 277 case '\b': 534 updated = screenbuffer_backspace(cons->frontbuf);278 updated = chargrid_backspace(cons->frontbuf); 535 279 break; 536 280 default: 537 updated = screenbuffer_putchar(cons->frontbuf, ch, true);281 updated = chargrid_putchar(cons->frontbuf, ch, true); 538 282 } 539 283 … … 547 291 { 548 292 fibril_mutex_lock(&cons->mtx); 549 screenbuffer_set_cursor(cons->frontbuf, col, row);293 chargrid_set_cursor(cons->frontbuf, col, row); 550 294 fibril_mutex_unlock(&cons->mtx); 551 295 … … 556 300 { 557 301 fibril_mutex_lock(&cons->mtx); 558 screenbuffer_set_cursor_visibility(cons->frontbuf, visible);302 chargrid_set_cursor_visibility(cons->frontbuf, visible); 559 303 fibril_mutex_unlock(&cons->mtx); 560 304 … … 568 312 569 313 fibril_mutex_lock(&cons->mtx); 570 screenbuffer_get_cursor(cons->frontbuf, &col, &row);314 chargrid_get_cursor(cons->frontbuf, &col, &row); 571 315 fibril_mutex_unlock(&cons->mtx); 572 316 … … 591 335 async_answer_1(iid, EOK, size); 592 336 free(buf); 593 594 cons_notify_data(cons);595 337 } 596 338 … … 613 355 614 356 size_t pos = 0; 357 358 /* 359 * Read input from keyboard and copy it to the buffer. 360 * We need to handle situation when wchar is split by 2 following 361 * reads. 362 */ 615 363 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; 364 /* Copy to the buffer remaining characters. */ 365 while ((pos < size) && (cons->char_remains_len > 0)) { 366 buf[pos] = cons->char_remains[0]; 621 367 pos++; 622 } 623 624 free(event); 368 369 /* Unshift the array. */ 370 for (size_t i = 1; i < cons->char_remains_len; i++) 371 cons->char_remains[i - 1] = cons->char_remains[i]; 372 373 cons->char_remains_len--; 374 } 375 376 /* Still not enough? Then get another key from the queue. */ 377 if (pos < size) { 378 link_t *link = prodcons_consume(&cons->input_pc); 379 kbd_event_t *event = list_get_instance(link, kbd_event_t, link); 380 381 /* Accept key presses of printable chars only. */ 382 if ((event->type == KEY_PRESS) && (event->c != 0)) { 383 wchar_t tmp[2] = { event->c, 0 }; 384 wstr_to_str(cons->char_remains, UTF8_CHAR_BUFFER_SIZE, tmp); 385 cons->char_remains_len = str_size(cons->char_remains); 386 } 387 388 free(event); 389 } 625 390 } 626 391 … … 633 398 { 634 399 fibril_mutex_lock(&cons->mtx); 635 screenbuffer_set_style(cons->frontbuf, style);400 chargrid_set_style(cons->frontbuf, style); 636 401 fibril_mutex_unlock(&cons->mtx); 637 402 } … … 641 406 { 642 407 fibril_mutex_lock(&cons->mtx); 643 screenbuffer_set_color(cons->frontbuf, bgcolor, fgcolor, attr);408 chargrid_set_color(cons->frontbuf, bgcolor, fgcolor, attr); 644 409 fibril_mutex_unlock(&cons->mtx); 645 410 } … … 649 414 { 650 415 fibril_mutex_lock(&cons->mtx); 651 screenbuffer_set_rgb_color(cons->frontbuf, bgcolor, fgcolor);416 chargrid_set_rgb_color(cons->frontbuf, bgcolor, fgcolor); 652 417 fibril_mutex_unlock(&cons->mtx); 653 418 } … … 681 446 } 682 447 683 if (atomic_postinc(&cons->refcnt) == 0) {448 if (atomic_postinc(&cons->refcnt) == 0) 684 449 cons_set_cursor_visibility(cons, true); 685 cons_notify_connect(cons);686 }687 450 688 451 /* Accept the connection */ … … 693 456 ipc_callid_t callid = async_get_call(&call); 694 457 695 if (!IPC_GET_IMETHOD(call)) { 696 if (atomic_postdec(&cons->refcnt) == 1) 697 cons_notify_disconnect(cons); 698 458 if (!IPC_GET_IMETHOD(call)) 699 459 return; 700 }701 460 702 461 switch (IPC_GET_IMETHOD(call)) { … … 754 513 } 755 514 756 static async_sess_t *input_connect(const char *svc)515 static int input_connect(const char *svc) 757 516 { 758 517 async_sess_t *sess; … … 760 519 761 520 int rc = loc_service_get_id(svc, &dsid, 0); 762 if (rc == EOK) { 763 sess = loc_service_connect(EXCHANGE_ATOMIC, dsid, 0); 764 if (sess == NULL) { 765 printf("%s: Unable to connect to input service %s\n", NAME, 766 svc); 767 return NULL; 768 } 769 } else 770 return NULL; 771 772 async_exch_t *exch = async_exchange_begin(sess); 773 rc = async_connect_to_me(exch, 0, 0, 0, input_events, NULL); 774 async_exchange_end(exch); 775 521 if (rc != EOK) { 522 printf("%s: Input service %s not found\n", NAME, svc); 523 return rc; 524 } 525 526 sess = loc_service_connect(EXCHANGE_ATOMIC, dsid, 0); 527 if (sess == NULL) { 528 printf("%s: Unable to connect to input service %s\n", NAME, 529 svc); 530 return EIO; 531 } 532 533 rc = input_open(sess, &input_ev_ops, NULL, &input); 776 534 if (rc != EOK) { 777 535 async_hangup(sess); 778 printf("%s: Unable to c reate callback connection toservice %s (%s)\n",536 printf("%s: Unable to communicate with service %s (%s)\n", 779 537 NAME, svc, str_error(rc)); 780 return NULL;781 } 782 783 return sess;538 return rc; 539 } 540 541 return EOK; 784 542 } 785 543 … … 789 547 } 790 548 791 static async_sess_t * fb_connect(const char *svc)549 static async_sess_t *output_connect(const char *svc) 792 550 { 793 551 async_sess_t *sess; … … 798 556 sess = loc_service_connect(EXCHANGE_SERIALIZE, dsid, 0); 799 557 if (sess == NULL) { 800 printf("%s: Unable to connect to framebufferservice %s\n",558 printf("%s: Unable to connect to output service %s\n", 801 559 NAME, svc); 802 560 return NULL; … … 808 566 } 809 567 810 static bool console_srv_init(char *input_svc, char *fb_svc) 811 { 812 /* Avoid double initialization */ 813 if (graphics_state != GRAPHICS_NONE) 568 static bool console_srv_init(char *input_svc, char *output_svc) 569 { 570 int rc; 571 572 /* Connect to input service */ 573 rc = input_connect(input_svc); 574 if (rc != EOK) 814 575 return false; 815 576 816 /* Connect to input service */ 817 input_sess = input_connect(input_svc); 818 if (input_sess == NULL) 819 return false; 820 821 /* Connect to framebuffer service */ 822 fb_sess = fb_connect(fb_svc); 823 if (fb_sess == NULL) 577 /* Connect to output service */ 578 output_sess = output_connect(output_svc); 579 if (output_sess == NULL) 824 580 return false; 825 581 826 582 /* Register server */ 827 583 async_set_client_connection(client_connection); 828 intrc = loc_server_register(NAME);584 rc = loc_server_register(NAME); 829 585 if (rc != EOK) { 830 586 printf("%s: Unable to register server (%s)\n", NAME, … … 833 589 } 834 590 835 fb_get_resolution(fb_sess, &xres, &yres); 836 837 /* Initialize the screen */ 838 screen_vp = fb_vp_create(fb_sess, 0, 0, xres, yres); 839 840 if ((xres >= 800) && (yres >= 600)) { 841 logo_vp = fb_vp_create(fb_sess, xres - 66, 2, 64, 60); 842 logo_img = imgmap_decode_tga((void *) helenos_tga, 843 helenos_tga_size, IMGMAP_FLAG_SHARED); 844 logo_handle = fb_imagemap_create(fb_sess, logo_img); 845 846 nameic_vp = fb_vp_create(fb_sess, 5, 17, 100, 26); 847 nameic_img = imgmap_decode_tga((void *) nameic_tga, 848 nameic_tga_size, IMGMAP_FLAG_SHARED); 849 nameic_handle = fb_imagemap_create(fb_sess, nameic_img); 850 851 cons_data_img = imgmap_decode_tga((void *) cons_data_tga, 852 cons_data_tga_size, IMGMAP_FLAG_SHARED); 853 cons_dis_img = imgmap_decode_tga((void *) cons_dis_tga, 854 cons_dis_tga_size, IMGMAP_FLAG_SHARED); 855 cons_dis_sel_img = imgmap_decode_tga((void *) cons_dis_sel_tga, 856 cons_dis_sel_tga_size, IMGMAP_FLAG_SHARED); 857 cons_idle_img = imgmap_decode_tga((void *) cons_idle_tga, 858 cons_idle_tga_size, IMGMAP_FLAG_SHARED); 859 cons_kernel_img = imgmap_decode_tga((void *) cons_kernel_tga, 860 cons_kernel_tga_size, IMGMAP_FLAG_SHARED); 861 cons_sel_img = imgmap_decode_tga((void *) cons_sel_tga, 862 cons_sel_tga_size, IMGMAP_FLAG_SHARED); 863 864 state_icons[CONS_DISCONNECTED] = 865 fb_imagemap_create(fb_sess, cons_dis_img); 866 state_icons[CONS_DISCONNECTED_SELECTED] = 867 fb_imagemap_create(fb_sess, cons_dis_sel_img); 868 state_icons[CONS_SELECTED] = 869 fb_imagemap_create(fb_sess, cons_sel_img); 870 state_icons[CONS_IDLE] = 871 fb_imagemap_create(fb_sess, cons_idle_img); 872 state_icons[CONS_DATA] = 873 fb_imagemap_create(fb_sess, cons_data_img); 874 state_icons[CONS_KERNEL] = 875 fb_imagemap_create(fb_sess, cons_kernel_img); 876 877 anim_1_img = imgmap_decode_tga((void *) anim_1_tga, 878 anim_1_tga_size, IMGMAP_FLAG_SHARED); 879 anim_2_img = imgmap_decode_tga((void *) anim_2_tga, 880 anim_2_tga_size, IMGMAP_FLAG_SHARED); 881 anim_3_img = imgmap_decode_tga((void *) anim_3_tga, 882 anim_3_tga_size, IMGMAP_FLAG_SHARED); 883 anim_4_img = imgmap_decode_tga((void *) anim_4_tga, 884 anim_4_tga_size, IMGMAP_FLAG_SHARED); 885 886 anim_1 = fb_imagemap_create(fb_sess, anim_1_img); 887 anim_2 = fb_imagemap_create(fb_sess, anim_2_img); 888 anim_3 = fb_imagemap_create(fb_sess, anim_3_img); 889 anim_4 = fb_imagemap_create(fb_sess, anim_4_img); 890 891 anim_seq = fb_sequence_create(fb_sess); 892 fb_sequence_add_imagemap(fb_sess, anim_seq, anim_1); 893 fb_sequence_add_imagemap(fb_sess, anim_seq, anim_2); 894 fb_sequence_add_imagemap(fb_sess, anim_seq, anim_3); 895 fb_sequence_add_imagemap(fb_sess, anim_seq, anim_4); 896 897 console_vp = fb_vp_create(fb_sess, CONSOLE_MARGIN, CONSOLE_TOP, 898 xres - 2 * CONSOLE_MARGIN, yres - (CONSOLE_TOP + CONSOLE_MARGIN)); 899 900 fb_vp_clear(fb_sess, screen_vp); 901 fb_vp_imagemap_damage(fb_sess, logo_vp, logo_handle, 902 0, 0, 64, 60); 903 fb_vp_imagemap_damage(fb_sess, nameic_vp, nameic_handle, 904 0, 0, 100, 26); 905 906 graphics_state = GRAPHICS_FULL; 907 } else { 908 console_vp = screen_vp; 909 graphics_state = GRAPHICS_BASIC; 910 } 911 912 fb_vp_set_style(fb_sess, console_vp, STYLE_NORMAL); 913 fb_vp_clear(fb_sess, console_vp); 914 915 sysarg_t cols; 916 sysarg_t rows; 917 fb_vp_get_dimensions(fb_sess, console_vp, &cols, &rows); 591 output_get_dimensions(output_sess, &cols, &rows); 592 output_set_style(output_sess, STYLE_NORMAL); 918 593 919 594 console_caps_t ccaps; 920 fb_vp_get_caps(fb_sess, console_vp, &ccaps); 921 922 mouse.x = xres / 2; 923 mouse.y = yres / 2; 924 mouse.pressed = false; 595 output_get_caps(output_sess, &ccaps); 925 596 926 597 /* Inititalize consoles */ … … 930 601 fibril_mutex_initialize(&consoles[i].mtx); 931 602 prodcons_initialize(&consoles[i].input_pc); 932 933 if (graphics_state == GRAPHICS_FULL) { 934 /* Create state buttons */ 935 consoles[i].state_vp = 936 fb_vp_create(fb_sess, STATE_START + (xres - 800) / 2 + 937 CONSOLE_MARGIN + i * (STATE_WIDTH + STATE_SPACE), 938 STATE_TOP, STATE_WIDTH, STATE_HEIGHT); 939 } 940 941 if (i == KERNEL_CONSOLE) { 942 consoles[i].state = CONS_KERNEL; 943 cons_redraw_state(&consoles[i]); 944 cons_kernel_sequence_start(&consoles[i]); 603 consoles[i].char_remains_len = 0; 604 605 if (i == KERNEL_CONSOLE) 945 606 continue; 946 }947 948 if (i == 0)949 consoles[i].state = CONS_DISCONNECTED_SELECTED;950 else951 consoles[i].state = CONS_DISCONNECTED;952 607 953 608 consoles[i].cols = cols; … … 955 610 consoles[i].ccaps = ccaps; 956 611 consoles[i].frontbuf = 957 screenbuffer_create(cols, rows, SCREENBUFFER_FLAG_SHARED);612 chargrid_create(cols, rows, CHARGRID_FLAG_SHARED); 958 613 959 614 if (consoles[i].frontbuf == NULL) { … … 962 617 } 963 618 964 consoles[i].fbid = fb_frontbuf_create(fb_sess, consoles[i].frontbuf); 619 consoles[i].fbid = output_frontbuf_create(output_sess, 620 consoles[i].frontbuf); 965 621 if (consoles[i].fbid == 0) { 966 622 printf("%s: Unable to create frontbuffer %zu\n", NAME, i); … … 968 624 } 969 625 970 cons_redraw_state(&consoles[i]);971 972 626 char vc[LOC_NAME_MAXLEN + 1]; 973 627 snprintf(vc, LOC_NAME_MAXLEN, "%s/vc%zu", NAMESPACE, i); … … 978 632 } 979 633 } 634 635 cons_damage(active_console); 980 636 981 637 /* Receive kernel notifications */ … … 989 645 } 990 646 991 static void usage( void)992 { 993 printf("Usage: console <input_dev> <framebuffer_dev>\n");647 static void usage(char *name) 648 { 649 printf("Usage: %s <input_dev> <output_dev>\n", name); 994 650 } 995 651 … … 997 653 { 998 654 if (argc < 3) { 999 usage( );655 usage(argv[0]); 1000 656 return -1; 1001 657 } … … 1010 666 async_manager(); 1011 667 668 /* Never reached */ 1012 669 return 0; 1013 670 }
Note:
See TracChangeset
for help on using the changeset viewer.