plasma: windows runner review

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-04-17 22:11:52 +03:00
parent 8a8631e902
commit 669c74744e
2 changed files with 151 additions and 132 deletions

View file

@ -34,7 +34,6 @@ WindowsRunner::WindowsRunner(QObject* parent, const QVariantList& args)
m_inSession(false),
m_ready(false)
{
Q_UNUSED(args)
setObjectName( QLatin1String("Windows" ));
addSyntax(Plasma::RunnerSyntax(":q:", i18n("Finds windows whose name, window class or window role match :q:. "
@ -57,10 +56,6 @@ WindowsRunner::WindowsRunner(QObject* parent, const QVariantList& args)
connect(this, SIGNAL(teardown()), this, SLOT(matchSessionComplete()));
}
WindowsRunner::~WindowsRunner()
{
}
void WindowsRunner::gatherInfo()
{
if (!m_inSession) {
@ -68,15 +63,20 @@ void WindowsRunner::gatherInfo()
}
foreach (const WId w, KWindowSystem::windows()) {
KWindowInfo info = KWindowSystem::windowInfo(w, NET::WMWindowType | NET::WMDesktop |
KWindowInfo info = KWindowSystem::windowInfo(
w,
NET::WMWindowType | NET::WMDesktop |
NET::WMState | NET::XAWMState |
NET::WMName,
NET::WM2WindowClass | NET::WM2WindowRole | NET::WM2AllowedActions);
NET::WM2WindowClass | NET::WM2WindowRole | NET::WM2AllowedActions
);
if (info.valid()) {
// ignore NET::Tool and other special window types
NET::WindowType wType = info.windowType(NET::NormalMask | NET::DesktopMask | NET::DockMask |
NET::WindowType wType = info.windowType(
NET::NormalMask | NET::DesktopMask | NET::DockMask |
NET::ToolbarMask | NET::MenuMask | NET::DialogMask |
NET::UtilityMask | NET::SplashMask);
NET::UtilityMask | NET::SplashMask
);
if (wType != NET::Normal && wType != NET::Unknown &&
wType != NET::Dialog && wType != NET::Utility) {
@ -258,7 +258,7 @@ void WindowsRunner::match(Plasma::RunnerContext& context)
}
// blacklisted everything else: we have a match
if (actionSupported(info, action)){
matches << windowMatch(info, action);
matches << windowMatch(info, action, 1.0, Plasma::QueryMatch::ExactMatch);
}
}
@ -356,51 +356,56 @@ void WindowsRunner::run(const Plasma::RunnerContext& context, const Plasma::Quer
WId w = WId(parts[1].toULong());
KWindowInfo info = m_windows[w];
switch (action) {
case ActivateAction:
case ActivateAction: {
KWindowSystem::forceActiveWindow(w);
break;
case CloseAction:
{
}
case CloseAction: {
NETRootInfo ri(QX11Info::display(), NET::CloseWindow);
ri.closeWindowRequest(w);
break;
}
case MinimizeAction:
case MinimizeAction: {
if (info.isMinimized()) {
KWindowSystem::unminimizeWindow(w);
} else {
KWindowSystem::minimizeWindow(w);
}
break;
case MaximizeAction:
}
case MaximizeAction: {
if (info.hasState(NET::Max)) {
KWindowSystem::clearState(w, NET::Max);
} else {
KWindowSystem::setState(w, NET::Max);
}
break;
case FullscreenAction:
}
case FullscreenAction: {
if (info.hasState(NET::FullScreen)) {
KWindowSystem::clearState(w, NET::FullScreen);
} else {
KWindowSystem::setState(w, NET::FullScreen);
}
break;
case ShadeAction:
}
case ShadeAction: {
if (info.hasState(NET::Shaded)) {
KWindowSystem::clearState(w, NET::Shaded);
} else {
KWindowSystem::setState(w, NET::Shaded);
}
break;
case KeepAboveAction:
}
case KeepAboveAction: {
if (info.hasState(NET::KeepAbove)) {
KWindowSystem::clearState(w, NET::KeepAbove);
} else {
KWindowSystem::setState(w, NET::KeepAbove);
}
break;
case KeepBelowAction:
}
case KeepBelowAction: {
if (info.hasState(NET::KeepBelow)) {
KWindowSystem::clearState(w, NET::KeepBelow);
} else {
@ -409,6 +414,7 @@ void WindowsRunner::run(const Plasma::RunnerContext& context, const Plasma::Quer
break;
}
}
}
Plasma::QueryMatch WindowsRunner::desktopMatch(int desktop, qreal relevance)
{
@ -433,7 +439,7 @@ Plasma::QueryMatch WindowsRunner::windowMatch(const KWindowInfo& info, WindowAct
{
Plasma::QueryMatch match(this);
match.setType(type);
match.setData(QString(QString::number((int)action) + "_" + QString::number(info.win())));
match.setData(QString::number((int)action) + QLatin1String("_") + QString::number(info.win()));
match.setIcon(m_icons[info.win()]);
match.setText(info.name());
QString desktopName;
@ -447,32 +453,40 @@ Plasma::QueryMatch WindowsRunner::windowMatch(const KWindowInfo& info, WindowAct
desktopName = KWindowSystem::desktopName(desktop);
}
switch (action) {
case CloseAction:
case CloseAction: {
match.setSubtext(i18n("Close running window on %1", desktopName));
break;
case MinimizeAction:
}
case MinimizeAction: {
match.setSubtext(i18n("(Un)minimize running window on %1", desktopName));
break;
case MaximizeAction:
}
case MaximizeAction: {
match.setSubtext(i18n("Maximize/restore running window on %1", desktopName));
break;
case FullscreenAction:
}
case FullscreenAction: {
match.setSubtext(i18n("Toggle fullscreen for running window on %1", desktopName));
break;
case ShadeAction:
}
case ShadeAction: {
match.setSubtext(i18n("(Un)shade running window on %1", desktopName));
break;
case KeepAboveAction:
}
case KeepAboveAction: {
match.setSubtext(i18n("Toggle keep above for running window on %1", desktopName));
break;
case KeepBelowAction:
}
case KeepBelowAction: {
match.setSubtext(i18n("Toggle keep below running window on %1", desktopName));
break;
}
case ActivateAction:
default:
default: {
match.setSubtext(i18n("Activate running window on %1", desktopName));
break;
}
}
match.setRelevance(relevance);
return match;
}
@ -480,22 +494,29 @@ Plasma::QueryMatch WindowsRunner::windowMatch(const KWindowInfo& info, WindowAct
bool WindowsRunner::actionSupported(const KWindowInfo &info, WindowAction action)
{
switch (action) {
case CloseAction:
case CloseAction: {
return info.actionSupported(NET::ActionClose);
case MinimizeAction:
}
case MinimizeAction: {
return info.actionSupported(NET::ActionMinimize);
case MaximizeAction:
}
case MaximizeAction: {
return info.actionSupported(NET::ActionMax);
case ShadeAction:
}
case ShadeAction: {
return info.actionSupported(NET::ActionShade);
case FullscreenAction:
}
case FullscreenAction: {
return info.actionSupported(NET::ActionFullScreen);
}
case KeepAboveAction:
case KeepBelowAction:
case ActivateAction:
default:
default: {
return true;
}
}
Q_UNREACHABLE();
}
#include "moc_windowsrunner.cpp"

View file

@ -26,13 +26,11 @@ class KWindowInfo;
class WindowsRunner : public Plasma::AbstractRunner
{
Q_OBJECT
public:
WindowsRunner(QObject* parent, const QVariantList &args);
~WindowsRunner();
virtual void match(Plasma::RunnerContext& context);
virtual void run(const Plasma::RunnerContext& context, const Plasma::QueryMatch& match);
void match(Plasma::RunnerContext &context) final;
void run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match) final;
private Q_SLOTS:
void prepareForMatchSession();
@ -51,16 +49,16 @@ class WindowsRunner : public Plasma::AbstractRunner
KeepBelowAction
};
Plasma::QueryMatch desktopMatch(int desktop, qreal relevance = 1.0);
Plasma::QueryMatch windowMatch(const KWindowInfo& info, WindowAction action, qreal relevance = 1.0,
Plasma::QueryMatch::Type type = Plasma::QueryMatch::ExactMatch);
Plasma::QueryMatch windowMatch(const KWindowInfo &info, WindowAction action, qreal relevance,
Plasma::QueryMatch::Type type);
bool actionSupported(const KWindowInfo& info, WindowAction action);
QHash<WId, KWindowInfo> m_windows;
QHash<WId, QIcon> m_icons;
QStringList m_desktopNames;
bool m_inSession : 1;
bool m_ready : 1;
bool m_inSession;
bool m_ready;
};
K_EXPORT_PLASMA_RUNNER(windows, WindowsRunner)