1
1
#include " Compositor.hpp"
2
+ #include " desktop/DesktopTypes.hpp"
2
3
#include " helpers/Splashes.hpp"
3
4
#include " config/ConfigValue.hpp"
4
5
#include " managers/CursorManager.hpp"
5
6
#include " managers/TokenManager.hpp"
6
7
#include " managers/PointerManager.hpp"
7
8
#include " managers/SeatManager.hpp"
8
9
#include " managers/eventLoop/EventLoopManager.hpp"
10
+ #include < cstdint>
9
11
#include < random>
12
+ #include < ranges>
10
13
#include < unordered_set>
11
14
#include " debug/HyprCtl.hpp"
12
15
#include " debug/CrashReporter.hpp"
13
16
#ifdef USES_SYSTEMD
14
17
#include < helpers/SdDaemon.hpp> // for SdNotify
15
18
#endif
16
19
#include < ranges>
17
- #include " helpers/varlist/VarList.hpp"
18
20
#include " protocols/FractionalScale.hpp"
19
21
#include " protocols/PointerConstraints.hpp"
20
22
#include " protocols/LayerShell.hpp"
@@ -671,6 +673,30 @@ CMonitor* CCompositor::getMonitorFromVector(const Vector2D& point) {
671
673
return mon.get ();
672
674
}
673
675
676
+ SP<CMonitor> CCompositor::getNextMonitor (uint64_t curID, bool reverse) {
677
+ const auto LN = m_vMonitors.size ();
678
+ if (LN == 1 ) {
679
+ return m_vMonitors[0 ];
680
+ }
681
+
682
+ size_t curPos = LN + 1 ;
683
+ for (size_t i = 0 ; i < LN; i++) {
684
+ if (m_vMonitors[i]->ID == curID) {
685
+ curPos = i;
686
+ }
687
+ }
688
+
689
+ if (curPos == LN && !reverse) {
690
+ return m_vMonitors[0 ];
691
+ }
692
+
693
+ if (curPos == 0 && reverse) {
694
+ return m_vMonitors[LN - 1 ];
695
+ }
696
+
697
+ return reverse ? m_vMonitors[curPos - 1 ] : m_vMonitors[curPos + 1 ];
698
+ }
699
+
674
700
void CCompositor::removeWindowFromVectorSafe (PHLWINDOW pWindow) {
675
701
if (!pWindow->m_bFadingOut ) {
676
702
EMIT_HOOK_EVENT (" destroyWindow" , pWindow);
@@ -1567,15 +1593,40 @@ PHLWINDOW CCompositor::getWindowInDirection(PHLWINDOW pWindow, char dir) {
1567
1593
}
1568
1594
1569
1595
PHLWINDOW CCompositor::getNextWindowOnWorkspace (PHLWINDOW pWindow, bool focusableOnly, std::optional<bool > floating) {
1570
- bool gotToWindow = false ;
1596
+ // going through all windows in the workspace after current, from current
1597
+ for (auto it = std::find (m_vWindows.begin (), m_vWindows.end (), pWindow); it != m_vWindows.end (); ++it) {
1598
+ auto & w = *it;
1599
+ if ((!floating.has_value () || w->m_bIsFloating == floating.value ()) && w->m_pWorkspace == pWindow->m_pWorkspace && w->m_bIsMapped && !w->isHidden () && (!focusableOnly || !w->m_sWindowData .noFocus .valueOrDefault ()))
1600
+ return w;
1601
+ }
1602
+
1603
+ // going through all windows in the workspace before current, from first
1571
1604
for (auto & w : m_vWindows) {
1572
- if (w != pWindow && !gotToWindow )
1573
- continue ;
1605
+ if (w == pWindow)
1606
+ return nullptr ;
1574
1607
1575
- if (w == pWindow) {
1576
- gotToWindow = true ;
1608
+ if (floating.has_value () && w->m_bIsFloating != floating.value ())
1577
1609
continue ;
1578
- }
1610
+
1611
+ if (w->m_pWorkspace == pWindow->m_pWorkspace && w->m_bIsMapped && !w->isHidden () && (!focusableOnly || !w->m_sWindowData .noFocus .valueOrDefault ()))
1612
+ return w;
1613
+ }
1614
+
1615
+ return nullptr ;
1616
+ }
1617
+
1618
+ PHLWINDOW CCompositor::getPrevWindowOnWorkspace (PHLWINDOW pWindow, bool focusableOnly, std::optional<bool > floating) {
1619
+ // going through all windows in the workspace before current, from current
1620
+ for (auto it = std::find (m_vWindows.rbegin (), m_vWindows.rend (), pWindow); it != m_vWindows.rend (); ++it) {
1621
+ auto & w = *it;
1622
+ if ((!floating.has_value () || w->m_bIsFloating == floating.value ()) && w->m_pWorkspace == pWindow->m_pWorkspace && w->m_bIsMapped && !w->isHidden () && (!focusableOnly || !w->m_sWindowData .noFocus .valueOrDefault ()))
1623
+ return w;
1624
+ }
1625
+
1626
+ // going through all windows in the workspace after current, from last
1627
+ for (auto & w : m_vWindows | std::views::reverse) {
1628
+ if (w == pWindow)
1629
+ return nullptr ;
1579
1630
1580
1631
if (floating.has_value () && w->m_bIsFloating != floating.value ())
1581
1632
continue ;
@@ -1584,41 +1635,74 @@ PHLWINDOW CCompositor::getNextWindowOnWorkspace(PHLWINDOW pWindow, bool focusabl
1584
1635
return w;
1585
1636
}
1586
1637
1638
+ return nullptr ;
1639
+ }
1640
+
1641
+ PHLWINDOW CCompositor::getNextVisibleWindow (PHLWINDOW pWindow, bool focusableOnly, std::optional<bool > floating) {
1642
+ // going through all windows in the workspace after current, from current
1643
+ for (auto it = std::find (m_vWindows.begin (), m_vWindows.end (), pWindow); it != m_vWindows.end (); ++it) {
1644
+ auto & w = *it;
1645
+ if ((!floating.has_value () || w->m_bIsFloating == floating.value ()) &&w->m_bIsMapped && !w->isHidden () && (!focusableOnly || !w->m_sWindowData .noFocus .valueOrDefault ()))
1646
+ return w;
1647
+ }
1648
+
1649
+ if (const auto & w = getWindowOnAnotherMonitor (pWindow->m_iMonitorID , floating, true ); w && (!floating.has_value () || w->m_bIsFloating == floating.value ()) && w->m_bIsMapped && !w->isHidden () && (!focusableOnly || !w->m_sWindowData .noFocus .valueOrDefault ()))
1650
+ return w;
1651
+
1652
+
1653
+ // going through all windows in the workspace before current, from first
1587
1654
for (auto & w : m_vWindows) {
1655
+ if (w == pWindow)
1656
+ return nullptr ;
1657
+
1588
1658
if (floating.has_value () && w->m_bIsFloating != floating.value ())
1589
1659
continue ;
1590
1660
1591
- if (w != pWindow && w-> m_pWorkspace == pWindow-> m_pWorkspace && w ->m_bIsMapped && !w->isHidden () && (!focusableOnly || !w->m_sWindowData .noFocus .valueOrDefault ()))
1661
+ if (w->m_bIsMapped && !w->isHidden () && (!focusableOnly || !w->m_sWindowData .noFocus .valueOrDefault ()))
1592
1662
return w;
1593
1663
}
1594
1664
1595
1665
return nullptr ;
1596
1666
}
1597
1667
1598
- PHLWINDOW CCompositor::getPrevWindowOnWorkspace (PHLWINDOW pWindow, bool focusableOnly, std::optional<bool > floating) {
1599
- bool gotToWindow = false ;
1600
- for (auto & w : m_vWindows | std::views::reverse) {
1601
- if (w != pWindow && !gotToWindow)
1602
- continue ;
1668
+ PHLWINDOW CCompositor::getPrevVisibleWindow (PHLWINDOW pWindow, bool focusableOnly, std::optional<bool > floating) {
1669
+ // going through all windows in the workspace before current, from current
1670
+ for (auto it = std::find (m_vWindows.rbegin (), m_vWindows.rend (), pWindow); it != m_vWindows.rend (); ++it) {
1671
+ auto & w = *it;
1672
+ if ((!floating.has_value () || w->m_bIsFloating == floating.value ()) && w->m_bIsMapped && !w->isHidden () && (!focusableOnly || !w->m_sWindowData .noFocus .valueOrDefault ()))
1673
+ return w;
1674
+ }
1603
1675
1604
- if (w == pWindow) {
1605
- gotToWindow = true ;
1606
- continue ;
1607
- }
1676
+ if (const auto & w = getWindowOnAnotherMonitor (pWindow->m_iMonitorID , floating, true ); w && (!floating.has_value () || w->m_bIsFloating == floating.value ()) && w->m_bIsMapped && !w->isHidden () && (!focusableOnly || !w->m_sWindowData .noFocus .valueOrDefault ()))
1677
+ return w;
1678
+
1679
+
1680
+ // going through all windows in the workspace after current, from last
1681
+ for (auto & w : m_vWindows | std::views::reverse) {
1682
+ if (w == pWindow)
1683
+ return nullptr ;
1608
1684
1609
1685
if (floating.has_value () && w->m_bIsFloating != floating.value ())
1610
1686
continue ;
1611
1687
1612
- if (w->m_pWorkspace == pWindow-> m_pWorkspace && w-> m_bIsMapped && !w->isHidden () && (!focusableOnly || !w->m_sWindowData .noFocus .valueOrDefault ()))
1688
+ if (w->m_bIsMapped && !w->isHidden () && (!focusableOnly || !w->m_sWindowData .noFocus .valueOrDefault ()))
1613
1689
return w;
1614
1690
}
1615
1691
1616
- for (auto & w : m_vWindows | std::views::reverse) {
1617
- if (floating.has_value () && w->m_bIsFloating != floating.value ())
1692
+ return nullptr ;
1693
+ }
1694
+
1695
+ PHLWINDOW CCompositor::getWindowOnAnotherMonitor (uint64_t curMonID, std::optional<bool > floating, bool reverse) {
1696
+ auto monID = curMonID;
1697
+ for (auto mon = getNextMonitor (monID, reverse); mon->ID != monID; mon = getNextMonitor (monID, reverse)) {
1698
+ if (mon->activeWorkspace == nullptr ) {
1699
+ monID = mon->ID ;
1618
1700
continue ;
1701
+ }
1619
1702
1620
- if (w != pWindow && w-> m_pWorkspace == pWindow-> m_pWorkspace && w-> m_bIsMapped && !w-> isHidden () && (!focusableOnly || ! w->m_sWindowData . noFocus . valueOrDefault ()))
1703
+ if (const auto w = mon-> activeWorkspace -> getLastFocusedWindow (); w && (!floating. has_value () || floating. value () == w->m_bIsFloating )) {
1621
1704
return w;
1705
+ }
1622
1706
}
1623
1707
1624
1708
return nullptr ;
0 commit comments