summaryrefslogtreecommitdiff
path: root/src/ui/touch.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-05-18 07:04:27 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-05-18 07:04:27 +0300
commitfacc3abb7faafb323cb87e26ddba8dac01af02e9 (patch)
tree387aa23e03b029f516ecca6880131fd6523e1c3f /src/ui/touch.c
parentced855c338b78e05c66d38618373728ef946ebaa (diff)
parent5d517c2f790a38d7fe3c3cc59a1b39fd49e20280 (diff)
Merge branch 'dev' into work/typesetter
# Conflicts: # src/ui/documentwidget.c # src/ui/inputwidget.c
Diffstat (limited to 'src/ui/touch.c')
-rw-r--r--src/ui/touch.c54
1 files changed, 31 insertions, 23 deletions
diff --git a/src/ui/touch.c b/src/ui/touch.c
index b2c52526..74a22baf 100644
--- a/src/ui/touch.c
+++ b/src/ui/touch.c
@@ -227,7 +227,7 @@ static void dispatchButtonUp_Touch_(iFloat3 pos) {
227 227
228static void dispatchNotification_Touch_(const iTouch *d, int code) { 228static void dispatchNotification_Touch_(const iTouch *d, int code) {
229 if (d->affinity) { 229 if (d->affinity) {
230 iRoot *oldRoot = get_Root(); 230 iRoot *oldRoot = current_Root();
231 setCurrent_Root(d->affinity->root); 231 setCurrent_Root(d->affinity->root);
232 dispatchEvent_Widget(d->affinity, (SDL_Event *) &(SDL_UserEvent){ 232 dispatchEvent_Widget(d->affinity, (SDL_Event *) &(SDL_UserEvent){
233 .type = SDL_USEREVENT, 233 .type = SDL_USEREVENT,
@@ -318,6 +318,8 @@ static void update_TouchState_(void *ptr) {
318 if (pixels.x || pixels.y) { 318 if (pixels.x || pixels.y) {
319 subv_F3(&mom->accum, initI2_F3(pixels)); 319 subv_F3(&mom->accum, initI2_F3(pixels));
320 dispatchMotion_Touch_(mom->pos, 0); 320 dispatchMotion_Touch_(mom->pos, 0);
321 iAssert(mom->affinity);
322 setCurrent_Root(mom->affinity->root);
321 dispatchEvent_Widget(mom->affinity, (SDL_Event *) &(SDL_MouseWheelEvent){ 323 dispatchEvent_Widget(mom->affinity, (SDL_Event *) &(SDL_MouseWheelEvent){
322 .type = SDL_MOUSEWHEEL, 324 .type = SDL_MOUSEWHEEL,
323 .timestamp = nowTime, 325 .timestamp = nowTime,
@@ -334,26 +336,13 @@ static void update_TouchState_(void *ptr) {
334 } 336 }
335 /* Keep updating if interaction is still ongoing. */ 337 /* Keep updating if interaction is still ongoing. */
336 if (!isEmpty_Array(d->touches) || !isEmpty_Array(d->moms)) { 338 if (!isEmpty_Array(d->touches) || !isEmpty_Array(d->moms)) {
337 addTicker_App(update_TouchState_, ptr); 339 addTickerRoot_App(update_TouchState_, NULL, ptr);
338 } 340 }
339} 341}
340 342
341static iWidget *findOverflowScrollable_Widget_(iWidget *d) {
342 const iInt2 rootSize = size_Root(d->root);
343 for (iWidget *w = d; w; w = parent_Widget(w)) {
344 if (flags_Widget(w) & overflowScrollable_WidgetFlag) {
345 if (height_Widget(w) > rootSize.y && !hasVisibleChildOnTop_Widget(w)) {
346 return w;
347 }
348 return NULL;
349 }
350 }
351 return NULL;
352}
353
354static iWidget *findSlidePanel_Widget_(iWidget *d) { 343static iWidget *findSlidePanel_Widget_(iWidget *d) {
355 for (iWidget *w = d; w; w = parent_Widget(w)) { 344 for (iWidget *w = d; w; w = parent_Widget(w)) {
356 if (isVisible_Widget(w) && flags_Widget(w) & horizontalOffset_WidgetFlag) { 345 if (isVisible_Widget(w) && flags_Widget(w) & edgeDraggable_WidgetFlag) {
357 return w; 346 return w;
358 } 347 }
359 } 348 }
@@ -466,6 +455,8 @@ iBool processEvent_Touch(const SDL_Event *ev) {
466 if (edge == left_TouchEdge) { 455 if (edge == left_TouchEdge) {
467 dragging = findSlidePanel_Widget_(aff); 456 dragging = findSlidePanel_Widget_(aff);
468 if (dragging) { 457 if (dragging) {
458// printf("Selected for dragging: ");
459// identify_Widget(dragging);
469 setFlags_Widget(dragging, dragged_WidgetFlag, iTrue); 460 setFlags_Widget(dragging, dragged_WidgetFlag, iTrue);
470 } 461 }
471 } 462 }
@@ -492,7 +483,7 @@ iBool processEvent_Touch(const SDL_Event *ev) {
492 } 483 }
493 /* This may begin a pinch. */ 484 /* This may begin a pinch. */
494 checkNewPinch_TouchState_(d, back_Array(d->touches)); 485 checkNewPinch_TouchState_(d, back_Array(d->touches));
495 addTicker_App(update_TouchState_, d); 486 addTickerRoot_App(update_TouchState_, NULL, d);
496 } 487 }
497 else if (ev->type == SDL_FINGERMOTION) { 488 else if (ev->type == SDL_FINGERMOTION) {
498 iTouch *touch = find_TouchState_(d, fing->fingerId); 489 iTouch *touch = find_TouchState_(d, fing->fingerId);
@@ -544,7 +535,7 @@ iBool processEvent_Touch(const SDL_Event *ev) {
544 divvf_F3(&touch->accum, 6); 535 divvf_F3(&touch->accum, 6);
545 divfv_I2(&pixels, 6); 536 divfv_I2(&pixels, 6);
546 /* Allow scrolling a scrollable widget. */ 537 /* Allow scrolling a scrollable widget. */
547 iWidget *flow = findOverflowScrollable_Widget_(touch->affinity); 538 iWidget *flow = findOverflowScrollable_Widget(touch->affinity);
548 if (flow) { 539 if (flow) {
549 touch->affinity = flow; 540 touch->affinity = flow;
550 } 541 }
@@ -567,7 +558,7 @@ iBool processEvent_Touch(const SDL_Event *ev) {
567 } 558 }
568 /* Edge swipe aborted? */ 559 /* Edge swipe aborted? */
569 if (touch->edge == left_TouchEdge) { 560 if (touch->edge == left_TouchEdge) {
570 if (fing->dx < 0) { 561 if (fing->dx < 0 && x_F3(touch->pos[0]) < tapRadiusPt_ * window->pixelRatio) {
571 touch->edge = none_TouchEdge; 562 touch->edge = none_TouchEdge;
572 if (touch->edgeDragging) { 563 if (touch->edgeDragging) {
573 setFlags_Widget(touch->edgeDragging, dragged_WidgetFlag, iFalse); 564 setFlags_Widget(touch->edgeDragging, dragged_WidgetFlag, iFalse);
@@ -598,6 +589,7 @@ iBool processEvent_Touch(const SDL_Event *ev) {
598 if (pixels.x || pixels.y) { 589 if (pixels.x || pixels.y) {
599 setFocus_Widget(NULL); 590 setFocus_Widget(NULL);
600 dispatchMotion_Touch_(touch->pos[0], 0); 591 dispatchMotion_Touch_(touch->pos[0], 0);
592 setCurrent_Root(touch->affinity->root);
601 dispatchEvent_Widget(touch->affinity, (SDL_Event *) &(SDL_MouseWheelEvent){ 593 dispatchEvent_Widget(touch->affinity, (SDL_Event *) &(SDL_MouseWheelEvent){
602 .type = SDL_MOUSEWHEEL, 594 .type = SDL_MOUSEWHEEL,
603 .timestamp = SDL_GetTicks(), 595 .timestamp = SDL_GetTicks(),
@@ -642,17 +634,19 @@ iBool processEvent_Touch(const SDL_Event *ev) {
642 continue; 634 continue;
643 } 635 }
644 /* Edge swipes do not generate momentum. */ 636 /* Edge swipes do not generate momentum. */
637 const size_t lastIndex = iMin(touch->posCount - 1, lastIndex_Touch_);
645 const uint32_t duration = nowTime - touch->startTime; 638 const uint32_t duration = nowTime - touch->startTime;
646 const iFloat3 gestureVector = sub_F3(pos, touch->startPos); 639 const iFloat3 gestureVector = sub_F3(pos, touch->pos[lastIndex]);
647 iFloat3 velocity = zero_F3(); 640 iFloat3 velocity = zero_F3();
648 if (touch->edge && fabsf(2 * x_F3(gestureVector)) > fabsf(y_F3(gestureVector)) && 641 if (touch->edge && fabsf(2 * x_F3(gestureVector)) > fabsf(y_F3(gestureVector)) &&
649 !isStationary_Touch_(touch)) { 642 !isStationary_Touch_(touch)) {
650 dispatchClick_Touch_(touch, touch->edge == left_TouchEdge ? SDL_BUTTON_X1 643 const int swipeDir = x_F3(gestureVector) > 0 ? +1 : -1;
651 : SDL_BUTTON_X2); 644 dispatchClick_Touch_(touch,
645 touch->edge == left_TouchEdge && swipeDir > 0 ? SDL_BUTTON_X1 :
646 touch->edge == right_TouchEdge && swipeDir < 0 ? SDL_BUTTON_X2 : 0);
652 setHover_Widget(NULL); 647 setHover_Widget(NULL);
653 } 648 }
654 else { 649 else {
655 const size_t lastIndex = iMin(touch->posCount - 1, lastIndex_Touch_);
656 const uint32_t elapsed = fing->timestamp - touch->posTime[lastIndex]; 650 const uint32_t elapsed = fing->timestamp - touch->posTime[lastIndex];
657 const float minVelocity = 400.0f; 651 const float minVelocity = 400.0f;
658 if (elapsed < 150) { 652 if (elapsed < 150) {
@@ -758,6 +752,20 @@ iInt2 latestPosition_Touch(void) {
758 return touchState_()->currentTouchPos; 752 return touchState_()->currentTouchPos;
759} 753}
760 754
755iBool isHovering_Touch(void) {
756 iTouchState *d = touchState_();
757 if (numFingers_Touch() == 1) {
758 const iTouch *touch = constFront_Array(d->touches);
759 if (touch->isTapBegun && isStationary_Touch_(touch)) {
760 return iTrue;
761 }
762 if (touch->isTapAndHold) {
763 return iTrue;
764 }
765 }
766 return iFalse;
767}
768
761size_t numFingers_Touch(void) { 769size_t numFingers_Touch(void) {
762 return size_Array(touchState_()->touches); 770 return size_Array(touchState_()->touches);
763} 771}