The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

871 lines
31KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. static int numAlwaysOnTopPeers = 0;
  22. bool juce_areThereAnyAlwaysOnTopWindows() { return numAlwaysOnTopPeers > 0; }
  23. //==============================================================================
  24. class LinuxComponentPeer : public ComponentPeer,
  25. private XWindowSystemUtilities::XSettings::Listener
  26. {
  27. public:
  28. LinuxComponentPeer (Component& comp, int windowStyleFlags, ::Window parentToAddTo)
  29. : ComponentPeer (comp, windowStyleFlags),
  30. isAlwaysOnTop (comp.isAlwaysOnTop())
  31. {
  32. // it's dangerous to create a window on a thread other than the message thread.
  33. JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
  34. const auto* instance = XWindowSystem::getInstance();
  35. if (! instance->isX11Available())
  36. return;
  37. if (isAlwaysOnTop)
  38. ++numAlwaysOnTopPeers;
  39. repainter = std::make_unique<LinuxRepaintManager> (*this);
  40. windowH = instance->createWindow (parentToAddTo, this);
  41. parentWindow = parentToAddTo;
  42. setTitle (component.getName());
  43. if (auto* xSettings = instance->getXSettings())
  44. xSettings->addListener (this);
  45. getNativeRealtimeModifiers = []() -> ModifierKeys { return XWindowSystem::getInstance()->getNativeRealtimeModifiers(); };
  46. }
  47. ~LinuxComponentPeer() override
  48. {
  49. // it's dangerous to delete a window on a thread other than the message thread.
  50. JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
  51. auto* instance = XWindowSystem::getInstance();
  52. repainter = nullptr;
  53. instance->destroyWindow (windowH);
  54. if (auto* xSettings = instance->getXSettings())
  55. xSettings->removeListener (this);
  56. if (isAlwaysOnTop)
  57. --numAlwaysOnTopPeers;
  58. }
  59. ::Window getWindowHandle() const noexcept
  60. {
  61. return windowH;
  62. }
  63. //==============================================================================
  64. void* getNativeHandle() const override
  65. {
  66. return reinterpret_cast<void*> (getWindowHandle());
  67. }
  68. //==============================================================================
  69. void setBounds (const Rectangle<int>& newBounds, bool isNowFullScreen) override
  70. {
  71. const auto correctedNewBounds = newBounds.withSize (jmax (1, newBounds.getWidth()),
  72. jmax (1, newBounds.getHeight()));
  73. if (bounds == correctedNewBounds && fullScreen == isNowFullScreen)
  74. return;
  75. bounds = correctedNewBounds;
  76. updateScaleFactorFromNewBounds (bounds, false);
  77. auto physicalBounds = parentWindow == 0 ? Desktop::getInstance().getDisplays().logicalToPhysical (bounds)
  78. : bounds * currentScaleFactor;
  79. WeakReference<Component> deletionChecker (&component);
  80. XWindowSystem::getInstance()->setBounds (windowH, physicalBounds, isNowFullScreen);
  81. fullScreen = isNowFullScreen;
  82. if (deletionChecker != nullptr)
  83. {
  84. updateBorderSize();
  85. handleMovedOrResized();
  86. }
  87. }
  88. Point<int> getScreenPosition (bool physical) const
  89. {
  90. auto physicalParentPosition = XWindowSystem::getInstance()->getPhysicalParentScreenPosition();
  91. auto parentPosition = parentWindow == 0 ? Desktop::getInstance().getDisplays().physicalToLogical (physicalParentPosition)
  92. : physicalParentPosition / currentScaleFactor;
  93. auto screenBounds = parentWindow == 0 ? bounds
  94. : bounds.translated (parentPosition.x, parentPosition.y);
  95. if (physical)
  96. return parentWindow == 0 ? Desktop::getInstance().getDisplays().logicalToPhysical (screenBounds.getTopLeft())
  97. : screenBounds.getTopLeft() * currentScaleFactor;
  98. return screenBounds.getTopLeft();
  99. }
  100. Rectangle<int> getBounds() const override
  101. {
  102. return bounds;
  103. }
  104. BorderSize<int> getFrameSize() const override
  105. {
  106. return windowBorder;
  107. }
  108. Point<float> localToGlobal (Point<float> relativePosition) override
  109. {
  110. return relativePosition + getScreenPosition (false).toFloat();
  111. }
  112. Point<float> globalToLocal (Point<float> screenPosition) override
  113. {
  114. return screenPosition - getScreenPosition (false).toFloat();
  115. }
  116. using ComponentPeer::localToGlobal;
  117. using ComponentPeer::globalToLocal;
  118. //==============================================================================
  119. StringArray getAvailableRenderingEngines() override
  120. {
  121. return { "Software Renderer" };
  122. }
  123. void setVisible (bool shouldBeVisible) override
  124. {
  125. XWindowSystem::getInstance()->setVisible (windowH, shouldBeVisible);
  126. }
  127. void setTitle (const String& title) override
  128. {
  129. XWindowSystem::getInstance()->setTitle (windowH, title);
  130. }
  131. void setMinimised (bool shouldBeMinimised) override
  132. {
  133. if (shouldBeMinimised)
  134. XWindowSystem::getInstance()->setMinimised (windowH, shouldBeMinimised);
  135. else
  136. setVisible (true);
  137. }
  138. bool isMinimised() const override
  139. {
  140. return XWindowSystem::getInstance()->isMinimised (windowH);
  141. }
  142. void setFullScreen (bool shouldBeFullScreen) override
  143. {
  144. auto r = lastNonFullscreenBounds; // (get a copy of this before de-minimising)
  145. setMinimised (false);
  146. if (fullScreen != shouldBeFullScreen)
  147. {
  148. const auto usingNativeTitleBar = ((styleFlags & windowHasTitleBar) != 0);
  149. if (usingNativeTitleBar)
  150. XWindowSystem::getInstance()->setMaximised (windowH, shouldBeFullScreen);
  151. if (shouldBeFullScreen)
  152. r = usingNativeTitleBar ? XWindowSystem::getInstance()->getWindowBounds (windowH, parentWindow)
  153. : Desktop::getInstance().getDisplays().getDisplayForRect (bounds)->userArea;
  154. if (! r.isEmpty())
  155. setBounds (ScalingHelpers::scaledScreenPosToUnscaled (component, r), shouldBeFullScreen);
  156. component.repaint();
  157. }
  158. }
  159. bool isFullScreen() const override
  160. {
  161. return fullScreen;
  162. }
  163. bool contains (Point<int> localPos, bool trueIfInAChildWindow) const override
  164. {
  165. if (! bounds.withZeroOrigin().contains (localPos))
  166. return false;
  167. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  168. {
  169. auto* c = Desktop::getInstance().getComponent (i);
  170. if (c == &component)
  171. break;
  172. if (! c->isVisible())
  173. continue;
  174. if (auto* peer = c->getPeer())
  175. if (peer->contains (localPos + bounds.getPosition() - peer->getBounds().getPosition(), true))
  176. return false;
  177. }
  178. if (trueIfInAChildWindow)
  179. return true;
  180. return XWindowSystem::getInstance()->contains (windowH, localPos * currentScaleFactor);
  181. }
  182. void toFront (bool makeActive) override
  183. {
  184. if (makeActive)
  185. {
  186. setVisible (true);
  187. grabFocus();
  188. }
  189. XWindowSystem::getInstance()->toFront (windowH, makeActive);
  190. handleBroughtToFront();
  191. }
  192. void toBehind (ComponentPeer* other) override
  193. {
  194. if (auto* otherPeer = dynamic_cast<LinuxComponentPeer*> (other))
  195. {
  196. if (otherPeer->styleFlags & windowIsTemporary)
  197. return;
  198. setMinimised (false);
  199. XWindowSystem::getInstance()->toBehind (windowH, otherPeer->windowH);
  200. }
  201. else
  202. {
  203. jassertfalse; // wrong type of window?
  204. }
  205. }
  206. bool isFocused() const override
  207. {
  208. return XWindowSystem::getInstance()->isFocused (windowH);
  209. }
  210. void grabFocus() override
  211. {
  212. if (XWindowSystem::getInstance()->grabFocus (windowH))
  213. isActiveApplication = true;
  214. }
  215. //==============================================================================
  216. void repaint (const Rectangle<int>& area) override
  217. {
  218. if (repainter != nullptr)
  219. repainter->repaint (area.getIntersection (bounds.withZeroOrigin()));
  220. }
  221. void performAnyPendingRepaintsNow() override
  222. {
  223. if (repainter != nullptr)
  224. repainter->performAnyPendingRepaintsNow();
  225. }
  226. void setIcon (const Image& newIcon) override
  227. {
  228. XWindowSystem::getInstance()->setIcon (windowH, newIcon);
  229. }
  230. double getPlatformScaleFactor() const noexcept override
  231. {
  232. return currentScaleFactor;
  233. }
  234. void setAlpha (float) override {}
  235. bool setAlwaysOnTop (bool) override { return false; }
  236. void textInputRequired (Point<int>, TextInputTarget&) override {}
  237. //==============================================================================
  238. void addOpenGLRepaintListener (Component* dummy)
  239. {
  240. if (dummy != nullptr)
  241. glRepaintListeners.addIfNotAlreadyThere (dummy);
  242. }
  243. void removeOpenGLRepaintListener (Component* dummy)
  244. {
  245. if (dummy != nullptr)
  246. glRepaintListeners.removeAllInstancesOf (dummy);
  247. }
  248. void repaintOpenGLContexts()
  249. {
  250. for (auto* c : glRepaintListeners)
  251. c->handleCommandMessage (0);
  252. }
  253. //==============================================================================
  254. ::Window getParentWindow() { return parentWindow; }
  255. void setParentWindow (::Window newParent) { parentWindow = newParent; }
  256. //==============================================================================
  257. void updateWindowBounds()
  258. {
  259. jassert (windowH != 0);
  260. if (windowH != 0)
  261. {
  262. auto physicalBounds = XWindowSystem::getInstance()->getWindowBounds (windowH, parentWindow);
  263. updateScaleFactorFromNewBounds (physicalBounds, true);
  264. bounds = parentWindow == 0 ? Desktop::getInstance().getDisplays().physicalToLogical (physicalBounds)
  265. : physicalBounds / currentScaleFactor;
  266. }
  267. }
  268. void updateBorderSize()
  269. {
  270. if ((styleFlags & windowHasTitleBar) == 0)
  271. windowBorder = {};
  272. else if (windowBorder.getTopAndBottom() == 0 && windowBorder.getLeftAndRight() == 0)
  273. windowBorder = XWindowSystem::getInstance()->getBorderSize (windowH);
  274. }
  275. //==============================================================================
  276. static bool isActiveApplication;
  277. bool focused = false;
  278. private:
  279. //==============================================================================
  280. class LinuxRepaintManager : public Timer
  281. {
  282. public:
  283. LinuxRepaintManager (LinuxComponentPeer& p)
  284. : peer (p),
  285. isSemiTransparentWindow ((peer.getStyleFlags() & ComponentPeer::windowIsSemiTransparent) != 0)
  286. {
  287. }
  288. void timerCallback() override
  289. {
  290. XWindowSystem::getInstance()->processPendingPaintsForWindow (peer.windowH);
  291. if (XWindowSystem::getInstance()->getNumPaintsPendingForWindow (peer.windowH) > 0)
  292. return;
  293. if (! regionsNeedingRepaint.isEmpty())
  294. {
  295. stopTimer();
  296. performAnyPendingRepaintsNow();
  297. }
  298. else if (Time::getApproximateMillisecondCounter() > lastTimeImageUsed + 3000)
  299. {
  300. stopTimer();
  301. image = Image();
  302. }
  303. }
  304. void repaint (Rectangle<int> area)
  305. {
  306. if (! isTimerRunning())
  307. startTimer (repaintTimerPeriod);
  308. regionsNeedingRepaint.add (area * peer.currentScaleFactor);
  309. }
  310. void performAnyPendingRepaintsNow()
  311. {
  312. if (XWindowSystem::getInstance()->getNumPaintsPendingForWindow (peer.windowH) > 0)
  313. {
  314. startTimer (repaintTimerPeriod);
  315. return;
  316. }
  317. auto originalRepaintRegion = regionsNeedingRepaint;
  318. regionsNeedingRepaint.clear();
  319. auto totalArea = originalRepaintRegion.getBounds();
  320. if (! totalArea.isEmpty())
  321. {
  322. if (image.isNull() || image.getWidth() < totalArea.getWidth()
  323. || image.getHeight() < totalArea.getHeight())
  324. {
  325. image = XWindowSystem::getInstance()->createImage (isSemiTransparentWindow,
  326. totalArea.getWidth(), totalArea.getHeight(),
  327. useARGBImagesForRendering);
  328. }
  329. startTimer (repaintTimerPeriod);
  330. RectangleList<int> adjustedList (originalRepaintRegion);
  331. adjustedList.offsetAll (-totalArea.getX(), -totalArea.getY());
  332. if (XWindowSystem::getInstance()->canUseARGBImages())
  333. for (auto& i : originalRepaintRegion)
  334. image.clear (i - totalArea.getPosition());
  335. {
  336. auto context = peer.getComponent().getLookAndFeel()
  337. .createGraphicsContext (image, -totalArea.getPosition(), adjustedList);
  338. context->addTransform (AffineTransform::scale ((float) peer.currentScaleFactor));
  339. peer.handlePaint (*context);
  340. }
  341. for (auto& i : originalRepaintRegion)
  342. XWindowSystem::getInstance()->blitToWindow (peer.windowH, image, i, totalArea);
  343. }
  344. lastTimeImageUsed = Time::getApproximateMillisecondCounter();
  345. startTimer (repaintTimerPeriod);
  346. }
  347. private:
  348. enum { repaintTimerPeriod = 1000 / 100 };
  349. LinuxComponentPeer& peer;
  350. const bool isSemiTransparentWindow;
  351. Image image;
  352. uint32 lastTimeImageUsed = 0;
  353. RectangleList<int> regionsNeedingRepaint;
  354. bool useARGBImagesForRendering = XWindowSystem::getInstance()->canUseARGBImages();
  355. JUCE_DECLARE_NON_COPYABLE (LinuxRepaintManager)
  356. };
  357. //==============================================================================
  358. void settingChanged (const XWindowSystemUtilities::XSetting& settingThatHasChanged) override
  359. {
  360. static StringArray possibleSettings { XWindowSystem::getWindowScalingFactorSettingName(),
  361. "Gdk/UnscaledDPI",
  362. "Xft/DPI" };
  363. if (possibleSettings.contains (settingThatHasChanged.name))
  364. forceDisplayUpdate();
  365. }
  366. void updateScaleFactorFromNewBounds (const Rectangle<int>& newBounds, bool isPhysical)
  367. {
  368. Point<int> translation = (parentWindow != 0 ? getScreenPosition (isPhysical) : Point<int>());
  369. const auto& desktop = Desktop::getInstance();
  370. if (auto* display = desktop.getDisplays().getDisplayForRect (newBounds.translated (translation.x, translation.y),
  371. isPhysical))
  372. {
  373. auto newScaleFactor = display->scale / desktop.getGlobalScaleFactor();
  374. if (! approximatelyEqual (newScaleFactor, currentScaleFactor))
  375. {
  376. currentScaleFactor = newScaleFactor;
  377. scaleFactorListeners.call ([&] (ScaleFactorListener& l) { l.nativeScaleFactorChanged (currentScaleFactor); });
  378. }
  379. }
  380. }
  381. //==============================================================================
  382. std::unique_ptr<LinuxRepaintManager> repainter;
  383. ::Window windowH = {}, parentWindow = {};
  384. Rectangle<int> bounds;
  385. BorderSize<int> windowBorder;
  386. bool fullScreen = false, isAlwaysOnTop = false;
  387. double currentScaleFactor = 1.0;
  388. Array<Component*> glRepaintListeners;
  389. //==============================================================================
  390. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LinuxComponentPeer)
  391. };
  392. bool LinuxComponentPeer::isActiveApplication = false;
  393. //==============================================================================
  394. ComponentPeer* Component::createNewPeer (int styleFlags, void* nativeWindowToAttachTo)
  395. {
  396. return new LinuxComponentPeer (*this, styleFlags, (::Window) nativeWindowToAttachTo);
  397. }
  398. //==============================================================================
  399. JUCE_API bool JUCE_CALLTYPE Process::isForegroundProcess() { return LinuxComponentPeer::isActiveApplication; }
  400. JUCE_API void JUCE_CALLTYPE Process::makeForegroundProcess() {}
  401. JUCE_API void JUCE_CALLTYPE Process::hide() {}
  402. //==============================================================================
  403. void Desktop::setKioskComponent (Component* comp, bool enableOrDisable, bool)
  404. {
  405. if (enableOrDisable)
  406. comp->setBounds (getDisplays().getDisplayForRect (comp->getScreenBounds())->totalArea);
  407. }
  408. void Displays::findDisplays (float masterScale)
  409. {
  410. if (XWindowSystem::getInstance()->getDisplay() != nullptr)
  411. {
  412. displays = XWindowSystem::getInstance()->findDisplays (masterScale);
  413. if (! displays.isEmpty())
  414. updateToLogical();
  415. }
  416. }
  417. bool Desktop::canUseSemiTransparentWindows() noexcept
  418. {
  419. return XWindowSystem::getInstance()->canUseSemiTransparentWindows();
  420. }
  421. class Desktop::NativeDarkModeChangeDetectorImpl : private XWindowSystemUtilities::XSettings::Listener
  422. {
  423. public:
  424. NativeDarkModeChangeDetectorImpl()
  425. {
  426. const auto* windowSystem = XWindowSystem::getInstance();
  427. if (auto* xSettings = windowSystem->getXSettings())
  428. xSettings->addListener (this);
  429. darkModeEnabled = windowSystem->isDarkModeActive();
  430. }
  431. ~NativeDarkModeChangeDetectorImpl() override
  432. {
  433. if (auto* windowSystem = XWindowSystem::getInstanceWithoutCreating())
  434. if (auto* xSettings = windowSystem->getXSettings())
  435. xSettings->removeListener (this);
  436. }
  437. bool isDarkModeEnabled() const noexcept { return darkModeEnabled; }
  438. private:
  439. void settingChanged (const XWindowSystemUtilities::XSetting& settingThatHasChanged) override
  440. {
  441. if (settingThatHasChanged.name == XWindowSystem::getThemeNameSettingName())
  442. {
  443. const auto wasDarkModeEnabled = std::exchange (darkModeEnabled, XWindowSystem::getInstance()->isDarkModeActive());
  444. if (darkModeEnabled != wasDarkModeEnabled)
  445. Desktop::getInstance().darkModeChanged();
  446. }
  447. }
  448. bool darkModeEnabled = false;
  449. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (NativeDarkModeChangeDetectorImpl)
  450. };
  451. std::unique_ptr<Desktop::NativeDarkModeChangeDetectorImpl> Desktop::createNativeDarkModeChangeDetectorImpl()
  452. {
  453. return std::make_unique<NativeDarkModeChangeDetectorImpl>();
  454. }
  455. bool Desktop::isDarkModeActive() const
  456. {
  457. return nativeDarkModeChangeDetectorImpl->isDarkModeEnabled();
  458. }
  459. static bool screenSaverAllowed = true;
  460. void Desktop::setScreenSaverEnabled (bool isEnabled)
  461. {
  462. if (screenSaverAllowed != isEnabled)
  463. {
  464. screenSaverAllowed = isEnabled;
  465. XWindowSystem::getInstance()->setScreenSaverEnabled (screenSaverAllowed);
  466. }
  467. }
  468. bool Desktop::isScreenSaverEnabled()
  469. {
  470. return screenSaverAllowed;
  471. }
  472. double Desktop::getDefaultMasterScale() { return 1.0; }
  473. Desktop::DisplayOrientation Desktop::getCurrentOrientation() const { return upright; }
  474. void Desktop::allowedOrientationsChanged() {}
  475. //==============================================================================
  476. bool MouseInputSource::SourceList::addSource()
  477. {
  478. if (sources.isEmpty())
  479. {
  480. addSource (0, MouseInputSource::InputSourceType::mouse);
  481. return true;
  482. }
  483. return false;
  484. }
  485. bool MouseInputSource::SourceList::canUseTouch()
  486. {
  487. return false;
  488. }
  489. Point<float> MouseInputSource::getCurrentRawMousePosition()
  490. {
  491. return Desktop::getInstance().getDisplays().physicalToLogical (XWindowSystem::getInstance()->getCurrentMousePosition());
  492. }
  493. void MouseInputSource::setRawMousePosition (Point<float> newPosition)
  494. {
  495. XWindowSystem::getInstance()->setMousePosition (Desktop::getInstance().getDisplays().logicalToPhysical (newPosition));
  496. }
  497. //==============================================================================
  498. void* CustomMouseCursorInfo::create() const
  499. {
  500. return XWindowSystem::getInstance()->createCustomMouseCursorInfo (image, hotspot);
  501. }
  502. void MouseCursor::deleteMouseCursor (void* cursorHandle, bool)
  503. {
  504. if (cursorHandle != nullptr)
  505. XWindowSystem::getInstance()->deleteMouseCursor (cursorHandle);
  506. }
  507. void* MouseCursor::createStandardMouseCursor (MouseCursor::StandardCursorType type)
  508. {
  509. return XWindowSystem::getInstance()->createStandardMouseCursor (type);
  510. }
  511. void MouseCursor::showInWindow (ComponentPeer* peer) const
  512. {
  513. if (peer != nullptr)
  514. XWindowSystem::getInstance()->showCursor ((::Window) peer->getNativeHandle(), getHandle());
  515. }
  516. //==============================================================================
  517. static LinuxComponentPeer* getPeerForDragEvent (Component* sourceComp)
  518. {
  519. if (sourceComp == nullptr)
  520. if (auto* draggingSource = Desktop::getInstance().getDraggingMouseSource (0))
  521. sourceComp = draggingSource->getComponentUnderMouse();
  522. if (sourceComp != nullptr)
  523. if (auto* lp = dynamic_cast<LinuxComponentPeer*> (sourceComp->getPeer()))
  524. return lp;
  525. jassertfalse; // This method must be called in response to a component's mouseDown or mouseDrag event!
  526. return nullptr;
  527. }
  528. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, bool canMoveFiles,
  529. Component* sourceComp, std::function<void()> callback)
  530. {
  531. if (files.isEmpty())
  532. return false;
  533. if (auto* peer = getPeerForDragEvent (sourceComp))
  534. return XWindowSystem::getInstance()->externalDragFileInit (peer, files, canMoveFiles, std::move (callback));
  535. // This method must be called in response to a component's mouseDown or mouseDrag event!
  536. jassertfalse;
  537. return false;
  538. }
  539. bool DragAndDropContainer::performExternalDragDropOfText (const String& text, Component* sourceComp,
  540. std::function<void()> callback)
  541. {
  542. if (text.isEmpty())
  543. return false;
  544. if (auto* peer = getPeerForDragEvent (sourceComp))
  545. return XWindowSystem::getInstance()->externalDragTextInit (peer, text, std::move (callback));
  546. // This method must be called in response to a component's mouseDown or mouseDrag event!
  547. jassertfalse;
  548. return false;
  549. }
  550. //==============================================================================
  551. void SystemClipboard::copyTextToClipboard (const String& clipText)
  552. {
  553. XWindowSystem::getInstance()->copyTextToClipboard (clipText);
  554. }
  555. String SystemClipboard::getTextFromClipboard()
  556. {
  557. return XWindowSystem::getInstance()->getTextFromClipboard();
  558. }
  559. //==============================================================================
  560. bool KeyPress::isKeyCurrentlyDown (int keyCode)
  561. {
  562. return XWindowSystem::getInstance()->isKeyCurrentlyDown (keyCode);
  563. }
  564. void LookAndFeel::playAlertSound()
  565. {
  566. std::cout << "\a" << std::flush;
  567. }
  568. //==============================================================================
  569. static int showDialog (const MessageBoxOptions& options,
  570. ModalComponentManager::Callback* callback,
  571. Async async)
  572. {
  573. const auto dummyCallback = [] (int) {};
  574. switch (options.getNumButtons())
  575. {
  576. case 2:
  577. {
  578. if (async == Async::yes && callback == nullptr)
  579. callback = ModalCallbackFunction::create (dummyCallback);
  580. return AlertWindow::showOkCancelBox (options.getIconType(),
  581. options.getTitle(),
  582. options.getMessage(),
  583. options.getButtonText (0),
  584. options.getButtonText (1),
  585. options.getAssociatedComponent(),
  586. callback) ? 1 : 0;
  587. }
  588. case 3:
  589. {
  590. if (async == Async::yes && callback == nullptr)
  591. callback = ModalCallbackFunction::create (dummyCallback);
  592. return AlertWindow::showYesNoCancelBox (options.getIconType(),
  593. options.getTitle(),
  594. options.getMessage(),
  595. options.getButtonText (0),
  596. options.getButtonText (1),
  597. options.getButtonText (2),
  598. options.getAssociatedComponent(),
  599. callback);
  600. }
  601. case 1:
  602. default:
  603. break;
  604. }
  605. #if JUCE_MODAL_LOOPS_PERMITTED
  606. if (async == Async::no)
  607. {
  608. AlertWindow::showMessageBox (options.getIconType(),
  609. options.getTitle(),
  610. options.getMessage(),
  611. options.getButtonText (0),
  612. options.getAssociatedComponent());
  613. }
  614. else
  615. #endif
  616. {
  617. AlertWindow::showMessageBoxAsync (options.getIconType(),
  618. options.getTitle(),
  619. options.getMessage(),
  620. options.getButtonText (0),
  621. options.getAssociatedComponent(),
  622. callback);
  623. }
  624. return 0;
  625. }
  626. #if JUCE_MODAL_LOOPS_PERMITTED
  627. void JUCE_CALLTYPE NativeMessageBox::showMessageBox (MessageBoxIconType iconType,
  628. const String& title, const String& message,
  629. Component* /*associatedComponent*/)
  630. {
  631. AlertWindow::showMessageBox (iconType, title, message);
  632. }
  633. int JUCE_CALLTYPE NativeMessageBox::show (const MessageBoxOptions& options)
  634. {
  635. return showDialog (options, nullptr, Async::no);
  636. }
  637. #endif
  638. void JUCE_CALLTYPE NativeMessageBox::showMessageBoxAsync (MessageBoxIconType iconType,
  639. const String& title, const String& message,
  640. Component* associatedComponent,
  641. ModalComponentManager::Callback* callback)
  642. {
  643. AlertWindow::showMessageBoxAsync (iconType, title, message, {}, associatedComponent, callback);
  644. }
  645. bool JUCE_CALLTYPE NativeMessageBox::showOkCancelBox (MessageBoxIconType iconType,
  646. const String& title, const String& message,
  647. Component* associatedComponent,
  648. ModalComponentManager::Callback* callback)
  649. {
  650. return AlertWindow::showOkCancelBox (iconType, title, message, {}, {}, associatedComponent, callback);
  651. }
  652. int JUCE_CALLTYPE NativeMessageBox::showYesNoCancelBox (MessageBoxIconType iconType,
  653. const String& title, const String& message,
  654. Component* associatedComponent,
  655. ModalComponentManager::Callback* callback)
  656. {
  657. return AlertWindow::showYesNoCancelBox (iconType, title, message, {}, {}, {},
  658. associatedComponent, callback);
  659. }
  660. int JUCE_CALLTYPE NativeMessageBox::showYesNoBox (MessageBoxIconType iconType,
  661. const String& title, const String& message,
  662. Component* associatedComponent,
  663. ModalComponentManager::Callback* callback)
  664. {
  665. return AlertWindow::showOkCancelBox (iconType, title, message, TRANS("Yes"), TRANS("No"),
  666. associatedComponent, callback);
  667. }
  668. void JUCE_CALLTYPE NativeMessageBox::showAsync (const MessageBoxOptions& options,
  669. ModalComponentManager::Callback* callback)
  670. {
  671. showDialog (options, callback, Async::yes);
  672. }
  673. void JUCE_CALLTYPE NativeMessageBox::showAsync (const MessageBoxOptions& options,
  674. std::function<void (int)> callback)
  675. {
  676. showAsync (options, ModalCallbackFunction::create (callback));
  677. }
  678. //==============================================================================
  679. Image juce_createIconForFile (const File&)
  680. {
  681. return {};
  682. }
  683. void juce_LinuxAddRepaintListener (ComponentPeer* peer, Component* dummy)
  684. {
  685. if (auto* linuxPeer = dynamic_cast<LinuxComponentPeer*> (peer))
  686. linuxPeer->addOpenGLRepaintListener (dummy);
  687. }
  688. void juce_LinuxRemoveRepaintListener (ComponentPeer* peer, Component* dummy)
  689. {
  690. if (auto* linuxPeer = dynamic_cast<LinuxComponentPeer*> (peer))
  691. linuxPeer->removeOpenGLRepaintListener (dummy);
  692. }
  693. } // namespace juce