///| test "parse_display: local displays only" { assert_eq(@x11.parse_display(":0"), Some((0, 0))) assert_eq(@x11.parse_display(":1.2"), Some((1, 2))) assert_eq(@x11.parse_display("unix:10"), Some((10, 0))) assert_eq(@x11.parse_display("localhost:10.0"), None) assert_eq(@x11.parse_display(""), None) assert_eq(@x11.parse_display(":"), None) } ///| One Xauthority entry: family, address, display number, auth name, data (big-endian lengths). fn xauth_entry(family : Int, addr : String, num : String, data : Array[Byte]) -> Array[Byte] { let out : Array[Byte] = [] fn field(b : Array[Byte]) -> Unit { out.push(((b.length() >> 8) & 0xFF).to_byte()) out.push((b.length() & 0xFF).to_byte()) for c in b { out.push(c) } } fn text(s : String) -> Array[Byte] { let b : Array[Byte] = [] for c in s { b.push(c.to_int().to_byte()) } b } out.push(((family >> 8) & 0xFF).to_byte()) out.push((family & 0xFF).to_byte()) field(text(addr)) field(text(num)) field(text("MIT-MAGIC-COOKIE-1")) field(data) out } ///| test "xauth_cookie: picks this host's entry for the display" { let file : Array[Byte] = [] file.append(xauth_entry(256, "otherhost", "0", [b'\x01'])) file.append(xauth_entry(256, "rig", "1", [b'\x02'])) file.append(xauth_entry(256, "rig", "0", [b'\x03', b'\x04'])) let f = Bytes::from_array(file) assert_eq(@x11.xauth_cookie(f, 0, "rig").to_array(), [b'\x03', b'\x04']) assert_eq(@x11.xauth_cookie(f, 1, "rig").to_array(), [b'\x02']) // No entry for this host: any local one for the display. assert_eq(@x11.xauth_cookie(f, 0, "elsewhere").to_array(), [b'\x01']) assert_eq(@x11.xauth_cookie(f, 7, "rig").length(), 0) // FamilyWild (xauth's "ffff" entries, as Docker setups write) matches any host. let wild = Bytes::from_array(xauth_entry(0xFFFF, "", "0", [b'\x09'])) assert_eq(@x11.xauth_cookie(wild, 0, "rig").to_array(), [b'\x09']) } ///| fn utf8_bytes(s : String) -> Array[Byte] { let out : Array[Byte] = [] for c in s { out.push(c.to_int().to_byte()) } out } ///| fn le32_bytes(vals : Array[Int]) -> Array[Byte] { let out : Array[Byte] = [] for v in vals { out.push((v & 0xFF).to_byte()) out.push(((v >> 8) & 0xFF).to_byte()) out.push(((v >> 16) & 0xFF).to_byte()) out.push(((v >> 24) & 0xFF).to_byte()) } out } ///| fn rd32(b : Array[Byte], off : Int) -> Int { b[off].to_int() | (b[off + 1].to_int() << 8) | (b[off + 2].to_int() << 16) | (b[off + 3].to_int() << 24) } ///| test "parse_wm_class splits instance and class" { assert_eq(@x11.parse_wm_class(utf8_bytes("ghostty\u0000com.mitchellh.ghostty\u0000")), ("ghostty", "com.mitchellh.ghostty")) assert_eq(@x11.parse_wm_class(utf8_bytes("steamwebhelper\u0000steam\u0000")), ("steamwebhelper", "steam")) assert_eq(@x11.parse_wm_class(utf8_bytes("astra\u0000astra\u0000")), ("astra", "astra")) assert_eq(@x11.parse_wm_class(utf8_bytes("single")), ("single", "")) assert_eq(@x11.parse_wm_class([]), ("", "")) } ///| test "parse_u32_list decodes little-endian 32-bit properties" { assert_eq(@x11.parse_u32_list([]), []) assert_eq(@x11.parse_u32_list(le32_bytes([0x01200007])), [0x01200007]) assert_eq(@x11.parse_u32_list(le32_bytes([0x00400001, 0x01200007, 0x01400003])), [0x00400001, 0x01200007, 0x01400003]) } ///| test "is_taskbar_window filters self, skip-taskbar, non-task types, and child dialogs" { let clients : Map[Int, Bool] = { 100: true, 200: true } let skip = 10 let t_norm = 20 let t_dlg = 21 let t_dock = 22 let t_util = 23 // Chandra's own window and zero are skipped. assert_false(@x11.is_taskbar_window(0, 50, [], skip, [t_norm], t_norm, t_dlg, 0, clients)) assert_false(@x11.is_taskbar_window(50, 50, [], skip, [t_norm], t_norm, t_dlg, 0, clients)) // _NET_WM_STATE_SKIP_TASKBAR is skipped. assert_false(@x11.is_taskbar_window(100, 50, [skip], skip, [t_norm], t_norm, t_dlg, 0, clients)) // Dock/utility/unknown window types are skipped when window types are present. assert_false(@x11.is_taskbar_window(100, 50, [], skip, [t_dock], t_norm, t_dlg, 0, clients)) assert_false(@x11.is_taskbar_window(100, 50, [], skip, [t_util], t_norm, t_dlg, 0, clients)) // Transient child dialog whose parent is in client_set is skipped. assert_false(@x11.is_taskbar_window(200, 50, [], skip, [t_dlg], t_norm, t_dlg, 100, clients)) // Normal window, standalone dialog (or transient for root 1), and untyped ICCCM window appear. assert_true(@x11.is_taskbar_window(100, 50, [], skip, [t_norm], t_norm, t_dlg, 0, clients)) assert_true(@x11.is_taskbar_window(200, 50, [], skip, [t_dlg], t_norm, t_dlg, 0, clients)) assert_true(@x11.is_taskbar_window(200, 50, [], skip, [t_dlg], t_norm, t_dlg, 1, clients)) assert_true(@x11.is_taskbar_window(100, 50, [], skip, [], t_norm, t_dlg, 0, clients)) } ///| test "build_client_msg_body and build_raise_body encode exact X11 wire payloads" { let msg = @x11.build_client_msg_body(0x200, 0x01200007, 300, 2, 11, 12, 2, 0) assert_eq(msg.length(), 40) assert_eq(rd32(msg, 0), 0x200) // root assert_eq(rd32(msg, 4), 0x180000) // SubstructureRedirectMask | SubstructureNotifyMask assert_eq(msg[8].to_int(), 33) // ClientMessage assert_eq(msg[9].to_int(), 32) // format 32 assert_eq(rd32(msg, 12), 0x01200007) // target window assert_eq(rd32(msg, 16), 300) // message type atom assert_eq(rd32(msg, 20), 2) assert_eq(rd32(msg, 24), 11) assert_eq(rd32(msg, 28), 12) assert_eq(rd32(msg, 32), 2) assert_eq(rd32(msg, 36), 0) let raise_body = @x11.build_raise_body(0x01200007) assert_eq(raise_body.length(), 12) assert_eq(rd32(raise_body, 0), 0x01200007) assert_eq(raise_body[4].to_int() | (raise_body[5].to_int() << 8), 0x40) // CWStackMode assert_eq(rd32(raise_body, 8), 0) // Above }