| @@ -1345,8 +1345,7 @@ public: | |||||
| { | { | ||||
| ScopedXDisplay xDisplay; | ScopedXDisplay xDisplay; | ||||
| ::Display* display = xDisplay.get(); | |||||
| XResizeWindow (display, (Window) getWindowHandle(), childBounds.getWidth(), childBounds.getHeight()); | |||||
| XResizeWindow (xDisplay.display, (Window) getWindowHandle(), childBounds.getWidth(), childBounds.getHeight()); | |||||
| } | } | ||||
| #endif | #endif | ||||
| @@ -250,9 +250,8 @@ namespace | |||||
| { | { | ||||
| ScopedXDisplay xDisplay; | ScopedXDisplay xDisplay; | ||||
| ::Display* display = xDisplay.get(); | |||||
| XGetWindowProperty (display, handle, atom, 0, 1, false, AnyPropertyType, | |||||
| XGetWindowProperty (xDisplay.display, handle, atom, 0, 1, false, AnyPropertyType, | |||||
| &userType, &userSize, &userCount, &bytes, &data); | &userType, &userSize, &userCount, &bytes, &data); | ||||
| } | } | ||||
| @@ -269,9 +268,7 @@ namespace | |||||
| { | { | ||||
| ScopedXDisplay xDisplay; | ScopedXDisplay xDisplay; | ||||
| ::Display* display = xDisplay.get(); | |||||
| XQueryTree (display, windowToCheck, &rootWindow, &parentWindow, &childWindows, &numChildren); | |||||
| XQueryTree (xDisplay.display, windowToCheck, &rootWindow, &parentWindow, &childWindows, &numChildren); | |||||
| } | } | ||||
| if (numChildren > 0) | if (numChildren > 0) | ||||
| @@ -225,23 +225,17 @@ void XWindowSystem::destroyXDisplay() noexcept | |||||
| juce_ImplementSingleton (XWindowSystem) | juce_ImplementSingleton (XWindowSystem) | ||||
| //============================================================================== | //============================================================================== | ||||
| ScopedXDisplay::ScopedXDisplay() | |||||
| ScopedXDisplay::ScopedXDisplay() : display (XWindowSystem::getInstance()->displayRef()) | |||||
| { | { | ||||
| display = XWindowSystem::getInstance()->displayRef(); | |||||
| } | } | ||||
| ScopedXDisplay::~ScopedXDisplay() | ScopedXDisplay::~ScopedXDisplay() | ||||
| { | { | ||||
| XWindowSystem::getInstance()->displayUnref(); | XWindowSystem::getInstance()->displayUnref(); | ||||
| } | } | ||||
| ::Display* ScopedXDisplay::get() | |||||
| { | |||||
| return display; | |||||
| } | |||||
| //============================================================================== | //============================================================================== | ||||
| ScopedXLock::ScopedXLock(::Display* _display) | |||||
| : display (_display) | |||||
| ScopedXLock::ScopedXLock(::Display* d) : display (d) | |||||
| { | { | ||||
| if (display != nullptr) XLockDisplay (display); | if (display != nullptr) XLockDisplay (display); | ||||
| } | } | ||||
| @@ -33,21 +33,26 @@ | |||||
| struct _XDisplay; | struct _XDisplay; | ||||
| #define ATOM_TYPE unsigned long | |||||
| #define WINDOW_TYPE unsigned long | |||||
| namespace juce | |||||
| { | |||||
| typedef ::_XDisplay* XDisplay; | |||||
| typedef unsigned long ATOM_TYPE; | |||||
| typedef unsigned long WINDOW_TYPE; | |||||
| namespace juce { | |||||
| //============================================================================== | //============================================================================== | ||||
| class XWindowSystem | class XWindowSystem | ||||
| { | { | ||||
| public: | public: | ||||
| ::_XDisplay* displayRef() noexcept; | |||||
| ::_XDisplay* displayUnref() noexcept; | |||||
| XDisplay displayRef() noexcept; | |||||
| XDisplay displayUnref() noexcept; | |||||
| juce_DeclareSingleton (XWindowSystem, false) | juce_DeclareSingleton (XWindowSystem, false) | ||||
| private: | private: | ||||
| ::_XDisplay* display; | |||||
| XDisplay display; | |||||
| Atomic<int> displayCount; | Atomic<int> displayCount; | ||||
| XWindowSystem() noexcept; | XWindowSystem() noexcept; | ||||
| @@ -63,11 +68,11 @@ class ScopedXDisplay | |||||
| public: | public: | ||||
| ScopedXDisplay(); | ScopedXDisplay(); | ||||
| ~ScopedXDisplay(); | ~ScopedXDisplay(); | ||||
| ::_XDisplay* get(); | |||||
| private: | |||||
| ::_XDisplay* display; | |||||
| const XDisplay display; | |||||
| }; | }; | ||||
| //============================================================================== | |||||
| /** A handy class that uses XLockDisplay and XUnlockDisplay to lock the X server | /** A handy class that uses XLockDisplay and XUnlockDisplay to lock the X server | ||||
| using RAII (Only available in Linux!). | using RAII (Only available in Linux!). | ||||
| */ | */ | ||||
| @@ -77,21 +82,22 @@ public: | |||||
| /** Creating a ScopedXLock object locks the X display. | /** Creating a ScopedXLock object locks the X display. | ||||
| This uses XLockDisplay() to grab the display that Juce is using. | This uses XLockDisplay() to grab the display that Juce is using. | ||||
| */ | */ | ||||
| ScopedXLock (::_XDisplay* _display); | |||||
| ScopedXLock (XDisplay); | |||||
| /** Deleting a ScopedXLock object unlocks the X display. | /** Deleting a ScopedXLock object unlocks the X display. | ||||
| This calls XUnlockDisplay() to release the lock. | This calls XUnlockDisplay() to release the lock. | ||||
| */ | */ | ||||
| ~ScopedXLock(); | ~ScopedXLock(); | ||||
| private: | private: | ||||
| // defined in juce_linux_X11.h | // defined in juce_linux_X11.h | ||||
| ::_XDisplay* display; | |||||
| XDisplay display; | |||||
| }; | }; | ||||
| //============================================================================== | //============================================================================== | ||||
| struct Atoms | struct Atoms | ||||
| { | { | ||||
| Atoms(::_XDisplay* display); | |||||
| Atoms (XDisplay); | |||||
| enum ProtocolItems | enum ProtocolItems | ||||
| { | { | ||||
| @@ -101,28 +107,28 @@ struct Atoms | |||||
| }; | }; | ||||
| ATOM_TYPE protocols, protocolList[3], changeState, state, userTime, | ATOM_TYPE protocols, protocolList[3], changeState, state, userTime, | ||||
| activeWin, pid, windowType, windowState, | |||||
| XdndAware, XdndEnter, XdndLeave, XdndPosition, XdndStatus, | |||||
| XdndDrop, XdndFinished, XdndSelection, XdndTypeList, XdndActionList, | |||||
| XdndActionDescription, XdndActionCopy, XdndActionPrivate, | |||||
| XembedMsgType, XembedInfo, | |||||
| allowedActions[5], | |||||
| allowedMimeTypes[4]; | |||||
| activeWin, pid, windowType, windowState, | |||||
| XdndAware, XdndEnter, XdndLeave, XdndPosition, XdndStatus, | |||||
| XdndDrop, XdndFinished, XdndSelection, XdndTypeList, XdndActionList, | |||||
| XdndActionDescription, XdndActionCopy, XdndActionPrivate, | |||||
| XembedMsgType, XembedInfo, | |||||
| allowedActions[5], | |||||
| allowedMimeTypes[4]; | |||||
| static const unsigned long DndVersion; | static const unsigned long DndVersion; | ||||
| static ATOM_TYPE getIfExists (::_XDisplay* display, const char* name); | |||||
| static ATOM_TYPE getCreating (::_XDisplay* display, const char* name); | |||||
| static ATOM_TYPE getIfExists (XDisplay, const char* name); | |||||
| static ATOM_TYPE getCreating (XDisplay, const char* name); | |||||
| static String getName (::_XDisplay* display, const ATOM_TYPE atom); | |||||
| static String getName (XDisplay, ATOM_TYPE atom); | |||||
| static bool isMimeTypeFile (::_XDisplay* display, const ATOM_TYPE atom); | |||||
| static bool isMimeTypeFile (XDisplay, ATOM_TYPE atom); | |||||
| }; | }; | ||||
| //============================================================================== | //============================================================================== | ||||
| struct GetXProperty | struct GetXProperty | ||||
| { | { | ||||
| GetXProperty (::_XDisplay* display, WINDOW_TYPE window, ATOM_TYPE atom, | |||||
| GetXProperty (XDisplay, WINDOW_TYPE window, ATOM_TYPE atom, | |||||
| long offset, long length, bool shouldDelete, | long offset, long length, bool shouldDelete, | ||||
| ATOM_TYPE requestedType); | ATOM_TYPE requestedType); | ||||
| @@ -211,9 +211,8 @@ static ClipboardCallbackInitialiser clipboardInitialiser; | |||||
| void SystemClipboard::copyTextToClipboard (const String& clipText) | void SystemClipboard::copyTextToClipboard (const String& clipText) | ||||
| { | { | ||||
| ScopedXDisplay xDisplay; | ScopedXDisplay xDisplay; | ||||
| ::Display* display = xDisplay.get(); | |||||
| if (display != nullptr) | |||||
| if (auto display = xDisplay.display) | |||||
| { | { | ||||
| ClipboardHelpers::initSelectionAtoms (display); | ClipboardHelpers::initSelectionAtoms (display); | ||||
| ClipboardHelpers::localClipboardContent = clipText; | ClipboardHelpers::localClipboardContent = clipText; | ||||
| @@ -227,9 +226,8 @@ String SystemClipboard::getTextFromClipboard() | |||||
| { | { | ||||
| String content; | String content; | ||||
| ScopedXDisplay xDisplay; | ScopedXDisplay xDisplay; | ||||
| ::Display* display = xDisplay.get(); | |||||
| if (display != nullptr) | |||||
| if (auto display = xDisplay.display) | |||||
| { | { | ||||
| ClipboardHelpers::initSelectionAtoms (display); | ClipboardHelpers::initSelectionAtoms (display); | ||||
| @@ -68,37 +68,38 @@ namespace Keys | |||||
| bool KeyPress::isKeyCurrentlyDown (const int keyCode) | bool KeyPress::isKeyCurrentlyDown (const int keyCode) | ||||
| { | { | ||||
| ScopedXDisplay xDisplay; | ScopedXDisplay xDisplay; | ||||
| ::Display* display = xDisplay.get(); | |||||
| if (display == nullptr) | |||||
| return false; | |||||
| int keysym; | |||||
| if (keyCode & Keys::extendedKeyModifier) | |||||
| { | |||||
| keysym = 0xff00 | (keyCode & 0xff); | |||||
| } | |||||
| else | |||||
| if (auto display = xDisplay.display) | |||||
| { | { | ||||
| keysym = keyCode; | |||||
| int keysym; | |||||
| if (keysym == (XK_Tab & 0xff) | |||||
| || keysym == (XK_Return & 0xff) | |||||
| || keysym == (XK_Escape & 0xff) | |||||
| || keysym == (XK_BackSpace & 0xff)) | |||||
| if (keyCode & Keys::extendedKeyModifier) | |||||
| { | { | ||||
| keysym |= 0xff00; | |||||
| keysym = 0xff00 | (keyCode & 0xff); | |||||
| } | } | ||||
| } | |||||
| else | |||||
| { | |||||
| keysym = keyCode; | |||||
| ScopedXLock xlock (display); | |||||
| if (keysym == (XK_Tab & 0xff) | |||||
| || keysym == (XK_Return & 0xff) | |||||
| || keysym == (XK_Escape & 0xff) | |||||
| || keysym == (XK_BackSpace & 0xff)) | |||||
| { | |||||
| keysym |= 0xff00; | |||||
| } | |||||
| } | |||||
| ScopedXLock xlock (display); | |||||
| const int keycode = XKeysymToKeycode (display, (KeySym) keysym); | |||||
| const int keycode = XKeysymToKeycode (display, (KeySym) keysym); | |||||
| const int keybyte = keycode >> 3; | |||||
| const int keybit = (1 << (keycode & 7)); | |||||
| return (Keys::keyStates [keybyte] & keybit) != 0; | |||||
| } | |||||
| const int keybyte = keycode >> 3; | |||||
| const int keybit = (1 << (keycode & 7)); | |||||
| return (Keys::keyStates [keybyte] & keybit) != 0; | |||||
| return false; | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -3798,9 +3799,8 @@ void ModifierKeys::updateCurrentModifiers() noexcept | |||||
| ModifierKeys ModifierKeys::getCurrentModifiersRealtime() noexcept | ModifierKeys ModifierKeys::getCurrentModifiersRealtime() noexcept | ||||
| { | { | ||||
| ScopedXDisplay xDisplay; | ScopedXDisplay xDisplay; | ||||
| ::Display* display = xDisplay.get(); | |||||
| if (display != nullptr) | |||||
| if (auto display = xDisplay.display) | |||||
| { | { | ||||
| Window root, child; | Window root, child; | ||||
| int x, y, winx, winy; | int x, y, winx, winy; | ||||
| @@ -3843,56 +3843,57 @@ ComponentPeer* Component::createNewPeer (int styleFlags, void* nativeWindowToAtt | |||||
| void Desktop::Displays::findDisplays (float masterScale) | void Desktop::Displays::findDisplays (float masterScale) | ||||
| { | { | ||||
| ScopedXDisplay xDisplay; | ScopedXDisplay xDisplay; | ||||
| ::Display* display = xDisplay.get(); | |||||
| DisplayGeometry& geometry = DisplayGeometry::getOrCreateInstance (display, masterScale); | |||||
| // add the main display first | |||||
| int mainDisplayIdx; | |||||
| for (mainDisplayIdx = 0; mainDisplayIdx < geometry.infos.size(); ++mainDisplayIdx) | |||||
| if (auto display = xDisplay.display) | |||||
| { | { | ||||
| const DisplayGeometry::ExtendedInfo& info = geometry.infos.getReference (mainDisplayIdx); | |||||
| if (info.isMain) | |||||
| break; | |||||
| } | |||||
| auto& geometry = DisplayGeometry::getOrCreateInstance (display, masterScale); | |||||
| // no main display found then use the first | |||||
| if (mainDisplayIdx >= geometry.infos.size()) | |||||
| mainDisplayIdx = 0; | |||||
| // add the main display first | |||||
| int mainDisplayIdx; | |||||
| // add the main display | |||||
| { | |||||
| const DisplayGeometry::ExtendedInfo& info = | |||||
| geometry.infos.getReference (mainDisplayIdx); | |||||
| Desktop::Displays::Display d; | |||||
| for (mainDisplayIdx = 0; mainDisplayIdx < geometry.infos.size(); ++mainDisplayIdx) | |||||
| { | |||||
| auto& info = geometry.infos.getReference (mainDisplayIdx); | |||||
| d.isMain = true; | |||||
| d.scale = masterScale * info.scale; | |||||
| d.dpi = info.dpi; | |||||
| if (info.isMain) | |||||
| break; | |||||
| } | |||||
| d.totalArea = DisplayGeometry::physicalToScaled (info.totalBounds); | |||||
| d.userArea = (info.usableBounds / d.scale) + info.topLeftScaled; | |||||
| // no main display found then use the first | |||||
| if (mainDisplayIdx >= geometry.infos.size()) | |||||
| mainDisplayIdx = 0; | |||||
| displays.add (d); | |||||
| } | |||||
| // add the main display | |||||
| { | |||||
| auto& info = geometry.infos.getReference (mainDisplayIdx); | |||||
| for (int i = 0; i < geometry.infos.size(); ++i) | |||||
| { | |||||
| // don't add the main display a second time | |||||
| if (i == mainDisplayIdx) | |||||
| continue; | |||||
| Desktop::Displays::Display d; | |||||
| d.isMain = true; | |||||
| d.scale = masterScale * info.scale; | |||||
| d.dpi = info.dpi; | |||||
| d.totalArea = DisplayGeometry::physicalToScaled (info.totalBounds); | |||||
| d.userArea = (info.usableBounds / d.scale) + info.topLeftScaled; | |||||
| const DisplayGeometry::ExtendedInfo& info = geometry.infos.getReference (i); | |||||
| Desktop::Displays::Display d; | |||||
| displays.add (d); | |||||
| } | |||||
| for (int i = 0; i < geometry.infos.size(); ++i) | |||||
| { | |||||
| // don't add the main display a second time | |||||
| if (i == mainDisplayIdx) | |||||
| continue; | |||||
| d.isMain = false; | |||||
| d.scale = masterScale * info.scale; | |||||
| d.dpi = info.dpi; | |||||
| auto& info = geometry.infos.getReference (i); | |||||
| d.totalArea = DisplayGeometry::physicalToScaled (info.totalBounds); | |||||
| d.userArea = (info.usableBounds / d.scale) + info.topLeftScaled; | |||||
| Desktop::Displays::Display d; | |||||
| d.isMain = false; | |||||
| d.scale = masterScale * info.scale; | |||||
| d.dpi = info.dpi; | |||||
| d.totalArea = DisplayGeometry::physicalToScaled (info.totalBounds); | |||||
| d.userArea = (info.usableBounds / d.scale) + info.topLeftScaled; | |||||
| displays.add (d); | |||||
| displays.add (d); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -3931,10 +3932,10 @@ bool Desktop::canUseSemiTransparentWindows() noexcept | |||||
| Point<float> MouseInputSource::getCurrentRawMousePosition() | Point<float> MouseInputSource::getCurrentRawMousePosition() | ||||
| { | { | ||||
| ScopedXDisplay xDisplay; | ScopedXDisplay xDisplay; | ||||
| ::Display* display = xDisplay.get(); | |||||
| auto display = xDisplay.display; | |||||
| if (display == nullptr) | if (display == nullptr) | ||||
| return Point<float>(); | |||||
| return {}; | |||||
| Window root, child; | Window root, child; | ||||
| int x, y, winx, winy; | int x, y, winx, winy; | ||||
| @@ -3957,9 +3958,8 @@ Point<float> MouseInputSource::getCurrentRawMousePosition() | |||||
| void MouseInputSource::setRawMousePosition (Point<float> newPosition) | void MouseInputSource::setRawMousePosition (Point<float> newPosition) | ||||
| { | { | ||||
| ScopedXDisplay xDisplay; | ScopedXDisplay xDisplay; | ||||
| ::Display* display = xDisplay.get(); | |||||
| if (display != nullptr) | |||||
| if (auto display = xDisplay.display) | |||||
| { | { | ||||
| ScopedXLock xlock (display); | ScopedXLock xlock (display); | ||||
| Window root = RootWindow (display, DefaultScreen (display)); | Window root = RootWindow (display, DefaultScreen (display)); | ||||
| @@ -3988,9 +3988,8 @@ void Desktop::setScreenSaverEnabled (const bool isEnabled) | |||||
| screenSaverAllowed = isEnabled; | screenSaverAllowed = isEnabled; | ||||
| ScopedXDisplay xDisplay; | ScopedXDisplay xDisplay; | ||||
| ::Display* display = xDisplay.get(); | |||||
| if (display != nullptr) | |||||
| if (auto display = xDisplay.display) | |||||
| { | { | ||||
| typedef void (*tXScreenSaverSuspend) (Display*, Bool); | typedef void (*tXScreenSaverSuspend) (Display*, Bool); | ||||
| static tXScreenSaverSuspend xScreenSaverSuspend = nullptr; | static tXScreenSaverSuspend xScreenSaverSuspend = nullptr; | ||||
| @@ -4109,7 +4108,7 @@ int JUCE_CALLTYPE NativeMessageBox::showYesNoBox (AlertWindow::AlertIconType ico | |||||
| void* CustomMouseCursorInfo::create() const | void* CustomMouseCursorInfo::create() const | ||||
| { | { | ||||
| ScopedXDisplay xDisplay; | ScopedXDisplay xDisplay; | ||||
| ::Display* display = xDisplay.get(); | |||||
| auto display = xDisplay.display; | |||||
| if (display == nullptr) | if (display == nullptr) | ||||
| return nullptr; | return nullptr; | ||||
| @@ -4236,20 +4235,22 @@ void* CustomMouseCursorInfo::create() const | |||||
| void MouseCursor::deleteMouseCursor (void* const cursorHandle, const bool) | void MouseCursor::deleteMouseCursor (void* const cursorHandle, const bool) | ||||
| { | { | ||||
| ScopedXDisplay xDisplay; | |||||
| ::Display* display = xDisplay.get(); | |||||
| if (cursorHandle != nullptr && display != nullptr) | |||||
| if (cursorHandler != nullptr) | |||||
| { | { | ||||
| ScopedXLock xlock (display); | |||||
| XFreeCursor (display, (Cursor) cursorHandle); | |||||
| ScopedXDisplay xDisplay; | |||||
| if (auto display = xDisplay.display) | |||||
| { | |||||
| ScopedXLock xlock (display); | |||||
| XFreeCursor (display, (Cursor) cursorHandle); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| void* MouseCursor::createStandardMouseCursor (MouseCursor::StandardCursorType type) | void* MouseCursor::createStandardMouseCursor (MouseCursor::StandardCursorType type) | ||||
| { | { | ||||
| ScopedXDisplay xDisplay; | ScopedXDisplay xDisplay; | ||||
| ::Display* display = xDisplay.get(); | |||||
| auto display = xDisplay.display; | |||||
| if (display == nullptr) | if (display == nullptr) | ||||
| return None; | return None; | ||||
| @@ -31,7 +31,7 @@ public: | |||||
| Pimpl (const Image& im, Window windowH) : image (im) | Pimpl (const Image& im, Window windowH) : image (im) | ||||
| { | { | ||||
| ScopedXDisplay xDisplay; | ScopedXDisplay xDisplay; | ||||
| ::Display* display = xDisplay.get(); | |||||
| auto display = xDisplay.display; | |||||
| ScopedXLock xlock (display); | ScopedXLock xlock (display); | ||||
| @@ -449,7 +449,7 @@ private: | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| Display* getDisplay() { return reinterpret_cast<Display*> (x11display.get()); } | |||||
| Display* getDisplay() { return reinterpret_cast<Display*> (x11display.display); } | |||||
| //============================================================================== | //============================================================================== | ||||
| bool getXEmbedMappedFlag() | bool getXEmbedMappedFlag() | ||||
| @@ -169,8 +169,7 @@ public: | |||||
| static void deactivateCurrentContext() | static void deactivateCurrentContext() | ||||
| { | { | ||||
| ScopedXDisplay xDisplay; | ScopedXDisplay xDisplay; | ||||
| ::Display* display = xDisplay.get(); | |||||
| glXMakeCurrent (display, None, 0); | |||||
| glXMakeCurrent (xDisplay.display, None, 0); | |||||
| } | } | ||||
| void swapBuffers() | void swapBuffers() | ||||
| @@ -245,8 +244,12 @@ private: | |||||
| bool OpenGLHelpers::isContextActive() | bool OpenGLHelpers::isContextActive() | ||||
| { | { | ||||
| ScopedXDisplay xDisplay; | ScopedXDisplay xDisplay; | ||||
| ::Display* display = xDisplay.get(); | |||||
| ScopedXLock xlock (display); | |||||
| return glXGetCurrentContext() != 0; | |||||
| if (auto display = xDisplay.display) | |||||
| { | |||||
| ScopedXLock xlock (xDisplay.display); | |||||
| return glXGetCurrentContext() != 0; | |||||
| } | |||||
| return false; | |||||
| } | } | ||||