#-----------------------------------------------------------------------
# File:         Vertical
# Version:      1.2.4
# Licence:      GPL 2
#
# Description:  Layout of object positions on desktop
#
# Author:       Thomas Funk <t.funk@web.de>    
#               Bernhard Popp <kermit.popp@googlemail.com>
#
# Created:      08/16/2012
# Changed:      05/28/2016
#-----------------------------------------------------------------------
# Top right
#
# +--------+
# |        | Panel
# +--------+
# +--------+
# |        | Pager
# +--------+
# +--------+
# |        | IconManager
# +--------+
#
#-----------------------------------------------------------------------

########################################################################
#                        Positioning
########################################################################


#=======================================================================
# FvwmButtons Panel
#=======================================================================

#-----------------------------------------------------------------------
# set bar and tray icon size depending on the screen height
#-----------------------------------------------------------------------
PipeRead    'if [ "$[vp.height]" -gt "2800" ]; then \
                echo InfoStoreAdd i_size 48; \
            elif [ "$[vp.height]" -gt "2500" ]; then \
                echo InfoStoreAdd i_size 36; \
            elif [ "$[vp.height]" -gt "2000" ]; then \
                echo InfoStoreAdd i_size 32; \
            elif [ "$[vp.height]" -gt "1800" ]; then \
                echo InfoStoreAdd i_size 30; \
            elif [ "$[vp.height]" -gt "1600" ]; then \
                echo InfoStoreAdd i_size 28; \
            elif [ "$[vp.height]" -gt "1500" ]; then \
                echo InfoStoreAdd i_size 26; \
            elif [ "$[vp.height]" -gt "1050" ]; then \
                echo InfoStoreAdd i_size 25; \
            elif [ "$[vp.height]" -gt "640" ]; then \
                echo InfoStoreAdd i_size 24; \
            elif [ "$[vp.height]" -gt "580" ]; then \
                echo InfoStoreAdd i_size 22; \
            else \
                echo InfoStoreAdd i_size 20; \
            fi'

#-----------------------------------------------------------------------
# Panel height
#-----------------------------------------------------------------------
PipeRead "echo InfoStoreAdd row_height $(($[infostore.i_size]+8))"

PipeRead "echo InfoStoreAdd panel_height $(($[infostore.row_height]*5))"

#-----------------------------------------------------------------------
# Panel width
#-----------------------------------------------------------------------
#InfoStoreAdd panel_width 125
PipeRead "echo InfoStoreAdd panel_width `perl -e \
    'printf \"%.0f\",($[infostore.row_height]*3*($[infostore.aspect_ratio]))+2'`"

# the count of systray icons is calculated by the panel width/icon size - 1 icon
PipeRead "echo InfoStoreAdd tray_icons `perl -e 'printf \"%.0f\",($[infostore.panel_width]/$[infostore.i_size])-1'`"

#-----------------------------------------------------------------------
# Panel geometry
#-----------------------------------------------------------------------
PipeRead 'echo InfoStoreAdd panel_geometry $[infostore.panel_width]x$[infostore.panel_height]-0+0'


#=======================================================================
# Pager
#=======================================================================

#-----------------------------------------------------------------------
# Set the desk top size in units of physical screen size
#
#   +-----+-----+
#   |     |     |
#   +-----+-----+
#   |     |     |
#   +-----+-----+
#-----------------------------------------------------------------------
DeskTopSize "$[infostore.x_desks]x$[infostore.y_desks]"

#-----------------------------------------------------------------------
# actual pager height
#-----------------------------------------------------------------------
PipeRead "echo InfoStoreAdd pager_height `perl -e 'printf \"%.0f\", \
    (($[infostore.row_height]+($[infostore.wratio]-$[infostore.ratio]))*($[infostore.y_desks]+1)+1)'`"


#-----------------------------------------------------------------------
# FvwmPager geometry
#-----------------------------------------------------------------------
PipeRead 'echo InfoStoreAdd pager_geometry $[infostore.panel_width]x$[infostore.pager_height]-0+$(($[infostore.panel_height]+4))'


#=======================================================================
# Icon Manager (WinList per Page)
#=======================================================================

#-----------------------------------------------------------------------
# GlobalIconMan Button Geometry
#-----------------------------------------------------------------------
PipeRead 'echo InfoStoreAdd iconman_button_geometry $(($[infostore.panel_width]-$[infostore.titlebar_height]+2))x0'

#-----------------------------------------------------------------------
# GlobalIconMan Manager Geometry
#-----------------------------------------------------------------------
PipeRead "echo InfoStoreAdd yStartIman `perl -e 'printf \"%.0f\", \
    (($[vp.height]-($[infostore.panel_height]+$[infostore.pager_height])-($[infostore.fontsize]+15)))'`"
PipeRead "echo InfoStoreAdd xStartIman `perl -e 'printf \"%.0f\",$[vp.width]-$[infostore.panel_width]-4'`"
InfoStoreAdd iconman_manager_geometry 1x0+$[infostore.xStartIman]-$[infostore.yStartIman]

#-----------------------------------------------------------------------
# GlobalIconMan Manager Titlebar position
#-----------------------------------------------------------------------
Style GlobalIconMan TitleAtLeft

#-----------------------------------------------------------------------
# GlobalIconMan Manager Tips
#-----------------------------------------------------------------------
InfoStoreAdd tips_iman always


#=======================================================================
# Others
#=======================================================================

#-----------------------------------------------------------------------
# Define bands at the edge of the screen. It is used to compute the
# Working Area: EwmhBaseStruts left right top bottom 
#-----------------------------------------------------------------------
Schedule 2000 PipeRead 'echo EwmhBaseStruts 0 $(($[infostore.panel_width]+4)) 0 0'

#-----------------------------------------------------------------------
# IconBox defines the area where FVWM will place any windows that are
# in the iconic state: 
#  IconBox left top right bottom
#
# IconGrid ist the distance between each icon. Default grid is 3x3 pixels:
#  IconGrid x y
#
# IconFill defines the direction icons will place. Default is from left
# to right. To fill an icon box in columns instead of rows, specify the
# vertical direction (top or bottom) first.
#-----------------------------------------------------------------------
Style * IconBox 20 80 -$[infostore.panel_width] -20, \
        IconGrid 40 40, \
        IconFill left bottom, \
        StaysOnBottom


#=======================================================================
# Load layout elements
#=======================================================================
Load modules/GlobalIconMan
Load modules/ShowHide_GlobalIconMan
Load modules/Pager
Load modules/VerticalPanel

#=======================================================================
# Functions
#=======================================================================

AddToFunc StartFunction
# start event handler for GlobalIconMan with ShowHide
+ I Module FvwmEvent FvwmEventGlobalIconMan
#-----------------------------------------------------------------------
# start window list module
+ I Module FvwmIconMan GlobalIconMan
#-----------------------------------------------------------------------
# start Pager
+ I Module FvwmPager
#-----------------------------------------------------------------------
# start horizontal panel
+ I Module FvwmButtons VerticalPanel
#-----------------------------------------------------------------------
# start systray applets
+ I Wait stalonetray
+ I FuncStartSystrayApplets
#-----------------------------------------------------------------------


DestroyFunc ReloadLayoutParts
AddToFunc   ReloadLayoutParts
+ I PipeRead 'fns-built-trayapplist $FVWM_USERDIR/.systray.log $FVWM_USERDIR/.trayapplist'
+ I FuncUnsetDeskKeyBindings
+ I Load modules/VerticalPanel
+ I FuncRestartModuleByAlias FvwmButtons VerticalPanel
+ I Wait stalonetray
+ I Exec exec fns-start-programs reload_applets $[FVWM_USERDIR]/.trayapplist


#=======================================================================
# Bindings
#=======================================================================

#   Keyname Context Modifi  Function

#-----------------------------------------------------------------------
# Help info with SHIFT-CTRL-ALT P to show all page related key bindings
#-----------------------------------------------------------------------
key P           A           SCM         FuncShowMessage  "Page Key Bindings" \
"SHIFT-CTRL:" \
"Cursor right/left: Switch to page right/left" \
"Cursor up/down: Switch to page up/down" \
"1-n: Switch to page n" \
"SHIFT-ALT:" \
"Cursor right/left: Switch active window to page right/left" \
"Cursor up/down: Switch active window to page up/down" \
"1-n: Switch active window to page n" \
"ALT-CTRL:" \
"Cursor right/left/up/down: Move mouse pointer by 1% of a page" \
"SHIFT-ALT-CTRL:" \
"Cursor right/left/up/down: Scroll right/left/up/down by 10% of a page"

