forked from quickshell/quickshell
		
	core/window: add min/max size to FloatingWindow
This commit is contained in:
		
							parent
							
								
									05ed9ff74c
								
							
						
					
					
						commit
						e931b85464
					
				
					 2 changed files with 61 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -4,11 +4,19 @@
 | 
			
		|||
#include <qqmlengine.h>
 | 
			
		||||
#include <qqmllist.h>
 | 
			
		||||
#include <qquickitem.h>
 | 
			
		||||
#include <qtmetamacros.h>
 | 
			
		||||
#include <qtypes.h>
 | 
			
		||||
 | 
			
		||||
#include "proxywindow.hpp"
 | 
			
		||||
#include "windowinterface.hpp"
 | 
			
		||||
 | 
			
		||||
void ProxyFloatingWindow::connectWindow() {
 | 
			
		||||
	this->ProxyWindowBase::connectWindow();
 | 
			
		||||
 | 
			
		||||
	this->window->setMinimumSize(this->bMinimumSize);
 | 
			
		||||
	this->window->setMaximumSize(this->bMaximumSize);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ProxyFloatingWindow::trySetWidth(qint32 implicitWidth) {
 | 
			
		||||
	if (!this->window->isVisible()) {
 | 
			
		||||
		this->ProxyWindowBase::trySetWidth(implicitWidth);
 | 
			
		||||
| 
						 | 
				
			
			@ -21,6 +29,16 @@ void ProxyFloatingWindow::trySetHeight(qint32 implicitHeight) {
 | 
			
		|||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ProxyFloatingWindow::onMinimumSizeChanged() {
 | 
			
		||||
	if (this->window) this->window->setMinimumSize(this->bMinimumSize);
 | 
			
		||||
	emit this->minimumSizeChanged();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ProxyFloatingWindow::onMaximumSizeChanged() {
 | 
			
		||||
	if (this->window) this->window->setMaximumSize(this->bMaximumSize);
 | 
			
		||||
	emit this->maximumSizeChanged();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FloatingWindowInterface
 | 
			
		||||
 | 
			
		||||
FloatingWindowInterface::FloatingWindowInterface(QObject* parent)
 | 
			
		||||
| 
						 | 
				
			
			@ -40,6 +58,9 @@ FloatingWindowInterface::FloatingWindowInterface(QObject* parent)
 | 
			
		|||
	QObject::connect(this->window, &ProxyWindowBase::colorChanged, this, &FloatingWindowInterface::colorChanged);
 | 
			
		||||
	QObject::connect(this->window, &ProxyWindowBase::maskChanged, this, &FloatingWindowInterface::maskChanged);
 | 
			
		||||
	QObject::connect(this->window, &ProxyWindowBase::surfaceFormatChanged, this, &FloatingWindowInterface::surfaceFormatChanged);
 | 
			
		||||
 | 
			
		||||
	QObject::connect(this->window, &ProxyFloatingWindow::minimumSizeChanged, this, &FloatingWindowInterface::minimumSizeChanged);
 | 
			
		||||
	QObject::connect(this->window, &ProxyFloatingWindow::maximumSizeChanged, this, &FloatingWindowInterface::maximumSizeChanged);
 | 
			
		||||
	// clang-format on
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,8 @@
 | 
			
		|||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <qobject.h>
 | 
			
		||||
#include <qproperty.h>
 | 
			
		||||
#include <qsize.h>
 | 
			
		||||
#include <qtmetamacros.h>
 | 
			
		||||
 | 
			
		||||
#include "proxywindow.hpp"
 | 
			
		||||
| 
						 | 
				
			
			@ -12,15 +14,46 @@ class ProxyFloatingWindow: public ProxyWindowBase {
 | 
			
		|||
public:
 | 
			
		||||
	explicit ProxyFloatingWindow(QObject* parent = nullptr): ProxyWindowBase(parent) {}
 | 
			
		||||
 | 
			
		||||
	void connectWindow() override;
 | 
			
		||||
 | 
			
		||||
	// Setting geometry while the window is visible makes the content item shrink but not the window
 | 
			
		||||
	// which is awful so we disable it for floating windows.
 | 
			
		||||
	void trySetWidth(qint32 implicitWidth) override;
 | 
			
		||||
	void trySetHeight(qint32 implicitHeight) override;
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
	void minimumSizeChanged();
 | 
			
		||||
	void maximumSizeChanged();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
	void onMinimumSizeChanged();
 | 
			
		||||
	void onMaximumSizeChanged();
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
	Q_OBJECT_BINDABLE_PROPERTY(
 | 
			
		||||
	    ProxyFloatingWindow,
 | 
			
		||||
	    QSize,
 | 
			
		||||
	    bMinimumSize,
 | 
			
		||||
	    &ProxyFloatingWindow::onMinimumSizeChanged
 | 
			
		||||
	);
 | 
			
		||||
 | 
			
		||||
	Q_OBJECT_BINDABLE_PROPERTY(
 | 
			
		||||
	    ProxyFloatingWindow,
 | 
			
		||||
	    QSize,
 | 
			
		||||
	    bMaximumSize,
 | 
			
		||||
	    &ProxyFloatingWindow::onMaximumSizeChanged
 | 
			
		||||
	);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
///! Standard toplevel operating system window that looks like any other application.
 | 
			
		||||
class FloatingWindowInterface: public WindowInterface {
 | 
			
		||||
	Q_OBJECT;
 | 
			
		||||
	// clang-format off
 | 
			
		||||
	/// Minimum window size given to the window system.
 | 
			
		||||
	Q_PROPERTY(QSize minimumSize READ default WRITE default NOTIFY minimumSizeChanged BINDABLE bindableMinimumSize);
 | 
			
		||||
	/// Maximum window size given to the window system.
 | 
			
		||||
	Q_PROPERTY(QSize maximumSize READ default WRITE default NOTIFY maximumSizeChanged BINDABLE bindableMaximumSize);
 | 
			
		||||
	// clang-format on
 | 
			
		||||
	QML_NAMED_ELEMENT(FloatingWindow);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
| 
						 | 
				
			
			@ -65,6 +98,13 @@ public:
 | 
			
		|||
	[[nodiscard]] QQmlListProperty<QObject> data() override;
 | 
			
		||||
	// NOLINTEND
 | 
			
		||||
 | 
			
		||||
	QBindable<QSize> bindableMinimumSize() { return &this->window->bMinimumSize; }
 | 
			
		||||
	QBindable<QSize> bindableMaximumSize() { return &this->window->bMaximumSize; }
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
	void minimumSizeChanged();
 | 
			
		||||
	void maximumSizeChanged();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
	ProxyFloatingWindow* window;
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue