emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master c274bd5c52: Implement face cursor color merging on Haiku


From: Po Lu
Subject: master c274bd5c52: Implement face cursor color merging on Haiku
Date: Fri, 4 Feb 2022 22:19:26 -0500 (EST)

branch: master
commit c274bd5c52fd64c888b1c713060da881bf72caa7
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    Implement face cursor color merging on Haiku
    
    * src/ftcrfont.c (ftcrfont_draw):
    * src/haikufont.c (haikufont_draw): Use
    `haiku_merge_cursor_foreground' to calculate cursor HL colors.
    * src/haikuterm.c (haiku_merge_cursor_foreground): New function.
    * src/haikuterm.h: Update prototypes.
---
 src/ftcrfont.c  | 19 ++++++++++++++-----
 src/haikufont.c | 19 +++++++++++--------
 src/haikuterm.c | 26 ++++++++++++++++++++++++++
 src/haikuterm.h |  3 +++
 4 files changed, 54 insertions(+), 13 deletions(-)

diff --git a/src/ftcrfont.c b/src/ftcrfont.c
index 7d192697ca..87a8692a3b 100644
--- a/src/ftcrfont.c
+++ b/src/ftcrfont.c
@@ -522,12 +522,23 @@ ftcrfont_draw (struct glyph_string *s,
                int from, int to, int x, int y, bool with_background)
 {
   struct frame *f = s->f;
-  struct face *face = s->face;
   struct font_info *ftcrfont_info = (struct font_info *) s->font;
   cairo_t *cr;
   cairo_glyph_t *glyphs;
   int len = to - from;
   int i;
+#ifdef USE_BE_CAIRO
+  unsigned long be_foreground, be_background;
+
+  if (s->hl != DRAW_CURSOR)
+    {
+      be_foreground = s->face->foreground;
+      be_background = s->face->background;
+    }
+  else
+    haiku_merge_cursor_foreground (s, &be_foreground,
+                                  &be_background);
+#endif
 
   block_input ();
 
@@ -562,8 +573,7 @@ ftcrfont_draw (struct glyph_string *s,
 #else
       struct face *face = s->face;
 
-      uint32_t col = s->hl == DRAW_CURSOR ?
-       FRAME_CURSOR_COLOR (s->f).pixel : face->background;
+      uint32_t col = be_background;
 
       cairo_set_source_rgb (cr, RED_FROM_ULONG (col) / 255.0,
                            GREEN_FROM_ULONG (col) / 255.0,
@@ -592,8 +602,7 @@ ftcrfont_draw (struct glyph_string *s,
   pgtk_set_cr_source_with_color (f, s->xgcv.foreground, false);
 #endif
 #else
-  uint32_t col = s->hl == DRAW_CURSOR ?
-    FRAME_OUTPUT_DATA (s->f)->cursor_fg : face->foreground;
+  uint32_t col = be_foreground;
 
   cairo_set_source_rgb (cr, RED_FROM_ULONG (col) / 255.0,
                        GREEN_FROM_ULONG (col) / 255.0,
diff --git a/src/haikufont.c b/src/haikufont.c
index 1ef5f54c9a..6cc984f316 100644
--- a/src/haikufont.c
+++ b/src/haikufont.c
@@ -951,10 +951,19 @@ haikufont_draw (struct glyph_string *s, int from, int to,
   struct font_info *info = (struct font_info *) s->font;
   unsigned char mb[MAX_MULTIBYTE_LENGTH];
   void *view = FRAME_HAIKU_VIEW (f);
+  unsigned long foreground, background;
 
   block_input ();
   prepare_face_for_display (s->f, face);
 
+  if (s->hl != DRAW_CURSOR)
+    {
+      foreground = s->face->foreground;
+      background = s->face->background;
+    }
+  else
+    haiku_merge_cursor_foreground (s, &foreground, &background);
+
   /* Presumably the draw lock is already held by
      haiku_draw_glyph_string; */
   if (with_background)
@@ -977,18 +986,12 @@ haikufont_draw (struct glyph_string *s, int from, int to,
          s->first_glyph->slice.glyphless.lower_yoff
          - s->first_glyph->slice.glyphless.upper_yoff;
 
-      BView_SetHighColor (view, s->hl == DRAW_CURSOR ?
-                         FRAME_CURSOR_COLOR (s->f).pixel : face->background);
-
+      BView_SetHighColor (view, background);
       BView_FillRectangle (view, x, y - ascent, s->width, height);
       s->background_filled_p = 1;
     }
 
-  if (s->hl == DRAW_CURSOR)
-    BView_SetHighColor (view, FRAME_OUTPUT_DATA (s->f)->cursor_fg);
-  else
-    BView_SetHighColor (view, face->foreground);
-
+  BView_SetHighColor (view, foreground);
   BView_MovePenTo (view, x, y);
   BView_SetFont (view, ((struct haikufont_info *) info)->be_font);
 
diff --git a/src/haikuterm.c b/src/haikuterm.c
index aac9582e6e..6707340ca0 100644
--- a/src/haikuterm.c
+++ b/src/haikuterm.c
@@ -3643,6 +3643,32 @@ haiku_end_cr_clip (cairo_t *cr)
 }
 #endif
 
+void
+haiku_merge_cursor_foreground (struct glyph_string *s,
+                              unsigned long *foreground_out,
+                              unsigned long *background_out)
+{
+  unsigned long background = FRAME_CURSOR_COLOR (s->f).pixel;
+  unsigned long foreground = s->face->background;
+
+  if (background == foreground)
+    foreground = s->face->background;
+  if (background == foreground)
+    foreground = FRAME_OUTPUT_DATA (s->f)->cursor_fg;
+  if (background == foreground)
+    foreground = s->face->foreground;
+
+  if (background == s->face->background
+      || foreground == s->face->foreground)
+    {
+      background = s->face->foreground;
+      foreground = s->face->background;
+    }
+
+  *foreground_out = foreground;
+  *background_out = background;
+}
+
 void
 syms_of_haikuterm (void)
 {
diff --git a/src/haikuterm.h b/src/haikuterm.h
index 2dbdb6aafc..a2520858f5 100644
--- a/src/haikuterm.h
+++ b/src/haikuterm.h
@@ -294,4 +294,7 @@ haiku_begin_cr_clip (struct frame *f, struct glyph_string 
*s);
 extern void
 haiku_end_cr_clip (cairo_t *cr);
 #endif
+
+extern void haiku_merge_cursor_foreground (struct glyph_string *, unsigned 
long *,
+                                          unsigned long *);
 #endif /* _HAIKU_TERM_H_ */



reply via email to

[Prev in Thread] Current Thread [Next in Thread]