Added fullscreen support to browser extension

This commit is contained in:
fourtf
2019-08-20 03:13:42 +02:00
parent e07d11e9a3
commit 1b0102c948
4 changed files with 88 additions and 41 deletions
-12
View File
@@ -70,18 +70,6 @@ void runBrowserExtensionHost()
{ {
initFileMode(); initFileMode();
std::atomic<bool> ping(false);
QTimer timer;
QObject::connect(&timer, &QTimer::timeout, [&ping] {
if (!ping.exchange(false))
{
_Exit(0);
}
});
timer.setInterval(11000);
timer.start();
NativeMessagingClient client; NativeMessagingClient client;
runLoop(client); runLoop(client);
+13 -4
View File
@@ -12,6 +12,7 @@
#include <QJsonObject> #include <QJsonObject>
#include <QJsonValue> #include <QJsonValue>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/interprocess/ipc/message_queue.hpp> #include <boost/interprocess/ipc/message_queue.hpp>
namespace ipc = boost::interprocess; namespace ipc = boost::interprocess;
@@ -117,7 +118,10 @@ void NativeMessagingClient::sendMessage(const QByteArray &array)
{ {
ipc::message_queue messageQueue(ipc::open_only, "chatterino_gui"); ipc::message_queue messageQueue(ipc::open_only, "chatterino_gui");
messageQueue.try_send(array.data(), array.size(), 1); messageQueue.try_send(array.data(), size_t(array.size()), 1);
// messageQueue.timed_send(array.data(), size_t(array.size()), 1,
// boost::posix_time::second_clock::local_time() +
// boost::posix_time::seconds(10));
} }
catch (ipc::interprocess_exception &ex) catch (ipc::interprocess_exception &ex)
{ {
@@ -183,25 +187,30 @@ void NativeMessagingServer::ReceiverThread::handleMessage(
return; return;
} }
qDebug() << root;
if (action == "select") if (action == "select")
{ {
QString _type = root.value("type").toString(); QString _type = root.value("type").toString();
bool attach = root.value("attach").toBool(); bool attach = root.value("attach").toBool();
bool attachFullscreen = root.value("attach_fullscreen").toBool();
QString name = root.value("name").toString(); QString name = root.value("name").toString();
qDebug() << attach;
#ifdef USEWINSDK #ifdef USEWINSDK
AttachedWindow::GetArgs args; AttachedWindow::GetArgs args;
args.winId = root.value("winId").toString(); args.winId = root.value("winId").toString();
args.yOffset = root.value("yOffset").toInt(-1); args.yOffset = root.value("yOffset").toInt(-1);
args.width = root.value("size").toObject().value("width").toInt(-1); args.width = root.value("size").toObject().value("width").toInt(-1);
args.height = root.value("size").toObject().value("height").toInt(-1); args.height = root.value("size").toObject().value("height").toInt(-1);
args.fullscreen = attachFullscreen;
qDebug() << args.width << args.height << args.winId;
if (_type.isNull() || args.winId.isNull()) if (_type.isNull() || args.winId.isNull())
{ {
qDebug() << "NM type, name or winId missing"; qDebug() << "NM type, name or winId missing";
attach = false; attach = false;
attachFullscreen = false;
return; return;
} }
#endif #endif
@@ -215,7 +224,7 @@ void NativeMessagingServer::ReceiverThread::handleMessage(
app->twitch.server->getOrAddChannel(name)); app->twitch.server->getOrAddChannel(name));
} }
if (attach) if (attach || attachFullscreen)
{ {
#ifdef USEWINSDK #ifdef USEWINSDK
// if (args.height != -1) { // if (args.height != -1) {
+71 -25
View File
@@ -18,6 +18,26 @@
namespace chatterino { namespace chatterino {
static thread_local std::vector<HWND> taskbarHwnds;
BOOL CALLBACK enumWindows(HWND hwnd, LPARAM)
{
constexpr int length = 16;
auto className = std::make_unique<WCHAR[]>(length);
GetClassName(hwnd, className.get(), length);
// qDebug() << QString::fromWCharArray(className.get(), length);
if (lstrcmp(className.get(), L"Shell_TrayWnd") == 0 ||
lstrcmp(className.get(), L"Shell_Secondary") == 0)
{
taskbarHwnds.push_back(hwnd);
}
return true;
}
AttachedWindow::AttachedWindow(void *_target, int _yOffset) AttachedWindow::AttachedWindow(void *_target, int _yOffset)
: QWidget(nullptr, Qt::FramelessWindowHint | Qt::Window) : QWidget(nullptr, Qt::FramelessWindowHint | Qt::Window)
, target_(_target) , target_(_target)
@@ -68,6 +88,8 @@ AttachedWindow *AttachedWindow::get(void *target, const GetArgs &args)
bool show = true; bool show = true;
QSize size = window->size(); QSize size = window->size();
window->fullscreen_ = args.fullscreen;
if (args.height != -1) if (args.height != -1)
{ {
if (args.height == 0) if (args.height == 0)
@@ -134,12 +156,13 @@ void AttachedWindow::attachToHwnd(void *_attachedPtr)
} }
this->attached_ = true; this->attached_ = true;
this->timer_.setInterval(1);
auto hwnd = HWND(this->winId()); //auto hwnd = HWND(this->winId());
auto attached = HWND(_attachedPtr); auto attached = HWND(_attachedPtr);
QObject::connect(&this->timer_, &QTimer::timeout, [this, hwnd, attached] { // FAST TIMER - used to resize/reorder windows
this->timer_.setInterval(1);
QObject::connect(&this->timer_, &QTimer::timeout, [this, attached] {
// check process id // check process id
if (!this->validProcessName_) if (!this->validProcessName_)
{ {
@@ -153,7 +176,7 @@ void AttachedWindow::attachToHwnd(void *_attachedPtr)
DWORD filenameLength = DWORD filenameLength =
::GetModuleFileNameEx(process, nullptr, filename.get(), 512); ::GetModuleFileNameEx(process, nullptr, filename.get(), 512);
QString qfilename = QString qfilename =
QString::fromWCharArray(filename.get(), filenameLength); QString::fromWCharArray(filename.get(), int(filenameLength));
if (!qfilename.endsWith("chrome.exe") && if (!qfilename.endsWith("chrome.exe") &&
!qfilename.endsWith("firefox.exe")) !qfilename.endsWith("firefox.exe"))
@@ -168,7 +191,26 @@ void AttachedWindow::attachToHwnd(void *_attachedPtr)
this->updateWindowRect(attached); this->updateWindowRect(attached);
}); });
this->timer_.start(); this->timer_.start();
// SLOW TIMER - used to hide taskbar behind fullscreen window
this->slowTimer_.setInterval(2000);
QObject::connect(&this->slowTimer_, &QTimer::timeout, [this, attached] {
if (this->fullscreen_)
{
taskbarHwnds.clear();
::EnumWindows(&enumWindows, 0);
for (auto taskbarHwnd : taskbarHwnds)
{
::SetWindowPos(taskbarHwnd,
GetNextWindow(attached, GW_HWNDNEXT), 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
}
}
});
this->slowTimer_.start();
#endif #endif
} }
@@ -195,38 +237,42 @@ void AttachedWindow::updateWindowRect(void *_attachedPtr)
} }
// set the correct z-order // set the correct z-order
HWND next = ::GetNextWindow(attached, GW_HWNDPREV); if (HWND next = ::GetNextWindow(attached, GW_HWNDPREV))
{
::SetWindowPos(hwnd, next ? next : HWND_TOPMOST, 0, 0, 0, 0, ::SetWindowPos(hwnd, next ? next : HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
}
float scale = 1.f; float scale = 1.f;
if (auto dpi = getWindowDpi(attached)) if (auto dpi = getWindowDpi(attached))
{ {
scale = dpi.get() / 96.f; scale = dpi.get() / 96.f;
// for (auto w : this->ui_.split->findChildren<BaseWidget *>()) { for (auto w : this->ui_.split->findChildren<BaseWidget *>())
// w->setOverrideScale(scale); {
// } w->setOverrideScale(scale);
// this->ui_.split->setOverrideScale(scale); }
this->ui_.split->setOverrideScale(scale);
} }
if (this->height_ == -1) if (this->height_ != -1)
{ {
// ::MoveWindow(hwnd, rect.right - this->width_ - 8, rect.top + this->ui_.split->setFixedWidth(int(this->width_ * scale));
// this->yOffset_ - 8,
// this->width_, rect.bottom - rect.top - this->yOffset_, // offset
// false); int o = this->fullscreen_ ? 0 : 8;
}
else ::MoveWindow(hwnd, int(rect.right - this->width_ * scale - o),
{ int(rect.bottom - this->height_ * scale - o) + 4,
::MoveWindow(hwnd, // int(this->width_ * scale) - 5,
int(rect.right - this->width_ * scale - 8), // int(this->height_ * scale) - 5, true);
int(rect.bottom - this->height_ * scale - 8), //
int(this->width_ * scale), int(this->height_ * scale),
true);
} }
// if (this->fullscreen_)
// {
// ::BringWindowToTop(attached);
// }
// ::MoveWindow(hwnd, rect.right - 360, rect.top + 82, 360 - 8, // ::MoveWindow(hwnd, rect.right - 360, rect.top + 82, 360 - 8,
// rect.bottom - rect.top - 82 - 8, false); // rect.bottom - rect.top - 82 - 8, false);
#endif #endif
+4
View File
@@ -19,6 +19,7 @@ public:
int yOffset = -1; int yOffset = -1;
int width = -1; int width = -1;
int height = -1; int height = -1;
bool fullscreen = false;
}; };
virtual ~AttachedWindow() override; virtual ~AttachedWindow() override;
@@ -54,11 +55,14 @@ private:
int currentYOffset_; int currentYOffset_;
int width_ = 360; int width_ = 360;
int height_ = -1; int height_ = -1;
bool fullscreen_ = false;
#ifdef USEWINSDK #ifdef USEWINSDK
bool validProcessName_ = false; bool validProcessName_ = false;
bool attached_ = false; bool attached_ = false;
#endif #endif
QTimer timer_; QTimer timer_;
QTimer slowTimer_;
}; };
} // namespace chatterino } // namespace chatterino