Skip to content

Commit e4829fb

Browse files
fix(shell): improve touchscreen support
1 parent 2e5794d commit e4829fb

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

src/shell/contextmenu/menu_render.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ menu_render menu_render::create(int x, int y, menu menu) {
9494

9595
rt->on_focus_changed = [](bool focused) {
9696
if (!focused) {
97+
rt->hide_as_close();
9798
}
9899
};
99100

src/shell/contextmenu/menu_widget.cc

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ void mb_shell::menu_item_normal_widget::render(ui::nanovg_context ctx) {
7979
}
8080

8181
auto paintY = floor(*y + (*height - icon_width) / 2);
82-
auto paintX = *x + padding + width->dest() - right_icon_padding - icon_width;
82+
auto paintX =
83+
*x + padding + width->dest() - right_icon_padding - icon_width;
8384
auto paint2 = ctx.imagePattern(paintX, paintY, icon_width, icon_width, 0,
8485
icon_unfold_img->id, *opacity / 255.f);
8586
ctx.beginPath();
@@ -367,6 +368,15 @@ void mb_shell::menu_item_normal_widget::reset_appear_animation(float delay) {
367368

368369
this->x->animate_to(0);
369370
}
371+
372+
BOOL IsCursorVisible() {
373+
CURSORINFO ci = {sizeof(CURSORINFO)};
374+
if (GetCursorInfo(&ci)) {
375+
return (ci.flags & CURSOR_SHOWING) != 0;
376+
}
377+
return FALSE;
378+
}
379+
370380
mb_shell::mouse_menu_widget_main::mouse_menu_widget_main(menu menu_data,
371381
float x, float y)
372382
: widget(), anchor_x(x), anchor_y(y) {
@@ -392,8 +402,12 @@ void mb_shell::mouse_menu_widget_main::update(ui::update_context &ctx) {
392402
}
393403
menu_wid->update(ctx);
394404

405+
auto using_touchscreen = !IsCursorVisible();
406+
395407
if (ctx.hovered_widgets->empty()) {
396-
glfwSetWindowAttrib(ctx.rt.window, GLFW_MOUSE_PASSTHROUGH, GLFW_TRUE);
408+
glfwSetWindowAttrib(ctx.rt.window, GLFW_MOUSE_PASSTHROUGH,
409+
using_touchscreen ? GLFW_FALSE : GLFW_TRUE);
410+
397411
if ((ctx.mouse_clicked || ctx.right_mouse_clicked) ||
398412
GetAsyncKeyState(VK_LBUTTON) & 0x8000 ||
399413
GetAsyncKeyState(VK_RBUTTON) & 0x8000) {
@@ -766,7 +780,7 @@ void mb_shell::menu_item_ownerdraw_widget::update(ui::update_context &ctx) {
766780
void mb_shell::menu_item_ownerdraw_widget::render(ui::nanovg_context ctx) {
767781
if (!img)
768782
img = ui::LoadBitmapImage(ctx, owner_draw.bitmap);
769-
783+
770784
auto paint = ctx.imagePattern(*x, y->dest(), owner_draw.width,
771785
owner_draw.height, 0, img->id, 1);
772786

src/shell/script/quickjspp.cc

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
#include "quickjspp.hpp"
2+
#include <print>
23

34
namespace qjs {
45
thread_local Context *Context::current;
56
void wait_with_msgloop(std::function<void()> f) {
6-
auto this_thread = GetCurrentThreadId();
7-
bool completed_flag = false;
8-
auto thread_wait = std::thread([=, &completed_flag]() {
9-
f();
10-
completed_flag = true;
11-
PostThreadMessageW(this_thread, WM_NULL, 0, 0);
12-
});
7+
auto this_thread = GetCurrentThreadId();
8+
bool completed_flag = false;
9+
auto thread_wait = std::thread([=, &completed_flag]() {
10+
f();
11+
completed_flag = true;
12+
PostThreadMessageW(this_thread, WM_NULL, 0, 0);
13+
});
1314

14-
MSG msg;
15-
while (GetMessageW(&msg, nullptr, 0, 0)) {
16-
TranslateMessage(&msg);
17-
DispatchMessageW(&msg);
15+
MSG msg;
16+
while (GetMessageW(&msg, nullptr, 0, 0)) {
17+
TranslateMessage(&msg);
18+
DispatchMessageW(&msg);
1819

19-
if (completed_flag) {
20-
break;
21-
}
20+
if (completed_flag) {
21+
break;
2222
}
23-
thread_wait.join();
23+
}
24+
thread_wait.join();
2425
}
2526
} // namespace qjs

0 commit comments

Comments
 (0)