changeset 11745:5a5709918a98 v8.0.0755

patch 8.0.0755: terminal window does not have colors in the GUI commit https://github.com/vim/vim/commit/26af85d97ba1ed0ade6cdd41890ca04ed879b9c7 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jul 23 16:45:10 2017 +0200 patch 8.0.0755: terminal window does not have colors in the GUI Problem: Terminal window does not have colors in the GUI. Solution: Lookup the GUI color.
author Christian Brabandt <cb@256bit.org>
date Sun, 23 Jul 2017 17:00:04 +0200
parents 44adc1cc0cdd
children 9b1e4fbfa6db
files src/gui_gtk_x11.c src/gui_mac.c src/gui_photon.c src/gui_w32.c src/gui_x11.c src/proto/gui_gtk_x11.pro src/proto/gui_mac.pro src/proto/gui_photon.pro src/proto/gui_w32.pro src/proto/gui_x11.pro src/proto/syntax.pro src/proto/term.pro src/syntax.c src/term.c src/terminal.c src/version.c
diffstat 16 files changed, 100 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/gui_gtk_x11.c
+++ b/src/gui_gtk_x11.c
@@ -5606,16 +5606,34 @@ gui_mch_get_color(char_u *name)
     return name != NULL ? gui_get_color_cmn(name) : INVALCOLOR;
 #else
     guicolor_T color;
-    GdkColor gcolor;
-    int ret;
 
     color = (name != NULL) ? gui_get_color_cmn(name) : INVALCOLOR;
     if (color == INVALCOLOR)
 	return INVALCOLOR;
 
-    gcolor.red = (guint16)(((color & 0xff0000) >> 16) / 255.0 * 65535 + 0.5);
-    gcolor.green = (guint16)(((color & 0xff00) >> 8) / 255.0 * 65535 + 0.5);
-    gcolor.blue = (guint16)((color & 0xff) / 255.0 * 65535 + 0.5);
+    return gui_mch_get_rgb_color(
+	    (color & 0xff0000) >> 16,
+	    (color & 0xff00) >> 8,
+	    color & 0xff);
+#endif
+}
+
+/*
+ * Return the Pixel value (color) for the given RGB values.
+ * Return INVALCOLOR for error.
+ */
+    guicolor_T
+gui_mch_get_rgb_color(int r, int g, int b)
+{
+#if GTK_CHECK_VERSION(3,0,0)
+    return gui_get_rgb_color_cmn(r, g, b);
+#else
+    GdkColor gcolor;
+    int ret;
+
+    gcolor.red = (guint16)(r / 255.0 * 65535 + 0.5);
+    gcolor.green = (guint16)(g / 255.0 * 65535 + 0.5);
+    gcolor.blue = (guint16)(b / 255.0 * 65535 + 0.5);
 
     ret = gdk_colormap_alloc_color(gtk_widget_get_colormap(gui.drawarea),
 	    &gcolor, FALSE, TRUE);
--- a/src/gui_mac.c
+++ b/src/gui_mac.c
@@ -3726,6 +3726,12 @@ gui_mch_get_color(char_u *name)
     return gui_get_color_cmn(name);
 }
 
+    guicolor_T
+gui_mch_get_rgb_color(int r, int g, int b)
+{
+    return gui_get_rgb_color_cmn(r, g, b);
+}
+
 /*
  * Set the current text foreground color.
  */
--- a/src/gui_photon.c
+++ b/src/gui_photon.c
@@ -1986,6 +1986,12 @@ gui_mch_get_color(char_u *name)
     return gui_get_color_cmn(name);
 }
 
+    guicolor_T
+gui_mch_get_rgb_color(int r, int g, int b)
+{
+    return gui_get_rgb_color_cmn(r, g, b);
+}
+
     void
 gui_mch_set_fg_color(guicolor_T color)
 {
--- a/src/gui_w32.c
+++ b/src/gui_w32.c
@@ -1597,6 +1597,12 @@ gui_mch_get_color(char_u *name)
     return gui_get_color_cmn(name);
 }
 
+    guicolor_T
+gui_mch_get_rgb_color(int r, int g, int b)
+{
+    return gui_get_rgb_color_cmn(r, g, b);
+}
+
 /*
  * Return OK if the key with the termcap name "name" is supported.
  */
--- a/src/gui_x11.c
+++ b/src/gui_x11.c
@@ -2272,8 +2272,6 @@ gui_mch_get_color(char_u *name)
     guicolor_T  requested;
     XColor      available;
     Colormap	colormap;
-#define COLORSPECBUFSIZE 8 /* space enough to hold "#RRGGBB" */
-    char        spec[COLORSPECBUFSIZE];
 
     /* can't do this when GUI not running */
     if (!gui.in_use || name == NULL || *name == NUL)
@@ -2283,11 +2281,22 @@ gui_mch_get_color(char_u *name)
     if (requested == INVALCOLOR)
 	return INVALCOLOR;
 
-    vim_snprintf(spec, COLORSPECBUFSIZE, "#%.2x%.2x%.2x",
+    return gui_mch_get_rgb_color(
 	    (requested & 0xff0000) >> 16,
 	    (requested & 0xff00) >> 8,
 	    requested & 0xff);
-#undef COLORSPECBUFSIZE
+}
+
+/*
+ * Return the Pixel value (color) for the given RGB values.
+ * Return INVALCOLOR for error.
+ */
+    guicolor_T
+gui_mch_get_rgb_color(int r, int g, int b)
+{
+    char        spec[8]; /* space enough to hold "#RRGGBB" */
+
+    vim_snprintf(spec, sizeof(spec), "#%.2x%.2x%.2x", r, g, b);
     colormap = DefaultColormap(gui.dpy, DefaultScreen(gui.dpy));
     if (XParseColor(gui.dpy, colormap, (char *)spec, &available) != 0
 	    && XAllocColor(gui.dpy, colormap, &available) != 0)
--- a/src/proto/gui_gtk_x11.pro
+++ b/src/proto/gui_gtk_x11.pro
@@ -36,6 +36,7 @@ GuiFont gui_mch_get_font(char_u *name, i
 char_u *gui_mch_get_fontname(GuiFont font, char_u *name);
 void gui_mch_free_font(GuiFont font);
 guicolor_T gui_mch_get_color(char_u *name);
+guicolor_T gui_mch_get_rgb_color(int r, int g, int b);
 void gui_mch_set_fg_color(guicolor_T color);
 void gui_mch_set_bg_color(guicolor_T color);
 void gui_mch_set_sp_color(guicolor_T color);
@@ -53,7 +54,7 @@ void gui_mch_draw_part_cursor(int w, int
 void gui_mch_update(void);
 int gui_mch_wait_for_chars(long wtime);
 void gui_mch_flush(void);
-void gui_mch_clear_block(int row1, int col1, int row2, int col2);
+void gui_mch_clear_block(int row1arg, int col1arg, int row2arg, int col2arg);
 void gui_mch_clear_all(void);
 void gui_mch_delete_lines(int row, int num_lines);
 void gui_mch_insert_lines(int row, int num_lines);
--- a/src/proto/gui_mac.pro
+++ b/src/proto/gui_mac.pro
@@ -47,6 +47,7 @@ void gui_mch_set_font(GuiFont font);
 int gui_mch_same_font(GuiFont f1, GuiFont f2);
 void gui_mch_free_font(GuiFont font);
 guicolor_T gui_mch_get_color(char_u *name);
+guicolor_T gui_mch_get_rgb_color(int r, int g, int b);
 void gui_mch_set_fg_color(guicolor_T color);
 void gui_mch_set_bg_color(guicolor_T color);
 void gui_mch_set_sp_color(guicolor_T color);
--- a/src/proto/gui_photon.pro
+++ b/src/proto/gui_photon.pro
@@ -28,6 +28,7 @@ void gui_mch_setmouse(int x, int y);
 guicolor_T gui_mch_get_rgb(guicolor_T pixel);
 void gui_mch_new_colors(void);
 guicolor_T gui_mch_get_color(char_u *name);
+guicolor_T gui_mch_get_rgb_color(int r, int g, int b);
 void gui_mch_set_fg_color(guicolor_T color);
 void gui_mch_set_bg_color(guicolor_T color);
 void gui_mch_set_sp_color(guicolor_T color);
--- a/src/proto/gui_w32.pro
+++ b/src/proto/gui_w32.pro
@@ -21,6 +21,7 @@ GuiFont gui_mch_get_font(char_u *name, i
 char_u *gui_mch_get_fontname(GuiFont font, char_u *name);
 void gui_mch_free_font(GuiFont font);
 guicolor_T gui_mch_get_color(char_u *name);
+guicolor_T gui_mch_get_rgb_color(int r, int g, int b);
 int gui_mch_haskey(char_u *name);
 void gui_mch_beep(void);
 void gui_mch_invert_rectangle(int r, int c, int nr, int nc);
--- a/src/proto/gui_x11.pro
+++ b/src/proto/gui_x11.pro
@@ -25,6 +25,7 @@ GuiFontset gui_mch_get_fontset(char_u *n
 int fontset_height(XFontSet fs);
 int fontset_height2(XFontSet fs);
 guicolor_T gui_mch_get_color(char_u *name);
+guicolor_T gui_mch_get_rgb_color(int r, int g, int b);
 void gui_mch_set_fg_color(guicolor_T color);
 void gui_mch_set_bg_color(guicolor_T color);
 void gui_mch_set_sp_color(guicolor_T color);
--- a/src/proto/syntax.pro
+++ b/src/proto/syntax.pro
@@ -32,6 +32,7 @@ void hl_set_font_name(char_u *font_name)
 void hl_set_bg_color_name(char_u *name);
 void hl_set_fg_color_name(char_u *name);
 int get_cterm_attr_idx(int attr, int fg, int bg);
+int get_gui_attr_idx(int attr, guicolor_T fg, guicolor_T bg);
 void clear_hl_tables(void);
 int hl_combine_attr(int char_attr, int prim_attr);
 attrentry_T *syn_gui_attr2entry(int attr);
--- a/src/proto/term.pro
+++ b/src/proto/term.pro
@@ -24,7 +24,7 @@ void term_append_lines(int line_count);
 void term_delete_lines(int line_count);
 void term_set_winpos(int x, int y);
 int term_get_winpos(int *x, int *y);
-void term_set_winsize(int width, int height);
+void term_set_winsize(int height, int width);
 void term_fg_color(int n);
 void term_bg_color(int n);
 void term_fg_rgb_color(guicolor_T rgb);
@@ -68,4 +68,5 @@ int show_one_termcode(char_u *name, char
 char_u *translate_mapping(char_u *str, int expmap);
 void update_tcap(int attr);
 guicolor_T gui_get_color_cmn(char_u *name);
+guicolor_T gui_get_rgb_color_cmn(int r, int g, int b);
 /* vim: set ft=c : */
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -7908,7 +7908,7 @@ do_highlight(
 		    HL_TABLE()[idx].sg_gui_fg = i;
 # endif
 		    vim_free(HL_TABLE()[idx].sg_gui_fg_name);
-		    if (STRCMP(arg, "NONE"))
+		    if (STRCMP(arg, "NONE") != 0)
 			HL_TABLE()[idx].sg_gui_fg_name = vim_strsave(arg);
 		    else
 			HL_TABLE()[idx].sg_gui_fg_name = NULL;
@@ -8789,12 +8789,31 @@ get_cterm_attr_idx(int attr, int fg, int
 {
     attrentry_T		at_en;
 
+    vim_memset(&at_en, 0, sizeof(attrentry_T));
     at_en.ae_attr = attr;
     at_en.ae_u.cterm.fg_color = fg;
     at_en.ae_u.cterm.bg_color = bg;
     return get_attr_entry(&cterm_attr_table, &at_en);
 }
 
+#if defined(FEAT_GUI) || defined(PROTO)
+/*
+ * Get an attribute index for a cterm entry.
+ * Uses an existing entry when possible or adds one when needed.
+ */
+    int
+get_gui_attr_idx(int attr, guicolor_T fg, guicolor_T bg)
+{
+    attrentry_T		at_en;
+
+    vim_memset(&at_en, 0, sizeof(attrentry_T));
+    at_en.ae_attr = attr;
+    at_en.ae_u.gui.fg_color = fg;
+    at_en.ae_u.gui.bg_color = bg;
+    return get_attr_entry(&gui_attr_table, &at_en);
+}
+#endif
+
 /*
  * Clear all highlight tables.
  */
--- a/src/term.c
+++ b/src/term.c
@@ -6399,4 +6399,14 @@ gui_get_color_cmn(char_u *name)
 
     return INVALCOLOR;
 }
+
+    guicolor_T
+gui_get_rgb_color_cmn(int r, int g, int b)
+{
+    guicolor_T  color = RGB(r, g, b);
+
+    if (color > 0xffffff)
+	return INVALCOLOR;
+    return color;
+}
 #endif
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -33,7 +33,6 @@
  * while, if the terminal window is visible, the screen contents is drawn.
  *
  * TODO:
- * - color for GUI
  * - color for 'termguicolors'
  * - cursor flickers when moving the cursor
  * - set buffer options to be scratch, hidden, nomodifiable, etc.
@@ -720,7 +719,11 @@ cell2attr(VTermScreenCell *cell)
 #ifdef FEAT_GUI
     if (gui.in_use)
     {
-	/* TODO */
+	guicolor_T fg, bg;
+
+	fg = gui_mch_get_rgb_color(cell->fg.red, cell->fg.green, cell->fg.blue);
+	bg = gui_mch_get_rgb_color(cell->bg.red, cell->bg.green, cell->bg.blue);
+	return get_gui_attr_idx(attr, fg, bg);
     }
     else
 #endif
--- a/src/version.c
+++ b/src/version.c
@@ -770,6 +770,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    755,
+/**/
     754,
 /**/
     753,