Xfce Forum

Sub domains
 

You are not logged in.

#1 2016-03-29 10:54:02

blight
Member
Registered: 2016-03-29
Posts: 6

Disable laptop screen when lid is closed

Hi!

Unable to find this on the forums / wiki / the googels after searching so:

Is there any possible way in XFCE to disable the laptop screen when the lid is closed? When docking my laptop to the docking station (with a closed lid) the external monitor shows up in XFCE and the laptop monitor. This leads to unexpected resolution behaviour and my dock being on the " primary"  screen (which is.. the laptop screen.. which is closed wink)

Does anybody have a workaround / suggestion or could you give me a pointer in the right direction?

Thanks!

OS: Xubuntu 15.10 (Also in 16.10 Beta 2)
XFCE Version: 4.12

Last edited by blight (2016-03-29 10:56:02)

Offline

#2 2016-03-29 15:39:32

sixsixfive
Member
From: behind you
Registered: 2012-04-08
Posts: 579
Website

Re: Disable laptop screen when lid is closed

with a recent power manager release

http://de.zimagez.com/zimage/unbenannt85.php

Offline

#3 2016-03-29 18:57:20

blight
Member
Registered: 2016-03-29
Posts: 6

Re: Disable laptop screen when lid is closed

sixsixfive wrote:

with a recent power manager release

http://de.zimagez.com/zimage/unbenannt85.php

This doesnt seem to be working. When i choose "suspend", "hibernate" or "lock screen" it does. Any way i can debug this?

Offline

#4 2016-03-30 14:23:25

sixsixfive
Member
From: behind you
Registered: 2012-04-08
Posts: 579
Website

Re: Disable laptop screen when lid is closed

xfce4-power-manager --quit;xfce4-power-manager --debug

Offline

#5 2016-03-30 16:17:05

blight
Member
Registered: 2016-03-29
Posts: 6

Re: Disable laptop screen when lid is closed

So i can ran a debug like suggested and although im changing the values nothing happens, it calls a "LID_TRIGGER_NOTHING" event;

Made a screenshot to clarify:

http://i.imgur.com/rLSaBPX.png

Any idea what im overlooking or doing wrong?

Thanks in advance.

Offline

#6 2016-03-30 17:15:18

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,494

Re: Disable laptop screen when lid is closed

"LID_TRIGGER_NOTHING" is an internal variable that basically means "turn the display off". From http://git.xfce.org/xfce/xfce4-power-ma … =xfce-4.12

if ( action == LID_TRIGGER_NOTHING )
	{
	    if ( !xfpm_is_multihead_connected () )
		xfpm_dpms_force_level (manager->priv->dpms, DPMSModeOff);
	}

So basically, "if not multihead", turn dpms off. So what is multihead? From http://git.xfce.org/xfce/xfce4-power-ma … =xfce-4.12:

gboolean xfpm_is_multihead_connected (void)
{
    GdkDisplay *dpy;
    GdkScreen *screen;
    gint nscreen;
    gint nmonitor;
    
    dpy = gdk_display_get_default ();
    
    nscreen = gdk_display_get_n_screens (dpy);
    
    if ( nscreen == 1 )
    {
	    screen = gdk_display_get_screen (dpy, 0);
	    if ( screen )
	    {
	        nmonitor = gdk_screen_get_n_monitors (screen);
	        if ( nmonitor > 1 )
	        {
		        g_debug ("Multiple monitor connected");
		        return TRUE; 
	        }
	        else
		        return FALSE;
	    }
    }
    else if ( nscreen > 1 )
    {
	    g_debug ("Multiple screen connected");
	    return TRUE;
    }
    
    return FALSE;
}

...so more than one monitor.

Therefore, this will only work if you don't have more than 1 monitor.

To confirm:
- Relevant log entries with external monitor connected (screen does not shut off when lid closed):

TRACE[xfpm-manager.c:438] xfpm_manager_lid_changed_cb(): LID close event: ((XfpmLidTriggerAction) LID_TRIGGER_NOTHING)
TRACE[xfpm-manager.c:471] xfpm_manager_lid_changed_cb(): LID opened: ((XfpmLidTriggerAction) LID_TRIGGER_NOTHING)
TRACE[xfpm-dpms.c:284] xfpm_dpms_force_level(): start
TRACE[xfpm-dpms.c:316] xfpm_dpms_force_level(): No need to change DPMS mode, current_level=0 requested_level=0

- Relevant log entries without external monitor connected (screen shuts off when lid closed):

TRACE[xfpm-manager.c:438] xfpm_manager_lid_changed_cb(): LID close event: ((XfpmLidTriggerAction) LID_TRIGGER_NOTHING)
TRACE[xfpm-dpms.c:284] xfpm_dpms_force_level(): start
TRACE[xfpm-dpms.c:303] xfpm_dpms_force_level(): Forcing DPMS mode 3
TRACE[xfpm-manager.c:471] xfpm_manager_lid_changed_cb(): LID opened: ((XfpmLidTriggerAction) LID_TRIGGER_NOTHING)
TRACE[xfpm-dpms.c:284] xfpm_dpms_force_level(): start
TRACE[xfpm-dpms.c:303] xfpm_dpms_force_level(): Forcing DPMS mode 0

Edit: Analysis based on 1.4.4 code base.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#7 2016-03-30 17:24:03

blight
Member
Registered: 2016-03-29
Posts: 6

Re: Disable laptop screen when lid is closed

Wow, thanks for the detailed explanation and clarification.

Im indeed using this in a multi-monitor setup, my laptop in a docking station with a closed lid and a external monitor connected to the HDMI output.

Any chance i can get this working with an external monitor? Or do i need to tinker around with udev + xrandr scripts?

Thanks again.

Offline

#8 2016-03-30 17:25:44

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,494

Re: Disable laptop screen when lid is closed

Or do i need to tinker around with udev + xrandr scripts?

How about something along the lines of https://gist.github.com/seanf/e3be5bf745395d50e975?


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#9 2016-03-31 16:53:20

blight
Member
Registered: 2016-03-29
Posts: 6

Re: Disable laptop screen when lid is closed

ToZ wrote:

Or do i need to tinker around with udev + xrandr scripts?

How about something along the lines of https://gist.github.com/seanf/e3be5bf745395d50e975?

This worked like a charm! Thank you!

Offline

#10 2016-03-31 19:24:44

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,494

Re: Disable laptop screen when lid is closed

Can you post your solution so that its available for others that may be interested? Thanks.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#11 2016-03-31 22:50:38

blight
Member
Registered: 2016-03-29
Posts: 6

Re: Disable laptop screen when lid is closed

Sure.

Currently running an HP Elitebook 850 G2 docked to a HP UltraSlim Docking Station 2013, latest Xubuntu.

I wanted to turn off the laptop display when im docking the laptop with the lid closed. Please keep in mind that this setup assumes you *always* have the LID closed when docking your laptop.

First find out with 'xrandr' what your displays are:

xrandr

In my case 'eDP1' is the internal laptop screen, 'DP2' is the attached monitor.

Also: Unplug ALL devices from the dock EXCEPT the monitor!

1) Dock the laptop and start a terminal, enter the following command;

udevadm monitor --environment --udev

2) Undock the laptop while not closing the terminal, and re-dock the laptop again.

3) In the terminal you'll see alot of addition and removal of USB devices, these USB devices have 'ID_VENDOR_ID' and '
ID_MODEL_ID'. Select one of the devices thats always persisent when docking / undocking.

In my case we'll be using a 'ID_VENDOR_ID' of 0424 and a ID_MODEL_ID of 2134.

4) Create a file (as root) in /etc/udev/rules.d/81-dock.rules

SUBSYSTEM=="usb", ACTION=="add|remove", ENV{ID_VENDOR_ID}=="0424", ENV{ID_MODEL_ID}=="2134", RUN+="/usr/sbin/dockme.sh"

With this UDEV rule im basicalyl telling the kernel interface to run a script whenether the USB device (the docking station) gets removed and/or added.

5) Write out the following script to /usr/sbin/dockme.sh as root and set the execution bit (chmod +x /usr/sbin/dockme.sh)

#!/bin/bash

# Originally from: https://gist.github.com/seanf/e3be5bf745395d50e975
# With thanks to ToZ / XFCE Team

# Save this file as /usr/sbin/dockme.sh

sleep 0.5

# Specify your username here
username=myusername

#export IFS=$"\n"

if [ "$ACTION" = "add" ] ; then
  DOCKED=1
  logger -t DOCKING "Detected condition: docked"
elif [ "$ACTION" = "remove" ]; then
  DOCKED=0
  logger -t DOCKING "Detected condition: un-docked"
else
  logger -t DOCKING "Detected condition: unknown"
  echo Please set env var \$ACTION to 'add' or 'remove'
  exit 1
fi

function switch_to_local {
  export DISPLAY=$1
  logger -t DOCKING "Switching off DP2 and moving to local."
  su $username -c '/usr/bin/xrandr --output DP2 --off --output eDP1 --auto'
}

function switch_to_external {
  export DISPLAY=$1
  logger -t DOCKING "Switching off local and moving to DP2"
  su $username -c '/usr/bin/xrandr --output eDP1  --off --output DP2 --auto'
}

case "$DOCKED" in
  "0")
    #undocked event
    switch_to_local :0 ;;
  "1")
    #docked event
    switch_to_external :0 ;;
esac

6) Reload UDEV Rule:

udevadm control --reload-rules

7) You're all set! Dock / Undock the laptop and you'll should be good to go. Its also safe to attach the extra USB devices at this point.

If for whatever reason something goes wrong just deleted out the 2 files we created. If you get a blank screen because something went  wrong you can always to press 'ALT+F2' (run command) followed by:

xrandr --output eDP1 --auto <enter>

Which should restore screen to your laptop.

If you have any questions and/or remarks let me know.

Offline

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.011 seconds, 7 queries executed - Memory usage: 588.17 KiB (Peak: 605.02 KiB) ]