~smspillaz/compiz-plugins-main/compiz-plugins-main.fix_939228

« back to all changes in this revision

Viewing changes to wall/src/offset_movement/src/offset-movement.cpp

  • Committer: smspillaz
  • Date: 2012-04-24 13:01:14 UTC
  • Revision ID: sam.spilsbury@canonical.com-20120424130114-sng6c43ulxxhrxz4
checkinĀ missingĀ files

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 *
 
3
 * Compiz wall plugin
 
4
 *
 
5
 * offset-movement.c
 
6
 *
 
7
 * Copyright (c) 2006 Robert Carr <racarr@beryl-project.org>
 
8
 *
 
9
 * Authors:
 
10
 * Robert Carr <racarr@beryl-project.org>
 
11
 * Dennis Kasprzyk <onestone@opencompositing.org>
 
12
 *
 
13
 * This program is free software; you can redistribute it and/or
 
14
 * modify it under the terms of the GNU General Public License
 
15
 * as published by the Free Software Foundation; either version 2
 
16
 * of the License, or (at your option) any later version.
 
17
 *
 
18
 * This program is distributed in the hope that it will be useful,
 
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
 * GNU General Public License for more details.
 
22
 *
 
23
 **/
 
24
 
 
25
#include "offset-movement.h"
 
26
 
 
27
CompPoint
 
28
compiz::wall::movementWindowOnScreen (const CompRect &serverBorderRect,
 
29
                                      const CompRegion &screenRegion)
 
30
{
 
31
    CompRegion sbrRegion (static_cast <const CompRect &> (serverBorderRect));
 
32
 
 
33
    /* If the window would be partially offscreen
 
34
     * after it was moved then we should move it back
 
35
     * so that it is completely onscreen, since we moved
 
36
     * from mostly offscreen on B to mostly onscreen on A,
 
37
     * the user should be able to see their selected window */
 
38
    CompRegion inter = sbrRegion.intersected (screenRegion);
 
39
    CompRegion rem = sbrRegion - screenRegion;
 
40
 
 
41
    int dx = 0;
 
42
    int dy = 0;
 
43
 
 
44
    for (std::vector <CompRect>::const_iterator it = rem.rects ().begin ();
 
45
         it != rem.rects ().end ();
 
46
         it++)
 
47
    {
 
48
        const CompRect &r = *it;
 
49
 
 
50
        if (r.x1 () >= inter.boundingRect ().x2 ())
 
51
            dx -= r.width ();
 
52
        else if (r.x2 () <= inter.boundingRect ().x1 ())
 
53
            dx += r.width ();
 
54
 
 
55
        if (r.y1 () >= inter.boundingRect ().y2 ())
 
56
            dy -= r.height ();
 
57
        else if (r.y2 () <= inter.boundingRect ().y1 ())
 
58
            dy += r.height ();
 
59
    }
 
60
 
 
61
    return CompPoint (dx, dy);
 
62
}