Advertisement
zqso

ns-alpha-background-2024-1-25-9b436cc .patch

Jan 25th, 2024
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 10.10 KB | None | 0 0
  1. diff --git a/src/macfont.m b/src/macfont.m
  2. index 8aba440d196..56c1eb57024 100644
  3. --- a/src/macfont.m
  4. +++ b/src/macfont.m
  5. @@ -2953,9 +2953,14 @@ So we use CTFontDescriptorCreateMatchingFontDescriptor (no
  6.              CG_SET_FILL_COLOR_WITH_FACE_FOREGROUND (context, face);
  7.            else
  8.              CG_SET_FILL_COLOR_WITH_FRAME_CURSOR (context, f);
  9. -        }
  10. +     CGContextSetAlpha(context, 1);
  11. +   }
  12.        else
  13. -        CG_SET_FILL_COLOR_WITH_FACE_BACKGROUND (context, face);
  14. +   {
  15. +     CGContextSetAlpha(context, f->alpha_background);
  16. +     CG_SET_FILL_COLOR_WITH_FACE_BACKGROUND (context, face);
  17. +   }
  18. +      CGContextClearRect(context, background_rect);
  19.        CGContextFillRects (context, &background_rect, 1);
  20.      }
  21.  
  22. @@ -2964,6 +2969,7 @@ So we use CTFontDescriptorCreateMatchingFontDescriptor (no
  23.        CGAffineTransform atfm;
  24.  
  25.        CGContextScaleCTM (context, 1, -1);
  26. +      CGContextSetAlpha(context, 1);
  27.        if (s->hl == DRAW_CURSOR)
  28.          {
  29.            if (face && (NS_FACE_BACKGROUND (face)
  30. diff --git a/src/nsfns.m b/src/nsfns.m
  31. index b0281aac257..3e19cce89de 100644
  32. --- a/src/nsfns.m
  33. +++ b/src/nsfns.m
  34. @@ -301,7 +301,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
  35.    struct face *face;
  36.    NSColor *col;
  37.    NSView *view = FRAME_NS_VIEW (f);
  38. -  EmacsCGFloat alpha;
  39. +  EmacsCGFloat alpha = f->alpha_background;
  40.  
  41.    block_input ();
  42.    if (ns_lisp_to_color (arg, &col))
  43. @@ -316,11 +316,10 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
  44.    f->output_data.ns->background_color = col;
  45.  
  46.    FRAME_BACKGROUND_PIXEL (f) = [col unsignedLong];
  47. -  alpha = [col alphaComponent];
  48.  
  49.    if (view != nil)
  50.      {
  51. -      [[view window] setBackgroundColor: col];
  52. +      [[view window] setBackgroundColor: [col colorWithAlphaComponent: alpha]];
  53.  
  54.        if (alpha != (EmacsCGFloat) 1.0)
  55.            [[view window] setOpaque: NO];
  56. @@ -330,10 +329,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
  57.        face = FRAME_DEFAULT_FACE (f);
  58.        if (face)
  59.          {
  60. -          col = [NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)];
  61. -          face->background = [[col colorWithAlphaComponent: alpha]
  62. -                               unsignedLong];
  63. -
  64. +          face->background = [col unsignedLong];
  65.            update_face_from_frame_parameter (f, Qbackground_color, arg);
  66.          }
  67.  
  68. @@ -346,6 +342,36 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
  69.    unblock_input ();
  70.  }
  71.  
  72. +static void
  73. +ns_set_alpha_background (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
  74. +{
  75. +  NSView *view = FRAME_NS_VIEW (f);
  76. +  double alpha = 1.0;
  77. +
  78. +  if (NILP (arg))
  79. +    alpha = 1.0;
  80. +  else if (FLOATP (arg))
  81. +    {
  82. +      alpha = XFLOAT_DATA (arg);
  83. +      if (! (0 <= alpha && alpha <= 1.0))
  84. +   args_out_of_range (make_float (0.0), make_float (1.0));
  85. +    }
  86. +  else if (FIXNUMP (arg))
  87. +    {
  88. +      EMACS_INT ialpha = XFIXNUM (arg);
  89. +      if (! (0 <= ialpha && ialpha <= 100))
  90. +   args_out_of_range (make_fixnum (0), make_fixnum (100));
  91. +      alpha = ialpha / 100.0;
  92. +    }
  93. +  else
  94. +    wrong_type_argument (Qnumberp, arg);
  95. +
  96. +  f->alpha_background = alpha;
  97. +  [[view window] setBackgroundColor: [f->output_data.ns->background_color
  98. +                    colorWithAlphaComponent: alpha]];
  99. +  recompute_basic_faces (f);
  100. +  SET_FRAME_GARBAGED (f);
  101. +}
  102.  
  103.  static void
  104.  ns_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
  105. @@ -1065,7 +1091,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
  106.    ns_set_z_group,
  107.    0, /* x_set_override_redirect */
  108.    gui_set_no_special_glyphs,
  109. -  gui_set_alpha_background,
  110. +  ns_set_alpha_background,
  111.    NULL,
  112.  #ifdef NS_IMPL_COCOA
  113.    ns_set_appearance,
  114. diff --git a/src/nsterm.m b/src/nsterm.m
  115. index 518b38658d1..bda3a12172f 100644
  116. --- a/src/nsterm.m
  117. +++ b/src/nsterm.m
  118. @@ -2618,8 +2618,9 @@ Hide the window (X11 semantics)
  119.  
  120.    block_input ();
  121.    ns_focus (f, &r, 1);
  122. -  [[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND
  123. -               (FACE_FROM_ID (f, DEFAULT_FACE_ID))] set];
  124. +  [[[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND
  125. +                (FACE_FROM_ID (f, DEFAULT_FACE_ID))]
  126. +                                 colorWithAlphaComponent: f->alpha_background] set];
  127.    NSRectFill (r);
  128.    ns_unfocus (f);
  129.  
  130. @@ -2647,7 +2648,7 @@ Hide the window (X11 semantics)
  131.  
  132.    r = NSIntersectionRect (r, [view frame]);
  133.    ns_focus (f, &r, 1);
  134. -  [[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)] set];
  135. +  [[[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)] colorWithAlphaComponent: f->alpha_background] set];
  136.  
  137.    NSRectFill (r);
  138.  
  139. @@ -2751,7 +2752,7 @@ Hide the window (X11 semantics)
  140.          return;
  141.  
  142.        ns_focus (f, NULL, 1);
  143. -      [[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)] set];
  144. +      [[[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)] colorWithAlphaComponent: f->alpha_background] set];
  145.        NSRectFill (NSMakeRect (0, margin, width, border));
  146.        NSRectFill (NSMakeRect (0, 0, border, height));
  147.        NSRectFill (NSMakeRect (0, margin, width, border));
  148. @@ -2802,7 +2803,7 @@ Hide the window (X11 semantics)
  149.            NSRect r = NSMakeRect (0, y, FRAME_PIXEL_WIDTH (f), height);
  150.            ns_focus (f, &r, 1);
  151.  
  152. -          [[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)] set];
  153. +          [[[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)] colorWithAlphaComponent: f->alpha_background] set];
  154.            NSRectFill (NSMakeRect (0, y, width, height));
  155.            NSRectFill (NSMakeRect (FRAME_PIXEL_WIDTH (f) - width,
  156.                                    y, width, height));
  157. @@ -2966,8 +2967,7 @@ Hide the window (X11 semantics)
  158.    if (! NSIsEmptyRect (clearRect))
  159.      {
  160.        NSTRACE_RECT ("clearRect", clearRect);
  161. -
  162. -      [[NSColor colorWithUnsignedLong:face->background] set];
  163. +      [[[NSColor colorWithUnsignedLong:face->background] colorWithAlphaComponent: f->alpha_background] set];
  164.        NSRectFill (clearRect);
  165.      }
  166.  
  167. @@ -2998,7 +2998,7 @@ Hide the window (X11 semantics)
  168.        else
  169.          bm_color = f->output_data.ns->cursor_color;
  170.  
  171. -      [bm_color set];
  172. +      [[bm_color colorWithAlphaComponent:f->alpha_background] set];
  173.        [bmp fill];
  174.  
  175.        [bmp release];
  176. @@ -3719,7 +3719,7 @@ Function modeled after x_draw_glyph_string_box ().
  177.    if (s->face->box == FACE_SIMPLE_BOX && s->face->box_color)
  178.      {
  179.        ns_draw_box (r, abs (hthickness), abs (vthickness),
  180. -                   [NSColor colorWithUnsignedLong:face->box_color],
  181. +                   [[NSColor colorWithUnsignedLong:face->box_color] colorWithAlphaComponent: s->f->alpha_background],
  182.                     left_p, right_p);
  183.      }
  184.    else
  185. @@ -3757,8 +3757,10 @@ Function modeled after x_draw_glyph_string_box ().
  186.              {
  187.                if (s->hl != DRAW_CURSOR)
  188.                  [(NS_FACE_BACKGROUND (face) != 0
  189. -                  ? [NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)]
  190. +         ? [[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)]
  191. +             colorWithAlphaComponent: s->f->alpha_background]
  192.                    : FRAME_BACKGROUND_COLOR (s->f)) set];
  193. +
  194.                else if (face && (NS_FACE_BACKGROUND (face)
  195.                                  == [(NSColor *) FRAME_CURSOR_COLOR (s->f)
  196.                                                  unsignedLong]))
  197. @@ -3902,7 +3904,7 @@ Function modeled after x_draw_glyph_string_box ().
  198.       otherwise, since we composite the image under NS (instead of mucking
  199.       with its background color), we must clear just the image area.  */
  200.  
  201. -  [[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)] set];
  202. +  [[[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)] colorWithAlphaComponent: s->f->alpha_background] set];
  203.  
  204.    if (bg_height > s->slice.height || s->img->hmargin || s->img->vmargin
  205.        || s->img->mask || s->img->pixmap == 0 || s->width != s->background_width)
  206. @@ -3972,7 +3974,7 @@ Function modeled after x_draw_glyph_string_box ().
  207.    if (s->hl == DRAW_CURSOR)
  208.      {
  209.        [FRAME_CURSOR_COLOR (s->f) set];
  210. -      tdCol = [NSColor colorWithUnsignedLong: NS_FACE_BACKGROUND (face)];
  211. +      tdCol = [[NSColor colorWithUnsignedLong: NS_FACE_BACKGROUND (face)] colorWithAlphaComponent: s->f->alpha_background];
  212.      }
  213.    else
  214.      tdCol = [NSColor colorWithUnsignedLong: NS_FACE_FOREGROUND (face)];
  215. @@ -4066,10 +4068,10 @@ Function modeled after x_draw_glyph_string_box ().
  216.         face = FACE_FROM_ID (s->f, MOUSE_FACE_ID);
  217.           prepare_face_for_display (s->f, face);
  218.  
  219. -         [[NSColor colorWithUnsignedLong: face->background] set];
  220. +         [[[NSColor colorWithUnsignedLong: face->background] colorWithAlphaComponent: s->f->alpha_background] set];
  221.         }
  222.       else
  223. -       [[NSColor colorWithUnsignedLong: s->face->background] set];
  224. +       [[[NSColor colorWithUnsignedLong: s->face->background] colorWithAlphaComponent: s->f->alpha_background] set];
  225.       NSRectFill (NSMakeRect (x, y, w, h));
  226.     }
  227.      }
  228. @@ -4095,7 +4097,7 @@ Function modeled after x_draw_glyph_string_box ().
  229.       if (s->hl == DRAW_CURSOR)
  230.         [FRAME_CURSOR_COLOR (s->f) set];
  231.       else
  232. -       [[NSColor colorWithUnsignedLong: s->face->background] set];
  233. +       [[[NSColor colorWithUnsignedLong: s->face->background] colorWithAlphaComponent: s->f->alpha_background] set];
  234.  
  235.       NSRectFill (NSMakeRect (x, s->y, background_width, s->height));
  236.     }
  237. @@ -8436,8 +8438,8 @@ - (void)toggleFullScreen: (id)sender
  238.          }
  239.  
  240.        [w setContentView:[fw contentView]];
  241. -      [w setBackgroundColor: col];
  242. -      if ([col alphaComponent] != (EmacsCGFloat) 1.0)
  243. +      [w setBackgroundColor: [col colorWithAlphaComponent: f->alpha_background]];
  244. +      if (f->alpha_background != (EmacsCGFloat) 1.0)
  245.          [w setOpaque: NO];
  246.  
  247.        f->border_width = [w borderWidth];
  248. @@ -9172,9 +9174,9 @@ - (instancetype) initWithEmacsFrame: (struct frame *) f
  249.        f->border_width = [self borderWidth];
  250.  
  251.        col = [NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND
  252. -                                     (FACE_FROM_ID (f, DEFAULT_FACE_ID))];
  253. -      [self setBackgroundColor:col];
  254. -      if ([col alphaComponent] != (EmacsCGFloat) 1.0)
  255. +             (FACE_FROM_ID (f, DEFAULT_FACE_ID))];
  256. +      [self setBackgroundColor:[col colorWithAlphaComponent:f->alpha_background]];
  257. +      if (f->alpha_background != (EmacsCGFloat) 1.0)
  258.          [self setOpaque:NO];
  259.  
  260.        /* toolbar support */
  261.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement