source separated to alot of files (don't know if it's better this way, but...)
[k8sterm.git] / src / mouseevents.c
blob7e108e4b6dd1efa8344c1e53ec5eb45bb41086af
1 static void bpress (XEvent *e) {
2 if (term == NULL) return;
3 //
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) {
8 case Button1: // left
9 msTabSwitch(e);
10 break;
11 case Button4: // wheel up
12 msTabScrollLeft();
13 break;
14 case Button5: // wheel down
15 msTabScrollRight();
16 break;
18 return;
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);
25 term->sel.mode = 1;
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);
30 draw(1);
31 return;
34 if (e->xbutton.button == Button3) {
35 term->sel.bx = -1;
36 selcopy();
37 draw(1);
40 return;
42 if (IS_SET(MODE_MOUSE)) mousereport(e);
46 static void brelease (XEvent *e) {
47 if (term == NULL) return;
49 switch (opt_tabposition) {
50 case 0: // bottom
51 if (e->xbutton.y >= xw.h-xw.tabheight) return;
52 break;
53 case 1: // top
54 if (e->xbutton.y < xw.tabheight) return;
55 break;
58 if ((e->xbutton.state&ShiftMask) == 0 && !term->sel.mode) {
59 if (IS_SET(MODE_MOUSE)) mousereport(e);
60 return;
63 if (e->xbutton.button == Button2) {
64 selpaste(XA_PRIMARY);
65 } else if (e->xbutton.button == Button1) {
66 term->sel.mode = 0;
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
71 MSTime now;
73 markDirty(term->sel.ey, 2);
74 term->sel.bx = -1;
75 now = mclock_ticks();
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);
85 if (l != NULL) {
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;
92 } else {
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;
102 selcopy();
103 draw(1);
104 } else {
105 // multiline or multichar selection
106 selcopy();
109 term->sel.tclick2 = term->sel.tclick1;
110 term->sel.tclick1 = mclock_ticks();
111 //draw(1);
115 static void bmotion (XEvent *e) {
116 if (term == NULL) return;
118 switch (opt_tabposition) {
119 case 0: // bottom
120 if (e->xbutton.y >= xw.h-xw.tabheight) return;
121 break;
122 case 1: // top
123 if (e->xbutton.y < xw.tabheight) return;
124 break;
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);
136 draw(1);
138 return;
140 //if (IS_SET(MODE_MOUSE) && e->xbutton.button != 0) mousereport(e);