2019-06-27 21:56:49 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
2022-12-11 08:48:25 +02:00
|
|
|
Copyright (C) 2019 Ivailo Monev <xakepa10@gmail.com>
|
2019-06-27 21:56:49 +00:00
|
|
|
|
|
|
|
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/>.
|
|
|
|
*********************************************************************/
|
2023-08-27 22:53:28 +03:00
|
|
|
|
2019-06-27 21:56:49 +00:00
|
|
|
#include "startupfeedback.h"
|
|
|
|
#include "client.h"
|
2023-08-27 22:53:28 +03:00
|
|
|
#include "effects.h"
|
2019-06-27 21:56:49 +00:00
|
|
|
// KDE
|
|
|
|
#include <KConfigGroup>
|
|
|
|
#include <KDebug>
|
|
|
|
#include <KGlobal>
|
|
|
|
#include <KStartupInfo>
|
|
|
|
|
|
|
|
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)
|
2023-08-27 22:53:28 +03:00
|
|
|
, m_type(StartupFeedbackEffect::PassiveFeedback)
|
2022-12-05 20:17:50 +02:00
|
|
|
, m_cursor(Qt::WaitCursor)
|
2019-06-27 21:56:49 +00:00
|
|
|
{
|
2022-12-05 23:08:54 +02:00
|
|
|
reconfigure(ReconfigureAll);
|
|
|
|
|
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)));
|
|
|
|
}
|
|
|
|
|
|
|
|
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-12-05 23:08:54 +02:00
|
|
|
const int timeout = c.readEntry("Timeout", 10);
|
|
|
|
m_startupInfo->setTimeout(timeout);
|
2019-06-27 21:56:49 +00:00
|
|
|
if (!busyCursor) {
|
2023-08-27 22:53:28 +03:00
|
|
|
m_type = StartupFeedbackEffect::NoFeedback;
|
2019-06-27 21:56:49 +00:00
|
|
|
} else {
|
2023-08-27 22:53:28 +03:00
|
|
|
m_type = StartupFeedbackEffect::PassiveFeedback;
|
2019-06-27 21:56:49 +00:00
|
|
|
}
|
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
|
|
|
{
|
2023-08-27 22:53:28 +03:00
|
|
|
if (m_type == StartupFeedbackEffect::NoFeedback) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
effects->startMouseInterception(this, Qt::WaitCursor);
|
|
|
|
xcb_window_t interceptionwindow = effects->mouseInterceptionWindow();
|
|
|
|
if (interceptionwindow == XCB_WINDOW_NONE) {
|
|
|
|
kWarning() << "no mouse interception window";
|
|
|
|
effects->stopMouseInterception(this);
|
|
|
|
m_active = false;
|
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
|
|
|
|
2022-10-29 07:11:05 +03:00
|
|
|
ScopedCPointer<xcb_grab_pointer_reply_t> grabPointer(
|
|
|
|
xcb_grab_pointer_reply(
|
2023-08-27 22:53:28 +03:00
|
|
|
connection(),
|
|
|
|
xcb_grab_pointer_unchecked(
|
|
|
|
connection(), true, interceptionwindow,
|
|
|
|
XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_POINTER_MOTION,
|
2022-10-29 07:11:05 +03:00
|
|
|
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, XCB_WINDOW_NONE,
|
2023-08-27 22:53:28 +03: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";
|
2023-08-27 22:53:28 +03:00
|
|
|
effects->stopMouseInterception(this);
|
2022-11-04 04:31:58 +02:00
|
|
|
m_active = false;
|
2019-06-27 21:56:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-08-27 22:53:28 +03:00
|
|
|
|
2019-06-27 21:56:49 +00:00
|
|
|
m_active = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void StartupFeedbackEffect::stop()
|
|
|
|
{
|
|
|
|
switch(m_type) {
|
2023-08-27 22:53:28 +03:00
|
|
|
case StartupFeedbackEffect::PassiveFeedback: {
|
2019-06-27 21:56:49 +00:00
|
|
|
if (m_active) {
|
|
|
|
xcb_ungrab_pointer(connection(), XCB_TIME_CURRENT_TIME);
|
2023-08-27 22:53:28 +03:00
|
|
|
effects->stopMouseInterception(this);
|
2019-06-27 21:56:49 +00:00
|
|
|
m_active = false;
|
|
|
|
}
|
|
|
|
break;
|
2023-08-27 22:53:28 +03:00
|
|
|
}
|
|
|
|
case StartupFeedbackEffect::NoFeedback: {
|
2022-12-05 07:30:01 +02:00
|
|
|
return;
|
2023-08-27 22:53:28 +03:00
|
|
|
}
|
|
|
|
default: {
|
|
|
|
// impossible
|
|
|
|
break;
|
|
|
|
}
|
2019-06-27 21:56:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool StartupFeedbackEffect::isActive() const
|
|
|
|
{
|
|
|
|
return m_active;
|
|
|
|
}
|
|
|
|
|
2023-08-27 22:53:28 +03:00
|
|
|
void StartupFeedbackEffect::windowInputMouseEvent(QEvent* e)
|
|
|
|
{
|
|
|
|
if (e->type() == QEvent::MouseButtonRelease) {
|
|
|
|
stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-27 21:56:49 +00:00
|
|
|
} // namespace
|