Skip to content

Commit 8774845

Browse files
committed
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)
1 parent 454709b commit 8774845

File tree

11 files changed

+274
-19
lines changed

11 files changed

+274
-19
lines changed

Filelist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ SRC_ALL = \
110110
src/testdir/setup.vim \
111111
src/testdir/gui_init.vim \
112112
src/testdir/setup_gui.vim \
113+
src/testdir/gui_preinit.vim \
113114
src/testdir/test[0-9]*.ok \
114115
src/testdir/test[0-9]*a.ok \
115116
src/testdir/test_[a-z]*.ok \

src/gui_x11.c

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,14 +1992,40 @@ gui_mch_get_font(char_u *name, int giveErrorIfMissing)
19921992
#if defined(FEAT_EVAL) || defined(PROTO)
19931993
/*
19941994
* Return the name of font "font" in allocated memory.
1995-
* Don't know how to get the actual name, thus use the provided name.
19961995
*/
19971996
char_u *
1998-
gui_mch_get_fontname(GuiFont font UNUSED, char_u *name)
1997+
gui_mch_get_fontname(GuiFont font, char_u *name)
19991998
{
2000-
if (name == NULL)
2001-
return NULL;
2002-
return vim_strsave(name);
1999+
char_u *ret = NULL;
2000+
2001+
if (name != NULL && font == NULL)
2002+
{
2003+
/* In this case, there's no way other than doing this. */
2004+
ret = vim_strsave(name);
2005+
}
2006+
else if (font != NULL)
2007+
{
2008+
/* In this case, try to retrieve the XLFD corresponding to 'font'->fid;
2009+
* if failed, use 'name' unless it's NULL. */
2010+
unsigned long value = 0L;
2011+
2012+
if (XGetFontProperty(font, XA_FONT, &value))
2013+
{
2014+
char *xa_font_name = NULL;
2015+
2016+
xa_font_name = XGetAtomName(gui.dpy, value);
2017+
if (xa_font_name != NULL)
2018+
{
2019+
ret = vim_strsave((char_u *)xa_font_name);
2020+
XFree(xa_font_name);
2021+
}
2022+
else if (name != NULL)
2023+
ret = vim_strsave(name);
2024+
}
2025+
else if (name != NULL)
2026+
ret = vim_strsave(name);
2027+
}
2028+
return ret;
20032029
}
20042030
#endif
20052031

src/syntax.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8169,7 +8169,7 @@ hl_has_settings(int idx, int check_link)
81698169
|| HL_TABLE()[idx].sg_gui_fg_name != NULL
81708170
|| HL_TABLE()[idx].sg_gui_bg_name != NULL
81718171
|| HL_TABLE()[idx].sg_gui_sp_name != NULL
8172-
|| HL_TABLE()[idx].sg_font_name != NUL
8172+
|| HL_TABLE()[idx].sg_font_name != NULL
81738173
#endif
81748174
|| (check_link && (HL_TABLE()[idx].sg_set & SG_LINK)));
81758175
}

src/testdir/Make_dos.mak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ test_gui.res: test_gui.vim
126126

127127
test_gui_init.res: test_gui_init.vim
128128
@echo "$(VIMPROG)" > vimcmd
129-
$(VIMPROG) -u NONE -U gui_init.vim $(NO_PLUGINS) -S runtest.vim $*.vim
129+
$(VIMPROG) -u gui_preinit.vim -U gui_init.vim $(NO_PLUGINS) -S runtest.vim $*.vim
130130
@del vimcmd
131131

132132
opt_test.vim: ../option.c gen_opt_test.vim

src/testdir/Make_ming.mak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ test_gui.res: test_gui.vim
129129

130130
test_gui_init.res: test_gui_init.vim
131131
@echo "$(VIMPROG)" > vimcmd
132-
$(VIMPROG) -u NONE -U gui_init.vim $(NO_PLUGINS) -S runtest.vim $<
132+
$(VIMPROG) -u gui_preinit_vim -U gui_init.vim $(NO_PLUGINS) -S runtest.vim $<
133133
@$(DEL) vimcmd
134134

135135
opt_test.vim: ../option.c gen_opt_test.vim

src/testdir/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ test_gui.res: test_gui.vim
138138

139139
test_gui_init.res: test_gui_init.vim
140140
@echo "$(RUN_GVIMTEST_WITH_GVIMRC)" > vimcmd
141-
$(RUN_VIMTEST) -u NONE -U gui_init.vim $(NO_PLUGINS) -S runtest.vim $<
141+
$(RUN_VIMTEST) -u gui_preinit.vim -U gui_init.vim $(NO_PLUGINS) -S runtest.vim $<
142142
@rm vimcmd
143143

144144
opt_test.vim: ../option.c gen_opt_test.vim

src/testdir/gui_init.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
if has('gui_athena') || has('gui_motif') || has('gui_gtk2') || has('gui_gtk3')
44
set guiheadroom=0
5+
set guioptions+=p
56
endif

src/testdir/gui_preinit.vim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
" vimrc for test_gui_init.vim
2+
3+
" Note that this flag must be added in the .vimrc file, before switching on
4+
" syntax or filetype recognition (when the |gvimrc| file is sourced the system
5+
" menu has already been loaded; the ":syntax on" and ":filetype on" commands
6+
" load the menu too).
7+
set guioptions+=M

src/testdir/test_gui.vim

Lines changed: 206 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ func Test_balloon_show()
3030
endif
3131
endfunc
3232

33+
func Test_colorscheme()
34+
let colorscheme_saved = exists('g:colors_name') ? g:colors_name : 'default'
35+
36+
colorscheme torte
37+
redraw!
38+
sleep 200m
39+
call assert_equal('dark', &background)
40+
41+
exec 'colorscheme' colorscheme_saved
42+
redraw!
43+
endfunc
44+
3345
func Test_getfontname_with_arg()
3446
let skipped = ''
3547

@@ -40,8 +52,8 @@ func Test_getfontname_with_arg()
4052
call assert_equal('', getfontname('notexist'))
4153

4254
" Valid font name. This is usually the real name of 7x13 by default.
43-
let fname = '-misc-fixed-medium-r-normal--13-120-75-75-c-70-iso8859-1'
44-
call assert_equal(fname, getfontname(fname))
55+
let fname = '-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1'
56+
call assert_match(fname, getfontname(fname))
4557

4658
elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
4759
" Invalid font name. The result should be the name plus the default size.
@@ -68,8 +80,9 @@ func Test_getfontname_without_arg()
6880
" 'expected' is the value specified by SetUp() above.
6981
call assert_equal('Courier 10 Pitch/8/-1/5/50/0/0/0/0/0', fname)
7082
elseif has('gui_athena') || has('gui_motif')
71-
" 'expected' is DFLT_FONT of gui_x11.c.
72-
call assert_equal('7x13', fname)
83+
" 'expected' is DFLT_FONT of gui_x11.c or its real name.
84+
let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)'
85+
call assert_match(pat, fname)
7386
elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
7487
" 'expected' is DEFAULT_FONT of gui_gtk_x11.c.
7588
call assert_equal('Monospace 10', fname)
@@ -80,6 +93,12 @@ func Test_getfontname_without_arg()
8093
endif
8194
endfunc
8295

96+
func Test_getwinpos()
97+
call assert_match('Window position: X \d\+, Y \d\+', execute('winpos'))
98+
call assert_true(getwinposx() >= 0)
99+
call assert_true(getwinposy() >= 0)
100+
endfunc
101+
83102
func Test_quoteplus()
84103
let skipped = ''
85104

@@ -125,6 +144,18 @@ func Test_quoteplus()
125144
endif
126145
endfunc
127146

147+
func Test_set_background()
148+
let background_saved = &background
149+
150+
set background&
151+
call assert_equal('light', &background)
152+
153+
set background=dark
154+
call assert_equal('dark', &background)
155+
156+
let &background = background_saved
157+
endfunc
158+
128159
func Test_set_balloondelay()
129160
if !exists('+balloondelay')
130161
return
@@ -248,6 +279,46 @@ func Test_set_balloonexpr()
248279
let &balloonexpr = balloonexpr_saved
249280
endfunc
250281

282+
" Invalid arguments are tested with test_options in conjunction with segfaults
283+
" caused by them (Patch 8.0.0357, 24922ec233).
284+
func Test_set_guicursor()
285+
let guicursor_saved = &guicursor
286+
287+
let default = [
288+
\ "n-v-c:block-Cursor/lCursor",
289+
\ "ve:ver35-Cursor",
290+
\ "o:hor50-Cursor",
291+
\ "i-ci:ver25-Cursor/lCursor",
292+
\ "r-cr:hor20-Cursor/lCursor",
293+
\ "sm:block-Cursor-blinkwait175-blinkoff150-blinkon175"
294+
\ ]
295+
296+
" Default Value
297+
set guicursor&
298+
call assert_equal(join(default, ','), &guicursor)
299+
300+
" Argument List Example 1
301+
let opt_list = copy(default)
302+
let opt_list[0] = "n-c-v:block-nCursor"
303+
exec "set guicursor=" . join(opt_list, ',')
304+
call assert_equal(join(opt_list, ','), &guicursor)
305+
unlet opt_list
306+
307+
" Argument List Example 2
308+
let opt_list = copy(default)
309+
let opt_list[3] = "i-ci:ver30-iCursor-blinkwait300-blinkon200-blinkoff150"
310+
exec "set guicursor=" . join(opt_list, ',')
311+
call assert_equal(join(opt_list, ','), &guicursor)
312+
unlet opt_list
313+
314+
" 'a' Mode
315+
set guicursor&
316+
let &guicursor .= ',a:blinkon0'
317+
call assert_equal(join(default, ',') . ",a:blinkon0", &guicursor)
318+
319+
let &guicursor = guicursor_saved
320+
endfunc
321+
251322
func Test_set_guifont()
252323
let skipped = ''
253324

@@ -274,11 +345,13 @@ func Test_set_guifont()
274345
" Non-empty font list with a valid font name. Should pick up the first
275346
" valid font.
276347
set guifont=-notexist1-*,fixed,-notexist2-*
277-
call assert_equal('fixed', getfontname())
348+
let pat = '\(fixed\)\|\(\c-Misc-Fixed-Medium-R-SemiCondensed--13-120-75-75-C-60-ISO8859-1\)'
349+
call assert_match(pat, getfontname())
278350

279351
" Empty list. Should fallback to the built-in default.
280352
set guifont=
281-
call assert_equal('7x13', getfontname())
353+
let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)'
354+
call assert_match(pat, getfontname())
282355

283356
elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
284357
" For GTK, what we refer to as 'font names' in our manual are actually
@@ -477,10 +550,120 @@ func Test_set_guiheadroom()
477550
endif
478551
endfunc
479552

480-
func Test_getwinpos()
481-
call assert_match('Window position: X \d\+, Y \d\+', execute('winpos'))
482-
call assert_true(getwinposx() >= 0)
483-
call assert_true(getwinposy() >= 0)
553+
func Test_set_guioptions()
554+
let guioptions_saved = &guioptions
555+
let duration = '200m'
556+
557+
if has('win32')
558+
" Default Value
559+
set guioptions&
560+
call assert_equal('egmrLtT', &guioptions)
561+
562+
else
563+
" Default Value
564+
set guioptions&
565+
call assert_equal('aegimrLtT', &guioptions)
566+
567+
" To activate scrollbars of type 'L' or 'R'.
568+
wincmd v
569+
redraw!
570+
571+
" Remove all default GUI ornaments
572+
set guioptions-=T
573+
exec 'sleep' . duration
574+
call assert_equal('aegimrLt', &guioptions)
575+
set guioptions-=t
576+
exec 'sleep' . duration
577+
call assert_equal('aegimrL', &guioptions)
578+
set guioptions-=L
579+
exec 'sleep' . duration
580+
call assert_equal('aegimr', &guioptions)
581+
set guioptions-=r
582+
exec 'sleep' . duration
583+
call assert_equal('aegim', &guioptions)
584+
set guioptions-=m
585+
exec 'sleep' . duration
586+
call assert_equal('aegi', &guioptions)
587+
588+
" Try non-default GUI ornaments
589+
set guioptions+=l
590+
exec 'sleep' . duration
591+
call assert_equal('aegil', &guioptions)
592+
set guioptions-=l
593+
exec 'sleep' . duration
594+
call assert_equal('aegi', &guioptions)
595+
596+
set guioptions+=R
597+
exec 'sleep' . duration
598+
call assert_equal('aegiR', &guioptions)
599+
set guioptions-=R
600+
exec 'sleep' . duration
601+
call assert_equal('aegi', &guioptions)
602+
603+
set guioptions+=b
604+
exec 'sleep' . duration
605+
call assert_equal('aegib', &guioptions)
606+
set guioptions+=h
607+
exec 'sleep' . duration
608+
call assert_equal('aegibh', &guioptions)
609+
set guioptions-=h
610+
exec 'sleep' . duration
611+
call assert_equal('aegib', &guioptions)
612+
set guioptions-=b
613+
exec 'sleep' . duration
614+
call assert_equal('aegi', &guioptions)
615+
616+
set guioptions+=v
617+
exec 'sleep' . duration
618+
call assert_equal('aegiv', &guioptions)
619+
set guioptions-=v
620+
exec 'sleep' . duration
621+
call assert_equal('aegi', &guioptions)
622+
623+
if has('gui_motif')
624+
set guioptions+=F
625+
exec 'sleep' . duration
626+
call assert_equal('aegiF', &guioptions)
627+
set guioptions-=F
628+
exec 'sleep' . duration
629+
call assert_equal('aegi', &guioptions)
630+
endif
631+
632+
" Restore GUI ornaments to the default state.
633+
set guioptions+=m
634+
exec 'sleep' . duration
635+
call assert_equal('aegim', &guioptions)
636+
set guioptions+=r
637+
exec 'sleep' . duration
638+
call assert_equal('aegimr', &guioptions)
639+
set guioptions+=L
640+
exec 'sleep' . duration
641+
call assert_equal('aegimrL', &guioptions)
642+
set guioptions+=t
643+
exec 'sleep' . duration
644+
call assert_equal('aegimrLt', &guioptions)
645+
set guioptions+=T
646+
exec 'sleep' . duration
647+
call assert_equal("aegimrLtT", &guioptions)
648+
649+
wincmd o
650+
redraw!
651+
endif
652+
653+
let &guioptions = guioptions_saved
654+
endfunc
655+
656+
func Test_set_guipty()
657+
let guipty_saved = &guipty
658+
659+
" Default Value
660+
set guipty&
661+
call assert_equal(1, &guipty)
662+
663+
set noguipty
664+
call assert_equal(0, &guipty)
665+
666+
let &guipty = guipty_saved
484667
endfunc
485668

486669
func Test_shell_command()
@@ -490,6 +673,19 @@ func Test_shell_command()
490673
bwipe!
491674
endfunc
492675

676+
func Test_syntax_colortest()
677+
runtime syntax/colortest.vim
678+
redraw!
679+
sleep 200m
680+
bwipe!
681+
endfunc
682+
683+
func Test_set_term()
684+
" It's enough to check the current value since setting 'term' to anything
685+
" other than builtin_gui makes no sense at all.
686+
call assert_equal('builtin_gui', &term)
687+
endfunc
688+
493689
func Test_windowid_variable()
494690
if g:x11_based_gui || has('win32')
495691
call assert_true(v:windowid > 0)

0 commit comments

Comments
 (0)