~ubuntu-branches/ubuntu/oneiric/unity/oneiric

« back to all changes in this revision

Viewing changes to .pc/debian-changes-4.14.2-0ubuntu2/plugins/unityshell/src/inputremover.cpp

  • Committer: Package Import Robot
  • Author(s): Didier Roche
  • Date: 2011-09-12 08:12:54 UTC
  • Revision ID: package-import@ubuntu.com-20110912081254-qtz600pc32fva88o
Tags: 4.14.2-0ubuntu2
* Cherry-pick a fix for remapping minimized window correctly (LP: #840285)
* debian/control:
  - bump build-dep for latest compiz-dev ABI break

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2011 Canonical Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
17
 *
 
18
 * Authored By:
 
19
 * Sam Spilsbury <sam.spilsbury@canonical.com>
 
20
 */
 
21
 
 
22
#include "inputremover.h"
 
23
#include <cstdio>
 
24
 
 
25
compiz::WindowInputRemover::WindowInputRemover (Display *dpy,
 
26
                                                Window xid) :
 
27
  mDpy (dpy),
 
28
  mShapeWindow (xid),
 
29
  mShapeMask (0),
 
30
  mInputRects (NULL),
 
31
  mNInputRects (0),
 
32
  mInputRectOrdering (0),
 
33
  mBoundingRects (NULL),
 
34
  mNBoundingRects (0),
 
35
  mBoundingRectOrdering (0),
 
36
  mRemoved (false)
 
37
{
 
38
}
 
39
 
 
40
compiz::WindowInputRemover::~WindowInputRemover ()
 
41
{
 
42
  if (mRemoved)
 
43
    restore ();
 
44
}
 
45
 
 
46
bool
 
47
compiz::WindowInputRemover::save ()
 
48
{
 
49
  XRectangle   *rects;
 
50
  int          count = 0, ordering;
 
51
  Window       root;
 
52
  int          x, y;
 
53
  unsigned int width, height, border, depth;
 
54
 
 
55
  /* FIXME: There should be a generic GetGeometry request we can
 
56
     * use here in order to avoid a round-trip */
 
57
  if (!XGetGeometry (mDpy, mShapeWindow, &root, &x, &y, &width, &height,
 
58
                     &border, &depth))
 
59
  {
 
60
    return false;
 
61
  }
 
62
 
 
63
  rects = XShapeGetRectangles (mDpy, mShapeWindow, ShapeInput,
 
64
                               &count, &ordering);
 
65
 
 
66
  /* check if the returned shape exactly matches the window shape -
 
67
   * if that is true, the window currently has no set input shape */
 
68
  if ((count == 1) &&
 
69
      (rects[0].x == -((int) border)) &&
 
70
      (rects[0].y == -((int) border)) &&
 
71
      (rects[0].width == (width + border)) &&
 
72
      (rects[0].height == (height + border)))
 
73
  {
 
74
    count = 0;
 
75
  }
 
76
 
 
77
  if (mInputRects)
 
78
    XFree (mInputRects);
 
79
 
 
80
  mInputRects = rects;
 
81
  mNInputRects = count;
 
82
  mInputRectOrdering = ordering;
 
83
 
 
84
  rects = XShapeGetRectangles (mDpy, mShapeWindow, ShapeBounding,
 
85
                               &count, &ordering);
 
86
 
 
87
  if (mBoundingRects)
 
88
    XFree (mBoundingRects);
 
89
 
 
90
  mBoundingRects = rects;
 
91
  mNBoundingRects = count;
 
92
  mBoundingRectOrdering = ordering;
 
93
 
 
94
  mShapeMask = XShapeInputSelected (mDpy, mShapeWindow);
 
95
 
 
96
  return true;
 
97
}
 
98
 
 
99
bool
 
100
compiz::WindowInputRemover::remove ()
 
101
{
 
102
  if (!mNInputRects)
 
103
    save ();
 
104
 
 
105
  XShapeSelectInput (mDpy, mShapeWindow, NoEventMask);
 
106
 
 
107
  XShapeCombineRectangles (mDpy, mShapeWindow, ShapeInput, 0, 0,
 
108
                           NULL, 0, ShapeSet, 0);
 
109
  XShapeCombineRectangles (mDpy, mShapeWindow, ShapeBounding, 0, 0,
 
110
                           NULL, 0, ShapeSet, 0);
 
111
 
 
112
  XShapeSelectInput (mDpy, mShapeWindow, ShapeNotify);
 
113
 
 
114
  mRemoved = true;
 
115
  return true;
 
116
}
 
117
 
 
118
bool
 
119
compiz::WindowInputRemover::restore ()
 
120
{
 
121
  if (mRemoved)
 
122
  {
 
123
    if (mNInputRects)
 
124
    {
 
125
      XShapeCombineRectangles (mDpy, mShapeWindow, ShapeInput, 0, 0,
 
126
                               mInputRects, mNInputRects,
 
127
                               ShapeSet, mInputRectOrdering);
 
128
    }
 
129
    else
 
130
    {
 
131
      XShapeCombineMask (mDpy, mShapeWindow, ShapeInput,
 
132
                       0, 0, None, ShapeSet);
 
133
    }
 
134
 
 
135
    if (mInputRects)
 
136
      XFree (mInputRects);
 
137
 
 
138
    if (mNBoundingRects)
 
139
    {
 
140
      XShapeCombineRectangles (mDpy, mShapeWindow, ShapeBounding, 0, 0,
 
141
                         mBoundingRects, mNBoundingRects,
 
142
                         ShapeSet, mBoundingRectOrdering);
 
143
    }
 
144
    else
 
145
    {
 
146
      XShapeCombineMask (mDpy, mShapeWindow, ShapeBounding,
 
147
                   0, 0, None, ShapeSet);
 
148
    }
 
149
 
 
150
    if (mBoundingRects)
 
151
      XFree (mBoundingRects);
 
152
  }
 
153
 
 
154
  XShapeSelectInput (mDpy, mShapeWindow, mShapeMask);
 
155
 
 
156
  mRemoved = false;
 
157
  mNInputRects  = 0;
 
158
  mInputRects = NULL;
 
159
  mNBoundingRects = 0;
 
160
  mBoundingRects = NULL;
 
161
  return true;
 
162
}