diff src/X_supp.c @ 757:f43224bf3524

Remove unused variables and refactor to X_MB_init_with_win
author Thinker K.F. Li <thinker@codemud.net>
date Thu, 26 Aug 2010 17:54:11 +0800
parents cceac4ba259e
children 586e50f82c1f
line wrap: on
line diff
--- a/src/X_supp.c	Thu Aug 26 14:54:50 2010 +0800
+++ b/src/X_supp.c	Thu Aug 26 17:54:11 2010 +0800
@@ -591,7 +591,7 @@
     }
 
     xmb_rt->backend_surface =
-	mbe_image_surface_create_for_data(ximage->data,
+	mbe_image_surface_create_for_data((unsigned char *)ximage->data,
 					  surf_fmt,
 					  xmb_rt->w,
 					  xmb_rt->h,
@@ -603,22 +603,23 @@
 
 /*! \brief Initialize a MadButterfy runtime for Xlib.
  *
- * It setups a runtime environment to run MadButterfly with Xlib.
- * Users should specify width and height of the opening window.
+ * This one is very like X_MB_init(), except it accepts a
+ * X_MB_runtime_t object initialized with a display connected to a X
+ * server and an opened window.
+ *
+ * Following field of the X_MB_runtime_t object should be initialized.
+ *   - w, h
+ *   - win
+ *   - display
+ *   - visual
  */
-static int X_MB_init(const char *display_name,
-	      int w, int h, X_MB_runtime_t *xmb_rt) {
+static int
+X_MB_init_with_win(X_MB_runtime_t *xmb_rt) {
     mb_img_ldr_t *img_ldr;
-    int r;
+    int w, h;
     
-    memset(xmb_rt, 0, sizeof(X_MB_runtime_t));
-
-    xmb_rt->w = w;
-    xmb_rt->h = h;
-    r = X_init_connection(display_name, w, h, &xmb_rt->display,
-			  &xmb_rt->visual, &xmb_rt->win);
-    if(r != OK)
-	return ERR;
+    w = xmb_rt->w;
+    h = xmb_rt->h;
 
 #ifdef XSHM
     xshm_init(xmb_rt);
@@ -648,8 +649,6 @@
     //        to get the xmb_rt->tman for the animation. We should relocate the tman
     //	      to the redraw_man_t instead.
     xmb_rt->rdman->rt = xmb_rt;
-    xmb_rt->rdman->w = w;
-    xmb_rt->rdman->h = h;
 
     xmb_rt->tman = mb_tman_new();
 
@@ -667,6 +666,29 @@
     return OK;
 }
 
+/*! \brief Initialize a MadButterfy runtime for Xlib.
+ *
+ * It setups a runtime environment to run MadButterfly with Xlib.
+ * Users should specify width and height of the opening window.
+ */
+static int X_MB_init(const char *display_name,
+	      int w, int h, X_MB_runtime_t *xmb_rt) {
+    int r;
+    
+    memset(xmb_rt, 0, sizeof(X_MB_runtime_t));
+
+    xmb_rt->w = w;
+    xmb_rt->h = h;
+    r = X_init_connection(display_name, w, h, &xmb_rt->display,
+			  &xmb_rt->visual, &xmb_rt->win);
+    if(r != OK)
+	return ERR;
+
+    r = X_MB_init_with_win(xmb_rt);
+    
+    return r;
+}
+
 static void X_MB_destroy(X_MB_runtime_t *xmb_rt) {
     if(xmb_rt->rdman) {
 	redraw_man_destroy(xmb_rt->rdman);