#include <fspanel.h>

int left_arrow_x = 25;
int right_arrow_x = 50;

applet_info_t info_g;


applet_info_t get_applet_info( void )
{
   
    return info_g;
}

set_applet_info( applet_info_t inf )
{
    info_g = inf;

    if( info_g.width == -1 )
    {
        info_g.width = 30;
    }
}

int gui_draw( int x, void *token ) 
{
    int winheight;     
     
    winheight = panel_get_winheight();
     
    left_arrow_x = x;
    right_arrow_x = x + 15;
     
    set_foreground (5);	/* black */
     
    fill_rect ( left_arrow_x + 2, (winheight - 4) / 2 + 1, 3, 3);
    draw_line ( left_arrow_x, (winheight - 4) / 2 + 3, left_arrow_x + 3, (winheight - 4) / 2);
    draw_line ( left_arrow_x + 3, (winheight - 4) / 2, left_arrow_x + 6, (winheight - 4) / 2 + 3);
    draw_line ( left_arrow_x + 1, (winheight - 4) / 2 + 3, left_arrow_x + 5, (winheight - 4) / 2 + 3);
     
     
    draw_line ( right_arrow_x, (winheight - 4) / 2, right_arrow_x + 3, (winheight - 4) / 2 + 3);
    draw_line ( right_arrow_x, (winheight - 4) / 2, right_arrow_x + 4, (winheight - 4) / 2 + 2);
    draw_line ( right_arrow_x, (winheight - 4) / 2, right_arrow_x + 5, (winheight - 4) / 2 + 1);
    draw_line ( right_arrow_x, (winheight - 4) / 2, right_arrow_x + 6, (winheight - 4) / 2);
     
    return right_arrow_x + 15;
}

int gui_button_press ( int x, int y, int button, void *token )
{
    int winheight;
     
    winheight = panel_get_winheight();

    // clicked on one of the arrows ...
    if (y > 3 && y < winheight - 3)
    {
        if (x >= right_arrow_x && x < right_arrow_x + 9)
        {
            //printf("\tbva - switching desktop + 1\n" );
            if( wm_get_current_desktop() + 1  < wm_get_workspace_count() )
            {
                wm_switch_desktop ( wm_get_current_desktop() + 1 );
            }
        }
        
        if (x >= left_arrow_x && x < left_arrow_x + 9)
        {
            if( wm_get_current_desktop() - 1 >= 0 )
            {
                //printf("\tbva - switching desktop - 1\n" );
                wm_switch_desktop ( wm_get_current_desktop() - 1);
            }
        }
    }

}

int event_notification( void *token )
{

}

int gui_button_release ( int x, int y, int button, void *token )
{

}
