Experimental preview implementation using XShmGetImage.

Not hooked up yet.
This commit is contained in:
Marco Pesenti Gritti
2007-11-04 16:20:54 +01:00
parent 2907b10dbb
commit eaef1eb015
7 changed files with 238 additions and 377 deletions
+3 -1
View File
@@ -32,7 +32,9 @@ _sugarext_la_SOURCES = \
sugar-key-grabber.c \
sugar-key-grabber.h \
sugar-menu.h \
sugar-menu.c
sugar-menu.c \
sugar-preview.h \
sugar-preview.c
BUILT_SOURCES = \
_sugarext.c \
+31
View File
@@ -22,6 +22,13 @@
(gtype-id "SUGAR_TYPE_MENU")
)
(define-object Preview
(in-module "Sugar")
(parent "GObject")
(c-name "SugarPreview")
(gtype-id "SUGAR_TYPE_PREVIEW")
)
(define-object IconEntry
(in-module "Sexy")
(parent "GtkEntry")
@@ -150,3 +157,27 @@
(return-type "none")
)
;; From sugar-preview.h
(define-function sugar_preview_get_type
(c-name "sugar_preview_get_type")
(return-type "GType")
)
(define-method take_screenshot
(of-object "SugarPreview")
(c-name "sugar_preview_take_screenshot")
(return-type "none")
(parameters
'("GdkDrawable" "drawable")
)
)
(define-method save
(of-object "SugarPreview")
(c-name "sugar_preview_save")
(return-type "gboolean")
(parameters
'("const-char*" "key")
)
)
+2
View File
@@ -7,6 +7,7 @@ headers
#include "sugar-address-entry.h"
#include "sugar-key-grabber.h"
#include "sugar-menu.h"
#include "sugar-preview.h"
#include "sexy-icon-entry.h"
#include <pygtk/pygtk.h>
@@ -20,6 +21,7 @@ import gtk.Entry as PyGtkEntry_Type
import gtk.Menu as PyGtkMenu_Type
import gtk.Container as PyGtkContainer_Type
import gtk.gdk.Window as PyGdkWindow_Type
import gtk.gdk.Drawable as PyGdkDrawable_Type
import gtk.Image as PyGtkImage_Type
%%
ignore-glob
+105
View File
@@ -0,0 +1,105 @@
/*
* Copyright (C) 2007, Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <gdk/gdkx.h>
#include <gtk/gtkwindow.h>
#include "sugar-preview.h"
static void sugar_preview_class_init (SugarPreviewClass *menu_class);
static void sugar_preview_init (SugarPreview *menu);
G_DEFINE_TYPE(SugarPreview, sugar_preview, G_TYPE_OBJECT)
gboolean
sugar_preview_save(SugarPreview *preview, const char *file_name)
{
GdkPixbuf *pixbuf;
if (preview->image != NULL) {
return FALSE;
}
pixbuf = gdk_pixbuf_get_from_image(NULL, preview->image, NULL,
0, 0, 0, 0,
preview->image->width,
preview->image->height);
gdk_pixbuf_save(pixbuf, file_name, "png", NULL);
if (preview->image != NULL) {
g_object_unref(G_OBJECT(preview->image));
preview->image = NULL;
}
return TRUE;
}
void
sugar_preview_take_screenshot(SugarPreview *preview, GdkDrawable *drawable)
{
GdkScreen *screen;
GdkVisual *visual;
GdkColormap *colormap;
gint width, height;
gdk_drawable_get_size(drawable, &width, &height);
screen = gdk_drawable_get_screen(drawable);
visual = gdk_drawable_get_visual(drawable);
colormap = gdk_drawable_get_colormap(drawable);
if (preview->image != NULL) {
g_object_unref(G_OBJECT(preview->image));
}
preview->image = gdk_image_new(GDK_IMAGE_SHARED, visual, width, height);
gdk_image_set_colormap(preview->image, colormap);
XShmGetImage(GDK_SCREEN_XDISPLAY(screen),
GDK_DRAWABLE_XID(drawable),
gdk_x11_image_get_ximage(preview->image),
0, 0, AllPlanes, ZPixmap);
}
static void
sugar_preview_dispose (GObject *object)
{
SugarPreview *preview = SUGAR_PREVIEW(object);
if (preview->image != NULL) {
g_object_unref(G_OBJECT(preview->image));
preview->image = NULL;
}
}
static void
sugar_preview_class_init(SugarPreviewClass *preview_class)
{
GObjectClass *g_object_class = G_OBJECT_CLASS (preview_class);
g_object_class->dispose = sugar_preview_dispose;
}
static void
sugar_preview_init(SugarPreview *preview)
{
preview->image = NULL;
}
+55
View File
@@ -0,0 +1,55 @@
/*
* Copyright (C) 2007, Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __SUGAR_PREVIEW_H__
#define __SUGAR_PREVIEW_H__
#include <gdk/gdkdrawable.h>
G_BEGIN_DECLS
typedef struct _SugarPreview SugarPreview;
typedef struct _SugarPreviewClass SugarPreviewClass;
#define SUGAR_TYPE_PREVIEW (sugar_preview_get_type())
#define SUGAR_PREVIEW(object) (G_TYPE_CHECK_INSTANCE_CAST((object), SUGAR_TYPE_PREVIEW, SugarPreview))
#define SUGAR_PREVIEW_CLASS(klass) (G_TYPE_CHACK_CLASS_CAST((klass), SUGAR_TYPE_PREVIEW, SugarPreviewClass))
#define SUGAR_IS_PREVIEW(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), SUGAR_TYPE_PREVIEW))
#define SUGAR_IS_PREVIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), SUGAR_TYPE_PREVIEW))
#define SUGAR_PREVIEW_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), SUGAR_TYPE_PREVIEW, SugarPreviewClass))
struct _SugarPreview {
GObject base_instance;
GdkImage *image;
};
struct _SugarPreviewClass {
GObjectClass base_class;
};
GType sugar_preview_get_type (void);
void sugar_preview_take_screenshot (SugarPreview *menu,
GdkDrawable *drawable);
gboolean sugar_preview_save (SugarPreview *menu,
const char *file_name);
G_END_DECLS
#endif /* __SUGAR_PREVIEW_H__ */