1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Linux: Recreate mouse cursors when showing them on a different display to the one that they were originally created on

This commit is contained in:
ed 2019-05-07 17:10:52 +01:00
parent e7136b57f2
commit 46a97e1f2c
2 changed files with 35 additions and 4 deletions

View file

@ -53,7 +53,8 @@ public:
}
SharedCursorHandle (const Image& image, Point<int> hotSpot, float scaleFactor)
: handle (CustomMouseCursorInfo (image, hotSpot, scaleFactor).create()),
: info (new CustomMouseCursorInfo (image, hotSpot, scaleFactor)),
handle (info->create()),
standardType (MouseCursor::NormalCursor),
isStandard (false)
{
@ -106,10 +107,15 @@ public:
}
}
void* getHandle() const noexcept { return handle; }
void* getHandle() const noexcept { return handle; }
void setHandle (void* newHandle) { handle = newHandle; }
MouseCursor::StandardCursorType getType() const noexcept { return standardType; }
CustomMouseCursorInfo* getCustomInfo() const noexcept { return info.get(); }
private:
void* const handle;
std::unique_ptr<CustomMouseCursorInfo> info;
void* handle;
Atomic<int> refCount { 1 };
const MouseCursor::StandardCursorType standardType;
const bool isStandard;

View file

@ -3790,6 +3790,7 @@ int JUCE_CALLTYPE NativeMessageBox::showYesNoBox (AlertWindow::AlertIconType ico
}
//============================== X11 - MouseCursor =============================
std::map<Cursor, Display*> cursorMap;
void* CustomMouseCursorInfo::create() const
{
@ -3852,7 +3853,10 @@ void* CustomMouseCursorInfo::create() const
xcursorImageDestroy (xcImage);
if (result != nullptr)
{
cursorMap[(Cursor) result] = display;
return result;
}
}
}
}
@ -3916,6 +3920,7 @@ void* CustomMouseCursorInfo::create() const
XFreePixmap (display, sourcePixmap);
XFreePixmap (display, maskPixmap);
cursorMap[(Cursor) result] = display;
return result;
}
@ -3983,13 +3988,33 @@ void* MouseCursor::createStandardMouseCursor (MouseCursor::StandardCursorType ty
}
ScopedXLock xlock (display);
return (void*) XCreateFontCursor (display, shape);
auto* result = (void*) XCreateFontCursor (display, shape);
cursorMap[(Cursor) result] = display;
return result;
}
void MouseCursor::showInWindow (ComponentPeer* peer) const
{
if (auto* lp = dynamic_cast<LinuxComponentPeer*> (peer))
{
ScopedXDisplay xDisplay;
if (cursorHandle != nullptr && xDisplay.display != cursorMap[(Cursor) getHandle()])
{
auto oldHandle = (Cursor) getHandle();
if (auto* customInfo = cursorHandle->getCustomInfo())
cursorHandle->setHandle (customInfo->create());
else
cursorHandle->setHandle (createStandardMouseCursor (cursorHandle->getType()));
cursorMap.erase (oldHandle);
}
lp->showMouseCursor ((Cursor) getHandle());
}
}
//=================================== X11 - DND ================================