Move ScreenEdge configuration from Workspace to ScreenEdge

Main motivation for this change except the fact that it doesn't belong
into Workspace is that the screen edges got updated from within setting
the desktop layout which got removed with the introduction of the
VirtualDesktopManager.

The ScreenEdge now keeps some state to be able to correctly unreserve the
electric borders when changes in the configuration are performed. There
is still room for improvement as there are still some deep function calls
from within reconfiguring in Workspace.

REVIEW: 107493
This commit is contained in:
Martin Gräßlin 2012-11-25 10:13:34 +01:00
parent 1d959dea64
commit 3ee9869ba0
4 changed files with 78 additions and 22 deletions

View file

@ -49,6 +49,8 @@ ScreenEdge::ScreenEdge()
: QObject(NULL)
, m_screenEdgeWindows(ELECTRIC_COUNT, None)
, m_screenEdgeReserved(ELECTRIC_COUNT, 0)
, m_virtualDesktopSwitching(Options::ElectricDisabled)
, m_virtualDesktopLayout(0)
{
}
@ -130,6 +132,52 @@ void ScreenEdge::restoreSize(ElectricBorder border)
xywh[border][0], xywh[border][1], xywh[border][2], xywh[border][3]);
}
void ScreenEdge::reconfigureVirtualDesktopSwitching()
{
const int newMode = options->electricBorders();
if (m_virtualDesktopSwitching == newMode) {
return;
}
if (m_virtualDesktopSwitching == Options::ElectricAlways) {
reserveDesktopSwitching(false, m_virtualDesktopLayout);
}
m_virtualDesktopSwitching = newMode;
if (m_virtualDesktopSwitching == Options::ElectricAlways) {
reserveDesktopSwitching(true, m_virtualDesktopLayout);
}
update();
}
void ScreenEdge::reconfigure()
{
reserveActions(true);
reconfigureVirtualDesktopSwitching();
updateLayout();
update();
}
void ScreenEdge::updateLayout()
{
const QSize desktopMatrix = VirtualDesktopManager::self()->grid().size();
Qt::Orientations newLayout = 0;
if (desktopMatrix.width() > 1) {
newLayout |= Qt::Horizontal;
}
if (desktopMatrix.height() > 1) {
newLayout |= Qt::Vertical;
}
if (newLayout == m_virtualDesktopLayout) {
return;
}
if (m_virtualDesktopSwitching == Options::ElectricAlways) {
reserveDesktopSwitching(false, m_virtualDesktopLayout);
}
m_virtualDesktopLayout = newLayout;
if (m_virtualDesktopSwitching == Options::ElectricAlways) {
reserveDesktopSwitching(true, m_virtualDesktopLayout);
}
}
void ScreenEdge::reserveActions(bool isToReserve)
{
for (int pos = 0; pos < ELECTRIC_COUNT; ++pos)
@ -255,11 +303,11 @@ void ScreenEdge::check(const QPoint& pos, Time now, bool forceNoPushback)
m_screenEdgeTimeLastTrigger = now;
if (Workspace::self()->getMovingClient()) {
// If moving a client or have force doing the desktop switch
if (options->electricBorders() != Options::ElectricDisabled)
if (m_virtualDesktopSwitching != Options::ElectricDisabled)
switchDesktop(border, pos);
return; // Don't reset cursor position
} else {
if (options->electricBorders() == Options::ElectricAlways &&
if (m_virtualDesktopSwitching == Options::ElectricAlways &&
(border == ElectricTop || border == ElectricRight ||
border == ElectricBottom || border == ElectricLeft)) {
// If desktop switching is always enabled don't apply it to the corners if
@ -290,7 +338,7 @@ void ScreenEdge::check(const QPoint& pos, Time now, bool forceNoPushback)
if (effects && static_cast<EffectsHandlerImpl*>(effects)->borderActivated(border))
{} // Handled by effects
else {
if (options->electricBorders() == Options::ElectricAlways) {
if (m_virtualDesktopSwitching == Options::ElectricAlways) {
switchDesktop(border, pos);
return; // Don't reset cursor position
}

View file

@ -114,6 +114,18 @@ public Q_SLOTS:
* actions or disabled desktop switching.
*/
void update(bool force=false);
/**
* Reconfigures the screen edges. That is reserves required borders.
**/
void reconfigure();
/**
* Reconfigures for virtual desktop switching, that is updates m_virtualDesktopSwitching.
**/
void reconfigureVirtualDesktopSwitching();
/**
* Updates the layout of virtual desktops, that is updates m_virtualDesktopLayout.
**/
void updateLayout();
Q_SIGNALS:
/**
* Emitted when the @p border got activated and there is neither an effect nor a global
@ -139,6 +151,18 @@ private:
Time m_screenEdgeTimeLast;
Time m_screenEdgeTimeLastTrigger;
QPoint m_screenEdgePushPoint;
/**
* The virtual desktop switching mode when hitting screen edges. Either:
* @li never enabled
* @li enabled when moving windows
* @li always enabled
**/
int m_virtualDesktopSwitching;
/**
* Used to know whether desktop switching at top/bottom or left/right borders is supported
* by the layout of virtual desktops.
**/
Qt::Orientations m_virtualDesktopLayout;
};
}
#endif // KWIN_SCREENEDGE_H

View file

@ -93,9 +93,6 @@ Workspace* Workspace::_self = 0;
Workspace::Workspace(bool restore)
: QObject(0)
#ifdef KWIN_BUILD_SCREENEDGES
, m_screenEdgeOrientation(0)
#endif
, m_compositor(NULL)
// Unsorted
, active_popup(NULL)
@ -255,6 +252,9 @@ void Workspace::init()
{
#ifdef KWIN_BUILD_SCREENEDGES
m_screenEdge.init();
connect(options, SIGNAL(configChanged()), &m_screenEdge, SLOT(reconfigure()));
connect(options, SIGNAL(electricBordersChanged()), &m_screenEdge, SLOT(reconfigureVirtualDesktopSwitching()));
connect(VirtualDesktopManager::self(), SIGNAL(layoutChanged(int,int)), &m_screenEdge, SLOT(updateLayout()));
#endif
supportWindow = new QWidget(NULL, Qt::X11BypassWindowManagerHint);
@ -997,8 +997,6 @@ void Workspace::slotReconfigure()
#ifdef KWIN_BUILD_SCREENEDGES
m_screenEdge.reserveActions(false);
if (options->electricBorders() == Options::ElectricAlways)
m_screenEdge.reserveDesktopSwitching(false, m_screenEdgeOrientation);
#endif
bool borderlessMaximizedWindows = options->borderlessMaximizedWindows();
@ -1033,19 +1031,6 @@ void Workspace::slotReconfigure()
c->triggerDecorationRepaint();
}
#ifdef KWIN_BUILD_SCREENEDGES
m_screenEdge.reserveActions(true);
if (options->electricBorders() == Options::ElectricAlways) {
QSize desktopMatrix = rootInfo->desktopLayoutColumnsRows();
m_screenEdgeOrientation = 0;
if (desktopMatrix.width() > 1)
m_screenEdgeOrientation |= Qt::Horizontal;
if (desktopMatrix.height() > 1)
m_screenEdgeOrientation |= Qt::Vertical;
m_screenEdge.reserveDesktopSwitching(true, m_screenEdgeOrientation);
}
m_screenEdge.update();
#endif
loadWindowRules();
for (ClientList::Iterator it = clients.begin();
it != clients.end();

View file

@ -218,7 +218,6 @@ private:
Outline* m_outline;
#ifdef KWIN_BUILD_SCREENEDGES
ScreenEdge m_screenEdge;
Qt::Orientations m_screenEdgeOrientation;
#endif
Compositor *m_compositor;