commit 6de57e1202899f185474b4e3506ffeec75ebcd7e
parent 0a5aa6a6a483916cdae1e412a6c9ebd41ef6ee5c
Author: Anselm R. Garbe <garbeam@wmii.de>
Date: Fri, 30 Jun 2006 12:21:26 +0200
implemented cursor setting (selection for 1 character I'm working on), eliminated several compiler warnings which drive me nuts
Diffstat:
8 files changed, 50 insertions(+), 16 deletions(-)
diff --git a/cmd/wm/fs.c b/cmd/wm/fs.c
@@ -262,11 +262,11 @@ message_root(char *message)
else if(!strncmp(message, "selcolors ", 10)) {
message += 10;
n = strlen(message);
- return parse_colors(&message, &n, &def.selcolor);
+ return parse_colors(&message, (int *)&n, &def.selcolor);
}else if(!strncmp(message, "normcolors ", 11)) {
message += 11;
n = strlen(message);
- return parse_colors(&message, &n, &def.normcolor);
+ return parse_colors(&message, (int *)&n, &def.normcolor);
}else if(!strncmp(message, "font ", 5)) {
message += 5;
free(def.font.fontstr);
@@ -673,7 +673,7 @@ fs_read(P9Req *r) {
r->ofcall.count = n;
return respond(r, nil);
case FsFTindex:
- buf = view_index(f->view);
+ buf = (char *)view_index(f->view);
n = strlen(buf);
write_buf(r, (void *)buf, n);
return respond(r, nil);
diff --git a/cmd/wm/view.c b/cmd/wm/view.c
@@ -309,12 +309,12 @@ view_index(View *v) {
a_i, idx_of_client(f->client),
r->width, f->client->props);
if(len - n < 0)
- return buffer;
+ return (unsigned char *)buffer;
buf_i += n;
len -= n;
}
}
- return buffer;
+ return (unsigned char *)buffer;
}
Client *
diff --git a/cmd/wm/wm.h b/cmd/wm/wm.h
@@ -317,7 +317,7 @@ void attach_to_view(View *v, Frame *f);
Client *sel_client_of_view(View *v);
char *message_view(View *v, char *message);
void restack_view(View *v);
-unsigned char * view_index(View *v);
+unsigned char *view_index(View *v);
void destroy_view(View *v);
void update_views();
unsigned int newcolw_of_view(View *v);
diff --git a/libixp/client.c b/libixp/client.c
@@ -176,7 +176,7 @@ ixp_client_write(IXPClient *c, unsigned int fid,
c->fcall.fid = fid;
c->fcall.offset = offset;
c->fcall.count = count;
- c->fcall.data = data;
+ c->fcall.data = (void *)data;
if(ixp_client_do_fcall(c) == -1)
return -1;
return c->fcall.count;
diff --git a/libixp/message.c b/libixp/message.c
@@ -101,13 +101,13 @@ ixp_fcall2msg(void *msg, Fcall *fcall, unsigned int msglen)
break;
case RREAD:
ixp_pack_u32(&p, &msize, fcall->count);
- ixp_pack_data(&p, &msize, fcall->data, fcall->count);
+ ixp_pack_data(&p, &msize, (unsigned char *)fcall->data, fcall->count);
break;
case TWRITE:
ixp_pack_u32(&p, &msize, fcall->fid);
ixp_pack_u64(&p, &msize, fcall->offset);
ixp_pack_u32(&p, &msize, fcall->count);
- ixp_pack_data(&p, &msize, fcall->data, fcall->count);
+ ixp_pack_data(&p, &msize, (unsigned char *)fcall->data, fcall->count);
break;
case RWRITE:
ixp_pack_u32(&p, &msize, fcall->count);
diff --git a/liblitz/blitz.h b/liblitz/blitz.h
@@ -85,6 +85,8 @@ int blitz_loadcolor(Blitz *blitz, BlitzColor *c);
/* draw.c */
void blitz_drawbg(Display *dpy, Drawable drawable, GC gc,
XRectangle rect, BlitzColor c, Bool border);
+void blitz_drawcursor(Display *dpy, Drawable drawable, GC gc,
+ int x, int y, unsigned int h, BlitzColor c);
/* font.c */
unsigned int blitz_textwidth(BlitzFont *font, char *text);
diff --git a/liblitz/draw.c b/liblitz/draw.c
@@ -3,6 +3,7 @@
* See LICENSE file for license details.
*/
+#include <stdio.h>
#include "blitz.h"
void
@@ -28,3 +29,23 @@ blitz_drawbg(Display *dpy, Drawable drawable, GC gc, XRectangle rect,
points[4].y = -(rect.height - 1);
XDrawLines(dpy, drawable, gc, points, 5, CoordModePrevious);
}
+
+void
+blitz_drawcursor(Display *dpy, Drawable drawable, GC gc,
+ int x, int y, unsigned int h, BlitzColor c)
+{
+ XSegment s[3];
+
+ XSetForeground(dpy, gc, c.fg);
+ XSetLineAttributes(dpy, gc, 1, LineSolid, CapButt, JoinMiter);
+ s[0].x1 = x - 2;
+ s[0].y1 = s[0].y2 = y;
+ s[0].x2 = x + 3;
+ s[1].x1 = s[1].x2 = x;
+ s[1].y1 = y;
+ s[1].y2 = y + h;
+ s[2].x1 = x - 2;
+ s[2].y1 = s[2].y2 = y + h;
+ s[2].x2 = x + 3;
+ XDrawSegments(dpy, drawable, gc, s, 3);
+}
diff --git a/liblitz/input.c b/liblitz/input.c
@@ -58,7 +58,7 @@ xdrawtextpart(BlitzInput *i, char *start, char *end,
void
blitz_draw_input(BlitzInput *i)
{
- unsigned int xoff, yoff;
+ unsigned int xoff, yoff, xcursor, h;
char *start, *end;
if (!i)
@@ -66,9 +66,9 @@ blitz_draw_input(BlitzInput *i)
blitz_drawbg(i->blitz->display, i->drawable, i->gc, i->rect, i->color, True);
- yoff = i->rect.y + (i->rect.height - (i->font->ascent + i->font->descent))
- / 2 + i->font->ascent;
- xoff = i->rect.x + i->rect.height / 2;
+ h = (i->font->ascent + i->font->descent);
+ yoff = i->rect.y + (i->rect.height - h) / 2 + i->font->ascent;
+ xcursor = xoff = i->rect.x + i->rect.height / 2;
start = end = nil;
if(i->curstart && i->curend && i->curstart < i->curend) {
@@ -79,18 +79,24 @@ blitz_draw_input(BlitzInput *i)
start = i->curend;
end = i->curstart;
}
- if(end)
- end++;
/* draw normal text */
xchangegc(i, &i->color, False);
xdrawtextpart(i, i->text, start, &xoff, yoff);
+ xcursor = xoff;
/* draw sel text */
xchangegc(i, &i->color, True);
xdrawtextpart(i, start, end, &xoff, yoff);
/* draw remaining normal text */
xchangegc(i, &i->color, False);
xdrawtextpart(i, end, nil, &xoff, yoff);
+
+ /* draw cursor */
+ if(!start && !end)
+ xcursor = xoff;
+ if(start == end)
+ blitz_drawcursor(i->blitz->display, i->drawable, i->gc,
+ xcursor, yoff - h + 2, h - 1, i->color);
}
Bool
@@ -119,11 +125,16 @@ xcharof(BlitzInput *i, int x, char *start, unsigned int len)
static char *
charof(BlitzInput *i, int x, int y)
{
+ unsigned int len;
+
if(!i->text || !blitz_ispointinrect(x, y, &i->rect))
return nil;
- /* normalize x */
+ len = strlen(i->text);
+ /* normalize and check x */
if((x -= (i->rect.x + i->rect.height / 2)) < 0)
+ return i->text;
+ else if(x > blitz_textwidth_l(i->font, i->text, len))
return nil;
return xcharof(i, x, i->text, strlen(i->text));