LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 02-20-2018, 10:36 AM   #1
shogun1234
Member
 
Registered: May 2004
Posts: 226

Rep: Reputation: 15
Execute disper second time doesn't take effect


I use disper to auto detect the event when my external monitor is plugged again.

The problem is if the command gets executed once it won't take effect at the second time (I believe it's because I don't understand its or its backend xrandr behavior).

For instance,

1. Unplug the external monitor.
2. Plug the external monitor again.
3. Execute `disper -d auto -e` takes effect because the external monitor is back displaying window manager's workspace.
4. Do 1.
5. Do 2.
6. Do 3 again (execute `disper -d auto -e` again), but this time the external monitor stays black without displaying workspace.

If executing command that basically swaps the position of monitors (e.g. first time inner monitor is at left, external monitor is at right; then swap to inner monitor is at right, external monitor is at left) like `disper -e -t left`. Then the monitor would display window manager's workspace without a problem.

My questions - why the command being executed the second doesn't take effect? And more importantly what steps should I follow so that monitors plug/unplug events auto detection can be done without a problem?

Last edited by shogun1234; 02-20-2018 at 10:40 AM.
 
Old 02-20-2018, 09:10 PM   #2
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
I think disper parses a command line for xrandr. After xrandr is run and the monitor is working, and then you unplug it, disper might not undo the xrandr command. So, when you run the program again it's trying to add a mode that's already been added.

OK, usually laptops have a button along the top to toggle between video devices, or ports. gnome-control-center will allow you to configure your displays persistently, so they won't change. When you unplug the ext. monitor, it will shut off the port.

When you plug it back in, use the key on your keyboard to toggle it back on.
 
Old 02-22-2018, 05:34 PM   #3
shogun1234
Member
 
Registered: May 2004
Posts: 226

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by AwesomeMachine View Post
I think disper parses a command line for xrandr. After xrandr is run and the monitor is working, and then you unplug it, disper might not undo the xrandr command. So, when you run the program again it's trying to add a mode that's already been added.

OK, usually laptops have a button along the top to toggle between video devices, or ports. gnome-control-center will allow you to configure your displays persistently, so they won't change. When you unplug the ext. monitor, it will shut off the port.

When you plug it back in, use the key on your keyboard to toggle it back on.
Thanks for the explanation. That helps me a lot! I then switch to run `disper -e` when unplug. Then `disper -e` again once the external monitor is plugged. This solves my problem. The procedure is:
1. write udev rule to detect plug/ unplug event.

Code:
KERNEL=="card?", SUBSYSTEM=="drm", ACTION=="change", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/user/.Xauthority", RUN+="/path/to/disper-script"
2. export X env variable
3. execute disper command with sudo -u <user> <disper command>


Code:
USER=<user-id>
XPID=`pgrep X | head -n 1`
XCOMMANDLINE="ps --no-header -o command $XPID"
export DISPLAY=`$XCOMMANDLINE | sed 's/.\+:/:/;s/ \+.*//'`
export XAUTHORITY=`$XCOMMANDLINE | sed 's/.*-auth *//;s/ \+-.*//'`
sudo -u $USER disper -e

Last edited by shogun1234; 02-22-2018 at 05:37 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] crontab doesn't execute the jobs at the right time shoutr Linux - General 5 02-16-2012 02:23 AM
UDEV takes more time to execute at boot up time.Can anyboby help me to reduce dis tim pabansal Linux - General 3 09-30-2011 06:45 AM
[SOLVED] Effect of using eval to execute a command as opposed to writing it on the commandline daudiam Programming 1 06-20-2010 01:11 AM
How do I adjust the time of my system with daylight saving time in effect? awmian Linux - Newbie 3 09-04-2008 08:57 AM
vimrc doesn't have effect, partially. Why? hottdogg Slackware 11 07-26-2006 03:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 04:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration