On Wed, 10 Dec 2008 13:08:26 -0500
Barry deFreese <bdefre...@debian.org> wrote:
> Here is a patch I started.  It does build but segfaults and I'm
> probably a bit over my head.  Hope this helps at least a little.

This patch works for me. The configure stuff might be completely wrong
though.

-- 
Peter De Wachter
--- a/Makefile.am
+++ b/Makefile.am
@@ -3,10 +3,12 @@
 bin_PROGRAMS = xteddy
 
 xteddy_SOURCES = xteddy.c
-LIBS = `imlib-config --libs`
 man_MANS = xteddy.6
 bin_SCRIPTS = xtoys xteddy_test
 
+AM_CFLAGS  = @IMLIB2_CFLAGS@
+AM_LDFLAGS = @IMLIB2_LIBS@ -lX11
+
 DEFS = -DPIXMAP_PATH=\"@pixmap_p...@\" -Wall
 
 SUBDIRS = html images
--- a/configure.in
+++ b/configure.in
@@ -4,7 +4,7 @@ AM_INIT_AUTOMAKE(xteddy, 2.1)
 AC_PROG_CC
 
 AC_PATH_XTRA
-AC_CHECK_LIB(Imlib, main, , , $X_LIBS -lX11)
+PKG_CHECK_MODULES(IMLIB2, imlib2)
 
 PIXMAP_PATH="/usr/share/xteddy"
 AC_SUBST(PIXMAP_PATH)
--- a/debian/control
+++ b/debian/control
@@ -4,7 +4,7 @@ Priority: optional
 Maintainer: Debian Games Team <pkg-games-de...@lists.alioth.debian.org>
 Uploaders: Andreas Tille <ti...@debian.org>
 DM-Upload-Allowed: yes
-Build-Depends: debhelper (>= 6.0.7), imlib11-dev (>= 1.9.14-16), quilt
+Build-Depends: debhelper (>= 6.0.7), libimlib2-dev, quilt
 Standards-Version: 3.8.0
 Vcs-Svn: svn://svn.debian.org/svn/pkg-games/packages/trunk/xteddy/
 Vcs-Browser: http://svn.debian.org/wsvn/pkg-games/packages/trunk/xteddy/?op=log
--- a/xteddy.c
+++ b/xteddy.c
@@ -28,7 +28,7 @@
 #include <X11/extensions/shape.h>
 #include <X11/cursorfont.h>
 
-#include <Imlib.h>
+#include <Imlib2.h>
 
 #include <ctype.h>
 #include <stdio.h>
@@ -130,9 +130,11 @@ int main(int argc, char **argv)
 {
   /* Display, window and gc manipulation variables */
   Window               win;
+  Pixmap               pm_image, pm_mask;
   XSetWindowAttributes setwinattr;
   unsigned long        valuemask, inputmask;
-  int                  x, y, geomflags, xw, xh;
+  int                  x, y, geomflags;
+  unsigned int         xw, xh;
   unsigned int         border_width = 0;
   unsigned int         display_width, display_height;
   XSizeHints           size_hints;
@@ -158,8 +160,8 @@ int main(int argc, char **argv)
   int                  offs_x, offs_y, new_x, new_y, tmp_x, tmp_y;
   unsigned int         tmp_mask;
 
-  ImlibData           *id;
-  ImlibImage          *im;
+  Imlib_Image         *im;
+  int                  im_width, im_height;
 
   /* Determine program name */
   if ((progname = strrchr(argv[0],'/')) == NULL)
@@ -232,33 +234,51 @@ int main(int argc, char **argv)
   display_width  = DisplayWidth(display, screen_num);
   display_height = DisplayHeight(display, screen_num);
 
-  if ( !(id=Imlib_init(display)) ) return -1;
+  /* set the maximum number of colors to allocate for 8bpp and less to 128 */  
+  imlib_set_color_usage(128);
+  /* dither for depths < 24bpp */
+  imlib_context_set_dither(1);
+  /* set the display, visual and colormap we are using */  
+  imlib_context_set_display(display);
+  imlib_context_set_visual(DefaultVisual(display, DefaultScreen(display)));
+  imlib_context_set_colormap(DefaultColormap(display, DefaultScreen(display)));
+
   if ( !(file = InitTeddy(teddy)) ) {
     fprintf(stderr, "Can not find any image with name '%s'.\n", teddy);
     return -1;
   }
-  if ( !(im=Imlib_load_image(id, file)) ) {
+  if ( !(im=imlib_load_image_immediately(file)) ) {
     fprintf(stderr, "Most probably, the file '%s' is not a valid image.\n", teddy);
     return -1;
   }
+  imlib_context_set_image(im);
+  im_width = imlib_image_get_width();
+  im_height = imlib_image_get_height();
   /* Set the window position according to user preferences */
   if (geomflags & XNegative)
-    x = display_width - im->rgb_width + x;
+    x = display_width - im_width + x;
   if (geomflags & YNegative)
-    y = display_height - im->rgb_height + y;
+    y = display_height - im_height + y;
   /* Clip against bounds to stay on the screen */
   if (x<0) x=0;
-  if (x > display_width - im->rgb_width) x = display_width - im->rgb_width;
+  if (x > display_width - im_width) x = display_width - im_width;
   if (y<0) y=0;
-  if (y > display_height - im->rgb_height) y = display_height - im->rgb_height;
+  if (y > display_height - im_height) y = display_height - im_height;
 
   /* Create the main window */
   win = XCreateSimpleWindow(display, DefaultRootWindow(display),
-			    x,y,im->rgb_width,im->rgb_height,border_width,
+			    x,y,im_width,im_height,border_width,
 			    BlackPixel(display,screen_num),
 			    WhitePixel(display,screen_num));
   XSelectInput(display,win,StructureNotifyMask);
-  Imlib_apply_image(id,im,win);
+
+  imlib_context_set_drawable(win);
+  imlib_render_pixmaps_for_whole_image(&pm_image, &pm_mask);
+  XSetWindowBackgroundPixmap(display, win, pm_image);
+  XShapeCombineMask(display, win, ShapeBounding, 0, 0, pm_mask, ShapeSet);
+  XFreePixmap(display, pm_image);
+  XFreePixmap(display, pm_mask);
+  imlib_free_image_and_decache();
 
   basewin = win;
 
@@ -272,15 +292,14 @@ int main(int argc, char **argv)
   XChangeWindowAttributes(display, win, valuemask, &setwinattr);
 
   /* Report size hints and other stuff to the window manager */
-  size_hints.min_width  = im->rgb_width;    /* Don't allow any resizing */
-  size_hints.min_height = im->rgb_height;
-  size_hints.max_width  = im->rgb_width;
-  size_hints.max_height = im->rgb_height;
+  size_hints.min_width  = im_width;    /* Don't allow any resizing */
+  size_hints.min_height = im_height;
+  size_hints.max_width  = im_width;
+  size_hints.max_height = im_height;
   size_hints.flags = PPosition | PSize | PMinSize | PMaxSize;
   if (XStringListToTextProperty(&(teddy), 1, &windowName) == 0)
     {
       (void) fprintf(stderr, "%s: structure allocation for windowName failed.\n", progname);
-      Imlib_kill_image(id, im);
       return -1;
     }
   wm_hints.initial_state = NormalState;
@@ -309,20 +328,6 @@ int main(int argc, char **argv)
       XNextEvent(display, &report);
       switch(report.type)
 	{
-	case Expose:
-	  if (report.xexpose.count != 0)
-	    break;
-	  else
-	    {
-	      /* No drawing needed - the background pixmap */
-	      /* is handled automatically by the X server  */
-	    }
-	  break;
-	case ConfigureNotify:
-	  /* Window has been resized */
-          Imlib_apply_image(id,im,win);
-          XSync(display,False);
-	  break;
 	case ReparentNotify:
 	  /* Window was reparented by the window manager */
 	  if (!use_wm)
@@ -382,7 +387,6 @@ int main(int argc, char **argv)
 	    {
               if (allow_quit)
 		{
-                  Imlib_kill_image(id, im);
 		  XCloseDisplay(display);
 		  return 0;
 		}

Reply via email to