Commit 62a7db70 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii

Use nullptr everywhere

Summary:
Because KWin is a very old project, we use three kinds of null pointer
literals: 0, NULL, and nullptr. Since C++11, it's recommended to use
nullptr keyword.

This change converts all usages of 0 and NULL literal to nullptr. Even
though it breaks git history, we need to do it in order to have consistent
code as well to ease code reviews (it's very tempting for some people to
add unrelated changes to their patches, e.g. converting NULL to nullptr).

Test Plan: Compiles.

Reviewers: #kwin, davidedmundson, romangg

Reviewed By: #kwin, davidedmundson, romangg

Subscribers: romangg, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D23618
parent 6b610927
......@@ -211,7 +211,7 @@ void AbstractClient::setActive(bool act)
? rules()->checkOpacityActive(qRound(opacity() * 100.0))
: rules()->checkOpacityInactive(qRound(opacity() * 100.0));
setOpacity(ruledOpacity / 100.0);
workspace()->setActiveClient(act ? this : NULL);
workspace()->setActiveClient(act ? this : nullptr);
if (!m_active)
cancelAutoRaise();
......
......@@ -239,12 +239,12 @@ void Workspace::setActiveClient(AbstractClient* c)
StackingUpdatesBlocker blocker(this);
++set_active_client_recursion;
updateFocusMousePosition(Cursor::pos());
if (active_client != NULL) {
if (active_client != nullptr) {
// note that this may call setActiveClient( NULL ), therefore the recursion counter
active_client->setActive(false);
}
active_client = c;
Q_ASSERT(c == NULL || c->isActive());
Q_ASSERT(c == nullptr || c->isActive());
if (active_client) {
last_active_client = active_client;
......@@ -291,9 +291,9 @@ void Workspace::setActiveClient(AbstractClient* c)
*/
void Workspace::activateClient(AbstractClient* c, bool force)
{
if (c == NULL) {
if (c == nullptr) {
focusToNull();
setActiveClient(NULL);
setActiveClient(nullptr);
return;
}
raiseClient(c);
......@@ -358,7 +358,7 @@ void Workspace::takeActivity(AbstractClient* c, ActivityFlags flags)
if (flags & ActivityFocus) {
AbstractClient* modal = c->findModal();
if (modal != NULL && modal != c) {
if (modal != nullptr && modal != c) {
if (!modal->isOnDesktop(c->desktop()))
modal->setDesktop(c->desktop());
if (!modal->isShown(true) && !modal->isMinimized()) // forced desktop or utility window
......@@ -434,7 +434,7 @@ AbstractClient *Workspace::clientUnderMouse(int screen) const
return client;
}
}
return 0;
return nullptr;
}
// deactivates 'c' and activates next client
......@@ -446,9 +446,9 @@ bool Workspace::activateNextClient(AbstractClient* c)
closeActivePopup();
if (c != NULL) {
if (c != nullptr) {
if (c == active_client)
setActiveClient(NULL);
setActiveClient(nullptr);
should_get_focus.removeAll(c);
}
......@@ -462,7 +462,7 @@ bool Workspace::activateNextClient(AbstractClient* c)
if (!options->focusPolicyIsReasonable())
return false;
AbstractClient* get_focus = NULL;
AbstractClient* get_focus = nullptr;
const int desktop = VirtualDesktopManager::self()->current();
......@@ -473,7 +473,7 @@ bool Workspace::activateNextClient(AbstractClient* c)
get_focus = clientUnderMouse(c ? c->screen() : screens()->current());
if (get_focus && (get_focus == c || get_focus->isDesktop())) {
// should rather not happen, but it cannot get the focus. rest of usability is tested above
get_focus = NULL;
get_focus = nullptr;
}
}
......@@ -492,10 +492,10 @@ bool Workspace::activateNextClient(AbstractClient* c)
}
}
if (get_focus == NULL) // last chance: focus the desktop
if (get_focus == nullptr) // last chance: focus the desktop
get_focus = findDesktop(true, desktop);
if (get_focus != NULL)
if (get_focus != nullptr)
requestFocus(get_focus);
else
focusToNull();
......@@ -513,9 +513,9 @@ void Workspace::setCurrentScreen(int new_screen)
closeActivePopup();
const int desktop = VirtualDesktopManager::self()->current();
AbstractClient *get_focus = FocusChain::self()->getForActivation(desktop, new_screen);
if (get_focus == NULL)
if (get_focus == nullptr)
get_focus = findDesktop(true, desktop);
if (get_focus != NULL && get_focus != mostRecentlyActivatedClient())
if (get_focus != nullptr && get_focus != mostRecentlyActivatedClient())
requestFocus(get_focus);
screens()->setCurrent(new_screen);
}
......@@ -589,7 +589,7 @@ bool Workspace::allowClientActivation(const KWin::AbstractClient *c, xcb_timesta
// No active client, it's ok to pass focus
// NOTICE that extreme protection needs to be handled before to allow protection on unmanged windows
if (ac == NULL || ac->isDesktop()) {
if (ac == nullptr || ac->isDesktop()) {
qCDebug(KWIN_CORE) << "Activation: No client active, allowing";
return true; // no active client -> always allow
}
......@@ -643,7 +643,7 @@ bool Workspace::allowFullClientRaising(const KWin::AbstractClient *c, xcb_timest
return true;
if (level == 4) // extreme
return false;
if (ac == NULL || ac->isDesktop()) {
if (ac == nullptr || ac->isDesktop()) {
qCDebug(KWIN_CORE) << "Raising: No client active, allowing";
return true; // no active client -> always allow
}
......@@ -706,7 +706,7 @@ void Client::updateUserTime(xcb_timestamp_t time)
&& (m_userTime == XCB_TIME_CURRENT_TIME
|| NET::timestampCompare(time, m_userTime) > 0)) { // time > user_time
m_userTime = time;
shade_below = NULL; // do not hover re-shade a window after it got interaction
shade_below = nullptr; // do not hover re-shade a window after it got interaction
}
group()->updateUserTime(m_userTime);
}
......@@ -726,7 +726,7 @@ xcb_timestamp_t Client::readUserTimeMapTimestamp(const KStartupInfoId *asn_id, c
// newer ASN timestamp always replaces user timestamp, unless user timestamp is 0
// helps e.g. with konqy reusing
if (asn_data != NULL && time != 0) {
if (asn_data != nullptr && time != 0) {
if (asn_id->timestamp() != 0
&& (time == -1U || NET::timestampCompare(asn_id->timestamp(), time) > 0)) {
time = asn_id->timestamp();
......@@ -742,7 +742,7 @@ xcb_timestamp_t Client::readUserTimeMapTimestamp(const KStartupInfoId *asn_id, c
// from already running application if this application
// is not the active one (unless focus stealing prevention is turned off).
Client* act = dynamic_cast<Client*>(workspace()->mostRecentlyActivatedClient());
if (act != NULL && !belongToSameApplication(act, this, SameApplicationCheck::RelaxedForActive)) {
if (act != nullptr && !belongToSameApplication(act, this, SameApplicationCheck::RelaxedForActive)) {
bool first_window = true;
auto sameApplicationActiveHackPredicate = [this](const Client *cl) {
// ignore already existing splashes, toolbars, utilities and menus,
......@@ -765,7 +765,7 @@ xcb_timestamp_t Client::readUserTimeMapTimestamp(const KStartupInfoId *asn_id, c
; // is transient for currently active window, even though it's not
// the same app (e.g. kcookiejar dialog) -> allow activation
else if (groupTransient() &&
findInList<Client, Client>(clientMainClients(), sameApplicationActiveHackPredicate) == NULL)
findInList<Client, Client>(clientMainClients(), sameApplicationActiveHackPredicate) == nullptr)
; // standalone transient
else
first_window = false;
......@@ -801,7 +801,7 @@ xcb_timestamp_t Client::userTime() const
xcb_timestamp_t time = m_userTime;
if (time == 0) // doesn't want focus after showing
return 0;
Q_ASSERT(group() != NULL);
Q_ASSERT(group() != nullptr);
if (time == -1U
|| (group()->userTime() != -1U
&& NET::timestampCompare(group()->userTime(), time) > 0))
......
......@@ -47,7 +47,7 @@ Activities::Activities(QObject *parent)
Activities::~Activities()
{
s_self = NULL;
s_self = nullptr;
}
KActivities::Consumer::ServiceStatus Activities::serviceStatus() const
......
......@@ -106,17 +106,17 @@ Client::Client()
, m_managed(false)
, m_transientForId(XCB_WINDOW_NONE)
, m_originalTransientForId(XCB_WINDOW_NONE)
, shade_below(NULL)
, shade_below(nullptr)
, m_motif(atoms->motif_wm_hints)
, blocks_compositing(false)
, shadeHoverTimer(NULL)
, shadeHoverTimer(nullptr)
, m_colormap(XCB_COLORMAP_NONE)
, in_group(NULL)
, ping_timer(NULL)
, in_group(nullptr)
, ping_timer(nullptr)
, m_killHelperPID(0)
, m_pingTimestamp(XCB_TIME_CURRENT_TIME)
, m_userTime(XCB_TIME_CURRENT_TIME) // Not known yet
, allowed_actions(0)
, allowed_actions(nullptr)
, shade_geometry_change(false)
, sm_stacking_order(-1)
, activitiesDefined(false)
......@@ -128,14 +128,14 @@ Client::Client()
{
// TODO: Do all as initialization
syncRequest.counter = syncRequest.alarm = XCB_NONE;
syncRequest.timeout = syncRequest.failsafeTimeout = NULL;
syncRequest.timeout = syncRequest.failsafeTimeout = nullptr;
syncRequest.lastTimestamp = xTime();
syncRequest.isPending = false;
// Set the initial mapping state
mapping_state = Withdrawn;
info = NULL;
info = nullptr;
shade_mode = ShadeNone;
deleting = false;
......@@ -214,7 +214,7 @@ void Client::releaseWindow(bool on_shutdown)
}
#endif
destroyWindowManagementInterface();
Deleted* del = NULL;
Deleted* del = nullptr;
if (!on_shutdown) {
del = Deleted::create(this);
}
......@@ -856,7 +856,7 @@ void Client::setShade(ShadeMode mode)
if (shade_mode == ShadeHover) {
ToplevelList order = workspace()->stackingOrder();
// invalidate, since "this" could be the topmost toplevel and shade_below dangeling
shade_below = NULL;
shade_below = nullptr;
// this is likely related to the index parameter?!
for (int idx = order.indexOf(this) + 1; idx < order.count(); ++idx) {
shade_below = qobject_cast<Client*>(order.at(idx));
......@@ -867,7 +867,7 @@ void Client::setShade(ShadeMode mode)
if (shade_below && shade_below->isNormalWindow())
workspace()->raiseClient(this);
else
shade_below = NULL;
shade_below = nullptr;
}
m_wrapper.map();
m_client.map();
......@@ -900,7 +900,7 @@ void Client::shadeUnhover()
void Client::cancelShadeHoverTimer()
{
delete shadeHoverTimer;
shadeHoverTimer = 0;
shadeHoverTimer = nullptr;
}
void Client::toggleShade()
......@@ -1077,7 +1077,7 @@ void Client::updateHiddenPreview()
workspace()->forceRestacking();
if (Xcb::Extensions::self()->isShapeInputAvailable()) {
xcb_shape_rectangles(connection(), XCB_SHAPE_SO_SET, XCB_SHAPE_SK_INPUT,
XCB_CLIP_ORDERING_UNSORTED, frameId(), 0, 0, 0, NULL);
XCB_CLIP_ORDERING_UNSORTED, frameId(), 0, 0, 0, nullptr);
}
} else {
workspace()->forceRestacking();
......@@ -1155,7 +1155,7 @@ void Client::pingWindow()
return; // Can't ping :(
if (options->killPingTimeout() == 0)
return; // Turned off
if (ping_timer != NULL)
if (ping_timer != nullptr)
return; // Pinging already
ping_timer = new QTimer(this);
connect(ping_timer, &QTimer::timeout, this,
......@@ -1188,7 +1188,7 @@ void Client::gotPing(xcb_timestamp_t timestamp)
if (NET::timestampCompare(timestamp, m_pingTimestamp) != 0)
return;
delete ping_timer;
ping_timer = NULL;
ping_timer = nullptr;
setUnresponsive(false);
......@@ -1759,7 +1759,7 @@ void Client::setBlockingCompositing(bool block)
const bool usedToBlock = blocks_compositing;
blocks_compositing = rules()->checkBlockCompositing(block && options->windowsBlockCompositing());
if (usedToBlock != blocks_compositing) {
emit blockingCompositingChanged(blocks_compositing ? this : 0);
emit blockingCompositingChanged(blocks_compositing ? this : nullptr);
}
}
......@@ -1768,7 +1768,7 @@ void Client::updateAllowedActions(bool force)
if (!isManaged() && !force)
return;
NET::Actions old_allowed_actions = NET::Actions(allowed_actions);
allowed_actions = 0;
allowed_actions = nullptr;
if (isMovable())
allowed_actions |= NET::ActionMove;
if (isResizable())
......
......@@ -100,7 +100,7 @@ public:
AbstractClient* findModal(bool allow_itself = false) override;
const Group* group() const override;
Group* group() override;
void checkGroup(Group* gr = NULL, bool force = false);
void checkGroup(Group* gr = nullptr, bool force = false);
void changeClientLeaderGroup(Group* gr);
void updateWindowRules(Rules::Types selection) override;
void updateFullscreenMonitors(NETFullscreenMonitors topology);
......
......@@ -54,8 +54,8 @@ GetAddrInfo::GetAddrInfo(const QByteArray &hostName, QObject *parent)
, m_ownResolved(false)
, m_hostName(hostName)
, m_addressHints(new addrinfo)
, m_address(NULL)
, m_ownAddress(NULL)
, m_address(nullptr)
, m_ownAddress(nullptr)
, m_watcher(new QFutureWatcher<int>(this))
, m_ownAddressWatcher(new QFutureWatcher<int>(this))
{
......
......@@ -34,7 +34,7 @@ class GetAddrInfo : public QObject
{
Q_OBJECT
public:
explicit GetAddrInfo(const QByteArray &hostName, QObject *parent = NULL);
explicit GetAddrInfo(const QByteArray &hostName, QObject *parent = nullptr);
~GetAddrInfo() override;
void resolve();
......@@ -64,7 +64,7 @@ class ClientMachine : public QObject
{
Q_OBJECT
public:
explicit ClientMachine(QObject *parent = NULL);
explicit ClientMachine(QObject *parent = nullptr);
~ClientMachine() override;
void resolve(xcb_window_t window, xcb_window_t clientLeader);
......
......@@ -94,7 +94,7 @@ void Manager::init()
// Monitor for the time changing (flags == TFD_TIMER_ABSTIME | TFD_TIMER_CANCEL_ON_SET).
// However these are not exposed in glibc so value is hardcoded:
::timerfd_settime(timeChangedFd, 3, &timespec, 0);
::timerfd_settime(timeChangedFd, 3, &timespec, nullptr);
connect(this, &QObject::destroyed, [timeChangedFd]() {
::close(timeChangedFd);
......
......@@ -121,11 +121,11 @@ static inline qint64 nanoToMilli(int nano) { return nano / (1000*1000); }
Compositor::Compositor(QObject* workspace)
: QObject(workspace)
, m_state(State::Off)
, m_selectionOwner(NULL)
, m_selectionOwner(nullptr)
, vBlankInterval(0)
, fpsInterval(0)
, m_timeSinceLastVBlank(0)
, m_scene(NULL)
, m_scene(nullptr)
, m_bufferSwapPending(false)
, m_composeAtSwapCompletion(false)
{
......@@ -176,7 +176,7 @@ Compositor::~Compositor()
stop();
deleteUnusedSupportProperties();
destroyCompositorSelection();
s_compositor = NULL;
s_compositor = nullptr;
}
bool Compositor::setupStart()
......@@ -250,12 +250,12 @@ bool Compositor::setupStart()
}
}
if (m_scene == NULL || m_scene->initFailed()) {
if (m_scene == nullptr || m_scene->initFailed()) {
qCCritical(KWIN_CORE) << "Failed to initialize compositing, compositing disabled";
m_state = State::Off;
delete m_scene;
m_scene = NULL;
m_scene = nullptr;
if (m_selectionOwner) {
m_selectionOwner->setOwning(false);
......@@ -449,7 +449,7 @@ void Compositor::stop()
}
delete m_scene;
m_scene = NULL;
m_scene = nullptr;
compositeTimer.stop();
repaints_region = QRegion();
......
......@@ -102,7 +102,7 @@ public:
* @return bool @c true if there is a Compositor and it is active, @c false otherwise
*/
static bool compositing() {
return s_compositor != NULL && s_compositor->isActive();
return s_compositor != nullptr && s_compositor->isActive();
}
// for delayed supportproperty management of effects
......
......@@ -56,7 +56,7 @@ Cursor::Cursor(QObject *parent)
Cursor::~Cursor()
{
s_self = NULL;
s_self = nullptr;
}
void Cursor::loadThemeSettings()
......
......@@ -92,7 +92,7 @@ void Deleted::discard()
void Deleted::copyToDeleted(Toplevel* c)
{
Q_ASSERT(dynamic_cast< Deleted* >(c) == NULL);
Q_ASSERT(dynamic_cast< Deleted* >(c) == nullptr);
Toplevel::copyToDeleted(c);
desk = c->desktop();
m_desktops = c->desktops();
......
......@@ -102,7 +102,7 @@ static xcb_atom_t registerSupportProperty(const QByteArray &propertyName)
// get the atom for the propertyName
ScopedCPointer<xcb_intern_atom_reply_t> atomReply(xcb_intern_atom_reply(c,
xcb_intern_atom_unchecked(c, false, propertyName.size(), propertyName.constData()),
NULL));
nullptr));
if (atomReply.isNull()) {
return XCB_ATOM_NONE;
}
......@@ -117,8 +117,8 @@ static xcb_atom_t registerSupportProperty(const QByteArray &propertyName)
EffectsHandlerImpl::EffectsHandlerImpl(Compositor *compositor, Scene *scene)
: EffectsHandler(scene->compositingType())
, keyboard_grab_effect(NULL)
, fullscreen_effect(0)
, keyboard_grab_effect(nullptr)
, fullscreen_effect(nullptr)
, next_window_quad_type(EFFECT_QUAD_TYPE_START)
, m_compositor(compositor)
, m_scene(scene)
......@@ -150,7 +150,7 @@ EffectsHandlerImpl::EffectsHandlerImpl(Compositor *compositor, Scene *scene)
[this](int old, AbstractClient *c) {
const int newDesktop = VirtualDesktopManager::self()->current();
if (old != 0 && newDesktop != old) {
emit desktopChanged(old, newDesktop, c ? c->effectWindow() : 0);
emit desktopChanged(old, newDesktop, c ? c->effectWindow() : nullptr);
// TODO: remove in 4.10
emit desktopChanged(old, newDesktop);
}
......@@ -464,7 +464,7 @@ Effect *EffectsHandlerImpl::provides(Effect::Feature ef)
for (int i = 0; i < loaded_effects.size(); ++i)
if (loaded_effects.at(i).second->provides(ef))
return loaded_effects.at(i).second;
return NULL;
return nullptr;
}
void EffectsHandlerImpl::drawWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
......@@ -620,7 +620,7 @@ void EffectsHandlerImpl::slotGeometryShapeChanged(Toplevel* t, const QRect& old)
{
// during late cleanup effectWindow() may be already NULL
// in some functions that may still call this
if (t == NULL || t->effectWindow() == NULL)
if (t == nullptr || t->effectWindow() == nullptr)
return;
emit windowGeometryShapeChanged(t->effectWindow(), old);
}
......@@ -629,7 +629,7 @@ void EffectsHandlerImpl::slotPaddingChanged(Toplevel* t, const QRect& old)
{
// during late cleanup effectWindow() may be already NULL
// in some functions that may still call this
if (t == NULL || t->effectWindow() == NULL)
if (t == nullptr || t->effectWindow() == nullptr)
return;
emit windowPaddingChanged(t->effectWindow(), old);
}
......@@ -659,7 +659,7 @@ bool EffectsHandlerImpl::hasActiveFullScreenEffect() const
bool EffectsHandlerImpl::grabKeyboard(Effect* effect)
{
if (keyboard_grab_effect != NULL)
if (keyboard_grab_effect != nullptr)
return false;
if (!doGrabKeyboard()) {
return false;
......@@ -675,9 +675,9 @@ bool EffectsHandlerImpl::doGrabKeyboard()
void EffectsHandlerImpl::ungrabKeyboard()
{
Q_ASSERT(keyboard_grab_effect != NULL);
Q_ASSERT(keyboard_grab_effect != nullptr);
doUngrabKeyboard();
keyboard_grab_effect = NULL;
keyboard_grab_effect = nullptr;
}
void EffectsHandlerImpl::doUngrabKeyboard()
......@@ -686,7 +686,7 @@ void EffectsHandlerImpl::doUngrabKeyboard()
void EffectsHandlerImpl::grabbedKeyboardEvent(QKeyEvent* e)
{
if (keyboard_grab_effect != NULL)
if (keyboard_grab_effect != nullptr)
keyboard_grab_effect->grabbedKeyboardEvent(e);
}
......@@ -788,7 +788,7 @@ void* EffectsHandlerImpl::getProxy(QString name)
if ((*it).first == name)
return (*it).second->proxy();
return NULL;
return nullptr;
}
void EffectsHandlerImpl::startMousePolling()
......@@ -805,7 +805,7 @@ void EffectsHandlerImpl::stopMousePolling()
bool EffectsHandlerImpl::hasKeyboardGrab() const
{
return keyboard_grab_effect != NULL;
return keyboard_grab_effect != nullptr;
}
void EffectsHandlerImpl::desktopResized(const QSize &size)
......@@ -885,7 +885,7 @@ void EffectsHandlerImpl::activateWindow(EffectWindow* c)
EffectWindow* EffectsHandlerImpl::activeWindow() const
{
return Workspace::self()->activeClient() ? Workspace::self()->activeClient()->effectWindow() : NULL;
return Workspace::self()->activeClient() ? Workspace::self()->activeClient()->effectWindow() : nullptr;
}
void EffectsHandlerImpl::moveWindow(EffectWindow* w, const QPoint& pos, bool snap, double snapAdjust)
......@@ -1072,7 +1072,7 @@ EffectWindow* EffectsHandlerImpl::findWindow(WId id) const
return w->effectWindow();
}
}
return NULL;
return nullptr;
}
EffectWindow* EffectsHandlerImpl::findWindow(KWayland::Server::SurfaceInterface *surf) const
......@@ -1207,7 +1207,7 @@ EffectWindow* EffectsHandlerImpl::currentTabBoxWindow() const
if (auto c = TabBox::TabBox::self()->currentClient())
return c->effectWindow();
#endif
return NULL;
return nullptr;
}
void EffectsHandlerImpl::addRepaintFull()
......@@ -2149,13 +2149,13 @@ EffectWindowList EffectWindowGroupImpl::members() const
//****************************************
EffectFrameImpl::EffectFrameImpl(EffectFrameStyle style, bool staticSize, QPoint position, Qt::Alignment alignment)
: QObject(0)
: QObject(nullptr)
, EffectFrame()
, m_style(style)
, m_static(staticSize)
, m_point(position)
, m_alignment(alignment)
, m_shader(NULL)
, m_shader(nullptr)
, m_theme(new Plasma::Theme(this))
{
if (m_style == EffectFrameStyled) {
......@@ -2271,7 +2271,7 @@ void EffectFrameImpl::render(QRegion region, double opacity, double frameOpacity
if (m_geometry.isEmpty()) {
return; // Nothing to display
}
m_shader = NULL;
m_shader = nullptr;
setScreenProjectionMatrix(static_cast<EffectsHandlerImpl*>(effects)->scene()->screenProjectionMatrix());
effects->paintEffectFrame(this, region, opacity, frameOpacity);
}
......
......@@ -34,7 +34,7 @@ using namespace KWin;
ContrastShader::ContrastShader()
: mValid(false), shader(NULL), m_opacity(1)
: mValid(false), shader(nullptr), m_opacity(1)
{
}
......@@ -51,7 +51,7 @@ ContrastShader *ContrastShader::create()
void ContrastShader::reset()
{
delete shader;
shader = NULL;
shader