2019-06-27 21:56:49 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2010 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
|
|
|
#include "startupfeedback.h"
|
|
|
|
#include "client.h"
|
|
|
|
// Qt
|
|
|
|
#include <QCursor>
|
|
|
|
// KDE
|
|
|
|
#include <KConfigGroup>
|
|
|
|
#include <KDebug>
|
|
|
|
#include <KGlobal>
|
|
|
|
#include <KIconLoader>
|
|
|
|
#include <KStandardDirs>
|
|
|
|
#include <KStartupInfo>
|
|
|
|
|
|
|
|
// based on StartupId in KRunner by Lubos Lunak
|
|
|
|
// Copyright (C) 2001 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
// Copyright (C) 2019 Ivailo Monev <xakepa10@gmail.com>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
StartupFeedbackEffect::StartupFeedbackEffect()
|
|
|
|
: m_startupInfo(new KStartupInfo(KStartupInfo::CleanOnCantDetect, this))
|
2022-12-05 20:17:50 +02:00
|
|
|
, m_startups(0)
|
2019-06-27 21:56:49 +00:00
|
|
|
, m_active(false)
|
|
|
|
, m_type(PassiveFeedback)
|
2022-12-05 20:17:50 +02:00
|
|
|
, m_cursor(Qt::WaitCursor)
|
2019-06-27 21:56:49 +00:00
|
|
|
{
|
|
|
|
connect(m_startupInfo, SIGNAL(gotNewStartup(KStartupInfoId,KStartupInfoData)), SLOT(gotNewStartup(KStartupInfoId,KStartupInfoData)));
|
|
|
|
connect(m_startupInfo, SIGNAL(gotRemoveStartup(KStartupInfoId,KStartupInfoData)), SLOT(gotRemoveStartup(KStartupInfoId,KStartupInfoData)));
|
|
|
|
reconfigure(ReconfigureAll);
|
|
|
|
}
|
|
|
|
|
|
|
|
StartupFeedbackEffect::~StartupFeedbackEffect()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void StartupFeedbackEffect::reconfigure(Effect::ReconfigureFlags flags)
|
|
|
|
{
|
|
|
|
Q_UNUSED(flags)
|
2022-12-05 07:30:01 +02:00
|
|
|
const bool oldactive = m_active;
|
|
|
|
if (oldactive) {
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
2019-06-27 21:56:49 +00:00
|
|
|
KConfig conf("klaunchrc", KConfig::NoGlobals);
|
|
|
|
KConfigGroup c = conf.group("FeedbackStyle");
|
|
|
|
const bool busyCursor = c.readEntry("BusyCursor", true);
|
|
|
|
|
|
|
|
c = conf.group("BusyCursorSettings");
|
2022-10-26 08:11:58 +03:00
|
|
|
m_startupInfo->setTimeout(c.readEntry("Timeout", 10));
|
2019-06-27 21:56:49 +00:00
|
|
|
if (!busyCursor) {
|
|
|
|
m_type = NoFeedback;
|
|
|
|
} else {
|
|
|
|
m_type = PassiveFeedback;
|
|
|
|
}
|
2022-12-05 07:30:01 +02:00
|
|
|
if (oldactive) {
|
2022-12-05 20:17:50 +02:00
|
|
|
start();
|
2019-06-27 21:56:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void StartupFeedbackEffect::gotNewStartup(const KStartupInfoId& id, const KStartupInfoData& data)
|
|
|
|
{
|
2022-12-05 20:17:50 +02:00
|
|
|
Q_UNUSED(id);
|
|
|
|
Q_UNUSED(data);
|
2019-06-27 21:56:49 +00:00
|
|
|
|
2022-12-05 20:17:50 +02:00
|
|
|
m_startups++;
|
|
|
|
if (!m_active) {
|
|
|
|
start();
|
2019-06-27 21:56:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-05 20:17:50 +02:00
|
|
|
void StartupFeedbackEffect::gotRemoveStartup(const KStartupInfoId& id, const KStartupInfoData& data)
|
2019-06-27 21:56:49 +00:00
|
|
|
{
|
2022-12-05 20:17:50 +02:00
|
|
|
Q_UNUSED(id);
|
|
|
|
Q_UNUSED(data);
|
|
|
|
|
|
|
|
m_startups--;
|
|
|
|
if (m_startups <= 0) {
|
|
|
|
m_startups = 0;
|
|
|
|
stop();
|
2019-06-27 21:56:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-05 20:17:50 +02:00
|
|
|
void StartupFeedbackEffect::start()
|
2019-06-27 21:56:49 +00:00
|
|
|
{
|
2022-11-04 04:31:58 +02:00
|
|
|
if (m_type == NoFeedback) {
|
2019-06-27 21:56:49 +00:00
|
|
|
return;
|
2022-11-04 04:31:58 +02:00
|
|
|
}
|
2019-06-27 21:56:49 +00:00
|
|
|
|
|
|
|
xcb_connection_t *c = connection();
|
2022-10-29 07:11:05 +03:00
|
|
|
ScopedCPointer<xcb_grab_pointer_reply_t> grabPointer(
|
|
|
|
xcb_grab_pointer_reply(
|
|
|
|
c,
|
|
|
|
xcb_grab_pointer_unchecked(c, false, rootWindow(),
|
|
|
|
XCB_EVENT_MASK_NO_EVENT,
|
|
|
|
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, XCB_WINDOW_NONE,
|
2022-12-05 20:17:50 +02:00
|
|
|
m_cursor.handle(), XCB_TIME_CURRENT_TIME),
|
2022-10-29 07:11:05 +03:00
|
|
|
NULL
|
|
|
|
)
|
|
|
|
);
|
2019-06-27 21:56:49 +00:00
|
|
|
if (grabPointer.isNull() || grabPointer->status != XCB_GRAB_STATUS_SUCCESS) {
|
|
|
|
kWarning() << "could not grab pointer";
|
2022-11-04 04:31:58 +02:00
|
|
|
m_active = false;
|
2019-06-27 21:56:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_active = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StartupFeedbackEffect::stop()
|
|
|
|
{
|
|
|
|
switch(m_type) {
|
|
|
|
case PassiveFeedback:
|
|
|
|
if (m_active) {
|
|
|
|
xcb_ungrab_pointer(connection(), XCB_TIME_CURRENT_TIME);
|
|
|
|
m_active = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case NoFeedback:
|
2022-12-05 07:30:01 +02:00
|
|
|
return;
|
2019-06-27 21:56:49 +00:00
|
|
|
default:
|
|
|
|
break; // impossible
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StartupFeedbackEffect::isActive() const
|
|
|
|
{
|
|
|
|
return m_active;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|