| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330 |
- /*
- * Copyright © 2015 Red Hat, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice (including the next
- * paragraph) shall be included in all copies or substantial portions of the
- * Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- */
- #include <config.h>
- #include <libinput.h>
- #include <valgrind/valgrind.h>
- #include "libinput-util.h"
- #include "litest.h"
- enum cardinal { N, NE, E, SE, S, SW, W, NW, NCARDINALS };
- enum hold_gesture_behaviour {
- HOLD_GESTURE_IGNORE,
- HOLD_GESTURE_REQUIRE,
- };
- static enum litest_runner_result
- test_gesture_swipe_3fg(enum cardinal cardinal, enum hold_gesture_behaviour hold)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_event *event;
- struct libinput_event_gesture *gevent;
- double dx, dy;
- double dir_x, dir_y;
- int cardinals[NCARDINALS][2] = {
- { 0, 30 }, { 30, 30 }, { 30, 0 }, { 30, -30 },
- { 0, -30 }, { -30, -30 }, { -30, 0 }, { -30, 30 },
- };
- if (litest_slot_count(dev) < 3)
- return LITEST_NOT_APPLICABLE;
- dir_x = cardinals[cardinal][0];
- dir_y = cardinals[cardinal][1];
- litest_drain_events(li);
- litest_touch_down(dev, 0, 40, 40);
- litest_touch_down(dev, 1, 50, 40);
- litest_touch_down(dev, 2, 60, 40);
- litest_dispatch(li);
- if (hold == HOLD_GESTURE_REQUIRE)
- litest_timeout_gesture_hold(li);
- litest_touch_move_three_touches(dev, 40, 40, 50, 40, 60, 40, dir_x, dir_y, 10);
- litest_dispatch(li);
- if (hold == HOLD_GESTURE_REQUIRE) {
- litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 3);
- litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 3);
- }
- event = libinput_get_event(li);
- gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, 3);
- dx = libinput_event_gesture_get_dx(gevent);
- dy = libinput_event_gesture_get_dy(gevent);
- litest_assert(dx == 0.0);
- litest_assert(dy == 0.0);
- libinput_event_destroy(event);
- while ((event = libinput_get_event(li)) != NULL) {
- gevent = litest_is_gesture_event(event,
- LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE,
- 3);
- dx = libinput_event_gesture_get_dx(gevent);
- dy = libinput_event_gesture_get_dy(gevent);
- if (dir_x == 0.0)
- litest_assert(dx == 0.0);
- else if (dir_x < 0.0)
- litest_assert(dx < 0.0);
- else if (dir_x > 0.0)
- litest_assert(dx > 0.0);
- if (dir_y == 0.0)
- litest_assert(dy == 0.0);
- else if (dir_y < 0.0)
- litest_assert(dy < 0.0);
- else if (dir_y > 0.0)
- litest_assert(dy > 0.0);
- dx = libinput_event_gesture_get_dx_unaccelerated(gevent);
- dy = libinput_event_gesture_get_dy_unaccelerated(gevent);
- if (dir_x == 0.0)
- litest_assert(dx == 0.0);
- else if (dir_x < 0.0)
- litest_assert(dx < 0.0);
- else if (dir_x > 0.0)
- litest_assert(dx > 0.0);
- if (dir_y == 0.0)
- litest_assert(dy == 0.0);
- else if (dir_y < 0.0)
- litest_assert(dy < 0.0);
- else if (dir_y > 0.0)
- litest_assert(dy > 0.0);
- libinput_event_destroy(event);
- }
- litest_touch_up(dev, 0);
- litest_touch_up(dev, 1);
- litest_touch_up(dev, 2);
- litest_dispatch(li);
- event = libinput_get_event(li);
- gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_END, 3);
- litest_assert(!libinput_event_gesture_get_cancelled(gevent));
- libinput_event_destroy(event);
- return LITEST_PASS;
- }
- static enum litest_runner_result
- test_gesture_swipe_4fg(enum cardinal cardinal, enum hold_gesture_behaviour hold)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_event *event;
- struct libinput_event_gesture *gevent;
- double dx, dy;
- double dir_x, dir_y;
- int cardinals[NCARDINALS][2] = {
- { 0, 3 }, { 3, 3 }, { 3, 0 }, { 3, -3 },
- { 0, -3 }, { -3, -3 }, { -3, 0 }, { -3, 3 },
- };
- int i;
- if (litest_slot_count(dev) < 4)
- return LITEST_NOT_APPLICABLE;
- dir_x = cardinals[cardinal][0];
- dir_y = cardinals[cardinal][1];
- litest_drain_events(li);
- litest_touch_down(dev, 0, 40, 40);
- litest_touch_down(dev, 1, 50, 40);
- litest_touch_down(dev, 2, 60, 40);
- litest_touch_down(dev, 3, 70, 40);
- litest_dispatch(li);
- if (hold == HOLD_GESTURE_REQUIRE)
- litest_timeout_gesture_hold(li);
- for (i = 0; i < 8; i++) {
- litest_push_event_frame(dev);
- dir_x += cardinals[cardinal][0];
- dir_y += cardinals[cardinal][1];
- litest_touch_move(dev, 0, 40 + dir_x, 40 + dir_y);
- litest_touch_move(dev, 1, 50 + dir_x, 40 + dir_y);
- litest_touch_move(dev, 2, 60 + dir_x, 40 + dir_y);
- litest_touch_move(dev, 3, 70 + dir_x, 40 + dir_y);
- litest_pop_event_frame(dev);
- litest_dispatch(li);
- }
- litest_dispatch(li);
- if (hold == HOLD_GESTURE_REQUIRE) {
- litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 4);
- litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 4);
- }
- event = libinput_get_event(li);
- gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, 4);
- dx = libinput_event_gesture_get_dx(gevent);
- dy = libinput_event_gesture_get_dy(gevent);
- litest_assert(dx == 0.0);
- litest_assert(dy == 0.0);
- libinput_event_destroy(event);
- while ((event = libinput_get_event(li)) != NULL) {
- gevent = litest_is_gesture_event(event,
- LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE,
- 4);
- dx = libinput_event_gesture_get_dx(gevent);
- dy = libinput_event_gesture_get_dy(gevent);
- if (dir_x == 0.0)
- litest_assert(dx == 0.0);
- else if (dir_x < 0.0)
- litest_assert(dx < 0.0);
- else if (dir_x > 0.0)
- litest_assert(dx > 0.0);
- if (dir_y == 0.0)
- litest_assert(dy == 0.0);
- else if (dir_y < 0.0)
- litest_assert(dy < 0.0);
- else if (dir_y > 0.0)
- litest_assert(dy > 0.0);
- dx = libinput_event_gesture_get_dx_unaccelerated(gevent);
- dy = libinput_event_gesture_get_dy_unaccelerated(gevent);
- if (dir_x == 0.0)
- litest_assert(dx == 0.0);
- else if (dir_x < 0.0)
- litest_assert(dx < 0.0);
- else if (dir_x > 0.0)
- litest_assert(dx > 0.0);
- if (dir_y == 0.0)
- litest_assert(dy == 0.0);
- else if (dir_y < 0.0)
- litest_assert(dy < 0.0);
- else if (dir_y > 0.0)
- litest_assert(dy > 0.0);
- libinput_event_destroy(event);
- }
- litest_touch_up(dev, 0);
- litest_touch_up(dev, 1);
- litest_touch_up(dev, 2);
- litest_touch_up(dev, 3);
- litest_dispatch(li);
- event = libinput_get_event(li);
- gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_END, 4);
- litest_assert(!libinput_event_gesture_get_cancelled(gevent));
- libinput_event_destroy(event);
- return LITEST_PASS;
- }
- static enum litest_runner_result
- test_gesture_pinch_2fg(enum cardinal cardinal, enum hold_gesture_behaviour hold)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_event *event;
- struct libinput_event_gesture *gevent;
- double dx, dy;
- double dir_x, dir_y;
- int i;
- double scale, oldscale;
- double angle;
- int cardinals[NCARDINALS][2] = {
- { 0, 30 }, { 30, 30 }, { 30, 0 }, { 30, -30 },
- { 0, -30 }, { -30, -30 }, { -30, 0 }, { -30, 30 },
- };
- if (litest_slot_count(dev) < 2 ||
- !libinput_device_has_capability(dev->libinput_device,
- LIBINPUT_DEVICE_CAP_GESTURE))
- return LITEST_NOT_APPLICABLE;
- /* If the device is too small to provide a finger spread wide enough
- * to avoid the scroll bias, skip the test */
- if (cardinal == E || cardinal == W) {
- double w = 0, h = 0;
- libinput_device_get_size(dev->libinput_device, &w, &h);
- /* 0.6 because the code below gives us points like 20/y and
- * 80/y. 45 because the threshold in the code is 40mm */
- if (w * 0.6 < 45)
- return LITEST_NOT_APPLICABLE;
- }
- dir_x = cardinals[cardinal][0];
- dir_y = cardinals[cardinal][1];
- litest_drain_events(li);
- litest_touch_down(dev, 0, 50 + dir_x, 50 + dir_y);
- litest_touch_down(dev, 1, 50 - dir_x, 50 - dir_y);
- litest_dispatch(li);
- if (hold == HOLD_GESTURE_REQUIRE)
- litest_timeout_gesture_hold(li);
- for (i = 0; i < 8; i++) {
- litest_push_event_frame(dev);
- if (dir_x > 0.0)
- dir_x -= 2;
- else if (dir_x < 0.0)
- dir_x += 2;
- if (dir_y > 0.0)
- dir_y -= 2;
- else if (dir_y < 0.0)
- dir_y += 2;
- litest_touch_move(dev, 0, 50 + dir_x, 50 + dir_y);
- litest_touch_move(dev, 1, 50 - dir_x, 50 - dir_y);
- litest_pop_event_frame(dev);
- litest_dispatch(li);
- }
- if (hold == HOLD_GESTURE_REQUIRE) {
- litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 2);
- litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 2);
- }
- event = libinput_get_event(li);
- gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, 2);
- dx = libinput_event_gesture_get_dx(gevent);
- dy = libinput_event_gesture_get_dy(gevent);
- scale = libinput_event_gesture_get_scale(gevent);
- litest_assert(dx == 0.0);
- litest_assert(dy == 0.0);
- litest_assert(scale == 1.0);
- libinput_event_destroy(event);
- while ((event = libinput_get_event(li)) != NULL) {
- gevent = litest_is_gesture_event(event,
- LIBINPUT_EVENT_GESTURE_PINCH_UPDATE,
- 2);
- oldscale = scale;
- scale = libinput_event_gesture_get_scale(gevent);
- litest_assert(scale < oldscale);
- angle = libinput_event_gesture_get_angle_delta(gevent);
- litest_assert_double_le(fabs(angle), 1.0);
- libinput_event_destroy(event);
- litest_dispatch(li);
- }
- litest_touch_up(dev, 0);
- litest_touch_up(dev, 1);
- litest_dispatch(li);
- event = libinput_get_event(li);
- gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_PINCH_END, 2);
- litest_assert(!libinput_event_gesture_get_cancelled(gevent));
- libinput_event_destroy(event);
- return LITEST_PASS;
- }
- static enum litest_runner_result
- test_gesture_pinch_3fg(enum cardinal cardinal, enum hold_gesture_behaviour hold)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_event *event;
- struct libinput_event_gesture *gevent;
- double dx, dy;
- double dir_x, dir_y;
- int i;
- double scale, oldscale;
- double angle;
- int cardinals[NCARDINALS][2] = {
- { 0, 30 }, { 30, 30 }, { 30, 0 }, { 30, -30 },
- { 0, -30 }, { -30, -30 }, { -30, 0 }, { -30, 30 },
- };
- if (litest_slot_count(dev) < 3)
- return LITEST_NOT_APPLICABLE;
- dir_x = cardinals[cardinal][0];
- dir_y = cardinals[cardinal][1];
- litest_drain_events(li);
- litest_touch_down(dev, 0, 50 + dir_x, 50 + dir_y);
- litest_touch_down(dev, 1, 50 - dir_x, 50 - dir_y);
- litest_touch_down(dev, 2, 51 - dir_x, 51 - dir_y);
- litest_dispatch(li);
- if (hold == HOLD_GESTURE_REQUIRE)
- litest_timeout_gesture_hold(li);
- for (i = 0; i < 8; i++) {
- litest_push_event_frame(dev);
- if (dir_x > 0.0)
- dir_x -= 2;
- else if (dir_x < 0.0)
- dir_x += 2;
- if (dir_y > 0.0)
- dir_y -= 2;
- else if (dir_y < 0.0)
- dir_y += 2;
- litest_touch_move(dev, 0, 50 + dir_x, 50 + dir_y);
- litest_touch_move(dev, 1, 50 - dir_x, 50 - dir_y);
- litest_touch_move(dev, 2, 51 - dir_x, 51 - dir_y);
- litest_pop_event_frame(dev);
- litest_dispatch(li);
- }
- if (hold == HOLD_GESTURE_REQUIRE) {
- litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 3);
- litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 3);
- }
- event = libinput_get_event(li);
- gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, 3);
- dx = libinput_event_gesture_get_dx(gevent);
- dy = libinput_event_gesture_get_dy(gevent);
- scale = libinput_event_gesture_get_scale(gevent);
- litest_assert(dx == 0.0);
- litest_assert(dy == 0.0);
- litest_assert(scale == 1.0);
- libinput_event_destroy(event);
- while ((event = libinput_get_event(li)) != NULL) {
- gevent = litest_is_gesture_event(event,
- LIBINPUT_EVENT_GESTURE_PINCH_UPDATE,
- 3);
- oldscale = scale;
- scale = libinput_event_gesture_get_scale(gevent);
- litest_assert(scale < oldscale);
- angle = libinput_event_gesture_get_angle_delta(gevent);
- litest_assert_double_le(fabs(angle), 1.0);
- libinput_event_destroy(event);
- litest_dispatch(li);
- }
- litest_touch_up(dev, 0);
- litest_touch_up(dev, 1);
- litest_touch_up(dev, 2);
- litest_dispatch(li);
- event = libinput_get_event(li);
- gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_PINCH_END, 3);
- litest_assert(!libinput_event_gesture_get_cancelled(gevent));
- libinput_event_destroy(event);
- return LITEST_PASS;
- }
- static enum litest_runner_result
- test_gesture_pinch_4fg(enum cardinal cardinal, enum hold_gesture_behaviour hold)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_event *event;
- struct libinput_event_gesture *gevent;
- double dx, dy;
- double dir_x, dir_y;
- int i;
- double scale, oldscale;
- double angle;
- int cardinals[NCARDINALS][2] = {
- { 0, 30 }, { 30, 30 }, { 30, 0 }, { 30, -30 },
- { 0, -30 }, { -30, -30 }, { -30, 0 }, { -30, 30 },
- };
- if (litest_slot_count(dev) < 4)
- return LITEST_NOT_APPLICABLE;
- dir_x = cardinals[cardinal][0];
- dir_y = cardinals[cardinal][1];
- litest_drain_events(li);
- litest_touch_down(dev, 0, 50 + dir_x, 50 + dir_y);
- litest_touch_down(dev, 1, 50 - dir_x, 50 - dir_y);
- litest_touch_down(dev, 2, 51 - dir_x, 51 - dir_y);
- litest_touch_down(dev, 3, 52 - dir_x, 52 - dir_y);
- litest_dispatch(li);
- if (hold == HOLD_GESTURE_REQUIRE)
- litest_timeout_gesture_hold(li);
- for (i = 0; i < 7; i++) {
- litest_push_event_frame(dev);
- if (dir_x > 0.0)
- dir_x -= 2;
- else if (dir_x < 0.0)
- dir_x += 2;
- if (dir_y > 0.0)
- dir_y -= 2;
- else if (dir_y < 0.0)
- dir_y += 2;
- litest_touch_move(dev, 0, 50 + dir_x, 50 + dir_y);
- litest_touch_move(dev, 1, 50 - dir_x, 50 - dir_y);
- litest_touch_move(dev, 2, 51 - dir_x, 51 - dir_y);
- litest_touch_move(dev, 3, 52 - dir_x, 52 - dir_y);
- litest_pop_event_frame(dev);
- litest_dispatch(li);
- }
- if (hold == HOLD_GESTURE_REQUIRE) {
- litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 4);
- litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 4);
- }
- event = libinput_get_event(li);
- gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, 4);
- dx = libinput_event_gesture_get_dx(gevent);
- dy = libinput_event_gesture_get_dy(gevent);
- scale = libinput_event_gesture_get_scale(gevent);
- litest_assert(dx == 0.0);
- litest_assert(dy == 0.0);
- litest_assert(scale == 1.0);
- libinput_event_destroy(event);
- while ((event = libinput_get_event(li)) != NULL) {
- gevent = litest_is_gesture_event(event,
- LIBINPUT_EVENT_GESTURE_PINCH_UPDATE,
- 4);
- oldscale = scale;
- scale = libinput_event_gesture_get_scale(gevent);
- litest_assert(scale < oldscale);
- angle = libinput_event_gesture_get_angle_delta(gevent);
- litest_assert_double_le(fabs(angle), 1.0);
- libinput_event_destroy(event);
- litest_dispatch(li);
- }
- litest_touch_up(dev, 0);
- litest_touch_up(dev, 1);
- litest_touch_up(dev, 2);
- litest_touch_up(dev, 3);
- litest_dispatch(li);
- event = libinput_get_event(li);
- gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_PINCH_END, 4);
- litest_assert(!libinput_event_gesture_get_cancelled(gevent));
- libinput_event_destroy(event);
- return LITEST_PASS;
- }
- static enum litest_runner_result
- test_gesture_spread(enum cardinal cardinal, enum hold_gesture_behaviour hold)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_event *event;
- struct libinput_event_gesture *gevent;
- double dx, dy;
- double dir_x, dir_y;
- int i;
- double scale, oldscale;
- double angle;
- int cardinals[NCARDINALS][2] = {
- { 0, 30 }, { 30, 30 }, { 30, 0 }, { 30, -30 },
- { 0, -30 }, { -30, -30 }, { -30, 0 }, { -30, 30 },
- };
- if (litest_slot_count(dev) < 2 ||
- !libinput_device_has_capability(dev->libinput_device,
- LIBINPUT_DEVICE_CAP_GESTURE))
- return LITEST_NOT_APPLICABLE;
- /* If the device is too small to provide a finger spread wide enough
- * to avoid the scroll bias, skip the test */
- if (cardinal == E || cardinal == W) {
- double w = 0, h = 0;
- libinput_device_get_size(dev->libinput_device, &w, &h);
- /* 0.6 because the code below gives us points like 20/y and
- * 80/y. 45 because the threshold in the code is 40mm */
- if (w * 0.6 < 45)
- return LITEST_NOT_APPLICABLE;
- }
- dir_x = cardinals[cardinal][0];
- dir_y = cardinals[cardinal][1];
- litest_drain_events(li);
- litest_touch_down(dev, 0, 50 + dir_x, 50 + dir_y);
- litest_touch_down(dev, 1, 50 - dir_x, 50 - dir_y);
- litest_dispatch(li);
- if (hold == HOLD_GESTURE_REQUIRE)
- litest_timeout_gesture_hold(li);
- for (i = 0; i < 15; i++) {
- litest_push_event_frame(dev);
- if (dir_x > 0.0)
- dir_x += 1;
- else if (dir_x < 0.0)
- dir_x -= 1;
- if (dir_y > 0.0)
- dir_y += 1;
- else if (dir_y < 0.0)
- dir_y -= 1;
- litest_touch_move(dev, 0, 50 + dir_x, 50 + dir_y);
- litest_touch_move(dev, 1, 50 - dir_x, 50 - dir_y);
- litest_pop_event_frame(dev);
- litest_dispatch(li);
- }
- if (hold == HOLD_GESTURE_REQUIRE) {
- litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 2);
- litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 2);
- }
- event = libinput_get_event(li);
- gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_PINCH_BEGIN, 2);
- dx = libinput_event_gesture_get_dx(gevent);
- dy = libinput_event_gesture_get_dy(gevent);
- scale = libinput_event_gesture_get_scale(gevent);
- litest_assert(dx == 0.0);
- litest_assert(dy == 0.0);
- litest_assert(scale == 1.0);
- libinput_event_destroy(event);
- while ((event = libinput_get_event(li)) != NULL) {
- gevent = litest_is_gesture_event(event,
- LIBINPUT_EVENT_GESTURE_PINCH_UPDATE,
- 2);
- oldscale = scale;
- scale = libinput_event_gesture_get_scale(gevent);
- litest_assert(scale > oldscale);
- angle = libinput_event_gesture_get_angle_delta(gevent);
- litest_assert_double_le(fabs(angle), 1.0);
- libinput_event_destroy(event);
- litest_dispatch(li);
- }
- litest_touch_up(dev, 0);
- litest_touch_up(dev, 1);
- litest_dispatch(li);
- event = libinput_get_event(li);
- gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_PINCH_END, 2);
- litest_assert(!libinput_event_gesture_get_cancelled(gevent));
- libinput_event_destroy(event);
- return LITEST_PASS;
- }
- static enum litest_runner_result
- test_gesture_3fg_buttonarea_scroll(enum hold_gesture_behaviour hold)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- if (litest_slot_count(dev) < 3)
- return LITEST_NOT_APPLICABLE;
- litest_enable_buttonareas(dev);
- litest_enable_2fg_scroll(dev);
- litest_drain_events(li);
- litest_touch_down(dev, 0, 40, 20);
- litest_touch_down(dev, 1, 30, 20);
- /* third finger in btnarea */
- litest_touch_down(dev, 2, 50, 99);
- litest_dispatch(li);
- if (hold == HOLD_GESTURE_REQUIRE)
- litest_timeout_gesture_hold(li);
- litest_touch_move_two_touches(dev, 40, 20, 30, 20, 0, 40, 10);
- litest_touch_up(dev, 0);
- litest_touch_up(dev, 1);
- litest_dispatch(li);
- if (hold == HOLD_GESTURE_REQUIRE) {
- litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 2);
- litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 2);
- }
- litest_assert_scroll(li,
- LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
- LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
- 4);
- return LITEST_PASS;
- }
- START_TEST(gestures_cap)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput_device *device = dev->libinput_device;
- if (libevdev_has_property(dev->evdev, INPUT_PROP_SEMI_MT))
- litest_assert(
- !libinput_device_has_capability(device,
- LIBINPUT_DEVICE_CAP_GESTURE));
- else
- litest_assert(
- libinput_device_has_capability(device,
- LIBINPUT_DEVICE_CAP_GESTURE));
- }
- END_TEST
- START_TEST(gestures_nocap)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput_device *device = dev->libinput_device;
- litest_assert(
- !libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_GESTURE));
- }
- END_TEST
- START_TEST(gestures_swipe_3fg)
- {
- enum cardinal cardinal =
- litest_test_param_get_i32(test_env->params, "direction");
- return test_gesture_swipe_3fg(cardinal, HOLD_GESTURE_IGNORE);
- }
- END_TEST
- START_TEST(gestures_swipe_3fg_btntool)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_event *event;
- struct libinput_event_gesture *gevent;
- double dx, dy;
- enum cardinal cardinal =
- litest_test_param_get_i32(test_env->params, "direction");
- double dir_x, dir_y;
- int cardinals[NCARDINALS][2] = {
- { 0, 30 }, { 30, 30 }, { 30, 0 }, { 30, -30 },
- { 0, -30 }, { -30, -30 }, { -30, 0 }, { -30, 30 },
- };
- if (litest_slot_count(dev) > 2 ||
- !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP) ||
- !libinput_device_has_capability(dev->libinput_device,
- LIBINPUT_DEVICE_CAP_GESTURE))
- return LITEST_NOT_APPLICABLE;
- dir_x = cardinals[cardinal][0];
- dir_y = cardinals[cardinal][1];
- litest_drain_events(li);
- litest_touch_down(dev, 0, 40, 40);
- litest_touch_down(dev, 1, 50, 40);
- litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0);
- litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1);
- litest_event(dev, EV_SYN, SYN_REPORT, 0);
- litest_dispatch(li);
- litest_touch_move_two_touches(dev, 40, 40, 50, 40, dir_x, dir_y, 10);
- litest_dispatch(li);
- event = libinput_get_event(li);
- gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, 3);
- dx = libinput_event_gesture_get_dx(gevent);
- dy = libinput_event_gesture_get_dy(gevent);
- litest_assert(dx == 0.0);
- litest_assert(dy == 0.0);
- libinput_event_destroy(event);
- while ((event = libinput_get_event(li)) != NULL) {
- gevent = litest_is_gesture_event(event,
- LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE,
- 3);
- dx = libinput_event_gesture_get_dx(gevent);
- dy = libinput_event_gesture_get_dy(gevent);
- if (dir_x == 0.0)
- litest_assert(dx == 0.0);
- else if (dir_x < 0.0)
- litest_assert(dx < 0.0);
- else if (dir_x > 0.0)
- litest_assert(dx > 0.0);
- if (dir_y == 0.0)
- litest_assert(dy == 0.0);
- else if (dir_y < 0.0)
- litest_assert(dy < 0.0);
- else if (dir_y > 0.0)
- litest_assert(dy > 0.0);
- dx = libinput_event_gesture_get_dx_unaccelerated(gevent);
- dy = libinput_event_gesture_get_dy_unaccelerated(gevent);
- if (dir_x == 0.0)
- litest_assert(dx == 0.0);
- else if (dir_x < 0.0)
- litest_assert(dx < 0.0);
- else if (dir_x > 0.0)
- litest_assert(dx > 0.0);
- if (dir_y == 0.0)
- litest_assert(dy == 0.0);
- else if (dir_y < 0.0)
- litest_assert(dy < 0.0);
- else if (dir_y > 0.0)
- litest_assert(dy > 0.0);
- libinput_event_destroy(event);
- }
- litest_touch_up(dev, 0);
- litest_touch_up(dev, 1);
- litest_dispatch(li);
- event = libinput_get_event(li);
- gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_END, 3);
- litest_assert(!libinput_event_gesture_get_cancelled(gevent));
- libinput_event_destroy(event);
- }
- END_TEST
- START_TEST(gestures_swipe_3fg_btntool_pinch_like)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_event *event;
- struct libinput_event_gesture *gevent;
- if (litest_slot_count(dev) > 2 ||
- !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_TRIPLETAP) ||
- !libinput_device_has_capability(dev->libinput_device,
- LIBINPUT_DEVICE_CAP_GESTURE))
- return LITEST_NOT_APPLICABLE;
- litest_drain_events(li);
- /* Technically a pinch position + pinch movement, but expect swipe
- * for nfingers > nslots */
- litest_touch_down(dev, 0, 20, 60);
- litest_touch_down(dev, 1, 50, 20);
- litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0);
- litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1);
- litest_event(dev, EV_SYN, SYN_REPORT, 0);
- litest_dispatch(li);
- litest_touch_move_to(dev, 0, 20, 60, 10, 80, 20);
- litest_dispatch(li);
- event = libinput_get_event(li);
- litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, 3);
- libinput_event_destroy(event);
- while ((event = libinput_get_event(li)) != NULL) {
- litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE, 3);
- libinput_event_destroy(event);
- }
- litest_touch_up(dev, 0);
- litest_touch_up(dev, 1);
- litest_dispatch(li);
- event = libinput_get_event(li);
- gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_END, 3);
- litest_assert(!libinput_event_gesture_get_cancelled(gevent));
- libinput_event_destroy(event);
- }
- END_TEST
- START_TEST(gestures_swipe_4fg)
- {
- enum cardinal cardinal =
- litest_test_param_get_i32(test_env->params, "direction");
- return test_gesture_swipe_4fg(cardinal, HOLD_GESTURE_IGNORE);
- }
- END_TEST
- START_TEST(gestures_swipe_4fg_btntool)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_event *event;
- struct libinput_event_gesture *gevent;
- double dx, dy;
- enum cardinal cardinal =
- litest_test_param_get_i32(test_env->params, "direction");
- double dir_x, dir_y;
- int cardinals[NCARDINALS][2] = {
- { 0, 30 }, { 30, 30 }, { 30, 0 }, { 30, -30 },
- { 0, -30 }, { -30, -30 }, { -30, 0 }, { -30, 30 },
- };
- if (litest_slot_count(dev) > 2 ||
- !libevdev_has_event_code(dev->evdev, EV_KEY, BTN_TOOL_QUADTAP) ||
- !libinput_device_has_capability(dev->libinput_device,
- LIBINPUT_DEVICE_CAP_GESTURE))
- return LITEST_NOT_APPLICABLE;
- dir_x = cardinals[cardinal][0];
- dir_y = cardinals[cardinal][1];
- litest_drain_events(li);
- litest_touch_down(dev, 0, 40, 40);
- litest_touch_down(dev, 1, 50, 40);
- litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0);
- litest_event(dev, EV_KEY, BTN_TOOL_QUADTAP, 1);
- litest_event(dev, EV_SYN, SYN_REPORT, 0);
- litest_dispatch(li);
- litest_touch_move_two_touches(dev, 40, 40, 50, 40, dir_x, dir_y, 10);
- litest_dispatch(li);
- event = libinput_get_event(li);
- gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, 4);
- dx = libinput_event_gesture_get_dx(gevent);
- dy = libinput_event_gesture_get_dy(gevent);
- litest_assert(dx == 0.0);
- litest_assert(dy == 0.0);
- libinput_event_destroy(event);
- while ((event = libinput_get_event(li)) != NULL) {
- gevent = litest_is_gesture_event(event,
- LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE,
- 4);
- dx = libinput_event_gesture_get_dx(gevent);
- dy = libinput_event_gesture_get_dy(gevent);
- if (dir_x == 0.0)
- litest_assert(dx == 0.0);
- else if (dir_x < 0.0)
- litest_assert(dx < 0.0);
- else if (dir_x > 0.0)
- litest_assert(dx > 0.0);
- if (dir_y == 0.0)
- litest_assert(dy == 0.0);
- else if (dir_y < 0.0)
- litest_assert(dy < 0.0);
- else if (dir_y > 0.0)
- litest_assert(dy > 0.0);
- dx = libinput_event_gesture_get_dx_unaccelerated(gevent);
- dy = libinput_event_gesture_get_dy_unaccelerated(gevent);
- if (dir_x == 0.0)
- litest_assert(dx == 0.0);
- else if (dir_x < 0.0)
- litest_assert(dx < 0.0);
- else if (dir_x > 0.0)
- litest_assert(dx > 0.0);
- if (dir_y == 0.0)
- litest_assert(dy == 0.0);
- else if (dir_y < 0.0)
- litest_assert(dy < 0.0);
- else if (dir_y > 0.0)
- litest_assert(dy > 0.0);
- libinput_event_destroy(event);
- }
- litest_touch_up(dev, 0);
- litest_touch_up(dev, 1);
- litest_dispatch(li);
- event = libinput_get_event(li);
- gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_END, 4);
- litest_assert(!libinput_event_gesture_get_cancelled(gevent));
- libinput_event_destroy(event);
- }
- END_TEST
- START_TEST(gestures_pinch)
- {
- enum cardinal cardinal =
- litest_test_param_get_i32(test_env->params, "direction");
- return test_gesture_pinch_2fg(cardinal, HOLD_GESTURE_IGNORE);
- }
- END_TEST
- START_TEST(gestures_pinch_3fg)
- {
- enum cardinal cardinal =
- litest_test_param_get_i32(test_env->params, "direction");
- return test_gesture_pinch_3fg(cardinal, HOLD_GESTURE_IGNORE);
- }
- END_TEST
- START_TEST(gestures_pinch_4fg)
- {
- enum cardinal cardinal =
- litest_test_param_get_i32(test_env->params, "direction");
- return test_gesture_pinch_4fg(cardinal, HOLD_GESTURE_IGNORE);
- }
- END_TEST
- START_TEST(gestures_spread)
- {
- enum cardinal cardinal =
- litest_test_param_get_i32(test_env->params, "direction");
- return test_gesture_spread(cardinal, HOLD_GESTURE_IGNORE);
- }
- END_TEST
- START_TEST(gestures_time_usec)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_event *event;
- struct libinput_event_gesture *gevent;
- uint64_t time_usec;
- if (litest_slot_count(dev) < 3)
- return LITEST_NOT_APPLICABLE;
- litest_drain_events(li);
- litest_touch_down(dev, 0, 40, 40);
- litest_touch_down(dev, 1, 50, 40);
- litest_touch_down(dev, 2, 60, 40);
- litest_dispatch(li);
- litest_touch_move_three_touches(dev, 40, 40, 50, 40, 60, 40, 0, 30, 30);
- litest_dispatch(li);
- event = libinput_get_event(li);
- gevent = litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, 3);
- time_usec = libinput_event_gesture_get_time_usec(gevent);
- litest_assert_int_eq(libinput_event_gesture_get_time(gevent),
- (uint32_t)(time_usec / 1000));
- libinput_event_destroy(event);
- }
- END_TEST
- START_TEST(gestures_3fg_buttonarea_scroll)
- {
- return test_gesture_3fg_buttonarea_scroll(HOLD_GESTURE_IGNORE);
- }
- END_TEST
- START_TEST(gestures_3fg_buttonarea_scroll_btntool)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- if (litest_slot_count(dev) > 2)
- return LITEST_NOT_APPLICABLE;
- litest_enable_buttonareas(dev);
- litest_enable_2fg_scroll(dev);
- litest_drain_events(li);
- /* first finger in btnarea */
- litest_touch_down(dev, 0, 20, 99);
- litest_touch_down(dev, 1, 30, 20);
- litest_event(dev, EV_KEY, BTN_TOOL_DOUBLETAP, 0);
- litest_event(dev, EV_KEY, BTN_TOOL_TRIPLETAP, 1);
- litest_event(dev, EV_SYN, SYN_REPORT, 0);
- litest_dispatch(li);
- litest_touch_move_to(dev, 1, 30, 20, 30, 70, 10);
- litest_touch_up(dev, 1);
- litest_dispatch(li);
- litest_assert_scroll(li,
- LIBINPUT_EVENT_POINTER_SCROLL_FINGER,
- LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
- 4);
- }
- END_TEST
- START_TEST(gestures_swipe_3fg_unaccel)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- struct libinput_event *event;
- double reference_ux = 0, reference_uy = 0;
- /**
- * This magic number is an artifact of the acceleration code.
- * The maximum factor in the touchpad accel profile is 4.8 times the
- * speed setting (1.000875 at default setting 0). The factor
- * applied to the const acceleration is the 0.9 baseline.
- * So our two sets of coordinates are:
- * accel = 4.8 * delta * normalize_magic
- * unaccel = 0.9 * delta * normalize_magic
- *
- * Since delta and the normalization magic are the same for both,
- * our accelerated deltas can be a maximum of 4.8/0.9 bigger than
- * the unaccelerated deltas.
- *
- * If any of the accel methods numbers change, this will have to
- * change here too.
- */
- const double max_factor = 5.34;
- if (litest_slot_count(dev) < 3)
- return LITEST_NOT_APPLICABLE;
- litest_drain_events(li);
- litest_touch_down(dev, 0, 40, 20);
- litest_touch_down(dev, 1, 50, 20);
- litest_touch_down(dev, 2, 60, 20);
- litest_dispatch(li);
- litest_touch_move_three_touches(dev, 40, 20, 50, 20, 60, 20, 30, 40, 10);
- litest_dispatch(li);
- event = libinput_get_event(li);
- litest_is_gesture_event(event, LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN, 3);
- libinput_event_destroy(event);
- event = libinput_get_event(li);
- do {
- struct libinput_event_gesture *gevent;
- double dx, dy;
- double ux, uy;
- gevent = litest_is_gesture_event(event,
- LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE,
- 3);
- dx = libinput_event_gesture_get_dx(gevent);
- dy = libinput_event_gesture_get_dy(gevent);
- ux = libinput_event_gesture_get_dx_unaccelerated(gevent);
- uy = libinput_event_gesture_get_dy_unaccelerated(gevent);
- litest_assert_double_ne(ux, 0.0);
- litest_assert_double_ne(uy, 0.0);
- if (!reference_ux)
- reference_ux = ux;
- if (!reference_uy)
- reference_uy = uy;
- /* The unaccelerated delta should be the same for every
- * event, but we have rounding errors since we only control
- * input data as percentage of the touchpad size.
- * so we just eyeball it */
- litest_assert_double_gt(ux, reference_ux - 2);
- litest_assert_double_lt(ux, reference_ux + 2);
- litest_assert_double_gt(uy, reference_uy - 2);
- litest_assert_double_lt(uy, reference_uy + 2);
- /* All our touchpads are large enough to make this is a fast
- * swipe, we don't expect deceleration, unaccel should
- * always be less than accel delta */
- litest_assert_double_lt(ux, dx);
- litest_assert_double_lt(ux, dx);
- /* Check our accelerated delta is within the expected
- * maximum. */
- litest_assert_double_lt(dx, ux * max_factor);
- litest_assert_double_lt(dy, uy * max_factor);
- libinput_event_destroy(event);
- } while ((event = libinput_get_event(li)));
- litest_touch_up(dev, 0);
- litest_touch_up(dev, 1);
- litest_touch_up(dev, 2);
- }
- END_TEST
- START_TEST(gestures_hold_config_default_disabled)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput_device *device = dev->libinput_device;
- litest_assert_int_eq(libinput_device_config_gesture_hold_is_available(device),
- 0);
- litest_assert_enum_eq(
- libinput_device_config_gesture_get_hold_default_enabled(device),
- LIBINPUT_CONFIG_HOLD_DISABLED);
- litest_assert_enum_eq(
- libinput_device_config_gesture_get_hold_default_enabled(device),
- LIBINPUT_CONFIG_HOLD_DISABLED);
- }
- END_TEST
- START_TEST(gestures_hold_config_default_enabled)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput_device *device = dev->libinput_device;
- litest_assert_int_eq(libinput_device_config_gesture_hold_is_available(device),
- 1);
- litest_assert_enum_eq(
- libinput_device_config_gesture_get_hold_default_enabled(device),
- LIBINPUT_CONFIG_HOLD_ENABLED);
- litest_assert_enum_eq(libinput_device_config_gesture_get_hold_enabled(device),
- LIBINPUT_CONFIG_HOLD_ENABLED);
- }
- END_TEST
- START_TEST(gestures_hold_config_set_invalid)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput_device *device = dev->libinput_device;
- litest_assert_enum_eq(
- libinput_device_config_gesture_set_hold_enabled(device, -1),
- LIBINPUT_CONFIG_STATUS_INVALID);
- litest_assert_enum_eq(
- libinput_device_config_gesture_set_hold_enabled(device, 2),
- LIBINPUT_CONFIG_STATUS_INVALID);
- }
- END_TEST
- START_TEST(gestures_hold_config_is_available)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput_device *device = dev->libinput_device;
- litest_assert_int_eq(libinput_device_config_gesture_hold_is_available(device),
- 1);
- litest_assert_enum_eq(libinput_device_config_gesture_get_hold_enabled(device),
- LIBINPUT_CONFIG_HOLD_ENABLED);
- litest_assert_enum_eq(libinput_device_config_gesture_set_hold_enabled(
- device,
- LIBINPUT_CONFIG_HOLD_DISABLED),
- LIBINPUT_CONFIG_STATUS_SUCCESS);
- litest_assert_enum_eq(libinput_device_config_gesture_get_hold_enabled(device),
- LIBINPUT_CONFIG_HOLD_DISABLED);
- }
- END_TEST
- START_TEST(gestures_hold_config_is_not_available)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput_device *device = dev->libinput_device;
- litest_assert_int_eq(libinput_device_config_gesture_hold_is_available(device),
- 0);
- litest_assert_enum_eq(libinput_device_config_gesture_get_hold_enabled(device),
- LIBINPUT_CONFIG_HOLD_DISABLED);
- litest_assert_enum_eq(libinput_device_config_gesture_set_hold_enabled(
- device,
- LIBINPUT_CONFIG_HOLD_ENABLED),
- LIBINPUT_CONFIG_STATUS_UNSUPPORTED);
- litest_assert_enum_eq(libinput_device_config_gesture_set_hold_enabled(
- device,
- LIBINPUT_CONFIG_HOLD_DISABLED),
- LIBINPUT_CONFIG_STATUS_SUCCESS);
- }
- END_TEST
- START_TEST(gestures_hold)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- int nfingers = litest_test_param_get_i32(test_env->params, "fingers");
- bool tap_enabled = litest_test_param_get_bool(test_env->params, "tap");
- if (litest_slot_count(dev) < nfingers)
- return LITEST_NOT_APPLICABLE;
- if (tap_enabled)
- litest_enable_tap(dev->libinput_device);
- else
- litest_disable_tap(dev->libinput_device);
- litest_drain_events(li);
- switch (nfingers) {
- case 4:
- litest_touch_down(dev, 3, 70, 30);
- _fallthrough_;
- case 3:
- litest_touch_down(dev, 2, 60, 30);
- _fallthrough_;
- case 2:
- litest_touch_down(dev, 1, 50, 30);
- _fallthrough_;
- case 1:
- litest_touch_down(dev, 0, 40, 30);
- break;
- }
- litest_timeout_gesture_hold(li);
- if (libinput_device_has_capability(dev->libinput_device,
- LIBINPUT_DEVICE_CAP_GESTURE)) {
- litest_assert_gesture_event(li,
- LIBINPUT_EVENT_GESTURE_HOLD_BEGIN,
- nfingers);
- } else {
- litest_assert_empty_queue(li);
- }
- switch (nfingers) {
- case 4:
- litest_touch_up(dev, 3);
- _fallthrough_;
- case 3:
- litest_touch_up(dev, 2);
- _fallthrough_;
- case 2:
- litest_touch_up(dev, 1);
- _fallthrough_;
- case 1:
- litest_touch_up(dev, 0);
- break;
- }
- litest_dispatch(li);
- if (libinput_device_has_capability(dev->libinput_device,
- LIBINPUT_DEVICE_CAP_GESTURE)) {
- _destroy_(libinput_event) *ev = libinput_get_event(li);
- auto gev = litest_is_gesture_event(ev,
- LIBINPUT_EVENT_GESTURE_HOLD_END,
- nfingers);
- litest_assert(!libinput_event_gesture_get_cancelled(gev));
- }
- litest_assert_empty_queue(li);
- }
- END_TEST
- START_TEST(gestures_hold_cancel)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- int nfingers = litest_test_param_get_i32(test_env->params, "fingers");
- bool tap_enabled = litest_test_param_get_bool(test_env->params, "tap");
- if (litest_slot_count(dev) < nfingers)
- return LITEST_NOT_APPLICABLE;
- if (tap_enabled)
- litest_enable_tap(dev->libinput_device);
- else
- litest_disable_tap(dev->libinput_device);
- litest_drain_events(li);
- int last_finger = (nfingers - 1);
- litest_drain_events(li);
- switch (nfingers) {
- case 4:
- litest_touch_down(dev, 3, 70, 30);
- _fallthrough_;
- case 3:
- litest_touch_down(dev, 2, 60, 30);
- _fallthrough_;
- case 2:
- litest_touch_down(dev, 1, 50, 30);
- _fallthrough_;
- case 1:
- litest_touch_down(dev, 0, 40, 30);
- break;
- }
- litest_timeout_gesture_hold(li);
- litest_touch_up(dev, last_finger);
- litest_dispatch(li);
- litest_timeout_gesture_hold(li);
- if (libinput_device_has_capability(dev->libinput_device,
- LIBINPUT_DEVICE_CAP_GESTURE)) {
- litest_assert_gesture_event(li,
- LIBINPUT_EVENT_GESTURE_HOLD_BEGIN,
- nfingers);
- _destroy_(libinput_event) *ev = libinput_get_event(li);
- auto gev = litest_is_gesture_event(ev,
- LIBINPUT_EVENT_GESTURE_HOLD_END,
- nfingers);
- if (nfingers > 1)
- litest_assert(libinput_event_gesture_get_cancelled(gev));
- else /* can't cancel a 1fg gesture */
- litest_assert(!libinput_event_gesture_get_cancelled(gev));
- }
- litest_assert_empty_queue(li);
- }
- END_TEST
- START_TEST(gestures_hold_then_swipe_3fg)
- {
- enum cardinal cardinal =
- litest_test_param_get_i32(test_env->params, "direction");
- return test_gesture_swipe_3fg(cardinal, HOLD_GESTURE_REQUIRE);
- }
- END_TEST
- START_TEST(gestures_hold_then_swipe_4fg)
- {
- enum cardinal cardinal =
- litest_test_param_get_i32(test_env->params, "direction");
- return test_gesture_swipe_4fg(cardinal, HOLD_GESTURE_REQUIRE);
- }
- END_TEST
- START_TEST(gestures_hold_then_pinch_2fg)
- {
- enum cardinal cardinal =
- litest_test_param_get_i32(test_env->params, "direction");
- return test_gesture_pinch_2fg(cardinal, HOLD_GESTURE_REQUIRE);
- }
- END_TEST
- START_TEST(gestures_hold_then_pinch_3fg)
- {
- enum cardinal cardinal =
- litest_test_param_get_i32(test_env->params, "direction");
- return test_gesture_pinch_3fg(cardinal, HOLD_GESTURE_REQUIRE);
- }
- END_TEST
- START_TEST(gestures_hold_then_pinch_4fg)
- {
- enum cardinal cardinal =
- litest_test_param_get_i32(test_env->params, "direction");
- return test_gesture_pinch_4fg(cardinal, HOLD_GESTURE_REQUIRE);
- }
- END_TEST
- START_TEST(gestures_hold_then_spread)
- {
- enum cardinal cardinal =
- litest_test_param_get_i32(test_env->params, "direction");
- return test_gesture_spread(cardinal, HOLD_GESTURE_REQUIRE);
- }
- END_TEST
- START_TEST(gestures_hold_then_3fg_buttonarea_scroll)
- {
- return test_gesture_3fg_buttonarea_scroll(HOLD_GESTURE_REQUIRE);
- }
- END_TEST
- START_TEST(gestures_hold_once_on_double_tap)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- if (!libinput_device_has_capability(dev->libinput_device,
- LIBINPUT_DEVICE_CAP_GESTURE))
- return LITEST_NOT_APPLICABLE;
- litest_enable_tap(dev->libinput_device);
- litest_drain_events(li);
- /* First tap, a hold gesture must be generated */
- litest_touch_down(dev, 0, 50, 50);
- litest_timeout_gesture_quick_hold(li);
- litest_touch_up(dev, 0);
- litest_dispatch(li);
- litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 1);
- litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 1);
- litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
- litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED);
- litest_assert_empty_queue(li);
- /* Double tap, don't generate an extra hold gesture */
- litest_touch_down(dev, 0, 50, 50);
- litest_touch_up(dev, 0);
- litest_timeout_gesture_quick_hold(li);
- litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
- litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED);
- litest_assert_empty_queue(li);
- }
- END_TEST
- START_TEST(gestures_hold_once_tap_n_drag)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- int nfingers = litest_test_param_get_i32(test_env->params, "fingers");
- unsigned int button = 0;
- if (nfingers > litest_slot_count(dev))
- return LITEST_NOT_APPLICABLE;
- if (!libinput_device_has_capability(dev->libinput_device,
- LIBINPUT_DEVICE_CAP_GESTURE))
- return LITEST_NOT_APPLICABLE;
- litest_enable_tap(dev->libinput_device);
- litest_disable_drag_lock(dev->libinput_device);
- litest_drain_events(li);
- switch (nfingers) {
- case 1:
- button = BTN_LEFT;
- break;
- case 2:
- button = BTN_RIGHT;
- break;
- case 3:
- button = BTN_MIDDLE;
- break;
- default:
- litest_assert_not_reached();
- }
- switch (nfingers) {
- case 3:
- litest_touch_down(dev, 2, 60, 30);
- _fallthrough_;
- case 2:
- litest_touch_down(dev, 1, 50, 30);
- _fallthrough_;
- case 1:
- litest_touch_down(dev, 0, 40, 30);
- break;
- }
- litest_timeout_gesture_quick_hold(li);
- switch (nfingers) {
- case 3:
- litest_touch_up(dev, 2);
- _fallthrough_;
- case 2:
- litest_touch_up(dev, 1);
- _fallthrough_;
- case 1:
- litest_touch_up(dev, 0);
- break;
- }
- litest_dispatch(li);
- /* "Quick" hold gestures are only generated when using 1 or 2 fingers */
- if (nfingers == 1 || nfingers == 2) {
- litest_assert_gesture_event(li,
- LIBINPUT_EVENT_GESTURE_HOLD_BEGIN,
- nfingers);
- litest_assert_gesture_event(li,
- LIBINPUT_EVENT_GESTURE_HOLD_END,
- nfingers);
- }
- /* Tap and drag, don't generate an extra hold gesture */
- litest_touch_down(dev, 0, 50, 50);
- litest_touch_move_to(dev, 0, 50, 50, 80, 80, 20);
- litest_dispatch(li);
- litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_PRESSED);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
- litest_touch_up(dev, 0);
- litest_dispatch(li);
- litest_assert_button_event(li, button, LIBINPUT_BUTTON_STATE_RELEASED);
- litest_assert_empty_queue(li);
- }
- END_TEST
- START_TEST(gestures_hold_and_motion_before_timeout)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- if (!libinput_device_has_capability(dev->libinput_device,
- LIBINPUT_DEVICE_CAP_GESTURE))
- return LITEST_NOT_APPLICABLE;
- litest_drain_events(li);
- litest_touch_down(dev, 0, 50, 50);
- litest_dispatch(li);
- litest_touch_move_to(dev, 0, 50, 50, 51, 51, 1);
- litest_touch_move_to(dev, 0, 51, 51, 50, 50, 1);
- litest_timeout_gesture_quick_hold(li);
- litest_drain_events_of_type(li, LIBINPUT_EVENT_POINTER_MOTION);
- litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 1);
- litest_touch_up(dev, 0);
- litest_dispatch(li);
- litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 1);
- litest_assert_empty_queue(li);
- }
- END_TEST
- START_TEST(gestures_hold_and_motion_after_timeout)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- if (!libinput_device_has_capability(dev->libinput_device,
- LIBINPUT_DEVICE_CAP_GESTURE))
- return LITEST_NOT_APPLICABLE;
- litest_drain_events(li);
- litest_touch_down(dev, 0, 50, 50);
- litest_timeout_gesture_quick_hold(li);
- litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_BEGIN, 1);
- litest_touch_move_to(dev, 0, 50, 50, 51, 51, 1);
- litest_touch_move_to(dev, 0, 51, 51, 50, 50, 1);
- litest_dispatch(li);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
- litest_touch_up(dev, 0);
- litest_dispatch(li);
- litest_assert_gesture_event(li, LIBINPUT_EVENT_GESTURE_HOLD_END, 1);
- litest_assert_empty_queue(li);
- }
- END_TEST
- static void
- drain_cancelled_swipe_gesture(struct libinput *li)
- {
- litest_drain_events_of_type(li,
- LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN,
- LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE);
- _destroy_(libinput_event) *end = libinput_get_event(li);
- auto gev = litest_is_gesture_event(end, LIBINPUT_EVENT_GESTURE_SWIPE_END, -1);
- litest_assert(libinput_event_gesture_get_cancelled(gev));
- }
- START_TEST(gestures_3fg_drag)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- uint32_t finger_count = litest_test_param_get_u32(test_env->params, "fingers");
- bool tap_enabled = litest_test_param_get_bool(test_env->params, "tap-enabled");
- if (litest_slot_count(dev) < 3)
- return LITEST_NOT_APPLICABLE;
- if (libinput_device_config_3fg_drag_get_finger_count(dev->libinput_device) <
- (int)finger_count)
- return LITEST_NOT_APPLICABLE;
- litest_enable_3fg_drag(dev->libinput_device, finger_count);
- if (tap_enabled)
- litest_enable_tap(dev->libinput_device);
- else
- litest_disable_tap(dev->libinput_device);
- litest_drain_events(li);
- double y = 30.0;
- for (uint32_t i = 0; i < finger_count; i++)
- litest_touch_down(dev, i, 10 + i, y);
- litest_dispatch(li);
- litest_drain_events_of_type(li,
- LIBINPUT_EVENT_GESTURE_HOLD_BEGIN,
- LIBINPUT_EVENT_GESTURE_HOLD_END);
- if (tap_enabled) {
- litest_checkpoint(
- "Expecting no immediate button press as tapping is enabled");
- litest_assert_empty_queue(li);
- } else {
- litest_checkpoint(
- "Expecting immediate swipe begin tapping is disabled");
- litest_assert_gesture_event(li,
- LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN,
- finger_count);
- }
- while (y < 60.0) {
- y += 2;
- for (uint32_t i = 0; i < finger_count; i++) {
- litest_touch_move(dev, i, 10 + i, y);
- if (i ==
- 0) /* Wait after the first movement to escape the swipe */
- litest_timeout_3fg_drag_or_swipe(li);
- }
- litest_dispatch(li);
- }
- drain_cancelled_swipe_gesture(li);
- litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
- for (uint32_t i = 0; i < finger_count; i++)
- litest_touch_up(dev, i);
- litest_dispatch(li);
- litest_assert_empty_queue(li);
- litest_timeout_3fg_drag(li);
- litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED);
- }
- END_TEST
- START_TEST(gestures_3fg_drag_lock_resume_3fg_motion)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- uint32_t finger_count = litest_test_param_get_u32(test_env->params, "fingers");
- bool tap_enabled = litest_test_param_get_bool(test_env->params, "tap-enabled");
- bool wait_for_timeout = litest_test_param_get_bool(test_env->params, "wait");
- if (litest_slot_count(dev) < 3)
- return LITEST_NOT_APPLICABLE;
- if (libinput_device_config_3fg_drag_get_finger_count(dev->libinput_device) <
- (int)finger_count)
- return LITEST_NOT_APPLICABLE;
- litest_enable_3fg_drag(dev->libinput_device, finger_count);
- if (tap_enabled)
- litest_enable_tap(dev->libinput_device);
- else
- litest_disable_tap(dev->libinput_device);
- litest_drain_events(li);
- litest_checkpoint("Putting three fingers down + movement)");
- double y = 30.0;
- for (uint32_t i = 0; i < finger_count; i++)
- litest_touch_down(dev, i, 10 + i, y);
- litest_dispatch(li);
- while (y < 60.0) {
- y += 2;
- for (uint32_t i = 0; i < finger_count; i++) {
- litest_touch_move(dev, i, 10 + i, y);
- if (i ==
- 0) /* Wait after the first movement to escape the swipe */
- litest_timeout_3fg_drag_or_swipe(li);
- }
- litest_dispatch(li);
- }
- drain_cancelled_swipe_gesture(li);
- litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
- litest_checkpoint("Releasing all fingers");
- for (uint32_t i = 0; i < finger_count; i++)
- litest_touch_up(dev, i);
- litest_dispatch(li);
- litest_assert_empty_queue(li);
- litest_checkpoint("Putting three fingers down (no movement)");
- y = 30.0;
- for (uint32_t i = 0; i < finger_count; i++)
- litest_touch_down(dev, i, 10 + i, y);
- litest_dispatch(li);
- litest_assert_empty_queue(li);
- litest_dispatch(li);
- litest_checkpoint("Waiting past finger switch timeout");
- litest_timeout_finger_switch(li);
- if (wait_for_timeout) {
- litest_checkpoint("Waiting past tap/3fg drag timeout");
- litest_timeout_3fg_drag(li);
- litest_assert_empty_queue(li);
- }
- litest_checkpoint("Moving three fingers");
- while (y < 60.0) {
- y += 2;
- for (uint32_t i = 0; i < finger_count; i++)
- litest_touch_move(dev, i, 10 + i, y);
- litest_dispatch(li);
- }
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
- litest_checkpoint("Releasing three fingers");
- for (uint32_t i = 0; i < finger_count; i++)
- litest_touch_up(dev, i);
- litest_dispatch(li);
- litest_assert_empty_queue(li);
- litest_timeout_3fg_drag(li);
- litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED);
- }
- END_TEST
- START_TEST(gestures_3fg_drag_lock_resume_3fg_release_no_motion)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- uint32_t finger_count = litest_test_param_get_u32(test_env->params, "fingers");
- bool tap_enabled = litest_test_param_get_bool(test_env->params, "tap-enabled");
- bool wait_for_timeout = litest_test_param_get_bool(test_env->params, "wait");
- /* tap-enabled for 4fg finger count doesn't make a difference */
- bool expect_tap = finger_count <= 3 && tap_enabled && !wait_for_timeout;
- if (litest_slot_count(dev) < 3)
- return LITEST_NOT_APPLICABLE;
- if (libinput_device_config_3fg_drag_get_finger_count(dev->libinput_device) <
- (int)finger_count)
- return LITEST_NOT_APPLICABLE;
- litest_enable_3fg_drag(dev->libinput_device, finger_count);
- if (tap_enabled)
- litest_enable_tap(dev->libinput_device);
- else
- litest_disable_tap(dev->libinput_device);
- litest_drain_events(li);
- litest_checkpoint("Putting %d fingers down with motion for drag", finger_count);
- double y = 30.0;
- for (uint32_t i = 0; i < finger_count; i++)
- litest_touch_down(dev, i, 10 + i, y);
- litest_dispatch(li);
- while (y < 60.0) {
- y += 2;
- for (uint32_t i = 0; i < finger_count; i++) {
- litest_touch_move(dev, i, 10 + i, y);
- if (i ==
- 0) /* Wait after the first movement to escape the swipe */
- litest_timeout_3fg_drag_or_swipe(li);
- }
- litest_dispatch(li);
- }
- drain_cancelled_swipe_gesture(li);
- litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
- for (uint32_t i = 0; i < finger_count; i++)
- litest_touch_up(dev, i);
- litest_dispatch(li);
- litest_assert_empty_queue(li);
- litest_checkpoint("Putting %d fingers down again (no motion)", finger_count);
- y = 30.0;
- for (uint32_t i = 0; i < finger_count; i++)
- litest_touch_down(dev, i, 10 + i, y);
- litest_dispatch(li);
- litest_assert_empty_queue(li);
- litest_checkpoint("Waiting past finger switch timeout");
- litest_timeout_finger_switch(li);
- if (wait_for_timeout) {
- litest_checkpoint("Waiting past tap/3fg drag timeout");
- litest_timeout_3fg_drag(li);
- litest_assert_empty_queue(li);
- }
- litest_checkpoint("Releasing %d fingers", finger_count);
- for (uint32_t i = 0; i < finger_count; i++)
- litest_touch_up(dev, i);
- litest_dispatch(li);
- if (expect_tap) {
- /* If we're not waiting and tapping is enabled, this is
- * the equivalent of a 3fg tap within the drag timeout */
- litest_checkpoint("Expecting 3fg drag release");
- litest_assert_button_event(li,
- BTN_LEFT,
- LIBINPUT_BUTTON_STATE_RELEASED);
- litest_checkpoint("Expecting 3fg tap");
- litest_assert_button_event(li,
- BTN_MIDDLE,
- LIBINPUT_BUTTON_STATE_PRESSED);
- litest_assert_button_event(li,
- BTN_MIDDLE,
- LIBINPUT_BUTTON_STATE_RELEASED);
- }
- litest_assert_empty_queue(li);
- litest_timeout_3fg_drag(li);
- if (!expect_tap)
- litest_assert_button_event(li,
- BTN_LEFT,
- LIBINPUT_BUTTON_STATE_RELEASED);
- litest_assert_empty_queue(li);
- }
- END_TEST
- START_TEST(gestures_3fg_drag_lock_resume_1fg_motion)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- uint32_t finger_count = litest_test_param_get_u32(test_env->params, "fingers");
- bool tap_enabled = litest_test_param_get_bool(test_env->params, "tap-enabled");
- if (litest_slot_count(dev) < 3)
- return LITEST_NOT_APPLICABLE;
- if (libinput_device_config_3fg_drag_get_finger_count(dev->libinput_device) <
- (int)finger_count)
- return LITEST_NOT_APPLICABLE;
- litest_enable_3fg_drag(dev->libinput_device, finger_count);
- if (tap_enabled)
- litest_enable_tap(dev->libinput_device);
- else
- litest_disable_tap(dev->libinput_device);
- litest_drain_events(li);
- litest_checkpoint("Putting 3 fingers down + motion to trigger 3fg drag");
- double y = 30.0;
- for (uint32_t i = 0; i < finger_count; i++)
- litest_touch_down(dev, i, 10 + i, y);
- while (y < 60.0) {
- y += 2;
- for (uint32_t i = 0; i < finger_count; i++) {
- litest_touch_move(dev, i, 10 + i, y);
- if (i ==
- 0) /* Wait after the first movement to escape the swipe */
- litest_timeout_3fg_drag_or_swipe(li);
- }
- litest_dispatch(li);
- }
- drain_cancelled_swipe_gesture(li);
- litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
- litest_checkpoint("Releasing 3 fingers");
- for (uint32_t i = 0; i < finger_count; i++)
- litest_touch_up(dev, i);
- litest_dispatch(li);
- litest_assert_empty_queue(li);
- litest_checkpoint("Putting 1 finger down and moving it");
- /* fingers are up, now let's put one finger down and move it */
- y = 30.0;
- litest_touch_down(dev, 0, 10, y);
- litest_dispatch(li);
- litest_assert_empty_queue(li);
- /* We need to wait until the gesture code accepts this is one finger only */
- litest_timeout_finger_switch(li);
- while (y < 60.0) {
- y += 2;
- litest_touch_move(dev, 0, 10, y);
- litest_dispatch(li);
- }
- litest_checkpoint("Expecting drag button release and motion");
- litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
- litest_touch_up(dev, 0);
- litest_dispatch(li);
- litest_assert_empty_queue(li);
- litest_timeout_3fg_drag(li);
- }
- END_TEST
- START_TEST(gestures_3fg_drag_lock_resume_2fg_scroll)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- uint32_t finger_count = litest_test_param_get_u32(test_env->params, "fingers");
- bool tap_enabled = litest_test_param_get_bool(test_env->params, "tap-enabled");
- if (litest_slot_count(dev) < 3)
- return LITEST_NOT_APPLICABLE;
- if (libinput_device_config_3fg_drag_get_finger_count(dev->libinput_device) <
- (int)finger_count)
- return LITEST_NOT_APPLICABLE;
- litest_enable_3fg_drag(dev->libinput_device, finger_count);
- if (tap_enabled)
- litest_enable_tap(dev->libinput_device);
- else
- litest_disable_tap(dev->libinput_device);
- litest_drain_events(li);
- litest_checkpoint("Putting 3 fingers down + motion to trigger 3fg drag");
- double y = 30.0;
- for (uint32_t i = 0; i < finger_count; i++)
- litest_touch_down(dev, i, 10 + i, y);
- while (y < 60.0) {
- y += 2;
- for (uint32_t i = 0; i < finger_count; i++) {
- litest_touch_move(dev, i, 10 + i, y);
- if (i ==
- 0) /* Wait after the first movement to escape the swipe */
- litest_timeout_3fg_drag_or_swipe(li);
- }
- litest_dispatch(li);
- }
- drain_cancelled_swipe_gesture(li);
- litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
- litest_checkpoint("Releasing 3 fingers");
- for (uint32_t i = 0; i < finger_count; i++)
- litest_touch_up(dev, i);
- litest_dispatch(li);
- litest_assert_empty_queue(li);
- litest_checkpoint("Putting 2 fingers down and moving them");
- y = 30.0;
- litest_touch_down(dev, 0, 10, y);
- litest_touch_down(dev, 1, 20, y);
- litest_dispatch(li);
- litest_assert_empty_queue(li);
- litest_timeout_finger_switch(li);
- while (y < 60.0) {
- y += 2;
- litest_touch_move(dev, 0, 10, y);
- litest_touch_move(dev, 1, 20, y);
- litest_dispatch(li);
- }
- litest_checkpoint("Expecting drag button release and scroll");
- litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED);
- litest_assert_only_axis_events(li, LIBINPUT_EVENT_POINTER_SCROLL_FINGER);
- litest_touch_up(dev, 0);
- litest_dispatch(li);
- litest_assert_empty_queue(li);
- litest_timeout_3fg_drag(li);
- }
- END_TEST
- START_TEST(gestures_3fg_drag_lock_resume_1fg_tap)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- int finger_count = litest_test_param_get_i32(test_env->params, "fingers");
- if (litest_slot_count(dev) < 3)
- return LITEST_NOT_APPLICABLE;
- if (libinput_device_config_3fg_drag_get_finger_count(dev->libinput_device) <
- finger_count)
- return LITEST_NOT_APPLICABLE;
- litest_enable_3fg_drag(dev->libinput_device, finger_count);
- litest_enable_tap(dev->libinput_device);
- litest_drain_events(li);
- litest_checkpoint("Putting 3 fingers down for 3fg drag");
- double y = 30.0;
- for (int i = 0; i < finger_count; i++)
- litest_touch_down(dev, i, 10 + i, y);
- litest_dispatch(li);
- while (y < 60.0) {
- y += 2;
- for (int i = 0; i < finger_count; i++) {
- litest_touch_move(dev, i, 10 + i, y);
- if (i ==
- 0) /* Wait after the first movement to escape the swipe */
- litest_timeout_3fg_drag_or_swipe(li);
- }
- litest_dispatch(li);
- }
- litest_drain_events_of_type(li,
- LIBINPUT_EVENT_GESTURE_HOLD_BEGIN,
- LIBINPUT_EVENT_GESTURE_HOLD_END,
- -1);
- drain_cancelled_swipe_gesture(li);
- litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
- litest_checkpoint("Releasing 3 fingers");
- for (int i = 0; i < finger_count; i++)
- litest_touch_up(dev, i);
- litest_dispatch(li);
- litest_assert_empty_queue(li);
- litest_checkpoint("Tapping with 1 finger");
- /* fingers are up, now let's tap with one finger */
- y = 30.0;
- litest_touch_down(dev, 0, 10, y);
- litest_dispatch(li);
- litest_assert_empty_queue(li);
- litest_touch_up(dev, 0);
- litest_dispatch(li);
- litest_timeout_tap(li);
- litest_checkpoint("Expecting drag release followed by 1fg tap");
- /* 3fg drag lock must be cancelled */
- litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED);
- /* And a 1fg tap */
- litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
- litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED);
- litest_assert_empty_queue(li);
- litest_timeout_3fg_drag(li);
- }
- END_TEST
- START_TEST(gestures_3fg_drag_fast_swipe)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- uint32_t finger_count = litest_test_param_get_u32(test_env->params, "fingers");
- bool tap_enabled = litest_test_param_get_bool(test_env->params, "tap-enabled");
- if (litest_slot_count(dev) < 3)
- return LITEST_NOT_APPLICABLE;
- if (libinput_device_config_3fg_drag_get_finger_count(dev->libinput_device) <
- (int)finger_count)
- return LITEST_NOT_APPLICABLE;
- litest_enable_3fg_drag(dev->libinput_device, finger_count);
- if (tap_enabled)
- litest_enable_tap(dev->libinput_device);
- else
- litest_disable_tap(dev->libinput_device);
- litest_drain_events(li);
- double y = 30.0;
- for (uint32_t i = 0; i < finger_count; i++)
- litest_touch_down(dev, i, 10 + i, y);
- while (y < 60.0) {
- y += 2;
- for (uint32_t i = 0; i < finger_count; i++) {
- litest_touch_move(dev, i, 10 + i, y);
- }
- litest_dispatch(li);
- }
- litest_drain_events_of_type(li,
- LIBINPUT_EVENT_GESTURE_HOLD_BEGIN,
- LIBINPUT_EVENT_GESTURE_HOLD_END);
- auto begin = libinput_get_event(li);
- litest_is_gesture_event(begin,
- LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN,
- finger_count);
- libinput_event_destroy(begin);
- struct libinput_event *update;
- while ((update = libinput_get_event(li))) {
- litest_is_gesture_event(update,
- LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE,
- finger_count);
- libinput_event_destroy(update);
- }
- for (uint32_t i = 0; i < finger_count; i++)
- litest_touch_up(dev, i);
- litest_dispatch(li);
- auto end = libinput_get_event(li);
- auto gev = litest_is_gesture_event(end,
- LIBINPUT_EVENT_GESTURE_SWIPE_END,
- finger_count);
- litest_assert(!libinput_event_gesture_get_cancelled(gev));
- libinput_event_destroy(end);
- }
- END_TEST
- START_TEST(gestures_3fg_drag_slow_start)
- {
- struct litest_device *dev = litest_current_device();
- struct libinput *li = dev->libinput;
- uint32_t finger_count = litest_test_param_get_u32(test_env->params, "fingers");
- bool tap_enabled = litest_test_param_get_bool(test_env->params, "tap-enabled");
- if (litest_slot_count(dev) < 3)
- return LITEST_NOT_APPLICABLE;
- if (libinput_device_config_3fg_drag_get_finger_count(dev->libinput_device) <
- (int)finger_count)
- return LITEST_NOT_APPLICABLE;
- litest_enable_3fg_drag(dev->libinput_device, finger_count);
- if (tap_enabled)
- litest_enable_tap(dev->libinput_device);
- else
- litest_disable_tap(dev->libinput_device);
- litest_drain_events(li);
- /* Fingers are set down, then we do nothing, then we swipe fast. Because
- * we did nothing at first even fast movement must become a 3fg drag, not
- * a swipe.
- */
- double y = 30.0;
- for (uint32_t i = 0; i < finger_count; i++)
- litest_touch_down(dev, i, 10 + i, y);
- litest_checkpoint("Waiting past timeout before fast finger move");
- litest_timeout_3fg_drag_or_swipe(li);
- /* Now move fast */
- while (y < 60.0) {
- y += 2;
- for (uint32_t i = 0; i < finger_count; i++) {
- litest_touch_move(dev, i, 10 + i, y);
- }
- litest_dispatch(li);
- }
- drain_cancelled_swipe_gesture(li);
- litest_checkpoint("Expecting button press for 3fg drag");
- litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
- litest_assert_only_typed_events(li, LIBINPUT_EVENT_POINTER_MOTION);
- for (uint32_t i = 0; i < finger_count; i++)
- litest_touch_up(dev, i);
- litest_dispatch(li);
- litest_assert_empty_queue(li);
- litest_timeout_3fg_drag(li);
- litest_assert_button_event(li, BTN_LEFT, LIBINPUT_BUTTON_STATE_RELEASED);
- }
- END_TEST
- TEST_COLLECTION(gestures)
- {
- /* clang-format off */
- litest_add(gestures_cap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
- litest_add(gestures_nocap, LITEST_ANY, LITEST_TOUCHPAD);
- litest_add(gestures_swipe_3fg_btntool_pinch_like, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
- litest_add(gestures_3fg_buttonarea_scroll, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH);
- litest_add(gestures_3fg_buttonarea_scroll_btntool, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH);
- litest_add(gestures_time_usec, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
- litest_add(gestures_hold_config_default_disabled, LITEST_TOUCHPAD|LITEST_SEMI_MT, LITEST_ANY);
- litest_add(gestures_hold_config_default_enabled, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT);
- litest_add(gestures_hold_config_set_invalid, LITEST_TOUCHPAD, LITEST_ANY);
- litest_add(gestures_hold_config_is_available, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH|LITEST_SEMI_MT);
- litest_add(gestures_hold_config_is_not_available, LITEST_TOUCHPAD|LITEST_SEMI_MT, LITEST_ANY);
- litest_with_parameters(params,
- "fingers", 'i', 4, 1, 2, 3, 4,
- "tap", 'b') {
- litest_add_parametrized(gestures_hold, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
- litest_add_parametrized(gestures_hold_cancel, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
- }
- litest_with_parameters(params, "direction", 'I', 8, litest_named_i32(N), litest_named_i32(NE),
- litest_named_i32(E), litest_named_i32(SE),
- litest_named_i32(S), litest_named_i32(SW),
- litest_named_i32(W), litest_named_i32(NW)) {
- litest_add_parametrized(gestures_swipe_3fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
- litest_add_parametrized(gestures_swipe_3fg_btntool, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
- litest_add_parametrized(gestures_swipe_4fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
- litest_add_parametrized(gestures_swipe_4fg_btntool, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
- litest_add_parametrized(gestures_pinch, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
- litest_add_parametrized(gestures_pinch_3fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
- litest_add_parametrized(gestures_pinch_4fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
- litest_add_parametrized(gestures_spread, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
- litest_add_parametrized(gestures_hold_then_swipe_3fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
- litest_add_parametrized(gestures_hold_then_swipe_4fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
- litest_add_parametrized(gestures_hold_then_pinch_2fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
- litest_add_parametrized(gestures_hold_then_pinch_3fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
- litest_add_parametrized(gestures_hold_then_pinch_4fg, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
- litest_add_parametrized(gestures_hold_then_spread, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
- }
- litest_add(gestures_hold_then_3fg_buttonarea_scroll, LITEST_CLICKPAD, LITEST_SINGLE_TOUCH);
- litest_add(gestures_hold_once_on_double_tap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
- litest_with_parameters(params, "fingers", 'i', 3, 1, 2, 3) {
- litest_add_parametrized(gestures_hold_once_tap_n_drag, LITEST_TOUCHPAD, LITEST_ANY, params);
- }
- litest_add(gestures_hold_and_motion_before_timeout, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
- litest_add(gestures_hold_and_motion_after_timeout, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
- litest_with_parameters(params,
- "fingers", 'u', 2, 3, 4,
- "tap-enabled", 'b') {
- litest_add_parametrized(gestures_3fg_drag, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
- }
- litest_with_parameters(params,
- "fingers", 'u', 2, 3, 4,
- "tap-enabled", 'b',
- "wait", 'b') {
- litest_add_parametrized(gestures_3fg_drag_lock_resume_3fg_motion, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
- litest_add_parametrized(gestures_3fg_drag_lock_resume_3fg_release_no_motion, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
- }
- litest_with_parameters(params,
- "fingers", 'u', 2, 3, 4,
- "tap-enabled", 'b') {
- litest_add_parametrized(gestures_3fg_drag_lock_resume_1fg_motion, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
- litest_add_parametrized(gestures_3fg_drag_lock_resume_2fg_scroll, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
- }
- litest_with_parameters(params, "fingers", 'i', 2, 3, 4) {
- litest_add_parametrized(gestures_3fg_drag_lock_resume_1fg_tap, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
- }
- litest_with_parameters(params,
- "fingers", 'u', 2, 3, 4,
- "tap-enabled", 'b') {
- litest_add_parametrized(gestures_3fg_drag_fast_swipe, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
- litest_add_parametrized(gestures_3fg_drag_slow_start, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH, params);
- }
- /* Timing-sensitive test, valgrind is too slow */
- if (!RUNNING_ON_VALGRIND)
- litest_add(gestures_swipe_3fg_unaccel, LITEST_TOUCHPAD, LITEST_SINGLE_TOUCH);
- /* clang-format on */
- }
|