diff options
| author | Manuel de la Pena <manuel@canonical.com> | 2012-10-08 13:44:37 +0200 |
|---|---|---|
| committer | Manuel de la Pena <manuel@canonical.com> | 2012-10-08 13:44:37 +0200 |
| commit | f3b0dc72f3c08339320943ee8995a0b591c065c1 (patch) | |
| tree | 693353dfb23dac5c5507633d704a83d4da5a83e7 /unity-shared | |
| parent | 1f41a138e20177f4b32c1e6e99581fb39c0be583 (diff) | |
| parent | c2b9f2ff889e16d8615e35eb3e0941623bf14dcf (diff) | |
Merged with trunk.
(bzr r2791.8.2)
Diffstat (limited to 'unity-shared')
23 files changed, 1019 insertions, 1296 deletions
diff --git a/unity-shared/BackgroundEffectHelper.cpp b/unity-shared/BackgroundEffectHelper.cpp index 2d3be7ef4..f9078b801 100644 --- a/unity-shared/BackgroundEffectHelper.cpp +++ b/unity-shared/BackgroundEffectHelper.cpp @@ -29,7 +29,6 @@ #undef FALSE #endif -#include <X11/Xregion.h> #include <boost/utility.hpp> #include "UnitySettings.h" diff --git a/unity-shared/CMakeLists.txt b/unity-shared/CMakeLists.txt index 41af501be..27b8ceef5 100644 --- a/unity-shared/CMakeLists.txt +++ b/unity-shared/CMakeLists.txt @@ -35,7 +35,6 @@ set (UNITY_SHARED_SOURCES DashStyle.cpp DefaultThumbnailProvider.cpp FontSettings.cpp - KeyboardUtil.cpp IMTextEntry.cpp IconLoader.cpp IconRenderer.cpp @@ -65,6 +64,8 @@ set (UNITY_SHARED_SOURCES UnityWindowView.cpp UserThumbnailProvider.cpp WindowManager.cpp + XKeyboardUtil.cpp + XWindowManager.cpp ubus-server.cpp ) @@ -78,7 +79,7 @@ add_dependencies (unity-shared unity-core-${UNITY_API_VERSION}) # compiz set (UNITY_SHARED_COMPIZ_SOURCES - PluginAdapterCompiz.cpp + PluginAdapter.cpp ) add_library (unity-shared-compiz STATIC ${UNITY_SHARED_COMPIZ_SOURCES}) target_link_libraries (unity-shared-compiz ${LIBS}) @@ -87,7 +88,7 @@ add_dependencies (unity-shared-compiz unity-shared) # standalone set (UNITY_SHARED_STANDALONE_SOURCES - PluginAdapterStandalone.cpp + StandaloneWindowManager.cpp ) add_library (unity-shared-standalone STATIC ${UNITY_SHARED_STANDALONE_SOURCES}) target_link_libraries (unity-shared-standalone ${LIBS}) diff --git a/unity-shared/CoverArt.cpp b/unity-shared/CoverArt.cpp index 5cc5e1788..d45ca65e9 100644 --- a/unity-shared/CoverArt.cpp +++ b/unity-shared/CoverArt.cpp @@ -42,6 +42,7 @@ namespace nux::logging::Logger logger("unity.dash.previews.coverart"); const int ICON_SIZE = 256; +const int IMAGE_TIMEOUT = 30; } NUX_IMPLEMENT_OBJECT_TYPE(CoverArt); @@ -88,9 +89,7 @@ void CoverArt::AddProperties(GVariantBuilder* builder) void CoverArt::SetImage(std::string const& image_hint) { - spinner_timeout_.reset(); - frame_timeout_.reset(); - waiting_ = false; + StopWaiting(); if (slot_handle_ > 0) { @@ -98,8 +97,6 @@ void CoverArt::SetImage(std::string const& image_hint) slot_handle_ = 0; } - GIcon* icon = g_icon_new_for_string(image_hint.c_str(), NULL); - bool bLoadTexture = false; bLoadTexture |= g_strrstr(image_hint.c_str(), "://") != NULL; if (!bLoadTexture && !image_hint.empty()) @@ -115,10 +112,8 @@ void CoverArt::SetImage(std::string const& image_hint) } else if (!image_hint.empty()) { - if (GetLayout()) - GetLayout()->RemoveChildObject(overlay_text_); - - if (G_IS_ICON(icon)) + glib::Object<GIcon> icon(g_icon_new_for_string(image_hint.c_str(), NULL)); + if (icon.IsType(G_TYPE_ICON)) { StartWaiting(); slot_handle_ = IconLoader::GetDefault().LoadFromGIconString(image_hint, ICON_SIZE, ICON_SIZE, sigc::mem_fun(this, &CoverArt::IconLoaded)); @@ -133,9 +128,6 @@ void CoverArt::SetImage(std::string const& image_hint) { SetNoImageAvailable(); } - - if (icon != NULL) - g_object_unref(icon); } void CoverArt::GenerateImage(std::string const& uri) @@ -159,12 +151,14 @@ void CoverArt::StartWaiting() if (waiting_) return; + if (GetLayout()) + GetLayout()->RemoveChildObject(overlay_text_); waiting_ = true; rotate_matrix_.Rotate_z(0.0f); rotation_ = 0.0f; - spinner_timeout_.reset(new glib::TimeoutSeconds(5, [&] + spinner_timeout_.reset(new glib::TimeoutSeconds(IMAGE_TIMEOUT, [&] { StopWaiting(); @@ -221,11 +215,13 @@ void CoverArt::IconLoaded(std::string const& texid, pixbuf_height = (pixbuf_height) ? pixbuf_height: 1; // no zeros please } + if (GetLayout()) + GetLayout()->RemoveChildObject(overlay_text_); + if (pixbuf_width == pixbuf_height) - { + { // quick path for square icons texture_screenshot_.Adopt(nux::CreateTexture2DFromPixbuf(pixbuf, true)); - QueueDraw(); } else { @@ -273,8 +269,8 @@ void CoverArt::IconLoaded(std::string const& texid, cairo_paint(cr); texture_screenshot_.Adopt(texture_from_cairo_graphics(cairo_graphics)); - QueueDraw(); } + QueueDraw(); } void CoverArt::TextureLoaded(std::string const& texid, @@ -291,6 +287,10 @@ void CoverArt::TextureLoaded(std::string const& texid, SetNoImageAvailable(); return; } + + if (GetLayout()) + GetLayout()->RemoveChildObject(overlay_text_); + texture_screenshot_.Adopt(nux::CreateTexture2DFromPixbuf(pixbuf, true)); QueueDraw(); } @@ -472,13 +472,7 @@ void CoverArt::OnThumbnailError(std::string const& error_hint) StopWaiting(); texture_screenshot_.Release(); - if (GetLayout()) - { - GetLayout()->RemoveChildObject(overlay_text_); - GetLayout()->AddView(overlay_text_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL, 100.0, nux::LayoutPosition(1)); - ComputeContentSize(); - } - QueueDraw(); + SetNoImageAvailable(); notifier_.Release(); } diff --git a/unity-shared/DashStyle.h b/unity-shared/DashStyle.h index 0f816a71f..8ddf17ac9 100755 --- a/unity-shared/DashStyle.h +++ b/unity-shared/DashStyle.h @@ -20,6 +20,8 @@ #ifndef DASH_STYLE_H #define DASH_STYLE_H +#include "DashStyleInterface.h" + #include <Nux/Nux.h> #include <Nux/View.h> #include <Nux/AbstractButton.h> @@ -83,7 +85,7 @@ enum class Arrow { }; -class Style +class Style : public StyleInterface { public: Style (); diff --git a/unity-shared/DashStyleInterface.h b/unity-shared/DashStyleInterface.h new file mode 100644 index 000000000..43d488bc4 --- /dev/null +++ b/unity-shared/DashStyleInterface.h @@ -0,0 +1,53 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2012 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com> + */ + +#ifndef UNITYSHELL_DASH_STYLE_INTERFACE_H +#define UNITYSHELL_DASH_STYLE_INTERFACE_H + +#include <memory> + +namespace nux { + class AbstractPaintLayer; + class BaseTexture; +} + +namespace unity { +namespace dash { + +class StyleInterface +{ +public: + virtual ~StyleInterface() {}; + + virtual nux::AbstractPaintLayer* FocusOverlay(int width, int height) = 0; + + virtual nux::BaseTexture* GetCategoryBackground() = 0; + virtual nux::BaseTexture* GetCategoryBackgroundNoFilters() = 0; + + virtual nux::BaseTexture* GetGroupUnexpandIcon() = 0; + virtual nux::BaseTexture* GetGroupExpandIcon() = 0; + + virtual int GetCategoryHeaderLeftPadding() const = 0; + virtual int GetPlacesGroupTopSpace() const = 0; +}; + +} +} + +#endif diff --git a/unity-shared/IntrospectableWrappers.cpp b/unity-shared/IntrospectableWrappers.cpp index 910628df4..5f152aca1 100644 --- a/unity-shared/IntrospectableWrappers.cpp +++ b/unity-shared/IntrospectableWrappers.cpp @@ -25,28 +25,35 @@ namespace unity { namespace debug { - ResultWrapper::ResultWrapper(dash::Result const& result, nux::Geometry const& geo) - : uri_(result.uri), + +ResultWrapper::ResultWrapper(dash::Result const& result, nux::Geometry const& geo) +: uri_(result.uri), name_(result.name), icon_hint_(result.icon_hint), mime_type_(result.mimetype), geo_(geo) - { - } +{ +} + +std::string ResultWrapper::GetName() const +{ + return "Result"; +} - std::string ResultWrapper::GetName() const - { - return "Result"; - } +void ResultWrapper::AddProperties(GVariantBuilder* builder) +{ + unity::variant::BuilderWrapper(builder) + .add("uri", uri_) + .add("name", name_) + .add("icon_hint", icon_hint_) + .add("mimetype", mime_type_) + .add(geo_); +} + +void ResultWrapper::UpdateGeometry(nux::Geometry const& geo) +{ + geo_ = geo; +} - void ResultWrapper::AddProperties(GVariantBuilder* builder) - { - unity::variant::BuilderWrapper(builder) - .add("uri", uri_) - .add("name", name_) - .add("icon_hint", icon_hint_) - .add("mimetype", mime_type_) - .add(geo_); - } } } diff --git a/unity-shared/IntrospectableWrappers.h b/unity-shared/IntrospectableWrappers.h index 5fae901ef..8f11e3700 100644 --- a/unity-shared/IntrospectableWrappers.h +++ b/unity-shared/IntrospectableWrappers.h @@ -39,6 +39,9 @@ public: ResultWrapper(const dash::Result& result, nux::Geometry const& geo = nux::Geometry()); std::string GetName() const; void AddProperties(GVariantBuilder* builder); + + void UpdateGeometry(nux::Geometry const& geo); + private: std::string uri_; std::string name_; diff --git a/unity-shared/KeyboardUtil.h b/unity-shared/KeyboardUtil.h index b5ee98146..d57ecc163 100644 --- a/unity-shared/KeyboardUtil.h +++ b/unity-shared/KeyboardUtil.h @@ -1,6 +1,6 @@ // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- /* - * Copyright (C) 2011 Canonical Ltd + * Copyright (C) 2011-2012 Canonical Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -14,49 +14,22 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * - * Authored by: Jason Smith <jason.smith@canonical.com> + * Authored by: Tim Penhey <tim.penhey@canonical.com> */ -#ifndef KEYBOARDUTIL_H -#define KEYBOARDUTIL_H - -#include <glib.h> - -#include <X11/keysym.h> -#include <X11/XKBlib.h> -#include <X11/extensions/XKBgeom.h> +#ifndef UNITYSHARED_KEYBOARDUTIL_H +#define UNITYSHARED_KEYBOARDUTIL_H namespace unity { -namespace ui +namespace keyboard { -class KeyboardUtil -{ -public: - KeyboardUtil(Display *display); - ~KeyboardUtil(); - - guint GetKeycodeAboveKeySymbol(KeySym key_symbol) const; - - static bool IsPrintableKeySymbol(KeySym key_symbol); - static bool IsMoveKeySymbol(KeySym sym); - -private: - bool CompareOffsets (int current_x, int current_y, int best_x, int best_y) const; - guint ConvertKeyToKeycode (XkbKeyPtr key) const; - - bool FindKeyInGeometry(XkbGeometryPtr geo, char *key_name, int& res_section, XkbBoundsRec& res_bounds) const; - bool FindKeyInSectionAboveBounds (XkbGeometryPtr geo, int section, XkbBoundsRec const& target_bounds, guint &keycode) const; - - XkbBoundsRec GetAbsoluteKeyBounds (XkbKeyPtr key, XkbRowPtr row, XkbSectionPtr section, XkbGeometryPtr geo) const; - - Display *display_; - XkbDescPtr keyboard_; -}; +bool is_printable_key_symbol(unsigned long key_symbol); +bool is_move_key_symbol(unsigned long key_symbol); } } -#endif // KEYBOARDUTIL_H +#endif // UNITYSHARED_KEYBOARDUTIL_H diff --git a/unity-shared/PluginAdapterCompiz.cpp b/unity-shared/PluginAdapter.cpp index 23702bf7f..f0cfbc4ef 100644 --- a/unity-shared/PluginAdapterCompiz.cpp +++ b/unity-shared/PluginAdapter.cpp @@ -1,6 +1,6 @@ // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- /* - * Copyright (C) 2010 Canonical Ltd + * Copyright (C) 2010-2012 Canonical Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -25,6 +25,8 @@ #include <NuxCore/Logger.h> #include <UnityCore/Variant.h> +namespace unity +{ namespace { @@ -33,10 +35,9 @@ nux::logging::Logger logger("unity.plugin"); const int THRESHOLD_HEIGHT = 600; const int THRESHOLD_WIDTH = 1024; +std::shared_ptr<PluginAdapter> global_instance; } -PluginAdapter* PluginAdapter::_default = 0; - #define MAXIMIZABLE (CompWindowActionMaximizeHorzMask & CompWindowActionMaximizeVertMask & CompWindowActionResizeMask) #define MWM_HINTS_FUNCTIONS (1L << 0) @@ -44,20 +45,23 @@ PluginAdapter* PluginAdapter::_default = 0; #define MWM_HINTS_UNDECORATED_UNITY 0x80 #define _XA_MOTIF_WM_HINTS "_MOTIF_WM_HINTS" + +WindowManagerPtr create_window_manager() +{ + return global_instance; +} + /* static */ -PluginAdapter* -PluginAdapter::Default() +PluginAdapter& PluginAdapter::Default() { - if (!_default) - return 0; - return _default; + // Better hope that initialize has been called first. + return *global_instance; } /* static */ -void -PluginAdapter::Initialize(CompScreen* screen) +void PluginAdapter::Initialize(CompScreen* screen) { - _default = new PluginAdapter(screen); + global_instance.reset(new PluginAdapter(screen)); } PluginAdapter::PluginAdapter(CompScreen* screen) : @@ -82,10 +86,9 @@ PluginAdapter::~PluginAdapter() } /* A No-op for now, but could be useful later */ -void -PluginAdapter::OnScreenGrabbed() +void PluginAdapter::OnScreenGrabbed() { - compiz_screen_grabbed.emit(); + screen_grabbed.emit(); if (!_spread_state && screen->grabExist("scale")) { @@ -100,8 +103,7 @@ PluginAdapter::OnScreenGrabbed() } } -void -PluginAdapter::OnScreenUngrabbed() +void PluginAdapter::OnScreenUngrabbed() { if (_spread_state && !screen->grabExist("scale")) { @@ -116,58 +118,53 @@ PluginAdapter::OnScreenUngrabbed() terminate_expo.emit(); } - compiz_screen_ungrabbed.emit(); + screen_ungrabbed.emit(); } -void -PluginAdapter::NotifyResized(CompWindow* window, int x, int y, int w, int h) +void PluginAdapter::NotifyResized(CompWindow* window, int x, int y, int w, int h) { window_resized.emit(window->id()); } -void -PluginAdapter::NotifyMoved(CompWindow* window, int x, int y) +void PluginAdapter::NotifyMoved(CompWindow* window, int x, int y) { window_moved.emit(window->id()); } -void -PluginAdapter::NotifyStateChange(CompWindow* window, unsigned int state, unsigned int last_state) +void PluginAdapter::NotifyStateChange(CompWindow* window, unsigned int state, unsigned int last_state) { if (!((last_state & MAXIMIZE_STATE) == MAXIMIZE_STATE) && ((state & MAXIMIZE_STATE) == MAXIMIZE_STATE)) { - WindowManager::window_maximized.emit(window->id()); + window_maximized.emit(window->id()); } else if (((last_state & MAXIMIZE_STATE) == MAXIMIZE_STATE) && !((state & MAXIMIZE_STATE) == MAXIMIZE_STATE)) { - WindowManager::window_restored.emit(window->id()); + window_restored.emit(window->id()); } } -void -PluginAdapter::NotifyNewDecorationState(guint32 xid) +void PluginAdapter::NotifyNewDecorationState(Window xid) { - bool wasTracked = (_window_decoration_state.find (xid) != _window_decoration_state.end ()); + bool wasTracked = (_window_decoration_state.find(xid) != _window_decoration_state.end()); bool wasDecorated = false; if (wasTracked) wasDecorated = _window_decoration_state[xid]; - bool decorated = IsWindowDecorated (xid); + bool decorated = IsWindowDecorated(xid); if (decorated == wasDecorated) return; if (decorated && (!wasDecorated || !wasTracked)) - WindowManager::window_decorated.emit(xid); + window_decorated.emit(xid); else if (wasDecorated || !wasTracked) - WindowManager::window_undecorated.emit(xid); + window_undecorated.emit(xid); } -void -PluginAdapter::Notify(CompWindow* window, CompWindowNotify notify) +void PluginAdapter::Notify(CompWindow* window, CompWindowNotify notify) { switch (notify) { @@ -190,38 +187,36 @@ PluginAdapter::Notify(CompWindow* window, CompWindowNotify notify) window_shown.emit(window->id()); break; case CompWindowNotifyMap: - WindowManager::window_mapped.emit(window->id()); + window_mapped.emit(window->id()); break; case CompWindowNotifyUnmap: - WindowManager::window_unmapped.emit(window->id()); + window_unmapped.emit(window->id()); break; case CompWindowNotifyFocusChange: - WindowManager::window_focus_changed.emit(window->id()); + window_focus_changed.emit(window->id()); break; default: break; } } -void -PluginAdapter::NotifyCompizEvent(const char* plugin, const char* event, CompOption::Vector& option) +void PluginAdapter::NotifyCompizEvent(const char* plugin, + const char* event, + CompOption::Vector& option) { if (g_strcmp0(event, "start_viewport_switch") == 0) { _vp_switch_started = true; - compiz_screen_viewport_switch_started.emit(); + screen_viewport_switch_started.emit(); } else if (g_strcmp0(event, "end_viewport_switch") == 0) { _vp_switch_started = false; - compiz_screen_viewport_switch_ended.emit(); + screen_viewport_switch_ended.emit(); } - - compiz_event.emit(plugin, event, option); } -void -MultiActionList::AddNewAction(std::string const& name, CompAction* a, bool primary) +void MultiActionList::AddNewAction(std::string const& name, CompAction* a, bool primary) { actions_[name] = a; @@ -328,13 +323,9 @@ void MultiActionList::TerminateAll(CompOption::Vector const& extra_args) const } } -unsigned long long -PluginAdapter::GetWindowActiveNumber (guint32 xid) const +unsigned long long PluginAdapter::GetWindowActiveNumber(Window window_id) const { - Window win = xid; - CompWindow* window; - - window = m_Screen->findWindow(win); + CompWindow* window = m_Screen->findWindow(window_id); if (window) { @@ -349,33 +340,32 @@ PluginAdapter::GetWindowActiveNumber (guint32 xid) const return 0; } -void -PluginAdapter::SetExpoAction(MultiActionList& expo) +void PluginAdapter::SetExpoAction(MultiActionList& expo) { m_ExpoActionList = expo; } -void -PluginAdapter::SetScaleAction(MultiActionList& scale) +void PluginAdapter::SetScaleAction(MultiActionList& scale) { m_ScaleActionList = scale; } -std::string -PluginAdapter::MatchStringForXids(std::vector<Window> const& windows) +std::string PluginAdapter::MatchStringForXids(std::vector<Window> const& windows) { - std::string out_string = "any & ("; + std::ostringstream sout; - for (auto const& xid : windows) - out_string += "| xid=" + std::to_string(xid) + " "; + sout << "any & ("; - out_string += ")"; + for (auto const& window : windows) + { + sout << "| xid=" << window << " "; + } + sout << ")"; - return out_string; + return sout.str(); } -void -PluginAdapter::InitiateScale(std::string const& match, int state) +void PluginAdapter::InitiateScale(std::string const& match, int state) { CompOption::Vector argument(1); argument[0].setName("match", CompOption::TypeMatch); @@ -384,32 +374,27 @@ PluginAdapter::InitiateScale(std::string const& match, int state) m_ScaleActionList.InitiateAll(argument, state); } -void -PluginAdapter::TerminateScale() +void PluginAdapter::TerminateScale() { m_ScaleActionList.TerminateAll(); } -bool -PluginAdapter::IsScaleActive() const +bool PluginAdapter::IsScaleActive() const { return m_Screen->grabExist("scale"); } -bool -PluginAdapter::IsScaleActiveForGroup() const +bool PluginAdapter::IsScaleActiveForGroup() const { return _spread_windows_state && m_Screen->grabExist("scale"); } -bool -PluginAdapter::IsExpoActive() const +bool PluginAdapter::IsExpoActive() const { return m_Screen->grabExist("expo"); } -bool -PluginAdapter::IsWallActive() const +bool PluginAdapter::IsWallActive() const { return m_Screen->grabExist("wall"); } @@ -425,19 +410,14 @@ void PluginAdapter::TerminateExpo() } // WindowManager implementation -guint32 -PluginAdapter::GetActiveWindow() const +Window PluginAdapter::GetActiveWindow() const { return m_Screen->activeWindow(); } -bool -PluginAdapter::IsWindowMaximized(guint xid) const +bool PluginAdapter::IsWindowMaximized(Window window_id) const { - Window win = xid; - CompWindow* window; - - window = m_Screen->findWindow(win); + CompWindow* window = m_Screen->findWindow(window_id); if (window) { return ((window->state() & MAXIMIZE_STATE) == MAXIMIZE_STATE); @@ -446,12 +426,9 @@ PluginAdapter::IsWindowMaximized(guint xid) const return false; } -bool -PluginAdapter::IsWindowDecorated(guint32 xid) +bool PluginAdapter::IsWindowDecorated(Window window_id) const { Display* display = m_Screen->dpy(); - Window win = xid; - Atom hints_atom = None; MotifWmHints* hints = NULL; Atom type = None; gint format; @@ -459,9 +436,9 @@ PluginAdapter::IsWindowDecorated(guint32 xid) gulong bytes_after; bool ret = true; - hints_atom = XInternAtom(display, _XA_MOTIF_WM_HINTS, false); + Atom hints_atom = XInternAtom(display, _XA_MOTIF_WM_HINTS, false); - if (XGetWindowProperty(display, win, hints_atom, 0, + if (XGetWindowProperty(display, window_id, hints_atom, 0, sizeof(MotifWmHints) / sizeof(long), False, hints_atom, &type, &format, &nitems, &bytes_after, (guchar**)&hints) != Success) @@ -477,22 +454,20 @@ PluginAdapter::IsWindowDecorated(guint32 xid) hints->flags & MWM_HINTS_DECORATIONS) { /* Must have both bits set */ - _window_decoration_state[xid] = ret = - (hints->decorations & (MwmDecorAll | MwmDecorTitle)) || + ret = (hints->decorations & (MwmDecorAll | MwmDecorTitle)) || (hints->decorations & MWM_HINTS_UNDECORATED_UNITY); + // This is mildly evil and we should look for another solution. + PluginAdapter* non_const_this = const_cast<PluginAdapter*>(this); + non_const_this->_window_decoration_state[window_id] = ret; } XFree(hints); return ret; } -bool -PluginAdapter::IsWindowOnCurrentDesktop(guint32 xid) const +bool PluginAdapter::IsWindowOnCurrentDesktop(Window window_id) const { - Window win = xid; - CompWindow* window; - - window = m_Screen->findWindow(win); + CompWindow* window = m_Screen->findWindow(window_id); if (window) { // we aren't checking window->onCurrentDesktop (), as the name implies, because that is broken @@ -502,13 +477,9 @@ PluginAdapter::IsWindowOnCurrentDesktop(guint32 xid) const return false; } -bool -PluginAdapter::IsWindowObscured(guint32 xid) const +bool PluginAdapter::IsWindowObscured(Window window_id) const { - Window win = xid; - CompWindow* window; - - window = m_Screen->findWindow(win); + CompWindow* window = m_Screen->findWindow(window_id); if (window) { @@ -535,35 +506,26 @@ PluginAdapter::IsWindowObscured(guint32 xid) const return false; } -bool -PluginAdapter::IsWindowMapped(guint32 xid) const +bool PluginAdapter::IsWindowMapped(Window window_id) const { - Window win = xid; - CompWindow* window; - - window = m_Screen->findWindow(win); + CompWindow* window = m_Screen->findWindow(window_id); if (window) return window->mapNum () > 0; return true; } -bool -PluginAdapter::IsWindowVisible(guint32 xid) const +bool PluginAdapter::IsWindowVisible(Window window_id) const { - Window win = xid; - CompWindow* window; - - window = m_Screen->findWindow(win); + CompWindow* window = m_Screen->findWindow(window_id); if (window) return !(window->state() & CompWindowStateHiddenMask) && !window->inShowDesktopMode(); return false; } -bool -PluginAdapter::IsWindowOnTop(guint32 xid) const +bool PluginAdapter::IsWindowOnTop(Window window_id) const { - if (xid == GetTopMostValidWindowInViewport()) + if (window_id == GetTopMostValidWindowInViewport()) return true; return false; @@ -594,130 +556,91 @@ Window PluginAdapter::GetTopMostValidWindowInViewport() const return 0; } -bool -PluginAdapter::IsWindowClosable(guint32 xid) const +bool PluginAdapter::IsWindowClosable(Window window_id) const { - Window win = xid; - CompWindow* window; - - window = m_Screen->findWindow(win); + CompWindow* window = m_Screen->findWindow(window_id); if (window) return (window->actions() & CompWindowActionCloseMask); return false; } -bool -PluginAdapter::IsWindowMinimizable(guint32 xid) const +bool PluginAdapter::IsWindowMinimizable(Window window_id) const { - Window win = xid; - CompWindow* window; - - window = m_Screen->findWindow(win); + CompWindow* window = m_Screen->findWindow(window_id); if (window) return (window->actions() & CompWindowActionMinimizeMask); return false; } -bool -PluginAdapter::IsWindowMaximizable(guint32 xid) const +bool PluginAdapter::IsWindowMaximizable(Window window_id) const { - Window win = xid; - CompWindow* window; - - window = m_Screen->findWindow(win); + CompWindow* window = m_Screen->findWindow(window_id); if (window) return (window->actions() & MAXIMIZABLE); return false; } -void -PluginAdapter::Restore(guint32 xid) +void PluginAdapter::Restore(Window window_id) { - Window win = xid; - CompWindow* window; - - window = m_Screen->findWindow(win); + CompWindow* window = m_Screen->findWindow(window_id); if (window) window->maximize(0); } -void -PluginAdapter::RestoreAt(guint32 xid, int x, int y) +void PluginAdapter::RestoreAt(Window window_id, int x, int y) { - Window win = xid; - CompWindow* window; - - window = m_Screen->findWindow(win); + CompWindow* window = m_Screen->findWindow(window_id); if (window && (window->state() & MAXIMIZE_STATE)) { - nux::Geometry new_geo(GetWindowSavedGeometry(xid)); + nux::Geometry new_geo(GetWindowSavedGeometry(window_id)); new_geo.x = x; new_geo.y = y; window->maximize(0); - MoveResizeWindow(xid, new_geo); + MoveResizeWindow(window_id, new_geo); } } -void -PluginAdapter::Minimize(guint32 xid) +void PluginAdapter::Minimize(Window window_id) { - Window win = xid; - CompWindow* window; - - window = m_Screen->findWindow(win); + CompWindow* window = m_Screen->findWindow(window_id); if (window && (window->actions() & CompWindowActionMinimizeMask)) window->minimize(); } -void -PluginAdapter::Close(guint32 xid) +void PluginAdapter::Close(Window window_id) { - Window win = xid; - CompWindow* window; - - window = m_Screen->findWindow(win); + CompWindow* window = m_Screen->findWindow(window_id); if (window) window->close(CurrentTime); } -void -PluginAdapter::Activate(guint32 xid) +void PluginAdapter::Activate(Window window_id) { - Window win = xid; - CompWindow* window; - - window = m_Screen->findWindow(win); + CompWindow* window = m_Screen->findWindow(window_id); if (window) window->activate(); } -void -PluginAdapter::Raise(guint32 xid) +void PluginAdapter::Raise(Window window_id) { - Window win = xid; - CompWindow* window; - - window = m_Screen->findWindow(win); + CompWindow* window = m_Screen->findWindow(window_id); if (window) window->raise(); } -void -PluginAdapter::Lower(guint32 xid) +void PluginAdapter::Lower(Window window_id) { - Window win = xid; - CompWindow* window; - - window = m_Screen->findWindow(win); + CompWindow* window = m_Screen->findWindow(window_id); if (window) window->lower(); } -void -PluginAdapter::FocusWindowGroup(std::vector<Window> window_ids, FocusVisibility focus_visibility, int monitor, bool only_top_win) +void PluginAdapter::FocusWindowGroup(std::vector<Window> const& window_ids, + FocusVisibility focus_visibility, + int monitor, bool only_top_win) { CompPoint target_vp = m_Screen->vp(); CompWindow* top_window = nullptr; @@ -838,8 +761,7 @@ PluginAdapter::FocusWindowGroup(std::vector<Window> window_ids, FocusVisibility } } -bool -PluginAdapter::ScaleWindowGroup(std::vector<Window> windows, int state, bool force) +bool PluginAdapter::ScaleWindowGroup(std::vector<Window> const& windows, int state, bool force) { std::size_t num_windows = windows.size(); if (num_windows > 1 || (force && num_windows)) @@ -852,8 +774,7 @@ PluginAdapter::ScaleWindowGroup(std::vector<Window> windows, int state, bool for return false; } -void -PluginAdapter::SetWindowIconGeometry(Window window, nux::Geometry const& geo) +void PluginAdapter::SetWindowIconGeometry(Window window, nux::Geometry const& geo) { long data[4]; @@ -867,8 +788,7 @@ PluginAdapter::SetWindowIconGeometry(Window window, nux::Geometry const& geo) (unsigned char*) data, 4); } -void -PluginAdapter::ShowDesktop() +void PluginAdapter::ShowDesktop() { if (_in_show_desktop) { @@ -887,25 +807,22 @@ bool PluginAdapter::InShowDesktop() const return _in_show_desktop; } -void -PluginAdapter::OnShowDesktop() +void PluginAdapter::OnShowDesktop() { LOG_DEBUG(logger) << "Now in show desktop mode."; _in_show_desktop = true; } -void -PluginAdapter::OnLeaveDesktop() +void PluginAdapter::OnLeaveDesktop() { LOG_DEBUG(logger) << "No longer in show desktop mode."; _in_show_desktop = false; } -int -PluginAdapter::GetWindowMonitor(guint32 xid) const +int PluginAdapter::GetWindowMonitor(Window window_id) const { // FIXME, we should use window->outputDevice() but this is not UScreen friendly - nux::Geometry const& geo = GetWindowGeometry(xid); + nux::Geometry const& geo = GetWindowGeometry(window_id); if (!geo.IsNull()) { @@ -918,14 +835,10 @@ PluginAdapter::GetWindowMonitor(guint32 xid) const return -1; } -nux::Geometry -PluginAdapter::GetWindowGeometry(guint32 xid) const +nux::Geometry PluginAdapter::GetWindowGeometry(Window window_id) const { - Window win = xid; - CompWindow* window; nux::Geometry geo; - - window = m_Screen->findWindow(win); + CompWindow* window = m_Screen->findWindow(window_id); if (window) { geo.x = window->borderRect().x(); @@ -936,14 +849,10 @@ PluginAdapter::GetWindowGeometry(guint32 xid) const return geo; } -nux::Geometry -PluginAdapter::GetWindowSavedGeometry(guint32 xid) const +nux::Geometry PluginAdapter::GetWindowSavedGeometry(Window window_id) const { - Window win = xid; nux::Geometry geo(0, 0, 1, 1); - CompWindow* window; - - window = m_Screen->findWindow(win); + CompWindow* window = m_Screen->findWindow(window_id); if (window) { XWindowChanges &wc = window->saveWc(); @@ -956,37 +865,27 @@ PluginAdapter::GetWindowSavedGeometry(guint32 xid) const return geo; } -nux::Geometry -PluginAdapter::GetScreenGeometry() const +nux::Geometry PluginAdapter::GetScreenGeometry() const { - nux::Geometry geo; - - geo.x = 0; - geo.y = 0; - geo.width = m_Screen->width(); - geo.height = m_Screen->height(); - + nux::Geometry geo(0, 0, m_Screen->width(), m_Screen->height()); return geo; } -nux::Geometry -PluginAdapter::GetWorkAreaGeometry(guint32 xid) const +nux::Geometry PluginAdapter::GetWorkAreaGeometry(Window window_id) const { CompWindow* window = nullptr; unsigned int output = 0; - if (xid != 0) + if (window_id) { - Window win = xid; - - window = m_Screen->findWindow(win); + window = m_Screen->findWindow(window_id); if (window) { output = window->outputDevice(); } } - if (xid == 0 || !window) + if (window_id == 0 || !window) { output = m_Screen->currentOutputDev().id(); } @@ -996,8 +895,7 @@ PluginAdapter::GetWorkAreaGeometry(guint32 xid) const return nux::Geometry(workarea.x(), workarea.y(), workarea.width(), workarea.height()); } -bool -PluginAdapter::CheckWindowIntersection(nux::Geometry const& region, CompWindow* window) const +bool PluginAdapter::CheckWindowIntersection(nux::Geometry const& region, CompWindow* window) const { int intersect_types = CompWindowTypeNormalMask | CompWindowTypeDialogMask | CompWindowTypeModalDialogMask | CompWindowTypeUtilMask; @@ -1015,8 +913,7 @@ PluginAdapter::CheckWindowIntersection(nux::Geometry const& region, CompWindow* return false; } -void -PluginAdapter::CheckWindowIntersections (nux::Geometry const& region, bool &active, bool &any) +void PluginAdapter::CheckWindowIntersections(nux::Geometry const& region, bool &active, bool &any) { // prime to false so we can assume values later one active = false; @@ -1053,14 +950,12 @@ PluginAdapter::CheckWindowIntersections (nux::Geometry const& region, bool &acti } } -int -PluginAdapter::WorkspaceCount() const +int PluginAdapter::WorkspaceCount() const { return m_Screen->vpSize().width() * m_Screen->vpSize().height(); } -void -PluginAdapter::SetMwmWindowHints(Window xid, MotifWmHints* new_hints) +void PluginAdapter::SetMwmWindowHints(Window xid, MotifWmHints* new_hints) const { Display* display = m_Screen->dpy(); Atom hints_atom = None; @@ -1111,19 +1006,17 @@ PluginAdapter::SetMwmWindowHints(Window xid, MotifWmHints* new_hints) XFree(data); } -void -PluginAdapter::Decorate(guint32 xid) +void PluginAdapter::Decorate(Window window_id) const { MotifWmHints hints = { 0 }; hints.flags = MWM_HINTS_DECORATIONS; hints.decorations = GDK_DECOR_ALL & ~(MWM_HINTS_UNDECORATED_UNITY); - SetMwmWindowHints(xid, &hints); + SetMwmWindowHints(window_id, &hints); } -void -PluginAdapter::Undecorate(guint32 xid) +void PluginAdapter::Undecorate(Window window_id) const { MotifWmHints hints = { 0 }; @@ -1133,17 +1026,15 @@ PluginAdapter::Undecorate(guint32 xid) hints.flags = MWM_HINTS_DECORATIONS; hints.decorations = MWM_HINTS_UNDECORATED_UNITY; - SetMwmWindowHints(xid, &hints); + SetMwmWindowHints(window_id, &hints); } -bool -PluginAdapter::IsScreenGrabbed() const +bool PluginAdapter::IsScreenGrabbed() const { return m_Screen->grabbed(); } -bool -PluginAdapter::IsViewPortSwitchStarted() const +bool PluginAdapter::IsViewPortSwitchStarted() const { return _vp_switch_started; } @@ -1208,8 +1099,7 @@ bool PluginAdapter::MaximizeIfBigEnough(CompWindow* window) const return true; } -void -PluginAdapter::ShowGrabHandles(CompWindow* window, bool use_timer) +void PluginAdapter::ShowGrabHandles(CompWindow* window, bool use_timer) { if (!_grab_show_action || !window) return; @@ -1226,8 +1116,7 @@ PluginAdapter::ShowGrabHandles(CompWindow* window, bool use_timer) _grab_show_action->initiate()(_grab_show_action, 0, argument); } -void -PluginAdapter::HideGrabHandles(CompWindow* window) +void PluginAdapter::HideGrabHandles(CompWindow* window) { if (!_grab_hide_action || !window) return; @@ -1242,8 +1131,7 @@ PluginAdapter::HideGrabHandles(CompWindow* window) _grab_hide_action->initiate()(_grab_hide_action, 0, argument); } -void -PluginAdapter::ToggleGrabHandles(CompWindow* window) +void PluginAdapter::ToggleGrabHandles(CompWindow* window) { if (!_grab_toggle_action || !window) return; @@ -1258,14 +1146,12 @@ PluginAdapter::ToggleGrabHandles(CompWindow* window) _grab_toggle_action->initiate()(_grab_toggle_action, 0, argument); } -void -PluginAdapter::SetCoverageAreaBeforeAutomaximize(float area) +void PluginAdapter::SetCoverageAreaBeforeAutomaximize(float area) { _coverage_area_before_automaximize = area; } -bool -PluginAdapter::saveInputFocus() +bool PluginAdapter::SaveInputFocus() { Window active = m_Screen->activeWindow (); CompWindow* cw = m_Screen->findWindow (active); @@ -1279,8 +1165,7 @@ PluginAdapter::saveInputFocus() return false; } -bool -PluginAdapter::restoreInputFocus() +bool PluginAdapter::RestoreInputFocus() { if (_last_focused_window) { @@ -1297,11 +1182,10 @@ PluginAdapter::restoreInputFocus() return false; } -void -PluginAdapter::MoveResizeWindow(guint32 xid, nux::Geometry geometry) +void PluginAdapter::MoveResizeWindow(Window window_id, nux::Geometry geometry) { int w, h; - CompWindow* window = m_Screen->findWindow(xid); + CompWindow* window = m_Screen->findWindow(window_id); if (!window) return; @@ -1333,15 +1217,13 @@ PluginAdapter::MoveResizeWindow(guint32 xid, nux::Geometry geometry) window->configureXWindow(CWX | CWY | CWWidth | CWHeight, &xwc); } -void -PluginAdapter::OnWindowClosed(CompWindow *w) +void PluginAdapter::OnWindowClosed(CompWindow *w) { if (_last_focused_window == w) _last_focused_window = NULL; } -void -PluginAdapter::AddProperties(GVariantBuilder* builder) +void PluginAdapter::AddProperties(GVariantBuilder* builder) { unity::variant::BuilderWrapper wrapper(builder); wrapper.add(GetScreenGeometry()) @@ -1355,28 +1237,26 @@ PluginAdapter::AddProperties(GVariantBuilder* builder) .add("showdesktop_active", _in_show_desktop); } -std::string -PluginAdapter::GetWindowName(guint32 xid) const +std::string PluginAdapter::GetWindowName(Window window_id) const { std::string name; Atom visibleNameAtom; visibleNameAtom = XInternAtom(m_Screen->dpy(), "_NET_WM_VISIBLE_NAME", 0); - name = GetUtf8Property(xid, visibleNameAtom); + name = GetUtf8Property(window_id, visibleNameAtom); if (name.empty()) { Atom wmNameAtom = XInternAtom(m_Screen->dpy(), "_NET_WM_NAME", 0); - name = GetUtf8Property(xid, wmNameAtom); + name = GetUtf8Property(window_id, wmNameAtom); } if (name.empty()) - name = GetTextProperty(xid, XA_WM_NAME); + name = GetTextProperty(window_id, XA_WM_NAME); return name; } -std::string -PluginAdapter::GetUtf8Property(guint32 xid, Atom atom) const +std::string PluginAdapter::GetUtf8Property(Window window_id, Atom atom) const { Atom type; int result, format; @@ -1386,7 +1266,7 @@ PluginAdapter::GetUtf8Property(guint32 xid, Atom atom) const Atom utf8StringAtom; utf8StringAtom = XInternAtom(m_Screen->dpy(), "UTF8_STRING", 0); - result = XGetWindowProperty(m_Screen->dpy(), xid, atom, 0L, 65536, False, + result = XGetWindowProperty(m_Screen->dpy(), window_id, atom, 0L, 65536, False, utf8StringAtom, &type, &format, &nItems, &bytesAfter, reinterpret_cast<unsigned char **>(&val)); @@ -1403,21 +1283,22 @@ PluginAdapter::GetUtf8Property(guint32 xid, Atom atom) const return retval; } -std::string -PluginAdapter::GetTextProperty(guint32 id, Atom atom) const +std::string PluginAdapter::GetTextProperty(Window window_id, Atom atom) const { XTextProperty text; std::string retval; text.nitems = 0; - if (XGetTextProperty(m_Screen->dpy(), id, &text, atom)) + if (XGetTextProperty(m_Screen->dpy(), window_id, &text, atom)) { if (text.value) { retval = std::string(reinterpret_cast<char*>(text.value), text.nitems); - XFree (text.value); + XFree(text.value); } } return retval; } + +} // namespace unity diff --git a/unity-shared/PluginAdapter.h b/unity-shared/PluginAdapter.h index 06ce7ef33..7a3e69a0c 100644 --- a/unity-shared/PluginAdapter.h +++ b/unity-shared/PluginAdapter.h @@ -1,6 +1,6 @@ // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- /* - * Copyright (C) 2010 Canonical Ltd + * Copyright (C) 2010-2012 Canonical Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -17,16 +17,19 @@ * Authored by: Jason Smith <jason.smith@canonical.com> */ -#ifndef PLUGINADAPTER_H -#define PLUGINADAPTER_H +#ifndef UNITYSHARED_PLUGINADAPTER_H +#define UNITYSHARED_PLUGINADAPTER_H /* Compiz */ #include <core/core.h> #include <core/atoms.h> -#include <sigc++/sigc++.h> +#include <NuxCore/Property.h> -#include "WindowManager.h" +#include "XWindowManager.h" + +namespace unity +{ typedef struct { @@ -60,11 +63,12 @@ private: }; -class PluginAdapter : public sigc::trackable, public WindowManager +class PluginAdapter : public sigc::trackable, public XWindowManager { public: - static PluginAdapter* Default(); - + // You shouldn't get the PluginAdapter if you really want a WindowManager. + // The PluginAdapter::Default should really only be called from within unityshell plugin. + static PluginAdapter& Default(); static void Initialize(CompScreen* screen); nux::Property<bool> bias_active_to_viewport; @@ -113,54 +117,56 @@ public: void NotifyResized(CompWindow* window, int x, int y, int w, int h); void NotifyStateChange(CompWindow* window, unsigned int state, unsigned int last_state); void NotifyCompizEvent(const char* plugin, const char* event, CompOption::Vector& option); - void NotifyNewDecorationState(guint32 xid); + void NotifyNewDecorationState(Window xid); - guint32 GetActiveWindow() const; + Window GetActiveWindow() const; - void Decorate(guint32 xid); - void Undecorate(guint32 xid); + void Decorate(Window xid) const; + void Undecorate(Window xid) const; // WindowManager implementation - bool IsWindowMaximized(guint xid) const; - bool IsWindowDecorated(guint xid); - bool IsWindowOnCurrentDesktop(guint xid) const; - bool IsWindowObscured(guint xid) const; - bool IsWindowMapped(guint xid) const; - bool IsWindowVisible(guint32 xid) const; - bool IsWindowOnTop(guint32 xid) const; - bool IsWindowClosable(guint32 xid) const; - bool IsWindowMinimizable(guint32 xid) const; - bool IsWindowMaximizable(guint32 xid) const; - - void Restore(guint32 xid); - void RestoreAt(guint32 xid, int x, int y); - void Minimize(guint32 xid); - void Close(guint32 xid); - void Activate(guint32 xid); - void Raise(guint32 xid); - void Lower(guint32 xid); + bool IsWindowMaximized(Window window_id) const; + bool IsWindowDecorated(Window window_id) const; + bool IsWindowOnCurrentDesktop(Window window_id) const; + bool IsWindowObscured(Window window_id) const; + bool IsWindowMapped(Window window_id) const; + bool IsWindowVisible(Window window_id) const; + bool IsWindowOnTop(Window window_id) const; + bool IsWindowClosable(Window window_id) const; + bool IsWindowMinimizable(Window window_id) const; + bool IsWindowMaximizable(Window window_id) const; + + void Restore(Window window_id); + void RestoreAt(Window window_id, int x, int y); + void Minimize(Window window_id); + void Close(Window window_id); + void Activate(Window window_id); + void Raise(Window window_id); + void Lower(Window window_id); void ShowDesktop(); bool InShowDesktop() const; void SetWindowIconGeometry(Window window, nux::Geometry const& geo); - void FocusWindowGroup(std::vector<Window> windows, FocusVisibility, int monitor = -1, bool only_top_win = true); - bool ScaleWindowGroup(std::vector<Window> windows, int state, bool force); + void FocusWindowGroup(std::vector<Window> const& windows, + FocusVisibility, int monitor = -1, bool only_top_win = true); + bool ScaleWindowGroup(std::vector<Window> const& windows, + int state, bool force); bool IsScreenGrabbed() const; bool IsViewPortSwitchStarted() const; - unsigned long long GetWindowActiveNumber (guint32 xid) const; + unsigned long long GetWindowActiveNumber(Window window_id) const; bool MaximizeIfBigEnough(CompWindow* window) const; - int GetWindowMonitor(guint32 xid) const; - nux::Geometry GetWindowGeometry(guint32 xid) const; - nux::Geometry GetWindowSavedGeometry(guint32 xid) const; + int GetWindowMonitor(Window window_id) const; + nux::Geometry GetWindowGeometry(Window window_id) const; + nux::Geometry GetWindowSavedGeometry(Window window_id) const; nux::Geometry GetScreenGeometry() const; - nux::Geometry GetWorkAreaGeometry(guint32 xid = 0) const; - std::string GetWindowName(guint32 xid) const; + nux::Geometry GetWorkAreaGeometry(Window window_id = 0) const; + std::string GetWindowName(Window window_id) const; void CheckWindowIntersections(nux::Geometry const& region, bool &active, bool &any); @@ -168,10 +174,10 @@ public: void SetCoverageAreaBeforeAutomaximize(float area); - bool saveInputFocus (); - bool restoreInputFocus (); + bool SaveInputFocus(); + bool RestoreInputFocus(); - void MoveResizeWindow(guint32 xid, nux::Geometry geometry); + void MoveResizeWindow(Window window_id, nux::Geometry geometry); protected: PluginAdapter(CompScreen* screen); @@ -182,12 +188,12 @@ private: void InitiateScale(std::string const& match, int state = 0); bool CheckWindowIntersection(nux::Geometry const& region, CompWindow* window) const; - void SetMwmWindowHints(Window xid, MotifWmHints* new_hints); + void SetMwmWindowHints(Window xid, MotifWmHints* new_hints) const; Window GetTopMostValidWindowInViewport() const; - std::string GetTextProperty(guint32 xid, Atom atom) const; - std::string GetUtf8Property(guint32 xid, Atom atom) const; + std::string GetTextProperty(Window xid, Atom atom) const; + std::string GetUtf8Property(Window xid, Atom atom) const; CompScreen* m_Screen; MultiActionList m_ExpoActionList; @@ -207,9 +213,9 @@ private: bool _in_show_desktop; CompWindow* _last_focused_window; - std::map<guint32, unsigned int> _window_decoration_state; - - static PluginAdapter* _default; + std::map<Window, unsigned int> _window_decoration_state; }; +} + #endif diff --git a/unity-shared/PluginAdapterStandalone.cpp b/unity-shared/PluginAdapterStandalone.cpp deleted file mode 100644 index b457c57d6..000000000 --- a/unity-shared/PluginAdapterStandalone.cpp +++ /dev/null @@ -1,491 +0,0 @@ -// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- -/* - * Copyright (C) 2010 Canonical Ltd - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 3 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * Authored by: Jason Smith <jason.smith@canonical.com> - */ - -#include <glib.h> -#include <sstream> -#include "PluginAdapter.h" -#include "UScreen.h" - -#include <NuxCore/Logger.h> -#include <UnityCore/Variant.h> - -//FIXME!! Entirely stubs for now, unless we need this functionality at some point - -namespace -{ -nux::logging::Logger logger("unity.plugin"); -} - -PluginAdapter* PluginAdapter::_default = 0; - -/* static */ -PluginAdapter* -PluginAdapter::Default() -{ - if (!_default) - return 0; - return _default; -} - -/* static */ -void -PluginAdapter::Initialize(CompScreen* screen) -{ - _default = new PluginAdapter(screen); -} - -PluginAdapter::PluginAdapter(CompScreen* screen) - : m_Screen(screen) - , _expo_state(false) - , _in_show_desktop(false) - , _last_focused_window(nullptr) -{ -} - -PluginAdapter::~PluginAdapter() -{ -} - -/* A No-op for now, but could be useful later */ -void -PluginAdapter::OnScreenGrabbed() -{ -} - -void -PluginAdapter::OnScreenUngrabbed() -{ -} - -void -PluginAdapter::NotifyResized(CompWindow* window, int x, int y, int w, int h) -{ -} - -void -PluginAdapter::NotifyMoved(CompWindow* window, int x, int y) -{ -} - -void -PluginAdapter::NotifyStateChange(CompWindow* window, unsigned int state, unsigned int last_state) -{ -} - -void -PluginAdapter::NotifyNewDecorationState(guint32 xid) -{ -} - -void -PluginAdapter::Notify(CompWindow* window, CompWindowNotify notify) -{ -} - -void -PluginAdapter::NotifyCompizEvent(const char* plugin, const char* event, CompOption::Vector& option) -{ -} - -void -MultiActionList::AddNewAction(std::string const& n, CompAction* a, bool primary) -{ -} - -void -MultiActionList::RemoveAction(std::string const& n) -{ -} - -void -MultiActionList::InitiateAll(CompOption::Vector const& extraArgs, int state) const -{ -} - -void -MultiActionList::TerminateAll(CompOption::Vector const& extraArgs) const -{ -} - -bool -MultiActionList::HasPrimary() const -{ - return false; -} - -CompAction* -MultiActionList::GetAction(std::string const& name) const -{ - return nullptr; -} - - -unsigned long long -PluginAdapter::GetWindowActiveNumber (guint32 xid) const -{ - return 0; -} - -void -PluginAdapter::SetExpoAction(MultiActionList& expo) -{ -} - -void -PluginAdapter::SetScaleAction(MultiActionList& scale) -{ -} - -std::string -PluginAdapter::MatchStringForXids(std::vector<Window> const& windows) -{ - return ""; -} - -void -PluginAdapter::InitiateScale(std::string const& match, int state) -{ -} - -void -PluginAdapter::TerminateScale() -{ -} - -bool -PluginAdapter::IsScaleActive() const -{ - return false; -} - -bool -PluginAdapter::IsScaleActiveForGroup() const -{ - return false; -} - -bool -PluginAdapter::IsExpoActive() const -{ - return _expo_state; -} - -void -PluginAdapter::InitiateExpo() -{ - _expo_state = true; -} - -void -PluginAdapter::TerminateExpo() -{ - _expo_state = false; -} - -bool -PluginAdapter::IsWallActive() const -{ - return false; -} - -// WindowManager implementation -guint32 -PluginAdapter::GetActiveWindow() const -{ - return 0; -} - -bool -PluginAdapter::IsWindowMaximized(guint xid) const -{ - return false; -} - -bool -PluginAdapter::IsWindowDecorated(guint32 xid) -{ - return false; -} - -bool -PluginAdapter::IsWindowOnCurrentDesktop(guint32 xid) const -{ - return false; -} - -bool -PluginAdapter::IsWindowObscured(guint32 xid) const -{ - return false; -} - -bool -PluginAdapter::IsWindowMapped(guint32 xid) const -{ - return false; -} - -bool -PluginAdapter::IsWindowVisible(guint32 xid) const -{ - return false; -} - -bool -PluginAdapter::IsWindowOnTop(guint32 xid) const -{ - return false; -} - -bool -PluginAdapter::IsWindowClosable(guint32 xid) const -{ - return false; -} - -bool -PluginAdapter::IsWindowMinimizable(guint32 xid) const -{ - return false; -} - -bool -PluginAdapter::IsWindowMaximizable(guint32 xid) const -{ - return false; -} - -void -PluginAdapter::Restore(guint32 xid) -{ -} - -void -PluginAdapter::RestoreAt(guint32 xid, int x, int y) -{ -} - -void -PluginAdapter::Minimize(guint32 xid) -{ -} - -void -PluginAdapter::Close(guint32 xid) -{ -} - -void -PluginAdapter::Activate(guint32 xid) -{ -} - -void -PluginAdapter::Raise(guint32 xid) -{ -} - -void -PluginAdapter::Lower(guint32 xid) -{ -} - -void -PluginAdapter::FocusWindowGroup(std::vector<Window> window_ids, FocusVisibility focus_visibility, int monitor, bool only_top_win) -{ -} - -bool -PluginAdapter::ScaleWindowGroup(std::vector<Window> windows, int state, bool force) -{ - return false; -} - -void -PluginAdapter::SetWindowIconGeometry(Window window, nux::Geometry const& geo) -{ -} - -void -PluginAdapter::ShowDesktop() -{ - _in_show_desktop = !_in_show_desktop; -} - -bool PluginAdapter::InShowDesktop() const -{ - return _in_show_desktop; -} - -void -PluginAdapter::OnShowDesktop() -{ -} - -void -PluginAdapter::OnLeaveDesktop() -{ -} - -int -PluginAdapter::GetWindowMonitor(guint32 xid) const -{ - return -1; -} - -nux::Geometry -PluginAdapter::GetWindowGeometry(guint32 xid) const -{ - nux::Geometry geo(0, 0, 1, 1); - return geo; -} - -nux::Geometry -PluginAdapter::GetWindowSavedGeometry(guint32 xid) const -{ - nux::Geometry geo(0, 0, 1, 1); - return geo; -} - -nux::Geometry -PluginAdapter::GetScreenGeometry() const -{ - nux::Geometry geo(0, 0, 1, 1); - return geo; -} - -nux::Geometry -PluginAdapter::GetWorkAreaGeometry(guint32 xid) const -{ - nux::Geometry geo(0, 0, 1, 1); - return geo; -} - -bool -PluginAdapter::CheckWindowIntersection(nux::Geometry const& region, CompWindow* window) const -{ - return false; -} - -void -PluginAdapter::CheckWindowIntersections (nux::Geometry const& region, bool &active, bool &any) -{ -} - -int -PluginAdapter::WorkspaceCount() const -{ - return 4; -} - -void -PluginAdapter::SetMwmWindowHints(Window xid, MotifWmHints* new_hints) -{ -} - -void -PluginAdapter::Decorate(guint32 xid) -{ -} - -void -PluginAdapter::Undecorate(guint32 xid) -{ -} - -bool -PluginAdapter::IsScreenGrabbed() const -{ - return false; -} - -bool -PluginAdapter::IsViewPortSwitchStarted() const -{ - return false; -} - -/* Returns true if the window was maximized */ -bool PluginAdapter::MaximizeIfBigEnough(CompWindow* window) const -{ - return true; -} - -void -PluginAdapter::ShowGrabHandles(CompWindow* window, bool use_timer) -{ -} - -void -PluginAdapter::HideGrabHandles(CompWindow* window) -{ -} - -void -PluginAdapter::ToggleGrabHandles(CompWindow* window) -{ -} - -void -PluginAdapter::SetCoverageAreaBeforeAutomaximize(float area) -{ -} - -bool -PluginAdapter::saveInputFocus() -{ - return false; -} - -bool -PluginAdapter::restoreInputFocus() -{ - return false; -} - -void -PluginAdapter::MoveResizeWindow(guint32 xid, nux::Geometry geometry) -{ -} - -void -PluginAdapter::OnWindowClosed(CompWindow *w) -{ -} - -void -PluginAdapter::AddProperties(GVariantBuilder* builder) -{ - unity::variant::BuilderWrapper wrapper(builder); - wrapper.add(GetScreenGeometry()) - .add("workspace_count", WorkspaceCount()) - .add("active_window", GetActiveWindow()) - .add("screen_grabbed", IsScreenGrabbed()) - .add("scale_active", IsScaleActive()) - .add("scale_active_for_group", IsScaleActiveForGroup()) - .add("expo_active", IsExpoActive()) - .add("viewport_switch_running", IsViewPortSwitchStarted()) - .add("showdesktop_active", _in_show_desktop); -} - -std::string -PluginAdapter::GetWindowName(guint32 xid) const -{ - return ""; -} diff --git a/unity-shared/StandaloneWindowManager.cpp b/unity-shared/StandaloneWindowManager.cpp new file mode 100644 index 000000000..bc3902c25 --- /dev/null +++ b/unity-shared/StandaloneWindowManager.cpp @@ -0,0 +1,274 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2010-2012 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authored by: Jason Smith <jason.smith@canonical.com> + * Tim Penhey <tim.penhey@canonical.com> + */ + +#include <glib.h> +#include <sstream> +#include "StandaloneWindowManager.h" +#include "UScreen.h" + +#include <NuxCore/Logger.h> +#include <UnityCore/Variant.h> + +// Entirely stubs for now, unless we need this functionality at some point + +namespace unity +{ + +namespace +{ +nux::logging::Logger logger("unity.wm"); +} + +WindowManagerPtr create_window_manager() +{ + return WindowManagerPtr(new StandaloneWindowManager); +} + +StandaloneWindowManager::StandaloneWindowManager() + : expo_state_(false) + , in_show_desktop_(false) +{ +} + +Window StandaloneWindowManager::GetActiveWindow() const +{ + return 0; +} + +bool StandaloneWindowManager::IsWindowMaximized(Window window_id) const +{ + return false; +} + +bool StandaloneWindowManager::IsWindowDecorated(Window window_id) const +{ + return false; +} + +bool StandaloneWindowManager::IsWindowOnCurrentDesktop(Window window_id) const +{ + return false; +} + +bool StandaloneWindowManager::IsWindowObscured(Window window_id) const +{ + return false; +} + +bool StandaloneWindowManager::IsWindowMapped(Window window_id) const +{ + return false; +} + +bool StandaloneWindowManager::IsWindowVisible(Window window_id) const +{ + return false; +} + +bool StandaloneWindowManager::IsWindowOnTop(Window window_id) const +{ + return false; +} + +bool StandaloneWindowManager::IsWindowClosable(Window window_id) const +{ + return false; +} + +bool StandaloneWindowManager::IsWindowMinimizable(Window window_id) const +{ + return false; +} + +bool StandaloneWindowManager::IsWindowMaximizable(Window window_id) const +{ + return false; +} + +void StandaloneWindowManager::ShowDesktop() +{ + in_show_desktop_ = !in_show_desktop_; +} + +bool StandaloneWindowManager::InShowDesktop() const +{ + return in_show_desktop_; +} + +void StandaloneWindowManager::Restore(Window window_id) +{} + +void StandaloneWindowManager::RestoreAt(Window window_id, int x, int y) +{} + +void StandaloneWindowManager::Minimize(Window window_id) +{} + +void StandaloneWindowManager::Close(Window window_id) +{} + +void StandaloneWindowManager::Activate(Window window_id) +{} + +void StandaloneWindowManager::Raise(Window window_id) +{} + +void StandaloneWindowManager::Lower(Window window_id) +{} + +void StandaloneWindowManager::TerminateScale() +{} + +bool StandaloneWindowManager::IsScaleActive() const +{ + return false; +} + +bool StandaloneWindowManager::IsScaleActiveForGroup() const +{ + return false; +} + +void StandaloneWindowManager::InitiateExpo() +{ + expo_state_ = !expo_state_; +} + +void StandaloneWindowManager::TerminateExpo() +{ + expo_state_ = false; +} + +bool StandaloneWindowManager::IsExpoActive() const +{ + return expo_state_; +} + +bool StandaloneWindowManager::IsWallActive() const +{ + return false; +} + +void StandaloneWindowManager::FocusWindowGroup(std::vector<Window> const& windows, + FocusVisibility, + int monitor, + bool only_top_win) +{} + +bool StandaloneWindowManager::ScaleWindowGroup(std::vector<Window> const& windows, + int state, bool force) +{ + return false; +} + +bool StandaloneWindowManager::IsScreenGrabbed() const +{ + return false; +} + +bool StandaloneWindowManager::IsViewPortSwitchStarted() const +{ + return false; +} + +void StandaloneWindowManager::MoveResizeWindow(Window window_id, nux::Geometry geometry) +{} + +void StandaloneWindowManager::StartMove(Window window_id, int x, int y) +{} + +int StandaloneWindowManager::GetWindowMonitor(Window window_id) const +{ + return -1; +} + +nux::Geometry StandaloneWindowManager::GetWindowGeometry(Window window_id) const +{ + nux::Geometry geo(0, 0, 1, 1); + return geo; +} + +nux::Geometry StandaloneWindowManager::GetWindowSavedGeometry(Window window_id) const +{ + nux::Geometry geo(0, 0, 1, 1); + return geo; +} + +nux::Geometry StandaloneWindowManager::GetScreenGeometry() const +{ + nux::Geometry geo(0, 0, 1, 1); + return geo; +} + +nux::Geometry StandaloneWindowManager::GetWorkAreaGeometry(Window window_id) const +{ + nux::Geometry geo(0, 0, 1, 1); + return geo; +} + +unsigned long long StandaloneWindowManager::GetWindowActiveNumber(Window window_id) const +{ + return 0; +} + +void StandaloneWindowManager::SetWindowIconGeometry(Window window, nux::Geometry const& geo) +{ +} + +void StandaloneWindowManager::CheckWindowIntersections(nux::Geometry const& region, + bool &active, bool &any) +{ +} + +int StandaloneWindowManager::WorkspaceCount() const +{ + return 4; +} + +bool StandaloneWindowManager::SaveInputFocus() +{ + return false; +} + +bool StandaloneWindowManager::RestoreInputFocus() +{ + return false; +} + +std::string StandaloneWindowManager::GetWindowName(Window window_id) const +{ + return ""; +} + +void StandaloneWindowManager::AddProperties(GVariantBuilder* builder) +{ + unity::variant::BuilderWrapper wrapper(builder); + wrapper.add(GetScreenGeometry()) + .add("workspace_count", WorkspaceCount()) + .add("active_window", GetActiveWindow()) + .add("screen_grabbed", IsScreenGrabbed()) + .add("scale_active", IsScaleActive()) + .add("scale_active_for_group", IsScaleActiveForGroup()) + .add("expo_active", IsExpoActive()) + .add("viewport_switch_running", IsViewPortSwitchStarted()) + .add("showdesktop_active", in_show_desktop_); +} + +} // namespace unity diff --git a/unity-shared/StandaloneWindowManager.h b/unity-shared/StandaloneWindowManager.h new file mode 100644 index 000000000..636e3c580 --- /dev/null +++ b/unity-shared/StandaloneWindowManager.h @@ -0,0 +1,108 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2012 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authored by: Tim Penhey <tim.penhey@canonical.com> + */ + +#ifndef UNITYSHARED_STANDALONE_WINDOW_MANAGER_H +#define UNITYSHARED_STANDALONE_WINDOW_MANAGER_H + +#include "unity-shared/WindowManager.h" + +namespace unity +{ + +class StandaloneWindowManager : public WindowManager +{ +public: + StandaloneWindowManager(); + + virtual Window GetActiveWindow() const; + + virtual bool IsWindowMaximized(Window window_id) const; + virtual bool IsWindowDecorated(Window window_id) const; + virtual bool IsWindowOnCurrentDesktop(Window window_id) const; + virtual bool IsWindowObscured(Window window_id) const; + virtual bool IsWindowMapped(Window window_id) const; + virtual bool IsWindowVisible(Window window_id) const; + virtual bool IsWindowOnTop(Window window_id) const; + virtual bool IsWindowClosable(Window window_id) const; + virtual bool IsWindowMinimizable(Window window_id) const; + virtual bool IsWindowMaximizable(Window window_id) const; + + virtual void ShowDesktop(); + virtual bool InShowDesktop() const; + + virtual void Restore(Window window_id); + virtual void RestoreAt(Window window_id, int x, int y); + virtual void Minimize(Window window_id); + virtual void Close(Window window_id); + + virtual void Activate(Window window_id); + virtual void Raise(Window window_id); + virtual void Lower(Window window_id); + + virtual void TerminateScale(); + virtual bool IsScaleActive() const; + virtual bool IsScaleActiveForGroup() const; + + virtual void InitiateExpo(); + virtual void TerminateExpo(); + virtual bool IsExpoActive() const; + + virtual bool IsWallActive() const; + + virtual void FocusWindowGroup(std::vector<Window> const& windows, + FocusVisibility, int monitor = -1, bool only_top_win = true); + virtual bool ScaleWindowGroup(std::vector<Window> const& windows, + int state, bool force); + + virtual bool IsScreenGrabbed() const; + virtual bool IsViewPortSwitchStarted() const; + + virtual void MoveResizeWindow(Window window_id, nux::Geometry geometry); + virtual void StartMove(Window window_id, int x, int y); + + virtual int GetWindowMonitor(Window window_id) const; + virtual nux::Geometry GetWindowGeometry(Window window_id) const; + virtual nux::Geometry GetWindowSavedGeometry(Window window_id) const; + virtual nux::Geometry GetScreenGeometry() const; + virtual nux::Geometry GetWorkAreaGeometry(Window window_id) const; + + virtual unsigned long long GetWindowActiveNumber(Window window_id) const; + + virtual void SetWindowIconGeometry(Window window, nux::Geometry const& geo); + + virtual void CheckWindowIntersections (nux::Geometry const& region, bool &active, bool &any); + + virtual int WorkspaceCount() const; + + virtual bool SaveInputFocus(); + virtual bool RestoreInputFocus(); + + virtual std::string GetWindowName(Window window_id) const; + +protected: + virtual void AddProperties(GVariantBuilder* builder); + +private: + bool expo_state_; + bool in_show_desktop_; +}; + +} + +#endif // UNITYSHARED_WINDOW_MANAGER_H diff --git a/unity-shared/StaticCairoText.cpp b/unity-shared/StaticCairoText.cpp index 33cea145c..e8d9a77fc 100644 --- a/unity-shared/StaticCairoText.cpp +++ b/unity-shared/StaticCairoText.cpp @@ -32,10 +32,6 @@ #include <pango/pango.h> #include <pango/pangocairo.h> -#if defined(NUX_OS_LINUX) -#include <X11/Xlib.h> -#endif - #include <UnityCore/GLibWrapper.h> #include "CairoTexture.h" @@ -303,11 +299,6 @@ void StaticCairoText::DrawContent(GraphicsEngine& gfxContext, bool forceDraw) // intentionally left empty } -void StaticCairoText::PostDraw(GraphicsEngine& gfxContext, bool forceDraw) -{ - // intentionally left empty -} - void StaticCairoText::SetText(std::string const& text, bool escape_text) { std::string tmp_text = escape_text ? GetEscapedText(text) : text; diff --git a/unity-shared/StaticCairoText.h b/unity-shared/StaticCairoText.h index cf6bed37c..683afac77 100644 --- a/unity-shared/StaticCairoText.h +++ b/unity-shared/StaticCairoText.h @@ -65,9 +65,6 @@ public: void DrawContent(GraphicsEngine& gfxContext, bool forceDraw); - void PostDraw(GraphicsEngine& gfxContext, - bool forceDraw); - // public API void SetText(std::string const& text, bool escape_text = false); void SetTextColor(Color const& textColor); diff --git a/unity-shared/UnityWindowView.cpp b/unity-shared/UnityWindowView.cpp index 99b2c28a9..6b6a8a920 100644 --- a/unity-shared/UnityWindowView.cpp +++ b/unity-shared/UnityWindowView.cpp @@ -148,8 +148,6 @@ void UnityWindowView::DrawContent(nux::GraphicsEngine& GfxContext, bool force_dr GfxContext.PopClippingRectangle(); DrawBackground(GfxContext, background_geo); - - PostDraw(GfxContext, force_draw); } void UnityWindowView::DrawBackground(nux::GraphicsEngine& GfxContext, nux::Geometry const& geo) diff --git a/unity-shared/UnityWindowView.h b/unity-shared/UnityWindowView.h index 439c022f4..a5c08c626 100644 --- a/unity-shared/UnityWindowView.h +++ b/unity-shared/UnityWindowView.h @@ -51,7 +51,6 @@ protected: virtual void PreDraw(nux::GraphicsEngine& GfxContext, bool force_draw) {}; virtual void DrawOverlay(nux::GraphicsEngine& GfxContext, bool force_draw, nux::Geometry clip) = 0; - virtual void PostDraw(nux::GraphicsEngine& GfxContext, bool force_draw) {}; virtual nux::Geometry GetBackgroundGeometry() = 0; // Introspectable methods diff --git a/unity-shared/WindowManager.cpp b/unity-shared/WindowManager.cpp index dc09eeeff..4caa81406 100644 --- a/unity-shared/WindowManager.cpp +++ b/unity-shared/WindowManager.cpp @@ -19,257 +19,19 @@ #include "WindowManager.h" -static WindowManager* window_manager = NULL; - -class WindowManagerDummy : public WindowManager +namespace unity { - guint32 GetActiveWindow() const - { - return 0; - } - - unsigned long long GetWindowActiveNumber (guint32 xid) const - { - return 0; - } - - bool IsScreenGrabbed() const - { - return false; - } - - bool IsViewPortSwitchStarted() const - { - return false; - } - - void ShowDesktop() - { - g_debug("%s", G_STRFUNC); - } - - bool InShowDesktop() const - { - return false; - } - - bool IsWindowMaximized(guint32 xid) const - { - return false; - } - - bool IsWindowDecorated(guint32 xid) - { - return true; - } - - bool IsWindowOnCurrentDesktop(guint32 xid) const - { - return true; - } - - bool IsWindowObscured(guint32 xid) const - { - return false; - } - - bool IsWindowMapped(guint32 xid) const - { - return true; - } - - bool IsWindowVisible(guint32 xid) const - { - return true; - } - - bool IsWindowOnTop(guint32 xid) const - { - return false; - } - - bool IsWindowClosable(guint32 xid) const - { - return true; - } - - bool IsWindowMinimizable(guint32 xid) const - { - return true; - } - - bool IsWindowMaximizable(guint32 xid) const - { - return true; - } - - void Restore(guint32 xid) - { - g_debug("%s", G_STRFUNC); - } - - void RestoreAt(guint32 xid, int x, int y) - { - g_debug("%s", G_STRFUNC); - } - - void Minimize(guint32 xid) - { - g_debug("%s", G_STRFUNC); - } - - void Close(guint32 xid) - { - g_debug("%s", G_STRFUNC); - } - - void Activate(guint32 xid) - { - g_debug("%s", G_STRFUNC); - } - - void Raise(guint32 xid) - { - g_debug("%s", G_STRFUNC); - } - - void Lower(guint32 xid) - { - g_debug("%s", G_STRFUNC); - } - - void FocusWindowGroup(std::vector<Window> windows, FocusVisibility, int monitor, bool only_top_win) - { - g_debug("%s", G_STRFUNC); - } - - bool ScaleWindowGroup(std::vector<Window> windows, int state, bool force) - { - g_debug("%s", G_STRFUNC); - return false; - } - - int GetWindowMonitor(guint32 xid) const - { - return -1; - } - - nux::Geometry GetWindowGeometry(guint xid) const - { - int width = (guint32)xid >> 16; - int height = (guint32)xid & 0x0000FFFF; - return nux::Geometry(0, 0, width, height); - } - - nux::Geometry GetWindowSavedGeometry(guint xid) const - { - return nux::Geometry(0, 0, 1, 1); - } - - nux::Geometry GetScreenGeometry() const - { - return nux::Geometry(0, 0, 1, 1); - } - - nux::Geometry GetWorkAreaGeometry(guint32 xid) const - { - return nux::Geometry(0, 0, 1, 1); - } - - void SetWindowIconGeometry(Window window, nux::Geometry const& geo) - { - g_debug("%s", G_STRFUNC); - } - - void CheckWindowIntersections (nux::Geometry const& region, bool &active, bool &any) - { - active = false; - any = false; - } - - int WorkspaceCount () const - { - return 1; - } - - void TerminateScale() - { - g_debug("%s", G_STRFUNC); - } - - bool IsScaleActive() const - { - g_debug("%s", G_STRFUNC); - return false; - } - - bool IsScaleActiveForGroup() const - { - g_debug("%s", G_STRFUNC); - return false; - } - - void InitiateExpo() - { - g_debug("%s", G_STRFUNC); - } - - void TerminateExpo() - { - g_debug("%s", G_STRFUNC); - } - - bool IsExpoActive() const - { - g_debug("%s", G_STRFUNC); - return false; - } - - bool IsWallActive() const - { - g_debug("%s", G_STRFUNC); - return false; - } - - void MoveResizeWindow(guint32 xid, nux::Geometry geometry) - { - g_debug("%s", G_STRFUNC); - } - - bool saveInputFocus() - { - return false; - } - - bool restoreInputFocus() - { - return false; - } - - - void AddProperties(GVariantBuilder* builder) - { - } - - std::string GetWindowName(guint32 xid) const - { - return "unknown"; - } -}; - -WindowManager* -WindowManager::Default() +namespace { - if (!window_manager) - window_manager = new WindowManagerDummy(); - - return window_manager; +WindowManagerPtr window_manager; } -void -WindowManager::SetDefault(WindowManager* manager) +WindowManager& WindowManager::Default() { - window_manager = manager; + if (!window_manager) + window_manager = create_window_manager(); + + return *window_manager; } std::string WindowManager::GetName() const @@ -277,61 +39,4 @@ std::string WindowManager::GetName() const return "WindowManager"; } -#define NET_WM_MOVERESIZE_MOVE 8 - -void WindowManager::StartMove(guint32 xid, int x, int y) -{ - if (x < 0 || y < 0) - return; - - XEvent ev; - Display* d = nux::GetGraphicsDisplay()->GetX11Display(); - - /* We first need to ungrab the pointer. FIXME: Evil */ - - XUngrabPointer(d, CurrentTime); - - // -------------------------------------------------------------------------- - // FIXME: This is a workaround until the non-paired events issue is fixed in - // nux - XButtonEvent bev = - { - ButtonRelease, - 0, - False, - d, - 0, - 0, - 0, - CurrentTime, - x, y, - x, y, - 0, - Button1, - True - }; - XEvent* e = (XEvent*)&bev; - nux::GetWindowThread()->ProcessForeignEvent(e, NULL); - - ev.xclient.type = ClientMessage; - ev.xclient.display = d; - - ev.xclient.serial = 0; - ev.xclient.send_event = true; - - ev.xclient.window = xid; - ev.xclient.message_type = m_MoveResizeAtom; - ev.xclient.format = 32; - - ev.xclient.data.l[0] = x; // x_root - ev.xclient.data.l[1] = y; // y_root - ev.xclient.data.l[2] = NET_WM_MOVERESIZE_MOVE; //direction - ev.xclient.data.l[3] = 1; // button - ev.xclient.data.l[4] = 2; // source - - XSendEvent(d, DefaultRootWindow(d), FALSE, - SubstructureRedirectMask | SubstructureNotifyMask, - &ev); - - XSync(d, FALSE); -} +} // namespace unity diff --git a/unity-shared/WindowManager.h b/unity-shared/WindowManager.h index f014cd19c..b9a7c7e42 100644 --- a/unity-shared/WindowManager.h +++ b/unity-shared/WindowManager.h @@ -1,5 +1,6 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- /* - * Copyright (C) 2010 Canonical Ltd + * Copyright (C) 2010-2012 Canonical Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -16,16 +17,35 @@ * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> */ -#ifndef WINDOW_MANAGER_H -#define WINDOW_MANAGER_H +#ifndef UNITYSHARED_WINDOW_MANAGER_H +#define UNITYSHARED_WINDOW_MANAGER_H -#include <Nux/Nux.h> -#include <gdk/gdkx.h> -#include <core/core.h> +#include <memory> +#include <vector> +#include <sigc++/sigc++.h> + +// To bring in nux::Geometry we first need the Rect header, then Utils. +#include <NuxCore/Rect.h> +#include <Nux/Utils.h> + +#ifdef UNITY_HAS_X_ORG_SUPPORT +#include <X11/Xlib.h> +#else +typedef unsigned long Window; +#endif #include "unity-shared/Introspectable.h" -class WindowManager : public unity::debug::Introspectable +namespace unity +{ +class WindowManager; +typedef std::shared_ptr<WindowManager> WindowManagerPtr; + +// This function is used by the static Default method on the WindowManager +// class, and uses link time to make sure there is a function available. +WindowManagerPtr create_window_manager(); + +class WindowManager : public debug::Introspectable { // This is a glue interface that breaks the dependancy of Unity with Compiz // Basically it has a default implementation that does nothing useful, but @@ -33,11 +53,7 @@ class WindowManager : public unity::debug::Introspectable // initialization so the things that require it get a usable implementation public: - WindowManager() : - m_MoveResizeAtom(XInternAtom(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), - "_NET_WM_MOVERESIZE", FALSE)) - { - }; + virtual ~WindowManager() {} enum class FocusVisibility { @@ -46,33 +62,32 @@ public: ForceUnminimizeOnCurrentDesktop }; - static WindowManager* Default(); - static void SetDefault(WindowManager* manager); + static WindowManager& Default(); - virtual guint32 GetActiveWindow() const = 0; + virtual Window GetActiveWindow() const = 0; - virtual bool IsWindowMaximized(guint32 xid) const = 0; - virtual bool IsWindowDecorated(guint32 xid) = 0; - virtual bool IsWindowOnCurrentDesktop(guint32 xid) const = 0; - virtual bool IsWindowObscured(guint32 xid) const = 0; - virtual bool IsWindowMapped(guint32 xid) const = 0; - virtual bool IsWindowVisible(guint32 xid) const = 0; - virtual bool IsWindowOnTop(guint32 xid) const = 0; - virtual bool IsWindowClosable(guint32 xid) const = 0; - virtual bool IsWindowMinimizable(guint32 xid) const = 0; - virtual bool IsWindowMaximizable(guint32 xid) const = 0; + virtual bool IsWindowMaximized(Window window_id) const = 0; + virtual bool IsWindowDecorated(Window window_id) const = 0; + virtual bool IsWindowOnCurrentDesktop(Window window_id) const = 0; + virtual bool IsWindowObscured(Window window_id) const = 0; + virtual bool IsWindowMapped(Window window_id) const = 0; + virtual bool IsWindowVisible(Window window_id) const = 0; + virtual bool IsWindowOnTop(Window window_id) const = 0; + virtual bool IsWindowClosable(Window window_id) const = 0; + virtual bool IsWindowMinimizable(Window window_id) const = 0; + virtual bool IsWindowMaximizable(Window window_id) const = 0; virtual void ShowDesktop() = 0; virtual bool InShowDesktop() const = 0; - virtual void Restore(guint32 xid) = 0; - virtual void RestoreAt(guint32 xid, int x, int y) = 0; - virtual void Minimize(guint32 xid) = 0; - virtual void Close(guint32 xid) = 0; + virtual void Restore(Window window_id) = 0; + virtual void RestoreAt(Window window_id, int x, int y) = 0; + virtual void Minimize(Window window_id) = 0; + virtual void Close(Window window_id) = 0; - virtual void Activate(guint32 xid) = 0; - virtual void Raise(guint32 xid) = 0; - virtual void Lower(guint32 xid) = 0; + virtual void Activate(Window window_id) = 0; + virtual void Raise(Window window_id) = 0; + virtual void Lower(Window window_id) = 0; virtual void TerminateScale() = 0; virtual bool IsScaleActive() const = 0; @@ -84,25 +99,28 @@ public: virtual bool IsWallActive() const = 0; - virtual void FocusWindowGroup(std::vector<Window> windows, FocusVisibility, int monitor = -1, bool only_top_win = true) = 0; - virtual bool ScaleWindowGroup(std::vector<Window> windows, int state, bool force) = 0; + virtual void FocusWindowGroup(std::vector<Window> const& windows, + FocusVisibility, int monitor = -1, + bool only_top_win = true) = 0; + virtual bool ScaleWindowGroup(std::vector<Window> const& windows, + int state, bool force) = 0; - virtual void Decorate(guint32 xid) {}; - virtual void Undecorate(guint32 xid) {}; + virtual void Decorate(Window window_id) const {}; + virtual void Undecorate(Window window_id) const {}; virtual bool IsScreenGrabbed() const = 0; virtual bool IsViewPortSwitchStarted() const = 0; - virtual void MoveResizeWindow(guint32 xid, nux::Geometry geometry) = 0; - void StartMove(guint32 xid, int, int); + virtual void MoveResizeWindow(Window window_id, nux::Geometry geometry) = 0; + virtual void StartMove(Window window_id, int x, int y) = 0; - virtual int GetWindowMonitor(guint32 xid) const = 0; - virtual nux::Geometry GetWindowGeometry(guint32 xid) const = 0; - virtual nux::Geometry GetWindowSavedGeometry(guint32 xid) const = 0; + virtual int GetWindowMonitor(Window window_id) const = 0; + virtual nux::Geometry GetWindowGeometry(Window window_id) const = 0; + virtual nux::Geometry GetWindowSavedGeometry(Window window_id) const = 0; virtual nux::Geometry GetScreenGeometry() const = 0; - virtual nux::Geometry GetWorkAreaGeometry(guint32 xid = 0) const = 0; + virtual nux::Geometry GetWorkAreaGeometry(Window window_id = 0) const = 0; - virtual unsigned long long GetWindowActiveNumber(guint32 xid) const = 0; + virtual unsigned long long GetWindowActiveNumber(Window window_id) const = 0; virtual void SetWindowIconGeometry(Window window, nux::Geometry const& geo) = 0; @@ -110,27 +128,27 @@ public: virtual int WorkspaceCount() const = 0; - virtual bool saveInputFocus() = 0; - virtual bool restoreInputFocus() = 0; + virtual bool SaveInputFocus() = 0; + virtual bool RestoreInputFocus() = 0; - virtual std::string GetWindowName(guint32 xid) const = 0; + virtual std::string GetWindowName(Window window_id) const = 0; // Signals - sigc::signal<void, guint32> window_mapped; - sigc::signal<void, guint32> window_unmapped; - sigc::signal<void, guint32> window_maximized; - sigc::signal<void, guint32> window_restored; - sigc::signal<void, guint32> window_minimized; - sigc::signal<void, guint32> window_unminimized; - sigc::signal<void, guint32> window_shaded; - sigc::signal<void, guint32> window_unshaded; - sigc::signal<void, guint32> window_shown; - sigc::signal<void, guint32> window_hidden; - sigc::signal<void, guint32> window_resized; - sigc::signal<void, guint32> window_moved; - sigc::signal<void, guint32> window_focus_changed; - sigc::signal<void, guint32> window_decorated; - sigc::signal<void, guint32> window_undecorated; + sigc::signal<void, Window> window_mapped; + sigc::signal<void, Window> window_unmapped; + sigc::signal<void, Window> window_maximized; + sigc::signal<void, Window> window_restored; + sigc::signal<void, Window> window_minimized; + sigc::signal<void, Window> window_unminimized; + sigc::signal<void, Window> window_shaded; + sigc::signal<void, Window> window_unshaded; + sigc::signal<void, Window> window_shown; + sigc::signal<void, Window> window_hidden; + sigc::signal<void, Window> window_resized; + sigc::signal<void, Window> window_moved; + sigc::signal<void, Window> window_focus_changed; + sigc::signal<void, Window> window_decorated; + sigc::signal<void, Window> window_undecorated; sigc::signal<void> initiate_spread; sigc::signal<void> terminate_spread; @@ -138,19 +156,17 @@ public: sigc::signal<void> initiate_expo; sigc::signal<void> terminate_expo; - sigc::signal<void> compiz_screen_grabbed; - sigc::signal<void> compiz_screen_ungrabbed; - sigc::signal<void> compiz_screen_viewport_switch_started; - sigc::signal<void> compiz_screen_viewport_switch_ended; - - sigc::signal<void, const char*, const char*, CompOption::Vector&> compiz_event; + sigc::signal<void> screen_grabbed; + sigc::signal<void> screen_ungrabbed; + sigc::signal<void> screen_viewport_switch_started; + sigc::signal<void> screen_viewport_switch_ended; protected: std::string GetName() const; virtual void AddProperties(GVariantBuilder* builder) = 0; -private: - Atom m_MoveResizeAtom; }; -#endif // WINDOW_MANAGER_H +} + +#endif // UNITYSHARED_WINDOW_MANAGER_H diff --git a/unity-shared/KeyboardUtil.cpp b/unity-shared/XKeyboardUtil.cpp index 90806d5e0..039eba3a8 100644 --- a/unity-shared/KeyboardUtil.cpp +++ b/unity-shared/XKeyboardUtil.cpp @@ -21,15 +21,46 @@ #include <string.h> #include <cmath> +#include <X11/keysym.h> +#include <X11/XKBlib.h> +#include <X11/extensions/XKBgeom.h> + #include "KeyboardUtil.h" +#include "XKeyboardUtil.h" -namespace unity { -namespace ui { -namespace { - const unsigned int FETCH_MASK = XkbGBN_KeyNamesMask | XkbGBN_ClientSymbolsMask | XkbGBN_GeometryMask; -} +namespace unity +{ +namespace keyboard +{ +namespace +{ +const unsigned int FETCH_MASK = (XkbGBN_KeyNamesMask | + XkbGBN_ClientSymbolsMask | + XkbGBN_GeometryMask); + +class KeyboardUtil +{ +public: + KeyboardUtil(Display* display); + ~KeyboardUtil(); + + guint GetKeycodeAboveKeySymbol(KeySym key_symbol) const; + +private: + bool CompareOffsets (int current_x, int current_y, int best_x, int best_y) const; + guint ConvertKeyToKeycode (XkbKeyPtr key) const; + + bool FindKeyInGeometry(XkbGeometryPtr geo, char *key_name, int& res_section, XkbBoundsRec& res_bounds) const; + bool FindKeyInSectionAboveBounds (XkbGeometryPtr geo, int section, XkbBoundsRec const& target_bounds, guint &keycode) const; + + XkbBoundsRec GetAbsoluteKeyBounds (XkbKeyPtr key, XkbRowPtr row, XkbSectionPtr section, XkbGeometryPtr geo) const; -KeyboardUtil::KeyboardUtil(Display *display) + Display *display_; + XkbDescPtr keyboard_; +}; + + +KeyboardUtil::KeyboardUtil(Display* display) : display_(display) , keyboard_(XkbGetKeyboard(display_, FETCH_MASK, XkbUseCoreKbd)) {} @@ -216,34 +247,42 @@ guint KeyboardUtil::GetKeycodeAboveKeySymbol(KeySym key_symbol) const return result; } -bool KeyboardUtil::IsPrintableKeySymbol(KeySym sym) + +} // anon namespace + + +bool is_printable_key_symbol(unsigned long key_symbol) { bool printable_key = false; - if (sym == XK_Delete || sym == XK_BackSpace || sym == XK_Return) + if (key_symbol == XK_Delete || + key_symbol == XK_BackSpace || + key_symbol == XK_Return) { printable_key = true; } else { - unsigned int unicode = gdk_keyval_to_unicode(sym); + unsigned int unicode = gdk_keyval_to_unicode(key_symbol); printable_key = g_unichar_isprint(unicode); } return printable_key; } -bool KeyboardUtil::IsMoveKeySymbol(KeySym sym) +bool is_move_key_symbol(unsigned long key_symbol) { - bool move_key = false; - - if (sym >= XK_Home && sym <= XK_Begin) - { - move_key = true; - } - - return move_key; + return (key_symbol >= XK_Home && key_symbol <= XK_Begin); } +KeySym get_key_above_key_symbol(Display* display, KeySym key_symbol) +{ + KeyboardUtil util(display); + guint above_keycode = util.GetKeycodeAboveKeySymbol(key_symbol); + const unsigned int group_interest = 0; + const unsigned int shift_interest = 0; + return XkbKeycodeToKeysym(display, above_keycode, group_interest, shift_interest); } -} \ No newline at end of file + +} // namespace keyboard +} // namespace unity diff --git a/unity-shared/XKeyboardUtil.h b/unity-shared/XKeyboardUtil.h new file mode 100644 index 000000000..230bd834a --- /dev/null +++ b/unity-shared/XKeyboardUtil.h @@ -0,0 +1,37 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2011-2012 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authored by: Jason Smith <jason.smith@canonical.com> + */ + +#ifndef UNITYSHARED_XKEYBOARDUTIL_H +#define UNITYSHARED_XKEYBOARDUTIL_H + +#include <X11/Xlib.h> + +namespace unity +{ +namespace keyboard +{ + +KeySym get_key_above_key_symbol(Display* display, KeySym key_symbol); + + +} +} + +#endif // UNITYSHARED_XKEYBOARDUTIL_H + diff --git a/unity-shared/XWindowManager.cpp b/unity-shared/XWindowManager.cpp new file mode 100644 index 000000000..a0bdc3f1a --- /dev/null +++ b/unity-shared/XWindowManager.cpp @@ -0,0 +1,86 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2010-2012 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> + */ + +#include "XWindowManager.h" + + +unity::XWindowManager::XWindowManager() + : move_resize_atom_(XInternAtom(GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), + "_NET_WM_MOVERESIZE", FALSE)) +{ +} + +void unity::XWindowManager::StartMove(Window window_id, int x, int y) +{ + if (x < 0 || y < 0) + return; + + XEvent ev; + Display* d = nux::GetGraphicsDisplay()->GetX11Display(); + + /* We first need to ungrab the pointer. FIXME: Evil */ + + XUngrabPointer(d, CurrentTime); + + // -------------------------------------------------------------------------- + // FIXME: This is a workaround until the non-paired events issue is fixed in + // nux + XButtonEvent bev = + { + ButtonRelease, + 0, + False, + d, + 0, + 0, + 0, + CurrentTime, + x, y, + x, y, + 0, + Button1, + True + }; + XEvent* e = (XEvent*)&bev; + nux::GetWindowThread()->ProcessForeignEvent(e, NULL); + + ev.xclient.type = ClientMessage; + ev.xclient.display = d; + + ev.xclient.serial = 0; + ev.xclient.send_event = true; + + ev.xclient.window = window_id; + ev.xclient.message_type = move_resize_atom_; + ev.xclient.format = 32; + + const long NET_WM_MOVERESIZE_MOVE = 8; + + ev.xclient.data.l[0] = x; // x_root + ev.xclient.data.l[1] = y; // y_root + ev.xclient.data.l[2] = NET_WM_MOVERESIZE_MOVE; //direction + ev.xclient.data.l[3] = 1; // button + ev.xclient.data.l[4] = 2; // source + + XSendEvent(d, DefaultRootWindow(d), FALSE, + SubstructureRedirectMask | SubstructureNotifyMask, + &ev); + + XSync(d, FALSE); +} diff --git a/unity-shared/XWindowManager.h b/unity-shared/XWindowManager.h new file mode 100644 index 000000000..6c2f54bab --- /dev/null +++ b/unity-shared/XWindowManager.h @@ -0,0 +1,45 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2010-2012 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * Authored by: Neil Jagdish Patel <neil.patel@canonical.com> + */ + +#ifndef UNITYSHARED_XWINDOW_MANAGER_H +#define UNITYSHARED_XWINDOW_MANAGER_H + +#include <Nux/Nux.h> +#include <gdk/gdkx.h> +#include <core/core.h> + +#include "unity-shared/WindowManager.h" + +namespace unity +{ + +class XWindowManager : public WindowManager +{ +public: + XWindowManager(); + + virtual void StartMove(Window window_id, int x, int y); + +private: + Atom move_resize_atom_; +}; + +} + +#endif // WINDOW_MANAGER_H |
