Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Restore window position/size on leaving full-screen

This fixes issue #2 reported by dionysiac- on GitHub
  • Loading branch information...
commit 681404594304bfa6a0526df23d41bb1833acba6d 1 parent 669a9f2
Peter Odding authored December 18, 2010

Showing 2 changed files with 24 additions and 9 deletions. Show diff stats Hide diff stats

  1. 29  autoload.vim
  2. 4  shell.vim
29  autoload.vim
... ...
@@ -1,6 +1,6 @@
1 1
 " Vim auto-load script
2 2
 " Author: Peter Odding <peter@peterodding.com>
3  
-" Last Change: December 4, 2010
  3
+" Last Change: December 18, 2010
4 4
 " URL: http://peterodding.com/code/vim/shell/
5 5
 
6 6
 if !exists('s:script')
@@ -136,12 +136,16 @@ endfunction
136 136
 
137 137
 function! xolox#shell#fullscreen() " -- toggle Vim between normal and full-screen mode {{{1
138 138
 
139  
-  " TODO Wrap in try/catch block with xolox#warning() feedback?
140  
-
141  
-  " On entering full-screen hide GUI components like the main menu, tool bar
142  
-  " and tab line. Remember which components were actually hidden and should be
143  
-  " restored when leaving full-screen later.
  139
+  " When entering full-screen...
144 140
   if !s:fullscreen_enabled
  141
+    " Save the window position and size when running Windows, because my
  142
+    " dynamic link library doesn't save/restore them while "wmctrl" does.
  143
+    if xolox#is_windows()
  144
+      let [s:lines_save, s:columns_save] = [&lines, &columns]
  145
+      let [s:winpos_x_save, s:winpos_y_save] = [getwinposx(), getwinposy()]
  146
+    endif
  147
+    " Hide the main menu, tool bar and/or tab line. Remember what was hidden
  148
+    " so its visibility can be restored when the user leaves full-screen.
145 149
     let s:go_toggled = ''
146 150
     for item in split(g:shell_fullscreen_items, '.\zs')
147 151
       if &go =~# item
@@ -177,13 +181,22 @@ function! xolox#shell#fullscreen() " -- toggle Vim between normal and full-scree
177 181
     call xolox#warning("%s: %s at %s", s:script, v:exception, v:throwpoint)
178 182
   endtry
179 183
 
180  
-  " On leaving full-screen restore display of previously hidden GUI components?
  184
+  " When leaving full-screen...
181 185
   if s:fullscreen_enabled
  186
+    " Restore display of previously hidden GUI components?
182 187
     let &go .= s:go_toggled
183 188
     if exists('s:stal_save')
184 189
       let &stal = s:stal_save
185 190
       unlet s:stal_save
186 191
     endif
  192
+    unlet s:go_toggled
  193
+    " Restore window position and size only on Windows -- I don't know why
  194
+    " but the following actually breaks when running under "wmctrl"...
  195
+    if xolox#is_windows()
  196
+      let [&lines, &columns] = [s:lines_save, s:columns_save]
  197
+      execute 'winpos' s:winpos_x_save s:winpos_y_save
  198
+      unlet s:lines_save s:columns_save s:winpos_x_save s:winpos_y_save
  199
+    endif
187 200
   endif
188 201
 
189 202
   " Toggle the boolean status returned by xolox#shell#is_fullscreen().
@@ -191,6 +204,8 @@ function! xolox#shell#fullscreen() " -- toggle Vim between normal and full-scree
191 204
 
192 205
   " Let the user know how to leave full-screen mode?
193 206
   if s:fullscreen_enabled
  207
+    " Take a moment to let Vim's GUI finish redrawing (:redraw is
  208
+    " useless here because it only redraws Vim's internal state).
194 209
     sleep 50 m
195 210
     call xolox#message("To return from full-screen type <F11> or execute :Fullscreen.")
196 211
   endif
4  shell.vim
... ...
@@ -1,9 +1,9 @@
1 1
 " Vim plug-in
2 2
 " Author: Peter Odding <peter@peterodding.com>
3  
-" Last Change: December 1, 2010
  3
+" Last Change: December 18, 2010
4 4
 " URL: http://peterodding.com/code/vim/shell/
5 5
 " License: MIT
6  
-" Version: 0.9
  6
+" Version: 0.9.1
7 7
 
8 8
 " Support for automatic update using the GLVS plug-in.
9 9
 " GetLatestVimScripts: 3123 1 :AutoInstall: shell.zip

0 notes on commit 6814045

Please sign in to comment.
Something went wrong with that request. Please try again.