41 const auto* instance = XWindowSystem::getInstance();
43 if (! instance->isX11Available())
47 ++WindowUtilsInternal::numAlwaysOnTopPeers;
49 repainter = std::make_unique<LinuxRepaintManager> (*
this);
56 if (
auto* xSettings = instance->getXSettings())
57 xSettings->addListener (
this);
59 getNativeRealtimeModifiers = []() ->
ModifierKeys {
return XWindowSystem::getInstance()->getNativeRealtimeModifiers(); };
69 auto* instance = XWindowSystem::getInstance();
72 instance->destroyWindow (windowH);
74 if (
auto* xSettings = instance->getXSettings())
75 xSettings->removeListener (
this);
78 --WindowUtilsInternal::numAlwaysOnTopPeers;
81 ::Window getWindowHandle()
const noexcept
89 return reinterpret_cast<void*
> (getWindowHandle());
97 updateScaleFactorFromNewBounds (bounds,
false);
100 : bounds * currentScaleFactor;
170 StringArray getAvailableRenderingEngines()
override
172 return {
"Software Renderer" };
182 XWindowSystem::getInstance()->setTitle (windowH, title);
195 return XWindowSystem::getInstance()->isMinimised (windowH);
200 auto r = lastNonFullscreenBounds;
212 r =
usingNativeTitleBar ? XWindowSystem::getInstance()->getWindowBounds (windowH, parentWindow)
239 if (! c->isVisible())
253 return XWindowSystem::getInstance()->contains (windowH,
localPos * currentScaleFactor);
264 XWindowSystem::getInstance()->toFront (windowH,
makeActive);
276 XWindowSystem::getInstance()->toBehind (windowH,
otherPeer->windowH);
286 return XWindowSystem::getInstance()->isFocused (windowH);
291 if (XWindowSystem::getInstance()->
grabFocus (windowH))
292 isActiveApplication =
true;
298 if (repainter !=
nullptr)
304 if (repainter !=
nullptr)
305 repainter->performAnyPendingRepaintsNow();
310 XWindowSystem::getInstance()->setIcon (windowH,
newIcon);
315 return currentScaleFactor;
325 if (
dummy !=
nullptr)
326 glRepaintListeners.addIfNotAlreadyThere (
dummy);
329 void removeOpenGLRepaintListener (Component*
dummy)
331 if (
dummy !=
nullptr)
332 glRepaintListeners.removeAllInstancesOf (
dummy);
335 void repaintOpenGLContexts()
337 for (
auto* c : glRepaintListeners)
338 c->handleCommandMessage (0);
342 ::Window getParentWindow() {
return parentWindow; }
346 bool isConstrainedNativeWindow()
const
348 return constrainer !=
nullptr
353 void updateWindowBounds()
361 if (isConstrainedNativeWindow())
362 XWindowSystem::getInstance()->updateConstraints (windowH);
364 auto physicalBounds = XWindowSystem::getInstance()->getWindowBounds (windowH, parentWindow);
374 void updateBorderSize()
378 windowBorder = ComponentPeer::OptionalBorderSize { BorderSize<int>() };
380 else if (! windowBorder
381 || ((*windowBorder).getTopAndBottom() == 0 && (*windowBorder).getLeftAndRight() == 0))
386 return OptionalBorderSize { (*unscaledBorderSize).multipliedBy (1.0 / currentScaleFactor) };
388 return OptionalBorderSize {};
393 bool setWindowAssociation (::Window
windowIn)
395 clearWindowAssociation();
397 return association.isValid();
400 void clearWindowAssociation() { association = {}; }
404 XWindowSystem::getInstance()->startHostManagedResize (windowH, zone);
408 static bool isActiveApplication;
409 bool focused =
false;
413 class LinuxRepaintManager
422 void dispatchDeferredRepaints()
424 XWindowSystem::getInstance()->processPendingPaintsForWindow (peer.windowH);
426 if (XWindowSystem::getInstance()->getNumPaintsPendingForWindow (peer.windowH) > 0)
429 if (! regionsNeedingRepaint.isEmpty())
430 performAnyPendingRepaintsNow();
435 void repaint (Rectangle<int> area)
437 regionsNeedingRepaint.add (area * peer.currentScaleFactor);
440 void performAnyPendingRepaintsNow()
442 if (XWindowSystem::getInstance()->getNumPaintsPendingForWindow (peer.windowH) > 0)
446 regionsNeedingRepaint.clear();
449 if (! totalArea.isEmpty())
453 if (
wasImageNull || image.getWidth() < totalArea.getWidth()
454 || image.getHeight() < totalArea.getHeight())
456 image = XWindowSystem::getInstance()->createImage (isSemiTransparentWindow,
457 totalArea.getWidth(), totalArea.getHeight(),
458 useARGBImagesForRendering);
472 peer.forceSetBounds (detail::ScalingHelpers::scaledScreenPosToUnscaled (peer.component, peer.component.getBoundsInParent()),
473 peer.isFullScreen());
478 adjustedList.offsetAll (-totalArea.getX(), -totalArea.getY());
480 if (XWindowSystem::getInstance()->canUseARGBImages())
482 image.clear (i - totalArea.getPosition());
485 auto context = peer.getComponent().getLookAndFeel()
486 .createGraphicsContext (image, -totalArea.getPosition(),
adjustedList);
489 peer.handlePaint (*context);
493 XWindowSystem::getInstance()->blitToWindow (peer.windowH, image, i, totalArea);
500 LinuxComponentPeer& peer;
501 const bool isSemiTransparentWindow;
503 uint32 lastTimeImageUsed = 0;
504 RectangleList<int> regionsNeedingRepaint;
506 bool useARGBImagesForRendering = XWindowSystem::getInstance()->canUseARGBImages();
512 template <
typename This>
518 template <
typename This>
527 static StringArray
possibleSettings { XWindowSystem::getWindowScalingFactorSettingName(),
532 forceDisplayUpdate();
537 Point<int> translation = (parentWindow != 0 ? getScreenPosition (
isPhysical) : Point<
int>());
540 if (
auto* display =
desktop.getDisplays().getDisplayForRect (
newBounds.translated (translation.x, translation.y),
548 scaleFactorListeners.call ([&] (ScaleFactorListener&
l) {
l.nativeScaleFactorChanged (currentScaleFactor); });
555 vBlankListeners.call ([] (
auto&
l) {
l.onVBlank(); });
557 if (repainter !=
nullptr)
558 repainter->dispatchDeferredRepaints();
561 void updateVBlankTimer()
577 TimedCallback vBlankManager { [
this]() { onVBlank(); } };
579 ::Window windowH = {}, parentWindow = {};
580 Rectangle<int> bounds;
581 ComponentPeer::OptionalBorderSize windowBorder;
582 bool fullScreen =
false, isAlwaysOnTop =
false;
583 double currentScaleFactor = 1.0;
585 ScopedWindowAssociation association;
591bool LinuxComponentPeer::isActiveApplication =
false;
614 if (XWindowSystem::getInstance()->getDisplay() !=
nullptr)
625 return XWindowSystem::getInstance()->canUseSemiTransparentWindows();
633 const auto*
windowSystem = XWindowSystem::getInstance();
636 xSettings->addListener (
this);
643 if (
auto*
windowSystem = XWindowSystem::getInstanceWithoutCreating())
645 xSettings->removeListener (
this);
648 bool isDarkModeEnabled()
const noexcept {
return darkModeEnabled; }
662 bool darkModeEnabled =
false;
669 return std::make_unique<NativeDarkModeChangeDetectorImpl>();
674 return nativeDarkModeChangeDetectorImpl->isDarkModeEnabled();
677static bool screenSaverAllowed =
true;
681 if (screenSaverAllowed != isEnabled)
683 screenSaverAllowed = isEnabled;
684 XWindowSystem::getInstance()->setScreenSaverEnabled (screenSaverAllowed);
690 return screenSaverAllowed;
693double Desktop::getDefaultMasterScale() {
return 1.0; }
696void Desktop::allowedOrientationsChanged() {}
699bool detail::MouseInputSourceList::addSource()
701 if (sources.isEmpty())
703 addSource (0, MouseInputSource::InputSourceType::mouse);
710bool detail::MouseInputSourceList::canUseTouch()
const
715Point<float> MouseInputSource::getCurrentRawMousePosition()
720void MouseInputSource::setRawMousePosition (Point<float>
newPosition)
730 : cursorHandle (makeHandle (type)) {}
733 : cursorHandle (makeHandle (info)) {}
737 if (cursorHandle != Cursor{})
738 XWindowSystem::getInstance()->deleteMouseCursor (cursorHandle);
743 const auto cursor = handle !=
nullptr ? handle->cursorHandle : Cursor{};
746 XWindowSystem::getInstance()->showCursor ((::Window) peer->
getNativeHandle(), cursor);
752 const auto image = info.image.
getImage();
753 return XWindowSystem::getInstance()->createCustomMouseCursorInfo (image.rescaled ((
int) (image.getWidth() / info.image.
getScale()),
754 (
int) (image.getHeight() / info.image.
getScale())), info.hotspot);
759 return XWindowSystem::getInstance()->createStandardMouseCursor (type);
790 if (
auto* peer = getPeerForDragEvent (
sourceComp))
791 return XWindowSystem::getInstance()->externalDragFileInit (peer, files,
canMoveFiles, std::move (callback));
804 if (
auto* peer = getPeerForDragEvent (
sourceComp))
805 return XWindowSystem::getInstance()->externalDragTextInit (peer, text, std::move (callback));
815 XWindowSystem::getInstance()->copyTextToClipboard (
clipText);
820 return XWindowSystem::getInstance()->getTextFromClipboard();
826 return XWindowSystem::getInstance()->isKeyCurrentlyDown (keyCode);
835Image detail::WindowingHelpers::createIconForFile (
const File&)
840void juce_LinuxAddRepaintListener (ComponentPeer* peer, Component*
dummy);
841void juce_LinuxAddRepaintListener (ComponentPeer* peer, Component*
dummy)
843 if (
auto*
linuxPeer =
dynamic_cast<LinuxComponentPeer*
> (peer))
847void juce_LinuxRemoveRepaintListener (ComponentPeer* peer, Component*
dummy);
848void juce_LinuxRemoveRepaintListener (ComponentPeer* peer, Component*
dummy)
850 if (
auto*
linuxPeer =
dynamic_cast<LinuxComponentPeer*
> (peer))
Specifies a set of gaps to be left around the sides of a rectangle.
Represents the window borders around a window component.
The Component class uses a ComponentPeer internally to create and manage a real operating-system wind...
int getStyleFlags() const noexcept
Returns the set of style flags that were set when the window was created.
virtual bool isKioskMode() const
True if the window is in kiosk-mode.
virtual void * getNativeHandle() const =0
Returns the raw handle to whatever kind of window is being used.
void handleMovedOrResized()
This is called when the window's bounds change.
@ windowIsResizable
Indicates that the window should have a resizable border.
@ windowIsTemporary
Indicates that the window is a temporary popup, like a menu, tooltip, etc.
@ windowIsSemiTransparent
Not intended for public use - makes a window transparent.
@ windowHasTitleBar
Indicates that the window should have a normal OS-specific title bar and frame.
virtual Point< float > localToGlobal(Point< float > relativePosition)=0
Converts a position relative to the top-left of this component to screen coordinates.
void handleBroughtToFront()
Called when the window is brought to the front, either by the OS or by a call to toFront().
virtual Point< float > globalToLocal(Point< float > screenPosition)=0
Converts a screen coordinate to a position relative to the top-left of this component.
The base class for all JUCE user-interface objects.
bool isAlwaysOnTop() const noexcept
Returns true if this component is set to always stay in front of its siblings.
void repaint()
Marks the whole component as needing to be redrawn.
Rectangle< int > getScreenBounds() const
Returns the bounds of this component, relative to the screen's top-left.
void setBounds(int x, int y, int width, int height)
Changes the component's position and size.
ComponentPeer * getPeer() const
Returns the heavyweight window that contains this component.
String getName() const noexcept
Returns the name of this component.
DisplayOrientation
In a tablet/mobile device which can be turned around, this is used to indicate the orientation.
@ upright
Indicates that the device is the normal way up.
const Displays & getDisplays() const noexcept
Returns the Displays object representing the connected displays.
static Desktop &JUCE_CALLTYPE getInstance()
There's only one desktop object, and this method will return it.
static void setScreenSaverEnabled(bool isEnabled)
This lets you prevent the screensaver from becoming active.
Component * getComponent(int index) const noexcept
Returns one of the top-level desktop window components.
bool isDarkModeActive() const
True if the operating system "dark mode" is active.
static bool canUseSemiTransparentWindows() noexcept
True if the OS supports semitransparent windows.
DisplayOrientation getCurrentOrientation() const
In a tablet device which can be turned around, this returns the current orientation.
static bool isScreenSaverEnabled()
Returns true if the screensaver has not been turned off.
Rectangle< int > userArea
The total area of this display in logical pixels which isn't covered by OS-dependent objects like the...
Rectangle< int > logicalToPhysical(Rectangle< int > logicalRect, const Display *useScaleFactorOfDisplay=nullptr) const noexcept
Converts an integer Rectangle from logical to physical pixels.
const Display * getDisplayForRect(Rectangle< int > rect, bool isPhysical=false) const noexcept
Returns the Display object representing the display containing a given Rectangle (either in logical o...
Array< Display > displays
An Array containing the Display objects for all of the connected displays.
Rectangle< int > physicalToLogical(Rectangle< int > physicalRect, const Display *useScaleFactorOfDisplay=nullptr) const noexcept
Converts an integer Rectangle from physical to logical pixels.
static bool performExternalDragDropOfText(const String &text, Component *sourceComponent=nullptr, std::function< void()> callback=nullptr)
This performs an asynchronous drag-and-drop of a block of text to some external application.
static bool performExternalDragDropOfFiles(const StringArray &files, bool canMoveFiles, Component *sourceComponent=nullptr, std::function< void()> callback=nullptr)
This performs an asynchronous drag-and-drop of a set of files to some external application.
Represents a local file or directory.
Holds a fixed-size bitmap.
static bool isKeyCurrentlyDown(int keyCode)
Checks whether a particular key is held down, irrespective of modifiers.
void setVisible(bool shouldBeVisible) override
Shows or hides the window.
void performAnyPendingRepaintsNow() override
This can be called (from the message thread) to cause the immediate redrawing of any areas of this wi...
void setAlpha(float) override
Changes the window's transparency.
double getPlatformScaleFactor() const noexcept override
On Windows and Linux this will return the OS scaling factor currently being applied to the native win...
void toBehind(ComponentPeer *other) override
Moves the window to be just behind another one.
void setTitle(const String &title) override
Changes the title of the window.
void setBounds(const Rectangle< int > &newBounds, bool isNowFullScreen) override
Moves and resizes the window.
Rectangle< int > getBounds() const override
Returns the current position and size of the window.
BorderSize< int > getFrameSize() const override
Returns the size of the window frame that's around this window.
void setIcon(const Image &newIcon) override
Attempts to change the icon associated with this window.
void setMinimised(bool shouldBeMinimised) override
Minimises the window.
Point< float > globalToLocal(Point< float > screenPosition) override
Converts a screen coordinate to a position relative to the top-left of this component.
bool contains(Point< int > localPos, bool trueIfInAChildWindow) const override
Checks if a point is in the window.
Point< float > localToGlobal(Point< float > relativePosition) override
Converts a position relative to the top-left of this component to screen coordinates.
bool setAlwaysOnTop(bool) override
Sets this window to either be always-on-top or normal.
void setFullScreen(bool shouldBeFullScreen) override
Enable/disable fullscreen mode for the window.
void repaint(const Rectangle< int > &area) override
Invalidates a region of the window to be repainted asynchronously.
void startHostManagedResize(Point< int >, ResizableBorderComponent::Zone zone) override
Asks the window-manager to begin resizing this window, on platforms where this is useful (currently j...
void * getNativeHandle() const override
Returns the raw handle to whatever kind of window is being used.
bool isFullScreen() const override
True if the window is currently full-screen.
bool isFocused() const override
True if the window has the keyboard focus.
void toFront(bool makeActive) override
Brings the window to the top, optionally also giving it keyboard focus.
void grabFocus() override
Tries to give the window keyboard focus.
bool isMinimised() const override
True if the window is currently minimised.
void textInputRequired(Point< int >, TextInputTarget &) override
Tells the window that text input may be required at the given position.
OptionalBorderSize getFrameSizeIfPresent() const override
Returns the size of the window frame that's around this window.
virtual void playAlertSound()
Plays the system's default 'beep' noise, to alert the user about something very important.
Represents the state of the mouse buttons and modifier keys.
StandardCursorType
The set of available standard mouse cursors.
A pair of (x, y) coordinates.
constexpr Point< float > toFloat() const noexcept
Casts this point to a Point<float> object.
constexpr Point< int > roundToInt() const noexcept
Casts this point to a Point<int> object using roundToInt() to convert the values.
static void JUCE_CALLTYPE makeForegroundProcess()
Attempts to make the current process the active one.
static void JUCE_CALLTYPE hide()
Hides the application (on an OS that supports this, e.g.
static bool JUCE_CALLTYPE isForegroundProcess()
Returns true if this application process is the one that the user is currently using.
Manages a rectangle and allows geometric operations to be performed on it.
bool contains(ValueType xCoord, ValueType yCoord) const noexcept
Returns true if this coordinate is inside the rectangle.
Point< ValueType > getTopLeft() const noexcept
Returns the rectangle's top-left position as a Point.
Rectangle getIntersection(Rectangle other) const noexcept
Returns the region that is the overlap between this and another rectangle.
Rectangle translated(ValueType deltaX, ValueType deltaY) const noexcept
Returns a rectangle which is the same as this one moved by a given amount.
Rectangle withZeroOrigin() const noexcept
Returns a rectangle whose size is the same as this one, but whose top-left position is (0,...
Represents the different sections of a resizable border, which allow it to resized in different ways.
double getScale() const
Returns the image's scale.
Image getImage() const
Returns the image at its original dimensions.
A special array for holding a list of strings.
bool isEmpty() const noexcept
Returns true if the array is empty, false otherwise.
bool isEmpty() const noexcept
Returns true if the string contains no characters.
static String getTextFromClipboard()
Gets the current clipboard's contents.
static void copyTextToClipboard(const String &text)
Copies a string of text onto the clipboard.
An abstract base class which can be implemented by components that function as text editors.
static uint32 getApproximateMillisecondCounter() noexcept
Less-accurate but faster version of getMillisecondCounter().
int getTimerInterval() const noexcept
Returns the timer's interval.
void startTimerHz(int timerFrequencyHz) noexcept
Starts the timer with an interval specified in Hertz.
This class acts as a pointer which will automatically become null if the object to which it points is...
#define JUCE_ASSERT_MESSAGE_MANAGER_IS_LOCKED
This macro is used to catch unsafe use of functions which expect to only be called on the message thr...
constexpr bool approximatelyEqual(Type a, Type b, Tolerance< Type > tolerance=Tolerance< Type >{} .withAbsolute(std::numeric_limits< Type >::min()) .withRelative(std::numeric_limits< Type >::epsilon()))
Returns true if the two floating-point numbers are approximately equal.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
unsigned int uint32
A platform-independent 32-bit unsigned integer type.
int roundToInt(const FloatType value) noexcept
Fast floating-point-to-integer conversion.
Represents a setting according to the XSETTINGS specification.