Members of the KDE Community are recommended to subscribe to the kde-community mailing list at to allow them to participate in important discussions and receive other important announcements

Commit ffe722b2 authored by Albert Vaca Cintora's avatar Albert Vaca Cintora

Make pointer go back immediately after pushing against a screen edge

parent bdcefe4a
......@@ -57,18 +57,17 @@ public class PresenterActivity extends AppCompatActivity implements SensorEventL
private SensorManager sensorManager;
private float xPos, yPos;
private float xOffset, yOffset;
static final float SENSITIVITY = 0.05f; //TODO: Make configurable?
public void gyroscopeEvent(SensorEvent event) {
xPos += -event.values[2];
yPos += -event.values[0];
xPos += -event.values[2] * SENSITIVITY;
yPos += -event.values[0] * SENSITIVITY;
float percentX = clamp((xPos - xOffset) * SENSITIVITY, -1.f, 1.f);
float percentY = clamp((yPos - yOffset) * SENSITIVITY, -1.f, 1.f);
xPos = clamp(xPos, -1.f, 1.f);
yPos = clamp(yPos, -1.f, 1.f);
plugin.sendPointer(percentX, percentY);
plugin.sendPointer(xPos, yPos);
public void onSensorChanged(SensorEvent event) {
......@@ -90,8 +89,8 @@ public class PresenterActivity extends AppCompatActivity implements SensorEventL
findViewById(, event) -> {
if(event.getAction() == MotionEvent.ACTION_DOWN){
yOffset = yPos;
xOffset = xPos;
yPos = 0;
xPos = 0;
sensorManager.registerListener(this, sensorManager.getDefaultSensor(Sensor.TYPE_GYROSCOPE), SensorManager.SENSOR_DELAY_GAME);
v.performClick(); // The linter complains if this is not called
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment