diff options
| author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2016-02-19 05:03:51 +0100 |
|---|---|---|
| committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2016-02-19 05:03:51 +0100 |
| commit | 35933ff4153668161c548b41efc993be11fe89a2 (patch) | |
| tree | 1bfbb9b984e1cb9321d478e69114782937ea80cf /decorations | |
| parent | 6f6f04108d401cb6374859a52964f49c5217a7b2 (diff) | |
DecorationsShape: make more C++ friendly
(bzr r4067.8.1)
Diffstat (limited to 'decorations')
| -rw-r--r-- | decorations/DecoratedWindow.cpp | 10 | ||||
| -rw-r--r-- | decorations/DecoratedWindow.h | 1 | ||||
| -rw-r--r-- | decorations/DecorationsManager.cpp | 13 | ||||
| -rw-r--r-- | decorations/DecorationsPriv.h | 5 | ||||
| -rw-r--r-- | decorations/DecorationsShape.cpp | 97 | ||||
| -rw-r--r-- | decorations/DecorationsShape.h | 41 |
6 files changed, 92 insertions, 75 deletions
diff --git a/decorations/DecoratedWindow.cpp b/decorations/DecoratedWindow.cpp index a9660801e..f2ddf5602 100644 --- a/decorations/DecoratedWindow.cpp +++ b/decorations/DecoratedWindow.cpp @@ -638,8 +638,7 @@ void Window::Impl::ComputeShapedShadowQuad() nux::Color color = active() ? manager_->active_shadow_color() : manager_->inactive_shadow_color(); unsigned int radius = active() ? manager_->active_shadow_radius() : manager_->inactive_shadow_radius(); - DecorationsShape shape; - shape.initShape(win_->id()); + Shape shape(win_->id()); shaped_shadow_pixmap_ = manager_->impl_->BuildShapedShadowTexture(radius, color, shape); const auto* texture = ShadowTexture(); @@ -651,8 +650,8 @@ void Window::Impl::ComputeShapedShadowQuad() nux::Point2D<int> shadow_offset = manager_->shadow_offset(); // ideally it would be -radius for the *2 part see comment in Manager::Impl::BuildShapedShadowTexture // in DecorationsManager.cpp Make sure to keep these factors in sync. - int x = border.x() + shadow_offset.x - radius * 2 + shape.getXoffs(); - int y = border.y() + shadow_offset.y - radius * 2 + shape.getYoffs(); + int x = border.x() + shadow_offset.x - radius * 2 + shape.XOffset(); + int y = border.y() + shadow_offset.y - radius * 2 + shape.YOffset(); int width = texture->width(); int height = texture->height(); @@ -663,7 +662,8 @@ void Window::Impl::ComputeShapedShadowQuad() quad->matrix.y0 = -COMP_TEX_COORD_Y(quad->matrix, quad->box.y1()); CompRect shaped_shadow_rect(x, y, width, height); - if (shaped_shadow_rect != last_shadow_rect_) { + if (shaped_shadow_rect != last_shadow_rect_) + { auto const& win_region = win_->region(); quad->region = CompRegion(quad->box) - win_region; diff --git a/decorations/DecoratedWindow.h b/decorations/DecoratedWindow.h index 893a6e0f3..049b04d9f 100644 --- a/decorations/DecoratedWindow.h +++ b/decorations/DecoratedWindow.h @@ -21,6 +21,7 @@ #define UNITY_DECORATED_WINDOW #include "Introspectable.h" +#include <NuxCore/Property.h> #include <memory> class CompRegion; diff --git a/decorations/DecorationsManager.cpp b/decorations/DecorationsManager.cpp index b36b9cf73..904a97081 100644 --- a/decorations/DecorationsManager.cpp +++ b/decorations/DecorationsManager.cpp @@ -90,22 +90,23 @@ cu::PixmapTexture::Ptr Manager::Impl::BuildShadowTexture(unsigned radius, nux::C return shadow_ctx; } -cu::PixmapTexture::Ptr Manager::Impl::BuildShapedShadowTexture(unsigned int radius, nux::Color const& color, DecorationsShape const& shape) { +cu::PixmapTexture::Ptr Manager::Impl::BuildShapedShadowTexture(unsigned int radius, nux::Color const& color, Shape const& shape) { //Ideally it would be shape.getWidth + radius * 2 but Cairographics::BlurSurface isn't bounded by the radius //and we need to compensate by using a larger texture. Make sure to modify Window::Impl::ComputeShapedShadowQuad in //DecoratedWindow.cpp if you change the factor. int blur_margin_factor = 2; - int img_width = shape.getWidth() + radius * 2 * blur_margin_factor; - int img_height = shape.getHeight() + radius * 2 * blur_margin_factor; + int img_width = shape.Width() + radius * 2 * blur_margin_factor; + int img_height = shape.Height() + radius * 2 * blur_margin_factor; nux::CairoGraphics img(CAIRO_FORMAT_ARGB32, img_width, img_height); auto* img_ctx = img.GetInternalContext(); - for (int i=0; i<shape.getRectangleCount(); i++) { - XRectangle rect = shape.getRectangle(i); - cairo_rectangle(img_ctx, rect.x + radius * blur_margin_factor - shape.getXoffs(), rect.y + radius * blur_margin_factor - shape.getYoffs(), rect.width, rect.height); + for (auto const& rect : shape.GetRectangles()) + { + cairo_rectangle(img_ctx, rect.x + radius * blur_margin_factor - shape.XOffset(), rect.y + radius * blur_margin_factor - shape.YOffset(), rect.width, rect.height); cairo_set_source_rgba(img_ctx, color.red, color.green, color.blue, color.alpha); cairo_fill(img_ctx); } + img.BlurSurface(radius); cu::CairoContext shadow_ctx(img_width, img_height); diff --git a/decorations/DecorationsPriv.h b/decorations/DecorationsPriv.h index 38b3461a5..949da658a 100644 --- a/decorations/DecorationsPriv.h +++ b/decorations/DecorationsPriv.h @@ -147,6 +147,7 @@ private: std::string last_title_; std::string panel_id_; std::vector<cu::SimpleTextureQuad> bg_textures_; + cu::PixmapTexture::Ptr shaped_shadow_pixmap_; std::shared_ptr<ForceQuitDialog> force_quit_; InputMixer::Ptr input_mixer_; Layout::Ptr top_layout_; @@ -157,8 +158,6 @@ private: Item::Ptr edge_borders_; EMConverter::Ptr cv_; - - cu::PixmapTexture::Ptr shaped_shadow_pixmap_; }; struct Manager::Impl : sigc::trackable @@ -184,7 +183,7 @@ private: void BuildActiveShadowTexture(); void BuildInactiveShadowTexture(); cu::PixmapTexture::Ptr BuildShadowTexture(unsigned radius, nux::Color const&); - cu::PixmapTexture::Ptr BuildShapedShadowTexture(unsigned int radius, nux::Color const& color, DecorationsShape const& shape); + cu::PixmapTexture::Ptr BuildShapedShadowTexture(unsigned int radius, nux::Color const&, Shape const&); void OnShadowOptionsChanged(bool active); void OnWindowFrameChanged(bool, ::Window, std::weak_ptr<decoration::Window> const&); bool OnMenuKeyActivated(std::string const&); diff --git a/decorations/DecorationsShape.cpp b/decorations/DecorationsShape.cpp index af73c9a6a..bd827d78e 100644 --- a/decorations/DecorationsShape.cpp +++ b/decorations/DecorationsShape.cpp @@ -17,86 +17,91 @@ * Authored by: Eleni Maria Stea <elenimaria.stea@canonical.com> */ -#include <string.h> -#include <X11/extensions/shape.h> -#include "DecoratedWindow.h" #include "DecorationsShape.h" -bool DecorationsShape::initShape(XID win) +#include <core/core.h> +#include <NuxCore/Logger.h> +#include <X11/extensions/shape.h> + +namespace unity +{ +namespace decoration +{ +namespace +{ +DECLARE_LOGGER(logger, "unity.decoration.shape"); +} + +Shape::Shape(Window xid) { Bool buse, cuse; int bx, by, cx, cy; unsigned int bw, bh, cw, ch; Display *dpy = screen->dpy(); - XShapeQueryExtents(dpy, win, &buse, &bx, &by, &bw, &bh, &cuse, &cx, &cy, &cw, &ch); + XShapeQueryExtents(dpy, xid, &buse, &bx, &by, &bw, &bh, &cuse, &cx, &cy, &cw, &ch); int kind; - if (buse) { - width = bw; - height = bh; - xoffs = bx; - yoffs = by; + + if (buse) + { + width_ = bw; + height_ = bh; + xoffs_ = bx; + yoffs_ = by; kind = ShapeBounding; } - else if (cuse) { - width = cw; - height = ch; - xoffs = cx; - yoffs = cy; + else if (cuse) + { + width_ = cw; + height_ = ch; + xoffs_ = cx; + yoffs_ = cy; kind = ShapeClip; } - else { - fprintf(stderr, "XShapeQueryExtend returned no extends.\n"); - return false; + else + { + LOG_ERROR(logger) << "XShapeQueryExtend returned no extents"; + return; } int rect_count, rect_order; - XRectangle *rectangles; - if (!(rectangles = XShapeGetRectangles(dpy, win, kind, &rect_count, &rect_order))) { - fprintf(stderr, "Failed to get shape rectangles\n"); - return false; - } + std::unique_ptr<XRectangle[], int(*)(void*)> rectangles(XShapeGetRectangles(dpy, xid, kind, &rect_count, &rect_order), XFree); - for (int i=0; i< rect_count; i++) { - rects.push_back(rectangles[i]); + if (!rectangles) + { + LOG_ERROR(logger) << "Failed to get shape rectangles"; + return; } - XFree(rectangles); - return true; + for (int i = 0; i < rect_count; ++i) + rectangles_.push_back(rectangles[i]); } -const XRectangle& DecorationsShape::getRectangle(int idx) const +std::vector<XRectangle> const& Shape::GetRectangles() const { - return rects[idx]; + return rectangles_; } -int DecorationsShape::getRectangleCount() const +int Shape::Width() const { - return (int)rects.size(); + return width_; } -int DecorationsShape::getWidth() const +int Shape::Height() const { - return width; + return height_; } -int DecorationsShape::getHeight() const +int Shape::XOffset() const { - return height; + return xoffs_; } -int DecorationsShape::getXoffs() const +int Shape::YOffset() const { - return xoffs; + return yoffs_; } -int DecorationsShape::getYoffs() const -{ - return yoffs; -} -void DecorationsShape::clear() -{ - width = height = 0; - rects.clear(); -} +} // decoration namespace +} // unity namespace diff --git a/decorations/DecorationsShape.h b/decorations/DecorationsShape.h index 0ca4c2ac3..a040bc8a9 100644 --- a/decorations/DecorationsShape.h +++ b/decorations/DecorationsShape.h @@ -20,24 +20,35 @@ #ifndef DECORATIONS_SHAPE_H_ #define DECORATIONS_SHAPE_H_ -#include "WindowManager.h" -#include "DecoratedWindow.h" +#include <X11/Xlib.h> +#include <vector> -class DecorationsShape +namespace unity { +namespace decoration +{ +class Shape +{ +public: + Shape(Window); + + int Width() const; + int Height() const; + int XOffset() const; + int YOffset() const; + + std::vector<XRectangle> const& GetRectangles() const; + private: - std::vector<XRectangle> rects; - int width, height; - int xoffs, yoffs; + int width_; + int height_; + int xoffs_; + int yoffs_; -public: - bool initShape(XID win); - const XRectangle& getRectangle(int idx) const; - int getRectangleCount() const; - int getWidth() const; - int getHeight() const; - int getXoffs() const; - int getYoffs() const; - void clear(); + std::vector<XRectangle> rectangles_; }; + +} // decoration namespace +} // unity namespace + #endif //DECORATIONS_SHAPE_H_ |
