improved chatterino native

This commit is contained in:
fourtf
2018-05-28 18:25:19 +02:00
parent cded61d28d
commit 0f8375a2f3
11 changed files with 378 additions and 142 deletions
+78 -13
View File
@@ -9,6 +9,8 @@
#ifdef USEWINSDK
#include "Windows.h"
#include "Psapi.h"
#pragma comment(lib, "Dwmapi.lib")
#endif
@@ -40,16 +42,47 @@ AttachedWindow::~AttachedWindow()
}
}
AttachedWindow *AttachedWindow::get(void *target, const QString &winId, int yOffset)
AttachedWindow *AttachedWindow::get(void *target, const GetArgs &args)
{
for (Item &item : items) {
if (item.hwnd == target) {
return item.window;
AttachedWindow *window = [&]() {
for (Item &item : items) {
if (item.hwnd == target) {
return item.window;
}
}
auto *window = new AttachedWindow(target, args.yOffset);
items.push_back(Item{target, window, args.winId});
return window;
}();
bool show = true;
QSize size = window->size();
if (args.height != -1) {
if (args.height == 0) {
window->hide();
show = false;
} else {
window->_height = args.height;
size.setHeight(args.height);
}
}
if (args.width != -1) {
if (args.width == 0) {
window->hide();
show = false;
} else {
window->_width = args.width;
size.setWidth(args.width);
}
}
auto *window = new AttachedWindow(target, yOffset);
items.push_back(Item{target, window, winId});
if (show) {
window->show();
window->resize(size);
}
return window;
}
@@ -80,26 +113,58 @@ void AttachedWindow::attachToHwnd(void *_hwnd)
HWND hwnd = HWND(this->winId());
HWND attached = HWND(_hwnd);
QObject::connect(timer, &QTimer::timeout, [this, hwnd, attached, timer] {
// check process id
DWORD processId;
::GetWindowThreadProcessId(attached, &processId);
HANDLE process =
::OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, false, processId);
std::unique_ptr<TCHAR[]> filename(new TCHAR[512]);
DWORD filenameLength = ::GetModuleFileNameEx(process, nullptr, filename.get(), 512);
QString qfilename = QString::fromWCharArray(filename.get(), filenameLength);
if (!qfilename.endsWith("chrome.exe")) {
qDebug() << "NM Illegal callee" << qfilename;
timer->stop();
timer->deleteLater();
this->deleteLater();
return;
}
// We get the window rect first so we can close this window when it returns an error.
// If we query the process first and check the filename then it will return and empty string
// that doens't match.
::SetLastError(0);
RECT xD;
::GetWindowRect(attached, &xD);
RECT rect;
::GetWindowRect(attached, &rect);
if (::GetLastError() != 0) {
timer->stop();
timer->deleteLater();
this->deleteLater();
return;
}
// set the correct z-order
HWND next = ::GetNextWindow(attached, GW_HWNDPREV);
::SetWindowPos(hwnd, next ? next : HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
::MoveWindow(hwnd, xD.right - 360, xD.top + this->yOffset - 8, 360 - 8,
xD.bottom - xD.top - this->yOffset, false);
// ::MoveWindow(hwnd, xD.right - 360, xD.top + 82, 360 - 8, xD.bottom - xD.top - 82 -
// 8,
// false);
if (this->_height == -1) {
::MoveWindow(hwnd, rect.right - this->_width - 8, rect.top + this->yOffset - 8,
this->_width, rect.bottom - rect.top - this->yOffset, false);
} else {
::MoveWindow(hwnd, rect.right - this->_width - 8, rect.bottom - this->_height - 8,
this->_width, this->_height, false);
}
// ::MoveWindow(hwnd, rect.right - 360, rect.top + 82, 360 - 8, rect.bottom -
// rect.top - 82 - 8, false);
});
timer->start();
#endif
+11 -1
View File
@@ -13,9 +13,16 @@ class AttachedWindow : public QWidget
AttachedWindow(void *target, int asdf);
public:
struct GetArgs {
QString winId;
int yOffset = -1;
int width = -1;
int height = -1;
};
~AttachedWindow();
static AttachedWindow *get(void *target, const QString &winId, int yOffset);
static AttachedWindow *get(void *target, const GetArgs &args);
static void detach(const QString &winId);
void setChannel(ChannelPtr channel);
@@ -28,6 +35,9 @@ protected:
private:
void *target;
int yOffset;
int currentYOffset;
int _width = 360;
int _height = -1;
struct {
Split *split;