diff options
| author | Christoph Lohmann <20h@r-36.net> | 2013-01-26 15:13:56 +0100 |
|---|---|---|
| committer | Christoph Lohmann <20h@r-36.net> | 2013-01-26 15:13:56 +0100 |
| commit | 384fabdb5b2ac6c700a974a7fac539c8c14107f6 (patch) | |
| tree | 8733dff058430bd4f6adcaf65f82aec0638080bd /st.c | |
| parent | deb720af7fe480b03c881818e79164817ce6f85f (diff) | |
| download | st-384fabdb5b2ac6c700a974a7fac539c8c14107f6.tar.gz st-384fabdb5b2ac6c700a974a7fac539c8c14107f6.zip | |
Adding extended mouse reporting in st.
Thanks Egmont Koblinger <egmont@gmail.com>!
Diffstat (limited to 'st.c')
| -rw-r--r-- | st.c | 35 |
1 files changed, 26 insertions, 9 deletions
| @@ -117,7 +117,8 @@ enum term_mode { | |||
| 117 | MODE_KBDLOCK = 256, | 117 | MODE_KBDLOCK = 256, |
| 118 | MODE_HIDE = 512, | 118 | MODE_HIDE = 512, |
| 119 | MODE_ECHO = 1024, | 119 | MODE_ECHO = 1024, |
| 120 | MODE_APPCURSOR = 2048 | 120 | MODE_APPCURSOR = 2048, |
| 121 | MODE_MOUSESGR = 4096, | ||
| 121 | }; | 122 | }; |
| 122 | 123 | ||
| 123 | enum escape_state { | 124 | enum escape_state { |
| @@ -666,11 +667,10 @@ getbuttoninfo(XEvent *e) { | |||
| 666 | 667 | ||
| 667 | void | 668 | void |
| 668 | mousereport(XEvent *e) { | 669 | mousereport(XEvent *e) { |
| 669 | int x = x2col(e->xbutton.x); | 670 | int x = x2col(e->xbutton.x), y = y2row(e->xbutton.y), |
| 670 | int y = y2row(e->xbutton.y); | 671 | button = e->xbutton.button, state = e->xbutton.state, |
| 671 | int button = e->xbutton.button; | 672 | len; |
| 672 | int state = e->xbutton.state; | 673 | char buf[40]; |
| 673 | char buf[] = { '\033', '[', 'M', 0, 32+x+1, 32+y+1 }; | ||
| 674 | static int ob, ox, oy; | 674 | static int ob, ox, oy; |
| 675 | 675 | ||
| 676 | /* from urxvt */ | 676 | /* from urxvt */ |
| @@ -679,7 +679,9 @@ mousereport(XEvent *e) { | |||
| 679 | return; | 679 | return; |
| 680 | button = ob + 32; | 680 | button = ob + 32; |
| 681 | ox = x, oy = y; | 681 | ox = x, oy = y; |
| 682 | } else if(e->xbutton.type == ButtonRelease || button == AnyButton) { | 682 | } else if(!IS_SET(MODE_MOUSESGR) |
| 683 | && (e->xbutton.type == ButtonRelease | ||
| 684 | || button == AnyButton)) { | ||
| 683 | button = 3; | 685 | button = 3; |
| 684 | } else { | 686 | } else { |
| 685 | button -= Button1; | 687 | button -= Button1; |
| @@ -691,11 +693,23 @@ mousereport(XEvent *e) { | |||
| 691 | } | 693 | } |
| 692 | } | 694 | } |
| 693 | 695 | ||
| 694 | buf[3] = 32 + button + (state & ShiftMask ? 4 : 0) | 696 | button += (state & ShiftMask ? 4 : 0) |
| 695 | + (state & Mod4Mask ? 8 : 0) | 697 | + (state & Mod4Mask ? 8 : 0) |
| 696 | + (state & ControlMask ? 16 : 0); | 698 | + (state & ControlMask ? 16 : 0); |
| 697 | 699 | ||
| 698 | ttywrite(buf, sizeof(buf)); | 700 | len = 0; |
| 701 | if(IS_SET(MODE_MOUSESGR)) { | ||
| 702 | len = snprintf(buf, sizeof(buf), "\033[<%d;%d;%d%c", | ||
| 703 | button, x+1, y+1, | ||
| 704 | e->xbutton.type == ButtonRelease ? 'm' : 'M'); | ||
| 705 | } else if(x < 223 && y < 223) { | ||
| 706 | len = snprintf(buf, sizeof(buf), "\033[M%c%c%c", | ||
| 707 | 32+button, 32+x+1, 32+y+1); | ||
| 708 | } else { | ||
| 709 | return; | ||
| 710 | } | ||
| 711 | |||
| 712 | ttywrite(buf, len); | ||
| 699 | } | 713 | } |
| 700 | 714 | ||
| 701 | void | 715 | void |
| @@ -1547,6 +1561,9 @@ tsetmode(bool priv, bool set, int *args, int narg) { | |||
| 1547 | case 1002: | 1561 | case 1002: |
| 1548 | MODBIT(term.mode, set, MODE_MOUSEMOTION); | 1562 | MODBIT(term.mode, set, MODE_MOUSEMOTION); |
| 1549 | break; | 1563 | break; |
| 1564 | case 1006: | ||
| 1565 | MODBIT(term.mode, set, MODE_MOUSESGR); | ||
| 1566 | break; | ||
| 1550 | case 1049: /* = 1047 and 1048 */ | 1567 | case 1049: /* = 1047 and 1048 */ |
| 1551 | case 47: | 1568 | case 47: |
| 1552 | case 1047: { | 1569 | case 1047: { |
