[hackers] [libdraw] changed drawrect + commitdraw || Connor Lane Smith

From: <hg_AT_suckless.org>
Date: Wed, 11 Aug 2010 13:24:09 +0000 (UTC)

changeset: 14:dda4630df932
tag: tip
user: Connor Lane Smith <cls_AT_lubutu.com>
date: Wed Aug 11 14:24:03 2010 +0100
files: commitdraw.c draw.h drawrect.c drawtext.c freedraw.c initdraw.c initfont.c setcanvas.c
description:
changed drawrect + commitdraw

diff -r 92c1aa044916 -r dda4630df932 commitdraw.c
--- a/commitdraw.c Tue Aug 10 20:31:26 2010 +0100
+++ b/commitdraw.c Wed Aug 11 14:24:03 2010 +0100
@@ -3,11 +3,6 @@
 #include "draw.h"
 
 void
-commitdraw(DC *dc, Window win)
-{
- XWindowAttributes wa;
-
- if(!XGetWindowAttributes(dc->dpy, win, &wa))
- eprintf("cannot get window attributes\n");
- XCopyArea(dc->dpy, dc->canvas, win, dc->gc, 0, 0, wa.width, wa.height, 0, 0);
+commitdraw(DC *dc, Window win, unsigned int w, unsigned int h) {
+ XCopyArea(dc->dpy, dc->canvas, win, dc->gc, 0, 0, w, h, 0, 0);
 }
diff -r 92c1aa044916 -r dda4630df932 draw.h
--- a/draw.h Tue Aug 10 20:31:26 2010 +0100
+++ b/draw.h Wed Aug 11 14:24:03 2010 +0100
@@ -7,10 +7,8 @@
 #define FG(dc, col) ((col)[(dc)->invert ? ColBG : ColFG])
 #define BG(dc, col) ((col)[(dc)->invert ? ColFG : ColBG])
 
-/* enums */
-enum { ColBorder, ColFG, ColBG, ColLast };
+enum { ColBG, ColFG, ColBorder, ColLast };
 
-/* typedefs */
 typedef struct {
         int x, y;
         unsigned int w, h;
@@ -19,17 +17,16 @@
         GC gc;
         Pixmap canvas;
         struct {
- XFontStruct *xfont;
- XFontSet set;
                 int ascent;
                 int descent;
                 int height;
+ XFontSet set;
+ XFontStruct *xfont;
         } font;
 } DC; /* draw context */
 
-/* forward declarations */
-void commitdraw(DC *dc, Window win);
-void drawrect(DC *dc, int x, int y, unsigned int w, unsigned int h, unsigned long color);
+void commitdraw(DC *dc, Window win, unsigned int w, unsigned int h);
+void drawrect(DC *dc, int x, int y, unsigned int w, unsigned int h, Bool fill, unsigned long color);
 void drawtext(DC *dc, const char *text, unsigned long col[ColLast]);
 void drawtextn(DC *dc, const char *text, size_t n, unsigned long col[ColLast]);
 void eprintf(const char *fmt, ...);
@@ -42,7 +39,6 @@
 int textw(DC *dc, const char *text);
 void weprintf(const char *fmt, ...);
 
-/* variables */
 extern const char *progname;
 
 #endif
diff -r 92c1aa044916 -r dda4630df932 drawrect.c
--- a/drawrect.c Tue Aug 10 20:31:26 2010 +0100
+++ b/drawrect.c Wed Aug 11 14:24:03 2010 +0100
@@ -3,10 +3,12 @@
 #include "draw.h"
 
 void
-drawrect(DC *dc, int x, int y, unsigned int w, unsigned int h, unsigned long color)
-{
- XRectangle r = { dc->x + x, dc->y + y, w, h };
+drawrect(DC *dc, int x, int y, unsigned int w, unsigned int h, Bool fill, unsigned long color) {
+ XRectangle r = { dc->x + x, dc->y + y, w - (fill ? 0 : 1), h - (fill ? 0 : 1) };
 
         XSetForeground(dc->dpy, dc->gc, color);
- XFillRectangles(dc->dpy, dc->canvas, dc->gc, &r, 1);
+ if(fill)
+ XFillRectangles(dc->dpy, dc->canvas, dc->gc, &r, 1);
+ else
+ XDrawRectangles(dc->dpy, dc->canvas, dc->gc, &r, 1);
 }
diff -r 92c1aa044916 -r dda4630df932 drawtext.c
--- a/drawtext.c Tue Aug 10 20:31:26 2010 +0100
+++ b/drawtext.c Wed Aug 11 14:24:03 2010 +0100
@@ -19,6 +19,6 @@
         if(mn < n)
                 for(n = MAX(mn-3, 0); n < mn; buf[n++] = '.');
 
- drawrect(dc, 0, 0, dc->w, dc->h, BG(dc, col));
+ drawrect(dc, 0, 0, dc->w, dc->h, True, BG(dc, col));
         drawtextn(dc, buf, mn, col);
 }
diff -r 92c1aa044916 -r dda4630df932 freedraw.c
--- a/freedraw.c Tue Aug 10 20:31:26 2010 +0100
+++ b/freedraw.c Wed Aug 11 14:24:03 2010 +0100
@@ -7,9 +7,10 @@
 freedraw(DC *dc) {
         if(dc->font.set)
                 XFreeFontSet(dc->dpy, dc->font.set);
- else
+ if(dc->font.xfont)
                 XFreeFont(dc->dpy, dc->font.xfont);
- XFreePixmap(dc->dpy, dc->canvas);
+ if(dc->canvas)
+ XFreePixmap(dc->dpy, dc->canvas);
         XFreeGC(dc->dpy, dc->gc);
         XCloseDisplay(dc->dpy);
         free(dc);
diff -r 92c1aa044916 -r dda4630df932 initdraw.c
--- a/initdraw.c Tue Aug 10 20:31:26 2010 +0100
+++ b/initdraw.c Wed Aug 11 14:24:03 2010 +0100
@@ -14,5 +14,11 @@
                 eprintf("cannot malloc %u bytes\n", sizeof *dc);
         if(!(dc->dpy = XOpenDisplay(NULL)))
                 eprintf("cannot open display\n");
+
+ dc->gc = XCreateGC(dc->dpy, DefaultRootWindow(dc->dpy), 0, NULL);
+ XSetLineAttributes(dc->dpy, dc->gc, 1, LineSolid, CapButt, JoinMiter);
+ dc->font.xfont = NULL;
+ dc->font.set = NULL;
+ dc->canvas = 0;
         return dc;
 }
diff -r 92c1aa044916 -r dda4630df932 initfont.c
--- a/initfont.c Tue Aug 10 20:31:26 2010 +0100
+++ b/initfont.c Wed Aug 11 14:24:03 2010 +0100
@@ -36,14 +36,10 @@
                 }
                 if(missing)
                         XFreeStringList(missing);
- return dc->font.set != NULL;
         }
- else {
- dc->font.set = NULL;
- if((dc->font.xfont = XLoadQueryFont(dc->dpy, fontstr))) {
- dc->font.ascent = dc->font.xfont->ascent;
- dc->font.descent = dc->font.xfont->descent;
- }
- return dc->font.xfont != NULL;
+ else if((dc->font.xfont = XLoadQueryFont(dc->dpy, fontstr))) {
+ dc->font.ascent = dc->font.xfont->ascent;
+ dc->font.descent = dc->font.xfont->descent;
         }
+ return (dc->font.set != NULL || dc->font.xfont != NULL);
 }
diff -r 92c1aa044916 -r dda4630df932 setcanvas.c
--- a/setcanvas.c Tue Aug 10 20:31:26 2010 +0100
+++ b/setcanvas.c Wed Aug 11 14:24:03 2010 +0100
@@ -4,11 +4,10 @@
 
 void
 setcanvas(DC *dc, unsigned int w, unsigned int h) {
+ if(dc->canvas)
+ XFreePixmap(dc->dpy, dc->canvas);
         dc->canvas = XCreatePixmap(dc->dpy, DefaultRootWindow(dc->dpy), w, h,
                                    DefaultDepth(dc->dpy, DefaultScreen(dc->dpy)));
- dc->gc = XCreateGC(dc->dpy, DefaultRootWindow(dc->dpy), 0, NULL);
- XSetLineAttributes(dc->dpy, dc->gc, 1, LineSolid, CapButt, JoinMiter);
-
         dc->x = dc->y = 0;
         dc->w = w;
         dc->h = h;
Received on Wed Aug 11 2010 - 15:24:09 CEST

This archive was generated by hypermail 2.2.0 : Wed Aug 11 2010 - 15:36:04 CEST