scripting: Handle bad output and desktop ids gracefully
Don't crash if a script has provided bad screen or desktop id to clientArea(). CCBUG: 449957
This commit is contained in:
parent
3c0ed5643b
commit
ac97e282fc
1 changed files with 24 additions and 14 deletions
|
@ -285,26 +285,36 @@ QRect WorkspaceWrapper::clientArea(ClientAreaOption option, KWin::Window *c) con
|
|||
return Workspace::self()->clientArea(static_cast<clientAreaOption>(option), c);
|
||||
}
|
||||
|
||||
QRect WorkspaceWrapper::clientArea(ClientAreaOption option, int screen, int desktop) const
|
||||
static VirtualDesktop *resolveDesktop(int desktopId)
|
||||
{
|
||||
VirtualDesktop *virtualDesktop;
|
||||
Output *output;
|
||||
auto vdm = VirtualDesktopManager::self();
|
||||
if (desktopId == NETWinInfo::OnAllDesktops || desktopId == 0) {
|
||||
return vdm->currentDesktop();
|
||||
}
|
||||
return vdm->desktopForX11Id(desktopId);
|
||||
}
|
||||
|
||||
if (desktop == NETWinInfo::OnAllDesktops || desktop == 0) {
|
||||
virtualDesktop = VirtualDesktopManager::self()->currentDesktop();
|
||||
} else {
|
||||
virtualDesktop = VirtualDesktopManager::self()->desktopForX11Id(desktop);
|
||||
Q_ASSERT(virtualDesktop);
|
||||
static Output *resolveOutput(int outputId)
|
||||
{
|
||||
if (outputId == -1) {
|
||||
return workspace()->activeOutput();
|
||||
}
|
||||
return kwinApp()->platform()->findOutput(outputId);
|
||||
}
|
||||
|
||||
QRect WorkspaceWrapper::clientArea(ClientAreaOption option, int outputId, int desktopId) const
|
||||
{
|
||||
VirtualDesktop *desktop = resolveDesktop(desktopId);
|
||||
if (Q_UNLIKELY(!desktop)) {
|
||||
return QRect();
|
||||
}
|
||||
|
||||
if (screen == -1) {
|
||||
output = workspace()->activeOutput();
|
||||
} else {
|
||||
output = kwinApp()->platform()->findOutput(screen);
|
||||
Q_ASSERT(output);
|
||||
Output *output = resolveOutput(outputId);
|
||||
if (Q_UNLIKELY(!output)) {
|
||||
return QRect();
|
||||
}
|
||||
|
||||
return workspace()->clientArea(static_cast<clientAreaOption>(option), output, virtualDesktop);
|
||||
return workspace()->clientArea(static_cast<clientAreaOption>(option), output, desktop);
|
||||
}
|
||||
|
||||
QRect WorkspaceWrapper::clientArea(ClientAreaOption option, Output *output, VirtualDesktop *desktop) const
|
||||
|
|
Loading…
Reference in a new issue