# ---------------------------------------------------------------------------
# Modifiers
#----------------------------------------------------------------------------

# 
# M: Meta or Alt, C: Control, S: Shift, 4: Super (Windows)
# check Super with xmodmap -pm
#

# For changing FvwmCompositor Key bindings modifiers
# Replace "4" by an approriate modifier(s), e.g. S4
DestroyFunc AFuncPointerKeyCompositorCmd
AddToFunc   AFuncPointerKeyCompositorCmd
+ I PointerKey $0 $1 4 $2

DestroyFunc FuncKeyCompositorCmd
AddToFunc   FuncKeyCompositorCmd
+ I Key $0 $1 4 $2

DestroyFunc FuncKeyCompositorWinCmd
AddToFunc   FuncKeyCompositorWinCmd
+ I Key $0 WSTF123456789 4 $1

# As above for usual window ops (e.g., Moving), replace
# M by SM for example
DestroyFunc AFuncPointerKeyWindowCmd
AddToFunc   AFuncPointerKeyWindowCmd
+ I PointerKey $0 $1 M $2

DestroyFunc FuncKeyWindowCmd
AddToFunc   FuncKeyWindowCmd
+ I Key $0 $1 M $2

DestroyFunc FuncKeyWindowWinCmd
AddToFunc   FuncKeyWindowWinCmd
+ I Key $0 WSTF123456789 M $1

# As above for global key binding (page switching), replace
# CM by 4CM for example
DestroyFunc AFuncPointerKeyGlobalCmd
AddToFunc   AFuncPointerKeyGlobalCmd
+ I Pointerkey $0 $1 CM $2

# as above (M to SM)
DestroyFunc AFuncMouseCmd
AddToFunc   AFuncMouseCmd
+ I Mouse $0 $1 M $2

# as above (M to SM?)
DestroyFunc AFuncMouseWindowCmd
AddToFunc   AFuncMouseWindowCmd
+ I Mouse $0 W M $1
# For consitency
+ I Mouse $0 T M $1

DestroyFunc AFuncMouseWindowCmdMore
AddToFunc   AFuncMouseWindowCmdMore
+ I Mouse $0 W CM $1
# For consitency
+ I Mouse $0 T CM $1

# As above (4 to S4)
DestroyFunc AFuncMouseMetisseCmd
AddToFunc   AFuncMouseMetisseCmd
+ I Mouse $0 $1 4 $2

# As above (C4 to SC4)
DestroyFunc AFuncMouseMetisseCmdMore
AddToFunc   AFuncMouseMetisseCmdMore
+ I Mouse $0 $1 C4 $2

# ---------------------------------------------------------------------------
# WindowList
#----------------------------------------------------------------------------

# WindoList, 
DestroyFunc FuncWindowListMouse
AddToFunc   FuncWindowListMouse
+ I WindowList $0 Alphabetic SortByClass NoCurrentDeskTitle TitleForAllDesks NoGeometry  SelectOnRelease "" $1
# NoCurrentDeskTitle

# Alt-Tab
DestroyFunc FuncWindowListKey
AddToFunc   FuncWindowListKey
#+ I FuncFvwmSaveWindowPointerPosition
+ I WindowList Root c c NoDeskSort NoGeometry NoCurrentDeskTitle SelectOnRelease Meta_L CurrentAtEnd $0	

DestroyFunc FuncFvwmSaveWindowPointerPosition
AddToFunc   FuncFvwmSaveWindowPointerPosition
+ I Silent All (HasPointer Focused) SaveWindowPointerPosition On
+ I TestRc (Match) Break 1
+ I Silent All (HasPointer) SaveWindowPointerPosition On
+ I TestRc (Match) Break 1

DestroyFunc FuncFvwmRestoreWindowPointerPosition
AddToFunc   FuncFvwmRestoreWindowPointerPosition
+ I Silent All (HasPointer Focused) WarpToWindow UseSavedPosition 50 50
+ I TestRc (Match) Break 1
+ I Silent All (HasPointer) WarpToWindow UseSavedPosition 50 50
+ I TestRc (Match) Break 1
+ I Silent Current WarpToWindow UseSavedPosition 50 50

DestroyFunc WindowListFunc
AddToFunc   WindowListFunc
+ I Iconify false
+ I ThisWindow (State 1) CompositorIconifyOff
+ I FlipFocus
+ I Raise
+ I sma ShowWindow
#+ I WarpToWindow UseSavedPosition ShowCursorOnSavedPosition 10p 10p
+  I WarpToWindow 10p 10p

#---------------------------------------------------------------------------
# Some useful functions
#----------------------------------------------------------------------------

DestroyFunc AFuncGotoPage 
AddToFunc   AFuncGotoPage 
+ I GotoPage Animate $*

DestroyFunc FuncMoveToPage 
AddToFunc   FuncMoveToPage 
+ I MoveToPage Animate $*

DestroyFunc AFuncWindowMouseRoot
AddToFunc   AFuncWindowMouseRoot
+ I AFuncRootMouse$0

# Selecting a zone on a window
DestroyFunc AFuncSelectRegion
AddToFunc   AFuncSelectRegion
+ I ModuleWindowOperation FvwmCompositor SelectWinRegion CROSS_HAIR
+ M Nop

DestroyFunc AFuncAddSelectRegion
AddToFunc   AFuncAddSelectRegion
+ I ModuleWindowOperation FvwmCompositor AddSelectWinRegion CROSS_HAIR

# ---------------------------------------------------------------------------
# 2. Mouse on the Root window
#----------------------------------------------------------------------------

# Mouse button 1 on the root window
DestroyFunc AFuncRootMouse1
AddToFunc   AFuncRootMouse1
+ I Menu AMenuRoot

# Mouse button 2 on the root window
DestroyFunc AFuncRootMouse2
AddToFunc   AFuncRootMouse2
+ I FuncWindowListMouse

# Mouse button 3 on the root window
DestroyFunc AFuncRootMouse3
AddToFunc   AFuncRootMouse3
+ I StrokeFunc FeedBack DrawMotion StrokeWidth 2

### FIXME: next too dangerous ?

# Mouse button 4 on the root window
DestroyFunc AFuncRootMouse4
AddToFunc   AFuncRootMouse4
#+ I sma PagerMode Off
#+ I GotoDesk -1 0 $[FVWM_LAST_DESK]
+ I Nop

# Mouse button 5 on the root window
DestroyFunc AFuncRootMouse5
AddToFunc   AFuncRootMouse5
#+ I sma PagerMode On
#+ I GotoDesk 1 0 $[FVWM_LAST_DESK]
+ I Nop

# If you run a desktop application (e.g., nautilus desktop or
# kdesktop) we need to add a modifier (sequence) to the "root"
# mouse binding. Here by default Alt

DestroyFunc AFuncDesktopMouse
AddToFunc   AFuncDesktopMouse
+ I AFuncMouseCmd $0 D "AFuncRootMouse$0"

# ---------------------------------------------------------------------------
# 3. Some useful functions for Window decoration bindings
# ---------------------------------------------------------------------------

# NOTE: Move should not be used, AFuncMove should be used!

DestroyFunc AFuncWheelScale
AddToFunc   AFuncWheelScale
+ I sma FixCursor start
+ I sma Scale $*
+ I sma FixCursor stop

DestroyFunc AFuncClickScale
AddToFunc   AFuncClickScale
+ I sma FixCursor start
+ I sma Scale $*
+ I sma FixCursor stop

DestroyFunc AFuncRaiseAndReset
AddToFunc   AFuncRaiseAndReset
+ I Raise
+ I sma Reset

DestroyFunc AFuncReset
AddToFunc   AFuncReset
+ I sma Reset

DestroyFunc AFuncRedo
AddToFunc   AFuncRedo
+ I Raise
+ I Redo

DestroyFunc AFuncUndo
AddToFunc   AFuncUndo
+ I Raise
+ I Undo

DestroyFunc AFuncDoubleClick
AddToFunc   AFuncDoubleClick
+ I ThisWindow (Maximized) sma Reset On
+ I ThisWindow (!Maximized) sma Reset Off
+ I AFuncMaximize

DestroyFunc AFuncButtonDragRotateWindow
AddToFunc   AFuncButtonDragRotateWindow
+ I  ModuleWindowOperation FvwmCompositor $0 $1 $2

DestroyFunc AFuncDragRotateWindow
AddToFunc   AFuncDragRotateWindow
+ I  WarpToWindow 50 50
+ I  ModuleWindowOperation FvwmCompositor $0 $1 $2

DestroyFunc AFuncRestore
AddToFunc   AFuncRestore
+ I ThisWindow (!Iconic !State 1 !Shaded Maximized) Maximize    false
+ I ThisWindow (!Iconic !State 1 Shaded           ) WindowShade false
+ I ThisWindow (!Iconic State 1                   ) AFuncCompositorIconify
+ I ThisWindow ( Iconic                           ) Iconify     false
+ I ThisWindow AFuncReset
+ I ThisWindow Raise

DestroyFunc FuncToggleOnTop
AddToFunc   FuncToggleOnTop
+ I ThisWindow (Layer 4) Layer 0 6
+ I TestRc (Match) Break
+ I ThisWindow (Layer 2) Layer 0 6
+ I TestRc (Match) Break
+ I Echo "Set 0 4"
+ I ThisWindow Layer 0 4

DestroyFunc FuncToggleOnBottom
AddToFunc   FuncToggleOnBottom
+ I ThisWindow (Layer 4) Layer 0 2
+ I TestRc (Match) break
+ I ThisWindow (Layer 6) Layer 0 2
+ I TestRc (Match) break
+ I ThisWindow Layer 0 4

DestroyFunc AFuncMoveOrShade
AddToFunc   AFuncMoveOrShade
+ I Raise
+ D AFuncDoubleClick $0
+ M AFuncMove
+ H AFuncMove

DestroyFunc AFuncMarkingMoveToPage
AddToFunc   AFuncMarkingMoveToPage
+ I ThisWindow (MarkingDirectionFull W) FuncMoveToPage -1p 0p
+ I TestRc (Match) Break
+ I ThisWindow (MarkingDirectionFull NW) FuncMoveToPage -1p -1p
+ I TestRc (Match) Break
+ I ThisWindow (MarkingDirectionFull N) FuncMoveToPage 0p -1p
+ I TestRc (Match) Break
+ I ThisWindow (MarkingDirectionFull NE) FuncMoveToPage 1p -1p
+ I TestRc (Match) Break
+ I ThisWindow (MarkingDirectionFull E) FuncMoveToPage 1p -0p
+ I TestRc (Match) Break
+ I ThisWindow (MarkingDirectionFull SE) FuncMoveToPage 1p 1p
+ I TestRc (Match) Break
+ I ThisWindow (MarkingDirectionFull S) FuncMoveToPage 0p 1p
+ I TestRc (Match) Break
+ I ThisWindow (MarkingDirectionFull SW) FuncMoveToPage -1p 1p
+ I TestRc (Match) Break


DestroyFunc AFuncMoveOrShadeOrTmpMoveOrScaleMaxVert
AddToFunc   AFuncMoveOrShadeOrTmpMoveOrScaleMaxVert
+ I Raise
+ D AFuncDoubleClick $0
+ CH AFuncTmpMove
+ CM AFuncTmpMove
+ EDA N "Up Page" NE "Up Right Page" E "Right Page" SE "Bottom Right Page" \
	S "Bottom Page" SW "Bottom Left Page" W "Left Page" NW "Up Left Page"
+ DA AFuncMarkingMoveToPage
+ T AFuncScaleMaximize 0 150 0.6666667
+ M AFuncMove
+ H AFuncMove

DestroyFunc AFuncBindTmpMove
AddToFunc   AFuncBindTmpMove
+ I Raise
+ M AFuncTmpMove
+ H AFuncTmpMove

DestroyFunc AFuncResizeOrShade
AddToFunc   AFuncResizeOrShade
+ I Raise
+ D AFuncDoubleClick
+ M Resize
+ H Resize

DestroyFunc AFuncResize
AddToFunc   AFuncResize
+ I Raise
+ M Resize
+ H Resize

DestroyFunc AFuncFoldOrShade
AddToFunc   AFuncFoldOrShade
+ I Raise
+ D AFuncDoubleClick $0
+ M ModuleWindowOperation FvwmCompositor Fold FOLD
+ H ModuleWindowOperation FvwmCompositor Fold FOLD

DestroyFunc AFuncScaleOrShade
AddToFunc   AFuncScaleOrShade
+ I Raise
+ D AFuncDoubleClick $0
+ M ModuleWindowOperation FvwmCompositor  InteractiveScale RESIZE 0.7
+ H ModuleWindowOperation FvwmCompositor  InteractiveScale RESIZE 0.7

DestroyFunc AFuncTmpScaleOrShade
AddToFunc   AFuncTmpScaleOrShade
+ I Raise
+ D AFuncDoubleClick $0
+ M ModuleWindowOperation FvwmCompositor  TmpInteractiveScale RESIZE 0.7
+ H ModuleWindowOperation FvwmCompositor  TmpInteractiveScale RESIZE 0.7

# For fvwm icons
DestroyFunc AFuncMoveOrIconify
AddToFunc   AFuncMoveOrIconify
+ M	Move
+ D	Iconify

#------------------------------
# A way to "iconify" 

DestroyFunc AFuncCompositorIconifyOn
AddToFunc   AFuncCompositorIconifyOn
+ I PipeRead 'perl $[METISSE_FVWM_CONFIG_DIR]/scripting.pl -iconify'
+ I State 1 True

DestroyFunc AFuncCompositorIconifyOff
AddToFunc   AFuncCompositorIconifyOff
+ I PipeRead 'perl $[METISSE_FVWM_CONFIG_DIR]/scripting.pl -deiconify'
+ I State 1 False
+ I Raise

DestroyFunc AFuncCompositorIconify
AddToFunc   AFuncCompositorIconify
+ I ThisWindow (State 1) AFuncCompositorIconifyOff
+ I TestRc (NoMatch)  AFuncCompositorIconifyOn

#-----------------------
# Scale Maximize

DestroyFunc AFuncScaleMaximizeOn
AddToFunc   AFuncScaleMaximizeOn
+ I Maximize $0 $1
+ I Schedule 350 sma Scale $2
+ I State 2 True

DestroyFunc AFuncScaleMaximizeOff
AddToFunc   AFuncScaleMaximizeOff
+ I Maximize Off
+ I sma Reset
+ I State 2 False

DestroyFunc AFuncScaleMaximize
AddToFunc   AFuncScaleMaximize
+ I ThisWindow (State 2) AFuncScaleMaximizeOff $*
+ I TestRc (NoMatch)  AFuncScaleMaximizeOn $*

# --------------------------

DestroyFunc AFuncScaleFullScreenOn
AddToFunc   AFuncScaleFullScreenOn
+ I Maximize Off
+ I WindowStyle !Borders, !Title
+ I UpdateStyles
+ I Raise
+ I Maximize $[w.width]p $[w.height]p
+ I PipeRead "perl $[METISSE_FVWM_CONFIG_DIR]/scripting.pl -sfs -w $[w.width] -h  $[w.height] -sw $[vp.width] -sh $[vp.height]"
+ I State 3 True

DestroyFunc AFuncScaleFullScreenOff
AddToFunc   AFuncScaleFullScreenOff
+ I WindowStyle Borders, Title 
+ I Maximize Off
+ I sma Reset
+ I State 3 False

DestroyFunc AFuncScaleFullScreen
AddToFunc   AFuncScaleFullScreen
+ I ThisWindow (State 3) AFuncScaleFullScreenOff $*
+ I TestRc (NoMatch)  AFuncScaleFullScreenOn $*

# -------------------------

DestroyFunc AFuncUnmaximize
AddToFunc   AFuncUnmaximize
+ I ThisWindow (State 3) AFuncScaleFullScreenOff $*
+ I ThisWindow (State 2) AFuncScaleMaximizeOff
+ I State 2 False
+ I State 3 False
+ I Maximize Off

DestroyFunc AFuncMaximizeOn
AddToFunc   AFuncMaximizeOn
+ I Maximize $*

DestroyFunc AFuncMaximize
AddToFunc   AFuncMaximize
+ I ThisWindow (!Maximized) Maximize $*
+ I TestRc (NoMatch)   AFuncUnmaximize

# --------------------------------------------------------------------------
# Marking functions

# ------------------------
# for left or right border
DestroyFunc AFuncMarkingSRotateNScaleEWResize
AddToFunc   AFuncMarkingSRotateNScaleEWResize
+ I ThisWindow (MarkingDirectionOrth S) \
	AFuncButtonDragRotateWindow DragRotateY RotateY
+ I TestRc (Match) Break 
+ I ThisWindow (MarkingDirectionOrth N) \
	ModuleWindowOperation FvwmCompositor  InteractiveScale RESIZE 0.7
+ I TestRc (Match) Break 
+ I ThisWindow (MarkingDirectionOrth E|W)  Resize

DestroyFunc AFuncMarkingTmpSRotateNScaleEWFold
AddToFunc   AFuncMarkingTmpSRotateNScaleEWFold
+ I ThisWindow (MarkingDirectionOrth S) \
	AFuncButtonDragRotateWindow DragRotateY RotateY Tmp
+ I TestRc (Match) Break 
+ I ThisWindow (MarkingDirectionOrth N) \
	ModuleWindowOperation FvwmCompositor  TmpInteractiveScale RESIZE 0.7
+ I TestRc (Match) Break
+ I ThisWindow (MarkingDirectionOrth E|W) ModuleWindowOperation FvwmCompositor Fold FOLD

DestroyFunc AFuncMarkingSRotateNScaleEWResizeOrDoubleClick
AddToFunc   AFuncMarkingSRotateNScaleEWResizeOrDoubleClick
+ I Raise
+ D AFuncDoubleClick $0
+ EA W Resize E Resize S "Y Rotate" N Scale
+ A AFuncMarkingSRotateNScaleEWResize
+ ECA W Fold E Fold N "Scale Tmp" S "Y Rotate Tmp"
+ CA AFuncMarkingTmpSRotateNScaleEWFold


# ------------------------
# for top or bottom border

DestroyFunc AFuncMarkingWRotateEScaleNSResize
AddToFunc   AFuncMarkingWRotateEScaleNSResize
+ I ThisWindow (MarkingDirectionOrth W) \
	AFuncButtonDragRotateWindow DragRotateX RotateX
+ I TestRc (Match) Break 
+ I ThisWindow (MarkingDirectionOrth E) \
	ModuleWindowOperation FvwmCompositor  InteractiveScale RESIZE 0.7
+ I TestRc (Match) Break
+ I ThisWindow (MarkingDirectionOrth N|S)  Resize

DestroyFunc AFuncMarkingTmpWRotateEScaleNSFold
AddToFunc   AFuncMarkingTmpWRotateEScaleNSFold
+ I ThisWindow (MarkingDirectionOrth W) \
	AFuncButtonDragRotateWindow DragRotateX RotateX Tmp
+ I TestRc (Match) Break 
+ I ThisWindow (MarkingDirectionOrth E) \
	ModuleWindowOperation FvwmCompositor  TmpInteractiveScale RESIZE 0.7
+ I TestRc (Match) Break
+ I ThisWindow (MarkingDirectionOrth N|S)   ModuleWindowOperation FvwmCompositor Fold FOLD

DestroyFunc AFuncMarkingWRotateEScaleNSResizeOrDoubleClick
AddToFunc   AFuncMarkingWRotateEScaleNSResizeOrDoubleClick
+ I Raise
+ D AFuncDoubleClick $0
+ EA W X-Rotate E Scale N Resize S Resize
+ A AFuncMarkingWRotateEScaleNSResize
+ ECA W "Rotate Tmp" E "Scale Tmp" S Fold N Fold
+ CA AFuncMarkingTmpWRotateEScaleNSFold

# ------------------------
# for top-left corner ????

DestroyFunc AFuncMarkingSSWRotateENEScaleSENWNWResize
AddToFunc   AFuncMarkingSSWRotateENEScaleSENWNWResize
+ I ThisWindow (MarkingDirectionFull S|SW) \
	AFuncButtonDragRotateWindow DragRotateZ RotateZ
+ I TestRc (Match) Break 
+ I ThisWindow (MarkingDirectionFull E|NE) \
	ModuleWindowOperation FvwmCompositor  InteractiveScale RESIZE 0.7
+ I TestRc (Match) Break
#+ I Resize
+ I ThisWindow (MarkingDirectionFull SE|NW|N|W)  Resize

DestroyFunc AFuncMarkingSSWRotateENEScaleSENWNWResizeOrDoubleClick
AddToFunc   AFuncMarkingSSWRotateENEScaleSENWNWResizeOrDoubleClick
+ I Raise
+ D AFuncDoubleClick $0
+ EA W Resize NW Resize N Resize NE Scale E Scale SE Resize S "Z Rotate" \
	 SW "Z Rotate"
+ A AFuncMarkingSSWRotateENEScaleSENWNWResize
+ CH ModuleWindowOperation FvwmCompositor Fold FOLD
+ CM ModuleWindowOperation FvwmCompositor Fold FOLD

# ------------------------
# for top-right corner ????

DestroyFunc AFuncMarkingSSERotateENWScaleSWNENWResize
AddToFunc   AFuncMarkingSSERotateENWScaleSWNENWResize
+ I ThisWindow (MarkingDirectionFull S|SE) \
	AFuncButtonDragRotateWindow DragRotateZ RotateZ
+ I TestRc (Match) Break 
+ I ThisWindow (MarkingDirectionFull W|NW) \
	ModuleWindowOperation FvwmCompositor  InteractiveScale RESIZE 0.7
+ I TestRc (Match) Break
+ I ThisWindow (MarkingDirectionFull SW|NE|N|E)  Resize

DestroyFunc AFuncMarkingSSERotateENWScaleSWNENWResizeOrDoubleClick
AddToFunc   AFuncMarkingSSERotateENWScaleSWNENWResizeOrDoubleClick
+ I Raise
+ D AFuncDoubleClick $0
+ EA W Scale NW Scale N Resize NE Resize E Resize SE "Z Rotate" S \
	"Z Rotate" SW "Resize"
+ A AFuncMarkingSSERotateENWScaleSWNENWResize
+ CH ModuleWindowOperation FvwmCompositor Fold FOLD
+ CM ModuleWindowOperation FvwmCompositor Fold FOLD

# ---------------------------------
# for bottom-right corner ????

DestroyFunc AFuncMarkingWSWRotateNNEScaleSENWSEResize
AddToFunc   AFuncMarkingWSWRotateNNEScaleSENWSEResize
+ I ThisWindow (MarkingDirectionFull W|SW) \
	AFuncButtonDragRotateWindow DragRotateZ RotateZ
+ I TestRc (Match) Break 
+ I ThisWindow (MarkingDirectionFull N|NE) \
	ModuleWindowOperation FvwmCompositor  InteractiveScale RESIZE 0.7
+ I TestRc (Match) Break
+ I ThisWindow (MarkingDirectionFull SE|NW|S|E)  Resize

DestroyFunc AFuncMarkingWSWRotateNNEScaleSENWSEResizeOrDoubleClick
AddToFunc   AFuncMarkingWSWRotateNNEScaleSENWSEResizeOrDoubleClick
+ I Raise
+ D AFuncDoubleClick $0
+ EA W "Z Rotate" NW "Resize" N "Scale" NE "Scale" E "Resize" SE "Resize" \
	S "Resize" SW "Z Rotate"
+ A AFuncMarkingWSWRotateNNEScaleSENWSEResize
+ CH ModuleWindowOperation FvwmCompositor Fold FOLD
+ CM ModuleWindowOperation FvwmCompositor Fold FOLD

# --------------------------------
# for bottom-left corner ????

DestroyFunc AFuncMarkingESERotateNNWScaleSWNESWResize
AddToFunc   AFuncMarkingESERotateNNWScaleSWNESWResize
+ I ThisWindow (MarkingDirectionFull E|SE) \
	AFuncButtonDragRotateWindow DragRotateZ RotateZ
+ I TestRc (Match) Break 
+ I ThisWindow (MarkingDirectionFull N|NW) \
	ModuleWindowOperation FvwmCompositor  InteractiveScale FOLD 0.7
+ I TestRc (Match) Break
+ I ThisWindow (MarkingDirectionFull SW|NE|S|W)  Resize

DestroyFunc AFuncMarkingESERotateNNWScaleSWNESWResizeOrDoubleClick
AddToFunc   AFuncMarkingESERotateNNWScaleSWNESWResizeOrDoubleClick
+ I Raise
+ D AFuncDoubleClick $0
+ EA W "Resize" NW "Scale" N "Scale" NE "Resize" E "Z Rotate" \
	SE "Z Rotate" S "Resize" SW "Resize"
+ A AFuncMarkingESERotateNNWScaleSWNESWResize
+ CH ModuleWindowOperation FvwmCompositor Fold FOLD
+ CM ModuleWindowOperation FvwmCompositor Fold FOLD

# -----------

DestroyFunc AFuncTestFunc
AddToFunc   AFuncTestFunc
+ M Echo Motion
+ H Echo Hold
+ A Echo Marking full: $[md.full],  orth: $[md.orth],  obl: $[md.obl]
+ C Echo Click
+ CH Echo ClickHold
+ CM Echo ClickMotion
+ CA Echo ClickMarking full: $[md.full],  orth: $[md.orth],  obl: $[md.obl]
+ D Echo DoubleClick 
+ DH Echo DoubleClickHold
+ DM Echo DoubleClickMotion
+ DA Echo DoubleClickMarking full: $[md.full],  orth: $[md.orth],  obl: $[md.obl]
+ T Echo TripleClick


# ---------------------------------------------------------------------------
# 4. Title bar and border
# ---------------------------------------------------------------------------

# Mouse button 1 on the window title bar
DestroyFunc AFuncWindowTitleBarMouse1
AddToFunc   AFuncWindowTitleBarMouse1
+ I AFuncMoveOrShadeOrTmpMoveOrScaleMaxVert
#+ I AFuncTestFunc

DestroyFunc AFuncWindowTitleBarMouse1Mod4
AddToFunc   AFuncWindowTitleBarMouse1Mod4
+ I AFuncBindTmpMove

# Mouse button 2 on the window title bar
DestroyFunc AFuncWindowTitleBarMouse2
AddToFunc   AFuncWindowTitleBarMouse2
+ I AFuncReset
#+ I RaiseLower

# Mouse button 3 on the window title bar
DestroyFunc AFuncWindowTitleBarMouse3
AddToFunc   AFuncWindowTitleBarMouse3
+ I Menu AMenuWinOps

# Mouse button 4 on the window title bar
DestroyFunc AFuncWindowTitleBarMouse4
AddToFunc   AFuncWindowTitleBarMouse4
+ I AFuncWheelScale 1.1111111

# Mouse button 5 on the window title bar
DestroyFunc AFuncWindowTitleBarMouse5
AddToFunc   AFuncWindowTitleBarMouse5
+ I AFuncWheelScale 0.9

#---------------------------------------
# Window borders

# NOTE: an additional argument is passed to these functions:
#       West, NorthWest, North, ..., SouthWest

# ----------------------
# Mouse 1 on the borders

DestroyFunc AFuncWindowLeftBorderMouse1
AddToFunc   AFuncWindowLeftBorderMouse1
+ I AFuncMarkingSRotateNScaleEWResizeOrDoubleClick $*

DestroyFunc AFuncWindowRightBorderMouse1
AddToFunc   AFuncWindowRightBorderMouse1
+ I AFuncMarkingSRotateNScaleEWResizeOrDoubleClick $*

DestroyFunc AFuncWindowTopBorderMouse1
AddToFunc   AFuncWindowTopBorderMouse1
+ I AFuncMarkingWRotateEScaleNSResizeOrDoubleClick $*

DestroyFunc AFuncWindowBottomBorderMouse1
AddToFunc   AFuncWindowBottomBorderMouse1
+ I AFuncMarkingWRotateEScaleNSResizeOrDoubleClick $*

# ----------------------
# Mouse 1 on the corners

DestroyFunc AFuncWindowTopLeftCornerMouse1
AddToFunc   AFuncWindowTopLeftCornerMouse1
+ I AFuncMarkingSSWRotateENEScaleSENWNWResizeOrDoubleClick  $*

DestroyFunc AFuncWindowTopRightCornerMouse1
AddToFunc   AFuncWindowTopRightCornerMouse1
+ I AFuncMarkingSSERotateENWScaleSWNENWResizeOrDoubleClick  $*

DestroyFunc AFuncWindowBottomRightCornerMouse1
AddToFunc   AFuncWindowBottomRightCornerMouse1
+ I AFuncMarkingWSWRotateNNEScaleSENWSEResizeOrDoubleClick  $*

DestroyFunc AFuncWindowBottomLeftCornerMouse1
AddToFunc   AFuncWindowBottomLeftCornerMouse1
+ I AFuncMarkingESERotateNNWScaleSWNESWResizeOrDoubleClick  $*

# ----------------------
# Mouse 2 on the borders
DestroyFunc AFuncWindowBordersMouse2
AddToFunc   AFuncWindowBordersMouse2
+ I sma Reset

# ----------------------
# Mouse 3 on the borders
DestroyFunc AFuncWindowBordersMouse3
AddToFunc   AFuncWindowBordersMouse3
+ I Menu AMenuWinOps

### What to do with buttons 4 and 5 ?


# ----------------------
# Mouse 1 + some modifiers on the borders (no arguments) 

DestroyFunc AFuncWindowBordersMouse1Mod1
AddToFunc   AFuncWindowBordersMouse1Mod1
+ I Mouse 1 FS M  AFuncScaleOrShade

DestroyFunc AFuncWindowBordersMouse1Mod2
AddToFunc   AFuncWindowBordersMouse1Mod2
+ I Mouse 1 FS S  AFuncResizeOrShade

DestroyFunc AFuncWindowBordersMouse1Mod4
AddToFunc   AFuncWindowBordersMouse1Mod4
+ I Mouse 1 FS 4 AFuncTmpScaleOrShade


DestroyFunc AFuncWindowBordersLeftRightMouse1Mod3
AddToFunc   AFuncWindowBordersLeftRightMouse1Mod3
+ I Mouse 1 [] C  AFuncButtonDragRotateWindow DragRotateY RotateY

DestroyFunc AFuncWindowBordersLeftRightMouse1Mod3Mod4
AddToFunc   AFuncWindowBordersLeftRightMouse1Mod3Mod4
+ I Mouse 1 [] 4C  AFuncButtonDragRotateWindow DragRotateY RotateY Tmp

DestroyFunc AFuncWindowBordersTopBottomMouse1Mod3
AddToFunc   AFuncWindowBordersTopBottomMouse1Mod3
+ I Mouse 1 -_ C  AFuncButtonDragRotateWindow DragRotateX RotateX

DestroyFunc AFuncWindowBordersTopBottomMouse1Mod3Mod4
AddToFunc   AFuncWindowBordersTopBottomMouse1Mod3Mod4
+ I Mouse 1 -_ 4C  AFuncButtonDragRotateWindow DragRotateX RotateX Tmp

DestroyFunc AFuncWindowBordersCornersMouse1Mod3
AddToFunc   AFuncWindowBordersCornersMouse1Mod3
+ I Mouse 1 <>^v C  AFuncButtonDragRotateWindow DragRotateZ RotateZ

DestroyFunc AFuncWindowBordersCornersMouse1Mod3Mod4
AddToFunc   AFuncWindowBordersCornersMouse1Mod3Mod4
+ I Mouse 1 <>^v 4C  AFuncButtonDragRotateWindow DragRotateZ RotateZ Tmp

#---------------------------------------
# icons

# Mouse 1 on icon
DestroyFunc AFuncWindowIconMouse1
AddToFunc   AFuncWindowIconMouse1
+ I Raise
+ I AFuncMoveOrIconify

# Mouse 2 on icon
DestroyFunc AFuncWindowIconMouse2
AddToFunc   AFuncWindowIconMouse2
+ I Iconify off

# Mouse 3 on icon
DestroyFunc AFuncWindowIconMouse3
AddToFunc   AFuncWindowIconMouse3
+ I Raise
+ I  Menu AMenuWinOps

### What to do with buttons 4 and 5 ?

# ---------------------------------------------------------------------------
# 5. Functions executed when you click on a window button
#----------------------------------------------------------------------------

# NOTE: used in window theme, not in bindings


#---------------------------------------
# Maximize Button
DestroyFunc AFuncMarkingMaximize
AddToFunc   AFuncMarkingMaximize
+ I ThisWindow (MarkingDirectionFull S|N) AFuncMaximize On 0 100
+ I TestRc (Match) Break
+ I ThisWindow (MarkingDirectionFull E|W) AFuncMaximize On 100 0
+ I TestRc (Match) Break
+ I ThisWindow (MarkingDirectionFull SE|SW|NE|NW) AFuncMaximize ewmhiwa On 100 100

# Mouse 1
DestroyFunc AFuncButtonMaximize
AddToFunc   AFuncButtonMaximize
#+ H sma Scale 1.1111111
#+ M sma Scale 1.4285714
+ I Raise
+ C AFuncMaximize
+ D Menu AMenuMaximize
+ A AFuncMarkingMaximize

# Mouse 2
DestroyFunc AFuncButtonMaximize2
AddToFunc   AFuncButtonMaximize2
+ I AFuncClickScale 1.4285714

# Mouse 3
DestroyFunc AFuncButtonMaximize3
AddToFunc   AFuncButtonMaximize3
+ I AFuncClickScale 1.1111111

# Mouse 4
DestroyFunc AFuncButtonMaximize4
AddToFunc   AFuncButtonMaximize4
+ I AFuncUnmaximize

# Mouse 5
DestroyFunc AFuncButtonMaximize5
AddToFunc   AFuncButtonMaximize5
+ I AFuncMaximize On 0 100

DestroyFunc AFuncButtonMaximizeShift
AddToFunc   AFuncButtonMaximizeShift
+ I  AFuncScaleMaximize 0 150 0.6666667

#---------------------------------------
# Minimize Button

DestroyFunc AFuncButtonMinimize
AddToFunc   AFuncButtonMinimize
+ C Iconify On
#+ H sma Scale 0.9
#+ M sma Scale 0.7
+ D Menu AMenuMinimize

DestroyFunc AFuncButtonMinimize2
AddToFunc   AFuncButtonMinimize2
+ C AFuncClickScale 0.7

DestroyFunc AFuncButtonMinimize3
AddToFunc   AFuncButtonMinimize3
+ C AFuncClickScale 0.9

DestroyFunc AFuncButtonMinimize4
AddToFunc   AFuncButtonMinimize4
#+ I AFuncClickScale 0.9
+ C Nop

DestroyFunc AFuncButtonMinimize5
AddToFunc   AFuncButtonMinimize5
+ C Iconify On

#---------------------------------------
# Close Button

DestroyFunc AFuncButtonClose
AddToFunc   AFuncButtonClose
+ H Nop
+ M Nop
+ C Delete
+ D Close

DestroyFunc AFuncButtonClose2
AddToFunc   AFuncButtonClose2
+ I Destroy

DestroyFunc AFuncButtonClose3
AddToFunc   AFuncButtonClose3
+ I Destroy

#---------------------------------------
# Menu Button

DestroyFunc AFuncButtonMenu
AddToFunc   AFuncButtonMenu
+ I Menu AMenuWinOps $*

DestroyFunc AFuncButtonMenu3
AddToFunc   AFuncButtonMenu3
+ I FvwmPager -transient-move $[w.id] FvwmPager-Swallowed-Single
# this move the viewport too
#+ I FvwmPager -transient-move-and-go $[w.id] FvwmPager-Swallowed-Single
#+ I Menu AMenuWinOpsMoveToDesk

DestroyFunc AFuncButtonMenu2
AddToFunc   AFuncButtonMenu2
#+ I Menu AMenuWinOpsLong
#+ I Menu MenuInterExtendedInputs2
+ I Menu MenuInterWindow

#---------------------------------------
# Stick Button
DestroyFunc AFuncMarkingStick
AddToFunc   AFuncMarkingStick
+ I ThisWindow (MarkingDirectionOrth S|W) AFuncUndo
+ I TestRc (Match) Break
+ I ThisWindow (MarkingDirectionOrth E|N) AFuncRedo
+ I TestRc (Match) Break

DestroyFunc AFuncButtonStick
AddToFunc   AFuncButtonStick
+ C Stick
+ A AFuncMarkingStick

DestroyFunc AFuncButtonStick2
AddToFunc   AFuncButtonStick2
+ I Stick

DestroyFunc AFuncButtonStick3
AddToFunc   AFuncButtonStick3
+ I Stick

#---------------------------------------
# Shade Button

DestroyFunc AFuncButtonShade
AddToFunc   AFuncButtonShade
+ I WindowShade

DestroyFunc AFuncButtonShade2
AddToFunc   AFuncButtonShade2
+ I WindowShade

DestroyFunc AFuncButtonShade3
AddToFunc   AFuncButtonShade3
+ I WindowShade

#---------------------------------------
# Gesture Button
DestroyFunc AFuncButtonGesture
AddToFunc   AFuncButtonGesture
+ I StrokeFunc FeedBack DrawMotion StrokeWidth 2

#---------------------------------------
# Y rotate button

DestroyFunc AFuncButtonRotateY
AddToFunc   AFuncButtonRotateY
+ I AFuncButtonDragRotateWindow DragRotateY RotateY

DestroyFunc AFuncButtonRotateYMod4
AddToFunc   AFuncButtonRotateYMod4
+ I AFuncButtonDragRotateWindow DragRotateY RotateY Tmp

DestroyFunc AFuncButtonRotateY2
AddToFunc   AFuncButtonRotateY2
+ I sma Rotate 36 0 36 0

DestroyFunc AFuncButtonRotateY3
AddToFunc   AFuncButtonRotateY3
+ I sma Rotate -36 0 36 0

#---------------------------------------
# X rotate button

DestroyFunc AFuncButtonRotateX
AddToFunc   AFuncButtonRotateX
+ I AFuncButtonDragRotateWindow DragRotateX RotateX

DestroyFunc AFuncButtonRotateXMod4
AddToFunc   AFuncButtonRotateXMod4
+ I AFuncButtonDragRotateWindow DragRotateX RotateX Tmp

DestroyFunc AFuncButtonRotateX2
AddToFunc   AFuncButtonRotateX2
+ I sma Rotate 29 29 0 0

DestroyFunc AFuncButtonRotateX3
AddToFunc   AFuncButtonRotateX3
+ I sma Rotate -29 29 0 0

#---------------------------------------
# Z rotate button

DestroyFunc AFuncButtonRotateZ
AddToFunc   AFuncButtonRotateZ
+ I AFuncButtonDragRotateWindow DragRotateZ RotateZ

DestroyFunc AFuncButtonRotateZMod4
AddToFunc   AFuncButtonRotateZMod4
+ I AFuncButtonDragRotateWindow DragRotateZ RotateZ Tmp

DestroyFunc AFuncButtonRotateZ2
AddToFunc   AFuncButtonRotateZ2
+ I sma Rotate 180 0 0 180 1

DestroyFunc AFuncButtonRotateZ3
AddToFunc   AFuncButtonRotateZ3
+ I sma Rotate 90 0 0 90 1

#---------------------------------------
# 

