Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] MouseEvent.MovementX and MouseEvent.MovementY do not work correctly on Linux #5063

Closed
vim-overlord opened this issue Aug 27, 2022 · 1 comment
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug

Comments

@vim-overlord
Copy link

vim-overlord commented Aug 27, 2022

Describe the bug

MouseEvent.MovementX and MouseEvent.MovementY should be equal to the difference between the current mouse position and the mouse position during the previous MouseEvent, but in this case, they seem to be equal to coordinates of the cursor on the page (i.e. the same as pageX and pageY.)

Reproduction

  1. Create a project with create-tauri-app using the svelte-ts template
  2. Create two files App.svelte and Draggable.svelte with the following contents:

App.svelte:

<script lang="ts">
  import Draggable from "./Draggable.svelte";
</script>

<Draggable>
  <span style="font-size: 8rem;">TEST</span>
</Draggable>

Draggable.svelte:

<script lang="ts">
  export let x = 0;
  export let y = 0;
  let isMoving = false;

  function begin() {
    isMoving = true;
  }

  function end() {
    isMoving = false;
  }

  function move(e) {
    if (isMoving) {
      x += e.movementX;
      y += e.movementY;
    }
  }
</script>

<svelte:window on:mouseup={end} on:mousemove={move} />
<section on:mousedown={begin} style="left: {x}px; top: {y}px;" class="draggable">
  <slot></slot>
</section>

<style>
  .draggable {
    cursor: grab;
    position: absolute;
    user-select: none;
  }
</style>
  1. Run the program and attempt to drag the TEST text on the screen

Expected behavior

The text should follow the cursor instead of drifting off the screen

Platform and versions

Environment
› OS: Arch Linux Unknown X64
› Node.js: 18.7.0
› npm: Not installed!
› pnpm: 7.9.4
› yarn: Not installed!
› rustup: Not installed!
› rustc: 1.63.0
› cargo: 1.63.0
› Rust toolchain:

Packages
› @tauri-apps/cli [NPM]: 1.0.5
› @tauri-apps/api [NPM]: 1.0.2
› tauri [RUST]: 1.0.5,
› tauri-build [RUST]: 1.0.4,
› tao [RUST]: 0.12.2,
› wry [RUST]: 0.19.0,

App
› build-type: bundle
› CSP: unset
› distDir: ../dist
› devPath: http://localhost:1420/
› framework: Svelte

Stack trace

No response

Additional context

No response

@vim-overlord vim-overlord added status: needs triage This issue needs to triage, applied to new issues type: bug labels Aug 27, 2022
@amrbashir
Copy link
Member

from MDN:

Warning: Browsers use different units for movementX and screenX than what the specification defines. Depending on the browser and operating system, the movementX units may be a physical pixel, a logical pixel, or a CSS pixel.

So it seems that this property is not reliable anyways and you should compute it yourself, MDN also gives you how to compute it properly

currentEvent.movementX = currentEvent.screenX - previousEvent.screenX

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage This issue needs to triage, applied to new issues type: bug
Projects
None yet
Development

No branches or pull requests

2 participants