Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 64da6c8d authored by Martin Flöser's avatar Martin Flöser

Replace Workspace::slotWindowQuickTileFoo by a quickTileWindow with argument

Summary:
Thanks to std::bind we don't need that many different slots to setup the
global shortcut connections. Instead we can have one shared
implementation which takes the argument and passes it to the window.

To support std::bind arguments in kwinbindings the initShortcut method
and dependencies are adjusted as well as a new macro is added.

As I don't want to include abstract_client.h in workspace.h a new enum
is created for the quick tiling flags used in Workspace. This caused a
larger refactoring as the change to an enum class also caused quite some
changes.

Test Plan: Affected test cases still pass

Reviewers: #kwin, #plasma

Subscribers: plasma-devel, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D6783
parent f1454048
......@@ -1281,7 +1281,7 @@ void AbstractClient::doResizeSync()
void AbstractClient::checkQuickTilingMaximizationZones(int xroot, int yroot)
{
QuickTileMode mode = QuickTileNone;
QuickTileMode mode = QuickTileFlag::None;
bool innerBorder = false;
for (int i=0; i < screens()->count(); ++i) {
......@@ -1302,21 +1302,21 @@ void AbstractClient::checkQuickTilingMaximizationZones(int xroot, int yroot)
QRect area = workspace()->clientArea(MaximizeArea, QPoint(xroot, yroot), desktop());
if (options->electricBorderTiling()) {
if (xroot <= area.x() + 20) {
mode |= QuickTileLeft;
mode |= QuickTileFlag::Left;
innerBorder = isInScreen(QPoint(area.x() - 1, yroot));
} else if (xroot >= area.x() + area.width() - 20) {
mode |= QuickTileRight;
mode |= QuickTileFlag::Right;
innerBorder = isInScreen(QPoint(area.right() + 1, yroot));
}
}
if (mode != QuickTileNone) {
if (mode != QuickTileMode(QuickTileFlag::None)) {
if (yroot <= area.y() + area.height() * options->electricBorderCornerRatio())
mode |= QuickTileTop;
mode |= QuickTileFlag::Top;
else if (yroot >= area.y() + area.height() - area.height() * options->electricBorderCornerRatio())
mode |= QuickTileBottom;
mode |= QuickTileFlag::Bottom;
} else if (options->electricBorderMaximize() && yroot <= area.y() + 5 && isMaximizable()) {
mode = QuickTileMaximize;
mode = QuickTileFlag::Maximize;
innerBorder = isInScreen(QPoint(xroot, area.y() - 1));
}
break; // no point in checking other screens to contain this... "point"...
......@@ -1330,12 +1330,12 @@ void AbstractClient::checkQuickTilingMaximizationZones(int xroot, int yroot)
m_electricMaximizingDelay->setSingleShot(true);
connect(m_electricMaximizingDelay, &QTimer::timeout, [this]() {
if (isMove())
setElectricBorderMaximizing(electricBorderMode() != QuickTileNone);
setElectricBorderMaximizing(electricBorderMode() != QuickTileMode(QuickTileFlag::None));
});
}
m_electricMaximizingDelay->start();
} else {
setElectricBorderMaximizing(mode != QuickTileNone);
setElectricBorderMaximizing(mode != QuickTileMode(QuickTileFlag::None));
}
}
}
......
......@@ -498,17 +498,6 @@ public:
// a helper for the workspace window packing. tests for screen validity and updates since in maximization case as with normal moving
void packTo(int left, int top);
enum QuickTileFlag {
QuickTileNone = 0,
QuickTileLeft = 1,
QuickTileRight = 1<<1,
QuickTileTop = 1<<2,
QuickTileBottom = 1<<3,
QuickTileHorizontal = QuickTileLeft|QuickTileRight,
QuickTileVertical = QuickTileTop|QuickTileBottom,
QuickTileMaximize = QuickTileLeft|QuickTileRight|QuickTileTop|QuickTileBottom
};
Q_DECLARE_FLAGS(QuickTileMode, QuickTileFlag)
/** Set the quick tile mode ("snap") of this window.
* This will also handle preserving and restoring of window geometry as necessary.
* @param mode The tile mode (left/right) to give this window.
......@@ -1028,11 +1017,11 @@ private:
Layer m_layer = UnknownLayer;
// electric border/quick tiling
QuickTileMode m_electricMode = QuickTileNone;
QuickTileMode m_electricMode = QuickTileFlag::None;
bool m_electricMaximizing = false;
/** The quick tile mode of this window.
*/
int m_quickTileMode = QuickTileNone;
int m_quickTileMode = int(QuickTileFlag::None);
QTimer *m_electricMaximizingDelay = nullptr;
// geometry
......@@ -1141,6 +1130,5 @@ inline void AbstractClient::setPendingGeometryUpdate(PendingGeometry_t update)
Q_DECLARE_METATYPE(KWin::AbstractClient*)
Q_DECLARE_METATYPE(QList<KWin::AbstractClient*>)
Q_DECLARE_OPERATORS_FOR_FLAGS(KWin::AbstractClient::QuickTileMode)
#endif
......@@ -41,7 +41,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <linux/input.h>
#include <xcb/xcb_icccm.h>
Q_DECLARE_METATYPE(KWin::AbstractClient::QuickTileMode)
Q_DECLARE_METATYPE(KWin::QuickTileMode)
Q_DECLARE_METATYPE(KWin::MaximizeMode)
namespace KWin
......
This diff is collapsed.
......@@ -1585,9 +1585,9 @@ bool Client::untab(const QRect &toGeometry, bool clientRemoved)
setClientShown(!(isMinimized() || isShade()));
bool keepSize = toGeometry.size() == size();
bool changedSize = false;
if (quickTileMode() != QuickTileNone) {
if (quickTileMode() != QuickTileMode(QuickTileFlag::None)) {
changedSize = true;
setQuickTileMode(QuickTileNone); // if we leave a quicktiled group, assume that the user wants to untile
setQuickTileMode(QuickTileFlag::None); // if we leave a quicktiled group, assume that the user wants to untile
}
if (toGeometry.isValid()) {
if (maximizeMode() != MaximizeRestore) {
......
......@@ -254,25 +254,25 @@ bool DecoratedClientImpl::isMaximizedHorizontally() const
Qt::Edges DecoratedClientImpl::adjacentScreenEdges() const
{
Qt::Edges edges;
const AbstractClient::QuickTileMode mode = m_client->quickTileMode();
if (mode.testFlag(AbstractClient::QuickTileLeft)) {
const QuickTileMode mode = m_client->quickTileMode();
if (mode.testFlag(QuickTileFlag::Left)) {
edges |= Qt::LeftEdge;
if (!mode.testFlag(AbstractClient::QuickTileTop) && !mode.testFlag(AbstractClient::QuickTileBottom)) {
if (!mode.testFlag(QuickTileFlag::Top) && !mode.testFlag(QuickTileFlag::Bottom)) {
// using complete side
edges |= Qt::TopEdge | Qt::BottomEdge;
}
}
if (mode.testFlag(AbstractClient::QuickTileTop)) {
if (mode.testFlag(QuickTileFlag::Top)) {
edges |= Qt::TopEdge;
}
if (mode.testFlag(AbstractClient::QuickTileRight)) {
if (mode.testFlag(QuickTileFlag::Right)) {
edges |= Qt::RightEdge;
if (!mode.testFlag(AbstractClient::QuickTileTop) && !mode.testFlag(AbstractClient::QuickTileBottom)) {
if (!mode.testFlag(QuickTileFlag::Top) && !mode.testFlag(QuickTileFlag::Bottom)) {
// using complete side
edges |= Qt::TopEdge | Qt::BottomEdge;
}
}
if (mode.testFlag(AbstractClient::QuickTileBottom)) {
if (mode.testFlag(QuickTileFlag::Bottom)) {
edges |= Qt::BottomEdge;
}
return edges;
......
This diff is collapsed.
......@@ -104,8 +104,8 @@ public:
* to the @p slot being invoked. If not using this overload it's required to ensure that
* registerShortcut is called before connecting to QAction's triggered signal.
**/
template <typename T>
void registerShortcut(const QKeySequence &shortcut, QAction *action, T *receiver, void (T::*slot)());
template <typename T, typename Slot>
void registerShortcut(const QKeySequence &shortcut, QAction *action, T *receiver, Slot slot);
void registerPointerShortcut(Qt::KeyboardModifiers modifiers, Qt::MouseButton pointerButtons, QAction *action);
void registerAxisShortcut(Qt::KeyboardModifiers modifiers, PointerAxisDirection axis, QAction *action);
void registerTouchpadSwipeShortcut(SwipeDirection direction, QAction *action);
......@@ -406,9 +406,9 @@ InputRedirection *input()
return InputRedirection::s_self;
}
template <typename T>
template <typename T, typename Slot>
inline
void InputRedirection::registerShortcut(const QKeySequence &shortcut, QAction *action, T *receiver, void (T::*slot)()) {
void InputRedirection::registerShortcut(const QKeySequence &shortcut, QAction *action, T *receiver, Slot slot) {
registerShortcut(shortcut, action);
connect(action, &QAction::triggered, receiver, slot);
}
......
......@@ -36,6 +36,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define DEF3( name, key, fnSlot, value ) \
initShortcut(QStringLiteral(name).arg(value), i18n(name, value), key, &Workspace::fnSlot, value);
#define DEF4( name, descr, key, functor ) \
initShortcut(QStringLiteral(name), i18n(descr), key, functor);
DEF(I18N_NOOP("Walk Through Window Tabs"), 0, slotActivateNextTab);
DEF(I18N_NOOP("Walk Through Window Tabs (Reverse)"), 0, slotActivatePrevTab);
......@@ -93,22 +96,22 @@ DEF2("Window Shrink Horizontal", I18N_NOOP("Pack Shrink Window Horizontally"),
0, slotWindowShrinkHorizontal);
DEF2("Window Shrink Vertical", I18N_NOOP("Pack Shrink Window Vertically"),
0, slotWindowShrinkVertical);
DEF2("Window Quick Tile Left", I18N_NOOP("Quick Tile Window to the Left"),
0, slotWindowQuickTileLeft);
DEF2("Window Quick Tile Right", I18N_NOOP("Quick Tile Window to the Right"),
0, slotWindowQuickTileRight);
DEF2("Window Quick Tile Top", I18N_NOOP("Quick Tile Window to the Top"),
0, slotWindowQuickTileTop);
DEF2("Window Quick Tile Bottom", I18N_NOOP("Quick Tile Window to the Bottom"),
0, slotWindowQuickTileBottom);
DEF2("Window Quick Tile Top Left", I18N_NOOP("Quick Tile Window to the Top Left"),
0, slotWindowQuickTileTopLeft);
DEF2("Window Quick Tile Bottom Left", I18N_NOOP("Quick Tile Window to the Bottom Left"),
0, slotWindowQuickTileBottomLeft);
DEF2("Window Quick Tile Top Right", I18N_NOOP("Quick Tile Window to the Top Right"),
0, slotWindowQuickTileTopRight);
DEF2("Window Quick Tile Bottom Right", I18N_NOOP("Quick Tile Window to the Bottom Right"),
0, slotWindowQuickTileBottomRight);
DEF4("Window Quick Tile Left", I18N_NOOP("Quick Tile Window to the Left"),
0, std::bind(&Workspace::quickTileWindow, this, QuickTileFlag::Left));
DEF4("Window Quick Tile Right", I18N_NOOP("Quick Tile Window to the Right"),
0, std::bind(&Workspace::quickTileWindow, this, QuickTileFlag::Right));
DEF4("Window Quick Tile Top", I18N_NOOP("Quick Tile Window to the Top"),
0, std::bind(&Workspace::quickTileWindow, this, QuickTileFlag::Top));
DEF4("Window Quick Tile Bottom", I18N_NOOP("Quick Tile Window to the Bottom"),
0, std::bind(&Workspace::quickTileWindow, this, QuickTileFlag::Bottom));
DEF4("Window Quick Tile Top Left", I18N_NOOP("Quick Tile Window to the Top Left"),
0, std::bind(&Workspace::quickTileWindow, this, QuickTileFlag::Top | QuickTileFlag::Left));
DEF4("Window Quick Tile Bottom Left", I18N_NOOP("Quick Tile Window to the Bottom Left"),
0, std::bind(&Workspace::quickTileWindow, this, QuickTileFlag::Bottom | QuickTileFlag::Left));
DEF4("Window Quick Tile Top Right", I18N_NOOP("Quick Tile Window to the Top Right"),
0, std::bind(&Workspace::quickTileWindow, this, QuickTileFlag::Top | QuickTileFlag::Right));
DEF4("Window Quick Tile Bottom Right", I18N_NOOP("Quick Tile Window to the Bottom Right"),
0, std::bind(&Workspace::quickTileWindow, this, QuickTileFlag::Bottom | QuickTileFlag::Right));
DEF2("Switch Window Up", I18N_NOOP("Switch to Window Above"),
Qt::META + Qt::ALT + Qt::Key_Up, slotSwitchWindowUp);
DEF2("Switch Window Down", I18N_NOOP("Switch to Window Below"),
......
......@@ -839,69 +839,13 @@ void AbstractClient::shrinkVertical()
}
}
void Workspace::slotWindowQuickTileLeft()
{
if (!active_client)
return;
active_client->setQuickTileMode(Client::QuickTileLeft, true);
}
void Workspace::slotWindowQuickTileRight()
{
if (!active_client)
return;
active_client->setQuickTileMode(Client::QuickTileRight, true);
}
void Workspace::slotWindowQuickTileTop()
{
if (!active_client)
return;
active_client->setQuickTileMode(Client::QuickTileTop, true);
}
void Workspace::slotWindowQuickTileBottom()
{
if (!active_client)
return;
active_client->setQuickTileMode(Client::QuickTileBottom, true);
}
void Workspace::slotWindowQuickTileTopLeft()
{
if (!active_client) {
return;
}
active_client->setQuickTileMode(Client::QuickTileTop|Client::QuickTileLeft, true);
}
void Workspace::slotWindowQuickTileTopRight()
void Workspace::quickTileWindow(QuickTileMode mode)
{
if (!active_client) {
return;
}
active_client->setQuickTileMode(Client::QuickTileTop|Client::QuickTileRight, true);
}
void Workspace::slotWindowQuickTileBottomLeft()
{
if (!active_client) {
return;
}
active_client->setQuickTileMode(Client::QuickTileBottom|Client::QuickTileLeft, true);
}
void Workspace::slotWindowQuickTileBottomRight()
{
if (!active_client) {
return;
}
active_client->setQuickTileMode(Client::QuickTileBottom|Client::QuickTileRight, true);
active_client->setQuickTileMode(mode, true);
}
int Workspace::packPositionLeft(const AbstractClient* cl, int oldx, bool left_edge) const
......
......@@ -149,14 +149,6 @@ SLOTWRAPPER(slotWindowGrowHorizontal)
SLOTWRAPPER(slotWindowGrowVertical)
SLOTWRAPPER(slotWindowShrinkHorizontal)
SLOTWRAPPER(slotWindowShrinkVertical)
SLOTWRAPPER(slotWindowQuickTileLeft)
SLOTWRAPPER(slotWindowQuickTileRight)
SLOTWRAPPER(slotWindowQuickTileTop)
SLOTWRAPPER(slotWindowQuickTileBottom)
SLOTWRAPPER(slotWindowQuickTileTopLeft)
SLOTWRAPPER(slotWindowQuickTileTopRight)
SLOTWRAPPER(slotWindowQuickTileBottomLeft)
SLOTWRAPPER(slotWindowQuickTileBottomRight)
SLOTWRAPPER(slotSwitchWindowUp)
SLOTWRAPPER(slotSwitchWindowDown)
......@@ -185,6 +177,22 @@ SLOTWRAPPER(slotWindowToDesktopDown)
#undef SLOTWRAPPER
#define SLOTWRAPPER(name,modes) \
void WorkspaceWrapper::name() { \
Workspace::self()->quickTileWindow(modes); \
}
SLOTWRAPPER(slotWindowQuickTileLeft, QuickTileFlag::Left)
SLOTWRAPPER(slotWindowQuickTileRight, QuickTileFlag::Right)
SLOTWRAPPER(slotWindowQuickTileTop, QuickTileFlag::Top)
SLOTWRAPPER(slotWindowQuickTileBottom, QuickTileFlag::Bottom)
SLOTWRAPPER(slotWindowQuickTileTopLeft, QuickTileFlag::Top | QuickTileFlag::Left)
SLOTWRAPPER(slotWindowQuickTileTopRight, QuickTileFlag::Top | QuickTileFlag::Right)
SLOTWRAPPER(slotWindowQuickTileBottomLeft, QuickTileFlag::Bottom | QuickTileFlag::Left)
SLOTWRAPPER(slotWindowQuickTileBottomRight, QuickTileFlag::Bottom | QuickTileFlag::Right)
#undef SLOTWRAPPER
#define SLOTWRAPPER(name,direction) \
void WorkspaceWrapper::name( ) { \
VirtualDesktopManager::self()->moveTo<direction>(options->isRollOverDesktops()); \
......
......@@ -728,7 +728,7 @@ void ShellClient::changeMaximize(bool horizontal, bool vertical, bool adjust)
// Conditional quick tiling exit points
const auto oldQuickTileMode = quickTileMode();
if (quickTileMode() != QuickTileNone) {
if (quickTileMode() != QuickTileMode(QuickTileFlag::None)) {
if (oldMode == MaximizeFull &&
!clientArea.contains(m_geomMaximizeRestore.center())) {
// Not restoring on the same screen
......@@ -737,7 +737,7 @@ void ShellClient::changeMaximize(bool horizontal, bool vertical, bool adjust)
} else if ((oldMode == MaximizeVertical && m_maximizeMode == MaximizeRestore) ||
(oldMode == MaximizeFull && m_maximizeMode == MaximizeHorizontal)) {
// Modifying geometry of a tiled window
updateQuickTileMode(QuickTileNone); // Exit quick tile mode without restoring geometry
updateQuickTileMode(QuickTileFlag::None); // Exit quick tile mode without restoring geometry
}
}
......@@ -746,9 +746,9 @@ void ShellClient::changeMaximize(bool horizontal, bool vertical, bool adjust)
m_geomMaximizeRestore = geometry();
// TODO: Client has more checks
if (options->electricBorderMaximize()) {
updateQuickTileMode(QuickTileMaximize);
updateQuickTileMode(QuickTileFlag::Maximize);
} else {
updateQuickTileMode(QuickTileNone);
updateQuickTileMode(QuickTileFlag::None);
}
if (quickTileMode() != oldQuickTileMode) {
emit quickTileModeChanged();
......@@ -757,7 +757,7 @@ void ShellClient::changeMaximize(bool horizontal, bool vertical, bool adjust)
workspace()->raiseClient(this);
} else {
if (m_maximizeMode == MaximizeRestore) {
updateQuickTileMode(QuickTileNone);
updateQuickTileMode(QuickTileFlag::None);
}
if (quickTileMode() != oldQuickTileMode) {
emit quickTileModeChanged();
......
......@@ -141,6 +141,18 @@ MaximizeMode operator^(MaximizeMode m1, MaximizeMode m2)
return MaximizeMode(int(m1) ^ int(m2));
}
enum class QuickTileFlag {
None = 0,
Left = 1,
Right = 1<<1,
Top = 1<<2,
Bottom = 1<<3,
Horizontal = Left|Right,
Vertical = Top|Bottom,
Maximize = Left|Right|Top|Bottom
};
Q_DECLARE_FLAGS(QuickTileMode, QuickTileFlag)
template <typename T> using ScopedCPointer = QScopedPointer<T, QScopedPointerPodDeleter>;
void KWIN_EXPORT updateXTime();
......@@ -246,5 +258,6 @@ protected:
// Must be outside namespace
Q_DECLARE_OPERATORS_FOR_FLAGS(KWin::StrutAreas)
Q_DECLARE_OPERATORS_FOR_FLAGS(KWin::QuickTileMode)
#endif
......@@ -369,6 +369,8 @@ public:
void markXStackingOrderAsDirty();
void quickTileWindow(QuickTileMode mode);
public Q_SLOTS:
void performWindowOperation(KWin::AbstractClient* c, Options::WindowOperation op);
// Keybindings
......@@ -401,14 +403,6 @@ public Q_SLOTS:
void slotWindowGrowVertical();
void slotWindowShrinkHorizontal();
void slotWindowShrinkVertical();
void slotWindowQuickTileLeft();
void slotWindowQuickTileRight();
void slotWindowQuickTileTop();
void slotWindowQuickTileBottom();
void slotWindowQuickTileTopLeft();
void slotWindowQuickTileTopRight();
void slotWindowQuickTileBottomLeft();
void slotWindowQuickTileBottomRight();
void slotSwitchWindowUp();
void slotSwitchWindowDown();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment