Implement warp-mouse-to-focus
Browse files at this commit741bee461cbdaf0236eaa55dc86dc84b01613128Parent: 0c578157 changed files +214 -18
- niri-config/src/lib.rs +5 -0
- resources/default-config.kdl +3 -0
- src/input.rs +78 -16
- src/layout/monitor.rs +8 -0
- src/layout/workspace.rs +38 -0
- src/niri.rs +78 -2
- src/utils/mod.rs +4 -0
niri-config/src/lib.rsmodified+5 -0
| @@ -69,6 +69,8 @@ pub struct Input { | |||
| 69 | pub touch: Touch, | 69 | pub touch: Touch, |
| 70 | #[knuffel(child)] | 70 | #[knuffel(child)] |
| 71 | pub disable_power_key_handling: bool, | 71 | pub disable_power_key_handling: bool, |
| 72 | + #[knuffel(child)] | ||
| 73 | + pub warp_mouse_to_focus: bool, | ||
| 72 | } | 74 | } |
| 73 | 75 | ||
| 74 | #[derive(knuffel::Decode, Debug, Default, PartialEq, Eq)] | 76 | #[derive(knuffel::Decode, Debug, Default, PartialEq, Eq)] |
| @@ -1592,6 +1594,8 @@ mod tests { | |||
| 1592 | } | 1594 | } |
| 1593 | 1595 | ||
| 1594 | disable-power-key-handling | 1596 | disable-power-key-handling |
| 1597 | + | ||
| 1598 | + warp-mouse-to-focus | ||
| 1595 | } | 1599 | } |
| 1596 | 1600 | ||
| 1597 | output "eDP-1" { | 1601 | output "eDP-1" { |
| @@ -1731,6 +1735,7 @@ mod tests { | |||
| 1731 | map_to_output: Some("eDP-1".to_owned()), | 1735 | map_to_output: Some("eDP-1".to_owned()), |
| 1732 | }, | 1736 | }, |
| 1733 | disable_power_key_handling: true, | 1737 | disable_power_key_handling: true, |
| 1738 | + warp_mouse_to_focus: true, | ||
| 1734 | }, | 1739 | }, |
| 1735 | outputs: vec![Output { | 1740 | outputs: vec![Output { |
| 1736 | off: false, | 1741 | off: false, |
resources/default-config.kdlmodified+3 -0
| @@ -67,6 +67,9 @@ input { | |||
| 67 | // Uncomment this if you would like to configure the power button elsewhere | 67 | // Uncomment this if you would like to configure the power button elsewhere |
| 68 | // (i.e. logind.conf). | 68 | // (i.e. logind.conf). |
| 69 | // disable-power-key-handling | 69 | // disable-power-key-handling |
| 70 | + | ||
| 71 | + // Uncomment this to make the mouse warp to the center of newly focused windows. | ||
| 72 | + // warp-mouse-to-focus | ||
| 70 | } | 73 | } |
| 71 | 74 | ||
| 72 | // You can configure outputs by their name, which you can find | 75 | // You can configure outputs by their name, which you can find |
src/input.rsmodified+78 -16
| @@ -411,139 +411,166 @@ impl State { | |||
| 411 | } | 411 | } |
| 412 | Action::MoveColumnLeft => { | 412 | Action::MoveColumnLeft => { |
| 413 | self.niri.layout.move_left(); | 413 | self.niri.layout.move_left(); |
| 414 | + self.maybe_warp_cursor_to_focus(); | ||
| 414 | // FIXME: granular | 415 | // FIXME: granular |
| 415 | self.niri.queue_redraw_all(); | 416 | self.niri.queue_redraw_all(); |
| 416 | } | 417 | } |
| 417 | Action::MoveColumnRight => { | 418 | Action::MoveColumnRight => { |
| 418 | self.niri.layout.move_right(); | 419 | self.niri.layout.move_right(); |
| 420 | + self.maybe_warp_cursor_to_focus(); | ||
| 419 | // FIXME: granular | 421 | // FIXME: granular |
| 420 | self.niri.queue_redraw_all(); | 422 | self.niri.queue_redraw_all(); |
| 421 | } | 423 | } |
| 422 | Action::MoveColumnToFirst => { | 424 | Action::MoveColumnToFirst => { |
| 423 | self.niri.layout.move_column_to_first(); | 425 | self.niri.layout.move_column_to_first(); |
| 426 | + self.maybe_warp_cursor_to_focus(); | ||
| 424 | // FIXME: granular | 427 | // FIXME: granular |
| 425 | self.niri.queue_redraw_all(); | 428 | self.niri.queue_redraw_all(); |
| 426 | } | 429 | } |
| 427 | Action::MoveColumnToLast => { | 430 | Action::MoveColumnToLast => { |
| 428 | self.niri.layout.move_column_to_last(); | 431 | self.niri.layout.move_column_to_last(); |
| 432 | + self.maybe_warp_cursor_to_focus(); | ||
| 429 | // FIXME: granular | 433 | // FIXME: granular |
| 430 | self.niri.queue_redraw_all(); | 434 | self.niri.queue_redraw_all(); |
| 431 | } | 435 | } |
| 432 | Action::MoveWindowDown => { | 436 | Action::MoveWindowDown => { |
| 433 | self.niri.layout.move_down(); | 437 | self.niri.layout.move_down(); |
| 438 | + self.maybe_warp_cursor_to_focus(); | ||
| 434 | // FIXME: granular | 439 | // FIXME: granular |
| 435 | self.niri.queue_redraw_all(); | 440 | self.niri.queue_redraw_all(); |
| 436 | } | 441 | } |
| 437 | Action::MoveWindowUp => { | 442 | Action::MoveWindowUp => { |
| 438 | self.niri.layout.move_up(); | 443 | self.niri.layout.move_up(); |
| 444 | + self.maybe_warp_cursor_to_focus(); | ||
| 439 | // FIXME: granular | 445 | // FIXME: granular |
| 440 | self.niri.queue_redraw_all(); | 446 | self.niri.queue_redraw_all(); |
| 441 | } | 447 | } |
| 442 | Action::MoveWindowDownOrToWorkspaceDown => { | 448 | Action::MoveWindowDownOrToWorkspaceDown => { |
| 443 | self.niri.layout.move_down_or_to_workspace_down(); | 449 | self.niri.layout.move_down_or_to_workspace_down(); |
| 450 | + self.maybe_warp_cursor_to_focus(); | ||
| 444 | // FIXME: granular | 451 | // FIXME: granular |
| 445 | self.niri.queue_redraw_all(); | 452 | self.niri.queue_redraw_all(); |
| 446 | } | 453 | } |
| 447 | Action::MoveWindowUpOrToWorkspaceUp => { | 454 | Action::MoveWindowUpOrToWorkspaceUp => { |
| 448 | self.niri.layout.move_up_or_to_workspace_up(); | 455 | self.niri.layout.move_up_or_to_workspace_up(); |
| 456 | + self.maybe_warp_cursor_to_focus(); | ||
| 449 | // FIXME: granular | 457 | // FIXME: granular |
| 450 | self.niri.queue_redraw_all(); | 458 | self.niri.queue_redraw_all(); |
| 451 | } | 459 | } |
| 452 | Action::ConsumeOrExpelWindowLeft => { | 460 | Action::ConsumeOrExpelWindowLeft => { |
| 453 | self.niri.layout.consume_or_expel_window_left(); | 461 | self.niri.layout.consume_or_expel_window_left(); |
| 462 | + self.maybe_warp_cursor_to_focus(); | ||
| 454 | // FIXME: granular | 463 | // FIXME: granular |
| 455 | self.niri.queue_redraw_all(); | 464 | self.niri.queue_redraw_all(); |
| 456 | } | 465 | } |
| 457 | Action::ConsumeOrExpelWindowRight => { | 466 | Action::ConsumeOrExpelWindowRight => { |
| 458 | self.niri.layout.consume_or_expel_window_right(); | 467 | self.niri.layout.consume_or_expel_window_right(); |
| 468 | + self.maybe_warp_cursor_to_focus(); | ||
| 459 | // FIXME: granular | 469 | // FIXME: granular |
| 460 | self.niri.queue_redraw_all(); | 470 | self.niri.queue_redraw_all(); |
| 461 | } | 471 | } |
| 462 | Action::FocusColumnLeft => { | 472 | Action::FocusColumnLeft => { |
| 463 | self.niri.layout.focus_left(); | 473 | self.niri.layout.focus_left(); |
| 474 | + self.maybe_warp_cursor_to_focus(); | ||
| 464 | // FIXME: granular | 475 | // FIXME: granular |
| 465 | self.niri.queue_redraw_all(); | 476 | self.niri.queue_redraw_all(); |
| 466 | } | 477 | } |
| 467 | Action::FocusColumnRight => { | 478 | Action::FocusColumnRight => { |
| 468 | self.niri.layout.focus_right(); | 479 | self.niri.layout.focus_right(); |
| 480 | + self.maybe_warp_cursor_to_focus(); | ||
| 469 | // FIXME: granular | 481 | // FIXME: granular |
| 470 | self.niri.queue_redraw_all(); | 482 | self.niri.queue_redraw_all(); |
| 471 | } | 483 | } |
| 472 | Action::FocusColumnFirst => { | 484 | Action::FocusColumnFirst => { |
| 473 | self.niri.layout.focus_column_first(); | 485 | self.niri.layout.focus_column_first(); |
| 486 | + self.maybe_warp_cursor_to_focus(); | ||
| 474 | // FIXME: granular | 487 | // FIXME: granular |
| 475 | self.niri.queue_redraw_all(); | 488 | self.niri.queue_redraw_all(); |
| 476 | } | 489 | } |
| 477 | Action::FocusColumnLast => { | 490 | Action::FocusColumnLast => { |
| 478 | self.niri.layout.focus_column_last(); | 491 | self.niri.layout.focus_column_last(); |
| 492 | + self.maybe_warp_cursor_to_focus(); | ||
| 479 | // FIXME: granular | 493 | // FIXME: granular |
| 480 | self.niri.queue_redraw_all(); | 494 | self.niri.queue_redraw_all(); |
| 481 | } | 495 | } |
| 482 | Action::FocusWindowDown => { | 496 | Action::FocusWindowDown => { |
| 483 | self.niri.layout.focus_down(); | 497 | self.niri.layout.focus_down(); |
| 498 | + self.maybe_warp_cursor_to_focus(); | ||
| 484 | // FIXME: granular | 499 | // FIXME: granular |
| 485 | self.niri.queue_redraw_all(); | 500 | self.niri.queue_redraw_all(); |
| 486 | } | 501 | } |
| 487 | Action::FocusWindowUp => { | 502 | Action::FocusWindowUp => { |
| 488 | self.niri.layout.focus_up(); | 503 | self.niri.layout.focus_up(); |
| 504 | + self.maybe_warp_cursor_to_focus(); | ||
| 489 | // FIXME: granular | 505 | // FIXME: granular |
| 490 | self.niri.queue_redraw_all(); | 506 | self.niri.queue_redraw_all(); |
| 491 | } | 507 | } |
| 492 | Action::FocusWindowOrWorkspaceDown => { | 508 | Action::FocusWindowOrWorkspaceDown => { |
| 493 | self.niri.layout.focus_window_or_workspace_down(); | 509 | self.niri.layout.focus_window_or_workspace_down(); |
| 510 | + self.maybe_warp_cursor_to_focus(); | ||
| 494 | // FIXME: granular | 511 | // FIXME: granular |
| 495 | self.niri.queue_redraw_all(); | 512 | self.niri.queue_redraw_all(); |
| 496 | } | 513 | } |
| 497 | Action::FocusWindowOrWorkspaceUp => { | 514 | Action::FocusWindowOrWorkspaceUp => { |
| 498 | self.niri.layout.focus_window_or_workspace_up(); | 515 | self.niri.layout.focus_window_or_workspace_up(); |
| 516 | + self.maybe_warp_cursor_to_focus(); | ||
| 499 | // FIXME: granular | 517 | // FIXME: granular |
| 500 | self.niri.queue_redraw_all(); | 518 | self.niri.queue_redraw_all(); |
| 501 | } | 519 | } |
| 502 | Action::MoveWindowToWorkspaceDown => { | 520 | Action::MoveWindowToWorkspaceDown => { |
| 503 | self.niri.layout.move_to_workspace_down(); | 521 | self.niri.layout.move_to_workspace_down(); |
| 522 | + self.maybe_warp_cursor_to_focus(); | ||
| 504 | // FIXME: granular | 523 | // FIXME: granular |
| 505 | self.niri.queue_redraw_all(); | 524 | self.niri.queue_redraw_all(); |
| 506 | } | 525 | } |
| 507 | Action::MoveWindowToWorkspaceUp => { | 526 | Action::MoveWindowToWorkspaceUp => { |
| 508 | self.niri.layout.move_to_workspace_up(); | 527 | self.niri.layout.move_to_workspace_up(); |
| 528 | + self.maybe_warp_cursor_to_focus(); | ||
| 509 | // FIXME: granular | 529 | // FIXME: granular |
| 510 | self.niri.queue_redraw_all(); | 530 | self.niri.queue_redraw_all(); |
| 511 | } | 531 | } |
| 512 | Action::MoveWindowToWorkspace(idx) => { | 532 | Action::MoveWindowToWorkspace(idx) => { |
| 513 | let idx = idx.saturating_sub(1) as usize; | 533 | let idx = idx.saturating_sub(1) as usize; |
| 514 | self.niri.layout.move_to_workspace(idx); | 534 | self.niri.layout.move_to_workspace(idx); |
| 535 | + self.maybe_warp_cursor_to_focus(); | ||
| 515 | // FIXME: granular | 536 | // FIXME: granular |
| 516 | self.niri.queue_redraw_all(); | 537 | self.niri.queue_redraw_all(); |
| 517 | } | 538 | } |
| 518 | Action::MoveColumnToWorkspaceDown => { | 539 | Action::MoveColumnToWorkspaceDown => { |
| 519 | self.niri.layout.move_column_to_workspace_down(); | 540 | self.niri.layout.move_column_to_workspace_down(); |
| 541 | + self.maybe_warp_cursor_to_focus(); | ||
| 520 | // FIXME: granular | 542 | // FIXME: granular |
| 521 | self.niri.queue_redraw_all(); | 543 | self.niri.queue_redraw_all(); |
| 522 | } | 544 | } |
| 523 | Action::MoveColumnToWorkspaceUp => { | 545 | Action::MoveColumnToWorkspaceUp => { |
| 524 | self.niri.layout.move_column_to_workspace_up(); | 546 | self.niri.layout.move_column_to_workspace_up(); |
| 547 | + self.maybe_warp_cursor_to_focus(); | ||
| 525 | // FIXME: granular | 548 | // FIXME: granular |
| 526 | self.niri.queue_redraw_all(); | 549 | self.niri.queue_redraw_all(); |
| 527 | } | 550 | } |
| 528 | Action::MoveColumnToWorkspace(idx) => { | 551 | Action::MoveColumnToWorkspace(idx) => { |
| 529 | let idx = idx.saturating_sub(1) as usize; | 552 | let idx = idx.saturating_sub(1) as usize; |
| 530 | self.niri.layout.move_column_to_workspace(idx); | 553 | self.niri.layout.move_column_to_workspace(idx); |
| 554 | + self.maybe_warp_cursor_to_focus(); | ||
| 531 | // FIXME: granular | 555 | // FIXME: granular |
| 532 | self.niri.queue_redraw_all(); | 556 | self.niri.queue_redraw_all(); |
| 533 | } | 557 | } |
| 534 | Action::FocusWorkspaceDown => { | 558 | Action::FocusWorkspaceDown => { |
| 535 | self.niri.layout.switch_workspace_down(); | 559 | self.niri.layout.switch_workspace_down(); |
| 560 | + self.maybe_warp_cursor_to_focus(); | ||
| 536 | // FIXME: granular | 561 | // FIXME: granular |
| 537 | self.niri.queue_redraw_all(); | 562 | self.niri.queue_redraw_all(); |
| 538 | } | 563 | } |
| 539 | Action::FocusWorkspaceUp => { | 564 | Action::FocusWorkspaceUp => { |
| 540 | self.niri.layout.switch_workspace_up(); | 565 | self.niri.layout.switch_workspace_up(); |
| 566 | + self.maybe_warp_cursor_to_focus(); | ||
| 541 | // FIXME: granular | 567 | // FIXME: granular |
| 542 | self.niri.queue_redraw_all(); | 568 | self.niri.queue_redraw_all(); |
| 543 | } | 569 | } |
| 544 | Action::FocusWorkspace(idx) => { | 570 | Action::FocusWorkspace(idx) => { |
| 545 | let idx = idx.saturating_sub(1) as usize; | 571 | let idx = idx.saturating_sub(1) as usize; |
| 546 | self.niri.layout.switch_workspace(idx); | 572 | self.niri.layout.switch_workspace(idx); |
| 573 | + self.maybe_warp_cursor_to_focus(); | ||
| 547 | // FIXME: granular | 574 | // FIXME: granular |
| 548 | self.niri.queue_redraw_all(); | 575 | self.niri.queue_redraw_all(); |
| 549 | } | 576 | } |
| @@ -559,11 +586,14 @@ impl State { | |||
| 559 | } | 586 | } |
| 560 | Action::ConsumeWindowIntoColumn => { | 587 | Action::ConsumeWindowIntoColumn => { |
| 561 | self.niri.layout.consume_into_column(); | 588 | self.niri.layout.consume_into_column(); |
| 589 | + // This does not cause immediate focus or window size change, so warping mouse to | ||
| 590 | + // focus won't do anything here. | ||
| 562 | // FIXME: granular | 591 | // FIXME: granular |
| 563 | self.niri.queue_redraw_all(); | 592 | self.niri.queue_redraw_all(); |
| 564 | } | 593 | } |
| 565 | Action::ExpelWindowFromColumn => { | 594 | Action::ExpelWindowFromColumn => { |
| 566 | self.niri.layout.expel_from_column(); | 595 | self.niri.layout.expel_from_column(); |
| 596 | + self.maybe_warp_cursor_to_focus(); | ||
| 567 | // FIXME: granular | 597 | // FIXME: granular |
| 568 | self.niri.queue_redraw_all(); | 598 | self.niri.queue_redraw_all(); |
| 569 | } | 599 | } |
| @@ -581,81 +611,105 @@ impl State { | |||
| 581 | Action::FocusMonitorLeft => { | 611 | Action::FocusMonitorLeft => { |
| 582 | if let Some(output) = self.niri.output_left() { | 612 | if let Some(output) = self.niri.output_left() { |
| 583 | self.niri.layout.focus_output(&output); | 613 | self.niri.layout.focus_output(&output); |
| 584 | - self.move_cursor_to_output(&output); | 614 | + if !self.maybe_warp_cursor_to_focus_centered() { |
| 615 | + self.move_cursor_to_output(&output); | ||
| 616 | + } | ||
| 585 | } | 617 | } |
| 586 | } | 618 | } |
| 587 | Action::FocusMonitorRight => { | 619 | Action::FocusMonitorRight => { |
| 588 | if let Some(output) = self.niri.output_right() { | 620 | if let Some(output) = self.niri.output_right() { |
| 589 | self.niri.layout.focus_output(&output); | 621 | self.niri.layout.focus_output(&output); |
| 590 | - self.move_cursor_to_output(&output); | 622 | + if !self.maybe_warp_cursor_to_focus_centered() { |
| 623 | + self.move_cursor_to_output(&output); | ||
| 624 | + } | ||
| 591 | } | 625 | } |
| 592 | } | 626 | } |
| 593 | Action::FocusMonitorDown => { | 627 | Action::FocusMonitorDown => { |
| 594 | if let Some(output) = self.niri.output_down() { | 628 | if let Some(output) = self.niri.output_down() { |
| 595 | self.niri.layout.focus_output(&output); | 629 | self.niri.layout.focus_output(&output); |
| 596 | - self.move_cursor_to_output(&output); | 630 | + if !self.maybe_warp_cursor_to_focus_centered() { |
| 631 | + self.move_cursor_to_output(&output); | ||
| 632 | + } | ||
| 597 | } | 633 | } |
| 598 | } | 634 | } |
| 599 | Action::FocusMonitorUp => { | 635 | Action::FocusMonitorUp => { |
| 600 | if let Some(output) = self.niri.output_up() { | 636 | if let Some(output) = self.niri.output_up() { |
| 601 | self.niri.layout.focus_output(&output); | 637 | self.niri.layout.focus_output(&output); |
| 602 | - self.move_cursor_to_output(&output); | 638 | + if !self.maybe_warp_cursor_to_focus_centered() { |
| 639 | + self.move_cursor_to_output(&output); | ||
| 640 | + } | ||
| 603 | } | 641 | } |
| 604 | } | 642 | } |
| 605 | Action::MoveWindowToMonitorLeft => { | 643 | Action::MoveWindowToMonitorLeft => { |
| 606 | if let Some(output) = self.niri.output_left() { | 644 | if let Some(output) = self.niri.output_left() { |
| 607 | self.niri.layout.move_to_output(&output); | 645 | self.niri.layout.move_to_output(&output); |
| 608 | self.niri.layout.focus_output(&output); | 646 | self.niri.layout.focus_output(&output); |
| 609 | - self.move_cursor_to_output(&output); | 647 | + if !self.maybe_warp_cursor_to_focus_centered() { |
| 648 | + self.move_cursor_to_output(&output); | ||
| 649 | + } | ||
| 610 | } | 650 | } |
| 611 | } | 651 | } |
| 612 | Action::MoveWindowToMonitorRight => { | 652 | Action::MoveWindowToMonitorRight => { |
| 613 | if let Some(output) = self.niri.output_right() { | 653 | if let Some(output) = self.niri.output_right() { |
| 614 | self.niri.layout.move_to_output(&output); | 654 | self.niri.layout.move_to_output(&output); |
| 615 | self.niri.layout.focus_output(&output); | 655 | self.niri.layout.focus_output(&output); |
| 616 | - self.move_cursor_to_output(&output); | 656 | + if !self.maybe_warp_cursor_to_focus_centered() { |
| 657 | + self.move_cursor_to_output(&output); | ||
| 658 | + } | ||
| 617 | } | 659 | } |
| 618 | } | 660 | } |
| 619 | Action::MoveWindowToMonitorDown => { | 661 | Action::MoveWindowToMonitorDown => { |
| 620 | if let Some(output) = self.niri.output_down() { | 662 | if let Some(output) = self.niri.output_down() { |
| 621 | self.niri.layout.move_to_output(&output); | 663 | self.niri.layout.move_to_output(&output); |
| 622 | self.niri.layout.focus_output(&output); | 664 | self.niri.layout.focus_output(&output); |
| 623 | - self.move_cursor_to_output(&output); | 665 | + if !self.maybe_warp_cursor_to_focus_centered() { |
| 666 | + self.move_cursor_to_output(&output); | ||
| 667 | + } | ||
| 624 | } | 668 | } |
| 625 | } | 669 | } |
| 626 | Action::MoveWindowToMonitorUp => { | 670 | Action::MoveWindowToMonitorUp => { |
| 627 | if let Some(output) = self.niri.output_up() { | 671 | if let Some(output) = self.niri.output_up() { |
| 628 | self.niri.layout.move_to_output(&output); | 672 | self.niri.layout.move_to_output(&output); |
| 629 | self.niri.layout.focus_output(&output); | 673 | self.niri.layout.focus_output(&output); |
| 630 | - self.move_cursor_to_output(&output); | 674 | + if !self.maybe_warp_cursor_to_focus_centered() { |
| 675 | + self.move_cursor_to_output(&output); | ||
| 676 | + } | ||
| 631 | } | 677 | } |
| 632 | } | 678 | } |
| 633 | Action::MoveColumnToMonitorLeft => { | 679 | Action::MoveColumnToMonitorLeft => { |
| 634 | if let Some(output) = self.niri.output_left() { | 680 | if let Some(output) = self.niri.output_left() { |
| 635 | self.niri.layout.move_column_to_output(&output); | 681 | self.niri.layout.move_column_to_output(&output); |
| 636 | self.niri.layout.focus_output(&output); | 682 | self.niri.layout.focus_output(&output); |
| 637 | - self.move_cursor_to_output(&output); | 683 | + if !self.maybe_warp_cursor_to_focus_centered() { |
| 684 | + self.move_cursor_to_output(&output); | ||
| 685 | + } | ||
| 638 | } | 686 | } |
| 639 | } | 687 | } |
| 640 | Action::MoveColumnToMonitorRight => { | 688 | Action::MoveColumnToMonitorRight => { |
| 641 | if let Some(output) = self.niri.output_right() { | 689 | if let Some(output) = self.niri.output_right() { |
| 642 | self.niri.layout.move_column_to_output(&output); | 690 | self.niri.layout.move_column_to_output(&output); |
| 643 | self.niri.layout.focus_output(&output); | 691 | self.niri.layout.focus_output(&output); |
| 644 | - self.move_cursor_to_output(&output); | 692 | + if !self.maybe_warp_cursor_to_focus_centered() { |
| 693 | + self.move_cursor_to_output(&output); | ||
| 694 | + } | ||
| 645 | } | 695 | } |
| 646 | } | 696 | } |
| 647 | Action::MoveColumnToMonitorDown => { | 697 | Action::MoveColumnToMonitorDown => { |
| 648 | if let Some(output) = self.niri.output_down() { | 698 | if let Some(output) = self.niri.output_down() { |
| 649 | self.niri.layout.move_column_to_output(&output); | 699 | self.niri.layout.move_column_to_output(&output); |
| 650 | self.niri.layout.focus_output(&output); | 700 | self.niri.layout.focus_output(&output); |
| 651 | - self.move_cursor_to_output(&output); | 701 | + if !self.maybe_warp_cursor_to_focus_centered() { |
| 702 | + self.move_cursor_to_output(&output); | ||
| 703 | + } | ||
| 652 | } | 704 | } |
| 653 | } | 705 | } |
| 654 | Action::MoveColumnToMonitorUp => { | 706 | Action::MoveColumnToMonitorUp => { |
| 655 | if let Some(output) = self.niri.output_up() { | 707 | if let Some(output) = self.niri.output_up() { |
| 656 | self.niri.layout.move_column_to_output(&output); | 708 | self.niri.layout.move_column_to_output(&output); |
| 657 | self.niri.layout.focus_output(&output); | 709 | self.niri.layout.focus_output(&output); |
| 658 | - self.move_cursor_to_output(&output); | 710 | + if !self.maybe_warp_cursor_to_focus_centered() { |
| 711 | + self.move_cursor_to_output(&output); | ||
| 712 | + } | ||
| 659 | } | 713 | } |
| 660 | } | 714 | } |
| 661 | Action::SetColumnWidth(change) => { | 715 | Action::SetColumnWidth(change) => { |
| @@ -672,25 +726,33 @@ impl State { | |||
| 672 | Action::MoveWorkspaceToMonitorLeft => { | 726 | Action::MoveWorkspaceToMonitorLeft => { |
| 673 | if let Some(output) = self.niri.output_left() { | 727 | if let Some(output) = self.niri.output_left() { |
| 674 | self.niri.layout.move_workspace_to_output(&output); | 728 | self.niri.layout.move_workspace_to_output(&output); |
| 675 | - self.move_cursor_to_output(&output); | 729 | + if !self.maybe_warp_cursor_to_focus_centered() { |
| 730 | + self.move_cursor_to_output(&output); | ||
| 731 | + } | ||
| 676 | } | 732 | } |
| 677 | } | 733 | } |
| 678 | Action::MoveWorkspaceToMonitorRight => { | 734 | Action::MoveWorkspaceToMonitorRight => { |
| 679 | if let Some(output) = self.niri.output_right() { | 735 | if let Some(output) = self.niri.output_right() { |
| 680 | self.niri.layout.move_workspace_to_output(&output); | 736 | self.niri.layout.move_workspace_to_output(&output); |
| 681 | - self.move_cursor_to_output(&output); | 737 | + if !self.maybe_warp_cursor_to_focus_centered() { |
| 738 | + self.move_cursor_to_output(&output); | ||
| 739 | + } | ||
| 682 | } | 740 | } |
| 683 | } | 741 | } |
| 684 | Action::MoveWorkspaceToMonitorDown => { | 742 | Action::MoveWorkspaceToMonitorDown => { |
| 685 | if let Some(output) = self.niri.output_down() { | 743 | if let Some(output) = self.niri.output_down() { |
| 686 | self.niri.layout.move_workspace_to_output(&output); | 744 | self.niri.layout.move_workspace_to_output(&output); |
| 687 | - self.move_cursor_to_output(&output); | 745 | + if !self.maybe_warp_cursor_to_focus_centered() { |
| 746 | + self.move_cursor_to_output(&output); | ||
| 747 | + } | ||
| 688 | } | 748 | } |
| 689 | } | 749 | } |
| 690 | Action::MoveWorkspaceToMonitorUp => { | 750 | Action::MoveWorkspaceToMonitorUp => { |
| 691 | if let Some(output) = self.niri.output_up() { | 751 | if let Some(output) = self.niri.output_up() { |
| 692 | self.niri.layout.move_workspace_to_output(&output); | 752 | self.niri.layout.move_workspace_to_output(&output); |
| 693 | - self.move_cursor_to_output(&output); | 753 | + if !self.maybe_warp_cursor_to_focus_centered() { |
| 754 | + self.move_cursor_to_output(&output); | ||
| 755 | + } | ||
| 694 | } | 756 | } |
| 695 | } | 757 | } |
| 696 | } | 758 | } |
src/layout/monitor.rsmodified+8 -0
| @@ -583,6 +583,14 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 583 | self.clean_up_workspaces(); | 583 | self.clean_up_workspaces(); |
| 584 | } | 584 | } |
| 585 | 585 | ||
| 586 | + /// Returns the geometry of the active tile relative to and clamped to the output. | ||
| 587 | + /// | ||
| 588 | + /// During animations, assumes the final view position. | ||
| 589 | + pub fn active_tile_visual_rectangle(&self) -> Option<Rectangle<i32, Logical>> { | ||
| 590 | + // FIXME: switch gesture. | ||
| 591 | + self.active_workspace_ref().active_tile_visual_rectangle() | ||
| 592 | + } | ||
| 593 | + | ||
| 586 | pub fn window_under( | 594 | pub fn window_under( |
| 587 | &self, | 595 | &self, |
| 588 | pos_within_output: Point<f64, Logical>, | 596 | pos_within_output: Point<f64, Logical>, |
src/layout/workspace.rsmodified+38 -0
| @@ -181,6 +181,15 @@ impl OutputId { | |||
| 181 | } | 181 | } |
| 182 | } | 182 | } |
| 183 | 183 | ||
| 184 | +impl ViewOffsetAdjustment { | ||
| 185 | + pub fn target_view_offset(&self) -> f64 { | ||
| 186 | + match self { | ||
| 187 | + ViewOffsetAdjustment::Animation(anim) => anim.to(), | ||
| 188 | + ViewOffsetAdjustment::Gesture(gesture) => gesture.current_view_offset, | ||
| 189 | + } | ||
| 190 | + } | ||
| 191 | +} | ||
| 192 | + | ||
| 184 | impl ColumnWidth { | 193 | impl ColumnWidth { |
| 185 | fn resolve(self, options: &Options, view_width: i32) -> i32 { | 194 | fn resolve(self, options: &Options, view_width: i32) -> i32 { |
| 186 | match self { | 195 | match self { |
| @@ -1124,6 +1133,31 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1124 | first.chain(rest) | 1133 | first.chain(rest) |
| 1125 | } | 1134 | } |
| 1126 | 1135 | ||
| 1136 | + fn active_column_ref(&self) -> Option<&Column<W>> { | ||
| 1137 | + if self.columns.is_empty() { | ||
| 1138 | + return None; | ||
| 1139 | + } | ||
| 1140 | + Some(&self.columns[self.active_column_idx]) | ||
| 1141 | + } | ||
| 1142 | + | ||
| 1143 | + /// Returns the geometry of the active tile relative to and clamped to the view. | ||
| 1144 | + /// | ||
| 1145 | + /// During animations, assumes the final view position. | ||
| 1146 | + pub fn active_tile_visual_rectangle(&self) -> Option<Rectangle<i32, Logical>> { | ||
| 1147 | + let col = self.active_column_ref()?; | ||
| 1148 | + let view_pos = self | ||
| 1149 | + .view_offset_adj | ||
| 1150 | + .as_ref() | ||
| 1151 | + .map_or(self.view_offset, |adj| adj.target_view_offset() as i32); | ||
| 1152 | + | ||
| 1153 | + let tile_pos = Point::from((-view_pos, col.tile_y(col.active_tile_idx))); | ||
| 1154 | + let tile_size = col.active_tile_ref().tile_size(); | ||
| 1155 | + let tile_rect = Rectangle::from_loc_and_size(tile_pos, tile_size); | ||
| 1156 | + | ||
| 1157 | + let view = Rectangle::from_loc_and_size((0, 0), self.view_size); | ||
| 1158 | + view.intersection(tile_rect) | ||
| 1159 | + } | ||
| 1160 | + | ||
| 1127 | pub fn window_under( | 1161 | pub fn window_under( |
| 1128 | &self, | 1162 | &self, |
| 1129 | pos: Point<f64, Logical>, | 1163 | pos: Point<f64, Logical>, |
| @@ -2010,6 +2044,10 @@ impl<W: LayoutElement> Column<W> { | |||
| 2010 | pos | 2044 | pos |
| 2011 | }) | 2045 | }) |
| 2012 | } | 2046 | } |
| 2047 | + | ||
| 2048 | + fn active_tile_ref(&self) -> &Tile<W> { | ||
| 2049 | + &self.tiles[self.active_tile_idx] | ||
| 2050 | + } | ||
| 2013 | } | 2051 | } |
| 2014 | 2052 | ||
| 2015 | fn compute_new_view_offset( | 2053 | fn compute_new_view_offset( |
src/niri.rsmodified+78 -2
| @@ -112,7 +112,7 @@ use crate::ui::hotkey_overlay::HotkeyOverlay; | |||
| 112 | use crate::ui::screenshot_ui::{ScreenshotUi, ScreenshotUiRenderElement}; | 112 | use crate::ui::screenshot_ui::{ScreenshotUi, ScreenshotUiRenderElement}; |
| 113 | use crate::utils::spawning::CHILD_ENV; | 113 | use crate::utils::spawning::CHILD_ENV; |
| 114 | use crate::utils::{ | 114 | use crate::utils::{ |
| 115 | - center, get_monotonic_time, make_screenshot_path, output_size, write_png_rgba8, | 115 | + center, center_f64, get_monotonic_time, make_screenshot_path, output_size, write_png_rgba8, |
| 116 | }; | 116 | }; |
| 117 | use crate::window::Unmapped; | 117 | use crate::window::Unmapped; |
| 118 | use crate::{animation, niri_render_elements}; | 118 | use crate::{animation, niri_render_elements}; |
| @@ -197,7 +197,6 @@ pub struct Niri { | |||
| 197 | // popup grabs are active (which means the real keyboard focus is on a popup descending from | 197 | // popup grabs are active (which means the real keyboard focus is on a popup descending from |
| 198 | // this toplevel surface). | 198 | // this toplevel surface). |
| 199 | pub keyboard_focus: Option<WlSurface>, | 199 | pub keyboard_focus: Option<WlSurface>, |
| 200 | - | ||
| 201 | pub idle_inhibiting_surfaces: HashSet<WlSurface>, | 200 | pub idle_inhibiting_surfaces: HashSet<WlSurface>, |
| 202 | pub is_fdo_idle_inhibited: Arc<AtomicBool>, | 201 | pub is_fdo_idle_inhibited: Arc<AtomicBool>, |
| 203 | 202 | ||
| @@ -314,6 +313,11 @@ struct SurfaceFrameThrottlingState { | |||
| 314 | last_sent_at: RefCell<Option<(Output, u32)>>, | 313 | last_sent_at: RefCell<Option<(Output, u32)>>, |
| 315 | } | 314 | } |
| 316 | 315 | ||
| 316 | +pub enum CenterCoords { | ||
| 317 | + Seperately, | ||
| 318 | + Both, | ||
| 319 | +} | ||
| 320 | + | ||
| 317 | #[derive(Default)] | 321 | #[derive(Default)] |
| 318 | pub struct WindowOffscreenId(pub RefCell<Option<Id>>); | 322 | pub struct WindowOffscreenId(pub RefCell<Option<Id>>); |
| 319 | 323 | ||
| @@ -401,6 +405,78 @@ impl State { | |||
| 401 | self.niri.queue_redraw_all(); | 405 | self.niri.queue_redraw_all(); |
| 402 | } | 406 | } |
| 403 | 407 | ||
| 408 | + /// Moves cursor within the specified rectangle, only adjusting coordinates if needed. | ||
| 409 | + fn move_cursor_to_rect(&mut self, rect: Rectangle<f64, Logical>, mode: CenterCoords) -> bool { | ||
| 410 | + let pointer = &self.niri.seat.get_pointer().unwrap(); | ||
| 411 | + let cur_loc = pointer.current_location(); | ||
| 412 | + let x_in_bound = cur_loc.x >= rect.loc.x && cur_loc.x <= rect.loc.x + rect.size.w; | ||
| 413 | + let y_in_bound = cur_loc.y >= rect.loc.y && cur_loc.y <= rect.loc.y + rect.size.h; | ||
| 414 | + | ||
| 415 | + let p = match mode { | ||
| 416 | + CenterCoords::Seperately => { | ||
| 417 | + if x_in_bound && y_in_bound { | ||
| 418 | + return false; | ||
| 419 | + } else if y_in_bound { | ||
| 420 | + // adjust x | ||
| 421 | + Point::from((rect.loc.x + rect.size.w / 2.0, cur_loc.y)) | ||
| 422 | + } else if x_in_bound { | ||
| 423 | + // adjust y | ||
| 424 | + Point::from((cur_loc.x, rect.loc.y + rect.size.h / 2.0)) | ||
| 425 | + } else { | ||
| 426 | + // adjust x and y | ||
| 427 | + center_f64(rect) | ||
| 428 | + } | ||
| 429 | + } | ||
| 430 | + CenterCoords::Both => { | ||
| 431 | + if x_in_bound && y_in_bound { | ||
| 432 | + return false; | ||
| 433 | + } else { | ||
| 434 | + // adjust x and y | ||
| 435 | + center_f64(rect) | ||
| 436 | + } | ||
| 437 | + } | ||
| 438 | + }; | ||
| 439 | + | ||
| 440 | + self.move_cursor(p); | ||
| 441 | + true | ||
| 442 | + } | ||
| 443 | + | ||
| 444 | + pub fn move_cursor_to_focused_tile(&mut self, mode: CenterCoords) -> bool { | ||
| 445 | + let Some(output) = self.niri.layout.active_output() else { | ||
| 446 | + return false; | ||
| 447 | + }; | ||
| 448 | + let output = output.clone(); | ||
| 449 | + let monitor = self.niri.layout.monitor_for_output(&output).unwrap(); | ||
| 450 | + | ||
| 451 | + let mut rv = false; | ||
| 452 | + let rect = monitor.active_tile_visual_rectangle(); | ||
| 453 | + | ||
| 454 | + if let Some(rect) = rect { | ||
| 455 | + let output_geo = self.niri.global_space.output_geometry(&output).unwrap(); | ||
| 456 | + let mut rect = rect; | ||
| 457 | + rect.loc += output_geo.loc; | ||
| 458 | + rv = self.move_cursor_to_rect(rect.to_f64(), mode); | ||
| 459 | + } | ||
| 460 | + | ||
| 461 | + rv | ||
| 462 | + } | ||
| 463 | + | ||
| 464 | + pub fn maybe_warp_cursor_to_focus(&mut self) -> bool { | ||
| 465 | + if !self.niri.config.borrow().input.warp_mouse_to_focus { | ||
| 466 | + return false; | ||
| 467 | + } | ||
| 468 | + | ||
| 469 | + self.move_cursor_to_focused_tile(CenterCoords::Seperately) | ||
| 470 | + } | ||
| 471 | + | ||
| 472 | + pub fn maybe_warp_cursor_to_focus_centered(&mut self) -> bool { | ||
| 473 | + if !self.niri.config.borrow().input.warp_mouse_to_focus { | ||
| 474 | + return false; | ||
| 475 | + } | ||
| 476 | + | ||
| 477 | + self.move_cursor_to_focused_tile(CenterCoords::Both) | ||
| 478 | + } | ||
| 479 | + | ||
| 404 | pub fn refresh_pointer_focus(&mut self) { | 480 | pub fn refresh_pointer_focus(&mut self) { |
| 405 | let _span = tracy_client::span!("Niri::refresh_pointer_focus"); | 481 | let _span = tracy_client::span!("Niri::refresh_pointer_focus"); |
| 406 | 482 | ||
src/utils/mod.rsmodified+4 -0
| @@ -40,6 +40,10 @@ pub fn center(rect: Rectangle<i32, Logical>) -> Point<i32, Logical> { | |||
| 40 | rect.loc + rect.size.downscale(2).to_point() | 40 | rect.loc + rect.size.downscale(2).to_point() |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | +pub fn center_f64(rect: Rectangle<f64, Logical>) -> Point<f64, Logical> { | ||
| 44 | + rect.loc + rect.size.downscale(2.0).to_point() | ||
| 45 | +} | ||
| 46 | + | ||
| 43 | pub fn output_size(output: &Output) -> Size<i32, Logical> { | 47 | pub fn output_size(output: &Output) -> Size<i32, Logical> { |
| 44 | let output_scale = output.current_scale().integer_scale(); | 48 | let output_scale = output.current_scale().integer_scale(); |
| 45 | let output_transform = output.current_transform(); | 49 | let output_transform = output.current_transform(); |