clear selections in all tabs when selection ownership is lost
[k8sterm.git] / src / x11evtvis.c
blob6cbcfa0929b0ec6895b786044b89eafd7e44f14a
1 static void xevtcbexpose (XEvent *ev) {
2 XExposeEvent *e = &ev->xexpose;
3 //
4 if (xw.state&K8T_WIN_REDRAW) {
5 if (!e->count && curterm != NULL) {
6 xw.state &= ~K8T_WIN_REDRAW;
7 k8t_drawCopy(curterm, 0, 0, curterm->col, curterm->row);
8 if (!updateTabBar) updateTabBar = -1;
10 xclearunused();
11 } else if (curterm != NULL) {
12 int taby = (opt_tabposition==1 ? 0 : xw.h-xw.tabheight);
13 int termy = (opt_tabposition==1 ? xw.tabheight : 0);
14 int x0 = e->x/xw.cw, y0 = (e->y-termy)/xw.ch;
15 int x1 = (e->x+e->width)/xw.cw, y1 = (e->y-termy+e->height)/xw.ch;
17 //fprintf(stderr, "x=%d; y=%d; w=%d; h=%d\n", e->x, e->y, e->width, e->height);
18 //fprintf(stderr, "taby=%d; tabh=%d\n", taby, xw.tabheight);
19 //fprintf(stderr, "x0=%d; y0=%d; x1=%d; y1=%d\n", x0, y0, x1, y1);
21 if (e->y <= taby+xw.tabheight && e->y+e->height >= taby) {
22 //fprintf(stderr, "tabbar!\n");
23 if (!updateTabBar) updateTabBar = -1;
25 //XCopyArea(xw.dpy, K8T_DATA(curterm)->picbuf, xw.win, dc.gc, e->x, e->y, e->width, e->height, e->x, e->y+(opt_tabposition==1?xw.height:0)));
26 //k8t_drawCopy(curterm, 0, 0, curterm->col, curterm->row);
27 //k8t_drawClear(curterm, x0, y0, x1-x0+1, y1-y0+1);
28 K8T_LIMIT(x0, 0, curterm->col-1);
29 K8T_LIMIT(x1, 0, curterm->col-1);
30 K8T_LIMIT(y0, 0, curterm->row-1);
31 K8T_LIMIT(y1, 0, curterm->row-1);
32 //fprintf(stderr, "*:x0=%d; y0=%d; x1=%d; y1=%d\n", x0, y0, x1, y1);
33 k8t_drawCopy(curterm, x0, y0, x1-x0+1, y1-y0+1);
34 //xclearunused(); //FIXME: optimize this
35 } else {
36 if (!updateTabBar) updateTabBar = -1;
38 xdrawTabBar();
39 //XFlush(xw.dpy);
43 static void xevtcbvisibility (XEvent *ev) {
44 XVisibilityEvent *e = &ev->xvisibility;
46 if (e->state == VisibilityFullyObscured) xw.state &= ~K8T_WIN_VISIBLE;
47 else if ((xw.state&K8T_WIN_VISIBLE) == 0) xw.state |= K8T_WIN_VISIBLE|K8T_WIN_REDRAW; /* need a full redraw for next Expose, not just a buf copy */
51 static void xevtcbunmap (XEvent *ev) {
52 xw.state &= ~K8T_WIN_VISIBLE;
56 static void xseturgency (int add) {
57 XWMHints *h = XGetWMHints(xw.dpy, xw.win);
59 h->flags = add ? (h->flags|XUrgencyHint) : (h->flags&~XUrgencyHint);
60 XSetWMHints(xw.dpy, xw.win, h);
61 XFree(h);
65 static void xevtcbfocus (XEvent *ev) {
66 if (ev->type == FocusIn) {
67 xw.state |= K8T_WIN_FOCUSED;
68 xseturgency(0);
69 k8t_tmSendFocusEvent(curterm, 1);
70 } else {
71 xw.state &= ~K8T_WIN_FOCUSED;
72 k8t_tmSendFocusEvent(curterm, 0);
74 //k8t_drawTerm(curterm, 1);
75 if (!updateTabBar) updateTabBar = -1;
76 xdrawTabBar();
77 k8t_drawCursor(curterm, 0);
78 k8t_tmWantRedraw(curterm, 0);
79 //k8t_drawCopy(curterm, 0, 0, curterm->col, curterm->row);
83 static void xevtcbresise (XEvent *e) {
84 int col, row;
86 //if (e->xconfigure.width == 65535 || e->xconfigure.width == -1) e->xconfigure.width = xw.w;
87 if (e->xconfigure.height == 65535 || e->xconfigure.height == -1) e->xconfigure.height = xw.h;
88 //if ((short int)e->xconfigure.height < xw.ch) return;
90 if (e->xconfigure.width == xw.w && e->xconfigure.height == xw.h) return;
91 xw.w = e->xconfigure.width;
92 xw.h = e->xconfigure.height;
93 col = xw.w/xw.cw;
94 row = (xw.h-xw.tabheight)/xw.ch;
95 //fprintf(stderr, "neww=%d; newh=%d; ch=%d; th=%d; col=%d; row=%d; ocol=%d; orow=%d\n", xw.w, xw.h, xw.ch, xw.tabheight, col, row, curterm->col, curterm->row);
96 if (curterm != NULL && col == curterm->col && row == curterm->row) return;
98 for (int f = 0; f < term_count; ++f) {
99 K8Term *t = term_array[f];
100 /*int trs =*/ k8t_tmResize(t, col, row);
102 k8t_ttyResize(t);
103 k8t_tmFullDirty(t);
104 //if (trs && t == curterm) k8t_drawTerm(t, 1);
107 termCreateXPixmap(curterm);
108 XFreePixmap(xw.dpy, xw.pictab);
109 xw.pictab = XCreatePixmap(xw.dpy, xw.win, xw.w, (xw.tabheight > 0 ? xw.tabheight : 1), XDefaultDepth(xw.dpy, xw.scr));
110 updateTabBar = 1;
111 xw.state |= K8T_WIN_REDRAW;
113 //k8t_drawTerm(curterm, 1);