Back to index

unity  6.0.0
PluginAdapter.h
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: Jason Smith <jason.smith@canonical.com>
00018  */
00019 
00020 #ifndef PLUGINADAPTER_H
00021 #define PLUGINADAPTER_H
00022 
00023 /* Compiz */
00024 #include <core/core.h>
00025 #include <core/atoms.h>
00026 
00027 #include <sigc++/sigc++.h>
00028 
00029 #include "WindowManager.h"
00030 
00031 typedef struct
00032 {
00033   unsigned long flags;
00034   unsigned long functions;
00035   unsigned long decorations;
00036   long input_mode;
00037   unsigned long status;
00038 } MotifWmHints, MwmHints;
00039 
00040 class MultiActionList
00041 {
00042 public:
00043 
00044   MultiActionList(int n) :
00045     m_ActionList(n),
00046     _primary_action(NULL) {};
00047 
00048   void InitiateAll(CompOption::Vector& extraArgs, int state);
00049   void TerminateAll(CompOption::Vector& extraArgs);
00050 
00051   void AddNewAction(CompAction*, bool primary);
00052   void RemoveAction(CompAction*);
00053 private:
00054 
00055   std::list <CompAction*> m_ActionList;
00056   CompAction*              _primary_action;
00057 };
00058 
00059 
00060 class PluginAdapter : public sigc::trackable, public WindowManager
00061 {
00062 public:
00063   static PluginAdapter* Default();
00064 
00065   static void Initialize(CompScreen* screen);
00066 
00067   nux::Property<bool> bias_active_to_viewport;
00068 
00069   ~PluginAdapter();
00070 
00071   void SetScaleAction(MultiActionList& scale);
00072   void SetExpoAction(MultiActionList& expo);
00073 
00074   void SetShowHandlesAction(CompAction* action)
00075   {
00076     _grab_show_action = action;
00077   }
00078   void SetHideHandlesAction(CompAction* action)
00079   {
00080     _grab_hide_action = action;
00081   }
00082   void SetToggleHandlesAction(CompAction* action)
00083   {
00084     _grab_toggle_action = action;
00085   }
00086 
00087   void OnWindowClosed (CompWindow *);
00088   void OnScreenGrabbed();
00089   void OnScreenUngrabbed();
00090 
00091   void OnShowDesktop ();
00092   void OnLeaveDesktop ();
00093 
00094   void TerminateScale();
00095   bool IsScaleActive();
00096   bool IsScaleActiveForGroup();
00097 
00098   void InitiateExpo();
00099   bool IsExpoActive();
00100 
00101   void ShowGrabHandles(CompWindow* window, bool use_timer);
00102   void HideGrabHandles(CompWindow* window);
00103   void ToggleGrabHandles(CompWindow* window);
00104 
00105   void Notify(CompWindow* window, CompWindowNotify notify);
00106   void NotifyMoved(CompWindow* window, int x, int y);
00107   void NotifyResized(CompWindow* window, int x, int y, int w, int h);
00108   void NotifyStateChange(CompWindow* window, unsigned int state, unsigned int last_state);
00109   void NotifyCompizEvent(const char* plugin, const char* event, CompOption::Vector& option);
00110   void NotifyNewDecorationState(guint32 xid);
00111 
00112   guint32 GetActiveWindow();
00113 
00114   void Decorate(guint32 xid);
00115   void Undecorate(guint32 xid);
00116 
00117   // WindowManager implementation
00118   bool IsWindowMaximized(guint xid);
00119   bool IsWindowDecorated(guint xid);
00120   bool IsWindowOnCurrentDesktop(guint xid);
00121   bool IsWindowObscured(guint xid);
00122   bool IsWindowMapped(guint xid);
00123   bool IsWindowVisible(guint32 xid);
00124   bool IsWindowOnTop(guint32 xid);
00125   bool IsWindowClosable(guint32 xid);
00126   bool IsWindowMinimizable(guint32 xid);
00127   bool IsWindowMaximizable(guint32 xid);
00128 
00129   void Restore(guint32 xid);
00130   void RestoreAt(guint32 xid, int x, int y);
00131   void Minimize(guint32 xid);
00132   void Close(guint32 xid);
00133   void Activate(guint32 xid);
00134   void Raise(guint32 xid);
00135   void Lower(guint32 xid);
00136   void ShowDesktop();
00137 
00138   void SetWindowIconGeometry(Window window, nux::Geometry const& geo);
00139 
00140   void FocusWindowGroup(std::vector<Window> windows, FocusVisibility, int monitor = -1, bool only_top_win = true);
00141   bool ScaleWindowGroup(std::vector<Window> windows, int state, bool force);
00142 
00143   bool IsScreenGrabbed();
00144   bool IsViewPortSwitchStarted();
00145 
00146   unsigned long long GetWindowActiveNumber (guint32 xid);
00147 
00148   bool MaximizeIfBigEnough(CompWindow* window);
00149 
00150   int GetWindowMonitor(guint32 xid) const;
00151   nux::Geometry GetWindowGeometry(guint32 xid) const;
00152   nux::Geometry GetWindowSavedGeometry(guint32 xid) const;
00153   nux::Geometry GetScreenGeometry() const;
00154   nux::Geometry GetWorkAreaGeometry(guint32 xid = 0) const;
00155 
00156   void CheckWindowIntersections(nux::Geometry const& region, bool &active, bool &any);
00157 
00158   int WorkspaceCount();
00159 
00160   void SetCoverageAreaBeforeAutomaximize(float area);
00161 
00162   bool saveInputFocus ();
00163   bool restoreInputFocus ();
00164 
00165   void MoveResizeWindow(guint32 xid, nux::Geometry geometry);
00166 
00167 protected:
00168   PluginAdapter(CompScreen* screen);
00169   void AddProperties(GVariantBuilder* builder);
00170 
00171 private:
00172   std::string MatchStringForXids(std::vector<Window> *windows);
00173   void InitiateScale(std::string const& match, int state = 0);
00174 
00175   bool CheckWindowIntersection(nux::Geometry const& region, CompWindow* window);
00176   void SetMwmWindowHints(Window xid, MotifWmHints* new_hints);
00177 
00178   CompScreen* m_Screen;
00179   MultiActionList m_ExpoActionList;
00180   MultiActionList m_ScaleActionList;
00181 
00182   bool _spread_state;
00183   bool _spread_windows_state;
00184   bool _expo_state;
00185   bool _vp_switch_started;
00186 
00187   CompAction* _grab_show_action;
00188   CompAction* _grab_hide_action;
00189   CompAction* _grab_toggle_action;
00190 
00191   float _coverage_area_before_automaximize;
00192 
00193   bool _in_show_desktop;
00194   CompWindow* _last_focused_window;
00195 
00196   std::map<guint32, unsigned int> _window_decoration_state;
00197 
00198   static PluginAdapter* _default;
00199 };
00200 
00201 #endif