diff options
| author | Andrea Azzarone <azzaronea@gmail.com> | 2014-10-21 15:56:00 +0200 |
|---|---|---|
| committer | Andrea Azzarone <azzaronea@gmail.com> | 2014-10-21 15:56:00 +0200 |
| commit | 06c1b560df36e5ebf7a66c4187dfba4d3c7b78fe (patch) | |
| tree | f91160c61bfe5127a17c943922f92ff36cb9f96e /unity-shared | |
| parent | b62a16430805b529eae136e7f9f7265ed6f5bd3a (diff) | |
| parent | 349a6b9030a3643e578858e4c7cbbe0b94bc79d0 (diff) | |
Merge lp:unity.
(bzr r3874.1.8)
Diffstat (limited to 'unity-shared')
| -rw-r--r-- | unity-shared/CompizUtils.cpp | 113 | ||||
| -rw-r--r-- | unity-shared/CompizUtils.h | 29 | ||||
| -rw-r--r-- | unity-shared/GnomeKeyGrabber.cpp | 9 | ||||
| -rw-r--r-- | unity-shared/LayoutSystem.cpp | 32 | ||||
| -rw-r--r-- | unity-shared/LayoutSystem.h | 3 | ||||
| -rw-r--r-- | unity-shared/StaticCairoText.cpp | 27 | ||||
| -rw-r--r-- | unity-shared/XWindowManager.cpp | 2 |
7 files changed, 134 insertions, 81 deletions
diff --git a/unity-shared/CompizUtils.cpp b/unity-shared/CompizUtils.cpp index be197c73e..94322a68f 100644 --- a/unity-shared/CompizUtils.cpp +++ b/unity-shared/CompizUtils.cpp @@ -1,6 +1,6 @@ // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- /* -* Copyright (C) 2013 Canonical Ltd +* Copyright (C) 2013-2014 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 @@ -30,6 +30,11 @@ namespace { const unsigned PIXMAP_DEPTH = 32; const float DEFAULT_SCALE = 1.0f; + const unsigned DECORABLE_WINDOW_TYPES = CompWindowTypeDialogMask | + CompWindowTypeModalDialogMask | + CompWindowTypeUtilMask | + CompWindowTypeMenuMask | + CompWindowTypeNormalMask; } SimpleTexture::SimpleTexture(GLTexture::List const& tex) @@ -39,7 +44,7 @@ SimpleTexture::SimpleTexture(GLTexture::List const& tex) // SimpleTextureQuad::SimpleTextureQuad() - : scale(DEFAULT_SCALE) + : scale_(DEFAULT_SCALE) {} bool SimpleTextureQuad::SetTexture(SimpleTexture::Ptr const& simple_texture) @@ -52,24 +57,27 @@ bool SimpleTextureQuad::SetTexture(SimpleTexture::Ptr const& simple_texture) if (st && st->texture()) { auto* tex = st->texture(); - CompPoint old_coords(quad.box.x(), quad.box.y()); - short invalid = std::numeric_limits<short>::min(); - quad.box.setGeometry(invalid, invalid, tex->width() * scale, tex->height() * scale); - SetCoords(old_coords.x(), old_coords.y()); + CompSize size(tex->width() * scale_, tex->height() * scale_); + + if (quad.box.width() != size.width() || quad.box.height() != size.height()) + { + quad.box.setSize(size); + UpdateMatrix(); + } } return true; } -bool SimpleTextureQuad::SetScale(float s) +bool SimpleTextureQuad::SetScale(double s) { - if (!st || scale == s) + if (!st || scale_ == s) return false; - scale = s; + scale_ = s; auto* tex = st->texture(); - quad.box.setWidth(tex->width() * scale); - quad.box.setHeight(tex->height() * scale); + quad.box.setWidth(tex->width() * scale_); + quad.box.setHeight(tex->height() * scale_); UpdateMatrix(); return true; } @@ -91,8 +99,8 @@ void SimpleTextureQuad::UpdateMatrix() int y = quad.box.y(); quad.matrix = (st && st->texture()) ? st->texture()->matrix() : GLTexture::Matrix(); - quad.matrix.xx /= scale; - quad.matrix.yy /= scale; + quad.matrix.xx /= scale_; + quad.matrix.yy /= scale_; quad.matrix.x0 = 0.0f - COMP_TEX_COORD_X(quad.matrix, x); quad.matrix.y0 = 0.0f - COMP_TEX_COORD_Y(quad.matrix, y); } @@ -166,57 +174,68 @@ int CairoContext::height() const return cairo_xlib_surface_get_height(surface_); } -bool IsWindowShadowDecorable(CompWindow* win) +// +// + +unsigned WindowDecorationElements(CompWindow* win) { + unsigned elements = DecorationElement::NONE; + if (!win) - return false; + return elements; if (!win->isViewable()) - return false; + return elements; if (win->wmType() & (CompWindowTypeDockMask | CompWindowTypeDesktopMask)) - return false; + return elements; - if (win->region().numRects() != 1) // Non rectangular windows - return false; + if (win->inShowDesktopMode()) + return elements; - if (win->alpha()) - return WindowHasMotifDecorations(win); + auto const& region = win->region(); + bool rectangular = (region.numRects() == 1); + bool alpha = win->alpha(); - return true; -} + if (!rectangular && alpha) // Non-rectangular windows with alpha channel + return elements; -bool IsWindowFullyDecorable(CompWindow* win) -{ - if (!win) - return false; + if (region.boundingRect() != win->geometry()) // Shaped windows + return elements; - if (!IsWindowShadowDecorable(win)) - return false; + if (rectangular) + elements |= DecorationElement::SHADOW; - return WindowHasMotifDecorations(win); + if (!win->overrideRedirect() && + (win->type() & DECORABLE_WINDOW_TYPES) && + (win->frame() || win->hasUnmapReference())) + { + if (win->actions() & CompWindowActionResizeMask) + elements |= DecorationElement::EDGE; + + if (rectangular && (win->mwmDecor() & (MwmDecorAll | MwmDecorTitle))) + elements |= DecorationElement::BORDER; + } + + if (alpha && !(elements & DecorationElement::BORDER) && !(win->mwmDecor() & MwmDecorBorder)) + elements &= ~DecorationElement::SHADOW; + + return elements; } -bool WindowHasMotifDecorations(CompWindow* win) +bool IsWindowEdgeDecorable(CompWindow* win) { - if (!win) - return false; - - if (win->overrideRedirect()) - return false; + return WindowDecorationElements(win) & DecorationElement::EDGE; +} - switch (win->type()) - { - case CompWindowTypeDialogMask: - case CompWindowTypeModalDialogMask: - case CompWindowTypeUtilMask: - case CompWindowTypeMenuMask: - case CompWindowTypeNormalMask: - if (win->mwmDecor() & (MwmDecorAll | MwmDecorTitle)) - return true; - } +bool IsWindowShadowDecorable(CompWindow* win) +{ + return WindowDecorationElements(win) & DecorationElement::SHADOW; +} - return false; +bool IsWindowFullyDecorable(CompWindow* win) +{ + return WindowDecorationElements(win) & DecorationElement::BORDER; } } // compiz_utils namespace diff --git a/unity-shared/CompizUtils.h b/unity-shared/CompizUtils.h index bab45a532..f1885a5cc 100644 --- a/unity-shared/CompizUtils.h +++ b/unity-shared/CompizUtils.h @@ -31,8 +31,15 @@ namespace compiz_utils struct TextureQuad { + TextureQuad() + : matrices(1) + , matrix(matrices[0]) + {} + CompRect box; - GLTexture::Matrix matrix; + CompRegion region; + GLTexture::MatrixList matrices; + GLTexture::Matrix& matrix; }; struct SimpleTexture @@ -59,11 +66,13 @@ struct SimpleTextureQuad { SimpleTextureQuad(); bool SetTexture(SimpleTexture::Ptr const&); - bool SetScale(float scale); + bool SetScale(double scale); bool SetCoords(int x, int y); bool SetX(int x); bool SetY(int y); + void UpdateMatrix(); + operator SimpleTexture::Ptr() const { return st; } operator bool() const { return st && st->texture(); } operator GLTexture*() const { return st ? st->texture() : nullptr; } @@ -73,8 +82,7 @@ struct SimpleTextureQuad TextureQuad quad; private: - void UpdateMatrix(); - float scale; + double scale_; }; struct PixmapTexture : SimpleTexture @@ -111,9 +119,20 @@ private: cairo_t *cr_; }; +enum DecorationElement +{ + NONE = 0, + EDGE = (1 << 0), + SHADOW = (1 << 1), + BORDER = (1 << 2), + FULL = EDGE|SHADOW|BORDER +}; + +unsigned WindowDecorationElements(CompWindow*); + +bool IsWindowEdgeDecorable(CompWindow*); bool IsWindowShadowDecorable(CompWindow*); bool IsWindowFullyDecorable(CompWindow*); -bool WindowHasMotifDecorations(CompWindow*); } // compiz_utils namespace } // unity namespace diff --git a/unity-shared/GnomeKeyGrabber.cpp b/unity-shared/GnomeKeyGrabber.cpp index a7d078de1..76c7161c0 100644 --- a/unity-shared/GnomeKeyGrabber.cpp +++ b/unity-shared/GnomeKeyGrabber.cpp @@ -200,6 +200,15 @@ unsigned int GnomeGrabber::Impl::grabAccelerator(char const* accelerator, unsign CompAction action; action.keyFromString(accelerator); + if (action.key().toString().empty()) + { + CompString prefixed = "XF86" + CompString(accelerator); + LOG_DEBUG(logger) << "Can't grab \"" << accelerator << "\", trying \"" << prefixed << "\""; + action.keyFromString(prefixed); + } + else + LOG_DEBUG(logger) << "grabAccelerator \"" << accelerator << "\""; + if (!isActionPostponed(action)) { action.setState(CompAction::StateInitKey); diff --git a/unity-shared/LayoutSystem.cpp b/unity-shared/LayoutSystem.cpp index f2ea8b87a..396ee4cac 100644 --- a/unity-shared/LayoutSystem.cpp +++ b/unity-shared/LayoutSystem.cpp @@ -32,7 +32,33 @@ void LayoutSystem::LayoutWindows(LayoutWindow::Vector const& windows, nux::Geome if (windows.empty()) return; - LayoutGridWindows(windows, max_bounds, final_bounds); + LayoutGridWindows(windows, GetRows(windows, max_bounds), max_bounds, final_bounds); +} + +void LayoutSystem::LayoutWindowsNearest(LayoutWindow::Vector& windows, nux::Geometry const& max_bounds, nux::Geometry& final_bounds) +{ + if (windows.empty()) + return; + + std::stable_sort(windows.begin(), windows.end(), [](LayoutWindow::Ptr const& a, LayoutWindow::Ptr const& b) { + return a->geo.y < b->geo.y; + }); + + std::vector<LayoutWindow::Vector> rows = GetRows(windows, max_bounds); + LayoutWindow::Vector ordered_windows; + + for (auto& row : rows) + { + std::stable_sort(row.begin(), row.end(), [](LayoutWindow::Ptr const& a, LayoutWindow::Ptr const& b) { + return (a->geo.x + a->geo.width / 2) < (b->geo.x + b->geo.width / 2); + }); + + for (auto const& win : row) + ordered_windows.push_back(win); + } + + LayoutGridWindows(ordered_windows, rows, max_bounds, final_bounds); + windows = ordered_windows; } nux::Size LayoutSystem::GridSizeForWindows(LayoutWindow::Vector const& windows, nux::Geometry const& max_bounds) const @@ -229,10 +255,8 @@ std::vector<LayoutWindow::Vector> LayoutSystem::GetRows(LayoutWindow::Vector con return rows; } -void LayoutSystem::LayoutGridWindows(LayoutWindow::Vector const& windows, nux::Geometry const& max_bounds, nux::Geometry& final_bounds) +void LayoutSystem::LayoutGridWindows(LayoutWindow::Vector const& windows, std::vector<LayoutWindow::Vector> const& rows, nux::Geometry const& max_bounds, nux::Geometry& final_bounds) { - std::vector<LayoutWindow::Vector> const& rows = GetRows(windows, max_bounds); - int height = rows.size(); int non_spacing_height = max_bounds.height - ((height - 1) * spacing); int row_height = std::min (max_row_height(), non_spacing_height / height); diff --git a/unity-shared/LayoutSystem.h b/unity-shared/LayoutSystem.h index 6241f727c..96b7d9c90 100644 --- a/unity-shared/LayoutSystem.h +++ b/unity-shared/LayoutSystem.h @@ -64,10 +64,11 @@ public: LayoutSystem(); void LayoutWindows(LayoutWindow::Vector const& windows, nux::Geometry const& max_bounds, nux::Geometry& final_bounds); + void LayoutWindowsNearest(LayoutWindow::Vector& windows, nux::Geometry const& max_bounds, nux::Geometry& final_bounds); std::vector<int> GetRowSizes(LayoutWindow::Vector const& windows, nux::Geometry const& max_bounds) const; protected: - void LayoutGridWindows(LayoutWindow::Vector const& windows, nux::Geometry const& max_bounds, nux::Geometry& final_bounds); + void LayoutGridWindows(LayoutWindow::Vector const& windows, std::vector<LayoutWindow::Vector> const& rows, nux::Geometry const& max_bounds, nux::Geometry& final_bounds); nux::Geometry LayoutRow(LayoutWindow::Vector const& row, nux::Geometry const& row_bounds); nux::Geometry CompressAndPadRow(LayoutWindow::Vector const& windows, nux::Geometry const& max_bounds); diff --git a/unity-shared/StaticCairoText.cpp b/unity-shared/StaticCairoText.cpp index 804ad1006..ebb634f6e 100644 --- a/unity-shared/StaticCairoText.cpp +++ b/unity-shared/StaticCairoText.cpp @@ -34,6 +34,7 @@ #include <pango/pangocairo.h> #include <UnityCore/GLibWrapper.h> +#include <UnityCore/GLibSignal.h> #include "CairoTexture.h" #include "UnitySettings.h" @@ -45,7 +46,6 @@ namespace unity struct StaticCairoText::Impl : sigc::trackable { Impl(StaticCairoText* parent, std::string const& text); - ~Impl(); PangoEllipsizeMode GetPangoEllipsizeMode() const; PangoAlignment GetPangoAlignment() const; @@ -77,8 +77,6 @@ struct StaticCairoText::Impl : sigc::trackable void UpdateTexture(); void OnFontChanged(); - static void FontChanged(GObject* gobject, GParamSpec* pspec, gpointer data); - StaticCairoText* parent_; bool accept_key_nav_focus_; mutable bool need_new_extent_cache_; @@ -106,6 +104,8 @@ struct StaticCairoText::Impl : sigc::trackable int actual_lines_; float line_spacing_; double scale_; + + glib::Signal<void, GtkSettings*, GParamSpec*> font_changed_; }; StaticCairoText::Impl::Impl(StaticCairoText* parent, std::string const& text) @@ -126,21 +126,10 @@ StaticCairoText::Impl::Impl(StaticCairoText* parent, std::string const& text) , line_spacing_(0.5) , scale_(1.0f) { - GtkSettings* settings = gtk_settings_get_default(); // not ref'ed - g_signal_connect(settings, "notify::gtk-font-name", - (GCallback)FontChanged, this); - + font_changed_.Connect(gtk_settings_get_default(), "notify::gtk-font-name", sigc::hide(sigc::hide(sigc::mem_fun(this, &Impl::OnFontChanged)))); Settings::Instance().font_scaling.changed.connect(sigc::hide(sigc::mem_fun(this, &Impl::OnFontChanged))); } -StaticCairoText::Impl::~Impl() -{ - GtkSettings* settings = gtk_settings_get_default(); // not ref'ed - g_signal_handlers_disconnect_by_func(settings, - (void*)FontChanged, - this); -} - PangoEllipsizeMode StaticCairoText::Impl::GetPangoEllipsizeMode() const { switch (ellipsize_) @@ -780,14 +769,6 @@ void StaticCairoText::Impl::UpdateTexture() } } -void StaticCairoText::Impl::FontChanged(GObject* gobject, - GParamSpec* pspec, - gpointer data) -{ - StaticCairoText::Impl* self = static_cast<StaticCairoText::Impl*>(data); - self->OnFontChanged(); -} - void StaticCairoText::Impl::OnFontChanged() { need_new_extent_cache_ = true; diff --git a/unity-shared/XWindowManager.cpp b/unity-shared/XWindowManager.cpp index aa3d9c54f..5058c2952 100644 --- a/unity-shared/XWindowManager.cpp +++ b/unity-shared/XWindowManager.cpp @@ -83,7 +83,7 @@ std::string XWindowManager::GetStringProperty(Window window_id, Atom atom) const { LOG_ERROR(logger) << "Impossible to get the property " << gdk_x11_get_xatom_name(atom) << " for window " << window_id << ": invalid string type: " - << gdk_x11_get_xatom_name(Atoms::utf8String); + << gdk_x11_get_xatom_name(type); return std::string(); } |
