/*
 *  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 Library 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

/*
 * 2005/01/04 Kristian Mueller (Kristian-M@Kristian-M.de)
 *  The name of this little program has been animated by the 
 *  nick of a sympatic nerdess :)
 */

#include "cEWMHVDesktopTools.h"
#include <iostream>

bool rotateScreen(bool bDirection, int iScreenNumber, int iScreenCount){
	cEWMHVDesktopTools aEWMHVDesktopTools;

	std::cout << "initially on " << iScreenNumber << std::endl;
	if (bDirection == true){ // left
		if (iScreenCount <= iScreenNumber){
			iScreenNumber = -1;
		}
	std::cout << "++" << iScreenNumber << std::endl;
		aEWMHVDesktopTools.setCurrentDesktop(++iScreenNumber);
	} else{  // right
		if (iScreenNumber <= 0){
			iScreenNumber = iScreenCount;
		}
	std::cout << "--" << iScreenNumber << std::endl;
		aEWMHVDesktopTools.setCurrentDesktop(--iScreenNumber);	
	}
	std::cout << "switching to " << iScreenNumber << std::endl;
	return true;
};


int main(int iArguments, char *sArguments[]){
	cEWMHVDesktopTools aEWMHVDesktopTools;
	int iVDesktopNumber = 0;
	int iScreenCount = 0;

	std::cout << "Trying to request number of desktops by using an EWMH message..." << std::endl;
	if (aEWMHVDesktopTools.probeWM()){	// we should have an EWMH-Environment	
		iScreenCount = aEWMHVDesktopTools.getDesktopCount();
		iVDesktopNumber = aEWMHVDesktopTools.getCurrentDesktopID();
		std::cout << "actualDestopCount = " << iScreenCount << std::endl;
		std::cout << "actualCurrentDesktopID = " << iVDesktopNumber << std::endl;
	}
	else {
		std::cout << "We are not in an EWMH environment - sorry, you can't use this tool here!" << std::endl;	
		return (-1);
	}
	
	if (iArguments == 2){
		rotateScreen(false, iVDesktopNumber, iScreenCount);
	}
	else 
		rotateScreen(true, iVDesktopNumber, iScreenCount);
	
	return 1;
}