VirtualDesktopManager: clean up API a bit

Using templates brings nothing except complexity here
remotes/origin/work/zamundaaa/ranges
Xaver Hugl 3 years ago
parent 147f3509ea
commit 681368d4cc
  1. 23
      autotests/test_virtual_desktops.cpp
  2. 4
      src/dbusinterface.cpp
  3. 8
      src/effects.cpp
  4. 20
      src/scripting/workspace_wrapper.cpp
  5. 6
      src/tabbox/tabbox.cpp
  6. 24
      src/useractions.cpp
  7. 59
      src/virtualdesktops.cpp
  8. 236
      src/virtualdesktops.h

@ -80,8 +80,7 @@ private Q_SLOTS:
private:
void addDirectionColumns();
template<typename T>
void testDirection(const QString &actionName);
void testDirection(const QString &actionName, VirtualDesktopManager::Direction direction);
};
void TestVirtualDesktops::init()
@ -266,8 +265,7 @@ void TestVirtualDesktops::addDirectionColumns()
QTest::addColumn<uint>("result");
}
template<typename T>
void TestVirtualDesktops::testDirection(const QString &actionName)
void TestVirtualDesktops::testDirection(const QString &actionName, VirtualDesktopManager::Direction direction)
{
VirtualDesktopManager *vds = VirtualDesktopManager::self();
QFETCH(uint, initCount);
@ -277,8 +275,7 @@ void TestVirtualDesktops::testDirection(const QString &actionName)
QFETCH(bool, wrap);
QFETCH(uint, result);
T functor;
QCOMPARE(functor(nullptr, wrap)->x11DesktopNumber(), result);
QCOMPARE(vds->inDirection(nullptr, direction, wrap)->x11DesktopNumber(), result);
vds->setNavigationWrappingAround(wrap);
vds->initShortcuts();
@ -286,7 +283,7 @@ void TestVirtualDesktops::testDirection(const QString &actionName)
QVERIFY(action);
action->trigger();
QCOMPARE(vds->current(), result);
QCOMPARE(functor(initCurrent, wrap), result);
QCOMPARE(vds->inDirection(initCurrent, direction, wrap), result);
}
void TestVirtualDesktops::next_data()
@ -303,7 +300,7 @@ void TestVirtualDesktops::next_data()
void TestVirtualDesktops::next()
{
testDirection<DesktopNext>(QStringLiteral("Switch to Next Desktop"));
testDirection(QStringLiteral("Switch to Next Desktop"), VirtualDesktopManager::Direction::Next);
}
void TestVirtualDesktops::previous_data()
@ -320,7 +317,7 @@ void TestVirtualDesktops::previous_data()
void TestVirtualDesktops::previous()
{
testDirection<DesktopPrevious>(QStringLiteral("Switch to Previous Desktop"));
testDirection(QStringLiteral("Switch to Previous Desktop"), VirtualDesktopManager::Direction::Previous);
}
void TestVirtualDesktops::left_data()
@ -345,7 +342,7 @@ void TestVirtualDesktops::left_data()
void TestVirtualDesktops::left()
{
testDirection<DesktopLeft>(QStringLiteral("Switch One Desktop to the Left"));
testDirection(QStringLiteral("Switch One Desktop to the Left"), VirtualDesktopManager::Direction::Left);
}
void TestVirtualDesktops::right_data()
@ -370,7 +367,7 @@ void TestVirtualDesktops::right_data()
void TestVirtualDesktops::right()
{
testDirection<DesktopRight>(QStringLiteral("Switch One Desktop to the Right"));
testDirection(QStringLiteral("Switch One Desktop to the Right"), VirtualDesktopManager::Direction::Right);
}
void TestVirtualDesktops::above_data()
@ -391,7 +388,7 @@ void TestVirtualDesktops::above_data()
void TestVirtualDesktops::above()
{
testDirection<DesktopAbove>(QStringLiteral("Switch One Desktop Up"));
testDirection(QStringLiteral("Switch One Desktop Up"), VirtualDesktopManager::Direction::Up);
}
void TestVirtualDesktops::below_data()
@ -412,7 +409,7 @@ void TestVirtualDesktops::below_data()
void TestVirtualDesktops::below()
{
testDirection<DesktopBelow>(QStringLiteral("Switch One Desktop Down"));
testDirection(QStringLiteral("Switch One Desktop Down"), VirtualDesktopManager::Direction::Down);
}
void TestVirtualDesktops::updateGrid_data()

@ -141,12 +141,12 @@ bool DBusInterface::setCurrentDesktop(int desktop)
void DBusInterface::nextDesktop()
{
VirtualDesktopManager::self()->moveTo<DesktopNext>();
VirtualDesktopManager::self()->moveTo(VirtualDesktopManager::Direction::Next);
}
void DBusInterface::previousDesktop()
{
VirtualDesktopManager::self()->moveTo<DesktopPrevious>();
VirtualDesktopManager::self()->moveTo(VirtualDesktopManager::Direction::Previous);
}
void DBusInterface::showDebugConsole()

@ -1075,22 +1075,22 @@ QPoint EffectsHandlerImpl::desktopCoords(int id) const
int EffectsHandlerImpl::desktopAbove(int desktop, bool wrap) const
{
return getDesktop<DesktopAbove>(desktop, wrap);
return VirtualDesktopManager::self()->inDirection(desktop, VirtualDesktopManager::Direction::Up, wrap);
}
int EffectsHandlerImpl::desktopToRight(int desktop, bool wrap) const
{
return getDesktop<DesktopRight>(desktop, wrap);
return VirtualDesktopManager::self()->inDirection(desktop, VirtualDesktopManager::Direction::Right, wrap);
}
int EffectsHandlerImpl::desktopBelow(int desktop, bool wrap) const
{
return getDesktop<DesktopBelow>(desktop, wrap);
return VirtualDesktopManager::self()->inDirection(desktop, VirtualDesktopManager::Direction::Down, wrap);
}
int EffectsHandlerImpl::desktopToLeft(int desktop, bool wrap) const
{
return getDesktop<DesktopLeft>(desktop, wrap);
return VirtualDesktopManager::self()->inDirection(desktop, VirtualDesktopManager::Direction::Left, wrap);
}
QString EffectsHandlerImpl::desktopName(int desktop) const

@ -223,18 +223,18 @@ SLOTWRAPPER(slotSwitchWindowLeft, DirectionWest)
#undef SLOTWRAPPER
#define SLOTWRAPPER(name, direction) \
void WorkspaceWrapper::name() \
{ \
VirtualDesktopManager::self()->moveTo<direction>(options->isRollOverDesktops()); \
#define SLOTWRAPPER(name, direction) \
void WorkspaceWrapper::name() \
{ \
VirtualDesktopManager::self()->moveTo(VirtualDesktopManager::Direction::direction, options->isRollOverDesktops()); \
}
SLOTWRAPPER(slotSwitchDesktopNext, DesktopNext)
SLOTWRAPPER(slotSwitchDesktopPrevious, DesktopPrevious)
SLOTWRAPPER(slotSwitchDesktopRight, DesktopRight)
SLOTWRAPPER(slotSwitchDesktopLeft, DesktopLeft)
SLOTWRAPPER(slotSwitchDesktopUp, DesktopAbove)
SLOTWRAPPER(slotSwitchDesktopDown, DesktopBelow)
SLOTWRAPPER(slotSwitchDesktopNext, Next)
SLOTWRAPPER(slotSwitchDesktopPrevious, Previous)
SLOTWRAPPER(slotSwitchDesktopRight, Right)
SLOTWRAPPER(slotSwitchDesktopLeft, Left)
SLOTWRAPPER(slotSwitchDesktopUp, Up)
SLOTWRAPPER(slotSwitchDesktopDown, Down)
#undef SLOTWRAPPER

@ -1476,14 +1476,12 @@ void TabBox::modifiersReleased()
int TabBox::nextDesktopStatic(int iDesktop) const
{
DesktopNext functor;
return functor(iDesktop, true);
return VirtualDesktopManager::self()->inDirection(iDesktop, VirtualDesktopManager::Direction::Next, true);
}
int TabBox::previousDesktopStatic(int iDesktop) const
{
DesktopPrevious functor;
return functor(iDesktop, true);
return VirtualDesktopManager::self()->inDirection(iDesktop, VirtualDesktopManager::Direction::Previous, true);
}
/**

@ -1525,14 +1525,12 @@ void Workspace::slotToggleShowDesktop()
setShowingDesktop(!showingDesktop());
}
template<typename Direction>
void windowToDesktop(Window *window)
void windowToDesktop(Window *window, VirtualDesktopManager::Direction direction)
{
VirtualDesktopManager *vds = VirtualDesktopManager::self();
Workspace *ws = Workspace::self();
Direction functor;
// TODO: why is options->isRollOverDesktops() not honored?
const auto desktop = functor(nullptr, true);
const auto desktop = vds->inDirection(nullptr, direction, true);
if (window && !window->isDesktop()
&& !window->isDock()) {
ws->setMoveResizeWindow(window);
@ -1553,7 +1551,7 @@ void Workspace::slotWindowToNextDesktop()
void Workspace::windowToNextDesktop(Window *window)
{
windowToDesktop<DesktopNext>(window);
windowToDesktop(window, VirtualDesktopManager::Direction::Next);
}
/**
@ -1568,17 +1566,15 @@ void Workspace::slotWindowToPreviousDesktop()
void Workspace::windowToPreviousDesktop(Window *window)
{
windowToDesktop<DesktopPrevious>(window);
windowToDesktop(window, VirtualDesktopManager::Direction::Previous);
}
template<typename Direction>
void activeWindowToDesktop()
void activeWindowToDesktop(VirtualDesktopManager::Direction direction)
{
VirtualDesktopManager *vds = VirtualDesktopManager::self();
Workspace *ws = Workspace::self();
VirtualDesktop *current = vds->currentDesktop();
Direction functor;
VirtualDesktop *newCurrent = functor(current, options->isRollOverDesktops());
VirtualDesktop *newCurrent = VirtualDesktopManager::self()->inDirection(current, direction, options->isRollOverDesktops());
if (newCurrent == current) {
return;
}
@ -1590,28 +1586,28 @@ void activeWindowToDesktop()
void Workspace::slotWindowToDesktopRight()
{
if (USABLE_ACTIVE_WINDOW) {
activeWindowToDesktop<DesktopRight>();
activeWindowToDesktop(VirtualDesktopManager::Direction::Right);
}
}
void Workspace::slotWindowToDesktopLeft()
{
if (USABLE_ACTIVE_WINDOW) {
activeWindowToDesktop<DesktopLeft>();
activeWindowToDesktop(VirtualDesktopManager::Direction::Left);
}
}
void Workspace::slotWindowToDesktopUp()
{
if (USABLE_ACTIVE_WINDOW) {
activeWindowToDesktop<DesktopAbove>();
activeWindowToDesktop(VirtualDesktopManager::Direction::Up);
}
}
void Workspace::slotWindowToDesktopDown()
{
if (USABLE_ACTIVE_WINDOW) {
activeWindowToDesktop<DesktopBelow>();
activeWindowToDesktop(VirtualDesktopManager::Direction::Down);
}
}

@ -240,10 +240,33 @@ void VirtualDesktopManager::setRootInfo(NETRootInfo *info)
}
}
uint VirtualDesktopManager::above(uint id, bool wrap) const
VirtualDesktop *VirtualDesktopManager::inDirection(VirtualDesktop *desktop, Direction direction, bool wrap)
{
auto vd = above(desktopForX11Id(id), wrap);
return vd ? vd->x11DesktopNumber() : 0;
switch (direction) {
case Direction::Up:
return above(desktop, wrap);
case Direction::Down:
return below(desktop, wrap);
case Direction::Right:
return toRight(desktop, wrap);
case Direction::Left:
return toLeft(desktop, wrap);
case Direction::Next:
return next(desktop, wrap);
case Direction::Previous:
return previous(desktop, wrap);
}
Q_UNREACHABLE();
}
uint VirtualDesktopManager::inDirection(uint desktop, Direction direction, bool wrap)
{
return inDirection(desktopForX11Id(desktop), direction, wrap)->x11DesktopNumber();
}
void VirtualDesktopManager::moveTo(Direction direction, bool wrap)
{
setCurrent(inDirection(nullptr, direction, wrap));
}
VirtualDesktop *VirtualDesktopManager::above(VirtualDesktop *desktop, bool wrap) const
@ -270,12 +293,6 @@ VirtualDesktop *VirtualDesktopManager::above(VirtualDesktop *desktop, bool wrap)
return nullptr;
}
uint VirtualDesktopManager::toRight(uint id, bool wrap) const
{
auto vd = toRight(desktopForX11Id(id), wrap);
return vd ? vd->x11DesktopNumber() : 0;
}
VirtualDesktop *VirtualDesktopManager::toRight(VirtualDesktop *desktop, bool wrap) const
{
Q_ASSERT(m_current);
@ -300,12 +317,6 @@ VirtualDesktop *VirtualDesktopManager::toRight(VirtualDesktop *desktop, bool wra
return nullptr;
}
uint VirtualDesktopManager::below(uint id, bool wrap) const
{
auto vd = below(desktopForX11Id(id), wrap);
return vd ? vd->x11DesktopNumber() : 0;
}
VirtualDesktop *VirtualDesktopManager::below(VirtualDesktop *desktop, bool wrap) const
{
Q_ASSERT(m_current);
@ -331,12 +342,6 @@ VirtualDesktop *VirtualDesktopManager::below(VirtualDesktop *desktop, bool wrap)
return nullptr;
}
uint VirtualDesktopManager::toLeft(uint id, bool wrap) const
{
auto vd = toLeft(desktopForX11Id(id), wrap);
return vd ? vd->x11DesktopNumber() : 0;
}
VirtualDesktop *VirtualDesktopManager::toLeft(VirtualDesktop *desktop, bool wrap) const
{
Q_ASSERT(m_current);
@ -950,32 +955,32 @@ void VirtualDesktopManager::setNavigationWrappingAround(bool enabled)
void VirtualDesktopManager::slotDown()
{
moveTo<DesktopBelow>(isNavigationWrappingAround());
moveTo(Direction::Down, isNavigationWrappingAround());
}
void VirtualDesktopManager::slotLeft()
{
moveTo<DesktopLeft>(isNavigationWrappingAround());
moveTo(Direction::Left, isNavigationWrappingAround());
}
void VirtualDesktopManager::slotPrevious()
{
moveTo<DesktopPrevious>(isNavigationWrappingAround());
moveTo(Direction::Previous, isNavigationWrappingAround());
}
void VirtualDesktopManager::slotNext()
{
moveTo<DesktopNext>(isNavigationWrappingAround());
moveTo(Direction::Next, isNavigationWrappingAround());
}
void VirtualDesktopManager::slotRight()
{
moveTo<DesktopRight>(isNavigationWrappingAround());
moveTo(Direction::Right, isNavigationWrappingAround());
}
void VirtualDesktopManager::slotUp()
{
moveTo<DesktopAbove>(isNavigationWrappingAround());
moveTo(Direction::Up, isNavigationWrappingAround());
}
} // KWin

@ -205,41 +205,33 @@ public:
*/
const VirtualDesktopGrid &grid() const;
/**
* @returns The ID of the desktop above desktop @a id. Wraps around to the bottom of
* the layout if @a wrap is set. If @a id is not set use the current one.
*/
uint above(uint id = 0, bool wrap = true) const;
enum class Direction {
Up,
Down,
Right,
Left,
Next,
Previous
};
VirtualDesktop *inDirection(VirtualDesktop *desktop, Direction direction, bool wrap = true);
uint inDirection(uint desktop, Direction direction, bool wrap = true);
void moveTo(Direction direction, bool wrap = true);
/**
* @returns The desktop above desktop @a desktop. Wraps around to the bottom of
* the layout if @a wrap is set. If @a desktop is @c null use the current one.
*/
VirtualDesktop *above(VirtualDesktop *desktop, bool wrap = true) const;
/**
* @returns The ID of the desktop to the right of desktop @a id. Wraps around to the
* left of the layout if @a wrap is set. If @a id is not set use the current one.
*/
uint toRight(uint id = 0, bool wrap = true) const;
/**
* @returns The desktop to the right of desktop @a desktop. Wraps around to the
* left of the layout if @a wrap is set. If @a desktop is @c null use the current one.
*/
VirtualDesktop *toRight(VirtualDesktop *desktop, bool wrap = true) const;
/**
* @returns The ID of the desktop below desktop @a id. Wraps around to the top of the
* layout if @a wrap is set. If @a id is not set use the current one.
*/
uint below(uint id = 0, bool wrap = true) const;
/**
* @returns The desktop below desktop @a desktop. Wraps around to the top of the
* layout if @a wrap is set. If @a desktop is @c null use the current one.
*/
VirtualDesktop *below(VirtualDesktop *desktop, bool wrap = true) const;
/**
* @returns The ID of the desktop to the left of desktop @a id. Wraps around to the
* right of the layout if @a wrap is set. If @a id is not set use the current one.
*/
uint toLeft(uint id = 0, bool wrap = true) const;
/**
* @returns The desktop to the left of desktop @a desktop. Wraps around to the
* right of the layout if @a wrap is set. If @a desktop is @c null use the current one.
@ -508,203 +500,6 @@ private:
KWIN_SINGLETON_VARIABLE(VirtualDesktopManager, s_manager)
};
/**
* Function object to select the desktop above in the layout.
* Note: does not switch to the desktop!
*/
class DesktopAbove
{
public:
DesktopAbove()
{
}
/**
* @param desktop The desktop from which the desktop above should be selected. If @c 0 the current desktop is used
* @param wrap Whether to wrap around if already topmost desktop
* @returns Id of the desktop above @p desktop
*/
uint operator()(uint desktop, bool wrap)
{
return (*this)(VirtualDesktopManager::self()->desktopForX11Id(desktop), wrap)->x11DesktopNumber();
}
/**
* @param desktop The desktop from which the desktop above should be selected. If @c 0 the current desktop is used
* @param wrap Whether to wrap around if already topmost desktop
* @returns the desktop above @p desktop
*/
VirtualDesktop *operator()(VirtualDesktop *desktop, bool wrap)
{
return VirtualDesktopManager::self()->above(desktop, wrap);
}
};
/**
* Function object to select the desktop below in the layout.
* Note: does not switch to the desktop!
*/
class DesktopBelow
{
public:
DesktopBelow()
{
}
/**
* @param desktop The desktop from which the desktop below should be selected. If @c 0 the current desktop is used
* @param wrap Whether to wrap around if already lowest desktop
* @returns Id of the desktop below @p desktop
*/
uint operator()(uint desktop, bool wrap)
{
return (*this)(VirtualDesktopManager::self()->desktopForX11Id(desktop), wrap)->x11DesktopNumber();
}
/**
* @param desktop The desktop from which the desktop below should be selected. If @c 0 the current desktop is used
* @param wrap Whether to wrap around if already lowest desktop
* @returns the desktop below @p desktop
*/
VirtualDesktop *operator()(VirtualDesktop *desktop, bool wrap)
{
return VirtualDesktopManager::self()->below(desktop, wrap);
}
};
/**
* Function object to select the desktop to the left in the layout.
* Note: does not switch to the desktop!
*/
class DesktopLeft
{
public:
DesktopLeft()
{
}
/**
* @param desktop The desktop from which the desktop on the left should be selected. If @c 0 the current desktop is used
* @param wrap Whether to wrap around if already leftmost desktop
* @returns Id of the desktop left of @p desktop
*/
uint operator()(uint desktop, bool wrap)
{
return (*this)(VirtualDesktopManager::self()->desktopForX11Id(desktop), wrap)->x11DesktopNumber();
}
/**
* @param desktop The desktop from which the desktop on the left should be selected. If @c 0 the current desktop is used
* @param wrap Whether to wrap around if already leftmost desktop
* @returns the desktop left of @p desktop
*/
VirtualDesktop *operator()(VirtualDesktop *desktop, bool wrap)
{
return VirtualDesktopManager::self()->toLeft(desktop, wrap);
}
};
/**
* Function object to select the desktop to the right in the layout.
* Note: does not switch to the desktop!
*/
class DesktopRight
{
public:
DesktopRight()
{
}
/**
* @param desktop The desktop from which the desktop on the right should be selected. If @c 0 the current desktop is used
* @param wrap Whether to wrap around if already rightmost desktop
* @returns Id of the desktop right of @p desktop
*/
uint operator()(uint desktop, bool wrap)
{
return (*this)(VirtualDesktopManager::self()->desktopForX11Id(desktop), wrap)->x11DesktopNumber();
}
/**
* @param desktop The desktop from which the desktop on the right should be selected. If @c 0 the current desktop is used
* @param wrap Whether to wrap around if already rightmost desktop
* @returns the desktop right of @p desktop
*/
VirtualDesktop *operator()(VirtualDesktop *desktop, bool wrap)
{
return VirtualDesktopManager::self()->toRight(desktop, wrap);
}
};
/**
* Function object to select the next desktop in the layout.
* Note: does not switch to the desktop!
*/
class DesktopNext
{
public:
DesktopNext()
{
}
/**
* @param desktop The desktop from which the next desktop should be selected. If @c 0 the current desktop is used
* @param wrap Whether to wrap around if already last desktop
* @returns Id of the next desktop
*/
uint operator()(uint desktop, bool wrap)
{
return (*this)(VirtualDesktopManager::self()->desktopForX11Id(desktop), wrap)->x11DesktopNumber();
}
/**
* @param desktop The desktop from which the next desktop should be selected. If @c 0 the current desktop is used
* @param wrap Whether to wrap around if already last desktop
* @returns the next desktop
*/
VirtualDesktop *operator()(VirtualDesktop *desktop, bool wrap)
{
return VirtualDesktopManager::self()->next(desktop, wrap);
}
};
/**
* Function object to select the previous desktop in the layout.
* Note: does not switch to the desktop!
*/
class DesktopPrevious
{
public:
DesktopPrevious()
{
}
/**
* @param desktop The desktop from which the previous desktop should be selected. If @c 0 the current desktop is used
* @param wrap Whether to wrap around if already first desktop
* @returns Id of the previous desktop
*/
uint operator()(uint desktop, bool wrap)
{
return (*this)(VirtualDesktopManager::self()->desktopForX11Id(desktop), wrap)->x11DesktopNumber();
}
/**
* @param desktop The desktop from which the previous desktop should be selected. If @c 0 the current desktop is used
* @param wrap Whether to wrap around if already first desktop
* @returns the previous desktop
*/
VirtualDesktop *operator()(VirtualDesktop *desktop, bool wrap)
{
return VirtualDesktopManager::self()->previous(desktop, wrap);
}
};
/**
* Helper function to get the ID of a virtual desktop in the direction from
* the given @p desktop. If @c 0 the current desktop is used as a starting point.
* @param desktop The desktop from which the desktop in given Direction should be selected.
* @param wrap Whether desktop navigation wraps around at the borders of the layout
* @returns The next desktop in specified direction
*/
template<typename Direction>
uint getDesktop(int desktop = 0, bool wrap = true);
template<typename Direction>
uint getDesktop(int d, bool wrap)
{
Direction direction;
return direction(d, wrap);
}
inline int VirtualDesktopGrid::width() const
{
return m_size.width();
@ -745,12 +540,5 @@ inline const VirtualDesktopGrid &VirtualDesktopManager::grid() const
return m_grid;
}
template<typename Direction>
void VirtualDesktopManager::moveTo(bool wrap)
{
Direction functor;
setCurrent(functor(nullptr, wrap));
}
} // namespace KWin
#endif

Loading…
Cancel
Save