C ++ - Linux: ala VirtualBox mouse capture

How can a person “capture a mouse” (in the same sense that a vbox captures a mouse [1])

on Linux using C ++ or C?

[1] In VBox (essentially), when you click on a vbox window, it captures the mouse in the sense that the mouse is attached to the window. When you press a key (or some other event), the mouse can return to the rest.

+4
source share
2 answers

Edit: I was thinking about Qt when I wrote this, and you can use it or not use it. Something like this might work, however, in any GUI framework you use.

It doesn't seem like there is one QWidget property that you can set that will affect this. So what you need to do: 1) enable mouse tracking, 2) handle mouse input and / or focus event (inside a QWidget), 3) handle subsequent vacation events and when they occur 4) reset the mouse position to the nearest point in the widgets using QCursor :: setPos (), which is static. 2) and 3) would take care with QWidget :: enterEvent (), QWidget :: focusInEvent () and QWidget :: leaveEvent ().

I don’t know if vacation events are placed if the mouse is above the widgets but the widget is out of focus; if not, then you can skip 2).

0
source

Since I do not have a specific answer, I would like to recommend you what I would do.

When there is a feature in an open source application, I recommend playing around with the sources.

If digging or reading is not enough, you can compile the application with full debugging information and run under the debugger to find the piece of code responsible for the interesting function.

If you have not been there, check the following places:

VirtualBox - source code organization

Frontend VirtuulBox GUI

Do some searches on chegesets, for example, search for changesets using mouse capture

In changeset 30448 I see a call to the "captureMouse" function, I think this or a similar place may follow you to the right part of the code.

What I found may interest you the most:

src / VBox / Frontends / VirtualBox / src / runtime / UIMouseHandler.cpp Description: "FE / Qt4-OSX: do not let the mouse leave the window in capture mode.", check these functions:

void UIMouseHandler::captureMouse(ulong uScreenId) 

To be complete, here is the header file: UIMouseHandler.h

0
source

Source: https://habr.com/ru/post/1346100/


All Articles