From b27e43e10804ca76bdebe4ba949789d8776a7487 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 5 Nov 2008 14:43:54 +0000 Subject: [PATCH] minor overlay refactoring, syntax changes --- Changes | 3 +- src/encoding.h | 6 ++-- src/perl/overlay-osc | 2 +- src/rxvt.h | 72 +++++++++++++++++++++++++++------------- src/rxvtdaemon.h | 3 +- src/rxvtfont.h | 9 +++-- src/rxvtperl.xs | 18 +++++++--- src/rxvttoolkit.h | 3 +- src/rxvtutil.h | 12 ++++--- src/salloc.h | 3 +- src/screen.C | 78 ++++++++++++++++++++++++-------------------- src/scrollbar.h | 3 +- 12 files changed, 134 insertions(+), 78 deletions(-) diff --git a/Changes b/Changes index a693c268..61a8c82d 100644 --- a/Changes +++ b/Changes @@ -19,7 +19,6 @@ WISH: load system-wide config file even if we don't have one WISH: look into XAddConnectionWatch, does anybody need that? DUMB: support tex fonts -TODO: cursor over overlays, when focus change? TODO: cursor restore/rendition restore on rmcup - the aterm code now frees the as visual and image manager objects when a window was closed. @@ -57,6 +56,8 @@ TODO: cursor restore/rendition restore on rmcup - use current rendition style in DCH sequence. - the 132/80 mode switch no longer forces a screen reset. - new perl extension "overlay-osc", for status displays and the like. + - fix some minor cursor drawing issues with overlays by allowing + overlays to modify screen flags (to disable the cursor themselves). 9.05 Sun Jun 15 20:09:20 CEST 2008 - new option --cd/chdir to set the starting working directory. diff --git a/src/encoding.h b/src/encoding.h index 2d1657f4..955482c6 100644 --- a/src/encoding.h +++ b/src/encoding.h @@ -68,7 +68,8 @@ enum { NOCHAR = 0xffff, // must be invalid in ANY codeset (!) }; -struct rxvt_codeset_conv { +struct rxvt_codeset_conv +{ uint32_t (*from_unicode) (unicode_t unicode); #if ENCODING_TO_UNICODE unicode_t (*to_unicode) (uint32_t enc); @@ -82,7 +83,8 @@ extern unicode_t rxvt_compose (unicode_t c1, unicode_t c2); #define FROM_UNICODE(cs,code) rxvt_codeset[cs].from_unicode (code) #define TO_UNICODE(cs,code) rxvt_codeset[cs].to_unicode (code) -struct unicode { // namespace für arme +struct unicode // namespace für arme +{ static bool is_space (unicode_t c); }; diff --git a/src/perl/overlay-osc b/src/perl/overlay-osc index aee671f4..289ec8b8 100644 --- a/src/perl/overlay-osc +++ b/src/perl/overlay-osc @@ -4,7 +4,7 @@ # printf "\033]777;overlay;action;args\007" # # action "simple;;;;;;" -# printf "\033]777;overlay;simple;ov1;0;0;t;test\007" +# printf "\033]777;overlay;simple;ov1;5;0;0;t;test\007" # # action "timeout;;" diff --git a/src/rxvt.h b/src/rxvt.h index 3fa5f83c..1b6d80ee 100644 --- a/src/rxvt.h +++ b/src/rxvt.h @@ -206,7 +206,8 @@ set_environ (char **envv) * the 'essential' information for reporting Mouse Events * pared down from XButtonEvent */ -struct mouse_event { +struct mouse_event +{ int clicks; Time time; /* milliseconds */ unsigned int state; /* key or button mask */ @@ -557,7 +558,8 @@ enum { #if ENABLE_FRILLS # include -typedef struct _mwmhints { +typedef struct _mwmhints +{ CARD32 flags; CARD32 functions; CARD32 decorations; @@ -614,8 +616,11 @@ typedef struct _mwmhints { #define Width2Pixel(n) ((int32_t)(n) * (int32_t)fwidth) #define Height2Pixel(n) ((int32_t)(n) * (int32_t)fheight) -#define LINENO(n) MOD (term_start + int(n), total_rows) -#define ROW(n) row_buf [LINENO (n)] +#define LINENO_of(t,n) MOD ((t)->term_start + int(n), (t)->total_rows) +#define ROW_of(t,n) (t)->row_buf [LINENO_of ((t), n)] + +#define LINENO(n) LINENO_of (this, n) +#define ROW(n) ROW_of (this, n) /* how to build & extract colors and attributes */ #define GET_BASEFG(x) (((x) & RS_fgMask)) @@ -642,11 +647,13 @@ typedef struct _mwmhints { #define ISSET_PIXCOLOR(idx) (!!rs[Rs_color + (idx)]) #if ENABLE_STYLES -# define FONTSET(style) fontset[GET_STYLE (style)] +# define FONTSET_of(t,style) (t)->fontset[GET_STYLE (style)] #else -# define FONTSET(style) fontset[0] +# define FONTSET_of(t,style) (t)->fontset[0] #endif +#define FONTSET(style) FONTSET_of (this, style) + typedef callback log_callback; typedef callback getfd_callback; @@ -658,7 +665,8 @@ typedef callback getfd_callback; #define LINE_FILTER 0x0008 // line needs to be filtered before display (NYI) #define LINE_BIDI 0x0010 // line needs bidi (NYI) -struct line_t { +struct line_t +{ text_t *t; // terminal the text rend_t *r; // rendition, uses RS_ flags tlen_t_ l; // length of each text line @@ -702,7 +710,8 @@ struct line_t { /****************************************************************************/ // primitive wrapper around mbstate_t to ensure initialisation -struct mbstate { +struct mbstate +{ mbstate_t mbs; operator mbstate_t *() { return &mbs; } @@ -733,14 +742,16 @@ struct mbstate { // compose chars are used to represent composite characters // that are not representable in unicode, as well as characters // not fitting in the BMP. -struct compose_char { +struct compose_char +{ unicode_t c1, c2; // any chars != NOCHAR are valid compose_char (unicode_t c1, unicode_t c2) : c1(c1), c2(c2) { } }; -class rxvt_composite_vec { +class rxvt_composite_vec +{ vector v; public: text_t compose (unicode_t c1, unicode_t c2 = NOCHAR); @@ -769,7 +780,20 @@ extern rxvt_t rxvt_current_term; #define SET_R(r) rxvt_current_term = const_cast(r) #define GET_R rxvt_current_term -typedef struct { +/* ------------------------------------------------------------------------- */ +struct overlay_base +{ + int x, y, w, h; // overlay dimensions + text_t **text; + rend_t **rend; + + // while tempting to add swap() etc. here, it effetcively only increases code size +}; + +/* ------------------------------------------------------------------------- */ + +typedef struct +{ int row; int col; } row_col_t; @@ -810,7 +834,8 @@ typedef struct { * END······················= total_rows */ -struct TermWin_t { +struct TermWin_t +{ int width; /* window width [pixels] */ int height; /* window height [pixels] */ int fwidth; /* font width [pixels] */ @@ -854,7 +879,8 @@ struct TermWin_t { * * Note: col == -1 ==> we're left of screen * */ -typedef struct { +struct screen_t +{ row_col_t cur; /* cursor position on the screen */ int tscroll; /* top of settable scroll region */ int bscroll; /* bottom of settable scroll region */ @@ -864,9 +890,10 @@ typedef struct { unsigned int s_charset; /* saved character set number [0..3] */ char s_charset_char; rend_t s_rstyle; /* saved rendition style */ -} screen_t; +}; -enum selection_op_t { +enum selection_op_t +{ SELECTION_CLEAR = 0, /* nothing selected */ SELECTION_INIT, /* marked a point */ SELECTION_BEGIN, /* started a selection */ @@ -874,7 +901,8 @@ enum selection_op_t { SELECTION_DONE /* selection put in CUT_BUFFER0 */ }; -typedef struct { +struct selection_t +{ wchar_t *text; /* selected text */ unsigned int len; /* length of selected text */ unsigned int screen; /* screen being used */ @@ -884,7 +912,7 @@ typedef struct { row_col_t beg; /* beginning of selection <= mark */ row_col_t mark; /* point of initial click <= end */ row_col_t end; /* one character past end point */ -} selection_t; +}; /* ------------------------------------------------------------------------- */ @@ -908,7 +936,8 @@ Opt_count /* ------------------------------------------------------------------------- */ -struct rxvt_vars : TermWin_t { +struct rxvt_vars : TermWin_t +{ scrollBar_t scrollBar; uint8_t options[(Opt_count + 7) >> 3]; XSizeHints szHint; @@ -928,7 +957,8 @@ struct rxvt_vars : TermWin_t { #endif }; -struct rxvt_term : zero_initialized, rxvt_vars, rxvt_screen { +struct rxvt_term : zero_initialized, rxvt_vars, rxvt_screen +{ // special markers with magic addresses static const char resval_undef []; // options specifically unset @@ -1038,9 +1068,7 @@ struct rxvt_term : zero_initialized, rxvt_vars, rxvt_screen { #endif #if ENABLE_OVERLAY - int ov_x, ov_y, ov_w, ov_h; // overlay dimensions - text_t **ov_text; - rend_t **ov_rend; + overlay_base ov; void scr_swap_overlay () NOTHROW; void scr_overlay_new (int x, int y, int w, int h) NOTHROW; diff --git a/src/rxvtdaemon.h b/src/rxvtdaemon.h index b7203ba4..e77f7650 100644 --- a/src/rxvtdaemon.h +++ b/src/rxvtdaemon.h @@ -3,7 +3,8 @@ #include "rxvtutil.h" -struct rxvt_connection { +struct rxvt_connection +{ int fd; static char *unix_sockname (); diff --git a/src/rxvtfont.h b/src/rxvtfont.h index 86281664..ec286a3a 100644 --- a/src/rxvtfont.h +++ b/src/rxvtfont.h @@ -15,7 +15,8 @@ struct rxvt_term; -struct rxvt_fontprop { +struct rxvt_fontprop +{ enum { unset = -1, medium = 100, bold = 200, @@ -25,7 +26,8 @@ struct rxvt_fontprop { int weight, slant; }; -struct rxvt_font { +struct rxvt_font +{ // managed by the fontset rxvt_term *term; void set_term (rxvt_term *term) { this->term = term; } @@ -62,7 +64,8 @@ struct rxvt_font { struct rxvt_fallback_font; -struct rxvt_fontset { +struct rxvt_fontset +{ char *fontdesc; rxvt_fontset (rxvt_term *term); diff --git a/src/rxvtperl.xs b/src/rxvtperl.xs index 6cf7e833..369e3cea 100644 --- a/src/rxvtperl.xs +++ b/src/rxvtperl.xs @@ -109,13 +109,11 @@ SvPTR (SV *sv, const char *klass) #define SvOVERLAY(sv) (overlay *)SvPTR (sv, "urxvt::overlay") -class overlay { +class overlay : overlay_base +{ rxvt_term *THIS; AV *overlay_av; - int x, y, w, h; int border; - text_t **text; - rend_t **rend; public: HV *self; @@ -132,8 +130,13 @@ public: }; overlay::overlay (rxvt_term *THIS, int x_, int y_, int w_, int h_, rend_t rstyle, int border) -: THIS(THIS), x(x_), y(y_), w(w_), h(h_), border(border == 2), overlay_av (0) +: THIS(THIS), border(border == 2), overlay_av (0) { + x = x_; + y = y_; + w = w_; + h = h_; + if (w < 0) w = 0; if (h < 0) h = 0; @@ -247,6 +250,11 @@ void overlay::swap () int ov_w = min (w, THIS->ncol - ov_x); int ov_h = min (h, THIS->nrow - ov_y); + // hide cursor if it is within the overlay area + if (IN_RANGE_EXC (THIS->screen.cur.col - ov_x, 0, ov_w) + && IN_RANGE_EXC (THIS->screen.cur.row - ov_y, 0, ov_h)) + THIS->screen.flags &= ~Screen_VisibleCursor; + for (int y = ov_h; y--; ) { text_t *t1 = text [y]; diff --git a/src/rxvttoolkit.h b/src/rxvttoolkit.h index 7b5ff29b..8b87e989 100644 --- a/src/rxvttoolkit.h +++ b/src/rxvttoolkit.h @@ -270,7 +270,8 @@ struct rxvt_display : refcounted }; #ifdef USE_XIM -struct im_watcher : rxvt_watcher, callback { +struct im_watcher : rxvt_watcher, callback +{ void start (rxvt_display *display) { display->reg (this); diff --git a/src/rxvtutil.h b/src/rxvtutil.h index dd3981fb..87bdcc6f 100644 --- a/src/rxvtutil.h +++ b/src/rxvtutil.h @@ -113,7 +113,8 @@ int popcount (unsigned int x) CONST; #define MOD(m,n) (((m) + (n)) % (n)) // makes dynamically allocated objects zero-initialised -struct zero_initialized { +struct zero_initialized +{ void *operator new (size_t s); void operator delete (void *p, size_t s); }; @@ -124,7 +125,8 @@ struct zero_initialized { * Copyright (C) 1997-98 Kay Roemer & Arno Puder */ template -struct simplevec { +struct simplevec +{ typedef T* iterator; typedef const T* const_iterator; typedef unsigned long size_type; @@ -389,7 +391,8 @@ struct stringvec : simplevec #if 0 template -struct rxvt_vec : simplevec { +struct rxvt_vec : simplevec +{ typedef T *iterator; void push_back (T d) { simplevec::push_back ((void *)d); } @@ -404,7 +407,8 @@ struct rxvt_vec : simplevec { #endif template -struct auto_ptr { +struct auto_ptr +{ T *p; auto_ptr () : p (0) { } diff --git a/src/salloc.h b/src/salloc.h index 991d4386..fbe03483 100644 --- a/src/salloc.h +++ b/src/salloc.h @@ -5,7 +5,8 @@ // small blocks allocator -struct rxvt_salloc { +struct rxvt_salloc +{ struct chain { struct chain *next; }; diff --git a/src/screen.C b/src/screen.C index 4f259804..715e8457 100644 --- a/src/screen.C +++ b/src/screen.C @@ -2010,8 +2010,6 @@ rxvt_term::scr_printscreen (int fullhist) NOTHROW void rxvt_term::scr_refresh () NOTHROW { - unsigned char have_bg, - showcursor; /* show the cursor */ int16_t col, row, /* column/row we're processing */ ocrow; /* old cursor row */ int i; /* tmp */ @@ -2032,7 +2030,8 @@ rxvt_term::scr_refresh () NOTHROW */ refresh_count = 0; - have_bg = 0; + unsigned int old_screen_flags = screen.flags; + char have_bg = 0; #ifdef HAVE_BG_PIXMAP have_bg = bgPixmap.pixmap != None; #endif @@ -2043,13 +2042,19 @@ rxvt_term::scr_refresh () NOTHROW */ scr_reverse_selection (); + HOOK_INVOKE ((this, HOOK_REFRESH_BEGIN, DT_END)); +#if ENABLE_OVERLAY + scr_swap_overlay (); +#endif + + char showcursor = screen.flags & Screen_VisibleCursor; + /* * C: set the cursor character (s) */ { unsigned char setoldcursor; - showcursor = (screen.flags & Screen_VisibleCursor); #ifdef CURSOR_BLINK if (hidden_cursor) showcursor = 0; @@ -2132,11 +2137,6 @@ rxvt_term::scr_refresh () NOTHROW } } - HOOK_INVOKE ((this, HOOK_REFRESH_BEGIN, DT_END)); -#if ENABLE_OVERLAY - scr_swap_overlay (); -#endif - #ifndef NO_SLOW_LINK_SUPPORT /* * D: CopyArea pass - very useful for slower links @@ -2418,11 +2418,6 @@ rxvt_term::scr_refresh () NOTHROW } /* for (col....) */ } /* for (row....) */ -#if ENABLE_OVERLAY - scr_swap_overlay (); -#endif - HOOK_INVOKE ((this, HOOK_REFRESH_END, DT_END)); - /* * G: cleanup cursor and display outline cursor if necessary */ @@ -2470,8 +2465,14 @@ rxvt_term::scr_refresh () NOTHROW /* * H: cleanup selection */ +#if ENABLE_OVERLAY + scr_swap_overlay (); +#endif + HOOK_INVOKE ((this, HOOK_REFRESH_END, DT_END)); + scr_reverse_selection (); + screen.flags = old_screen_flags; num_scr = 0; num_scr_allow = 1; } @@ -3740,16 +3741,16 @@ rxvt_term::scr_overlay_new (int x, int y, int w, int h) NOTHROW x -= 1; clamp_it (x, 0, ncol - w); y -= 1; clamp_it (y, 0, nrow - h); - ov_x = x; ov_y = y; - ov_w = w; ov_h = h; + ov.x = x; ov.y = y; + ov.w = w; ov.h = h; - ov_text = new text_t *[h]; - ov_rend = new rend_t *[h]; + ov.text = new text_t *[h]; + ov.rend = new rend_t *[h]; for (y = 0; y < h; y++) { - text_t *tp = ov_text[y] = new text_t[w]; - rend_t *rp = ov_rend[y] = new rend_t[w]; + text_t *tp = ov.text[y] = new text_t[w]; + rend_t *rp = ov.rend[y] = new rend_t[w]; text_t t0, t1, t2; rend_t r = OVERLAY_RSTYLE; @@ -3778,31 +3779,31 @@ rxvt_term::scr_overlay_new (int x, int y, int w, int h) NOTHROW void rxvt_term::scr_overlay_off () NOTHROW { - if (!ov_text) + if (!ov.text) return; want_refresh = 1; - for (int y = 0; y < ov_h; y++) + for (int y = 0; y < ov.h; y++) { - delete [] ov_text[y]; - delete [] ov_rend[y]; + delete [] ov.text[y]; + delete [] ov.rend[y]; } - delete [] ov_text; ov_text = 0; - delete [] ov_rend; ov_rend = 0; + delete [] ov.text; ov.text = 0; + delete [] ov.rend; ov.rend = 0; } void rxvt_term::scr_overlay_set (int x, int y, text_t text, rend_t rend) NOTHROW { - if (!ov_text || x >= ov_w - 2 || y >= ov_h - 2) + if (!ov.text || x >= ov.w - 2 || y >= ov.h - 2) return; x++, y++; - ov_text[y][x] = text; - ov_rend[y][x] = rend; + ov.text[y][x] = text; + ov.rend[y][x] = rend; } void @@ -3831,19 +3832,24 @@ rxvt_term::scr_overlay_set (int x, int y, const wchar_t *s) NOTHROW void rxvt_term::scr_swap_overlay () NOTHROW { - if (!ov_text) + if (!ov.text) return; + // hide cursor if it is within the overlay area + if (IN_RANGE_EXC (screen.cur.col - ov.x, 0, ov.w) + && IN_RANGE_EXC (screen.cur.row - ov.y, 0, ov.h)) + screen.flags &= ~Screen_VisibleCursor; + // swap screen mem with overlay - for (int y = ov_h; y--; ) + for (int y = ov.h; y--; ) { - text_t *t1 = ov_text[y]; - rend_t *r1 = ov_rend[y]; + text_t *t1 = ov.text[y]; + rend_t *r1 = ov.rend[y]; - text_t *t2 = ROW(y + ov_y + view_start).t + ov_x; - rend_t *r2 = ROW(y + ov_y + view_start).r + ov_x; + text_t *t2 = ROW(y + ov.y + view_start).t + ov.x; + rend_t *r2 = ROW(y + ov.y + view_start).r + ov.x; - for (int x = ov_w; x--; ) + for (int x = ov.w; x--; ) { text_t t = *t1; *t1++ = *t2; *t2++ = t; rend_t r = *r1; *r1++ = *r2; *r2++ = SET_FONT (r, FONTSET (r)->find_font (t)); diff --git a/src/scrollbar.h b/src/scrollbar.h index 28e9670f..ec031f6f 100644 --- a/src/scrollbar.h +++ b/src/scrollbar.h @@ -46,7 +46,8 @@ enum sb_state { STATE_DOWN, }; -struct scrollBar_t { +struct scrollBar_t +{ rxvt_term *term; char state; /* scrollbar state */ char init; /* scrollbar has been initialised */ -- 2.34.1