topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Tuesday November 5, 2024, 10:55 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Trying to make WindowWidth center on cursor  (Read 10600 times)

Expletive

  • Participant
  • Joined in 2013
  • *
  • Posts: 7
    • View Profile
    • Donate to Member
Trying to make WindowWidth center on cursor
« on: February 18, 2013, 06:48 AM »
I'm trying to change it so that when WindowWidth or WindowHeight are used in a grid file, the window is positioned so that the cursor is at the center of the grid's top edge. Since WindowWidth and WindowHeight can't be operated on like [MonitorXWidth] etc, I figured I have to edit gridmove's source, after digging around in the assortment of .ahk files, I've found only a couple of references to them, so I'm assuming their what I'd have to change. I'm just fuzzy on how. The code I found was:

Code: Autohotkey [Select]
  1. ;Line 206 of Command.ahk
  2.   If (GridLeft = "WindowWidth" AND GridRight = "WindowWidth")
  3.   {
  4.     WinGetClass,WinClass,A
  5.  
  6.     if ShouldUseSizeMoveMessage(WinClass)
  7.       SendMessage WM_ENTERSIZEMOVE, , , ,ahk_id %windowid%
  8.  
  9.     WinMove, A, ,%WinLeft%,%GridTop%, %WinWidth%,% GridBottom - GridTop,    
  10.  
  11.     if ShouldUseSizeMoveMessage(WinClass)
  12.       SendMessage WM_EXITSIZEMOVE, , , ,ahk_id %windowid%
  13.     StoreWindowState(WindowId,WinLeft,WinTop,WinWidth,WinHeight)
  14.     return
  15.   }
  16.   If (GridTop = "WindowHeight" AND GridBottom = "WindowHeight")
  17.   {
  18.     WinGetClass,WinClass,A
  19.  
  20.     if ShouldUseSizeMoveMessage(WinClass)
  21.       SendMessage WM_ENTERSIZEMOVE, , , ,ahk_id %windowid%
  22.  
  23.     WinMove, A, ,%GridLeft%,%WinTop%, % GridRight - GridLeft,%WinHeight%,    
  24.  
  25.     if ShouldUseSizeMoveMessage(WinClass)
  26.       SendMessage WM_EXITSIZEMOVE, , , ,ahk_id %windowid%
  27.     StoreWindowState(WindowId,WinLeft,WinTop,WinWidth,WinHeight)
  28.     return
  29.   }
  30.  
  31. ;line 849 of GridMoveP1.ahk
  32.  
  33.     If ShowNumbersFlag
  34.     {
  35.       If (GridTop = "WindowHeight" OR GridLeft = "WindowWidth")
  36.       {
  37.         Gui, add, text,c%shadowcolor% BackGroundTrans  X%ShadowLeft% Y%ShadowTop% ,%A_Index%
  38.         Gui, add, text,c%textcolor% BackGroundTrans  X%TextLeft% Y%TextTop% ,%A_Index%
  39.       }

Also, I'm realizing the Gridmove I've been using for years is now apparently 9 versions out of date. From 19.62 to 19.71. I really like the Aero effects, but I'm not so sure about the new icon. I may just be too set in my ways.

jgpaiva

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Donate to Member
Re: Trying to make WindowWidth center on cursor
« Reply #1 on: February 18, 2013, 07:27 AM »
I'm sorry, but I really can't understand what you want to do :(

Could you try explaining in another way?

(The last lines - from 30 do 39 - only have to do with drawing the grid, so you should ignore those)

Expletive

  • Participant
  • Joined in 2013
  • *
  • Posts: 7
    • View Profile
    • Donate to Member
Re: Trying to make WindowWidth center on cursor
« Reply #2 on: February 18, 2013, 09:39 AM »
Here's a visual aid:


Grid 8, the one at the top:
Code: Text [Select]
  1. [8]
  2.         TriggerTop              = [Monitor3Top]
  3.         TriggerBottom   = [Monitor3Top] + [Monitor3Height] / 30
  4.         TriggerLeft             = [Monitor3Left]
  5.         TriggerRight    = [Monitor3Right]
  6.         GridTop                 = [Monitor3Top]
  7.         GridBottom              = [Monitor3Bottom]
  8.         GridLeft                = WindowWidth
  9.         GridRight               = WindowWidth

In the image I am holding MButton and dragging the notepad to the top of the window. See how the grid moves with the left edge attached to the mouse cursor? I want to change it so that instead of the current behavior, the window aligns the center to the cursor, such as in the following visual mockup:


jgpaiva

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Donate to Member
Re: Trying to make WindowWidth center on cursor
« Reply #3 on: February 19, 2013, 09:45 AM »
Ah! Indeed that makes sense :)
Ok, so what you're looking for is in GridMoveP1, lines 685-701:

  If GridTop = WindowHeight
  {
    MonitorBottom := GetMonitorBottom(MouseX, MouseY)
    GridTop := MouseY       
    If (GridTop + WinHeight > MonitorBottom)
      GridTop := MonitorBottom - WinHeight
    GridBottom := GridTop + WinHeight
  }
   
  If GridLeft = WindowWidth
  {
    MonitorRight := GetMonitorRight(MouseX, MouseY)
    GridLeft := MouseX
    If (GridLeft + WinWidth > MonitorRight)
      GridLeft := MonitorRight - WinWidth
    GridRight := GridLeft + WinWidth       
  }   

And you should replace it with:

  If GridTop = WindowHeight
  {
    MonitorBottom := GetMonitorBottom(MouseX, MouseY)
    MonitorTop := GetMonitorTop(MouseX, MouseY)
    GridTop := MouseY - 0.5 * WinHeight
    If (GridTop + 0.5 * WinHeight > MonitorBottom)
      GridTop := MonitorBottom - WinHeight
    If (GridTop - 0.5 * WinHeight < MonitorTop)
      GridTop := MonitorTop
    GridBottom := GridTop + WinHeight
  }
   
  If GridLeft = WindowWidth
  {
    MonitorRight := GetMonitorRight(MouseX, MouseY)
    MonitorLeft := GetMonitorLeft(MouseX, MouseY)
    GridLeft := MouseX - 0.5 * WinWidth
    If (GridLeft + 0.5 * WinWidth > MonitorRight)
      GridLeft := MonitorRight - WinWidth
    If (GridLeft - 0.5 * WinWidth < MonitorLeft)
      GridLeft := MonitorLeft
    GridRight := GridLeft + WinWidth       
  } 



I'm really sorry that I can't neither test nor generate a compiled version of GridMove for you (I now only own macs, unfortunately :( ), but I hope this helps.

Expletive

  • Participant
  • Joined in 2013
  • *
  • Posts: 7
    • View Profile
    • Donate to Member
Re: Trying to make WindowWidth center on cursor
« Reply #4 on: February 19, 2013, 11:11 AM »
It's working! Thank. But now it doesn't snap to the edges of the Monitor like it used to. In these images the Notepad++ window is maximized on the next monitor over.

Old:  http://i.imgur.com/hPejoGA.jpg

New code: http://i.imgur.com/RVUoQZh.jpg

Is it possible to make it limit the positions of the edges to the edges of the grid, while still trying to center itself on your mouse?


jgpaiva

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Donate to Member
Re: Trying to make WindowWidth center on cursor
« Reply #5 on: February 19, 2013, 06:16 PM »
Sorry, bad math on my part. This line:
If (GridTop + 0.5 * WinHeight > MonitorBottom)
Should be like this:
If (GridTop + 1.5 * WinHeight > MonitorBottom)
Also, do the same on every other line similar to that one (all those that have the comparisons).
« Last Edit: February 20, 2013, 04:55 AM by jgpaiva, Reason: wrong code »

jgpaiva

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Donate to Member
Re: Trying to make WindowWidth center on cursor
« Reply #6 on: February 20, 2013, 04:56 AM »
I'm sorry, I was probably sleeping when I did the code above.

This version should fix all the problems:
  If GridTop = WindowHeight
  {
    MonitorBottom := GetMonitorBottom(MouseX, MouseY)
    MonitorTop := GetMonitorTop(MouseX, MouseY)
    GridTop := MouseY - 0.5 * WinHeight
    If (GridTop + WinHeight > MonitorBottom)
      GridTop := MonitorBottom - WinHeight
    If (GridTop < MonitorTop)
      GridTop := MonitorTop
    GridBottom := GridTop + WinHeight
  }
   
  If GridLeft = WindowWidth
  {
    MonitorRight := GetMonitorRight(MouseX, MouseY)
    MonitorLeft := GetMonitorLeft(MouseX, MouseY)
    GridLeft := MouseX - 0.5 * WinWidth
    If (GridLeft + WinWidth > MonitorRight)
      GridLeft := MonitorRight - WinWidth
    If (GridLeft < MonitorLeft)
      GridLeft := MonitorLeft
    GridRight := GridLeft + WinWidth       
  }