Changeset f03d1308 in mainline for uspace/app/terminal/terminal.c
- Timestamp:
- 2020-10-28T12:42:11Z (4 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8009dc27
- Parents:
- d284ce9
- git-author:
- Jiri Svoboda <jiri@…> (2020-10-28 12:41:11)
- git-committer:
- Jiri Svoboda <jiri@…> (2020-10-28 12:42:11)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/terminal/terminal.c
rd284ce9 rf03d1308 1 1 /* 2 * Copyright (c) 20 19Jiri Svoboda2 * Copyright (c) 2020 Jiri Svoboda 3 3 * Copyright (c) 2012 Petr Koupy 4 4 * All rights reserved. … … 32 32 */ 33 33 /** 34 * @file Terminal application using display service for output34 * @file Terminal application 35 35 */ 36 36 … … 51 51 #include <str.h> 52 52 #include <ui/resource.h> 53 #include <ui/ui.h> 53 54 #include <ui/wdecor.h> 55 #include <ui/window.h> 54 56 55 57 #include "terminal.h" … … 102 104 }; 103 105 104 static void terminal_close_event(void *); 105 static void terminal_focus_event(void *); 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 *); 109 110 static display_wnd_cb_t terminal_wnd_cb = { 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 static void terminal_close_event(ui_window_t *, void *); 107 static void terminal_focus_event(ui_window_t *, void *); 108 static void terminal_kbd_event(ui_window_t *, void *, kbd_event_t *); 109 static void terminal_pos_event(ui_window_t *, void *, pos_event_t *); 110 static void terminal_unfocus_event(ui_window_t *, void *); 111 112 static ui_window_cb_t terminal_window_cb = { 113 .close = terminal_close_event, 114 .focus = terminal_focus_event, 115 .kbd = terminal_kbd_event, 116 .pos = terminal_pos_event, 117 .unfocus = terminal_unfocus_event 124 118 }; 125 119 … … 677 671 678 672 /** Handle window close event. */ 679 static void terminal_close_event( void *arg)673 static void terminal_close_event(ui_window_t *window, void *arg) 680 674 { 681 675 terminal_t *term = (terminal_t *) arg; … … 688 682 689 683 /** Handle window focus event. */ 690 static void terminal_focus_event( void *arg)684 static void terminal_focus_event(ui_window_t *window, void *arg) 691 685 { 692 686 terminal_t *term = (terminal_t *) arg; 693 687 694 if (term->wdecor != NULL) { 695 ui_wdecor_set_active(term->wdecor, true); 696 ui_wdecor_paint(term->wdecor); 697 698 term->is_focused = true; 699 term_update(term); 700 } 688 term->is_focused = true; 689 term_update(term); 701 690 } 702 691 703 692 /** Handle window keyboard event */ 704 static void terminal_kbd_event(void *arg, kbd_event_t *kbd_event) 693 static void terminal_kbd_event(ui_window_t *window, void *arg, 694 kbd_event_t *kbd_event) 705 695 { 706 696 terminal_t *term = (terminal_t *) arg; … … 714 704 715 705 /** Handle window position event */ 716 static void terminal_pos_event( void *arg, pos_event_t *event)706 static void terminal_pos_event(ui_window_t *window, void *arg, pos_event_t *event) 717 707 { 718 708 cons_event_t cevent; 719 709 terminal_t *term = (terminal_t *) arg; 720 721 /* Make sure we don't process events until fully initialized */722 if (term->wdecor == NULL)723 return;724 725 ui_wdecor_pos_event(term->wdecor, event);726 710 727 711 sysarg_t sx = -term->off.x; … … 741 725 742 726 /** Handle window unfocus event. */ 743 static void terminal_unfocus_event( void *arg)727 static void terminal_unfocus_event(ui_window_t *window, void *arg) 744 728 { 745 729 terminal_t *term = (terminal_t *) arg; 746 730 747 if (term->wdecor != NULL) { 748 ui_wdecor_set_active(term->wdecor, false); 749 ui_wdecor_paint(term->wdecor); 750 751 term->is_focused = false; 752 term_update(term); 753 } 754 } 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); 731 term->is_focused = false; 732 term_update(term); 783 733 } 784 734 … … 805 755 } 806 756 807 errno_t terminal_create( display_t *display, sysarg_t width, sysarg_t height,808 terminal_t **rterm)757 errno_t terminal_create(const char *display_spec, sysarg_t width, 758 sysarg_t height, terminal_t **rterm) 809 759 { 810 760 terminal_t *term; 811 761 gfx_bitmap_params_t params; 812 display_wnd_params_t wparams;762 ui_wnd_params_t wparams; 813 763 gfx_rect_t rect; 814 764 gfx_coord2_t off; … … 859 809 rect.p1.y = height; 860 810 861 display_wnd_params_init(&wparams); 811 ui_wnd_params_init(&wparams); 812 wparams.caption = "Terminal"; 862 813 863 814 /* … … 871 822 term->off = off; 872 823 873 rc = display_window_create(display, &wparams, &terminal_wnd_cb, 874 (void *) term, &term->window); 824 rc = ui_create(display_spec, &term->ui); 825 if (rc != EOK) { 826 printf("Error creating UI on %s.\n", display_spec); 827 goto error; 828 } 829 830 rc = ui_window_create(term->ui, &wparams, &term->window); 875 831 if (rc != EOK) { 876 832 printf("Error creating window.\n"); … … 878 834 } 879 835 880 rc = display_window_get_gc(term->window, &term->gc); 881 if (rc != EOK) { 882 printf("Error getting window GC.\n"); 883 goto error; 884 } 885 886 rc = ui_resource_create(term->gc, &term->ui_res); 887 if (rc != EOK) { 888 printf("Error creating UI.\n"); 889 goto error; 890 } 891 892 rc = ui_wdecor_create(term->ui_res, "Terminal", &term->wdecor); 893 if (rc != EOK) { 894 printf("Error creating window decoration.\n"); 895 goto error; 896 } 897 898 ui_wdecor_set_rect(term->wdecor, &wparams.rect); 899 ui_wdecor_set_cb(term->wdecor, &wdecor_cb, (void *) term); 900 901 (void) ui_wdecor_paint(term->wdecor); 836 term->gc = ui_window_get_gc(term->window); 837 term->ui_res = ui_window_get_res(term->window); 838 839 ui_window_set_cb(term->window, &terminal_window_cb, (void *) term); 902 840 903 841 gfx_bitmap_params_init(¶ms); … … 943 881 getterm(vc, "/app/bdsh"); 944 882 883 term->is_focused = true; 884 945 885 term->update.p0.x = 0; 946 886 term->update.p0.y = 0; … … 953 893 return EOK; 954 894 error: 955 if (term->wdecor != NULL)956 ui_wdecor_destroy(term->wdecor);957 if (term->ui_res != NULL)958 ui_resource_destroy(term->ui_res);959 if (term->gc != NULL)960 gfx_context_delete(term->gc);961 895 if (term->window != NULL) 962 display_window_destroy(term->window); 896 ui_window_destroy(term->window); 897 if (term->ui != NULL) 898 ui_destroy(term->ui); 963 899 if (term->frontbuf != NULL) 964 900 chargrid_destroy(term->frontbuf);
Note:
See TracChangeset
for help on using the changeset viewer.