fixed some warnings
[k8sterm.git] / src / x11evtvis.c
blob8f95c3a0eee8cbf780c9451d93c14a52f4ddb5d1
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 if (!updateTabBar) updateTabBar = -1;
8 xdrawTabBar();
9 k8t_tmFullDirty(curterm);
10 k8t_drawTerm(curterm, 1);
11 k8t_drawCopy(curterm, 0, 0, curterm->col, curterm->row);
12 //if (!updateTabBar) updateTabBar = -1;
14 xclearunused();
15 } else if (curterm != NULL) {
16 int taby = (opt_tabposition==1 ? 0 : xw.h-xw.tabheight);
17 int termy = (opt_tabposition==1 ? xw.tabheight : 0);
18 int x0 = e->x/xw.cw, y0 = (e->y-termy)/xw.ch;
19 int x1 = (e->x+e->width+xw.cw-1)/xw.cw, y1 = (e->y-termy+e->height+xw.ch-1)/xw.ch;
21 //fprintf(stderr, "x=%d; y=%d; w=%d; h=%d\n", e->x, e->y, e->width, e->height);
22 //fprintf(stderr, "taby=%d; tabh=%d\n", taby, xw.tabheight);
23 //fprintf(stderr, "x0=%d; y0=%d; x1=%d; y1=%d\n", x0, y0, x1, y1);
25 if (e->y <= taby+xw.tabheight && e->y+e->height >= taby) {
26 //fprintf(stderr, "tabbar!\n");
27 if (!updateTabBar) updateTabBar = -1;
29 //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)));
30 //k8t_drawCopy(curterm, 0, 0, curterm->col, curterm->row);
31 //k8t_drawClear(curterm, x0, y0, x1-x0+1, y1-y0+1);
32 K8T_LIMIT(x0, 0, curterm->col-1);
33 K8T_LIMIT(x1, 0, curterm->col-1);
34 K8T_LIMIT(y0, 0, curterm->row-1);
35 K8T_LIMIT(y1, 0, curterm->row-1);
36 //fprintf(stderr, "*:x0=%d; y0=%d; x1=%d; y1=%d\n", x0, y0, x1, y1);
37 k8t_drawCopy(curterm, x0, y0, x1-x0+1, y1-y0+1);
38 //xclearunused(); //FIXME: optimize this
39 } else {
40 if (!updateTabBar) updateTabBar = -1;
42 xdrawTabBar();
43 //XFlush(xw.dpy);
47 static void xevtcbvisibility (XEvent *ev) {
48 XVisibilityEvent *e = &ev->xvisibility;
50 if (e->state == VisibilityFullyObscured) xw.state &= ~K8T_WIN_VISIBLE;
51 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 */
55 static void xevtcbunmap (XEvent *ev) {
56 (void)ev;
57 xw.state &= ~K8T_WIN_VISIBLE;
61 static void xseturgency (int add) {
62 XWMHints *h = XGetWMHints(xw.dpy, xw.win);
64 h->flags = add ? (h->flags|XUrgencyHint) : (h->flags&~XUrgencyHint);
65 XSetWMHints(xw.dpy, xw.win, h);
66 XFree(h);
70 static void xevtcbfocus (XEvent *ev) {
71 if (ev->type == FocusIn) {
72 xw.state |= K8T_WIN_FOCUSED;
73 xseturgency(0);
74 k8t_tmSendFocusEvent(curterm, 1);
75 } else {
76 xw.state &= ~K8T_WIN_FOCUSED;
77 k8t_tmSendFocusEvent(curterm, 0);
79 //k8t_drawTerm(curterm, 1);
81 if (!updateTabBar) updateTabBar = -1;
82 xdrawTabBar();
84 k8t_drawCursor(curterm, 1);
85 //k8t_tmWantRedraw(curterm, 0);
86 //k8t_drawCopy(curterm, 0, 0, curterm->col, curterm->row);
90 static void xevtcbresise (XEvent *e) {
91 int col, row;
93 //if (e->xconfigure.width == 65535 || e->xconfigure.width == -1) e->xconfigure.width = xw.w;
94 if (e->xconfigure.height == 65535 || e->xconfigure.height == -1) e->xconfigure.height = xw.h;
95 //if ((short int)e->xconfigure.height < xw.ch) return;
97 if (e->xconfigure.width == xw.w && e->xconfigure.height == xw.h) return;
98 xw.w = e->xconfigure.width;
99 xw.h = e->xconfigure.height;
100 col = xw.w/xw.cw;
101 row = (xw.h-xw.tabheight)/xw.ch;
102 //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);
103 if (curterm != NULL && col == curterm->col && row == curterm->row) return;
105 for (int f = 0; f < term_count; ++f) {
106 K8Term *t = term_array[f];
107 /*int trs =*/ k8t_tmResize(t, col, row);
109 k8t_ttyResize(t);
110 k8t_tmFullDirty(t);
111 //if (trs && t == curterm) k8t_drawTerm(t, 1);
114 termCreateXPixmap(curterm);
115 XFreePixmap(xw.dpy, xw.pictab);
116 xw.pictab = XCreatePixmap(xw.dpy, xw.win, xw.w, (xw.tabheight > 0 ? xw.tabheight : 1), XDefaultDepth(xw.dpy, xw.scr));
117 updateTabBar = 1;
118 xw.state |= K8T_WIN_REDRAW;
120 //k8t_drawTerm(curterm, 1);