How to dock laptop more easily

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

How to dock laptop more easily

Joe Nelson
I'd like to write a daemon to change machdep.lidaction and the xrandr output as
an external monitor or power is attached/detached from my laptop. Is there a
way to detect those events from a C program?

Here is how I want the sleep state and output display to change based on
whether power is connected, an external monitor is attached, and the laptop is
open:

Power    Mon      Open    | Sleep    Display
--------------------------+------------------
x        x        x       | awake    both
x        x                | awake    external
x                 x       | awake    laptop
x                         | asleep
         x        x       | awake    both
         x                | asleep
                  x       | awake    laptop
                          | asleep

--
Joe Nelson      https://begriffs.com

Reply | Threaded
Open this post in threaded view
|

Re: How to dock laptop more easily

Theo de Raadt-2
Half the details you require are in sysctl output, and the other will
require you to figure out how xrandr learns.


Joe Nelson <[hidden email]> wrote:

> I'd like to write a daemon to change machdep.lidaction and the xrandr output as
> an external monitor or power is attached/detached from my laptop. Is there a
> way to detect those events from a C program?
>
> Here is how I want the sleep state and output display to change based on
> whether power is connected, an external monitor is attached, and the laptop is
> open:
>
> Power    Mon      Open    | Sleep    Display
> --------------------------+------------------
> x        x        x       | awake    both
> x        x                | awake    external
> x                 x       | awake    laptop
> x                         | asleep
>          x        x       | awake    both
>          x                | asleep
>                   x       | awake    laptop
>                           | asleep
>
> --
> Joe Nelson      https://begriffs.com
>

Reply | Threaded
Open this post in threaded view
|

Re: How to dock laptop more easily

Marcus MERIGHI
In reply to this post by Joe Nelson
[hidden email] (Joe Nelson), 2019.10.14 (Mon) 04:32 (CEST):
> I'd like to write a daemon to change machdep.lidaction and the xrandr output as
> an external monitor or power is attached/detached from my laptop. Is there a
> way to detect those events from a C program?
 
x-on-resize[1] might help with detecting plug/unplug events of external
monitors.

[1]
https://keithp.com/blogs/x-on-resize/
git://people.freedesktop.org/~keithp/x-on-resize
https://github.com/thedward/x-on-resize
https://marc.info/?l=openbsd-misc&m=148839239518671

Marcus

> Here is how I want the sleep state and output display to change based on
> whether power is connected, an external monitor is attached, and the laptop is
> open:
>
> Power    Mon      Open    | Sleep    Display
> --------------------------+------------------
> x        x        x       | awake    both
> x        x                | awake    external
> x                 x       | awake    laptop
> x                         | asleep
>          x        x       | awake    both
>          x                | asleep
>                   x       | awake    laptop
>                           | asleep
>
> --
> Joe Nelson      https://begriffs.com
>

Reply | Threaded
Open this post in threaded view
|

Re: How to dock laptop more easily

tom ryan
On 2019-10-14 19:33, Marcus MERIGHI wrote:

> [hidden email] (Joe Nelson), 2019.10.14 (Mon) 04:32 (CEST):
>> I'd like to write a daemon to change machdep.lidaction and the xrandr output as
>> an external monitor or power is attached/detached from my laptop. Is there a
>> way to detect those events from a C program?
>  
> x-on-resize[1] might help with detecting plug/unplug events of external
> monitors.
>
> [1]
> https://keithp.com/blogs/x-on-resize/
> git://people.freedesktop.org/~keithp/x-on-resize
> https://github.com/thedward/x-on-resize
> https://marc.info/?l=openbsd-misc&m=148839239518671

I was about to mention x-on-resize. I use it to invoke autorandr.

https://pypi.org/project/autorandr/

And for power there's already sensorsd

    $ sysctl hw.sensors.acpibat0.raw0
    hw.sensors.acpibat0.raw0=1 (battery discharging), OK

Not sure how you will transition from this state:

>> Power    Mon      Open    | Sleep    Display
>> --------------------------+------------------
>>          x                | asleep

to this one:

>> x        x                | awake    external

I.e. wake up from standby when power is applied, without opening the
laptop - machdep.lidaction won't help with that.

t

> Marcus
>
>> Here is how I want the sleep state and output display to change based on
>> whether power is connected, an external monitor is attached, and the laptop is
>> open:
>>
>> Power    Mon      Open    | Sleep    Display
>> --------------------------+------------------
>> x        x        x       | awake    both
>> x        x                | awake    external
>> x                 x       | awake    laptop
>> x                         | asleep
>>          x        x       | awake    both
>>          x                | asleep
>>                   x       | awake    laptop
>>                           | asleep
>>
>> --
>> Joe Nelson      https://begriffs.com
>>
>