on edcd710 help sign in
unity8/plugins/WindowManager/TopLevelWindowModel.cpp
781 lines 25 kB history raw
1/*
2 * Copyright (C) 2016-2017 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17#include "TopLevelWindowModel.h"
19// unity-api
20#include <unity/shell/application/ApplicationInfoInterface.h>
21#include <unity/shell/application/ApplicationManagerInterface.h>
22#include <unity/shell/application/MirSurfaceInterface.h>
23#include <unity/shell/application/MirSurfaceListInterface.h>
24#include <unity/shell/application/SurfaceManagerInterface.h>
26// Qt
27#include <QGuiApplication>
28#include <QDebug>
30// local
31#include "Window.h"
33Q_LOGGING_CATEGORY(TOPLEVELWINDOWMODEL, "toplevelwindowmodel", QtInfoMsg)
35#define DEBUG_MSG qCDebug(TOPLEVELWINDOWMODEL).nospace().noquote() << __func__
36#define INFO_MSG qCInfo(TOPLEVELWINDOWMODEL).nospace().noquote() << __func__
38namespace unityapi = unity::shell::application;
40TopLevelWindowModel::TopLevelWindowModel()
41 : m_nullWindow(createWindow(nullptr))
43 connect(m_nullWindow, &Window::focusedChanged, this, [this] {
44 Q_EMIT rootFocusChanged();
45 });
48void TopLevelWindowModel::setApplicationManager(unityapi::ApplicationManagerInterface* value)
50 if (m_applicationManager == value) {
51 return;
52 }
54 DEBUG_MSG << "(" << value << ")";
56 Q_ASSERT(m_modelState == IdleState);
57 m_modelState = ResettingState;
59 beginResetModel();
61 if (m_applicationManager) {
62 m_windowModel.clear();
63 disconnect(m_applicationManager, 0, this, 0);
64 }
66 m_applicationManager = value;
68 if (m_applicationManager) {
69 connect(m_applicationManager, &QAbstractItemModel::rowsInserted,
70 this, [this](const QModelIndex &/*parent*/, int first, int last) {
71 for (int i = first; i <= last; ++i) {
72 auto application = m_applicationManager->get(i);
73 addApplication(application);
74 }
75 });
77 connect(m_applicationManager, &QAbstractItemModel::rowsAboutToBeRemoved,
78 this, [this](const QModelIndex &/*parent*/, int first, int last) {
79 for (int i = first; i <= last; ++i) {
80 auto application = m_applicationManager->get(i);
81 removeApplication(application);
82 }
83 });
85 for (int i = 0; i < m_applicationManager->rowCount(); ++i) {
86 auto application = m_applicationManager->get(i);
87 addApplication(application);
88 }
89 }
91 endResetModel();
92 m_modelState = IdleState;
95void TopLevelWindowModel::setSurfaceManager(unityapi::SurfaceManagerInterface *surfaceManager)
97 if (surfaceManager == m_surfaceManager) {
98 return;
99 }
101 DEBUG_MSG << "(" << surfaceManager << ")";
103 if (m_surfaceManager) {
104 disconnect(m_surfaceManager, 0, this, 0);
105 }
107 m_surfaceManager = surfaceManager;
109 if (m_surfaceManager) {
110 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfaceCreated, this, &TopLevelWindowModel::onSurfaceCreated);
111 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::surfacesRaised, this, &TopLevelWindowModel::onSurfacesRaised);
112 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::modificationsStarted, this, &TopLevelWindowModel::onModificationsStarted);
113 connect(m_surfaceManager, &unityapi::SurfaceManagerInterface::modificationsEnded, this, &TopLevelWindowModel::onModificationsEnded);
114 }
116 Q_EMIT surfaceManagerChanged(m_surfaceManager);
119void TopLevelWindowModel::addApplication(unityapi::ApplicationInfoInterface *application)
121 DEBUG_MSG << "(" << application->appId() << ")";
123 if (application->state() != unityapi::ApplicationInfoInterface::Stopped && application->surfaceList()->count() == 0) {
124 prependPlaceholder(application);
125 }
128void TopLevelWindowModel::removeApplication(unityapi::ApplicationInfoInterface *application)
130 DEBUG_MSG << "(" << application->appId() << ")";
132 Q_ASSERT(m_modelState == IdleState);
134 int i = 0;
135 while (i < m_windowModel.count()) {
136 if (m_windowModel.at(i).application == application) {
137 deleteAt(i);
138 } else {
139 ++i;
140 }
141 }
144void TopLevelWindowModel::prependPlaceholder(unityapi::ApplicationInfoInterface *application)
146 INFO_MSG << "(" << application->appId() << ")";
148 prependSurfaceHelper(nullptr, application);
151void TopLevelWindowModel::prependSurface(unityapi::MirSurfaceInterface *surface, unityapi::ApplicationInfoInterface *application)
153 Q_ASSERT(surface != nullptr);
155 connectSurface(surface);
157 bool filledPlaceholder = false;
158 for (int i = 0; i < m_windowModel.count() && !filledPlaceholder; ++i) {
159 ModelEntry &entry = m_windowModel[i];
160 if (entry.application == application && entry.window->surface() == nullptr) {
161 entry.window->setSurface(surface);
162 INFO_MSG << " appId=" << application->appId() << " surface=" << surface
163 << ", filling out placeholder. after: " << toString();
164 filledPlaceholder = true;
165 }
166 }
168 if (!filledPlaceholder) {
169 INFO_MSG << " appId=" << application->appId() << " surface=" << surface << ", adding new row";
170 prependSurfaceHelper(surface, application);
171 }
174void TopLevelWindowModel::prependSurfaceHelper(unityapi::MirSurfaceInterface *surface, unityapi::ApplicationInfoInterface *application)
177 Window *window = createWindow(surface);
179 connect(window, &Window::stateChanged, this, [=](Mir::State newState) {
180 if (newState == Mir::HiddenState) {
181 // Comply, removing it from our model. Just as if it didn't exist anymore.
182 removeAt(indexForId(window->id()));
183 } else {
184 if (indexForId(window->id()) == -1) {
185 // was probably hidden before. put it back on the list
186 auto *application = m_applicationManager->findApplicationWithSurface(window->surface());
187 Q_ASSERT(application);
188 prependWindow(window, application);
189 }
190 }
191 });
193 prependWindow(window, application);
195 if (!surface) {
196 activateEmptyWindow(window);
197 }
199 INFO_MSG << " after " << toString();
202void TopLevelWindowModel::prependWindow(Window *window, unityapi::ApplicationInfoInterface *application)
204 if (m_modelState == IdleState) {
205 m_modelState = InsertingState;
206 beginInsertRows(QModelIndex(), 0 /*first*/, 0 /*last*/);
207 } else {
208 Q_ASSERT(m_modelState == ResettingState);
209 // No point in signaling anything if we're resetting the whole model
210 }
212 m_windowModel.prepend(ModelEntry(window, application));
214 if (m_modelState == InsertingState) {
215 endInsertRows();
216 Q_EMIT countChanged();
217 Q_EMIT listChanged();
218 m_modelState = IdleState;
219 }
222void TopLevelWindowModel::connectWindow(Window *window)
224 connect(window, &Window::focusRequested, this, [this, window]() {
225 if (!window->surface()) {
226 activateEmptyWindow(window);
227 }
228 });
230 connect(window, &Window::focusedChanged, this, [this, window](bool focused) {
231 if (window->surface()) {
232 // Condense changes to the focused window
233 // eg: Do focusedWindow=A to focusedWindow=B instead of
234 // focusedWindow=A to focusedWindow=null to focusedWindow=B
235 if (focused) {
236 Q_ASSERT(m_newlyFocusedWindow == nullptr);
237 m_focusedWindowChanged = true;
238 m_newlyFocusedWindow = window;
239 } else if (m_focusedWindow == window) {
240 m_focusedWindowChanged = true;
241 } else {
242 // don't clear the focused window if you were not there in the first place
243 // happens when a filled window gets replaced with an empty one (no surface) as the focused window.
244 }
245 }
246 });
248 connect(window, &Window::closeRequested, this, [this, window]() {
249 if (!window->surface()) {
250 // do things ourselves as miral doesn't know about this window
251 int id = window->id();
252 int index = indexForId(id);
253 bool focusOther = false;
254 Q_ASSERT(index >= 0);
255 if (window->focused()) {
256 focusOther = true;
257 }
258 m_windowModel[index].application->close();
259 if (focusOther) {
260 activateTopMostWindowWithoutId(id);
261 }
262 }
263 });
265 connect(window, &Window::emptyWindowActivated, this, [this, window]() {
266 activateEmptyWindow(window);
267 });
269 connect(window, &Window::liveChanged, this, [this, window](bool isAlive) {
270 if (!isAlive && window->state() == Mir::HiddenState) {
271 // Hidden windows are not in the model. So just delete it right away.
272 delete window;
273 }
274 });
277void TopLevelWindowModel::activateEmptyWindow(Window *window)
279 Q_ASSERT(!window->surface());
280 DEBUG_MSG << "(" << window << ")";
282 // miral doesn't know about empty windows (ie, windows that are not backed up by MirSurfaces)
283 // So we have to activate them ourselves (instead of asking SurfaceManager to do it for us).
285 window->setFocused(true);
286 raiseId(window->id());
287 Window *previousWindow = m_focusedWindow;
288 setFocusedWindow(window);
289 if (previousWindow && previousWindow->surface() && previousWindow->surface()->focused()) {
290 m_surfaceManager->activate(nullptr);
291 }
294void TopLevelWindowModel::connectSurface(unityapi::MirSurfaceInterface *surface)
296 connect(surface, &unityapi::MirSurfaceInterface::liveChanged, this, [this, surface](bool live){
297 if (!live) {
298 onSurfaceDied(surface);
299 }
300 });
301 connect(surface, &QObject::destroyed, this, [this, surface](){ this->onSurfaceDestroyed(surface); });
304void TopLevelWindowModel::onSurfaceDied(unityapi::MirSurfaceInterface *surface)
306 if (surface->type() == Mir::InputMethodType) {
307 removeInputMethodWindow();
308 return;
309 }
311 int i = indexOf(surface);
312 if (i == -1) {
313 return;
314 }
316 auto application = m_windowModel[i].application;
318 // can't be starting if it already has a surface
319 Q_ASSERT(application->state() != unityapi::ApplicationInfoInterface::Starting);
321 if (application->state() == unityapi::ApplicationInfoInterface::Running) {
322 m_windowModel[i].removeOnceSurfaceDestroyed = true;
323 } else {
324 // assume it got killed by the out-of-memory daemon.
325 //
326 // So leave entry in the model and only remove its surface, so shell can display a screenshot
327 // in its place.
328 m_windowModel[i].removeOnceSurfaceDestroyed = false;
329 }
332void TopLevelWindowModel::onSurfaceDestroyed(unityapi::MirSurfaceInterface *surface)
334 int i = indexOf(surface);
335 if (i == -1) {
336 return;
337 }
339 if (m_windowModel[i].removeOnceSurfaceDestroyed) {
340 deleteAt(i);
341 } else {
342 auto window = m_windowModel[i].window;
343 window->setSurface(nullptr);
344 window->setFocused(false);
345 INFO_MSG << " Removed surface from entry. After: " << toString();
346 }
349Window *TopLevelWindowModel::createWindow(unityapi::MirSurfaceInterface *surface)
351 int id = generateId();
352 Window *qmlWindow = new Window(id, this);
353 connectWindow(qmlWindow);
354 if (surface) {
355 qmlWindow->setSurface(surface);
356 }
357 return qmlWindow;
360void TopLevelWindowModel::onSurfaceCreated(unityapi::MirSurfaceInterface *surface)
362 DEBUG_MSG << "(" << surface << ")";
364 if (surface->parentSurface()) {
365 // Wrap it in a Window so that we keep focusedWindow() up to date.
366 Window *window = createWindow(surface);
367 connect(surface, &QObject::destroyed, window, [=](){
368 window->setSurface(nullptr);
369 window->deleteLater();
370 });
371 } else {
372 if (surface->type() == Mir::InputMethodType) {
373 connectSurface(surface);
374 setInputMethodWindow(createWindow(surface));
375 } else {
376 auto *application = m_applicationManager->findApplicationWithSurface(surface);
377 if (application) {
378 if (surface->state() == Mir::HiddenState) {
379 // Ignore it until it's finally shown
380 connect(surface, &unityapi::MirSurfaceInterface::stateChanged, this, [=](Mir::State newState) {
381 Q_ASSERT(newState != Mir::HiddenState);
382 disconnect(surface, &unityapi::MirSurfaceInterface::stateChanged, this, 0);
383 prependSurface(surface, application);
384 });
385 } else {
386 prependSurface(surface, application);
387 }
388 } else {
389 // Must be a prompt session. No need to do add it as a prompt surface is not top-level.
390 // It will show up in the ApplicationInfoInterface::promptSurfaceList of some application.
391 // Still wrap it in a Window though, so that we keep focusedWindow() up to date.
392 Window *promptWindow = createWindow(surface);
393 connect(surface, &QObject::destroyed, promptWindow, [=](){
394 promptWindow->setSurface(nullptr);
395 promptWindow->deleteLater();
396 });
397 }
398 }
399 }
402void TopLevelWindowModel::deleteAt(int index)
404 auto window = m_windowModel[index].window;
406 removeAt(index);
408 window->setSurface(nullptr);
410 delete window;
413void TopLevelWindowModel::removeAt(int index)
415 if (m_modelState == IdleState) {
416 beginRemoveRows(QModelIndex(), index, index);
417 m_modelState = RemovingState;
418 } else {
419 Q_ASSERT(m_modelState == ResettingState);
420 // No point in signaling anything if we're resetting the whole model
421 }
423 auto window = m_windowModel[index].window;
425 if (!window->surface()) {
426 window->setFocused(false);
427 }
429 m_windowModel.removeAt(index);
431 if (m_modelState == RemovingState) {
432 endRemoveRows();
433 Q_EMIT countChanged();
434 Q_EMIT listChanged();
435 m_modelState = IdleState;
436 }
438 if (m_focusedWindow == window) {
439 setFocusedWindow(nullptr);
440 }
442 if (m_closingAllApps) {
443 if (m_windowModel.isEmpty()) {
444 Q_EMIT closedAllWindows();
445 }
446 }
448 INFO_MSG << " after " << toString() << " apps left " << m_windowModel.count();
451void TopLevelWindowModel::setInputMethodWindow(Window *window)
453 if (m_inputMethodWindow) {
454 qWarning("Multiple Input Method Surfaces created, removing the old one!");
455 delete m_inputMethodWindow;
456 }
457 m_inputMethodWindow = window;
458 Q_EMIT inputMethodSurfaceChanged(m_inputMethodWindow->surface());
461void TopLevelWindowModel::removeInputMethodWindow()
463 if (m_inputMethodWindow) {
464 delete m_inputMethodWindow;
465 m_inputMethodWindow = nullptr;
466 Q_EMIT inputMethodSurfaceChanged(nullptr);
467 }
470void TopLevelWindowModel::onSurfacesRaised(const QVector<unityapi::MirSurfaceInterface*> &surfaces)
472 DEBUG_MSG << "(" << surfaces << ")";
473 const int raiseCount = surfaces.size();
474 for (int i = 0; i < raiseCount; i++) {
475 int fromIndex = findIndexOf(surfaces[i]);
476 if (fromIndex != -1) {
477 move(fromIndex, 0);
478 }
479 }
482int TopLevelWindowModel::rowCount(const QModelIndex &/*parent*/) const
484 return m_windowModel.count();
487QVariant TopLevelWindowModel::data(const QModelIndex& index, int role) const
489 if (index.row() < 0 || index.row() >= m_windowModel.size())
490 return QVariant();
492 if (role == WindowRole) {
493 Window *window = m_windowModel.at(index.row()).window;
494 return QVariant::fromValue(window);
495 } else if (role == ApplicationRole) {
496 return QVariant::fromValue(m_windowModel.at(index.row()).application);
497 } else {
498 return QVariant();
499 }
502int TopLevelWindowModel::findIndexOf(const unityapi::MirSurfaceInterface *surface) const
504 for (int i=0; i<m_windowModel.count(); i++) {
505 if (m_windowModel[i].window->surface() == surface) {
506 return i;
507 }
508 }
509 return -1;
512int TopLevelWindowModel::generateId()
514 int id = m_nextId;
515 m_nextId = nextFreeId(nextId(id), id);
516 return id;
519int TopLevelWindowModel::nextId(int id) const
521 if (id == m_maxId) {
522 return id = 1;
523 } else {
524 return id + 1;
525 }
528int TopLevelWindowModel::nextFreeId(int candidateId, const int latestId)
530 int firstCandidateId = candidateId;
532 while (indexForId(candidateId) != -1 || candidateId == latestId) {
533 candidateId = nextId(candidateId);
535 if (candidateId == firstCandidateId) {
536 qFatal("TopLevelWindowModel: run out of window ids.");
537 }
538 }
540 return candidateId;
543QString TopLevelWindowModel::toString()
545 QString str;
546 for (int i = 0; i < m_windowModel.count(); ++i) {
547 auto item = m_windowModel.at(i);
549 QString itemStr = QString("(index=%1,appId=%2,surface=0x%3,id=%4)")
550 .arg(QString::number(i),
551 item.application->appId(),
552 QString::number((qintptr)item.window->surface(), 16),
553 QString::number(item.window->id()));
555 if (i > 0) {
556 str.append(",");
557 }
558 str.append(itemStr);
559 }
560 return str;
563int TopLevelWindowModel::indexOf(unityapi::MirSurfaceInterface *surface)
565 for (int i = 0; i < m_windowModel.count(); ++i) {
566 if (m_windowModel.at(i).window->surface() == surface) {
567 return i;
568 }
569 }
570 return -1;
573int TopLevelWindowModel::indexForId(int id) const
575 for (int i = 0; i < m_windowModel.count(); ++i) {
576 if (m_windowModel[i].window->id() == id) {
577 return i;
578 }
579 }
580 return -1;
583Window *TopLevelWindowModel::windowAt(int index) const
585 if (index >=0 && index < m_windowModel.count()) {
586 return m_windowModel[index].window;
587 } else {
588 return nullptr;
589 }
592unityapi::MirSurfaceInterface *TopLevelWindowModel::surfaceAt(int index) const
594 if (index >=0 && index < m_windowModel.count()) {
595 return m_windowModel[index].window->surface();
596 } else {
597 return nullptr;
598 }
601unityapi::ApplicationInfoInterface *TopLevelWindowModel::applicationAt(int index) const
603 if (index >=0 && index < m_windowModel.count()) {
604 return m_windowModel[index].application;
605 } else {
606 return nullptr;
607 }
610int TopLevelWindowModel::idAt(int index) const
612 if (index >=0 && index < m_windowModel.count()) {
613 return m_windowModel[index].window->id();
614 } else {
615 return 0;
616 }
619void TopLevelWindowModel::raiseId(int id)
621 if (m_modelState == IdleState) {
622 DEBUG_MSG << "(id=" << id << ") - do it now.";
623 doRaiseId(id);
624 } else {
625 DEBUG_MSG << "(id=" << id << ") - Model busy (modelState=" << m_modelState << "). Try again in the next event loop.";
626 // The model has just signalled some change. If we have a Repeater responding to this update, it will get nuts
627 // if we perform yet another model change straight away.
628 //
629 // A bad sympton of this problem is a Repeater.itemAt(index) call returning null event though Repeater.count says
630 // the index is definitely within bounds.
631 QMetaObject::invokeMethod(this, "raiseId", Qt::QueuedConnection, Q_ARG(int, id));
632 }
635void TopLevelWindowModel::doRaiseId(int id)
637 int fromIndex = indexForId(id);
638 // can't raise something that doesn't exist or that it's already on top
639 if (fromIndex != -1 && fromIndex != 0) {
640 auto surface = m_windowModel[fromIndex].window->surface();
641 if (surface) {
642 m_surfaceManager->raise(surface);
643 } else {
644 // move it ourselves. Since there's no mir::scene::Surface/miral::Window, there's nothing
645 // miral can do about it.
646 move(fromIndex, 0);
647 }
648 }
651void TopLevelWindowModel::setFocusedWindow(Window *window)
653 if (window != m_focusedWindow) {
654 INFO_MSG << "(" << window << ")";
656 m_previousWindow = m_focusedWindow;
658 m_focusedWindow = window;
659 Q_EMIT focusedWindowChanged(m_focusedWindow);
661 if (m_previousWindow && m_previousWindow->focused() && !m_previousWindow->surface()) {
662 // do it ourselves. miral doesn't know about this window
663 m_previousWindow->setFocused(false);
664 }
665 }
667 // Reset
668 m_pendingActivation = false;
671unityapi::MirSurfaceInterface* TopLevelWindowModel::inputMethodSurface() const
673 return m_inputMethodWindow ? m_inputMethodWindow->surface() : nullptr;
676Window* TopLevelWindowModel::focusedWindow() const
678 return m_focusedWindow;
681void TopLevelWindowModel::move(int from, int to)
683 if (from == to) return;
684 DEBUG_MSG << " from=" << from << " to=" << to;
686 if (from >= 0 && from < m_windowModel.size() && to >= 0 && to < m_windowModel.size()) {
687 QModelIndex parent;
688 /* When moving an item down, the destination index needs to be incremented
689 by one, as explained in the documentation:
690 http://qt-project.org/doc/qt-5.0/qtcore/qabstractitemmodel.html#beginMoveRows */
692 Q_ASSERT(m_modelState == IdleState);
693 m_modelState = MovingState;
695 beginMoveRows(parent, from, from, parent, to + (to > from ? 1 : 0));
696#if QT_VERSION < QT_VERSION_CHECK(5, 6, 0)
697 const auto &window = m_windowModel.takeAt(from);
698 m_windowModel.insert(to, window);
699#else
700 m_windowModel.move(from, to);
701#endif
702 endMoveRows();
704 Q_EMIT listChanged();
705 m_modelState = IdleState;
707 INFO_MSG << " after " << toString();
708 }
710void TopLevelWindowModel::onModificationsStarted()
714void TopLevelWindowModel::onModificationsEnded()
716 if (m_focusedWindowChanged) {
717 setFocusedWindow(m_newlyFocusedWindow);
718 }
719 // reset
720 m_focusedWindowChanged = false;
721 m_newlyFocusedWindow = nullptr;
724void TopLevelWindowModel::activateTopMostWindowWithoutId(int forbiddenId)
726 DEBUG_MSG << "(" << forbiddenId << ")";
728 for (int i = 0; i < m_windowModel.count(); ++i) {
729 Window *window = m_windowModel[i].window;
730 if (window->id() != forbiddenId) {
731 window->activate();
732 }
733 }
736void TopLevelWindowModel::closeAllWindows()
738 m_closingAllApps = true;
739 for (auto win : m_windowModel) {
740 win.window->close();
741 }
743 // This is done after the for loop in the unlikely event that
744 // an app starts in between this
745 if (m_windowModel.isEmpty()) {
746 Q_EMIT closedAllWindows();
747 }
750bool TopLevelWindowModel::rootFocus()
752 return !m_nullWindow->focused();
755void TopLevelWindowModel::setRootFocus(bool focus)
757 INFO_MSG << "(" << focus << ")";
758 if (focus) {
759 // Give focus back to previous focused window, only if null window is focused.
760 // If null window is not focused, a different app had taken the focus and we
761 // should repect that, or if a pendingActivation is going on.
762 if (m_previousWindow && !m_previousWindow->focused() && !m_pendingActivation &&
763 m_nullWindow == m_focusedWindow && m_previousWindow != m_nullWindow) {
764 m_previousWindow->activate();
765 }
766 } else {
767 if (!m_nullWindow->focused()) {
768 m_nullWindow->activate();
769 }
770 }
773// Pending Activation will block refocus of previous focused window
774// this is needed since surface activation with miral is async,
775// and activation of placeholder is sync. This causes a race condition
776// between placeholder and prev window. This results in prev window
777// gets focused, as it will always be later than the placeholder.
778void TopLevelWindowModel::pendingActivation()
780 m_pendingActivation = true;