|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960 |
- /*
- ==============================================================================
-
- This file is part of the JUCE library.
- Copyright (c) 2022 - Raw Material Software Limited
-
- JUCE is an open source library subject to commercial or open-source
- licensing.
-
- By using JUCE, you agree to the terms of both the JUCE 7 End-User License
- Agreement and JUCE Privacy Policy.
-
- End User License Agreement: www.juce.com/juce-7-licence
- Privacy Policy: www.juce.com/juce-privacy-policy
-
- Or: You may also use this code under the terms of the GPL v3 (see
- www.gnu.org/licenses).
-
- JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
- EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
- DISCLAIMED.
-
- ==============================================================================
- */
-
- namespace juce
- {
-
- //==============================================================================
- static int numAlwaysOnTopPeers = 0;
- bool juce_areThereAnyAlwaysOnTopWindows() { return numAlwaysOnTopPeers > 0; }
-
- //==============================================================================
- class LinuxComponentPeer : public ComponentPeer,
- private XWindowSystemUtilities::XSettings::Listener
- {
- public:
- LinuxComponentPeer (Component& comp, int windowStyleFlags, ::Window parentToAddTo)
- : ComponentPeer (comp, windowStyleFlags),
- isAlwaysOnTop (comp.isAlwaysOnTop())
- {
- // it's dangerous to create a window on a thread other than the message thread.
- JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
-
- const auto* instance = XWindowSystem::getInstance();
-
- if (! instance->isX11Available())
- return;
-
- if (isAlwaysOnTop)
- ++numAlwaysOnTopPeers;
-
- repainter = std::make_unique<LinuxRepaintManager> (*this);
-
- windowH = instance->createWindow (parentToAddTo, this);
- parentWindow = parentToAddTo;
-
- setTitle (component.getName());
-
- if (auto* xSettings = instance->getXSettings())
- xSettings->addListener (this);
-
- getNativeRealtimeModifiers = []() -> ModifierKeys { return XWindowSystem::getInstance()->getNativeRealtimeModifiers(); };
- }
-
- ~LinuxComponentPeer() override
- {
- // it's dangerous to delete a window on a thread other than the message thread.
- JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
-
- auto* instance = XWindowSystem::getInstance();
-
- repainter = nullptr;
- instance->destroyWindow (windowH);
-
- if (auto* xSettings = instance->getXSettings())
- xSettings->removeListener (this);
-
- if (isAlwaysOnTop)
- --numAlwaysOnTopPeers;
- }
-
- ::Window getWindowHandle() const noexcept
- {
- return windowH;
- }
-
- //==============================================================================
- void* getNativeHandle() const override
- {
- return reinterpret_cast<void*> (getWindowHandle());
- }
-
- //==============================================================================
- void forceSetBounds (const Rectangle<int>& correctedNewBounds, bool isNowFullScreen)
- {
- bounds = correctedNewBounds;
-
- updateScaleFactorFromNewBounds (bounds, false);
-
- auto physicalBounds = parentWindow == 0 ? Desktop::getInstance().getDisplays().logicalToPhysical (bounds)
- : bounds * currentScaleFactor;
-
- WeakReference<Component> deletionChecker (&component);
-
- XWindowSystem::getInstance()->setBounds (windowH, physicalBounds, isNowFullScreen);
-
- fullScreen = isNowFullScreen;
-
- if (deletionChecker != nullptr)
- {
- updateBorderSize();
- handleMovedOrResized();
- }
- }
-
- void setBounds (const Rectangle<int>& newBounds, bool isNowFullScreen) override
- {
- const auto correctedNewBounds = newBounds.withSize (jmax (1, newBounds.getWidth()),
- jmax (1, newBounds.getHeight()));
-
- if (bounds != correctedNewBounds || fullScreen != isNowFullScreen)
- forceSetBounds (correctedNewBounds, isNowFullScreen);
- }
-
- Point<int> getScreenPosition (bool physical) const
- {
- auto physicalParentPosition = XWindowSystem::getInstance()->getPhysicalParentScreenPosition();
- auto parentPosition = parentWindow == 0 ? Desktop::getInstance().getDisplays().physicalToLogical (physicalParentPosition)
- : physicalParentPosition / currentScaleFactor;
-
- auto screenBounds = parentWindow == 0 ? bounds
- : bounds.translated (parentPosition.x, parentPosition.y);
-
- if (physical)
- return parentWindow == 0 ? Desktop::getInstance().getDisplays().logicalToPhysical (screenBounds.getTopLeft())
- : screenBounds.getTopLeft() * currentScaleFactor;
-
- return screenBounds.getTopLeft();
- }
-
- Rectangle<int> getBounds() const override
- {
- return bounds;
- }
-
- OptionalBorderSize getFrameSizeIfPresent() const override
- {
- return windowBorder;
- }
-
- BorderSize<int> getFrameSize() const override
- {
- const auto optionalBorderSize = getFrameSizeIfPresent();
- return optionalBorderSize ? (*optionalBorderSize) : BorderSize<int>();
- }
-
- Point<float> localToGlobal (Point<float> relativePosition) override
- {
- return localToGlobal (*this, relativePosition);
- }
-
- Point<float> globalToLocal (Point<float> screenPosition) override
- {
- return globalToLocal (*this, screenPosition);
- }
-
- using ComponentPeer::localToGlobal;
- using ComponentPeer::globalToLocal;
-
- //==============================================================================
- StringArray getAvailableRenderingEngines() override
- {
- return { "Software Renderer" };
- }
-
- void setVisible (bool shouldBeVisible) override
- {
- XWindowSystem::getInstance()->setVisible (windowH, shouldBeVisible);
- }
-
- void setTitle (const String& title) override
- {
- XWindowSystem::getInstance()->setTitle (windowH, title);
- }
-
- void setMinimised (bool shouldBeMinimised) override
- {
- if (shouldBeMinimised)
- XWindowSystem::getInstance()->setMinimised (windowH, shouldBeMinimised);
- else
- setVisible (true);
- }
-
- bool isMinimised() const override
- {
- return XWindowSystem::getInstance()->isMinimised (windowH);
- }
-
- void setFullScreen (bool shouldBeFullScreen) override
- {
- auto r = lastNonFullscreenBounds; // (get a copy of this before de-minimising)
-
- setMinimised (false);
-
- if (fullScreen != shouldBeFullScreen)
- {
- const auto usingNativeTitleBar = ((styleFlags & windowHasTitleBar) != 0);
-
- if (usingNativeTitleBar)
- XWindowSystem::getInstance()->setMaximised (windowH, shouldBeFullScreen);
-
- if (shouldBeFullScreen)
- r = usingNativeTitleBar ? XWindowSystem::getInstance()->getWindowBounds (windowH, parentWindow)
- : Desktop::getInstance().getDisplays().getDisplayForRect (bounds)->userArea;
-
- if (! r.isEmpty())
- setBounds (ScalingHelpers::scaledScreenPosToUnscaled (component, r), shouldBeFullScreen);
-
- component.repaint();
- }
- }
-
- bool isFullScreen() const override
- {
- return fullScreen;
- }
-
- bool contains (Point<int> localPos, bool trueIfInAChildWindow) const override
- {
- if (! bounds.withZeroOrigin().contains (localPos))
- return false;
-
- for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
- {
- auto* c = Desktop::getInstance().getComponent (i);
-
- if (c == &component)
- break;
-
- if (! c->isVisible())
- continue;
-
- auto* otherPeer = c->getPeer();
- jassert (otherPeer == nullptr || dynamic_cast<LinuxComponentPeer*> (c->getPeer()) != nullptr);
-
- if (auto* peer = static_cast<LinuxComponentPeer*> (otherPeer))
- if (peer->contains (globalToLocal (*peer, localToGlobal (*this, localPos.toFloat())).roundToInt(), true))
- return false;
- }
-
- if (trueIfInAChildWindow)
- return true;
-
- return XWindowSystem::getInstance()->contains (windowH, localPos * currentScaleFactor);
- }
-
- void toFront (bool makeActive) override
- {
- if (makeActive)
- {
- setVisible (true);
- grabFocus();
- }
-
- XWindowSystem::getInstance()->toFront (windowH, makeActive);
- handleBroughtToFront();
- }
-
- void toBehind (ComponentPeer* other) override
- {
- if (auto* otherPeer = dynamic_cast<LinuxComponentPeer*> (other))
- {
- if (otherPeer->styleFlags & windowIsTemporary)
- return;
-
- setMinimised (false);
- XWindowSystem::getInstance()->toBehind (windowH, otherPeer->windowH);
- }
- else
- {
- jassertfalse; // wrong type of window?
- }
- }
-
- bool isFocused() const override
- {
- return XWindowSystem::getInstance()->isFocused (windowH);
- }
-
- void grabFocus() override
- {
- if (XWindowSystem::getInstance()->grabFocus (windowH))
- isActiveApplication = true;
- }
-
- //==============================================================================
- void repaint (const Rectangle<int>& area) override
- {
- if (repainter != nullptr)
- repainter->repaint (area.getIntersection (bounds.withZeroOrigin()));
- }
-
- void performAnyPendingRepaintsNow() override
- {
- if (repainter != nullptr)
- repainter->performAnyPendingRepaintsNow();
- }
-
- void setIcon (const Image& newIcon) override
- {
- XWindowSystem::getInstance()->setIcon (windowH, newIcon);
- }
-
- double getPlatformScaleFactor() const noexcept override
- {
- return currentScaleFactor;
- }
-
- void setAlpha (float) override {}
- bool setAlwaysOnTop (bool) override { return false; }
- void textInputRequired (Point<int>, TextInputTarget&) override {}
-
- //==============================================================================
- void addOpenGLRepaintListener (Component* dummy)
- {
- if (dummy != nullptr)
- glRepaintListeners.addIfNotAlreadyThere (dummy);
- }
-
- void removeOpenGLRepaintListener (Component* dummy)
- {
- if (dummy != nullptr)
- glRepaintListeners.removeAllInstancesOf (dummy);
- }
-
- void repaintOpenGLContexts()
- {
- for (auto* c : glRepaintListeners)
- c->handleCommandMessage (0);
- }
-
- //==============================================================================
- ::Window getParentWindow() { return parentWindow; }
- void setParentWindow (::Window newParent) { parentWindow = newParent; }
-
- //==============================================================================
- bool isConstrainedNativeWindow() const
- {
- return constrainer != nullptr
- && (styleFlags & (windowHasTitleBar | windowIsResizable)) == (windowHasTitleBar | windowIsResizable)
- && ! isKioskMode();
- }
-
- void updateWindowBounds()
- {
- if (windowH == 0)
- {
- jassertfalse;
- return;
- }
-
- if (isConstrainedNativeWindow())
- XWindowSystem::getInstance()->updateConstraints (windowH);
-
- auto physicalBounds = XWindowSystem::getInstance()->getWindowBounds (windowH, parentWindow);
-
- updateScaleFactorFromNewBounds (physicalBounds, true);
-
- bounds = parentWindow == 0 ? Desktop::getInstance().getDisplays().physicalToLogical (physicalBounds)
- : physicalBounds / currentScaleFactor;
- }
-
- void updateBorderSize()
- {
- if ((styleFlags & windowHasTitleBar) == 0)
- {
- windowBorder = ComponentPeer::OptionalBorderSize { BorderSize<int>() };
- }
- else if (! windowBorder
- || ((*windowBorder).getTopAndBottom() == 0 && (*windowBorder).getLeftAndRight() == 0))
- {
- windowBorder = [&]()
- {
- if (auto unscaledBorderSize = XWindowSystem::getInstance()->getBorderSize (windowH))
- return OptionalBorderSize { (*unscaledBorderSize).multipliedBy (1.0 / currentScaleFactor) };
-
- return OptionalBorderSize {};
- }();
- }
- }
-
- //==============================================================================
- static bool isActiveApplication;
- bool focused = false;
-
- private:
- //==============================================================================
- class LinuxRepaintManager : public Timer
- {
- public:
- LinuxRepaintManager (LinuxComponentPeer& p)
- : peer (p),
- isSemiTransparentWindow ((peer.getStyleFlags() & ComponentPeer::windowIsSemiTransparent) != 0)
- {
- }
-
- void timerCallback() override
- {
- XWindowSystem::getInstance()->processPendingPaintsForWindow (peer.windowH);
-
- if (XWindowSystem::getInstance()->getNumPaintsPendingForWindow (peer.windowH) > 0)
- return;
-
- if (! regionsNeedingRepaint.isEmpty())
- {
- stopTimer();
- performAnyPendingRepaintsNow();
- }
- else if (Time::getApproximateMillisecondCounter() > lastTimeImageUsed + 3000)
- {
- stopTimer();
- image = Image();
- }
- }
-
- void repaint (Rectangle<int> area)
- {
- if (! isTimerRunning())
- startTimer (repaintTimerPeriod);
-
- regionsNeedingRepaint.add (area * peer.currentScaleFactor);
- }
-
- void performAnyPendingRepaintsNow()
- {
- if (XWindowSystem::getInstance()->getNumPaintsPendingForWindow (peer.windowH) > 0)
- {
- startTimer (repaintTimerPeriod);
- return;
- }
-
- auto originalRepaintRegion = regionsNeedingRepaint;
- regionsNeedingRepaint.clear();
- auto totalArea = originalRepaintRegion.getBounds();
-
- if (! totalArea.isEmpty())
- {
- const auto wasImageNull = image.isNull();
-
- if (wasImageNull || image.getWidth() < totalArea.getWidth()
- || image.getHeight() < totalArea.getHeight())
- {
- image = XWindowSystem::getInstance()->createImage (isSemiTransparentWindow,
- totalArea.getWidth(), totalArea.getHeight(),
- useARGBImagesForRendering);
- if (wasImageNull)
- {
- // After calling createImage() XWindowSystem::getWindowBounds() will return
- // changed coordinates that look like the result of some position
- // defaulting mechanism. If we handle a configureNotifyEvent after
- // createImage() and before we would issue new, valid coordinates, we will
- // apply these default, unwanted coordinates to our window. To avoid that
- // we immediately send another positioning message to guarantee that the
- // next configureNotifyEvent will read valid values.
- //
- // This issue only occurs right after peer creation, when the image is
- // null. Updating when only the width or height is changed would lead to
- // incorrect behaviour.
- peer.forceSetBounds (ScalingHelpers::scaledScreenPosToUnscaled (peer.component,
- peer.component.getBoundsInParent()),
- peer.isFullScreen());
- }
- }
-
- startTimer (repaintTimerPeriod);
-
- RectangleList<int> adjustedList (originalRepaintRegion);
- adjustedList.offsetAll (-totalArea.getX(), -totalArea.getY());
-
- if (XWindowSystem::getInstance()->canUseARGBImages())
- for (auto& i : originalRepaintRegion)
- image.clear (i - totalArea.getPosition());
-
- {
- auto context = peer.getComponent().getLookAndFeel()
- .createGraphicsContext (image, -totalArea.getPosition(), adjustedList);
-
- context->addTransform (AffineTransform::scale ((float) peer.currentScaleFactor));
- peer.handlePaint (*context);
- }
-
- for (auto& i : originalRepaintRegion)
- XWindowSystem::getInstance()->blitToWindow (peer.windowH, image, i, totalArea);
- }
-
- lastTimeImageUsed = Time::getApproximateMillisecondCounter();
- startTimer (repaintTimerPeriod);
- }
-
- private:
- enum { repaintTimerPeriod = 1000 / 100 };
-
- LinuxComponentPeer& peer;
- const bool isSemiTransparentWindow;
- Image image;
- uint32 lastTimeImageUsed = 0;
- RectangleList<int> regionsNeedingRepaint;
-
- bool useARGBImagesForRendering = XWindowSystem::getInstance()->canUseARGBImages();
-
- JUCE_DECLARE_NON_COPYABLE (LinuxRepaintManager)
- };
-
- //==============================================================================
- template <typename This>
- static Point<float> localToGlobal (This& t, Point<float> relativePosition)
- {
- return relativePosition + t.getScreenPosition (false).toFloat();
- }
-
- template <typename This>
- static Point<float> globalToLocal (This& t, Point<float> screenPosition)
- {
- return screenPosition - t.getScreenPosition (false).toFloat();
- }
-
- //==============================================================================
- void settingChanged (const XWindowSystemUtilities::XSetting& settingThatHasChanged) override
- {
- static StringArray possibleSettings { XWindowSystem::getWindowScalingFactorSettingName(),
- "Gdk/UnscaledDPI",
- "Xft/DPI" };
-
- if (possibleSettings.contains (settingThatHasChanged.name))
- forceDisplayUpdate();
- }
-
- void updateScaleFactorFromNewBounds (const Rectangle<int>& newBounds, bool isPhysical)
- {
- Point<int> translation = (parentWindow != 0 ? getScreenPosition (isPhysical) : Point<int>());
- const auto& desktop = Desktop::getInstance();
-
- if (auto* display = desktop.getDisplays().getDisplayForRect (newBounds.translated (translation.x, translation.y),
- isPhysical))
- {
- auto newScaleFactor = display->scale / desktop.getGlobalScaleFactor();
-
- if (! approximatelyEqual (newScaleFactor, currentScaleFactor))
- {
- currentScaleFactor = newScaleFactor;
- scaleFactorListeners.call ([&] (ScaleFactorListener& l) { l.nativeScaleFactorChanged (currentScaleFactor); });
- }
- }
- }
-
- //==============================================================================
- std::unique_ptr<LinuxRepaintManager> repainter;
-
- ::Window windowH = {}, parentWindow = {};
- Rectangle<int> bounds;
- ComponentPeer::OptionalBorderSize windowBorder;
- bool fullScreen = false, isAlwaysOnTop = false;
- double currentScaleFactor = 1.0;
- Array<Component*> glRepaintListeners;
-
- //==============================================================================
- JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LinuxComponentPeer)
- };
-
- bool LinuxComponentPeer::isActiveApplication = false;
-
- //==============================================================================
- ComponentPeer* Component::createNewPeer (int styleFlags, void* nativeWindowToAttachTo)
- {
- return new LinuxComponentPeer (*this, styleFlags, (::Window) nativeWindowToAttachTo);
- }
-
- //==============================================================================
- JUCE_API bool JUCE_CALLTYPE Process::isForegroundProcess() { return LinuxComponentPeer::isActiveApplication; }
-
- JUCE_API void JUCE_CALLTYPE Process::makeForegroundProcess() {}
- JUCE_API void JUCE_CALLTYPE Process::hide() {}
-
- //==============================================================================
- void Desktop::setKioskComponent (Component* comp, bool enableOrDisable, bool)
- {
- if (enableOrDisable)
- comp->setBounds (getDisplays().getDisplayForRect (comp->getScreenBounds())->totalArea);
- }
-
- void Displays::findDisplays (float masterScale)
- {
- if (XWindowSystem::getInstance()->getDisplay() != nullptr)
- {
- displays = XWindowSystem::getInstance()->findDisplays (masterScale);
-
- if (! displays.isEmpty())
- updateToLogical();
- }
- }
-
- bool Desktop::canUseSemiTransparentWindows() noexcept
- {
- return XWindowSystem::getInstance()->canUseSemiTransparentWindows();
- }
-
- class Desktop::NativeDarkModeChangeDetectorImpl : private XWindowSystemUtilities::XSettings::Listener
- {
- public:
- NativeDarkModeChangeDetectorImpl()
- {
- const auto* windowSystem = XWindowSystem::getInstance();
-
- if (auto* xSettings = windowSystem->getXSettings())
- xSettings->addListener (this);
-
- darkModeEnabled = windowSystem->isDarkModeActive();
- }
-
- ~NativeDarkModeChangeDetectorImpl() override
- {
- if (auto* windowSystem = XWindowSystem::getInstanceWithoutCreating())
- if (auto* xSettings = windowSystem->getXSettings())
- xSettings->removeListener (this);
- }
-
- bool isDarkModeEnabled() const noexcept { return darkModeEnabled; }
-
- private:
- void settingChanged (const XWindowSystemUtilities::XSetting& settingThatHasChanged) override
- {
- if (settingThatHasChanged.name == XWindowSystem::getThemeNameSettingName())
- {
- const auto wasDarkModeEnabled = std::exchange (darkModeEnabled, XWindowSystem::getInstance()->isDarkModeActive());
-
- if (darkModeEnabled != wasDarkModeEnabled)
- Desktop::getInstance().darkModeChanged();
- }
- }
-
- bool darkModeEnabled = false;
-
- JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NativeDarkModeChangeDetectorImpl)
- };
-
- std::unique_ptr<Desktop::NativeDarkModeChangeDetectorImpl> Desktop::createNativeDarkModeChangeDetectorImpl()
- {
- return std::make_unique<NativeDarkModeChangeDetectorImpl>();
- }
-
- bool Desktop::isDarkModeActive() const
- {
- return nativeDarkModeChangeDetectorImpl->isDarkModeEnabled();
- }
-
- static bool screenSaverAllowed = true;
-
- void Desktop::setScreenSaverEnabled (bool isEnabled)
- {
- if (screenSaverAllowed != isEnabled)
- {
- screenSaverAllowed = isEnabled;
- XWindowSystem::getInstance()->setScreenSaverEnabled (screenSaverAllowed);
- }
- }
-
- bool Desktop::isScreenSaverEnabled()
- {
- return screenSaverAllowed;
- }
-
- double Desktop::getDefaultMasterScale() { return 1.0; }
-
- Desktop::DisplayOrientation Desktop::getCurrentOrientation() const { return upright; }
- void Desktop::allowedOrientationsChanged() {}
-
- //==============================================================================
- bool MouseInputSource::SourceList::addSource()
- {
- if (sources.isEmpty())
- {
- addSource (0, MouseInputSource::InputSourceType::mouse);
- return true;
- }
-
- return false;
- }
-
- bool MouseInputSource::SourceList::canUseTouch()
- {
- return false;
- }
-
- Point<float> MouseInputSource::getCurrentRawMousePosition()
- {
- return Desktop::getInstance().getDisplays().physicalToLogical (XWindowSystem::getInstance()->getCurrentMousePosition());
- }
-
- void MouseInputSource::setRawMousePosition (Point<float> newPosition)
- {
- XWindowSystem::getInstance()->setMousePosition (Desktop::getInstance().getDisplays().logicalToPhysical (newPosition));
- }
-
- //==============================================================================
- class MouseCursor::PlatformSpecificHandle
- {
- public:
- explicit PlatformSpecificHandle (const MouseCursor::StandardCursorType type)
- : cursorHandle (makeHandle (type)) {}
-
- explicit PlatformSpecificHandle (const CustomMouseCursorInfo& info)
- : cursorHandle (makeHandle (info)) {}
-
- ~PlatformSpecificHandle()
- {
- if (cursorHandle != Cursor{})
- XWindowSystem::getInstance()->deleteMouseCursor (cursorHandle);
- }
-
- static void showInWindow (PlatformSpecificHandle* handle, ComponentPeer* peer)
- {
- const auto cursor = handle != nullptr ? handle->cursorHandle : Cursor{};
-
- if (peer != nullptr)
- XWindowSystem::getInstance()->showCursor ((::Window) peer->getNativeHandle(), cursor);
- }
-
- private:
- static Cursor makeHandle (const CustomMouseCursorInfo& info)
- {
- const auto image = info.image.getImage();
- return XWindowSystem::getInstance()->createCustomMouseCursorInfo (image.rescaled ((int) (image.getWidth() / info.image.getScale()),
- (int) (image.getHeight() / info.image.getScale())), info.hotspot);
- }
-
- static Cursor makeHandle (MouseCursor::StandardCursorType type)
- {
- return XWindowSystem::getInstance()->createStandardMouseCursor (type);
- }
-
- Cursor cursorHandle;
-
- //==============================================================================
- JUCE_DECLARE_NON_COPYABLE (PlatformSpecificHandle)
- JUCE_DECLARE_NON_MOVEABLE (PlatformSpecificHandle)
- };
-
- //==============================================================================
- static LinuxComponentPeer* getPeerForDragEvent (Component* sourceComp)
- {
- if (sourceComp == nullptr)
- if (auto* draggingSource = Desktop::getInstance().getDraggingMouseSource (0))
- sourceComp = draggingSource->getComponentUnderMouse();
-
- if (sourceComp != nullptr)
- if (auto* lp = dynamic_cast<LinuxComponentPeer*> (sourceComp->getPeer()))
- return lp;
-
- jassertfalse; // This method must be called in response to a component's mouseDown or mouseDrag event!
- return nullptr;
- }
-
- bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, bool canMoveFiles,
- Component* sourceComp, std::function<void()> callback)
- {
- if (files.isEmpty())
- return false;
-
- if (auto* peer = getPeerForDragEvent (sourceComp))
- return XWindowSystem::getInstance()->externalDragFileInit (peer, files, canMoveFiles, std::move (callback));
-
- // This method must be called in response to a component's mouseDown or mouseDrag event!
- jassertfalse;
- return false;
- }
-
- bool DragAndDropContainer::performExternalDragDropOfText (const String& text, Component* sourceComp,
- std::function<void()> callback)
- {
- if (text.isEmpty())
- return false;
-
- if (auto* peer = getPeerForDragEvent (sourceComp))
- return XWindowSystem::getInstance()->externalDragTextInit (peer, text, std::move (callback));
-
- // This method must be called in response to a component's mouseDown or mouseDrag event!
- jassertfalse;
- return false;
- }
-
- //==============================================================================
- void SystemClipboard::copyTextToClipboard (const String& clipText)
- {
- XWindowSystem::getInstance()->copyTextToClipboard (clipText);
- }
-
- String SystemClipboard::getTextFromClipboard()
- {
- return XWindowSystem::getInstance()->getTextFromClipboard();
- }
-
- //==============================================================================
- bool KeyPress::isKeyCurrentlyDown (int keyCode)
- {
- return XWindowSystem::getInstance()->isKeyCurrentlyDown (keyCode);
- }
-
- void LookAndFeel::playAlertSound()
- {
- std::cout << "\a" << std::flush;
- }
-
- //==============================================================================
- static int showDialog (const MessageBoxOptions& options,
- ModalComponentManager::Callback* callback,
- Async async)
- {
- const auto dummyCallback = [] (int) {};
-
- switch (options.getNumButtons())
- {
- case 2:
- {
- if (async == Async::yes && callback == nullptr)
- callback = ModalCallbackFunction::create (dummyCallback);
-
- return AlertWindow::showOkCancelBox (options.getIconType(),
- options.getTitle(),
- options.getMessage(),
- options.getButtonText (0),
- options.getButtonText (1),
- options.getAssociatedComponent(),
- callback) ? 1 : 0;
- }
-
- case 3:
- {
- if (async == Async::yes && callback == nullptr)
- callback = ModalCallbackFunction::create (dummyCallback);
-
- return AlertWindow::showYesNoCancelBox (options.getIconType(),
- options.getTitle(),
- options.getMessage(),
- options.getButtonText (0),
- options.getButtonText (1),
- options.getButtonText (2),
- options.getAssociatedComponent(),
- callback);
- }
-
- case 1:
- default:
- break;
- }
-
- #if JUCE_MODAL_LOOPS_PERMITTED
- if (async == Async::no)
- {
- AlertWindow::showMessageBox (options.getIconType(),
- options.getTitle(),
- options.getMessage(),
- options.getButtonText (0),
- options.getAssociatedComponent());
- }
- else
- #endif
- {
- AlertWindow::showMessageBoxAsync (options.getIconType(),
- options.getTitle(),
- options.getMessage(),
- options.getButtonText (0),
- options.getAssociatedComponent(),
- callback);
- }
-
- return 0;
- }
-
- #if JUCE_MODAL_LOOPS_PERMITTED
- void JUCE_CALLTYPE NativeMessageBox::showMessageBox (MessageBoxIconType iconType,
- const String& title, const String& message,
- Component* /*associatedComponent*/)
- {
- AlertWindow::showMessageBox (iconType, title, message);
- }
-
- int JUCE_CALLTYPE NativeMessageBox::show (const MessageBoxOptions& options)
- {
- return showDialog (options, nullptr, Async::no);
- }
- #endif
-
- void JUCE_CALLTYPE NativeMessageBox::showMessageBoxAsync (MessageBoxIconType iconType,
- const String& title, const String& message,
- Component* associatedComponent,
- ModalComponentManager::Callback* callback)
- {
- AlertWindow::showMessageBoxAsync (iconType, title, message, {}, associatedComponent, callback);
- }
-
- bool JUCE_CALLTYPE NativeMessageBox::showOkCancelBox (MessageBoxIconType iconType,
- const String& title, const String& message,
- Component* associatedComponent,
- ModalComponentManager::Callback* callback)
- {
- return AlertWindow::showOkCancelBox (iconType, title, message, {}, {}, associatedComponent, callback);
- }
-
- int JUCE_CALLTYPE NativeMessageBox::showYesNoCancelBox (MessageBoxIconType iconType,
- const String& title, const String& message,
- Component* associatedComponent,
- ModalComponentManager::Callback* callback)
- {
- return AlertWindow::showYesNoCancelBox (iconType, title, message, {}, {}, {},
- associatedComponent, callback);
- }
-
- int JUCE_CALLTYPE NativeMessageBox::showYesNoBox (MessageBoxIconType iconType,
- const String& title, const String& message,
- Component* associatedComponent,
- ModalComponentManager::Callback* callback)
- {
- return AlertWindow::showOkCancelBox (iconType, title, message, TRANS("Yes"), TRANS("No"),
- associatedComponent, callback);
- }
-
- void JUCE_CALLTYPE NativeMessageBox::showAsync (const MessageBoxOptions& options,
- ModalComponentManager::Callback* callback)
- {
- showDialog (options, callback, Async::yes);
- }
-
- void JUCE_CALLTYPE NativeMessageBox::showAsync (const MessageBoxOptions& options,
- std::function<void (int)> callback)
- {
- showAsync (options, ModalCallbackFunction::create (callback));
- }
-
- //==============================================================================
- Image juce_createIconForFile (const File&)
- {
- return {};
- }
-
- void juce_LinuxAddRepaintListener (ComponentPeer* peer, Component* dummy);
- void juce_LinuxAddRepaintListener (ComponentPeer* peer, Component* dummy)
- {
- if (auto* linuxPeer = dynamic_cast<LinuxComponentPeer*> (peer))
- linuxPeer->addOpenGLRepaintListener (dummy);
- }
-
- void juce_LinuxRemoveRepaintListener (ComponentPeer* peer, Component* dummy);
- void juce_LinuxRemoveRepaintListener (ComponentPeer* peer, Component* dummy)
- {
- if (auto* linuxPeer = dynamic_cast<LinuxComponentPeer*> (peer))
- linuxPeer->removeOpenGLRepaintListener (dummy);
- }
-
- } // namespace juce
|