[mousetweaks/gnome-2-26] Fix cursor drawing on 64bit platforms - bgo#584256
- From: Gerd Kohlberger <gerdk src gnome org>
- To: svn-commits-list gnome org
- Subject: [mousetweaks/gnome-2-26] Fix cursor drawing on 64bit platforms - bgo#584256
- Date: Sun, 31 May 2009 03:39:26 -0400 (EDT)
commit ef9f4cb05972c6f3adbc1461dbc411af4da9411f
Author: Gerd Kohlberger <gerdk src gnome org>
Date: Sun May 31 09:14:41 2009 +0200
Fix cursor drawing on 64bit platforms - bgo#584256
---
src/mt-cursor-manager.c | 43 ++++++++++++++++++++++++++++++++-----------
src/mt-cursor.c | 30 ++----------------------------
2 files changed, 34 insertions(+), 39 deletions(-)
diff --git a/src/mt-cursor-manager.c b/src/mt-cursor-manager.c
index 61a1405..aba23e2 100644
--- a/src/mt-cursor-manager.c
+++ b/src/mt-cursor-manager.c
@@ -102,30 +102,34 @@ static void
mt_cursor_manager_set_xcursor (MtCursor *cursor)
{
XcursorImage *ximage;
- const guchar *image;
const gchar *name;
Cursor xcursor;
gushort width, height;
gushort xhot, yhot;
- mt_cursor_get_hotspot (cursor, &xhot, &yhot);
mt_cursor_get_dimension (cursor, &width, &height);
- image = mt_cursor_get_image (cursor);
-
ximage = XcursorImageCreate (width, height);
- ximage->xhot = xhot;
- ximage->yhot = yhot;
- ximage->delay = 0;
- ximage->pixels = (XcursorPixel *) image;
+ xcursor = 0;
+
+ if (ximage) {
+ mt_cursor_get_hotspot (cursor, &xhot, &yhot);
+
+ ximage->xhot = xhot;
+ ximage->yhot = yhot;
+ ximage->delay = 0;
+ ximage->pixels = (XcursorPixel *) mt_cursor_get_image (cursor);
- xcursor = XcursorImageLoadCursor (GDK_DISPLAY (), ximage);
- XcursorImageDestroy (ximage);
+ xcursor = XcursorImageLoadCursor (GDK_DISPLAY (), ximage);
+ XcursorImageDestroy (ximage);
+ }
if (xcursor) {
name = mt_cursor_get_name (cursor);
+
XFixesSetCursorName (GDK_DISPLAY (), xcursor, name);
XFixesChangeCursorByName (GDK_DISPLAY (), xcursor, name);
XFreeCursor (GDK_DISPLAY (), xcursor);
+
gdk_flush ();
}
}
@@ -144,8 +148,25 @@ mt_cursor_manager_add_cursor (MtCursorManager *manager,
{
MtCursor *cursor;
MtCursorManagerPrivate *priv;
+ guint32 *copy;
+ guchar *pixels;
+ guint i, n_pixels;
+
+ /* convert cursor image on x64 arch */
+ if (sizeof (unsigned long) != sizeof (guint32)) {
+ n_pixels = image->width * image->height;
+ copy = g_new (guint32, n_pixels);
+
+ for (i = 0; i < n_pixels; i++)
+ copy[i] = image->pixels[i];
+
+ pixels = (guchar *) copy;
+ }
+ else
+ pixels = (guchar *) image->pixels;
+
- cursor = mt_cursor_new (image->name, (guchar *) image->pixels,
+ cursor = mt_cursor_new (image->name, pixels,
image->width, image->height,
image->xhot, image->yhot);
diff --git a/src/mt-cursor.c b/src/mt-cursor.c
index a890c03..05ee4b2 100644
--- a/src/mt-cursor.c
+++ b/src/mt-cursor.c
@@ -18,7 +18,6 @@
*/
#include <glib.h>
-#include <string.h>
#include "mt-cursor.h"
@@ -74,23 +73,6 @@ mt_cursor_finalize (GObject *object)
G_OBJECT_CLASS (mt_cursor_parent_class)->finalize (object);
}
-static guchar *
-mt_cursor_copy_image (guchar *image,
- gushort width,
- gushort height)
-{
- guchar *copy;
- gulong n_bytes;
-
- n_bytes = width * height * 4;
- copy = (guchar *) g_try_malloc (n_bytes);
-
- if (copy)
- memcpy (copy, image, n_bytes);
-
- return copy;
-}
-
MtCursor *
mt_cursor_new (const gchar *name,
guchar *image,
@@ -101,7 +83,6 @@ mt_cursor_new (const gchar *name,
{
MtCursor *cursor;
MtCursorPrivate *priv;
- guchar *copy;
g_return_val_if_fail (name != NULL, NULL);
g_return_val_if_fail (image != NULL, NULL);
@@ -111,15 +92,10 @@ mt_cursor_new (const gchar *name,
if (*name == 0)
return NULL;
- copy = mt_cursor_copy_image (image, width, height);
- if (!copy)
- return NULL;
-
cursor = g_object_new (MT_TYPE_CURSOR, NULL);
priv = MT_CURSOR_GET_PRIVATE (cursor);
-
priv->name = g_strdup (name);
- priv->image = copy;
+ priv->image = g_memdup (image, width * height * 4);
priv->width = width;
priv->height = height;
priv->xhot = xhot;
@@ -148,14 +124,12 @@ guchar *
mt_cursor_get_image_copy (MtCursor *cursor)
{
MtCursorPrivate *priv;
- guchar *image;
g_return_val_if_fail (MT_IS_CURSOR (cursor), NULL);
priv = MT_CURSOR_GET_PRIVATE(cursor);
- image = mt_cursor_copy_image (priv->image, priv->width, priv->height);
- return image;
+ return g_memdup (priv->image, priv->width * priv->height * 4);
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]