Changeset 77ffa01 in mainline
- Timestamp:
- 2021-02-27T21:34:15Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 9c7dc8e
- Parents:
- b433f68
- Location:
- uspace
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/terminal/terminal.c
rb433f68 r77ffa01 843 843 sysarg_t sy = -term->off.y; 844 844 845 if (event->type == POS_PRESS ) {845 if (event->type == POS_PRESS || event->type == POS_RELEASE) { 846 846 cevent.type = CEV_POS; 847 847 cevent.ev.pos.type = event->type; -
uspace/lib/ui/include/types/ui/ui.h
rb433f68 r77ffa01 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 45 45 #define UI_DISPLAY_DEFAULT NULL 46 46 47 /** Window system */ 48 typedef enum { 49 /** Unknown */ 50 ui_ws_unknown, 51 /** Display service */ 52 ui_ws_display, 53 /** Console */ 54 ui_ws_console 55 } ui_winsys_t; 56 47 57 #endif 48 58 -
uspace/lib/ui/include/ui/ui.h
rb433f68 r77ffa01 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 39 39 #include <display.h> 40 40 #include <errno.h> 41 #include <io/console.h> 41 42 #include <types/ui/ui.h> 42 43 43 44 extern errno_t ui_create(const char *, ui_t **); 45 extern errno_t ui_create_cons(console_ctrl_t *, ui_t **); 44 46 extern errno_t ui_create_disp(display_t *, ui_t **); 45 47 extern void ui_destroy(ui_t *); -
uspace/lib/ui/meson.build
rb433f68 r77ffa01 27 27 # 28 28 29 deps = [ 'gfx', 'gfxfont', 'memgfx', 'display' ]29 deps = [ 'gfx', 'gfxfont', 'memgfx', 'display', 'congfx' ] 30 30 src = files( 31 31 'src/checkbox.c', -
uspace/lib/ui/private/ui.h
rb433f68 r77ffa01 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 39 39 40 40 #include <display.h> 41 #include <io/console.h> 41 42 #include <stdbool.h> 42 43 … … 46 47 */ 47 48 struct ui { 49 /** Console */ 50 console_ctrl_t *console; 48 51 /** Display */ 49 52 display_t *display; … … 52 55 /** @c true if terminating */ 53 56 bool quit; 57 /** Root window (in fullscreen/console mode) */ 58 struct ui_window *root_wnd; 54 59 }; 55 60 -
uspace/lib/ui/private/window.h
rb433f68 r77ffa01 44 44 #include <io/pos_event.h> 45 45 #include <memgfx/memgc.h> 46 #include <types/ui/cursor.h> 47 #include <types/ui/window.h> 46 48 47 49 /** Actual structure of window. -
uspace/lib/ui/src/ui.c
rb433f68 r77ffa01 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 34 34 */ 35 35 36 #include <ctype.h> 36 37 #include <display.h> 37 38 #include <errno.h> 38 39 #include <fibril.h> 40 #include <io/console.h> 39 41 #include <stdlib.h> 42 #include <str.h> 40 43 #include <task.h> 41 44 #include <ui/ui.h> 45 #include <ui/wdecor.h> 46 #include "../private/window.h" 42 47 #include "../private/ui.h" 48 49 /** Parse output specification. 50 * 51 * Output specification has the form <proto>@<service> where proto is 52 * eiher 'disp' for display service or 'cons' for console. Service 53 * is a location ID service name (e.g. hid/display). 54 * 55 * @param ospec Output specification 56 * @param ws Place to store window system type (protocol) 57 * @param osvc Place to store pointer to output service name 58 */ 59 static void ui_ospec_parse(const char *ospec, ui_winsys_t *ws, 60 const char **osvc) 61 { 62 const char *cp; 63 64 if (ospec == UI_DISPLAY_DEFAULT) { 65 *ws = ui_ws_display; 66 *osvc = DISPLAY_DEFAULT; 67 return; 68 } 69 70 cp = ospec; 71 while (isalpha(*cp)) 72 ++cp; 73 74 if (*cp == '@') { 75 if (str_lcmp(ospec, "disp@", str_length("disp@")) == 0) { 76 *ws = ui_ws_display; 77 } else if (str_lcmp(ospec, "cons@", str_length("cons@")) == 0) { 78 *ws = ui_ws_console; 79 } else { 80 *ws = ui_ws_unknown; 81 } 82 83 if (cp[1] != '\0') 84 *osvc = cp + 1; 85 else 86 *osvc = NULL; 87 } else { 88 *ws = ui_ws_display; 89 *osvc = ospec; 90 } 91 } 43 92 44 93 /** Create new user interface. … … 53 102 errno_t rc; 54 103 display_t *display; 104 console_ctrl_t *console; 105 ui_winsys_t ws; 106 const char *osvc; 55 107 ui_t *ui; 56 108 57 rc = display_open(ospec, &display); 58 if (rc != EOK) 59 return rc; 60 61 rc = ui_create_disp(display, &ui); 62 if (rc != EOK) { 63 display_close(display); 64 return rc; 65 } 66 67 ui->display = display; 109 ui_ospec_parse(ospec, &ws, &osvc); 110 111 if (ws == ui_ws_display) { 112 rc = display_open(osvc, &display); 113 if (rc != EOK) 114 return rc; 115 116 rc = ui_create_disp(display, &ui); 117 if (rc != EOK) { 118 display_close(display); 119 return rc; 120 } 121 } else if (ws == ui_ws_console) { 122 console = console_init(stdin, stdout); 123 if (console == NULL) 124 return EIO; 125 126 /* ws == ui_ws_console */ 127 rc = ui_create_cons(console, &ui); 128 if (rc != EOK) { 129 console_done(console); 130 return rc; 131 } 132 } else { 133 return EINVAL; 134 } 135 68 136 ui->myoutput = true; 69 137 *rui = ui; … … 71 139 } 72 140 141 /** Create new user interface using console service. 142 * 143 * @param rui Place to store pointer to new UI 144 * @return EOK on success or an error code 145 */ 146 errno_t ui_create_cons(console_ctrl_t *console, ui_t **rui) 147 { 148 ui_t *ui; 149 150 ui = calloc(1, sizeof(ui_t)); 151 if (ui == NULL) 152 return ENOMEM; 153 154 ui->console = console; 155 *rui = ui; 156 return EOK; 157 } 158 73 159 /** Create new user interface using display service. 74 160 * … … 99 185 return; 100 186 101 if (ui->myoutput) 102 display_close(ui->display); 187 if (ui->myoutput) { 188 if (ui->console != NULL) 189 console_done(ui->console); 190 if (ui->display != NULL) 191 display_close(ui->display); 192 } 193 103 194 free(ui); 195 } 196 197 static void ui_cons_event_process(ui_t *ui, cons_event_t *event) 198 { 199 if (ui->root_wnd == NULL) 200 return; 201 202 switch (event->type) { 203 case CEV_KEY: 204 ui_window_send_kbd(ui->root_wnd, &event->ev.key); 205 break; 206 case CEV_POS: 207 ui_wdecor_pos_event(ui->root_wnd->wdecor, &event->ev.pos); 208 ui_window_send_pos(ui->root_wnd, &event->ev.pos); 209 break; 210 } 104 211 } 105 212 … … 113 220 void ui_run(ui_t *ui) 114 221 { 115 task_retval(0); 116 117 while (!ui->quit) 118 fibril_usleep(100000); 222 bool have_event; 223 cons_event_t event; 224 usec_t timeout; 225 226 /* Only return command prompt if we are running in a separate window */ 227 if (ui->display != NULL) 228 task_retval(0); 229 230 while (!ui->quit) { 231 if (ui->console != NULL) { 232 timeout = 100000; 233 have_event = console_get_event_timeout(ui->console, 234 &event, &timeout); 235 if (have_event) 236 ui_cons_event_process(ui, &event); 237 } else { 238 fibril_usleep(100000); 239 } 240 } 119 241 } 120 242 -
uspace/lib/ui/src/window.c
rb433f68 r77ffa01 34 34 */ 35 35 36 #include <congfx/console.h> 36 37 #include <display.h> 37 38 #include <errno.h> … … 130 131 gfx_bitmap_t *bmp = NULL; 131 132 mem_gc_t *memgc = NULL; 133 console_gc_t *cgc; 132 134 errno_t rc; 135 136 if (ui->root_wnd != NULL) 137 return EEXIST; 133 138 134 139 window = calloc(1, sizeof(ui_window_t)); … … 194 199 if (rc != EOK) 195 200 goto error; 201 } else if (ui->console != NULL) { 202 rc = console_gc_create(ui->console, NULL, &cgc); 203 if (rc != EOK) 204 goto error; 205 206 gc = console_gc_get_ctx(cgc); 196 207 } else { 197 208 /* Needed for unit tests */ … … 207 218 gfx_bitmap_params_init(&bparams); 208 219 #ifndef CONFIG_WIN_DOUBLE_BUF 209 bparams.flags |= bmpf_direct_output; 220 /* Console does not support direct output */ 221 if (ui->display != NULL) 222 bparams.flags |= bmpf_direct_output; 210 223 #endif 211 224 … … 262 275 window->cursor = ui_curs_arrow; 263 276 *rwindow = window; 277 278 ui->root_wnd = window; 264 279 return EOK; 265 280 error: … … 303 318 gfx_bitmap_destroy(window->bmp); 304 319 gfx_context_delete(window->gc); 305 display_window_destroy(window->dwindow); 320 if (window->dwindow != NULL) 321 display_window_destroy(window->dwindow); 306 322 free(window); 307 323 } … … 650 666 ui_window_t *window = (ui_window_t *) arg; 651 667 652 (void) display_window_move_req(window->dwindow, pos); 668 if (window->dwindow != NULL) 669 (void) display_window_move_req(window->dwindow, pos); 653 670 } 654 671 … … 665 682 ui_window_t *window = (ui_window_t *) arg; 666 683 667 (void) display_window_resize_req(window->dwindow, rsztype, pos); 684 if (window->dwindow != NULL) 685 (void) display_window_resize_req(window->dwindow, rsztype, pos); 668 686 } 669 687 … … 703 721 } 704 722 705 (void) display_window_set_cursor(window->dwindow, dcursor); 723 if (window->dwindow != NULL) 724 (void) display_window_set_cursor(window->dwindow, dcursor); 706 725 window->cursor = cursor; 707 726 }
Note:
See TracChangeset
for help on using the changeset viewer.