fix alt+tab behavior and improve keys mapping on windows

This commit is contained in:
2019-03-06 12:21:14 +01:00
parent 4141ba0ce6
commit b484e495ff
2 changed files with 49 additions and 32 deletions

View File

@@ -1566,7 +1566,8 @@ Here's a list of what's available in this release.
<text text="About"/>
</button-custom>
<!--<button id="btn-anim" width="70" height="100%" margin="1 0 0 10" text="Animate"/>-->
<node dir="row" margin="0 0 0 50">
<node dir="row" margin="0 0 0 0" grow="1" justify="center">
<!--panel togglers-->
<button-custom id="btn-stroke" width="50" height="50" margin="0 5 0 0" thickness="1" border-color=".1" pad="2">
<image path="data/ui/stroke.png" width="100%" height="100%" align="center" justify="flex-end"/>
@@ -1588,6 +1589,13 @@ Here's a list of what's available in this release.
<image path="data/ui/grid.png" width="100%" height="100%" align="center" justify="flex-end" mips="true"/>
</button-custom>
</node>
<button-custom id="btn-undo" width="50" height="100%" margin="0 5 0 0" thickness="1" border-color="0 0 0 1" pad="2">
<image path="data/ui/undo.png" width="100%" height="100%" align="center" justify="flex-end"/>
</button-custom>
<button-custom id="btn-redo" width="50" height="100%" margin="0 5 0 0" thickness="1" border-color="0 0 0 1" pad="2">
<image path="data/ui/redo.png" width="100%" height="100%" align="center" justify="flex-end"/>
</button-custom>
<!--
<button-custom id="btn-layer" width="50" height="100%" margin="0 5 0 0" thickness="1" border-color="0 0 0 1" pad="6" align="center" justify="center">
<icon width="100%" height="100%" icon="disk"/>
@@ -1632,12 +1640,6 @@ Here's a list of what's available in this release.
<image path="data/ui/notouch.png" width="100%" height="100%" align="center" justify="flex-end"/>
</button-custom>
<button-custom id="btn-undo" width="40" height="40" margin="46 0 2 5" thickness="1" border-color="0 0 0 1" pad="2">
<image path="data/ui/undo.png" width="100%" height="100%" align="center" justify="flex-end"/>
</button-custom>
<button-custom id="btn-redo" width="40" height="40" margin="2 0 2 5" thickness="1" border-color="0 0 0 1" pad="2">
<image path="data/ui/redo.png" width="100%" height="100%" align="center" justify="flex-end"/>
</button-custom>
</node>
</border>

View File

@@ -28,6 +28,7 @@ bool keys[256];
std::mutex gl_mutex;
std::mutex async_mutex;
std::thread::id gl_thread;
std::map<kKey, int> vkey_map;
std::thread hmd_renderer;
std::thread renderer;
@@ -406,6 +407,29 @@ static void SetupExceptionHandler()
}, 0);
}
// create a reverse map from kKey to VK_XXX
void init_vk_map()
{
for (int k = 1; k < 256; k++) // ignore kKey::Unknown = 0
{
for (int vk = 0; vk < 256; vk++)
{
if (k == (int)convert_key(k))
{
if (vkey_map.find((kKey)k) == vkey_map.end())
{
vkey_map.insert({ (kKey)k, vk });
}
else
{
LOG("KEY MAP COLLISION %d and %d maps to",
(int)vk, (int)vkey_map[(kKey)k], (int)k);
}
}
}
}
}
int main(int argc, char** argv)
{
WNDCLASS wc;
@@ -416,6 +440,7 @@ int main(int argc, char** argv)
if (argc == 1)
App::I.initLog();
init_vk_map();
/*
if (!App::I.check_license())
{
@@ -863,31 +888,20 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
tasklist.emplace_back([=] {
int active = GET_WM_ACTIVATE_STATE(wp, lp);
WacomTablet::I.set_focus(active);
for (int k = 0; k < 256; k++)
static BYTE keys[256];
if (GetKeyboardState(keys))
{
if (App::I.keys[k])
bool alt = keys[VK_TAB] & 0x80;
for (auto k : vkey_map)
{
for (int i = 0; i < 256; i++)
{
if ((int)convert_key(i) == k)
{
bool down = GetKeyState(i) & 0x8000;
if (!down)
App::I.key_up((kKey)k);
}
}
}
else
{
for (int i = 0; i < 256; i++)
{
if ((int)convert_key(i) == k)
{
bool down = GetKeyState(i) & 0x8000;
if (down)
App::I.key_down((kKey)k);
}
}
// ignore alt + tab
if (alt && k.first == kKey::KeyAlt)
continue;
bool down = keys[k.second] & 0x80;
if (App::I.keys[(int)k.first] && !down)
App::I.key_up(k.first);
else if(!App::I.keys[(int)k.first] && down)
App::I.key_down(k.first);
}
}
});
@@ -913,9 +927,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
}
case WM_SYSKEYDOWN:
case WM_KEYDOWN:
if ((lp >> 30 & 1) == 0) // ignore repeated
if ((lp >> 30 & 1) == 0 && // ignore repeated
!(wp == VK_TAB && App::I.keys[(int)kKey::KeyAlt])) // ignore alt+tab
{
std::lock_guard<std::mutex> lock(task_mutex);
tasklist.emplace_back([wp] {
App::I.key_down(convert_key((int)wp));
@@ -924,6 +938,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
break;
case WM_SYSKEYUP:
case WM_KEYUP:
if (!(wp == VK_TAB && App::I.keys[(int)kKey::KeyAlt])) // ignore alt+tab
{
std::lock_guard<std::mutex> lock(task_mutex);
tasklist.emplace_back([wp] {