Beispiel #1
0
        def write(self, device, data_bytes):
            def handler(device, n):
                """Called on notification events from the mouse."""
                if n.sub_id < 0x40 and device.features[
                        n.sub_id] == _F.REPROG_CONTROLS_V4:
                    state = device._slidingDpiState
                    if n.address == 0x00:
                        cid1, cid2, cid3, cid4 = _unpack('!HHHH', n.data[:8])
                        state.handle_keys_event({cid1, cid2, cid3, cid4})
                    elif n.address == 0x10:
                        dx, dy = _unpack('!hh', n.data[:4])
                        state.handle_move_event(dx, dy)

            key = _bytes2int(data_bytes)
            if key:  # Enable DPI sliding
                # Enable HID++ events on sliding the mouse while DPI button held
                self.key = next((k for k in device.keys if k.key == key), None)
                if self.key:
                    self.key.set_rawXY_reporting(True)
                    divertSetting = next(
                        filter(lambda s: s.name == _DIVERT_KEYS[0],
                               device.settings), None)
                    divertSetting.write_key_value(int(self.key.key), 1)
                    from solaar.ui import status_changed as _status_changed
                    _status_changed(device, refresh=True)  # update main window
                    # Store our variables in the device object
                    dpiSetting = next(
                        filter(lambda s: s.name == _DPI[0], device.settings),
                        None)
                    device._slidingDpiState = self.MxVerticalDpiState(
                        device, dpiSetting, self.key.key)
                    device.add_notification_handler('mx-vertical-dpi-handler',
                                                    handler)
                    return True
                else:
                    _log.error('cannot enable DPI sliding on %s for key %s',
                               device, key)
            else:  # Disable DPI sliding
                if self.key:
                    self.key.set_rawXY_reporting(False)
                    divertSetting = next(
                        filter(lambda s: s.name == _DIVERT_KEYS[0],
                               device.settings), None)
                    divertSetting.write_key_value(int(self.key.key), 0)
                    from solaar.ui import status_changed as _status_changed
                    _status_changed(device, refresh=True)  # update main window
                try:
                    device.remove_notification_handler(
                        'mx-vertical-dpi-handler')
                except Exception:
                    if _log.isEnabledFor(_WARNING):
                        _log.warn('cannot disable DPI sliding on %s', device)
                if hasattr(device, '_slidingDpiState'):
                    del device._slidingDpiState
            return True
Beispiel #2
0
    def write(self, device, data_bytes):
        def handler(device, n):
            """Called on notification events from the mouse."""
            if n.sub_id < 0x40 and device.features[
                    n.sub_id] == _hidpp20.FEATURE.REPROG_CONTROLS_V4:
                state = device._divertedMMState
                if n.address == 0x00:
                    cid1, cid2, cid3, cid4 = _unpack('!HHHH', n.data[:8])
                    state.handle_keys_event({cid1, cid2, cid3, cid4})
                elif n.address == 0x10:
                    dx, dy = _unpack('!hh', n.data[:4])
                    state.handle_move_event(dx, dy)

        key = _bytes2int(data_bytes)
        if key:  # enable
            # Enable HID++ events on moving the mouse while button held
            self.key = next((k for k in device.keys if k.key == key), None)
            if self.key:
                self.key.set_rawXY_reporting(True)
                divertSetting = next(
                    filter(lambda s: s.name == self.divert_name,
                           device.settings), None)
                divertSetting.write_key_value(int(self.key.key), 1)
                from solaar.ui import status_changed as _status_changed
                _status_changed(device, refresh=True)  # update main window
                # Store our variables in the device object
                device._divertedMMState = DivertedMouseMovement(
                    device, self.dpi_name, self.key.key)
                device.add_notification_handler(
                    'diverted-mouse-movement-handler', handler)
                return True
            else:
                _log.error(
                    'cannot enable diverted mouse movement on %s for key %s',
                    device.name, key)
        else:  # disable
            if self.key:
                self.key.set_rawXY_reporting(False)
                divertSetting = next(
                    filter(lambda s: s.name == self.divert_name,
                           device.settings), None)
                divertSetting.write_key_value(int(self.key.key), 0)
                from solaar.ui import status_changed as _status_changed
                _status_changed(device, refresh=True)  # update main window
                self.key = None
            try:
                device.remove_notification_handler(
                    'diverted-mouse-movement-handler')
            except Exception:
                pass
            if hasattr(device, '_divertedMMState'):
                del device._divertedMMState
        return True
Beispiel #3
0
    def write(self, device, data_bytes):
        def handler(device, n):  # Called on notification events from the device
            if n.sub_id < 0x40 and device.features[n.sub_id] == _hidpp20.FEATURE.REPROG_CONTROLS_V4:
                if n.address == 0x00:
                    cids = _unpack('!HHHH', n.data[:8])
                    if not self.pressed and int(self.key.key) in cids:  # trigger key pressed
                        self.pressed = True
                        self.press_action()
                    elif self.pressed:
                        if int(self.key.key) not in cids:  # trigger key released
                            self.pressed = False
                            self.release_action()
                        else:
                            for key in cids:
                                if key and not key == self.key.key:  # some other diverted key pressed
                                    self.key_action(key)
                elif n.address == 0x10:
                    if self.pressed:
                        dx, dy = _unpack('!hh', n.data[:4])
                        self.move_action(dx, dy)

        divertSetting = next(filter(lambda s: s.name == self.divert_setting_name, device.settings), None)
        self.device = device
        key = _bytes2int(data_bytes)
        if key:  # Enable
            self.key = next((k for k in device.keys if k.key == key), None)
            if self.key:
                self.active = True
                divertSetting.write_key_value(int(self.key.key), 1)
                device.add_notification_handler(self.name, handler)
                from solaar.ui import status_changed as _status_changed
                self.activate_action()
                _status_changed(device, refresh=True)  # update main window
            else:
                _log.error('cannot enable %s on %s for key %s', self.name, device, key)
        else:  # Disable
            if self.active:
                self.active = False
                divertSetting.write_key_value(int(self.key.key), 0)
                from solaar.ui import status_changed as _status_changed
                _status_changed(device, refresh=True)  # update main window
                try:
                    device.remove_notification_handler(self.name)
                except Exception:
                    if _log.isEnabledFor(_WARNING):
                        _log.warn('cannot disable %s on %s', self.name, device)
                self.deactivate_action()
        return True
 def setNewDpi(self, newDpiIdx):
     newDpi = self.dpiChoices[newDpiIdx]
     self.dpiSetting.write(newDpi)
     from solaar.ui import status_changed as _status_changed
     _status_changed(self.device,
                     refresh=True)  # update main window