summaryrefslogtreecommitdiff
path: root/src/gui_x11.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2017-03-12 17:10:33 +0100
committerBram Moolenaar <Bram@vim.org>2017-03-12 17:10:33 +0100
commit8774845ce1a7def122ea07c057a79417f3be3d17 (patch)
treec0ae2632287e08c330ceb462e38e7ca342df4f21 /src/gui_x11.c
parent454709baffd3205bf2b7d2519419675a122f2bd2 (diff)
downloadvim-git-8774845ce1a7def122ea07c057a79417f3be3d17.tar.gz
patch 8.0.0447: getting font name does not work on X11v8.0.0447
Problem: Getting font name does not work on X11. Solution: Implement gui_mch_get_fontname() for X11. Add more GUI tests. (Kazunobu Kuriyama)
Diffstat (limited to 'src/gui_x11.c')
-rw-r--r--src/gui_x11.c36
1 files changed, 31 insertions, 5 deletions
diff --git a/src/gui_x11.c b/src/gui_x11.c
index 2cc0eba85..2226e8954 100644
--- a/src/gui_x11.c
+++ b/src/gui_x11.c
@@ -1992,14 +1992,40 @@ gui_mch_get_font(char_u *name, int giveErrorIfMissing)
#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