Changeset 5e0acaa in mainline
- Timestamp:
- 2024-10-10T11:52:43Z (3 months ago)
- Branches:
- master
- Children:
- fb06afd
- Parents:
- 5f5d375
- git-author:
- Jiri Svoboda <jiri@…> (2024-10-09 17:46:33)
- git-committer:
- Jiri Svoboda <jiri@…> (2024-10-10 11:52:43)
- Location:
- uspace
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/vt/include/vt/vt100.h
r5f5d375 r5e0acaa 37 37 #include <io/charfield.h> 38 38 #include <io/keycode.h> 39 #include <io/pos_event.h> 39 40 #include <ipc/common.h> 40 41 #include <uchar.h> … … 77 78 void (*flush)(void *); 78 79 void (*key)(void *, keymod_t, keycode_t, char); 80 void (*pos_event)(void *, pos_event_t *); 79 81 } vt100_cb_t; 80 82 … … 124 126 vts_1b5b33, 125 127 /** Prefix 1b 5b 36 */ 126 vts_1b5b36 128 vts_1b5b36, 129 /** Prefix 1b 5b 3c - mouse report */ 130 vts_1b5b3c 127 131 } vt100_state_t; 132 133 enum { 134 INNUM_MAX = 3 135 }; 128 136 129 137 /** VT100 instance */ … … 151 159 /** Input decoding state */ 152 160 vt100_state_t state; 161 /** Decoded numeric parameters */ 162 uint16_t innum[INNUM_MAX]; 163 /** Index of current numeric parameter */ 164 unsigned inncnt; 153 165 } vt100_t; 154 166 … … 170 182 extern void vt100_set_attr(vt100_t *, char_attrs_t); 171 183 extern void vt100_cursor_visibility(vt100_t *, bool); 184 extern void vt100_set_button_reporting(vt100_t *, bool); 172 185 extern void vt100_putuchar(vt100_t *, char32_t); 173 186 extern void vt100_flush(vt100_t *); -
uspace/lib/vt/src/vt100.c
r5f5d375 r5e0acaa 32 32 */ 33 33 34 #include <ctype.h> 34 35 #include <errno.h> 35 36 #include <io/color.h> … … 309 310 } 310 311 312 /** Set mouse button press/release reporting. 313 * 314 * @param vt VT instance 315 * @param @c true to enable button press/release reporting 316 */ 317 void vt100_set_button_reporting(vt100_t *vt, bool enable) 318 { 319 if (enable) { 320 /* Enable button tracking */ 321 vt->cb->control_puts(vt->arg, "\033[?1000h"); 322 /* Enable SGR encoding of mouse reports */ 323 vt->cb->control_puts(vt->arg, "\033[?1006h"); 324 } else { 325 /* Disable button tracking */ 326 vt->cb->control_puts(vt->arg, "\033[?1000l"); 327 /* Disable SGR encoding of mouse reports */ 328 vt->cb->control_puts(vt->arg, "\033[?1006l"); 329 } 330 } 331 311 332 /** Print Unicode character. 312 333 * … … 349 370 } 350 371 372 /** Generate position event callback. 373 * * 374 * @param vt VT instance 375 * @param ev Position event 376 */ 377 static void vt100_pos_event(vt100_t *vt, pos_event_t *ev) 378 { 379 vt->cb->pos_event(vt->arg, ev); 380 } 381 382 /** Clear number decoder state. 383 * 384 * @param vt VT instance 385 */ 386 static void vt100_clear_innum(vt100_t *vt) 387 { 388 unsigned i; 389 390 vt->inncnt = 0; 391 for (i = 0; i < INNUM_MAX; i++) 392 vt->innum[i] = 0; 393 } 394 351 395 /** Process input character with prefix 1b. 352 396 * … … 576 620 vt->state = vts_1b5b36; 577 621 break; 622 case 0x3c: 623 vt->state = vts_1b5b3c; 624 break; 578 625 case 0x41: 579 626 vt100_key(vt, 0, KC_UP, 0); … … 966 1013 vt->state = vts_base; 967 1014 break; 1015 } 1016 } 1017 1018 /** Process input character with prefix 1b 5b 3c - mouse report. 1019 * 1020 * @param vt VT instance 1021 * @param c Input character 1022 */ 1023 static void vt100_rcvd_1b5b3c(vt100_t *vt, char c) 1024 { 1025 pos_event_t ev; 1026 1027 if (isdigit(c)) { 1028 /* Decode next base-10 digit */ 1029 vt->innum[vt->inncnt] = vt->innum[vt->inncnt] * 10 + (c - '0'); 1030 } else if (c == ';') { 1031 /* Move to next parameter */ 1032 if (vt->inncnt >= INNUM_MAX - 1) { 1033 vt->state = vts_base; 1034 vt100_clear_innum(vt); 1035 return; 1036 } 1037 ++vt->inncnt; 1038 } else { 1039 switch (c) { 1040 case 'M': 1041 case 'm': 1042 /* Button press / release */ 1043 ev.pos_id = 0; 1044 ev.type = (c == 'M') ? POS_PRESS : POS_RELEASE; 1045 1046 /* 1047 * VT reports button 0 = left button, 1048 * 1 = middle, 2 = right. 1049 * pos_event needs 1 = left, 2 = right, 3 = middle,... 1050 * so right and middle need to be reversed. 1051 */ 1052 switch (vt->innum[0]) { 1053 case 1: 1054 ev.btn_num = 3; 1055 break; 1056 case 2: 1057 ev.btn_num = 2; 1058 break; 1059 default: 1060 ev.btn_num = 1 + vt->innum[0]; 1061 break; 1062 } 1063 ev.hpos = vt->innum[1] - 1; 1064 ev.vpos = vt->innum[2] - 1; 1065 vt100_pos_event(vt, &ev); 1066 break; 1067 } 1068 vt100_clear_innum(vt); 1069 vt->state = vts_base; 968 1070 } 969 1071 } … … 1453 1555 vt100_rcvd_1b5b36(vt, c); 1454 1556 break; 1557 case vts_1b5b3c: 1558 vt100_rcvd_1b5b3c(vt, c); 1559 break; 1455 1560 } 1456 1561 } -
uspace/srv/hid/remcons/remcons.c
r5f5d375 r5e0acaa 126 126 static void remcons_vt_flush(void *); 127 127 static void remcons_vt_key(void *, keymod_t, keycode_t, char); 128 static void remcons_vt_pos_event(void *, pos_event_t *); 128 129 129 130 static vt100_cb_t remcons_vt_cb = { … … 131 132 .control_puts = remcons_vt_cputs, 132 133 .flush = remcons_vt_flush, 133 .key = remcons_vt_key 134 .key = remcons_vt_key, 135 .pos_event = remcons_vt_pos_event 134 136 }; 135 137 … … 369 371 event->cev.ev.key.key = key; 370 372 event->cev.ev.key.c = c; 373 374 return event; 375 } 376 377 /** Creates new position event. 378 * 379 * @param ev Position event. 380 * @param c Pressed character. 381 */ 382 static remcons_event_t *new_pos_event(pos_event_t *ev) 383 { 384 remcons_event_t *event = malloc(sizeof(remcons_event_t)); 385 if (event == NULL) { 386 fprintf(stderr, "Out of memory.\n"); 387 return NULL; 388 } 389 390 link_initialize(&event->link); 391 event->cev.type = CEV_POS; 392 event->cev.ev.pos = *ev; 371 393 372 394 return event; … … 627 649 } 628 650 651 static void remcons_vt_pos_event(void *arg, pos_event_t *ev) 652 { 653 remcons_t *remcons = (remcons_t *)arg; 654 655 remcons_event_t *cev = new_pos_event(ev); 656 if (cev == NULL) 657 return; 658 659 list_append(&cev->link, &remcons->in_events); 660 } 661 629 662 /** Window size update callback. 630 663 * … … 700 733 vt100_cls(remcons->vt); 701 734 vt100_set_pos(remcons->vt, 0, 0); 735 vt100_set_button_reporting(remcons->vt, true); 702 736 } 703 737
Note:
See TracChangeset
for help on using the changeset viewer.