changeset: 60:d5a6a8ab8857
tag: tip
user: Anselm R. Garbe <arg_AT_suckless.org>
date: Mon Mar 05 14:50:53 2007 +0100
summary: moved gc into DC
diff -r 265c6ff60a2b -r d5a6a8ab8857 main.c
--- a/main.c Fri Mar 02 16:11:38 2007 +0100
+++ b/main.c Mon Mar 05 14:50:53 2007 +0100
@@ -118,11 +118,11 @@ initwin(void) {
XMapWindow(dpy, win);
/* Wait for the window to be mapped */
wait_for_specific_event(MapNotify);
- gc = XCreateGC(dpy, win, 0, NULL);
- XSetForeground(dpy, gc, dc.fg[0]);
- XSetBackground(dpy, gc, dc.bg[0]);
+ dc.gc = XCreateGC(dpy, win, 0, NULL);
+ XSetForeground(dpy, dc.gc, dc.fg[0]);
+ XSetBackground(dpy, dc.gc, dc.bg[0]);
if(!dc.font.set)
- XSetFont(dpy, gc, dc.font.xfont->fid);
+ XSetFont(dpy, dc.gc, dc.font.xfont->fid);
XDefineCursor(dpy, win, cursor);
sh.x = sh.y = 0;
sh.width = ww;
@@ -146,8 +146,6 @@ DC dc = { 0 };
DC dc = { 0 };
Display *dpy;
Window win, root;
-GC gc;
-Colormap cmap;
Cursor cursor;
int screen;
int ww;
@@ -176,7 +174,6 @@ main(int argc, char **argv) {
eprint("cannot open display\n");
screen = DefaultScreen(dpy);
root = RootWindow(dpy, screen);
- cmap = DefaultColormap(dpy, screen);
if(!(cursor = XCreateFontCursor(dpy, XC_xterm)))
eprint("cannot create cursor\n");
initcolors();
diff -r 265c6ff60a2b -r d5a6a8ab8857 st.h
--- a/st.h Fri Mar 02 16:11:38 2007 +0100
+++ b/st.h Mon Mar 05 14:50:53 2007 +0100
@@ -43,6 +43,7 @@ typedef struct {
unsigned long *fg;
unsigned int nbg;
unsigned long *bg;
+ GC gc;
struct {
XFontStruct *xfont;
XFontSet set;
@@ -71,8 +72,6 @@ extern Row *saved_screen;
extern Row *saved_screen;
extern Display *dpy;
extern Window win, root;
-extern GC gc;
-extern Colormap cmap;
extern Cursor cursor;
extern int screen;
extern int ww;
diff -r 265c6ff60a2b -r d5a6a8ab8857 vt.c
--- a/vt.c Fri Mar 02 16:11:38 2007 +0100
+++ b/vt.c Mon Mar 05 14:50:53 2007 +0100
@@ -24,16 +24,16 @@ wait_for_specific_event(int event_type)
void
win_clear_region(int x1, int y1, int x2, int y2, int color) {
- XSetBackground(dpy, gc, color);
+ XSetBackground(dpy, dc.gc, color);
XClearArea(dpy, win, x1, y1, x2 - x1, y2 - y1, 0);
}
void
win_draw_string(int row, int col, char *s, int l) {
if(dc.font.set)
- XmbDrawImageString(dpy, win, dc.font.set, gc, col * dc.font.width, row * dc.font.height + dc.font.ascent, s, l);
+ 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, gc, col * dc.font.width, row * dc.font.height + dc.font.ascent, s, l);
+ XDrawImageString(dpy, win, dc.gc, col * dc.font.width, row * dc.font.height + dc.font.ascent, s, l);
}
void
@@ -43,46 +43,28 @@ win_set_window_title(char *title) {
void
window_scroll_up(int lines) {
- XCopyArea(dpy, win, win, 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));
+ 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));
}
void
region_scroll_up(int start, int end, int lines) {
- XCopyArea(dpy, win, win, gc,
- 0, (start - 1 + lines) * dc.font.height,
- ww, (end - start + 2 - lines) * dc.font.height,
+ 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));
+ win_clear_region(0, (end - lines) * dc.font.height, ww, end * dc.font.height, GET_BG_COLOR(text_attrs));
}
void
window_scroll_down(int lines) {
- XCopyArea(dpy, win, win, 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));
+ 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));
}
void
region_scroll_down(int start, int end, int lines) {
- XCopyArea(dpy, win, win, gc,
- 0, (start - 1) * dc.font.height,
- ww, (end - start + 2 - lines) * dc.font.height,
+ 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));
+ win_clear_region(0, (start - 1) * dc.font.height, ww, (start + lines - 1) * dc.font.height, GET_BG_COLOR(text_attrs));
}
void
@@ -94,12 +76,12 @@ set_text_attrs(Glyph l) {
else
fg = l.fg, bg = l.bg;
if(l.bold && fg == 0)
- XSetForeground(dpy, gc, dc.fg[8]);
+ XSetForeground(dpy, dc.gc, dc.fg[8]);
else
- XSetForeground(dpy, gc, dc.fg[fg]);
+ XSetForeground(dpy, dc.gc, dc.fg[fg]);
if(!dc.font.set)
- XSetFont(dpy, gc, dc.font.xfont->fid);
- XSetBackground(dpy, gc, dc.bg[bg]);
+ XSetFont(dpy, dc.gc, dc.font.xfont->fid);
+ XSetBackground(dpy, dc.gc, dc.bg[bg]);
}
/* Max number of characters to be drawn at once */
@@ -201,11 +183,11 @@ show_cursor(void) {
if(curr_col > screen_cols)
cursor_col = screen_cols;
if(!dc.font.set)
- XSetFont(dpy, gc, dc.font.xfont->fid);
+ XSetFont(dpy, dc.gc, dc.font.xfont->fid);
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, dc.fg[0]);
- XSetForeground(dpy, gc, dc.fg[0]);
- XSetBackground(dpy, gc, dc.fg[1]);
+ XSetForeground(dpy, dc.gc, dc.fg[0]);
+ XSetBackground(dpy, dc.gc, dc.fg[1]);
win_draw_string(cursor_row - 1, cursor_col - 1, &(text_screen[cursor_row - 1].line[cursor_col - 1]), 1);
XFlush(dpy);
cursor_is_visible = 1;
Received on Mon Mar 05 2007 - 14:54:23 UTC
This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:56:10 UTC