From 5ee36e0fd6d6f627c68827edd6f5094035d13510 Mon Sep 17 00:00:00 2001 From: Michael Jennings Date: Tue, 14 Sep 1999 23:22:06 +0000 Subject: [PATCH] Tue Sep 14 16:41:08 PDT 1999 Michael Jennings Worked around a XF86 3.9.16 (perhaps Xinerama) problem. Also added some XIM changes from Sung-Hyun Nam to handle buffer overflows. SVN revision: 274 --- ChangeLog | 7 ++++++ src/events.c | 19 ++++++++++------- src/feature.h | 7 +----- src/options.c | 27 +++++++---------------- src/options.h | 2 +- src/screen.c | 16 -------------- src/screen.h | 2 +- src/scrollbar.c | 3 ++- src/term.c | 57 +++++++++++++++++++++++++++++++------------------ src/windows.c | 13 ++++------- 10 files changed, 71 insertions(+), 82 deletions(-) diff --git a/ChangeLog b/ChangeLog index bbcdd38..a09fe39 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2386,3 +2386,10 @@ Mon Sep 13 12:23:36 PDT 1999 Michael Jennings without all the crap on the command line. :-) ------------------------------------------------------------------------------- +Tue Sep 14 16:41:08 PDT 1999 Michael Jennings + + Worked around a XF86 3.9.16 (perhaps Xinerama) problem. Also added + some XIM changes from Sung-Hyun Nam to handle + buffer overflows. + +------------------------------------------------------------------------------- diff --git a/src/events.c b/src/events.c index a62c533..f6ff1bb 100644 --- a/src/events.c +++ b/src/events.c @@ -242,7 +242,7 @@ handle_property_notify(event_t * ev) free_desktop_pixmap(); } render_simage(images[image_bg].current, TermWin.vt, TermWin_TotalWidth(), TermWin_TotalHeight(), image_bg, 1); - scr_expose(0, 0, TermWin_TotalWidth(), TermWin_TotalHeight()); + scr_touch(); scrollbar_show(0); } else if (ev->xany.window == desktop_window) { @@ -254,7 +254,7 @@ handle_property_notify(event_t * ev) free_desktop_pixmap(); } render_simage(images[image_bg].current, TermWin.vt, TermWin_TotalWidth(), TermWin_TotalHeight(), image_bg, 1); - scr_expose(0, 0, TermWin_TotalWidth(), TermWin_TotalHeight()); + scr_touch(); scrollbar_show(0); } } @@ -321,16 +321,15 @@ handle_visibility_notify(event_t * ev) REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); switch (ev->xvisibility.state) { case VisibilityUnobscured: -#ifdef USE_SMOOTH_REFRESH - refresh_type = SMOOTH_REFRESH; -#else + D_X11(("handle_visibility_notify(): Window completely visible\n")); refresh_type = FAST_REFRESH; -#endif break; case VisibilityPartiallyObscured: + D_X11(("handle_visibility_notify(): Window partially hidden\n")); refresh_type = SLOW_REFRESH; break; default: + D_X11(("handle_visibility_notify(): Window completely hidden\n")); refresh_type = NO_REFRESH; break; } @@ -349,7 +348,7 @@ handle_focus_in(event_t * ev) if (background_is_pixmap() && (images[image_bg].norm != images[image_bg].selected)) { images[image_bg].current = images[image_bg].selected; render_simage(images[image_bg].current, TermWin.vt, TermWin_TotalWidth(), TermWin_TotalHeight(), image_bg, 1); - scr_expose(0, 0, TermWin_TotalWidth(), TermWin_TotalHeight()); + scr_touch(); } if (Options & Opt_scrollbar_popup) { map_scrollbar(Options & Opt_scrollBar); @@ -374,7 +373,7 @@ handle_focus_out(event_t * ev) if (background_is_pixmap() && (images[image_bg].norm != images[image_bg].selected)) { images[image_bg].current = images[image_bg].norm; render_simage(images[image_bg].current, TermWin.vt, TermWin_TotalWidth(), TermWin_TotalHeight(), image_bg, 1); - scr_expose(0, 0, TermWin_TotalWidth(), TermWin_TotalHeight()); + scr_touch(); } if (Options & Opt_scrollbar_popup) { map_scrollbar(0); @@ -450,6 +449,10 @@ handle_expose(event_t * ev) REQUIRE_RVAL(XEVENT_IS_MYWIN(ev, &primary_data), 0); if (ev->xany.window == TermWin.vt) { + if (refresh_type == NO_REFRESH) { + print_warning("Received Expose event while obscured. Possible X server bug!"); + refresh_type = FAST_REFRESH; + } scr_expose(ev->xexpose.x, ev->xexpose.y, ev->xexpose.width, ev->xexpose.height); } else { diff --git a/src/feature.h b/src/feature.h index 1107d3b..ee059ff 100644 --- a/src/feature.h +++ b/src/feature.h @@ -188,9 +188,6 @@ /* Continuous scrolling by pressing the scrollbar arrow buttons */ #define SCROLLBAR_BUTTON_CONTINUAL_SCROLLING -/* To allow smooth refresh when the terminal window is fully unobscured. */ -/* #define USE_SMOOTH_REFRESH */ - /* Delay periods for continuous scrolling */ /* #define SCROLLBAR_INITIAL_DELAY 40 */ /* #define SCROLLBAR_CONTINUOUS_DELAY 2 */ @@ -368,9 +365,7 @@ inline void *memmove(void *, const void *, size_t); # define NSCREENS 1 #endif -#ifdef USE_SMOOTH_REFRESH -# define DEFAULT_REFRESH SMOOTH_REFRESH -#else +#ifndef DEFAULT_REFRESH # define DEFAULT_REFRESH FAST_REFRESH #endif diff --git a/src/options.c b/src/options.c index 04850ff..b1db043 100644 --- a/src/options.c +++ b/src/options.c @@ -253,7 +253,7 @@ static char *rs_greek_keyboard = NULL; #endif #ifdef PIXMAP_SUPPORT char *rs_pixmapScale = NULL; -const char *rs_saveUnder = NULL; +const char *rs_backing_store = NULL; char *rs_icon = NULL; char *rs_cmod_image = NULL; char *rs_cmod_red = NULL; @@ -429,9 +429,7 @@ static const struct { #ifdef META8_OPTION OPT_BOOL('8', "meta-8", "Meta key toggles 8-bit", &rs_meta8, &Options, Opt_meta8), #endif -#ifdef BACKING_STORE - OPT_BLONG("save-under", "use backing store", &rs_saveUnder, &Options, Opt_saveUnder), -#endif + OPT_BLONG("backing-store", "use backing store", &rs_backing_store, &Options, Opt_backing_store), OPT_BLONG("no-cursor", "disable the text cursor", &rs_noCursor, &Options, Opt_noCursor), OPT_BLONG("pause", "pause for a keypress after the child process exits", &rs_pause, &Options, Opt_pause), OPT_BLONG("xterm-select", "duplicate xterm's broken selection behavior", &rs_xterm_select, &Options, Opt_xterm_select), @@ -792,11 +790,6 @@ version(void) #else printf(" -SCROLLBAR_BUTTON_CONTINUAL_SCROLLING"); #endif -#ifdef USE_SMOOTH_REFRESH - printf(" +USE_SMOOTH_REFRESH"); -#else - printf(" -USE_SMOOTH_REFRESH"); -#endif #ifdef MENU_SHADOW_IN printf(" +MENU_SHADOW_IN"); #else @@ -2078,18 +2071,14 @@ parse_toggles(char *buff) Options &= ~(Opt_borderless); rs_borderless = *false_vals; } - } else if (!BEG_STRCASECMP(buff, "save_under ")) { -#ifdef BACKING_STORE + } else if (!BEG_STRCASECMP(buff, "backing_store ")) { if (bool_val) { - Options |= Opt_saveUnder; - rs_saveUnder = *true_vals; + Options |= Opt_backing_store; + rs_backing_store = *true_vals; } else { - Options &= ~(Opt_saveUnder); - rs_saveUnder = *false_vals; + Options &= ~(Opt_backing_store); + rs_backing_store = *false_vals; } -#else - print_warning("Support for the save_under attribute was not compiled in, ignoring"); -#endif } else if (!BEG_STRCASECMP(buff, "no_cursor ")) { if (bool_val) { @@ -3626,7 +3615,7 @@ save_config(char *path) fprintf(fp, " scrollbar_right %d\n", (Options & Opt_scrollBar_right ? 1 : 0)); fprintf(fp, " scrollbar_popup %d\n", (Options & Opt_scrollbar_popup ? 1 : 0)); fprintf(fp, " borderless %d\n", (Options & Opt_borderless ? 1 : 0)); - fprintf(fp, " save_under %d\n", (Options & Opt_saveUnder ? 1 : 0)); + fprintf(fp, " backing_store %d\n", (Options & Opt_backing_store ? 1 : 0)); fprintf(fp, " no_cursor %d\n", (Options & Opt_noCursor ? 1 : 0)); fprintf(fp, " pause %d\n", (Options & Opt_pause ? 1 : 0)); fprintf(fp, " xterm_select %d\n", (Options & Opt_xterm_select ? 1 : 0)); diff --git a/src/options.h b/src/options.h index 86a3675..b660e1a 100644 --- a/src/options.h +++ b/src/options.h @@ -67,7 +67,7 @@ # define Opt_scrollBar_right (1LU << 14) # define Opt_borderless (1LU << 15) # define Opt_pixmapTrans (1LU << 16) -# define Opt_saveUnder (1LU << 17) +# define Opt_backing_store (1LU << 17) # define Opt_noCursor (1LU << 18) # define Opt_pause (1LU << 19) # define Opt_homeOnInput (1LU << 20) diff --git a/src/screen.c b/src/screen.c index 412c3d9..1833c46 100644 --- a/src/screen.c +++ b/src/screen.c @@ -1638,20 +1638,6 @@ scr_expose(int x, int y, int width, int height) #endif } -/* ------------------------------------------------------------------------- */ -/* - * Refresh the entire screen - */ -#ifdef __GNUC__ -inline void -#else -void -#endif -scr_touch(void) -{ - scr_expose(0, 0, TermWin.width, TermWin.height); -} - /* ------------------------------------------------------------------------- */ /* * Move the display so that the line represented by scrollbar value Y is at @@ -2184,8 +2170,6 @@ scr_refresh(int type) #if defined(PIXMAP_SUPPORT) && defined(PIXMAP_BUFFERING) XClearWindow(Xdisplay, TermWin.vt); #endif - if (type & SMOOTH_REFRESH) - XSync(Xdisplay, False); D_SCREEN(("scr_refresh() exiting.\n")); #ifdef PROFILE_SCREEN diff --git a/src/screen.h b/src/screen.h index bef0128..6424ff8 100644 --- a/src/screen.h +++ b/src/screen.h @@ -32,6 +32,7 @@ #define CHECK_SELECTION do { \ if (selection.op) selection_check(); \ } while (0) +#define scr_touch() scr_expose(0, 0, TermWin.width, TermWin.height) /* * CLEAR_ROWS : clear rows starting from row @@ -254,7 +255,6 @@ extern void set_multichar_encoding(const char *); extern int scr_get_fgcolor(void); extern int scr_get_bgcolor(void); extern void scr_expose(int, int, int, int); -extern void scr_touch(void); extern int scr_move_to(int, int); extern int scr_page(int, int); extern void scr_bell(void); diff --git a/src/scrollbar.c b/src/scrollbar.c index 9212750..2e019e5 100644 --- a/src/scrollbar.c +++ b/src/scrollbar.c @@ -203,12 +203,13 @@ scrollbar_init(void) Attributes.background_pixel = PixColors[scrollColor]; Attributes.border_pixel = PixColors[bgColor]; Attributes.override_redirect = TRUE; + Attributes.save_under = TRUE; cursor = XCreateFontCursor(Xdisplay, XC_left_ptr); mask = ExposureMask | EnterWindowMask | LeaveWindowMask | ButtonPressMask | ButtonReleaseMask | Button1MotionMask | Button2MotionMask | Button3MotionMask; scrollBar.win = XCreateWindow(Xdisplay, TermWin.parent, 0, 0, 1, 1, 0, Xdepth, InputOutput, CopyFromParent, - CWOverrideRedirect | CWSaveUnder | CWBackingStore | CWBackPixel | CWBorderPixel | CWColormap, &Attributes); + CWOverrideRedirect | CWBackingStore | CWBackPixel | CWBorderPixel | CWColormap, &Attributes); XDefineCursor(Xdisplay, scrollBar.win, cursor); XSelectInput(Xdisplay, scrollBar.win, mask); diff --git a/src/term.c b/src/term.c index be33d81..be9e622 100644 --- a/src/term.c +++ b/src/term.c @@ -93,17 +93,27 @@ char *def_colorName[] = char *rs_color[NRS_COLORS]; Pixel PixColors[NRS_COLORS + NSHADOWCOLORS]; +/* To handle buffer overflows properly, we must malloc a buffer. Free it when done. */ +#ifdef USE_XIM +# define LK_RET() do {if (kbuf_alloced) FREE(kbuf); return;} while (0) +#else +# define LK_RET() return +#endif /* Convert the keypress event into a string */ void lookup_key(XEvent * ev) { static int numlock_state = 0; - static unsigned char kbuf[KBUFSZ]; int ctrl, meta, shft, len; KeySym keysym; #ifdef USE_XIM int valid_keysym; + static unsigned char short_buf[256]; + unsigned char *kbuf = short_buf; + int kbuf_alloced = 0; +#else + static unsigned char kbuf[KBUFSZ]; #endif #if DEBUG >= DEBUG_CMD static int debug_key = 1; /* accessible by a debugger only */ @@ -130,11 +140,16 @@ lookup_key(XEvent * ev) Status status_return; kbuf[0] = '\0'; - len = XmbLookupString(Input_Context, &ev->xkey, kbuf, sizeof(kbuf), - &keysym, &status_return); + len = XmbLookupString(Input_Context, &ev->xkey, (char *)kbuf, + sizeof(short_buf), &keysym, &status_return); + if (status_return == XBufferOverflow) { + kbuf = (unsigned char *) MALLOC(len + 1); + kbuf_alloced = 1; + len = XmbLookupString(Input_Context, &ev->xkey, (char *)kbuf, len, &keysym, &status_return); + } valid_keysym = (status_return == XLookupKeySym) || (status_return == XLookupBoth); } else { - len = XLookupString(&ev->xkey, kbuf, sizeof(kbuf), &keysym, NULL); + len = XLookupString(&ev->xkey, kbuf, sizeof(short_buf), &keysym, NULL); } #else /* USE_XIM */ len = XLookupString(&ev->xkey, kbuf, sizeof(kbuf), &keysym, NULL); @@ -154,7 +169,7 @@ lookup_key(XEvent * ev) #endif if (action_dispatch(ev, keysym)) { - return; + LK_RET(); } if (len) { if (keypress_exit) { @@ -167,17 +182,17 @@ lookup_key(XEvent * ev) if ((Options & Opt_report_as_keysyms) && (keysym >= 0xff00)) { len = sprintf(kbuf, "\e[k%X;%X~", (unsigned int) (ev->xkey.state & 0xff), (unsigned int) (keysym & 0xff)); tt_write(kbuf, len); - return; + LK_RET(); } #ifdef HOTKEY /* for some backwards compatibility */ if (HOTKEY) { if (keysym == ks_bigfont) { change_font(0, FONT_UP); - return; + LK_RET(); } else if (keysym == ks_smallfont) { change_font(0, FONT_DN); - return; + LK_RET(); } } #endif @@ -202,31 +217,31 @@ lookup_key(XEvent * ev) case XK_Prior: /* Shift+Prior = scroll back */ if (TermWin.saveLines) { scr_page(UP, lnsppg); - return; + LK_RET(); } break; case XK_Next: /* Shift+Next = scroll forward */ if (TermWin.saveLines) { scr_page(DN, lnsppg); - return; + LK_RET(); } break; case XK_Insert: /* Shift+Insert = paste mouse selection */ selection_request(ev->xkey.time, ev->xkey.x, ev->xkey.y); - return; + LK_RET(); break; /* Eterm extras */ case XK_KP_Add: /* Shift+KP_Add = bigger font */ change_font(0, FONT_UP); - return; + LK_RET(); break; case XK_KP_Subtract: /* Shift+KP_Subtract = smaller font */ change_font(0, FONT_DN); - return; + LK_RET(); break; } } @@ -237,14 +252,14 @@ lookup_key(XEvent * ev) case XK_Prior: if (TermWin.saveLines) { scr_page(UP, TermWin.nrow * 4 / 5); - return; + LK_RET(); } break; case XK_Next: if (TermWin.saveLines) { scr_page(DN, TermWin.nrow * 4 / 5); - return; + LK_RET(); } break; } @@ -260,7 +275,7 @@ lookup_key(XEvent * ev) #endif #ifdef PRINTPIPE scr_printscreen(ctrl | shft); - return; + LK_RET(); #endif break; @@ -272,7 +287,7 @@ lookup_key(XEvent * ev) greek_reset(); } else xterm_seq(XTerm_title, APL_NAME "-" VERSION); - return; + LK_RET(); #endif break; } @@ -298,7 +313,7 @@ lookup_key(XEvent * ev) tt_write(&ch, 1); } tt_write(kbuf, len); - return; + LK_RET(); } else #endif switch (keysym) { @@ -598,7 +613,7 @@ sprintf(kbuf,"\033[%02d~", (int)((n) + (keysym - fkey))); \ #endif if (len <= 0) - return; /* not mapped */ + LK_RET(); /* not mapped */ /* * these modifications only affect the static keybuffer @@ -1150,7 +1165,7 @@ process_window_mode(unsigned int nargs, int args[]) XClearWindow(Xdisplay, TermWin.vt); XSync(Xdisplay, False); scr_touch(); - scr_refresh(SMOOTH_REFRESH); + scr_refresh(DEFAULT_REFRESH); break; case 8: if (i + 2 >= nargs) @@ -1795,7 +1810,7 @@ xterm_seq(int op, const char *str) free_desktop_pixmap(); } render_simage(images[image_bg].current, TermWin.vt, TermWin_TotalWidth(), TermWin_TotalHeight(), image_bg, 1); - scr_expose(0, 0, TermWin_TotalWidth(), TermWin_TotalHeight()); + scr_touch(); } break; #endif diff --git a/src/windows.c b/src/windows.c index 7fc266e..3e3a5d8 100644 --- a/src/windows.c +++ b/src/windows.c @@ -169,7 +169,6 @@ Create_Windows(int argc, char *argv[]) } else { mwmhints.flags = 0; } - Attributes.save_under = TRUE; Attributes.backing_store = WhenMapped; Attributes.colormap = cmap; @@ -400,19 +399,15 @@ Create_Windows(int argc, char *argv[]) cursor = XCreateFontCursor(Xdisplay, XC_left_ptr); /* the vt window */ - -#ifdef BACKING_STORE - if ((!(Options & Opt_borderless)) && (Options & Opt_saveUnder)) { + if ((!(Options & Opt_borderless)) && (Options & Opt_backing_store)) { D_X11(("Creating term window with save_under = TRUE\n")); TermWin.vt = XCreateWindow(Xdisplay, TermWin.parent, 0, 0, szHint.width, szHint.height, 0, Xdepth, InputOutput, CopyFromParent, - CWBackPixel | CWBorderPixel | CWOverrideRedirect | CWSaveUnder | CWBackingStore | CWColormap, &Attributes); + CWBackPixel | CWBorderPixel | CWOverrideRedirect | CWBackingStore | CWColormap, &Attributes); if (!(background_is_pixmap()) && !(Options & Opt_borderless)) { XSetWindowBackground(Xdisplay, TermWin.vt, PixColors[bgColor]); XClearWindow(Xdisplay, TermWin.vt); } - } else -#endif - { + } else { D_X11(("Creating term window with no backing store\n")); TermWin.vt = XCreateWindow(Xdisplay, TermWin.parent, 0, 0, szHint.width, szHint.height, 0, Xdepth, InputOutput, CopyFromParent, CWBackPixel | CWBorderPixel | CWOverrideRedirect | CWColormap, &Attributes); @@ -610,7 +605,7 @@ resize_window1(unsigned int width, unsigned int height) || ((Options & Opt_viewport_mode) || (images[image_bg].mode & MODE_VIEWPORT))) { resize_subwindows(width, height); scrollbar_show(0); - scr_expose(0, 0, width, height); + scr_touch(); } }