Changeset dcfd422 in mainline
- Timestamp:
- 2020-10-23T13:45:18Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5a43bd0
- Parents:
- 26653c9
- git-author:
- Jiri Svoboda <jiri@…> (2020-10-22 19:44:59)
- git-committer:
- Jiri Svoboda <jiri@…> (2020-10-23 13:45:18)
- Location:
- uspace
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/terminal/main.c
r26653c9 rdcfd422 40 40 #define NAME "terminal" 41 41 42 /** Print syntax. */ 43 static void print_syntax(void) 44 { 45 printf("Syntax: %s [-d <display>]\n", NAME); 46 } 47 42 48 int main(int argc, char *argv[]) 43 49 { 50 const char *display_svc = DISPLAY_DEFAULT; 44 51 display_t *display = NULL; 45 52 terminal_t *terminal = NULL; 46 53 errno_t rc; 54 int i; 47 55 48 rc = display_open(DISPLAY_DEFAULT, &display); 56 i = 1; 57 while (i < argc && argv[i][0] == '-') { 58 if (str_cmp(argv[i], "-d") == 0) { 59 ++i; 60 if (i >= argc) { 61 printf("Argument missing.\n"); 62 print_syntax(); 63 return 1; 64 } 65 66 display_svc = argv[i++]; 67 } else { 68 printf("Invalid option '%s'.\n", argv[i]); 69 print_syntax(); 70 return 1; 71 } 72 } 73 74 if (i < argc) { 75 print_syntax(); 76 return 1; 77 } 78 79 rc = display_open(display_svc, &display); 49 80 if (rc != EOK) { 50 81 printf("%s: Error opening display.\n", NAME); -
uspace/app/terminal/terminal.c
r26653c9 rdcfd422 50 50 #include <stdlib.h> 51 51 #include <str.h> 52 #include <ui/resource.h> 53 #include <ui/wdecor.h> 52 54 53 55 #include "terminal.h" … … 100 102 }; 101 103 104 static void terminal_close_event(void *); 105 static void terminal_focus_event(void *); 102 106 static void terminal_kbd_event(void *, kbd_event_t *); 107 static void terminal_pos_event(void *, pos_event_t *); 108 static void terminal_unfocus_event(void *); 103 109 104 110 static display_wnd_cb_t terminal_wnd_cb = { 105 .kbd_event = terminal_kbd_event 111 .close_event = terminal_close_event, 112 .focus_event = terminal_focus_event, 113 .kbd_event = terminal_kbd_event, 114 .pos_event = terminal_pos_event, 115 .unfocus_event = terminal_unfocus_event 116 }; 117 118 static void terminal_wd_close(ui_wdecor_t *, void *); 119 static void terminal_wd_move(ui_wdecor_t *, void *, gfx_coord2_t *); 120 121 static ui_wdecor_cb_t wdecor_cb = { 122 .close = terminal_wd_close, 123 .move = terminal_wd_move 106 124 }; 107 125 … … 305 323 pixelmap_t pixelmap; 306 324 gfx_bitmap_alloc_t alloc; 325 gfx_coord2_t pos; 307 326 errno_t rc; 308 327 … … 360 379 361 380 if (update) { 362 (void) gfx_bitmap_render(term->bmp, &term->update, NULL); 381 pos.x = 4; 382 pos.y = 26; 383 (void) gfx_bitmap_render(term->bmp, &term->update, &pos); 363 384 364 385 term->update.p0.x = 0; … … 655 676 } 656 677 657 /* Got key press/release event */ 678 /** Handle window close event. */ 679 static void terminal_close_event(void *arg) 680 { 681 terminal_t *term = (terminal_t *) arg; 682 683 (void) term; 684 685 // XXX This is not really a clean way of terminating 686 exit(0); 687 } 688 689 /** Handle window focus event. */ 690 static void terminal_focus_event(void *arg) 691 { 692 terminal_t *term = (terminal_t *) arg; 693 694 if (term->wdecor != NULL) { 695 ui_wdecor_set_active(term->wdecor, true); 696 ui_wdecor_paint(term->wdecor); 697 } 698 } 699 700 /** Handle window keyboard event */ 658 701 static void terminal_kbd_event(void *arg, kbd_event_t *kbd_event) 659 702 { … … 665 708 666 709 terminal_queue_cons_event(term, &event); 710 } 711 712 /** Handle window position event */ 713 static void terminal_pos_event(void *arg, pos_event_t *event) 714 { 715 terminal_t *term = (terminal_t *) arg; 716 717 /* Make sure we don't process events until fully initialized */ 718 if (term->wdecor == NULL) 719 return; 720 721 ui_wdecor_pos_event(term->wdecor, event); 722 } 723 724 /** Handle window unfocus event. */ 725 static void terminal_unfocus_event(void *arg) 726 { 727 terminal_t *term = (terminal_t *) arg; 728 729 if (term->wdecor != NULL) { 730 ui_wdecor_set_active(term->wdecor, false); 731 ui_wdecor_paint(term->wdecor); 732 } 667 733 } 668 734 … … 688 754 #endif 689 755 756 /** Window decoration requested window closure. 757 * 758 * @param wdecor Window decoration 759 * @param arg Argument (demo) 760 */ 761 static void terminal_wd_close(ui_wdecor_t *wdecor, void *arg) 762 { 763 terminal_t *term = (terminal_t *) arg; 764 765 (void) term; 766 767 // XXX This is not really a clean way of terminating 768 exit(0); 769 } 770 771 /** Window decoration requested window move. 772 * 773 * @param wdecor Window decoration 774 * @param arg Argument (demo) 775 * @param pos Position where the title bar was pressed 776 */ 777 static void terminal_wd_move(ui_wdecor_t *wdecor, void *arg, gfx_coord2_t *pos) 778 { 779 terminal_t *term = (terminal_t *) arg; 780 781 if (term->window != NULL) 782 (void) display_window_move_req(term->window, pos); 783 } 784 690 785 static void term_connection(ipc_call_t *icall, void *arg) 691 786 { … … 716 811 gfx_bitmap_params_t params; 717 812 display_wnd_params_t wparams; 813 gfx_rect_t rect; 814 gfx_coord2_t off; 815 gfx_rect_t wrect; 718 816 errno_t rc; 719 817 … … 756 854 } 757 855 856 rect.p0.x = 0; 857 rect.p0.y = 0; 858 rect.p1.x = width; 859 rect.p1.y = height; 860 758 861 display_wnd_params_init(&wparams); 759 wparams.rect.p0.x = 0; 760 wparams.rect.p0.y = 0; 761 wparams.rect.p1.x = width; 762 wparams.rect.p1.y = height; 862 863 /* 864 * Compute window rectangle such that application area corresponds 865 * to rect 866 */ 867 ui_wdecor_rect_from_app(&rect, &wrect); 868 off = wrect.p0; 869 gfx_rect_rtranslate(&off, &wrect, &wparams.rect); 763 870 764 871 rc = display_window_create(display, &wparams, &terminal_wnd_cb, … … 775 882 } 776 883 884 rc = ui_resource_create(term->gc, &term->ui_res); 885 if (rc != EOK) { 886 printf("Error creating UI.\n"); 887 goto error; 888 } 889 890 rc = ui_wdecor_create(term->ui_res, "Terminal", &term->wdecor); 891 if (rc != EOK) { 892 printf("Error creating window decoration.\n"); 893 goto error; 894 } 895 896 ui_wdecor_set_rect(term->wdecor, &wparams.rect); 897 ui_wdecor_set_cb(term->wdecor, &wdecor_cb, (void *) term); 898 899 (void) ui_wdecor_paint(term->wdecor); 900 777 901 gfx_bitmap_params_init(¶ms); 778 902 params.rect.p0.x = 0; … … 827 951 return EOK; 828 952 error: 953 if (term->wdecor != NULL) 954 ui_wdecor_destroy(term->wdecor); 955 if (term->ui_res != NULL) 956 ui_resource_destroy(term->ui_res); 829 957 if (term->gc != NULL) 830 958 gfx_context_delete(term->gc); -
uspace/app/terminal/terminal.h
r26653c9 rdcfd422 50 50 #include <stdatomic.h> 51 51 #include <str.h> 52 #include <ui/resource.h> 53 #include <ui/wdecor.h> 52 54 53 55 #define UTF8_CHAR_BUFFER_SIZE (STR_BOUNDS(1) + 1) … … 60 62 sysarg_t h; 61 63 gfx_rect_t update; 64 65 ui_resource_t *ui_res; 66 ui_wdecor_t *wdecor; 62 67 63 68 fibril_mutex_t mtx; -
uspace/lib/ui/include/ui/wdecor.h
r26653c9 rdcfd422 52 52 extern errno_t ui_wdecor_paint(ui_wdecor_t *); 53 53 extern void ui_wdecor_pos_event(ui_wdecor_t *, pos_event_t *); 54 extern void ui_wdecor_rect_from_app(gfx_rect_t *, gfx_rect_t *); 54 55 55 56 #endif -
uspace/lib/ui/src/wdecor.c
r26653c9 rdcfd422 271 271 } 272 272 273 /** Get outer rectangle from application area rectangle. 274 * 275 * Note that this needs to work just based on a UI, without having an actual 276 * window decoration, since we need it in order to create the window 277 * and its decoration. 278 * 279 * @param app Application area rectangle 280 * @param rect Place to store (outer) window decoration rectangle 281 */ 282 void ui_wdecor_rect_from_app(gfx_rect_t *app, gfx_rect_t *rect) 283 { 284 rect->p0.x = app->p0.x - 4; 285 rect->p0.y = app->p0.y - 22 - 4; 286 rect->p1.x = app->p1.x + 4; 287 rect->p1.y = app->p1.y + 4; 288 } 289 273 290 /** Handle window decoration position event. 274 291 * -
uspace/lib/ui/test/wdecor.c
r26653c9 rdcfd422 310 310 } 311 311 312 /** ui_wdecor_get_geom() produces the correct geometry */ 312 313 PCUT_TEST(get_geom) 313 314 { … … 349 350 350 351 ui_wdecor_destroy(wdecor); 352 } 353 354 /** ui_wdecor_rect_from_app() correctly converts application to window rect */ 355 PCUT_TEST(rect_from_app) 356 { 357 gfx_rect_t arect; 358 gfx_rect_t rect; 359 360 arect.p0.x = 14; 361 arect.p0.y = 46; 362 arect.p1.x = 96; 363 arect.p1.y = 196; 364 365 ui_wdecor_rect_from_app(&arect, &rect); 366 367 PCUT_ASSERT_INT_EQUALS(10, rect.p0.x); 368 PCUT_ASSERT_INT_EQUALS(20, rect.p0.y); 369 PCUT_ASSERT_INT_EQUALS(100, rect.p1.x); 370 PCUT_ASSERT_INT_EQUALS(200, rect.p1.y); 351 371 } 352 372
Note:
See TracChangeset
for help on using the changeset viewer.