diff --git a/abstract_client.cpp b/abstract_client.cpp index e1d58c7d61..b7f7e99585 100644 --- a/abstract_client.cpp +++ b/abstract_client.cpp @@ -634,6 +634,47 @@ void AbstractClient::destroyWindowManagementInterface() #endif } +Options::MouseCommand AbstractClient::getMouseCommand(Qt::MouseButton button, bool *handled) const +{ + *handled = false; + if (button == Qt::NoButton) { + return Options::MouseNothing; + } + if (isActive()) { + if (options->isClickRaise()) { + *handled = true; + return Options::MouseActivateRaiseAndPassClick; + } + } else { + *handled = true; + switch (button) { + case Qt::LeftButton: + return options->commandWindow1(); + case Qt::MiddleButton: + return options->commandWindow2(); + case Qt::RightButton: + return options->commandWindow3(); + default: + // all other buttons pass Activate & Pass Client + return Options::MouseActivateAndPassClick; + } + } + return Options::MouseNothing; +} + +Options::MouseCommand AbstractClient::getWheelCommand(Qt::Orientation orientation, bool *handled) const +{ + *handled = false; + if (orientation != Qt::Vertical) { + return Options::MouseNothing; + } + if (!isActive()) { + *handled = true; + return options->commandWindowWheel(); + } + return Options::MouseNothing; +} + bool AbstractClient::performMouseCommand(Options::MouseCommand cmd, const QPoint &globalPos) { bool replay = false; diff --git a/abstract_client.h b/abstract_client.h index b72e4cac91..3b35e7a886 100644 --- a/abstract_client.h +++ b/abstract_client.h @@ -357,6 +357,16 @@ public: virtual bool hasStrut() const; + /** + * Determines the mouse command for the given @p button in the current state. + * + * The @p handled argument specifies whether the button was handled or not. + * This value should be used to determine whether the mouse button should be + * passed to the AbstractClient or being filtered out. + **/ + Options::MouseCommand getMouseCommand(Qt::MouseButton button, bool *handled) const; + Options::MouseCommand getWheelCommand(Qt::Orientation orientation, bool *handled) const; + // TODO: remove boolean trap static bool belongToSameApplication(const AbstractClient* c1, const AbstractClient* c2, bool active_hack = false); diff --git a/events.cpp b/events.cpp index 1add8e0494..3ce3f917c9 100644 --- a/events.cpp +++ b/events.cpp @@ -1135,31 +1135,13 @@ bool Client::buttonPressEvent(xcb_window_t w, int button, int state, int x, int break; } } else { - // inactive inner window - if (!isActive() && w == wrapperId() && button < 6) { - was_action = true; - switch(button) { - case XCB_BUTTON_INDEX_1: - com = options->commandWindow1(); - break; - case XCB_BUTTON_INDEX_2: - com = options->commandWindow2(); - break; - case XCB_BUTTON_INDEX_3: - com = options->commandWindow3(); - break; - case XCB_BUTTON_INDEX_4: - case XCB_BUTTON_INDEX_5: - com = options->commandWindowWheel(); - break; + if (w == wrapperId()) { + if (button < 4) { + com = getMouseCommand(x11ToQtMouseButton(button), &was_action); + } else if (button < 6) { + com = getWheelCommand(Qt::Vertical, &was_action); } } - // active inner window - if (isActive() && w == wrapperId() - && options->isClickRaise() && button < 4) { // exclude wheel - com = Options::MouseActivateRaiseAndPassClick; - was_action = true; - } } if (was_action) { bool replay = performMouseCommand(com, QPoint(x_root, y_root));