Refactoring Tiling

This initial commit introduces a new class Tiling. It is provided by
the files tiling/tiling.h and tiling/tiling.cpp. It covers all the
Tiling functionality which was provided by Workspace. In this initial
commit, all the functions were just moved and adjusted.
A  new member variable m_tiling is introduced to Workspace, which
makes the new class Tiling accessible from Workspace.
The Tiling pointer is created in the constructor and deleted in
the deconstructor. Also a getter method tiling() is provided.
All calls from other classes are updated to use the methods in class
Tiling now.
icc-effect-5.14.5
Arthur Arlt 2011-07-13 18:48:56 +02:00
parent 6db74c8d66
commit 3634525613
11 changed files with 283 additions and 192 deletions

View File

@ -42,6 +42,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "group.h"
#include "rules.h"
#include <QX11Info>
#include "tiling/tiling.h"
namespace KWin
{
@ -263,8 +264,8 @@ void Workspace::setActiveClient(Client* c, allowed_t)
active_client->sl_activated();
}
if (tilingEnabled())
notifyTilingWindowActivated(active_client);
if (m_tiling->tilingEnabled())
m_tiling->notifyTilingWindowActivated(active_client);
--set_active_client_recursion;
}

View File

@ -47,6 +47,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "notifications.h"
#include "rules.h"
#include "shadow.h"
#include "tiling/tiling.h"
#include "deleted.h"
#include "paintredirector.h"
#ifdef KWIN_BUILD_TABBOX
@ -951,7 +952,7 @@ void Client::minimize(bool avoid_animation)
emit clientMinimized(this, !avoid_animation);
// when tiling, request a rearrangement
workspace()->notifyTilingWindowMinimizeToggled(this);
workspace()->tiling()->notifyTilingWindowMinimizeToggled(this);
// Update states of all other windows in this group
if (clientGroup())
@ -978,11 +979,11 @@ void Client::unminimize(bool avoid_animation)
updateAllowedActions();
workspace()->updateMinimizedOfTransients(this);
updateWindowRules();
workspace()->updateAllTiles();
workspace()->tiling()->updateAllTiles();
emit clientUnminimized(this, !avoid_animation);
// when tiling, request a rearrangement
workspace()->notifyTilingWindowMinimizeToggled(this);
workspace()->tiling()->notifyTilingWindowMinimizeToggled(this);
// Update states of all other windows in this group
if (clientGroup())

View File

@ -50,6 +50,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <kephal/screens.h>
#include <KDE/KGlobalSettings>
#include "outline.h"
#include "tiling/tiling.h"
namespace KWin
{
@ -2032,7 +2033,7 @@ void Client::move(int x, int y, ForceGeometry_t force)
workspace()->checkActiveScreen(this);
workspace()->updateStackingOrder();
workspace()->checkUnredirect();
workspace()->notifyTilingWindowMove(this, moveResizeGeom, initialMoveResizeGeom);
workspace()->tiling()->notifyTilingWindowMove(this, moveResizeGeom, initialMoveResizeGeom);
// client itself is not damaged
const QRect deco_rect = decorationRect().translated(geom.x(), geom.y());
addWorkspaceRepaint(deco_rect_before_block);
@ -2590,11 +2591,11 @@ void Client::finishMoveResize(bool cancel)
leaveMoveResize();
if (workspace()->tilingEnabled()) {
if (workspace()->tiling()->tilingEnabled()) {
if (wasResize)
workspace()->notifyTilingWindowResizeDone(this, moveResizeGeom, initialMoveResizeGeom, cancel);
workspace()->tiling()->notifyTilingWindowResizeDone(this, moveResizeGeom, initialMoveResizeGeom, cancel);
else if (wasMove)
workspace()->notifyTilingWindowMoveDone(this, moveResizeGeom, initialMoveResizeGeom, cancel);
workspace()->tiling()->notifyTilingWindowMoveDone(this, moveResizeGeom, initialMoveResizeGeom, cancel);
} else {
if (cancel)
setGeometry(initialMoveResizeGeom);
@ -2763,8 +2764,8 @@ void Client::handleMoveResize(int x, int y, int x_root, int y_root)
bool update = false;
if (isResize()) {
// query layout for supported resize mode
if (workspace()->tilingEnabled()) {
mode = workspace()->supportedTilingResizeMode(this, mode);
if (workspace()->tiling()->tilingEnabled()) {
mode = workspace()->tiling()->supportedTilingResizeMode(this, mode);
}
// first resize (without checking constrains), then snap, then check bounds, then check constrains
QRect orig = initialMoveResizeGeom;
@ -2801,7 +2802,7 @@ void Client::handleMoveResize(int x, int y, int x_root, int y_root)
case PositionCenter:
// exception for tiling
// Center means no resizing allowed
if (workspace()->tilingEnabled()) {
if (workspace()->tiling()->tilingEnabled()) {
finishMoveResize(false);
buttonDown = false;
return;
@ -2810,7 +2811,7 @@ void Client::handleMoveResize(int x, int y, int x_root, int y_root)
abort();
break;
}
workspace()->notifyTilingWindowResize(this, moveResizeGeom, initialMoveResizeGeom);
workspace()->tiling()->notifyTilingWindowResize(this, moveResizeGeom, initialMoveResizeGeom);
// adjust new size to snap to other windows/borders
moveResizeGeom = workspace()->adjustClientSize(this, moveResizeGeom, mode);
@ -2968,7 +2969,7 @@ void Client::handleMoveResize(int x, int y, int x_root, int y_root)
performMoveResize();
if (isMove()) {
workspace()->notifyTilingWindowMove(this, moveResizeGeom, initialMoveResizeGeom);
workspace()->tiling()->notifyTilingWindowMove(this, moveResizeGeom, initialMoveResizeGeom);
#ifdef KWIN_BUILD_SCREENEDGES
workspace()->screenEdge()->check(globalPos, xTime());
#endif
@ -2986,7 +2987,7 @@ void Client::performMoveResize()
sendSyncRequest();
}
#endif
if (!workspace()->tilingEnabled())
if (!workspace()->tiling()->tilingEnabled())
setGeometry(moveResizeGeom);
positionGeometryTip();
emit clientStepUserMovedResized(this, moveResizeGeom);

9
sm.cpp
View File

@ -34,6 +34,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QSocketNotifier>
#include <QSessionManager>
#include <kdebug.h>
#include "tiling/tiling.h"
namespace KWin
{
@ -84,10 +85,10 @@ void Workspace::storeSession(KConfig* config, SMSavePhase phase)
int active_client = -1;
if (phase == SMSavePhase2 || phase == SMSavePhase2Full) {
cg.writeEntry("tiling", tilingEnabled());
if (tilingEnabled()) {
cg.writeEntry("tiling", m_tiling->tilingEnabled());
if (m_tiling->tilingEnabled()) {
kDebug(1212) << "Tiling was ON";
setTilingEnabled(false);
m_tiling->setTilingEnabled(false);
}
}
@ -273,7 +274,7 @@ void Workspace::loadSessionInfo()
session.clear();
KConfigGroup cg(kapp->sessionConfig(), "Session");
setTilingEnabled(cg.readEntry("tiling", false));
m_tiling->setTilingEnabled(cg.readEntry("tiling", false));
addSessionInfo(cg);
}

View File

@ -26,6 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "client.h"
#include "workspace.h"
#include "tiling/tiling.h"
namespace KWin
{
@ -95,7 +96,7 @@ void Tile::floatTile()
restorePreviousGeometry();
commit();
client()->workspace()->notifyTilingWindowActivated(client());
client()->workspace()->tiling()->notifyTilingWindowActivated(client());
// TODO: notify layout manager
}

View File

@ -3,6 +3,7 @@
This file is part of the KDE project.
Copyright (C) 2009 Nikhil Marathe <nsm.nikhil@gmail.com>
Copyright (C) 2011 Arthur Arlt <a.arlt@stud.uni-heidelberg.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -18,30 +19,36 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
// all the tiling related code that is extensions to existing KWin classes
// Includes Workspace for now
#include <tiling/tiling.h>
#include "client.h"
#include "workspace.h"
#include "tile.h"
#include "tilinglayout.h"
#include "tilinglayoutfactory.h"
#include <knotification.h>
#include <klocale.h>
#include <knotification.h>
#include <kwindowinfo.h>
#include <kwindowsystem.h>
#include "tile.h"
#include "tilinglayout.h"
#include "tilinglayoutfactory.h"
#include "workspace.h"
namespace KWin
namespace KWin {
Tiling::Tiling(KWin::Workspace* w)
: QObject(w)
, m_workspace(w)
, tilingEnabled_(false)
{
}
bool Workspace::tilingEnabled() const
Tiling::~Tiling()
{
}
bool Tiling::tilingEnabled() const
{
return tilingEnabled_;
}
void Workspace::setTilingEnabled(bool tiling)
void Tiling::setTilingEnabled(bool tiling)
{
if (tilingEnabled() == tiling) return;
@ -56,8 +63,8 @@ void Workspace::setTilingEnabled(bool tiling)
options->tilingRaisePolicy = config.readEntry("TilingRaisePolicy", 0);
if (tilingEnabled_) {
tilingLayouts.resize(numberOfDesktops() + 1);
foreach (Client * c, stackingOrder()) {
tilingLayouts.resize(Workspace::self()->numberOfDesktops() + 1);
foreach (Client * c, Workspace::self()->stackingOrder()) {
createTile(c);
}
} else {
@ -66,7 +73,7 @@ void Workspace::setTilingEnabled(bool tiling)
}
}
void Workspace::slotToggleTiling()
void Tiling::slotToggleTiling()
{
if (tilingEnabled()) {
setTilingEnabled(false);
@ -79,7 +86,7 @@ void Workspace::slotToggleTiling()
}
}
void Workspace::createTile(Client *c)
void Tiling::createTile(Client* c)
{
if (c == NULL)
return;
@ -90,28 +97,27 @@ void Workspace::createTile(Client *c)
if (!tilingEnabled() || !tileable(c))
return;
Tile *t = new Tile(c, clientArea(PlacementArea, c));
Tile *t = new Tile(c, Workspace::self()->clientArea(PlacementArea, c));
if (!tileable(c)) {
kDebug(1212) << c->caption() << "is not tileable";
t->floatTile();
}
if (!tilingLayouts.value(c->desktop())) {
tilingLayouts[c->desktop()] = TilingLayoutFactory::createLayout(TilingLayoutFactory::DefaultLayout, this);
tilingLayouts[c->desktop()] = TilingLayoutFactory::createLayout(TilingLayoutFactory::DefaultLayout, m_workspace);
}
tilingLayouts[c->desktop()]->addTile(t);
tilingLayouts[c->desktop()]->commit();
}
void Workspace::removeTile(Client *c)
void Tiling::removeTile(Client *c)
{
if (tilingLayouts[ c->desktop()])
tilingLayouts[ c->desktop()]->removeTile(c);
}
bool Workspace::tileable(Client *c)
bool Tiling::tileable(Client* c)
{
kDebug(1212) << c->caption();
KWindowInfo info = KWindowSystem::windowInfo(c->window(), -1U, NET::WM2WindowClass);
kDebug(1212) << "WINDOW CLASS IS " << info.windowClassClass();
@ -134,21 +140,21 @@ bool Workspace::tileable(Client *c)
return true;
}
void Workspace::belowCursor()
void Tiling::belowCursor()
{
// TODO
}
Tile* Workspace::getNiceTile() const
Tile* Tiling::getNiceTile() const
{
if (!tilingEnabled()) return NULL;
if (!tilingLayouts.value(activeClient()->desktop())) return NULL;
if (!tilingLayouts.value(m_workspace->activeClient()->desktop())) return NULL;
return tilingLayouts[ activeClient()->desktop()]->findTile(activeClient());
return tilingLayouts[ m_workspace->activeClient()->desktop()]->findTile(m_workspace->activeClient());
// TODO
}
void Workspace::updateAllTiles()
void Tiling::updateAllTiles()
{
foreach (TilingLayout * t, tilingLayouts) {
if (!t) continue;
@ -159,14 +165,14 @@ void Workspace::updateAllTiles()
/*
* Resize the neighbouring clients to close any gaps
*/
void Workspace::notifyTilingWindowResize(Client *c, const QRect &moveResizeGeom, const QRect &orig)
void Tiling::notifyTilingWindowResize(Client *c, const QRect &moveResizeGeom, const QRect &orig)
{
if (tilingLayouts.value(c->desktop()) == NULL)
return;
tilingLayouts[ c->desktop()]->clientResized(c, moveResizeGeom, orig);
}
void Workspace::notifyTilingWindowMove(Client *c, const QRect &moveResizeGeom, const QRect &orig)
void Tiling::notifyTilingWindowMove(Client *c, const QRect &moveResizeGeom, const QRect &orig)
{
if (tilingLayouts.value(c->desktop()) == NULL) {
return;
@ -175,7 +181,7 @@ void Workspace::notifyTilingWindowMove(Client *c, const QRect &moveResizeGeom, c
updateAllTiles();
}
void Workspace::notifyTilingWindowResizeDone(Client *c, const QRect &moveResizeGeom, const QRect &orig, bool canceled)
void Tiling::notifyTilingWindowResizeDone(Client *c, const QRect &moveResizeGeom, const QRect &orig, bool canceled)
{
if (canceled)
notifyTilingWindowResize(c, orig, moveResizeGeom);
@ -183,7 +189,7 @@ void Workspace::notifyTilingWindowResizeDone(Client *c, const QRect &moveResizeG
notifyTilingWindowResize(c, moveResizeGeom, orig);
}
void Workspace::notifyTilingWindowMoveDone(Client *c, const QRect &moveResizeGeom, const QRect &orig, bool canceled)
void Tiling::notifyTilingWindowMoveDone(Client *c, const QRect &moveResizeGeom, const QRect &orig, bool canceled)
{
if (canceled)
notifyTilingWindowMove(c, orig, moveResizeGeom);
@ -191,9 +197,9 @@ void Workspace::notifyTilingWindowMoveDone(Client *c, const QRect &moveResizeGeo
notifyTilingWindowMove(c, moveResizeGeom, orig);
}
void Workspace::notifyTilingWindowDesktopChanged(Client *c, int old_desktop)
void Tiling::notifyTilingWindowDesktopChanged(Client *c, int old_desktop)
{
if (c->desktop() < 1 || c->desktop() > numberOfDesktops())
if (c->desktop() < 1 || c->desktop() > m_workspace->numberOfDesktops())
return;
if (tilingLayouts.value(old_desktop)) {
@ -201,7 +207,7 @@ void Workspace::notifyTilingWindowDesktopChanged(Client *c, int old_desktop)
// TODO: copied from createTile(), move this into separate method?
if (!tilingLayouts.value(c->desktop())) {
tilingLayouts[c->desktop()] = TilingLayoutFactory::createLayout(TilingLayoutFactory::DefaultLayout, this);
tilingLayouts[c->desktop()] = TilingLayoutFactory::createLayout(TilingLayoutFactory::DefaultLayout, m_workspace);
}
if (t)
@ -215,7 +221,7 @@ void Workspace::notifyTilingWindowDesktopChanged(Client *c, int old_desktop)
/*
* Implements the 3 raising modes in Window Behaviour -> Advanced
*/
void Workspace::notifyTilingWindowActivated(Client *c)
void Tiling::notifyTilingWindowActivated(Client *c)
{
if (c == NULL)
return;
@ -226,7 +232,7 @@ void Workspace::notifyTilingWindowActivated(Client *c)
if (tilingLayouts.value(c->desktop())) {
QList<Tile *> tiles = tilingLayouts[ c->desktop()]->tiles();
StackingUpdatesBlocker blocker(this);
StackingUpdatesBlocker blocker(m_workspace);
Tile *tile_to_raise = tilingLayouts[ c->desktop()]->findTile(c);
@ -243,24 +249,24 @@ void Workspace::notifyTilingWindowActivated(Client *c)
foreach (Tile * t, tiles) {
if (t->floating() == raise_floating && t != tile_to_raise)
raiseClient(t->client());
m_workspace->raiseClient(t->client());
}
// raise the current tile last so that it ends up on top
// but only if it supposed to be raised, required to support tilingRaisePolicy
kDebug(1212) << "Raise floating? " << raise_floating << "to raise is floating?" << tile_to_raise->floating();
if (tile_to_raise->floating() == raise_floating)
raiseClient(tile_to_raise->client());
m_workspace->raiseClient(tile_to_raise->client());
}
}
void Workspace::notifyTilingWindowMinimizeToggled(Client *c)
void Tiling::notifyTilingWindowMinimizeToggled(Client *c)
{
if (tilingLayouts.value(c->desktop())) {
tilingLayouts[ c->desktop()]->clientMinimizeToggled(c);
}
}
void Workspace::notifyTilingWindowMaximized(Client *c, Options::WindowOperation op)
void Tiling::notifyTilingWindowMaximized(Client *c, Options::WindowOperation op)
{
if (tilingLayouts.value(c->desktop())) {
Tile *t = tilingLayouts[ c->desktop()]->findTile(c);
@ -291,7 +297,7 @@ void Workspace::notifyTilingWindowMaximized(Client *c, Options::WindowOperation
}
}
Tile* Workspace::findAdjacentTile(Tile *ref, int d)
Tile* Tiling::findAdjacentTile(Tile *ref, int d)
{
QRect reference = ref->geometry();
QPoint origin = reference.center();
@ -346,17 +352,17 @@ Tile* Workspace::findAdjacentTile(Tile *ref, int d)
return closest;
}
void Workspace::focusTile(int d)
void Tiling::focusTile(int d)
{
Tile *t = getNiceTile();
if (t) {
Tile *adj = findAdjacentTile(t, d);
if (adj)
activateClient(adj->client());
m_workspace->activateClient(adj->client());
}
}
void Workspace::moveTile(int d)
void Tiling::moveTile(int d)
{
Tile *t = getNiceTile();
if (t) {
@ -366,75 +372,75 @@ void Workspace::moveTile(int d)
}
}
void Workspace::slotFocusTileLeft()
void Tiling::slotFocusTileLeft()
{
focusTile(Tile::Left);
}
void Workspace::slotFocusTileRight()
void Tiling::slotFocusTileRight()
{
focusTile(Tile::Right);
}
void Workspace::slotFocusTileTop()
void Tiling::slotFocusTileTop()
{
focusTile(Tile::Top);
}
void Workspace::slotFocusTileBottom()
void Tiling::slotFocusTileBottom()
{
focusTile(Tile::Bottom);
}
void Workspace::slotMoveTileLeft()
void Tiling::slotMoveTileLeft()
{
moveTile(Tile::Left);
}
void Workspace::slotMoveTileRight()
void Tiling::slotMoveTileRight()
{
moveTile(Tile::Right);
}
void Workspace::slotMoveTileTop()
void Tiling::slotMoveTileTop()
{
moveTile(Tile::Top);
}
void Workspace::slotMoveTileBottom()
void Tiling::slotMoveTileBottom()
{
moveTile(Tile::Bottom);
}
void Workspace::slotToggleFloating()
void Tiling::slotToggleFloating()
{
Client *c = activeClient();
Client *c = m_workspace->activeClient();
if (tilingLayouts.value(c->desktop())) {
tilingLayouts[ c->desktop()]->toggleFloatTile(c);
}
}
void Workspace::slotNextTileLayout()
void Tiling::slotNextTileLayout()
{
if (tilingLayouts.value(currentDesktop())) {
if (tilingLayouts.value(m_workspace->currentDesktop())) {
tilingLayouts.replace(currentDesktop(), TilingLayoutFactory::nextLayout(tilingLayouts[currentDesktop()]));
tilingLayouts.replace(m_workspace->currentDesktop(), TilingLayoutFactory::nextLayout(tilingLayouts[m_workspace->currentDesktop()]));
tilingLayouts[currentDesktop()]->commit();
tilingLayouts[m_workspace->currentDesktop()]->commit();
}
}
void Workspace::slotPreviousTileLayout()
void Tiling::slotPreviousTileLayout()
{
if (tilingLayouts.value(currentDesktop())) {
if (tilingLayouts.value(m_workspace->currentDesktop())) {
tilingLayouts.replace(currentDesktop(), TilingLayoutFactory::previousLayout(tilingLayouts[currentDesktop()]));
tilingLayouts.replace(m_workspace->currentDesktop(), TilingLayoutFactory::previousLayout(tilingLayouts[m_workspace->currentDesktop()]));
tilingLayouts[currentDesktop()]->commit();
tilingLayouts[m_workspace->currentDesktop()]->commit();
}
}
KDecorationDefines::Position Workspace::supportedTilingResizeMode(Client *c, KDecorationDefines::Position currentMode)
KDecorationDefines::Position Tiling::supportedTilingResizeMode(Client *c, KDecorationDefines::Position currentMode)
{
if (tilingLayouts.value(c->desktop())) {
return tilingLayouts[c->desktop()]->resizeMode(c, currentMode);
@ -442,7 +448,7 @@ KDecorationDefines::Position Workspace::supportedTilingResizeMode(Client *c, KDe
return currentMode;
}
void Workspace::dumpTiles() const
void Tiling::dumpTiles() const
{
foreach (TilingLayout * t, tilingLayouts) {
if (!t) {
@ -455,5 +461,10 @@ void Workspace::dumpTiles() const
}
}
}
} // namespace
QVector< TilingLayout* >& Tiling::getTilingLayouts()
{
return tilingLayouts;
}
}

108
tiling/tiling.h Normal file
View File

@ -0,0 +1,108 @@
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2009 Nikhil Marathe <nsm.nikhil@gmail.com>
Copyright (C) 2011 Arthur Arlt <a.arlt@stud.uni-heidelberg.de>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef KWIN_TILING_H
#define KWIN_TILING_H
#include <kdecoration.h>
#include "client.h"
#include <QtCore/QVector>
namespace KWin {
class Tile;
class TilingLayout;
class Tiling : public QObject {
Q_OBJECT
public:
Tiling(Workspace *w);
~Tiling();
bool tilingEnabled() const;
void setTilingEnabled(bool tiling);
bool tileable(Client *c);
void createTile(Client *c);
void removeTile(Client *c);
// updates geometry of tiles on all desktops,
// this rearranges the tiles.
void updateAllTiles();
QVector< TilingLayout* >& getTilingLayouts();
// The notification functions are called from
// various points in existing code so that
// tiling can take any action if required.
// They are defined in tiling.cpp
void notifyTilingWindowResize(Client *c, const QRect &moveResizeGeom, const QRect &orig);
void notifyTilingWindowMove(Client *c, const QRect &moveResizeGeom, const QRect &orig);
void notifyTilingWindowResizeDone(Client *c, const QRect &moveResizeGeom, const QRect &orig, bool canceled);
void notifyTilingWindowMoveDone(Client *c, const QRect &moveResizeGeom, const QRect &orig, bool canceled);
void notifyTilingWindowDesktopChanged(Client *c, int old_desktop);
void notifyTilingWindowActivated(Client *c);
void notifyTilingWindowMinimizeToggled(Client *c);
void notifyTilingWindowMaximized(Client *c, KDecorationDefines::WindowOperation op);
KDecorationDefines::Position supportedTilingResizeMode(Client *c, KDecorationDefines::Position currentMode);
public Q_SLOTS:
// user actions, usually bound to shortcuts
// and also provided through the D-BUS interface.
void slotToggleTiling();
void slotToggleFloating();
void slotNextTileLayout();
void slotPreviousTileLayout();
// Changes the focused client
void slotFocusTileLeft();
void slotFocusTileRight();
void slotFocusTileTop();
void slotFocusTileBottom();
// swaps active and adjacent client.
void slotMoveTileLeft();
void slotMoveTileRight();
void slotMoveTileTop();
void slotMoveTileBottom();
void belowCursor();
// NOTE: debug method
void dumpTiles() const;
private:
// try to get a decent tile, either the one with
// focus or the one below the mouse.
Tile* getNiceTile() const;
// int, and not Tile::Direction because
// we are using a forward declaration for Tile
Tile* findAdjacentTile(Tile *ref, int d);
void focusTile(int d);
void moveTile(int d);
Workspace* m_workspace;
bool tilingEnabled_;
// Each tilingLayout is for one virtual desktop.
// The length is always one more than the number of
// virtual desktops so that we can quickly index them
// without having to remember to subtract one.
QVector<TilingLayout *> tilingLayouts;
};
}
#endif // KWIN_TILING_H

View File

@ -25,6 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "client.h"
#include "tile.h"
#include "workspace.h"
#include "tiling/tiling.h"
namespace KWin
{
@ -194,7 +195,7 @@ void TilingLayout::reconfigureTiling()
foreach (Client * c, workspace()->stackingOrder()) {
if (c->rules()->checkTilingOption(0) == 1)
workspace()->createTile(c);
workspace()->tiling()->createTile(c);
}
}

View File

@ -32,6 +32,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "effects.h"
#include "tile.h"
#include "tilinglayout.h"
#include "tiling/tiling.h"
#include "kactivityinfo.h"
@ -198,7 +199,7 @@ QMenu* Workspace::clientPopup()
// then hide it
mTilingStateOpAction->setVisible(false);
// actions for window tiling
if (tilingEnabled()) {
if (m_tiling->tilingEnabled()) {
kaction = qobject_cast<KAction*>(keys->action("Toggle Floating"));
mTilingStateOpAction->setCheckable(true);
mTilingStateOpAction->setData(Options::ToggleClientTiledStateOp);
@ -289,15 +290,15 @@ void Workspace::clientPopupAboutToShow()
mMinimizeOpAction->setEnabled(active_popup_client->isMinimizable());
mCloseOpAction->setEnabled(active_popup_client->isCloseable());
if (tilingEnabled()) {
if (m_tiling->tilingEnabled()) {
int desktop = active_popup_client->desktop();
if (tilingLayouts.value(desktop)) {
Tile *t = tilingLayouts[desktop]->findTile(active_popup_client);
if (m_tiling->getTilingLayouts().value(desktop)) {
Tile *t = m_tiling->getTilingLayouts()[desktop]->findTile(active_popup_client);
if (t)
mTilingStateOpAction->setChecked(t->floating());
}
}
mTilingStateOpAction->setVisible(tilingEnabled());
mTilingStateOpAction->setVisible(m_tiling->tilingEnabled());
delete switch_to_tab_popup;
switch_to_tab_popup = 0;
@ -661,12 +662,12 @@ void Workspace::performWindowOperation(Client* c, Options::WindowOperation op)
return;
// Allows us to float a window when it is maximized, if it is tiled.
if (tilingEnabled()
if (m_tiling->tilingEnabled()
&& (op == Options::MaximizeOp
|| op == Options::HMaximizeOp
|| op == Options::VMaximizeOp
|| op == Options::RestoreOp)) {
notifyTilingWindowMaximized(c, op);
m_tiling->notifyTilingWindowMaximized(c, op);
}
if (op == Options::MoveOp || op == Options::UnrestrictedMoveOp)
@ -780,8 +781,8 @@ void Workspace::performWindowOperation(Client* c, Options::WindowOperation op)
c->clientGroup()->closeAll();
case Options::ToggleClientTiledStateOp: {
int desktop = c->desktop();
if (tilingLayouts.value(desktop)) {
tilingLayouts[desktop]->toggleFloatTile(c);
if (m_tiling->getTilingLayouts().value(desktop)) {
m_tiling->getTilingLayouts()[desktop]->toggleFloatTile(c);
}
}
}

View File

@ -63,6 +63,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "effects.h"
#include "overlaywindow.h"
#include "tilinglayout.h"
#include "tiling/tiling.h"
#ifdef KWIN_BUILD_SCRIPTING
#include "scripting/scripting.h"
@ -107,7 +108,6 @@ Workspace::Workspace(bool restore)
, desktopGridSize_(1, 2) // Default to two rows
, desktopGrid_(new int[2])
, currentDesktop_(0)
, tilingEnabled_(false)
// Unsorted
, active_popup(NULL)
, active_popup_client(NULL)
@ -235,11 +235,14 @@ Workspace::Workspace(bool restore)
);
client_keys = new KActionCollection(this);
initShortcuts();
#ifdef KWIN_BUILD_DESKTOPCHANGEOSD
desktop_change_osd = new DesktopChangeOSD(this);
#endif
m_outline = new Outline();
m_tiling = new Tiling(this);
initShortcuts();
init();
@ -488,7 +491,7 @@ void Workspace::init()
activateClient(new_active_client);
// Enable/disable tiling
setTilingEnabled(options->tilingOn);
m_tiling->setTilingEnabled(options->tilingOn);
// SELI TODO: This won't work with unreasonable focus policies,
// and maybe in rare cases also if the selected client doesn't
@ -525,6 +528,7 @@ Workspace::~Workspace()
delete desktop_change_osd;
#endif
delete m_outline;
delete m_tiling;
discardPopup();
XDeleteProperty(display(), rootWindow(), atoms->kwin_running);
@ -562,9 +566,9 @@ Client* Workspace::createClient(Window w, bool is_mapped)
}
addClient(c, Allowed);
tilingLayouts.resize(numberOfDesktops() + 1);
m_tiling->getTilingLayouts().resize(numberOfDesktops() + 1);
m_tiling->createTile(c);
createTile(c);
return c;
}
@ -668,8 +672,8 @@ void Workspace::removeClient(Client* c, allowed_t)
#endif
Q_ASSERT(clients.contains(c) || desktops.contains(c));
if (tilingEnabled() && tilingLayouts.value(c->desktop())) {
removeTile(c);
if (m_tiling->tilingEnabled() && m_tiling->getTilingLayouts().value(c->desktop())) {
m_tiling->removeTile(c);
}
// TODO: if marked client is removed, notify the marked list
clients.removeAll(c);
@ -1027,13 +1031,13 @@ void Workspace::slotReconfigure()
}
}
setTilingEnabled(options->tilingOn);
foreach (TilingLayout * layout, tilingLayouts) {
m_tiling->setTilingEnabled(options->tilingOn);
foreach (TilingLayout * layout, m_tiling->getTilingLayouts()) {
if (layout)
layout->reconfigureTiling();
}
// just so that we reset windows in the right manner, 'activate' the current active window
notifyTilingWindowActivated(activeClient());
m_tiling->notifyTilingWindowActivated(activeClient());
if (hasDecorationPlugin()) {
rootInfo->setSupported(NET::WM2FrameOverlap, mgr->factory()->supports(AbilityExtendIntoClientArea));
} else {
@ -1296,8 +1300,8 @@ bool Workspace::setCurrentDesktop(int new_desktop)
if (movingClient && !movingClient->isOnDesktop(new_desktop)) {
int old_desktop = movingClient->desktop();
movingClient->setDesktop(new_desktop);
if (tilingEnabled()) {
notifyTilingWindowDesktopChanged(movingClient, old_desktop);
if (m_tiling->tilingEnabled()) {
m_tiling->notifyTilingWindowDesktopChanged(movingClient, old_desktop);
}
}
@ -1577,7 +1581,7 @@ void Workspace::setNumberOfDesktops(int n)
for (int i = 0; i < int(desktop_focus_chain.size()); i++)
desktop_focus_chain[i] = i + 1;
tilingLayouts.resize(numberOfDesktops() + 1);
m_tiling->getTilingLayouts().resize(numberOfDesktops() + 1);
saveDesktopSettings();
emit numberDesktopsChanged(old_number_of_desktops);
@ -1611,7 +1615,7 @@ void Workspace::sendClientToDesktop(Client* c, int desk, bool dont_activate)
} else
raiseClient(c);
notifyTilingWindowDesktopChanged(c, old_desktop);
m_tiling->notifyTilingWindowDesktopChanged(c, old_desktop);
ClientList transients_stacking_order = ensureStackingOrder(c->transients());
for (ClientList::ConstIterator it = transients_stacking_order.constBegin();
@ -2151,6 +2155,47 @@ TabBox::TabBox* Workspace::tabBox() const
}
#endif
Tiling* Workspace::tiling()
{
return m_tiling;
}
/*
* Called from D-BUS
*/
void Workspace::toggleTiling()
{
if (m_tiling) {
m_tiling->slotToggleTiling();
}
}
/*
* Called from D-BUS
*/
void Workspace::nextTileLayout()
{
if (m_tiling) {
m_tiling->slotNextTileLayout();
}
}
/*
* Called from D-BUS
*/
void Workspace::previousTileLayout()
{
if (m_tiling) {
m_tiling->slotPreviousTileLayout();
}
}
void Workspace::dumpTiles() const {
if (m_tiling) {
m_tiling->dumpTiles();
}
}
} // namespace
#include "workspace.moc"

View File

@ -74,6 +74,7 @@ class TabBox;
class Client;
class Tile;
class Tiling;
class TilingLayout;
class ClientGroup;
#ifdef KWIN_BUILD_DESKTOPCHANGEOSD
@ -197,31 +198,7 @@ public:
return unmanaged;
}
//-------------------------------------------------
// Tiling
public:
bool tilingEnabled() const;
void setTilingEnabled(bool tiling);
bool tileable(Client *c);
void createTile(Client *c);
// updates geometry of tiles on all desktops,
// this rearranges the tiles.
void updateAllTiles();
// The notification functions are called from
// various points in existing code so that
// tiling can take any action if required.
// They are defined in tiling.cpp
void notifyTilingWindowResize(Client *c, const QRect &moveResizeGeom, const QRect &orig);
void notifyTilingWindowMove(Client *c, const QRect &moveResizeGeom, const QRect &orig);
void notifyTilingWindowResizeDone(Client *c, const QRect &moveResizeGeom, const QRect &orig, bool canceled);
void notifyTilingWindowMoveDone(Client *c, const QRect &moveResizeGeom, const QRect &orig, bool canceled);
void notifyTilingWindowDesktopChanged(Client *c, int old_desktop);
void notifyTilingWindowActivated(Client *c);
void notifyTilingWindowMinimizeToggled(Client *c);
void notifyTilingWindowMaximized(Client *c, WindowOperation op);
Position supportedTilingResizeMode(Client *c, Position currentMode);
Tiling* tiling();
Outline* outline();
#ifdef KWIN_BUILD_SCREENEDGES
@ -329,14 +306,10 @@ private:
KActivityController activityController_;
bool tilingEnabled_;
// Each tilingLayout is for one virtual desktop.
// The length is always one more than the number of
// virtual desktops so that we can quickly index them
// without having to remember to subtract one.
QVector<TilingLayout *> tilingLayouts;
Tiling* m_tiling;
Outline* m_outline;
#ifdef KWIN_BUILD_SCREENEDGES
ScreenEdge m_screenEdge;
#endif
@ -640,25 +613,6 @@ public slots:
void suspendCompositing();
void suspendCompositing(bool suspend);
// user actions, usually bound to shortcuts
// and also provided through the D-BUS interface.
void slotToggleTiling();
void slotToggleFloating();
void slotNextTileLayout();
void slotPreviousTileLayout();
// Changes the focused client
void slotFocusTileLeft();
void slotFocusTileRight();
void slotFocusTileTop();
void slotFocusTileBottom();
// swaps active and adjacent client.
void slotMoveTileLeft();
void slotMoveTileRight();
void slotMoveTileTop();
void slotMoveTileBottom();
void belowCursor();
// NOTE: debug method
void dumpTiles() const;
@ -805,16 +759,6 @@ private:
static NET::WindowType txtToWindowType(const char* txt);
static bool sessionInfoWindowTypeMatch(Client* c, SessionInfo* info);
// try to get a decent tile, either the one with
// focus or the one below the mouse.
Tile* getNiceTile() const;
void removeTile(Client *c);
// int, and not Tile::Direction because
// we are using a forward declaration for Tile
Tile* findAdjacentTile(Tile *ref, int d);
void focusTile(int d);
void moveTile(int d);
Client* active_client;
Client* last_active_client;
Client* most_recently_raised; // Used ONLY by raiseOrLowerClient()
@ -1263,30 +1207,6 @@ inline void Workspace::removeClientGroup(ClientGroup* group)
clientGroups.removeAll(group);
}
/*
* Called from D-BUS
*/
inline void Workspace::toggleTiling()
{
slotToggleTiling();
}
/*
* Called from D-BUS
*/
inline void Workspace::nextTileLayout()
{
slotNextTileLayout();
}
/*
* Called from D-BUS
*/
inline void Workspace::previousTileLayout()
{
slotPreviousTileLayout();
}
} // namespace
#endif