Description: Fix illegal memory access by ui_window_set_icon().
* ui_window.[ch]:
  - Fix illegal memory access by ui_window_set_icon().
    (u_int32_t -> u_long)
    (enbugged at 3d38b723e0e4a6dd434af2d49aca53890982a828)
  - Execute initialization code for a root window in ui_window_show()
    even if --parent option is specified.
    (Related to https://github.com/arakiken/mlterm/issues/118)
  - Add HINT_CHILD_WINDOW_ATTR for libvte compatible libraray.
Date: Fri Jan 3 02:01:40 2025 +0900
Origin: upstream, commit: 4eb3aa4bba9d918b1923b5a46a67c92142ecaade
Bug-Debian: https://bugs.debian.org/1089753
Index: mlterm/gtk/vte_xlib.c
===================================================================
--- mlterm.orig/gtk/vte_xlib.c	2025-01-06 15:56:15.723221871 +0100
+++ mlterm/gtk/vte_xlib.c	2025-01-06 15:56:15.719221924 +0100
@@ -499,7 +499,8 @@
   }
 #endif
 
-  ui_display_show_root(disp, &PVT(terminal)->screen->window, 0, 0, 0, "mlterm", NULL, xid);
+  ui_display_show_root(disp, &PVT(terminal)->screen->window, 0, 0,
+                       HINT_CHILD_WINDOW_ATTR, "mlterm", NULL, xid);
 
 #if GTK_CHECK_VERSION(2, 90, 0) && defined(GDK_TYPE_X11_DEVICE_MANAGER_XI2)
   if (is_xinput2) {
Index: mlterm/uitoolkit/ui_window.h
===================================================================
--- mlterm.orig/uitoolkit/ui_window.h	2025-01-06 15:56:15.723221871 +0100
+++ mlterm/uitoolkit/ui_window.h	2025-01-06 15:56:15.719221924 +0100
@@ -25,6 +25,13 @@
  */
 #define PARENT_WINDOWID_IS_TOP(win) ((win)->parent_window == (win)->disp->my_window)
 
+/*
+ * Hint for libvte (x11), in addition to bitmask hints (0x0-0x20) returned by
+ * XParseGeometry().
+ * (see ui_window_show(), Xutil.h)
+ */
+#define HINT_CHILD_WINDOW_ATTR 0x1000
+
 typedef enum ui_resize_flag {
   NOTIFY_TO_NONE = 0x0,
   NOTIFY_TO_CHILDREN = 0x01,
Index: mlterm/uitoolkit/xlib/ui_window.c
===================================================================
--- mlterm.orig/uitoolkit/xlib/ui_window.c	2025-01-06 15:56:15.723221871 +0100
+++ mlterm/uitoolkit/xlib/ui_window.c	2025-01-06 15:56:15.719221924 +0100
@@ -76,11 +76,11 @@
   ((win)->height_inc ? ((win)->height - (win)->min_height) % (win)->height_inc : 0)
 
 typedef struct {
-  u_int32_t flags;
-  u_int32_t functions;
-  u_int32_t decorations;
-  int32_t inputMode;
-  u_int32_t status;
+  u_long flags;
+  u_long functions;
+  u_long decorations;
+  u_long inputMode;
+  u_long status;
 } MWMHints_t;
 
 #define MWM_HINTS_ELEMENTS      5
@@ -1344,29 +1344,8 @@
                           ACTUAL_HEIGHT(win), 0, win->fg_color.pixel, win->bg_color.pixel);
 #endif
 
-  if (win->create_gc) {
-    ui_gc_t *gc;
-
-    if ((gc = ui_gc_new(win->disp->display, win->my_window)) == NULL) {
-#ifdef DEBUG
-      bl_debug_printf(BL_DEBUG_TAG " ui_gc_new failed.\n");
-#endif
-      win->create_gc = 0;
-    } else {
-      win->gc = gc;
-    }
-  }
-
-  if (win->cursor_shape) {
-    Cursor cursor;
-
-    if ((cursor = ui_display_get_cursor(win->disp, win->cursor_shape))) {
-      XDefineCursor(win->disp->display, win->my_window, cursor);
-    }
-  }
-
   /* Don't use win->parent here in case mlterm works as libvte. */
-  if (PARENT_WINDOWID_IS_TOP(win)) {
+  if (PARENT_WINDOWID_IS_TOP(win) || !(hint & HINT_CHILD_WINDOW_ATTR)) {
     /* Root window */
 
     XSizeHints size_hints;
@@ -1378,9 +1357,11 @@
         "mlterm", NULL,
     };
     Atom protocols[2];
-    XID pid;
+    u_long pid;
 
     win->event_mask |= StructureNotifyMask;
+    /* Call XSelectInput just after creating a new Window not to miss any events. */
+    XSelectInput(win->disp->display, win->my_window, win->event_mask);
 
     /*
      * XXX
@@ -1466,6 +1447,30 @@
                       8, PropModeReplace, (unsigned char *)win->wm_role,
                       (int)strlen(win->wm_role));
     }
+  } else {
+    /* Call XSelectInput just after creating a new Window not to miss any events. */
+    XSelectInput(win->disp->display, win->my_window, win->event_mask);
+  }
+
+  if (win->create_gc) {
+    ui_gc_t *gc;
+
+    if ((gc = ui_gc_new(win->disp->display, win->my_window)) == NULL) {
+#ifdef DEBUG
+      bl_debug_printf(BL_DEBUG_TAG " ui_gc_new failed.\n");
+#endif
+      win->create_gc = 0;
+    } else {
+      win->gc = gc;
+    }
+  }
+
+  if (win->cursor_shape) {
+    Cursor cursor;
+
+    if ((cursor = ui_display_get_cursor(win->disp, win->cursor_shape))) {
+      XDefineCursor(win->disp->display, win->my_window, cursor);
+    }
   }
 
   if (win->parent && !win->parent->is_transparent && win->parent->wall_picture_is_set) {
@@ -1480,8 +1485,6 @@
     (*win->window_realized)(win);
   }
 
-  XSelectInput(win->disp->display, win->my_window, win->event_mask);
-
 #if 0
   {
     char *locale;
@@ -3179,7 +3182,7 @@
   /* set extended window manager hint's icon */
   if (icon->cardinal && icon->cardinal[0] && icon->cardinal[1]) {
     int num;
-    u_int32_t *data;
+    u_long *data;
 
     /* width * height + 2 */
     num = icon->cardinal[0] * icon->cardinal[1] + 2;
@@ -3187,7 +3190,7 @@
     if (sizeof(u_long) != 4) {
       int count;
 
-      if (!(data = alloca(sizeof(u_int32_t) * num))) {
+      if (!(data = alloca(sizeof(u_long) * num))) {
         return;
       }
 
@@ -3195,7 +3198,7 @@
         data[count] = icon->cardinal[count];
       }
     } else {
-      data = icon->cardinal;
+      data = (u_long*)icon->cardinal;
     }
 
     /*it should be possible to set multiple icons...*/
