patch 8.0.0755: terminal window does not have colors in the GUI v8.0.0755
authorBram Moolenaar <Bram@vim.org>
Sun, 23 Jul 2017 14:45:10 +0000 (16:45 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 23 Jul 2017 14:45:10 +0000 (16:45 +0200)
Problem:    Terminal window does not have colors in the GUI.
Solution:   Lookup the GUI color.

16 files changed:
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

index 5837c0b172464c8e78ff6fcffa40869be719b4f9..480b8d3b8345c7d819dc328d7b6d04cc32e377bf 100644 (file)
@@ -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);
index 39f9ba5a7867ca3d22bd0ab9c57841b4628e82b8..dea648ac88aa57b2b4dea5804ba804b67f0fe002 100644 (file)
@@ -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.
  */
index 593be56fbe07006c2a6bb029321e1a5d738b180a..faed61d7b2d4edba58eb16e773587f21f594879e 100644 (file)
@@ -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)
 {
index 611902557e2ed83c752f46d37ad479bdfac12bd3..a91e0710beb38fc1e780b906f6159e3a16942264 100644 (file)
@@ -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.
  */
index 2226e89547aa755318a0461f17eae4dbb7c504aa..e0b91e65cdc14e9cef6abb859971a89de8a985da 100644 (file)
@@ -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)
index 124e2ae37526d6fe8fd420f7f9e39826db77ffb4..aaf710c172164dd0df295bbe4753bcb335d67bac 100644 (file)
@@ -36,6 +36,7 @@ GuiFont gui_mch_get_font(char_u *name, int report_error);
 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 h, guicolor_T color);
 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);
index 9b59f1f484a5eeeebadaa02100aaa2ea130a04d8..c7ab98204975aae07e450e965ea9867bdac5ec65 100644 (file)
@@ -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);
index 7681b87822b3c16daa75b415dc7855bf3c20efae..cfa735cf20a49746c1e8c81137cf0d8f2f4fe935 100644 (file)
@@ -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);
index 3c99f97e5e45be82e6455af889269168aab0c788..3528b5fa20a811831c95b8b7cec946bf70e47fdd 100644 (file)
@@ -21,6 +21,7 @@ GuiFont gui_mch_get_font(char_u *name, int giveErrorIfMissing);
 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);
index 1e4410e318ead58ea763baf0c2f07562cb2d33d5..e490d0cf334969f27afe85be4cd9e5f8ad3186fb 100644 (file)
@@ -25,6 +25,7 @@ GuiFontset gui_mch_get_fontset(char_u *name, int giveErrorIfMissing, int fixed_w
 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);
index 08725466c0d3dc48b17627713237ac277bd52b3a..cd21418682f2578daf628664870073dc66ecda5e 100644 (file)
@@ -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);
index 9af725ff837776ddf131cd72c578f4db709873b8..57188e1daa23a7386f8cff0e680f2d29aad345cf 100644 (file)
@@ -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_u *code, int printit);
 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 : */
index 4cd753c1e17c2b97dd69500943ec652fdbf65159..6fdc2af2c65bc159c690c5a20a7118546df26c8d 100644 (file)
@@ -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 bg)
 {
     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.
  */
index fa0be05572ad3f2dc4d9737fac0507ba3e830993..26527fb62b94f53ce21aa2e9aea3cba77d48e283 100644 (file)
@@ -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
index 862a669440493e82b9cd4723789154708a2dedba..5fbfc2eea41242e72a29c00cdf8fb50056ba0fc6 100644 (file)
@@ -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
index 263e6718eecd3df227bb6c78c694e056a4240d74..b6885f37026dc4d5cda56b55e910f42c1b1cd604 100644 (file)
@@ -769,6 +769,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    755,
 /**/
     754,
 /**/