forked from quickshell/quickshell
		
	core/popupanchor: add anchoring signal for last second repositioning
This commit is contained in:
		
							parent
							
								
									ee93306312
								
							
						
					
					
						commit
						f4066cb4ed
					
				
					 3 changed files with 22 additions and 2 deletions
				
			
		| 
						 | 
					@ -151,6 +151,8 @@ void PopupPositioner::reposition(PopupAnchor* anchor, QWindow* window, bool only
 | 
				
			||||||
	if (onlyIfDirty && !anchor->isDirty()) return;
 | 
						if (onlyIfDirty && !anchor->isDirty()) return;
 | 
				
			||||||
	anchor->markClean();
 | 
						anchor->markClean();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						emit anchor->anchoring();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	auto adjustment = anchor->adjustment();
 | 
						auto adjustment = anchor->adjustment();
 | 
				
			||||||
	auto screenGeometry = parentWindow->screen()->geometry();
 | 
						auto screenGeometry = parentWindow->screen()->geometry();
 | 
				
			||||||
	auto anchorRectGeometry = anchor->rect().qrect().translated(parentGeometry.topLeft());
 | 
						auto anchorRectGeometry = anchor->rect().qrect().translated(parentGeometry.topLeft());
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -77,9 +77,18 @@ class PopupAnchor: public QObject {
 | 
				
			||||||
	/// determined by the @@edges, @@gravity, and @@adjustment.
 | 
						/// determined by the @@edges, @@gravity, and @@adjustment.
 | 
				
			||||||
	///
 | 
						///
 | 
				
			||||||
	/// If you leave @@edges, @@gravity and @@adjustment at their default values,
 | 
						/// If you leave @@edges, @@gravity and @@adjustment at their default values,
 | 
				
			||||||
	/// setting more than `x` and `y` does not matter.
 | 
						/// setting more than `x` and `y` does not matter. The anchor rect cannot
 | 
				
			||||||
 | 
						/// be smaller than 1x1 pixels.
 | 
				
			||||||
	///
 | 
						///
 | 
				
			||||||
	/// > [!INFO] The anchor rect cannot be smaller than 1x1 pixels.
 | 
						/// > [!INFO] To position a popup relative to an item inside a window,
 | 
				
			||||||
 | 
						/// > you can use [coordinate mapping functions] (note the warning below).
 | 
				
			||||||
 | 
						///
 | 
				
			||||||
 | 
						/// > [!WARNING] Using [coordinate mapping functions] in a binding to
 | 
				
			||||||
 | 
						/// > this property will position the anchor incorrectly.
 | 
				
			||||||
 | 
						/// > If you want to use them, do so in @@anchoring(s), or use
 | 
				
			||||||
 | 
						/// > @@TransformWatcher if you need real-time updates to mapped coordinates.
 | 
				
			||||||
 | 
						///
 | 
				
			||||||
 | 
						/// [coordinate mapping functions]: https://doc.qt.io/qt-6/qml-qtquick-item.html#mapFromItem-method
 | 
				
			||||||
	Q_PROPERTY(Box rect READ rect WRITE setRect NOTIFY rectChanged);
 | 
						Q_PROPERTY(Box rect READ rect WRITE setRect NOTIFY rectChanged);
 | 
				
			||||||
	/// The point on the anchor rectangle the popup should anchor to.
 | 
						/// The point on the anchor rectangle the popup should anchor to.
 | 
				
			||||||
	/// Opposing edges suchs as `Edges.Left | Edges.Right` are not allowed.
 | 
						/// Opposing edges suchs as `Edges.Left | Edges.Right` are not allowed.
 | 
				
			||||||
| 
						 | 
					@ -127,6 +136,12 @@ public:
 | 
				
			||||||
	void updatePlacement(const QPoint& anchorpoint, const QSize& size);
 | 
						void updatePlacement(const QPoint& anchorpoint, const QSize& size);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
signals:
 | 
					signals:
 | 
				
			||||||
 | 
						/// Emitted when this anchor is about to be used. Mostly useful for modifying
 | 
				
			||||||
 | 
						/// the anchor @@rect using [coordinate mapping functions], which are not reactive.
 | 
				
			||||||
 | 
						///
 | 
				
			||||||
 | 
						/// [coordinate mapping functions]: https://doc.qt.io/qt-6/qml-qtquick-item.html#mapFromItem-method
 | 
				
			||||||
 | 
						void anchoring();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void windowChanged();
 | 
						void windowChanged();
 | 
				
			||||||
	QSDOC_HIDE void backingWindowVisibilityChanged();
 | 
						QSDOC_HIDE void backingWindowVisibilityChanged();
 | 
				
			||||||
	void rectChanged();
 | 
						void rectChanged();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -41,6 +41,8 @@ void WaylandPopupPositioner::reposition(PopupAnchor* anchor, QWindow* window, bo
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		positioner.set_constraint_adjustment(anchor->adjustment().toInt());
 | 
							positioner.set_constraint_adjustment(anchor->adjustment().toInt());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							emit anchor->anchoring();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		auto anchorRect = anchor->rect();
 | 
							auto anchorRect = anchor->rect();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (auto* p = window->transientParent()) {
 | 
							if (auto* p = window->transientParent()) {
 | 
				
			||||||
| 
						 | 
					@ -101,6 +103,7 @@ void WaylandPopupPositioner::reposition(PopupAnchor* anchor, QWindow* window, bo
 | 
				
			||||||
bool WaylandPopupPositioner::shouldRepositionOnMove() const { return true; }
 | 
					bool WaylandPopupPositioner::shouldRepositionOnMove() const { return true; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void WaylandPopupPositioner::setFlags(PopupAnchor* anchor, QWindow* window) {
 | 
					void WaylandPopupPositioner::setFlags(PopupAnchor* anchor, QWindow* window) {
 | 
				
			||||||
 | 
						emit anchor->anchoring();
 | 
				
			||||||
	auto anchorRect = anchor->rect();
 | 
						auto anchorRect = anchor->rect();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (auto* p = window->transientParent()) {
 | 
						if (auto* p = window->transientParent()) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue