Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #--- pro file ---#
- #-------------------------------------------------
- #
- # Project created by QtCreator 2015-02-20T11:34:42
- #
- #-------------------------------------------------
- QT += core gui
- TARGET = scrns1
- CONFIG += console
- CONFIG -= app_bundle
- TEMPLATE = app
- SOURCES += main.cpp
- INCLUDEPATH += /usr/include/KDE
- LIBS += -lkdecore -lkdeui -lX11 -lXrender -lXcomposite -lXdamage
- HEADERS +=
- #-------------------------------------------------
- #
- # Project created by QtCreator 2015-02-20T11:34:42
- #
- #-------------------------------------------------
- QT += core gui
- TARGET = scrns1
- CONFIG += console
- CONFIG -= app_bundle
- TEMPLATE = app
- SOURCES += main.cpp
- INCLUDEPATH += /usr/include/KDE
- LIBS += -lkdecore -lkdeui -lX11 -lXrender -lXcomposite -lXdamage
- HEADERS +=
- //--- main.cpp ---//
- #include <QApplication>
- #include <QTimer>
- #include <QPixmap>
- #include <QPainter>
- #include <QIODevice>
- #include <QFile>
- #include <QMap>
- #include <QWidget>
- #include <QBuffer>
- #include <KWindowSystem>
- #include <KWindowInfo>
- #include <iostream>
- #include <string>
- #include <X11/Xlib.h>
- #include <X11/Xfuncproto.h>
- #include <X11/X.h>
- #include <X11/extensions/Xcomposite.h>
- #include <X11/extensions/Xrender.h>
- #include <X11/extensions/Xdamage.h>
- #include <time.h>
- #include <QGraphicsBlurEffect>
- #include <unistd.h>
- class MyWidget : public QWidget {
- Q_OBJECT
- private:
- QMap<WId, QPixmap> images;
- public:
- explicit MyWidget(QWidget *parent = 0) : QWidget(parent) {
- QTimer::singleShot(0, this, SLOT(run()));
- }
- ~MyWidget(){
- }
- void paintEvent(QPaintEvent* evt){
- QRect geo = this->geometry();
- QPainter painter(this);
- int width = geo.width();
- int height = geo.height();
- QList<WId> wids = images.keys();
- if (wids.size() == 1){
- const WId wid = wids.at(0);
- QPixmap p = images.value(wid);
- painter.drawPixmap(0, 0, width, height, p);
- } else {
- int i = 0;
- int num = 1;
- for (; num*num < wids.size(); num++){
- //
- }
- int w = width /num;
- int h = height/num;
- for (int row = 0; row < num; row++){
- for (int col = 0; col < num; col++){
- std::cout << col << "x" << row << "\n";
- if (wids.size() > i){
- const WId wid = wids.at(i);
- QPixmap p = images.value(wid);
- if (!p.isNull()){
- painter.drawPixmap(col*w, row*h, w, h, p);
- } else {
- std::cout << "SKIP\n";
- }
- KWindowInfo info(wid, NET::WMName | NET::WMState | NET::XAWMState);
- painter.setPen(QColor("red"));
- painter.drawText(col*w, row*h + h*0.25, QString::number(wid));
- painter.drawText(col*w, row*h + h*0.5, QString::number(col) + "x" + QString::number(row));
- painter.drawText(col*w, row*h + h*0.75, info.name());
- }
- i++;
- }
- }
- }
- }
- void clearPixmap(){
- this->images.clear();
- }
- void addPixmap(WId wid, QPixmap image){
- this->images.insert(wid, image);
- }
- };
- class Task : public QObject
- {
- Q_OBJECT
- public:
- Task(QObject *parent = 0) : QObject(parent) {
- display = XOpenDisplay(NULL);
- }
- ~Task(){
- XCloseDisplay(display);
- }
- Display* display;
- MyWidget* wdg;
- private:
- QPixmap makeScreenshot(XID xid, Display *display){
- QPixmap qpxmp;
- XCompositeRedirectWindow (display, xid, CompositeRedirectAutomatic);
- XFlush(display);
- Pixmap pixmap = XCompositeNameWindowPixmap (display, xid);
- XSync(display, false);
- qpxmp = QPixmap::fromX11Pixmap(pixmap).copy();
- XFreePixmap (display, pixmap);
- XCompositeUnredirectWindow (display, xid, CompositeRedirectAutomatic);
- return qpxmp;
- }
- public slots:
- void update(){
- std::cout << "update\n";
- if (!wdg){
- std::cout << "no widget\n";
- } else {
- wdg->clearPixmap();
- if (!display) {
- std::cout << "display was not opened\n";
- } else {
- const QList<WId> wndws = KWindowSystem::windows();
- for (int i = 0; i < wndws.size(); i++){
- const WId wid = wndws.at(i);
- KWindowInfo info(wid, NET::WMName | NET::WMState | NET::XAWMState | NET::WMDesktop | NET::WMGeometry);
- if (!info.isOnCurrentDesktop()){
- QRect geo = info.geometry();
- QPixmap p(10, (geo.height() * 10) / geo.width());
- p.fill(Qt::gray);
- wdg->addPixmap(wid, p);
- } else if (info.name().indexOf("plasma") >= 0){
- //do nothing
- } else if (info.valid() && info.isMinimized()){
- QRect geo = info.geometry();
- QPixmap p(10, (geo.height() * 10) / geo.width());
- p.fill(Qt::gray);
- wdg->addPixmap(wid, p);
- } else {
- std::cout << wid << " = " << info.name().toStdString() << "\n";
- QPixmap p = makeScreenshot(wid, display);
- p = makeScreenshot(wid, display);
- wdg->addPixmap(wid, p);
- }
- }
- wdg->repaint();
- }
- }
- }
- void run()
- {
- wdg = new MyWidget;
- wdg->show();
- QTimer *timer = new QTimer(this);
- connect(timer, SIGNAL(timeout()), this, SLOT(update()));
- timer->start(1000);
- }
- signals:
- void finished();
- };
- #include "main.moc"
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- Task *task = new Task(&a);
- QObject::connect(task, SIGNAL(finished()), &a, SLOT(quit()));
- QTimer::singleShot(0, task, SLOT(run()));
- return a.exec();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement