Back to index

unity  6.0.0
networkarearegion.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2010 Canonical Ltd
00003  *
00004  * This program is free software: you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License version 3 as
00006  * published by the Free Software Foundation.
00007  *
00008  * This program is distributed in the hope that it will be useful,
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  * GNU General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00015  *
00016  * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
00017  */
00018 
00019 #include "networkarearegion.h"
00020 
00021 COMPIZ_PLUGIN_20090315(networkarearegion, UnityNETWorkareaRegionPluginVTable);
00022 
00023 void
00024 UnityNETWorkareaRegionScreen::setProperty()
00025 {
00026   CompRegion    sr;
00027   unsigned long* data;
00028   unsigned int  dataSize;
00029   unsigned int  offset = 0;
00030 
00031   sr = sr.united(CompRect(0, 0, screen->width(), screen->height()));
00032 
00033   foreach(CompWindow * w, screen->clientList())
00034   {
00035     if (!w->struts())
00036       continue;
00037 
00038     sr -= CompRect(w->struts()->left.x, w->struts()->left.y, w->struts()->left.width, w->struts()->left.height);
00039     sr -= CompRect(w->struts()->right.x, w->struts()->right.y, w->struts()->right.width, w->struts()->right.height);
00040     sr -= CompRect(w->struts()->top.x, w->struts()->top.y, w->struts()->top.width, w->struts()->top.height);
00041     sr -= CompRect(w->struts()->bottom.x, w->struts()->bottom.y, w->struts()->bottom.width, w->struts()->bottom.height);
00042   }
00043 
00044   dataSize = sr.rects().size()  * 4;
00045   data = new unsigned long[dataSize];
00046 
00047   foreach(const CompRect & r, sr.rects())
00048   {
00049     data[offset * 4 + 0] = r.x();
00050     data[offset * 4 + 1] = r.y();
00051     data[offset * 4 + 2] = r.width();
00052     data[offset * 4 + 3] = r.height();
00053 
00054     offset++;
00055   }
00056 
00057   XChangeProperty(screen->dpy(), screen->root(), mUnityNETWorkareaRegionAtom,
00058                   XA_CARDINAL, 32, PropModeReplace, (const unsigned char*) data, dataSize);
00059 
00060   delete[] data;
00061 }
00062 
00063 void
00064 UnityNETWorkareaRegionScreen::outputChangeNotify()
00065 {
00066   setProperty();
00067 }
00068 
00069 void
00070 UnityNETWorkareaRegionScreen::handleEvent(XEvent* event)
00071 {
00072   screen->handleEvent(event);
00073 
00074   switch (event->type)
00075   {
00076     case PropertyNotify:
00077 
00078       if (event->xproperty.atom == (Atom) Atoms::wmStrut ||
00079          event->xproperty.atom == (Atom) Atoms::wmStrutPartial)
00080       {
00081         CompWindow* w = screen->findWindow(event->xproperty.window);
00082 
00083         if (w)
00084         {
00085           if (w->struts())
00086           {
00087             UnityNETWorkareaRegionWindow* unwmh = UnityNETWorkareaRegionWindow::get(w);
00088 
00089             w->moveNotifySetEnabled(unwmh, true);
00090             w->resizeNotifySetEnabled(unwmh, true);
00091 
00092             /* The struts got updated, so we need to set the property again */
00093             setProperty();
00094           }
00095         }
00096       }
00097   }
00098 }
00099 
00100 void
00101 UnityNETWorkareaRegionWindow::moveNotify(int dx, int dy, bool immediate)
00102 {
00103   UnityNETWorkareaRegionScreen::get(screen)->setProperty();
00104   window->moveNotify(dx, dy, immediate);
00105 }
00106 
00107 void
00108 UnityNETWorkareaRegionWindow::resizeNotify(int dx, int dy, int dwidth, int dheight)
00109 {
00110   UnityNETWorkareaRegionScreen::get(screen)->setProperty();
00111   window->resizeNotify(dx, dy, dwidth, dheight);
00112 }
00113 
00114 void
00115 UnityNETWorkareaRegionScreen::addSupportedAtoms(std::vector<Atom> &atoms)
00116 {
00117   atoms.push_back(mUnityNETWorkareaRegionAtom);
00118 
00119   screen->addSupportedAtoms(atoms);
00120 }
00121 
00122 UnityNETWorkareaRegionScreen::UnityNETWorkareaRegionScreen(CompScreen* s) :
00123   PluginClassHandler <UnityNETWorkareaRegionScreen, CompScreen> (s),
00124   mUnityNETWorkareaRegionAtom(XInternAtom(screen->dpy(), "_UNITY_NET_WORKAREA_REGION", 0))
00125 {
00126   ScreenInterface::setHandler(screen);
00127   screen->updateSupportedWmHints();
00128 }
00129 
00130 UnityNETWorkareaRegionScreen::~UnityNETWorkareaRegionScreen()
00131 {
00132   /* Delete the property and the bit saying we support it */
00133   screen->addSupportedAtomsSetEnabled(this, false);
00134   screen->updateSupportedWmHints();
00135 
00136   XDeleteProperty(screen->dpy(), screen->root(), mUnityNETWorkareaRegionAtom);
00137 }
00138 
00139 
00140 UnityNETWorkareaRegionWindow::UnityNETWorkareaRegionWindow(CompWindow* w) :
00141   PluginClassHandler <UnityNETWorkareaRegionWindow, CompWindow> (w),
00142   window(w)
00143 {
00144   if (w->struts())
00145   {
00146     UnityNETWorkareaRegionScreen::get(screen)->setProperty();
00147     WindowInterface::setHandler(w, true);
00148   }
00149   else
00150     WindowInterface::setHandler(w, false);
00151 }
00152 
00153 UnityNETWorkareaRegionWindow::~UnityNETWorkareaRegionWindow()
00154 {
00155   if (window->struts())
00156     UnityNETWorkareaRegionScreen::get(screen)->setProperty();
00157 }
00158 
00159 bool
00160 UnityNETWorkareaRegionPluginVTable::init()
00161 {
00162   if (!CompPlugin::checkPluginABI("core", CORE_ABIVERSION))
00163     return false;
00164 
00165   return true;
00166 }