Back to index

unity  6.0.0
WindowManager.cpp
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright (C) 2010 Canonical Ltd
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 3 as
00007  * published by the Free Software Foundation.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  *
00017  * Authored by: Neil Jagdish Patel <neil.patel@canonical.com>
00018  */
00019 
00020 #include "WindowManager.h"
00021 
00022 static WindowManager* window_manager = NULL;
00023 
00024 class WindowManagerDummy : public WindowManager
00025 {
00026   guint32 GetActiveWindow()
00027   {
00028     return 0;
00029   }
00030 
00031   unsigned long long GetWindowActiveNumber (guint32 xid)
00032   {
00033     return 0;
00034   }
00035 
00036   bool IsScreenGrabbed()
00037   {
00038     return false;
00039   }
00040 
00041   bool IsViewPortSwitchStarted()
00042   {
00043     return false;
00044   }
00045 
00046   void ShowDesktop()
00047   {
00048     g_debug("%s", G_STRFUNC);
00049   }
00050 
00051   bool IsWindowMaximized(guint32 xid)
00052   {
00053     return false;
00054   }
00055 
00056   bool IsWindowDecorated(guint32 xid)
00057   {
00058     return true;
00059   }
00060 
00061   bool IsWindowOnCurrentDesktop(guint32 xid)
00062   {
00063     return true;
00064   }
00065 
00066   bool IsWindowObscured(guint32 xid)
00067   {
00068     return false;
00069   }
00070 
00071   bool IsWindowMapped(guint32 xid)
00072   {
00073     return true;
00074   }
00075 
00076   bool IsWindowVisible(guint32 xid)
00077   {
00078     return true;
00079   }
00080 
00081   bool IsWindowOnTop(guint32 xid)
00082   {
00083     return false;
00084   }
00085 
00086   bool IsWindowClosable(guint32 xid)
00087   {
00088     return true;
00089   }
00090 
00091   bool IsWindowMinimizable(guint32 xid)
00092   {
00093     return true;
00094   }
00095 
00096   bool IsWindowMaximizable(guint32 xid)
00097   {
00098     return true;
00099   }
00100 
00101   void Restore(guint32 xid)
00102   {
00103     g_debug("%s", G_STRFUNC);
00104   }
00105 
00106   void RestoreAt(guint32 xid, int x, int y)
00107   {
00108     g_debug("%s", G_STRFUNC);
00109   }
00110 
00111   void Minimize(guint32 xid)
00112   {
00113     g_debug("%s", G_STRFUNC);
00114   }
00115 
00116   void Close(guint32 xid)
00117   {
00118     g_debug("%s", G_STRFUNC);
00119   }
00120 
00121   void Activate(guint32 xid)
00122   {
00123     g_debug("%s", G_STRFUNC);
00124   }
00125 
00126   void Raise(guint32 xid)
00127   {
00128     g_debug("%s", G_STRFUNC);
00129   }
00130 
00131   void Lower(guint32 xid)
00132   {
00133     g_debug("%s", G_STRFUNC);
00134   }
00135 
00136   void FocusWindowGroup(std::vector<Window> windows, FocusVisibility, int monitor, bool only_top_win)
00137   {
00138     g_debug("%s", G_STRFUNC);
00139   }
00140 
00141   bool ScaleWindowGroup(std::vector<Window> windows, int state, bool force)
00142   {
00143     g_debug("%s", G_STRFUNC);
00144     return false;
00145   }
00146 
00147   int GetWindowMonitor(guint32 xid) const
00148   {
00149     return -1;
00150   }
00151 
00152   nux::Geometry GetWindowGeometry(guint xid) const
00153   {
00154     int width = (guint32)xid >> 16;
00155     int height = (guint32)xid & 0x0000FFFF;
00156     return nux::Geometry(0, 0, width, height);
00157   }
00158 
00159   nux::Geometry GetWindowSavedGeometry(guint xid) const
00160   {
00161     return nux::Geometry(0, 0, 1, 1);
00162   }
00163 
00164   nux::Geometry GetScreenGeometry() const
00165   {
00166     return nux::Geometry(0, 0, 1, 1);
00167   }
00168 
00169   nux::Geometry GetWorkAreaGeometry(guint32 xid) const
00170   {
00171     return nux::Geometry(0, 0, 1, 1);
00172   }
00173 
00174   void SetWindowIconGeometry(Window window, nux::Geometry const& geo)
00175   {
00176     g_debug("%s", G_STRFUNC);
00177   }
00178 
00179   void CheckWindowIntersections (nux::Geometry const& region, bool &active, bool &any)
00180   {
00181     active = false;
00182     any = false;
00183   }
00184 
00185   int WorkspaceCount ()
00186   {
00187     return 1;
00188   }
00189 
00190   void TerminateScale()
00191   {
00192     g_debug("%s", G_STRFUNC);
00193   }
00194 
00195   bool IsScaleActive()
00196   {
00197     g_debug("%s", G_STRFUNC);
00198     return false;
00199   }
00200 
00201   bool IsScaleActiveForGroup()
00202   {
00203     g_debug("%s", G_STRFUNC);
00204     return false;
00205   }
00206 
00207   void InitiateExpo()
00208   {
00209     g_debug("%s", G_STRFUNC);
00210   }
00211 
00212   bool IsExpoActive()
00213   {
00214     g_debug("%s", G_STRFUNC);
00215     return false;
00216   }
00217 
00218   void MoveResizeWindow(guint32 xid, nux::Geometry geometry)
00219   {
00220     g_debug("%s", G_STRFUNC);
00221   }
00222 
00223   bool saveInputFocus()
00224   {
00225     return false;
00226   }
00227 
00228   bool restoreInputFocus()
00229   {
00230     return false;
00231   }
00232 
00233 
00234   void AddProperties(GVariantBuilder* builder)
00235   {
00236   }
00237 };
00238 
00239 WindowManager*
00240 WindowManager::Default()
00241 {
00242   if (!window_manager)
00243     window_manager = new WindowManagerDummy();
00244 
00245   return window_manager;
00246 }
00247 
00248 void
00249 WindowManager::SetDefault(WindowManager* manager)
00250 {
00251   window_manager = manager;
00252 }
00253 
00254 std::string WindowManager::GetName() const
00255 {
00256   return "WindowManager";
00257 }
00258 
00259 #define NET_WM_MOVERESIZE_MOVE 8
00260 
00261 void WindowManager::StartMove(guint32 xid, int x, int y)
00262 {
00263   if (x < 0 || y < 0)
00264     return;
00265 
00266   XEvent ev;
00267   Display* d = nux::GetGraphicsDisplay()->GetX11Display();
00268 
00269   /* We first need to ungrab the pointer. FIXME: Evil */
00270 
00271   XUngrabPointer(d, CurrentTime);
00272 
00273   // --------------------------------------------------------------------------
00274   // FIXME: This is a workaround until the non-paired events issue is fixed in
00275   // nux
00276   XButtonEvent bev =
00277   {
00278     ButtonRelease,
00279     0,
00280     False,
00281     d,
00282     0,
00283     0,
00284     0,
00285     CurrentTime,
00286     x, y,
00287     x, y,
00288     0,
00289     Button1,
00290     True
00291   };
00292   XEvent* e = (XEvent*)&bev;
00293   nux::GetWindowThread()->ProcessForeignEvent(e, NULL);
00294 
00295   ev.xclient.type    = ClientMessage;
00296   ev.xclient.display = d;
00297 
00298   ev.xclient.serial     = 0;
00299   ev.xclient.send_event = true;
00300 
00301   ev.xclient.window     = xid;
00302   ev.xclient.message_type = m_MoveResizeAtom;
00303   ev.xclient.format     = 32;
00304 
00305   ev.xclient.data.l[0] = x; // x_root
00306   ev.xclient.data.l[1] = y; // y_root
00307   ev.xclient.data.l[2] = NET_WM_MOVERESIZE_MOVE; //direction
00308   ev.xclient.data.l[3] = 1; // button
00309   ev.xclient.data.l[4] = 2; // source
00310 
00311   XSendEvent(d, DefaultRootWindow(d), FALSE,
00312              SubstructureRedirectMask | SubstructureNotifyMask,
00313              &ev);
00314 
00315   XSync(d, FALSE);
00316 }