minor overlay refactoring, syntax changes
authorroot <root>
Wed, 5 Nov 2008 14:43:54 +0000 (14:43 +0000)
committerroot <root>
Wed, 5 Nov 2008 14:43:54 +0000 (14:43 +0000)
12 files changed:
Changes
src/encoding.h
src/perl/overlay-osc
src/rxvt.h
src/rxvtdaemon.h
src/rxvtfont.h
src/rxvtperl.xs
src/rxvttoolkit.h
src/rxvtutil.h
src/salloc.h
src/screen.C
src/scrollbar.h

diff --git a/Changes b/Changes
index a693c2687cf7e6f7e7ae9aba9d96465a2dc7c239..61a8c82d2e3a1767ad66347bf5959d42992b336b 100644 (file)
--- 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.
index 2d1657f4d881df0e8b248d47cc3b4f7118b09c53..955482c6e497dbc1ddca6418854f0b9d0c513028 100644 (file)
@@ -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);
 };
 
index aee671f477405c9a7cc5d246f00771e2aaacd32d..289ec8b8b7c6237d12e96f07cce9df9ed1eb79b3 100644 (file)
@@ -4,7 +4,7 @@
 # printf "\033]777;overlay;action;args\007"
 #
 # action "simple;<id>;<timeout>;<x>;<y>;<h|t>;<text>"
-#   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;<id>;<seconds>"
index 3fa5f83c9cfb2c36e3d6cd5b67a13b8c5bb8d2a3..1b6d80eeae19da7e4887bbc9487bf2083ae439fc 100644 (file)
@@ -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 <X11/Xmd.h>
-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<void (const char *)> log_callback;
 typedef callback<int (int)> getfd_callback;
 
@@ -658,7 +665,8 @@ typedef callback<int (int)> 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<compose_char> 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<rxvt_term *>(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;
index b7203ba48fa58963603cbe5a967e8ef5a6b3837d..e77f7650d1e738150117eca9e111220470a7574c 100644 (file)
@@ -3,7 +3,8 @@
 
 #include "rxvtutil.h"
 
-struct rxvt_connection {
+struct rxvt_connection
+{
   int fd;
 
   static char *unix_sockname ();
index 86281664eeaa2c50ac55f9007dcf8a4c7780bb43..ec286a3a50e8c2730f20bc8c4d4009d3f60aa862 100644 (file)
@@ -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);
index 6cf7e8334f587cd2a8d8cd7a034166d92f8749ad..369e3cea2535e263169937e05c950265e6398d18 100644 (file)
@@ -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];
index 7b5ff29b313426df9fd58fecc817e9f358b4a7dc..8b87e989d029aff5abaadf18cd3fa718658a2ead 100644 (file)
@@ -270,7 +270,8 @@ struct rxvt_display : refcounted
 };
 
 #ifdef USE_XIM
-struct im_watcher : rxvt_watcher, callback<void (void)> {
+struct im_watcher : rxvt_watcher, callback<void (void)>
+{
   void start (rxvt_display *display)
   {
     display->reg (this);
index dd3981fb33f72a0045a865d631c0f46ddcad50d3..87bdcc6fe68bd700d2d58c832f1e1d8ccac7b72d 100644 (file)
@@ -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<class T>
-struct simplevec {
+struct simplevec
+{
     typedef T* iterator;
     typedef const T* const_iterator;
     typedef unsigned long size_type;
@@ -389,7 +391,8 @@ struct stringvec : simplevec<char *>
 
 #if 0
 template<typename T>
-struct rxvt_vec : simplevec<void *> {
+struct rxvt_vec : simplevec<void *>
+{
   typedef T *iterator;
 
   void push_back (T d) { simplevec<void *>::push_back ((void *)d); }
@@ -404,7 +407,8 @@ struct rxvt_vec : simplevec<void *> {
 #endif
 
 template<typename T>
-struct auto_ptr {
+struct auto_ptr
+{
   T *p;
 
   auto_ptr () : p (0) { }
index 991d43865d39c4ef14050de907a89b35feeafe92..fbe034834951ee3d76c9b1ba544effddaa2ca22e 100644 (file)
@@ -5,7 +5,8 @@
 
 // small blocks allocator
 
-struct rxvt_salloc {
+struct rxvt_salloc
+{
   struct chain {
     struct chain *next;
   };
index 4f259804276e232c95289284f725fcf63951fcf6..715e8457c5a3f8a1b1d010ace98e0f85f78f36c0 100644 (file)
@@ -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));
index 28e9670f87fbabe65c9a4631bf1afa94bb7b1a08..ec031f6f6bfee3717dc4a3fea6013addcb4b7ae8 100644 (file)
@@ -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           */