~jamespharaoh/ubuntu/oneiric/unity/fix-for-880672

« back to all changes in this revision

Viewing changes to .pc/debian-changes-4.8.2-0ubuntu3/plugins/networkarearegion/src/networkarearegion.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2011-08-19 18:53:28 UTC
  • Revision ID: james.westby@ubuntu.com-20110819185328-qaxk9eepjaghewu9
Tags: 4.8.2-0ubuntu4
Backport another trunk commit to fix an alt-tab segfault

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2010 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 version 3 as
6
 
 * published by the Free Software Foundation.
7
 
 *
8
 
 * This program is distributed in the hope that it will be useful,
9
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
 * GNU General Public License for more details.
12
 
 *
13
 
 * You should have received a copy of the GNU General Public License
14
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
 
 *
16
 
 * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
17
 
 */
18
 
 
19
 
#include "networkarearegion.h"
20
 
 
21
 
COMPIZ_PLUGIN_20090315(networkarearegion, UnityNETWorkareaRegionPluginVTable);
22
 
 
23
 
void
24
 
UnityNETWorkareaRegionScreen::setProperty()
25
 
{
26
 
  CompRegion    sr;
27
 
  unsigned long* data;
28
 
  unsigned int  dataSize;
29
 
  unsigned int  offset = 0;
30
 
 
31
 
  sr = sr.united(CompRect(0, 0, screen->width(), screen->height()));
32
 
 
33
 
  foreach(CompWindow * w, screen->clientList())
34
 
  {
35
 
    if (!w->struts())
36
 
      continue;
37
 
 
38
 
    sr -= CompRect(w->struts()->left.x, w->struts()->left.y, w->struts()->left.width, w->struts()->left.height);
39
 
    sr -= CompRect(w->struts()->right.x, w->struts()->right.y, w->struts()->right.width, w->struts()->right.height);
40
 
    sr -= CompRect(w->struts()->top.x, w->struts()->top.y, w->struts()->top.width, w->struts()->top.height);
41
 
    sr -= CompRect(w->struts()->bottom.x, w->struts()->bottom.y, w->struts()->bottom.width, w->struts()->bottom.height);
42
 
  }
43
 
 
44
 
  dataSize = sr.rects().size()  * 4;
45
 
  data = new unsigned long[dataSize];
46
 
 
47
 
  foreach(const CompRect & r, sr.rects())
48
 
  {
49
 
    data[offset * 4 + 0] = r.x();
50
 
    data[offset * 4 + 1] = r.y();
51
 
    data[offset * 4 + 2] = r.width();
52
 
    data[offset * 4 + 3] = r.height();
53
 
 
54
 
    offset++;
55
 
  }
56
 
 
57
 
  XChangeProperty(screen->dpy(), screen->root(), mUnityNETWorkareaRegionAtom,
58
 
                  XA_CARDINAL, 32, PropModeReplace, (const unsigned char*) data, dataSize);
59
 
 
60
 
  delete[] data;
61
 
}
62
 
 
63
 
void
64
 
UnityNETWorkareaRegionScreen::outputChangeNotify()
65
 
{
66
 
  setProperty();
67
 
}
68
 
 
69
 
void
70
 
UnityNETWorkareaRegionScreen::handleEvent(XEvent* event)
71
 
{
72
 
  screen->handleEvent(event);
73
 
 
74
 
  switch (event->type)
75
 
  {
76
 
    case PropertyNotify:
77
 
 
78
 
      if (event->xproperty.atom == (int) Atoms::wmStrut ||
79
 
          event->xproperty.atom == (int) Atoms::wmStrutPartial)
80
 
      {
81
 
        CompWindow* w = screen->findWindow(event->xproperty.window);
82
 
 
83
 
        if (w)
84
 
        {
85
 
          if (w->struts())
86
 
          {
87
 
            UnityNETWorkareaRegionWindow* unwmh = UnityNETWorkareaRegionWindow::get(w);
88
 
 
89
 
            w->moveNotifySetEnabled(unwmh, true);
90
 
            w->resizeNotifySetEnabled(unwmh, true);
91
 
 
92
 
            /* The struts got updated, so we need to set the property again */
93
 
            setProperty();
94
 
          }
95
 
        }
96
 
      }
97
 
  }
98
 
}
99
 
 
100
 
void
101
 
UnityNETWorkareaRegionWindow::moveNotify(int dx, int dy, bool immediate)
102
 
{
103
 
  UnityNETWorkareaRegionScreen::get(screen)->setProperty();
104
 
  window->moveNotify(dx, dy, immediate);
105
 
}
106
 
 
107
 
void
108
 
UnityNETWorkareaRegionWindow::resizeNotify(int dx, int dy, unsigned int dwidth, unsigned int dheight)
109
 
{
110
 
  UnityNETWorkareaRegionScreen::get(screen)->setProperty();
111
 
  window->resizeNotify(dx, dy, dwidth, dheight);
112
 
}
113
 
 
114
 
void
115
 
UnityNETWorkareaRegionScreen::addSupportedAtoms(std::vector<Atom> &atoms)
116
 
{
117
 
  atoms.push_back(mUnityNETWorkareaRegionAtom);
118
 
 
119
 
  screen->addSupportedAtoms(atoms);
120
 
}
121
 
 
122
 
UnityNETWorkareaRegionScreen::UnityNETWorkareaRegionScreen(CompScreen* s) :
123
 
  PluginClassHandler <UnityNETWorkareaRegionScreen, CompScreen> (s),
124
 
  mUnityNETWorkareaRegionAtom(XInternAtom(screen->dpy(), "_UNITY_NET_WORKAREA_REGION", 0))
125
 
{
126
 
  ScreenInterface::setHandler(screen);
127
 
  screen->updateSupportedWmHints();
128
 
}
129
 
 
130
 
UnityNETWorkareaRegionScreen::~UnityNETWorkareaRegionScreen()
131
 
{
132
 
  /* Delete the property and the bit saying we support it */
133
 
  screen->addSupportedAtomsSetEnabled(this, false);
134
 
  screen->updateSupportedWmHints();
135
 
 
136
 
  XDeleteProperty(screen->dpy(), screen->root(), mUnityNETWorkareaRegionAtom);
137
 
}
138
 
 
139
 
 
140
 
UnityNETWorkareaRegionWindow::UnityNETWorkareaRegionWindow(CompWindow* w) :
141
 
  PluginClassHandler <UnityNETWorkareaRegionWindow, CompWindow> (w),
142
 
  window(w)
143
 
{
144
 
  if (w->struts())
145
 
  {
146
 
    UnityNETWorkareaRegionScreen::get(screen)->setProperty();
147
 
    WindowInterface::setHandler(w, true);
148
 
  }
149
 
  else
150
 
    WindowInterface::setHandler(w, false);
151
 
}
152
 
 
153
 
UnityNETWorkareaRegionWindow::~UnityNETWorkareaRegionWindow()
154
 
{
155
 
  if (window->struts())
156
 
    UnityNETWorkareaRegionScreen::get(screen)->setProperty();
157
 
}
158
 
 
159
 
bool
160
 
UnityNETWorkareaRegionPluginVTable::init()
161
 
{
162
 
  if (!CompPlugin::checkPluginABI("core", CORE_ABIVERSION))
163
 
    return false;
164
 
 
165
 
  return true;
166
 
}