///| Client-side decorated windows: GTK apps (GNOME Files, most GNOME apps) never ask for /// server-side decoration, draw their own title bar, and put a shadow around it in the buffer. ///| The shadow a GTK window draws around itself, in buffer pixels. let gtk_shadow : Int = 24 ///| Answer the last configure the way GTK does: a buffer `w` x `h` plus the shadow on every /// side, the visible window (solid red, its own title bar included) announced with /// set_window_geometry, the shadow transparent. fn gtk_frame( comp : @host.ChandraCompositor, c : TestWaylandClient, shm : UInt, surf : UInt, xdg : UInt, tl : UInt, ) -> (Int, Int) { for _i = 0; _i < 6; _i = _i + 1 { comp.step() c.read_events(xdg, tl, 0U) @sys.sleep_ms(2) } for cfg in c.configures { let ack = @wayland.WireWriter::new() ack.u32(cfg.3) c.send(ack.finish_msg(xdg, 4U)) } c.configures.clear() let w = c.configured_w let h = c.configured_h let s = gtk_shadow let bw = w + 2 * s let bh = h + 2 * s let px : Array[Byte] = Array(capacity=bw * bh * 4) for y = 0; y < bh; y = y + 1 { for x = 0; x < bw; x = x + 1 { if x >= s && x < s + w && y >= s && y < s + h { px.push(b'\x00') px.push(b'\x00') px.push(b'\xff') px.push(b'\xff') } else { for _k = 0; _k < 4; _k = _k + 1 { px.push(b'\x00') } } } } let fd = @sys.memfd_create("gtk-frame", bw * bh * 4) ignore(@sys.pwrite_bytes(fd, Bytes::from_array(px), 0)) let pool = c.alloc_id() let p = @wayland.WireWriter::new() p.u32(pool) p.i32(bw * bh * 4) c.send(p.finish_msg(shm, 0U), send_fd=fd) @sys.close_fd(fd) let buf = c.alloc_id() let cb = @wayland.WireWriter::new() cb.u32(buf) cb.i32(0) cb.i32(bw) cb.i32(bh) cb.i32(bw * 4) cb.u32(0U) c.send(cb.finish_msg(pool, 0U)) // xdg_surface.set_window_geometry(x, y, w, h) let g = @wayland.WireWriter::new() g.i32(s) g.i32(s) g.i32(w) g.i32(h) c.send(g.finish_msg(xdg, 3U)) attach_commit(comp, c, surf, Some(buf)) (w, h) } ///| fn csd_setup(name : String) -> (@host.ChandraCompositor, TestWaylandClient, UInt, UInt, UInt, UInt) { let socket_path = "/tmp/wayland-moon-csd-" + name + "-" + @sys.getpid().to_string() + ".sock" let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap() comp.set_layout_mode(@wm.LayoutMode::Floating) let (c, shm, surf, xdg, tl, _) = open_and_configure_client( comp, socket_path, "Home", "org.gnome.Nautilus", server_deco=false, ) (comp, c, shm, surf, xdg, tl) } ///| test "a GTK window draws its own frame: no second title bar, and its shadow is not the window" { // GNOME Files showed its own header bar inside a Chandra-titled frame, with its transparent // shadow margin drawn as part of the window (content shifted down/right and cut off). let (comp, c, shm, surf, xdg, tl) = csd_setup("frame") ignore(gtk_frame(comp, c, shm, surf, xdg, tl)) let win = comp.windows.get(1UL).unwrap() assert_true(win.csd) assert_eq((win.geo_x, win.geo_y), (gtk_shadow, gtk_shadow)) // The client is asked to fill the frame's whole box: where Chandra's title bar would be is its own. let r = win.client_rect() assert_eq((r.w, r.h), (win.geometry.w + 4, win.geometry.h + 34)) let (w, h) = gtk_frame(comp, c, shm, surf, xdg, tl) assert_eq((w, h), (r.w, r.h)) let red = Some(@scene.Rgba::new(0xff, 0, 0, 0xff)) let frame = comp.compose_frame() // The client's pixels start right at the box's top-left (no Chandra title bar over them) // and fill it to the bottom-right corner. assert_eq(frame.pixel(r.x + 3, r.y + 3), red) assert_eq(frame.pixel(r.x + r.w - 3, r.y + r.h - 3), red) // The transparent shadow is not drawn as part of the window. assert_true(frame.pixel(r.x + r.w + 10, r.y + 10) != red) assert_true(frame.pixel(r.x + 10, r.y - 10) != red) } ///| test "a server-decorated client keeps Chandra's frame" { let socket_path = "/tmp/wayland-moon-csd-ssd-" + @sys.getpid().to_string() + ".sock" let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap() comp.set_layout_mode(@wm.LayoutMode::Floating) let (c, shm, surf, xdg, tl, _) = open_and_configure_client(comp, socket_path, "Dolphin", "org.kde.dolphin") let size_for = fn(w, h, _max) { (w, h) } ignore(answer_configures(comp, c, shm, surf, xdg, tl, size_for)) let win = comp.windows.get(1UL).unwrap() assert_false(win.csd) let r = win.client_rect() assert_eq((r.x, r.y, r.w, r.h), (win.geometry.x, win.geometry.y, win.geometry.w, win.geometry.h)) } ///| test "dragging a GTK header bar moves the window, and its border resizes it" { let (comp, c, shm, surf, xdg, tl) = csd_setup("move") ignore(gtk_frame(comp, c, shm, surf, xdg, tl)) ignore(gtk_frame(comp, c, shm, surf, xdg, tl)) let before = comp.windows.get(1UL).unwrap().geometry let r = comp.windows.get(1UL).unwrap().client_rect() // Press on the header bar (the client's own), which answers with xdg_toplevel.move. let (px, py) = (r.x + r.w / 2, r.y + 15) comp.handle_input(@nested.InputEvent::PointerMove(px.to_double(), py.to_double()), 10U) comp.handle_input(@nested.InputEvent::PointerButton(0x110U, true), 11U) assert_true(comp.wm.drag is None) // the press went to the client, not to a Chandra title bar let mv = @wayland.WireWriter::new() mv.u32(0U) // seat mv.u32(1U) // serial c.send(mv.finish_msg(tl, 5U)) for _i = 0; _i < 4; _i = _i + 1 { comp.step() @sys.sleep_ms(2) } assert_true(comp.wm.drag is Some(_)) comp.handle_input(@nested.InputEvent::PointerMove((px + 60).to_double(), (py + 40).to_double()), 12U) comp.handle_input(@nested.InputEvent::PointerButton(0x110U, false), 13U) let after = comp.windows.get(1UL).unwrap().geometry assert_eq((after.x - before.x, after.y - before.y), (60, 40)) assert_eq((after.w, after.h), (before.w, before.h)) // xdg_toplevel.resize from the bottom-right corner (edges 10). let r = comp.windows.get(1UL).unwrap().client_rect() let (px, py) = (r.x + r.w - 2, r.y + r.h - 2) comp.handle_input(@nested.InputEvent::PointerMove(px.to_double(), py.to_double()), 20U) comp.handle_input(@nested.InputEvent::PointerButton(0x110U, true), 21U) let rs = @wayland.WireWriter::new() rs.u32(0U) rs.u32(2U) rs.u32(10U) c.send(rs.finish_msg(tl, 6U)) for _i = 0; _i < 4; _i = _i + 1 { comp.step() @sys.sleep_ms(2) } if comp.wm.drag is Some(_) { comp.handle_input(@nested.InputEvent::PointerMove((px + 30).to_double(), (py + 20).to_double()), 22U) comp.handle_input(@nested.InputEvent::PointerButton(0x110U, false), 23U) let resized = comp.windows.get(1UL).unwrap().geometry assert_eq((resized.w - after.w, resized.h - after.h), (30, 20)) } else { // The press landed in one of Chandra's own resize zones instead: also a resize. comp.handle_input(@nested.InputEvent::PointerButton(0x110U, false), 23U) } } ///| test "Chrome asking to draw its own frame gets it, instead of a second one around it" { // Chrome with "Use system title bar and borders" off (and its installed web apps) asks for // client-side decoration and keeps drawing its own title bar and shadow even when told // server-side: Chandra's title bar showed above Chrome's, with Chrome's shadow as a gap. let socket_path = "/tmp/wayland-moon-csd-chrome-" + @sys.getpid().to_string() + ".sock" let comp = @host.ChandraCompositor::new(socket_path, @scene.ThemeTokens::moon_night(), 1280, 720).unwrap() comp.set_layout_mode(@wm.LayoutMode::Floating) let (c, shm, surf, xdg, tl, deco) = open_and_configure_client(comp, socket_path, "YouTube", "chrome-youtube") assert_eq(c.deco_mode, Some(2U)) // zxdg_toplevel_decoration_v1.set_mode(client_side) let m = @wayland.WireWriter::new() m.u32(1U) c.send(m.finish_msg(deco, 1U)) for _i = 0; _i < 4; _i = _i + 1 { comp.step() c.read_events(xdg, tl, deco) @sys.sleep_ms(2) } assert_eq(c.deco_mode, Some(1U)) ignore(gtk_frame(comp, c, shm, surf, xdg, tl)) let win = comp.windows.get(1UL).unwrap() assert_true(win.csd) let r = win.client_rect() assert_eq((r.w, r.h), (win.geometry.w + 4, win.geometry.h + 34)) // unset_mode: back to Chandra's frame. c.send(@wayland.WireWriter::new().finish_msg(deco, 2U)) for _i = 0; _i < 4; _i = _i + 1 { comp.step() c.read_events(xdg, tl, deco) @sys.sleep_ms(2) } assert_eq(c.deco_mode, Some(2U)) ignore(gtk_frame(comp, c, shm, surf, xdg, tl)) assert_false(comp.windows.get(1UL).unwrap().csd) }