Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put dropdown window on active screen under Wayland #1196

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ MainWindow::MainWindow(TerminalConfig &cfg,
presetsMenu(nullptr),
m_config(cfg),
m_dropLockButton(nullptr),
m_dropMode(dropMode)
m_dropMode(dropMode),
m_layerWindow(nullptr)
{
#ifdef HAVE_QDBUS
registerAdapter<WindowAdaptor, MainWindow>(this);
Expand Down Expand Up @@ -176,12 +177,17 @@ void MainWindow::enableDropMode()
winId();
if (QWindow *win = windowHandle())
{
if (LayerShellQt::Window* layershell = LayerShellQt::Window::get(win))
m_layerWindow = LayerShellQt::Window::get(win);
if (m_layerWindow)
{
layershell->setLayer(LayerShellQt::Window::Layer::LayerOverlay);
layershell->setKeyboardInteractivity(LayerShellQt::Window::KeyboardInteractivityOnDemand);
LayerShellQt::Window::Anchors anchors = {LayerShellQt::Window::AnchorTop};
layershell->setAnchors(anchors);
m_layerWindow->setLayer(LayerShellQt::Window::Layer::LayerOverlay);
m_layerWindow->setKeyboardInteractivity(LayerShellQt::Window::KeyboardInteractivityOnDemand);
LayerShellQt::Window::Anchors anchors = {LayerShellQt::Window::AnchorTop
| LayerShellQt::Window::AnchorBottom
| LayerShellQt::Window::AnchorLeft
| LayerShellQt::Window::AnchorRight};
m_layerWindow->setAnchors(anchors);
m_layerWindow->setScreenConfiguration(LayerShellQt::Window::ScreenConfiguration::ScreenFromCompositor);
}
}
}
Expand Down Expand Up @@ -757,9 +763,15 @@ void MainWindow::realign()
{
if (m_dropMode)
{
if (m_layerWindow)
{
return; // done in showEvent
}
QScreen *appScreen = QGuiApplication::screenAt(QCursor::pos());
if(appScreen == nullptr)
{
appScreen = QGuiApplication::primaryScreen();
}
const QRect desktop = appScreen->availableGeometry();
QRect g = QRect(desktop.x(),
desktop.y(),
Expand All @@ -768,7 +780,8 @@ void MainWindow::realign()
g.moveCenter(desktop.center());
// do not use 0 here - we need to calculate with potential panel on top
g.moveTop(desktop.top());
if (g != geometry()) {
if (g != geometry())
{
setGeometry(g);
}
}
Expand Down Expand Up @@ -871,6 +884,18 @@ bool MainWindow::event(QEvent *event)
return QMainWindow::event(event);
}

void MainWindow::showEvent(QShowEvent* event)
{
if (m_dropMode && m_layerWindow)
{
const QRect desktop = windowHandle()->screen()->availableGeometry();
int hMargin = desktop.width() * (100 - Properties::Instance()->dropWidth) / 200;
int vMargin = desktop.height() * (100 - Properties::Instance()->dropHeight) / 100;
m_layerWindow->setMargins(QMargins(hMargin, 0, hMargin, vMargin));
}
QMainWindow::showEvent(event);
}

void MainWindow::newTerminalWindow()
{
TerminalConfig cfg;
Expand Down
5 changes: 5 additions & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include "terminalconfig.h"
#include "dbusaddressable.h"

namespace LayerShellQt {
class Window;
}

class QToolButton;

Expand Down Expand Up @@ -55,6 +58,7 @@ class MainWindow : public QMainWindow, private Ui::mainWindow, public DBusAddres

protected:
bool event(QEvent* event) override;
void showEvent(QShowEvent* event) override;

private:
QActionGroup *tabPosition, *scrollBarPosition, *keyboardCursorShape;
Expand Down Expand Up @@ -86,6 +90,7 @@ class MainWindow : public QMainWindow, private Ui::mainWindow, public DBusAddres
void enableDropMode();
QToolButton *m_dropLockButton;
bool m_dropMode;
LayerShellQt::Window *m_layerWindow;
QxtGlobalShortcut m_dropShortcut;
void realign();
void setDropShortcut(const QKeySequence& dropShortCut);
Expand Down