Commit 71914795 authored by Xaver Hugl's avatar Xaver Hugl
Browse files

rulebook: move singleton to Workspace

parent 0d704b89
......@@ -68,7 +68,7 @@ void WindowRuleTest::init()
void WindowRuleTest::cleanup()
{
// discards old rules
RuleBook::self()->load();
workspace()->rulebook()->load();
}
struct XcbConnectionDeleter
......@@ -94,7 +94,7 @@ void WindowRuleTest::testApplyInitialMaximizeVert()
// load the rule
QFile ruleFile(QFINDTESTDATA("./data/rules/maximize-vert-apply-initial"));
QVERIFY(ruleFile.open(QIODevice::ReadOnly | QIODevice::Text));
QMetaObject::invokeMethod(RuleBook::self(), "temporaryRulesMessage", Q_ARG(QString, QString::fromUtf8(ruleFile.readAll())));
QMetaObject::invokeMethod(workspace()->rulebook(), "temporaryRulesMessage", Q_ARG(QString, QString::fromUtf8(ruleFile.readAll())));
// create the test window
QScopedPointer<xcb_connection_t, XcbConnectionDeleter> c(xcb_connect(nullptr, nullptr));
......@@ -161,7 +161,7 @@ void WindowRuleTest::testWindowClassChange()
group.writeEntry("wmclassmatch", 1);
group.sync();
RuleBook::self()->setConfig(config);
workspace()->rulebook()->setConfig(config);
workspace()->slotReconfigure();
// create the test window
......
......@@ -193,7 +193,7 @@ void TestXdgShellWindowRules::initTestCase()
Test::initWaylandWorkspace();
m_config = KSharedConfig::openConfig(QStringLiteral("kwinrulesrc"), KConfig::SimpleConfig);
RuleBook::self()->setConfig(m_config);
workspace()->rulebook()->setConfig(m_config);
}
void TestXdgShellWindowRules::init()
......
......@@ -776,7 +776,7 @@ void WindowRules::update(Window *c, int selection)
}
}
if (updated) {
RuleBook::self()->requestDiskStorage();
workspace()->rulebook()->requestDiskStorage();
}
}
......@@ -879,11 +879,8 @@ CHECK_RULE(DesktopFile, QString)
#undef CHECK_RULE
#undef CHECK_FORCE_RULE
KWIN_SINGLETON_FACTORY(RuleBook)
RuleBook::RuleBook(QObject *parent)
: QObject(parent)
, m_updateTimer(new QTimer(this))
RuleBook::RuleBook()
: m_updateTimer(new QTimer(this))
, m_updatesDisabled(false)
, m_temporaryRulesMessages()
{
......
......@@ -301,6 +301,7 @@ class KWIN_EXPORT RuleBook : public QObject
{
Q_OBJECT
public:
explicit RuleBook();
~RuleBook() override;
WindowRules find(const Window *, bool);
void discardUsed(Window *c, bool withdraw);
......@@ -329,8 +330,6 @@ private:
QList<Rules *> m_rules;
QScopedPointer<KXMessages> m_temporaryRulesMessages;
KSharedConfig::Ptr m_config;
KWIN_SINGLETON(RuleBook)
};
inline bool RuleBook::areUpdatesDisabled() const
......
......@@ -370,11 +370,11 @@ void SessionManager::setState(SessionState state)
}
// If we're starting to save a session
if (state == SessionState::Saving) {
RuleBook::self()->setUpdatesDisabled(true);
workspace()->rulebook()->setUpdatesDisabled(true);
}
// If we're ending a save session due to either completion or cancellation
if (m_sessionState == SessionState::Saving) {
RuleBook::self()->setUpdatesDisabled(false);
workspace()->rulebook()->setUpdatesDisabled(false);
Workspace::self()->forEachClient([](X11Window *client) {
client->setSessionActivityOverride(false);
});
......
......@@ -1260,10 +1260,10 @@ void Workspace::performWindowOperation(Window *window, Options::WindowOperation
window->performMouseCommand(Options::MouseShade, Cursors::self()->mouse()->pos());
break;
case Options::WindowRulesOp:
RuleBook::self()->edit(window, false);
m_rulebook->edit(window, false);
break;
case Options::ApplicationRulesOp:
RuleBook::self()->edit(window, true);
m_rulebook->edit(window, true);
break;
case Options::SetupWindowShortcutOp:
setupWindowShortcut(window);
......
......@@ -4442,13 +4442,13 @@ void Window::cleanTabBox()
void Window::setupWindowRules(bool ignore_temporary)
{
disconnect(this, &Window::captionChanged, this, &Window::evaluateWindowRules);
m_rules = RuleBook::self()->find(this, ignore_temporary);
m_rules = workspace()->rulebook()->find(this, ignore_temporary);
// check only after getting the rules, because there may be a rule forcing window type
}
void Window::updateWindowRules(Rules::Types selection)
{
if (RuleBook::self()->areUpdatesDisabled()) {
if (workspace()->rulebook()->areUpdatesDisabled()) {
return;
}
m_rules.update(this, selection);
......
......@@ -154,7 +154,8 @@ Workspace::Workspace()
m_quickTileCombineTimer = new QTimer(this);
m_quickTileCombineTimer->setSingleShot(true);
RuleBook::create(this)->load();
m_rulebook = std::make_unique<RuleBook>();
m_rulebook->load();
Screens::create(this);
ScreenEdges::create(this);
......@@ -487,7 +488,7 @@ Workspace::~Workspace()
it = deleted.erase(it);
}
delete RuleBook::self();
m_rulebook.reset();
kwinApp()->config()->sync();
m_placement.reset();
......@@ -957,11 +958,11 @@ void Workspace::slotReconfigure()
m_userActionsMenu->discard();
updateToolWindows(true);
RuleBook::self()->load();
m_rulebook->load();
for (Window *window : qAsConst(m_allClients)) {
if (window->supportsWindowRules()) {
window->evaluateWindowRules();
RuleBook::self()->discardUsed(window, false);
m_rulebook->discardUsed(window, false);
}
}
......@@ -2852,6 +2853,11 @@ Placement *Workspace::placement() const
return m_placement.get();
}
RuleBook *Workspace::rulebook() const
{
return m_rulebook.get();
}
#if KWIN_BUILD_ACTIVITIES
Activities *Workspace::activities() const
{
......
......@@ -63,6 +63,7 @@ class FocusChain;
class ApplicationMenu;
enum class Predicate;
class Outline;
class RuleBook;
#if KWIN_BUILD_ACTIVITIES
class Activities;
#endif
......@@ -439,6 +440,7 @@ public:
Decoration::DecorationBridge *decorationBridge() const;
Outline *outline() const;
Placement *placement() const;
RuleBook *rulebook() const;
#if KWIN_BUILD_ACTIVITIES
Activities *activities() const;
#endif
......@@ -715,6 +717,7 @@ private:
std::unique_ptr<Decoration::DecorationBridge> m_decorationBridge;
std::unique_ptr<Outline> m_outline;
std::unique_ptr<Placement> m_placement;
std::unique_ptr<RuleBook> m_rulebook;
#if KWIN_BUILD_ACTIVITIES
std::unique_ptr<Activities> m_activities;
#endif
......
......@@ -291,7 +291,7 @@ void X11Window::releaseWindow(bool on_shutdown)
}
Q_EMIT windowClosed(this, del);
finishCompositing();
RuleBook::self()->discardUsed(this, true); // Remove ForceTemporarily rules
workspace()->rulebook()->discardUsed(this, true); // Remove ForceTemporarily rules
StackingUpdatesBlocker blocker(workspace());
if (isInteractiveMoveResize()) {
leaveInteractiveMoveResize();
......@@ -357,7 +357,7 @@ void X11Window::destroyWindow()
}
Q_EMIT windowClosed(this, del);
finishCompositing(ReleaseReason::Destroyed);
RuleBook::self()->discardUsed(this, true); // Remove ForceTemporarily rules
workspace()->rulebook()->discardUsed(this, true); // Remove ForceTemporarily rules
StackingUpdatesBlocker blocker(workspace());
if (isInteractiveMoveResize()) {
leaveInteractiveMoveResize();
......@@ -956,7 +956,7 @@ bool X11Window::manage(xcb_window_t w, bool isMapped)
discardTemporaryRules();
applyWindowRules(); // Just in case
RuleBook::self()->discardUsed(this, false); // Remove ApplyNow rules
workspace()->rulebook()->discardUsed(this, false); // Remove ApplyNow rules
updateWindowRules(Rules::All); // Was blocked while !isManaged()
setBlockingCompositing(info->isBlockingCompositing());
......
......@@ -333,7 +333,7 @@ void XdgSurfaceWindow::destroyWindow()
Deleted *deleted = Deleted::create(this);
Q_EMIT windowClosed(this, deleted);
StackingUpdatesBlocker blocker(workspace());
RuleBook::self()->discardUsed(this, true);
workspace()->rulebook()->discardUsed(this, true);
setDecoration(nullptr);
cleanGrouping();
waylandServer()->removeWindow(this);
......@@ -1401,7 +1401,7 @@ void XdgToplevelWindow::initialize()
}
discardTemporaryRules();
RuleBook::self()->discardUsed(this, false); // Remove Apply Now rules.
workspace()->rulebook()->discardUsed(this, false); // Remove Apply Now rules.
updateWindowRules(Rules::All);
if (isRequestedFullScreen()) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment