Ticket #2662: mc-4.8.0-extended-mouse-coordinates.patch

File mc-4.8.0-extended-mouse-coordinates.patch, 7.3 KB (added by egmont, 12 years ago)
  • lib/tty/key.c

    http://www.midnight-commander.org/ticket/2662
    
    diff -ur mc-4.8.0.orig/lib/tty/key.c mc-4.8.0/lib/tty/key.c
    old new  
    518518 
    519519static int *pending_keys = NULL; 
    520520 
     521static int mouse_btn, mouse_x, mouse_y; 
     522 
    521523#ifdef __QNXNTO__ 
    522524ph_dv_f ph_attach; 
    523525ph_ov_f ph_input_group; 
     
    708710static void 
    709711xmouse_get_event (Gpm_Event * ev) 
    710712{ 
    711     int btn; 
    712713    static struct timeval tv1 = { 0, 0 };       /* Force first click as single */ 
    713714    static struct timeval tv2; 
    714715    static int clicks = 0; 
     
    716717 
    717718    /* Decode Xterm mouse information to a GPM style event */ 
    718719 
    719     /* Variable btn has following meaning: */ 
    720     /* 0 = btn1 dn, 1 = btn2 dn, 2 = btn3 dn, 3 = btn up */ 
    721     btn = tty_lowlevel_getch () - 32; 
    722  
    723720    /* There seems to be no way of knowing which button was released */ 
    724721    /* So we assume all the buttons were released */ 
    725722 
     723    int btn = mouse_btn; 
    726724    if (btn == 3) 
    727725    { 
    728726        if (last_btn != 0) 
     
    797795        } 
    798796        last_btn = ev->buttons; 
    799797    } 
    800     /* Coordinates are 33-based */ 
    801     /* Transform them to 1-based */ 
    802     ev->x = tty_lowlevel_getch () - 32; 
    803     ev->y = tty_lowlevel_getch () - 32; 
     798    ev->x = mouse_x; 
     799    ev->y = mouse_y; 
    804800} 
    805801 
    806802/* --------------------------------------------------------------------------------------------- */ 
     
    935931} 
    936932 
    937933/* --------------------------------------------------------------------------------------------- */ 
     934/* Parse extended mouse coordinates. 
     935   Returns -1 if pending_keys cannot be a prefix of extended mouse coordinates. 
     936   Returns 0 if pending_keys is a valid (but still incomplete) prefix for extended mouse coordinates, e.g. "^[[32;4". 
     937   Returns 1 and fills the mouse_btn, mouse_x, mouse_y values if pending_keys is a complete extended mouse sequence, e.g. "^[[32;42;5M" */ 
     938static int 
     939parse_extended_mouse_coordinates (void) 
     940{ 
     941    int c, btn = 0, x = 0, y = 0; 
     942    const int *p = pending_keys; 
     943 
     944    c = *p++; 
     945    if (c == 0) 
     946        return 0; 
     947    else if (c != ESC_CHAR) 
     948        return -1; 
     949 
     950    c = *p++; 
     951    if (c == 0) 
     952        return 0; 
     953    else if (c != '[') 
     954        return -1; 
     955 
     956    while (1) { 
     957        c = *p++; 
     958        if (c == 0) 
     959            return 0; 
     960        if (c == ';') 
     961            break; 
     962        if (c < '0' || c > '9') 
     963            return -1; 
     964        btn = 10 * btn + c - '0'; 
     965    } 
     966    if (btn < 32) 
     967        return -1; 
     968    btn -= 32; 
     969 
     970    while (1) { 
     971        c = *p++; 
     972        if (c == 0) 
     973            return 0; 
     974        if (c == ';') 
     975            break; 
     976        if (c < '0' || c > '9') 
     977            return -1; 
     978        x = 10 * x + c - '0'; 
     979    } 
     980    if (x < 1) 
     981        return -1; 
     982 
     983    while (1) { 
     984        c = *p++; 
     985        if (c == 0) 
     986            return 0; 
     987        if (c == 'M') 
     988            break; 
     989        if (c < '0' || c > '9') 
     990            return -1; 
     991        y = 10 * y + c - '0'; 
     992    } 
     993    if (y < 1) 
     994        return -1; 
     995 
     996    mouse_btn = btn; 
     997    mouse_x = x; 
     998    mouse_y = y; 
     999    return 1; 
     1000} 
     1001 
     1002/* --------------------------------------------------------------------------------------------- */ 
    9381003/* Apply corrections for the keycode generated in get_key_code() */ 
    9391004 
    9401005static int 
     
    16931758  pend_send: 
    16941759    if (pending_keys != NULL) 
    16951760    { 
    1696         int d = *pending_keys++; 
    1697       check_pend: 
    1698         if (*pending_keys == 0) 
    1699         { 
    1700             pending_keys = NULL; 
    1701             seq_append = NULL; 
    1702         } 
    1703         if ((d == ESC_CHAR) && (pending_keys != NULL)) 
    1704         { 
    1705             d = ALT (*pending_keys++); 
    1706             goto check_pend; 
     1761        int m = parse_extended_mouse_coordinates(); 
     1762        if (m == 1) { 
     1763            pending_keys = seq_append = NULL; 
     1764            this = NULL; 
     1765            return MCKEY_EXTENDED_MOUSE; 
     1766        } 
     1767        else if (m == -1) { 
     1768            int d = *pending_keys++; 
     1769          check_pend: 
     1770            if (*pending_keys == 0) 
     1771            { 
     1772                pending_keys = NULL; 
     1773                seq_append = NULL; 
     1774            } 
     1775            if ((d == ESC_CHAR) && (pending_keys != NULL)) 
     1776            { 
     1777                d = ALT (*pending_keys++); 
     1778                goto check_pend; 
     1779            } 
     1780            if ((d > 127 && d < 256) && use_8th_bit_as_meta) 
     1781                d = ALT (d & 0x7f); 
     1782            this = NULL; 
     1783            return correct_key_code (d); 
    17071784        } 
    1708         if ((d > 127 && d < 256) && use_8th_bit_as_meta) 
    1709             d = ALT (d & 0x7f); 
    1710         this = NULL; 
    1711         return correct_key_code (d); 
     1785        /* else if (m == 0), just let it continue */ 
    17121786    } 
    17131787 
    17141788  nodelay_try_again: 
     
    20152089#ifdef KEY_MOUSE 
    20162090                          || c == KEY_MOUSE 
    20172091#endif /* KEY_MOUSE */ 
     2092                          || c == MCKEY_EXTENDED_MOUSE 
    20182093        )) 
    20192094    { 
    20202095        /* Mouse event */ 
     2096        /* In case of extended coordinates, mouse_btn, mouse_x and mouse_y are already filled in. */ 
     2097        if (c != MCKEY_EXTENDED_MOUSE) { 
     2098            /* Variable btn has following meaning: */ 
     2099            /* 0 = btn1 dn, 1 = btn2 dn, 2 = btn3 dn, 3 = btn up */ 
     2100            mouse_btn = tty_lowlevel_getch () - 32; 
     2101            /* Coordinates are 33-based */ 
     2102            /* Transform them to 1-based */ 
     2103            mouse_x = tty_lowlevel_getch () - 32; 
     2104            mouse_y = tty_lowlevel_getch () - 32; 
     2105        } 
    20212106        xmouse_get_event (event); 
    20222107        return (event->type != 0) ? EV_MOUSE : EV_NONE; 
    20232108    } 
  • lib/tty/key.h

    diff -ur mc-4.8.0.orig/lib/tty/key.h mc-4.8.0/lib/tty/key.h
    old new  
    3333/* Return code for the mouse sequence */ 
    3434#define MCKEY_MOUSE     -2 
    3535 
     36/* Return code for the extended mouse sequence */ 
     37#define MCKEY_EXTENDED_MOUSE     -3 
     38 
    3639/*** enums ***************************************************************************************/ 
    3740 
    3841/*** structures declarations (and typedefs of structures)*****************************************/ 
  • lib/tty/mouse.c

    diff -ur mc-4.8.0.orig/lib/tty/mouse.c mc-4.8.0/lib/tty/mouse.c
    old new  
    138138        /* enable mouse tracking */ 
    139139        printf (ESC_STR "[?1000h"); 
    140140 
     141        /* enable urxvt extended mouse coordinate reporting */ 
     142        printf (ESC_STR "[?1015h"); 
     143 
    141144        fflush (stdout); 
    142145        mouse_enabled = TRUE; 
    143146        break; 
     
    149152        /* enable mouse tracking */ 
    150153        printf (ESC_STR "[?1002h"); 
    151154 
     155        /* enable urxvt extended mouse coordinate reporting */ 
     156        printf (ESC_STR "[?1015h"); 
     157 
    152158        fflush (stdout); 
    153159        mouse_enabled = TRUE; 
    154160        break; 
     
    176182        break; 
    177183#endif 
    178184    case MOUSE_XTERM_NORMAL_TRACKING: 
     185        /* disable urxvt extended mouse coordinate reporting */ 
     186        printf (ESC_STR "[?1015l"); 
     187 
    179188        /* disable mouse tracking */ 
    180189        printf (ESC_STR "[?1000l"); 
    181190 
     
    185194        fflush (stdout); 
    186195        break; 
    187196    case MOUSE_XTERM_BUTTON_EVENT_TRACKING: 
     197        /* disable urxvt extended mouse coordinate reporting */ 
     198        printf (ESC_STR "[?1015l"); 
     199 
    188200        /* disable mouse tracking */ 
    189201        printf (ESC_STR "[?1002l"); 
    190202