diff --git a/compositor/host/compositor.mbt b/compositor/host/compositor.mbt index b9f70d2..830499c 100644 --- a/compositor/host/compositor.mbt +++ b/compositor/host/compositor.mbt @@ -756,7 +756,7 @@ fn MoonPlasmaCompositor::press_title_button( let order = self.wm.stacking_order() if order.length() > 0 { let top = order[order.length() - 1] - self.apply_actions([@wm.WmAction::Focus(top), @wm.WmAction::Raise(top)]) + self.activate_window(top) } else { self.set_kbd_focus(None) } @@ -764,6 +764,14 @@ fn MoonPlasmaCompositor::press_title_button( self.damage.mark_full() } +///| Focus a window and bring it to the front through the window manager, so its stacking +/// order (not just the drawing) changes. +fn MoonPlasmaCompositor::activate_window(self : MoonPlasmaCompositor, wid : UInt64) -> Unit { + self.apply_actions( + self.wm.handle_request(wid, @wm.WindowRequest::Activate, self.work_area), + ) +} + ///| Restore a minimized window (or focus a visible one) from its task-bar pill. fn MoonPlasmaCompositor::activate_task(self : MoonPlasmaCompositor, wid : UInt64) -> Unit { let minimized = match self.wm.windows.get(wid) { @@ -999,7 +1007,7 @@ pub fn MoonPlasmaCompositor::handle_input( if button == 272U && self.resize_at(xi, yi) is None { // Drag the window by its title bar; a tiled window becomes floating first. self.leave_pointer() - self.apply_actions([@wm.WmAction::Focus(wid), @wm.WmAction::Raise(wid)]) + self.activate_window(wid) self.apply_actions(self.wm.float_window(wid, self.work_area)) ignore(self.wm.start_drag(wid, @wm.DragMode::Move, xi, yi)) return @@ -1011,7 +1019,7 @@ pub fn MoonPlasmaCompositor::handle_input( match self.resize_at(xi, yi) { Some((wid, mode)) => { self.leave_pointer() - self.apply_actions([@wm.WmAction::Focus(wid), @wm.WmAction::Raise(wid)]) + self.activate_window(wid) ignore(self.wm.start_drag(wid, mode, xi, yi)) return } @@ -1032,10 +1040,7 @@ pub fn MoonPlasmaCompositor::handle_input( } match self.window_at(xi, yi) { Some((wid, _)) => { - self.apply_actions([ - @wm.WmAction::Focus(wid), - @wm.WmAction::Raise(wid), - ]) + self.activate_window(wid) } None => () } diff --git a/compositor/host/input_test.mbt b/compositor/host/input_test.mbt index 5254571..5be48d1 100644 --- a/compositor/host/input_test.mbt +++ b/compositor/host/input_test.mbt @@ -922,3 +922,24 @@ test "the desktop card position is saved when dropped and restored" { assert_eq(b.shell.desk_y, a.shell.desk_y) } } + +///| +test "clicking a floating window brings it in front of the others" { + let socket_path = "/tmp/wayland-moon-z-" + @sys.getpid().to_string() + ".sock" + let theme = @scene.ThemeTokens::moon_night() + let comp = @host.MoonPlasmaCompositor::new(socket_path, theme, 1280, 720).unwrap() + ignore(open_and_configure_client(comp, socket_path, "A", "a")) + ignore(open_and_configure_client(comp, socket_path, "B", "b")) + comp.set_layout_mode(@wm.LayoutMode::Floating) + ignore(comp.compose_frame()) + let order = comp.wm.stacking_order() + assert_eq(order.length(), 2) + let (back, front) = (order[0], order[1]) + // Click the window in back (its title bar, away from any overlap): it comes to the front. + let g = comp.windows.get(back).unwrap().geometry + click_at(comp, g.x + 20, g.y - 16, 1U) + ignore(comp.compose_frame()) + let after = comp.wm.stacking_order() + assert_eq(after[1], back) + assert_eq(after[0], front) +}