2013-03-17 17:06:52 -04:00
#
2013-10-27 21:59:46 +01:00
# Copyright 2009, 2013 Red Hat, Inc.
2013-03-17 17:06:52 -04:00
#
2018-04-04 14:35:41 +01:00
# This work is licensed under the GNU GPLv2 or later.
2018-03-20 15:00:02 -04:00
# See the COPYING file in the top-level directory.
2013-03-17 17:06:52 -04:00
2018-03-20 12:18:35 -04:00
from . device import Device
2018-03-20 12:27:37 -04:00
from . . xmlbuilder import XMLProperty
2013-03-17 17:06:52 -04:00
2013-04-13 14:34:52 -04:00
2018-03-20 12:18:35 -04:00
class DeviceInput ( Device ) :
2018-03-21 10:53:34 -04:00
XML_NAME = " input "
2013-03-17 17:06:52 -04:00
2013-07-15 16:55:49 -04:00
TYPE_MOUSE = " mouse "
TYPE_TABLET = " tablet "
2015-04-09 13:22:40 -04:00
TYPE_KEYBOARD = " keyboard "
2021-07-27 20:21:46 +02:00
TYPE_EVDEV = " evdev "
2013-07-15 16:55:49 -04:00
BUS_PS2 = " ps2 "
BUS_USB = " usb "
2018-04-24 15:40:33 -04:00
BUS_VIRTIO = " virtio "
2013-07-15 16:55:49 -04:00
BUS_XEN = " xen "
2018-04-24 15:40:33 -04:00
2018-09-01 17:26:35 -04:00
type = XMLProperty ( " ./@type " )
bus = XMLProperty ( " ./@bus " )
2021-07-27 20:21:46 +02:00
model = XMLProperty ( " ./@model " )
source_evdev = XMLProperty ( " ./source/@evdev " )
source_dev = XMLProperty ( " ./source/@dev " )
source_repeat = XMLProperty ( " ./source/@repeat " , is_onoff = True )
source_grab = XMLProperty ( " ./source/@grab " )
source_grabToggle = XMLProperty ( " ./source/@grabToggle " )
2015-11-21 20:26:50 -05:00
2018-09-01 17:26:35 -04:00
##################
# Default config #
##################
def _default_bus ( self , _guest ) :
2015-11-21 20:26:50 -05:00
if self . type == self . TYPE_TABLET :
return self . BUS_USB
2021-07-27 20:21:46 +02:00
# This is not explicitly stated in the docs, but the example provided
# for evdev inputs does not have a bus type set and libvirt won't
# accept such XML either.
if self . type == self . TYPE_EVDEV :
return None
2015-11-21 20:26:50 -05:00
if self . conn . is_xen ( ) :
return self . BUS_XEN
return self . BUS_PS2
2018-09-01 17:26:35 -04:00
def set_defaults ( self , guest ) :
if not self . type :
self . type = self . TYPE_MOUSE
if not self . bus :
self . bus = self . _default_bus ( guest )