Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Keeping windows where they are.
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
onefriedrice
n00b
n00b


Joined: 26 Aug 2007
Posts: 57

PostPosted: Wed Dec 10, 2008 5:51 am    Post subject: Keeping windows where they are. Reply with quote

Hello,

I don't know how useful this will be to anyone else, but when I recently found out about the amazing wmctrl program, I was thrilled I would be able to finally fix one really annoying thing about my Gentoo desktop.

The problem: Some programs (i.e. wine) change the screen resolution in such a way that other open windows are left in different positions after the resolution is changed back. Does anyone else have this problem with some programs, or maybe it's just me? If you don't have this problem, you probably don't need this.

The solution is this program wrapper which saves the window positions, runs whatever program, then restores the windows back to their original positions after the program terminates.

You can see what this script does by running "wmsavepos sleep 5", moving windows around for a few seconds, then watching them jump back to their original positions.

This is how I use it:

wmsavepos wine ~/.wine/drive_c/Program\ Files/Warcraft\ III/Frozen\ Throne.exe

Then after a little Warcraft III which changes the screen resolution, I exit and feel happy that all my windows are where I left them. :D

Code:
#!/usr/bin/perl

#
# This script is designed as a wrapper for another program:
# Usage: wmsavepos [some_program options]
#
# It will save the positions and dimensions of X11 windows currently being
# managed by the window manager and restore those positions and dimensions when
# the program terminates.  It is useful to wrap this around programs which
# change the resolution in such a way that windows move around to accomodate the
# size change and are not restored.  Isn't that so annoying!?
#
# The wmctrl command is required.
#
#  Author: Charles McGarvey
#    Date: 9 Dec 2008
# License: MIT
#
# This script is not a model of beautiful perl programming.
#

# Save the command to execute.
for ($i = 1; $ARGV[$i]; $i++)
{
   $ARGV[$i] = "\"$ARGV[$i]\"";
}
$command = join(' ', @ARGV);


# Save the positions of all windows handled by the window manager.
$windows = `wmctrl -Gl | cut -c1-34`;
@windows = split('\n', $windows);


# Execute the passed command.
$dummy = `$command`;


# Restore the positions of all windows saved.
foreach $window (@windows)
{
   @params = split(' ', $window);

   $winID = shift @params;
   $gravity = shift @params;

   if ($gravity != -1)
   {
      # TODO - Why is this necessary?
      $params[0] -= 1;
      $params[1] -= 43;
   }

   $pos = join(',', @params);

   $dummy = `wmctrl -ir $winID -e 0,$pos`;
}


Now, one problem is I'm not sure how generalized this solution is (I'm not knowledgable enough with X11). It works on my desktop running fluxbox, but I don't know how well it will work with other window managers. For example, the "TODO" part of the script shows some magic numbers I had to use to modify the restoration position because I found that wmctrl didn't move windows with borders back into the same place when given the same coordinates obtained by wmctrl. I don't really know why. These magic numbers may need to be different with different window managers (or maybe even different themes), or maybe you won't even need them. Feel free to experiment.

Bottom line is it works for me so I'm happy, but I'd be interested if anyone has improvements for this. Or if there is already a solution for this problem "out there" that I didn't find before writing this little script, please let me know so I can kick myself for suffering for so long without it.

Cheers.
Back to top
View user's profile Send private message
oliver
Apprentice
Apprentice


Joined: 25 Jun 2003
Posts: 170

PostPosted: Thu Dec 11, 2008 10:18 pm    Post subject: Re: Keeping windows where they are. Reply with quote

seems like a nice way to mess with someone who leaves their desktop open :-)

You might also like devilspie (it's in portage)... not saying it does the same thing but if you like things to be in certain places it's a great app
_________________
I can't help quoting you. 'Cos everything that you said rings true.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum