forge
Explore
Log in

Don't you dare go Hollow

Implement move-column/window-to-monitor actions for the screenshot UI

Browse files at this commit

2f18d8e32831a1e6000ca0d56dba05727088bb52Ivan MolodetskikhParent: 7aec37f
src/input/mod.rsmodified+104 -20
@@ -1535,7 +1535,12 @@ impl State {
1535 }1535 }
1536 }1536 }
1537 Action::MoveWindowToMonitorLeft => {1537 Action::MoveWindowToMonitorLeft => {
1538- if let Some(output) = self.niri.output_left() {1538+ if let Some(current_output) = self.niri.screenshot_ui.selection_output() {
1539+ if let Some(target_output) = self.niri.output_left_of(current_output) {
1540+ self.move_cursor_to_output(&target_output);
1541+ self.niri.screenshot_ui.move_to_output(target_output);
1542+ }
1543+ } else if let Some(output) = self.niri.output_left() {
1539 self.niri1544 self.niri
1540 .layout1545 .layout
1541 .move_to_output(None, &output, None, ActivateWindow::Smart);1546 .move_to_output(None, &output, None, ActivateWindow::Smart);
@@ -1546,7 +1551,12 @@ impl State {
1546 }1551 }
1547 }1552 }
1548 Action::MoveWindowToMonitorRight => {1553 Action::MoveWindowToMonitorRight => {
1549- if let Some(output) = self.niri.output_right() {1554+ if let Some(current_output) = self.niri.screenshot_ui.selection_output() {
1555+ if let Some(target_output) = self.niri.output_right_of(current_output) {
1556+ self.move_cursor_to_output(&target_output);
1557+ self.niri.screenshot_ui.move_to_output(target_output);
1558+ }
1559+ } else if let Some(output) = self.niri.output_right() {
1550 self.niri1560 self.niri
1551 .layout1561 .layout
1552 .move_to_output(None, &output, None, ActivateWindow::Smart);1562 .move_to_output(None, &output, None, ActivateWindow::Smart);
@@ -1557,7 +1567,12 @@ impl State {
1557 }1567 }
1558 }1568 }
1559 Action::MoveWindowToMonitorDown => {1569 Action::MoveWindowToMonitorDown => {
1560- if let Some(output) = self.niri.output_down() {1570+ if let Some(current_output) = self.niri.screenshot_ui.selection_output() {
1571+ if let Some(target_output) = self.niri.output_down_of(current_output) {
1572+ self.move_cursor_to_output(&target_output);
1573+ self.niri.screenshot_ui.move_to_output(target_output);
1574+ }
1575+ } else if let Some(output) = self.niri.output_down() {
1561 self.niri1576 self.niri
1562 .layout1577 .layout
1563 .move_to_output(None, &output, None, ActivateWindow::Smart);1578 .move_to_output(None, &output, None, ActivateWindow::Smart);
@@ -1568,7 +1583,12 @@ impl State {
1568 }1583 }
1569 }1584 }
1570 Action::MoveWindowToMonitorUp => {1585 Action::MoveWindowToMonitorUp => {
1571- if let Some(output) = self.niri.output_up() {1586+ if let Some(current_output) = self.niri.screenshot_ui.selection_output() {
1587+ if let Some(target_output) = self.niri.output_up_of(current_output) {
1588+ self.move_cursor_to_output(&target_output);
1589+ self.niri.screenshot_ui.move_to_output(target_output);
1590+ }
1591+ } else if let Some(output) = self.niri.output_up() {
1572 self.niri1592 self.niri
1573 .layout1593 .layout
1574 .move_to_output(None, &output, None, ActivateWindow::Smart);1594 .move_to_output(None, &output, None, ActivateWindow::Smart);
@@ -1579,7 +1599,12 @@ impl State {
1579 }1599 }
1580 }1600 }
1581 Action::MoveWindowToMonitorPrevious => {1601 Action::MoveWindowToMonitorPrevious => {
1582- if let Some(output) = self.niri.output_previous() {1602+ if let Some(current_output) = self.niri.screenshot_ui.selection_output() {
1603+ if let Some(target_output) = self.niri.output_previous_of(current_output) {
1604+ self.move_cursor_to_output(&target_output);
1605+ self.niri.screenshot_ui.move_to_output(target_output);
1606+ }
1607+ } else if let Some(output) = self.niri.output_previous() {
1583 self.niri1608 self.niri
1584 .layout1609 .layout
1585 .move_to_output(None, &output, None, ActivateWindow::Smart);1610 .move_to_output(None, &output, None, ActivateWindow::Smart);
@@ -1590,7 +1615,12 @@ impl State {
1590 }1615 }
1591 }1616 }
1592 Action::MoveWindowToMonitorNext => {1617 Action::MoveWindowToMonitorNext => {
1593- if let Some(output) = self.niri.output_next() {1618+ if let Some(current_output) = self.niri.screenshot_ui.selection_output() {
1619+ if let Some(target_output) = self.niri.output_next_of(current_output) {
1620+ self.move_cursor_to_output(&target_output);
1621+ self.niri.screenshot_ui.move_to_output(target_output);
1622+ }
1623+ } else if let Some(output) = self.niri.output_next() {
1594 self.niri1624 self.niri
1595 .layout1625 .layout
1596 .move_to_output(None, &output, None, ActivateWindow::Smart);1626 .move_to_output(None, &output, None, ActivateWindow::Smart);
@@ -1602,12 +1632,17 @@ impl State {
1602 }1632 }
1603 Action::MoveWindowToMonitor(output) => {1633 Action::MoveWindowToMonitor(output) => {
1604 if let Some(output) = self.niri.output_by_name_match(&output).cloned() {1634 if let Some(output) = self.niri.output_by_name_match(&output).cloned() {
1605- self.niri1635+ if self.niri.screenshot_ui.is_open() {
1606- .layout
1607- .move_to_output(None, &output, None, ActivateWindow::Smart);
1608- self.niri.layout.focus_output(&output);
1609- if !self.maybe_warp_cursor_to_focus_centered() {
1610 self.move_cursor_to_output(&output);1636 self.move_cursor_to_output(&output);
1637+ self.niri.screenshot_ui.move_to_output(output);
1638+ } else {
1639+ self.niri
1640+ .layout
1641+ .move_to_output(None, &output, None, ActivateWindow::Smart);
1642+ self.niri.layout.focus_output(&output);
1643+ if !self.maybe_warp_cursor_to_focus_centered() {
1644+ self.move_cursor_to_output(&output);
1645+ }
1611 }1646 }
1612 }1647 }
1613 }1648 }
@@ -1641,7 +1676,12 @@ impl State {
1641 }1676 }
1642 }1677 }
1643 Action::MoveColumnToMonitorLeft => {1678 Action::MoveColumnToMonitorLeft => {
1644- if let Some(output) = self.niri.output_left() {1679+ if let Some(current_output) = self.niri.screenshot_ui.selection_output() {
1680+ if let Some(target_output) = self.niri.output_left_of(current_output) {
1681+ self.move_cursor_to_output(&target_output);
1682+ self.niri.screenshot_ui.move_to_output(target_output);
1683+ }
1684+ } else if let Some(output) = self.niri.output_left() {
1645 self.niri.layout.move_column_to_output(&output, None, true);1685 self.niri.layout.move_column_to_output(&output, None, true);
1646 self.niri.layout.focus_output(&output);1686 self.niri.layout.focus_output(&output);
1647 if !self.maybe_warp_cursor_to_focus_centered() {1687 if !self.maybe_warp_cursor_to_focus_centered() {
@@ -1650,7 +1690,12 @@ impl State {
1650 }1690 }
1651 }1691 }
1652 Action::MoveColumnToMonitorRight => {1692 Action::MoveColumnToMonitorRight => {
1653- if let Some(output) = self.niri.output_right() {1693+ if let Some(current_output) = self.niri.screenshot_ui.selection_output() {
1694+ if let Some(target_output) = self.niri.output_right_of(current_output) {
1695+ self.move_cursor_to_output(&target_output);
1696+ self.niri.screenshot_ui.move_to_output(target_output);
1697+ }
1698+ } else if let Some(output) = self.niri.output_right() {
1654 self.niri.layout.move_column_to_output(&output, None, true);1699 self.niri.layout.move_column_to_output(&output, None, true);
1655 self.niri.layout.focus_output(&output);1700 self.niri.layout.focus_output(&output);
1656 if !self.maybe_warp_cursor_to_focus_centered() {1701 if !self.maybe_warp_cursor_to_focus_centered() {
@@ -1659,7 +1704,12 @@ impl State {
1659 }1704 }
1660 }1705 }
1661 Action::MoveColumnToMonitorDown => {1706 Action::MoveColumnToMonitorDown => {
1662- if let Some(output) = self.niri.output_down() {1707+ if let Some(current_output) = self.niri.screenshot_ui.selection_output() {
1708+ if let Some(target_output) = self.niri.output_down_of(current_output) {
1709+ self.move_cursor_to_output(&target_output);
1710+ self.niri.screenshot_ui.move_to_output(target_output);
1711+ }
1712+ } else if let Some(output) = self.niri.output_down() {
1663 self.niri.layout.move_column_to_output(&output, None, true);1713 self.niri.layout.move_column_to_output(&output, None, true);
1664 self.niri.layout.focus_output(&output);1714 self.niri.layout.focus_output(&output);
1665 if !self.maybe_warp_cursor_to_focus_centered() {1715 if !self.maybe_warp_cursor_to_focus_centered() {
@@ -1668,7 +1718,12 @@ impl State {
1668 }1718 }
1669 }1719 }
1670 Action::MoveColumnToMonitorUp => {1720 Action::MoveColumnToMonitorUp => {
1671- if let Some(output) = self.niri.output_up() {1721+ if let Some(current_output) = self.niri.screenshot_ui.selection_output() {
1722+ if let Some(target_output) = self.niri.output_up_of(current_output) {
1723+ self.move_cursor_to_output(&target_output);
1724+ self.niri.screenshot_ui.move_to_output(target_output);
1725+ }
1726+ } else if let Some(output) = self.niri.output_up() {
1672 self.niri.layout.move_column_to_output(&output, None, true);1727 self.niri.layout.move_column_to_output(&output, None, true);
1673 self.niri.layout.focus_output(&output);1728 self.niri.layout.focus_output(&output);
1674 if !self.maybe_warp_cursor_to_focus_centered() {1729 if !self.maybe_warp_cursor_to_focus_centered() {
@@ -1677,7 +1732,12 @@ impl State {
1677 }1732 }
1678 }1733 }
1679 Action::MoveColumnToMonitorPrevious => {1734 Action::MoveColumnToMonitorPrevious => {
1680- if let Some(output) = self.niri.output_previous() {1735+ if let Some(current_output) = self.niri.screenshot_ui.selection_output() {
1736+ if let Some(target_output) = self.niri.output_previous_of(current_output) {
1737+ self.move_cursor_to_output(&target_output);
1738+ self.niri.screenshot_ui.move_to_output(target_output);
1739+ }
1740+ } else if let Some(output) = self.niri.output_previous() {
1681 self.niri.layout.move_column_to_output(&output, None, true);1741 self.niri.layout.move_column_to_output(&output, None, true);
1682 self.niri.layout.focus_output(&output);1742 self.niri.layout.focus_output(&output);
1683 if !self.maybe_warp_cursor_to_focus_centered() {1743 if !self.maybe_warp_cursor_to_focus_centered() {
@@ -1686,7 +1746,12 @@ impl State {
1686 }1746 }
1687 }1747 }
1688 Action::MoveColumnToMonitorNext => {1748 Action::MoveColumnToMonitorNext => {
1689- if let Some(output) = self.niri.output_next() {1749+ if let Some(current_output) = self.niri.screenshot_ui.selection_output() {
1750+ if let Some(target_output) = self.niri.output_next_of(current_output) {
1751+ self.move_cursor_to_output(&target_output);
1752+ self.niri.screenshot_ui.move_to_output(target_output);
1753+ }
1754+ } else if let Some(output) = self.niri.output_next() {
1690 self.niri.layout.move_column_to_output(&output, None, true);1755 self.niri.layout.move_column_to_output(&output, None, true);
1691 self.niri.layout.focus_output(&output);1756 self.niri.layout.focus_output(&output);
1692 if !self.maybe_warp_cursor_to_focus_centered() {1757 if !self.maybe_warp_cursor_to_focus_centered() {
@@ -1696,10 +1761,15 @@ impl State {
1696 }1761 }
1697 Action::MoveColumnToMonitor(output) => {1762 Action::MoveColumnToMonitor(output) => {
1698 if let Some(output) = self.niri.output_by_name_match(&output).cloned() {1763 if let Some(output) = self.niri.output_by_name_match(&output).cloned() {
1699- self.niri.layout.move_column_to_output(&output, None, true);1764+ if self.niri.screenshot_ui.is_open() {
1700- self.niri.layout.focus_output(&output);
1701- if !self.maybe_warp_cursor_to_focus_centered() {
1702 self.move_cursor_to_output(&output);1765 self.move_cursor_to_output(&output);
1766+ self.niri.screenshot_ui.move_to_output(output);
1767+ } else {
1768+ self.niri.layout.move_column_to_output(&output, None, true);
1769+ self.niri.layout.focus_output(&output);
1770+ if !self.maybe_warp_cursor_to_focus_centered() {
1771+ self.move_cursor_to_output(&output);
1772+ }
1703 }1773 }
1704 }1774 }
1705 }1775 }
@@ -4120,6 +4190,20 @@ fn allowed_during_screenshot(action: &Action) -> bool {
4120 | Action::MoveWindowUpOrToWorkspaceUp4190 | Action::MoveWindowUpOrToWorkspaceUp
4121 | Action::MoveWindowDown4191 | Action::MoveWindowDown
4122 | Action::MoveWindowDownOrToWorkspaceDown4192 | Action::MoveWindowDownOrToWorkspaceDown
4193+ | Action::MoveColumnToMonitorLeft
4194+ | Action::MoveColumnToMonitorRight
4195+ | Action::MoveColumnToMonitorUp
4196+ | Action::MoveColumnToMonitorDown
4197+ | Action::MoveColumnToMonitorPrevious
4198+ | Action::MoveColumnToMonitorNext
4199+ | Action::MoveColumnToMonitor(_)
4200+ | Action::MoveWindowToMonitorLeft
4201+ | Action::MoveWindowToMonitorRight
4202+ | Action::MoveWindowToMonitorUp
4203+ | Action::MoveWindowToMonitorDown
4204+ | Action::MoveWindowToMonitorPrevious
4205+ | Action::MoveWindowToMonitorNext
4206+ | Action::MoveWindowToMonitor(_)
4123 | Action::SetWindowWidth(_)4207 | Action::SetWindowWidth(_)
4124 | Action::SetWindowHeight(_)4208 | Action::SetWindowHeight(_)
4125 | Action::SetColumnWidth(_)4209 | Action::SetColumnWidth(_)
src/ui/screenshot_ui.rsmodified+69 -0
@@ -347,6 +347,75 @@ impl ScreenshotUi {
347 self.update_buffers();347 self.update_buffers();
348 }348 }
349 349
350+ /// Moves the screenshot selection to a different output.
351+ ///
352+ /// This preserves the relative position while keeping logical size. It is (intentionally) very
353+ /// similar to how floating windows move across monitors, but with one difference: floating
354+ /// windows can go partially outside the view, while the screenshot selection cannot. So, we
355+ /// clamp it to new output bounds, trying to preserve the size if possible.
356+ pub fn move_to_output(&mut self, new_output: Output) {
357+ let Self::Open {
358+ selection,
359+ output_data,
360+ ..
361+ } = self
362+ else {
363+ return;
364+ };
365+
366+ let (current_output, current_a, current_b) = selection;
367+
368+ if current_output == &new_output {
369+ return;
370+ }
371+
372+ let Some(target_data) = output_data.get(&new_output) else {
373+ return;
374+ };
375+
376+ let current_data = &output_data[current_output];
377+
378+ let current_rect: Rectangle<_, Physical> = Rectangle::new(
379+ Point::from((current_a.x.min(current_b.x), current_a.y.min(current_b.y))),
380+ Size::from((
381+ (current_a.x.max(current_b.x) - current_a.x.min(current_b.x) + 1),
382+ (current_a.y.max(current_b.y) - current_a.y.min(current_b.y) + 1),
383+ )),
384+ );
385+ let current_rect = current_rect.to_f64();
386+
387+ let rel_x = current_rect.loc.x / current_data.size.w as f64;
388+ let rel_y = current_rect.loc.y / current_data.size.h as f64;
389+
390+ let factor = target_data.scale / current_data.scale;
391+ let mut new_width = (current_rect.size.w * factor).round() as i32;
392+ let mut new_height = (current_rect.size.h * factor).round() as i32;
393+
394+ new_width = new_width.clamp(1, target_data.size.w);
395+ new_height = new_height.clamp(1, target_data.size.h);
396+
397+ let new_x = (rel_x * target_data.size.w as f64).round() as i32;
398+ let new_y = (rel_y * target_data.size.h as f64).round() as i32;
399+
400+ let max_x = target_data.size.w - new_width;
401+ let max_y = target_data.size.h - new_height;
402+ let new_x = new_x.clamp(0, max_x);
403+ let new_y = new_y.clamp(0, max_y);
404+
405+ let new_rect = Rectangle::new(
406+ Point::from((new_x, new_y)),
407+ Size::from((new_width, new_height)),
408+ );
409+
410+ *selection = (
411+ new_output,
412+ new_rect.loc,
413+ new_rect.loc + new_rect.size - Size::from((1, 1)),
414+ );
415+
416+ self.update_buffers();
417+ }
418+
350 pub fn set_width(&mut self, change: SizeChange) {419 pub fn set_width(&mut self, change: SizeChange) {
351 let Self::Open {420 let Self::Open {
352 selection: (output, a, b),421 selection: (output, a, b),