1 static void bpress (XEvent
*e
) {
2 if (term
== NULL
) return;
4 if (xw
.tabheight
> 0) {
5 if ((opt_tabposition
== 0 && e
->xbutton
.y
>= xw
.h
-xw
.tabheight
) ||
6 (opt_tabposition
!= 0 && e
->xbutton
.y
< xw
.tabheight
)) {
7 switch (e
->xbutton
.button
) {
11 case Button4
: // wheel up
14 case Button5
: // wheel down
22 if ((e
->xbutton
.state
&ShiftMask
) != 0) {
23 if (e
->xbutton
.button
== Button1
) {
24 if (term
->sel
.bx
!= -1) tsetdirt(term
->sel
.b
.y
, term
->sel
.e
.y
);
26 term
->sel
.b
.y
= term
->sel
.e
.y
= term
->row
+1;
27 term
->sel
.ex
= term
->sel
.bx
= X2COL(e
->xbutton
.x
);
28 term
->sel
.ey
= term
->sel
.by
= Y2ROW(e
->xbutton
.y
);
29 //fprintf(stderr, "x=%d; y=%d\n", term->sel.bx, term->sel.by);
34 if (e->xbutton.button == Button3) {
42 if (IS_SET(MODE_MOUSE
)) mousereport(e
);
46 static void brelease (XEvent
*e
) {
47 if (term
== NULL
) return;
49 switch (opt_tabposition
) {
51 if (e
->xbutton
.y
>= xw
.h
-xw
.tabheight
) return;
54 if (e
->xbutton
.y
< xw
.tabheight
) return;
58 if ((e
->xbutton
.state
&ShiftMask
) == 0 && !term
->sel
.mode
) {
59 if (IS_SET(MODE_MOUSE
)) mousereport(e
);
63 if (e
->xbutton
.button
== Button2
) {
65 } else if (e
->xbutton
.button
== Button1
) {
67 getbuttoninfo(e
, NULL
, &term
->sel
.ex
, &term
->sel
.ey
); // this sets sel.b and sel.e
69 if (term
->sel
.bx
== term
->sel
.ex
&& term
->sel
.by
== term
->sel
.ey
) {
70 // single line, single char selection
73 markDirty(term
->sel
.ey
, 2);
76 if (now
-term
->sel
.tclick2
<= opt_tripleclick_timeout
) {
77 /* triple click on the line */
78 term
->sel
.b
.x
= term
->sel
.bx
= 0;
79 term
->sel
.e
.x
= term
->sel
.ex
= term
->col
;
80 term
->sel
.b
.y
= term
->sel
.e
.y
= term
->sel
.ey
;
81 } else if (now
-term
->sel
.tclick1
<= opt_doubleclick_timeout
) {
82 /* double click to select word */
83 Line l
= selgetlinebyy(term
->sel
.ey
);
86 //FIXME: write better word selection code
87 term
->sel
.bx
= term
->sel
.ex
;
88 if (IS_GFX(l
[term
->sel
.bx
].attr
)) {
89 while (term
->sel
.bx
> 0 && IS_GFX(l
[term
->sel
.bx
-1].attr
)) --term
->sel
.bx
;
90 term
->sel
.b
.x
= term
->sel
.bx
;
91 while (term
->sel
.ex
< term
->col
-1 && IS_GFX(l
[term
->sel
.ex
+1].attr
)) ++term
->sel
.ex
;
93 while (term
->sel
.bx
> 0 && !IS_GFX(l
[term
->sel
.bx
-1].attr
) && l
[term
->sel
.bx
-1].c
[0] != ' ') --term
->sel
.bx
;
94 term
->sel
.b
.x
= term
->sel
.bx
;
95 while (term
->sel
.ex
< term
->col
-1 && !IS_GFX(l
[term
->sel
.ex
+1].attr
) && l
[term
->sel
.ex
+1].c
[0] != ' ') ++term
->sel
.ex
;
97 term
->sel
.e
.x
= term
->sel
.ex
;
98 term
->sel
.b
.y
= term
->sel
.e
.y
= term
->sel
.ey
;
105 // multiline or multichar selection
109 term
->sel
.tclick2
= term
->sel
.tclick1
;
110 term
->sel
.tclick1
= mclock_ticks();
115 static void bmotion (XEvent
*e
) {
116 if (term
== NULL
) return;
118 switch (opt_tabposition
) {
120 if (e
->xbutton
.y
>= xw
.h
-xw
.tabheight
) return;
123 if (e
->xbutton
.y
< xw
.tabheight
) return;
127 if (term
->sel
.mode
) {
128 int oldey
= term
->sel
.ey
, oldex
= term
->sel
.ex
;
130 getbuttoninfo(e
, NULL
, &term
->sel
.ex
, &term
->sel
.ey
); // this sets sel.b and sel.e
131 if (oldey
!= term
->sel
.ey
|| oldex
!= term
->sel
.ex
) {
132 int starty
= MIN(oldey
, term
->sel
.ey
);
133 int endy
= MAX(oldey
, term
->sel
.ey
);
135 tsetdirt(starty
, endy
);
140 //if (IS_SET(MODE_MOUSE) && e->xbutton.button != 0) mousereport(e);