[hackers] [swk] fix event issue on some xorg versions || pancake<nopcode.org>

From: <hg_AT_suckless.org>
Date: Tue, 24 Aug 2010 16:38:46 +0000 (UTC)

changeset: 62:7789f576b969
tag: tip
user: pancake<nopcode.org>
date: Tue Aug 24 18:34:44 2010 +0200
files: gi_x11.c swk.c
description:
fix event issue on some xorg versions
various simplifications in the x11 backend
use the libdraw's pixmap
add left spacing in button and bigbutton widgets

diff -r 4b50cb2a25d7 -r 7789f576b969 gi_x11.c
--- a/gi_x11.c Sun Aug 22 08:06:19 2010 +0200
+++ b/gi_x11.c Tue Aug 24 18:34:44 2010 +0200
@@ -18,7 +18,7 @@
 
 static int fs = FONTSIZE; // TODO: we need fsW and fsH
 static Window window;
-static int first = 1;
+static XWindowAttributes wa;
 static DC *dc = NULL;
 static int col[ColorLast];
 static int colors[ColorLast] = { FGCOLOR, BGCOLOR, HICOLOR, TFCOLOR };
@@ -32,13 +32,10 @@
 }
 
 static Window dc_window(DC *dc, int x, int y, int w, int h) {
- Drawable drawable;
         Window window;
         int screen = DefaultScreen(dc->dpy);
         window = XCreateSimpleWindow(dc->dpy, RootWindow(dc->dpy, screen),
                 x, y, w, h, 1, col[ColorBG], col[ColorFG]);
- drawable = XCreatePixmap(dc->dpy, window, w, h,
- DefaultDepth(dc->dpy, screen));
         XSelectInput(dc->dpy, window, EVENTMASK);
         XMapWindow(dc->dpy, window);
         return window;
@@ -46,19 +43,17 @@
 
 int
 swk_gi_init(SwkWindow *w) {
+ char buf[128];
         int i;
- char buf[128];
- if(first) {
- first = 0;
- dc = dc_init();
- for(i=0;i<ColorLast;i++) {
- sprintf(buf, "#%06x", colors[i]);
- col[i] = dc_color(dc, buf);
- }
- dc_font(dc, FONTNAME);
- // TODO: must be dc_window(dc, x, y, w, h, bg, fg)
- window = dc_window(dc, 10, 10, w->r.w, w->r.h);
+ if (dc) return 0;
+ dc = dc_init();
+ for(i=0;i<ColorLast;i++) {
+ sprintf(buf, "#%06x", colors[i]);
+ col[i] = dc_color(dc, buf);
         }
+ dc_font(dc, FONTNAME);
+ // TODO: must be dc_window(dc, x, y, w, h, bg, fg)
+ window = dc_window(dc, 10, 10, w->r.w, w->r.h);
         return swk_gi_fontsize(0);
 }
 
@@ -74,6 +69,7 @@
 void
 swk_gi_exit() {
         dc_free(dc);
+ dc = NULL;
 }
 
 SwkEvent *
@@ -84,7 +80,7 @@
         XEvent event;
         SwkEvent *ret = &w->_e;
 
- if(!XCheckMaskEvent(dc->dpy, -1, &event))
+ if(!XCheckMaskEvent(dc->dpy, 0xffff, &event))
                 return NULL;
         switch(event.type) {
         case Expose:
@@ -189,25 +185,18 @@
         return ret;
 }
 
-void
 swk_gi_clear() {
- Rect r ={0};
- XWindowAttributes wa;
+ Rect r = {0};
         XGetWindowAttributes(dc->dpy, window, &wa);
         dc_resize(dc, wa.width, wa.height);
- r.w=wa.width;
- r.h=wa.height;
+ r.w = wa.width; // TODO: propagate those values into SwkWindow?
+ r.h = wa.height;
         swk_gi_fill(r, ColorBG, 0);
 }
 
 void
 swk_gi_flip() {
-#if 0
- XWindowAttributes wa;
- XGetWindowAttributes(dc->dpy, window, &wa);
- XCopyArea(dc->dpy, drawable, window, gc, 0, 0, wa.width, wa.height, 0, 0);
- XFlush(dc->dpy);
-#endif
+ dc_map(dc, window, wa.width, wa.height);
 }
 
 /* -- drawing primitives -- */
@@ -223,16 +212,16 @@
 swk_gi_fill(Rect r, int color, int lil) {
         XRectangle area = { r.x*fs, r.y*fs, r.w*fs, r.h*fs };
         if(lil) {
- const int s = fs/4;
+ int s = fs/4;
                 area.x += s;
                 area.y += s;
                 area.width -= (s*2);
                 area.height -= (s*2);
         }
- if(!area.width) area.width = 1;
- if(!area.height) area.height = 1;
+ if(area.width<1) area.width = 1;
+ if(area.height<1) area.height = 1;
         XSetForeground(dc->dpy, dc->gc, col[color]);
- XFillRectangles(dc->dpy, window, dc->gc, &area, 1);
+ XFillRectangles(dc->dpy, dc->canvas, dc->gc, &area, 1);
 }
 
 void
@@ -248,7 +237,7 @@
         if(!text||!*text)
                 return;
         XSetForeground(dc->dpy, dc->gc, col[ColorFG]);
- XDrawString(dc->dpy, window, dc->gc, r.x*fs, ((1+r.y)*fs)-3, text, strlen (text));
+ XDrawString(dc->dpy, dc->canvas, dc->gc, 5+r.x*fs, ((1+r.y)*fs)-3, text, strlen (text));
 }
 
 void
diff -r 4b50cb2a25d7 -r 7789f576b969 swk.c
--- a/swk.c Sun Aug 22 08:06:19 2010 +0200
+++ b/swk.c Tue Aug 24 18:34:44 2010 +0200
@@ -393,7 +393,8 @@
                 break;
         case EExpose:
                 // XXX: add support for cursor (handle arrow keys)
- len = e->box->r.x+(strlen(e->box->text)*0.7);
+ len = strlen(e->box->text);
+ len += e->box->r.x;
                 swk_label(e);
                 swk_gi_line(len, e->box->r.y, 0, 1, ColorFG);
                 break;
@@ -409,6 +410,7 @@
                 r.x++;
                 swk_gi_text(r, e->box->text);
                 r.x--;
+ r.w--;
                 if(e->win->box == e->box)
                         swk_gi_rect(r, ColorHI);
                 else swk_gi_rect(r, ColorFG);
@@ -425,11 +427,12 @@
         case EExpose:
                 e->box->r.h = 3;
                 r = e->box->r;
- r.x += 2;
+ r.x += 3;
                 r.y += 1;
                 swk_gi_text(r, e->box->text);
                 r.y -= 1;
- r.x -= 2;
+ r.x -= 1;
+ r.w--;
                 if(e->win->box == e->box)
                         swk_gi_rect(r, ColorHI);
                 else swk_gi_rect(r, ColorFG);
Received on Tue Aug 24 2010 - 18:38:46 CEST

This archive was generated by hypermail 2.2.0 : Tue Aug 24 2010 - 18:48:04 CEST