all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Robert Pluim <rpluim@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Identifying the face between STRETCH and right fringe.
Date: Tue, 27 Nov 2018 20:14:14 +0100	[thread overview]
Message-ID: <m2r2f6s589.fsf@gmail.com> (raw)
In-Reply-To: <831s76gxkq.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 27 Nov 2018 20:55:01 +0200")

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Robert Pluim <rpluim@gmail.com>
>> Cc: emacs-devel@gnu.org
>> Date: Tue, 27 Nov 2018 14:55:23 +0100
>> 
>> >> When we get here, face->background == 1, and FRAME_BACKGROUND_PIXEL ==
>> >> 0xfffeffff
>> >> 
>> >> Looking through nsfns.m, the problem becomes obvious: the NS port uses
>> >> indices into a color table to specify the background colour of faces,
>> >> and FRAME_BACKGROUND_PIXEL is an RGBA value.
>> >
>> > Why does NS use indices here, and not RGBA values?
>> 
>> Probably because NS doesnʼt really use the RGBA values directly at
>> all, but uses the indices all the time.
>
> So where does the RGBA value in FRAME_BACKGROUND_PIXEL come from?
>
>> > If no better/cleaner idea emerges, how about having an NS-specific
>> > code here that computed the it->face's background RGBA by indexing
>> > into the color table, before comparing that with
>> > FRAME_BACKGROUND_PIXEL?
>> 
>> Thatʼs doable.
>
> Thanks.
>
> Note that there are a couple more of such comparisons, so perhaps a
> macro is in order, with different implementations for NS and the rest.

I love those rare moments when I implement something one way, and then
Eli tells me to do it that way :-)

In theory there are a couple of other fields in the face structure
that might need the same type of treatment, but I didnʼt see any code
comparing them to RGBA pixel values.

I suck at naming things, comments welcome.

diff --git i/src/dispextern.h w/src/dispextern.h
index 579665c2ff..776d14080e 100644
--- i/src/dispextern.h
+++ w/src/dispextern.h
@@ -74,10 +74,13 @@ typedef HDC XImagePtr_or_DC;
 
 #ifdef HAVE_NS
 #include "nsgui.h"
+#define FACE_COLOR_TO_PIXEL(face_color, frame) ns_color_index_to_rgba(face_color, frame)
 /* Following typedef needed to accommodate the MSDOS port, believe it or not.  */
 typedef struct ns_display_info Display_Info;
 typedef Pixmap XImagePtr;
 typedef XImagePtr XImagePtr_or_DC;
+#else
+#define FACE_COLOR_TO_PIXEL(face_color, frame) face_color
 #endif
 
 #ifdef HAVE_WINDOW_SYSTEM
diff --git i/src/nsgui.h w/src/nsgui.h
index 4e7d7d35da..0c29eed5e4 100644
--- i/src/nsgui.h
+++ w/src/nsgui.h
@@ -73,6 +73,8 @@ typedef unichar XChar2b;
 #define XCHAR2B_BYTE2(chp) \
   (*(chp) & 0x00ff)
 
+/* For xdisp.c */
+extern unsigned long ns_color_index_to_rgba(int idx, struct frame *f);
 
 /* XXX: xfaces requires these structures, but the question is are we
         forced to use them?  */
diff --git i/src/nsterm.m w/src/nsterm.m
index bcc23ffeaf..cacfc57fd7 100644
--- i/src/nsterm.m
+++ w/src/nsterm.m
@@ -2356,6 +2356,22 @@ so some key presses (TAB) are swallowed by the system.  */
   return 1;
 }
 
+/* Convert an index into the color table into an RGBA value.  Used in
+   xdisp.c:extend_face_to_end_of_line when comparing faces and frame
+   color values.  */
+
+unsigned long
+ns_color_index_to_rgba(int idx, struct frame *f)
+{
+  NSColor *col;
+  col = ns_lookup_indexed_color (idx, f);
+
+  EmacsCGFloat r, g, b, a;
+  [col getRed: &r green: &g blue: &b alpha: &a];
+
+  return ARGB_TO_ULONG((int)(a*255),
+                       (int)(r*255), (int)(g*255), (int)(b*255));
+}
 
 void
 ns_query_color(void *col, XColor *color_def, int setPixel)
diff --git i/src/xdisp.c w/src/xdisp.c
index fa7691cdd0..e9048afb86 100644
--- i/src/xdisp.c
+++ w/src/xdisp.c
@@ -20287,7 +20287,7 @@ extend_face_to_end_of_line (struct it *it)
   if (FRAME_WINDOW_P (f)
       && MATRIX_ROW_DISPLAYS_TEXT_P (it->glyph_row)
       && face->box == FACE_NO_BOX
-      && face->background == FRAME_BACKGROUND_PIXEL (f)
+      && FACE_COLOR_TO_PIXEL(face->background, f) == FRAME_BACKGROUND_PIXEL (f)
 #ifdef HAVE_WINDOW_SYSTEM
       && !face->stipple
 #endif
@@ -20432,7 +20432,7 @@ extend_face_to_end_of_line (struct it *it)
 	  && (it->glyph_row->used[LEFT_MARGIN_AREA]
 	      < WINDOW_LEFT_MARGIN_WIDTH (it->w))
 	  && !it->glyph_row->mode_line_p
-	  && default_face->background != FRAME_BACKGROUND_PIXEL (f))
+	  && FACE_COLOR_TO_PIXEL(face->background, f) != FRAME_BACKGROUND_PIXEL (f))
 	{
 	  struct glyph *g = it->glyph_row->glyphs[LEFT_MARGIN_AREA];
 	  struct glyph *e = g + it->glyph_row->used[LEFT_MARGIN_AREA];
@@ -20473,7 +20473,7 @@ extend_face_to_end_of_line (struct it *it)
 	  && (it->glyph_row->used[RIGHT_MARGIN_AREA]
 	      < WINDOW_RIGHT_MARGIN_WIDTH (it->w))
 	  && !it->glyph_row->mode_line_p
-	  && default_face->background != FRAME_BACKGROUND_PIXEL (f))
+	  && FACE_COLOR_TO_PIXEL(face->background, f) != FRAME_BACKGROUND_PIXEL (f))
 	{
 	  struct glyph *g = it->glyph_row->glyphs[RIGHT_MARGIN_AREA];
 	  struct glyph *e = g + it->glyph_row->used[RIGHT_MARGIN_AREA];



  reply	other threads:[~2018-11-27 19:14 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-20 16:39 Identifying the face between STRETCH and right fringe Keith David Bershatsky
2018-11-20 17:20 ` Eli Zaretskii
2018-11-21  7:44   ` Robert Pluim
2018-11-23 10:04     ` Eli Zaretskii
2018-11-23 13:25       ` Robert Pluim
2018-11-23 13:48         ` Eli Zaretskii
2018-11-23 14:04           ` Robert Pluim
2018-11-23 15:51             ` Eli Zaretskii
2018-11-23 15:58               ` Robert Pluim
2018-11-23 20:33                 ` Eli Zaretskii
2018-11-27  8:56                   ` Robert Pluim
2018-11-27  9:34                     ` Eli Zaretskii
2018-11-27 11:02                       ` Robert Pluim
2018-11-27 11:29                         ` Eli Zaretskii
2018-11-27 13:55                           ` Robert Pluim
2018-11-27 18:55                             ` Eli Zaretskii
2018-11-27 19:14                               ` Robert Pluim [this message]
2018-11-27 19:38                                 ` Robert Pluim
2018-11-28  6:03                                   ` Eli Zaretskii
2018-11-28  9:00                                     ` Robert Pluim
2018-11-28  9:42                                       ` Eli Zaretskii
2018-11-28  9:49                                         ` Eli Zaretskii
2018-11-28 13:24                                           ` Robert Pluim
2018-11-28 16:19                                             ` Eli Zaretskii
2018-11-28  7:13                                 ` Eli Zaretskii
2018-11-28  8:36                                   ` Robert Pluim
2018-11-28  9:45                                     ` Eli Zaretskii
2018-11-28  9:56                                       ` Robert Pluim
2018-11-28 10:11                                         ` Eli Zaretskii
2018-11-28 13:21                                           ` Robert Pluim
2018-11-28 16:20                                             ` Eli Zaretskii
2018-11-29 12:51                                               ` Robert Pluim
2018-11-29 14:15                                                 ` Eli Zaretskii
2018-11-28 21:14                                   ` Alan Third
2018-11-29 12:26                                     ` Robert Pluim
2018-11-29 12:54                                       ` Eli Zaretskii
2018-11-29 13:52                                         ` Robert Pluim
2018-11-29 14:08                                           ` Eli Zaretskii
2018-11-30  7:59                                             ` Robert Pluim
2018-11-30  8:04                                             ` Robert Pluim
2018-11-30  8:22                                               ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2r2f6s589.fsf@gmail.com \
    --to=rpluim@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.