alot of renaming...
[k8sterm.git] / src / x11evtvis.c
blob93e2eece7095bebd73a5f3751dbc4bc4c9aecc68
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, 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_Draw(curterm, 1);
75 if (!updateTabBar) updateTabBar = -1;
76 xdrawTabBar();
77 k8t_DrawCursor(curterm);
78 //k8t_DrawCopy(curterm, 0, 0, curterm->col, curterm->row);
82 static void xevtcbresise (XEvent *e) {
83 int col, row;
85 //if (e->xconfigure.width == 65535 || e->xconfigure.width == -1) e->xconfigure.width = xw.w;
86 if (e->xconfigure.height == 65535 || e->xconfigure.height == -1) e->xconfigure.height = xw.h;
87 //if ((short int)e->xconfigure.height < xw.ch) return;
89 if (e->xconfigure.width == xw.w && e->xconfigure.height == xw.h) return;
90 xw.w = e->xconfigure.width;
91 xw.h = e->xconfigure.height;
92 col = xw.w/xw.cw;
93 row = (xw.h-xw.tabheight)/xw.ch;
94 //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);
95 if (col == curterm->col && row == curterm->row) return;
96 for (int f = 0; f < term_count; ++f) {
97 K8Term *t = term_array[f];
98 int trs = k8t_tmResize(t, col, row);
100 k8t_ttyResize(t);
101 xresize(t, col, row);
102 if (trs && t == curterm) k8t_Draw(t, 1);
104 XFreePixmap(xw.dpy, xw.pictab);
105 xw.pictab = XCreatePixmap(xw.dpy, xw.win, xw.w, xw.tabheight>0?xw.tabheight:1, XDefaultDepth(xw.dpy, xw.scr));
106 updateTabBar = 1;