def is_has_touchpad():
    devices = gdk.devices_list()
    for d in devices:
        name = d.get_name().lower()
        if "touchpad" in name:
            return True
    return False
def is_has_touchpad():
    devices = gdk.devices_list()
    for d in devices:
        name = d.get_name().lower()
        if "touchpad" in name:
            return True
    return False
示例#3
0
    def update_input_devices(self):
        # avoid doing this 5 times at startup
        modesetting = self.preferences['input.device_mode']
        if getattr(self, 'last_modesetting', None) == modesetting:
            return
        self.last_modesetting = modesetting

        # init extended input devices
        self.pressure_devices = []

        if pygtkcompat.USE_GTK3:
            display = pygtkcompat.gdk.display_get_default()
            device_mgr = display.get_device_manager()
            for device in device_mgr.list_devices(gdk.DeviceType.SLAVE):
                if device.get_source() == gdk.InputSource.KEYBOARD:
                    continue
                name = device.get_name().lower()
                n_axes = device.get_n_axes()
                if n_axes <= 0:
                    continue
                # TODO: may need exception voodoo, min/max checking etc. here
                #       like the GTK2 code below.
                for i in xrange(n_axes):
                    use = device.get_axis_use(i)
                    if use != gdk.AxisUse.PRESSURE:
                        continue
                    # Set preferred device mode
                    mode = getattr(gdk.InputMode, modesetting.upper())
                    if device.get_mode() != mode:
                        print 'Setting %s mode for "%s"' \
                          % (mode, device.get_name())
                        device.set_mode(mode)
                    # Record as a pressure-sensitive device
                    self.pressure_devices.append(name)
                    break
            return

        # GTK2/PyGTK
        print 'Looking for GTK devices with pressure:'
        for device in gdk.devices_list():
            #print device.name, device.source

            #if device.source in [gdk.SOURCE_PEN, gdk.SOURCE_ERASER]:
            # The above contition is True sometimes for a normal USB
            # Mouse. https://gna.org/bugs/?11215
            # In fact, GTK also just guesses this value from device.name.

            #print 'Device "%s" (%s) reports %d axes.' % (device.name, device.source.value_name, len(device.axes))

            pressure = False
            for use, val_min, val_max in device.axes:
                if use == gdk.AXIS_PRESSURE:
                    print 'Device "%s" has a pressure axis' % device.name
                    # Some mice have a third "pressure" axis, but without minimum or maximum.
                    if val_min == val_max:
                        print 'But the pressure range is invalid'
                    else:
                        pressure = True
                    break
            if not pressure:
                #print 'Skipping device "%s" because it has no pressure axis' % device.name
                continue

            name = device.name.lower()
            name = name.replace('-', ' ').replace('_', ' ')
            last_word = name.split()[-1]

            # Step 1: BLACKLIST
            if last_word == 'pad':
                # Setting the intuos3 pad into "screen mode" causes
                # glitches when you press a pad-button in mid-stroke,
                # and it's not a pointer device anyway. But it reports
                # axes almost identical to the pen and eraser.
                #
                # device.name is usually something like "wacom intuos3 6x8 pad" or just "pad"
                print 'Skipping "%s" (probably wacom keypad device)' % device.name
                continue
            if last_word == 'touchpad':
                print 'Skipping "%s" (probably a laptop touchpad without pressure info)' % device.name
                continue
            if last_word == 'cursor':
                # for wacom, this is the "normal" mouse and does not work in screen mode
                print 'Skipping "%s" (probably wacom mouse device)' % device.name
                continue
            if 'keyboard' in name:
                print 'Skipping "%s" (probably a keyboard)' % device.name
                continue
            if 'mouse' in name and 'mousepen' not in name:
                print 'Skipping "%s" (probably a mouse)' % device.name
                continue

            # Step 2: WHITELIST
            #
            # Required now as too many input devices report a pressure
            # axis with recent Xorg versions. Wrongly enabling them
            # breaks keyboard and/or mouse input in random ways.
            #
            tablet_strings  = '''
            tablet pressure graphic stylus eraser pencil brush
            wacom bamboo intuos graphire cintiq
            hanvon rollick graphicpal artmaster sentip
            genius mousepen
            aiptek
            touchcontroller
            '''
            match = False
            for s in tablet_strings.split():
                if s in name:
                    match = True

            words = name.split()
            if 'pen' in words or 'art' in words:
                match = True
            if 'uc logic' in name:
                match = True

            if not match:
                print 'Skipping "%s" (not in the list of known tablets)' % device.name
                continue

            self.pressure_devices.append(device.name)
            mode = getattr(gdk, 'MODE_' + modesetting.upper())
            if device.mode != mode:
                print 'Setting %s mode for "%s"' % (modesetting, device.name)
                device.set_mode(mode)
        print ''
示例#4
0
    def update_input_devices(self):
        # avoid doing this 5 times at startup
        modesetting = self.preferences['input.device_mode']
        if getattr(self, 'last_modesetting', None) == modesetting:
            return
        self.last_modesetting = modesetting

        # init extended input devices
        self.pressure_devices = []

        logger.info('Looking for GTK devices with pressure')
        display = gtk2compat.gdk.display_get_default()
        device_mgr = display.get_device_manager()
        for device in device_mgr.list_devices(gdk.DeviceType.SLAVE):
            if device.get_source() == gdk.InputSource.KEYBOARD:
                continue
            name = device.get_name().lower()
            n_axes = device.get_n_axes()
            if n_axes <= 0:
                continue
            # TODO: may need exception voodoo, min/max checking etc. here
            #       like the GTK2 code below.
            for i in xrange(n_axes):
                use = device.get_axis_use(i)
                if use != gdk.AxisUse.PRESSURE:
                    continue
                # Set preferred device mode
                mode = getattr(gdk.InputMode, modesetting.upper())
                if device.get_mode() != mode:
                    logger.info('Setting %s mode for %r', mode.value_name,
                                device.get_name())
                    device.set_mode(mode)
                # Record as a pressure-sensitive device
                self.pressure_devices.append(name)
                break
        return

        # GTK2/PyGTK (unused, but consider porting fully to GTK3)
        for device in gdk.devices_list():
            #print device.name, device.source

            #if device.source in [gdk.SOURCE_PEN, gdk.SOURCE_ERASER]:
            # The above contition is True sometimes for a normal USB
            # Mouse. https://gna.org/bugs/?11215
            # In fact, GTK also just guesses this value from device.name.

            #print 'Device "%s" (%s) reports %d axes.' % (device.name, device.source.value_name, len(device.axes))

            pressure = False
            for use, val_min, val_max in device.axes:
                if use == gdk.AXIS_PRESSURE:
                    print 'Device "%s" has a pressure axis' % device.name
                    # Some mice have a third "pressure" axis, but without minimum or maximum.
                    if val_min == val_max:
                        print 'But the pressure range is invalid'
                    else:
                        pressure = True
                    break
            if not pressure:
                #print 'Skipping device "%s" because it has no pressure axis' % device.name
                continue

            name = device.name.lower()
            name = name.replace('-', ' ').replace('_', ' ')
            last_word = name.split()[-1]

            # Step 1: BLACKLIST
            if last_word == 'pad':
                # Setting the intuos3 pad into "screen mode" causes
                # glitches when you press a pad-button in mid-stroke,
                # and it's not a pointer device anyway. But it reports
                # axes almost identical to the pen and eraser.
                #
                # device.name is usually something like "wacom intuos3 6x8 pad" or just "pad"
                print 'Skipping "%s" (probably wacom keypad device)' % device.name
                continue
            if last_word == 'touchpad':
                print 'Skipping "%s" (probably a laptop touchpad without pressure info)' % device.name
                continue
            if last_word == 'cursor':
                # for wacom, this is the "normal" mouse and does not work in screen mode
                print 'Skipping "%s" (probably wacom mouse device)' % device.name
                continue
            if 'keyboard' in name:
                print 'Skipping "%s" (probably a keyboard)' % device.name
                continue
            if 'mouse' in name and 'mousepen' not in name:
                print 'Skipping "%s" (probably a mouse)' % device.name
                continue

            # Step 2: WHITELIST
            #
            # Required now as too many input devices report a pressure
            # axis with recent Xorg versions. Wrongly enabling them
            # breaks keyboard and/or mouse input in random ways.
            #
            tablet_strings = '''
            tablet pressure graphic stylus eraser pencil brush
            wacom bamboo intuos graphire cintiq
            hanvon rollick graphicpal artmaster sentip
            genius mousepen
            aiptek
            touchcontroller
            '''
            match = False
            for s in tablet_strings.split():
                if s in name:
                    match = True

            words = name.split()
            if 'pen' in words or 'art' in words:
                match = True
            if 'uc logic' in name:
                match = True

            if not match:
                print 'Skipping "%s" (not in the list of known tablets)' % device.name
                continue

            self.pressure_devices.append(device.name)
            mode = getattr(gdk, 'MODE_' + modesetting.upper())
            if device.mode != mode:
                print 'Setting %s mode for "%s"' % (modesetting, device.name)
                device.set_mode(mode)
        print ''