--- rxvt-unicode/src/rxvt.h 2012/05/25 08:27:47 1.484 +++ rxvt-unicode/src/rxvt.h 2021/05/07 19:03:11 1.554 @@ -72,22 +72,24 @@ #include #include -#ifdef HAVE_PIXBUF +#if HAVE_PIXBUF # include #endif -#if defined(BG_IMAGE_FROM_FILE) || defined(ENABLE_TRANSPARENCY) -# define HAVE_BG_PIXMAP 1 +#if XRENDER && (HAVE_PIXBUF || ENABLE_TRANSPARENCY) +# define HAVE_IMG 1 #endif -#include +#define ECB_NO_THREADS 1 +#include "ecb.h" + #include "encoding.h" #include "rxvtutil.h" #include "rxvtfont.h" #include "rxvttoolkit.h" +#include "rxvtimg.h" #include "scrollbar.h" #include "ev_cpp.h" -#include "salloc.h" #include "libptytty.h" #include "rxvtperl.h" @@ -150,11 +152,17 @@ void rxvt_vlog (const char *fmt, va_list arg_ptr) NOTHROW; void rxvt_log (const char *fmt,...) NOTHROW; void rxvt_warn (const char *fmt,...) NOTHROW; -void rxvt_fatal (const char *fmt, ...) THROW ((class rxvt_failure_exception)) ecb_noreturn; -void rxvt_exit_failure () THROW ((class rxvt_failure_exception)) ecb_noreturn; +ecb_noreturn ecb_cold +void rxvt_fatal (const char *fmt, ...) THROW ((class rxvt_failure_exception)); +ecb_noreturn ecb_cold +void rxvt_exit_failure () THROW ((class rxvt_failure_exception)); + +void * rxvt_malloc (size_t size); +void * rxvt_calloc (size_t number, size_t size); +void * rxvt_realloc (void *ptr, size_t size); -char * rxvt_strtrim (char *str) NOTHROW; -char ** rxvt_strsplit (char delim, const char *str) NOTHROW; +char * rxvt_strtrim (char *str) NOTHROW; +char ** rxvt_strsplit (char delim, const char *str) NOTHROW; static inline void rxvt_free_strsplit (char **ptr) NOTHROW @@ -163,9 +171,7 @@ free (ptr); } -void * rxvt_malloc (size_t size); -void * rxvt_calloc (size_t number, size_t size); -void * rxvt_realloc (void *ptr, size_t size); +KeySym rxvt_XKeycodeToKeysym (Display *dpy, KeyCode keycode, int index); ///////////////////////////////////////////////////////////////////////////// @@ -174,17 +180,6 @@ extern char **rxvt_environ; // the original environ pointer static inline void -set_environ (stringvec *envv) -{ -#if ENABLE_PERL - assert (envv); -#else - if (envv) -#endif - environ = (char **)envv->begin (); -} - -static inline void set_environ (char **envv) { #if ENABLE_PERL @@ -211,55 +206,6 @@ } }; -#ifdef HAVE_BG_PIXMAP -# ifdef BG_IMAGE_FROM_FILE -enum { - IM_IS_SET = 1 << 0, - IM_IS_SIZE_SENSITIVE = 1 << 1, - IM_KEEP_ASPECT = 1 << 2, - IM_ROOT_ALIGN = 1 << 3, - IM_TILE = 1 << 4, - IM_GEOMETRY_FLAGS = IM_KEEP_ASPECT | IM_ROOT_ALIGN | IM_TILE, -}; - -enum { - noScale = 0, - windowScale = 100, - defaultScale = windowScale, - centerAlign = 50, - defaultAlign = centerAlign, -}; - -struct rxvt_image -{ - int id; - unsigned short alpha; - uint8_t flags; - unsigned int h_scale, v_scale; /* percents of the window size */ - int h_align, v_align; /* percents of the window size: - 0 - left align, 50 - center, 100 - right */ - -# ifdef HAVE_PIXBUF - auto_ptr pixbuf; - - int width () - { - return gdk_pixbuf_get_width (pixbuf); - } - int height () - { - return gdk_pixbuf_get_height (pixbuf); - } -# endif - - rxvt_image (); - bool set_file_geometry (const char *file); - bool set_file (const char *file); - bool set_geometry (const char *geom, bool update = false); -}; -# endif -#endif - /* ***************************************************************************** * STRUCTURES AND TYPEDEFS @@ -311,7 +257,7 @@ /* COLORTERM, TERM environment variables */ #define COLORTERMENV "rxvt" -#ifdef BG_IMAGE_FROM_FILE +#if HAVE_IMG # define COLORTERMENVFULL COLORTERMENV "-xpm" #else # define COLORTERMENVFULL COLORTERMENV @@ -324,6 +270,23 @@ # endif #endif +// Hidden color cube for indexed 24-bit colors. There are fewer blue levels +// because normal human eye is less sensitive to the blue component than to +// the red or green. (https://en.m.wikipedia.org/wiki/Color_depth#8-bit_color) +#if USE_256_COLORS +// 7x7x5=245 < 254 unused color indices +# define Red_levels 7 +# define Green_levels 7 +# define Blue_levels 5 +#else +// 6x6x4=144 < 166 unused color indices +# define Red_levels 6 +# define Green_levels 6 +# define Blue_levels 4 +#endif + +#define RGB24_CUBE_SIZE (Red_levels * Green_levels * Blue_levels) + #if defined (NO_MOUSE_REPORT) && !defined (NO_MOUSE_REPORT_SCROLLBAR) # define NO_MOUSE_REPORT_SCROLLBAR 1 #endif @@ -362,9 +325,9 @@ /* modes for rxvt_term::scr_page () - scroll page. used by scrollbar window */ enum page_dirn { - UP, - DN, - NO_DIR, + DN = -1, + NO_DIR = 0, + UP = 1, }; /* arguments for rxvt_term::scr_change_screen () */ @@ -462,14 +425,12 @@ Rxvt_restoreFG = 39, Rxvt_restoreBG = 49, - Rxvt_Pixmap = 20, // new bg pixmap Rxvt_dumpscreen = 55, // dump scrollback and all of screen URxvt_locale = 701, // change locale URxvt_version = 702, // request version URxvt_Color_IT = 704, // change actual 'Italic' colour - URxvt_Color_tint = 705, // change actual tint colour URxvt_Color_BD = 706, // change actual 'Bold' color URxvt_Color_UL = 707, // change actual 'Underline' color URxvt_Color_border = 708, @@ -527,6 +488,9 @@ #else maxTermCOLOR = Color_White + 72, #endif + minTermCOLOR24, + maxTermCOLOR24 = minTermCOLOR24 + + RGB24_CUBE_SIZE - 1, #ifndef NO_CURSORCOLOR Color_cursor, Color_cursor2, @@ -551,9 +515,6 @@ #ifdef RXVT_SCROLLBAR Color_trough, #endif -#if ENABLE_TRANSPARENCY - Color_tint, -#endif #if OFF_FOCUS_FADING Color_fade, #endif @@ -568,9 +529,13 @@ }; #if USE_256_COLORS -# define Color_Bits 9 // 0 .. maxTermCOLOR +# define Color_Bits 9 // 0 .. maxTermCOLOR24 #else -# define Color_Bits 7 // 0 .. maxTermCOLOR +# define Color_Bits 8 // 0 .. maxTermCOLOR24 +#endif + +#if maxTermCOLOR24 >= (1 << Color_Bits) +# error color index overflow #endif /* @@ -611,6 +576,9 @@ #define PrivMode_BracketPaste (1UL<<22) #define PrivMode_ExtModeMouse (1UL<<23) // xterm pseudo-utf-8 hack #define PrivMode_ExtMouseRight (1UL<<24) // xterm pseudo-utf-8, but works in non-utf-8-locales +#define PrivMode_BlinkingCursor (1UL<<25) +#define PrivMode_FocusEvent (1UL<<26) +#define PrivMode_ExtMouseSGR (1UL<<27) #define PrivMode_mouse_report (PrivMode_MouseX10|PrivMode_MouseX11|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent) @@ -623,7 +591,7 @@ // do not change these constants lightly, there are many interdependencies #define IMBUFSIZ 128 // input modifier buffer sizes #define KBUFSZ 512 // size of keyboard mapping buffer -#define CBUFSIZ 2048 // size of command buffer +#define CBUFSIZ 32768 // size of command buffer (longest command sequence possible) #define CBUFCNT 8 // never call pty_fill/cmd_parse more than this often in a row #define UBUFSIZ 2048 // character buffer @@ -706,13 +674,6 @@ #define SET_STYLE(x,style) (((x) & ~RS_styleMask) | ((style) << RS_styleShift)) #define GET_ATTR(x) (((x) & RS_attrMask)) -// return attributes defining the background, encoding doesn't matter -// depends on RS_fgShift > RS_bgShift -#define GET_BGATTR(x) \ - (ecb_unlikely ((x) & RS_RVid) \ - ? (((x) & (RS_attrMask & ~RS_RVid)) \ - | (((x) & RS_fgMask) >> (RS_fgShift - RS_bgShift))) \ - : ((x) & (RS_attrMask | RS_bgMask))) #define SET_FGCOLOR(x,fg) (((x) & ~RS_fgMask) | ((fg) << RS_fgShift)) #define SET_BGCOLOR(x,bg) (((x) & ~RS_bgMask) | ((bg) << RS_bgShift)) #define SET_ATTR(x,a) (((x) & ~RS_attrMask) | (a)) @@ -748,6 +709,16 @@ tlen_t_ l; // length of each text line uint32_t f; // flags + bool valid () + { + return l >= 0; + } + + void alloc () + { + l = 0; + } + bool is_longer () { return f & LINE_LONGER; @@ -821,9 +792,7 @@ struct compose_char { unicode_t c1, c2; // any chars != NOCHAR are valid - #if __cplusplus >= 201103L || ECB_GCC_VERSION(4,4) - compose_char () = default; - #endif + compose_char (unicode_t c1, unicode_t c2) : c1(c1), c2(c2) { } @@ -1027,6 +996,7 @@ XSizeHints szHint; rxvt_color *pix_colors; Cursor TermWin_cursor; /* cursor for vt window */ + line_t *row_buf; // all lines, scrollback + terminal, circular line_t *drawn_buf; // text on screen line_t *swap_buf; // lines for swap buffer @@ -1094,7 +1064,6 @@ /* ---------- */ #ifdef SELECTION_SCROLLING int scroll_selection_lines; - enum page_dirn scroll_selection_dir; int selection_save_x, selection_save_y, selection_save_state; @@ -1113,6 +1082,8 @@ # ifdef POINTER_BLANK pointerBlankDelay, # endif + multiClickTime, + cursor_type, allowedxerror; /* ---------- */ unsigned int ModLevel3Mask, @@ -1132,80 +1103,16 @@ XComposeStatus compose; static struct termios def_tio; row_col_t oldcursor; -#ifdef HAVE_BG_PIXMAP - void bg_init (); - void bg_destroy (); +#ifdef HAVE_IMG enum { - BG_IS_VALID = 1 << 0, - BG_IS_TRANSPARENT = 1 << 1, BG_NEEDS_REFRESH = 1 << 2, - - BG_HAS_RENDER = 1 << 3, - BG_HAS_RENDER_CONV = 1 << 4, - BG_CLIENT_RENDER = 1 << 5, - - BG_TINT_SET = 1 << 6, - BG_TINT_BITAND = 1 << 7, }; uint8_t bg_flags; -# ifdef BG_IMAGE_FROM_FILE - vector image_vec; - rxvt_image *new_image () - { - image_vec.resize (image_vec.size () + 1); - return &image_vec.back (); - } - void get_image_geometry (rxvt_image &image, int &w, int &h, int &x, int &y); - bool render_image (rxvt_image &image); - void parse_image (int id, const char *type, const char *arg); -# endif - -# ifdef ENABLE_TRANSPARENCY - Pixmap root_pixmap; /* current root pixmap set */ - rxvt_color tint; - int shade; - int h_blurRadius, v_blurRadius; - - void bg_set_transparent () - { - bg_flags |= BG_IS_TRANSPARENT; - } - void bg_set_root_pixmap (); - bool bg_set_tint (rxvt_color &new_tint); - bool bg_set_shade (const char *shade_str); - bool bg_set_blur (const char *geom); - - bool blur_pixmap (Pixmap pixmap, int width, int height); - bool tint_pixmap (Pixmap pixmap, int width, int height); - void tint_ximage (XImage *ximage); - bool make_transparency_pixmap (); -# endif - - ev_tstamp bg_valid_since; - - Pixmap bg_pixmap; - unsigned int bg_pmap_width, bg_pmap_height; - - int target_x; - int target_y; - bool bg_set_position (int x, int y); - bool bg_window_size_sensitive (); - bool bg_window_position_sensitive (); - - bool bg_render (); - void bg_invalidate () - { - bg_flags &= ~BG_IS_VALID; - } -#endif -#ifdef HAVE_PIXBUF - bool pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, - int src_x, int src_y, int dst_x, int dst_y, - unsigned int width, unsigned int height, bool argb); + rxvt_img *bg_img; #endif #if ENABLE_OVERLAY @@ -1223,11 +1130,14 @@ vector allocated; // free these memory blocks with free() + int parent_x, parent_y; // parent window position relative to root, only updated on demand + char *locale; char charsets[4]; char *v_buffer; /* pointer to physical buffer */ unsigned int v_buflen; /* size of area to write */ stringvec *argv, *envv; /* if != 0, will be freed at destroy time */ + char **env; #ifdef KEYSYM_RESOURCE keyboard_manager *keyboard; @@ -1243,8 +1153,14 @@ ptytty *pty; - rxvt_salloc *talloc; // text line allocator - rxvt_salloc *ralloc; // rend line allocator + // chunk contains all line_t's as well as rend_t and text_t buffers + // for drawn_buf, swap_buf and row_buf, in this order + void *chunk; + size_t chunk_size; + + uint32_t rgb24_color[RGB24_CUBE_SIZE]; // the 24-bit color value + uint16_t rgb24_seqno[RGB24_CUBE_SIZE]; // which one is older? + uint16_t rgb24_sequence; static vector termlist; // a vector of all running rxvt_term's @@ -1253,7 +1169,7 @@ unicode_t iso14755buf; void commit_iso14755 (); # if ISO_14755 - void iso14755_51 (unicode_t ch, rend_t r = DEFAULT_RSTYLE, int x = 0, int y = -1); + void iso14755_51 (unicode_t ch, rend_t r = DEFAULT_RSTYLE, int x = 0, int y = -1, int y2 = -1); void iso14755_54 (int x, int y); # endif #endif @@ -1265,15 +1181,10 @@ XSelectInput (dpy, vt, vt_emask | vt_emask_perl | vt_emask_xim | vt_emask_mouse); } -#if ENABLE_TRANSPARENCY || ENABLE_PERL +#if ENABLE_PERL void rootwin_cb (XEvent &xev); xevent_watcher rootwin_ev; #endif -#ifdef HAVE_BG_PIXMAP - void update_background (); - void update_background_cb (ev::timer &w, int revents); - ev::timer update_background_ev; -#endif void x_cb (XEvent &xev); xevent_watcher termwin_ev; @@ -1318,13 +1229,15 @@ void pointer_unblank (); void tt_printf (const char *fmt,...); + void tt_write_ (const char *data, unsigned int len); void tt_write (const char *data, unsigned int len); + void tt_write_user_input (const char *data, unsigned int len); void pty_write (); void make_current () const // make this the "currently active" urxvt instance { SET_R (this); - set_environ (envv); + set_environ (env); rxvt_set_locale (locale); } @@ -1367,7 +1280,7 @@ #else void set_urgency (bool enable) { } #endif - void update_fade_color (unsigned int idx); + void update_fade_color (unsigned int idx, bool first_time = false); #ifdef PRINTPIPE FILE *popen_printer (); int pclose_printer (FILE *stream); @@ -1383,9 +1296,11 @@ void process_osc_seq (); void process_color_seq (int report, int color, const char *str, char resp); void process_xterm_seq (int op, char *str, char resp); + unsigned int map_rgb24_color (unsigned int r, unsigned int g, unsigned int b, unsigned int a); int privcases (int mode, unsigned long bit); void process_terminal_mode (int mode, int priv, unsigned int nargs, const int *arg); void process_sgr_mode (unsigned int nargs, const int *arg); + void set_cursor_style (int style); // init.C void init (stringvec *argv, stringvec *envv); void init (int argc, const char *const *argv, const char *const *envv); @@ -1400,7 +1315,7 @@ int run_child (const char *const *argv); void color_aliases (int idx); void create_windows (int argc, const char *const *argv); - void get_colours (); + void get_colors (); void get_ourmods (); void set_icon (const char *file); // main.C @@ -1409,7 +1324,7 @@ ~rxvt_term (); void destroy (); void emergency_cleanup (); - void recolour_cursor (); + void recolor_cursor (); void resize_all_windows (unsigned int newwidth, unsigned int newheight, int ignoreparent); void window_calc (unsigned int newwidth, unsigned int newheight); bool set_fonts (); @@ -1424,37 +1339,15 @@ void alias_color (int dst, int src); void set_widthheight (unsigned int newwidth, unsigned int newheight); void get_window_origin (int &x, int &y); - Pixmap get_pixmap_property (Atom property); // screen.C - void lalloc (line_t &l) const - { - l.t = (text_t *)talloc->alloc (); - l.r = (rend_t *)ralloc->alloc (); - } - -#if 0 - void lfree (line_t &l) + bool option (uint8_t opt) const NOTHROW { - talloc->free (l.t); - ralloc->free (l.r); + return options[opt >> 3] & (1 << (opt & 7)); } -#endif - void lresize (line_t &l) const - { - if (!l.t) - return; - - l.t = (text_t *)talloc->alloc (l.t, prev_ncol * sizeof (text_t)); - l.r = (rend_t *)ralloc->alloc (l.r, prev_ncol * sizeof (rend_t)); - - l.l = min (l.l, ncol); - - if (ncol > prev_ncol) - scr_blank_line (l, prev_ncol, ncol - prev_ncol, DEFAULT_RSTYLE); - } + void set_option (uint8_t opt, bool set = true) NOTHROW; int fgcolor_of (rend_t r) const NOTHROW { @@ -1484,20 +1377,16 @@ return base; } - bool option (uint8_t opt) const NOTHROW - { - return options[opt >> 3] & (1 << (opt & 7)); - } - - void set_option (uint8_t opt, bool set = true) NOTHROW; - // modifies first argument(!) void tt_paste (char *data, unsigned int len) NOTHROW; void paste (char *data, unsigned int len) NOTHROW; + void scr_alloc () NOTHROW; void scr_blank_line (line_t &l, unsigned int col, unsigned int width, rend_t efs) const NOTHROW; void scr_blank_screen_mem (line_t &l, rend_t efs) const NOTHROW; void scr_kill_char (line_t &l, int col) const NOTHROW; + void scr_set_char_rend (line_t &l, int col, rend_t rend); int scr_scroll_text (int row1, int row2, int count) NOTHROW; + void copy_line (line_t &dst, line_t &src); void scr_reset (); void scr_release () NOTHROW; void scr_clear (bool really = false) NOTHROW; @@ -1511,7 +1400,7 @@ #endif void scr_touch (bool refresh) NOTHROW; void scr_expose (int x, int y, int width, int height, bool refresh) NOTHROW; - void scr_recolour (bool refresh = true) NOTHROW; + void scr_recolor (bool refresh = true) NOTHROW; void scr_remap_chars () NOTHROW; void scr_remap_chars (line_t &l) NOTHROW; @@ -1546,7 +1435,11 @@ void scr_charset_choose (int set) NOTHROW; void scr_charset_set (int set, unsigned int ch) NOTHROW; void scr_move_to (int y, int len) NOTHROW; - bool scr_page (enum page_dirn direction, int nlines) NOTHROW; + bool scr_page (int nlines) NOTHROW; + bool scr_page (enum page_dirn direction, int nlines) NOTHROW + { + return scr_page (direction * nlines); + } bool scr_changeview (int new_view_start) NOTHROW; void scr_bell () NOTHROW; void scr_printscreen (int fullhist) NOTHROW; @@ -1556,6 +1449,7 @@ void scr_dump (int fd) NOTHROW; void selection_check (int check_more) NOTHROW; + void selection_changed () NOTHROW; /* sets want_refresh, corrects coordinates */ void selection_request (Time tm, int selnum = Sel_Primary) NOTHROW; void selection_clear (bool clipboard = false) NOTHROW; void selection_make (Time tm); @@ -1570,20 +1464,18 @@ void selection_rotate (int x, int y) NOTHROW; // xdefaults.C + void rxvt_usage (int type); const char **get_options (int argc, const char *const *argv); - int parse_keysym (const char *str, const char *arg); + int parse_keysym (const char *str, unsigned int &state); + int bind_action (const char *str, const char *arg); const char *x_resource (const char *name); void extract_resources (); - void extract_keysym_resources (); - void find_resources (const char *n_prefix, const char *c_prefix, int mode, - Bool (*proc)(XrmDatabase *, XrmBindingList, XrmQuarkList, XrmRepresentation *, XrmValue *, XPointer)); - bool parse_bool_resource (const char *str) + void enumerate_resources (void (*cb)(rxvt_term *, const char *, const char *), const char *name_p = 0, const char *class_p = 0); + void enumerate_keysym_resources (void (*cb)(rxvt_term *, const char *, const char *)) { - return (!strcasecmp (str, "TRUE") - || !strcasecmp (str, "YES") - || !strcasecmp (str, "ON") - || !strcasecmp (str, "1")); + enumerate_resources (cb, "keysym", "Keysym"); } + void extract_keysym_resources (); }; #endif /* _RXVT_H_ */