AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Window Management: KDE-like resizing & dragging + some m
Goto page 1, 2  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
aurelian
Guest





PostPosted: Tue Jan 25, 2005 4:50 pm    Post subject: Window Management: KDE-like resizing & dragging + some m Reply with quote

Hi out there,

I discovered AHK few days ago, but I am already amazed how mighty this handy little tool is. Here is part of my Init script that I thought you might be interested in. I know such stuff has been posted before, but maybe you want to give it a try. Smile

Code:

; Smart Window Management Script

; This script is based on the Easy Window Dragging Script in the Showcase
; (http://www.autohotkey.com/docs/scripts/EasyWindowDrag.htm),
; but goes much further. Of course you are free to change the combinations to
; anything you like.
;
; Author: Johannes Loehnert
; Contact: a.u.r.e.l.i.a.n@gmx.net
; Last Change: 2005-01-25
; AHK version: 1.0.25
;
; The script establishes the following combinations:
; - Lwin  + LB: Hold and drag to move window
; - TB    + LB: same
; - Lwin  + RB: Hold and drag to resize window (resize corner which is closest to cursor)
; - TB    + RB: same
; - LCtrl + LWin + LB: Minimize window
; - LCtr  + LWin + RB: Close Window
; - TB    + MB: click to minimize window, hold for 0.5 sec to close window
; All commands apply to the window under the mouse cursor.
; Abbreviations: LB, MB, RB, TB = left, middle, right, thumb button of mouse.
;
; Flaws so far:
;  - Thumb button stops working in normal way; disable TB combinations if you need.
;  - Code might be prettier :-)


;Minimize Window; when held over 0.5 sec: close window
XButton2 & MButton::     
CoordMode, Mouse
MouseGetPos, SWM_MouseStartX, SWM_MouseStartY, SWM_MouseWin
SetTimer, SMW_MidButtonClose, 500   ;<-- TIMER FOR TB+MB CLOSE
SMW_MidButtonCloseTimer=1
loop
{
   GetKeyState, SMW_MButtonState, MButton, P
   if SMW_MidButtonCloseTimer=0
      return
   if SMW_MButtonState=U
   {
      SetTimer, SMW_MidButtonClose, Off
      WinMinimize, ahk_id %SWM_MouseWin%
      SMW_MidButtonCloseTimer=0
      return
   }
}


SMW_MidButtonClose:
SMW_MidButtonCloseTimer=0
SetTimer, SMW_MidButtonClose, Off
WinClose, ahk_id %SWM_MouseWin%
return

; Move window on Lwin+LB or TB+LB; minimize window on LCtrl+Lwin+LB or LCtrl+TB+LB
XButton2 & LButton::
LWin & LBUtton::
CoordMode, Mouse  ; Switch to screen/absolute coordinates.
MouseGetPos, SWM_MouseStartX, SWM_MouseStartY, SWM_MouseWin
GetKeyState, SMW_LCtrlState, LCtrl
if SMW_LCtrlState=D
   WinMinimize, ahk_id %SWM_MouseWin%
else
   SetTimer, SWM_WatchMouse_Move, 10 ; Track the mouse as the user drags it.
return

; resize window on Lwin+RB or TB+RB; minimize window on LCtrl+Lwin+RB or LCtrl+TB+RB
XButton2 & RButton:: ;resize or close
LWin & RButton::
CoordMode, Mouse  ; Switch to screen/absolute coordinates.
MouseGetPos, SWM_MouseStartX, SWM_MouseStartY, SWM_MouseWin
WinGetPos, SWM_WinX, SWM_WinY, SWM_WinW, SWM_WinH, ahk_id %SWM_MouseWin%
GetKeyState, SMW_LCtrlState, LCtrl
if SMW_LCtrlState=D
{
   WinClose, ahk_id %SWM_MouseWin%
   return
}   
SWM_ResizeTypeX=0
SWM_ResizeTypeY=0
if (SWM_MouseStartX < SWM_WinX+SWM_WinW/2)
   SWM_ResizeTypeX=1
if (SWM_MouseStartY < SWM_WinY+SWM_WinH/2)
   SWM_ResizeTypeY=1
SetTimer, SWM_WatchMouse_Resize, 10 ; Track the mouse as the user drags it.
return


SWM_WatchMouse_Move:
GetKeyState, SMW_LButtonState, LButton, P

if SMW_LButtonState = U ; Button has been released, so drag is complete.
{
   SetTimer, SWM_WatchMouse_Move, off
   return
}
; Otherwise, reposition the window to match the change in mouse coordinates
; caused by the user having dragged the mouse:
CoordMode, Mouse
MouseGetPos, SWM_MouseX, SWM_MouseY
SWM_DeltaX = %SWM_MouseX%
SWM_DeltaX -= %SWM_MouseStartX%
SWM_DeltaY = %SWM_MouseY%
SWM_DeltaY -= %SWM_MouseStartY%
SWM_MouseStartX = %SWM_MouseX%  ; Update for the next timer call to this subroutine.
SWM_MouseStartY = %SWM_MouseY%
WinGetPos, SWM_WinX, SWM_WinY,,, ahk_id %SWM_MouseWin%
SWM_WinX += %SWM_DeltaX%
SWM_WinY += %SWM_DeltaY%
SetWinDelay, -1   ; Makes the below move faster/smoother.
WinMove, ahk_id %SWM_MouseWin%,, %SWM_WinX%, %SWM_WinY%
return


SWM_WatchMouse_Resize:
GetKeyState, SMW_RButtonState, RButton, P

if SMW_RButtonState = U ; Button has been released, so drag is complete.
{
   SetTimer, SWM_WatchMouse_Resize, off
   return
}
; Otherwise, resize the window to match the change in mouse coordinates
; caused by the user having dragged the mouse:
CoordMode, Mouse
MouseGetPos, SWM_MouseX, SWM_MouseY
SWM_DeltaX = %SWM_MouseX%
SWM_DeltaX -= %SWM_MouseStartX%
SWM_DeltaY = %SWM_MouseY%
SWM_DeltaY -= %SWM_MouseStartY%
SWM_MouseStartX = %SWM_MouseX%  ; Update for the next timer call to this subroutine.
SWM_MouseStartY = %SWM_MouseY%
WinGetPos, SWM_WinX, SWM_WinY, SWM_WinW, SWM_WinH, ahk_id %SWM_MouseWin%
if SWM_ResizeTypeX
{
   SWM_WinX += %SWM_DeltaX%
   SWM_WinW -= %SWM_DeltaX%
}
else
   SWM_WinW += %SWM_DeltaX%
if SWM_ResizeTypeY
{
   SWM_WinY += %SWM_DeltaY%
   SWM_WinH -= %SWM_DeltaY%
}
else
   SWM_WinH += %SWM_DeltaY%
SetWinDelay, -1   ; Makes the below move faster/smoother.
WinMove, ahk_id %SWM_MouseWin%,, %SWM_WinX%, %SWM_WinY%, %SWM_WinW%, %SWM_WinH%
return

; End of Smart Window Management Script


Hope somebody may find it helpful, and looking forward to feedback Smile

cu, aurelian
Back to top
aurelian



Joined: 25 Jan 2005
Posts: 3
Location: Germany / Dresden

PostPosted: Tue Jan 25, 2005 6:38 pm    Post subject: Reply with quote

I am registered now! *wide smile*

Adding the following to the code:
Code:

~XButton2::
return

seems to fix the problem with the thumb button. Smile

Also, note that the move & resize functionality does not work with WinAmp (at least not with version 5.05).

-aurelian
Back to top
View user's profile Send private message
BoBo
Guest





PostPosted: Tue Jan 25, 2005 6:58 pm    Post subject: Reply with quote

@ aurelian (Johannes)
Einer ist immer der Erste! Könntest du deinem Script noch eine deutschsprachige kurze Beschreibung (der übliche längere Satz) voranstellen/hinzufügen ? Chris ist bereits aufgefallen, das der Anteil der deutschsprachigen AHK-User ständig zunimmt, könnte also helfen.

Danke und Gruß nach DD Hellerau, Prolis, Lockwitz, ... ? Wink
Back to top
Nemroth



Joined: 07 Sep 2004
Posts: 272
Location: France

PostPosted: Tue Jan 25, 2005 7:12 pm    Post subject: Reply with quote

En allemand dans le texte... Very Happy
Back to top
View user's profile Send private message
jonny



Joined: 13 Nov 2004
Posts: 2951
Location: Minnesota

PostPosted: Tue Jan 25, 2005 7:40 pm    Post subject: Reply with quote

I've lost count of how many scripts there are to emulate KDE's window moving/resizing. At least three I know of. Pretty handy to have. Wink
Back to top
View user's profile Send private message
aurelian



Joined: 25 Jan 2005
Posts: 3
Location: Germany / Dresden

PostPosted: Tue Jan 25, 2005 7:54 pm    Post subject: Reply with quote

Klar, mach ich doch gern. Leider kann ich den Beitrag oben nicht editieren, deswegen stell ichs hier noch mal in voller Pracht zum rauskopieren hin. Habe gleich mal noch etwas reduntanten Code entfernt.

Dresden-Pillnitz Smile
~
Sure, no problem. Unfortunately I can not edit the first post, so I'll paste the whole thing once again. Also I removed some reduntant code.

Code:
; Smart Window Management Script
;
; Erlaubt es, Fenster auf komfortable Weise zu bewegen, zu vergroessern /
; verkleinern, zu minimieren und zu schliessen. Das Skript basiert auf dem
; Easy Window Dragging Script im Showcase
; (http://www.autohotkey.com/docs/scripts/EasyWindowDrag.htm).
; Definierte Tastenkombinationen siehe unten.
; ~
; Allows window moving, resizing, minimizing and closing in a very comfortable
; manner. This script is based on the Easy Window Dragging Script in the
; Showcase (Link above).
;
; Author     : Johannes Loehnert
; Contact    : a.u.r.e.l.i.a.n@gmx.net
; Last Change: 2005-01-25
; AHK version: 1.0.25
;
; Folgende Tastenkombinationen werden definiert:
; The script establishes the following combinations:
;
; - LWin  + LB: Hold and drag to move window / Halten und ziehen, um Fenster zu verschieben
; - TB    + LB: same / gleich
; - Lwin  + RB: Hold and drag to resize window (resize corner which is closest to cursor) /
;               Halten und ziehen, um Groesse zu aendern.
; - TB    + RB: same / gleich
; - LCtrl + LWin + LB: Minimize window / Fenster minimieren
; - LCtr  + LWin + RB: Close Window / Fenster schliessen
; - TB    + MB: click to minimize window, hold for 0.5 sec to close window /
;               nur klicken, um Fenster zu minimieren; 0.5 sec halten, um Fenster zu schliessen.
;
; All commands apply to the window under the mouse cursor.
; Abbreviations: LB, MB, RB, TB = left, middle, right, thumb button of mouse.
;
; Alle Kombinationen wirken auf das Fenster, in welchem die Maus sich befindet.
; Abkuerzungen: LB, MB, RB, TB: linke, mittlere, rechte, Daumen-Taste der Maus.


; pass through single clicks of thumb button
~XButton2::
return


;Minimize Window; when held over 0.5 sec: close window
XButton2 & MButton::     
CoordMode, Mouse
MouseGetPos, SWM_MouseStartX, SWM_MouseStartY, SWM_MouseWin
SetTimer, SMW_MidButtonClose, 500   ;<-- TIMER FOR TB+MB CLOSE
SMW_MidButtonCloseTimer=1
loop
{
   GetKeyState, SMW_MButtonState, MButton, P
   if SMW_MidButtonCloseTimer=0
      return
   if SMW_MButtonState=U
   {
      SetTimer, SMW_MidButtonClose, Off
      WinMinimize, ahk_id %SWM_MouseWin%
      SMW_MidButtonCloseTimer=0
      return
   }
}


SMW_MidButtonClose:
SMW_MidButtonCloseTimer=0
SetTimer, SMW_MidButtonClose, Off
WinClose, ahk_id %SWM_MouseWin%
return


; Move window on Lwin+LB or TB+LB; minimize window on LCtrl+Lwin+LB or LCtrl+TB+LB
XButton2 & LButton::
LWin & LBUtton::
CoordMode, Mouse  ; Switch to screen/absolute coordinates.
MouseGetPos, SWM_MouseStartX, SWM_MouseStartY, SWM_MouseWin
GetKeyState, SMW_LCtrlState, LCtrl
if SMW_LCtrlState=D
   WinMinimize, ahk_id %SWM_MouseWin%
else
   SetTimer, SWM_WatchMouse_Move, 10 ; Track the mouse as the user drags it.
return


; resize window on Lwin+RB or TB+RB; minimize window on LCtrl+Lwin+RB or LCtrl+TB+RB
XButton2 & RButton:: ;resize or close
LWin & RButton::
CoordMode, Mouse  ; Switch to screen/absolute coordinates.
MouseGetPos, SWM_MouseStartX, SWM_MouseStartY, SWM_MouseWin
WinGetPos, SWM_WinX, SWM_WinY, SWM_WinW, SWM_WinH, ahk_id %SWM_MouseWin%
GetKeyState, SMW_LCtrlState, LCtrl
if SMW_LCtrlState=D
{
   WinClose, ahk_id %SWM_MouseWin%
   return
}   
SWM_ResizeTypeX=0
SWM_ResizeTypeY=0
if (SWM_MouseStartX < SWM_WinX+SWM_WinW/2)
   SWM_ResizeTypeX=1
if (SWM_MouseStartY < SWM_WinY+SWM_WinH/2)
   SWM_ResizeTypeY=1
SetTimer, SWM_WatchMouse_Resize, 10 ; Track the mouse as the user drags it.
return


SWM_WatchMouse_Move:
GetKeyState, SMW_LButtonState, LButton, P
if SMW_LButtonState = U ; Button has been released, so drag is complete.
{
   SetTimer, SWM_WatchMouse_Move, off
   return
}
Gosub SWM_GetMouseAndWindowPos
SWM_WinX += %SWM_DeltaX%
SWM_WinY += %SWM_DeltaY%
SetWinDelay, -1   ; Makes the below move faster/smoother.
WinMove, ahk_id %SWM_MouseWin%,, %SWM_WinX%, %SWM_WinY%
return


SWM_WatchMouse_Resize:
GetKeyState, SMW_RButtonState, RButton, P
if SMW_RButtonState = U ; Button has been released, so drag is complete.
{
   SetTimer, SWM_WatchMouse_Resize, off
   return
}
Gosub SWM_GetMouseAndWindowPos
if SWM_ResizeTypeX
{
   SWM_WinX += %SWM_DeltaX%
   SWM_WinW -= %SWM_DeltaX%
}
else
   SWM_WinW += %SWM_DeltaX%
if SWM_ResizeTypeY
{
   SWM_WinY += %SWM_DeltaY%
   SWM_WinH -= %SWM_DeltaY%
}
else
   SWM_WinH += %SWM_DeltaY%
SetWinDelay, -1   ; Makes the below move faster/smoother.
WinMove, ahk_id %SWM_MouseWin%,, %SWM_WinX%, %SWM_WinY%, %SWM_WinW%, %SWM_WinH%
return


SWM_GetMouseAndWindowPos:
CoordMode, Mouse
MouseGetPos, SWM_MouseX, SWM_MouseY
SWM_DeltaX = %SWM_MouseX%
SWM_DeltaX -= %SWM_MouseStartX%
SWM_DeltaY = %SWM_MouseY%
SWM_DeltaY -= %SWM_MouseStartY%
SWM_MouseStartX = %SWM_MouseX%  ; Update for the next timer call to this subroutine.
SWM_MouseStartY = %SWM_MouseY%
WinGetPos, SWM_WinX, SWM_WinY, SWM_WinW, SWM_WinH, ahk_id %SWM_MouseWin%
return

; End of Smart Window Management Script
Back to top
View user's profile Send private message
BoBo
Guest





PostPosted: Tue Jan 25, 2005 8:05 pm    Post subject: Reply with quote

Danke. Thx. Merci. Very Happy
Back to top
Guest






PostPosted: Tue Jan 25, 2005 9:06 pm    Post subject: Reply with quote

@BoBo
De rien. De nada. It was my pleasure. Sorry, in German I know only one word : kartoffel (and that's (almost) true...)
Back to top
Nemroth



Joined: 07 Sep 2004
Posts: 272
Location: France

PostPosted: Tue Jan 25, 2005 9:13 pm    Post subject: Reply with quote

The precedent post was mine...
Back to top
View user's profile Send private message
BoBo
Guest





PostPosted: Tue Jan 25, 2005 9:33 pm    Post subject: Reply with quote

Kartoffel = pomme de terre. Tres bien, mon amie Wink
Eh, j'ai ne parle pas francais Rolling Eyes
Back to top
BoBo
Guest





PostPosted: Tue Jan 25, 2005 9:38 pm    Post subject: Reply with quote

Je ne parle pas francais (c'est correct, oui ?)
Back to top
jonny



Joined: 13 Nov 2004
Posts: 2951
Location: Minnesota

PostPosted: Tue Jan 25, 2005 10:18 pm    Post subject: Reply with quote

Et "mon amie" = "mon ami"

Watch those genders! Wink

(Assuming Nemroth's of the masculine orientation)
Back to top
View user's profile Send private message
Nemroth



Joined: 07 Sep 2004
Posts: 272
Location: France

PostPosted: Wed Jan 26, 2005 5:34 am    Post subject: Reply with quote

BoBo wrote:
Je ne parle pas francais (c'est correct, oui ?)

It's perfectly correct
jonny wrote:
Et "mon amie" = "mon ami"
Watch those genders! Wink
(Assuming Nemroth's of the masculine orientation)

Oui, Nemroth est un ami et non une amie.
Congratulations, french is not a simple language. Smile Smile Smile
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10716

PostPosted: Wed Jan 26, 2005 1:40 pm    Post subject: Reply with quote

aurelian wrote:
Adding the following to the code:
Code:

~XButton2::
return
seems to fix the problem with the thumb button. Smile
I think you could achieve the same effect more concisely by including the tilde (~) here instead:
~XButton2 & MButton::

And thanks for posting another great KDE window helper. I imagine this or one of the other KDE scripts should be put into the showcase. Perhaps they can all be merged somehow into one "ultimate and configurable" KDE script.
Back to top
View user's profile Send private message Send e-mail
aurelian



Joined: 25 Jan 2005
Posts: 3
Location: Germany / Dresden

PostPosted: Wed Jan 26, 2005 2:32 pm    Post subject: Reply with quote

Quote:
I think you could achieve the same effect more concisely by including the tilde (~) here instead:
~XButton2 & MButton::


As I unterstand it, this would forward the XBUtton2 event to the window in any case (MButton pressed or not), and that is not how I wanted it to work. If you minimize the window by Xbutton2&MButton, the XButton2 event should not be sent to the window. (Maybe I'll try out your suggestion when I am home today.)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group