Changeset 5e0acaa in mainline for uspace/lib/vt/src/vt100.c


Ignore:
Timestamp:
2024-10-10T11:52:43Z (20 hours ago)
Author:
Jiri Svoboda <jiri@…>
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)
Message:

Implement mouse tracking in libvt / remcons

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/vt/src/vt100.c

    r5f5d375 r5e0acaa  
    3232 */
    3333
     34#include <ctype.h>
    3435#include <errno.h>
    3536#include <io/color.h>
     
    309310}
    310311
     312/** Set mouse button press/release reporting.
     313 *
     314 * @param vt VT instance
     315 * @param @c true to enable button press/release reporting
     316 */
     317void 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
    311332/** Print Unicode character.
    312333 *
     
    349370}
    350371
     372/** Generate position event callback.
     373 * *
     374 * @param vt VT instance
     375 * @param ev Position event
     376 */
     377static 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 */
     386static 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
    351395/** Process input character with prefix 1b.
    352396 *
     
    576620                vt->state = vts_1b5b36;
    577621                break;
     622        case 0x3c:
     623                vt->state = vts_1b5b3c;
     624                break;
    578625        case 0x41:
    579626                vt100_key(vt, 0, KC_UP, 0);
     
    9661013                vt->state = vts_base;
    9671014                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 */
     1023static 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;
    9681070        }
    9691071}
     
    14531555                vt100_rcvd_1b5b36(vt, c);
    14541556                break;
     1557        case vts_1b5b3c:
     1558                vt100_rcvd_1b5b3c(vt, c);
     1559                break;
    14551560        }
    14561561}
Note: See TracChangeset for help on using the changeset viewer.