martin-ueding / thinkpad-scripts

Screen rotation, docking and other scripts for ThinkPad® X220 and X230 Tablet
Other
133 stars 23 forks source link

ThinkPad X220(T) never docked with "Series 3" Docking Station #129

Closed dnisyd closed 7 years ago

dnisyd commented 7 years ago

This drove me nuts: It seems like newer docks don't really dock. Cat /sys/devices/platform/dock.*/docked always results in 0 whether docked or not. Which means that the thinkpad-dock-hook will never work. You check this here: thinkpad-scripts/tps/dock.py

def is_docked():
    '''
    Determines whether the laptop is on a docking station.
    This checks for ``/sys/devices/platform/dock.*/docked``.
    :returns: True if laptop is docked
    :rtype: bool
    '''
    dockfiles = glob.glob('/sys/devices/platform/dock.*/docked')
    for dockfile in dockfiles:
        with open(dockfile) as handle:
            contents = handle.read()
            dock_state = int(contents) == 1
            if dock_state:
                logger.info('Docking station found.')
                return True
    logger.info('No docking station found.')
return False

I found some information on this over here "tlp-rdw doesn't recognize newer docks #56" and here are some notes about different event IDs "Thinkpad "Series 3" Docking Station on Linux" Maybe you have an idea to find a way around this.

martin-ueding commented 7 years ago

You can always call thinkpad-dock on to force docking. I have just checked on my X220, there is dock.2 which is docked.

We could try to use a different device that is plugged in only with your dock as an indicator for the dock. For my computer, I could use the particular USB keyboard I have at home. If that can be found, then it must be on the docking station (except when I take the keyboard with me).

Perhaps that would be something that we should implement? A searching for a device as a substitute for the is_docked() check? If so, what would be something that would be useful in your case?

dnisyd commented 7 years ago

Yeah right now I am using thinkpad-dock on|off, would be nicer if it works automatic.

Actually that would be a good idea because the Lenovo "ThinkPad Mini Dock Plus Series 3" is recognized under lsusb and also tlp stat: Bus 001 Device 015: ID 17ef:100a Lenovo ThinkPad Mini Dock Plus Series 3 if my X220T is docked.

martin-ueding commented 7 years ago

I think what we could do is to add a configuration option where you would specify the USB ID (17ef:100a in your case). In case that option is present in the configuration, the is_docked() test will query lsusb for that number, otherwise use the current behavior.

Would everyone be happy with that?

dnisyd commented 7 years ago

Sounds like a solid plan which should work. I'd gladly test it out.

martin-ueding commented 7 years ago

This is now added in the branch feature/alt-dock-criterion. It seems to work on my machine. There is new documentation for this feature.

Please try out the branch, and then I can merge it.

dnisyd commented 7 years ago

Alright, I am not sure I am doing this right so let me explain what I did. I uninstalled the thinkpad-scripts I installed via your apt repository (I am running Ubuntu 16.04). I cloned your feature/alt-dock-criterion branch via git and followed your install guide. Everything works the same as before. Now I have this in my .config/thinkpad-scripts/config.ini:

[sound]
dock_loudness = 100%
undock_loudness = 0%

[network]
disable_wifi = true

[dock]
lsusb_indicator_regex = 17ef:100a

[screen]
brightness = 40%
primary = LVDS1
secondary = HDMI3
relative_position = left-of

[trigger]
enable_dock = true
enable_rotate = true

[rotate]
default_rotation = flip
xrandr_bug_workaround = true

And this is the dock in lsusb: Bus 001 Device 025: ID 17ef:100a Lenovo ThinkPad Mini Dock Plus Series 3

Using thinkpad-dock on|off works fine when docked. But it still does not automatically switch between on|off if I manually dock|undock my ThinkPad. Did I do anything wrong and what other information can I provide?

martin-ueding commented 7 years ago

The installation sounds correct. Try running thinkpad-dock -vv while the dock is plugged in. There should be a debug message saying what method is used for the dock detection. On my system (with the default configuration file), I get the following off-dock:

__main__      DEBUG    Using sysfs to determine docking status.
__main__      INFO     No docking station found.

Since you have the option enabled, there should be some different message. If it is not there, then something is not correct. If there is the sysfs message, then the configuration is probably not picked up correctly.

dnisyd commented 7 years ago

thinkpad-dock -vv while docked outputs the following:

tps.config    DEBUG    ----------------------------------
tps.config    DEBUG    Program was started with arguments: ['/usr/local/bin/thinkpad-dock', '-vv']
tps.config    DEBUG    Default configfile is /home/dantempla/.python-eggs/thinkpad_scripts-4.8.1-py3.5.egg-tmp/tps/default.ini.
tps.dock      DEBUG    Using lsusb to determine docking status.
tps.dock      DEBUG    subprocess “lsusb”
tps.dock      INFO     Desired is True
tps.dock      INFO     dock(True)
tps           DEBUG    Command “/home/dantempla/.config/thinkpad-scripts/hooks/predock” not found.
tps           DEBUG    Command “pactl” found.
tps.sound     DEBUG    subprocess “pactl list sinks”
tps.sound     DEBUG    subprocess “pactl set-sink-mute 2 0”
tps           DEBUG    Command “pactl” found.
tps.sound     DEBUG    subprocess “pactl list sinks”
tps.sound     DEBUG    subprocess “pactl set-sink-volume 2 100%”
tps           DEBUG    Command “xbacklight” found.
tps.screen    DEBUG    subprocess “xbacklight -set 40%”
tps.screen    DEBUG    subprocess “xrandr”
tps.screen    DEBUG    Screens available on this system are HDMI3, LVDS1.
tps.screen    DEBUG    Internal screen is determined to be LVDS1.
tps.dock      DEBUG    select_docking_screens(internal=LVDS1, primary=LVDS1, secondary=HDMI3)
tps.screen    DEBUG    subprocess “xrandr”
tps.dock      DEBUG    primary: LVDS1, secondary: HDMI3, others: []
tps.screen    DEBUG    subprocess “xrandr --output HDMI3 --auto”
tps.screen    DEBUG    subprocess “xrandr --output LVDS1 --auto”
tps.screen    DEBUG    subprocess “xrandr --output LVDS1 --auto --left-of HDMI3 --primary”
tps           DEBUG    Command “nmcli” found.
tps           DEBUG    Command “nmcli” found.
tps.network   DEBUG    subprocess “nmcli --version”
tps.network   DEBUG    subprocess “nmcli radio wifi off”
tps           DEBUG    Command “nmcli” found.
tps           DEBUG    Command “nmcli” found.
tps.network   DEBUG    subprocess “nmcli --version”
tps.network   DEBUG    subprocess “nmcli --terse --fields NAME,TYPE con show”
tps           DEBUG    Command “nmcli” found.
tps.network   DEBUG    subprocess “nmcli con up id 'Kabelnetzwerkverbindung 1'”
Verbindung wurde erfolgreich aktiviert (aktiver D-Bus-Pfad: /org/freedesktop/NetworkManager/ActiveConnection/1)
tps.screen    DEBUG    subprocess “xrandr -q --verbose”
tps           DEBUG    Converted “normal” to “Direction(xrandr='normal', xsetwacom='none', subpixel='rgb', physically_closed=False, rot_mat=[1, 0, 0, 0, 1, 0, 0, 0, 1])”.
tps.screen    INFO     Current rotation is “Direction(xrandr='normal', xsetwacom='none', subpixel='rgb', physically_closed=False, rot_mat=[1, 0, 0, 0, 1, 0, 0, 0, 1])”.
tps.screen    DEBUG    subprocess “xrandr -q”
tps.input     DEBUG    Translation and scaling matrix: [[  0.41570   0.00000   0.00000 ][  0.00000   0.64000   0.00000 ][  0.00000   0.00000   1.00000 ]]
tps.input     DEBUG    Complete transformation matrix: [[  0.41570   0.00000   0.00000 ][  0.00000   0.64000   0.00000 ][  0.00000   0.00000   1.00000 ]]
tps.config    DEBUG    Default configfile is /home/dantempla/.python-eggs/thinkpad_scripts-4.8.1-py3.5.egg-tmp/tps/default.ini.
tps.input     DEBUG    Using “Wacom ISD.*id=(\d+)” as regex to find Wacom devices.
tps.input     DEBUG    subprocess “xinput”
tps.input     INFO     Mapping and rotating all input devices.
tps.input     DEBUG    subprocess “xinput --list-props 9”
tps.input     DEBUG    Device 9 has property “Wacom Rotation”
tps.input     INFO     Device 9 has “Wacom Rotation” property, use xsetwacom.
tps.input     DEBUG    subprocess “xsetwacom set 9 rotate none”
tps.input     DEBUG    subprocess “xsetwacom set 9 MapToOutput LVDS1”
tps.input     DEBUG    subprocess “xinput --list-props 14”
tps.input     DEBUG    Device 14 has property “Wacom Rotation”
tps.input     INFO     Device 14 has “Wacom Rotation” property, use xsetwacom.
tps.input     DEBUG    subprocess “xsetwacom set 14 rotate none”
tps.input     DEBUG    subprocess “xsetwacom set 14 MapToOutput LVDS1”
tps.input     DEBUG    subprocess “xinput --list-props 10”
tps.input     DEBUG    Device 10 has property “Wacom Rotation”
tps.input     INFO     Device 10 has “Wacom Rotation” property, use xsetwacom.
tps.input     DEBUG    subprocess “xsetwacom set 10 rotate none”
tps.input     DEBUG    subprocess “xsetwacom set 10 MapToOutput LVDS1”
tps           DEBUG    Command “/home/dantempla/.config/thinkpad-scripts/hooks/postdock” not found.
martin-ueding commented 7 years ago

That seems to be working well:

tps.dock      DEBUG    Using lsusb to determine docking status.
tps.dock      DEBUG    subprocess “lsusb”
tps.dock      INFO     Desired is True
tps.dock      INFO     dock(True)

The lsusb method is used and it determined that you want to dock on. It could be that either the dock hook does not work because we do not have an udev rule/hook for that, or because that only works well with the package version.

I will then release this branch and package the software for Ubuntu 16.04. For that I should have a VM flying around.

dnisyd commented 7 years ago

Okay, if there is anything I can help with or should try out; Feel free to tell me.

martin-ueding commented 7 years ago

The package is currently building, unless it fails you should be able to install that within a couple of hours.

If the dock hook still does not work, please open a new issue for that. Then we need to talk about the hardware and find out what kind of hooks are needed. You could start with Find hardware events and write what output you get there.