1 static void xevtcbbpress (XEvent
*e
) {
2 if (curterm
== 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 (curterm
->sel
.bx
!= -1) k8t_tmDirty(curterm
, curterm
->sel
.b
.y
, curterm
->sel
.e
.y
);
25 curterm
->sel
.mode
= 1;
26 curterm
->sel
.b
.y
= curterm
->sel
.e
.y
= curterm
->row
+1;
27 curterm
->sel
.ex
= curterm
->sel
.bx
= K8T_X2COL(e
->xbutton
.x
);
28 curterm
->sel
.ey
= curterm
->sel
.by
= K8T_Y2ROW(curterm
, e
->xbutton
.y
);
29 //fprintf(stderr, "x=%d; y=%d\n", curterm->sel.bx, curterm->sel.by);
34 if (e->xbutton.button == Button3) {
42 if (K8T_ISSET(curterm
, K8T_MODE_MOUSE
)) k8t_mouseReport(curterm
, e
);
46 static void xevtcbbrelease (XEvent
*e
) {
47 if (curterm
== 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 && !curterm
->sel
.mode
) {
59 if (K8T_ISSET(curterm
, K8T_MODE_MOUSE
)) k8t_mouseReport(curterm
, e
);
63 if (e
->xbutton
.button
== Button2
) {
64 selpaste(curterm
, XA_PRIMARY
);
65 } else if (e
->xbutton
.button
== Button1
) {
66 curterm
->sel
.mode
= 0;
67 k8t_getButtonInfo(curterm
, e
, NULL
, &curterm
->sel
.ex
, &curterm
->sel
.ey
); // this sets sel.b and sel.e
69 if (curterm
->sel
.bx
== curterm
->sel
.ex
&& curterm
->sel
.by
== curterm
->sel
.ey
) {
70 // single line, single char selection
73 k8t_tmDirtyMark(curterm
, curterm
->sel
.ey
, 2);
76 if (now
-curterm
->sel
.tclick2
<= opt_tripleclick_timeout
) {
77 /* triple click on the line */
78 curterm
->sel
.b
.x
= curterm
->sel
.bx
= 0;
79 curterm
->sel
.e
.x
= curterm
->sel
.ex
= curterm
->col
;
80 curterm
->sel
.b
.y
= curterm
->sel
.e
.y
= curterm
->sel
.ey
;
81 } else if (now
-curterm
->sel
.tclick1
<= opt_doubleclick_timeout
) {
82 /* double click to select word */
83 K8TLine l
= k8t_selGet(curterm
, curterm
->sel
.ey
);
86 //FIXME: write better word selection code
87 curterm
->sel
.bx
= curterm
->sel
.ex
;
88 if (K8T_ISGFX(l
[curterm
->sel
.bx
].attr
)) {
89 while (curterm
->sel
.bx
> 0 && K8T_ISGFX(l
[curterm
->sel
.bx
-1].attr
)) --curterm
->sel
.bx
;
90 curterm
->sel
.b
.x
= curterm
->sel
.bx
;
91 while (curterm
->sel
.ex
< curterm
->col
-1 && K8T_ISGFX(l
[curterm
->sel
.ex
+1].attr
)) ++curterm
->sel
.ex
;
93 while (curterm
->sel
.bx
> 0 && !K8T_ISGFX(l
[curterm
->sel
.bx
-1].attr
) && l
[curterm
->sel
.bx
-1].c
[0] != ' ') --curterm
->sel
.bx
;
94 curterm
->sel
.b
.x
= curterm
->sel
.bx
;
95 while (curterm
->sel
.ex
< curterm
->col
-1 && !K8T_ISGFX(l
[curterm
->sel
.ex
+1].attr
) && l
[curterm
->sel
.ex
+1].c
[0] != ' ') ++curterm
->sel
.ex
;
97 curterm
->sel
.e
.x
= curterm
->sel
.ex
;
98 curterm
->sel
.b
.y
= curterm
->sel
.e
.y
= curterm
->sel
.ey
;
102 k8t_selCopy(curterm
);
103 k8t_Draw(curterm
, 1);
105 // multiline or multichar selection
106 k8t_selCopy(curterm
);
109 curterm
->sel
.tclick2
= curterm
->sel
.tclick1
;
110 curterm
->sel
.tclick1
= mclock_ticks();
115 static void xevtcbbmotion (XEvent
*e
) {
116 if (curterm
== 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 (curterm
->sel
.mode
) {
128 int oldey
= curterm
->sel
.ey
, oldex
= curterm
->sel
.ex
;
130 k8t_getButtonInfo(curterm
, e
, NULL
, &curterm
->sel
.ex
, &curterm
->sel
.ey
); // this sets sel.b and sel.e
131 if (oldey
!= curterm
->sel
.ey
|| oldex
!= curterm
->sel
.ex
) {
132 int starty
= K8T_MIN(oldey
, curterm
->sel
.ey
);
133 int endy
= K8T_MAX(oldey
, curterm
->sel
.ey
);
135 k8t_tmDirty(curterm
, starty
, endy
);
136 k8t_Draw(curterm
, 1);
140 //if (K8T_ISSET(curterm, K8T_MODE_MOUSE) && e->xbutton.button != 0) k8t_mouseReport(e);