diff src/gui_x11.c @ 11119:d8a550329a97 v8.0.0447

patch 8.0.0447: getting font name does not work on X11 commit https://github.com/vim/vim/commit/8774845ce1a7def122ea07c057a79417f3be3d17 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Mar 12 17:10:33 2017 +0100 patch 8.0.0447: getting font name does not work on X11 Problem: Getting font name does not work on X11. Solution: Implement gui_mch_get_fontname() for X11. Add more GUI tests. (Kazunobu Kuriyama)
author Christian Brabandt <cb@256bit.org>
date Sun, 12 Mar 2017 17:15:04 +0100
parents 90af0c60d78d
children 5a5709918a98
line wrap: on
line diff
--- a/src/gui_x11.c
+++ b/src/gui_x11.c
@@ -1992,14 +1992,40 @@ gui_mch_get_font(char_u *name, int giveE
 #if defined(FEAT_EVAL) || defined(PROTO)
 /*
  * Return the name of font "font" in allocated memory.
- * Don't know how to get the actual name, thus use the provided name.
  */
     char_u *
-gui_mch_get_fontname(GuiFont font UNUSED, char_u *name)
+gui_mch_get_fontname(GuiFont font, char_u *name)
 {
-    if (name == NULL)
-	return NULL;
-    return vim_strsave(name);
+    char_u *ret = NULL;
+
+    if (name != NULL && font == NULL)
+    {
+	/* In this case, there's no way other than doing this. */
+	ret = vim_strsave(name);
+    }
+    else if (font != NULL)
+    {
+	/* In this case, try to retrieve the XLFD corresponding to 'font'->fid;
+	 * if failed, use 'name' unless it's NULL. */
+	unsigned long value = 0L;
+
+	if (XGetFontProperty(font, XA_FONT, &value))
+	{
+	    char *xa_font_name = NULL;
+
+	    xa_font_name = XGetAtomName(gui.dpy, value);
+	    if (xa_font_name != NULL)
+	    {
+		ret = vim_strsave((char_u *)xa_font_name);
+		XFree(xa_font_name);
+	    }
+	    else if (name != NULL)
+		ret = vim_strsave(name);
+	}
+	else if (name != NULL)
+	    ret = vim_strsave(name);
+    }
+    return ret;
 }
 #endif