Move updateCursor() functionality to AbstractClient

Includes moving the m_cursor and Qt::CursorShape cursor() method to
AbstractClient. In addition AbstractClient now emits a signal whenever
the shape changes allowing Client to react on it (update the low level
cursor) and also hopefully the Wayland Backends to react to it, so that
we have the cursor.
icc-effect-5.14.5
Martin Gräßlin 2015-10-16 15:27:53 +02:00
parent b8e68307bb
commit dcb5e29316
5 changed files with 61 additions and 57 deletions

View File

@ -1065,4 +1065,40 @@ void AbstractClient::updateInitialMoveResizeGeometry()
m_moveResize.geometry = m_moveResize.initialGeometry;
}
void AbstractClient::updateCursor()
{
Position m = moveResizePointerMode();
if (!isResizable() || isShade())
m = PositionCenter;
Qt::CursorShape c = Qt::ArrowCursor;
switch(m) {
case PositionTopLeft:
case PositionBottomRight:
c = Qt::SizeFDiagCursor;
break;
case PositionBottomLeft:
case PositionTopRight:
c = Qt::SizeBDiagCursor;
break;
case PositionTop:
case PositionBottom:
c = Qt::SizeVerCursor;
break;
case PositionLeft:
case PositionRight:
c = Qt::SizeHorCursor;
break;
default:
if (isMoveResize())
c = Qt::SizeAllCursor;
else
c = Qt::ArrowCursor;
break;
}
if (c == m_moveResize.cursor)
return;
m_moveResize.cursor = c;
emit moveResizeCursorChanged(c);
}
}

View File

@ -442,6 +442,12 @@ public:
bool isResize() const {
return isMoveResize() && moveResizePointerMode() != PositionCenter;
}
/**
* Cursor shape for move/resize mode.
**/
Qt::CursorShape cursor() const {
return m_moveResize.cursor;
}
virtual bool hasStrut() const;
@ -491,6 +497,7 @@ Q_SIGNALS:
void modalChanged();
void quickTileModeChanged();
void moveResizedChanged();
void moveResizeCursorChanged(Qt::CursorShape);
protected:
AbstractClient();
@ -679,6 +686,10 @@ protected:
m_moveResize.buttonDown = down;
}
void checkUnrestrictedMoveResize();
/**
* Sets an appropriate cursor shape for the logical mouse position.
*/
void updateCursor();
private:
void handlePaletteChange();
@ -735,6 +746,7 @@ private:
QRect geometry;
Position pointer = PositionCenter;
bool buttonDown = false;
Qt::CursorShape cursor = Qt::ArrowCursor;
} m_moveResize;
};

View File

@ -110,7 +110,6 @@ Client::Client()
, shade_below(NULL)
, m_motif(atoms->motif_wm_hints)
, blocks_compositing(false)
, m_cursor(Qt::ArrowCursor)
, shadeHoverTimer(NULL)
, delayedMoveResizeTimer(NULL)
, m_colormap(XCB_COLORMAP_NONE)
@ -173,6 +172,18 @@ Client::Client()
connect(clientMachine(), &ClientMachine::localhostChanged, this, &Client::updateCaption);
connect(options, &Options::condensedTitleChanged, this, &Client::updateCaption);
connect(this, &Client::moveResizeCursorChanged, this, [this] (Qt::CursorShape cursor) {
xcb_cursor_t nativeCursor = Cursor::x11Cursor(cursor);
m_frame.defineCursor(nativeCursor);
if (m_decoInputExtent.isValid())
m_decoInputExtent.defineCursor(nativeCursor);
if (isMoveResize()) {
// changing window attributes doesn't change cursor if there's pointer grab active
xcb_change_active_pointer_grab(connection(), nativeCursor, xTime(),
XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW);
}
});
// SELI TODO: Initialize xsizehints??
}
@ -1834,53 +1845,6 @@ bool Client::wantsInput() const
return rules()->checkAcceptFocus(info->input() || info->supportsProtocol(NET::TakeFocusProtocol));
}
/**
* Sets an appropriate cursor shape for the logical mouse position \a m
*/
void Client::updateCursor()
{
Position m = moveResizePointerMode();
if (!isResizable() || isShade())
m = PositionCenter;
Qt::CursorShape c = Qt::ArrowCursor;
switch(m) {
case PositionTopLeft:
case PositionBottomRight:
c = Qt::SizeFDiagCursor;
break;
case PositionBottomLeft:
case PositionTopRight:
c = Qt::SizeBDiagCursor;
break;
case PositionTop:
case PositionBottom:
c = Qt::SizeVerCursor;
break;
case PositionLeft:
case PositionRight:
c = Qt::SizeHorCursor;
break;
default:
if (isMoveResize())
c = Qt::SizeAllCursor;
else
c = Qt::ArrowCursor;
break;
}
if (c == m_cursor)
return;
m_cursor = c;
xcb_cursor_t nativeCursor = Cursor::x11Cursor(m_cursor);
m_frame.defineCursor(nativeCursor);
if (m_decoInputExtent.isValid())
m_decoInputExtent.defineCursor(nativeCursor);
if (isMoveResize()) {
// changing window attributes doesn't change cursor if there's pointer grab active
xcb_change_active_pointer_grab(connection(), nativeCursor, xTime(),
XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW);
}
}
void Client::setBlockingCompositing(bool block)
{
const bool usedToBlock = blocks_compositing;

View File

@ -188,7 +188,6 @@ public:
bool processDecorationButtonPress(QMouseEvent *event);
void processDecorationButtonRelease(QMouseEvent *event);
void processDecorationMove();
Qt::CursorShape cursor() const;
bool manage(xcb_window_t w, bool isMapped);
void releaseWindow(bool on_shutdown = false);
@ -429,7 +428,6 @@ private:
virtual ~Client(); ///< Use destroyClient() or releaseWindow()
Position mousePosition() const;
void updateCursor();
// Handlers for X11 events
bool mapRequestEvent(xcb_map_request_event_t *e);
@ -648,7 +646,6 @@ private:
uint ignore_focus_stealing : 1; ///< Don't apply focus stealing prevention to this client
bool blocks_compositing;
WindowRules client_rules;
Qt::CursorShape m_cursor;
// DON'T reorder - Saved to config files !!!
enum FullScreenMode {
FullScreenNone,
@ -868,11 +865,6 @@ inline void Client::print(T &stream) const
<< resourceName() << ";Caption:" << caption() << "\'";
}
inline Qt::CursorShape Client::cursor() const
{
return m_cursor;
}
} // namespace
Q_DECLARE_METATYPE(KWin::Client*)
Q_DECLARE_METATYPE(QList<KWin::Client*>)

View File

@ -2627,7 +2627,7 @@ bool Client::startMoveResize()
const xcb_grab_pointer_cookie_t cookie = xcb_grab_pointer_unchecked(connection(), false, m_moveResizeGrabWindow,
XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION |
XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW,
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, m_moveResizeGrabWindow, Cursor::x11Cursor(m_cursor), xTime());
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, m_moveResizeGrabWindow, Cursor::x11Cursor(cursor()), xTime());
ScopedCPointer<xcb_grab_pointer_reply_t> pointerGrab(xcb_grab_pointer_reply(connection(), cookie, NULL));
if (!pointerGrab.isNull() && pointerGrab->status == XCB_GRAB_STATUS_SUCCESS) {
has_grab = true;