forked from quickshell/quickshell
core/menu: add QsMenuAnchor for more control of platform menus
This commit is contained in:
parent
54350277be
commit
6b9b1fcb53
10 changed files with 245 additions and 21 deletions
|
@ -16,6 +16,7 @@
|
|||
#include <qwindow.h>
|
||||
|
||||
#include "generation.hpp"
|
||||
#include "popupanchor.hpp"
|
||||
#include "proxywindow.hpp"
|
||||
#include "qsmenu.hpp"
|
||||
#include "windowinterface.hpp"
|
||||
|
@ -111,6 +112,33 @@ bool PlatformMenuEntry::display(QObject* parentWindow, int relativeX, int relati
|
|||
return true;
|
||||
}
|
||||
|
||||
bool PlatformMenuEntry::display(PopupAnchor* anchor) {
|
||||
if (!anchor->backingWindow() || !anchor->backingWindow()->isVisible()) {
|
||||
qCritical() << "Cannot display PlatformMenuEntry on anchor without visible window.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ACTIVE_MENU && this->qmenu != ACTIVE_MENU) {
|
||||
ACTIVE_MENU->close();
|
||||
}
|
||||
|
||||
ACTIVE_MENU = this->qmenu;
|
||||
|
||||
this->qmenu->createWinId();
|
||||
this->qmenu->windowHandle()->setTransientParent(anchor->backingWindow());
|
||||
|
||||
// Update the window geometry to the menu's actual dimensions so reposition
|
||||
// can accurately adjust it if applicable for the current platform.
|
||||
this->qmenu->windowHandle()->setGeometry({{0, 0}, this->qmenu->sizeHint()});
|
||||
|
||||
PopupPositioner::instance()->reposition(anchor, this->qmenu->windowHandle(), false);
|
||||
|
||||
// Open the menu at the position determined by the popup positioner.
|
||||
this->qmenu->popup(this->qmenu->windowHandle()->position());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void PlatformMenuEntry::relayout() {
|
||||
if (this->menu->hasChildren()) {
|
||||
delete this->qaction;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue