how to draw a cursor in glfw while getting mouse input? - sprite

I have a program using glfw for window management and opengl for rendering. The program works on Windows and linux, and eventually Mac OSX so I want any solution to be portable.
glfw seems to either support a cursor, or getting full mouse input but not both. For example, with the cursor enabled (default) the glfwscroll_callback does nothing. If I disable the cursor, then scrolling the mouse is captured but then the user cannot see where the mouse pointer is. That's ok if I can draw the cursor myself when I want but I cannot find any function to drawcursor at a particular location.
How does the cursor work, ie what is the hardware basis for the cursor? Is there a sprite in hardware still? If it's all in software, I suppose we could draw a cursor at the current mouse location the last thing in render. But that's not convenient. For one thing if the scene hasn't changed, I shut down rendering completely to reduce power.
Is there any way to manually draw a cursor on top of the current screen so that we don't have to manage the buffers manually? Is my only option to change the logic and not render the scene if nothing has changed, but to manually draw a cursor on top of the current scene every frame?

Related

Disable mouse hover event on Windows globally without blocking mousemove

I've made a Node/AutoHotKey script to control two computers with one mouse. I've made the cursor disappear on the first computer when using the second computer (https://www.autohotkey.com/boards/viewtopic.php?t=6167), but the mouseover event is still firing of course.
What I mean is simply if you hover over some icons on the desktop you will see tooltips, and so on.
I'm using a graphics tablet (absolute positioning), the cursor position gets captured and sent to the second computer.
I've found this method:
Found it here: https://www.autohotkey.com/boards/viewtopic.php?t=33128 (Also from the documentation: https://www.autohotkey.com/docs/commands/BlockInput.htm)
BlockInput, MouseMove ;to disable mouse interaction
BlockInPut, MouseMoveOff ;to enable mouse interaction
But it blocks mousemove completely, so that the cursor stops moving at all.
Is there any way to programmatically disable/enable mouseover (so that buttons don't change their color and tooltips don't appear, but AutoHotKey could still capture cursor position) event globally on Windows without blocking mousemove?

In Linux, what piece of software is responsible for drawing the mouse cursor?

As the title states it: what software actually draws the mouse cursor? Is there a programmatic way for modifying the visual appearance?
The mouse cursor (or mouse pointer) is drawn by the X server. Each application that the cursor moves over may be able to modify the appearance of the mouse cursor.
Since there are different applications and those are built over different toolkits, each could use a different method for changing the cursor's appearance.
xterm uses the X library for manipulating this:
XDefineCursor
XRecolorCursor
XCreateFontCursor
xterm may choose a cursor-font which is small enough to hide the mouse pointer, but the X server continues to "draw" it.
Like other applications, xterm may also use cursor themes, which (in desktop systems such as GNOME, KDE, XFCE), may be configured in a desktop-settings.
But ultimately it is the X server which draws the mouse cursor. The application does not have to do anything to allow it to move around the screen. Rather, each application listens for X events to keep track of the mouse cursor.
Further reading:
How do I change the cursor from an arrow to a watch?
Cursor themes (Arch)
How do you hide the mouse pointer under Linux/X11?

Propagating all events from a X window

I'a currently working on a small utility, it's my first ever X project. The utility is used to draw a small circle around your mouse pointer. I use an app called Pinpoint to do the same on my Mac, it helps me find my mouse as I'm visually impaired.
The utility creates an transparent X window and draw a circle inside, it then moves that window with the mouse pointer so that the circle follows the mouse.
It currently works, except for one detail. Mouse events are not propagated up to the underlying windows. Basically, the utility makes the mouse useless.
As far as I can tell from the Xlib docs, if not otherwise specified, new windows should propagate all events. How can I fix this?
The code can be found on GitHub: https://github.com/blubber/circle-cursor it's a bit messy currently, becaue it is just a proof of concept.
I would suggest doing via cursor image as well, there are many ways when you won't be able to receive mouse events and only possible source would be polling with XQueryPointer.
With xfixes extension you can subscribe to all cursor image changed events and get most recent shape of the cursor, and whit XRender you can set your own ( possibly animated cursor )

Three.js First Person Controls moves the camera all the time

The game I'm designing currently requires a first person controller and luckily Three.js offers that class as well.
However I can't stop the camera from flying around. I know that the mouse movement causes the fly because it happens as soon as I move the mouse. But reading the js code,I cant find the attribue which causes this movement. Here is how I initiate the controls:
controls = new THREE.FirstPersonControls(camera);
controls.movementSpeed = 0.1;
controls.lookSpeed = 0.001;
controls.lookVertical = true;
I do not want the view direction to change when I am not moving the mouse.
any idea ?
Keep in mind that the FPS style mouse movement in webGL is usable rather only in a full screen mode. If an application runs in a standard windowed mode, the cursor is visible, and the application can not detect cursor movements that cross the edge of the window. This makes it impossible to look around in the FPS style (look movement stops when the cursors reaches the window edge).
This is probably the main reason why a PointerLockControls demo asks you to switch to the full screen mode.
With FirstPersonControls the look movement continues when the mouse reaches the edge. Such approach works well in the windowed mode.
You might want to use the PointerLockControls instead
See an example here:
https://github.com/mrdoob/three.js/blob/master/examples/misc_controls_pointerlock.html

I need to draw a line moving with the cursor, but I want to avoid redrawing the whole window every 100ms

I have a program which displays a ruler on the screen, and with Xlib it polls for the cursor position every 100ms and updates the display. The display consists of numbers/lines etc, in particular a line indicating the position of the cursor (which is why it updates).
The problem is that the old line needs to be erased and the content underneath restored, so I have to redraw the whole window to reflect a change in position. Doing this 10 times a second results in a very flickery program.
I could only redraw the ruler after I have confirmed that the cursor is in a position to change the indicator line (i.e. within the bounds of the ruler), but it would still flicker pretty bad when it was updating.
Sort of a noob to GTK and Xlib and all, any advice would be appreciated.
Code is at https://github.com/zjmichen/zRuler
Well you have arrived at one of the earliest problems faced when cursors were being implemented!! Cursor changes are so frequent that redrawing full window every time just doesn't make any sense! Coming to your problem, look at what is needed & what exactly you are doing. Do you need to update the full window when cursor moves? No. You need to update only a section of the window so don't update the whole window. Off the top, I can think of 2 ways of reducing flicker:
1. Simple way is to make use of GdkCursor. Create a new cursor from the pixmap (Sample provided on the developer page) with the shape of your need, a line in your case. Associate cursor with the GdkWindow of your application's main window. This way you don't have to track cursor & draw the line. The cursor itself will appear as the line (so you don't to bother about clearing & redrawing it). Now in the timer callback where you redraw the complete window, redraw only the component which has to be updated on cursor position change. This should hopefully reduce the flicker as you are not drawing all the components.
2. In case you don't want to use GdkCursor, you could create a separate transparent window on top of application window dedicated to cursor. In this approach you can update only the cursor window & the component in the application window which is to updated on change in cursor position. This way other components in the application window are not redrawn each time & this hopefully should also be able to reduce flicker.
Hope this helps!

Resources