mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
refactor(input): name the scene input types and wheel scale (#2524)
nativeSendSceneInput took bare integers (3, 4, 6, 11, 12) and the wheel step (120) and pointer fixed-point scale (256) were repeated inline. BottomDesktopPanel kept its own private copies of three of them. Move them to WaylandCompositor next to the native method and use them at every call site. No behavior change. Co-authored-by: Dennis Zabolotny <15849186+zdennisz@users.noreply.github.com>
This commit is contained in:
1 parent
76aa3771b7
commit
e3d86c4b17
4 files changed
+21
-20
No files matched your search
@@ -3703,7 +3703,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
if (h == 0 && v == 0) return
|
||||
scrollRestX -= h
|
||||
scrollRestY -= v
|
||||
WaylandCompositor.nativeSendSceneInput(11, ScrollTouchGestures.wheelUnits(v, out.second), ScrollTouchGestures.wheelUnits(h, out.first))
|
||||
WaylandCompositor.nativeSendSceneInput(WaylandCompositor.SCENE_AXIS, ScrollTouchGestures.wheelUnits(v, out.second), ScrollTouchGestures.wheelUnits(h, out.first))
|
||||
}
|
||||
override fun onLongPress() = pointerListener.onLongPress()
|
||||
}
|
||||
@@ -3758,13 +3758,13 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
if (h == 0 && v == 0) return
|
||||
scrollRestX -= h
|
||||
scrollRestY -= v
|
||||
WaylandCompositor.nativeSendSceneInput(12, v, h)
|
||||
WaylandCompositor.nativeSendSceneInput(WaylandCompositor.SCENE_AXIS_FINGER, v, h)
|
||||
}
|
||||
|
||||
private fun fingerScrollEnd() {
|
||||
scrollRestX = 0f
|
||||
scrollRestY = 0f
|
||||
WaylandCompositor.nativeSendSceneInput(12, 0, 0)
|
||||
WaylandCompositor.nativeSendSceneInput(WaylandCompositor.SCENE_AXIS_FINGER, 0, 0)
|
||||
}
|
||||
|
||||
private fun placeTouchpadAtGuest(rect: android.graphics.RectF) {
|
||||
@@ -4518,14 +4518,14 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
else guestButtonsDown.remove(code) ?: evdevMouseActive
|
||||
val writer = if (raw) mouseWriter else null
|
||||
if (writer != null) writer.writeMouseButton(code.toShort(), down)
|
||||
else WaylandCompositor.nativeSendSceneInput(3, code, if (down) 1 else 0)
|
||||
else WaylandCompositor.nativeSendSceneInput(WaylandCompositor.SCENE_BUTTON, code, if (down) 1 else 0)
|
||||
}
|
||||
|
||||
private fun sendSceneWheel(steps: Int, horizontal: Boolean = false): Unit = synchronized(heldButtons) {
|
||||
val writer = if (evdevMouseActive) mouseWriter else null
|
||||
if (writer != null) writer.writeMouseWheel(if (horizontal) 0 else -steps, if (horizontal) steps else 0, 120)
|
||||
else if (horizontal) WaylandCompositor.nativeSendSceneInput(11, 0, steps * 120)
|
||||
else WaylandCompositor.nativeSendSceneInput(4, steps, 0)
|
||||
if (writer != null) writer.writeMouseWheel(if (horizontal) 0 else -steps, if (horizontal) steps else 0, WaylandCompositor.WHEEL_STEP_UNITS)
|
||||
else if (horizontal) WaylandCompositor.nativeSendSceneInput(WaylandCompositor.SCENE_AXIS, 0, steps * WaylandCompositor.WHEEL_STEP_UNITS)
|
||||
else WaylandCompositor.nativeSendSceneInput(WaylandCompositor.SCENE_WHEEL, steps, 0)
|
||||
}
|
||||
|
||||
private fun sendMouseDelta(x: Float, y: Float) {
|
||||
|
||||
@@ -194,7 +194,7 @@ object BottomDesktop {
|
||||
send(target, Message.obtain(null, Comp.MSG_POINTER, x, y))
|
||||
}
|
||||
|
||||
/** Button (3), wheel (4) and smooth-scroll (12) input, as `WaylandCompositor.nativeSendSceneInput` takes it. */
|
||||
/** Button, wheel and finger-scroll input, using the `WaylandCompositor.SCENE_*` types `nativeSendSceneInput` takes. */
|
||||
fun sendScene(type: Int, a: Int, b: Int = 0) {
|
||||
val target = service ?: return
|
||||
send(target, Message.obtain(null, Comp.MSG_SCENE, type, a).apply {
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.droiddeck.launcher.input.PointerGestures
|
||||
import com.droiddeck.launcher.input.TouchpadGestures
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.session.BottomDesktop
|
||||
import com.droiddeck.launcher.wayland.WaylandCompositor
|
||||
|
||||
@SuppressLint("ViewConstructor")
|
||||
class BottomDesktopPanel(
|
||||
@@ -289,10 +290,10 @@ class BottomDesktopPanel(
|
||||
|
||||
override fun onButton(button: Int, pressed: Boolean, x: Float, y: Float) {
|
||||
movePointer(x, y)
|
||||
BottomDesktop.sendScene(SCENE_BUTTON, button, if (pressed) 1 else 0)
|
||||
BottomDesktop.sendScene(WaylandCompositor.SCENE_BUTTON, button, if (pressed) 1 else 0)
|
||||
}
|
||||
|
||||
override fun onWheel(steps: Int) = BottomDesktop.sendScene(SCENE_WHEEL, steps)
|
||||
override fun onWheel(steps: Int) = BottomDesktop.sendScene(WaylandCompositor.SCENE_WHEEL, steps)
|
||||
|
||||
override fun onScroll(dx: Float, dy: Float) {
|
||||
val (outW, outH) = BottomDesktop.outputSize
|
||||
@@ -303,18 +304,18 @@ class BottomDesktopPanel(
|
||||
if (h == 0 && v == 0) return
|
||||
scrollRestX -= h
|
||||
scrollRestY -= v
|
||||
BottomDesktop.sendScene(SCENE_AXIS, v, h)
|
||||
BottomDesktop.sendScene(WaylandCompositor.SCENE_AXIS_FINGER, v, h)
|
||||
}
|
||||
|
||||
override fun onScrollEnd() {
|
||||
scrollRestX = 0f
|
||||
scrollRestY = 0f
|
||||
BottomDesktop.sendScene(SCENE_AXIS, 0, 0)
|
||||
BottomDesktop.sendScene(WaylandCompositor.SCENE_AXIS_FINGER, 0, 0)
|
||||
}
|
||||
|
||||
override fun onZoom(steps: Int) {
|
||||
BottomDesktop.sendKey(KEY_LEFTCTRL, true)
|
||||
BottomDesktop.sendScene(SCENE_WHEEL, steps)
|
||||
BottomDesktop.sendScene(WaylandCompositor.SCENE_WHEEL, steps)
|
||||
BottomDesktop.sendKey(KEY_LEFTCTRL, false)
|
||||
}
|
||||
|
||||
@@ -331,9 +332,6 @@ class BottomDesktopPanel(
|
||||
private fun dp(value: Int): Int = (value * resources.displayMetrics.density + 0.5f).toInt()
|
||||
|
||||
private companion object {
|
||||
const val SCENE_BUTTON = 3
|
||||
const val SCENE_WHEEL = 4
|
||||
const val SCENE_AXIS = 12
|
||||
const val KEY_LEFTCTRL = 29
|
||||
const val AXIS_UNITS_PER_PIXEL = 3f
|
||||
const val TEXT_FIELD_TAP_MS = 1_000L
|
||||
|
||||
@@ -327,6 +327,9 @@ public final class WaylandCompositor {
|
||||
|
||||
public static native void nativeSendSceneInput(int type, int a, int b);
|
||||
|
||||
public static final int SCENE_BUTTON = 3, SCENE_WHEEL = 4, SCENE_POINTER_DELTA = 6, SCENE_AXIS = 11, SCENE_AXIS_FINGER = 12;
|
||||
public static final int WHEEL_STEP_UNITS = 120, POINTER_DELTA_SCALE = 256;
|
||||
|
||||
public static final int FG_ENGINE_LSFG = 0, FG_ENGINE_DDFG = 1;
|
||||
|
||||
public static native void nativeSetFrameGenEngine(int kind);
|
||||
@@ -355,19 +358,19 @@ public final class WaylandCompositor {
|
||||
|
||||
public static void sendPointerDelta(int dx, int dy) {
|
||||
if (dx == 0 && dy == 0) return;
|
||||
nativeSendSceneInput(6, dx * 256, dy * 256);
|
||||
nativeSendSceneInput(SCENE_POINTER_DELTA, dx * POINTER_DELTA_SCALE, dy * POINTER_DELTA_SCALE);
|
||||
}
|
||||
|
||||
private static float pendingDeltaX, pendingDeltaY;
|
||||
|
||||
public static void sendPointerDelta(float dx, float dy) {
|
||||
pendingDeltaX += dx * 256f;
|
||||
pendingDeltaY += dy * 256f;
|
||||
pendingDeltaX += dx * POINTER_DELTA_SCALE;
|
||||
pendingDeltaY += dy * POINTER_DELTA_SCALE;
|
||||
int x = (int) Math.floor(pendingDeltaX);
|
||||
int y = (int) Math.floor(pendingDeltaY);
|
||||
if (x == 0 && y == 0) return;
|
||||
pendingDeltaX -= x;
|
||||
pendingDeltaY -= y;
|
||||
nativeSendSceneInput(6, x, y);
|
||||
nativeSendSceneInput(SCENE_POINTER_DELTA, x, y);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user