On window messages added.

file:d1aea2d5642bd1abedf82769bbc6a7558a032d4b -> file:a1ae6e9ca66fbfde48b997165d15c8fec74a7425
--- a/vdu.c
+++ b/vdu.c
@@ -6,6 +6,7 @@
#include <math.h>
#include "scan.h"
#include "window.h"
+#include "vdu.h"
const unsigned int colors[] = {0xff0000,
0x00ff00,
@@ -99,13 +100,16 @@ void draw_window(wind * w) {
next = next->next;
}
}
- paintdir((Ftree *) w->udata, 0, 0, getwidth(w), getheight(w), 0, -1);
+ vdu_data * vd;
+ vd = (vdu_data *) w->udata;
+ paintdir(vd->ft, 0, 0, getwidth(w), getheight(w), 0, -1);
}
void find_dir(wind * w, int x, int y, unsigned int state, unsigned int code) {
if (code == 1) {
char name[MAXPATH] = "";
unsigned long long size = 0;
+ char * str;
void search(Ftree * ft, int x, int y) {
Ftree * next;
if ((x >= ft->x && x <= ft->x + ft->dx) && (y >= ft->y && y <= ft->y + ft->dy)) {
@@ -119,10 +123,27 @@ void find_dir(wind * w, int x, int y, un
}
}
}
- search((Ftree *) w->udata, x, y);
- char * str;
+ vdu_data * vd;
+ vd = (vdu_data *) w->udata;
+ search(vd->ft, x, y);
str = hread(size);
printf("%s %s\n", str, name);
+
+ if ((vd->saved_screen) && (!saved_area_valid(w, vd->saved_screen))) {
+ free_saved_area(w, vd->saved_screen);
+ vd->saved_screen = 0;
+ }
+ if (!vd->saved_screen) {
+ vd->saved_screen = save_area(w, 0, 0, 0, 0);
+ }
+ color(w, 0x000000);
+ text(w, 3, 21, name);
+ text(w, 3, 36, str);
+ color(w, 0xFFFFFF);
+ text(w, 2, 20, name);
+ text(w, 2, 35, str);
+ copy_to_screen(w);
+
free(str);
}
}
@@ -130,11 +151,17 @@ void find_dir(wind * w, int x, int y, un
void destroy_info(wind * w, int x, int y, unsigned int state, unsigned int code) {
if (code == 1) {
//printf("\n");
+ vdu_data * vd;
+ vd = (vdu_data *) w->udata;
+ if ((vd->saved_screen) && (saved_area_valid(w, vd->saved_screen))) {
+ restore_area(w, vd->saved_screen);
+ copy_to_screen(w);
+ }
}
}
int main (int argc, char ** argv) {
- Ftree * ft;
+ vdu_data * vd;
int tx, ty;
char title[256];
char * path;
@@ -167,9 +194,16 @@ int main (int argc, char ** argv) {
text(w, tx, ty, "Reading...");
copy_to_screen(w);
flush(w);
- ft = mktree(path);
- w->udata = (char *) ft;
+ vd = (vdu_data *) malloc(sizeof(vdu_data));
+ if (!vd) {
+ fprintf(stderr, "Out of memory\n");
+ exit(1);
+ }
+ vd->ft = mktree(path);
+ vd->saved_screen = 0;
+
+ w->udata = (char *) vd;
w->draw = draw_window;
w->buttondown = find_dir;
w->buttonup = destroy_info;
@@ -177,7 +211,8 @@ int main (int argc, char ** argv) {
event_loop(w);
rmwind(w);
- freetree(ft);
+ freetree(vd->ft);
+ free(vd);
return 0;
}
file:893fe7463e218268c2c42c4b0bf696395edc80e3(new)
--- /dev/null
+++ b/vdu.h
@@ -0,0 +1,10 @@
+
+/* vdu.h
+ *
+ * sim 13 Dec 2007
+ */
+
+typedef struct {
+ Ftree * ft;
+ int saved_screen;
+} vdu_data;
file:65ac256ee8329aee6127e62e56dee8a3eeb978b9 -> file:12ccd9acb971c0d8ab47925cb4204c212e2623e4
--- a/window.c
+++ b/window.c
@@ -502,6 +502,7 @@ int save_area(wind * w, int x, int y, in
sa->dy = dy;
sa->valid = True;
sa->id = 1;
+ sa->next = (struct saved_area *) NULL;
sanext = w->saved_areas;
if (!sanext) {
@@ -590,14 +591,16 @@ void free_saved_area(wind * w, int id) {
if (id == sa->id) {
/* this can't be right...*/
struct saved_area * tmp;
- tmp = sanext->next;
+ tmp = sanext;
w->saved_areas = sanext;
sanext = sa;
sanext->next = tmp;
}
do {
if (id == sanext->id) {
- XFreePixmap(w->dsp, sanext->pix);
+ if (sanext->valid) {
+ XFreePixmap(w->dsp, sanext->pix);
+ }
sa->next = sanext->next;
free(sanext);
}
@@ -607,4 +610,3 @@ void free_saved_area(wind * w, int id) {
}
-