// Path: src/org/sleeksnap/util/active/ActiveWindow.java
// public class ActiveWindow {
// 	
// 	/**
// 	 * The window name
// 	 */
// 	private String name;
// 
// 	/**
// 	 * The window's bounds
// 	 */
// 	private Rectangle bounds;
// 
// 	public ActiveWindow(String name, Rectangle bounds) {
// 		this.name = name;
// 		this.bounds = bounds;
// 	}
// 
// 	/**
// 	 * Get the window's bounds as a rectangle
// 	 * @return
// 	 * 		A rectangle containing the window's bounds
// 	 */
// 	public Rectangle getBounds() {
// 		return bounds;
// 	}
// 
// 	/**
// 	 * Get the window name
// 	 * @return
// 	 * 		The window name
// 	 */
// 	public String getName() {
// 		return name;
// 	}
// 
// 	@Override
// 	public String toString() {
// 		return name + " [x=" + bounds.x + ",y=" + bounds.y + ",width="
// 				+ bounds.width + ",height=" + bounds.height + "]";
// 	}
// }
// 
// Path: src/org/sleeksnap/util/active/WindowUtil.java
// public interface WindowUtil {
// 
// 	/**
// 	 * Get the active window
// 	 * 
// 	 * @return The active desktop window
// 	 * @throws Exception
// 	 *             If we failed to get the window
// 	 */
// 	public ActiveWindow getActiveWindow() throws Exception;
// }
// 
// Path: src/org/sleeksnap/util/active/linux/Gtk.java
// public static class GdkRectangle extends Structure {
// 	public int x;
// 	public int y;
// 	public int width;
// 	public int height;
// 
// 	public Rectangle toRectangle() {
// 		Rectangle out = new Rectangle(x, y, width, height);
// 		if (out.x < 0) {
// 			out.width = out.width + out.x;
// 			out.x = 0;
// 		}
// 		if (out.y < 0) {
// 			out.height = out.height + out.y;
// 			out.y = 0;
// 		}
// 		return out;
// 	}
// }


import org.sleeksnap.util.active.ActiveWindow;
import org.sleeksnap.util.active.WindowUtil;
import org.sleeksnap.util.active.linux.Gtk.GdkRectangle;
import com.sun.jna.Native;
import com.sun.jna.NativeLong;
/**
 * Sleeksnap, the open source cross-platform screenshot uploader
 * Copyright (C) 2012 Nikki <nikki@nikkii.us>
 *
 * 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 3 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, see <http://www.gnu.org/licenses/>.
 */
package org.sleeksnap.util.active.linux;



/**
 * Gets the active window by using Gtk/Gdk functions This method does not return
 * a window title, but is still preferred over XPropWindowUtil since it will get
 * the window location including the title bar
 * 
 * @author Nikki
 * 
 */
public class GnomeWindowUtil implements WindowUtil {

	private static Gtk gtk;

	@Override
	public ActiveWindow getActiveWindow() throws Exception {
		if (gtk == null) {
			throw new Exception("Gtk library not loaded!");
		}
		gtk.gtk_init(null, null);
		// Display and window are pointers...
		NativeLong display = gtk.gdk_screen_get_default();
		if (display == null) {
			throw new Exception("Unable to find the default screen");
		}
		// Try to get the active window
		NativeLong window = gtk.gdk_screen_get_active_window(display);
		// If not, try to get the window under the cursor
		if (window == null) {
			window = gtk.gdk_window_at_pointer(null, null);
		}
		// If we didn't find a window, throw an exception
		if (window == null) {
			throw new Exception("Unable to get the active window!");
		}
		// Get the frame bounds as a GdkRectangle, why not a structure since
		// we'd get it in an int[] the other way
// Path: src/org/sleeksnap/util/active/ActiveWindow.java
// public class ActiveWindow {
// 	
// 	/**
// 	 * The window name
// 	 */
// 	private String name;
// 
// 	/**
// 	 * The window's bounds
// 	 */
// 	private Rectangle bounds;
// 
// 	public ActiveWindow(String name, Rectangle bounds) {
// 		this.name = name;
// 		this.bounds = bounds;
// 	}
// 
// 	/**
// 	 * Get the window's bounds as a rectangle
// 	 * @return
// 	 * 		A rectangle containing the window's bounds
// 	 */
// 	public Rectangle getBounds() {
// 		return bounds;
// 	}
// 
// 	/**
// 	 * Get the window name
// 	 * @return
// 	 * 		The window name
// 	 */
// 	public String getName() {
// 		return name;
// 	}
// 
// 	@Override
// 	public String toString() {
// 		return name + " [x=" + bounds.x + ",y=" + bounds.y + ",width="
// 				+ bounds.width + ",height=" + bounds.height + "]";
// 	}
// }
// 
// Path: src/org/sleeksnap/util/active/WindowUtil.java
// public interface WindowUtil {
// 
// 	/**
// 	 * Get the active window
// 	 * 
// 	 * @return The active desktop window
// 	 * @throws Exception
// 	 *             If we failed to get the window
// 	 */
// 	public ActiveWindow getActiveWindow() throws Exception;
// }
// 
// Path: src/org/sleeksnap/util/active/linux/Gtk.java
// public static class GdkRectangle extends Structure {
// 	public int x;
// 	public int y;
// 	public int width;
// 	public int height;
// 
// 	public Rectangle toRectangle() {
// 		Rectangle out = new Rectangle(x, y, width, height);
// 		if (out.x < 0) {
// 			out.width = out.width + out.x;
// 			out.x = 0;
// 		}
// 		if (out.y < 0) {
// 			out.height = out.height + out.y;
// 			out.y = 0;
// 		}
// 		return out;
// 	}
// }


// Path: src/org/sleeksnap/util/active/linux/GnomeWindowUtil.java
import org.sleeksnap.util.active.ActiveWindow;
import org.sleeksnap.util.active.WindowUtil;
import org.sleeksnap.util.active.linux.Gtk.GdkRectangle;
import com.sun.jna.Native;
import com.sun.jna.NativeLong;

/**
 * Sleeksnap, the open source cross-platform screenshot uploader
 * Copyright (C) 2012 Nikki <nikki@nikkii.us>
 *
 * 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 3 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, see <http://www.gnu.org/licenses/>.
 */
package org.sleeksnap.util.active.linux;



/**
 * Gets the active window by using Gtk/Gdk functions This method does not return
 * a window title, but is still preferred over XPropWindowUtil since it will get
 * the window location including the title bar
 * 
 * @author Nikki
 * 
 */
public class GnomeWindowUtil implements WindowUtil {

	private static Gtk gtk;

	@Override
	public ActiveWindow getActiveWindow() throws Exception {
		if (gtk == null) {
			throw new Exception("Gtk library not loaded!");
		}
		gtk.gtk_init(null, null);
		// Display and window are pointers...
		NativeLong display = gtk.gdk_screen_get_default();
		if (display == null) {
			throw new Exception("Unable to find the default screen");
		}
		// Try to get the active window
		NativeLong window = gtk.gdk_screen_get_active_window(display);
		// If not, try to get the window under the cursor
		if (window == null) {
			window = gtk.gdk_window_at_pointer(null, null);
		}
		// If we didn't find a window, throw an exception
		if (window == null) {
			throw new Exception("Unable to get the active window!");
		}
		// Get the frame bounds as a GdkRectangle, why not a structure since
		// we'd get it in an int[] the other way
		GdkRectangle rect = new GdkRectangle();