# Makie mouse events during drag

**URL:** https://discourse.julialang.org/t/makie-mouse-events-during-drag/66726
**Category:** Specific Domains
**Tags:** makie
**Created:** [August 20, 2021, 12:53pm UTC](https://discourse.julialang.org/t/makie-mouse-events-during-drag/66726 "2021-08-20T12:53:46Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![RainerHeintzmann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rainerheintzmann/32/19726_2.png) [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)
#### Post date: [August 20, 2021, 12:53pm UTC](https://discourse.julialang.org/t/makie-mouse-events-during-drag/66726/1 "2021-08-20T12:53:46Z")

</div>

I am trying to implement a crosshair, which is updated during a mouse click but can also be “dragged”.  
However, `register_interaction!(ax, :my_mouse_interaction) do event::MouseEvent` does not seem to yield any MouseEvents in `GLMakie v0.4.4`, while dragging.  
Is there a way to enable mouse events during drag, or is it a bug?

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [August 20, 2021, 2:30pm UTC](https://discourse.julialang.org/t/makie-mouse-events-during-drag/66726/2 "2021-08-20T14:30:24Z")

</div>

Try it exactly like it’s described here, you need two arguments for example [https://makie.juliaplots.org/dev/examples/layoutables/axis/#function\_interaction](https://makie.juliaplots.org/dev/examples/layoutables/axis/#function_interaction)

---

<div class="post-metadata">

### Author: ![RainerHeintzmann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rainerheintzmann/32/19726_2.png) [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)
#### Post date: [August 20, 2021, 4:48pm UTC](https://discourse.julialang.org/t/makie-mouse-events-during-drag/66726/3 "2021-08-20T16:48:42Z")

</div>

Do you mean the `, axis` after the `do` keyword? Yes, this is what I did, but I forgot to paste it. The full line is `register_interaction!(ax, :my_mouse_interaction) do event::MouseEvent, axis` but during a drag event no mouse updates are available.

---

<div class="post-metadata">

### Author: ![RainerHeintzmann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rainerheintzmann/32/19726_2.png) [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)
#### Post date: [August 20, 2021, 5:19pm UTC](https://discourse.julialang.org/t/makie-mouse-events-during-drag/66726/4 "2021-08-20T17:19:09Z")

</div>

A bit more experimenting revealed the following behaviour: Starting a drag with the left mouse button yield only a `Makie.MakieLayout.MouseEventTypes.leftdown` event and no mouse events during the drag. Starting it with the right mouse button yields `Makie.MakieLayout.MouseEventTypes.rightdragstart` but no events during the drag. Starting it with the middle mouse button yields `Makie.MakieLayout.MouseEventTypes.middledragstart` and during the drag `Makie.MakieLayout.MouseEventTypes.middledrag` and the appropriate stop event. This is the way that I would have expected it also for left and right drags, but this is not what happens.

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [August 20, 2021, 6:38pm UTC](https://discourse.julialang.org/t/makie-mouse-events-during-drag/66726/5 "2021-08-20T18:38:28Z")

</div>

oh it must be the zoom rectangle that consumes the event, have you tried deactivating that one?

---

<div class="post-metadata">

### Author: ![RainerHeintzmann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rainerheintzmann/32/19726_2.png) [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)
#### Post date: [August 21, 2021, 7:20am UTC](https://discourse.julialang.org/t/makie-mouse-events-during-drag/66726/6 "2021-08-21T07:20:16Z")

</div>

That’s a great idea.  
Its a little difficult to find out how to deactivate it. Here is the problem:  
All the functions accept any arguments and do not throw errors. This has sometimes bad side-effects if you have a typo, and you don’t even know, if you are trying to plug the argument into the right function. E.g., I tried plugging it into `image!(rand(10,10), xrectzoom=false, yrectzoom=false)` and there is no error, yet the zooming is not deactivated, which I only found out by writing an extra test program with a new figure etc. If I type `?image!` there is close to no information. By trial and error I found out, that you can create an image by giving it an axis and also somewhere I found that it has the possible argument `interpolate=false`. Probably it has many more features, but how can I know?  
Also this [documentation](https://makie.juliaplots.org/stable/plotting_functions/image.html#MakieCore.image) does not give me more information.

Anyway,  
I gave all the axes I created the arguments `xrectzoom=false, yrectzoom=false`, yet I still have the same missing events problem. Here is a simple code that shows the problem:

```julia
fig = Figure()
ax = Axis(fig[1,1], xrectzoom=false, yrectzoom=false)
image!(rand(10,10))
register_interaction!(ax, :my_mouse_interaction) do event::MouseEvent, axis
    @show event.type 
end

```

As you can see, the zoom is disable, yet the mouse events are still missing as described.

---

<div class="post-metadata">

### Author: ![ffreyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffreyer/32/21569_2.png) [@ffreyer](https://discourse.julialang.org/u/ffreyer)
#### Post date: [August 21, 2021, 1:13pm UTC](https://discourse.julialang.org/t/makie-mouse-events-during-drag/66726/7 "2021-08-21T13:13:13Z")

</div>

Alternatively you could go through the base event system. If I get it correctly, you want something like

```julia
fig, ax, p = scatter(rand(Point2f0, 100))
pos = Node([Point2f0(0)])
scatter!(ax, pos, marker = "+")

# on move, higher priority that interactions (runs first)
on(events(ax.scene).mouseposition, priority = 2) do _
    if ispressed(ax.scene, Mouse.left)
        pos[] = [mouseposition(ax.scene)]
        return Consume(true) # this would block rectangle zoom
    end
    return Consume(false)
end

# on left click/release
on(events(ax.scene).mousebutton, priority = 2) do mb
    if mb.button == Mouse.left 
        pos[] = [mouseposition(ax.scene)]
        return Consume(true)
    end
    return Consume(false)
end

```

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [August 21, 2021, 6:25pm UTC](https://discourse.julialang.org/t/makie-mouse-events-during-drag/66726/8 "2021-08-21T18:25:33Z")

</div>

don’t use xrectzoom and yrectzoom, they only lock dimensions. it’s explained here how to remove or deactivate interactions [http://makie.juliaplots.org/dev/examples/layoutables/axis/#registering\_and\_deregistering\_interactions](http://makie.juliaplots.org/dev/examples/layoutables/axis/#registering_and_deregistering_interactions)

---

<div class="post-metadata">

### Author: ![RainerHeintzmann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rainerheintzmann/32/19726_2.png) [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)
#### Post date: [August 23, 2021, 6:21am UTC](https://discourse.julialang.org/t/makie-mouse-events-during-drag/66726/9 "2021-08-23T06:21:55Z")

</div>

Thanks a lot! The base-level registration of events seems to be fine. Thanks also for the hint on xrectzoom and yrectzoom. Still not quite sure how to `deregister` this specific zoom interaction responsible for the rectable and whether it would stop shadowing. In the long run, should it not be advantageous when a user registration of an interaction always shadows the predefined one? After all, if the user wants to still inherit the original behaviour, this is what “Consume(false)” is meant to achieve.

---

<div class="post-metadata">

### Author: ![RainerHeintzmann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rainerheintzmann/32/19726_2.png) [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)
#### Post date: [August 23, 2021, 7:04am UTC](https://discourse.julialang.org/t/makie-mouse-events-during-drag/66726/10 "2021-08-23T07:04:39Z")

</div>

Well, the base event system gives me other problems, which I don’t quite now how to deal with properly: I have 3 axes each containing 1 plot in (nested) cells. Via `register_interaction` the events nicely went to the correct plots, yet at base level, the first registered axis takes over everything.  
I probably need to individually test, if this even is within the currently displayed range and not consume it, or is there a better solution?

---

<div class="post-metadata">

### Author: ![ffreyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffreyer/32/21569_2.png) [@ffreyer](https://discourse.julialang.org/u/ffreyer)
#### Post date: [August 24, 2021, 4:53pm UTC](https://discourse.julialang.org/t/makie-mouse-events-during-drag/66726/11 "2021-08-24T16:53:28Z")

</div>

Yup, you have to do something like `if Makie.is_mouseinside(ax.scene)` to filter the events you need.

Removing the rectangle zoom is just `deregister_interaction!(ax, :rectanglezoom)`.

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [August 24, 2021, 8:00pm UTC](https://discourse.julialang.org/t/makie-mouse-events-during-drag/66726/12 "2021-08-24T20:00:14Z")

</div>

Drag is just annoying to implement correctly, so I recommend to use the thing I painstakingly implemented haha 🙂 For example, if you use naive drag, you will drag over another axis and activate it as well. It should work once you deregister or deactivate the conflicting interaction, I see no reason why it wouldn’t.

---

<div class="post-metadata">

### Author: ![RainerHeintzmann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rainerheintzmann/32/19726_2.png) [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)
#### Post date: [August 25, 2021, 6:14am UTC](https://discourse.julialang.org/t/makie-mouse-events-during-drag/66726/13 "2021-08-25T06:14:53Z")

</div>

> [@ffreyer](#):
>
> deregister\_interaction!(ax, :rectanglezoom)

Thanks a lot. This is exactly the information I needed. The `deregister` did the trick. Works great!

By the way, when GLMakie starts up, I always get tons of warnings like this:

```julia
(process:18236): GLib-GIO-WARNING **: 08:00:24.504: Unexpectedly, UWP app `Evernote.Evernote_10.10.5.0_x86__q4d96b2w5wcc2' (AUMId `Evernote.Evernote_q4d96b2w5wcc2!Evernote') supports 1 extensions but has no verbs

```

And during operation, I sometimes get total crashes when scrolling:

```julia
julia> GLFWError (PLATFORM_ERROR): WGL: Failed to make context current: Der angeforderte Transformationsvorgang wird nicht unterstützt. 
Stacktrace:
 [1] _ErrorCallbackWrapper(code::Int32, description::Cstring)
   @ GLFW ~\.julia\packages\GLFW\BWxfF\src\callback.jl:43
 [2] MakeContextCurrent
   @ ~\.julia\packages\GLFW\BWxfF\src\glfw3.jl:694 [inlined]
 [3] make_context_current
   @ ~\.julia\packages\GLMakie\rXGL8\src\drawing_primitives.jl:46 [inlined]
 [4] fps_renderloop(screen::GLMakie.Screen, framerate::Float64)
   @ GLMakie ~\.julia\packages\GLMakie\rXGL8\src\rendering.jl:26
 [5] renderloop(screen::GLMakie.Screen; framerate::Float64)
   @ GLMakie ~\.julia\packages\GLMakie\rXGL8\src\rendering.jl:48
 [6] renderloop(screen::GLMakie.Screen)
   @ GLMakie ~\.julia\packages\GLMakie\rXGL8\src\rendering.jl:41
 [7] (::GLMakie.var"#50#52"{GLMakie.Screen})()
   @ GLMakie .\task.jl:406

```

---

<div class="post-metadata">

### Author: ![RainerHeintzmann](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rainerheintzmann/32/19726_2.png) [@RainerHeintzmann](https://discourse.julialang.org/u/RainerHeintzmann)
#### Post date: [August 25, 2021, 11:26am UTC](https://discourse.julialang.org/t/makie-mouse-events-during-drag/66726/14 "2021-08-25T11:26:13Z")

</div>

I can imagine this. Yet, in my case I just wanted to be able to drag a home-written crosshair along, always centered at the mouse.  
That’s a bit easier as you do not “grab” an object.
