@@ -211,95 +211,151 @@ impl EdgeCaptureState { |
| 211 | tracing::info!("Screen bounds: ({}, {}) to ({}, {})", min_x, min_y, max_x, max_y); | 211 | tracing::info!("Screen bounds: ({}, {}) to ({}, {})", min_x, min_y, max_x, max_y); |
| 212 | | 212 | |
| 213 | for direction in &self.config.enabled_edges.clone() { | 213 | for direction in &self.config.enabled_edges.clone() { |
| 214 | - // Find the correct output for this edge direction | 214 | + // Find the output(s) for this edge direction |
| 215 | - let target_output = self.find_edge_output(*direction); | 215 | + // Up/Down may return multiple outputs (all monitors at top/bottom) |
| 216 | - tracing::info!(" {:?} edge -> output at {:?}", | 216 | + let edge_outputs = self.find_edge_outputs(*direction); |
| 217 | - direction, | 217 | + tracing::info!(" {:?} edge -> {} output(s)", direction, edge_outputs.len()); |
| 218 | - target_output.as_ref().map(|o| (o.x, o.y, o.width, o.height))); | 218 | + |
| 219 | - | 219 | + // Create a barrier on each edge output |
| 220 | - let (width, height, anchor) = match direction { | 220 | + for target_output in &edge_outputs { |
| 221 | - Direction::Left => ( | 221 | + let (width, height, anchor) = match direction { |
| 222 | - self.config.barrier_size, | 222 | + Direction::Left => ( |
| 223 | - target_output.as_ref().map(|o| o.height).unwrap_or((max_y - min_y) as u32), | 223 | + self.config.barrier_size, |
| 224 | - Anchor::LEFT | Anchor::TOP | Anchor::BOTTOM, | 224 | + target_output.height, |
| 225 | - ), | 225 | + Anchor::LEFT | Anchor::TOP | Anchor::BOTTOM, |
| 226 | - Direction::Right => ( | 226 | + ), |
| 227 | - self.config.barrier_size, | 227 | + Direction::Right => ( |
| 228 | - target_output.as_ref().map(|o| o.height).unwrap_or((max_y - min_y) as u32), | 228 | + self.config.barrier_size, |
| 229 | - Anchor::RIGHT | Anchor::TOP | Anchor::BOTTOM, | 229 | + target_output.height, |
| 230 | - ), | 230 | + Anchor::RIGHT | Anchor::TOP | Anchor::BOTTOM, |
| 231 | - Direction::Up => ( | 231 | + ), |
| 232 | - target_output.as_ref().map(|o| o.width).unwrap_or((max_x - min_x) as u32), | 232 | + Direction::Up => ( |
| 233 | - self.config.barrier_size, | 233 | + target_output.width, |
| 234 | - Anchor::TOP | Anchor::LEFT | Anchor::RIGHT, | 234 | + self.config.barrier_size, |
| 235 | - ), | 235 | + Anchor::TOP | Anchor::LEFT | Anchor::RIGHT, |
| 236 | - Direction::Down => ( | 236 | + ), |
| 237 | - target_output.as_ref().map(|o| o.width).unwrap_or((max_x - min_x) as u32), | 237 | + Direction::Down => ( |
| 238 | - self.config.barrier_size, | 238 | + target_output.width, |
| 239 | - Anchor::BOTTOM | Anchor::LEFT | Anchor::RIGHT, | 239 | + self.config.barrier_size, |
| 240 | - ), | 240 | + Anchor::BOTTOM | Anchor::LEFT | Anchor::RIGHT, |
| 241 | - }; | 241 | + ), |
| 242 | - | 242 | + }; |
| 243 | - // Create layer surface on the specific edge output | 243 | + |
| 244 | - let surface = self.compositor_state.create_surface(qh); | 244 | + // Create layer surface on this specific output |
| 245 | - let output_ref = target_output.as_ref().map(|o| &o.output); | 245 | + let surface = self.compositor_state.create_surface(qh); |
| 246 | - let layer_surface = self.layer_shell.create_layer_surface( | 246 | + let layer_surface = self.layer_shell.create_layer_surface( |
| 247 | - qh, | 247 | + qh, |
| 248 | - surface, | 248 | + surface, |
| 249 | - Layer::Top, // Top layer to catch pointer | 249 | + Layer::Top, // Top layer to catch pointer |
| 250 | - Some(format!("hyprkvm-edge-{}", direction)), | 250 | + Some(format!("hyprkvm-edge-{}", direction)), |
| 251 | - output_ref, | 251 | + Some(&target_output.output), |
| 252 | - ); | 252 | + ); |
| 253 | - | 253 | + |
| 254 | - tracing::info!( | 254 | + tracing::info!( |
| 255 | - "Creating {:?} barrier on output {:?}, size {}x{}", | 255 | + "Creating {:?} barrier on output at ({}, {}), size {}x{}", |
| 256 | - direction, | 256 | + direction, |
| 257 | - target_output.as_ref().map(|o| format!("at ({}, {})", o.x, o.y)), | 257 | + target_output.x, |
| 258 | - width, | 258 | + target_output.y, |
| 259 | - height | 259 | + width, |
| 260 | - ); | 260 | + height |
| 261 | - | 261 | + ); |
| 262 | - // Configure the layer surface | 262 | + |
| 263 | - layer_surface.set_anchor(anchor); | 263 | + // Configure the layer surface |
| 264 | - layer_surface.set_size(width, height); | 264 | + layer_surface.set_anchor(anchor); |
| 265 | - layer_surface.set_exclusive_zone(-1); // Don't reserve space | 265 | + layer_surface.set_size(width, height); |
| 266 | - layer_surface.set_keyboard_interactivity(KeyboardInteractivity::None); | 266 | + layer_surface.set_exclusive_zone(-1); // Don't reserve space |
| 267 | - | 267 | + layer_surface.set_keyboard_interactivity(KeyboardInteractivity::None); |
| 268 | - // Commit to apply configuration | 268 | + |
| 269 | - layer_surface.commit(); | 269 | + // Commit to apply configuration |
| 270 | - | 270 | + layer_surface.commit(); |
| 271 | - self.barriers.push(EdgeBarrier { | 271 | + |
| 272 | - direction: *direction, | 272 | + self.barriers.push(EdgeBarrier { |
| 273 | - surface: layer_surface, | 273 | + direction: *direction, |
| 274 | - width, | 274 | + surface: layer_surface, |
| 275 | - height, | 275 | + width, |
| 276 | - configured: false, | 276 | + height, |
| 277 | - }); | 277 | + configured: false, |
| | 278 | + }); |
| | 279 | + } |
| | 280 | + |
| | 281 | + // Fallback if no outputs found for this direction |
| | 282 | + if edge_outputs.is_empty() { |
| | 283 | + tracing::warn!("No outputs found for {:?} edge, creating fallback barrier", direction); |
| | 284 | + let (width, height, anchor) = match direction { |
| | 285 | + Direction::Left => ( |
| | 286 | + self.config.barrier_size, |
| | 287 | + (max_y - min_y) as u32, |
| | 288 | + Anchor::LEFT | Anchor::TOP | Anchor::BOTTOM, |
| | 289 | + ), |
| | 290 | + Direction::Right => ( |
| | 291 | + self.config.barrier_size, |
| | 292 | + (max_y - min_y) as u32, |
| | 293 | + Anchor::RIGHT | Anchor::TOP | Anchor::BOTTOM, |
| | 294 | + ), |
| | 295 | + Direction::Up => ( |
| | 296 | + (max_x - min_x) as u32, |
| | 297 | + self.config.barrier_size, |
| | 298 | + Anchor::TOP | Anchor::LEFT | Anchor::RIGHT, |
| | 299 | + ), |
| | 300 | + Direction::Down => ( |
| | 301 | + (max_x - min_x) as u32, |
| | 302 | + self.config.barrier_size, |
| | 303 | + Anchor::BOTTOM | Anchor::LEFT | Anchor::RIGHT, |
| | 304 | + ), |
| | 305 | + }; |
| | 306 | + |
| | 307 | + let surface = self.compositor_state.create_surface(qh); |
| | 308 | + let layer_surface = self.layer_shell.create_layer_surface( |
| | 309 | + qh, |
| | 310 | + surface, |
| | 311 | + Layer::Top, |
| | 312 | + Some(format!("hyprkvm-edge-{}", direction)), |
| | 313 | + None, // No specific output |
| | 314 | + ); |
| | 315 | + |
| | 316 | + layer_surface.set_anchor(anchor); |
| | 317 | + layer_surface.set_size(width, height); |
| | 318 | + layer_surface.set_exclusive_zone(-1); |
| | 319 | + layer_surface.set_keyboard_interactivity(KeyboardInteractivity::None); |
| | 320 | + layer_surface.commit(); |
| | 321 | + |
| | 322 | + self.barriers.push(EdgeBarrier { |
| | 323 | + direction: *direction, |
| | 324 | + surface: layer_surface, |
| | 325 | + width, |
| | 326 | + height, |
| | 327 | + configured: false, |
| | 328 | + }); |
| | 329 | + } |
| 278 | } | 330 | } |
| 279 | } | 331 | } |
| 280 | | 332 | |
| 281 | - /// Find the output at the edge of the screen for a given direction | 333 | + /// Find the output(s) at the edge of the screen for a given direction |
| 282 | - fn find_edge_output(&self, direction: Direction) -> Option<OutputInfo> { | 334 | + /// For Left/Right: returns single monitor at the edge |
| | 335 | + /// For Up/Down: returns ALL monitors at the top/bottom edge (for horizontal layouts) |
| | 336 | + fn find_edge_outputs(&self, direction: Direction) -> Vec<OutputInfo> { |
| 283 | if self.outputs.is_empty() { | 337 | if self.outputs.is_empty() { |
| 284 | - return None; | 338 | + return vec![]; |
| 285 | } | 339 | } |
| 286 | | 340 | |
| 287 | match direction { | 341 | match direction { |
| 288 | Direction::Left => { | 342 | Direction::Left => { |
| 289 | - // Find output with minimum x (leftmost) | 343 | + // Find output with minimum x (leftmost) - single monitor |
| 290 | - self.outputs.iter().min_by_key(|o| o.x).cloned() | 344 | + self.outputs.iter().min_by_key(|o| o.x).cloned().into_iter().collect() |
| 291 | } | 345 | } |
| 292 | Direction::Right => { | 346 | Direction::Right => { |
| 293 | - // Find output with maximum x + width (rightmost) | 347 | + // Find output with maximum x + width (rightmost) - single monitor |
| 294 | - self.outputs.iter().max_by_key(|o| o.x + o.width as i32).cloned() | 348 | + self.outputs.iter().max_by_key(|o| o.x + o.width as i32).cloned().into_iter().collect() |
| 295 | } | 349 | } |
| 296 | Direction::Up => { | 350 | Direction::Up => { |
| 297 | - // Find output with minimum y (topmost) | 351 | + // Find ALL outputs at minimum y (all topmost monitors) |
| 298 | - self.outputs.iter().min_by_key(|o| o.y).cloned() | 352 | + let min_y = self.outputs.iter().map(|o| o.y).min().unwrap_or(0); |
| | 353 | + self.outputs.iter().filter(|o| o.y == min_y).cloned().collect() |
| 299 | } | 354 | } |
| 300 | Direction::Down => { | 355 | Direction::Down => { |
| 301 | - // Find output with maximum y + height (bottommost) | 356 | + // Find ALL outputs at maximum y + height (all bottommost monitors) |
| 302 | - self.outputs.iter().max_by_key(|o| o.y + o.height as i32).cloned() | 357 | + let max_bottom = self.outputs.iter().map(|o| o.y + o.height as i32).max().unwrap_or(0); |
| | 358 | + self.outputs.iter().filter(|o| o.y + o.height as i32 == max_bottom).cloned().collect() |
| 303 | } | 359 | } |
| 304 | } | 360 | } |
| 305 | } | 361 | } |