Example #1
0
    def _create_spice_session(self):
        self._spice_session = SpiceClientGLib.Session()
        SpiceClientGLib.set_session_option(self._spice_session)
        gtk_session = SpiceClientGtk.GtkSession.get(self._spice_session)
        gtk_session.set_property("auto-clipboard", True)

        GObject.GObject.connect(self._spice_session, "channel-new",
                                self._channel_new_cb)

        # Distros might have usb redirection compiled out, like OpenBSD
        # https://bugzilla.redhat.com/show_bug.cgi?id=1348479
        try:
            self._usbdev_manager = SpiceClientGLib.UsbDeviceManager.get(
                                        self._spice_session)
            self._usbdev_manager.connect("auto-connect-failed",
                                        self._usbdev_redirect_error)
            self._usbdev_manager.connect("device-error",
                                        self._usbdev_redirect_error)

            autoredir = self.config.get_auto_usbredir()
            if autoredir:
                gtk_session.set_property("auto-usbredir", True)
        except Exception:
            self._usbdev_manager = None
            logging.debug("Error initializing spice usb device manager",
                exc_info=True)
Example #2
0
    def _create_spice_session(self):
        self._spice_session = SpiceClientGLib.Session()
        SpiceClientGLib.set_session_option(self._spice_session)
        gtk_session = SpiceClientGtk.GtkSession.get(self._spice_session)
        gtk_session.set_property("auto-clipboard", True)

        GObject.GObject.connect(self._spice_session, "channel-new",
                                self._channel_new_cb)

        # Distros might have usb redirection compiled out, like OpenBSD
        # https://bugzilla.redhat.com/show_bug.cgi?id=1348479
        try:
            self._usbdev_manager = SpiceClientGLib.UsbDeviceManager.get(
                                        self._spice_session)
            self._usbdev_manager.connect("auto-connect-failed",
                                        self._usbdev_redirect_error)
            self._usbdev_manager.connect("device-error",
                                        self._usbdev_redirect_error)

            autoredir = self.config.get_auto_redirection()
            if autoredir:
                gtk_session.set_property("auto-usbredir", True)
        except:
            self._usbdev_manager = None
            logging.debug("Error initializing spice usb device manager",
                exc_info=True)
Example #3
0
    def _create_spice_session(self, conf={}):
        assert not self._spice_session
        self._spice_session = SpiceClientGLib.Session(read_only=False, **conf)
        SpiceClientGLib.set_session_option(self._spice_session)

        GObject.GObject.connect(self._spice_session, "channel-new",
                                self._channel_new_cb)
Example #4
0
 def open_fd(self, fd, password=None):
     self.spice_session = SpiceClientGLib.Session()
     if password:
         self.spice_session.set_property("password", password)
     GObject.GObject.connect(self.spice_session, "channel-new",
                             self._channel_new_cb)
     self.spice_session.open_fd(fd)
Example #5
0
 def _tablet_buttons_cb(self, instance, buttons_state):
     # TODO Need to swap middle and right buttons - why?
     buttons_state = (
         buttons_state
         & ~6) | (buttons_state & 2) << 1 | (buttons_state & 4) >> 1
     for button in (MOUSE_LEFT, MOUSE_MIDDLE, MOUSE_RIGHT):
         mask = 1 << (button - 1)
         if (buttons_state
                 & mask) and not (self._tablet_buttons_state & mask):
             SpiceClientGLib.inputs_button_press(self._inputs_channel,
                                                 button, mask)
             self._tablet_buttons_state = self._tablet_buttons_state | mask
         if (self._tablet_buttons_state
                 & mask) and not (buttons_state & mask):
             SpiceClientGLib.inputs_button_release(self._inputs_channel,
                                                   button, mask)
             self._tablet_buttons_state = self._tablet_buttons_state & ~mask
Example #6
0
    def _create_spice_session(self):
        self._spice_session = SpiceClientGLib.Session()
        SpiceClientGLib.set_session_option(self._spice_session)
        gtk_session = SpiceClientGtk.GtkSession.get(self._spice_session)
        gtk_session.set_property("auto-clipboard", True)

        GObject.GObject.connect(self._spice_session, "channel-new",
                                self._channel_new_cb)

        self._usbdev_manager = SpiceClientGLib.UsbDeviceManager.get(
                                    self._spice_session)
        self._usbdev_manager.connect("auto-connect-failed",
                                    self._usbdev_redirect_error)
        self._usbdev_manager.connect("device-error",
                                    self._usbdev_redirect_error)

        autoredir = self.config.get_auto_redirection()
        if autoredir:
            gtk_session.set_property("auto-usbredir", True)
Example #7
0
    def _create_spice_session(self):
        self._spice_session = SpiceClientGLib.Session()
        SpiceClientGLib.set_session_option(self._spice_session)
        gtk_session = SpiceClientGtk.GtkSession.get(self._spice_session)
        gtk_session.set_property("auto-clipboard", True)

        GObject.GObject.connect(self._spice_session, "channel-new",
                                self._channel_new_cb)

        self._usbdev_manager = SpiceClientGLib.UsbDeviceManager.get(
            self._spice_session)
        self._usbdev_manager.connect("auto-connect-failed",
                                     self._usbdev_redirect_error)
        self._usbdev_manager.connect("device-error",
                                     self._usbdev_redirect_error)

        autoredir = self.config.get_auto_redirection()
        if autoredir:
            gtk_session.set_property("auto-usbredir", True)
Example #8
0
 def _tablet_wheel_cb(self, instance, wheel_motion, buttons_state):
     self._tablet_buttons_cb(instance, buttons_state)
     if wheel_motion < 0:
         SpiceClientGLib.inputs_button_press(self._inputs_channel, MOUSE_UP,
                                             self._tablet_buttons_state)
         SpiceClientGLib.inputs_button_release(self._inputs_channel,
                                               MOUSE_UP,
                                               self._tablet_buttons_state)
     if wheel_motion > 0:
         SpiceClientGLib.inputs_button_press(self._inputs_channel,
                                             MOUSE_DOWN,
                                             self._tablet_buttons_state)
         SpiceClientGLib.inputs_button_release(self._inputs_channel,
                                               MOUSE_DOWN,
                                               self._tablet_buttons_state)
Example #9
0
    def open_host(self, ginfo, password=None):
        host, port = ginfo.get_conn_host()

        uri = "spice://"
        uri += str(host) + "?port=" + str(port)
        logging.debug("spice uri: %s", uri)

        self.spice_session = SpiceClientGLib.Session()
        self.spice_session.set_property("uri", uri)
        if password:
            self.spice_session.set_property("password", password)
        GObject.GObject.connect(self.spice_session, "channel-new",
                                self._channel_new_cb)
        self.spice_session.connect()
Example #10
0
    def __init__(self, host, port, listen_port, overlay):
        self._mainloop = GLib.MainLoop()
        self._qxlinstance = None
        self._main_channel = None
        self._display_channel = None
        self._cursor_channel = None
        self._inputs_channel = None
        self._command_queue = Queue()
        self._cursor_set_command = None
        self._tablet_buttons_state = 0
        self._show_overlay = overlay

        # Client

        self._spice_session = SpiceClientGLib.Session(host=host, port=port)
        GObject.GObject.connect(self._spice_session, "channel-new",
                                self._channel_new_cb)
        self._spice_session.connect()

        # Server

        self._spiceserver = SpiceServerGLib.Server(
            noauth=True,
            port=listen_port,
            image_compression=SpiceServerGLib.ImageCompression.OFF,
            jpeg_compression=SpiceServerGLib.WANCompression.NEVER,
            zlib_glz_compression=SpiceServerGLib.WANCompression.NEVER)
        self._spiceserver.init()

        self._keyboardinstance = SpiceServerGLib.KeyboardInstance()
        self._keyboardinstance.connect("push-key", self._keyboard_push_key_cb)
        self._spiceserver.add_interface(self._keyboardinstance)

        self._tabletinstance = SpiceServerGLib.TabletInstance()
        self._tabletinstance.connect("position", self._tablet_position_cb)
        self._tabletinstance.connect("wheel", self._tablet_wheel_cb)
        self._tabletinstance.connect("buttons", self._tablet_buttons_cb)
        self._spiceserver.add_interface(self._tabletinstance)
Example #11
0
 def _tablet_position_cb(self, instance, x, y, buttons_state):
     SpiceClientGLib.inputs_position(self._inputs_channel, x, y, 0,
                                     buttons_state)
Example #12
0
 def _keyboard_push_key_cb(self, instance, key):
     if key & 0x80:
         SpiceClientGLib.inputs_key_release(self._inputs_channel,
                                            key & ~0x80)
     else:
         SpiceClientGLib.inputs_key_press(self._inputs_channel, key)
Example #13
0
                                lambda a, b: opened_event.set())
        char_device_instance.port_event(SpiceServerGLib.PortEvent.OPENED)
        await opened_event.wait()

        # When
        port_channel.write_async(b"efghi", None,
                                 lambda s, r, u: port_channel.write_finish(r),
                                 None)
        await write_event.wait()

        # Then
        self.assertEqual(b"efghi", written_data.get_data())


# XXX Temporary: patch SpiceClientGLib.PortChannel if method-name fix has not been applied
if not hasattr(SpiceClientGLib.PortChannel, "event"):
    SpiceClientGLib.PortChannel.event = lambda self, a: SpiceClientGLib.port_event(
        self, a)
    SpiceClientGLib.PortChannel.write_async = lambda self, a, b, c, d: SpiceClientGLib.port_write_async(
        self, a, b, c, d)
    SpiceClientGLib.PortChannel.write_finish = lambda self, a: SpiceClientGLib.port_write_finish(
        self, a)
if not hasattr(SpiceClientGLib.InputsChannel, "position"):
    SpiceClientGLib.InputsChannel.position = lambda self, a, b, c, d: SpiceClientGLib.inputs_position(
        self, a, b, c, d)
    SpiceClientGLib.InputsChannel.key_press = lambda self, a: SpiceClientGLib.inputs_key_press(
        self, a)

if __name__ == "__main__":
    unittest.main()