Changes in uspace/lib/ui/src/ui.c [252d03c:e3e64f6] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/src/ui.c
r252d03c re3e64f6 39 39 #include <errno.h> 40 40 #include <fibril.h> 41 #include <gfx/color.h> 42 #include <gfx/cursor.h> 43 #include <gfx/render.h> 41 44 #include <io/console.h> 42 45 #include <stdbool.h> … … 47 50 #include <ui/wdecor.h> 48 51 #include <ui/window.h> 52 #include "../private/wdecor.h" 49 53 #include "../private/window.h" 50 54 #include "../private/ui.h" … … 53 57 * 54 58 * Output specification has the form <proto>@<service> where proto is 55 * eiher 'disp' for display service or 'cons' for console. Service56 * is a location ID service name (e.g. hid/display).59 * eiher 'disp' for display service, 'cons' for console, 'null' 60 * for dummy output. Service is a location ID service name (e.g. hid/display). 57 61 * 58 62 * @param ospec Output specification … … 64 68 { 65 69 const char *cp; 66 67 if (ospec == UI_DISPLAY_DEFAULT) {68 *ws = ui_ws_display;69 *osvc = DISPLAY_DEFAULT;70 return;71 }72 70 73 71 cp = ospec; … … 80 78 } else if (str_lcmp(ospec, "cons@", str_length("cons@")) == 0) { 81 79 *ws = ui_ws_console; 80 } else if (str_lcmp(ospec, "null@", str_length("null@")) == 0) { 81 *ws = ui_ws_null; 82 } else if (str_lcmp(ospec, "@", str_length("@")) == 0) { 83 *ws = ui_ws_any; 82 84 } else { 83 85 *ws = ui_ws_unknown; … … 97 99 * 98 100 * @param ospec Output specification or @c UI_DISPLAY_DEFAULT to use 99 * the default output 101 * the default display service, UI_CONSOLE_DEFAULT to use 102 * the default console service, UI_DISPLAY_NULL to use 103 * dummy output. 100 104 * @param rui Place to store pointer to new UI 101 105 * @return EOK on success or an error code … … 109 113 ui_winsys_t ws; 110 114 const char *osvc; 115 sysarg_t cols; 116 sysarg_t rows; 111 117 ui_t *ui; 112 118 113 119 ui_ospec_parse(ospec, &ws, &osvc); 114 120 115 if (ws == ui_ws_display) { 116 rc = display_open(osvc, &display); 121 if (ws == ui_ws_display || ws == ui_ws_any) { 122 rc = display_open(osvc != NULL ? osvc : DISPLAY_DEFAULT, 123 &display); 117 124 if (rc != EOK) 118 return rc;125 goto disp_fail; 119 126 120 127 rc = ui_create_disp(display, &ui); 121 128 if (rc != EOK) { 122 129 display_close(display); 123 return rc; 124 } 125 } else if (ws == ui_ws_console) { 130 goto disp_fail; 131 } 132 133 ui->myoutput = true; 134 *rui = ui; 135 return EOK; 136 } 137 138 disp_fail: 139 if (ws == ui_ws_console || ws == ui_ws_any) { 126 140 console = console_init(stdin, stdout); 127 141 if (console == NULL) 128 return EIO; 142 goto cons_fail; 143 144 rc = console_get_size(console, &cols, &rows); 145 if (rc != EOK) { 146 console_done(console); 147 goto cons_fail; 148 } 149 150 console_cursor_visibility(console, false); 129 151 130 152 /* ws == ui_ws_console */ … … 132 154 if (rc != EOK) { 133 155 console_done(console); 134 return rc;156 goto cons_fail; 135 157 } 136 158 … … 139 161 ui_destroy(ui); 140 162 console_done(console); 163 goto cons_fail; 164 } 165 166 ui->cgc = cgc; 167 ui->rect.p0.x = 0; 168 ui->rect.p0.y = 0; 169 ui->rect.p1.x = cols; 170 ui->rect.p1.y = rows; 171 172 (void) ui_paint(ui); 173 ui->myoutput = true; 174 *rui = ui; 175 return EOK; 176 } 177 178 cons_fail: 179 if (ws == ui_ws_null) { 180 rc = ui_create_disp(NULL, &ui); 181 if (rc != EOK) 141 182 return rc; 142 } 143 144 ui->cgc = cgc; 145 } else { 146 return EINVAL; 147 } 148 149 ui->myoutput = true; 150 *rui = ui; 151 return EOK; 183 184 ui->myoutput = true; 185 *rui = ui; 186 return EOK; 187 } 188 189 return EINVAL; 152 190 } 153 191 … … 203 241 if (ui->cgc != NULL) 204 242 console_gc_delete(ui->cgc); 205 if (ui->console != NULL) 243 if (ui->console != NULL) { 244 console_cursor_visibility(ui->console, true); 206 245 console_done(ui->console); 246 } 207 247 if (ui->display != NULL) 208 248 display_close(ui->display); … … 216 256 ui_window_t *awnd; 217 257 ui_evclaim_t claim; 258 pos_event_t pos; 218 259 219 260 awnd = ui_window_get_active(ui); … … 226 267 break; 227 268 case CEV_POS: 228 claim = ui_wdecor_pos_event(awnd->wdecor, &event->ev.pos); 269 pos = event->ev.pos; 270 /* Translate event to window-relative coordinates */ 271 pos.hpos -= awnd->dpos.x; 272 pos.vpos -= awnd->dpos.y; 273 274 claim = ui_wdecor_pos_event(awnd->wdecor, &pos); 229 275 /* Note: If event is claimed, awnd might not be valid anymore */ 230 276 if (claim == ui_unclaimed) 231 ui_window_send_pos(awnd, &event->ev.pos); 277 ui_window_send_pos(awnd, &pos); 278 232 279 break; 233 280 } … … 280 327 { 281 328 errno_t rc; 329 gfx_context_t *gc; 282 330 ui_window_t *awnd; 331 gfx_color_t *color = NULL; 332 333 /* In case of null output */ 334 if (ui->cgc == NULL) 335 return EOK; 336 337 gc = console_gc_get_ctx(ui->cgc); 338 339 rc = gfx_color_new_ega(0x11, &color); 340 if (rc != EOK) 341 return rc; 342 343 rc = gfx_set_color(gc, color); 344 if (rc != EOK) { 345 gfx_color_delete(color); 346 return rc; 347 } 348 349 rc = gfx_fill_rect(gc, &ui->rect); 350 if (rc != EOK) { 351 gfx_color_delete(color); 352 return rc; 353 } 354 355 gfx_color_delete(color); 283 356 284 357 /* XXX Should repaint all windows */ … … 292 365 293 366 return ui_window_paint(awnd); 367 } 368 369 /** Free up console for other users. 370 * 371 * Release console resources for another application (that the current 372 * task is starting). After the other application finishes, resume 373 * operation with ui_resume(). No calls to UI must happen inbetween 374 * and no events must be processed (i.e. the calling function must not 375 * return control to UI. 376 * 377 * @param ui UI 378 * @return EOK on success or an error code 379 */ 380 errno_t ui_suspend(ui_t *ui) 381 { 382 if (ui->cgc == NULL) 383 return EOK; 384 385 (void) console_set_caption(ui->console, ""); 386 return console_gc_suspend(ui->cgc); 387 } 388 389 /** Resume suspended UI. 390 * 391 * Reclaim console resources (after child application has finished running) 392 * and restore UI operation previously suspended by calling ui_suspend(). 393 * 394 * @param ui UI 395 * @return EOK on success or an error code 396 */ 397 errno_t ui_resume(ui_t *ui) 398 { 399 errno_t rc; 400 ui_window_t *awnd; 401 sysarg_t col; 402 sysarg_t row; 403 cons_event_t ev; 404 405 if (ui->cgc == NULL) 406 return EOK; 407 408 rc = console_get_pos(ui->console, &col, &row); 409 if (rc != EOK) 410 return rc; 411 412 /* 413 * Here's a little heuristic to help determine if we need 414 * to pause before returning to the UI. If we are in the 415 * top-left corner, chances are the screen is empty and 416 * there is no need to pause. 417 */ 418 if (col != 0 || row != 0) { 419 printf("Press any key or button to continue...\n"); 420 421 while (true) { 422 rc = console_get_event(ui->console, &ev); 423 if (rc != EOK) 424 return EIO; 425 426 if (ev.type == CEV_KEY && ev.ev.key.type == KEY_PRESS) 427 break; 428 429 if (ev.type == CEV_POS && ev.ev.pos.type == POS_PRESS) 430 break; 431 } 432 } 433 434 rc = console_gc_resume(ui->cgc); 435 if (rc != EOK) 436 return rc; 437 438 awnd = ui_window_get_active(ui); 439 if (awnd != NULL) 440 (void) console_set_caption(ui->console, awnd->wdecor->caption); 441 442 return gfx_cursor_set_visible(console_gc_get_ctx(ui->cgc), false); 294 443 } 295 444
Note:
See TracChangeset
for help on using the changeset viewer.