Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
bin\
*.dll
108 changes: 68 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Solution:

## Configuration

**I will start by saying that the solution is pretty hacky.**

The plugin consists of two ``*.dll`` files.
GVim removes plugin from memory just after using it, so we need two plugins:
Expand All @@ -32,63 +31,92 @@ GVim removes plugin from memory just after using it, so we need two plugins:
itself from memory after Gvim closes

**Repository provides you with precompiled dll libraries
for 32b and 64b system. But you need to change the name
of the files when copying into GVim installation directory.**
for 32bit and 64bit systems (located in lib/x86 and lib/x64).**

Both dll libraries need to be placed in GVim installation directory.
The default installation directory (for 64 bit system) is:
``C:\Program Files\vim\vim80``
These dll's live in the lib directory of the package itself. No need to
copy them elsewhere!

Then we need to put those lines in our vimrc:
## Installation

```vim
" GVim settings only
if has("gui_running")
**Pathogen**
```
IF NOT EXIST %HOMEPATH%\vimfiles\bundle mkdir %HOMEPATH%\vimfiles\bundle
cd %HOMEPATH%\vimfiles\bundle
git clone https://github.com/azzoam/FixGVimBorder.git
```

"FixGVimBorder
if $VIM_FULLSCREEN_DLL_FIX
" dll already loaded, do nothing
else
" load the dll fix
Other Vim package managers should work fine, but I have not tested
all of them.

" auto detects background color and uses it on the border
" this works most of the time
"autocmd GUIEnter * call libcall("loadfixgvimborder.dll", "LoadFixGVimBorder", 0)
Once installed, all we need is to put these lines in our vimrc:

" permanent solution - setup border color by hand using hex format
" this is recomended solution
autocmd GUIEnter * call libcall("loadfixgvimborder.dll", "LoadFixGVimBorder", "#002B36")
let $VIM_FULLSCREEN_DLL_FIX = 1
endif
```vim
execute pathogen#infect()

if has('gui_running')
" ...
colorscheme SOME_COLOR_SCHEME
" ...
endif

endif
call fixGVimBorder#auto()
```
`fixGVimBorder#auto()` will do all the work to autodetect your background
color, load the dll patches, and fill in GVim's borders with the background
color. It also autodetects whether to center the screen or not to
ensure compatibility with scrollbars and menus.

**The plugin can be loaded only in GVim section.**
Please **NOTE** that the only requirement for the placement of `call fixGVimBorder#auto()`
is **after** `execute pathogen#infect()` and setting of the colorscheme.

**If you put it inside console vim then it may crasch the program.**
`fixGVimBorder#auto()` can be called either inside or outside of the
`has('gui_running')` block, it does not matter. In console Vim the code does nothing.

**The plugin can be loaded only ONCE after GVim startup!**
## Customization

**NOTE** that the recommeded use sets an environment variable
`$VIM_FULLSCREEN_DLL_FIX` to 1 when the dll loads, which prevents
the dll from being reloaded if you reload your vimrc in the same session.
The vimrc above will autodetect your background color and fill the screen
border with it. If you experience issues, or wish to specificy the color
yourself, simply pass a hex color to fixGVimBorder like below.

Reloading the plugin a second time may cause memory leaks and glitches
(not tested).
```vim
call fixGVimBorder#auto("#FF0000")
```
or
```vim
call fixGVimBorder#withColor("#FF0000")
```

If plugin doesn't work try loading it using ``echo`` instead of ``call``
command to see if there are any detected errors:
If plugin doesn't work try the following in your vimrc to see if there are
any detected errors:

```vim
" GVim settings only
if has("gui_running")
" use echo instead of call to see returned message
autocmd GUIEnter * echo libcall("loadfixgvimborder.dll", "LoadFixGVimBorder", 0)
endif
call fixGVimBorder#printErrors()
```

## Centering

The patch can either center the VimText area or not. Centering looks
better on GVim with no menu or scrollbars present, but interferes with
several elements -- see "Scrollbar and other GUI elements issues"

The user-facing functions can either autodetect which should occur,
or allow you to specify them yourself.

**Autodetect centering:**
* `fixGVimBorder#auto()`
* `fixGVimBorder#withColor()`
* `fixGVimBorder#printErrors()`

**Force centering:**
* `fixGVimBorder#center()`
* `fixGVimBorder#withColorCenter()`
* `fixGVimBorder#printErrorsCenter()`

**Force no centering:**
* `fixGVimBorder#noCenter()`
* `fixGVimBorder#withColorNoCenter()`
* `fixGVimBorder#printErrorsNoCenter()`

# Known problems

There are situations not handled by this plugin:
Expand All @@ -103,7 +131,7 @@ Because the plugin tries to center the vim text area it may interfere with GUI.
The well know problem is scroll bar.

If you have any problems with GUI elements when using the plugin load it using
`LoadFixGVimBorderWithoutAutocentering` function instead of `LoadFixGVimBorder`.
the force no centering functions insead.

# Thanks

Expand Down
223 changes: 223 additions & 0 deletions autoload/fixGVimBorder.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@

function! fixGVimBorder#auto(...)

if has("gui_running")

if a:0 == 0
let border_color = synIDattr(synIDtrans(hlID("Normal")), "bg", "gui")
elseif a:0 == 1
let border_color = a:1
else
" TODO(alex): handle this error
return 0
endif

if &go =~ "m" || &go =~ "T" || &go =~ "r" || &go =~ "L"
call fixGVimBorder#noCenter(border_color)
else
call fixGVimBorder#center(border_color)
endif

endif

endfunction

function! fixGVimBorder#center(...)

if has("gui_running")

if a:0 == 0
let border_color = synIDattr(synIDtrans(hlID("Normal")), "bg", "gui")
elseif a:0 == 1
let border_color = a:1
else
" TODO(alex): handle this error
return 0
endif

call s:fixGVimBorder(border_color, 1, 0)

endif

endfunction

function! fixGVimBorder#noCenter(...)

if has("gui_running")

if a:0 == 0
let border_color = synIDattr(synIDtrans(hlID("Normal")), "bg", "gui")
elseif a:0 == 1
let border_color = a:1
else
" TODO(alex): handle this error
return 0
endif

call s:fixGVimBorder(border_color, 0, 0)

endif

endfunction

function! fixGVimBorder#withColor(border_color)

if has("gui_running")

call fixGVimBorder#auto(a:border_color)

endif

endfunction

function! fixGVimBorder#withColorCenter(border_color)

if has("gui_running")

call fixGVimBorder#center(a:border_color)

endif

endfunction

function! fixGVimBorder#withColorNoCenter(border_color)

if has("gui_running")

call fixGVimBorder#noCenter(a:border_color)

endif

endfunction

function! fixGVimBorder#printErrors(...)

if has("gui_running")

if a:0 == 0
let border_color = synIDattr(synIDtrans(hlID("Normal")), "bg", "gui")
elseif a:0 == 1
let border_color = a:1
else
" TODO(alex): handle this error
return 0
endif

if &go =~ "m" || &go =~ "T" || &go =~ "r" || &go =~ "L"
call fixGVimBorder#printErrorsNoCenter(border_color)
else
call fixGVimBorder#printErrorsCenter(border_color)
endif

endif

endfunction

function! fixGVimBorder#printErrorsCenter(...)

if has("gui_running")

if a:0 == 0
let border_color = synIDattr(synIDtrans(hlID("Normal")), "bg", "gui")
elseif a:0 == 1
let border_color = a:1
else
" TODO(alex): handle this error
return 0
endif

call s:fixGVimBorder(border_color, 1, 1)

endif

endfunction

function! fixGVimBorder#printErrorsNoCenter(...)

if has("gui_running")

if a:0 == 0
let border_color = synIDattr(synIDtrans(hlID("Normal")), "bg", "gui")
elseif a:0 == 1
let border_color = a:1
else
" TODO(alex): handle this error
return 0
endif

call s:fixGVimBorder(border_color, 0, 1)

endif

endfunction


function! DLLIsInstalled(lib_path)

let dll_installed = len(split(globpath(&rtp, a:lib_path), '\n'))

return dll_installed && 1

endfunction


function! s:fixGVimBorder(border_color, auto_center, debug_mode)

if !exists("g:gvim_border_fixed")
" load the dll fix

if has("win32")
" Fix for Windows
call s:Win32Fix(a:border_color, a:auto_center, a:debug_mode)
else
" TODO(alex): add support for linux and macos here

endif

let g:gvim_border_fixed = 1
else
" dll already loaded, do nothing
endif

endfunction

function! s:Win32Fix(border_color, auto_center, debug_mode)

let first_lib_path = "lib/x86/loadfixgvimborder.dll"
let second_lib_path = "lib/x86/fixgvimborder.dll"
if has("win64")
let first_lib_path = "lib/x64/loadfixgvimborder.dll"
let second_lib_path = "lib/x64/fixgvimborder.dll"
endif

if DLLIsInstalled(first_lib_path) && DLLIsInstalled(second_lib_path)
let $GVIM_BORDER_FIX_DLL_PATH = split(globpath(&rtp, first_lib_path))[0]
if a:debug_mode
if a:auto_center
let $GVIM_BORDER_COL = a:border_color
autocmd GUIEnter * echom libcall($GVIM_BORDER_FIX_DLL_PATH, "LoadFixGVimBorder", $GVIM_BORDER_COL)
else
let $GVIM_BORDER_COL = a:border_color
autocmd GUIEnter * echom libcall($GVIM_BORDER_FIX_DLL_PATH, "LoadFixGVimBorderWithoutAutocentering", $GVIM_BORDER_COL)
endif
else
if a:auto_center
let $GVIM_BORDER_COL = a:border_color
autocmd GUIEnter * call libcall($GVIM_BORDER_FIX_DLL_PATH, "LoadFixGVimBorder", $GVIM_BORDER_COL)
else
let $GVIM_BORDER_COL = a:border_color
autocmd GUIEnter * call libcall($GVIM_BORDER_FIX_DLL_PATH, "LoadFixGVimBorderWithoutAutocentering", $GVIM_BORDER_COL)
endif
endif
else
" TODO(alex): handle dll not installed error
return 0
endif

endfunction






Loading