-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththreads.cpp
More file actions
134 lines (113 loc) · 3.75 KB
/
Copy paththreads.cpp
File metadata and controls
134 lines (113 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "threads.h"
#include <stdio.h>
#include <X11/extensions/Xdamage.h>
#include <stdlib.h>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
unsigned long size;
int windowSize;
Display *display = XOpenDisplay(0);
void Threads::createWindowicon(Context& context, int& i)
{
QString type = context.xwindowType(this->client_list[i]);
printf("type: %s\n", type.toUtf8().constData());
if (type == "_NET_WM_WINDOW_TYPE_NORMAL" || type == "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE")
{
windowSize++;
this->noWindow = false;
this->renderThread[i] = new Threads;
this->main->connect(renderThread[i], SIGNAL(onDesktopWindow(QString, QString, int, int)), this->main, SIGNAL(desktopWindow(QString, QString, int, int)));
this->renderThread[i]->onDesktopWindow(context.xwindowName(this->client_list[i]), QString(context.xwindowClass(this->client_list[i])).toLower(), (int)this->client_list[i], (int)i);
printf("%s\n", QString(context.xwindowClass(this->client_list[i])).toLower().toUtf8().constData());
}
}
void Threads::renderWindowlist(Context& context)
{
this->client_list = context.xwindows(display, &size);
if (this->client_list != NULL)
{
this->main->setProperty("windowVerify", true);
this->noWindow = true;
for (int i = 0; i < size; i++)
{
this->createWindowicon(context, i);
}
if (this->noWindow)
{
this->clearwindowThread = new Threads;
this->main->connect(clearwindowThread, SIGNAL(onClearWindows()), this->main, SIGNAL(clearWindows()));
this->clearwindowThread->onClearWindows();
}
XFree(this->client_list);
}
}
void Threads::renderTrayIcons(Context& context, XEvent event)
{
printf("trayIcon\n");
QList<QString> trayList;
QList<Window> _trayList;
XDamageNotifyEvent *dEvent;
Window id = event.xclient.data.l[2];
QString wclass = QString(context.xwindowClass(id));
bool add = true;
if (context.xwindowIcon(id).isNull())
{
add = false;
}
// qDebug() << add << wclass << context.xwindowClass(dEvent->drawable);
if (wclass != "unknow")
{
for (int i = 0; i < trayList.length(); i++)
{
if (trayList.at(i) == wclass)
{
add = false;
break;
}
}
for (int i = 0; i < _trayList.length(); i++)
{
if (_trayList.at(i) == id)
{
add = false;
break;
}
}
QString type = QString(context.xwindowType(id));
if (type == "_NET_WM_WINDOW_TYPE_NORMAL" || type == "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE")
{
if (add)
{
int status;
unsigned long nitems;
QString args = QString::number(id);// + ";" + wclass;
QMetaObject::invokeMethod(this->main, "addTrayIcon",
Q_ARG(QVariant, args)
);
trayList.append(wclass);
}
}
}
}
void Threads::run()
{
QObject *obj;
if(!display)
exit(2);
Context context;
XSelectInput(display, DefaultRootWindow(display), SubstructureNotifyMask);
XEvent dispayEvent;
this->client_list = context.xwindows(display, &size);
while (true)
{
XNextEvent(display, &dispayEvent);
QThread::msleep(600);
context.updatePanelWidth(this->main);
if (dispayEvent.type == CreateNotify || dispayEvent.type == DestroyNotify)
this->renderWindowlist(context);
if (dispayEvent.type == ClientMessage)
this->renderTrayIcons(context, dispayEvent);
XFlush(display);
}
}