News for hackers. Stuff that matters.
Re:Show HN: Change screen layout when connecting/disconnecti... by raphman_ on Tuesday April 26, 2016 @09:36AM (#11571704)
For reference, there's also autorandr [1] and x-on-resize [2].

[1] https://github.com/wertarbyte/autorandr

[2] http://keithp.com/blogs/x-on-resize/

Re:Show HN: Change screen layout when connecting/disconnecti... by wlk on Tuesday April 26, 2016 @12:20PM (#11573162)
This is a good documentation for autorandr: https://help.ubuntu.com/community/DynamicMultiMonitor
Re:Show HN: Change screen layout when connecting/disconnecti... by qwertymaster on Tuesday April 26, 2016 @11:21AM (#11572598)
I am not sure if I just overlooked something, but autorandr doesn't seem to stay in the background and wait for a change but needs to be called manually, is that correct? While saving profiles can be useful if you do that a lot, that task is easily solved by writing the xrandr command used into a shellscript.

x-on-resize looks like a good alternative to xoutputd though. It's probably worth to take a closer look at it and use the one whose code is simpler and easier to read.

Re:Show HN: Change screen layout when connecting/disconnecti... by jlpc on Tuesday April 26, 2016 @04:30PM (#11575359)
Thank you for those links, I actually tried to find something like this before implementing my own solution. I guess I didn't search enough.
Re:Show HN: Change screen layout when connecting/disconnecti... by larkery on Tuesday April 26, 2016 @09:35AM (#11571694)
I have a little python script to do a similar thing:

https://github.com/larkery/nix-session/blob/master/scripts/d...

This remembers the randr state that's associated with plugged in displays by their EDID and the ACPI lid switch. When you change the randr state, it remembers it, and when you change what displays are connected or open the laptop lid, it loads a previously remembered state if there is one. The state saving and loading is done by arandr, which handles the resolution, position, and choice of primary output.

Re:Show HN: Change screen layout when connecting/disconnecti... by betimsl on Tuesday April 26, 2016 @09:53AM (#11571823)
I used a bash script to do this, until I got a laptop that has only a mini-display port. Now I don't/can't connect to anything :(
Re:Show HN: Change screen layout when connecting/disconnecti... by qwertymaster on Tuesday April 26, 2016 @10:03AM (#11571925)
Why? you would've needed a cable anyway, so not owning the right one is no excuse, (m)DP can connect to pretty much anything using cheap _passive_ adapter cables.
Re:Show HN: Change screen layout when connecting/disconnecti... by qwertymaster on Tuesday April 26, 2016 @10:00AM (#11571887)
This is exactly what I needed, gonna put it in my window manager startup script. I already wrote a dock and undock script for my laptop a while ago, which I still had to run manually, so this is the perfect addition to that script. Though I had some problems compiling it. For others who want to try it: On some systems (gentoo here) flex replaces lex and you need to use -lfl to link it, even though lex seems to be ususally a symlink to flex, there is no symlink for the libraries. Also on some distributions yacc doesn't seem to come with liby anymore, just remove the -ly from cflags.

TL;DR: Replace "LDADD+= -ll -ly -lX11 -lXrandr" with "LDADD+= -lfl -lX11 -lXrandr" to make it compile on Gentoo. Make sure yacc and flex are emerged.

Re:Show HN: Change screen layout when connecting/disconnecti... by jlpc on Tuesday April 26, 2016 @05:18PM (#11575725)
Thank you for your comment, I tested on Debian jessie, and OpenBSD only. I will try to make the build more compatible to other distro/OS.
Re:Show HN: Change screen layout when connecting/disconnecti... by paol on Tuesday April 26, 2016 @08:33AM (#11571273)
May I ask what desktop environment you use, and what you usually use this for?

I ask because a good DE should remember the settings pertaining to each monitor configuration (display positions of course, but also things like panels placed in secondary monitors). I've been using Plasma (KDE) for about a year and it handles this reasonably well.

Re:Show HN: Change screen layout when connecting/disconnecti... by mbrock on Tuesday April 26, 2016 @08:39AM (#11571304)
Lots of people don't use any "desktop environment." I just use ratpoison, for example.
Re:Show HN: Change screen layout when connecting/disconnecti... by paol on Tuesday April 26, 2016 @08:51AM (#11571369)
Well, call it a "window manager" then, it still should handle this. But that's just my opinion of the responsibilities of WMs/DEs/whatever you call them, and I understand that some don't.
Re:Show HN: Change screen layout when connecting/disconnecti... by creshal on Tuesday April 26, 2016 @08:58AM (#11571411)
No, handling screen layout isn't the window manager's responsibility. That's what external tools like xrandr and its various GUIs are for.
Re:Show HN: Change screen layout when connecting/disconnecti... by jlpc on Tuesday April 26, 2016 @04:48PM (#11575489)
I use dwm on my laptop, and I have 2 external monitors.

Every morning I had to make an xrandr call when I plugged them, and another one at the end of the day when I unplugged them to make my window manager aware of my screen layout.

I was tired so I automated the thing.

Re:Show HN: Change screen layout when connecting/disconnecti... by kingosticks on Tuesday April 26, 2016 @08:56AM (#11571394)
I agree that good software should do this but unfortunately multi-monitor configuration software isn't always very good. My Ubuntu 15.10 system with Unity desktop decides to move the taskbar/dock thing to the other monitor every time I turn the other monitor on in the morning. There is nothing in the Screen Display GUI that seems to allow me to stop this from happening. Out of frustration I've resorted to running the xrandr command a few times (once is sometimes not enough!) to fix it each time. This tool would at least automate the task for me and seems useful.
Re:Show HN: Change screen layout when connecting/disconnecti... by tlackemann on Tuesday April 26, 2016 @09:06AM (#11571482)
My laptop running i3 is often moved between a dock on my desk and used as a regular laptop, I have to say I've been looking to write something like this but it fell by the wayside. Very useful IMO
Re:Show HN: Change screen layout when connecting/disconnecti... by leppr on Tuesday April 26, 2016 @10:29AM (#11572140)
This issue is the very reason I use KDE Plasma, I never came across another DE that handled multi-monitors correctly.
Re:Show HN: Change screen layout when connecting/disconnecti... by cmiles74 on Tuesday April 26, 2016 @09:23AM (#11571595)
Gnome doesn't do this. Without fail, every time, it puts the dock on the wrong external display. Every. Time.
Re:Show HN: Change screen layout when connecting/disconnecti... by bechampion on Tuesday April 26, 2016 @10:09AM (#11571967)
feel your frustration , I just never take mine of the dock cause i can't be arsed anymore.
Re:Show HN: Change screen layout when connecting/disconnecti... by shenal on Tuesday April 26, 2016 @12:35PM (#11573315)
As an i3wm user I couldn't be happier
Re:Show HN: Change screen layout when connecting/disconnecti... by jlpc on Tuesday April 26, 2016 @05:13PM (#11575674)
I'm glad it is useful for someone else.
Re:Show HN: Change screen layout when connecting/disconnecti... by rndstr on Wednesday April 27, 2016 @07:42AM (#11579482)
Here is my script that supports scaling up if your main monitor is hidpi while the external one is not:

https://github.com/rndstr/dotfiles/blob/master/bin/monitor-h...

Re:Show HN: Change screen layout when connecting/disconnecti... by mikeokner on Tuesday April 26, 2016 @10:23AM (#11572095)
For those on Mac, Slate will do the same thing: https://github.com/jigish/slate
Re:Show HN: Change screen layout when connecting/disconnecti... by mwfunk on Tuesday April 26, 2016 @01:11PM (#11573701)
Actually for those on the Mac, OS X will do the same thing. It tries to at least (not 100% reliable).
Re:Show HN: Change screen layout when connecting/disconnecti... by mikeokner on Tuesday April 26, 2016 @03:39PM (#11574913)
"xoutputd is a daemon that monitors the connection state of outputs and then executes commands based on defined rules."

I'm not aware of anything built in to OS X that allows you to execute scripts to perform custom actions when displays are connected/disconnected. OS X just tries to replicate the last layout you had.

* Plugged into your desk monitor? You can have Slate hide Steam and put MacVim & iTerm side by side. * Plugged into your TV? You can have Slate run a script to make sure your Plex server is up and then full-screen your browser. * Etc.

Re:Show HN: Change screen layout when connecting/disconnecti... by Carrok on Tuesday April 26, 2016 @05:16PM (#11575702)
I would recommend Hammerspoon for this type of automation. http://www.hammerspoon.org/
Re:Show HN: Change screen layout when connecting/disconnecti... by nasalgoat on Tuesday April 26, 2016 @04:57PM (#11575554)
Sadly, Slate hasn't been updated in three years and recent El Capitan releases has broken it for certain applications, most importantly iTerm2.
Re:Show HN: Change screen layout when connecting/disconnecti... by daveloyall on Tuesday April 26, 2016 @03:46PM (#11574985)
Re:Show HN: Change screen layout when connecting/disconnecti... by jlpc on Tuesday April 26, 2016 @04:50PM (#11575499)
I wonder why I didn't think about it when looking for a solution at my problem.
Re:Show HN: Change screen layout when connecting/disconnecti... by andmarios on Tuesday April 26, 2016 @11:06AM (#11572468)
KDE does this automatically. I'd guess there is similar functionality for other DEs too.
Re:Show HN: Change screen layout when connecting/disconnecti... by gtirloni on Tuesday April 26, 2016 @11:59AM (#11572965)
The MATE DE seems to handle this pretty well too.