--- rxvt-unicode/src/rxvt.h 2010/03/31 23:49:08 1.390 +++ rxvt-unicode/src/rxvt.h 2011/12/12 13:56:03 1.453 @@ -30,6 +30,8 @@ using namespace std; +// we assume that Xlib.h defines XPointer, and it does since at least 1994... + extern "C" { #include #include @@ -74,6 +76,20 @@ #include #include +#ifdef HAVE_AFTERIMAGE +# include +# undef min +# undef max +#endif + +#ifdef HAVE_PIXBUF +# include +#endif + +#if defined(BG_IMAGE_FROM_FILE) || defined(ENABLE_TRANSPARENCY) +# define HAVE_BG_PIXMAP 1 +#endif + #include "encoding.h" #include "rxvtutil.h" #include "rxvtfont.h" @@ -100,14 +116,8 @@ ***************************************************************************** */ -#ifndef HAVE_XPOINTER -typedef char *XPointer; -#endif - #include -#include "background.h" - #ifndef STDIN_FILENO # define STDIN_FILENO 0 # define STDOUT_FILENO 1 @@ -119,10 +129,6 @@ # define EXIT_FAILURE 1 /* exit function failure */ #endif -#ifndef PATH_MAX -# define PATH_MAX 16384 -#endif - /****************************************************************************/ // exception thrown on fatal (per-instance) errors @@ -153,12 +159,18 @@ 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)) NORETURN; -void rxvt_exit_failure () THROW ((class rxvt_failure_exception)) NORETURN; +void rxvt_fatal (const char *fmt, ...) THROW ((class rxvt_failure_exception)) ecb_noreturn; +void rxvt_exit_failure () THROW ((class rxvt_failure_exception)) ecb_noreturn; char * rxvt_strtrim (char *str) NOTHROW; -char ** rxvt_splitcommastring (const char *cs) NOTHROW; -void rxvt_freecommastring (char **cs) NOTHROW; +char ** rxvt_strsplit (char delim, const char *str) NOTHROW; + +static inline void +rxvt_free_strsplit (char **ptr) NOTHROW +{ + free (ptr[0]); + free (ptr); +} void * rxvt_malloc (size_t size); void * rxvt_calloc (size_t number, size_t size); @@ -192,6 +204,22 @@ environ = envv; } +struct localise_env +{ + char **orig_env; + + localise_env (char **new_env) + { + orig_env = environ; + environ = new_env; + } + + ~localise_env () + { + environ = orig_env; + } +}; + /* ***************************************************************************** * STRUCTURES AND TYPEDEFS @@ -249,7 +277,11 @@ # define COLORTERMENVFULL COLORTERMENV #endif #ifndef TERMENV -# define TERMENV "rxvt-unicode" +# if USE_256_COLORS +# define TERMENV "rxvt-unicode-256color" +# else +# define TERMENV "rxvt-unicode" +# endif #endif #if defined (NO_MOUSE_REPORT) && !defined (NO_MOUSE_REPORT_SCROLLBAR) @@ -274,71 +306,73 @@ # define NSCREENS 1 #endif -/* special (internal) prefix for font commands */ -#define FONT_CMD '#' -#define FONT_DN "#-" -#define FONT_UP "#+" - -/* flags for rxvt_scr_gotorc () */ +/* flags for rxvt_term::scr_gotorc () */ enum { C_RELATIVE = 1, /* col movement is relative */ R_RELATIVE = 2, /* row movement is relative */ RELATIVE = C_RELATIVE | R_RELATIVE, }; -/* modes for rxvt_scr_insdel_chars (), rxvt_scr_insdel_lines () */ +/* modes for rxvt_term::scr_insdel_chars (), rxvt_term::scr_insdel_lines () */ enum { INSERT = -1, /* don't change these values */ DELETE = +1, ERASE = +2, }; -/* modes for rxvt_scr_page () - scroll page. used by scrollbar window */ +/* modes for rxvt_term::scr_page () - scroll page. used by scrollbar window */ enum page_dirn { UP, DN, NO_DIR, }; -/* arguments for rxvt_scr_change_screen () */ +/* arguments for rxvt_term::scr_change_screen () */ enum { PRIMARY = 0, SECONDARY, }; +// define various rendition bits and masks. the rendition word +// is 32 bits in size, and we should use it as efficiently as possible + #define RS_None 0 -#define RS_colorMask 0x0000007fUL // 128 colors -#define RS_fgShift 0 -#define RS_bgShift Color_Bits -#define RS_fgMask (RS_colorMask << RS_fgShift) +// GET_BGATTR depends on RS_fgShift > RS_bgShift +#define RS_colorMask ((1UL << Color_Bits) - 1UL) +#define RS_bgShift 0 +#define RS_fgShift (RS_bgShift + Color_Bits) #define RS_bgMask (RS_colorMask << RS_bgShift) - -// font styles -#define RS_Bold 0x08000000UL // value 1 -#define RS_Italic 0x10000000UL // value 2 - -// fake styles -#define RS_Blink 0x20000000UL // blink -#define RS_RVid 0x40000000UL // reverse video -#define RS_Uline 0x80000000UL // underline - -// 5 custom bits for extensions -#define RS_customCount 16 -#define RS_customMask 0x07800000UL -#define RS_customShift 23 +#define RS_fgMask (RS_colorMask << RS_fgShift) // must have space for rxvt_fontset::fontCount * 2 + 2 values -#define RS_fontMask 0x007c0000UL // includes RS_Careful -#define RS_fontShift 18 -#define RS_Careful 0x00010000UL /* be careful when drawing these */ +#define RS_fontShift (RS_fgShift + Color_Bits) +#define RS_Careful (1UL << RS_fontShift) /* be careful when drawing these */ +#define RS_fontCount rxvt_fontset::fontCount +#define RS_fontMask ((RS_fontCount << (RS_fontShift + 1)) | RS_Careful) // includes RS_Careful // toggle this to force redraw, must be != RS_Careful and otherwise "pretty neutral" -#define RS_redraw 0x00020000UL +#define RS_redraw (2UL << RS_fontShift) + +#define RS_Sel (1UL << 22) + +// 4 custom bits for extensions +#define RS_customCount 16UL +#define RS_customShift 23 +#define RS_customMask ((RS_customCount - 1UL) << RS_customShift) + +// font styles +#define RS_Bold (1UL << RS_styleShift) +#define RS_Italic (2UL << RS_styleShift) #define RS_styleCount 4 -#define RS_styleMask (RS_Bold | RS_Italic) #define RS_styleShift 27 +#define RS_styleMask (RS_Bold | RS_Italic) + +// fake styles +#define RS_Blink (1UL << 29) +#define RS_RVid (1UL << 30) // reverse video +#define RS_Uline (1UL << 31) // underline #define RS_baseattrMask (RS_Italic | RS_Bold | RS_Blink | RS_RVid | RS_Uline) #define RS_attrMask (RS_baseattrMask | RS_fontMask) @@ -346,17 +380,6 @@ #define DEFAULT_RSTYLE (RS_None | (Color_fg << RS_fgShift) | (Color_bg << RS_bgShift)) #define OVERLAY_RSTYLE (RS_None | (Color_Black << RS_fgShift) | (Color_Yellow << RS_bgShift)) -#define Sel_none 0 /* Not waiting */ -#define Sel_normal 0x01 /* normal selection */ -#define Sel_incr 0x02 /* incremental selection */ -#define Sel_direct 0x00 -#define Sel_Primary 0x01 -#define Sel_Secondary 0x02 -#define Sel_Clipboard 0x03 -#define Sel_whereMask 0x0f -#define Sel_CompoundText 0x10 /* last request was COMPOUND_TEXT */ -#define Sel_UTF8String 0x20 /* last request was UTF8_STRING */ - enum { C0_NUL = 0x00, C0_SOH, C0_STX, C0_ETX, C0_EOT, C0_ENQ, C0_ACK, C0_BEL, @@ -383,7 +406,8 @@ XTerm_Color_pointer_bg = 14, // change actual 'Pointer' bg color XTerm_Color05 = 15, // not implemented (tektronix fg) XTerm_Color06 = 16, // not implemented (tektronix bg) - XTerm_Color_RV = 17, // change actual 'Highlight' color + XTerm_Color_HC = 17, // change actual 'Highlight' bg color + XTerm_Color_HTC = 19, // change actual 'Highlight' fg color XTerm_logfile = 46, // not implemented XTerm_font = 50, @@ -395,8 +419,6 @@ */ // deprecated - Rxvt_Color_BD = 18, - Rxvt_Color_UL = 19, Rxvt_restoreFG = 39, Rxvt_restoreBG = 49, @@ -460,10 +482,10 @@ Color_White = maxCOLOR, #endif minTermCOLOR = Color_White + 1, -#ifndef XTERM_256_COLORS - maxTermCOLOR = Color_White + 72, -#else +#if USE_256_COLORS maxTermCOLOR = Color_White + 240, +#else + maxTermCOLOR = Color_White + 72, #endif #ifndef NO_CURSORCOLOR Color_cursor, @@ -483,6 +505,7 @@ #endif #ifdef OPTION_HC Color_HC, + Color_HTC, #endif Color_scroll, #ifdef RXVT_SCROLLBAR @@ -504,10 +527,10 @@ #endif }; -#ifndef XTERM_256_COLORS -#define Color_Bits 7 // 0 .. maxTermCOLOR +#if USE_256_COLORS +# define Color_Bits 9 // 0 .. maxTermCOLOR #else -#define Color_Bits 9 // 0 .. maxTermCOLOR +# define Color_Bits 7 // 0 .. maxTermCOLOR #endif /* @@ -546,6 +569,8 @@ #define PrivMode_MouseBtnEvent (1UL<<20) #define PrivMode_MouseAnyEvent (1UL<<21) #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_mouse_report (PrivMode_MouseX10|PrivMode_MouseX11|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent) @@ -606,6 +631,8 @@ * MACRO DEFINES ***************************************************************************** */ + +// speed hack, copy some member variable into a local variable of the same name #define dLocal(type,name) type const name = this->name // for speed reasons, we assume that all codepoints 32 to 126 are @@ -639,10 +666,13 @@ #define SET_STYLE(x,style) (((x) & ~RS_styleMask) | ((style) << RS_styleShift)) #define GET_ATTR(x) (((x) & RS_attrMask)) -#define GET_BGATTR(x) \ - (((x) & RS_RVid) ? (((x) & (RS_attrMask & ~RS_RVid)) \ - | (((x) & RS_colorMask) << RS_bgShift)) \ - : ((x) & (RS_attrMask | RS_bgMask))) +// 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)) @@ -793,7 +823,7 @@ text_t **text; rend_t **rend; - // while tempting to add swap() etc. here, it effetcively only increases code size + // while tempting to add swap() etc. here, it effectively only increases code size }; /* ------------------------------------------------------------------------- */ @@ -860,7 +890,7 @@ int term_start; /* term lines start here */ int view_start; /* scrollback view starts here */ int top_row; /* topmost row index of scrollback */ - Window parent[6]; /* parent identifiers - we're parent[0] */ + Window parent; /* parent identifier */ Window vt; /* vt100 window */ GC gc; /* GC for drawing */ Pixmap pixmap; @@ -935,12 +965,13 @@ /* rxvt_vars.options */ enum { -# define def(name,idx) Opt_ ## name = idx, -# define nodef(name) Opt_ ## name = 0, +# define def(name) Opt_ ## name, +# define nodef(name) Opt_prev_ ## name, Opt_ ## name = 0, Opt_next_ ## name = Opt_prev_ ## name - 1, + Opt_0, # include "optinc.h" # undef nodef # undef def -Opt_count + Opt_count }; /* ------------------------------------------------------------------------- */ @@ -952,8 +983,7 @@ XSizeHints szHint; rxvt_color *pix_colors; Cursor TermWin_cursor; /* cursor for vt window */ - int numlock_state; - line_t *row_buf; // all lines, scrollback + terminal, circular, followed by temp_buf + line_t *row_buf; // all lines, scrollback + terminal, circular line_t *drawn_buf; // text on screen line_t *swap_buf; // lines for swap buffer char *tabs; /* per location: 1 == tab-stop */ @@ -1004,10 +1034,8 @@ unsigned char refresh_type, #ifdef META8_OPTION - meta_char, /* Alt-key prefix */ + meta_char; /* Alt-key prefix */ #endif - selection_wait, - selection_type; /* ---------- */ bool rvideo_state, rvideo_mode; #ifndef NO_BELL @@ -1053,20 +1081,110 @@ Atom *xa; /* ---------- */ Time selection_time, - selection_request_time, clipboard_time; + rxvt_selection *selection_req; pid_t cmd_pid; /* process id of child */ - char * incr_buf; - size_t incr_buf_size, incr_buf_fill; /* ---------- */ struct mouse_event MEvent; XComposeStatus compose; - struct termios tio; + static struct termios def_tio; row_col_t oldcursor; #ifdef HAVE_BG_PIXMAP - bgPixmap_t bgPixmap; + void bg_init (); + void bg_destroy (); + + enum { + //subset returned by make_transparency_pixmap + BG_IS_VALID = 1 << 0, + BG_NEEDS_TINT = 1 << 1, + BG_NEEDS_BLUR = 1 << 2, + + BG_EFFECTS_FLAGS = BG_NEEDS_TINT | BG_NEEDS_BLUR, + + BG_KEEP_ASPECT = 1 << 3, + BG_ROOT_ALIGN = 1 << 4, + BG_TILE = 1 << 14, + BG_GEOMETRY_FLAGS = BG_KEEP_ASPECT | BG_ROOT_ALIGN | BG_TILE, + + BG_TINT_SET = 1 << 5, + BG_TINT_BITAND = 1 << 6, + BG_TINT_FLAGS = BG_NEEDS_TINT | BG_TINT_BITAND, + + BG_HAS_RENDER = 1 << 7, + BG_HAS_RENDER_CONV = 1 << 8, + BG_CLIENT_RENDER = 1 << 9, + + BG_IS_TRANSPARENT = 1 << 10, + BG_NEEDS_REFRESH = 1 << 11, + BG_IS_SIZE_SENSITIVE = 1 << 12, + BG_IS_FROM_FILE = 1 << 13, + }; + + unsigned int bg_flags; + +# ifdef BG_IMAGE_FROM_FILE + void get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y); + bool render_image (unsigned long tr_flags); + + enum { + noScale = 0, + windowScale = 100, + defaultScale = windowScale, + centerAlign = 50, + defaultAlign = centerAlign, + }; + + 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 */ + + bool bg_set_geometry (const char *geom, bool update = false); + void bg_set_default_geometry () + { + h_scale = v_scale = defaultScale; + h_align = v_align = defaultAlign; + } + + bool bg_set_file (const char *file); +# endif + +# ifdef ENABLE_TRANSPARENCY + Pixmap root_pixmap; /* current root pixmap set */ + rxvt_color tint; + int shade; + int h_blurRadius, v_blurRadius; + + bool bg_set_transparent (); + void bg_set_root_pixmap (); + void set_tint_shade_flags (); + 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, Visual *visual, int width, int height); + bool tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height); + unsigned long 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_AFTERIMAGE + ASImage *original_asim; ASVisual *asv; ASImageManager *asimman; @@ -1076,6 +1194,12 @@ asv = create_asvisual_for_id (dpy, display->screen, depth, XVisualIDFromVisual (visual), cmap, NULL); } #endif +#ifdef HAVE_PIXBUF + GdkPixbuf *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); +#endif #if ENABLE_OVERLAY overlay_base ov; @@ -1145,10 +1269,6 @@ #endif #ifdef HAVE_BG_PIXMAP void update_background (); -#if TRACE_PIXMAPS - void trace_update_background (const char *file, int line); -# define update_background() trace_update_background (__FILE__, __LINE__) -#endif void update_background_cb (ev::timer &w, int revents); ev::timer update_background_ev; #endif @@ -1163,9 +1283,10 @@ void refresh_check (); void flush (); void flush_cb (ev::timer &w, int revents); ev::timer flush_ev; + void cmdbuf_reify (); + void cmdbuf_append (const char *str, size_t count); bool pty_fill (); void pty_cb (ev::io &w, int revents); ev::io pty_ev; - void incr_cb (ev::timer &w, int revents) NOTHROW; ev::timer incr_ev; #ifdef CURSOR_BLINK void cursor_blink_cb (ev::timer &w, int revents); ev::timer cursor_blink_ev; @@ -1200,7 +1321,10 @@ void init (stringvec *argv, stringvec *envv) { this->argv = argv; - init (argv->size (), argv->begin (), envv); + this->envv = envv; + argv->push_back (0); + envv->push_back (0); + init (argv->size () - 1, argv->begin ()); } void make_current () const // make this the "currently active" urxvt instance @@ -1223,16 +1347,15 @@ void im_set_color (unsigned long &fg, unsigned long &bg); void im_set_preedit_area (XRectangle &preedit_rect, XRectangle &status_rect, const XRectangle &needed_rect); - bool IMisRunning (); - void IMSendSpot (); - bool IM_get_IC (const char *modifiers); - void IMSetPosition (); + bool im_is_running (); + void im_send_spot (); + bool im_get_ic (const char *modifiers); + void im_set_position (); #endif // command.C void key_press (XKeyEvent &ev); void key_release (XKeyEvent &ev); - unsigned int cmd_write (const char *str, unsigned int count); wchar_t next_char () NOTHROW; wchar_t cmd_getc () THROW ((class out_of_input)); @@ -1269,11 +1392,10 @@ 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 process_graphics (); // init.C void init_vars (); const char **init_resources (int argc, const char *const *argv); - void init (int argc, const char *const *argv, stringvec *envv); + void init (int argc, const char *const *argv); void init_env (); void set_locale (const char *locale); void init_xlocale (); @@ -1284,6 +1406,7 @@ void create_windows (int argc, const char *const *argv); void get_colours (); void get_ourmods (); + void set_icon (const char *file); // main.C void tt_winch (); rxvt_term (); @@ -1295,6 +1418,7 @@ void window_calc (unsigned int newwidth, unsigned int newheight); bool set_fonts (); void set_string_property (Atom prop, const char *str, int len = -1); + void set_mbstring_property (Atom prop, const char *str, int len = -1); void set_utf8_property (Atom prop, const char *str, int len = -1); void set_title (const char *str); void set_icon_name (const char *str); @@ -1304,7 +1428,7 @@ 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 (int prop_id); + Pixmap get_pixmap_property (Atom property); // screen.C @@ -1344,7 +1468,7 @@ # if ENABLE_STYLES && option (Opt_intensityStyles) # endif - && IN_RANGE_INC (base, minCOLOR, minBrightCOLOR)) + && IN_RANGE_EXC (base, minCOLOR, minBrightCOLOR)) base += minBrightCOLOR - minCOLOR; #endif return base; @@ -1358,7 +1482,7 @@ # if ENABLE_STYLES && option (Opt_intensityStyles) # endif - && IN_RANGE_INC (base, minCOLOR, minBrightCOLOR)) + && IN_RANGE_EXC (base, minCOLOR, minBrightCOLOR)) base += minBrightCOLOR - minCOLOR; #endif return base; @@ -1366,34 +1490,13 @@ bool option (uint8_t opt) const NOTHROW { - if (!opt) - return 0; - - --opt; return options[opt >> 3] & (1 << (opt & 7)); } - void set_option (uint8_t opt, bool set = true) NOTHROW - { - if (!opt) - return; - - --opt; - if (set) - options[opt >> 3] |= (1 << (opt & 7)); - else - options[opt >> 3] &= ~(1 << (opt & 7)); - } - - void set_privmode (unsigned bit, int set) NOTHROW - { - if (set) - priv_modes |= bit; - else - priv_modes &= ~bit; - } + 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_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; @@ -1412,7 +1515,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 () NOTHROW; + void scr_recolour (bool refresh = true) NOTHROW; void scr_remap_chars () NOTHROW; void scr_remap_chars (line_t &l) NOTHROW; @@ -1457,12 +1560,8 @@ void scr_dump (int fd) NOTHROW; void selection_check (int check_more) NOTHROW; - void selection_paste (Window win, Atom prop, bool delete_prop) NOTHROW; - void selection_property (Window win, Atom prop) NOTHROW; void selection_request (Time tm, int selnum = Sel_Primary) NOTHROW; - int selection_request_other (Atom target, int selnum) NOTHROW; void selection_clear (bool clipboard = false) NOTHROW; - void clipboard_copy (Time tm); void selection_make (Time tm); bool selection_grab (Time tm, bool clipboard = false) NOTHROW; void selection_start_colrow (int col, int row) NOTHROW; @@ -1479,6 +1578,7 @@ int parse_keysym (const char *str, const char *arg); const char *x_resource (const char *name); void extract_resources (); + void extract_keysym_resources (); }; #endif /* _RXVT_H_ */