Loading ...
Sorry, an error occurred while loading the content.

(fwd) Patch for mac-specific bug in :winpos

Expand Messages
  • Bram Moolenaar
    [forwarding from the vim-dev list] Date: Sat, 18 Aug 2007 18:29:54 -0400 From: Michael Henry To: vim-dev Subject: Patch
    Message 1 of 1 , Aug 19, 2007
      [forwarding from the vim-dev list]

      Date: Sat, 18 Aug 2007 18:29:54 -0400
      From: Michael Henry <vim@...>
      To: vim-dev <vim-dev@...>
      Subject: Patch for mac-specific bug in :winpos
      Reply-To: vim_dev@...


      The mac port of gvim has a bug in the implementation of :winpos.

      Version: 7.1.82 (mac only)


      The following command, which should do nothing, causes gvim's window
      to move up the screen on the mac:

      exe "winpos " . getwinposx() . " " . getwinpoxy()

      On Linux and Windows, the above command correctly does nothing[1].

      The problem stems from a mis-matched pair of function calls in
      src/gui_mac.c. Vim implements the getwinposx() and getwinposy()
      functions in terms of a port-specific function gui_mch_get_winpos().
      In gui_mac.c, this function makes this call[2]:

      GetWindowBounds(gui.VimWindow, kWindowStructureRgn, &bounds);

      The constant kWindowStructureRegion requests coordinates relative
      to the outer bounds of the window.

      The implementation of `:winpos x y` calls the port-specific function
      gui_mch_set_winpos(). In gui_mac.c, this function make this call[3]:

      MoveWindow(gui.VimWindow, x, y, TRUE);

      The coordinates of MoveWindow() are relative to the content area inside
      the window; this content area is shifted down a distance equal to the
      height of the title bar. The mis-match between the two system calls
      results in a vertical shift of the window in the example given above.

      The attached patch fixes this problem by using the MoveWindowStructure()
      function[4], whose coordinates are compatible with those used for the
      GetWindowBounds() function.

      Michael Henry

      [1]: For the curious non-mac user: The bug may be simulated on a
      correctly operating gvim using this command:

      exe "winpos " . getwinposx() . " " . (getwinpoxy() - 22)


      [3]: http://developer.apple.com/documentation/mac/Toolbox/Toolbox-246.html


      -------- begin patch ------------

      --- src/gui_mac.c.orig 2007-08-18 17:24:21.000000000 -0400
      +++ src/gui_mac.c 2007-08-18 17:56:07.000000000 -0400
      @@ -3149,7 +3149,7 @@
      /* TODO: Should make sure the window is move within range
      * e.g.: y > ~16 [Menu bar], x > 0, x < screen width
      - MoveWindow(gui.VimWindow, x, y, TRUE);
      + MoveWindowStructure(gui.VimWindow, x, y);


      You received this message from the "vim_mac" maillist.
      For more information, visit http://www.vim.org/maillist.php
    Your message has been successfully submitted and would be delivered to recipients shortly.