]> granicus.if.org Git - vim/commitdiff
patch 8.0.0447: getting font name does not work on X11 v8.0.0447
authorBram Moolenaar <Bram@vim.org>
Sun, 12 Mar 2017 16:10:33 +0000 (17:10 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 12 Mar 2017 16:10:33 +0000 (17:10 +0100)
Problem:    Getting font name does not work on X11.
Solution:   Implement gui_mch_get_fontname() for X11.  Add more GUI tests.
            (Kazunobu Kuriyama)

Filelist
src/gui_x11.c
src/syntax.c
src/testdir/Make_dos.mak
src/testdir/Make_ming.mak
src/testdir/Makefile
src/testdir/gui_init.vim
src/testdir/gui_preinit.vim [new file with mode: 0644]
src/testdir/test_gui.vim
src/testdir/test_gui_init.vim
src/version.c

index 2aeea2800e7bd45d717bcf68f03fec4d6fecdf22..72a1f9685b2a7ce352e19971f2088ed02f76a70c 100644 (file)
--- a/Filelist
+++ b/Filelist
@@ -110,6 +110,7 @@ SRC_ALL =   \
                src/testdir/setup.vim \
                src/testdir/gui_init.vim \
                src/testdir/setup_gui.vim \
+               src/testdir/gui_preinit.vim \
                src/testdir/test[0-9]*.ok \
                src/testdir/test[0-9]*a.ok \
                src/testdir/test_[a-z]*.ok \
index 2cc0eba85cb824f0553e70e7553696c777cb8dcd..2226e89547aa755318a0461f17eae4dbb7c504aa 100644 (file)
@@ -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
 
index 11f679c0c831bbd66d73a76dd6b76abdf5805913..b13bd93a2aa846f0b4bcd1ea2cba3acce685c427 100644 (file)
@@ -8169,7 +8169,7 @@ hl_has_settings(int idx, int check_link)
            || HL_TABLE()[idx].sg_gui_fg_name != NULL
            || HL_TABLE()[idx].sg_gui_bg_name != NULL
            || HL_TABLE()[idx].sg_gui_sp_name != NULL
-           || HL_TABLE()[idx].sg_font_name != NUL
+           || HL_TABLE()[idx].sg_font_name != NULL
 #endif
            || (check_link && (HL_TABLE()[idx].sg_set & SG_LINK)));
 }
index 0e7b461d772e004dfa84e75ef21efd90d2a7f157..f9d21a5fa8d09b2c4a82467d7acda04d12755223 100644 (file)
@@ -126,7 +126,7 @@ test_gui.res: test_gui.vim
 
 test_gui_init.res: test_gui_init.vim
        @echo "$(VIMPROG)" > vimcmd
-       $(VIMPROG) -u NONE -U gui_init.vim $(NO_PLUGINS) -S runtest.vim $*.vim
+       $(VIMPROG) -u gui_preinit.vim -U gui_init.vim $(NO_PLUGINS) -S runtest.vim $*.vim
        @del vimcmd
 
 opt_test.vim: ../option.c gen_opt_test.vim
index ad4697d723113906cc41999b26293fd0b2e66881..7e13c0f787e33416229feea04eff6db73d6bd058 100644 (file)
@@ -129,7 +129,7 @@ test_gui.res: test_gui.vim
 
 test_gui_init.res: test_gui_init.vim
        @echo "$(VIMPROG)" > vimcmd
-       $(VIMPROG) -u NONE -U gui_init.vim $(NO_PLUGINS) -S runtest.vim $<
+       $(VIMPROG) -u gui_preinit_vim -U gui_init.vim $(NO_PLUGINS) -S runtest.vim $<
        @$(DEL) vimcmd
 
 opt_test.vim: ../option.c gen_opt_test.vim
index ca8597fe7363e47e1106b26b7d888f7f9d216306..ce1c24cd68251ead35c6ab778d6e3b7fdbff013d 100644 (file)
@@ -138,7 +138,7 @@ test_gui.res: test_gui.vim
 
 test_gui_init.res: test_gui_init.vim
        @echo "$(RUN_GVIMTEST_WITH_GVIMRC)" > vimcmd
-       $(RUN_VIMTEST) -u NONE -U gui_init.vim $(NO_PLUGINS) -S runtest.vim $<
+       $(RUN_VIMTEST) -u gui_preinit.vim -U gui_init.vim $(NO_PLUGINS) -S runtest.vim $<
        @rm vimcmd
 
 opt_test.vim: ../option.c gen_opt_test.vim
index bc5e33cb2adb05d075c8da76552606a7ba7f2302..42b2bca7fe5d7d2c9c2cf8250b86c12296e7ed60 100644 (file)
@@ -2,4 +2,5 @@
 
 if has('gui_athena') || has('gui_motif') || has('gui_gtk2') || has('gui_gtk3')
   set guiheadroom=0
+  set guioptions+=p
 endif
diff --git a/src/testdir/gui_preinit.vim b/src/testdir/gui_preinit.vim
new file mode 100644 (file)
index 0000000..c351b72
--- /dev/null
@@ -0,0 +1,7 @@
+" vimrc for test_gui_init.vim
+
+" Note that this flag must be added in the .vimrc file, before switching on
+" syntax or filetype recognition (when the |gvimrc| file is sourced the system
+" menu has already been loaded; the ":syntax on" and ":filetype on" commands
+" load the menu too).
+set guioptions+=M
index 7d39a1d40deb4553d36060a1e679cf068f3a504e..3e06eab344dcc6256b16256dae525167f9c2939d 100644 (file)
@@ -30,6 +30,18 @@ func Test_balloon_show()
   endif
 endfunc
 
+func Test_colorscheme()
+  let colorscheme_saved = exists('g:colors_name') ? g:colors_name : 'default'
+
+  colorscheme torte
+  redraw!
+  sleep 200m
+  call assert_equal('dark', &background)
+
+  exec 'colorscheme' colorscheme_saved
+  redraw!
+endfunc
+
 func Test_getfontname_with_arg()
   let skipped = ''
 
@@ -40,8 +52,8 @@ func Test_getfontname_with_arg()
     call assert_equal('', getfontname('notexist'))
 
     " Valid font name. This is usually the real name of 7x13 by default.
-    let fname = '-misc-fixed-medium-r-normal--13-120-75-75-c-70-iso8859-1'
-    call assert_equal(fname, getfontname(fname))
+    let fname = '-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1'
+    call assert_match(fname, getfontname(fname))
 
   elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
     " Invalid font name. The result should be the name plus the default size.
@@ -68,8 +80,9 @@ func Test_getfontname_without_arg()
     " 'expected' is the value specified by SetUp() above.
     call assert_equal('Courier 10 Pitch/8/-1/5/50/0/0/0/0/0', fname)
   elseif has('gui_athena') || has('gui_motif')
-    " 'expected' is DFLT_FONT of gui_x11.c.
-    call assert_equal('7x13', fname)
+    " 'expected' is DFLT_FONT of gui_x11.c or its real name.
+    let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)'
+    call assert_match(pat, fname)
   elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
     " 'expected' is DEFAULT_FONT of gui_gtk_x11.c.
     call assert_equal('Monospace 10', fname)
@@ -80,6 +93,12 @@ func Test_getfontname_without_arg()
   endif
 endfunc
 
+func Test_getwinpos()
+  call assert_match('Window position: X \d\+, Y \d\+', execute('winpos'))
+  call assert_true(getwinposx() >= 0)
+  call assert_true(getwinposy() >= 0)
+endfunc
+
 func Test_quoteplus()
   let skipped = ''
 
@@ -125,6 +144,18 @@ func Test_quoteplus()
   endif
 endfunc
 
+func Test_set_background()
+  let background_saved = &background
+
+  set background&
+  call assert_equal('light', &background)
+
+  set background=dark
+  call assert_equal('dark', &background)
+
+  let &background = background_saved
+endfunc
+
 func Test_set_balloondelay()
   if !exists('+balloondelay')
     return
@@ -248,6 +279,46 @@ func Test_set_balloonexpr()
   let &balloonexpr = balloonexpr_saved
 endfunc
 
+" Invalid arguments are tested with test_options in conjunction with segfaults
+" caused by them (Patch 8.0.0357, 24922ec233).
+func Test_set_guicursor()
+  let guicursor_saved = &guicursor
+
+  let default = [
+        \ "n-v-c:block-Cursor/lCursor",
+        \ "ve:ver35-Cursor",
+        \ "o:hor50-Cursor",
+        \ "i-ci:ver25-Cursor/lCursor",
+        \ "r-cr:hor20-Cursor/lCursor",
+        \ "sm:block-Cursor-blinkwait175-blinkoff150-blinkon175"
+        \ ]
+
+  " Default Value
+  set guicursor&
+  call assert_equal(join(default, ','), &guicursor)
+
+  " Argument List Example 1
+  let opt_list = copy(default)
+  let opt_list[0] = "n-c-v:block-nCursor"
+  exec "set guicursor=" . join(opt_list, ',')
+  call assert_equal(join(opt_list, ','), &guicursor)
+  unlet opt_list
+
+  " Argument List Example 2
+  let opt_list = copy(default)
+  let opt_list[3] = "i-ci:ver30-iCursor-blinkwait300-blinkon200-blinkoff150"
+  exec "set guicursor=" . join(opt_list, ',')
+  call assert_equal(join(opt_list, ','), &guicursor)
+  unlet opt_list
+
+  " 'a' Mode
+  set guicursor&
+  let &guicursor .= ',a:blinkon0'
+  call assert_equal(join(default, ',') . ",a:blinkon0", &guicursor)
+
+  let &guicursor = guicursor_saved
+endfunc
+
 func Test_set_guifont()
   let skipped = ''
 
@@ -274,11 +345,13 @@ func Test_set_guifont()
     " Non-empty font list with a valid font name.  Should pick up the first
     " valid font.
     set guifont=-notexist1-*,fixed,-notexist2-*
-    call assert_equal('fixed', getfontname())
+    let pat = '\(fixed\)\|\(\c-Misc-Fixed-Medium-R-SemiCondensed--13-120-75-75-C-60-ISO8859-1\)'
+    call assert_match(pat, getfontname())
 
     " Empty list. Should fallback to the built-in default.
     set guifont=
-    call assert_equal('7x13', getfontname())
+    let pat = '\(7x13\)\|\(\c-Misc-Fixed-Medium-R-Normal--13-120-75-75-C-70-ISO8859-1\)'
+    call assert_match(pat, getfontname())
 
   elseif has('gui_gtk2') || has('gui_gnome') || has('gui_gtk3')
     " For GTK, what we refer to as 'font names' in our manual are actually
@@ -477,10 +550,120 @@ func Test_set_guiheadroom()
   endif
 endfunc
 
-func Test_getwinpos()
-  call assert_match('Window position: X \d\+, Y \d\+', execute('winpos'))
-  call assert_true(getwinposx() >= 0)
-  call assert_true(getwinposy() >= 0)
+func Test_set_guioptions()
+  let guioptions_saved = &guioptions
+  let duration = '200m'
+
+  if has('win32')
+    " Default Value
+    set guioptions&
+    call assert_equal('egmrLtT', &guioptions)
+
+  else
+    " Default Value
+    set guioptions&
+    call assert_equal('aegimrLtT', &guioptions)
+
+    " To activate scrollbars of type 'L' or 'R'.
+    wincmd v
+    redraw!
+
+    " Remove all default GUI ornaments
+    set guioptions-=T
+    exec 'sleep' . duration
+    call assert_equal('aegimrLt', &guioptions)
+    set guioptions-=t
+    exec 'sleep' . duration
+    call assert_equal('aegimrL', &guioptions)
+    set guioptions-=L
+    exec 'sleep' . duration
+    call assert_equal('aegimr', &guioptions)
+    set guioptions-=r
+    exec 'sleep' . duration
+    call assert_equal('aegim', &guioptions)
+    set guioptions-=m
+    exec 'sleep' . duration
+    call assert_equal('aegi', &guioptions)
+
+    " Try non-default GUI ornaments
+    set guioptions+=l
+    exec 'sleep' . duration
+    call assert_equal('aegil', &guioptions)
+    set guioptions-=l
+    exec 'sleep' . duration
+    call assert_equal('aegi', &guioptions)
+
+    set guioptions+=R
+    exec 'sleep' . duration
+    call assert_equal('aegiR', &guioptions)
+    set guioptions-=R
+    exec 'sleep' . duration
+    call assert_equal('aegi', &guioptions)
+
+    set guioptions+=b
+    exec 'sleep' . duration
+    call assert_equal('aegib', &guioptions)
+    set guioptions+=h
+    exec 'sleep' . duration
+    call assert_equal('aegibh', &guioptions)
+    set guioptions-=h
+    exec 'sleep' . duration
+    call assert_equal('aegib', &guioptions)
+    set guioptions-=b
+    exec 'sleep' . duration
+    call assert_equal('aegi', &guioptions)
+
+    set guioptions+=v
+    exec 'sleep' . duration
+    call assert_equal('aegiv', &guioptions)
+    set guioptions-=v
+    exec 'sleep' . duration
+    call assert_equal('aegi', &guioptions)
+
+    if has('gui_motif')
+      set guioptions+=F
+      exec 'sleep' . duration
+      call assert_equal('aegiF', &guioptions)
+      set guioptions-=F
+      exec 'sleep' . duration
+      call assert_equal('aegi', &guioptions)
+    endif
+
+    " Restore GUI ornaments to the default state.
+    set guioptions+=m
+    exec 'sleep' . duration
+    call assert_equal('aegim', &guioptions)
+    set guioptions+=r
+    exec 'sleep' . duration
+    call assert_equal('aegimr', &guioptions)
+    set guioptions+=L
+    exec 'sleep' . duration
+    call assert_equal('aegimrL', &guioptions)
+    set guioptions+=t
+    exec 'sleep' . duration
+    call assert_equal('aegimrLt', &guioptions)
+    set guioptions+=T
+    exec 'sleep' . duration
+    call assert_equal("aegimrLtT", &guioptions)
+
+    wincmd o
+    redraw!
+  endif
+
+  let &guioptions = guioptions_saved
+endfunc
+
+func Test_set_guipty()
+  let guipty_saved = &guipty
+
+  " Default Value
+  set guipty&
+  call assert_equal(1, &guipty)
+
+  set noguipty
+  call assert_equal(0, &guipty)
+
+  let &guipty = guipty_saved
 endfunc
 
 func Test_shell_command()
@@ -490,6 +673,19 @@ func Test_shell_command()
   bwipe!
 endfunc
 
+func Test_syntax_colortest()
+  runtime syntax/colortest.vim
+  redraw!
+  sleep 200m
+  bwipe!
+endfunc
+
+func Test_set_term()
+  " It's enough to check the current value since setting 'term' to anything
+  " other than builtin_gui makes no sense at all.
+  call assert_equal('builtin_gui', &term)
+endfunc
+
 func Test_windowid_variable()
   if g:x11_based_gui || has('win32')
     call assert_true(v:windowid > 0)
index 811c6ecb23f381dd580dc45245a344fdb9f5a207..21e5bb6a7af8bc1f0ec8a41b501b1e7eb9c3b001 100644 (file)
@@ -36,3 +36,25 @@ func Test_set_guiheadroom()
     throw skipped
   endif
 endfunc
+
+func Test_set_guioptions_for_M()
+  sleep 200ms
+  " Check if the 'M' option is included.
+  call assert_match('.*M.*', &guioptions)
+endfunc
+
+func Test_set_guioptions_for_p()
+  let skipped = ''
+
+  if !g:x11_based_gui
+    let skipped = g:not_supported . '''p'' of guioptions'
+  else
+    sleep 200ms
+    " Check if the 'p' option is included.
+    call assert_match('.*p.*', &guioptions)
+  endif
+
+  if !empty(skipped)
+    throw skipped
+  endif
+endfunc
index cb416dcf90f2112d1a537b7c210bfd160b2447e5..caf1b64dc0be956a02895dccdcb448dc366ae65e 100644 (file)
@@ -764,6 +764,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    447,
 /**/
     446,
 /**/