This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Different desktop activities for external laptop monitor

Tags: plasma, activities, monitor plasma, activities, monitor plasma, activities, monitor
(comma "," separated)
User avatar
Thailandian
Registered Member
Posts
30
Karma
1
OS
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...

Fair warning
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.

Background
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:
Code: Select all
#!/bin/bash
myvar="$(xrandr -q)"
if [[ $myvar == *"VGA connected"* ]]
then
  xrandr --output VGA --auto;
  xrandr --output LVDS --auto;
  xrandr --output LVDS --off;
else
  xrandr --output LVDS --auto;
fi
(for further details, see viewtopic.php?f=14&t=88659)

That made life much easier, but I still had a problem.

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:
Code: Select all
[Containments][16]
activity=Internet 16X9
desktop=0
formfactor=0
geometry=1372,0,1366,768
immutability=1
location=0
plugin=desktop
screen=1
wallpaperplugin=image
wallpaperpluginmode=SingleImage
zvalue=0

...

[Containments][37]
activity=Internet 5X4
desktop=0
formfactor=0
geometry=1286,2104,1280,1024
immutability=1
location=0
plugin=desktop
screen=0
wallpaperplugin=image
wallpaperpluginmode=SingleImage
zvalue=0

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:
Code: Select all
ln -f -s /home/myusername/.kde4/share/config/plasma-desktop-appletsrcs/plasma-desktop-appletsrc-VGA /home/myusername/.kde4/share/config/plasma-desktop-appletsrc
Actually, the -f (force) option is not necessary the first time you make the link, but will be later on, as it forces ln to overwrite an existing link.

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:
Code: Select all
ln -f -s /home/ian/.kde4/share/config/plasma-desktop-appletsrcs/plasma-desktop-appletsrc-LVDS /home/ian/.kde4/share/config/plasma-desktop-appletsrc

... 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:
Code: Select all
#!/bin/bash
myvar="$(xrandr -q)"
if [[ $myvar == *"VGA connected"* ]]
then
  ln -f -s /home/myusername/.kde4/share/config/plasma-desktop-appletsrcs/plasma-desktop-appletsrc-VGA /home/myusername/.kde4/share/config/plasma-desktop-appletsrc
  xrandr --output VGA --auto;
  xrandr --output LVDS --auto;
  xrandr --output LVDS --off;
else
  ln -f -s /home/myusername/.kde4/share/config/plasma-desktop-appletsrcs/plasma-desktop-appletsrc-LVDS /home/myusername/.kde4/share/config/plasma-desktop-appletsrc
  xrandr --output LVDS --auto;
fi


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.

Implication
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.
paolinux
Registered Member
Posts
18
Karma
0
OS
Hi Thailandian ,
your procedure works with a proprieary video dirver installed, for example with nvidia driver?

regards
User avatar
Thailandian
Registered Member
Posts
30
Karma
1
OS
paolinux wrote:Hi Thailandian ,
your procedure works with a proprieary video dirver installed, for example with nvidia driver?

regards

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:
Code: Select all
if [[ $myvar == *"VGA connected"* ]]
to
Code: Select all
if [[ $myvar == *"VGA1 connected"* ]]

So, if you would like to try this, I would suggest first querying how xrandr reports your display hardware, by entering:
Code: Select all
xrandr -q
into a console.

The output for my laptop is now:
Code: Select all
Screen 0: minimum 320 x 200, current 1280 x 1024, maximum 8192 x 8192
VGA1 connected 1280x1024+0+0 (normal left inverted right x axis y axis) 338mm x 270mm
   1280x1024      60.0*+   75.0 
   1152x864       75.0 
   1024x768       75.1     75.0     60.0 
   832x624        74.6 
   800x600        75.0     60.3 
   640x480        75.0     60.0 
   720x400        70.1 
LVDS1 connected (normal left inverted right x axis y axis)
   1366x768       60.0 +
   1024x768       60.0 
   800x600        60.3     56.2 
   640x480        59.9 
DP1 disconnected (normal left inverted right x axis y axis)


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
Code: Select all
xrandr -q
here and I'll show you how to edit the script for your setup.

Cheers


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Sogou [Bot]