Extract output_left/right/up/down/previous/next_of()
Browse files at this commit7aec37f5c97a2b38553472d786a95f8a7f4324fbParent: 07080a01 changed file +69 -47
- src/niri.rs +69 -47
src/niri.rsmodified+69 -47
| @@ -3392,82 +3392,121 @@ impl Niri { | |||
| 3392 | self.global_space.output_under(pos).next().cloned() | 3392 | self.global_space.output_under(pos).next().cloned() |
| 3393 | } | 3393 | } |
| 3394 | 3394 | ||
| 3395 | - pub fn output_left(&self) -> Option<Output> { | 3395 | + pub fn output_left_of(&self, current: &Output) -> Option<Output> { |
| 3396 | - let active = self.layout.active_output()?; | 3396 | + let current_geo = self.global_space.output_geometry(current)?; |
| 3397 | - let active_geo = self.global_space.output_geometry(active).unwrap(); | ||
| 3398 | let extended_geo = Rectangle::new( | 3397 | let extended_geo = Rectangle::new( |
| 3399 | - Point::from((i32::MIN / 2, active_geo.loc.y)), | 3398 | + Point::from((i32::MIN / 2, current_geo.loc.y)), |
| 3400 | - Size::from((i32::MAX, active_geo.size.h)), | 3399 | + Size::from((i32::MAX, current_geo.size.h)), |
| 3401 | ); | 3400 | ); |
| 3402 | 3401 | ||
| 3403 | self.global_space | 3402 | self.global_space |
| 3404 | .outputs() | 3403 | .outputs() |
| 3405 | .map(|output| (output, self.global_space.output_geometry(output).unwrap())) | 3404 | .map(|output| (output, self.global_space.output_geometry(output).unwrap())) |
| 3406 | - .filter(|(_, geo)| center(*geo).x < center(active_geo).x && geo.overlaps(extended_geo)) | 3405 | + .filter(|(_, geo)| center(*geo).x < center(current_geo).x && geo.overlaps(extended_geo)) |
| 3407 | - .min_by_key(|(_, geo)| center(active_geo).x - center(*geo).x) | 3406 | + .min_by_key(|(_, geo)| center(current_geo).x - center(*geo).x) |
| 3408 | .map(|(output, _)| output) | 3407 | .map(|(output, _)| output) |
| 3409 | .cloned() | 3408 | .cloned() |
| 3410 | } | 3409 | } |
| 3411 | 3410 | ||
| 3412 | - pub fn output_right(&self) -> Option<Output> { | 3411 | + pub fn output_right_of(&self, current: &Output) -> Option<Output> { |
| 3413 | - let active = self.layout.active_output()?; | 3412 | + let current_geo = self.global_space.output_geometry(current)?; |
| 3414 | - let active_geo = self.global_space.output_geometry(active).unwrap(); | ||
| 3415 | let extended_geo = Rectangle::new( | 3413 | let extended_geo = Rectangle::new( |
| 3416 | - Point::from((i32::MIN / 2, active_geo.loc.y)), | 3414 | + Point::from((i32::MIN / 2, current_geo.loc.y)), |
| 3417 | - Size::from((i32::MAX, active_geo.size.h)), | 3415 | + Size::from((i32::MAX, current_geo.size.h)), |
| 3418 | ); | 3416 | ); |
| 3419 | 3417 | ||
| 3420 | self.global_space | 3418 | self.global_space |
| 3421 | .outputs() | 3419 | .outputs() |
| 3422 | .map(|output| (output, self.global_space.output_geometry(output).unwrap())) | 3420 | .map(|output| (output, self.global_space.output_geometry(output).unwrap())) |
| 3423 | - .filter(|(_, geo)| center(*geo).x > center(active_geo).x && geo.overlaps(extended_geo)) | 3421 | + .filter(|(_, geo)| center(*geo).x > center(current_geo).x && geo.overlaps(extended_geo)) |
| 3424 | - .min_by_key(|(_, geo)| center(*geo).x - center(active_geo).x) | 3422 | + .min_by_key(|(_, geo)| center(*geo).x - center(current_geo).x) |
| 3425 | .map(|(output, _)| output) | 3423 | .map(|(output, _)| output) |
| 3426 | .cloned() | 3424 | .cloned() |
| 3427 | } | 3425 | } |
| 3428 | 3426 | ||
| 3429 | - pub fn output_up(&self) -> Option<Output> { | 3427 | + pub fn output_up_of(&self, current: &Output) -> Option<Output> { |
| 3430 | - let active = self.layout.active_output()?; | 3428 | + let current_geo = self.global_space.output_geometry(current)?; |
| 3431 | - let active_geo = self.global_space.output_geometry(active).unwrap(); | ||
| 3432 | let extended_geo = Rectangle::new( | 3429 | let extended_geo = Rectangle::new( |
| 3433 | - Point::from((active_geo.loc.x, i32::MIN / 2)), | 3430 | + Point::from((current_geo.loc.x, i32::MIN / 2)), |
| 3434 | - Size::from((active_geo.size.w, i32::MAX)), | 3431 | + Size::from((current_geo.size.w, i32::MAX)), |
| 3435 | ); | 3432 | ); |
| 3436 | 3433 | ||
| 3437 | self.global_space | 3434 | self.global_space |
| 3438 | .outputs() | 3435 | .outputs() |
| 3439 | .map(|output| (output, self.global_space.output_geometry(output).unwrap())) | 3436 | .map(|output| (output, self.global_space.output_geometry(output).unwrap())) |
| 3440 | - .filter(|(_, geo)| center(*geo).y < center(active_geo).y && geo.overlaps(extended_geo)) | 3437 | + .filter(|(_, geo)| center(*geo).y < center(current_geo).y && geo.overlaps(extended_geo)) |
| 3441 | - .min_by_key(|(_, geo)| center(active_geo).y - center(*geo).y) | 3438 | + .min_by_key(|(_, geo)| center(current_geo).y - center(*geo).y) |
| 3442 | .map(|(output, _)| output) | 3439 | .map(|(output, _)| output) |
| 3443 | .cloned() | 3440 | .cloned() |
| 3444 | } | 3441 | } |
| 3445 | 3442 | ||
| 3446 | - pub fn output_previous(&self) -> Option<Output> { | 3443 | + pub fn output_down_of(&self, current: &Output) -> Option<Output> { |
| 3447 | - let active = self.layout.active_output()?; | 3444 | + let current_geo = self.global_space.output_geometry(current)?; |
| 3445 | + let extended_geo = Rectangle::new( | ||
| 3446 | + Point::from((current_geo.loc.x, i32::MIN / 2)), | ||
| 3447 | + Size::from((current_geo.size.w, i32::MAX)), | ||
| 3448 | + ); | ||
| 3449 | + | ||
| 3450 | + self.global_space | ||
| 3451 | + .outputs() | ||
| 3452 | + .map(|output| (output, self.global_space.output_geometry(output).unwrap())) | ||
| 3453 | + .filter(|(_, geo)| center(*geo).y > center(current_geo).y && geo.overlaps(extended_geo)) | ||
| 3454 | + .min_by_key(|(_, geo)| center(*geo).y - center(current_geo).y) | ||
| 3455 | + .map(|(output, _)| output) | ||
| 3456 | + .cloned() | ||
| 3457 | + } | ||
| 3448 | 3458 | ||
| 3459 | + pub fn output_previous_of(&self, current: &Output) -> Option<Output> { | ||
| 3449 | self.sorted_outputs | 3460 | self.sorted_outputs |
| 3450 | .iter() | 3461 | .iter() |
| 3451 | .rev() | 3462 | .rev() |
| 3452 | - .skip_while(|&output| output != active) | 3463 | + .skip_while(|&output| output != current) |
| 3453 | .nth(1) | 3464 | .nth(1) |
| 3454 | .or(self.sorted_outputs.last()) | 3465 | .or(self.sorted_outputs.last()) |
| 3455 | - .filter(|&output| output != active) | 3466 | + .filter(|&output| output != current) |
| 3456 | .cloned() | 3467 | .cloned() |
| 3457 | } | 3468 | } |
| 3458 | 3469 | ||
| 3459 | - pub fn output_next(&self) -> Option<Output> { | 3470 | + pub fn output_next_of(&self, current: &Output) -> Option<Output> { |
| 3460 | - let active = self.layout.active_output()?; | ||
| 3461 | - | ||
| 3462 | self.sorted_outputs | 3471 | self.sorted_outputs |
| 3463 | .iter() | 3472 | .iter() |
| 3464 | - .skip_while(|&output| output != active) | 3473 | + .skip_while(|&output| output != current) |
| 3465 | .nth(1) | 3474 | .nth(1) |
| 3466 | .or(self.sorted_outputs.first()) | 3475 | .or(self.sorted_outputs.first()) |
| 3467 | - .filter(|&output| output != active) | 3476 | + .filter(|&output| output != current) |
| 3468 | .cloned() | 3477 | .cloned() |
| 3469 | } | 3478 | } |
| 3470 | 3479 | ||
| 3480 | + pub fn output_left(&self) -> Option<Output> { | ||
| 3481 | + let active = self.layout.active_output()?; | ||
| 3482 | + self.output_left_of(active) | ||
| 3483 | + } | ||
| 3484 | + | ||
| 3485 | + pub fn output_right(&self) -> Option<Output> { | ||
| 3486 | + let active = self.layout.active_output()?; | ||
| 3487 | + self.output_right_of(active) | ||
| 3488 | + } | ||
| 3489 | + | ||
| 3490 | + pub fn output_up(&self) -> Option<Output> { | ||
| 3491 | + let active = self.layout.active_output()?; | ||
| 3492 | + self.output_up_of(active) | ||
| 3493 | + } | ||
| 3494 | + | ||
| 3495 | + pub fn output_down(&self) -> Option<Output> { | ||
| 3496 | + let active = self.layout.active_output()?; | ||
| 3497 | + self.output_down_of(active) | ||
| 3498 | + } | ||
| 3499 | + | ||
| 3500 | + pub fn output_previous(&self) -> Option<Output> { | ||
| 3501 | + let active = self.layout.active_output()?; | ||
| 3502 | + self.output_previous_of(active) | ||
| 3503 | + } | ||
| 3504 | + | ||
| 3505 | + pub fn output_next(&self) -> Option<Output> { | ||
| 3506 | + let active = self.layout.active_output()?; | ||
| 3507 | + self.output_next_of(active) | ||
| 3508 | + } | ||
| 3509 | + | ||
| 3471 | pub fn find_output_and_workspace_index( | 3510 | pub fn find_output_and_workspace_index( |
| 3472 | &self, | 3511 | &self, |
| 3473 | workspace_reference: WorkspaceReference, | 3512 | workspace_reference: WorkspaceReference, |
| @@ -3487,23 +3526,6 @@ impl Niri { | |||
| 3487 | Some((target_output.cloned(), target_workspace_index)) | 3526 | Some((target_output.cloned(), target_workspace_index)) |
| 3488 | } | 3527 | } |
| 3489 | 3528 | ||
| 3490 | - pub fn output_down(&self) -> Option<Output> { | ||
| 3491 | - let active = self.layout.active_output()?; | ||
| 3492 | - let active_geo = self.global_space.output_geometry(active).unwrap(); | ||
| 3493 | - let extended_geo = Rectangle::new( | ||
| 3494 | - Point::from((active_geo.loc.x, i32::MIN / 2)), | ||
| 3495 | - Size::from((active_geo.size.w, i32::MAX)), | ||
| 3496 | - ); | ||
| 3497 | - | ||
| 3498 | - self.global_space | ||
| 3499 | - .outputs() | ||
| 3500 | - .map(|output| (output, self.global_space.output_geometry(output).unwrap())) | ||
| 3501 | - .filter(|(_, geo)| center(active_geo).y < center(*geo).y && geo.overlaps(extended_geo)) | ||
| 3502 | - .min_by_key(|(_, geo)| center(*geo).y - center(active_geo).y) | ||
| 3503 | - .map(|(output, _)| output) | ||
| 3504 | - .cloned() | ||
| 3505 | - } | ||
| 3506 | - | ||
| 3507 | pub fn output_for_tablet(&self) -> Option<&Output> { | 3529 | pub fn output_for_tablet(&self) -> Option<&Output> { |
| 3508 | let config = self.config.borrow(); | 3530 | let config = self.config.borrow(); |
| 3509 | let map_to_output = config.input.tablet.map_to_output.as_ref(); | 3531 | let map_to_output = config.input.tablet.map_to_output.as_ref(); |