Another poor attempt to fix vim

At least I think I'm geting closer?
This commit is contained in:
Rekketstone 2025-01-16 14:35:29 -07:00
parent d8c40cb367
commit dc7562af52

View File

@ -308,6 +308,9 @@ static void draw_char(Display *display, Drawable d, int x, int y) {
unsigned long fg_color = color_buffer[y][x];
unsigned long bg_color = bg_color_buffer[y][x];
int attrs = attr_buffer[y][x];
static unsigned long last_bg_color = 0;
static int last_x = -1;
static int last_y = -1;
if (attrs & ATTR_REVERSE) {
unsigned long temp = fg_color;
@ -315,19 +318,24 @@ static void draw_char(Display *display, Drawable d, int x, int y) {
bg_color = temp;
}
// Clear the character position first
XSetForeground(display, gc, bg_color);
XFillRectangle(display, d, gc, x * CHAR_WIDTH, y * CHAR_HEIGHT, CHAR_WIDTH,
CHAR_HEIGHT);
if (last_x != x || last_y != y || last_bg_color != bg_color) {
XSetForeground(display, gc, bg_color);
XFillRectangle(display, d, gc, x * CHAR_WIDTH, y * CHAR_HEIGHT, CHAR_WIDTH,
CHAR_HEIGHT);
last_x = x;
last_y = y;
last_bg_color = bg_color;
}
XSetForeground(display, gc, fg_color);
char str[2] = {terminal_buffer[y][x], '\0'};
// Select appropriate font based on attributes
XFontStruct *font = regular_font;
if (attr_buffer[y][x] & ATTR_BOLD) {
if (attrs & ATTR_BOLD) {
font = bold_font;
} else if (attr_buffer[y][x] & ATTR_ITALIC) {
} else if (attrs & ATTR_ITALIC) {
font = italic_font;
}
XSetFont(display, gc, font->fid);
@ -368,10 +376,12 @@ static void draw_terminal(Display *display, Window window) {
term_rows * CHAR_HEIGHT, DefaultDepth(display, DefaultScreen(display)));
}
// Draw to buffer first
for (int y = 0; y < term_rows; y++) {
for (int x = 0; x < term_cols; x++) {
draw_char(display, buffer_pixmap, x, y);
// Only draw the changed parts of the terminal to the buffer
if (needs_refresh) {
for (int y = 0; y < term_rows; y++) {
for (int x = 0; x < term_cols; x++) {
draw_char(display, buffer_pixmap, x, y);
}
}
}
@ -400,22 +410,6 @@ static void check_refresh(Display *display, Window window) {
}
}
static void clear_terminal(Display *display, Window window) {
if (!terminal_buffer || !color_buffer || !attr_buffer || !bg_color_buffer)
return;
for (int y = 0; y < term_rows; y++) {
memset(terminal_buffer[y], ' ', term_cols);
for (int x = 0; x < term_cols; x++) {
color_buffer[y][x] = current_color;
attr_buffer[y][x] = current_attr;
bg_color_buffer[y][x] = current_bg_color;
}
}
cursor_x = 0;
cursor_y = 0;
needs_refresh = 1;
}
// Scroll the terminal up one line
static void scroll_up(void) {
// Move all lines up one position