[x11] Fix interactive point selection
Summary: The support for interactive point selection was missing. This results in the ColorPicker dbus API always returning an error on X11. We either need to disable the ColorPicker on X11 or add support for this functionality. As the X11 platform basically supports selecting a point in the interactive window selection it makes more sense to add this missing method in the platform than to disable support of color picker effect. BUG: 387720 FIXED-IN: 5.12.1 Test Plan: Run KWin/X11 on Xephyr and was able to pick a color and kill a window Reviewers: #kwin, #plasma Subscribers: plasma-devel, kwin Tags: #plasma Differential Revision: https://phabricator.kde.org/D10302
This commit is contained in:
parent
93dd777351
commit
ea5e701164
4 changed files with 70 additions and 13 deletions
plugins/platforms/x11/standalone
|
@ -56,12 +56,38 @@ WindowSelector::~WindowSelector()
|
|||
|
||||
void WindowSelector::start(std::function<void(KWin::Toplevel*)> callback, const QByteArray &cursorName)
|
||||
{
|
||||
xcb_cursor_t cursor = createCursor(cursorName);
|
||||
if (m_active) {
|
||||
callback(nullptr);
|
||||
return;
|
||||
}
|
||||
|
||||
m_active = activate(cursorName);
|
||||
if (!m_active) {
|
||||
callback(nullptr);
|
||||
return;
|
||||
}
|
||||
m_callback = callback;
|
||||
}
|
||||
|
||||
void WindowSelector::start(std::function<void (const QPoint &)> callback)
|
||||
{
|
||||
if (m_active) {
|
||||
callback(QPoint(-1, -1));
|
||||
return;
|
||||
}
|
||||
|
||||
m_active = activate();
|
||||
if (!m_active) {
|
||||
callback(QPoint(-1, -1));
|
||||
return;
|
||||
}
|
||||
m_pointSelectionFallback = callback;
|
||||
}
|
||||
|
||||
bool WindowSelector::activate(const QByteArray &cursorName)
|
||||
{
|
||||
xcb_cursor_t cursor = createCursor(cursorName);
|
||||
|
||||
xcb_connection_t *c = connection();
|
||||
ScopedCPointer<xcb_grab_pointer_reply_t> grabPointer(xcb_grab_pointer_reply(c, xcb_grab_pointer_unchecked(c, false, rootWindow(),
|
||||
XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE |
|
||||
|
@ -70,17 +96,15 @@ void WindowSelector::start(std::function<void(KWin::Toplevel*)> callback, const
|
|||
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, XCB_WINDOW_NONE,
|
||||
cursor, XCB_TIME_CURRENT_TIME), NULL));
|
||||
if (grabPointer.isNull() || grabPointer->status != XCB_GRAB_STATUS_SUCCESS) {
|
||||
callback(nullptr);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
m_active = grabXKeyboard();
|
||||
if (!m_active) {
|
||||
const bool grabbed = grabXKeyboard();
|
||||
if (grabbed) {
|
||||
grabXServer();
|
||||
} else {
|
||||
xcb_ungrab_pointer(connection(), XCB_TIME_CURRENT_TIME);
|
||||
callback(nullptr);
|
||||
return;
|
||||
}
|
||||
grabXServer();
|
||||
m_callback = callback;
|
||||
return grabbed;
|
||||
}
|
||||
|
||||
xcb_cursor_t WindowSelector::createCursor(const QByteArray &cursorName)
|
||||
|
@ -136,12 +160,16 @@ bool WindowSelector::event(xcb_generic_event_t *event)
|
|||
void WindowSelector::handleButtonRelease(xcb_button_t button, xcb_window_t window)
|
||||
{
|
||||
if (button == XCB_BUTTON_INDEX_3) {
|
||||
m_callback(nullptr);
|
||||
cancelCallback();
|
||||
release();
|
||||
return;
|
||||
}
|
||||
if (button == XCB_BUTTON_INDEX_1 || button == XCB_BUTTON_INDEX_2) {
|
||||
selectWindowId(window);
|
||||
if (m_callback) {
|
||||
selectWindowId(window);
|
||||
} else if (m_pointSelectionFallback) {
|
||||
m_pointSelectionFallback(Cursor::pos());
|
||||
}
|
||||
release();
|
||||
return;
|
||||
}
|
||||
|
@ -173,11 +201,15 @@ void WindowSelector::handleKeyPress(xcb_keycode_t keycode, uint16_t state)
|
|||
}
|
||||
Cursor::setPos(Cursor::pos() + QPoint(mx, my));
|
||||
if (returnPressed) {
|
||||
selectWindowUnderPointer();
|
||||
if (m_callback) {
|
||||
selectWindowUnderPointer();
|
||||
} else if (m_pointSelectionFallback) {
|
||||
m_pointSelectionFallback(Cursor::pos());
|
||||
}
|
||||
}
|
||||
if (returnPressed || escapePressed) {
|
||||
if (escapePressed) {
|
||||
m_callback(nullptr);
|
||||
cancelCallback();
|
||||
}
|
||||
release();
|
||||
}
|
||||
|
@ -199,6 +231,7 @@ void WindowSelector::release()
|
|||
ungrabXServer();
|
||||
m_active = false;
|
||||
m_callback = std::function<void(KWin::Toplevel*)>();
|
||||
m_pointSelectionFallback = std::function<void(const QPoint&)>();
|
||||
}
|
||||
|
||||
void WindowSelector::selectWindowId(xcb_window_t window_to_select)
|
||||
|
@ -228,4 +261,13 @@ void WindowSelector::selectWindowId(xcb_window_t window_to_select)
|
|||
}
|
||||
}
|
||||
|
||||
void WindowSelector::cancelCallback()
|
||||
{
|
||||
if (m_callback) {
|
||||
m_callback(nullptr);
|
||||
} else if (m_pointSelectionFallback) {
|
||||
m_pointSelectionFallback(QPoint(-1, -1));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -29,6 +29,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
|
||||
#include <functional>
|
||||
|
||||
class QPoint;
|
||||
|
||||
namespace KWin
|
||||
{
|
||||
class Toplevel;
|
||||
|
@ -41,6 +43,7 @@ public:
|
|||
~WindowSelector();
|
||||
|
||||
void start(std::function<void(KWin::Toplevel*)> callback, const QByteArray &cursorName);
|
||||
void start(std::function<void (const QPoint &)> callback);
|
||||
bool isActive() const {
|
||||
return m_active;
|
||||
}
|
||||
|
@ -55,8 +58,11 @@ private:
|
|||
void handleKeyPress(xcb_keycode_t keycode, uint16_t state);
|
||||
void handleButtonRelease(xcb_button_t button, xcb_window_t window);
|
||||
void selectWindowId(xcb_window_t window_to_kill);
|
||||
bool activate(const QByteArray &cursorName = QByteArray());
|
||||
void cancelCallback();
|
||||
bool m_active;
|
||||
std::function<void(KWin::Toplevel*)> m_callback;
|
||||
std::function<void(const QPoint &)> m_pointSelectionFallback;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
|
|
@ -318,6 +318,14 @@ void X11StandalonePlatform::startInteractiveWindowSelection(std::function<void(K
|
|||
m_windowSelector->start(callback, cursorName);
|
||||
}
|
||||
|
||||
void X11StandalonePlatform::startInteractivePositionSelection(std::function<void (const QPoint &)> callback)
|
||||
{
|
||||
if (m_windowSelector.isNull()) {
|
||||
m_windowSelector.reset(new WindowSelector);
|
||||
}
|
||||
m_windowSelector->start(callback);
|
||||
}
|
||||
|
||||
void X11StandalonePlatform::setupActionForGlobalAccel(QAction *action)
|
||||
{
|
||||
connect(action, &QAction::triggered, kwinApp(), [action] {
|
||||
|
|
|
@ -54,6 +54,7 @@ public:
|
|||
bool openGLCompositingIsBroken() const override;
|
||||
void createOpenGLSafePoint(OpenGLSafePoint safePoint) override;
|
||||
void startInteractiveWindowSelection(std::function<void (KWin::Toplevel *)> callback, const QByteArray &cursorName = QByteArray()) override;
|
||||
void startInteractivePositionSelection(std::function<void (const QPoint &)> callback) override;
|
||||
|
||||
PlatformCursorImage cursorImage() const override;
|
||||
|
||||
|
|
Loading…
Reference in a new issue