From 5720b8abe62a917d52357d0ec8665a431f55c27e Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sat, 13 Mar 2021 14:00:37 +0200 Subject: Touch: Long-press context click on any widget --- src/ui/window.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'src/ui/window.c') diff --git a/src/ui/window.c b/src/ui/window.c index dc056887..d896ac21 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -1159,7 +1159,7 @@ static void setupUserInterface_Window(iWindow *d) { (iMenuItem[]) { { leftHalf_Icon " Toggle Left Sidebar", 0, 0, "sidebar.toggle" }, { rightHalf_Icon " Toggle Right Sidebar", 0, 0, "sidebar2.toggle" }, - }, 2); + }, deviceType_App() == phone_AppDeviceType ? 1 : 2); iWidget *clipMenu = makeMenu_Widget(d->root, (iMenuItem[]){ { scissor_Icon " Cut", 0, 0, "input.copy cut:1" }, @@ -1765,16 +1765,7 @@ iBool processEvent_Window(iWindow *d, const SDL_Event *ev) { wasUsed = dispatchEvent_Widget(widget, &paste); } if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_RIGHT) { - /* A context menu may still get triggered here. */ - const iWidget *hit = hitChild_Widget(d->root, init_I2(event.button.x, event.button.y)); - while (hit && isEmpty_String(id_Widget(hit))) { - hit = parent_Widget(hit); - } - if (hit) { - postCommandf_App("contextclick id:%s ptr:%p coord:%d %d", - cstr_String(id_Widget(hit)), hit, - event.button.x, event.button.y); - } + postContextClick_Window(d, &event.button); } } if (isMetricsChange_UserEvent(&event)) { @@ -1792,6 +1783,21 @@ iBool processEvent_Window(iWindow *d, const SDL_Event *ev) { return iFalse; } +iBool postContextClick_Window(iWindow *d, const SDL_MouseButtonEvent *ev) { + /* A context menu may still get triggered here. */ + const iWidget *hit = hitChild_Widget(d->root, init_I2(ev->x, ev->y)); + while (hit && isEmpty_String(id_Widget(hit))) { + hit = parent_Widget(hit); + } + if (hit) { + postCommandf_App("contextclick id:%s ptr:%p coord:%d %d", + cstr_String(id_Widget(hit)), hit, + ev->x, ev->y); + return iTrue; + } + return iFalse; +} + void draw_Window(iWindow *d) { if (d->isDrawFrozen) { return; -- cgit v1.2.3