@@ -54,11 +54,106 @@ impl WindowManager { |
| 54 | 54 | } |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | + // Grab Alt+Button1/Button3 on root for floating window move/resize |
| 58 | + self.conn.grab_mod_buttons()?; |
| 59 | + |
| 57 | 60 | self.conn.flush()?; |
| 58 | 61 | tracing::info!("{} keybinds registered", state.keybinds.len()); |
| 59 | 62 | Ok(()) |
| 60 | 63 | } |
| 61 | 64 | |
| 65 | + /// Set up EWMH workspace hints for status bar integration. |
| 66 | + pub fn setup_ewmh_hints(&self) -> Result<()> { |
| 67 | + // Advertise supported EWMH atoms |
| 68 | + self.conn.set_ewmh_supported()?; |
| 69 | + |
| 70 | + // Set number of desktops |
| 71 | + let num_desktops = self.workspaces.len() as u32; |
| 72 | + self.conn.set_number_of_desktops(num_desktops)?; |
| 73 | + |
| 74 | + // Set desktop names |
| 75 | + let names: Vec<String> = self.workspaces.iter().map(|ws| ws.name.clone()).collect(); |
| 76 | + self.conn.set_desktop_names(&names)?; |
| 77 | + |
| 78 | + // Set current desktop |
| 79 | + self.conn.set_current_desktop(self.focused_workspace as u32)?; |
| 80 | + |
| 81 | + // Set active window (none at startup) |
| 82 | + self.conn.set_active_window(None)?; |
| 83 | + |
| 84 | + self.conn.flush()?; |
| 85 | + tracing::info!("EWMH workspace hints initialized: {} desktops", num_desktops); |
| 86 | + Ok(()) |
| 87 | + } |
| 88 | + |
| 89 | + /// Adopt any existing windows that were already mapped before we started. |
| 90 | + pub fn adopt_existing_windows(&mut self) -> Result<()> { |
| 91 | + use x11rb::protocol::xproto::MapState; |
| 92 | + |
| 93 | + // Query children of root window |
| 94 | + let reply = self.conn.conn.query_tree(self.conn.root)?.reply()?; |
| 95 | + let mut adopted = 0; |
| 96 | + |
| 97 | + for &window in &reply.children { |
| 98 | + // Get window attributes to check if it's mapped and not override-redirect |
| 99 | + let attrs = match self.conn.conn.get_window_attributes(window)?.reply() { |
| 100 | + Ok(a) => a, |
| 101 | + Err(_) => continue, // Window may have been destroyed |
| 102 | + }; |
| 103 | + |
| 104 | + // Skip override-redirect windows (menus, tooltips, etc.) |
| 105 | + if attrs.override_redirect { |
| 106 | + continue; |
| 107 | + } |
| 108 | + |
| 109 | + // Only adopt currently mapped windows |
| 110 | + if attrs.map_state != MapState::VIEWABLE { |
| 111 | + continue; |
| 112 | + } |
| 113 | + |
| 114 | + // Skip if we already manage this window |
| 115 | + if self.windows.contains_key(&window) { |
| 116 | + continue; |
| 117 | + } |
| 118 | + |
| 119 | + // Subscribe to events on the window |
| 120 | + self.conn.select_input( |
| 121 | + window, |
| 122 | + EventMask::ENTER_WINDOW |
| 123 | + | EventMask::FOCUS_CHANGE |
| 124 | + | EventMask::PROPERTY_CHANGE |
| 125 | + | EventMask::STRUCTURE_NOTIFY, |
| 126 | + )?; |
| 127 | + |
| 128 | + // Grab button for click-to-focus |
| 129 | + self.conn.grab_button(window)?; |
| 130 | + |
| 131 | + // Check window rules and EWMH hints |
| 132 | + let rule_actions = self.check_rules(window); |
| 133 | + let should_float = rule_actions.floating.unwrap_or_else(|| self.conn.should_float(window)); |
| 134 | + |
| 135 | + // Manage the window |
| 136 | + if should_float { |
| 137 | + self.manage_window_floating(window); |
| 138 | + } else { |
| 139 | + self.manage_window(window); |
| 140 | + } |
| 141 | + adopted += 1; |
| 142 | + } |
| 143 | + |
| 144 | + if adopted > 0 { |
| 145 | + self.apply_layout()?; |
| 146 | + // Focus the first window |
| 147 | + if let Some(window) = self.focused_window { |
| 148 | + self.set_focus(window)?; |
| 149 | + self.conn.ungrab_button(window)?; |
| 150 | + } |
| 151 | + tracing::info!("Adopted {} existing windows", adopted); |
| 152 | + } |
| 153 | + |
| 154 | + Ok(()) |
| 155 | + } |
| 156 | + |
| 62 | 157 | pub fn handle_event(&mut self, event: Event) -> Result<()> { |
| 63 | 158 | match event { |
| 64 | 159 | Event::MapRequest(e) => self.handle_map_request(e)?, |
@@ -103,17 +198,43 @@ impl WindowManager { |
| 103 | 198 | // Grab button for click-to-focus |
| 104 | 199 | self.conn.grab_button(window)?; |
| 105 | 200 | |
| 106 | | - // Manage the window |
| 107 | | - self.manage_window(window); |
| 201 | + // Check window rules first |
| 202 | + let rule_actions = self.check_rules(window); |
| 203 | + |
| 204 | + // Determine target workspace (rule or current) |
| 205 | + let target_workspace = rule_actions.workspace.unwrap_or(self.focused_workspace + 1); |
| 206 | + let target_idx = target_workspace.saturating_sub(1).min(self.workspaces.len() - 1); |
| 108 | 207 | |
| 109 | | - // Map the window |
| 110 | | - self.conn.map_window(window)?; |
| 208 | + // Determine if window should float (rule > ICCCM/EWMH hints) |
| 209 | + let should_float = rule_actions.floating.unwrap_or_else(|| self.conn.should_float(window)); |
| 210 | + |
| 211 | + // Manage window on target workspace |
| 212 | + if target_idx != self.focused_workspace { |
| 213 | + // Window goes to a different workspace |
| 214 | + if should_float { |
| 215 | + self.manage_window_floating_on_workspace(window, target_idx); |
| 216 | + } else { |
| 217 | + self.manage_window_on_workspace(window, target_idx); |
| 218 | + } |
| 219 | + // Don't map - it's on another workspace |
| 220 | + } else { |
| 221 | + // Window goes to current workspace |
| 222 | + if should_float { |
| 223 | + self.manage_window_floating(window); |
| 224 | + } else { |
| 225 | + self.manage_window(window); |
| 226 | + } |
| 227 | + // Map the window |
| 228 | + self.conn.map_window(window)?; |
| 229 | + } |
| 111 | 230 | |
| 112 | 231 | // Apply layout to all windows |
| 113 | 232 | self.apply_layout()?; |
| 114 | 233 | |
| 115 | | - // Focus the new window |
| 116 | | - self.set_focus(window)?; |
| 234 | + // Focus the new window (only if on current workspace) |
| 235 | + if target_idx == self.focused_workspace { |
| 236 | + self.set_focus(window)?; |
| 237 | + } |
| 117 | 238 | |
| 118 | 239 | Ok(()) |
| 119 | 240 | } |
@@ -178,38 +299,46 @@ impl WindowManager { |
| 178 | 299 | |
| 179 | 300 | fn handle_button_press(&mut self, event: ButtonPressEvent) -> Result<()> { |
| 180 | 301 | let window = event.event; |
| 181 | | - tracing::debug!("ButtonPress on window {}, button {}", window, event.detail); |
| 302 | + let child = event.child; |
| 303 | + tracing::debug!("ButtonPress on window {}, child {}, button {}", window, child, event.detail); |
| 182 | 304 | |
| 183 | 305 | // Check for mod+click on floating windows (move/resize) |
| 184 | 306 | let has_mod = event.state.contains(x11rb::protocol::xproto::KeyButMask::MOD1); |
| 185 | 307 | |
| 186 | | - if has_mod && self.is_floating(window) { |
| 187 | | - let geometry = self.get_floating_geometry(window); |
| 308 | + // For Alt+click from root grab, use child window (the window under cursor) |
| 309 | + let target = if window == self.conn.root && child != 0 { |
| 310 | + child |
| 311 | + } else { |
| 312 | + window |
| 313 | + }; |
| 314 | + |
| 315 | + if has_mod && self.is_floating(target) { |
| 316 | + let geometry = self.get_floating_geometry(target); |
| 188 | 317 | |
| 189 | 318 | if event.detail == 1 { |
| 190 | 319 | // Mod+Button1 = Move |
| 191 | | - tracing::debug!("Starting move for floating window {}", window); |
| 320 | + tracing::debug!("Starting move for floating window {}", target); |
| 192 | 321 | self.drag_state = Some(DragState::Move { |
| 193 | | - window, |
| 322 | + window: target, |
| 194 | 323 | start_x: event.root_x, |
| 195 | 324 | start_y: event.root_y, |
| 196 | 325 | start_geometry: geometry, |
| 197 | 326 | }); |
| 198 | 327 | // Grab pointer for motion events |
| 199 | | - self.conn.grab_pointer(window)?; |
| 328 | + self.conn.grab_pointer(target)?; |
| 200 | 329 | return Ok(()); |
| 201 | 330 | } else if event.detail == 3 { |
| 202 | 331 | // Mod+Button3 = Resize |
| 203 | 332 | let edge = determine_resize_edge(&geometry, event.root_x, event.root_y); |
| 204 | | - tracing::debug!("Starting resize for floating window {}, edge {:?}", window, edge); |
| 333 | + tracing::debug!("Starting resize for floating window {}, edge {:?}", target, edge); |
| 205 | 334 | self.drag_state = Some(DragState::Resize { |
| 206 | | - window, |
| 335 | + window: target, |
| 207 | 336 | start_x: event.root_x, |
| 208 | 337 | start_y: event.root_y, |
| 209 | 338 | start_geometry: geometry, |
| 210 | 339 | edge, |
| 211 | 340 | }); |
| 212 | | - self.conn.grab_pointer(window)?; |
| 341 | + self.conn.grab_pointer(target)?; |
| 213 | 342 | return Ok(()); |
| 214 | 343 | } |
| 215 | 344 | } |
@@ -385,6 +514,9 @@ impl WindowManager { |
| 385 | 514 | self.toggle_floating(window)?; |
| 386 | 515 | } |
| 387 | 516 | } |
| 517 | + Action::CycleFloating => { |
| 518 | + self.cycle_floating()?; |
| 519 | + } |
| 388 | 520 | Action::LuaCallback(index) => { |
| 389 | 521 | if let Err(e) = self.lua_config.execute_callback(index) { |
| 390 | 522 | tracing::error!("Lua callback error: {}", e); |
@@ -397,11 +529,16 @@ impl WindowManager { |
| 397 | 529 | fn close_window(&mut self, window: u32) -> Result<()> { |
| 398 | 530 | tracing::info!("Closing window {}", window); |
| 399 | 531 | |
| 400 | | - // TODO: Send WM_DELETE_WINDOW if supported (ICCCM) |
| 401 | | - // For now, just kill the client |
| 402 | | - self.conn.conn.kill_client(window)?; |
| 403 | | - self.conn.sync()?; |
| 532 | + // Try graceful ICCCM close first |
| 533 | + if self.conn.supports_delete_window(window) { |
| 534 | + tracing::debug!("Window {} supports WM_DELETE_WINDOW, sending graceful close", window); |
| 535 | + self.conn.send_delete_window(window)?; |
| 536 | + } else { |
| 537 | + tracing::debug!("Window {} doesn't support WM_DELETE_WINDOW, using kill_client", window); |
| 538 | + self.conn.conn.kill_client(window)?; |
| 539 | + } |
| 404 | 540 | |
| 541 | + self.conn.flush()?; |
| 405 | 542 | Ok(()) |
| 406 | 543 | } |
| 407 | 544 | |
@@ -482,26 +619,30 @@ impl WindowManager { |
| 482 | 619 | |
| 483 | 620 | tracing::info!("Switching to workspace {}", idx + 1); |
| 484 | 621 | |
| 485 | | - // Hide windows on current workspace |
| 486 | | - for window in self.current_workspace().tree.windows() { |
| 622 | + // Hide all windows on current workspace (tiled + floating) |
| 623 | + for window in self.current_workspace().all_windows() { |
| 487 | 624 | self.conn.unmap_window(window)?; |
| 488 | 625 | } |
| 489 | 626 | |
| 490 | 627 | // Switch workspace |
| 491 | 628 | self.focused_workspace = idx; |
| 492 | 629 | |
| 493 | | - // Show windows on new workspace |
| 494 | | - for window in self.current_workspace().tree.windows() { |
| 630 | + // Update EWMH _NET_CURRENT_DESKTOP |
| 631 | + self.conn.set_current_desktop(idx as u32)?; |
| 632 | + |
| 633 | + // Show all windows on new workspace (tiled + floating) |
| 634 | + for window in self.current_workspace().all_windows() { |
| 495 | 635 | self.conn.map_window(window)?; |
| 496 | 636 | } |
| 497 | 637 | |
| 498 | 638 | // Apply layout and update focus |
| 499 | 639 | self.apply_layout()?; |
| 500 | 640 | |
| 501 | | - // Focus the workspace's focused window or first window |
| 641 | + // Focus the workspace's focused window, preferring floating on top |
| 502 | 642 | if let Some(window) = self |
| 503 | 643 | .current_workspace() |
| 504 | 644 | .focused |
| 645 | + .or_else(|| self.current_workspace().floating.last().copied()) |
| 505 | 646 | .or_else(|| self.current_workspace().tree.first_window()) |
| 506 | 647 | { |
| 507 | 648 | self.set_focus(window)?; |
@@ -523,13 +664,20 @@ impl WindowManager { |
| 523 | 664 | return Ok(()); |
| 524 | 665 | }; |
| 525 | 666 | |
| 526 | | - tracing::info!("Moving window {} to workspace {}", window, idx + 1); |
| 667 | + let is_floating = self.windows.get(&window).map(|w| w.floating).unwrap_or(false); |
| 668 | + |
| 669 | + tracing::info!("Moving window {} to workspace {} (floating: {})", window, idx + 1, is_floating); |
| 527 | 670 | |
| 528 | | - // Remove from current workspace tree |
| 529 | | - self.current_workspace_mut().tree.remove(window); |
| 671 | + // Remove from current workspace (tree or floating list) |
| 672 | + if is_floating { |
| 673 | + self.current_workspace_mut().remove_floating(window); |
| 674 | + } else { |
| 675 | + self.current_workspace_mut().tree.remove(window); |
| 676 | + } |
| 530 | 677 | |
| 531 | 678 | // Update focus on current workspace |
| 532 | | - self.focused_window = self.current_workspace().tree.first_window(); |
| 679 | + self.focused_window = self.current_workspace().tree.first_window() |
| 680 | + .or_else(|| self.current_workspace().floating.last().copied()); |
| 533 | 681 | self.current_workspace_mut().focused = self.focused_window; |
| 534 | 682 | |
| 535 | 683 | // Update window's workspace tracking |
@@ -537,15 +685,22 @@ impl WindowManager { |
| 537 | 685 | win.workspace = idx; |
| 538 | 686 | } |
| 539 | 687 | |
| 688 | + // Update EWMH _NET_WM_DESKTOP |
| 689 | + self.conn.set_window_desktop(window, idx as u32)?; |
| 690 | + |
| 540 | 691 | // Hide the window (it's moving to another workspace) |
| 541 | 692 | self.conn.unmap_window(window)?; |
| 542 | 693 | |
| 543 | 694 | // Insert into target workspace |
| 544 | | - let target_focused = self.workspaces[idx].focused; |
| 545 | | - let screen = self.screen_rect(); |
| 546 | | - self.workspaces[idx] |
| 547 | | - .tree |
| 548 | | - .insert_with_rect(window, target_focused, screen); |
| 695 | + if is_floating { |
| 696 | + self.workspaces[idx].add_floating(window); |
| 697 | + } else { |
| 698 | + let target_focused = self.workspaces[idx].focused; |
| 699 | + let screen = self.screen_rect(); |
| 700 | + self.workspaces[idx] |
| 701 | + .tree |
| 702 | + .insert_with_rect(window, target_focused, screen); |
| 703 | + } |
| 549 | 704 | |
| 550 | 705 | // Re-apply layout on current workspace |
| 551 | 706 | self.apply_layout()?; |
@@ -595,6 +750,12 @@ impl WindowManager { |
| 595 | 750 | // Set up keybinds |
| 596 | 751 | self.setup_grabs()?; |
| 597 | 752 | |
| 753 | + // Set up EWMH workspace hints |
| 754 | + self.setup_ewmh_hints()?; |
| 755 | + |
| 756 | + // Adopt any existing windows |
| 757 | + self.adopt_existing_windows()?; |
| 758 | + |
| 598 | 759 | while self.running { |
| 599 | 760 | let event = self.conn.conn.wait_for_event()?; |
| 600 | 761 | self.handle_event(event)?; |
@@ -616,20 +777,20 @@ impl WindowManager { |
| 616 | 777 | fn get_floating_geometry(&self, window: u32) -> Rect { |
| 617 | 778 | self.windows |
| 618 | 779 | .get(&window) |
| 619 | | - .map(|w| w.geometry) |
| 780 | + .map(|w| w.floating_geometry) |
| 620 | 781 | .unwrap_or_default() |
| 621 | 782 | } |
| 622 | 783 | |
| 623 | 784 | fn set_floating_position(&mut self, window: u32, x: i16, y: i16) -> Result<()> { |
| 624 | 785 | if let Some(win) = self.windows.get_mut(&window) { |
| 625 | | - win.geometry.x = x; |
| 626 | | - win.geometry.y = y; |
| 786 | + win.floating_geometry.x = x; |
| 787 | + win.floating_geometry.y = y; |
| 627 | 788 | self.conn.configure_window( |
| 628 | 789 | window, |
| 629 | 790 | x, |
| 630 | 791 | y, |
| 631 | | - win.geometry.width, |
| 632 | | - win.geometry.height, |
| 792 | + win.floating_geometry.width, |
| 793 | + win.floating_geometry.height, |
| 633 | 794 | self.config.border_width, |
| 634 | 795 | )?; |
| 635 | 796 | self.conn.flush()?; |
@@ -639,7 +800,7 @@ impl WindowManager { |
| 639 | 800 | |
| 640 | 801 | fn set_floating_geometry(&mut self, window: u32, x: i16, y: i16, w: u16, h: u16) -> Result<()> { |
| 641 | 802 | if let Some(win) = self.windows.get_mut(&window) { |
| 642 | | - win.geometry = Rect::new(x, y, w, h); |
| 803 | + win.floating_geometry = Rect::new(x, y, w, h); |
| 643 | 804 | self.conn.configure_window( |
| 644 | 805 | window, |
| 645 | 806 | x, |
@@ -654,33 +815,84 @@ impl WindowManager { |
| 654 | 815 | } |
| 655 | 816 | |
| 656 | 817 | fn raise_window(&mut self, window: u32) -> Result<()> { |
| 818 | + // Update stacking order in workspace's floating list |
| 819 | + self.current_workspace_mut().raise_floating(window); |
| 820 | + |
| 821 | + // Raise in X11 |
| 657 | 822 | let aux = ConfigureWindowAux::new().stack_mode(StackMode::ABOVE); |
| 658 | 823 | self.conn.conn.configure_window(window, &aux)?; |
| 659 | 824 | self.conn.flush()?; |
| 660 | 825 | Ok(()) |
| 661 | 826 | } |
| 662 | 827 | |
| 828 | + /// Cycle through floating windows on the current workspace. |
| 829 | + fn cycle_floating(&mut self) -> Result<()> { |
| 830 | + let floating = &self.current_workspace().floating; |
| 831 | + if floating.is_empty() { |
| 832 | + tracing::debug!("No floating windows to cycle"); |
| 833 | + return Ok(()); |
| 834 | + } |
| 835 | + |
| 836 | + // Find current position in floating list |
| 837 | + let current_idx = self.focused_window |
| 838 | + .and_then(|w| floating.iter().position(|&fw| fw == w)); |
| 839 | + |
| 840 | + // Get next floating window (wrap around) |
| 841 | + let next_idx = match current_idx { |
| 842 | + Some(idx) => (idx + 1) % floating.len(), |
| 843 | + None => 0, // Not focused on a floating window, focus the first one |
| 844 | + }; |
| 845 | + |
| 846 | + let next_window = floating[next_idx]; |
| 847 | + |
| 848 | + // Regrab button on old focused window |
| 849 | + if let Some(old) = self.focused_window { |
| 850 | + self.conn.grab_button(old)?; |
| 851 | + } |
| 852 | + |
| 853 | + // Focus and raise the next floating window |
| 854 | + self.set_focus(next_window)?; |
| 855 | + self.conn.ungrab_button(next_window)?; |
| 856 | + self.raise_window(next_window)?; |
| 857 | + |
| 858 | + tracing::debug!("Cycled to floating window {} (idx {})", next_window, next_idx); |
| 859 | + Ok(()) |
| 860 | + } |
| 861 | + |
| 663 | 862 | fn toggle_floating(&mut self, window: u32) -> Result<()> { |
| 664 | | - let Some(win) = self.windows.get_mut(&window) else { |
| 863 | + // Check if window is managed |
| 864 | + let Some(win_state) = self.windows.get(&window) else { |
| 865 | + tracing::warn!("toggle_floating: window {} not managed", window); |
| 665 | 866 | return Ok(()); |
| 666 | 867 | }; |
| 868 | + let is_floating = win_state.floating; |
| 667 | 869 | |
| 668 | | - if win.floating { |
| 870 | + tracing::debug!( |
| 871 | + "toggle_floating: window={}, is_floating={}, in_tree={}, in_floating_list={}", |
| 872 | + window, |
| 873 | + is_floating, |
| 874 | + self.current_workspace().tree.contains(window), |
| 875 | + self.current_workspace().floating.contains(&window) |
| 876 | + ); |
| 877 | + |
| 878 | + if is_floating { |
| 669 | 879 | // Return to tiled |
| 670 | 880 | tracing::info!("Returning window {} to tiled", window); |
| 671 | | - win.floating = false; |
| 881 | + |
| 882 | + // Update window state |
| 883 | + if let Some(win) = self.windows.get_mut(&window) { |
| 884 | + win.floating = false; |
| 885 | + } |
| 672 | 886 | |
| 673 | 887 | // Remove from floating list |
| 674 | | - self.current_workspace_mut() |
| 675 | | - .floating |
| 676 | | - .retain(|w| w.id != window); |
| 888 | + self.current_workspace_mut().remove_floating(window); |
| 677 | 889 | |
| 678 | | - // Insert back into BSP tree |
| 679 | | - let focused = self.current_workspace().focused; |
| 890 | + // Find a target window to insert next to (not ourselves) |
| 891 | + let target = self.current_workspace().tree.first_window(); |
| 680 | 892 | let screen = self.screen_rect(); |
| 681 | 893 | self.current_workspace_mut() |
| 682 | 894 | .tree |
| 683 | | - .insert_with_rect(window, focused, screen); |
| 895 | + .insert_with_rect(window, target, screen); |
| 684 | 896 | |
| 685 | 897 | // Re-apply layout |
| 686 | 898 | self.apply_layout()?; |
@@ -688,44 +900,37 @@ impl WindowManager { |
| 688 | 900 | // Make floating |
| 689 | 901 | tracing::info!("Floating window {}", window); |
| 690 | 902 | |
| 691 | | - // Get current geometry before removing from tree |
| 903 | + // Check if window is actually in the tree |
| 904 | + if !self.current_workspace().tree.contains(window) { |
| 905 | + tracing::warn!("toggle_floating: window {} not in tree, cannot float", window); |
| 906 | + return Ok(()); |
| 907 | + } |
| 908 | + |
| 909 | + // Use a centered floating geometry (80% of screen size, centered) |
| 692 | 910 | let screen = self.screen_rect(); |
| 693 | | - let geometries = self.current_workspace().tree.calculate_geometries(screen); |
| 694 | | - let geometry = geometries |
| 695 | | - .iter() |
| 696 | | - .find(|(w, _)| *w == window) |
| 697 | | - .map(|(_, r)| *r) |
| 698 | | - .unwrap_or_else(|| Rect::new(100, 100, 640, 480)); |
| 911 | + let float_w = (screen.width * 4 / 5).max(400); |
| 912 | + let float_h = (screen.height * 4 / 5).max(300); |
| 913 | + let float_x = screen.x + (screen.width as i16 - float_w as i16) / 2; |
| 914 | + let float_y = screen.y + (screen.height as i16 - float_h as i16) / 2; |
| 915 | + let geometry = Rect::new(float_x, float_y, float_w, float_h); |
| 916 | + |
| 917 | + tracing::debug!("Floating geometry: {:?}", geometry); |
| 699 | 918 | |
| 700 | 919 | // Remove from BSP tree |
| 701 | | - self.current_workspace_mut().tree.remove(window); |
| 920 | + let removed = self.current_workspace_mut().tree.remove(window); |
| 921 | + tracing::debug!("Removed from tree: {}", removed); |
| 702 | 922 | |
| 703 | | - // Mark as floating and store geometry |
| 704 | | - let win = self.windows.get_mut(&window).unwrap(); |
| 705 | | - win.floating = true; |
| 706 | | - win.geometry = geometry; |
| 923 | + // Update window state with floating geometry |
| 924 | + if let Some(win) = self.windows.get_mut(&window) { |
| 925 | + win.floating = true; |
| 926 | + win.floating_geometry = geometry; |
| 927 | + } |
| 707 | 928 | |
| 708 | | - // Add to floating list |
| 709 | | - let workspace_idx = self.focused_workspace; |
| 710 | | - self.current_workspace_mut() |
| 711 | | - .floating |
| 712 | | - .push(crate::core::Window::new(window, workspace_idx)); |
| 929 | + // Add to floating list (on top) |
| 930 | + self.current_workspace_mut().add_floating(window); |
| 713 | 931 | |
| 714 | | - // Re-apply layout for tiled windows |
| 932 | + // Re-apply layout (this will configure the floating window and stack it) |
| 715 | 933 | self.apply_layout()?; |
| 716 | | - |
| 717 | | - // Configure floating window to its geometry |
| 718 | | - self.conn.configure_window( |
| 719 | | - window, |
| 720 | | - geometry.x, |
| 721 | | - geometry.y, |
| 722 | | - geometry.width, |
| 723 | | - geometry.height, |
| 724 | | - self.config.border_width, |
| 725 | | - )?; |
| 726 | | - |
| 727 | | - // Raise floating window above tiled |
| 728 | | - self.raise_window(window)?; |
| 729 | 934 | } |
| 730 | 935 | |
| 731 | 936 | Ok(()) |