experimental hackfix for non-existing problem ;-)
[k8sterm.git] / src / x11CB.c
blob955f7008380ed368a5f2d41346479910f7e2ff11
1 static K8TTimeMSec clockTicksCB (K8Term *term) {
2 return mclock_ticks();
6 static void setLastDrawTimeCB (K8Term *term, K8TTimeMSec time) {
7 lastDrawTime = time;
11 static int isFocusedCB (K8Term *term) {
12 return (xw.state&K8T_WIN_FOCUSED ? 1 : 0);
16 static int isVisibleCB (K8Term *term) {
17 return (xw.state&K8T_WIN_VISIBLE ? 1 : 0);
21 static void drawSetFGCB (K8Term *term, int clr) {
22 XSetForeground(xw.dpy, dc.gc, getColor(clr));
26 static void drawSetBGCB (K8Term *term, int clr) {
27 XSetBackground(xw.dpy, dc.gc, getColor(clr));
31 static void drawRectCB (K8Term *term, int x0, int y0, int cols, int rows) {
32 if (cols > 0 && rows > 0) {
33 XDrawRectangle(xw.dpy, K8T_DATA(term)->picbuf, dc.gc, x0*xw.cw, y0*xw.ch, cols*xw.cw-1, rows*xw.ch-1);
38 static void drawFillRectCB (K8Term *term, int x0, int y0, int cols, int rows) {
39 if (cols > 0 && rows > 0) {
40 XFillRectangle(xw.dpy, K8T_DATA(term)->picbuf, dc.gc, x0*xw.cw, y0*xw.ch, cols*xw.cw-1, rows*xw.ch-1);
45 // copy pixmap to screen
46 static void drawCopyAreaCB (K8Term *term, int x0, int y0, int cols, int rows) {
47 if (cols > 0 && rows > 0) {
48 int src_x = x0*xw.cw, src_y = y0*xw.ch, src_w = cols*xw.cw, src_h = rows*xw.ch;
49 int dst_x = src_x, dst_y = src_y;
51 if (opt_tabposition == 1) { dst_y += xw.tabheight; }
52 XCopyArea(xw.dpy, K8T_DATA(term)->picbuf, xw.win, dc.gc, src_x, src_y, src_w, src_h, dst_x, dst_y);
57 // cols can be used for underlining
58 static void drawStringCB (K8Term *term, int x, int y, int cols, const K8TGlyph *base, int fontset, const char *s, int bytelen) {
59 XFontSet xfontset = dc.font[fontset].set;
60 int winx = x*xw.cw, winy = y*xw.ch+dc.font[fontset].ascent;
62 if (K8T_ISGFX(base->attr)) {
63 XmbDrawImageString(xw.dpy, K8T_DATA(term)->picbuf, xfontset, dc.gc, winx, winy, s, bytelen);
64 } else if (!needConversion) {
65 XmbDrawImageString(xw.dpy, K8T_DATA(term)->picbuf, xfontset, dc.gc, winx, winy, s, bytelen);
66 } else {
67 if (bytelen > 0) {
68 //k8: dunno why, but Xutf8DrawImageString() ignores ascii (at least for terminus)
69 const char *pos = s;
70 int xpos = winx;
72 while (pos < s+bytelen) {
73 const char *e;
74 int clen;
76 if ((unsigned char)(pos[0]) < 128) {
77 for (e = pos+1; e < s+bytelen && (unsigned char)(*e) < 128; ++e) ;
78 clen = e-pos;
79 XmbDrawImageString(xw.dpy, K8T_DATA(term)->picbuf, xfontset, dc.gc, xpos, winy, pos, e-pos);
80 } else {
81 for (clen = 0, e = pos; e < s+bytelen && (unsigned char)(*e) >= 128; ++e) {
82 if (((unsigned char)(e[0])&0xc0) == 0xc0) ++clen;
84 Xutf8DrawImageString(xw.dpy, K8T_DATA(term)->picbuf, xfontset, dc.gc, xpos, winy, pos, e-pos);
86 xpos += xw.cw*clen;
87 pos = e;
92 if (opt_drawunderline && (base->attr&K8T_ATTR_UNDERLINE)) {
93 XDrawLine(xw.dpy, K8T_DATA(term)->picbuf, dc.gc, winx, winy+1, winx+(cols*xw.cw)-1, winy+1);
98 static int drawOverlayCB (K8Term *term, int x0, int x1, int scry, int lineno, int dontcopy) {
99 if (scry == term->row-1 && K8T_DATA(term)->cmdline.cmdMode != K8T_CMDMODE_NONE) {
100 xdrawcmdline(term, &K8T_DATA(term)->cmdline, scry);
101 return 1;
103 return 0;
107 static void fixSelectionCB (K8Term *term) {
108 if (lastSelStr != NULL) free(lastSelStr);
109 lastSelStr = (term->sel.clip != NULL ? strdup(term->sel.clip) : NULL);
111 xfixsel();
115 static void clearSelectionCB (K8Term *term) {
116 if (lastSelStr != NULL) free(lastSelStr);
117 lastSelStr = NULL;
121 static void titleChangedCB (K8Term *term) {
122 if (curterm == term) fixWindowTitle(term);
123 updateTabBar = 1;
127 static void doBellCB (K8Term *term) {
128 if (!(xw.state&K8T_WIN_FOCUSED) && (term->belltype&K8T_BELL_URGENT)) xseturgency(1);
129 if (term->belltype&K8T_BELL_AUDIO) XBell(xw.dpy, 100);
133 // 0: no
134 // 1: fully
135 // -1: partially
136 static int isUnderOverlayCB (K8Term *term, int x, int y, int w) {
137 if (w > 0 && K8T_DATA(term)->cmdline.cmdMode != K8T_CMDMODE_NONE) {
138 int xe = x+w-1;
140 if (xe >= 0 && x < term->col && y < term->row) {
141 if (x < 0) x = 0;
142 if (y < 0) y = 0;
143 if (xe >= term->col) xe = term->col-1;
145 if (xe >= x) {
146 if (y == term->row-1) return 1; // cmdline is active, and we are inside
151 return 0;
155 static void clipToOverlayCB (K8Term *term, int *x0, int y, int *w) {
156 int ovr = term->isUnderOverlay(term, *x0, y, *w);
158 if (ovr < 0) {
159 // partially inside
160 // easy deal for now: do nothing
161 } else if (ovr == 0) {
162 // outside
163 *w = 0;
164 } // else it's fully inside, do nothing