Skip to content
Snippets Groups Projects
Commit 7ac04a3b authored by Jerome Guelfucci's avatar Jerome Guelfucci
Browse files

Reorganize code.

(Old svn revision: 4898)
parent 7e2df40e
No related branches found
No related tags found
No related merge requests found
2008-06-06 19:19 jeromeg
* Move the code to a src/ folder and remove the panel-plugin one.
* src/screenshooter-utils.{c,h}: moved generic code here.
* src/screenshooter.c: updated to use the generic code.
* Update the makefiles and autotools to use new code structure.
2008-06-06 15:35 jeromeg
* panel-plugin/screenshooter.c:
- remove deprecated function.
- set button sensitive at the end of the screenshot procedure.
2008-06-06 15:19 jeromeg
* panel-plugin/screenshooter.c:
......
@SET_MAKE@
SUBDIRS = panel-plugin po
SUBDIRS = src po
distclean-local:
rm -rf *.cache *~
......
......@@ -43,7 +43,7 @@ XDT_FEATURE_DEBUG()
AC_OUTPUT([
Makefile
panel-plugin/Makefile
src/Makefile
po/Makefile.in
])
......@@ -9,7 +9,8 @@ xfce4_screenshooter_plugin_LDFLAGS = \
@LIBXFCE4PANEL_LIBS@
xfce4_screenshooter_plugin_SOURCES = \
screenshooter.c
screenshooter.c \
screenshooter-utils.c
# .desktop file
#
......
/* $Id$
*
* Copyright © 2004 German Poo-Caaman~o <gpoo@ubiobio.cl>
* Copyright © 2005,2006 Daniel Bobadilla Leal <dbobadil@dcc.uchile.cl>
* Copyright © 2005 Jasper Huijsmans <jasper@xfce.org>
* Copyright © 2006 Jani Monoses <jani@ubuntu.com>
* Copyright © 2008 Jérôme Guelfucci <jerome.guelfucci@gmail.com>
*
* Portions from the Gimp sources by
* Copyright © 1998-2000 Sven Neumann <sven@gimp.org>
* Copyright © 2003 Henrik Brix Andersen <brix@gimp.org>
*
* 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.
*/
#include <screenshooter-utils.h>
/* Prototypes */
static Window get_window_property (Window xwindow, Atom atom);
static Window find_toplevel_window (Window xid);
static Window screenshot_find_active_window (void);
/* Internals */
/* Borrowed from libwnck */
static Window
get_window_property (Window xwindow,
Atom atom)
{
Atom type;
int format;
gulong nitems;
gulong bytes_after;
Window *w;
int err, result;
Window retval;
gdk_error_trap_push ();
type = None;
result = XGetWindowProperty (gdk_display,
xwindow,
atom,
0, G_MAXLONG,
False, XA_WINDOW, &type, &format, &nitems,
&bytes_after, (unsigned char **) &w);
err = gdk_error_trap_pop ();
if (err != Success ||
result != Success)
return None;
if (type != XA_WINDOW)
{
XFree (w);
return None;
}
retval = *w;
XFree (w);
return retval;
}
/* Borrowed from gnome-screenshot */
static Window
screenshot_find_active_window (void)
{
Window retval = None;
Window root_window;
root_window = GDK_ROOT_WINDOW ();
if (gdk_net_wm_supports (gdk_atom_intern ("_NET_ACTIVE_WINDOW", FALSE)))
{
retval = get_window_property (root_window,
gdk_x11_get_xatom_by_name ("_NET_ACTIVE_WINDOW"));
}
return retval;
}
/* Borrowed from gnome-screenshot */
static Window
find_toplevel_window (Window xid)
{
Window root, parent, *children;
unsigned int nchildren;
do
{
if (XQueryTree (GDK_DISPLAY (), xid, &root,
&parent, &children, &nchildren) == 0)
{
g_warning ("Couldn't find window manager window");
return None;
}
if (root == parent)
return xid;
xid = parent;
}
while (TRUE);
}
/* Public */
GdkPixbuf *take_screenshot (gint fullscreen, gint delay)
{
GdkPixbuf * screenshot;
GdkWindow * window;
gint width;
gint height;
if (fullscreen)
{
window = gdk_get_default_root_window();
}
else
{
window = gdk_window_foreign_new (find_toplevel_window (screenshot_find_active_window ()));
}
sleep(delay);
gdk_drawable_get_size(window, &width, &height);
screenshot = gdk_pixbuf_get_from_drawable (NULL,
window,
NULL, 0, 0, 0, 0,
width, height);
return screenshot;
}
/* $Id$
*
* Copyright © 2004 German Poo-Caaman~o <gpoo@ubiobio.cl>
* Copyright © 2005,2006 Daniel Bobadilla Leal <dbobadil@dcc.uchile.cl>
* Copyright © 2005 Jasper Huijsmans <jasper@xfce.org>
* Copyright © 2006 Jani Monoses <jani@ubuntu.com>
* Copyright © 2008 Jérôme Guelfucci <jerome.guelfucci@gmail.com>
*
* Portions from the Gimp sources by
* Copyright © 1998-2000 Sven Neumann <sven@gimp.org>
* Copyright © 2003 Henrik Brix Andersen <brix@gimp.org>
*
* 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.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <X11/Xatom.h>
GdkPixbuf *take_screenshot (gint fullscreen, gint delay);
......@@ -4,6 +4,7 @@
* Copyright © 2005,2006 Daniel Bobadilla Leal <dbobadil@dcc.uchile.cl>
* Copyright © 2005 Jasper Huijsmans <jasper@xfce.org>
* Copyright © 2006 Jani Monoses <jani@ubuntu.com>
* Copyright © 2008 Jérôme Guelfucci <jerome.guelfucci@gmail.com>
*
* Portions from the Gimp sources by
* Copyright © 1998-2000 Sven Neumann <sven@gimp.org>
......@@ -40,6 +41,8 @@
#include <fcntl.h>
#include <X11/Xatom.h>
#include "screenshooter-utils.h"
#define SCREENSHOT_ICON_NAME "applets-screenshooter"
#define MODE 0644
......@@ -68,7 +71,6 @@ typedef struct
}
ScreenshotData;
/* Panel Plugin Interface */
static void screenshot_properties_dialog (XfcePanelPlugin *plugin,
......@@ -77,7 +79,6 @@ static void screenshot_construct (XfcePanelPlugin * plugin);
XFCE_PANEL_PLUGIN_REGISTER_INTERNAL (screenshot_construct);
/* internal functions */
static gboolean
......@@ -113,88 +114,6 @@ screenshot_free_data (XfcePanelPlugin * plugin, ScreenshotData * sd)
g_free (sd);
}
/* Borrowed from libwnck */
static Window
get_window_property (Window xwindow,
Atom atom)
{
Atom type;
int format;
gulong nitems;
gulong bytes_after;
Window *w;
int err, result;
Window retval;
gdk_error_trap_push ();
type = None;
result = XGetWindowProperty (gdk_display,
xwindow,
atom,
0, G_MAXLONG,
False, XA_WINDOW, &type, &format, &nitems,
&bytes_after, (unsigned char **) &w);
err = gdk_error_trap_pop ();
if (err != Success ||
result != Success)
return None;
if (type != XA_WINDOW)
{
XFree (w);
return None;
}
retval = *w;
XFree (w);
return retval;
}
/* Borrowed from gnome-screenshot */
static Window
screenshot_find_active_window (void)
{
Window retval = None;
Window root_window;
root_window = GDK_ROOT_WINDOW ();
if (gdk_net_wm_supports (gdk_atom_intern ("_NET_ACTIVE_WINDOW", FALSE)))
{
retval = get_window_property (root_window,
gdk_x11_get_xatom_by_name ("_NET_ACTIVE_WINDOW"));
}
return retval;
}
/* Borrowed from gnome-screenshot */
static Window
find_toplevel_window (Window xid)
{
Window root, parent, *children;
unsigned int nchildren;
do
{
if (XQueryTree (GDK_DISPLAY (), xid, &root,
&parent, &children, &nchildren) == 0)
{
g_warning ("Couldn't find window manager window");
return None;
}
if (root == parent)
return xid;
xid = parent;
}
while (TRUE);
}
gchar *generate_filename_for_uri(char *uri){
int test;
gchar *file_name;
......@@ -221,32 +140,17 @@ button_clicked(GtkWidget * button, ScreenshotData * sd)
{
GdkPixbuf * screenshot;
GdkPixbuf * thumbnail;
GdkWindow * window;
gint width;
gint height;
gint dialog_response;
gchar * filename = NULL;
if (sd->whole_screen)
{
window = gdk_get_default_root_window();
}
else
{
window = gdk_window_foreign_new (find_toplevel_window (screenshot_find_active_window ()));
}
/* delay, we make the button unclickable so that no other screenshot
can be taken at the same time */
gtk_widget_set_sensitive(GTK_WIDGET (sd->button), FALSE);
sleep( sd->screenshot_delay);
gdk_drawable_get_size(window, &width, &height);
screenshot = gdk_pixbuf_get_from_drawable (NULL,
window,
NULL, 0, 0, 0, 0,
width, height);
screenshot = take_screenshot(sd->whole_screen, sd->screenshot_delay);
width = gdk_pixbuf_get_width(screenshot);
height = gdk_pixbuf_get_height(screenshot);
thumbnail = gdk_pixbuf_scale_simple (screenshot,
width/5,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment