#include "blackwindow.h"
#include <QColor>
#include <QGuiApplication>
#include <QPainter>
#include <QScreen>
#include <QTimer>
#include <QX11Info>
#include <QPaintEvent>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include <X11/Xlib.h>
#include <xcb/xcb.h>

BlackWindow::BlackWindow(QWidget *parent) : QWidget(parent)
{
    setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint
                   | Qt::X11BypassWindowManagerHint);

    setAttribute(Qt::WA_TranslucentBackground);

    setCursor(Qt::BlankCursor);
    //qApp->installNativeEventFilter(this);
    //installEventFilter(this);
}

void BlackWindow::paintEvent(QPaintEvent *event)
{
    for(auto screen : QGuiApplication::screens())
    {
        QPainter painter(this);
        QColor cor = "#000000";
        painter.setBrush(cor);
        painter.drawRect(screen->geometry());

    }
    return QWidget::paintEvent(event);
}

void BlackWindow::laterActivate()
{
    raise();
}

bool BlackWindow::eventFilter(QObject *obj, QEvent *event)
{
    if(event->type() == QEvent::WindowDeactivate){
         QTimer::singleShot(50,this,SLOT(laterActivate()));
    }

    return false;
}

bool BlackWindow::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
{
    return false;
}
