Loading ...
Sorry, an error occurred while loading the content.

Transparent Background Patch Update

Expand Messages
  • Eckehard Berns
    Hi! I just updated the TransBack patch to apply cleanly to vim 6.3a.006. This also includes a fix for situations where a scrollbar is drawn to the left of the
    Message 1 of 1 , May 8 11:27 PM
    • 0 Attachment
      Hi!

      I just updated the TransBack patch to apply cleanly to vim 6.3a.006.
      This also includes a fix for situations where a scrollbar is drawn to
      the left of the vim window.

      *** ../vim63a.006/src/gui_mac.c Fri Apr 23 10:45:48 2004
      --- ./src/gui_mac.c Sun May 9 07:54:24 2004
      ***************
      *** 88,93 ****
      --- 88,102 ----
      static EventHandlerUPP mouseWheelHandlerUPP = NULL;
      #endif

      + #ifdef USE_CARBONIZED
      + # undef USE_TRANSPARENTBACKGROUND
      + # define USE_TRANSPARENTBACKGROUND
      + static void carbon_set_transparency(WindowRef w, float alpha);
      +
      + static float mytrans_alpha = 1.0f;
      + static CGContextRef mytrans_context;
      + #endif
      +
      /* Debugging feature: start Vim window OFFSETed */
      #undef USE_OFFSETED_WINDOW

      ***************
      *** 1796,1801 ****
      --- 1805,1822 ----
      gui_resize_shell(newWidth, newHeight);
      gui_mch_set_bg_color(gui.back_pixel);
      gui_set_shellsize(TRUE, FALSE);
      + # ifdef USE_TRANSPARENTBACKGROUND
      + if (mytrans_alpha != 1.0f)
      + {
      + Rect r;
      +
      + r.right = newWidth;
      + r.left = 0;
      + r.bottom = newHeight;
      + r.top = 0;
      + InvalWindowRect(gui.VimWindow, &r);
      + }
      + # endif
      #else
      newSize = GrowWindow(whichWindow, where, &resizeLimits);
      if (newSize != 0)
      ***************
      *** 1887,1892 ****
      --- 1908,1948 ----
      * ------------------------------------------------------------
      */

      + #ifdef USE_TRANSPARENTBACKGROUND
      + /*
      + * A transparent version of EraseRect
      + */
      + static void
      + EraseRectTrans(Rect *r)
      + {
      + CGrafPtr p;
      + CGRect cgr;
      + Rect pb;
      + RGBColor rgb;
      +
      + if (mytrans_alpha == 1.0f)
      + {
      + EraseRect(r);
      + return;
      + }
      +
      + p = GetWindowPort(gui.VimWindow);
      + GetPortBounds(p, &pb);
      + cgr = CGRectMake(pb.left + r->left, pb.bottom - r->bottom,
      + r->right - r->left, r->bottom - r->top);
      + if (gui.which_scrollbars[SBAR_LEFT])
      + cgr.origin.x += gui.scrollbar_width;
      + CGContextClearRect(mytrans_context, cgr);
      + GetBackColor(&rgb);
      + CGContextSetRGBFillColor(mytrans_context,
      + (float)rgb.red / 65535.0f,
      + (float)rgb.green / 65535.0f,
      + (float)rgb.blue / 65535.0f,
      + mytrans_alpha);
      + CGContextFillRect(mytrans_context, cgr);
      + }
      + #endif /* defined(USE_TRANSPARENTBACKGROUND) */
      +
      /*
      * Handle the Update Event
      */
      ***************
      *** 1923,1928 ****
      --- 1979,1988 ----

      /* Select the Window's Port */
      #ifdef USE_CARBONIZED
      + # ifdef USE_TRANSPARENTBACKGROUND
      + CGContextFlush(mytrans_context);
      + CGContextRelease(mytrans_context);
      + # endif
      SetPortWindowPort (whichWindow);
      #else
      SetPort (whichWindow);
      ***************
      *** 1930,1935 ****
      --- 1990,1998 ----

      /* Let's update the window */
      BeginUpdate (whichWindow);
      + #ifdef USE_TRANSPARENTBACKGROUND
      + CreateCGContextForPort(GetWindowPort(whichWindow), &mytrans_context);
      + #endif
      /* Redraw the biggest rectangle covering the area
      * to be updated.
      */
      ***************
      *** 1967,1990 ****
      --- 2030,2069 ----
      if (updateRectPtr->left < FILL_X(0))
      {
      SetRect (&rc, 0, 0, FILL_X(0), FILL_Y(Rows));
      + #ifdef USE_TRANSPARENTBACKGROUND
      + EraseRectTrans(&rc);
      + #else
      EraseRect (&rc);
      + #endif
      }
      if (updateRectPtr->top < FILL_Y(0))
      {
      SetRect (&rc, 0, 0, FILL_X(Columns), FILL_Y(0));
      + #ifdef USE_TRANSPARENTBACKGROUND
      + EraseRectTrans(&rc);
      + #else
      EraseRect (&rc);
      + #endif
      }
      if (updateRectPtr->right > FILL_X(Columns))
      {
      SetRect (&rc, FILL_X(Columns), 0,
      FILL_X(Columns) + gui.border_offset, FILL_Y(Rows));
      + #ifdef USE_TRANSPARENTBACKGROUND
      + EraseRectTrans(&rc);
      + #else
      EraseRect (&rc);
      + #endif
      }
      if (updateRectPtr->bottom > FILL_Y(Rows))
      {
      SetRect (&rc, 0, FILL_Y(Rows), FILL_X(Columns) + gui.border_offset,
      FILL_Y(Rows) + gui.border_offset);
      + #ifdef USE_TRANSPARENTBACKGROUND
      + EraseRectTrans(&rc);
      + #else
      EraseRect (&rc);
      + #endif
      }
      HUnlock ((Handle) updateRgn);
      #ifdef USE_CARBONIZED
      ***************
      *** 2011,2016 ****
      --- 2090,2112 ----
      DisposeRgn (saveRgn);
      EndUpdate (whichWindow);

      + #ifdef USE_TRANSPARENTBACKGROUND
      + /*
      + * TODO: I don't know how to reset the clipping path after
      + * ClipCGContextToRegion(), so I just create a new context for the
      + * current port.
      + * The header files state that the clipping path cannot be restored
      + * by a SaveGState/RestoreGState pair.
      + */
      + if (mytrans_alpha != 1.0f)
      + {
      + CGContextFlush(mytrans_context);
      + CGContextRelease(mytrans_context);
      + CreateCGContextForPort(GetWindowPort(gui.VimWindow),
      + &mytrans_context);
      + }
      + #endif
      +
      /* Restore original Port */
      SetPort (savePort);
      }
      ***************
      *** 2028,2034 ****
      --- 2124,2155 ----
      whichWindow = (WindowPtr) event->message;
      if ((event->modifiers) & activeFlag)
      /* Activate */
      + #ifdef USE_TRANSPARENTBACKGROUND
      + {
      + gui_focus_change(TRUE);
      + if (mytrans_alpha != 1.0f)
      + {
      + Rect r;
      +
      + /*
      + * in case the activate event is caused by showing Vim after
      + * it has been hidden, the whole window has to be redrawn
      + *
      + * TODO: distinguish between a normal focus change and a show
      + * application
      + */
      + GetWindowBounds(gui.VimWindow, kWindowContentRgn, &r);
      + r.right -= r.left;
      + r.left = 0;
      + r.bottom -= r.top;
      + r.top = 0;
      + gui_mch_set_bg_color(gui.back_pixel);
      + InvalWindowRect(gui.VimWindow, &r);
      + }
      + }
      + #else
      gui_focus_change(TRUE);
      + #endif
      else
      {
      /* Deactivate */
      ***************
      *** 2879,2884 ****
      --- 3000,3046 ----
      return noErr;
      }

      + #if defined(USE_TRANSPARENTBACKGROUND)
      + /*
      + * this handler does nothing more than return an empty region if
      + * the system asks for the kWindowOpaqueRgn of the window. Everything
      + * else is passed through to the next handler.
      + */
      + static OSStatus
      + gui_mac_window_getrgn(inHandlerCallRef, inEvent, inUserData)
      + EventHandlerCallRef inHandlerCallRef;
      + EventRef inEvent;
      + void *inUserData;
      + {
      + OSStatus err;
      + RgnHandle rgn, contentRgn;
      + WindowRegionCode rgnCode;
      +
      + if (mytrans_alpha == 1.0f)
      + goto nextHandler;
      +
      + if (kEventClassWindow != GetEventClass(inEvent)
      + || kEventWindowGetRegion != GetEventKind(inEvent))
      + goto nextHandler;
      + if (noErr != GetEventParameter(inEvent, kEventParamWindowRegionCode,
      + typeWindowRegionCode, NULL, sizeof(WindowRegionCode),
      + NULL, &rgnCode))
      + goto nextHandler;
      + if (rgnCode != kWindowOpaqueRgn)
      + goto nextHandler;
      + err = CallNextEventHandler(inHandlerCallRef, inEvent);
      + if (noErr != GetEventParameter(inEvent, kEventParamRgnHandle,
      + typeQDRgnHandle, NULL, sizeof(RgnHandle), NULL, &rgn))
      + goto nextHandler;
      + contentRgn = NewRgn();
      + GetWindowRegion(gui.VimWindow, kWindowContentRgn, contentRgn);
      + SetEmptyRgn(rgn);
      + return err;
      + nextHandler:
      + return CallNextEventHandler(inHandlerCallRef, inEvent);
      + }
      + #endif /* defined(USE_TRANSPARENTBACKGROUND) */
      +
      /*
      * Initialise the GUI. Create all the windows, set up all the call-backs
      * etc.
      ***************
      *** 2959,2965 ****
      --- 3121,3144 ----
      InstallReceiveHandler((DragReceiveHandlerUPP)receiveHandler,
      gui.VimWindow, NULL);
      #ifdef USE_CARBONIZED
      + # ifdef USE_TRANSPARENTBACKGROUND
      + {
      + /* install the event handler for kEventWindowGetRegion */
      + EventTypeSpec ets[] = {
      + { kEventClassWindow, kEventWindowGetRegion }
      + };
      + EventHandlerRef ehr;
      + EventHandlerUPP handlerUPP =
      + NewEventHandlerUPP(gui_mac_window_getrgn);
      + if (noErr != InstallEventHandler(GetWindowEventTarget(gui.VimWindow),
      + handlerUPP, 1, ets, NULL, &ehr))
      + printf("couldn't install handler for kEventWindowGetRegion\n");
      + }
      + # endif
      SetPortWindowPort ( gui.VimWindow );
      + # ifdef USE_TRANSPARENTBACKGROUND
      + carbon_set_transparency(gui.VimWindow, (float)p_transparency / 255.0f);
      + # endif
      #else
      SetPort(gui.VimWindow);
      #endif
      ***************
      *** 3076,3081 ****
      --- 3255,3263 ----
      int
      gui_mch_open()
      {
      + #ifdef USE_TRANSPARENTBACKGROUND
      + CreateCGContextForPort(GetWindowPort(gui.VimWindow), &mytrans_context);
      + #endif
      ShowWindow(gui.VimWindow);

      if (gui_win_x != -1 && gui_win_y != -1)
      ***************
      *** 3257,3262 ****
      --- 3439,3458 ----
      gui.char_width = CharWidth ('_');
      gui.char_height = font_info.ascent + font_info.descent + p_linespace;

      + #ifdef USE_TRANSPARENTBACKGROUND
      + if (mytrans_alpha != 1.0f)
      + {
      + Rect r;
      +
      + GetWindowBounds(gui.VimWindow, kWindowContentRgn, &r);
      + r.right -= r.left;
      + r.left = 0;
      + r.bottom -= r.top;
      + r.top = 0;
      + InvalWindowRect(gui.VimWindow, &r);
      + }
      + #endif
      +
      return OK;

      }
      ***************
      *** 3534,3539 ****
      --- 3730,3738 ----
      #if defined(FEAT_GUI) && defined(MACOS_X)
      SInt32 sys_version;
      #endif
      + #ifdef USE_TRANSPARENTBACKGROUND
      + Rect r;
      + #endif
      #ifdef FEAT_MBYTE
      char_u *tofree = NULL;

      ***************
      *** 3587,3593 ****
      --- 3786,3796 ----
      rc.top = FILL_Y(row);
      rc.right = FILL_X(col + len) + (col + len == Columns);
      rc.bottom = FILL_Y(row + 1);
      + #ifdef USE_TRANSPARENTBACKGROUND
      + EraseRectTrans(&rc);
      + #else
      EraseRect(&rc);
      + #endif
      }

      MoveTo(TEXT_X(col), TEXT_Y(row));
      ***************
      *** 3606,3611 ****
      --- 3809,3825 ----
      {
      TextMode (srcOr);
      }
      + #ifdef USE_TRANSPARENTBACKGROUND
      + else if (mytrans_alpha != 1.0f)
      + {
      + r.left = TEXT_X(col);
      + r.top = row * gui.char_height + gui.border_width;
      + r.right = TEXT_X(col + len);
      + r.bottom = (row + 1) * gui.char_height + gui.border_width;
      + EraseRectTrans(&r);
      + TextMode(srcOr /* transparent */);
      + }
      + #endif

      MoveTo (TEXT_X(col), TEXT_Y(row));
      DrawText ((char *)s, 0, len);
      ***************
      *** 3670,3676 ****

      ui_delay((long)msec, TRUE); /* wait for some msec */

      ! InvertRect(&rc);
      }

      /*
      --- 3884,3903 ----

      ui_delay((long)msec, TRUE); /* wait for some msec */

      ! #ifdef USE_TRANSPARENTBACKGROUND
      ! if (mytrans_alpha != 1.0f)
      ! {
      ! Rect r;
      !
      ! GetWindowBounds(gui.VimWindow, kWindowContentRgn, &r);
      ! r.right -= r.left;
      ! r.left = 0;
      ! r.bottom -= r.top;
      ! r.top = 0;
      ! InvalWindowRect(gui.VimWindow, &r);
      ! } else
      ! #endif
      ! InvertRect(&rc);
      }

      /*
      ***************
      *** 3904,3909 ****
      --- 4131,4140 ----
      gui_mch_flush()
      {
      /* TODO: Is anything needed here? */
      + #ifdef USE_TRANSPARENTBACKGROUND
      + if (mytrans_alpha != 1.0f)
      + CGContextSynchronize(mytrans_context);
      + #endif
      }

      /*
      ***************
      *** 3929,3935 ****
      --- 4160,4170 ----
      rc.bottom = FILL_Y(row2 + 1);

      gui_mch_set_bg_color(gui.back_pixel);
      + #ifdef USE_TRANSPARENTBACKGROUND
      + EraseRectTrans(&rc);
      + #else
      EraseRect (&rc);
      + #endif
      }

      /*
      ***************
      *** 3946,3952 ****
      --- 4181,4191 ----
      rc.bottom = Rows * gui.char_height + 2 * gui.border_width;

      gui_mch_set_bg_color(gui.back_pixel);
      + #ifdef USE_TRANSPARENTBACKGROUND
      + EraseRectTrans(&rc);
      + #else
      EraseRect(&rc);
      + #endif
      /* gui_mch_set_fg_color(gui.norm_pixel);
      FrameRect(&rc);
      */
      ***************
      *** 4649,4654 ****
      --- 4888,4897 ----
      int w;
      int h;
      {
      + #ifdef USE_TRANSPARENTBACKGROUND
      + Rect r;
      + #endif
      +
      gui_mch_set_bg_color(gui.back_pixel);
      /* if (gui.which_scrollbars[SBAR_LEFT])
      {
      ***************
      *** 4668,4678 ****
      --- 4911,4931 ----
      if (gui.which_scrollbars[SBAR_LEFT])
      x -= 15;

      + #ifdef USE_TRANSPARENTBACKGROUND
      + if (mytrans_alpha != 1.0f)
      + GetControlBounds(sb->id, &r);
      + #endif
      +
      MoveControl (sb->id, x, y);
      SizeControl (sb->id, w, h);
      #ifdef DEBUG_MAC_SB
      printf ("size_sb (%x) %x, %x, %x, %x\n",sb->id, x, y, w, h);
      #endif
      +
      + #ifdef USE_TRANSPARENTBACKGROUND
      + if (mytrans_alpha != 1.0f && r.left < x)
      + EraseRectTrans(&r);
      + #endif
      }

      void
      ***************
      *** 5818,5820 ****
      --- 6071,6111 ----
      && script == GetScriptManagerVariable(smSysScript)) ? 1 : 0;
      }
      #endif /* defined(USE_IM_CONTROL) || defined(PROTO) */
      +
      + #ifdef USE_TRANSPARENTBACKGROUND
      + void
      + carbon_set_transparency(w, alpha)
      + WindowRef w;
      + float alpha;
      + {
      + Rect r;
      +
      + if (!w)
      + w = gui.VimWindow;
      +
      + /*
      + * if we want a transparent window background the system must be fooled
      + * that the window isn't fully opaque. I do this by setting the alpha
      + * value a bit below 1.0f
      + */
      + if (alpha == 1.0f)
      + SetWindowAlpha(w, 1.0f);
      + else
      + SetWindowAlpha(w, 0.9999999f);
      + mytrans_alpha = alpha;
      +
      + GetWindowBounds(gui.VimWindow, kWindowContentRgn, &r);
      + r.right -= r.left;
      + r.left = 0;
      + r.bottom -= r.top;
      + r.top = 0;
      + InvalWindowRect(gui.VimWindow, &r);
      + }
      +
      + void
      + gui_mch_set_transparency(alpha)
      + int alpha;
      + {
      + carbon_set_transparency(NULL, (float)alpha / 255);
      + }
      + #endif
      *** ../vim63a.006/src/option.c Wed May 5 11:43:49 2004
      --- ./src/option.c Sun May 9 07:23:22 2004
      ***************
      *** 2113,2118 ****
      --- 2113,2123 ----
      (char_u *)&p_tbis, PV_NONE,
      {(char_u *)"small", (char_u *)0L}},
      #endif
      + #ifdef USE_TRANSPARENTBACKGROUND
      + {"transparency", "tra", P_NUM|P_VI_DEF,
      + (char_u *)&p_transparency, PV_NONE,
      + {(char_u *)255L, (char_u *)0L}},
      + #endif
      {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
      (char_u *)&p_ttimeout, PV_NONE,
      {(char_u *)FALSE, (char_u *)0L}},
      ***************
      *** 6692,6697 ****
      --- 6697,6711 ----
      foldUpdateAll(curwin);
      }
      #endif /* FEAT_FOLDING */
      +
      + #ifdef USE_TRANSPARENTBACKGROUND
      + else if ((long *)varp == &p_transparency)
      + {
      + if (p_transparency < 1 || p_transparency > 255)
      + p_transparency = 255;
      + gui_mch_set_transparency(p_transparency);
      + }
      + #endif

      else if (pp == &curbuf->b_p_iminsert)
      {
      *** ../vim63a.006/src/option.h Wed May 5 11:43:49 2004
      --- ./src/option.h Sun May 9 07:23:22 2004
      ***************
      *** 704,709 ****
      --- 704,712 ----
      #ifdef FEAT_INS_EXPAND
      EXTERN char_u *p_tsr; /* 'thesaurus' */
      #endif
      + #ifdef USE_TRANSPARENTBACKGROUND
      + EXTERN long p_transparency; /* 'transparency'*/
      + #endif
      EXTERN int p_ttimeout; /* 'ttimeout' */
      EXTERN long p_ttm; /* 'ttimeoutlen' */
      EXTERN int p_tbi; /* 'ttybuiltin' */
      *** ../vim63a.006/src/os_mac.h Sun Feb 1 21:40:30 2004
      --- ./src/os_mac.h Sun May 9 07:23:22 2004
      ***************
      *** 118,123 ****
      --- 118,124 ----
      #if defined(TARGET_API_MAC_OSX) && TARGET_API_MAC_OSX
      # undef COLON_AS_PATHSEP
      # define USE_UNIXFILENAME
      + # define USE_TRANSPARENTBACKGROUND
      #else
      # define COLON_AS_PATHSEP
      # define DONT_ADD_PATHSEP_TO_DIR
      diff -cr --exclude=auto --exclude=po ../vim63a.006/src/proto/gui_mac.pro ./src/proto/gui_mac.pro
      *** ../vim63a.006/src/proto/gui_mac.pro Sun Sep 7 23:42:13 2003
      --- ./src/proto/gui_mac.pro Sun May 9 07:23:22 2004
      ***************
      *** 134,139 ****
      --- 134,140 ----
      void gui_mac_doMouseDownEvent __ARGS((EventRecord *theEvent));
      void gui_mac_doMouseMovedEvent __ARGS((EventRecord *event));
      void gui_mac_doMouseUpEvent __ARGS((EventRecord *theEvent));
      + void gui_mch_set_transparency __ARGS((int alpha));

      int C2PascalString (char_u *CString, Str255 *PascalString);
      int GetFSSpecFromPath ( char_u *file, FSSpec *fileFSSpec);

      --
      Eckehard Berns
    Your message has been successfully submitted and would be delivered to recipients shortly.