repo: rxvt-unicode-sixel
action: commit
revision: 
path_from: 
revision_from: 592c239b125c32f730d303569159d94668176429:
path_to: 
revision_to: 
git.thebackupbox.net
rxvt-unicode-sixel
git clone git://git.thebackupbox.net/rxvt-unicode-sixel
commit 592c239b125c32f730d303569159d94668176429
Author: Emanuele Giaquinta 
Date:   Sun Aug 29 15:04:40 2010 +0000

    Move code to set icon image to a new method.

diff --git a/src/init.C b/src/init.C
index a22d88c97b3fb6785ea8ee3cb3f91d5b907305e6..
index ..aa9795fdbbb4ccac88d40160c9fa6dd8b6aecb86 100644
--- a/src/init.C
+++ b/src/init.C
@@ -1281,6 +1281,54 @@ rxvt_term::get_ourmods ()
     ModMetaMask = modmasks[i - 1];
 }

+void
+rxvt_term::set_icon (const char *file)
+{
+#ifdef HAVE_AFTERIMAGE
+  init_asv ();
+
+  ASImage *im = file2ASImage (file, 0xFFFFFFFF, SCREEN_GAMMA, 0, NULL);
+  if (!im)
+    {
+      rxvt_warn ("Loading image icon failed, continuing without.\n");
+      return;
+    }
+
+  int w = im->width;
+  int h = im->height;
+
+  ASImage *result = scale_asimage (asv, im,
+                                   w, h, ASA_ARGB32,
+                                   100, ASIMAGE_QUALITY_DEFAULT);
+  destroy_asimage (&im);
+
+  if (!result)
+    {
+      rxvt_warn ("Icon image transformation to ARGB failed, continuing without.\n");
+      return;
+    }
+
+  long *buffer = (long *)malloc ((2 + w * h) * sizeof (long));
+  if (buffer)
+    {
+      ARGB32 *asbuf = result->alt.argb32;
+      buffer [0] = w;
+      buffer [1] = h;
+
+      for (unsigned int i = 0; i < w * h; ++i)
+        buffer [i + 2] = asbuf [i];
+
+      XChangeProperty (dpy, parent[0], xa[XA_NET_WM_ICON], XA_CARDINAL, 32,
+                       PropModeReplace, (const unsigned char *) buffer, 2 + w * h);
+      free (buffer);
+    }
+  else
+    rxvt_warn ("Memory allocation for icon hint failed, continuing without.\n");
+
+  destroy_asimage (&result);
+#endif
+}
+
 /*----------------------------------------------------------------------*/
 /* rxvt_Create_Windows () - Open and map the window */
 void
@@ -1370,7 +1418,6 @@ rxvt_term::create_windows (int argc, const char *const *argv)
   XmbSetWMProperties (dpy, top, NULL, NULL, (char **)argv, argc,
                       &szHint, &wmHint, &classHint);
 #if ENABLE_EWMH
-# ifdef HAVE_AFTERIMAGE
   /*
    * set up icon hint
    * rs [Rs_iconfile] is path to icon
@@ -1378,46 +1425,8 @@ rxvt_term::create_windows (int argc, const char *const *argv)

   if (rs [Rs_iconfile])
     {
-      init_asv ();
-
-      ASImage *im = file2ASImage (rs [Rs_iconfile], 0xFFFFFFFF, SCREEN_GAMMA, 0, NULL);
-      if (im)
-        {
-          int w = im->width;
-          int h = im->height;
-          ASImage *result = scale_asimage (asv, im,
-                                           w, h, ASA_ARGB32,
-                                           100, ASIMAGE_QUALITY_DEFAULT);
-          destroy_asimage (&im);
-
-          if (result)
-            {
-              long *buffer = (long *)malloc ((2 + w * h) * sizeof (long));
-              if (buffer)
-                {
-                  ARGB32 *asbuf = result->alt.argb32;
-                  buffer [0] = w;
-                  buffer [1] = h;
-
-                  for (unsigned int i = 0; i < w * h; ++i)
-                    buffer [i + 2] = asbuf [i];
-
-                  XChangeProperty (dpy, top, xa[XA_NET_WM_ICON], XA_CARDINAL, 32,
-                                   PropModeReplace, (const unsigned char *) buffer, 2 + w * h);
-                  free (buffer);
-                }
-              else
-                rxvt_warn ("Memory allocation for icon hint failed, continuing without.\n");
-
-              destroy_asimage (&result);
-            }
-          else
-            rxvt_warn ("Icon image transformation to ARGB failed, continuing without.\n");
-        }
-      else
-        rxvt_warn ("Loading image icon failed, continuing without.\n");
+      set_icon (rs [Rs_iconfile]);
     }
-# endif
 #endif

 #if ENABLE_FRILLS
diff --git a/src/rxvt.h b/src/rxvt.h
index 32e4ed41ae6956644b4281ef2eb3938ecf1b7cf5..
index ..cf332c4a5f8b314848e9e1c22f177ee0e004538e 100644
--- a/src/rxvt.h
+++ b/src/rxvt.h
@@ -1299,6 +1299,7 @@ struct rxvt_term : zero_initialized, rxvt_vars, rxvt_screen
   void create_windows (int argc, const char *const *argv);
   void get_colours ();
   void get_ourmods ();
+  void set_icon (const char *file);
   // main.C
   void tt_winch ();
   rxvt_term ();

-----END OF PAGE-----