diff options
author | Matthieu Herrb <matthieu@cvs.openbsd.org> | 2014-01-02 15:14:51 +0000 |
---|---|---|
committer | Matthieu Herrb <matthieu@cvs.openbsd.org> | 2014-01-02 15:14:51 +0000 |
commit | 238f00af31ce204960b9b467fdbd78b8e38388fa (patch) | |
tree | ad1913177a96d700ac268b3f056d27e18c66ae14 /app/xterm/misc.c | |
parent | e9de148a5dd84cc98019847738a1c0a6e9de0242 (diff) |
Update to xterm-300. Tested by ajacoutot@ and shadchin@.
Diffstat (limited to 'app/xterm/misc.c')
-rw-r--r-- | app/xterm/misc.c | 165 |
1 files changed, 126 insertions, 39 deletions
diff --git a/app/xterm/misc.c b/app/xterm/misc.c index 571818bfb..baea82211 100644 --- a/app/xterm/misc.c +++ b/app/xterm/misc.c @@ -1,4 +1,4 @@ -/* $XTermId: misc.c,v 1.670 2013/06/23 22:11:54 tom Exp $ */ +/* $XTermId: misc.c,v 1.682 2013/12/03 23:24:48 tom Exp $ */ /* * Copyright 1999-2012,2013 by Thomas E. Dickey @@ -692,6 +692,82 @@ make_hidden_cursor(XtermWidget xw) return (c); } +/* + * Xlib uses Xcursor to customize cursor coloring, which interferes with + * xterm's pointerColor resource. Work around this by providing our own + * default theme. Testing seems to show that we only have to provide this + * until the window is initialized. + */ +void +init_colored_cursor(void) +{ +#ifdef HAVE_LIB_XCURSOR + const char *theme = "index.theme"; + const char *pattern = "xtermXXXXXXXX"; + const char *tmp_dir; + char *filename; + size_t needed; + FILE *fp; + + xterm_cursor_theme = 0; + if ((tmp_dir = getenv("TMPDIR")) == 0) + tmp_dir = P_tmpdir; + needed = strlen(tmp_dir) + 4 + strlen(theme) + strlen(pattern); + if ((filename = malloc(needed)) != 0) { + sprintf(filename, "%s/%s", tmp_dir, pattern); + +#ifdef HAVE_MKDTEMP + xterm_cursor_theme = mkdtemp(filename); +#else + if (mktemp(filename) != 0 + && mkdir(filename, 0700) == 0) { + xterm_cursor_theme = filename; + } +#endif + /* + * Actually, Xcursor does what _we_ want just by steering its search + * path away from home. We are setting up the complete theme just in + * case the library ever acquires a maintainer. + */ + if (xterm_cursor_theme != 0) { + char *leaf = xterm_cursor_theme + strlen(xterm_cursor_theme); + strcat(leaf, "/"); + strcat(leaf, theme); + if ((fp = fopen(xterm_cursor_theme, "w")) != 0) { + fprintf(fp, "[Icon Theme]\n"); + fclose(fp); + *leaf = '\0'; + xtermSetenv("XCURSOR_PATH", xterm_cursor_theme); + *leaf = '/'; + } + atexit(cleanup_colored_cursor); + } + } +#endif /* HAVE_LIB_XCURSOR */ +} + +/* + * Once done, discard the file and directory holding it. + */ +void +cleanup_colored_cursor(void) +{ +#ifdef HAVE_LIB_XCURSOR + if (xterm_cursor_theme != 0) { + char *my_path = getenv("XCURSOR_PATH"); + struct stat sb; + if (!IsEmpty(my_path) + && stat(my_path, &sb) == 0 + && (sb.st_mode & S_IFMT) == S_IFDIR) { + unlink(xterm_cursor_theme); + rmdir(my_path); + free(xterm_cursor_theme); + xterm_cursor_theme = 0; + } + } +#endif /* HAVE_LIB_XCURSOR */ +} + Cursor make_colored_cursor(unsigned cursorindex, /* index into font */ unsigned long fg, /* pixel value */ @@ -712,7 +788,7 @@ make_colored_cursor(unsigned cursorindex, /* index into font */ void HandleKeyPressed(Widget w GCC_UNUSED, XEvent * event, - String * params GCC_UNUSED, + String *params GCC_UNUSED, Cardinal *nparams GCC_UNUSED) { TRACE(("Handle insert-seven-bit for %p\n", (void *) w)); @@ -723,7 +799,7 @@ HandleKeyPressed(Widget w GCC_UNUSED, void HandleEightBitKeyPressed(Widget w GCC_UNUSED, XEvent * event, - String * params GCC_UNUSED, + String *params GCC_UNUSED, Cardinal *nparams GCC_UNUSED) { TRACE(("Handle insert-eight-bit for %p\n", (void *) w)); @@ -734,7 +810,7 @@ HandleEightBitKeyPressed(Widget w GCC_UNUSED, void HandleStringEvent(Widget w GCC_UNUSED, XEvent * event GCC_UNUSED, - String * params, + String *params, Cardinal *nparams) { @@ -753,7 +829,7 @@ HandleStringEvent(Widget w GCC_UNUSED, value *= 16; if (c >= '0' && c <= '9') value += (unsigned) (c - '0'); - else if ((xxxxxx = strchr(abcdef, c)) != 0) + else if ((xxxxxx = (strchr) (abcdef, c)) != 0) value += (unsigned) (xxxxxx - abcdef) + 10; else break; @@ -779,7 +855,7 @@ HandleStringEvent(Widget w GCC_UNUSED, void HandleSpawnTerminal(Widget w GCC_UNUSED, XEvent * event GCC_UNUSED, - String * params, + String *params, Cardinal *nparams) { TScreen *screen = TScreenOf(term); @@ -873,7 +949,7 @@ HandleSpawnTerminal(Widget w GCC_UNUSED, void HandleInterpret(Widget w GCC_UNUSED, XEvent * event GCC_UNUSED, - String * params, + String *params, Cardinal *param_count) { if (*param_count == 1) { @@ -897,7 +973,7 @@ void HandleEnterWindow(Widget w GCC_UNUSED, XtPointer eventdata GCC_UNUSED, XEvent * event GCC_UNUSED, - Boolean * cont GCC_UNUSED) + Boolean *cont GCC_UNUSED) { /* NOP since we handled it above */ TRACE(("HandleEnterWindow ignored\n")); @@ -909,7 +985,7 @@ void HandleLeaveWindow(Widget w GCC_UNUSED, XtPointer eventdata GCC_UNUSED, XEvent * event GCC_UNUSED, - Boolean * cont GCC_UNUSED) + Boolean *cont GCC_UNUSED) { /* NOP since we handled it above */ TRACE(("HandleLeaveWindow ignored\n")); @@ -921,7 +997,7 @@ void HandleFocusChange(Widget w GCC_UNUSED, XtPointer eventdata GCC_UNUSED, XEvent * ev, - Boolean * cont GCC_UNUSED) + Boolean *cont GCC_UNUSED) { XFocusChangeEvent *event = (XFocusChangeEvent *) ev; XtermWidget xw = term; @@ -1121,7 +1197,7 @@ Bell(XtermWidget xw, int which, int percent) #define VB_DELAY screen->visualBellDelay static void -flashWindow(TScreen * screen, Window window, GC visualGC, unsigned width, unsigned height) +flashWindow(TScreen *screen, Window window, GC visualGC, unsigned width, unsigned height) { int y = 0; int x = 0; @@ -1172,7 +1248,7 @@ void HandleBellPropertyChange(Widget w GCC_UNUSED, XtPointer data GCC_UNUSED, XEvent * ev, - Boolean * more GCC_UNUSED) + Boolean *more GCC_UNUSED) { TScreen *screen = TScreenOf(term); @@ -1251,7 +1327,7 @@ WMFrameWindow(XtermWidget xw) #define MAXWLEN 1024 /* maximum word length as in tcsh */ static int -dabbrev_prev_char(TScreen * screen, CELL * cell, LineData ** ld) +dabbrev_prev_char(TScreen *screen, CELL *cell, LineData **ld) { int result = -1; int firstLine = -(screen->savedlines); @@ -1275,7 +1351,7 @@ dabbrev_prev_char(TScreen * screen, CELL * cell, LineData ** ld) } static char * -dabbrev_prev_word(TScreen * screen, CELL * cell, LineData ** ld) +dabbrev_prev_word(TScreen *screen, CELL *cell, LineData **ld) { static char ab[MAXWLEN]; @@ -1310,7 +1386,7 @@ dabbrev_prev_word(TScreen * screen, CELL * cell, LineData ** ld) } static int -dabbrev_expand(TScreen * screen) +dabbrev_expand(TScreen *screen) { int pty = screen->respond; /* file descriptor of pty */ @@ -1412,7 +1488,7 @@ dabbrev_expand(TScreen * screen) void HandleDabbrevExpand(Widget w, XEvent * event GCC_UNUSED, - String * params GCC_UNUSED, + String *params GCC_UNUSED, Cardinal *nparams GCC_UNUSED) { XtermWidget xw; @@ -1431,7 +1507,7 @@ HandleDabbrevExpand(Widget w, void HandleDeIconify(Widget w, XEvent * event GCC_UNUSED, - String * params GCC_UNUSED, + String *params GCC_UNUSED, Cardinal *nparams GCC_UNUSED) { XtermWidget xw; @@ -1446,7 +1522,7 @@ HandleDeIconify(Widget w, void HandleIconify(Widget w, XEvent * event GCC_UNUSED, - String * params GCC_UNUSED, + String *params GCC_UNUSED, Cardinal *nparams GCC_UNUSED) { XtermWidget xw; @@ -1613,7 +1689,7 @@ RequestMaximize(XtermWidget xw, int maximize) void HandleMaximize(Widget w, XEvent * event GCC_UNUSED, - String * params GCC_UNUSED, + String *params GCC_UNUSED, Cardinal *nparams GCC_UNUSED) { XtermWidget xw; @@ -1627,7 +1703,7 @@ HandleMaximize(Widget w, void HandleRestoreSize(Widget w, XEvent * event GCC_UNUSED, - String * params GCC_UNUSED, + String *params GCC_UNUSED, Cardinal *nparams GCC_UNUSED) { XtermWidget xw; @@ -1848,7 +1924,7 @@ creat_as(uid_t uid, gid_t gid, Bool append, char *pathname, unsigned mode) #endif /* !VMS */ int -xtermResetIds(TScreen * screen) +xtermResetIds(TScreen *screen) { int result = 0; if (setgid(screen->gid) == -1) { @@ -2096,7 +2172,7 @@ ReportAnsiColorRequest(XtermWidget xw, int colornum, int final) } static void -getColormapInfo(Display * display, unsigned *typep, unsigned *sizep) +getColormapInfo(Display *display, unsigned *typep, unsigned *sizep) { int numFound; XVisualInfo myTemplate, *visInfoPtr; @@ -2706,7 +2782,7 @@ xtermClosestColor(XtermWidget xw, int find_red, int find_green, int find_blue) #if OPT_PASTE64 static void -ManipulateSelectionData(XtermWidget xw, TScreen * screen, char *buf, int final) +ManipulateSelectionData(XtermWidget xw, TScreen *screen, char *buf, int final) { #define PDATA(a,b) { a, #b } static struct { @@ -2774,7 +2850,7 @@ ManipulateSelectionData(XtermWidget xw, TScreen * screen, char *buf, int final) /* terminator will be written in this call */ xtermGetSelection((Widget) xw, - (Time) 0, + XtLastTimestampProcessed(TScreenOf(xw)->display), select_args, n, NULL); } @@ -2800,7 +2876,7 @@ ManipulateSelectionData(XtermWidget xw, TScreen * screen, char *buf, int final) #define IsSetUtf8Title(xw) (IsTitleMode(xw, tmSetUtf8) || (xw->screen.utf8_title)) static Bool -xtermIsPrintable(XtermWidget xw, Char ** bufp, Char * last) +xtermIsPrintable(XtermWidget xw, Char **bufp, Char *last) { TScreen *screen = TScreenOf(xw); Bool result = False; @@ -3125,7 +3201,7 @@ ResetColorsRequest(XtermWidget xw, * the corresponding menu font entry. */ static int -ParseShiftedFont(XtermWidget xw, String source, String * target) +ParseShiftedFont(XtermWidget xw, String source, String *target) { TScreen *screen = TScreenOf(xw); int num = screen->menu_font_number; @@ -3290,7 +3366,7 @@ ChangeFontRequest(XtermWidget xw, String buf) /***====================================================================***/ void -do_osc(XtermWidget xw, Char * oscbuf, size_t len, int final) +do_osc(XtermWidget xw, Char *oscbuf, size_t len, int final) { TScreen *screen = TScreenOf(xw); int mode; @@ -3638,7 +3714,7 @@ parse_decudk(const char *cp) * interspersing with control characters, but have the string already. */ static void -parse_ansi_params(ANSI * params, const char **string) +parse_ansi_params(ANSI *params, const char **string) { const char *cp = *string; ParmType nparam = 0; @@ -3681,7 +3757,7 @@ parse_ansi_params(ANSI * params, const char **string) #define SOFT_HIGH 20 static void -parse_decdld(ANSI * params, const char *string) +parse_decdld(ANSI *params, const char *string) { char DscsName[8]; int len; @@ -3791,7 +3867,7 @@ parse_decdld(ANSI * params, const char *string) #endif void -do_dcs(XtermWidget xw, Char * dcsbuf, size_t dcslen) +do_dcs(XtermWidget xw, Char *dcsbuf, size_t dcslen) { TScreen *screen = TScreenOf(xw); char reply[BUFSIZ]; @@ -5231,7 +5307,7 @@ xtermUnsetenv(const char *var) /*ARGSUSED*/ int -xerror(Display * d, XErrorEvent * ev) +xerror(Display *d, XErrorEvent * ev) { xtermWarning("warning, error event received:\n"); (void) XmuPrintDefaultErrorMessage(d, ev, stderr); @@ -5252,7 +5328,7 @@ ice_error(IceConn iceConn) /*ARGSUSED*/ int -xioerror(Display * dpy) +xioerror(Display *dpy) { int the_error = errno; @@ -5292,7 +5368,7 @@ XStrCmp(char *s1, char *s2) #if OPT_TEK4014 static void -withdraw_window(Display * dpy, Window w, int scr) +withdraw_window(Display *dpy, Window w, int scr) { TRACE(("withdraw_window %#lx\n", (long) w)); (void) XmuUpdateMapHints(dpy, w, NULL); @@ -5649,7 +5725,18 @@ xtermEnvUTF8(void) #ifdef HAVE_LANGINFO_CODESET result = (strcmp(xtermEnvEncoding(), "UTF-8") == 0); #else - result = (strstr(xtermEnvLocale(), "UTF-8") != NULL); + { + char *locale = x_strdup(xtermEnvLocale()); + int n; + for (n = 0; locale[n] != 0; ++n) { + locale[n] = x_toupper(locale[n]); + } + if (strstr(locale, "UTF-8") != 0) + result = True; + else if (strstr(locale, "UTF8") != 0) + result = True; + free(locale); + } #endif TRACE(("xtermEnvUTF8 ->%s\n", BtoS(result))); } @@ -5736,8 +5823,8 @@ xtermOpenApplication(XtAppContext * app_context_return, XrmOptionDescRec * options, Cardinal num_options, int *argc_in_out, - String * argv_in_out, - String * fallback_resources, + String *argv_in_out, + String *fallback_resources, WidgetClass widget_class, ArgList args, Cardinal num_args) @@ -5775,7 +5862,7 @@ xtermOpenApplication(XtAppContext * app_context_return, static int x11_errors; static int -catch_x11_error(Display * display, XErrorEvent * error_event) +catch_x11_error(Display *display, XErrorEvent * error_event) { (void) display; (void) error_event; @@ -5784,7 +5871,7 @@ catch_x11_error(Display * display, XErrorEvent * error_event) } Boolean -xtermGetWinAttrs(Display * dpy, Window win, XWindowAttributes * attrs) +xtermGetWinAttrs(Display *dpy, Window win, XWindowAttributes * attrs) { Boolean result = False; Status code; @@ -5806,7 +5893,7 @@ xtermGetWinAttrs(Display * dpy, Window win, XWindowAttributes * attrs) } Boolean -xtermGetWinProp(Display * display, +xtermGetWinProp(Display *display, Window win, Atom property, long long_offset, |