#!/bin/sh
# $Xorg: Xsetup_0,v 1.3 2000/08/17 19:54:17 cpqbld Exp $

# put me in /etc/X11/xenodm

# Use OpenBSD logo as background instead default steelblue
# /usr/local/bin/xsetroot -solid steelblue
/usr/local/bin/feh --bg-fill /usr/local/share/pixmaps/openbsd-background.jpg

# Add shutdown, reboot, restart X11 buttons
# xwininfo sees multiple monitors as one big screen
# Use xrandr to separate them.  Assuming monitors are side-by-side,
# so xwininfo is fine for height.
# width=`xwininfo -root | awk '$1 == "Width:" { print $2 }'`

# Uncomment these to debug
# xwininfo -root > /root/xwininfo
# xrandr --screen 0 > /root/xrandr

height=`xwininfo -root | awk '$1 == "Height:" { print $2 }'`

# First component of field containing ####x###+#+#
width=`xrandr --screen 0 | grep -E '[0-9]+x[0-9]+\+[0-9]+\+[0-9]+' | awk -F x '{ print $1 }' | awk '{ print $NF }'`

printf "width = $width height = $height\n" > /root/dims

# Primary display could be on left or right.  3rd value in xrandr output
# is the offset of the left edge of a monitor, e.g.
# VGA-1 connected primary 1280x1024+1925+0
left_edge=`xrandr --screen 0 | grep primary | awk '{ print $4 }' \
    | awk -F [x\+] '{ print $3 }'`

x=$(( $left_edge + ($width - 150) / 2 ))
y=$(( ($height - 10) / 2 + 120 ))
/usr/local/sbin/xenodmshutdown -geometry +$x+$y &
echo $! > /var/run/xenodmshutdown.pid
