Skip to content

Commit

Permalink
Merge PR #2692: os_win: remove MumbleHWNDForQWidget, add mumble_mw_hwnd.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkrautz committed Dec 3, 2016
2 parents aa263e9 + 5075b6c commit 5998cc0
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 96 deletions.
6 changes: 3 additions & 3 deletions src/mumble/ASIOInput.cpp
Expand Up @@ -11,7 +11,7 @@
#include "Global.h"

// From os_win.cpp.
extern HWND MumbleHWNDForQWidget(QWidget *w);
extern HWND mumble_mw_hwnd;

class ASIOAudioInputRegistrar : public AudioInputRegistrar {
public:
Expand Down Expand Up @@ -185,7 +185,7 @@ void ASIOConfig::on_qpbQuery_clicked() {
CLSIDFromString(const_cast<wchar_t *>(reinterpret_cast<const wchar_t *>(qsCls.utf16())), &clsid);
if (CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, clsid, reinterpret_cast<void **>(&iasio)) == S_OK) {
SleepEx(10, false);
if (iasio->init(MumbleHWNDForQWidget(this))) {
if (iasio->init(mumble_mw_hwnd)) {
SleepEx(10, false);
char buff[512];
memset(buff, 0, 512);
Expand Down Expand Up @@ -267,7 +267,7 @@ void ASIOConfig::on_qpbConfig_clicked() {
CLSIDFromString(const_cast<wchar_t *>(reinterpret_cast<const wchar_t *>(qsCls.utf16())), &clsid);
if (CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, clsid, reinterpret_cast<void **>(&iasio)) == S_OK) {
SleepEx(10, false);
if (iasio->init(MumbleHWNDForQWidget(this))) {
if (iasio->init(mumble_mw_hwnd)) {
SleepEx(10, false);
iasio->controlPanel();
SleepEx(10, false);
Expand Down
4 changes: 2 additions & 2 deletions src/mumble/DirectSound.cpp
Expand Up @@ -13,7 +13,7 @@
#include "Global.h"

// from os_win.cpp
extern HWND MumbleHWNDForQWidget(QWidget *w);
extern HWND mumble_mw_hwnd;

#undef FAILED
#define FAILED(Status) (static_cast<HRESULT>(Status)<0)
Expand Down Expand Up @@ -236,7 +236,7 @@ void DXAudioOutput::run() {
if (! pDS && FAILED(hr = DirectSoundCreate8(&DSDEVID_DefaultVoicePlayback, &pDS, NULL))) {
qWarning("DXAudioOutput: DirectSoundCreate failed: hr=0x%08lx", hr);
goto cleanup;
} else if (FAILED(hr = pDS->SetCooperativeLevel(MumbleHWNDForQWidget(g.mw), DSSCL_PRIORITY))) {
} else if (FAILED(hr = pDS->SetCooperativeLevel(mumble_mw_hwnd, DSSCL_PRIORITY))) {
qWarning("DXAudioOutput: SetCooperativeLevel failed: hr=0x%08lx", hr);
goto cleanup;
} else if (FAILED(hr = pDS->CreateSoundBuffer(&dsbdesc, &pDSBPrimary, NULL))) {
Expand Down
70 changes: 2 additions & 68 deletions src/mumble/GlobalShortcut_win.cpp
Expand Up @@ -20,7 +20,7 @@
#define DX_SAMPLE_BUFFER_SIZE 512

// from os_win.cpp
extern HWND MumbleHWNDForQWidget(QWidget *w);
extern HWND mumble_mw_hwnd;

static uint qHash(const GUID &a) {
uint val = a.Data1 ^ a.Data2 ^ a.Data3;
Expand Down Expand Up @@ -272,24 +272,6 @@ LRESULT CALLBACK GlobalShortcutWin::HookKeyboard(int nCode, WPARAM wParam, LPARA
ql << QVariant(QUuid(GUID_SysKeyboard));
bool suppress = gsw->handleButton(ql, !(key->flags & LLKHF_UP));

if (! suppress && g.ocIntercept) {
// In full-GUI-overlay always suppress
suppress = true;

HWND hwnd = MumbleHWNDForQWidget(&g.ocIntercept->qgv);

GUITHREADINFO gti;
ZeroMemory(&gti, sizeof(gti));
gti.cbSize = sizeof(gti);
::GetGUIThreadInfo(::GetWindowThreadProcessId(hwnd, NULL), &gti);

if (gti.hwndFocus)
hwnd = gti.hwndFocus;

if (! nomsg)
::PostMessage(hwnd, msg, w, l);
}

if (suppress)
return 1;

Expand Down Expand Up @@ -343,54 +325,6 @@ LRESULT CALLBACK GlobalShortcutWin::HookMouse(int nCode, WPARAM wParam, LPARAM l
break;
}

if (g.ocIntercept) {
// In full-GUI-overlay always suppress
suppress = true;

POINT p;
GetCursorPos(&p);

int dx = mouse->pt.x - p.x;
int dy = mouse->pt.y - p.y;

g.ocIntercept->iMouseX = qBound<int>(0, g.ocIntercept->iMouseX + dx, g.ocIntercept->uiWidth - 1);
g.ocIntercept->iMouseY = qBound<int>(0, g.ocIntercept->iMouseY + dy, g.ocIntercept->uiHeight - 1);

WPARAM w = 0;
LPARAM l = (static_cast<short>(g.ocIntercept->iMouseX) & 0xFFFF) | ((g.ocIntercept->iMouseY << 16) & 0xFFFF0000);

if (ucKeyState[VK_CONTROL] & 0x80)
w |= MK_CONTROL;
if (ucKeyState[VK_LBUTTON] & 0x80)
w |= MK_LBUTTON;
if (ucKeyState[VK_MBUTTON] & 0x80)
w |= MK_MBUTTON;
if (ucKeyState[VK_RBUTTON] & 0x80)
w |= MK_RBUTTON;
if (ucKeyState[VK_SHIFT] & 0x80)
w |= MK_SHIFT;
if (ucKeyState[VK_XBUTTON1] & 0x80)
w |= MK_XBUTTON1;
if (ucKeyState[VK_XBUTTON2] & 0x80)
w |= MK_XBUTTON2;

w |= (mouse->mouseData & 0xFFFF0000);

HWND hwnd = MumbleHWNDForQWidget(&g.ocIntercept->qgv);

GUITHREADINFO gti;
ZeroMemory(&gti, sizeof(gti));
gti.cbSize = sizeof(gti);
::GetGUIThreadInfo(::GetWindowThreadProcessId(hwnd, NULL), &gti);

if (gti.hwndCapture)
hwnd = gti.hwndCapture;

::PostMessage(hwnd, msg, w, l);

QMetaObject::invokeMethod(g.ocIntercept, "updateMouse", Qt::QueuedConnection);
}

bool down = false;
unsigned int btn = 0;
switch (msg) {
Expand Down Expand Up @@ -569,7 +503,7 @@ BOOL GlobalShortcutWin::EnumDevicesCB(LPCDIDEVICEINSTANCE pdidi, LPVOID pContext
id->qhTypeToOfs[dwType] = dwOfs;
}

if (FAILED(hr = id->pDID->SetCooperativeLevel(MumbleHWNDForQWidget(g.mw), DISCL_NONEXCLUSIVE|DISCL_BACKGROUND)))
if (FAILED(hr = id->pDID->SetCooperativeLevel(mumble_mw_hwnd, DISCL_NONEXCLUSIVE|DISCL_BACKGROUND)))
qFatal("GlobalShortcutWin: SetCooperativeLevel: %lx", hr);

if (FAILED(hr = id->pDID->SetDataFormat(&df)))
Expand Down
7 changes: 7 additions & 0 deletions src/mumble/main.cpp
Expand Up @@ -411,6 +411,13 @@ int main(int argc, char **argv) {
g.mw=new MainWindow(NULL);
g.mw->show();

#ifdef Q_OS_WIN
// Set mumble_mw_hwnd in os_win.cpp.
// Used by APIs in ASIOInput, DirectSound and GlobalShortcut_win that require a HWND.
extern HWND mumble_mw_hwnd;
mumble_mw_hwnd = GetForegroundWindow();
#endif

#ifdef USE_DBUS
new MumbleDBus(g.mw);
QDBusConnection::sessionBus().registerObject(QLatin1String("/"), g.mw);
Expand Down
1 change: 0 additions & 1 deletion src/mumble/mumble.pro
Expand Up @@ -64,7 +64,6 @@ QT *= network sql xml svg
isEqual(QT_MAJOR_VERSION, 5) {
QT *= widgets
# Allow native widget access.
win32:QT *= gui-private
macx:QT *= gui-private
}

Expand Down
24 changes: 2 additions & 22 deletions src/mumble/os_win.cpp
Expand Up @@ -5,10 +5,6 @@

#include "mumble_pch.hpp"

#if QT_VERSION >= 0x050000
# include <qpa/qplatformnativeinterface.h>
#endif

#include <windows.h>
#include <tlhelp32.h>
#include <dbghelp.h>
Expand Down Expand Up @@ -36,6 +32,8 @@ static int cpuinfo[4];
bool bIsWin7 = false;
bool bIsVistaSP1 = false;

HWND mumble_mw_hwnd = 0;

static void mumbleMessageOutputQString(QtMsgType type, const QString &msg) {
char c;
switch (type) {
Expand Down Expand Up @@ -313,21 +311,3 @@ DWORD WinVerifySslCert(const QByteArray& cert) {

return errorStatus;
}

HWND MumbleHWNDForQWidget(QWidget *widget) {
#if QT_VERSION >= 0x050000
QWindow *window = widget->windowHandle();
if (window == NULL) {
QWidget *npw = widget->nativeParentWidget();
if (npw != NULL) {
window = npw->windowHandle();
}
}
if (window != NULL && window->handle() != 0) {
return static_cast<HWND>(qApp->platformNativeInterface()->nativeResourceForWindow("handle", window));
}
return 0;
#else
return widget->winId();
#endif
}

0 comments on commit 5998cc0

Please sign in to comment.