# FVWM-Crystal: Fullscreen
# Written by: Maciej Delmanowski <harnir@linux.net.pl>

# Overview:
# After using this function, current window will lose it's border and title
# and will be maximized to the full screen (wow). After using Fullscreen
# function on a "fullscreened" window it will return to it's previous size and
# position and border/title will be brought back.

# How to use:
# Bind "Fullscreen" command somewhere, example:
# Key Q A M Fullscreen

# Technical note:
# Fullscreen* functions are using 'State 0' as indicator if current window is
# in "fullscreened" mode.
# 'Fullscreen-Start' and 'Fullscreen-Stop' functions shouldn't be called
# directly, use 'Fullscreen' function instead.

# Bugs/Improvements:
# - Make a way to prevent "fullscreened" window to move or resize - when
#   FixedSize or FixedPosition are put into WindowStyle command, window doesn't
#   return to it's previous state.
# - terminal windows are not fully maximized, there is free space at the bottom
#   and right edge of the screen. That's because terminal windows in FVWM can
#   be resized usind character's width and height as the resolution.  See Move
#   and Resize commands description regarding "c" in FVWM manual.


DestroyFunc Fullscreen
AddToFunc Fullscreen
+ I Fullscreen-Stop
+ I Current (!Maximizable) Break
+ I TestRc (False) Fullscreen-Start

DestroyFunc Fullscreen-Start
AddToFunc Fullscreen-Start
+ I Current (State 0) Break
+ I SetEnv OldX-$[w.id] $[w.x]
+ I SetEnv OldY-$[w.id] $[w.y]
+ I SetEnv OldWidth-$[w.id] $[cw.width]
+ I SetEnv OldHeight-$[w.id] $[cw.height]
+ I Move 0p 0p
+ I Resize 100 100 frame
#+ I Layer 0 5
+ I WindowStyle NoTitle, !Borders, StaysOnTop, !Iconifiable, !Maximizable
+ I State 0 true

DestroyFunc Fullscreen-Stop
AddToFunc Fullscreen-Stop
#+ I Current (!State 0) Break
+ I DestroyWindowStyle
+ I State 0 false
#+ I Layer 0 4
+ I PipeRead "echo ResizeMove \\$\\[OldWidth-$[w.id]\\]p \\$\\[OldHeight-$[w.id]\\]p \\$\\[OldX-$[w.id]\\]p \\$\\[OldY-$[w.id]\\]p"
+ I UnSetEnv OldX-$[w.id]
+ I UnSetEnv OldY-$[w.id]
+ I UnSetEnv OldWidth-$[w.id]
+ I UnSetEnv OldHeight-$[w.id]

# vim:ft=fvwm
