diff options
-rw-r--r-- | src/gui_gtk_x11.c | 28 | ||||
-rw-r--r-- | src/gui_mac.c | 6 | ||||
-rw-r--r-- | src/gui_photon.c | 6 | ||||
-rw-r--r-- | src/gui_w32.c | 6 | ||||
-rw-r--r-- | src/gui_x11.c | 17 | ||||
-rw-r--r-- | src/proto/gui_gtk_x11.pro | 3 | ||||
-rw-r--r-- | src/proto/gui_mac.pro | 1 | ||||
-rw-r--r-- | src/proto/gui_photon.pro | 1 | ||||
-rw-r--r-- | src/proto/gui_w32.pro | 1 | ||||
-rw-r--r-- | src/proto/gui_x11.pro | 1 | ||||
-rw-r--r-- | src/proto/syntax.pro | 1 | ||||
-rw-r--r-- | src/proto/term.pro | 3 | ||||
-rw-r--r-- | src/syntax.c | 21 | ||||
-rw-r--r-- | src/term.c | 10 | ||||
-rw-r--r-- | src/terminal.c | 7 | ||||
-rw-r--r-- | src/version.c | 2 |
16 files changed, 100 insertions, 14 deletions
diff --git a/src/gui_gtk_x11.c b/src/gui_gtk_x11.c index 5837c0b17..480b8d3b8 100644 --- 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); diff --git a/src/gui_mac.c b/src/gui_mac.c index 39f9ba5a7..dea648ac8 100644 --- 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. */ diff --git a/src/gui_photon.c b/src/gui_photon.c index 593be56fb..faed61d7b 100644 --- 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) { diff --git a/src/gui_w32.c b/src/gui_w32.c index 611902557..a91e0710b 100644 --- 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. */ diff --git a/src/gui_x11.c b/src/gui_x11.c index 2226e8954..e0b91e65c 100644 --- 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) diff --git a/src/proto/gui_gtk_x11.pro b/src/proto/gui_gtk_x11.pro index 124e2ae37..aaf710c17 100644 --- 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, 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); diff --git a/src/proto/gui_mac.pro b/src/proto/gui_mac.pro index 9b59f1f48..c7ab98204 100644 --- 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); diff --git a/src/proto/gui_photon.pro b/src/proto/gui_photon.pro index 7681b8782..cfa735cf2 100644 --- 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); diff --git a/src/proto/gui_w32.pro b/src/proto/gui_w32.pro index 3c99f97e5..3528b5fa2 100644 --- a/src/proto/gui_w32.pro +++ b/src/proto/gui_w32.pro @@ -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); diff --git a/src/proto/gui_x11.pro b/src/proto/gui_x11.pro index 1e4410e31..e490d0cf3 100644 --- a/src/proto/gui_x11.pro +++ b/src/proto/gui_x11.pro @@ -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); diff --git a/src/proto/syntax.pro b/src/proto/syntax.pro index 08725466c..cd2141868 100644 --- 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); diff --git a/src/proto/term.pro b/src/proto/term.pro index 9af725ff8..57188e1da 100644 --- 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_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 : */ diff --git a/src/syntax.c b/src/syntax.c index 4cd753c1e..6fdc2af2c 100644 --- 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 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. */ diff --git a/src/term.c b/src/term.c index fa0be0557..26527fb62 100644 --- 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 diff --git a/src/terminal.c b/src/terminal.c index 862a66944..5fbfc2eea 100644 --- 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 diff --git a/src/version.c b/src/version.c index 263e6718e..b6885f370 100644 --- 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, |