From: Gordon Williams Date: Wed, 11 Feb 2009 17:01:31 +0000 (+0000) Subject: * src/hildon-remote-texture.c * src/hildon-remote-texture.h * src/hildon-remote-textu... X-Git-Tag: 2.1.66-1~162 X-Git-Url: http://git.maemo.org/git/?p=hildon;a=commitdiff_plain;h=a3bd0f3c1a314d65a78f21e990fe9fd834965554 * src/hildon-remote-texture.c * src/hildon-remote-texture.h * src/hildon-remote-texture-private.h * examples/hildon-remote-texture-example.c: Updates/fixes to remote-texture and its example. --- diff --git a/ChangeLog b/ChangeLog index 1a1075c..1ff0d47 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2009-02-11 Gordon Williams + + * src/hildon-remote-texture.c + * src/hildon-remote-texture.h + * src/hildon-remote-texture-private.h + * examples/hildon-remote-texture-example.c: + Updates/fixes to remote-texture and its example. + 2009-02-11 Claudio Saavedra Patch by Mox Soini (ext-mox.soini@nokia.com) diff --git a/examples/hildon-remote-texture-example.c b/examples/hildon-remote-texture-example.c index 927ecae..0964e5f 100644 --- a/examples/hildon-remote-texture-example.c +++ b/examples/hildon-remote-texture-example.c @@ -19,15 +19,19 @@ * An area 640x480 in the top-left corner will be updated with an animation * to show how to modify the area. */ +#define DO_ANIM 1 /* whether to animate the area defined below */ + #define ANIM_X 0 #define ANIM_Y 0 #define ANIM_WIDTH 640 #define ANIM_HEIGHT 480 #define ANIM_FRAMES 64 +/* this could come from ftol, but we hardcode it for this example */ static key_t shm_key = 0xCAFEBEEF; + static gint bpp, width, height; -static guchar *shm = 0; /* shared mem */ +static guchar *shm = 0; /* shared mem area */ static int anim_frame = 0; static double scale = 1; @@ -44,7 +48,7 @@ static void timeout_cb (void *obj) { HildonRemoteTexture *actor = HILDON_REMOTE_TEXTURE (obj); - if (shm) { + if (shm && DO_ANIM) { gint x,y; for (y=0;y0.01 || fabs(y_inc)>0.01) + { + x += x_inc; + y += y_inc; + x_inc = x_inc * 0.8; + y_inc = y_inc * 0.8; + hildon_remote_texture_set_offset (actor, x, y); + } + + if (fabs(scale - scale_smooth)>0.01) + { + scale_smooth = scale_smooth*0.9 + scale*0.1; + hildon_remote_texture_set_scale (actor, scale_smooth, scale_smooth); + } } } @@ -116,7 +126,7 @@ static void motion_cb (GtkWidget *widget, x += x_inc; y += y_inc; - hildon_remote_texture_set_position (actor, x, y); + hildon_remote_texture_set_offset (actor, x, y); } last_x = event->x; @@ -146,8 +156,6 @@ main (int argc, char **argv) bpp = gdk_pixbuf_get_n_channels (pixbuf); /* assume 8 bit */ gpixels = gdk_pixbuf_get_pixels (pixbuf); g_debug("Creating Shared Memory"); - - size_t shm_size = width*height*bpp; int shmid; @@ -166,41 +174,36 @@ main (int argc, char **argv) } memcpy(shm, gpixels, shm_size); - g_debug("Done."); - - + /* Craete the program with the remote texture */ HildonProgram *program = hildon_program_get_instance (); - HildonWindow *window = HILDON_WINDOW( hildon_window_new()); hildon_program_add_window (program, window); - gtk_window_set_decorated (GTK_WINDOW (window), FALSE); gtk_widget_show (GTK_WIDGET(window)); HildonRemoteTexture *actor = HILDON_REMOTE_TEXTURE (hildon_remote_texture_new ()); - gtk_window_resize(GTK_WINDOW(actor), W, H); g_set_application_name ("Animation"); - g_signal_connect (G_OBJECT (actor), + g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL); - g_signal_connect (G_OBJECT (actor), + g_signal_connect (G_OBJECT (window), "button-press-event", G_CALLBACK (press_cb), actor); - g_signal_connect (G_OBJECT (actor), + g_signal_connect (G_OBJECT (window), "button-release-event", G_CALLBACK (release_cb), actor); - g_signal_connect (G_OBJECT (actor), + g_signal_connect (G_OBJECT (window), "motion-notify-event", G_CALLBACK (motion_cb), actor); - gtk_widget_add_events (GTK_WIDGET(actor), + gtk_widget_add_events (GTK_WIDGET(window), GDK_BUTTON_PRESS_MASK| GDK_BUTTON_MOTION_MASK| GDK_BUTTON_RELEASE_MASK); @@ -209,9 +212,12 @@ main (int argc, char **argv) gtk_widget_show_all (GTK_WIDGET (actor)); gdk_flush (); + /* vital: add this remote texture to a proper window */ hildon_remote_texture_set_parent(actor, GTK_WINDOW(window)); + /* Set the actual data we'll be displaying, via the shm key */ hildon_remote_texture_set_image(actor, shm_key, width, height, bpp); - hildon_remote_texture_set_position (actor, x, y); + /* Set the actual position on the screen */ + hildon_remote_texture_set_position (actor, 0, 56, W, H-56); hildon_remote_texture_set_show (actor, 1); g_timeout_add (25, (GSourceFunc)timeout_cb, actor); diff --git a/src/hildon-remote-texture-private.h b/src/hildon-remote-texture-private.h index a9a30eb..806cc22 100644 --- a/src/hildon-remote-texture-private.h +++ b/src/hildon-remote-texture-private.h @@ -45,6 +45,7 @@ struct _HildonRemoteTexturePrivate guint set_damage : 1; guint set_show : 1; guint set_position : 1; + guint set_offset : 1; guint set_scale : 1; guint set_parent : 1; @@ -61,8 +62,13 @@ struct _HildonRemoteTexturePrivate guint show; guint opacity; - double position_x; - double position_y; + gint x; + gint y; + gint width; + gint height; + + double offset_x; + double offset_y; double scale_x; double scale_y; diff --git a/src/hildon-remote-texture.c b/src/hildon-remote-texture.c index cc8f607..1dcd8ba 100644 --- a/src/hildon-remote-texture.c +++ b/src/hildon-remote-texture.c @@ -66,6 +66,7 @@ static guint32 shm_atom; static guint32 damage_atom; static guint32 show_atom; static guint32 position_atom; +static guint32 offset_atom; static guint32 scale_atom; static guint32 parent_atom; static guint32 ready_atom; @@ -109,6 +110,9 @@ hildon_remote_texture_realize (GtkWidget *widget) position_atom = gdk_x11_get_xatom_by_name_for_display (display, "_HILDON_TEXTURE_CLIENT_MESSAGE_POSITION"); + offset_atom = + gdk_x11_get_xatom_by_name_for_display + (display, "_HILDON_TEXTURE_CLIENT_MESSAGE_OFFSET"); scale_atom = gdk_x11_get_xatom_by_name_for_display (display, "_HILDON_TEXTURE_CLIENT_MESSAGE_SCALE"); @@ -123,6 +127,7 @@ hildon_remote_texture_realize (GtkWidget *widget) g_debug ("damage atom = %lu\n", damage_atom); g_debug ("show atom = %lu\n", show_atom); g_debug ("position atom = %lu\n", position_atom); + g_debug ("offset atom = %lu\n", offset_atom); g_debug ("scale atom = %lu\n", scale_atom); g_debug ("parent atom = %lu\n", parent_atom); g_debug ("ready atom = %lu\n", ready_atom); @@ -335,8 +340,15 @@ hildon_remote_texture_send_pending_messages (HildonRemoteTexture *self) if (priv->set_position) hildon_remote_texture_set_position (self, - priv->position_x, - priv->position_y); + priv->x, + priv->y, + priv->width, + priv->height); + + if (priv->set_offset) + hildon_remote_texture_set_offset (self, + priv->offset_x, + priv->offset_y); if (priv->set_scale) hildon_remote_texture_set_scale (self, @@ -453,6 +465,10 @@ hildon_remote_texture_set_image (HildonRemoteTexture *self, if (GTK_WIDGET_MAPPED (widget) && priv->ready) { + /* Defer messages until the remote texture is parented + * and the parent window is mapped */ + if (!priv->parent || !GTK_WIDGET_MAPPED (GTK_WIDGET (priv->parent))) + return; hildon_remote_texture_send_message (self, shm_atom, priv->shm_key, @@ -505,6 +521,10 @@ hildon_remote_texture_update_area (HildonRemoteTexture *self, if (GTK_WIDGET_MAPPED (widget) && priv->ready) { + /* Defer messages until the remote texture is parented + * and the parent window is mapped */ + if (!priv->parent || !GTK_WIDGET_MAPPED (GTK_WIDGET (priv->parent))) + return; hildon_remote_texture_send_message (self, damage_atom, priv->damage_x1, @@ -565,10 +585,8 @@ hildon_remote_texture_set_show_full (HildonRemoteTexture *self, { /* Defer show messages until the remote texture is parented * and the parent window is mapped */ - if (!priv->parent || !GTK_WIDGET_MAPPED (GTK_WIDGET (priv->parent))) return; - hildon_remote_texture_send_message (self, show_atom, show, opacity, @@ -620,11 +638,12 @@ hildon_remote_texture_set_opacity (HildonRemoteTexture *self, } /** - * hildon_remote_texture_set_position_full: + * hildon_remote_texture_set_position: * @self: A #HildonRemoteTexture * @x: Desired X coordinate * @y: Desired Y coordinate - * @depth: Desired window depth (Z coordinate) + * @width: Desired width + * @height: Desired height * * Send a message to the window manager setting the offset of the remote * texture in the window (in Remote texture's pixels). The texture @@ -636,6 +655,52 @@ hildon_remote_texture_set_opacity (HildonRemoteTexture *self, **/ void hildon_remote_texture_set_position (HildonRemoteTexture *self, + gint x, + gint y, + gint width, + gint height) +{ + HildonRemoteTexturePrivate + *priv = HILDON_REMOTE_TEXTURE_GET_PRIVATE (self); + GtkWidget *widget = GTK_WIDGET (self); + + priv->x = x; + priv->y = y; + priv->width = width; + priv->height = height; + priv->set_position = 1; + + if (GTK_WIDGET_MAPPED (widget) && priv->ready) + { + /* Defer messages until the remote texture is parented + * and the parent window is mapped */ + + if (!priv->parent || !GTK_WIDGET_MAPPED (GTK_WIDGET (priv->parent))) + return; + hildon_remote_texture_send_message (self, + position_atom, + x, y, + width, height, 0); + priv->set_position = 0; + } +} + +/** + * hildon_remote_texture_set_offset: + * @self: A #HildonRemoteTexture + * @x: Desired X offset + * @y: Desired Y offset + * + * Send a message to the window manager setting the offset of the remote + * texture in the window (in Remote texture's pixels). The texture + * is also subject to the animation effects rendered by the compositing + * window manager on that window (like those by task switcher). + * + * If the remote texture WM-counterpart is not ready, the show message + * will be queued until the WM is ready for it. + **/ +void +hildon_remote_texture_set_offset (HildonRemoteTexture *self, double x, double y) { @@ -643,17 +708,22 @@ hildon_remote_texture_set_position (HildonRemoteTexture *self, *priv = HILDON_REMOTE_TEXTURE_GET_PRIVATE (self); GtkWidget *widget = GTK_WIDGET (self); - priv->position_x = x; - priv->position_y = y; - priv->set_position = 1; + priv->offset_x = x; + priv->offset_y = y; + priv->set_offset = 1; if (GTK_WIDGET_MAPPED (widget) && priv->ready) { - hildon_remote_texture_send_message (self, - position_atom, - (gint)(x*65536), (gint)(y*65536), - 0, 0, 0); - priv->set_position = 0; + /* Defer messages until the remote texture is parented + * and the parent window is mapped */ + + if (!priv->parent || !GTK_WIDGET_MAPPED (GTK_WIDGET (priv->parent))) + return; + hildon_remote_texture_send_message (self, + offset_atom, + (gint)(x*65536), (gint)(y*65536), + 0, 0, 0); + priv->set_offset = 0; } } @@ -678,12 +748,16 @@ hildon_remote_texture_set_scale (HildonRemoteTexture *self, if (GTK_WIDGET_MAPPED (widget) && priv->ready) { - hildon_remote_texture_send_message (self, - scale_atom, - priv->scale_x * (1 << 16), - priv->scale_y * (1 << 16), - 0, 0, 0); - priv->set_scale = 0; + /* Defer messages until the remote texture is parented + * and the parent window is mapped */ + if (!priv->parent || !GTK_WIDGET_MAPPED (GTK_WIDGET (priv->parent))) + return; + hildon_remote_texture_send_message (self, + scale_atom, + priv->scale_x * (1 << 16), + priv->scale_y * (1 << 16), + 0, 0, 0); + priv->set_scale = 0; } } diff --git a/src/hildon-remote-texture.h b/src/hildon-remote-texture.h index 5889122..3bdfd1d 100644 --- a/src/hildon-remote-texture.h +++ b/src/hildon-remote-texture.h @@ -115,8 +115,14 @@ hildon_remote_texture_set_opacity (HildonRemoteTexture *self, gint opacity); void hildon_remote_texture_set_position (HildonRemoteTexture *self, - double x, - double y); + gint x, + gint y, + gint width, + gint height); +void +hildon_remote_texture_set_offset (HildonRemoteTexture *self, + double x, + double y); void hildon_remote_texture_set_scale (HildonRemoteTexture *self, double x_scale,