*** empty log message ***
authorpcg <pcg>
Tue, 24 Feb 2004 00:44:23 +0000 (00:44 +0000)
committerpcg <pcg>
Tue, 24 Feb 2004 00:44:23 +0000 (00:44 +0000)
src/defaultfont.C
src/defaultfont.h
src/init.C
src/rxvtlib.h.in
src/screen.C

index d72d9cf3df220df74d99c70a81bb322cf33c91b3..ed1f5aac2c8ed8d6e440c9a36044867e9777da96 100644 (file)
@@ -26,7 +26,6 @@
 #include <cstdlib>
 
 #define DISPLAY  r->display->display
-#define DRAWABLE r->TermWin.vt
 #define GC       r->TermWin.gc
 
 const struct rxvt_fallback_font {
@@ -101,6 +100,22 @@ const struct rxvt_fallback_font {
 
 /////////////////////////////////////////////////////////////////////////////
 
+rxvt_drawable::~rxvt_drawable ()
+{
+  if (xftdrawable)
+    XftDrawDestroy (xftdrawable);
+}
+
+rxvt_drawable::operator XftDraw *()
+{
+  if (!xftdrawable)
+    xftdrawable = XftDrawCreate (display->display, drawable, display->visual, display->cmap);
+
+  return xftdrawable;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
 static void *enc_buf;
 static uint32_t enc_len;
 
@@ -163,14 +178,18 @@ enc_xchar2b (const text_t *text, uint32_t len, codeset cs, bool &zero)
 /////////////////////////////////////////////////////////////////////////////
 
 void
-rxvt_font::clear_rect (int x, int y, int w, int h, int color)
+rxvt_font::clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color)
 {
   if (color == Color_bg)
-    XClearArea (DISPLAY, DRAWABLE, x, y, w, h, FALSE);
+    XClearArea (d.display->display, d, x, y, w, h, FALSE);
   else if (color >= 0)
     {
-      XSetForeground (DISPLAY, GC, r->PixColors[color]);
-      XFillRectangle (DISPLAY, DRAWABLE, GC, x, y, w, h);
+#if XFT
+      XftDrawRect (d, &r->PixColors[color].c, x, y, w, h);
+#else
+      XSetForeground (d.display->display, GC, r->PixColors[color]);
+      XFillRectangle (d.display->display, d, GC, x, y, w, h);
+#endif
     }
 }
 
@@ -265,19 +284,19 @@ struct rxvt_font_default : rxvt_font {
     return false;
   }
 
-  void draw (int x, int y,
+  void draw (rxvt_drawable &d, int x, int y,
              const text_t *text, int len,
              int fg, int bg);
 };
 
 void
-rxvt_font_default::draw (int x, int y,
+rxvt_font_default::draw (rxvt_drawable &d, int x, int y,
                          const text_t *text, int len,
                          int fg, int bg)
 {
-  clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
+  clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
 
-  XSetForeground (DISPLAY, GC, r->PixColors[fg]);
+  XSetForeground (d.display->display, GC, r->PixColors[fg]);
 
   while (len--)
     {
@@ -298,25 +317,25 @@ rxvt_font_default::draw (int x, int y,
                 {
                   case '1':
                     gcv.line_width = 0;
-                    XChangeGC (DISPLAY, GC, GCLineWidth, &gcv);
+                    XChangeGC (d.display->display, GC, GCLineWidth, &gcv);
                     break;
 
                   case '2':
                     gcv.line_width = 2;
-                    XChangeGC (DISPLAY, GC, GCLineWidth, &gcv);
+                    XChangeGC (d.display->display, GC, GCLineWidth, &gcv);
                     break;
 
-                  case 'h': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y1, x1, y1); break;
-                  case 'H': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y1, x2, y1); break;
-                  case 'v': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y0, x1, y1); break;
-                  case 'V': XDrawLine (DISPLAY, DRAWABLE, GC, x1, y1, x1, y2); break;
-                  case 'a': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y2, x2, y0); break;
-                  case 'b': XDrawLine (DISPLAY, DRAWABLE, GC, x0, y0, x2, y2); break;
+                  case 'h': XDrawLine (d.display->display, d, GC, x0, y1, x1, y1); break;
+                  case 'H': XDrawLine (d.display->display, d, GC, x1, y1, x2, y1); break;
+                  case 'v': XDrawLine (d.display->display, d, GC, x1, y0, x1, y1); break;
+                  case 'V': XDrawLine (d.display->display, d, GC, x1, y1, x1, y2); break;
+                  case 'a': XDrawLine (d.display->display, d, GC, x0, y2, x2, y0); break;
+                  case 'b': XDrawLine (d.display->display, d, GC, x0, y0, x2, y2); break;
                 }
             }
 
           gcv.line_width = 0;
-          XChangeGC (DISPLAY, GC, GCLineWidth, &gcv);
+          XChangeGC (d.display->display, GC, GCLineWidth, &gcv);
         }
       else
         switch (*text++)
@@ -325,7 +344,7 @@ rxvt_font_default::draw (int x, int y,
             case ZERO_WIDTH_CHAR:
               break;
             default:
-              XDrawRectangle (DISPLAY, DRAWABLE, GC, x + 2, y + 2, r->TermWin.fwidth - 5, r->TermWin.fheight - 5);
+              XDrawRectangle (d.display->display, d, GC, x + 2, y + 2, r->TermWin.fwidth - 5, r->TermWin.fheight - 5);
           }
 
       x += r->TermWin.fwidth;
@@ -345,7 +364,7 @@ struct rxvt_font_x11 : rxvt_font {
 
   bool has_codepoint (uint32_t unicode);
 
-  void draw (int x, int y,
+  void draw (rxvt_drawable &d, int x, int y,
              const text_t *text, int len,
              int fg, int bg);
 
@@ -646,7 +665,7 @@ rxvt_font_x11::has_codepoint (uint32_t unicode)
 }
 
 void
-rxvt_font_x11::draw (int x, int y,
+rxvt_font_x11::draw (rxvt_drawable &d, int x, int y,
                      const text_t *text, int len,
                      int fg, int bg)
 {
@@ -672,21 +691,21 @@ rxvt_font_x11::draw (int x, int y,
 
       if (bg == Color_bg && !slow)
         {
-          XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v);
-          XDrawImageString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, len);
+          XChangeGC (d.display->display, GC, GCForeground | GCBackground | GCFont, &v);
+          XDrawImageString16 (d.display->display, d, GC, x, y + base, xc, len);
         }
       else
         {
-          clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
+          clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
 
-          XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v);
+          XChangeGC (d.display->display, GC, GCForeground | GCFont, &v);
           
           if (slow)
             {
               do
                 {
                   if (xc->byte1 || xc->byte2)
-                    XDrawString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1);
+                    XDrawString16 (d.display->display, d, GC, x, y + base, xc, 1);
 
                   x += r->TermWin.fwidth;
                   xc++; len--;
@@ -694,7 +713,7 @@ rxvt_font_x11::draw (int x, int y,
               while (len);
             }
           else
-            XDrawString16 (DISPLAY, DRAWABLE, GC, x, y + base, xc, len);
+            XDrawString16 (d.display->display, d, GC, x, y + base, xc, len);
         }
     }
   else
@@ -703,21 +722,21 @@ rxvt_font_x11::draw (int x, int y,
 
       if (bg == Color_bg && !slow)
         {
-          XChangeGC (DISPLAY, GC, GCForeground | GCBackground | GCFont, &v);
-          XDrawImageString (DISPLAY, DRAWABLE, GC, x, y + base, xc, len);
+          XChangeGC (d.display->display, GC, GCForeground | GCBackground | GCFont, &v);
+          XDrawImageString (d.display->display, d, GC, x, y + base, xc, len);
         }
       else
         {
-          clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
+          clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
 
-          XChangeGC (DISPLAY, GC, GCForeground | GCFont, &v);
+          XChangeGC (d.display->display, GC, GCForeground | GCFont, &v);
           
           if (slow)
             {
               do
                 {
                   if (*xc)
-                    XDrawString (DISPLAY, DRAWABLE, GC, x, y + base, xc, 1);
+                    XDrawString (d.display->display, d, GC, x, y + base, xc, 1);
 
                   x += r->TermWin.fwidth;
                   xc++; len--;
@@ -725,7 +744,7 @@ rxvt_font_x11::draw (int x, int y,
               while (len);
             }
           else
-            XDrawString (DISPLAY, DRAWABLE, GC, x, y + base, xc, len);
+            XDrawString (d.display->display, d, GC, x, y + base, xc, len);
         }
     }
 }
@@ -740,7 +759,7 @@ rxvt_font_x11::draw (int x, int y,
 #endif
 
 struct rxvt_font_xft : rxvt_font {
-  rxvt_font_xft () { f = 0; d = 0; }
+  rxvt_font_xft () { f = 0; }
 
   void clear ();
 
@@ -748,7 +767,7 @@ struct rxvt_font_xft : rxvt_font {
 
   bool load (const rxvt_fontprop &prop);
 
-  void draw (int x, int y,
+  void draw (rxvt_drawable &d, int x, int y,
              const text_t *text, int len,
              int fg, int bg);
 
@@ -756,18 +775,11 @@ struct rxvt_font_xft : rxvt_font {
 
 protected:
   XftFont *f;
-  XftDraw *d;
 };
 
 void
 rxvt_font_xft::clear ()
 {
-  if (d)
-    {
-      XftDrawDestroy (d);
-      d = 0;
-    }
-
   if (f)
     {
       XftFontClose (DISPLAY, f);
@@ -888,16 +900,11 @@ rxvt_font_xft::has_codepoint (uint32_t unicode)
 }
 
 void
-rxvt_font_xft::draw (int x, int y,
+rxvt_font_xft::draw (rxvt_drawable &d, int x, int y,
                      const text_t *text, int len,
                      int fg, int bg)
 {
-  d = XftDrawCreate (DISPLAY, DRAWABLE, r->display->visual, r->display->cmap);
-
-  if (bg >= 0 && bg != Color_bg)
-    XftDrawRect (d, &r->PixColors[bg].c, x, y, r->TermWin.fwidth * len, r->TermWin.fheight);
-  else
-    clear_rect (x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
+  clear_rect (d, x, y, r->TermWin.fwidth * len, r->TermWin.fheight, bg);
 
   if (!slow && width == r->TermWin.fwidth && 0)
     {
@@ -919,14 +926,14 @@ rxvt_font_xft::draw (int x, int y,
               XGlyphInfo extents;
               if (sizeof (text_t) == sizeof (FcChar16))
                 {
-                  XftTextExtents16 (DISPLAY, f, (const FcChar16 *)text, 1, &extents);
+                  XftTextExtents16 (d.display->display, f, (const FcChar16 *)text, 1, &extents);
                   XftDrawString16 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2,
                                    y + r->TermWin.fbase, (const FcChar16 *)text, 1);
                 }
               else
                 {
                   XGlyphInfo extents;
-                  XftTextExtents32 (DISPLAY, f, (const FcChar32 *)text, 1, &extents);
+                  XftTextExtents32 (d.display->display, f, (const FcChar32 *)text, 1, &extents);
                   XftDrawString32 (d, &r->PixColors[fg].c, f, x + extents.x + (fwidth - extents.width) / 2,
                                    y + r->TermWin.fbase, (const FcChar32 *)text, 1);
                 }
index 3b9a6380b43e1c1276bab1503b2963a4660f882d..ab7cb5765f3b5aecc968fb9d4d26b9edb2bc186f 100644 (file)
@@ -1,6 +1,11 @@
 #ifndef DEFAULTFONT_H_
 #define DEFAULTFONT_H_
 
+#include <X11/Xlib.h>
+#if XFT
+# include <X11/Xft/Xft.h>
+#endif
+
 #ifdef HAVE_XSETLOCALE
 # define X_LOCALE
 # include <X11/Xlocale.h>
@@ -28,6 +33,20 @@ struct rxvt_fontprop {
   int weight, slant;
 };
 
+struct rxvt_drawable {
+  rxvt_display *display;
+  Drawable drawable;
+# if XFT
+  XftDraw *xftdrawable;
+#endif
+  rxvt_drawable (rxvt_display *display, Drawable drawable)
+  : display(display), drawable(drawable), xftdrawable(0) { }
+  ~rxvt_drawable ();
+
+  operator Drawable() { return drawable; }
+  operator XftDraw *();
+};
+
 struct rxvt_font {
   // managed by the fontset
   rxvt_t r;
@@ -51,7 +70,7 @@ struct rxvt_font {
   rxvt_font () { name = 0; }
   ~rxvt_font () { free (name); };
 
-  void clear_rect (int x, int y, int w, int h, int color);
+  void clear_rect (rxvt_drawable &d, int x, int y, int w, int h, int color);
 
   virtual void clear () { };
 
@@ -60,7 +79,8 @@ struct rxvt_font {
   virtual bool load (const rxvt_fontprop &prop) = 0;
   virtual bool has_codepoint (uint32_t unicode) = 0;
 
-  virtual void draw (int x, int y,
+  virtual void draw (rxvt_drawable &d,
+                     int x, int y,
                      const text_t *text, int len,
                      int fg, int bg) = 0;
 };
index 9427dc4548320ac5c1d3a9cb9de0d1370727da9a..6f2f043bed12e39aec4cdd367c0a70615fef8f3a 100644 (file)
@@ -1286,17 +1286,15 @@ rxvt_term::create_windows (int argc, const char *const *argv)
                          GCForeground | GCBackground
                          | GCGraphicsExposures, &gcvalue);
 
+  TermWin.drawable = new rxvt_drawable (display, TermWin.vt);
+
 #if defined(MENUBAR) || defined(RXVT_SCROLLBAR)
   gcvalue.foreground = PixColors[Color_topShadow];
-  topShadowGC = XCreateGC (display->display, TermWin.vt,
-                          GCForeground, &gcvalue);
+  topShadowGC = XCreateGC (display->display, TermWin.vt, GCForeground, &gcvalue);
   gcvalue.foreground = PixColors[Color_bottomShadow];
-  botShadowGC = XCreateGC (display->display, TermWin.vt,
-                          GCForeground, &gcvalue);
-  gcvalue.foreground = PixColors[ (XDEPTH <= 2 ? Color_fg
-                                  : Color_scroll)];
-  scrollbarGC = XCreateGC (display->display, TermWin.vt,
-                          GCForeground, &gcvalue);
+  botShadowGC = XCreateGC (display->display, TermWin.vt, GCForeground, &gcvalue);
+  gcvalue.foreground = PixColors[ (XDEPTH <= 2 ? Color_fg : Color_scroll)];
+  scrollbarGC = XCreateGC (display->display, TermWin.vt, GCForeground, &gcvalue);
 #endif
 }
 
index ddbd81935aa1eba5e9cb820984185aa9c57521c7..fbb5ee20e798231333f39ba0f8e56ebf80353fc1 100644 (file)
@@ -46,6 +46,7 @@ struct rxvt_vars;               /* defined later on */
 struct rxvt_term;
 struct rxvt_display;
 struct rxvt_im;
+struct rxvt_drawable;
 
 typedef struct rxvt_term *rxvt_t;
 
@@ -102,6 +103,7 @@ typedef struct {
   GC             gc;            /* GC for drawing                           */
   Pixmap         pixmap;
   rxvt_fontset  *fontset;
+  rxvt_drawable *drawable;
 } TermWin_t;
 
 /*
index 7176cbe01e0104d7efc0a40c029129c99c6a4087..b64b106bd600d3afe02a4066e5b240b7005959c2 100644 (file)
@@ -2171,7 +2171,7 @@ rxvt_term::scr_refresh (unsigned char refresh_type)
           rxvt_font *font = (*TermWin.fontset)[fid];
 
           if (back == fore)
-            font->clear_rect (xpixel, ypixel,
+            font->clear_rect (*TermWin.drawable, xpixel, ypixel,
                               TermWin.fwidth * count, TermWin.fheight,
                               back);
           else if (back == Color_bg)
@@ -2183,15 +2183,15 @@ rxvt_term::scr_refresh (unsigned char refresh_type)
                   for (i = 0; i < count; i++) /* don't draw empty strings */
                     if (text[i] != ' ')
                       {
-                        font->draw (xpixel, ypixel, text, count, fore, -1);
+                        font->draw (*TermWin.drawable, xpixel, ypixel, text, count, fore, -1);
                         break;
                       }
                 }
               else
-                font->draw (xpixel, ypixel, text, count, fore, Color_bg);
+                font->draw (*TermWin.drawable, xpixel, ypixel, text, count, fore, Color_bg);
             }
           else
-            font->draw (xpixel, ypixel, text, count, fore, back);
+            font->draw (*TermWin.drawable, xpixel, ypixel, text, count, fore, back);
 
           if ((rend & RS_Uline) && (font->descent > 1))
             XDrawLine (display->display, drawBuffer, TermWin.gc,