#-----------------------------------------------------------------------
# File:         G2like
# Version:      1.2.3
# Licence:      GPL 2
#
# Description:  Gnome like layout with a top and bottom bar
#
# Author:       Thomas Funk <t.funk@web.de>    
#               Bernhard Popp <kermit.popp@googlemail.com>
#
# Created:      10/09/2012
# Changed:      05/28/2016
#-----------------------------------------------------------------------
#
# Topbar
# +---+---+--------+------------------------+----------+---------+---+
# |   |   |        |                        |          |         |   |
# +---+---+--------+------------------------+----------+---------+---+
# Menu     (Apps)                            Systray    Date    Logout
#    Personal

# Bottombar
# +---+----------------------------------------------+---------------+
# |   |                                              |               |
# +---+----------------------------------------------+---------------+
# Desktop                                             Pager
#      IconMan
#
#-----------------------------------------------------------------------


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

#=======================================================================
# General
#=======================================================================
#-----------------------------------------------------------------------
# set bar and tray icon size depending on the screen height
#-----------------------------------------------------------------------
PipeRead    'if [ "$[vp.height]" -gt "2800" ]; then \
                echo InfoStoreAdd i_size 40; \
            elif [ "$[vp.height]" -gt "2300" ]; then \
                echo InfoStoreAdd i_size 36; \
            elif [ "$[vp.height]" -gt "1800" ]; then \
                echo InfoStoreAdd i_size 32; \
            elif [ "$[vp.height]" -gt "1600" ]; then \
                echo InfoStoreAdd i_size 30; \
            elif [ "$[vp.height]" -gt "1300" ]; then \
                echo InfoStoreAdd i_size 28; \
            elif [ "$[vp.height]" -gt "1000" ]; then \
                echo InfoStoreAdd i_size 26; \
            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'


PipeRead "echo InfoStoreAdd column_size `perl -e 'printf \"%.0f\",$[infostore.i_size]/1.7'`"

PipeRead "echo InfoStoreAdd columns `perl -e 'printf \"%.0f\",$[vp.width]/$[infostore.column_size]'`"


#=======================================================================
# FvwmButtons TopBarG2
#=======================================================================

#-----------------------------------------------------------------------
# Bar height
#-----------------------------------------------------------------------
PipeRead "echo InfoStoreAdd bar_height `perl -e 'printf \"%.0f\",(-1.57E-6*$[vp.height]**2+0.017*$[vp.height]+17.929)'`"

#-----------------------------------------------------------------------
# Bar geometry
#-----------------------------------------------------------------------
InfoStoreAdd topbar_geometry $[vp.width]x$[infostore.bar_height]-0+0


#=======================================================================
# FvwmButtons G2likeBottomBar
#=======================================================================

#-----------------------------------------------------------------------
# Bar geometry
#-----------------------------------------------------------------------
InfoStoreAdd bottombar_geometry $[vp.width]x$[infostore.bar_height]+0-0


#=======================================================================
# 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 0 $(($[infostore.bar_height]+4)) $(($[infostore.bar_height]+4))'

#-----------------------------------------------------------------------
# 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 -100 -60, \
        IconGrid 40 40, \
        IconFill left bottom, \
        StaysOnBottom


#=======================================================================
# Load layout elements
#=======================================================================
Load modules/G2likeTopBar
Load modules/G2likeBottomBar
Load modules/Pager
Load modules/GlobalIconMan
Load modules/Bar_GlobalIconMan


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

AddToFunc StartFunction
#-----------------------------------------------------------------------
# start Pager
+ I Module FvwmPager
#-----------------------------------------------------------------------
# start window list module
+ I Module FvwmIconMan GlobalIconMan
#-----------------------------------------------------------------------
# start bottom bar panel
+ I Module FvwmButtons G2likeBottomBar
#-----------------------------------------------------------------------
# start top bar panel
+ I module FvwmButtons G2likeTopBar
#-----------------------------------------------------------------------
# start systray applets
+ I Wait stalonetray
+ I FuncStartSystrayApplets


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

DestroyFunc ShowDesktop
AddToFunc   ShowDesktop
+ I All (CurrentPage, Iconic, State 1) RestoreDesktop
+ I TestRc (Match) Break
+ I All (CurrentPage, !Iconic, !G2likeBottomBar, !G2likeTopBar, !State 1) ThisWindow State 1 True
+ I All (CurrentPage, !Iconic, !G2likeBottomBar, !G2likeTopBar, State 1) FuncThumbnail

DestroyFunc RestoreDesktop
AddToFunc   RestoreDesktop
+ I All (CurrentPage, Iconic, State 1) Iconify off
+ I All (CurrentPage, State 1) ThisWindow State 1 False


#=======================================================================
# 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" \
"1-n: Switch to page n" \
"SHIFT-ALT:" \
"Cursor right/left: Switch active window to page right/left" \
"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 by 10% of a page"
