PERFORCE change 214097 for review
Brooks Davis
brooks at FreeBSD.org
Sun Jul 8 22:39:38 UTC 2012
http://p4web.freebsd.org/@@214097?ac=10
Change 214097 by brooks at brooks_ecr_current on 2012/07/08 22:39:20
Checkpoint code with the touch screen working. Navigation works as
long as you stay out of large directories. That will be fixed when
I rewrite directory scanning in the near future.
Affected files ...
.. //depot/projects/ctsrd/beribsd/src/ctsrd/browser/browser.c#5 edit
Differences ...
==== //depot/projects/ctsrd/beribsd/src/ctsrd/browser/browser.c#5 (text+ko) ====
@@ -34,6 +34,7 @@
#include <sys/stat.h>
#include <sys/wait.h>
+#include <assert.h>
#include <ctype.h>
#include <de4tc.h>
#include <dirent.h>
@@ -50,18 +51,18 @@
#include <time.h>
#include <unistd.h>
-#define BASEIMG "/usr/share/images/browser.png"
-#define ICONS "/usr/share/images/icons.png"
+#define BASEIMG "/usr/share/images/browser.png"
+#define ICONS "/usr/share/images/icons.png"
-#define vwhite(v) fb_colour((v), (v), (v))
-#define vred(v) fb_colour((v), 0, 0)
-#define vgreen(v) fb_colour(0, (v), 0)
-#define vblue(v) fb_colour(0, 0, (v))
-#define black vwhite(0)
-#define white vwhite(0xFF)
-#define red vred(0xFF)
-#define green vgreen(0xFF)
-#define blue vblue(0xFF)
+#define vwhite(v) fb_colour((v), (v), (v))
+#define vred(v) fb_colour((v), 0, 0)
+#define vgreen(v) fb_colour(0, (v), 0)
+#define vblue(v) fb_colour(0, 0, (v))
+#define black vwhite(0)
+#define white vwhite(0xFF)
+#define red vred(0xFF)
+#define green vgreen(0xFF)
+#define blue vblue(0xFF)
/*
* Each file is displayed in a 266x40 box:
@@ -75,33 +76,41 @@
* +--------------------------------------------------------------------------+
* |----------------------------------(800/3 = 266) pixels--------------------|
*/
-#define FROW 41
-#define NCOL 3
-#define NROW 10
-#define NSLOTS (NCOL * NROW)
-#define CWIDTH 266
-#define RHEIGHT 40
-#define ICON_WH 32
-#define BORDER 4
-#define CHAR_HEIGHT 32
-#define CHAR_WIDTH 16
-#define TEXT_OFFSET (BORDER + ICON_WH + BORDER)
-#define _TEXTSPACE (CWIDTH - (TEXT_OFFSET + BORDER))
-#define TEXTSPACE (_TEXTSPACE - _TEXTSPACE % CHAR_WIDTH)
+#define FROW 41
+#define NCOL 3
+#define NROW 10
+#define NSLOTS (NCOL * NROW)
+#define CWIDTH 266
+#define RHEIGHT 40
+#define ICON_WH 32
+#define BORDER 4
+#define CHAR_HEIGHT 32
+#define CHAR_WIDTH 16
+#define TEXT_OFFSET (BORDER + ICON_WH + BORDER)
+#define _TEXTSPACE (CWIDTH - (TEXT_OFFSET + BORDER))
+#define TEXTSPACE (_TEXTSPACE - _TEXTSPACE % CHAR_WIDTH)
+/*
+ * The get_action() function polls for input and returns a slot number
+ * (either a line on the console or a space on the screen) or one of
+ * these actions. Internally it handles changing protection modes.
+ */
+#define ACT_QUIT 100
+#define ACT_PREV 101
+#define ACT_NEXT 102
/* Beginning and ending colums of each sandbox type's name */
-#define SB_IMG_SPACING 20
-#define SB_IMG_NONE_BCOL 145
-#define SB_IMG_CAPSICUM_BCOL 223
-#define SB_IMG_CHERI_BCOL 350
-#define SB_IMG_NONE_ECOL (SB_IMG_CAPSICUM_BCOL - SB_IMG_SPACING)
-#define SB_IMG_CAPSICUM_ECOL (SB_IMG_CHERI_BCOL - SB_IMG_SPACING)
-#define SB_IMG_CHERI_ECOL 445
-#define SB_MINCOL SB_IMG_NONE_BCOL
-#define SB_MAXCOL SB_IMG_CHERI_ECOL
-#define SB_MINROW (fb_height - 39)
-#define SB_MAXROW (fb_height - 1)
+#define SB_IMG_SPACING 20
+#define SB_IMG_NONE_BCOL 145
+#define SB_IMG_CAPSICUM_BCOL 223
+#define SB_IMG_CHERI_BCOL 350
+#define SB_IMG_NONE_ECOL (SB_IMG_CAPSICUM_BCOL - SB_IMG_SPACING)
+#define SB_IMG_CAPSICUM_ECOL (SB_IMG_CHERI_BCOL - SB_IMG_SPACING)
+#define SB_IMG_CHERI_ECOL 445
+#define SB_MINCOL SB_IMG_NONE_BCOL
+#define SB_MAXCOL SB_IMG_CHERI_ECOL
+#define SB_MINROW (fb_height - 39)
+#define SB_MAXROW (fb_height - 1)
/* Start offsets for browser columns */
const int colstart[] = {0, 267, 534};
@@ -202,6 +211,21 @@
}
}
+static const char *
+get_magic(int fd)
+{
+ switch (sbtype) {
+ case SB_NONE:
+ return magic_descriptor(magic, fd);
+ case SB_CAPSICUM:
+ return "devil";
+ case SB_CHERI:
+ return "devil";
+ default:
+ errx(1, "invalid sandbox type");
+ }
+}
+
static void
update_sandbox(enum _sbtype type)
{
@@ -221,7 +245,7 @@
pixel = (j * fb_width) + i;
if (bgimage[pixel] != black) {
/* XXX: Assuming we're either blue or white */
- value = (bgimage[pixel] >> 8) & 0xFF;
+ value = (bgimage[pixel] >> 24) & 0xFF;
if (value == 0) {
printf("unexpected zero value, pixel %08x\n",
bgimage[pixel]);
@@ -236,21 +260,6 @@
}
static const char *
-get_magic(int fd)
-{
- switch (sbtype) {
- case SB_NONE:
- return magic_descriptor(magic, fd);
- case SB_CAPSICUM:
- return "devil";
- case SB_CHERI:
- return "devil";
- default:
- return "unknown";
- }
-}
-
-static const char *
get_desc(int dfd, struct dirent *entry)
{
int fd, type;
@@ -314,15 +323,116 @@
return (NULL);
}
+static void
+update_slot(int s, u_int32_t *icon, const char *text)
+{
+ u_int32_t textbuf[TEXTSPACE*CHAR_HEIGHT];
+
+ memset(textbuf, 0, sizeof(textbuf));
+ fb_render_text(text, 2, white, black, textbuf,
+ TEXTSPACE, CHAR_HEIGHT);
+ fb_post_region(textbuf, colstart[(s/NROW)] + TEXT_OFFSET,
+ FROW + (RHEIGHT * (s % NROW)) + BORDER, TEXTSPACE,
+ CHAR_HEIGHT);
+ fb_post_region(icon, colstart[(s/NROW)] + BORDER,
+ FROW + (RHEIGHT * (s % NROW)) + BORDER, ICON_WH, ICON_WH);
+}
+
+#ifdef TEXT_INPUT
+static int
+get_action(int next_slot, int prev_slot)
+{
+ int f;
+ char line[256];
+
+prompt:
+ printf("select a file or directory by number :\n");
+ if (fgets(line, sizeof(line), stdin) == NULL) {
+ if (feof(stdin))
+ return (-1);
+ else
+ errx(1, "fgets(): %s", strerror(ferror(stdin)));
+ }
+ printf("line '%s'\n", line);
+ f = 0; /* XXX: gcc warning*/
+ switch (line[0]) {
+ case '\n':
+ case 'n':
+ return (ACT_NEXT);
+ case 'p':
+ return (ACT_PREV);
+ case 'q':
+ return (ACT_QUIT);
+
+ default:
+ if (!isnumber(line[0])) {
+ printf("invalid file %s\n", line);
+ goto prompt;
+ }
+ f = atoi(line);
+ if (f < 0 || f >= NSLOTS - 1) {
+ printf("invalid file %s\n", line);
+ goto prompt;
+ }
+ return (f);
+ }
+}
+
+#else /* TEXT_INPUT */
+
static int
+get_action(int next_slot, int prev_slot)
+{
+ struct tsstate *ts;
+ int action = -1, col, i, row, slot;
+
+ printf("entering get_action\n");
+
+ while(action < 0) {
+ ts = ts_poll();
+ if (ts->ts_gesture == TSG_CLICK) {
+ if (ts->ts_x1 < FROW) {
+ if (ts->ts_x1 > fb_width - 40)
+ return (ACT_QUIT);
+ } else if (ts->ts_y1 <= FROW + (NROW * RHEIGHT)) {
+ row = (ts->ts_y1 - FROW) / RHEIGHT;
+ for (col = NCOL - 1;
+ col > 0 && ts->ts_x1 < colstart[col]; col--)
+ /* do nothing */
+ printf("row %d col %d\n", row, col);
+ slot = col * NROW + row;
+ if (slot == next_slot)
+ return (ACT_NEXT);
+ else if (slot == prev_slot)
+ return (ACT_PREV);
+ else
+ return (slot);
+ } else {
+ printf("in bottom bar, x = %d\n", ts->ts_x1);
+ if (ts->ts_x1 >= SB_MINCOL &&
+ ts->ts_x1 <= SB_MAXCOL) {
+ for (i =0 ; ts->ts_x1 < sbdata[i].bcol ||
+ ts->ts_x1 > sbdata[i].ecol; i++)
+ /* do nothing */
+ assert(sbdata[i].sbtype != 0);
+ update_sandbox(sbdata[i].sbtype);
+ /* XXX: should trigger a rescan? */
+ }
+ }
+ }
+ }
+ /* NOTREACHED */
+ return (ACT_QUIT);
+}
+#endif /* TEXT_INPUT */
+
+static int
browsedir(int dfd)
{
- int f, i, j, s;
+ int action, i, j, s;
long curloc, nextloc;
DIR *dirp;
struct dirent *entry, *entry2;
- u_int32_t *icon, textbuf[TEXTSPACE*CHAR_HEIGHT];
- char line[256];
const char *desc;
if ((dirp = fdopendir(dfd)) == NULL)
@@ -340,29 +450,14 @@
s = 0;
if (i > 0) {
printf("p %20s\n", "previous page");
- memset(textbuf, 0, sizeof(textbuf));
- fb_render_text("previous page", 2, white, black, textbuf,
- TEXTSPACE, CHAR_HEIGHT);
- fb_post_region(textbuf, colstart[(s/NROW)] + TEXT_OFFSET,
- FROW + (RHEIGHT * (s % NROW)) + BORDER, TEXTSPACE,
- CHAR_HEIGHT);
- icon = get_icon("prev");
- fb_post_region(icon, colstart[(s/NROW)] + BORDER,
- FROW + (RHEIGHT * (s % NROW)) + BORDER, ICON_WH, ICON_WH);
+ update_slot(s, get_icon("prev"), "previous page");
s = 1;
}
entry = NULL; /* XXX: gcc warning */
while(s < NSLOTS - 1 && (entry = readdir(dirp)) != NULL) {
desc = get_desc(dfd, entry);
printf("%2d %20s %s\n", s, entry->d_name, desc);
- memset(textbuf, 0, sizeof(textbuf));
- fb_render_text(entry->d_name, 2, white, black, textbuf,
- TEXTSPACE, CHAR_HEIGHT);
- fb_post_region(textbuf, colstart[(s/NROW)]+TEXT_OFFSET,
- FROW + (RHEIGHT * (s % NROW)) + BORDER, TEXTSPACE, CHAR_HEIGHT);
- icon = get_icon(desc);
- fb_post_region(icon, colstart[(s/NROW)] + BORDER,
- FROW + (RHEIGHT * (s % NROW)) + BORDER, ICON_WH, ICON_WH);
+ update_slot(s, get_icon(desc), entry->d_name);
s++;
}
@@ -382,72 +477,35 @@
desc = get_desc(dfd, entry);
printf("%2d %20s %s\n", s,
entry->d_name, desc);
- memset(textbuf, 0, sizeof(textbuf));
- fb_render_text(entry->d_name, 2, white, black,
- textbuf, TEXTSPACE, CHAR_HEIGHT);
- fb_post_region(textbuf,
- colstart[(s/NROW)]+TEXT_OFFSET,
- FROW + (RHEIGHT * (s % NROW)) + BORDER,
- TEXTSPACE, CHAR_HEIGHT);
- icon = get_icon(desc);
- fb_post_region(icon,
- colstart[(s/NROW)] + BORDER,
- FROW + (RHEIGHT * (s % NROW)) + BORDER,
- ICON_WH, ICON_WH);
+ update_slot(s, get_icon(desc), entry->d_name);
s++;
} else {
printf("n %20s\n", "next page");
- memset(textbuf, 0, sizeof(textbuf));
- fb_render_text("next page", 2, white, black,
- textbuf, TEXTSPACE, CHAR_HEIGHT);
- fb_post_region(textbuf,
- colstart[(s/NROW)]+TEXT_OFFSET,
- FROW + (RHEIGHT * (s % NROW)) + BORDER,
- TEXTSPACE, CHAR_HEIGHT);
- icon = get_icon("next");
- fb_post_region(icon,
- colstart[(s/NROW)] + BORDER,
- FROW + (RHEIGHT * (s % NROW)) + BORDER,
- ICON_WH, ICON_WH);
+ update_slot(s, get_icon("next"), "next page");
}
}
}
-prompt:
- printf("select a file or directory by number :\n");
- if (fgets(line, sizeof(line), stdin) == NULL) {
- if (feof(stdin))
- return (-1);
- else
- errx(1, "fgets(): %s", strerror(ferror(stdin)));
- }
- printf("line '%s'\n", line);
- f = 0; /* XXX: gcc warning*/
- switch (line[0]) {
- case '\n':
- case 'n':
+ action = get_action((s == NSLOTS - 1) && entry != NULL ? NSLOTS - 1 : -1,
+ i == 0 ? -1 : 0);
+ printf("action %d\n", action);
+ switch (action) {
+ case ACT_NEXT:
/* This leaks an internal struct associted with curloc/ */
if (nextloc != 0) {
i += s;
curloc = nextloc;
}
goto start;
- case 'p':
+ case ACT_PREV:
i -= s;
// XXX previous page
break;
- case 'q':
- return(-1);
+ case ACT_QUIT:
+ return (-1);
default:
- if (!isnumber(line[0])) {
- printf("invalid file %s\n", line);
- goto prompt;
- }
- f = atoi(line);
- if (f < 0 || f >= NSLOTS - 1) {
- printf("invalid file %s\n", line);
- goto prompt;
- }
+ if (action < 0 || action >= NSLOTS - 1)
+ errx(1, "invalid action");
}
/* Take action on the specified file */
@@ -456,7 +514,7 @@
j = 0;
while((entry = readdir(dirp)) != NULL) {
printf("%s\n", entry->d_name);
- if (j++ != f)
+ if (j++ != action)
continue;
if (entry->d_type == DT_DIR) {
if ((dfd = openat(dfd, entry->d_name,
More information about the p4-projects
mailing list