#!/bin/sh
#-*- tcl -*- \
PATH=/usr/pkgsrc/sysutils/tkdesk/work/.destdir/usr/pkg/bin:$PATH ;#\
exec tkdesksh "$0" "$@"

set tkdesk(library) "/usr/pkgsrc/sysutils/tkdesk/work/.destdir/usr/pkg/lib/tkdesk"
set tkdesk(in_development) 0
set tkdesk(debug) 0

# Set the following variable to 0 to enable dynamic auto-loading of TkDesk's
# library files.  This usually improves start-up time.
set tkdesk(no_auto_loading) 1

#    TkDesk - a file manager for Unix and the X Window System
#    Copyright (C) 1996 Christian Bolik
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#    See the file "COPYING" in the base directory of this distribution
#    for more.

#
# =============================================================================
#
#                           START FILE FOR TKDESK
#
# =============================================================================
#

wm withdraw .
wm group . .
wm command . "$argv0 $argv"

#
# ==== Init ===================================================================
#

set tkdesk(version) "2.0b"
set tkdesk(date) "April 15, 2004"

if [info exists env(TKDESK_LIBRARY)] {
    set tkdesk(library) $env(TKDESK_LIBRARY)
}
if ![info exists tkdesk(library)] {
    set tkdesk(library) "./tcldesk"
}
if {[string index $tkdesk(library) 0] == "~"} {
    catch {set tkdesk(library) [glob $tkdesk(library)]}
}

if ![file exists $tkdesk(library)] {
    puts ""
    puts "Can't find the TkDesk run-time library.  Please either edit"
    puts "the first lines of the tkdesk script to point to where you"
    puts "installed the library, or set the environment variable"
    puts "TKDESK_LIBRARY accordingly.  Also please check that the"
    puts "correct tkdesksh is being used by the script."
    puts ""
    exit 2
}

if {![info exists dskC_version] || $dskC_version != $tkdesk(version)} {
    puts ""
    puts "The tkdesk script seems to be using an older version of tkdesksh."
    puts "Please edit the third line of this script to point to the absolute"
    puts "path and file name of tkdesksh.  Both are usually located in the"
    puts "same directory."
    puts ""
    puts "An alternative is also to modify your PATH environment variable to"
    puts "list the directory where you installed Tkdesk $tkdesk(version) before"
    puts "the one that contains the older tkdesksh."
    puts ""
    puts "The easiest method is of course to simply delete the old tkdesksh."
    puts ""
    exit 3
}
   
# -------------------------------------------------------
# Following is the bitmap used by dsk_welcome:

set tkdesk(welcome_bm) {
#define tkdesk_width 253
#define tkdesk_height 66
static char tkdesk_bits[] = {
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x0e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x1c,0x00,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0xf8,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x1f,0x00,0x00,0xe0,0x00,0x00,0x00,
 0x00,0x00,0x00,0xc0,0xff,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xff,0x0f,0x00,0x00,0xe0,0x00,
 0x00,0x00,0x00,0x00,0x00,0xc0,0xff,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xff,0x0f,0x00,0x00,
 0xe0,0x00,0xfe,0xff,0xff,0xff,0xff,0x0f,0xfc,0x07,0x00,0x00,0x00,0xff,0xff,
 0xff,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0x0f,
 0x00,0x00,0xe0,0x00,0xfe,0xff,0xff,0xff,0xff,0x07,0xf0,0x07,0x00,0x00,0x00,
 0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0xe0,0x0f,0x00,0x00,0xe0,0x00,0xfe,0xff,0xff,0xff,0xff,0x07,0xf0,0x03,0x00,
 0x00,0x00,0xff,0xff,0xff,0xff,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0xe0,0x07,0x00,0x00,0xe0,0x00,0xff,0x00,0xfc,0x01,0xf8,0x07,0xf0,
 0x03,0x00,0x00,0x00,0xc0,0x3f,0x00,0xfc,0x1f,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0xe0,0x07,0x00,0x00,0xe0,0x00,0x3f,0x00,0xfc,0x01,0xe0,
 0x07,0xf8,0x03,0x00,0x00,0x00,0xc0,0x1f,0x00,0xc0,0x3f,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x07,0x00,0x00,0xe0,0x00,0x0f,0x00,0xfc,
 0x01,0xc0,0x07,0xf8,0x03,0x00,0x00,0x00,0xc0,0x1f,0x00,0x00,0xff,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x07,0x00,0x00,0xe0,0x00,0x07,
 0x00,0xfe,0x00,0x80,0x03,0xf8,0x01,0x00,0x00,0x00,0xc0,0x1f,0x00,0x00,0xfe,
 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x03,0x00,0x00,0xe0,
 0x80,0x07,0x00,0xfe,0x00,0x80,0x03,0xf8,0x01,0x00,0x00,0x00,0xe0,0x1f,0x00,
 0x00,0xfc,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x03,0x00,
 0x00,0xe0,0x80,0x03,0x00,0xfe,0x00,0x80,0x03,0xfc,0x01,0x00,0x00,0x00,0xe0,
 0x0f,0x00,0x00,0xf8,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,
 0x03,0x00,0x00,0xe0,0x80,0x03,0x00,0xfe,0x00,0x80,0x03,0xfc,0x01,0x00,0x00,
 0x00,0xe0,0x0f,0x00,0x00,0xf0,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0xf8,0x03,0x00,0x00,0xe0,0x80,0x01,0x00,0xfe,0x00,0x80,0x01,0xfc,0x01,
 0x00,0x00,0x00,0xe0,0x0f,0x00,0x00,0xf0,0x07,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0xf8,0x03,0x00,0x00,0xe0,0x80,0x01,0x00,0x7f,0x00,0x80,0x01,
 0xfc,0x00,0x00,0x00,0x00,0xe0,0x0f,0x00,0x00,0xe0,0x0f,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0xf8,0x01,0x00,0x00,0xe0,0xc0,0x01,0x00,0x7f,0x00,
 0x80,0x01,0xfc,0x00,0x00,0x00,0x00,0xf0,0x07,0x00,0x00,0xe0,0x0f,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf8,0x01,0x00,0x00,0xe0,0x00,0x00,0x00,
 0x7f,0x00,0x00,0x00,0xfe,0x00,0x00,0x00,0x00,0xf0,0x07,0x00,0x00,0xe0,0x1f,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfc,0x01,0x00,0x00,0xe0,0x00,
 0x00,0x00,0x7f,0x00,0x00,0x00,0xfe,0x00,0x80,0x0f,0x00,0xf0,0x07,0x00,0x00,
 0xc0,0x1f,0x00,0x00,0xf0,0x07,0x00,0x00,0x7f,0x00,0x00,0xfc,0x01,0x00,0x1f,
 0xe0,0x00,0x00,0x80,0x3f,0x00,0x00,0x00,0x7e,0x00,0xe0,0x1f,0x00,0xf0,0x07,
 0x00,0x00,0xc0,0x1f,0x00,0x00,0xfe,0x3f,0x00,0xe0,0xff,0x03,0x00,0xfc,0x00,
 0xc0,0x3f,0xe0,0x00,0x00,0x80,0x3f,0x00,0x00,0x00,0x7e,0x00,0xf0,0x3f,0x00,
 0xf8,0x07,0x00,0x00,0xc0,0x3f,0x00,0xc0,0xff,0x7f,0x00,0xf0,0xff,0x07,0x00,
 0xfc,0x00,0xe0,0x7f,0xe0,0x00,0x00,0x80,0x3f,0x00,0x00,0x00,0x7f,0x00,0xfc,
 0x3f,0x00,0xf8,0x03,0x00,0x00,0xc0,0x3f,0x00,0xe0,0x07,0xff,0x00,0xf8,0xf0,
 0x0f,0x00,0xfe,0x00,0xf8,0x7f,0xe0,0x00,0x00,0x80,0x3f,0x00,0x00,0x00,0x7f,
 0x00,0xfe,0x3f,0x00,0xf8,0x03,0x00,0x00,0xc0,0x3f,0x00,0xf8,0x01,0xfe,0x00,
 0x3c,0xe0,0x1f,0x00,0xfe,0x00,0xfc,0x7f,0xe0,0x00,0x00,0x80,0x3f,0x00,0x00,
 0x00,0x3f,0x00,0xff,0x3f,0x00,0xf8,0x03,0x00,0x00,0xc0,0x3f,0x00,0xfc,0x00,
 0xfc,0x01,0x3e,0xc0,0x1f,0x00,0x7e,0x00,0xfe,0x7f,0xe0,0x00,0x00,0xc0,0x1f,
 0x00,0x00,0x00,0x3f,0x80,0xc7,0x1f,0x00,0xf8,0x03,0x00,0x00,0xc0,0x3f,0x00,
 0x7e,0x00,0xfc,0x01,0x1e,0x80,0x1f,0x00,0x7e,0x00,0x8f,0x3f,0xe0,0x00,0x00,
 0xc0,0x1f,0x00,0x00,0x80,0x3f,0xc0,0x01,0x0f,0x00,0xfc,0x01,0x00,0x00,0xc0,
 0x3f,0x00,0x3f,0x00,0xfc,0x01,0x1e,0x80,0x1f,0x00,0x7f,0x80,0x03,0x1e,0xe0,
 0x00,0x00,0xc0,0x1f,0x00,0x00,0x80,0x3f,0xe0,0x00,0x00,0x00,0xfc,0x01,0x00,
 0x00,0xc0,0x3f,0x80,0x1f,0x00,0xfc,0x01,0x1f,0x00,0x1f,0x00,0x7f,0xc0,0x01,
 0x00,0xe0,0x00,0x00,0xc0,0x1f,0x00,0x00,0x80,0x3f,0x70,0x00,0x00,0x00,0xfc,
 0x01,0x00,0x00,0xc0,0x3f,0xc0,0x1f,0x00,0xfc,0x01,0x1f,0x00,0x06,0x00,0x7f,
 0xe0,0x00,0x00,0xe0,0x00,0x00,0xe0,0x0f,0x00,0x00,0x80,0x1f,0x38,0x00,0x00,
 0x00,0xfc,0x01,0x00,0x00,0xc0,0x3f,0xc0,0x0f,0x00,0xfe,0x01,0x3f,0x00,0x00,
 0x00,0x3f,0x70,0x00,0x00,0xe0,0x00,0x00,0xe0,0x0f,0x00,0x00,0xc0,0x1f,0x1c,
 0x00,0x00,0x00,0xfe,0x00,0x00,0x00,0xc0,0x3f,0xe0,0x0f,0x00,0xfe,0x00,0x3f,
 0x00,0x00,0x80,0x3f,0x38,0x00,0x00,0xe0,0x00,0x00,0xe0,0x0f,0x00,0x00,0xc0,
 0x1f,0x0e,0x00,0x00,0x00,0xfe,0x00,0x00,0x00,0xe0,0x3f,0xf0,0x07,0x00,0xff,
 0x00,0x7f,0x00,0x00,0x80,0x3f,0x1c,0x00,0x00,0xe0,0x00,0x00,0xe0,0x0f,0x00,
 0x00,0xc0,0x1f,0x07,0x00,0x00,0x00,0xfe,0x00,0x00,0x00,0xe0,0x1f,0xf0,0x07,
 0x00,0x7f,0x00,0xff,0x00,0x00,0x80,0x3f,0x0e,0x00,0x00,0xe0,0x00,0x00,0xf0,
 0x07,0x00,0x00,0xc0,0x8f,0x03,0x00,0x00,0x00,0xfe,0x00,0x00,0x00,0xe0,0x1f,
 0xf8,0x03,0x80,0x3f,0x00,0xff,0x01,0x00,0x80,0x1f,0x07,0x00,0x00,0xe0,0x00,
 0x00,0xf0,0x07,0x00,0x00,0xc0,0xcf,0x03,0x00,0x00,0x00,0xff,0x00,0x00,0x00,
 0xe0,0x1f,0xf8,0x03,0xc0,0x1f,0x00,0xfe,0x03,0x00,0x80,0x9f,0x07,0x00,0x00,
 0xe0,0x00,0x00,0xf0,0x07,0x00,0x00,0xe0,0xef,0x07,0x00,0x00,0x00,0x7f,0x00,
 0x00,0x00,0xf0,0x1f,0xf8,0x03,0xf0,0x0f,0x00,0xfe,0x07,0x00,0xc0,0xdf,0x0f,
 0x00,0x00,0xe0,0x00,0x00,0xf0,0x07,0x00,0x00,0xe0,0xef,0x07,0x00,0x00,0x00,
 0x7f,0x00,0x00,0x00,0xf0,0x0f,0xfc,0x01,0xf8,0x03,0x00,0xfc,0x0f,0x00,0xc0,
 0xdf,0x0f,0x00,0x00,0xe0,0x00,0x00,0xf0,0x07,0x00,0x00,0xe0,0xf7,0x07,0x00,
 0x00,0x00,0x7f,0x00,0x00,0x00,0xf0,0x0f,0xfc,0x01,0xfe,0x01,0x00,0xf8,0x1f,
 0x00,0xc0,0xef,0x0f,0x00,0x00,0xe0,0x00,0x00,0xf8,0x03,0x00,0x00,0xe0,0xe7,
 0x0f,0x00,0x00,0x00,0x7f,0x00,0x00,0x00,0xf8,0x0f,0xfc,0xc1,0x3f,0x00,0x00,
 0xf0,0x3f,0x00,0xc0,0xcf,0x1f,0x00,0x00,0xe0,0x00,0x00,0xf8,0x03,0x00,0x00,
 0xf0,0xe7,0x0f,0x00,0x00,0x80,0x3f,0x00,0x00,0x00,0xf8,0x07,0xfc,0xf9,0x0f,
 0x00,0x00,0xe0,0x7f,0x00,0xe0,0xcf,0x1f,0x00,0x00,0xe0,0x00,0x00,0xf8,0x03,
 0x00,0x00,0xf0,0xe7,0x0f,0x00,0x00,0x80,0x3f,0x00,0x00,0x00,0xfc,0x07,0xfe,
 0xff,0x01,0x00,0x00,0xc0,0x7f,0x00,0xe0,0xcf,0x1f,0x00,0x00,0xe0,0x00,0x00,
 0xf8,0x03,0x00,0x00,0xf0,0xc7,0x1f,0x00,0x00,0x80,0x3f,0x00,0x00,0x00,0xfc,
 0x03,0xfe,0x1f,0x00,0x00,0x00,0x80,0xff,0x00,0xe0,0x8f,0x3f,0x00,0x00,0xe0,
 0x00,0x00,0xfc,0x01,0x00,0x00,0xf0,0xc3,0x1f,0x00,0x00,0x80,0x3f,0x00,0x00,
 0x00,0xfe,0x03,0xfe,0x01,0x00,0x00,0x00,0x00,0xff,0x00,0xe0,0x87,0x3f,0x00,
 0x00,0xe0,0x00,0x00,0xfc,0x01,0x00,0x00,0xf8,0xc3,0x1f,0x00,0x00,0xc0,0x3f,
 0x00,0x00,0x00,0xfe,0x01,0xfe,0x00,0x00,0x00,0x00,0x00,0xfe,0x01,0xf0,0x87,
 0x3f,0x00,0x00,0xe0,0x00,0x00,0xfc,0x01,0x00,0x00,0xf8,0x83,0x3f,0x00,0x00,
 0xc0,0x1f,0x00,0x00,0x00,0xff,0x00,0xfe,0x00,0x00,0x00,0x00,0x00,0xfc,0x01,
 0xf0,0x07,0x7f,0x00,0x00,0xe0,0x00,0x00,0xfc,0x01,0x00,0x00,0xf8,0x83,0x3f,
 0x00,0x00,0xc0,0x1f,0x00,0x00,0x80,0xff,0x00,0xfe,0x00,0x00,0x00,0x00,0x00,
 0xfc,0x01,0xf0,0x07,0x7f,0x00,0x00,0xe0,0x00,0x00,0xfc,0x01,0x00,0x00,0xf8,
 0x01,0x7f,0x00,0x00,0xc0,0x1f,0x00,0x00,0xc0,0x7f,0x00,0xfe,0x00,0x00,0x18,
 0x00,0x00,0xfc,0x01,0xf0,0x03,0xfe,0x00,0x00,0xe0,0x00,0x00,0xfe,0x00,0x00,
 0x00,0xfc,0x01,0x7f,0x00,0x06,0xe0,0x1f,0x00,0x00,0xc0,0x3f,0x00,0xfe,0x00,
 0x00,0x1c,0x78,0x00,0xf8,0x01,0xf8,0x03,0xfe,0x00,0x0c,0xe0,0x00,0x00,0xfe,
 0x00,0x00,0x00,0xfc,0x01,0xff,0x00,0x06,0xe0,0x0f,0x00,0x00,0xf0,0x1f,0x00,
 0xfe,0x01,0x00,0x1e,0x7c,0x00,0xf8,0x01,0xf8,0x03,0xfe,0x01,0x0c,0xe0,0x00,
 0x00,0xfe,0x00,0x00,0x00,0xfc,0x01,0xfe,0x00,0x07,0xe0,0x0f,0x00,0x00,0xf8,
 0x0f,0x00,0xfe,0x01,0x00,0x0e,0x7e,0x00,0xf8,0x01,0xf8,0x03,0xfc,0x01,0x0e,
 0xe0,0x00,0x00,0xfe,0x00,0x00,0x00,0xfc,0x00,0xfe,0x01,0x03,0xe0,0x0f,0x00,
 0x00,0xfc,0x07,0x00,0xfc,0x01,0x80,0x07,0xfe,0x00,0xf8,0x00,0xf8,0x01,0xfc,
 0x03,0x06,0xe0,0x00,0x00,0x7f,0x00,0x00,0x00,0xfc,0x00,0xfc,0x81,0x03,0xe0,
 0x0f,0x00,0x00,0xff,0x01,0x00,0xfc,0x03,0xc0,0x03,0xfe,0x00,0xf8,0x00,0xf8,
 0x01,0xf8,0x03,0x07,0xe0,0x00,0x00,0x7f,0x00,0x00,0x00,0xfe,0x00,0xfc,0xc3,
 0x01,0xf0,0x0f,0x00,0xe0,0xff,0x00,0x00,0xfc,0x07,0xe0,0x01,0xfe,0x01,0x7c,
 0x00,0xfc,0x01,0xf8,0x87,0x03,0xe0,0x00,0x80,0xff,0x00,0x00,0x00,0xfe,0x00,
 0xf8,0xe7,0x00,0xf0,0x1f,0x00,0xfe,0x3f,0x00,0x00,0xf8,0x0f,0xfc,0x00,0xfc,
 0x03,0x7c,0x00,0xfc,0x01,0xf0,0xcf,0x01,0xe0,0x00,0xe0,0xff,0x03,0x00,0x00,
 0xfe,0x00,0xf8,0xff,0xe0,0xff,0xff,0xff,0xff,0x07,0x00,0x00,0xf0,0xff,0x7f,
 0x00,0xf8,0x0f,0x3e,0x00,0xfc,0x01,0xf0,0xff,0x01,0xe0,0x00,0xff,0xff,0x7f,
 0x00,0x00,0x7e,0x00,0xf0,0x7f,0xe0,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0xe0,
 0xff,0x1f,0x00,0xf0,0xff,0x1f,0x00,0xfc,0x00,0xe0,0xff,0x00,0xe0,0x00,0xff,
 0xff,0x7f,0x00,0x00,0x7f,0x00,0xe0,0x3f,0xe0,0xff,0xff,0xff,0x07,0x00,0x00,
 0x00,0xc0,0xff,0x07,0x00,0xe0,0xff,0x07,0x00,0xfe,0x00,0xc0,0x7f,0x00,0xe0,
 0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0x00,0x80,0x0f,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0xfe,0x00,0x00,0x00,0xff,0x00,0x00,0x1e,0x00,0x00,0x1f,
 0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xe0};
}

#
# -----------------------------------------------------------------------------
#
# Proc:    dsk_welcome
# Desc:    Shows an informational "welcome" window when starting up.
# In:      cmd: "show" or "hide"
# Out:     ""
# Side FX: none
#

proc dsk_welcome {cmd} {
    global tkdesk

    #set bgcol gray
    set bgcol gray82
    set t .dsk_welcome

    if {$cmd == "hide"} {
	catch "destroy $t"
	return ""
    }
    
    toplevel $t -bg $bgcol
    wm withdraw $t
    wm group $t .
    wm command $t
    
    frame $t.f -bd 2 -relief raised -bg $bgcol
    pack $t.f

    frame $t.f1 -bd 2 -relief groove -bg $bgcol
    pack $t.f1 -in $t.f -padx 8 -pady 8

    label $t.lLabel -text "Welcome to..." -anchor center -fg black -bg $bgcol
    catch {$t.lLabel config -font -*-helvetica-medium-r-*-*-14-*}
    pack $t.lLabel -in $t.f1 -padx 8 -pady 8 -fill x -expand yes

    if {[file exists $tkdesk(library)/images/tkdesk_logo.ppm]} {
        image create photo welcome_bm -file $tkdesk(library)/images/tkdesk_logo.ppm
        label $t.lTkDesk -image welcome_bm -bg $bgcol -relief raised -bd 10
    } else {
        image create bitmap welcome_bm -data $tkdesk(welcome_bm) -foreground blue3
        label $t.lTkDesk -image welcome_bm -bg $bgcol
    }	
    pack $t.lTkDesk -in $t.f1 -padx 6 -pady 2 -fill x -expand yes

    message $t.lVersion -text "Version $tkdesk(version), dated $tkdesk(date)\nCopyright (C) 1996 Christian Bolik\n\nTkDesk comes with ABSOLUTELY NO WARRANTY.\nSee menu entry Help/License for details." \
	    -bg $bgcol -fg black \
	    -aspect 1000 -justify center
    catch {$t.lVersion config -font -*-helvetica-medium-r-*-*-14-*}
    pack $t.lVersion -in $t.f1 -padx 8 -pady 8 -fill x -expand yes

    if $tkdesk(in_development) {
	label $t.lDevel -text "...in Development..." \
		-bg $bgcol -fg black
	catch {$t.lDevel config -font -*-helvetica-bold-o-*-*-14-*}
	pack $t.lDevel -in $t.f1 -padx 8 -pady 8 -fill x -expand yes
    }

    frame $t.f2 -bd 2 -relief groove -bg $bgcol
    pack $t.f2 -in $t.f -fill x -padx 8 -pady 8
    
    label $t.lProgress -text "Loading..." -anchor w \
	    -bg $bgcol -fg black -width 25
    pack $t.lProgress -in $t.f2 -fill x -anchor w -padx 8

    update idletasks
    set x [expr [winfo screenwidth $t]/2 - [winfo reqwidth $t]/2 \
	    - [winfo vrootx [winfo parent $t]]]
    set y [expr [winfo screenheight $t]/2 - [winfo reqheight $t]/2 \
	    - [winfo vrooty [winfo parent $t]]]
    wm geom $t +$x+$y
    wm title $t "Starting..."
    wm deiconify $t
    update

    return ""
}

proc dsk_progress {string} {
    if ![winfo exists .dsk_welcome] return
    
    .dsk_welcome.lProgress config -text $string
    update idletasks
}

set tkdesk(error_source) ""
proc tkerror {err} {
    global tkdesk errorCode errorInfo tk_patchLevel tcl_patchLevel
    global blt_version itcl::version

    set code $errorCode
    set info $errorInfo
    
    if [winfo exists .dsk_tkerror] return
    
    cd ~
    dsk_lazy force
    dsk_sound dsk_bug
    
    if {$tkdesk(error_source) == "" || $tkdesk(in_development)} {
	set ans [tk_dialog [toplevel .dsk_tkerror] \
		"Oh no, an error!" \
		"Sorry, but you have just found an error in TkDesk. You can ignore it or choose one of the actions below." \
		@$tkdesk(library)/images/xbm/bomb.xbm \
		0 " Ignore " " Inspect " " Mail Author "]
    } else {
	set ans [tk_dialog [toplevel .dsk_tkerror] \
		"Configuration Error" \
		"Error while executing action from \"$tkdesk(error_source)\":\n$err" \
		error 0 "   OK   " " Inspect "]
	set tkdesk(error_source) ""
    }

    switch $ans {
	1 {dsk_editor string "Error: $err\n\nerrorCode: $code\n\nerrorInfo: $info"}
	2 {
	    set subject "Error in TkDesk $tkdesk(version)"
	    set msg "What did you try to do when this bug occured:\n"
	    append msg "\n\n-----------------------------------------------"
	    append msg "\nError in TkDesk $tkdesk(version), using "
	    append msg "Tcl [set tcl_patchLevel], "
	    append msg "Tk [set tk_patchLevel], "
	    if [info exists itcl::version] {
		append msg "Itcl [set itcl::version], "
	    } else {
		append msg "Itcl 1.5, "
	    }
	    append msg "BLT [set blt_version].\nPlatform: "
	    catch {append msg "[exec uname -a]\n"}
	    append msg "\n"
	    append msg "Error: $err\n"
	    append msg "errorCode: $code\n"
	    append msg "errorInfo: $info"

	    dsk_mailbug $subject $msg
	}
    }
    
    return ""
}

proc dsk_mailbug {subject msg} {
    global tkdesk dsk_mailbug

    catch {destroy .dsk_mailbug}
    toplevel [set t .dsk_mailbug]
    wm withdraw $t

    frame $t.f1 -bd 1 -relief raised
    pack $t.f1 -fill x
    label $t.ls -text "Subject:"
    pack $t.ls -in $t.f1 -side left -padx 4 -pady 4
    entry $t.es -width 10 -bd 2 -relief sunken
    $t.es insert end $subject
    pack $t.es -in $t.f1 -side left -fill x -expand yes \
	    -padx 4 -pady 4 -ipady 2

    frame $t.f2 -bd 1 -relief raised
    pack $t.f2 -fill both -expand yes
    frame $t.f2a
    pack $t.f2a -in $t.f2 -fill both -expand yes -padx 4 -pady 4
    text $t.tm -width 10 -height 4 -bd 2 -relief sunken -setgrid 1 \
	    -yscroll "$t.sb set"
    $t.tm insert end "$msg"
    $t.tm mark set insert 2.0
    pack $t.tm -in $t.f2a -side left -fill both -expand yes
    scrollbar $t.sb -orient vertical -command "$t.tm yview"
    pack $t.sb -in $t.f2a -side left -fill y

    frame $t.f3 -bd 1 -relief raised
    pack $t.f3 -fill x
    button $t.bc -text "Cancel" \
	    -command "set dsk_mailbug(mail) 0"
    button $t.bs -text "Save..." \
	    -command "set dsk_mailbug(mail) 2"
    button $t.bm -text "Send Mail to $tkdesk(maintmail)" \
	    -command "set dsk_mailbug(mail) 1"
    pack $t.bc $t.bs $t.bm -in $t.f3 -side left -padx 4 -pady 4 -ipady 1

    wm protocol $t WM_DELETE_WINDOW "set dsk_mailbug(mail) 0"
    if {$msg != ""} {
	wm title $t "Mail Bug Report to Author"
    } else {
	wm title $t "Send Mail to Author"
    }
    wm geometry $t 38x15
    cb_centerToplevel $t
    wm deiconify $t

    focus $t.tm
    grab $t
    set dsk_mailbug(mail) ""
    tkwait variable dsk_mailbug(mail)

    if {$dsk_mailbug(mail) == 1} {
	catch {set fd [open "|mail -s \"$subject\" $tkdesk(maintmail)" w]} em
	if ![info exists fd] {
	    catch {set fd [open "|mail $tkdesk(maintmail)" w]} em
	}
	if ![info exists fd] {
	    cb_error "Couldn't execute: mail $tkdesk(maintmail). Please send your bug report manually."
	    tkwait variable dsk_mailbug(mail)
	} else {
	    set msg [$t.tm get 1.0 end]
	    puts -nonewline $fd $msg
	    close $fd
	}
    } elseif {$dsk_mailbug(mail) == 2} {
	while 1 {
	    set f [cb_fileSelector -label "Save bug report"]
	    if {$f != ""} {
		set err [catch {set fd [open $f "w"]}]
		if $err {
		    cb_error "Couldn't open $f for writing."
		} else {
		    set msg [$t.tm get 1.0 end]
		    puts -nonewline $fd $msg
		    close $fd
		    break
		}
	    } else {
		break
	    }
	}
    }
    destroy $t
}

proc dsk_widget_config {} {
    global tkdesk
    
    dsk_Listbox::selcolor [cb_col $tkdesk(color,listsel)]
    dsk_Listbox::modifier $tkdesk(use_old_modifiers)

    # "System" Settings
    dsk_FileListbox::font [cb_font $tkdesk(font,file_lbs)]

    dsk_FileListbox::tag config dir \
	    [cb_col $tkdesk(color,directories)] \
	    [cb_font $tkdesk(font,directories)]
    dsk_FileListbox::tag config exec \
	    [cb_col $tkdesk(color,executables)] \
	    [cb_font $tkdesk(font,executables)]
    dsk_FileListbox::tag config sym \
	    [cb_col $tkdesk(color,symlinks)] \
	    [cb_font $tkdesk(font,symlinks)]
    dsk_FileListbox::tag config symdir \
	    [cb_col $tkdesk(color,symdirectories)] \
	    [cb_font $tkdesk(font,symdirectories)]
    dsk_FileListbox::tag config symexec \
	    [cb_col $tkdesk(color,symexecutables)] \
	    [cb_font $tkdesk(font,symexecutables)]

    # "Preferences" Settings
    dsk_FileListbox::showall $tkdesk(show_all_files)
    dsk_FileListbox::longlist $tkdesk(long_listing)
    dsk_FileListbox::topfolders $tkdesk(folders_on_top)
    dsk_FileListbox::typechar $tkdesk(append_type_char)
    dsk_FileListbox::addicons $tkdesk(add_icons)
    dsk_FileListbox::sort $tkdesk(default_sort)

    # "FileTags" Settings
    dsk_FileListbox_fileTags
}

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

if {$tkdesk(library) == "./tcldesk"} {
    # need an absolute library path
    set tkdesk(library) [pwd]/tcldesk
}

# See if the user just wants to learn TkDesk's command line arguments:
if {$argv == "-?" || $argv == "--help"} {
    puts -nonewline \
"TkDesk - A Graphical Desktop and File Manager for UNIX and X11
Version $tkdesk(version), dated $tkdesk(date)
Copyright (C) 1996 Christian Bolik

Usage: tkdesk \[options\]

Options may be any combination of the following:

    -configdir <dir>       Read user configuration from <dir>.
    -debug                 Enable so-called debug mode.
    -default               Use default user configuration found in:
                           $tkdesk(library)/configs
    -develop               Enable development mode.
    -iconic                Iconify all windows of TkDesk on start-up.
    -layout <file>         Read the window layout from <file>.
    -startdir <dir>        Display <dir> in first file browser.
    -twm                   Disable use of colored icon windows.
"
exit 0
}

dsk_welcome show

# store Tcl version for compatibility handling
set tkdesk(tcl_version) [info tclversion]

# "Uglify" ;-) namespaced BLT:
if {$tkdesk(tcl_version) >= 8.0} {
    namespace import blt::*
}

# Update BLT lib path
# (Fix this: depending on certain BLT lib files is a bit unreliable...)
if {![file exists $blt_library/bltDragdrop.tcl] &&
    ![file exists $blt_library/dragdrop.tcl]} {
    set blt_library $tkdesk(library)
    #puts "blt_library: $blt_library"
}

if {[info command bgexec] != ""} {
    rename bgexec blt_bgexec
}
if {[info command busy] != ""} {
    rename busy blt_busy
}
if {[info command drag&drop] != ""} {
    # this must be handled differently due to internal bindings:
    proc blt_drag&drop {args} {
	eval drag&drop $args
    }
}

#
# Init cb_tools
#

dsk_progress "Initializing cb_tools..."
set cb_tools(path) [glob "$tkdesk(library)/cb_tools"]
source $cb_tools(path)/tools.tcl

cb_tools_init $cb_tools(path) \
	      $tkdesk(in_development) \
	      $tkdesk(no_auto_loading)

#cb_debug trace wm
#cb_debug trace update
#cb_debug trace cb_image

#
# Init tcldesk
#

if {[info command grab-orig] == ""} {
    rename grab grab-orig
    proc grab {args} {
	set ret ""
	catch {set ret [eval grab-orig $args]}
	return $ret
    }
}

#if {[info command itcl_class-orig] == ""} {
#    rename itcl_class itcl_class-orig
#    proc itcl_class {name def} {
#	 catch {rename $name {}}
#	 uplevel 1 itcl_class-orig $name [list $def]
#    }
#}
proc itcl_class {name def} {
    catch {itcl::delete class $name}
    uplevel 1 itcl::class $name [list $def]
}

# Provide backward-compatibility for "history:"
# (force auto-loading of ::history for Tcl 8.0)
catch {history}
if {[info command history-orig] == "" && [info command history] != ""} {
    rename history history-orig
    proc history {args} {
	set ret {}
	set err [catch {set ret [eval dir_history $args]}]
	if $err {
	    set ret [eval history-orig $args]
	}
	return $ret
    }
}

# Give options set in tk_setPalette higher priority (to override weird
# CDE resources, for instance):
catch {tk_setPalette}
if [regsub {widgetDefault} [info body tk_setPalette] {interactive} nb] {
    proc tk_setPalette [info args tk_setPalette] $nb
    unset nb
}

dsk_progress "Initializing tcldesk..."
foreach c [itcl::find classes dsk_*] {
    catch {itcl::delete class $c}
}

if $tkdesk(no_auto_loading) {
    set tkdesk(color,listsel) white
    set libfiles {
	config.tcl
	Frame.tcl         
	Toplevel.tcl         
	Common.tcl         
	Desktop.tcl        
	DiskUsage.tcl      
	Editor.tcl         
	FileInfo.tcl       
	FileListbox.tcl    
	HistEntry.tcl
	List.tcl           
	Periodic.tcl       
	Viewer.tcl         
	action.tcl         
	annotations.tcl    
	appbar-date.tcl    
	appbar-dialup.tcl  
	appbar-load.tcl    
	appbar-mail.tcl    
	appbar-trash.tcl   
	appbar.tcl         
	bookmarks.tcl      
	copy.tcl      
	cpanels.tcl
	bltDnd.tcl
	bltDragdrop.tcl
	delete.tcl    
	diary.tcl     
	dsk_Listbox.tcl
	envedit.tcl
	file_ops.tcl  
	find.tcl      
	help.tcl      
	history.tcl   
	itcl_reload.tcl
	jdb_rcs.tcl   
	jobs.tcl      
	popup.tcl     
	server.tcl    
	sound.tcl     
	update.tcl    
	util.tcl
    }
    foreach f $libfiles {
	#puts "sourcing $tkdesk(library)/$f"
	dsk_progress "Initializing tcldesk... ($f)"
	source $tkdesk(library)/$f
    }
} else {
    set auto_path "$tkdesk(library) $auto_path"
}
    
if $tkdesk(in_development) {
    blt_drag&drop errors tkerror
} else {
    blt_drag&drop errors ""
}

# Disable BLT's built-in d&d bindings (except for motion):
catch {
    bind BltDrag&DropButton2 <Button-2> {}
    bind BltDrag&DropButton2 <ButtonRelease-2> {}
}

#
# ====  Set misc. global variables ============================================
#

# Christian is still the author, of course, but I'm not sure he wants
# to see these emails anymore.  I'm not even sure this address is still
# valid...
#set tkdesk(authormail) "Christian.Bolik@mainz.netsurf.de"
set tkdesk(authormail) "jchris@users.sourceforge.net"
set tkdesk(maintmail) "jchris@users.sourceforge.net"
set tkdesk(startdir) [pwd]
set tkdesk(initdir) $tkdesk(startdir)
set tkdesk(menu,control) 0	;# used to track <control> in menu invocations
set tkdesk(file_lb,control) 0	;# used to track <control> in file LBs
set tkdesk(active_viewer) ""	;# contains name of window last entered
set tkdesk(button_bar) ""	;# list for the button bar
set tkdesk(xmaster) 0		;# X "master" app
set tkdesk(status) lazy         ;# busy or lazy
set tkdesk(_dd_x) 0
set tkdesk(_dd_y) 0
set tkdesk_filelb_cmd ""
set tkdesk(systype) ""
catch {set tkdesk(systype) [exec uname]}

proc _menuEntryHeight {} {
    menu .m
    .m add command -label "TkDesk:"; update; set rw1 [winfo reqheight .m]
    .m add command -label "Cool!"; update; set rw2 [winfo reqheight .m]
    #puts "$rw2 - $rw1"
    return [expr $rw2 - $rw1]
}
set tkdesk(_max_menu_entries) \
	[expr [winfo screenheight .] / ([_menuEntryHeight] + 1)]

# Temp dir to use by this TkDesk:
set tkdesk(tmpdir) /tmp/tkdesk[pid]
set err [catch {
    exec rm -rf $tkdesk(tmpdir)
    exec mkdir $tkdesk(tmpdir)
} errmsg]
if {$err} {
    puts stderr "TkDesk: Couldn't create temp dir $tkdesk(tmpdir)"
    puts stderr "TkDesk: errmsg: $errmsg"
    puts stderr "TkDesk: Exiting"
    exit 1
}

# use icon windows by default
set tkdesk(fvwm) 1

# Overwrite cb_tools' busy and lazy commands:
set cb_tools(busy_cmd) dsk_busy
set cb_tools(lazy_cmd) dsk_lazy

# cd to user's home dir cause this is unlikely to be moved/deleted
cd $env(HOME)

#
# ==== Process command line arguments =========================================
#

dsk_busy
dsk_progress "Processing command line options..."
dsk_debug "Processing cmdline arguments"
set tkdesk(iconic) 0
if {$argc > 0} {
    for {set i 0} {$i < [llength $argv]} {incr i} {
	set o [lindex $argv $i]
	switch -glob -- $o {
	    -conf* {
		incr i
		set tkdesk(configdir) [lindex $argv $i]
		if {[string index $tkdesk(configdir) 0] != "/" && \
		    [string index $tkdesk(configdir) 0] != "~"} {
		    set tkdesk(configdir) $tkdesk(startdir)/$tkdesk(configdir)
		}
	    }
	    -deb* {
		set tkdesk(debug) 1
		dsk_debug "Debugging enabled (hopefully :-))"
	    }
	    -def* {
		set tkdesk(configdir) $tkdesk(library)/configs
		dsk_debug "Reading default configuration."
	    }
	    -dev* {
		set tkdesk(in_development) 1
		dsk_debug "Development mode."
	    }
	    -fvwm {
		set tkdesk(fvwm) 1
		dsk_debug "Fvwm mode forced."
	    }
	    -ic* {
		set tkdesk(iconic) 1
		dsk_debug "Iconic startup."
	    }
	    -lay* {
		incr i
		set tkdesk(layout_file) [lindex $argv $i]
		if {[string index $tkdesk(layout_file) 0] != "/" && \
		    [string index $tkdesk(layout_file) 0] != "~"} {
		    set tkdesk(layout_file) \
			    $tkdesk(startdir)/$tkdesk(layout_file)
		}
	    }
	    -sta* {
		incr i
		set tkdesk(user,startdir) [lindex $argv $i]
	    }
	    -twm {
		set tkdesk(fvwm) 0
		dsk_debug "Fvwm mode switched off."
	    }
	    -xm* {
		set tkdesk(xmaster) 1
	    }
	    default {
		if {[string index $o 0] == "-"} {
		    puts "Don't know what $o means. Proceding anyway."
		} else {
		    set tkdesk(initdir) $o
		    dsk_debug " tkdesk(initdir) = $tkdesk(initdir)"
		}
	    }
	}
    }
}

#
# ==== Read config files: =====================================================
#

dsk_progress "Reading configuration..."
dsk_read_config
set tkdesk(config_done) 1

if $tkdesk(no_auto_loading) {
    # adjust widget config if not auto-loading
    dsk_widget_config
}

if {[winfo depth .] == 1} {
    set tkdesk(append_type_char) 1
    dsk_FileListbox::typechar $tkdesk(append_type_char)
}

#
# ==== Start-up ===============================================================
#

dsk_debug "Now starting up"
if ![info exists tkdesk(restarted)] {
    dsk_sound dsk_welcome_begin
}

#
# ---- Enable history management:
#
dsk_progress "Enabling history..."
# path history:
dsk_history dir_history -size $tkdesk(history_size)
# interactive command history:
dsk_history cmd_history -size $tkdesk(history_size)
# periodic execution history
dsk_history pcmd_history -size $tkdesk(history_size) \
	-callback dsk_periodic_cb
# hypersearch history:
dsk_history hsearch_history -size $tkdesk(history_size) \
	-callback dsk_editor_hsearch_cb
# opened file history:
dsk_history file_history -size $tkdesk(history_size) \
	-command "dsk_open .fv0"
# executed commands history:
dsk_history exec_history -size $tkdesk(history_size) \
	-command "eval dsk_exec"
# read strings history:
dsk_history string_history -size $tkdesk(history_size)
# print command history:
dsk_history printer_history -size $tkdesk(history_size)
# file mask history:
dsk_history mask_history -size $tkdesk(history_size)
# "execute here" history:
dsk_history xhere_history -size $tkdesk(history_size)
# mail history:
dsk_history mail_history -size $tkdesk(history_size)
# search history:
dsk_history search_history -size $tkdesk(history_size)
# replace history:
dsk_history replace_history -size $tkdesk(history_size)
# dial-up phone number history:
dsk_history dialup_history -size $tkdesk(history_size)

set histlist {dir_history cmd_history pcmd_history hsearch_history \
	file_history exec_history string_history printer_history \
        mask_history xhere_history mail_history search_history \
        replace_history dialup_history}

set hi 0
if [info exists tkdesk(history_list)] {
    set hlist [lindex $histlist 0]
    set i 0
    foreach h $tkdesk(history_list) {
	set ll 0
	catch {set ll [llength [lindex $h 0]]}
	if {[regexp {^\#.*history$} [lindex $h 0]] && $i > 0} {
	    incr hi
	    set hlist [lindex $histlist $hi]
	} elseif {$i > 0} {
	    $hlist add $h
	}
	incr i
    }
}

set tkdesk(histlist) $histlist
unset histlist hi

#
# ---- Possibly restore the window layout of the last session:
#
dsk_progress "Restoring layout..."
dsk_restore_layout

#
# ---- Open the initial file viewer window:
#

if {![info exists tkdesk(layout)] || !$tkdesk(have_window)} {
    # disable at_pointer placement for initial window:
    set ap $tkdesk(at_pointer)
    set tkdesk(at_pointer) 0
    
    dsk_progress "Creating a file browser..."
    set dir [dir_history get]
    if {$dir != ""} {
	set dir [lindex $dir end]
    } else {
	if [info exists tkdesk(user,startdir)] {
	    set dir $tkdesk(user,startdir)
	} else {
	    set dir $tkdesk(initdir)
	}
    }
    set tkdesk(geometry,fbrowser) \
	    $tkdesk(file_lb,width)x$tkdesk(file_lb,height)+100+50
    dsk_FileViewer .fv[dsk_FileViewer::id] \
	    -dir $dir -num_lbs $tkdesk(num_lbs)
    set tkdesk(geometry,fbrowser) ""

    # create the Trash window:
    #set twin .dfl[dsk_FileList::id]
    #dsk_progress "Creating the trash window..."
    #dsk_FileList $twin -dir $tkdesk(configdir)/.trash -dontmap 1
    #update
    #wm iconify $twin
    #unset twin

    # and the app bar
    dsk_progress "Creating the Application Bar..."
    dsk_appbar

    set tkdesk(at_pointer) $ap
}

if ![info exists tkdesk(restarted)] {
    #
    # ---- Start the periodic update of the file listboxes:
    #
    dsk_progress "Starting background procs..."
    after [expr $tkdesk(update,file_lists) * 1000] dsk_update_flbs

    # ... and the periodic config-save:
    if !$tkdesk(xmaster) {
	after [expr $tkdesk(update,config) * 60000] dsk_persave_config
    }
}

dsk_progress "Ready."
if ![info exists tkdesk(restarted)] {
    dsk_sound dsk_welcome_end
}
dsk_welcome hide
dsk_lazy

if [info exists tkdesk(first_time_user)] {
    dsk_help quick
}

if [info exists tkdesk(after_startup)] {
    set tkdesk(error_source) "System"
    eval $tkdesk(after_startup)
    set tkdesk(error_source) ""
}

#
# ==== Misc. Procs ============================================================
#

#
# -----------------------------------------------------------------------------
#
# Proc:		dsk_exit
# Args:		ask	(opt.) set to 1 if it should ask by all means
# Returns: 	""
# Desc:		Exits TkDesk.
# Side-FX:	May lead to the termination of tkdesk.
#

proc dsk_exit {{ask 0}} {
    global tkdesk

    if {($tkdesk(ask_on_exit) && !$tkdesk(in_development)) || $ask} {
	if !$tkdesk(xmaster) {
	    set msg "Are you sure you want to exit TkDesk?"
	} else {
	    set msg "This will end your X Session! Is this o.k.?"
	}
    	if {[cb_yesno $msg] != 0} {
	    return
	}
    }

    foreach obj [itcl::find objects -class dsk_Editor] {
	if [winfo exists [$obj getToplevel]] {
	    if {[$obj close_win] == "cancel"} {
		return
	    }
	}
    }
    if [info exists tkdesk(at_exit)] {
	set tkdesk(error_source) "System"
	eval $tkdesk(at_exit)
	set tkdesk(error_source) ""
    }
    dsk_sound dsk_quit_tkdesk
    dsk_save_config
    catch {dsk_shutdown_server}
    catch {exec rm -rf $tkdesk(tmpdir)}
    exit 0
}

#
# -----------------------------------------------------------------------------
#
# Proc:		dsk_restart
# Args:		-
# Returns: 	""
# Desc:		Restarts TkDesk.
# Side-FX:	none
#

proc dsk_restart {} {
   global argv0 tkdesk

    dsk_save_config

    # clean up
    cb_image !reset
    foreach obj [itcl::find objects -class dsk_Editor] {
	if {[$obj close_win] == "cancel"} {
	    return
	}
    }
    catch {eval itcl_unload [itcl::find classes]}
    foreach w [winfo children .] {destroy $w}

    # and now restart
    set tkdesk(restarted) 1
    uplevel #0 "cd $tkdesk(startdir)"
    uplevel #0 "source $argv0"
}

# -----------------------------------------------------------------------------
# _dsk_server_connect:
# Gets invoked when a client connects to our server port.
#
