Changeset dcfd422 in mainline for uspace/app/terminal/terminal.c
- 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)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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);
Note:
See TracChangeset
for help on using the changeset viewer.