ui: add an embedded Barrier client
RFC 1/1 ui: add an embedded Barrier client
This allows to receive mouse and keyboard events from a Barrier server.
This is enabled by adding the following parameter on the command line
... -object input-barrier,id=$id,name=$name ...
Where $name is the name declared in the screens section of barrier.conf
The barrier server (barriers) must be configured and must run on the local host.
For instance:
section: screens
localhost:
...
VM-1:
...
end section: links
localhost:
right = VM-1
VM-1:
left = localhost
end
Then on the QEMU command line:
... -object input-barrier,id=barrie0,name=VM-1 ...
When the mouse will move out of the screen of the local host on the right, the mouse and the keyboard will be grabbed and all related events will be send to the guest OS.
This is usefull when qemu is configured without emulated graphic card but with a VFIO attached graphic card.
More information about Barrier can be found at:
https://github.com/debauchee/barrier
This avoids to install the Barrier server in the guest OS, for instance when it is not supported or during the installation.
--- ui/Makefile.objs | 1 + ui/input-barrier.c | 639 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 640 insertions(+) create mode 100644 ui/input-barrier.c
ui/Makefile.objs +1 -0
@@ -9,6 +9,7 @@ vnc-obj-y += vnc-jobs.o common-obj-y += keymaps.o console.o cursor.o qemu-pixman.o common-obj-y += input.o input-keymap.o input-legacy.o kbd-state.o +common-obj-y += input-barrier.o common-obj-$(CONFIG_LINUX) += input-linux.o common-obj-$(CONFIG_SPICE) += spice-core.o spice-input.o spice-display.o common-obj-$(CONFIG_COCOA) += cocoa.o
ui/input-barrier.c new file +639 -0
639 lines not on this page · raw message
Signature · 1 line
2.21.0
Hi,
Quoted 16 lines
For instance:
section: screens
localhost: ... VM-1: ... endsection: links
localhost:
right = VM-1
VM-1:
left = localhost
end
Quoted 7 lines
Then on the QEMU command line:
... -object input-barrier,id=barrie0,name=VM-1 ...When the mouse will move out of the screen of the local host on the right, the mouse and the keyboard will be grabbed and all related events will be send to the guest OS.
Put that into docs/ ?
Quoted 25 lines
ui/input-barrier.c new file +25
-0+#define BARRIER_VERSION_MAJOR 1 +#define BARRIER_VERSION_MINOR 6 + +enum cmdids { + MSG_CNoop, + MSG_CClose, + MSG_CEnter, + MSG_CLeave, + MSG_CClipboard, + MSG_CScreenSaver, + MSG_CResetOptions, + MSG_CInfoAck, + MSG_CKeepAlive, + MSG_DKeyDown, + MSG_DKeyRepeat, + MSG_DKeyUp, + MSG_DMouseDown, + MSG_DMouseUp, + MSG_DMouseMove, + MSG_DMouseRelMove, + MSG_DMouseWheel, + MSG_DClipboard, + MSG_DInfo, + MSG_DSetOptions, + MSG_DFileTransfer,
ui/input-barrier.c line 86
Quoted 10 lines
ui/input-barrier.c new file +10
-0+ MSG_DDragInfo, + MSG_QInfo, + MSG_EIncompatible, + MSG_EBusy, + MSG_EUnknown, + MSG_EBad, +/* connection sequence */ + MSG_Hello, + MSG_HelloBack, +};
Put that into a barrier-protocol header file?
ui/input-barrier.c line 461
Quoted 6 lines
ui/input-barrier.c new file +6
-0+case MSG_QInfo: + p =write_cmd (ib, p, MSG_DInfo); + p =write_short (ib, p,0 );/* x origin */ + p =write_short (ib, p,0 );/* y origin */ + p =write_short (ib, p,1920 );/* width */ + p =write_short (ib, p,1080 );/* height */
Hmm.
This is the screen size I guess? Which you don't know ... What this is used for?
Should we maybe use INPUT_EVENT_ABS_MAX here?
ui/input-barrier.c line 483
Quoted 3 lines
ui/input-barrier.c new file +3
-0+case MSG_DMouseMove: +qemu_input_queue_abs (NULL ,INPUT_AXIS_X , msg.mousepos.x,0 ,1920 ); +qemu_input_queue_abs (NULL ,INPUT_AXIS_Y , msg.mousepos.y,0 ,1080 );
... and here too of course.
ui/input-barrier.c line 555
Quoted 3 lines
ui/input-barrier.c new file +3
-0+ addr.type =SOCKET_ADDRESS_TYPE_INET ; + addr.u.inet.host =g_strdup ("localhost" ); + addr.u.inet.port =g_strdup ("24800" );
Does it make sens to allow connecting to other machines? Or will the barrier daemon run on every machine anyway?
Looks reasonable overall.
cheers,
Gerd
Hi,
Le 28/08/2019 à 08:11, Gerd Hoffmann a écrit :
Quoted 20 lines
Hi,
Quoted 18 lines
For instance:
section: screens
localhost: ... VM-1: ... endsection: links
localhost:
right = VM-1
VM-1:
left = localhost
endThen on the QEMU command line:
Quoted 7 lines
Quoted 5 lines
... -object input-barrier,id=barrie0,name=VM-1 ...When the mouse will move out of the screen of the local host on the right, the mouse and the keyboard will be grabbed and all related events will be send to the guest OS.
Put that into docs/ ?
Yes, I'll add more docs once the code is ready.
Quoted 30 lines
Quoted 30 lines
ui/input-barrier.c new file +29
-0+#define BARRIER_VERSION_MAJOR 1 +#define BARRIER_VERSION_MINOR 6 + +enum cmdids { + MSG_CNoop, + MSG_CClose, + MSG_CEnter, + MSG_CLeave, + MSG_CClipboard, + MSG_CScreenSaver, + MSG_CResetOptions, + MSG_CInfoAck, + MSG_CKeepAlive, + MSG_DKeyDown, + MSG_DKeyRepeat, + MSG_DKeyUp, + MSG_DMouseDown, + MSG_DMouseUp, + MSG_DMouseMove, + MSG_DMouseRelMove, + MSG_DMouseWheel, + MSG_DClipboard, + MSG_DInfo, + MSG_DSetOptions, + MSG_DFileTransfer, + MSG_DDragInfo, + MSG_QInfo, + MSG_EIncompatible, + MSG_EBusy,
Quoted 8 lines
ui/input-barrier.c line 86
Quoted 6 lines
ui/input-barrier.c new file +6
-0+ MSG_EUnknown, + MSG_EBad, +/* connection sequence */ + MSG_Hello, + MSG_HelloBack, +};Put that into a barrier-protocol header file?
I agree.
Quoted 7 lines
ui/input-barrier.c line 461
Quoted 6 lines
ui/input-barrier.c new file +6
-0+case MSG_QInfo: + p =write_cmd (ib, p, MSG_DInfo); + p =write_short (ib, p,0 );/* x origin */ + p =write_short (ib, p,0 );/* y origin */ + p =write_short (ib, p,1920 );/* width */ + p =write_short (ib, p,1080 );/* height */
Quoted 6 lines
Hmm.
This is the screen size I guess? Which you don't know ... What this is used for?
Should we maybe useINPUT_EVENT_ABS_MAXhere?
Yes, it's screen size but we can't use INPUT_EVENT_ABS_MAX.
In fact Barrier can manage more than 2 displays:
0 x1 x2 x3
0 +------------+------------+------------+--- | | | | | localhost | VM-1 | VM-2 | | | | | y1 +------------+------------+------------+--- | | | | | remotehost | | | | | | |
y2 +------------+------------+------------+---
| | | |
So Barrier will send events to localhost while x(mouse) is between 0 and x1, to VM-1 while it is between x1 and x2, and to VM-2 between x2 and x3. So we need to know the size of the display to have x2.
Normally when the barrier client runs into an OS it intercepts the screen resizing information and send them to the server. In our case we cannot (for instance if we use a vfio display) but I plan to add properties to the input-barrier object to provide the information at least statically.
Quoted 4 lines
ui/input-barrier.c line 483
Quoted 3 lines
ui/input-barrier.c new file +3
-0+case MSG_DMouseMove: +qemu_input_queue_abs (NULL ,INPUT_AXIS_X , msg.mousepos.x,0 ,1920 ); +qemu_input_queue_abs (NULL ,INPUT_AXIS_Y , msg.mousepos.y,0 ,1080 );
Quoted 8 lines
... and here too of course.
ui/input-barrier.c line 555
Quoted 3 lines
ui/input-barrier.c new file +3
-0+ addr.type =SOCKET_ADDRESS_TYPE_INET ; + addr.u.inet.host =g_strdup ("localhost" ); + addr.u.inet.port =g_strdup ("24800" );Does it make sens to allow connecting to other machines? Or will the barrier daemon run on every machine anyway?
The barrier server runs only on the machine with the mouse and the keyboard. Other machines have normally the barrier client daemon to inject the mouse and keyboard events in the OS.
But we can imagine to have a remote host with a VM inside we want to access from our local host. So, yes, I think it makes sens to allow connecting to other machine. I will add that too.
I will try to add a keyboard remapping as we have with VNC because it doesn't work well with my french keyboard (AZERTY). Or perhaps I can use the "button" id instead of the keyid but I don't now how to map the value to a qcode.
Thanks,
Laurent
Hi,
Quoted 24 lines
Quoted 9 lines
ui/input-barrier.c line 461
Quoted 2 lines
ui/input-barrier.c new file +2
-0+ p =write_short (ib, p,1920 );/* width */ + p =write_short (ib, p,1080 );/* height */ Hmm.
This is the screen size I guess? Which you don't know ... What this is used for?
Should we maybe useINPUT_EVENT_ABS_MAXhere?Yes, it's screen size but we can't use
INPUT_EVENT_ABS_MAX.In fact Barrier can manage more than 2 displays:
0 x1 x2 x3
0 +------------+------------+------------+--- | | | | | localhost | VM-1 | VM-2 | | | | | y1 +------------+------------+------------+--- | | | | | remotehost | | | | | | |
Quoted 6 lines
y2 +------------+------------+------------+---
| | | |So Barrier will send events to localhost while x(mouse) is between 0 and x1, to VM-1 while it is between x1 and x2, and to VM-2 between x2 and x3. So we need to know the size of the display to have x2.
Ok, I see.
Quoted 3 lines
Normally when the barrier client runs into an OS it intercepts the screen resizing information and send them to the server. In our case we cannot (for instance if we use a vfio display)
Yes, for the vfio case we can't (unless it is a vgpu).
Otherwise looking up the DisplaySurface (via QemuConsole) and checking the size should work. Not a priority given that vfio is probably the most interesting use case.
How does barrier send input events to physical machines btw?
Quoted 3 lines
but I plan to add
properties to the input-barrier object to provide the information at least statically.
Makes sense.
Quoted 3 lines
The barrier server runs only on the machine with the mouse and the keyboard. Other machines have normally the barrier client daemon to inject the mouse and keyboard events in the OS.
Ok.
Quoted 4 lines
I will try to add a keyboard remapping as we have with VNC because it doesn't work well with my french keyboard (AZERTY). Or perhaps I can use the "button" id instead of the keyid but I don't now how to map the value to a qcode.
Depends on how the button id is defined. If it is one of the usual keycodes it should be easy and should work better than reverse mapping.
cheers,
Gerd
Le 28/08/2019 à 11:07, Gerd Hoffmann a écrit :
...
Quoted 7 lines
Quoted 4 lines
I will try to add a keyboard remapping as we have with VNC because it doesn't work well with my french keyboard (AZERTY). Or perhaps I can use the "button" id instead of the keyid but I don't now how to map the value to a qcode.
Depends on how the button id is defined. If it is one of the usual keycodes it should be easy and should work better than reverse mapping.
Yes, it's an Xkb keycode and qemu_input_map_xorgkbd_to_qcode[] works like a charm.
Thanks,
Laurent