From 5785144a718ffb3c3723949322871d51f7837e6d Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Tue, 8 Oct 2013 20:33:08 +0200 Subject: [PATCH] Experiments: First OSD without libxosd Alas, the outlining algorithm (borrowed from libxosd) is very ugly... --- test.c | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/test.c b/test.c index 676a1e5..dc3a3be 100644 --- a/test.c +++ b/test.c @@ -29,7 +29,8 @@ struct osd_state { // Xft stuff XftFont *font; - XftDraw *xft_draw; + XftDraw *mask_draw; + XftDraw *image_draw; }; int @@ -59,7 +60,7 @@ main(int argc, char **argv) osd->screen_height = XDisplayHeight(osd->dpy, osd->screen); XSetWindowAttributes win_attr = { - .override_redirect = 0, // FIXME: 1 + .override_redirect = 1, }; osd->win = XCreateWindow(osd->dpy, XRootWindow(osd->dpy, osd->screen), @@ -85,7 +86,9 @@ main(int argc, char **argv) osd->mask_gc = XCreateGC(osd->dpy, osd->mask_bitmap, GCGraphicsExposures, &gcv); XSetBackground(osd->dpy, osd->gc, BlackPixel(osd->dpy, osd->screen)); - XSetForeground(osd->dpy, osd->gc, BlackPixel(osd->dpy, osd->screen)); + XColor shadow_color = { .red = 0xffff, .green = 0xffff, .blue = 0 }; + XAllocColor(osd->dpy, osd->cmap, &shadow_color); + XSetForeground(osd->dpy, osd->gc, shadow_color.pixel); XSetBackground(osd->dpy, osd->mask_gc, WhitePixel(osd->dpy, osd->screen)); XSetForeground(osd->dpy, osd->mask_gc, BlackPixel(osd->dpy, osd->screen)); @@ -94,12 +97,18 @@ main(int argc, char **argv) XFillRectangle(osd->dpy, osd->image_pixmap, osd->gc, 0, 0, osd->screen_width, osd->screen_height); + XFillRectangle(osd->dpy, osd->mask_bitmap, osd->mask_gc, 0, 0, osd->screen_width, osd->screen_height); + osd->font = XftFontOpenName(osd->dpy, osd->screen, "times-64"); if (!osd->font) die("Cannot open font"); - osd->xft_draw = XftDrawCreate(osd->dpy, osd->image_pixmap, osd->visual, osd->cmap); - if (!osd->xft_draw) + osd->mask_draw = XftDrawCreateBitmap(osd->dpy, osd->mask_bitmap); + if (!osd->mask_draw) + die("Cannot create XftDraw"); + + osd->image_draw = XftDrawCreate(osd->dpy, osd->image_pixmap, osd->visual, osd->cmap); + if (!osd->image_draw) die("Cannot create XftDraw"); XRenderColor xrc = { .red = 0, .green = 0xffff, .blue = 0, .alpha = 0xffff }; @@ -107,14 +116,28 @@ main(int argc, char **argv) if (!XftColorAllocValue(osd->dpy, osd->visual, osd->cmap, &xrc, &xfc)) die("XftColorAllocValue failed"); const unsigned char str[] = "Žluťoučká vlkodlačice"; - XftDrawStringUtf8(osd->xft_draw, &xfc, osd->font, 100, 100, str, strlen((char *) str)); + XftDrawStringUtf8(osd->image_draw, &xfc, osd->font, 100, 100, str, strlen((char *) str)); + + XRenderColor xrcm = { .red = 0xffff, .green = 0xffff, .blue = 0xffff, .alpha = 0xffff }; + XftColor xfcm; + if (!XftColorAllocValue(osd->dpy, osd->visual, osd->cmap, &xrcm, &xfcm)) + die("XftColorAllocValue failed"); + + // FIXME: This is very ugly! + XftDrawStringUtf8(osd->mask_draw, &xfcm, osd->font, 100, 100, str, strlen((char *) str)); + for (int off=1; off<=2; off++) + for (int dir=0; dir<9; dir++) + if (dir != 4) + XftDrawStringUtf8(osd->mask_draw, &xfcm, osd->font, 100 + (dir/3 - 1) * off, 100 + (dir%3 - 1) * off, str, strlen((char *) str)); +#if 0 XGlyphInfo gi; XftTextExtentsUtf8(osd->dpy, osd->font, str, strlen((char *) str), &gi); DBG("Glyph info: (%d,%d)+(%d,%d) off (%d,%d)\n", gi.x, gi.y, gi.width, gi.height, gi.xOff, gi.yOff); - XftDrawRect(osd->xft_draw, &xfc, 100 + gi.x, 100 - gi.y, gi.width, gi.height); + XftDrawRect(osd->image_draw, &xfc, 100 + gi.x, 100 - gi.y, gi.width, gi.height); +#endif - XftDrawRect(osd->xft_draw, &xfc, 30, 30, 50, 50); + XShapeCombineMask(osd->dpy, osd->win, ShapeBounding, 0, 0, osd->mask_bitmap, ShapeSet); XSelectInput(osd->dpy, osd->win, ExposureMask); XMapRaised(osd->dpy, osd->win); -- 2.39.2