Changeset View
Changeset View
Standalone View
Standalone View
processui/ProcessModel.cpp
Show First 20 Lines • Show All 121 Lines • ▼ Show 20 Line(s) | |||||
122 | #ifdef HAVE_XRES | 122 | #ifdef HAVE_XRES | ||
123 | mHaveXRes = false; | 123 | mHaveXRes = false; | ||
124 | #endif | 124 | #endif | ||
125 | mHaveTimer = false, | 125 | mHaveTimer = false, | ||
126 | mTimerId = -1, | 126 | mTimerId = -1, | ||
127 | mMovingRow = false; | 127 | mMovingRow = false; | ||
128 | mRemovingRow = false; | 128 | mRemovingRow = false; | ||
129 | mInsertingRow = false; | 129 | mInsertingRow = false; | ||
130 | #if HAVE_X11 | ||||
131 | mIsX11 = QX11Info::isPlatformX11(); | ||||
132 | #else | ||||
133 | mIsX11 = false; | ||||
134 | #endif | ||||
130 | } | 135 | } | ||
131 | 136 | | |||
132 | ProcessModelPrivate::~ProcessModelPrivate() | 137 | ProcessModelPrivate::~ProcessModelPrivate() | ||
133 | { | 138 | { | ||
134 | #if HAVE_X11 | 139 | #if HAVE_X11 | ||
135 | qDeleteAll(mPidToWindowInfo); | 140 | qDeleteAll(mPidToWindowInfo); | ||
136 | #endif | 141 | #endif | ||
137 | delete mProcesses; | 142 | delete mProcesses; | ||
138 | mProcesses = NULL; | 143 | mProcesses = NULL; | ||
139 | } | 144 | } | ||
140 | 145 | | |||
141 | ProcessModel::ProcessModel(QObject* parent, const QString &host) | 146 | ProcessModel::ProcessModel(QObject* parent, const QString &host) | ||
142 | : QAbstractItemModel(parent), d(new ProcessModelPrivate) | 147 | : QAbstractItemModel(parent), d(new ProcessModelPrivate) | ||
143 | { | 148 | { | ||
144 | d->q=this; | 149 | d->q=this; | ||
145 | #ifdef HAVE_XRES | 150 | #ifdef HAVE_XRES | ||
151 | if (d->mIsX11) { | ||||
146 | int event, error, major, minor; | 152 | int event, error, major, minor; | ||
147 | d->mHaveXRes = XResQueryExtension(QX11Info::display(), &event, &error) && XResQueryVersion(QX11Info::display(), &major, &minor); | 153 | d->mHaveXRes = XResQueryExtension(QX11Info::display(), &event, &error) && XResQueryVersion(QX11Info::display(), &major, &minor); | ||
154 | } | ||||
148 | #endif | 155 | #endif | ||
149 | 156 | | |||
150 | if(host.isEmpty() || host == QLatin1String("localhost")) { | 157 | if(host.isEmpty() || host == QLatin1String("localhost")) { | ||
151 | d->mHostName = QString(); | 158 | d->mHostName = QString(); | ||
152 | d->mIsLocalhost = true; | 159 | d->mIsLocalhost = true; | ||
153 | } else { | 160 | } else { | ||
154 | d->mHostName = host; | 161 | d->mHostName = host; | ||
155 | d->mIsLocalhost = false; | 162 | d->mIsLocalhost = false; | ||
▲ Show 20 Lines • Show All 221 Lines • ▼ Show 20 Line(s) | 383 | else | |||
377 | row = process->parent()->children().indexOf(process); | 384 | row = process->parent()->children().indexOf(process); | ||
378 | QModelIndex index2 = q->createIndex(row, ProcessModel::HeadingXTitle, process); | 385 | QModelIndex index2 = q->createIndex(row, ProcessModel::HeadingXTitle, process); | ||
379 | emit q->dataChanged(index2, index2); | 386 | emit q->dataChanged(index2, index2); | ||
380 | } | 387 | } | ||
381 | #endif | 388 | #endif | ||
382 | 389 | | |||
383 | #if HAVE_X11 | 390 | #if HAVE_X11 | ||
384 | void ProcessModelPrivate::setupWindows() { | 391 | void ProcessModelPrivate::setupWindows() { | ||
392 | if (!mIsX11) { | ||||
393 | return; | ||||
394 | } | ||||
385 | connect( KWindowSystem::self(), SIGNAL(windowChanged(WId,uint)), this, SLOT(windowChanged(WId,uint))); | 395 | connect( KWindowSystem::self(), SIGNAL(windowChanged(WId,uint)), this, SLOT(windowChanged(WId,uint))); | ||
386 | connect( KWindowSystem::self(), &KWindowSystem::windowAdded, this, &ProcessModelPrivate::windowAdded); | 396 | connect( KWindowSystem::self(), &KWindowSystem::windowAdded, this, &ProcessModelPrivate::windowAdded); | ||
387 | connect( KWindowSystem::self(), &KWindowSystem::windowRemoved, this, &ProcessModelPrivate::windowRemoved); | 397 | connect( KWindowSystem::self(), &KWindowSystem::windowRemoved, this, &ProcessModelPrivate::windowRemoved); | ||
388 | 398 | | |||
389 | //Add all the windows that KWin is managing - i.e. windows that the user can see | 399 | //Add all the windows that KWin is managing - i.e. windows that the user can see | ||
390 | const QList<WId> windows = KWindowSystem::windows(); | 400 | const QList<WId> windows = KWindowSystem::windows(); | ||
391 | for (auto it = windows.begin(); it != windows.end(); ++it ) { | 401 | for (auto it = windows.begin(); it != windows.end(); ++it ) { | ||
392 | updateWindowInfo(*it, ~0u, true); | 402 | updateWindowInfo(*it, ~0u, true); | ||
393 | } | 403 | } | ||
394 | } | 404 | } | ||
395 | #endif | 405 | #endif | ||
396 | 406 | | |||
397 | #ifdef HAVE_XRES | 407 | #ifdef HAVE_XRES | ||
398 | bool ProcessModelPrivate::updateXResClientData() { | 408 | bool ProcessModelPrivate::updateXResClientData() { | ||
409 | if (!mIsX11) { | ||||
410 | return false; | ||||
411 | } | ||||
399 | XResClient *clients; | 412 | XResClient *clients; | ||
400 | int count; | 413 | int count; | ||
401 | 414 | | |||
402 | XResQueryClients(QX11Info::display(), &count, &clients); | 415 | XResQueryClients(QX11Info::display(), &count, &clients); | ||
403 | 416 | | |||
404 | mXResClientResources.clear(); | 417 | mXResClientResources.clear(); | ||
405 | for (int i=0; i < count; i++) | 418 | for (int i=0; i < count; i++) | ||
406 | mXResClientResources.insert(-(qlonglong)(clients[i].resource_base), clients[i].resource_mask); | 419 | mXResClientResources.insert(-(qlonglong)(clients[i].resource_base), clients[i].resource_mask); | ||
407 | 420 | | |||
408 | if(clients) | 421 | if(clients) | ||
409 | XFree(clients); | 422 | XFree(clients); | ||
410 | return true; | 423 | return true; | ||
411 | } | 424 | } | ||
412 | 425 | | |||
413 | void ProcessModelPrivate::queryForAndUpdateAllXWindows() { | 426 | void ProcessModelPrivate::queryForAndUpdateAllXWindows() { | ||
427 | if (!mIsX11) { | ||||
428 | return; | ||||
429 | } | ||||
414 | updateXResClientData(); | 430 | updateXResClientData(); | ||
415 | Window *children, dummy; | 431 | Window *children, dummy; | ||
416 | unsigned int count; | 432 | unsigned int count; | ||
417 | Status result = XQueryTree(QX11Info::display(), QX11Info::appRootWindow(), &dummy, &dummy, &children, &count); | 433 | Status result = XQueryTree(QX11Info::display(), QX11Info::appRootWindow(), &dummy, &dummy, &children, &count); | ||
418 | if(!result) | 434 | if(!result) | ||
419 | return; | 435 | return; | ||
420 | if(!updateXResClientData()) | 436 | if(!updateXResClientData()) | ||
421 | return; | 437 | return; | ||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | |||||
493 | 509 | | |||
494 | void ProcessModelPrivate::windowAdded(WId wid) | 510 | void ProcessModelPrivate::windowAdded(WId wid) | ||
495 | { | 511 | { | ||
496 | updateWindowInfo(wid, ~0u, true); | 512 | updateWindowInfo(wid, ~0u, true); | ||
497 | } | 513 | } | ||
498 | 514 | | |||
499 | void ProcessModelPrivate::updateWindowInfo(WId wid, unsigned int properties, bool newWindow) | 515 | void ProcessModelPrivate::updateWindowInfo(WId wid, unsigned int properties, bool newWindow) | ||
500 | { | 516 | { | ||
517 | if (!mIsX11) { | ||||
518 | return; | ||||
519 | } | ||||
501 | properties &= (NET::WMPid | NET::WMVisibleName | NET::WMName | NET::WMIcon); | 520 | properties &= (NET::WMPid | NET::WMVisibleName | NET::WMName | NET::WMIcon); | ||
502 | 521 | | |||
503 | if(!properties) | 522 | if(!properties) | ||
504 | return; //Nothing interesting changed | 523 | return; //Nothing interesting changed | ||
505 | 524 | | |||
506 | WindowInfo *w = mWIdToWindowInfo.value(wid); | 525 | WindowInfo *w = mWIdToWindowInfo.value(wid); | ||
507 | if(!w && !newWindow) | 526 | if(!w && !newWindow) | ||
508 | return; //We do not have a record of this window and this is not a new window | 527 | return; //We do not have a record of this window and this is not a new window | ||
▲ Show 20 Lines • Show All 1346 Lines • ▼ Show 20 Line(s) | 1863 | void ProcessModel::setupHeader() { | |||
1855 | headings << i18nc("process heading", "IO Read"); | 1874 | headings << i18nc("process heading", "IO Read"); | ||
1856 | headings << i18nc("process heading", "IO Write"); | 1875 | headings << i18nc("process heading", "IO Write"); | ||
1857 | headings << i18nc("process heading", "Virtual Size"); | 1876 | headings << i18nc("process heading", "Virtual Size"); | ||
1858 | headings << i18nc("process heading", "Memory"); | 1877 | headings << i18nc("process heading", "Memory"); | ||
1859 | headings << i18nc("process heading", "Shared Mem"); | 1878 | headings << i18nc("process heading", "Shared Mem"); | ||
1860 | headings << i18nc("process heading", "Relative Start Time"); | 1879 | headings << i18nc("process heading", "Relative Start Time"); | ||
1861 | headings << i18nc("process heading", "Command"); | 1880 | headings << i18nc("process heading", "Command"); | ||
1862 | #if HAVE_X11 | 1881 | #if HAVE_X11 | ||
1882 | if (d->mIsX11) { | ||||
1863 | headings << i18nc("process heading", "X11 Memory"); | 1883 | headings << i18nc("process heading", "X11 Memory"); | ||
1864 | headings << i18nc("process heading", "Window Title"); | 1884 | headings << i18nc("process heading", "Window Title"); | ||
1885 | } | ||||
1865 | #endif | 1886 | #endif | ||
1866 | 1887 | | |||
1867 | if(d->mHeadings.isEmpty()) { // If it's empty, this is the first time this has been called, so insert the headings | 1888 | if(d->mHeadings.isEmpty()) { // If it's empty, this is the first time this has been called, so insert the headings | ||
1868 | beginInsertColumns(QModelIndex(), 0, headings.count()-1); | 1889 | beginInsertColumns(QModelIndex(), 0, headings.count()-1); | ||
1869 | { | 1890 | { | ||
1870 | d->mHeadings = headings; | 1891 | d->mHeadings = headings; | ||
1871 | } | 1892 | } | ||
1872 | endInsertColumns(); | 1893 | endInsertColumns(); | ||
▲ Show 20 Lines • Show All 269 Lines • Show Last 20 Lines |