changeset: 66:31c260fe352d
tag: tip
user: Anselm R. Garbe <arg_AT_suckless.org>
date: Tue Mar 13 13:35:14 2007 +0100
summary: made order of func decl. alphabetically (similiar to dwm/dmenu)
diff -r ac0ccddcf0e4 -r 31c260fe352d event.c
--- a/event.c Tue Mar 13 13:08:27 2007 +0100
+++ b/event.c Tue Mar 13 13:35:14 2007 +0100
@@ -49,89 +49,6 @@ selection_paste(Time tm) {
}
static void
-keypress(XEvent *xev) {
- char kbuf[KEYSEQLEN];
- KeySym keysym;
- static XComposeStatus compose = {NULL, 0};
- int len;
- int meta;
- int shift;
-
- meta = xev->xkey.state & ModMetaMask;
- shift = xev->xkey.state & ShiftMask;
- len = XLookupString(&(xev->xkey), &kbuf[0], sizeof(kbuf), &keysym, &compose);
- if(len > 0) {
- kbuf[KEYSEQLEN-1] = 0;
- if(meta && len == 1)
- cmd_write("\033", 1);
- cmd_write(kbuf, len);
- return;
- }
- if(keysym >= XK_Shift_L && keysym <= XK_Hyper_R)
- /* modifiers, these are handled by XLookupString */
- return;
- switch(keysym) {
- default:
- fprintf(stderr, "Unhandled special key: %d\n", (int)keysym);
- break;
- case XK_Up:
- case XK_Down:
- case XK_Left:
- case XK_Right:
- kbuf[0] = '\033';
- if(decckm_mode)
- kbuf[1] = 'O';
- else
- kbuf[1] = '[';
- kbuf[2] = "DACB"[keysym - XK_Left];
- cmd_write(kbuf, 3);
- break;
- case XK_Delete:
- cmd_write(DELETE_KEY, sizeof(DELETE_KEY)-1);
- break;
- case XK_Home:
- cmd_write(HOME_KEY, sizeof(HOME_KEY)-1);
- break;
- case XK_End:
- cmd_write(END_KEY, sizeof(END_KEY)-1);
- break;
- case XK_Prior:
- cmd_write(PREV_KEY, sizeof(PREV_KEY)-1);
- break;
- case XK_Next:
- cmd_write(NEXT_KEY, sizeof(NEXT_KEY)-1);
- break;
- case XK_Insert:
- if(shift)
- selection_paste(CurrentTime);
- break;
- }
-}
-
-static void
-configurenotify(XEvent *xev) {
- int new_cols, new_rows;
-
- new_cols = xev->xconfigure.width / dc.font.width;
- new_rows = xev->xconfigure.height / dc.font.height;
- if(new_cols != screen_cols || new_rows != screen_rows) {
- buffer_resize(new_rows, new_cols);
- screen_cols = new_cols;
- screen_rows = new_rows;
- scroll_region_start = 1;
- scroll_region_end = screen_rows;
- ww = xev->xconfigure.width;
- wh = xev->xconfigure.height;
- /* make sure the cursor is within the window */
- cursor_rego();
- /* Finally: pass the info to the application */
- resize_app();
- /* and redraw */
- force_redraw_screen();
- }
-}
-
-static void
selection_reset(void) {
int i, j;
@@ -148,11 +65,22 @@ selection_reset(void) {
}
static void
-selection_start(int row, int col, Time tm) {
- fprintf(stderr, "Selection started, row=%d, col=%d\n", row, col);
- selection_start_col = col, selection_start_row = row;
- selection_end_col = col, selection_end_row = row;
- selection_mode = SELECT_LETTER;
+selection_select_line(int row, int col, Time tm) {
+ int i;
+
+ if(selection_text)
+ free(selection_text);
+ selection_text = malloc(screen_cols+1);
+ assert(selection_text);
+ fprintf(stderr, "select line %d\n", row);
+ for(i = 0; i < screen_cols; i++) {
+ selection_text[i] = text_screen[row-1].line[i].letter;
+ text_screen[row-1].line[i].sel = 1;
+ }
+ while(selection_text[i] == ' ') i--;
+ text_screen[row-1].needs_update=1;
+ XStoreBuffer(dpy, (char *)selection_text, screen_cols, XA_CUT_BUFFER0);
+ XSetSelectionOwner(dpy, XA_PRIMARY, win, tm);
}
static void
@@ -181,23 +109,14 @@ selection_select_word(int row, int col,
}
static void
-selection_select_line(int row, int col, Time tm) {
- int i;
-
- if(selection_text)
- free(selection_text);
- selection_text = malloc(screen_cols+1);
- assert(selection_text);
- fprintf(stderr, "select line %d\n", row);
- for(i = 0; i < screen_cols; i++) {
- selection_text[i] = text_screen[row-1].line[i].letter;
- text_screen[row-1].line[i].sel = 1;
- }
- while(selection_text[i] == ' ') i--;
- text_screen[row-1].needs_update=1;
- XStoreBuffer(dpy, (char *)selection_text, screen_cols, XA_CUT_BUFFER0);
- XSetSelectionOwner(dpy, XA_PRIMARY, win, tm);
-}
+selection_start(int row, int col, Time tm) {
+ fprintf(stderr, "Selection started, row=%d, col=%d\n", row, col);
+ selection_start_col = col, selection_start_row = row;
+ selection_end_col = col, selection_end_row = row;
+ selection_mode = SELECT_LETTER;
+}
+
+/* event handlers */
static void
buttonpress(XEvent *xev) {
@@ -244,6 +163,89 @@ buttonpress(XEvent *xev) {
}
static void
+configurenotify(XEvent *xev) {
+ int new_cols, new_rows;
+
+ new_cols = xev->xconfigure.width / dc.font.width;
+ new_rows = xev->xconfigure.height / dc.font.height;
+ if(new_cols != screen_cols || new_rows != screen_rows) {
+ buffer_resize(new_rows, new_cols);
+ screen_cols = new_cols;
+ screen_rows = new_rows;
+ scroll_region_start = 1;
+ scroll_region_end = screen_rows;
+ ww = xev->xconfigure.width;
+ wh = xev->xconfigure.height;
+ /* make sure the cursor is within the window */
+ cursor_rego();
+ /* Finally: pass the info to the application */
+ resize_app();
+ /* and redraw */
+ force_redraw_screen();
+ }
+}
+
+static void
+keypress(XEvent *xev) {
+ char kbuf[KEYSEQLEN];
+ KeySym keysym;
+ static XComposeStatus compose = {NULL, 0};
+ int len;
+ int meta;
+ int shift;
+
+ meta = xev->xkey.state & ModMetaMask;
+ shift = xev->xkey.state & ShiftMask;
+ len = XLookupString(&(xev->xkey), &kbuf[0], sizeof(kbuf), &keysym, &compose);
+ if(len > 0) {
+ kbuf[KEYSEQLEN-1] = 0;
+ if(meta && len == 1)
+ cmd_write("\033", 1);
+ cmd_write(kbuf, len);
+ return;
+ }
+ if(keysym >= XK_Shift_L && keysym <= XK_Hyper_R)
+ /* modifiers, these are handled by XLookupString */
+ return;
+ switch(keysym) {
+ default:
+ fprintf(stderr, "Unhandled special key: %d\n", (int)keysym);
+ break;
+ case XK_Up:
+ case XK_Down:
+ case XK_Left:
+ case XK_Right:
+ kbuf[0] = '\033';
+ if(decckm_mode)
+ kbuf[1] = 'O';
+ else
+ kbuf[1] = '[';
+ kbuf[2] = "DACB"[keysym - XK_Left];
+ cmd_write(kbuf, 3);
+ break;
+ case XK_Delete:
+ cmd_write(DELETE_KEY, sizeof(DELETE_KEY)-1);
+ break;
+ case XK_Home:
+ cmd_write(HOME_KEY, sizeof(HOME_KEY)-1);
+ break;
+ case XK_End:
+ cmd_write(END_KEY, sizeof(END_KEY)-1);
+ break;
+ case XK_Prior:
+ cmd_write(PREV_KEY, sizeof(PREV_KEY)-1);
+ break;
+ case XK_Next:
+ cmd_write(NEXT_KEY, sizeof(NEXT_KEY)-1);
+ break;
+ case XK_Insert:
+ if(shift)
+ selection_paste(CurrentTime);
+ break;
+ }
+}
+
+static void
expose(XEvent *xev) {
int a,b,c,d;
switch(refresh_type) {
@@ -260,21 +262,6 @@ expose(XEvent *xev) {
c = c > screen_cols ? screen_cols : c;
d = d > screen_rows ? screen_rows : d;
redraw_region(a,b,c,d);
- break;
- }
-}
-
-static void
-visibilitynotify(XEvent *xev) {
- switch(xev->xvisibility.state) {
- case VisibilityUnobscured:
- refresh_type = REFRESH_FULL;
- break;
- case VisibilityPartiallyObscured:
- refresh_type = REFRESH_PARTIALLY;
- break;
- default:
- refresh_type = REFRESH_NO;
break;
}
}
@@ -350,6 +337,21 @@ selectionrequest(XEvent *xev) {
XSendEvent(dpy, rq->requestor, False, 0, &ev);
}
+static void
+visibilitynotify(XEvent *xev) {
+ switch(xev->xvisibility.state) {
+ case VisibilityUnobscured:
+ refresh_type = REFRESH_FULL;
+ break;
+ case VisibilityPartiallyObscured:
+ refresh_type = REFRESH_PARTIALLY;
+ break;
+ default:
+ refresh_type = REFRESH_NO;
+ break;
+ }
+}
+
/* extern */
void (*handler[LASTEvent]) (XEvent *) = {
diff -r ac0ccddcf0e4 -r 31c260fe352d process.c
--- a/process.c Tue Mar 13 13:08:27 2007 +0100
+++ b/process.c Tue Mar 13 13:35:14 2007 +0100
@@ -33,6 +33,40 @@ static int slave;
static int slave;
char *ptydev, *ttydev;
+static void
+fill_buffer(int fd) {
+ int len;
+
+ wait_for_input();
+ len = read(fd, &output_buf[0], sizeof(output_buf));
+ if(len < 0) {
+ fprintf(stderr, "Error reading from command: %m\n");
+ exit(1);
+ }
+ if(len == 0) {
+ fprintf(stderr, "No more data! exiting.\n");
+ exit(1);
+ }
+ endptr = len;
+ startptr = 0;
+}
+
+static struct passwd *
+find_user(void) {
+ uid_t uid;
+ struct passwd *pw;
+
+ if((uid = getuid()) == -1) {
+ fprintf(stderr, "Couldn't find current uid: %m\n");
+ exit(2);
+ }
+ if((pw = getpwuid(uid)) == NULL) {
+ fprintf(stderr, "Couldn't find password entry for user %d: %m\n", uid);
+ exit(2);
+ }
+ return pw;
+}
+
static struct winsize *
get_font_dim() {
static struct winsize w;
@@ -41,42 +75,6 @@ get_font_dim() {
w.ws_col = screen_cols;
w.ws_xpixel = w.ws_ypixel = 0;
return &w;
-}
-
-static void
-sigchld_handler(int a) {
- int status = 0;
-
- if(waitpid(pid, &status, 0) < 0) {
- fprintf(stderr, "Waiting for pid %hd failed: %m\n",
- pid);
- exit(1);
- }
- if(WIFEXITED(status)) /* Child exited by itself */ {
- if(WEXITSTATUS(status))
- exit(WEXITSTATUS(status));
- }
- else if(WIFSIGNALED(status)) /* Child was killed by a signal */
- exit(1);
- else /* Something strange happened */
- exit(1);
- exit(0);
-}
-
-static struct passwd *
-find_user(void) {
- uid_t uid;
- struct passwd *pw;
-
- if((uid = getuid()) == -1) {
- fprintf(stderr, "Couldn't find current uid: %m\n");
- exit(2);
- }
- if((pw = getpwuid(uid)) == NULL) {
- fprintf(stderr, "Couldn't find password entry for user %d: %m\n", uid);
- exit(2);
- }
- return pw;
}
static int
@@ -124,21 +122,23 @@ get_tty(void) {
}
static void
-fill_buffer(int fd) {
- int len;
-
- wait_for_input();
- len = read(fd, &output_buf[0], sizeof(output_buf));
- if(len < 0) {
- fprintf(stderr, "Error reading from command: %m\n");
- exit(1);
- }
- if(len == 0) {
- fprintf(stderr, "No more data! exiting.\n");
- exit(1);
- }
- endptr = len;
- startptr = 0;
+sigchld_handler(int a) {
+ int status = 0;
+
+ if(waitpid(pid, &status, 0) < 0) {
+ fprintf(stderr, "Waiting for pid %hd failed: %m\n",
+ pid);
+ exit(1);
+ }
+ if(WIFEXITED(status)) /* Child exited by itself */ {
+ if(WEXITSTATUS(status))
+ exit(WEXITSTATUS(status));
+ }
+ else if(WIFSIGNALED(status)) /* Child was killed by a signal */
+ exit(1);
+ else /* Something strange happened */
+ exit(1);
+ exit(0);
}
/* extern */
@@ -166,15 +166,6 @@ cmd_write(const char *buf, int len) {
if(write(cmd_fd, buf, len) < 0) {
fprintf(stderr, "Error writing to process: %m\n");
exit(2);
- }
- return 0;
-}
-
-int
-resize_app(void) {
- if(ioctl(cmd_fd, TIOCSWINSZ, get_font_dim()) < 0) {
- fprintf(stderr, "Couldn't set window size: %m\n");
- return -1;
}
return 0;
}
@@ -209,6 +200,15 @@ execute_command(int argc, char **argv) {
/* parent */
close(slave);
signal(SIGCHLD, sigchld_handler);
+ return 0;
+}
+
+int
+resize_app(void) {
+ if(ioctl(cmd_fd, TIOCSWINSZ, get_font_dim()) < 0) {
+ fprintf(stderr, "Couldn't set window size: %m\n");
+ return -1;
+ }
return 0;
}
@@ -263,4 +263,3 @@ wait_for_input(void) {
}
}
}
-
diff -r ac0ccddcf0e4 -r 31c260fe352d util.c
--- a/util.c Tue Mar 13 13:08:27 2007 +0100
+++ b/util.c Tue Mar 13 13:35:14 2007 +0100
@@ -10,17 +10,17 @@
#include <unistd.h>
void *
-emallocz(unsigned int size) {
- void *res = calloc(1, size);
-
+emalloc(unsigned int size) {
+ void *res = malloc(size);
if(!res)
eprint("fatal: could not malloc() %u bytes\n", size);
return res;
}
void *
-emalloc(unsigned int size) {
- void *res = malloc(size);
+emallocz(unsigned int size) {
+ void *res = calloc(1, size);
+
if(!res)
eprint("fatal: could not malloc() %u bytes\n", size);
return res;
diff -r ac0ccddcf0e4 -r 31c260fe352d vt.c
--- a/vt.c Tue Mar 13 13:08:27 2007 +0100
+++ b/vt.c Tue Mar 13 13:35:14 2007 +0100
@@ -12,111 +12,80 @@
int curr_row, curr_col;
-/* Maximum (numerical) parameters to an escape sequence */
-#define NPAR 16
+#define NPAR 16 /* Maximum (numerical) parameters to an escape sequence */
+#define MAXRUNLENGTH 100 /* Max number of characters to be drawn at once */
/* static */
static int saved_cursor_x, saved_cursor_y;
-
-static void
-win_clear_region(int x1, int y1, int x2, int y2, int color) {
- XSetBackground(dpy, dc.gc, color);
- XClearArea(dpy, win, x1, y1, x2 - x1, y2 - y1, 0);
-}
-
-static void
-win_draw_string(int row, int col, char *s, int l) {
- if(dc.font.set)
- XmbDrawImageString(dpy, win, dc.font.set, dc.gc, col * dc.font.width, row * dc.font.height + dc.font.ascent, s, l);
- else
- XDrawImageString(dpy, win, dc.gc, col * dc.font.width, row * dc.font.height + dc.font.ascent, s, l);
-}
-
-static void
-win_set_window_title(char *title) {
- XStoreName(dpy, win, title);
-}
-
-static void
-window_scroll_up(int lines) {
- XCopyArea(dpy, win, win, dc.gc, 0, lines * dc.font.height, ww, (screen_rows - lines + 1) * dc.font.height, 0, 0);
- win_clear_region(0, (screen_rows - lines) * dc.font.height, ww, screen_rows * dc.font.height, GET_BG_COLOR(text_attrs));
-}
-
-static void
-region_scroll_up(int start, int end, int lines) {
- XCopyArea(dpy, win, win, dc.gc, 0, (start - 1 + lines) * dc.font.height, ww, (end - start + 2 - lines) * dc.font.height,
- 0, (start - 1) * dc.font.height);
- win_clear_region(0, (end - lines) * dc.font.height, ww, end * dc.font.height, GET_BG_COLOR(text_attrs));
-}
-
-static void
-window_scroll_down(int lines) {
- XCopyArea(dpy, win, win, dc.gc, 0, 0, ww, (screen_rows - lines + 1) * dc.font.height, 0, lines * dc.font.height);
- win_clear_region(0, 0, ww, (lines) * dc.font.height, GET_BG_COLOR(text_attrs));
-}
-
-static void
-region_scroll_down(int start, int end, int lines) {
- XCopyArea(dpy, win, win, dc.gc, 0, (start - 1) * dc.font.height, ww, (end - start + 2 - lines) * dc.font.height,
- 0, (start - 1 + lines) * dc.font.height);
- win_clear_region(0, (start - 1) * dc.font.height, ww, (start + lines - 1) * dc.font.height, GET_BG_COLOR(text_attrs));
-}
-
static int cursor_row, cursor_col;
static int cursor_is_visible = 0;
-
-/* Cursor movement functions */
-static int
-cursor_move_up(int n) {
- curr_row -= n;
- if(curr_row < 1)
- curr_row = 0;
- return curr_row;
-}
-
-static int
-cursor_move_down(int n) {
- curr_row += n;
- if(curr_row > screen_rows)
- curr_row = screen_rows;
- return curr_row;
-}
-
-static int
-cursor_move_left(int n) {
- curr_col -= n;
- if(curr_col < 1)
- curr_col = 1;
- return curr_col;
-}
-
-static int
-cursor_move_right(int n) {
- curr_col += n;
- if(curr_col > screen_cols)
- curr_col = screen_cols;
- return curr_col;
-}
-
-static int
-cursor_move_col(int n) {
- curr_col = n;
- if(curr_col < 1)
- curr_col = 1;
- if(curr_col > screen_cols)
- curr_col = screen_cols;
- return curr_col;
-}
-
-static int
-cursor_move_row(int n) {
- curr_row = n;
- if(curr_row < 1)
- curr_row = 1;
- if(curr_row > screen_rows)
- curr_row = screen_rows;
- return curr_row;
+static void delete_rows(Row *screen, int start, int n);
+static void moverows(Row *screen, int from, int to, int n);
+static void add_rows(Row *screen, int pos, int n);
+static void win_clear_region(int x1, int y1, int x2, int y2, int color);
+static void scroll_down(int rows);
+static void window_scroll_down(int lines);
+
+static void
+_buffer_resize(Row **s, int rows, int cols) {
+ int i;
+
+ if(rows < screen_rows) {
+ delete_rows(*s, 1, screen_rows - rows);
+ moverows(*s, screen_rows - rows + 1, 1, rows);
+ }
+ *s = realloc(*s, rows * sizeof(Row));
+ assert(*s);
+ if(rows > screen_rows)
+ add_rows(*s, screen_rows + 1, rows - screen_rows);
+ if(cols != screen_cols) {
+ for(i = 0; i < rows; i++) {
+ int j;
+
+ (*s)[i].line = realloc((*s)[i].line, cols * sizeof(Glyph));
+ assert((*s)[i].line);
+ for(j = screen_cols; j < cols; j++)
+ *(int*)(&((*s)[i]).line[j]) = 0;
+ (*s)[i].needs_update = 1;
+ }
+ }
+}
+
+static void
+add_rows(Row *screen, int pos, int n) {
+ int i, j;
+
+ text_attrs.letter = ' ';
+ for(i = 0; i < n; i++) {
+ screen[pos + i - 1].line = calloc(screen_cols, sizeof(Glyph));
+ assert(screen[pos + i - 1].line);
+ for(j = 0; j < screen_cols; j++)
+ screen[pos + i - 1].line[j] = text_attrs;
+ screen[pos + i - 1].needs_update = 1;
+ }
+}
+
+static void
+buffer_destroy(Row *screen) {
+ int i;
+
+ for(i = 0; i < screen_rows; i++)
+ free(screen[i].line);
+ free(screen);
+}
+
+static void
+clear_area(int x1, int y1, int x2, int y2) {
+ int i, j;
+
+ win_clear_region((x1 - 1) * dc.font.width, (y1 - 1) * dc.font.height,
+ x2 * dc.font.width, y2 * dc.font.height,
+ GET_BG_COLOR(text_attrs));
+ for(i = y1; i <= y2; i++)
+ for(j = x1; j <= x2; j++) {
+ text_screen[i-1].line[j-1] = text_attrs;
+ text_screen[i-1].line[j-1].letter = ' ';
+ }
}
static void
@@ -133,114 +102,78 @@ cursor_goto(int x, int y) {
curr_row = screen_rows;
}
+static int
+cursor_move_down(int n) {
+ curr_row += n;
+ if(curr_row > screen_rows)
+ curr_row = screen_rows;
+ return curr_row;
+}
+
+static int
+cursor_move_col(int n) {
+ curr_col = n;
+ if(curr_col < 1)
+ curr_col = 1;
+ if(curr_col > screen_cols)
+ curr_col = screen_cols;
+ return curr_col;
+}
+
+static int
+cursor_move_left(int n) {
+ curr_col -= n;
+ if(curr_col < 1)
+ curr_col = 1;
+ return curr_col;
+}
+
+static int
+cursor_move_right(int n) {
+ curr_col += n;
+ if(curr_col > screen_cols)
+ curr_col = screen_cols;
+ return curr_col;
+}
+
+static int
+cursor_move_row(int n) {
+ curr_row = n;
+ if(curr_row < 1)
+ curr_row = 1;
+ if(curr_row > screen_rows)
+ curr_row = screen_rows;
+ return curr_row;
+}
+
+static int
+cursor_move_up(int n) {
+ curr_row -= n;
+ if(curr_row < 1)
+ curr_row = 0;
+ return curr_row;
+}
+
+static void
+delete_lines(int lines) {
+ int a,b;
+
+ /* Fake region scroll */
+ a = scroll_region_start;
+ b = scroll_in_region;
+ scroll_region_start = curr_row;
+ scroll_in_region = 1;
+ scroll_up(lines);
+ scroll_region_start = a;
+ scroll_in_region = b;
+}
+
static void
delete_rows(Row *screen, int start, int n) {
int i;
for(i = 0; i < n; i++)
free(screen[start + i - 1].line);
-}
-
-static void
-add_rows(Row *screen, int pos, int n) {
- int i, j;
-
- text_attrs.letter = ' ';
- for(i = 0; i < n; i++) {
- screen[pos + i - 1].line = calloc(screen_cols, sizeof(Glyph));
- assert(screen[pos + i - 1].line);
- for(j = 0; j < screen_cols; j++)
- screen[pos + i - 1].line[j] = text_attrs;
- screen[pos + i - 1].needs_update = 1;
- }
-}
-
-static void
-buffer_destroy(Row *screen) {
- int i;
-
- for(i = 0; i < screen_rows; i++)
- free(screen[i].line);
- free(screen);
-}
-
-static void
-save_current_screen(void) {
- saved_screen = text_screen;
- text_screen = buffer_create(screen_rows, screen_cols);
-}
-
-static void
-restore_saved_screen(void) {
- int i;
-
- buffer_destroy(text_screen);
- text_screen = saved_screen;
- for(i = 0; i < screen_rows; i++)
- text_screen[i].needs_update = 1;
-}
-
-static void
-moverows(Row *screen, int from, int to, int n) {
- memmove(&(screen[to-1]), &(screen[from-1]), n * sizeof(Row));
-}
-
-static void
-_buffer_resize(Row **s, int rows, int cols) {
- int i;
-
- if(rows < screen_rows) {
- delete_rows(*s, 1, screen_rows - rows);
- moverows(*s, screen_rows - rows + 1, 1, rows);
- }
- *s = realloc(*s, rows * sizeof(Row));
- assert(*s);
- if(rows > screen_rows)
- add_rows(*s, screen_rows + 1, rows - screen_rows);
- if(cols != screen_cols) {
- for(i = 0; i < rows; i++) {
- int j;
-
- (*s)[i].line = realloc((*s)[i].line, cols * sizeof(Glyph));
- assert((*s)[i].line);
- for(j = screen_cols; j < cols; j++)
- *(int*)(&((*s)[i]).line[j]) = 0;
- (*s)[i].needs_update = 1;
- }
- }
-}
-
-static void
-clear_area(int x1, int y1, int x2, int y2) {
- int i, j;
-
- win_clear_region((x1 - 1) * dc.font.width, (y1 - 1) * dc.font.height,
- x2 * dc.font.width, y2 * dc.font.height,
- GET_BG_COLOR(text_attrs));
- for(i = y1; i <= y2; i++)
- for(j = x1; j <= x2; j++)
- {
- text_screen[i-1].line[j-1] = text_attrs;
- text_screen[i-1].line[j-1].letter = ' ';
- }
-}
-
-static void
-scroll_down(int rows) {
- if(scroll_in_region) {
- /* Only scroll region */
- region_scroll_down(scroll_region_start, scroll_region_end, rows);
- delete_rows(text_screen, scroll_region_end - rows + 1, rows);
- moverows(text_screen, scroll_region_start, scroll_region_start + rows, scroll_region_end - scroll_region_start - rows + 1);
- add_rows(text_screen, scroll_region_start, rows);
- }
- else {
- /* Scroll entire buffer */
- window_scroll_down(rows);
- delete_rows(text_screen, screen_rows - rows + 1, rows);
- moverows(text_screen, 1, rows + 1, screen_rows - rows);
- add_rows(text_screen, 1, rows);
- }
}
static void
@@ -258,22 +191,92 @@ insert_lines(int lines) {
}
static void
-delete_lines(int lines) {
- int a,b;
-
- /* Fake region scroll */
- a = scroll_region_start;
- b = scroll_in_region;
- scroll_region_start = curr_row;
- scroll_in_region = 1;
- scroll_up(lines);
- scroll_region_start = a;
- scroll_in_region = b;
-}
-
-static void set_buffer_reverse(int rev)
-{
+moverows(Row *screen, int from, int to, int n) {
+ memmove(&(screen[to-1]), &(screen[from-1]), n * sizeof(Row));
+}
+
+static void
+region_scroll_down(int start, int end, int lines) {
+ XCopyArea(dpy, win, win, dc.gc, 0, (start - 1) * dc.font.height, ww, (end - start + 2 - lines) * dc.font.height,
+ 0, (start - 1 + lines) * dc.font.height);
+ win_clear_region(0, (start - 1) * dc.font.height, ww, (start + lines - 1) * dc.font.height, GET_BG_COLOR(text_attrs));
+}
+
+static void
+region_scroll_up(int start, int end, int lines) {
+ XCopyArea(dpy, win, win, dc.gc, 0, (start - 1 + lines) * dc.font.height, ww, (end - start + 2 - lines) * dc.font.height,
+ 0, (start - 1) * dc.font.height);
+ win_clear_region(0, (end - lines) * dc.font.height, ww, end * dc.font.height, GET_BG_COLOR(text_attrs));
+}
+
+static void
+restore_saved_screen(void) {
+ int i;
+
+ buffer_destroy(text_screen);
+ text_screen = saved_screen;
+ for(i = 0; i < screen_rows; i++)
+ text_screen[i].needs_update = 1;
+}
+
+static void
+save_current_screen(void) {
+ saved_screen = text_screen;
+ text_screen = buffer_create(screen_rows, screen_cols);
+}
+
+static void
+scroll_down(int rows) {
+ if(scroll_in_region) {
+ /* Only scroll region */
+ region_scroll_down(scroll_region_start, scroll_region_end, rows);
+ delete_rows(text_screen, scroll_region_end - rows + 1, rows);
+ moverows(text_screen, scroll_region_start, scroll_region_start + rows, scroll_region_end - scroll_region_start - rows + 1);
+ add_rows(text_screen, scroll_region_start, rows);
+ }
+ else {
+ /* Scroll entire buffer */
+ window_scroll_down(rows);
+ delete_rows(text_screen, screen_rows - rows + 1, rows);
+ moverows(text_screen, 1, rows + 1, screen_rows - rows);
+ add_rows(text_screen, 1, rows);
+ }
+}
+
+static void
+set_buffer_reverse(int rev) {
text_attrs.rev = rev ? 1 : 0;
+}
+
+static void
+win_clear_region(int x1, int y1, int x2, int y2, int color) {
+ XSetBackground(dpy, dc.gc, color);
+ XClearArea(dpy, win, x1, y1, x2 - x1, y2 - y1, 0);
+}
+
+static void
+win_draw_string(int row, int col, char *s, int l) {
+ if(dc.font.set)
+ XmbDrawImageString(dpy, win, dc.font.set, dc.gc, col * dc.font.width, row * dc.font.height + dc.font.ascent, s, l);
+ else
+ XDrawImageString(dpy, win, dc.gc, col * dc.font.width, row * dc.font.height + dc.font.ascent, s, l);
+}
+
+static void
+win_set_window_title(char *title) {
+ XStoreName(dpy, win, title);
+}
+
+static void
+window_scroll_up(int lines) {
+ XCopyArea(dpy, win, win, dc.gc, 0, lines * dc.font.height, ww, (screen_rows - lines + 1) * dc.font.height, 0, 0);
+ win_clear_region(0, (screen_rows - lines) * dc.font.height, ww, screen_rows * dc.font.height, GET_BG_COLOR(text_attrs));
+}
+
+static void
+window_scroll_down(int lines) {
+ XCopyArea(dpy, win, win, dc.gc, 0, 0, ww, (screen_rows - lines + 1) * dc.font.height, 0, lines * dc.font.height);
+ win_clear_region(0, 0, ww, (lines) * dc.font.height, GET_BG_COLOR(text_attrs));
}
static void
@@ -305,6 +308,29 @@ xterm_seq(int op) {
}
/* extern */
+
+Row *
+buffer_create(int rows, int cols) {
+ int i;
+ Row *tr;
+
+ tr = emallocz(rows * sizeof(Row));
+ for(i = 0; i < rows; i++)
+ tr[i].line = emallocz(cols * sizeof(Glyph));
+ return tr;
+}
+
+void
+buffer_resize(int rows, int cols) {
+ if(using_alternate_screen)
+ _buffer_resize(&saved_screen, rows, cols);
+ _buffer_resize(&text_screen, rows, cols);
+}
+
+void
+cursor_rego(void) {
+ cursor_goto(curr_col, curr_row);
+}
void
dispatch_escape(void) {
@@ -590,13 +616,128 @@ dispatch_escape(void) {
}
void
-wait_for_specific_event(int event_type) {
- XEvent e;
- for(;;) {
- XNextEvent(dpy, &e);
- if(e.type == event_type)
- break;
- }
+force_redraw_screen(void) {
+ int i;
+ for(i = 0; i < screen_rows; i++)
+ text_screen[i].needs_update = 1;
+ redraw_screen();
+}
+
+void
+hide_cursor(void) {
+ if(!cursor_is_visible)
+ return;
+ if(cursor_row <= screen_rows && cursor_col <= screen_cols)
+ {
+ set_text_attrs(text_screen[cursor_row-1].line[cursor_col-1]);
+ win_clear_region((cursor_col - 1) * dc.font.width, (cursor_row - 1) * dc.font.height,
+ cursor_col * dc.font.width, cursor_row * dc.font.height,
+ GET_BG_COLOR(text_screen[cursor_row-1].line[cursor_col-1]));
+ win_draw_string(cursor_row - 1, cursor_col - 1, (char *)&(text_screen[cursor_row - 1].line[cursor_col - 1]), 1);
+ XFlush(dpy);
+ }
+ cursor_is_visible = 0;
+}
+
+void
+redraw_region(int x1, int y1, int x2, int y2) {
+ int i, j;
+ int a;
+ int sl, start;
+ unsigned char buf[MAXRUNLENGTH];
+
+ a = (*(int*)&(text_screen[y1-1].line[x1-1])) & ~0xff;
+ set_text_attrs(text_screen[y1-1].line[x1-1]);
+ for(i = y1 - 1; i < y2; i++) {
+ sl = 0; start = x1 - 1;
+ for(j = x1 - 1; j <= x2; j++) {
+ if(j == x2) {
+ if(sl > 0)
+ win_draw_string(i, start, (char *)buf, sl);
+ break;
+ }
+ if(a != ((*(int*)&(text_screen[i].line[j])) & ~0xff) || sl >= sizeof(buf)) {
+ if(sl > 0)
+ win_draw_string(i, start, (char *)buf, sl);
+ set_text_attrs(text_screen[i].line[j]);
+ a = (*(int*)&(text_screen[i].line[j])) & ~0xff;
+ start = j;
+ sl = 0;
+ }
+ buf[sl] = text_screen[i].line[j].letter;
+ sl++;
+ }
+ text_screen[i].needs_update = 0;
+ }
+ XFlush(dpy);
+}
+
+void
+redraw_screen(void) {
+ int i, j;
+ int a;
+ int sl, start;
+ unsigned char buf[MAXRUNLENGTH];
+
+ a = 0;
+ set_text_attrs(text_screen[0].line[0]);
+ for(i = 0; i < screen_rows; i++) {
+ if(!text_screen[i].needs_update)
+ continue;
+ sl = 0; start = 0;
+ for(j = 0; j <= screen_cols; j++) {
+ if(j == screen_cols) {
+ if(sl > 0)
+ win_draw_string(i, start, (char *)buf, sl);
+ break;
+ }
+ if(a != ((*(int*)&(text_screen[i].line[j])) & ~0xff) || sl >= sizeof(buf)) {
+ if(sl > 0)
+ win_draw_string(i, start, (char *)buf, sl);
+ set_text_attrs(text_screen[i].line[j]);
+ a = (*(int*)&(text_screen[i].line[j])) & ~0xff;
+ start = j;
+ sl = 0;
+ }
+ buf[sl] = text_screen[i].line[j].letter;
+ sl++;
+ }
+ text_screen[i].needs_update = 0;
+ }
+ XFlush(dpy);
+}
+
+void
+scroll_up(int rows) {
+ if(scroll_in_region) {
+ /* Only scroll region */
+ region_scroll_up(scroll_region_start, scroll_region_end, rows);
+ delete_rows(text_screen, scroll_region_start, rows);
+ moverows(text_screen, rows + scroll_region_start, scroll_region_start, scroll_region_end - scroll_region_start - rows + 1);
+ add_rows(text_screen, scroll_region_end - rows + 1, rows);
+ }
+ else {
+ /* Scroll entire buffer */
+ window_scroll_up(rows);
+ delete_rows(text_screen, 1, rows);
+ moverows(text_screen, rows + 1, 1, screen_rows - rows);
+ add_rows(text_screen, screen_rows - rows + 1, rows);
+ }
+}
+
+void
+set_buffer_attrs(int bold) {
+ text_attrs.bold = bold ? 1 : 0;
+}
+
+void
+set_buffer_fg_color(int c) {
+ text_attrs.fg = c;
+}
+
+void
+set_buffer_bg_color(int c) {
+ text_attrs.bg = c;
}
void
@@ -614,84 +755,6 @@ set_text_attrs(Glyph l) {
if(!dc.font.set)
XSetFont(dpy, dc.gc, dc.font.xfont->fid);
XSetBackground(dpy, dc.gc, dc.bg[bg]);
-}
-
-/* Max number of characters to be drawn at once */
-#define MAXRUNLENGTH 100
-void
-redraw_screen(void) {
- int i, j;
- int a;
- int sl, start;
- unsigned char buf[MAXRUNLENGTH];
-
- a = 0;
- set_text_attrs(text_screen[0].line[0]);
- for(i = 0; i < screen_rows; i++) {
- if(!text_screen[i].needs_update)
- continue;
- sl = 0; start = 0;
- for(j = 0; j <= screen_cols; j++) {
- if(j == screen_cols) {
- if(sl > 0)
- win_draw_string(i, start, (char *)buf, sl);
- break;
- }
- if(a != ((*(int*)&(text_screen[i].line[j])) & ~0xff) || sl >= sizeof(buf)) {
- if(sl > 0)
- win_draw_string(i, start, (char *)buf, sl);
- set_text_attrs(text_screen[i].line[j]);
- a = (*(int*)&(text_screen[i].line[j])) & ~0xff;
- start = j;
- sl = 0;
- }
- buf[sl] = text_screen[i].line[j].letter;
- sl++;
- }
- text_screen[i].needs_update = 0;
- }
- XFlush(dpy);
-}
-
-void
-force_redraw_screen(void) {
- int i;
- for(i = 0; i < screen_rows; i++)
- text_screen[i].needs_update = 1;
- redraw_screen();
-}
-
-void
-redraw_region(int x1, int y1, int x2, int y2) {
- int i, j;
- int a;
- int sl, start;
- unsigned char buf[MAXRUNLENGTH];
-
- a = (*(int*)&(text_screen[y1-1].line[x1-1])) & ~0xff;
- set_text_attrs(text_screen[y1-1].line[x1-1]);
- for(i = y1 - 1; i < y2; i++) {
- sl = 0; start = x1 - 1;
- for(j = x1 - 1; j <= x2; j++) {
- if(j == x2) {
- if(sl > 0)
- win_draw_string(i, start, (char *)buf, sl);
- break;
- }
- if(a != ((*(int*)&(text_screen[i].line[j])) & ~0xff) || sl >= sizeof(buf)) {
- if(sl > 0)
- win_draw_string(i, start, (char *)buf, sl);
- set_text_attrs(text_screen[i].line[j]);
- a = (*(int*)&(text_screen[i].line[j])) & ~0xff;
- start = j;
- sl = 0;
- }
- buf[sl] = text_screen[i].line[j].letter;
- sl++;
- }
- text_screen[i].needs_update = 0;
- }
- XFlush(dpy);
}
void
@@ -716,82 +779,13 @@ show_cursor(void) {
}
void
-hide_cursor(void) {
- if(!cursor_is_visible)
- return;
- if(cursor_row <= screen_rows && cursor_col <= screen_cols)
- {
- set_text_attrs(text_screen[cursor_row-1].line[cursor_col-1]);
- win_clear_region((cursor_col - 1) * dc.font.width, (cursor_row - 1) * dc.font.height,
- cursor_col * dc.font.width, cursor_row * dc.font.height,
- GET_BG_COLOR(text_screen[cursor_row-1].line[cursor_col-1]));
- win_draw_string(cursor_row - 1, cursor_col - 1, (char *)&(text_screen[cursor_row - 1].line[cursor_col - 1]), 1);
- XFlush(dpy);
- }
- cursor_is_visible = 0;
-}
-
-Row *
-buffer_create(int rows, int cols) {
- int i;
- Row *tr;
-
- tr = emallocz(rows * sizeof(Row));
- for(i = 0; i < rows; i++)
- tr[i].line = emallocz(cols * sizeof(Glyph));
- return tr;
-}
-
-void
-cursor_rego(void) {
- cursor_goto(curr_col, curr_row);
-}
-
-void
-buffer_resize(int rows, int cols) {
- if(using_alternate_screen)
- _buffer_resize(&saved_screen, rows, cols);
- _buffer_resize(&text_screen, rows, cols);
-}
-
-void
-scroll_up(int rows) {
- if(scroll_in_region) {
- /* Only scroll region */
- region_scroll_up(scroll_region_start, scroll_region_end, rows);
- delete_rows(text_screen, scroll_region_start, rows);
- moverows(text_screen, rows + scroll_region_start, scroll_region_start, scroll_region_end - scroll_region_start - rows + 1);
- add_rows(text_screen, scroll_region_end - rows + 1, rows);
- }
- else {
- /* Scroll entire buffer */
- window_scroll_up(rows);
- delete_rows(text_screen, 1, rows);
- moverows(text_screen, rows + 1, 1, screen_rows - rows);
- add_rows(text_screen, screen_rows - rows + 1, rows);
- }
-}
-
-void
-set_buffer_fg_color(int c) {
- text_attrs.fg = c;
-}
-
-void
-set_buffer_bg_color(int c) {
- text_attrs.bg = c;
-}
-
-void
-set_buffer_attrs(int bold) {
- text_attrs.bold = bold ? 1 : 0;
-}
-
-void
-write_buffer(unsigned char c) {
- text_attrs.letter = c;
- text_screen[curr_row-1].line[curr_col-1] = text_attrs;
- text_screen[curr_row-1].needs_update = 1;
+wait_for_specific_event(int event_type) {
+ XEvent e;
+ for(;;) {
+ XNextEvent(dpy, &e);
+ if(e.type == event_type)
+ break;
+ }
}
void
@@ -807,3 +801,10 @@ wrap_line(void) {
}
}
+void
+write_buffer(unsigned char c) {
+ text_attrs.letter = c;
+ text_screen[curr_row-1].line[curr_col-1] = text_attrs;
+ text_screen[curr_row-1].needs_update = 1;
+}
+
Received on Tue Mar 13 2007 - 13:38:52 UTC
This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:56:17 UTC