]> git.eshelyaron.com Git - emacs.git/commitdiff
Implement face cursor color merging on Haiku
authorPo Lu <luangruo@yahoo.com>
Sat, 5 Feb 2022 03:17:58 +0000 (03:17 +0000)
committerPo Lu <luangruo@yahoo.com>
Sat, 5 Feb 2022 03:17:58 +0000 (03:17 +0000)
* 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
src/haikufont.c
src/haikuterm.c
src/haikuterm.h

index 7d192697ca197c93cdb0518a53c8ed502adefa7b..87a8692a3b8ce4c4e2c407277630d4c448e37aa3 100644 (file)
@@ -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,
index 1ef5f54c9aa8bce016b8af2e233c94972bc95a21..6cc984f31656c2dc4369b42c2a2850051dd1dc04 100644 (file)
@@ -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);
 
index aac9582e6ef415ffaa476569347cf96885aefb2c..6707340ca050bae6bd35f42d240cbe461815985f 100644 (file)
@@ -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)
 {
index 2dbdb6aafcb3077e8d6c99b168fc0c742131ee5e..a2520858f54493855c00982f8b48afa646061a79 100644 (file)
@@ -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_ */