1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
|
#include <config.h>
#include <stdlib.h>
#include <string.h>
#if HAVE_CLUTTER_GLX
#include <clutter/clutter.h>
#include <clutter/x11/clutter-x11.h>
#include <clutter/x11/clutter-x11-texture-pixmap.h>
#include <clutter/glx/clutter-glx.h>
#include <clutter/glx/clutter-glx-texture-pixmap.h>
#include <X11/Xlib.h>
#include <X11/extensions/Xcomposite.h>
#define IMAGE "redhand.png"
# ifdef USE_GDKPIXBUF
static gboolean disable_x11 = FALSE;
static gboolean disable_glx = FALSE;
static GOptionEntry g_options[] =
{
{ "disable-x11",
0, 0,
G_OPTION_ARG_NONE,
&disable_x11,
"Disable redirection through X11 pixmap",
NULL },
{ "disable-glx",
0, 0,
G_OPTION_ARG_NONE,
&disable_glx,
"Disable redirection through GLX pixmap",
NULL },
{ NULL }
};
static gboolean
stage_key_release_cb (ClutterActor *actor,
ClutterEvent *event,
gpointer data)
{
switch (clutter_key_event_symbol (&event->key))
{
case CLUTTER_q:
case CLUTTER_Q:
clutter_main_quit ();
break;
}
return FALSE;
}
static gboolean
stage_button_press_cb (ClutterActor *actor,
ClutterEvent *event,
gpointer data)
{
Pixmap pxm = (Pixmap)data;
Display *dpy = clutter_x11_get_default_display ();
GC gc;
XGCValues gc_values = {0};
gc = XCreateGC (dpy,
pxm,
0,
&gc_values);
XDrawLine (dpy, pxm, gc, 0, 0, 100, 100);
return FALSE;
}
Pixmap
create_pixmap (guint *width, guint *height, guint *depth)
{
Display *dpy = clutter_x11_get_default_display ();
Pixmap pixmap;
GdkPixbuf *pixbuf;
GError *error = NULL;
XImage *image;
char *data, *d;
guchar *p, *line, *endofline, *end;
guint w, h, rowstride;
GC gc;
XGCValues gc_values = {0};
pixbuf = gdk_pixbuf_new_from_file (IMAGE, &error);
if (error)
g_error (error->message);
/* We assume that the image had an alpha channel */
g_assert (gdk_pixbuf_get_has_alpha (pixbuf));
w = gdk_pixbuf_get_width (pixbuf);
h = gdk_pixbuf_get_height (pixbuf);
rowstride = gdk_pixbuf_get_rowstride (pixbuf);
data = g_malloc (w * h * 4);
image = XCreateImage (dpy,
None,
32,
ZPixmap,
0,
data,
w, h,
8,
w * 4);
p = gdk_pixbuf_get_pixels (pixbuf);
d = data;
end = p + rowstride*h;
/* Convert from RGBA as contained in the pixmap to ARGB as used in X */
for (line = p; line < end ; line += rowstride)
{
p = line;
endofline = p + 4 * w;
for (p = line; p < endofline; p += 4, d+=4)
{
# define r ((guint32)(*(p)))
# define g ((guint32)(*(p+1)))
# define b ((guint32)(*(p+2)))
# define a ((guint32)(*(p+3)))
guint32 pixel =
((a << 24) & 0xFF000000 ) |
((r << 16) & 0x00FF0000 ) |
((g << 8) & 0x0000FF00) |
((b) & 0x000000FF );
*((guint32 *)d) = pixel;
}
# undef r
# undef g
# undef b
# undef a
}
g_object_unref (pixbuf);
pixmap = XCreatePixmap (dpy,
DefaultRootWindow (dpy),
w, h,
32);
gc = XCreateGC (dpy,
pixmap,
0,
&gc_values);
XPutImage (dpy,
pixmap,
gc,
image,
0, 0,
0, 0,
w, h);
XFreeGC (dpy, gc);
XDestroyImage (image);
if (width) *width = w;
if (height) *height = h;
if (depth) *depth = 32;
return pixmap;
}
# endif /* USE_GDKPIXBUF */
int
main (int argc, char **argv)
{
#ifdef USE_GDKPIXBUF
GOptionContext *context;
ClutterActor *stage, *tex;
Pixmap pixmap;
const ClutterColor gry = { 0x99, 0x99, 0x99, 0xFF };
Window win_remote;
guint w, h, d;
clutter_init (&argc, &argv);
context = g_option_context_new (" - text-pixmap options");
g_option_context_add_main_entries (context, g_options, NULL);
g_option_context_parse (context, &argc, &argv, NULL);
if (argc < 2)
g_error ("usage: %s <window id>", argv[0]);
win_remote = strtol (argv[1], NULL, 0);
stage = clutter_stage_get_default ();
clutter_stage_set_color (CLUTTER_STAGE (stage), &gry);
/* a pixmap */
pixmap = create_pixmap (&w, &h, &d);
tex = clutter_x11_texture_pixmap_new_with_pixmap (pixmap);
clutter_container_add_actor (CLUTTER_CONTAINER (stage), tex);
/* oddly, the actor's size is 0 until it is realized, even though
pixmap-height is set */
clutter_actor_set_position (tex, 0,
clutter_actor_get_height (stage)
- clutter_actor_get_height (tex));
/* a window */
if (!disable_x11)
{
tex = clutter_x11_texture_pixmap_new_with_window (win_remote);
clutter_actor_set_position (tex, 0, 0);
clutter_container_add_actor (CLUTTER_CONTAINER (stage), tex);
clutter_x11_texture_pixmap_set_automatic (CLUTTER_X11_TEXTURE_PIXMAP (tex),
TRUE);
}
# ifdef HAVE_CLUTTER_GLX
/* a window with glx */
if (!disable_glx)
{
tex = clutter_glx_texture_pixmap_new_with_window (win_remote);
clutter_actor_set_position (tex,
clutter_actor_get_width (stage)
- clutter_actor_get_width (tex),
0);
clutter_container_add_actor (CLUTTER_CONTAINER (stage), tex);
clutter_x11_texture_pixmap_set_automatic (CLUTTER_X11_TEXTURE_PIXMAP (tex),
TRUE);
}
#endif /* HAVE_CLUTTER_GLX */
g_signal_connect (stage, "key-release-event",
G_CALLBACK (stage_key_release_cb), (gpointer)pixmap);
g_signal_connect (stage, "button-press-event",
G_CALLBACK (stage_button_press_cb), (gpointer)pixmap);
clutter_actor_show_all (stage);
clutter_main ();
# endif /* USE_GDKPIXBUF */
return EXIT_SUCCESS;
}
#else /* HAVE_CLUTTER_GLX */
int main (int argc, char **argv) { return EXIT_SUCCESS; };
#endif /* HAVE_CLUTTER_GLX */
|