File indexing completed on 2024-05-19 05:39:08

0001 /*
0002     SPDX-FileCopyrightText: 2005 Lubos Lunak <l.lunak@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "kcheckrunning.h"
0008 #include <X11/Xlib.h>
0009 
0010 /*
0011  Return 0 when KDE is running, 1 when KDE is not running but it is possible
0012  to connect to X, 2 when it's not possible to connect to X.
0013 */
0014 CheckRunningState kCheckRunning()
0015 {
0016     Display *dpy = XOpenDisplay(nullptr);
0017     if (dpy == nullptr)
0018         return NoX11;
0019     Atom atom = XInternAtom(dpy, "_KDE_RUNNING", False);
0020     return XGetSelectionOwner(dpy, atom) != None ? PlasmaRunning : NoPlasmaRunning;
0021 }