Allow setting current AbstractOutput

This commit is contained in:
Vlad Zahorodnii 2021-08-28 17:51:57 +03:00 committed by Aleix Pol Gonzalez
parent 507c5140b7
commit e0c941109c
10 changed files with 38 additions and 17 deletions

View file

@ -85,7 +85,7 @@ AbstractClient::AbstractClient()
Q_UNUSED(c)
if (isOnScreenDisplay() && !frameGeometry().isEmpty() && old.size() != frameGeometry().size() && isPlaceable()) {
GeometryUpdatesBlocker blocker(this);
placeIn(workspace()->clientArea(PlacementArea, this, Screens::self()->current()));
placeIn(workspace()->clientArea(PlacementArea, this, Screens::self()->currentOutput()));
}
}
);
@ -1222,7 +1222,7 @@ void AbstractClient::handleInteractiveMoveResize(int x, int y, int x_root, int y
// Make sure the titlebar isn't behind a restricted area. We don't need to restrict
// the other directions. If not visible enough, move the window to the closest valid
// point. We bruteforce this by slowly moving the window back to its previous position
QRegion availableArea(workspace()->clientArea(FullArea, this, screens()->current()));
QRegion availableArea(workspace()->clientArea(FullArea, this, screens()->currentOutput()));
availableArea -= workspace()->restrictedMoveArea(VirtualDesktopManager::self()->currentDesktop());
bool transposed = false;
int requiredPixels;
@ -1350,7 +1350,7 @@ void AbstractClient::handleInteractiveMoveResize(int x, int y, int x_root, int y
if (!isUnrestrictedInteractiveMoveResize()) {
const QRegion strut = workspace()->restrictedMoveArea(VirtualDesktopManager::self()->currentDesktop());
QRegion availableArea(workspace()->clientArea(FullArea, this, screens()->current()));
QRegion availableArea(workspace()->clientArea(FullArea, this, screens()->currentOutput()));
availableArea -= strut; // Strut areas
bool transposed = false;
int requiredPixels;

View file

@ -391,8 +391,9 @@ bool Workspace::takeActivity(AbstractClient* c, ActivityFlags flags)
if (flags & ActivityRaise)
workspace()->raiseClient(c);
if (!c->isOnActiveScreen())
screens()->setCurrent(c->screen());
if (!c->isOnActiveOutput()) {
screens()->setCurrent(c->output());
}
return ret;
}

View file

@ -41,7 +41,7 @@ void LayerShellV1Integration::createClient(LayerSurfaceV1Interface *shellSurface
{
AbstractOutput *output = waylandServer()->findOutput(shellSurface->output());
if (!output) {
output = kwinApp()->platform()->findOutput(screens()->current());
output = screens()->currentOutput();
}
if (!output) {
qCWarning(KWIN_CORE) << "Could not find any suitable output for a layer surface";

View file

@ -185,6 +185,15 @@ void Screens::setCurrent(int current)
Q_EMIT currentChanged();
}
void Screens::setCurrent(AbstractOutput *output)
{
#ifdef KWIN_UNIT_TEST
Q_UNUSED(output)
#else
setCurrent(kwinApp()->platform()->enabledOutputs().indexOf(output));
#endif
}
void Screens::setCurrent(const QPoint &pos)
{
setCurrent(number(pos));
@ -220,6 +229,15 @@ int Screens::current() const
return m_current;
}
AbstractOutput *Screens::currentOutput() const
{
#ifdef KWIN_UNIT_TEST
return nullptr;
#else
return kwinApp()->platform()->findOutput(current());
#endif
}
int Screens::intersecting(const QRect &r) const
{
int cnt = 0;

View file

@ -42,12 +42,14 @@ public:
void setConfig(KSharedConfig::Ptr config);
int count() const;
int current() const;
AbstractOutput *currentOutput() const;
void setCurrent(int current);
/**
* Called e.g. when a user clicks on a window, set current screen to be the screen
* where the click occurred
*/
void setCurrent(const QPoint &pos);
void setCurrent(AbstractOutput *output);
/**
* Check whether a client moved completely out of what's considered the current screen,
* if yes, set a new active screen.

View file

@ -235,9 +235,9 @@ bool TabBoxHandlerImpl::checkMultiScreen(TabBoxClient* client) const
case TabBoxConfig::IgnoreMultiScreen:
return true;
case TabBoxConfig::ExcludeCurrentScreenClients:
return current->screen() != screens()->current();
return current->output() != screens()->currentOutput();
default: // TabBoxConfig::OnlyCurrentScreenClients
return current->screen() == screens()->current();
return current->output() == screens()->currentOutput();
}
}
@ -322,7 +322,7 @@ QWeakPointer<TabBoxClient> TabBoxHandlerImpl::desktopClient() const
{
Q_FOREACH (Toplevel *toplevel, Workspace::self()->stackingOrder()) {
auto client = qobject_cast<AbstractClient*>(toplevel);
if (client && client->isDesktop() && client->isOnCurrentDesktop() && client->screen() == screens()->current()) {
if (client && client->isDesktop() && client->isOnCurrentDesktop() && client->output() == screens()->currentOutput()) {
return client->tabBoxClient();
}
}

View file

@ -424,9 +424,9 @@ bool Toplevel::isOnScreen(int screen) const
return screens()->geometry(screen).intersects(frameGeometry());
}
bool Toplevel::isOnActiveScreen() const
bool Toplevel::isOnActiveOutput() const
{
return isOnScreen(screens()->current());
return isOnOutput(screens()->currentOutput());
}
bool Toplevel::isOnOutput(AbstractOutput *output) const

View file

@ -343,7 +343,7 @@ public:
int height() const;
bool isOnScreen(int screen) const; // true if it's at least partially there
bool isOnOutput(AbstractOutput *output) const;
bool isOnActiveScreen() const;
bool isOnActiveOutput() const;
int screen() const; // the screen where the center is
AbstractOutput *output() const;
/**

View file

@ -786,7 +786,7 @@ void Workspace::addShellClient(AbstractClient *client)
client->updateLayer();
if (client->isPlaceable()) {
const QRect area = clientArea(PlacementArea, client, Screens::self()->current());
const QRect area = clientArea(PlacementArea, client, Screens::self()->currentOutput());
bool placementDone = false;
if (client->isRequestedFullScreen()) {
placementDone = true;
@ -1099,7 +1099,7 @@ AbstractClient *Workspace::findClientToActivateOnDesktop(VirtualDesktop *desktop
}
if (!(client->isShown(false) && client->isOnDesktop(desktop) &&
client->isOnCurrentActivity() && client->isOnActiveScreen()))
client->isOnCurrentActivity() && client->isOnActiveOutput()))
continue;
if (client->frameGeometry().contains(Cursors::self()->mouse()->pos())) {
@ -1926,7 +1926,7 @@ void Workspace::addInternalClient(InternalClient *client)
client->updateLayer();
if (client->isPlaceable()) {
const QRect area = clientArea(PlacementArea, client, screens()->current());
const QRect area = clientArea(PlacementArea, client, screens()->currentOutput());
client->placeIn(area);
}

View file

@ -1235,7 +1235,7 @@ void XdgToplevelClient::initialize()
needsPlacement = false;
}
if (needsPlacement) {
const QRect area = workspace()->clientArea(PlacementArea, this, Screens::self()->current());
const QRect area = workspace()->clientArea(PlacementArea, this, Screens::self()->currentOutput());
placeIn(area);
}
@ -2058,7 +2058,7 @@ void XdgPopupClient::initialize()
updateReactive();
const QRect area = workspace()->clientArea(PlacementArea, this, Screens::self()->current());
const QRect area = workspace()->clientArea(PlacementArea, this, Screens::self()->currentOutput());
placeIn(area);
scheduleConfigure();
}