[hackers] [swk] fix screen size on non-tiled window managers || pancake

From: <hg_AT_suckless.org>
Date: Wed, 28 Apr 2010 20:38:27 +0000 (UTC)

changeset: 29:102e189e199b
tag: tip
user: pancake <pancake_AT_nopcode.org>
date: Wed Apr 28 22:32:03 2010 +0200
files: gi_sdl.c swk.c test.c
description:
fix screen size on non-tiled window managers
fit initial resize on tiled window managers
lock surface on flipping
support more than one scrolling area
display scroll index on scrolling separators

diff -r 940979cb2a7f -r 102e189e199b gi_sdl.c
--- a/gi_sdl.c Wed Apr 28 17:55:20 2010 +0200
+++ b/gi_sdl.c Wed Apr 28 22:32:03 2010 +0200
@@ -70,6 +70,9 @@
                 fprintf(stderr, "Cannot initialize TTF: %s\n", TTF_GetError());
                 return 0;
         }
+ SDL_VideoInit(NULL, 0);
+ SDL_SetVideoMode(w->r.w, w->r.h, BPP, SDLFLAGS);
+ // double init is necesary to get window size
         SDL_SetVideoMode(w->r.w, w->r.h, BPP, SDLFLAGS);
         SDL_WM_SetCaption(w->title, NULL);
         screen = SDL_GetVideoSurface();
@@ -200,7 +203,9 @@
 
 void
 swk_gi_flip() {
+ SDL_LockSurface(screen);
         SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);
+ SDL_UnlockSurface(screen);
 }
 
 /* -- drawing primitives -- */
diff -r 940979cb2a7f -r 102e189e199b swk.c
--- a/swk.c Wed Apr 28 17:55:20 2010 +0200
+++ b/swk.c Wed Apr 28 22:32:03 2010 +0200
@@ -23,7 +23,9 @@
 
 void
 swk_update(SwkWindow *w) {
+ char text[8];
         int roy, oy;
+ int scroll = 0;
         w->_e.type = EExpose;
         if(swk_gi_update(w)) {
                 SwkBox *b = w->boxes;
@@ -34,8 +36,18 @@
                         w->_e.box = b;
                         if(b->r.w==-1 && b->r.h==-1 && ((int)(size_t)b->data)<0)
                                 roy = oy+1;
- if(roy && b->r.y < roy)
- swk_gi_line(0, roy, w->r.w, 0, ColorHI);
+ if (b->scroll)
+ scroll = b->scroll;
+ if(roy && b->r.y < roy) {
+ sprintf(text, "(%d)", scroll);
+ Rect r = w->r;
+ r.x = r.w-1;
+ r.y = roy;
+ r.w = 3;
+ swk_gi_text(r, text);
+ r.x--;
+ swk_gi_line(r.x, roy, r.w, 0, ColorHI);
+ }
                         else b->cb(&w->_e);
                         oy = b->r.y;
                 }
@@ -72,10 +84,14 @@
 
 static SwkBox *
 getscrollbox(SwkWindow *w) {
+ SwkBox *r = NULL;
         SwkBox *b = w->boxes;
- for(; b->cb; b++)
+ for(; b->cb; b++) {
                 if(b->r.w==-1 && b->r.h==-1 && ((int)(size_t)b->data)<0)
- return b;
+ r = b;
+ if(w->box==b)
+ return r?r:w->boxes;
+ }
         return w->boxes;
 }
 
@@ -272,6 +288,7 @@
         switch(e->type) {
         case EExpose:
                 r = e->box->r;
+ r.w+=6;
                 swk_gi_text(r, e->box->text);
                 if(e->win->box == e->box)
                         swk_gi_line(r.x, r.y+1, r.w, 0, ColorHI);
diff -r 940979cb2a7f -r 102e189e199b test.c
--- a/test.c Wed Apr 28 17:55:20 2010 +0200
+++ b/test.c Wed Apr 28 22:32:03 2010 +0200
@@ -27,19 +27,20 @@
 
 static void myprogressbutton(SwkEvent *e) {
         if(e->type == EClick) {
- pccount+=15;
+ pccount+=6;
                 if(pccount > 100) {
                         pccount = 0;
                         e->win->boxes = helloworld;
                         swk_update(e->win);
                 }
                 sprintf(pctext, "%d%%", pccount);
- about[10].text = pctext;
+ about[11].text = pctext;
         }
         swk_button(e);
 }
 
 static SwkBox about[] = {
+ SWK_BOX_NEWLINE(-1),
         { .cb=swk_label, .text="About this program...", },
         SWK_BOX_NEWLINE(1),
         { .cb=swk_separator },
Received on Wed Apr 28 2010 - 20:38:27 UTC

This archive was generated by hypermail 2.2.0 : Wed Apr 28 2010 - 20:48:04 UTC