[hackers] [swk] add some more notes in TODO file || pancake

From: <hg_AT_suckless.org>
Date: Wed, 9 Jun 2010 21:48:48 +0000 (UTC)

changeset: 46:25ae5b02f00c
tag: tip
user: pancake <pancake_AT_nopcode.org>
date: Wed Jun 09 23:43:08 2010 +0200
files: TODO gi_sdl.c swk.c swk.h t/tlock.c
description:
add some more notes in TODO file
define FONTFACTOR in gi_sdl and fix text width wrap
add IS_SCROLLBOX macro
some indent fixes and simplify some code

diff -r a79818ebdde3 -r 25ae5b02f00c TODO
--- a/TODO Wed Jun 09 23:03:19 2010 +0200
+++ b/TODO Wed Jun 09 23:43:08 2010 +0200
@@ -1,5 +1,7 @@
 TODO
 ====
+ * allow to set absolute font size
+ * buttons must be 3 line height
   * receive fine-grained x,y in Point? for sketch or imaging stuff is important
   * support for clipboard (implemented in gi_ backend)
   * simple way to define callback for buttons instead of reimplementing widget (?)
diff -r a79818ebdde3 -r 25ae5b02f00c gi_sdl.c
--- a/gi_sdl.c Wed Jun 09 23:03:19 2010 +0200
+++ b/gi_sdl.c Wed Jun 09 23:43:08 2010 +0200
@@ -8,6 +8,7 @@
 #include "config.h"
 
 #define FONTNAME "Inconsolata.otf"
+#define FONTFACTOR 2.1
 #define BPP 32
 #define SDLFLAGS SDL_DOUBLEBUF|SDL_RESIZABLE
 
@@ -31,7 +32,8 @@
         return p;
 }
 
-static void putpixel(SDL_Surface *scr, int x, int y, Uint32 pixel) {
+static void
+putpixel(SDL_Surface *scr, int x, int y, Uint32 pixel) {
         Uint8 *p = getscrpoint(scr, x, y);
         if(!p) return;
 #if BPP == 8
@@ -189,21 +191,19 @@
                         ret->data.key.modmask |= Meta;
                 if(ret->data.key.keycode != 0 && event.key.keysym.unicode != 0) {
                         ret->data.key.keycode = event.key.keysym.unicode;
- } else {
- // TODO key aliases defined in config.h
- switch((int)event.key.keysym.sym) {
- case 1073741906: // n900 up key
- case 273:
- ret->data.key.keycode = KUp;
- break;
- case 1073741912: // n900 down key
- case 274:
- ret->data.key.keycode = KDown;
- break;
- default:
- ret->data.key.keycode = event.key.keysym.sym;
- break;
- }
+ } else // TODO key aliases defined in config.h
+ switch((int)event.key.keysym.sym) {
+ case 1073741906: // n900 up key
+ case 273:
+ ret->data.key.keycode = KUp;
+ break;
+ case 1073741912: // n900 down key
+ case 274:
+ ret->data.key.keycode = KDown;
+ break;
+ default:
+ ret->data.key.keycode = event.key.keysym.sym;
+ break;
                 }
                 fprintf(stderr, "event: key %d %d\n",
                         ret->data.key.modmask, ret->data.key.keycode);
@@ -264,13 +264,13 @@
 void
 swk_gi_text(Rect r, const char *text) {
         char *ptr = NULL;
- int w = (int)((double)r.w * 1.6); // hacky
+ int w = (int)((double)r.w * FONTFACTOR);
         if(text && *text) {
                 int len = text?strlen(text):0;
                 if(len>w) {
                         ptr = strdup(text);
                         text = (const char *)ptr;
- ptr[w] = '\0';
+ ptr[w]='\0';
                 }
                 SDL_Surface *ts = TTF_RenderText_Shaded(font, text, fontcolor, bgcolor);
                 if(ts) {
diff -r a79818ebdde3 -r 25ae5b02f00c swk.c
--- a/swk.c Wed Jun 09 23:03:19 2010 +0200
+++ b/swk.c Wed Jun 09 23:43:08 2010 +0200
@@ -93,7 +93,7 @@
         SwkBox *r = NULL;
         SwkBox *b = w->boxes;
         for(; b->cb; b++) {
- if(b->r.w==-1 && b->r.h==-1 && ((int)(size_t)b->data)<0)
+ if(IS_SCROLLBOX(b))
                         r = b;
                 if(w->box==b && r)
                         break;
@@ -131,13 +131,11 @@
 
 static int
 countrows(SwkBox *b) {
- int row = 0;
- for(; b->cb; b++) {
- if(b->r.w==-1&&b->r.h==-1)
- if((int)(size_t)b->data>0)
- row += (int)(size_t)b->data;
- }
- return row+7; // hacky
+ int row = 7; // hacky value to center widgets
+ for(; b->cb; b++)
+ if(IS_SCROLLBOX(b))
+ row += (int)(size_t)b->data;
+ return row;
 }
 
 void
@@ -361,7 +359,7 @@
                 break;
         case EExpose:
                 // XXX: add support for cursor (handle arrow keys)
- len = e->box->r.x+(strlen(e->box->text)*0.6);
+ len = e->box->r.x+(strlen(e->box->text)*0.7);
                 swk_label(e);
                 swk_gi_line(len, e->box->r.y, 0, 1, ColorFG);
                 break;
@@ -374,6 +372,7 @@
         switch(e->type) {
         case EExpose:
                 r = e->box->r;
+ //r.h = 3; // TODO: add support for multiple-line widgets
                 r.x++;
                 swk_gi_text(r, e->box->text);
                 r.x--;
diff -r a79818ebdde3 -r 25ae5b02f00c swk.h
--- a/swk.h Wed Jun 09 23:03:19 2010 +0200
+++ b/swk.h Wed Jun 09 23:43:08 2010 +0200
@@ -1,5 +1,6 @@
 /* See LICENSE file for copyright and license details. */
 
+#define IS_SCROLLBOX(b) (b->r.w==-1 && b->r.h==-1 && ((int)(size_t)b->data)<0)
 #define SWK_BOX_NEWLINE(x) { .data=(void*)(size_t)x, .r.w=-1, .r.h=-1, .cb = swk_filler }
 #define SWK_BOX_VFILL(x) { .data=(void*)(size_t)x, .r.w=-1, .r.h=-2, .cb = swk_filler }
 #define SWK_HIT(r,p) (p.x>=r.x && p.x<(r.x+r.w) && p.y>=r.y && p.y<(r.y+r.h))
diff -r a79818ebdde3 -r 25ae5b02f00c t/tlock.c
--- a/t/tlock.c Wed Jun 09 23:03:19 2010 +0200
+++ b/t/tlock.c Wed Jun 09 23:43:08 2010 +0200
@@ -8,16 +8,15 @@
 // TODO: enable alarm when dpms on
 
 static SwkBox contents[];
-#define COUNT 0
-static int count = COUNT;
+static int count = 0;
+static char timestring[80];
 
-static char timestring[80];
 static void settimestring() {
         struct tm lt;
         time_t t = time(0);
         localtime_r(&t, &lt);
         snprintf(timestring, sizeof(timestring),
- "%04d/%02d/%02d %02d:%02d:%02d",
+ " %04d/%02d/%02d %02d:%02d:%02d",
                 1900+lt.tm_year, lt.tm_mon+1, lt.tm_mday,
                 lt.tm_hour, lt.tm_min, lt.tm_sec);
 }
@@ -25,10 +24,8 @@
 static void timepoll() {
         settimestring();
         swk_update();
- if(count--<0) {
- contents[2].scroll = 0;
- count = COUNT;
- }
+ if(count--<0)
+ count = contents[2].scroll = 0;
         alarm(1);
 }
 
@@ -69,6 +66,7 @@
         if(!swk_use(&w))
                 return 1;
         init_alarm();
+ swk_fontsize_increase();
         swk_loop();
         return 0;
 }
Received on Wed Jun 09 2010 - 21:48:48 UTC

This archive was generated by hypermail 2.2.0 : Wed Jun 09 2010 - 22:00:07 UTC