Changeset dc5c303 in mainline for uspace/app/gfxdemo/gfxdemo.c
- Timestamp:
- 2023-12-28T13:59:23Z (2 years ago)
- Children:
- 6b66de6b
- Parents:
- 42c2e65 (diff), f87ff8e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - git-author:
- boba-buba <120932204+boba-buba@…> (2023-12-28 13:59:23)
- git-committer:
- GitHub <noreply@…> (2023-12-28 13:59:23)
- File:
-
- 1 edited
-
uspace/app/gfxdemo/gfxdemo.c (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/gfxdemo/gfxdemo.c
r42c2e65 rdc5c303 1 1 /* 2 * Copyright (c) 202 2Jiri Svoboda2 * Copyright (c) 2023 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 51 51 #include <ui/window.h> 52 52 #include <ui/wdecor.h> 53 #include "gfxdemo.h" 53 54 54 55 static void wnd_close_event(void *); … … 68 69 }; 69 70 71 static void demo_kbd_event(kbd_event_t *); 72 70 73 static bool quit = false; 74 static FIBRIL_MUTEX_INITIALIZE(quit_lock); 75 static FIBRIL_CONDVAR_INITIALIZE(quit_cv); 71 76 static gfx_typeface_t *tface; 72 77 static gfx_font_t *font; 73 78 static gfx_coord_t vpad; 79 static console_ctrl_t *con = NULL; 80 static ui_t *ui; 74 81 75 82 /** Determine if we are running in text mode. … … 83 90 // XXX Need a proper way to determine text mode 84 91 return w <= 80; 92 } 93 94 /** Sleep until timeout or quit request. 95 * 96 * @param msec Number of microseconds to sleep for 97 */ 98 static void demo_msleep(unsigned msec) 99 { 100 errno_t rc; 101 usec_t usec; 102 cons_event_t cevent; 103 104 if (ui != NULL) 105 ui_unlock(ui); 106 fibril_mutex_lock(&quit_lock); 107 if (!quit) { 108 if (con != NULL) { 109 usec = (usec_t)msec * 1000; 110 while (usec > 0 && !quit) { 111 rc = console_get_event_timeout(con, &cevent, &usec); 112 if (rc == EOK) { 113 if (cevent.type == CEV_KEY) { 114 fibril_mutex_unlock(&quit_lock); 115 demo_kbd_event(&cevent.ev.key); 116 fibril_mutex_lock(&quit_lock); 117 } 118 } 119 } 120 } else { 121 (void) fibril_condvar_wait_timeout(&quit_cv, &quit_lock, 122 (usec_t)msec * 1000); 123 } 124 } 125 fibril_mutex_unlock(&quit_lock); 126 if (ui != NULL) 127 ui_lock(ui); 85 128 } 86 129 … … 316 359 gfx_color_delete(color); 317 360 318 fibril_usleep(500 * 1000); 319 361 demo_msleep(500); 320 362 if (quit) 321 363 break; … … 478 520 if (rc != EOK) 479 521 goto error; 480 fibril_usleep(250 * 1000); 481 522 523 demo_msleep(250); 482 524 if (quit) 483 525 goto out; … … 539 581 } 540 582 541 fibril_usleep(500 * 1000); 542 583 demo_msleep(500); 543 584 if (quit) 544 585 break; … … 600 641 } 601 642 602 fibril_usleep(500 * 1000); 603 643 demo_msleep(500); 604 644 if (quit) 605 645 break; … … 791 831 792 832 for (i = 0; i < 10; i++) { 793 fibril_usleep(500 * 1000);833 demo_msleep(500); 794 834 if (quit) 795 835 break; … … 872 912 873 913 for (i = 0; i < 10; i++) { 874 fibril_usleep(500 * 1000);914 demo_msleep(500); 875 915 if (quit) 876 916 break; … … 969 1009 } 970 1010 971 fibril_usleep(500 * 1000); 972 1011 demo_msleep(500); 973 1012 if (quit) 974 1013 break; … … 1036 1075 static errno_t demo_console(void) 1037 1076 { 1038 console_ctrl_t *con = NULL;1039 1077 console_gc_t *cgc = NULL; 1040 1078 gfx_context_t *gc; 1041 errno_t rc;1042 1043 printf("Init console..\n"); 1079 sysarg_t cols, rows; 1080 errno_t rc; 1081 1044 1082 con = console_init(stdin, stdout); 1045 1083 if (con == NULL) 1046 1084 return EIO; 1047 1085 1048 printf("Create console GC\n"); 1086 rc = console_get_size(con, &cols, &rows); 1087 if (rc != EOK) 1088 return rc; 1089 1049 1090 rc = console_gc_create(con, stdout, &cgc); 1050 1091 if (rc != EOK) … … 1053 1094 gc = console_gc_get_ctx(cgc); 1054 1095 1055 rc = demo_loop(gc, 80, 25);1096 rc = demo_loop(gc, cols, rows); 1056 1097 if (rc != EOK) 1057 1098 return rc; … … 1062 1103 1063 1104 return EOK; 1105 } 1106 1107 static errno_t demo_ui_fibril(void *arg) 1108 { 1109 demo_ui_args_t *args = (demo_ui_args_t *)arg; 1110 errno_t rc; 1111 1112 ui_lock(args->ui); 1113 rc = demo_loop(args->gc, args->dims.x, args->dims.y); 1114 ui_unlock(args->ui); 1115 ui_quit(args->ui); 1116 return rc; 1064 1117 } 1065 1118 … … 1067 1120 static errno_t demo_ui(const char *display_spec) 1068 1121 { 1069 ui_t *ui = NULL;1070 1122 ui_wnd_params_t params; 1071 1123 ui_window_t *window = NULL; … … 1074 1126 gfx_rect_t wrect; 1075 1127 gfx_coord2_t off; 1076 errno_t rc; 1077 1078 printf("Init UI..\n"); 1128 gfx_rect_t ui_rect; 1129 gfx_coord2_t dims; 1130 demo_ui_args_t args; 1131 fid_t fid; 1132 errno_t rc; 1079 1133 1080 1134 rc = ui_create(display_spec, &ui); 1081 1135 if (rc != EOK) { 1082 1136 printf("Error initializing UI (%s)\n", display_spec); 1137 goto error; 1138 } 1139 1140 rc = ui_get_rect(ui, &ui_rect); 1141 if (rc != EOK) { 1142 printf("Error getting display size.\n"); 1083 1143 goto error; 1084 1144 } … … 1091 1151 ui_wnd_params_init(¶ms); 1092 1152 params.caption = "GFX Demo"; 1153 1154 /* Do not decorate the window in fullscreen mode */ 1155 if (ui_is_fullscreen(ui)) 1156 params.style &= ~ui_wds_decorated; 1093 1157 1094 1158 /* … … 1100 1164 gfx_rect_rtranslate(&off, &wrect, ¶ms.rect); 1101 1165 1166 gfx_rect_dims(&ui_rect, &dims); 1167 1168 /* Make sure window is not larger than the entire screen */ 1169 if (params.rect.p1.x > dims.x) 1170 params.rect.p1.x = dims.x; 1171 if (params.rect.p1.y > dims.y) 1172 params.rect.p1.y = dims.y; 1173 1102 1174 rc = ui_window_create(ui, ¶ms, &window); 1103 1175 if (rc != EOK) { … … 1114 1186 } 1115 1187 1116 task_retval(0); 1117 1118 rc = demo_loop(gc, rect.p1.x, rect.p1.y); 1119 if (rc != EOK) 1120 goto error; 1121 1188 ui_window_get_app_rect(window, &rect); 1189 gfx_rect_dims(&rect, &dims); 1190 1191 if (!ui_is_fullscreen(ui)) 1192 task_retval(0); 1193 1194 args.gc = gc; 1195 args.dims = dims; 1196 args.ui = ui; 1197 1198 fid = fibril_create(demo_ui_fibril, (void *)&args); 1199 if (fid == 0) { 1200 rc = ENOMEM; 1201 goto error; 1202 } 1203 1204 fibril_add_ready(fid); 1205 1206 ui_run(ui); 1122 1207 ui_window_destroy(window); 1123 1208 ui_destroy(ui); … … 1141 1226 errno_t rc; 1142 1227 1143 printf("Init display..\n");1144 1145 1228 rc = display_open(display_svc, &display); 1146 1229 if (rc != EOK) { … … 1184 1267 } 1185 1268 1269 static void demo_quit(void) 1270 { 1271 fibril_mutex_lock(&quit_lock); 1272 quit = true; 1273 fibril_mutex_unlock(&quit_lock); 1274 fibril_condvar_broadcast(&quit_cv); 1275 } 1276 1186 1277 static void wnd_close_event(void *arg) 1187 1278 { 1188 printf("Close event\n"); 1189 quit = true; 1279 demo_quit(); 1280 } 1281 1282 static void demo_kbd_event(kbd_event_t *event) 1283 { 1284 if (event->type == KEY_PRESS) { 1285 /* Ctrl-Q */ 1286 if ((event->mods & KM_CTRL) != 0 && 1287 (event->mods & KM_ALT) == 0 && 1288 (event->mods & KM_SHIFT) == 0 && 1289 event->key == KC_Q) { 1290 demo_quit(); 1291 } 1292 1293 /* Escape */ 1294 if ((event->mods & KM_CTRL) == 0 && 1295 (event->mods & KM_ALT) == 0 && 1296 (event->mods & KM_SHIFT) == 0 && 1297 event->key == KC_ESCAPE) { 1298 demo_quit(); 1299 } 1300 } 1190 1301 } 1191 1302 1192 1303 static void wnd_kbd_event(void *arg, kbd_event_t *event) 1193 1304 { 1194 printf("Keyboard event type=%d key=%d\n", event->type, event->key); 1195 if (event->type == KEY_PRESS) 1196 quit = true; 1305 (void)arg; 1306 demo_kbd_event(event); 1197 1307 } 1198 1308 1199 1309 static void uiwnd_close_event(ui_window_t *window, void *arg) 1200 1310 { 1201 printf("Close event\n"); 1202 quit = true; 1311 demo_quit(); 1203 1312 } 1204 1313 1205 1314 static void uiwnd_kbd_event(ui_window_t *window, void *arg, kbd_event_t *event) 1206 1315 { 1207 printf("Keyboard event type=%d key=%d\n", event->type, event->key);1208 if (event->type == KEY_PRESS)1209 quit = true;1316 (void)window; 1317 (void)arg; 1318 demo_kbd_event(event); 1210 1319 } 1211 1320 … … 1219 1328 errno_t rc; 1220 1329 const char *display_svc = DISPLAY_DEFAULT; 1221 const char *ui_display_spec = UI_ DISPLAY_DEFAULT;1330 const char *ui_display_spec = UI_ANY_DEFAULT; 1222 1331 int i; 1223 1332
Note:
See TracChangeset
for help on using the changeset viewer.
