Skip to content
This repository has been archived by the owner on Jan 9, 2019. It is now read-only.

Commit

Permalink
+now anchored to topright of XY window
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeshi committed Feb 19, 2016
1 parent 6bf8522 commit 51c9676
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 35 deletions.
86 changes: 53 additions & 33 deletions XYAHKLiveFilter.ahk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;XYAHKLiveFilter.ahk/v4.1.2/author:SammaySarkar
;XYAHKLiveFilter.ahk/v4.2.0/author:SammaySarkar
;http://xyplorer.com/xyfc/viewtopic.php?t=12588

#SingleInstance, Off ;multiple instances can run for multiple XY instances
Expand Down Expand Up @@ -33,15 +33,11 @@ OnMessage(0x02, "Destroyer") ;WM_DESTROY
;setup GUI
Gui, +HwndGUIhWnd -Border -Caption +OwnDialogs +AlwaysOnTop
Gui, Margin, 2, 1
GoSub, Sysdims ;get some system element dims for positioning
GoSub, Sysdims ;get some system element dims for correct positioning
If (SyncPos = 1) ;right-align with AB
GoSub, ABdims
Else { ;else place GUI at topleft of XY clientarea
GUIX := 1
GUIY := 1
FontName := "Segoe UI"
FontSize := 8
}
Else ;else right-align with window
GoSub, Windims
Gui, Font, s%FontSize%, %FontName%
GUI, Add, Checkbox, gCallUpdateFilter hWndGUIPausehWnd 0xc00, P ;pause checkbox
Gui, Add, Edit, y1 gCallUpdateFilter hWndGUIEdithWnd R1, "" ;the filterbox
Expand All @@ -54,12 +50,16 @@ Gui, +HwndGUIhWnd -Border -Caption +OwnDialogs +AlwaysOnTop
SendInput, {Right}{Left} ;put cursor between default quotes

;setup position
If (SyncPos = 1) { ;right align filterbox with AB
WinGetPos,,, GUIW,, ahk_id %GUIhWnd% ;get current width
GUIX := ABX + ABW - xborder - GUIW ;get real abwidth - GUIWidth
WinMove, ahk_id %GUIhWnd%,, %GUIX%, %GUIY% ;set new position
WinGetPos,,, GUIW,, ahk_id %GUIhWnd% ;get current width
If (SyncPos = 1){ ;right align filterbox with AB
GUIX := AncX + AncW - xborder - GUIW ;get real abwidth - GUIWidth
SetTimer, UpdatePosAB, 100 ;turn on the position synchronizer
}
Else {
GUIX := AncW - xborder*2 - GUIW ;get real winwidth - GUIWidth
SetTimer, UpdatePosWin, 100 ;turn on the position synchronizer
}
WinMove, ahk_id %GUIhWnd%,, %GUIX%, %GUIY% ;set new position

;setup hotkeys
If (Shortcut) { ;put this first to override any other
Expand All @@ -74,7 +74,7 @@ Hotkey, IfWinActive, ahk_id %GUIhWnd%
Return
;=== END OF AUTO-EXECUTION SECTION =============================================

;obtain necessary AddressBar attributes, called only if SyncPos=1
;obtain necessary AddressBar attributes
ABdims:
;ensure AB is visible
MsgToXy("::copydata " AHKhWnd ",get('#660'),0;setlayout('showaddressbar=1');")
Expand All @@ -83,37 +83,44 @@ ABdims:
ReceivedData := "" ;reset receiveddata
;infer AB position relative to clientarea (thanks, autocart :) )
ControlGet, XYABhWnd, Hwnd,, Edit16, ahk_id %XYhWnd%
;^Edit16 isn't a static identifier either, fingers crossed ...
ControlGetPos, ABX, ABY, ABW, ABH,, ahk_id %XYABhWnd%
GUIX := ABX + ABW - xborder ;GUIWidth is accounted for after GUI,Show
GUIY := ABY - yborder - CaptionH - MenuH - ABPadding
FontName := GetFont(XYABhWnd) ;get fontname of AB
FontSize := A_LastError ;get fontsize of AB
ControlGetPos, AncX, AncY, AncW, AncH,, ahk_id %XYABhWnd%
GUIX := AncX + AncW - xborder ;GUIWidth is accounted for after GUI,Show
GUIY := AncY - yborder - CaptionH - MenuH - ABPadding
FontName := GetFont(XYABhWnd) ;get fontname of AB
FontSize := A_LastError ;get fontsize of AB
Return
;obtain necessary XY Window attributes
Windims:
WinGetPos,,, AncW,, ahk_id %XYhWnd%
GUIX := AncW - xborder*2 ;GUIWidth is accounted for after GUI,Show
GUIY := 1 ;no need for dynamic Y pos
FontName := GetFont(XYhWnd) ;get fontname of win
FontSize := A_LastError ;get fontsize of win
Return
;obtain some system dimension attributes
Sysdims:
;correct positioning takes some system gui elems into account
SysGet, CaptionH, 4
SysGet, MenuH, 15
SysGet, xborder, 32
SysGet, yborder, 33
SysGet, CaptionH, 4
SysGet, MenuH, 15
Return

;update filterbox position to match AB. Called by timer
UpdatePosAB:
If WinActive("ahk_id" XYhWnd) { ;update position only while XY is active
If WinActive("ahk_id" XYhWnd) { ;update position only while XY is active
ControlGet, ABvis, Visible,,, ahk_id %XYABhWnd% ;get AB visiblity
If (ABvis = 0) ;if AB is hidden
MsgToXY("::setlayout('showaddressbar=1')") ;unhide AB while running
PABP = %ABX% %ABY% %ABH% %ABW% ;previous AB dims
PABH = %ABH% ;previous AB H
ControlGetPos, ABX, ABY, ABW, ABH,, ahk_id %XYABhWnd%
CABP = %ABX% %ABY% %ABH% %ABW% ;current AB dims
CABH = %ABH% ;current AB H
If (PABP != CABP) { ;AB position changed, sync with new position
GUIX := ABX + ABW - xborder - GUIW
GUIY := ABY - yborder - CaptionH - MenuH - ABPadding
GUIH := ABH + ABPadding
If (PABH <> CABH) { ;AB height change = font change
PAncA = %AncX% %AncY% %AncH% %AncW% ;previous AB dims
PAncB = %AncH% ;previous AB H
ControlGetPos, AncX, AncY, AncW, AncH,, ahk_id %XYABhWnd%
CAncA = %AncX% %AncY% %AncH% %AncW% ;current AB dims
CAncB = %AncH% ;current AB H
If (PAncA != CAncA) { ;AB pos change = sync new pos
GUIX := AncX + AncW - xborder - GUIW
GUIY := AncY - yborder - CaptionH - MenuH - ABPadding
GUIH := AncH + ABPadding
If (PAncB <> CAncB) { ;AB H change = font change
FontName := GetFont(XYABhWnd) ;get new fontname
FontSize := A_LastError ;get new fontsize
Gui, Font, s%FontSize%, %FontName% ;set new font
Expand All @@ -126,6 +133,19 @@ UpdatePosAB:
}
}
Return
;update filterbox position to match Window. Called by timer
UpdatePosWin:
If WinActive("ahk_id" XYhWnd) { ;update position only while XY is active
PAncA = %AncW% ;previous win W
WinGetPos,,, AncW,, ahk_id %XYhWnd%
CAncA = %AncW% ;current win W
If (PAncA != CAncA) { ;Win W change = sync new pos
GUIX := AncW - xborder*2 - GUIW
GUIY := 1
WinMove, ahk_id %GUIhWnd%,, %GUIX%, %GUIY% ;set new position
}
}
Return

;triggered by filterbox or Pause chkbox change.
CallUpdateFilter:
Expand Down
2 changes: 1 addition & 1 deletion XYAHKLiveFilter.xys
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//XYAHKLiveFilter.ahk/v4.1.2//author:SammaySarkar
//XYAHKLiveFilter.xys/v4.2.0//author:SammaySarkar
//http://xyplorer.com/xyfc/viewtopic.php?&t=12588

perm $p_XYAHKLiveFilter_A, $p_XYAHKLiveFilter_B;
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Some options may be modified in the XYscript.
It follows [Authotkey's hotkey definition syntax](https://autohotkey.com/docs/Hotkeys.htm).
* `$SyncToAB`: if `$SyncToAB` is 1, the filterbox is positioned over right edge the of the addressbar.
This also forces the AB to stay visible as long as livefilter is running, and reverts back to last state when the filter is closed.<br/>
If `$SyncToAB` is not 1, then the filterbox is positioned at the _topleft_ of XY, and does not try to modify AB visibility.
If `$SyncToAB` is not 1, then the filterbox is pops up and stays at the _topright_ of XY, and does not try to modify AB visibility.
* `$ABPadding`: Adjust this value only if the filterbox doesn't horizontal-align exactly with the addressbar.<br/>
The value should be a (small) integer: 0,3,-2 etc.<br/>
The filterbox moves up/down this many pixels. Only effective when `$SyncToAB = 1`.
Expand Down

0 comments on commit 51c9676

Please sign in to comment.