├── README.md ├── README.orig ├── gvimfullscreen.c ├── gvimfullscreen.dll ├── gvimfullscreen.dll.x64 └── makefile /README.md: -------------------------------------------------------------------------------- 1 | This is a mirror of http://www.vim.org/scripts/script.php?script_id=2596 2 | 3 | Allows you to run gvim in full screen on Windows on a single monitor. 4 | 5 | This is a copy of Yasuhiro Matsumoto's VimTweak's EnableMaximize functionality modified to deal with window borders and allowing the window to overlap the task bar. 6 | 7 | 8 | * 修复在多个显示器下将GVim切入全屏时只能在主显示器全屏的问题. 9 | * 修复在将GVim窗口切换到全屏时,窗口右侧和底部出现的白色边框(白边)问题. 10 | * 准确记录GVim窗口的大小,坐标,状态等信息,由全屏切回正常窗口时准确还原切换前的状态. 11 | * 增加设置GVim窗口透明度和置顶的功能. 12 | 13 | 14 | #使用方法 15 | ``` 16 | :call libcallnr("gvimfullscreen.dll", "ToggleFullScreen", 0) 17 | ``` 18 | 19 | #vimrc 配置实例: 20 | ``` 21 | if has('gui_running') && has('libcall') 22 | let g:MyVimLib = $VIMRUNTIME.'/gvimfullscreen.dll' 23 | function ToggleFullScreen() 24 | call libcallnr(g:MyVimLib, "ToggleFullScreen", 0) 25 | endfunction 26 | 27 | "Alt+Enter 28 | map :call ToggleFullScreen() 29 | 30 | let g:VimAlpha = 240 31 | function! SetAlpha(alpha) 32 | let g:VimAlpha = g:VimAlpha + a:alpha 33 | if g:VimAlpha < 180 34 | let g:VimAlpha = 180 35 | endif 36 | if g:VimAlpha > 255 37 | let g:VimAlpha = 255 38 | endif 39 | call libcall(g:MyVimLib, 'SetAlpha', g:VimAlpha) 40 | endfunction 41 | 42 | "Shift+Y 43 | nmap :call SetAlpha(3) 44 | "Shift+T 45 | nmap :call SetAlpha(-3) 46 | 47 | let g:VimTopMost = 0 48 | function! SwitchVimTopMostMode() 49 | if g:VimTopMost == 0 50 | let g:VimTopMost = 1 51 | else 52 | let g:VimTopMost = 0 53 | endif 54 | call libcall(g:MyVimLib, 'EnableTopMost', g:VimTopMost) 55 | endfunction 56 | 57 | "Shift+R 58 | nmap :call SwitchVimTopMostMode() 59 | endif 60 | ``` 61 | 62 | #dll文件说明 63 | 64 | `gvimfullscreen.dll` for x86(32位) 65 | `gvimfullscreen.dll.x64` for x64(64位,使用时请将.x64的扩展名去掉) 66 | 67 | 68 | 69 | #全屏后GVim窗口的一些小问题. 70 | * 可能会存在全屏后窗口仍有一部分边框的问题, 可以通过修改`src/gui_w32.c`来解决. 71 | 72 | ``` 73 | diff -r 87ef9ff527dd src/gui_w32.c 74 | --- a/src/gui_w32.c Tue Nov 05 17:40:53 2013 +0100 75 | +++ b/src/gui_w32.c Wed Nov 06 10:54:51 2013 +0800 76 | @@ -1516,7 +1516,8 @@ 77 | return FAIL; 78 | } 79 | s_textArea = CreateWindowEx( 80 | - WS_EX_CLIENTEDGE, 81 | + /*WS_EX_CLIENTEDGE,*/ 82 | + 0, 83 | szTextAreaClass, "Vim text area", 84 | WS_CHILD | WS_VISIBLE, 0, 0, 85 | 100, /* Any value will do for now */ 86 | @@ -1565,7 +1566,8 @@ 87 | /* 88 | * Start out by adding the configured border width into the border offset 89 | */ 90 | - gui.border_offset = gui.border_width + 2; /*CLIENT EDGE*/ 91 | + /*gui.border_offset = gui.border_width + 2; [>CLIENT EDGE<]*/ 92 | + gui.border_offset = gui.border_width; 93 | 94 | /* 95 | * Set up for Intellimouse processing 96 | ``` -------------------------------------------------------------------------------- /README.orig: -------------------------------------------------------------------------------- 1 | gVimWin32FullScreen 2 | Derek McLoughlin 3 | 4 | * What is this 5 | Put gvim into full screen on the primary monitor in Microsoft Windows. 6 | This is a copy of Yasuhiro Matsumoto's VimTweak's EnableMaximize 7 | functionality modified to deal with window borders and making the 8 | window overlap the task bar. 9 | 10 | Note: this only works on the primary monitor. I'll add other monitor support 11 | later. 12 | 13 | * Compiling 14 | Compile the DLL using any version of Visual C++ for Windows 15 | Use the makefile - nmake 16 | copy gvimfullscreen.dll to the directory that has gvim.exe 17 | 18 | * Usage 19 | Toggle 20 | :call libcallnr("gvimfullscreen.dll", "ToggleFullScreen", 0) 21 | 22 | For example: 23 | map :call libcallnr("gvimfullscreen.dll", "ToggleFullScreen", 0) 24 | -------------------------------------------------------------------------------- /gvimfullscreen.c: -------------------------------------------------------------------------------- 1 | /* 2 | for x86 3 | cl /LD gvimfullscreen.c user32.lib Gdi32.lib 4 | for x64 5 | cl /LD /favor:INTEL64 gvimfullscreen.c user32.lib Gdi32.lib 6 | ------------------------------ 7 | .vimrc 8 | ``` 9 | function ToggleFullScreen() 10 | call libcallnr("gvimfullscreen.dll", "ToggleFullScreen", 0) 11 | endfunction 12 | map :call ToggleFullScreen() 13 | ``` 14 | */ 15 | 16 | #include 17 | 18 | #ifndef LWA_ALPHA 19 | #define LWA_ALPHA 2 20 | #endif 21 | 22 | #ifndef MONITOR_DEFAULTTONEAREST 23 | #define MONITOR_DEFAULTTONEAREST 0x00000002 24 | #endif 25 | 26 | #ifndef WS_EX_LAYERED 27 | #define WS_EX_LAYERED 0x00080000 28 | #endif 29 | 30 | int g_x, g_y, g_dx, g_dy; 31 | 32 | BOOL CALLBACK FindWindowProc(HWND hwnd, LPARAM lParam) { 33 | HWND* pphWnd = (HWND*)lParam; 34 | 35 | if (GetParent(hwnd)) { 36 | *pphWnd = NULL; 37 | return TRUE; 38 | } 39 | *pphWnd = hwnd; 40 | return FALSE; 41 | } 42 | 43 | LONG _declspec(dllexport) ToggleFullScreen() { 44 | HWND hTop = NULL; 45 | HWND hTextArea = NULL; 46 | 47 | EnumThreadWindows(GetCurrentThreadId(), FindWindowProc, (LPARAM)&hTop); 48 | hTextArea = FindWindowEx(hTop, NULL, "VimTextArea", "Vim text area"); 49 | 50 | if (hTop != NULL && hTextArea != NULL) { 51 | 52 | if ( GetWindowLong(hTop, GWL_STYLE) & WS_CAPTION ) { 53 | /* Has a caption, so isn't maximised */ 54 | 55 | MONITORINFO mi; 56 | RECT rc; 57 | HMONITOR hMonitor; 58 | long unsigned int z; 59 | char p[MAX_PATH]; 60 | HDC dc; 61 | COLORREF rgb; 62 | 63 | dc = GetDC(hTextArea); 64 | if (dc != NULL) { 65 | GetWindowRect(hTextArea, &rc); 66 | rgb = GetPixel(dc, rc.right - rc.left - 4, rc.bottom - rc.top - 4); 67 | if (rgb != CLR_INVALID) { 68 | SetDCBrushColor(dc, rgb); 69 | } 70 | ReleaseDC(hTextArea, dc); 71 | } 72 | 73 | z = (long unsigned int)IsZoomed(hTop)?1:0; 74 | if(z) { 75 | SendMessage(hTop, WM_SYSCOMMAND, SC_RESTORE, 0); 76 | } 77 | 78 | GetWindowRect(hTop, &rc); 79 | sprintf(p, "gVim_Position=%ld\t%ld\t%ld\t%ld\t%d", rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, z); 80 | putenv(p); 81 | 82 | hMonitor = MonitorFromRect(&rc, MONITOR_DEFAULTTONEAREST); 83 | 84 | // 85 | // get the work area or entire monitor rect. 86 | // 87 | mi.cbSize = sizeof(mi); 88 | GetMonitorInfo(hMonitor, &mi); 89 | 90 | g_x = mi.rcMonitor.left; 91 | g_y = mi.rcMonitor.top; 92 | g_dx = mi.rcMonitor.right - g_x; 93 | g_dy = mi.rcMonitor.bottom - g_y; 94 | 95 | /* Remove border, caption, and edges */ 96 | SetWindowLong(hTop, GWL_STYLE, GetWindowLong(hTop, GWL_EXSTYLE) & ~WS_BORDER); 97 | SetWindowLong(hTop, GWL_STYLE, GetWindowLong(hTop, GWL_STYLE) & ~WS_CAPTION); 98 | SetWindowLong(hTop, GWL_EXSTYLE, GetWindowLong(hTop, GWL_STYLE) & ~WS_EX_CLIENTEDGE); 99 | SetWindowLong(hTop, GWL_EXSTYLE, GetWindowLong(hTop, GWL_STYLE) & ~WS_EX_WINDOWEDGE); 100 | 101 | 102 | SetWindowPos(hTop, HWND_TOP, g_x, g_y, g_dx, g_dy, SWP_SHOWWINDOW); 103 | //sprintf(p, "%ld\t%ld\t%ld\t%ld", g_x, g_y, g_dx, g_dy, z); 104 | 105 | //SetWindowLong(hTextArea, GWL_EXSTYLE, GetWindowLong(hTextArea, GWL_EXSTYLE) & ~(WS_EX_DLGMODALFRAME | WS_EX_CLIENTEDGE | WS_EX_WINDOWEDGE | WS_EX_RIGHTSCROLLBAR)); 106 | 107 | /*SetWindowLong(hTextArea, GWL_EXSTYLE, GetWindowLong(hTextArea, GWL_STYLE) & ~WS_EX_CLIENTEDGE);*/ 108 | SetWindowLong(hTextArea, GWL_EXSTYLE, GetWindowLong(hTextArea, GWL_STYLE) & ~WS_EX_WINDOWEDGE); 109 | SetWindowPos(hTextArea, HWND_TOP, 0, 0, g_dx, g_dy, SWP_SHOWWINDOW); 110 | 111 | }else{ 112 | long unsigned int L, R, W, H, Z; 113 | char *p; 114 | 115 | /* Already full screen, so restore all the previous styles */ 116 | SetWindowLong(hTop, GWL_EXSTYLE, GetWindowLong(hTop, GWL_EXSTYLE) | WS_BORDER); 117 | SetWindowLong(hTop, GWL_STYLE, GetWindowLong(hTop, GWL_STYLE) | WS_CAPTION); 118 | SetWindowLong(hTop, GWL_STYLE, GetWindowLong(hTop, GWL_STYLE) | WS_SYSMENU); 119 | SetWindowLong(hTop, GWL_STYLE, GetWindowLong(hTop, GWL_STYLE) | WS_MINIMIZEBOX); 120 | SetWindowLong(hTop, GWL_STYLE, GetWindowLong(hTop, GWL_STYLE) | WS_MAXIMIZEBOX); 121 | SetWindowLong(hTop, GWL_STYLE, GetWindowLong(hTop, GWL_STYLE) | WS_SYSMENU); 122 | SetWindowLong(hTop, GWL_STYLE, GetWindowLong(hTop, GWL_STYLE) | WS_EX_CLIENTEDGE); 123 | SetWindowLong(hTop, GWL_EXSTYLE, GetWindowLong(hTop, GWL_EXSTYLE) | WS_EX_WINDOWEDGE); 124 | SetWindowLong(hTop, GWL_STYLE, GetWindowLong(hTop, GWL_STYLE) | WS_THICKFRAME); 125 | SetWindowLong(hTop, GWL_STYLE, GetWindowLong(hTop, GWL_STYLE) | WS_DLGFRAME); 126 | 127 | /*SetWindowLong(hTextArea, GWL_EXSTYLE, GetWindowLong(hTextArea, GWL_EXSTYLE) | WS_EX_CLIENTEDGE);*/ 128 | 129 | if((p = getenv("gVim_Position")) != NULL) { 130 | sscanf(p, "%ld\t%ld\t%ld\t%ld\t%d", &L, &R, &W, &H, &Z); 131 | SetWindowPos(hTop, HWND_TOP, L, R, W, H, SWP_SHOWWINDOW); 132 | if(Z) { 133 | SendMessage(hTop, WM_SYSCOMMAND, SC_MAXIMIZE, 0); 134 | } 135 | } 136 | }; 137 | 138 | #ifdef _WIN64 139 | SetClassLongPtr(hTextArea, GCLP_HBRBACKGROUND, (LONG)GetStockObject(DC_BRUSH)); 140 | #else 141 | SetClassLong(hTextArea, GCL_HBRBACKGROUND, (LONG)GetStockObject(DC_BRUSH)); 142 | #endif 143 | //MessageBox(NULL, (char *)p, "", MB_OK); 144 | } 145 | return GetLastError(); 146 | } 147 | 148 | LONG _declspec(dllexport) SetAlpha(LONG nTrans) { 149 | HWND hTop = NULL; 150 | 151 | EnumThreadWindows(GetCurrentThreadId(), FindWindowProc, (LPARAM)&hTop); 152 | 153 | if(hTop != NULL) { 154 | if(nTrans == 255) { 155 | SetWindowLong(hTop, GWL_EXSTYLE, GetWindowLong(hTop, GWL_EXSTYLE) & ~WS_EX_LAYERED); 156 | }else{ 157 | SetWindowLong(hTop, GWL_EXSTYLE, GetWindowLong(hTop, GWL_EXSTYLE) | WS_EX_LAYERED); 158 | SetLayeredWindowAttributes(hTop, 0, (BYTE)nTrans, LWA_ALPHA); 159 | } 160 | } 161 | return GetLastError(); 162 | } 163 | 164 | LONG _declspec(dllexport) EnableTopMost(LONG bEnable) { 165 | HWND hTop = NULL; 166 | DWORD dwThreadID; 167 | 168 | dwThreadID = GetCurrentThreadId(); 169 | EnumThreadWindows(dwThreadID, FindWindowProc, (LPARAM)&hTop); 170 | 171 | if(hTop) { 172 | if (bEnable == 0) { 173 | SetWindowPos(hTop, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); 174 | }else{ 175 | SetWindowPos(hTop, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); 176 | } 177 | } 178 | return GetLastError(); 179 | } 180 | 181 | // vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4: 182 | -------------------------------------------------------------------------------- /gvimfullscreen.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqin/gvimfullscreen/42ddaded3c66ba0075b1bfcfc2dd5df91b5085ac/gvimfullscreen.dll -------------------------------------------------------------------------------- /gvimfullscreen.dll.x64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xqin/gvimfullscreen/42ddaded3c66ba0075b1bfcfc2dd5df91b5085ac/gvimfullscreen.dll.x64 -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | gvimfullscreen.dll: gvimfullscreen.c 2 | cl /LD user32.lib Gdi32.lib gvimfullscreen.c 3 | 4 | clean: 5 | del *.obj 6 | del *.dll 7 | del *.exp 8 | del *.lib 9 | --------------------------------------------------------------------------------