helper.php 2.19 KB
Newer Older
epsi sayidina's avatar
epsi sayidina committed
1 2 3 4 5
<?php # using PHP7

# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# helpers

epsi sayidina's avatar
epsi sayidina committed
6
// script arguments
epsi sayidina's avatar
epsi sayidina committed
7 8
function get_monitor($arguments)
{
epsi sayidina's avatar
epsi sayidina committed
9
    // ternary operator
epsi sayidina's avatar
epsi sayidina committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
    return count($arguments) > 0 ? (int)$arguments[0] : 0;
}

# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# geometry calculation

function get_geometry($monitor)
{
    $raw = shell_exec('herbstclient monitor_rect '.$monitor);

    if (empty($raw)) {
        print('Invalid monitor '.$monitors);
        exit(1);
    }
    
    return explode(' ', trim($raw));
}

function get_top_panel_geometry($height, $geometry)
{
epsi sayidina's avatar
epsi sayidina committed
30
    // geometry has the format X Y W H
epsi sayidina's avatar
epsi sayidina committed
31 32 33 34 35 36
    return array(
        $geometry[0], $geometry[1], $geometry[2], $height);
}

function get_bottom_panel_geometry($height, $geometry)
{
epsi sayidina's avatar
epsi sayidina committed
37
    // geometry has the format X Y W H
epsi sayidina's avatar
epsi sayidina committed
38
    return array(
epsi sayidina's avatar
epsi sayidina committed
39 40
        $geometry[0] + 0, ($geometry[3] - $height), 
        $geometry[2] - 0, $height);
epsi sayidina's avatar
epsi sayidina committed
41 42 43 44 45
}

# ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----
# dzen Parameters

epsi sayidina's avatar
epsi sayidina committed
46
function get_params_top($monitor, $panel_height)
epsi sayidina's avatar
epsi sayidina committed
47 48 49 50 51 52 53 54 55
{
    $geometry = get_geometry($monitor);
    list($xpos, $ypos, $width, $height) = get_top_panel_geometry(
        $panel_height, $geometry);
    
    $bgcolor = '#000000';
    $fgcolor = '#ffffff';
    $font    = '-*-takaopgothic-medium-*-*-*-12-*-*-*-*-*-*-*';
  
epsi sayidina's avatar
epsi sayidina committed
56 57
    $parameters  = "  -x $xpos -y $ypos -w $width -h $height"
                 . " -ta l -bg '$bgcolor' -fg '$fgcolor'"
epsi sayidina's avatar
epsi sayidina committed
58 59 60
                 . " -title-name dzentop"
                 . " -fn '$font'";

epsi sayidina's avatar
epsi sayidina committed
61 62
    return $parameters;
}
epsi sayidina's avatar
epsi sayidina committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83

function get_params_bottom($monitor, $panel_height)
{
    $geometry = get_geometry($monitor);
    list($xpos, $ypos, $width, $height) = get_bottom_panel_geometry(
        $panel_height, $geometry);
    
    $bgcolor = '#000000';
    $fgcolor = '#ffffff';
    $font    = '-*-fixed-medium-*-*-*-11-*-*-*-*-*-*-*';
  
    $parameters  = "  -x $xpos -y $ypos -w $width -h $height"
                 . " -ta l -bg '$bgcolor' -fg '$fgcolor'"
                 . " -title-name dzenbottom"
                 . " -fn '$font'";

    return $parameters;
}

function get_dzen2_parameters($monitor, $panel_height)
{   return get_params_top($monitor, $panel_height); }