mousePenetrateWindow.pro
#-------------------------------------------------
#
# Project created by QtCreator 2016-09-22T14:25:32
#
#-------------------------------------------------
QT += core gui
win32{
LIBS += -luser32
}
linux{
QT += x11extras
LIBS += -lX11 -lXext
}
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = mousePenetrateWindow
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#ifndef Q_OS_WIN
#include <X11/extensions/shape.h>
#include <QtX11Extras/QX11Info>
#else
#include <windows.h>
#endif
#include <QTimer>
//#include <QDebug>
//#include <qdebug.h>
//#include <QCursor>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// showFullScreen();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
QPoint point = QCursor::pos();
qDebug() << "cursor pos: " << point;
#ifdef Q_OS_LINUX
XShapeCombineRectangles(QX11Info::display(), winId(), ShapeInput,0,0, NULL, 0, ShapeSet, YXBanded);
#endif
#ifdef Q_OS_WIN
// SetWindowPos((HWND)winId(), HWND_BOTTOM, 0, 0,width(), height(), SWP_NOREDRAW);//useless?
m_intExTemp = GetWindowLong((HWND)winId(), GWL_EXSTYLE);
SetWindowLong((HWND)winId(), GWL_EXSTYLE, m_intExTemp | WS_EX_TRANSPARENT | WS_EX_LAYERED);
#endif
QTimer::singleShot(3000, this, SLOT(timerSlot()));
}
void MainWindow::timerSlot()
{
#ifdef Q_OS_LINUX
XRectangle* myrect = new XRectangle;
myrect->x = 0;
myrect->y = 0;
myrect->width = width();
myrect->height = height();
XShapeCombineRectangles(QX11Info::display(), winId(), ShapeInput, 0, 0, myrect,1,ShapeSet,YXBanded);
#endif
#ifdef Q_OS_WIN
SetWindowLong((HWND)winId(), GWL_EXSTYLE, m_intExTemp);
#endif
}