Mon Jun 21, 2010 4:15 pm
I'm not sure if this will be useful to anybody else, but before I worked out a solution, I googled for ages, so just in case anyone else needs this, here it is...
This is probably not for noobs. You don't need to be a programmer (I'm not), but should be reasonably comfortable editing config files, and creating bash scripts.
I have a laptop, which I plug into an external monitor at home. I had already automated detecting whether there is an external monitor connected, then turning on the correct video output, with the following script:
That made life much easier, but I still had a problem.
I use 5 virtual desktops with a different activity per desktop. My laptop monitor is 16:9, but the external one is 5:4. So a desktop activity designed for the 16:9 aspect looks **** on the 5:4 monitor and vice versa.
The problem was how to get KDE to automatically select desktop activities that suit the aspect of the selected monitor.
Solution (in seven steps) ...
Step 1: Full complement of desktop activities
The first thing I did was make sure I had two activities for each virtual desktop - one for each monitor. When I zoomed out, using the ZUI, I found that indeed KDE had already created them. This is probably because I had already be playing around with desktop activities for some time, both with and without the external monitor connected.
If you find that you don't have the full complement of activities, there is an "Add Activity" option in the cashew. If you need to add an activity, be sure to log in using the monitor with the missing activity, so that the new activity has the correct dimensions set for it.
Step 2: Name each activity
While still zoomed out, I went through every activity and named it clearly. For example, I have one desktop set up for Internet use, so I called the two activities for that desktop "Internet 5X4" and "Internet 16X9" respectively.
Step 3: Make two copies of plasma-desktop-appletsrc
After zooming in again, I opened up the the /.kde4/share/config/ folder, and created a new folder in it (I named the folder "plasma-desktop-appletsrcs" but you might want to name it something shorter )
Next, I made two copies of the plasma-desktop-appletsrc file (located in the /.kde4/share/config/ folder), and put them in the new folder. I renamed one file: "plasma-desktop-appletsrc-LVDS" and the other "plasma-desktop-appletsrc-VGA". (Again, you don't need to make these names so long - I just have a policy when naming things; I imagine stumbling across a file 20 years from now - will I remember what the hell it was for?)
Step 4: Edit the two plasma-desktop-appletsrc files
Next, I edited each file. For the VGA version, I made sure that all 5X4 activities were set to "screen=0" and the corresponding 16X9 ones were set to "screen=1" (in fact you could possibly delete the 16X9 ones, but I occasionally use xinerama so I didn't).
Hint: to locate the desktop activity sections within the file, search for "plugin=desktop".
Here are a couple of snippets of the -VGA file after I had edited it:
In the LVDS version, I did the opposite - set the 5X4 activities to "screen=1" and 16X9 to "screen=0".
Step 5: Replace plasma-desktop-appletsrc with a symlink
Next, I deleted the original plasma-desktop-appletsrc file (if you're sensible you will back it up somewhere first), and replaced it with a symlink to plasma-desktop-appletsrc-VGA (because I was using the external monitor at the time).
The command for this is:
Warning: of course, if you try this yourself, you will need to replace "myusername" with your own, "plasma-desktop-appletsrcs" with whatever you named your folder, and "plasma-desktop-appletsrc-VGA" with whatever you named your file. That also goes for all following code snippets.
Step 6: Testing
I logged out and logged back in, and, sure enough, each desktop was using the correct activity for 5X4!
Then I replaced the symlink with one to plasma-desktop-appletsrc-LVDS:
... logged out, disconnected the external monitor, logged back in, and yet again, each desktop was using the correctly proportioned activity.
Step 7: Automating
Finally, I added the two bash commands to my login script to automatically select which set of desktop activities to use, in addition to turning on the correct video output:
One important thing: this script needs to go into the .kde4/env/ directory rather than Autostart, so that the correct file is symlinked before KDE starts.
One implication of this setup is that any changes you make to your desktops while using the external monitor will not show up next time you use your laptop stand-alone, and vice versa. There is good and bad in this of course, but the whole idea is to be able to customise desktop configurations for each monitor.
Of course, this is a bit of a kludge, and if anyone can think of a better way to do it, I'd be very interested. But for the moment, I'm happy, and just maybe there's someone out there that has the same or similar problem.
Wed Jul 28, 2010 1:09 pm
Hi Thailandian ,
your procedure works with a proprieary video dirver installed, for example with nvidia driver?
Fri Aug 06, 2010 1:25 pm
Sorry for the late reply paolinux.
I have an Intel display chipset on my laptop so I can't be sure. The section that switches the link between plasma-desktop-appletsrc files should not be effected by drivers. However I understand that proprietary drivers support xrandr to varying degrees so that could be problematic.
I recently updated to openSuse 11.3 and all of these scripts (here and those described in viewtopic.php?f=14&t=88659) stopped working. After a bit of digging, I discovered that xrandr was reporting my display hardware differently. Before it had listed my displays as "VGA" and "LVDS". Now it lists them as "VGA1" and "LVDS1".
To get the scripts working again, I had to change the "if statement" from:
So, if you would like to try this, I would suggest first querying how xrandr reports your display hardware, by entering:
The output for my laptop is now:
Take note of what xrandr labels your external display, and edit the line that begins "if [[ $myvar == " accordingly.
I hope this helps. If it's confusing, paste the output of