From 0bbd42fc906c4ce887a90ebb2ffb950efe93f703 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Fri, 31 Aug 2012 16:55:43 -0300 Subject: Moved function "GetWindowName" from UnityWindow to WindowManager. (bzr r2650.1.1) --- plugins/unityshell/src/unityshell.cpp | 81 +---------------------------------- plugins/unityshell/src/unityshell.h | 5 --- 2 files changed, 1 insertion(+), 85 deletions(-) (limited to 'plugins/unityshell/src') diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index 640fd3654..a22da6e54 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -3611,7 +3611,7 @@ void UnityWindow::RenderText (WindowCairoContext *context, pango_layout_set_auto_dir (layout, false); pango_layout_set_text (layout, - GetWindowName (window->id ()).c_str (), + WindowManager::Default()->GetWindowName(window->id()).c_str(), -1); /* update the size of the pango layout */ @@ -3863,85 +3863,6 @@ bool UnityPluginVTable::init() return true; } -CompString UnityWindow::GetUtf8Property (Window id, - Atom atom) -{ - Atom type; - int result, format; - unsigned long nItems, bytesAfter; - char *val; - CompString retval; - Atom utf8StringAtom; - - utf8StringAtom = XInternAtom (screen->dpy (), "UTF8_STRING", 0); - result = XGetWindowProperty (screen->dpy (), id, atom, 0L, 65536, False, - utf8StringAtom, &type, &format, &nItems, - &bytesAfter, (unsigned char **) &val); - - if (result != Success) - return retval; - - if (type == utf8StringAtom && format == 8 && val && nItems > 0) - { - char valueString[nItems + 1]; - strncpy (valueString, val, nItems); - valueString[nItems] = 0; - retval = valueString; - } - if (val) - XFree (val); - - return retval; -} - -CompString UnityWindow::GetTextProperty (Window id, - Atom atom) -{ - XTextProperty text; - CompString retval; - - text.nitems = 0; - if (XGetTextProperty (screen->dpy (), id, &text, atom)) - { - if (text.value) - { - char valueString[text.nitems + 1]; - - strncpy (valueString, (char *) text.value, text.nitems); - valueString[text.nitems] = 0; - - retval = valueString; - - XFree (text.value); - } - } - - return retval; -} - - -CompString UnityWindow::GetWindowName (Window id) -{ - CompString name; - Atom visibleNameAtom; - - visibleNameAtom = XInternAtom (screen->dpy (), "_NET_WM_VISIBLE_NAME", 0); - name = GetUtf8Property (id, visibleNameAtom); - if (name.empty ()) - { - Atom wmNameAtom = XInternAtom (screen->dpy (), "_NET_WM_NAME", 0); - name = GetUtf8Property (id, wmNameAtom); - } - - - if (name.empty ()) - name = GetTextProperty (id, XA_WM_NAME); - - return name; -} - - - namespace { diff --git a/plugins/unityshell/src/unityshell.h b/plugins/unityshell/src/unityshell.h index b9bea314a..b9afe93d2 100644 --- a/plugins/unityshell/src/unityshell.h +++ b/plugins/unityshell/src/unityshell.h @@ -482,11 +482,6 @@ private: float maxWidth, float maxHeight); WindowCairoContext* CreateCairoContext (float width, float height); - // based on compiz text plugin - CompString GetWindowName (Window id); - CompString GetUtf8Property (Window id, Atom atom); - CompString GetTextProperty (Window id, Atom atom); - compiz::WindowInputRemoverLock::Weak input_remover_; glib::Source::UniquePtr focus_desktop_timeout_; -- cgit v1.2.3 From 94f96e9b4c7ce198f8b6072168302cd7bdf8126d Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Fri, 31 Aug 2012 17:12:09 -0300 Subject: Fixed code style. (bzr r2650.1.2) --- plugins/unityshell/src/unityshell.cpp | 327 +++++++++++++++++----------------- plugins/unityshell/src/unityshell.h | 32 ++-- 2 files changed, 183 insertions(+), 176 deletions(-) (limited to 'plugins/unityshell/src') diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index a22da6e54..42272fc0c 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -1257,7 +1257,8 @@ void UnityWindow::handleEvent (XEvent *event) } } -CompRect UnityWindow::closeButtonArea () +CompRect +UnityWindow::CloseButtonArea() { return close_button_area_; } @@ -1633,14 +1634,14 @@ void UnityScreen::handleEvent(XEvent* event) event->xbutton.button == Button1 && highlighted_window_ != 0) { - CompWindow *w = screen->findWindow (highlighted_window_); + CompWindow *w = screen->findWindow(highlighted_window_); if (w) { - UnityWindow *uw = UnityWindow::get (w); - CompPoint pointer (pointerX, pointerY); - if (uw->closeButtonArea ().contains (pointer)) + UnityWindow *uw = UnityWindow::get(w); + CompPoint pointer(pointerX, pointerY); + if (uw->CloseButtonArea().contains(pointer)) { - w->close (0); + w->close(0); skip_other_plugins = true; } } @@ -3517,18 +3518,19 @@ UnityWindow::UnityWindow(CompWindow* window) } } -void UnityWindow::DrawTexture (GLTexture* icon, - const GLWindowPaintAttrib& attrib, - const GLMatrix& transform, - unsigned int mask, - float x, float y, - int &maxWidth, int &maxHeight) +void +UnityWindow::DrawTexture(GLTexture* icon, + const GLWindowPaintAttrib& attrib, + const GLMatrix& transform, + unsigned int mask, + float x, float y, + int &maxWidth, int &maxHeight) { if (icon) { int width, height; - width = icon->width (); - height = icon->height (); + width = icon->width(); + height = icon->height(); if (height > maxHeight) maxHeight = height; @@ -3536,117 +3538,120 @@ void UnityWindow::DrawTexture (GLTexture* icon, if (width > maxWidth) maxWidth = width; - CompRegion iconReg (0, 0, width, height); - GLTexture::MatrixList ml (1); + CompRegion iconReg(0, 0, width, height); + GLTexture::MatrixList ml(1); - ml[0] = icon->matrix (); - gWindow->vertexBuffer ()->begin (); + ml[0] = icon->matrix(); + gWindow->vertexBuffer()->begin(); if (width && height) - gWindow->glAddGeometry (ml, iconReg, iconReg); + gWindow->glAddGeometry(ml, iconReg, iconReg); - if (gWindow->vertexBuffer ()->end ()) + if (gWindow->vertexBuffer()->end()) { - GLMatrix wTransform (transform); + GLMatrix wTransform(transform); - wTransform.translate (x, y, 0.0f); + wTransform.translate(x, y, 0.0f); - gWindow->glDrawTexture (icon, wTransform, attrib, mask); + gWindow->glDrawTexture(icon, wTransform, attrib, mask); } } } -WindowCairoContext* UnityWindow::CreateCairoContext (float width, float height) +WindowCairoContext* +UnityWindow::CreateCairoContext(float width, float height) { - XRenderPictFormat *format; - Screen *xScreen; - WindowCairoContext *context = new WindowCairoContext(); + XRenderPictFormat *format; + Screen *xScreen; + WindowCairoContext *context = new WindowCairoContext(); - xScreen = ScreenOfDisplay (screen->dpy (), screen->screenNum ()); + xScreen = ScreenOfDisplay(screen->dpy(), screen->screenNum()); - format = XRenderFindStandardFormat (screen->dpy (), PictStandardARGB32); - context->pixmap_ = XCreatePixmap (screen->dpy (), - screen->root (), - width, height, 32); + format = XRenderFindStandardFormat(screen->dpy(), PictStandardARGB32); + context->pixmap_ = XCreatePixmap(screen->dpy(), + screen->root(), + width, height, 32); - context->texture_ = GLTexture::bindPixmapToTexture (context->pixmap_, - width, height, - 32); - if (context->texture_.empty ()) - { - delete context; - return 0; - } + context->texture_ = GLTexture::bindPixmapToTexture(context->pixmap_, + width, height, + 32); + if (context->texture_.empty()) + { + delete context; + return 0; + } - context->surface_ = cairo_xlib_surface_create_with_xrender_format (screen->dpy (), - context->pixmap_, - xScreen, - format, - width, - height); - context->cr_ = cairo_create (context->surface_); + context->surface_ = cairo_xlib_surface_create_with_xrender_format(screen->dpy(), + context->pixmap_, + xScreen, + format, + width, + height); + context->cr_ = cairo_create(context->surface_); - // clear - cairo_save (context->cr_); - cairo_set_operator (context->cr_, CAIRO_OPERATOR_CLEAR); - cairo_paint (context->cr_); - cairo_restore (context->cr_); + // clear + cairo_save(context->cr_); + cairo_set_operator(context->cr_, CAIRO_OPERATOR_CLEAR); + cairo_paint(context->cr_); + cairo_restore(context->cr_); - return context; + return context; } -void UnityWindow::RenderText (WindowCairoContext *context, - float x, float y, - float maxWidth, float maxHeight) -{ - PangoFontDescription* font = pango_font_description_new (); - pango_font_description_set_family (font, "sans"); - pango_font_description_set_absolute_size (font, 12 * PANGO_SCALE); - pango_font_description_set_style (font, PANGO_STYLE_NORMAL); - pango_font_description_set_weight (font, PANGO_WEIGHT_BOLD); - - PangoLayout* layout = pango_cairo_create_layout (context->cr_); - pango_layout_set_font_description (layout, font); - pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END); - pango_layout_set_height (layout, maxHeight); - - pango_layout_set_auto_dir (layout, false); - pango_layout_set_text (layout, - WindowManager::Default()->GetWindowName(window->id()).c_str(), - -1); +void +UnityWindow::RenderText(WindowCairoContext *context, + float x, float y, + float maxWidth, float maxHeight) +{ + PangoFontDescription* font = pango_font_description_new(); + pango_font_description_set_family(font, "sans"); + pango_font_description_set_absolute_size(font, 12 * PANGO_SCALE); + pango_font_description_set_style(font, PANGO_STYLE_NORMAL); + pango_font_description_set_weight(font, PANGO_WEIGHT_BOLD); + + PangoLayout* layout = pango_cairo_create_layout(context->cr_); + pango_layout_set_font_description(layout, font); + pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); + pango_layout_set_height(layout, maxHeight); + + pango_layout_set_auto_dir(layout, false); + pango_layout_set_text(layout, + WindowManager::Default()->GetWindowName(window->id()).c_str(), + -1); /* update the size of the pango layout */ - pango_layout_set_width (layout, maxWidth * PANGO_SCALE); - pango_cairo_update_layout (context->cr_, layout); + pango_layout_set_width(layout, maxWidth * PANGO_SCALE); + pango_cairo_update_layout(context->cr_, layout); - cairo_set_operator (context->cr_, CAIRO_OPERATOR_OVER); + cairo_set_operator(context->cr_, CAIRO_OPERATOR_OVER); - cairo_set_source_rgba (context->cr_, - 1.0, - 1.0, - 1.0, - 1.0); + cairo_set_source_rgba(context->cr_, + 1.0, + 1.0, + 1.0, + 1.0); // alignment int lWidth, lHeight; - pango_layout_get_pixel_size (layout, &lWidth, &lHeight); + pango_layout_get_pixel_size(layout, &lWidth, &lHeight); y = ((maxHeight - lHeight) / 2.0) + y; - cairo_translate (context->cr_, x, y); - pango_cairo_show_layout (context->cr_, layout); + cairo_translate(context->cr_, x, y); + pango_cairo_show_layout(context->cr_, layout); } -void UnityWindow::DrawWindowTitle (const GLWindowPaintAttrib& attrib, - const GLMatrix& transform, - unsigned int mask, - float x, float y, float x2, float y2) +void +UnityWindow::DrawWindowTitle(const GLWindowPaintAttrib& attrib, + const GLMatrix& transform, + unsigned int mask, + float x, float y, float x2, float y2) { const float width = x2 - x; // Paint a fake window decoration - WindowCairoContext *context = CreateCairoContext (width, SCALE_WINDOW_TITLE_SIZE); + WindowCairoContext *context = CreateCairoContext(width, SCALE_WINDOW_TITLE_SIZE); - cairo_save (context->cr_); - cairo_push_group (context->cr_); + cairo_save(context->cr_); + cairo_push_group(context->cr_); // Round window decoration top border const double height = SCALE_WINDOW_TITLE_SIZE; @@ -3655,152 +3660,154 @@ void UnityWindow::DrawWindowTitle (const GLWindowPaintAttrib& attrib, const double radius = corner_radius / aspect; const double degrees = M_PI / 180.0; - cairo_new_sub_path (context->cr_); + cairo_new_sub_path(context->cr_); - cairo_arc (context->cr_, radius, radius, radius, 180 * degrees, 270 * degrees); - cairo_arc (context->cr_, width - radius, radius, radius, -90 * degrees, 0 * degrees); - cairo_line_to (context->cr_, width, height); - cairo_line_to (context->cr_, 0, height); + cairo_arc(context->cr_, radius, radius, radius, 180 * degrees, 270 * degrees); + cairo_arc(context->cr_, width - radius, radius, radius, -90 * degrees, 0 * degrees); + cairo_line_to(context->cr_, width, height); + cairo_line_to(context->cr_, 0, height); - cairo_close_path (context->cr_); - cairo_clip (context->cr_); + cairo_close_path(context->cr_); + cairo_clip(context->cr_); // Draw window decoration abased on gtk style - gtk_render_background (window_header_style_, context->cr_, 0, 0, width, SCALE_WINDOW_TITLE_SIZE); - gtk_render_frame (window_header_style_, context->cr_, 0, 0, width, SCALE_WINDOW_TITLE_SIZE); + gtk_render_background(window_header_style_, context->cr_, 0, 0, width, SCALE_WINDOW_TITLE_SIZE); + gtk_render_frame(window_header_style_, context->cr_, 0, 0, width, SCALE_WINDOW_TITLE_SIZE); - cairo_pop_group_to_source (context->cr_); + cairo_pop_group_to_source(context->cr_); - cairo_paint_with_alpha (context->cr_, 1.0); - cairo_restore (context->cr_); + cairo_paint_with_alpha(context->cr_, 1.0); + cairo_restore(context->cr_); // Draw windows title - RenderText (context, - CLOSE_ICON_SPACE * 2 + CLOSE_ICON_SIZE, - 0.0, - width, SCALE_WINDOW_TITLE_SIZE); + RenderText(context, + CLOSE_ICON_SPACE * 2 + CLOSE_ICON_SIZE, + 0.0, + width, SCALE_WINDOW_TITLE_SIZE); mask |= PAINT_WINDOW_BLEND_MASK; int maxWidth, maxHeight; foreach(GLTexture *icon, context->texture_) { - DrawTexture (icon, attrib, transform, mask, - x, y, - maxWidth , maxHeight); + DrawTexture(icon, attrib, transform, mask, + x, y, + maxWidth , maxHeight); } delete context; } -void UnityWindow::scalePaintDecoration (const GLWindowPaintAttrib& attrib, - const GLMatrix& transform, - const CompRegion& region, - unsigned int mask) +void +UnityWindow::scalePaintDecoration(const GLWindowPaintAttrib& attrib, + const GLMatrix& transform, + const CompRegion& region, + unsigned int mask) { - ScaleWindow *sWindow = ScaleWindow::get (window); + ScaleWindow *sWindow = ScaleWindow::get(window); if (!sWindow) return; - sWindow->scalePaintDecoration (attrib, transform, region, mask); + sWindow->scalePaintDecoration(attrib, transform, region, mask); if (!sWindow->hasSlot()) // animation not finished return; if (!window_header_style_) { - GtkWidgetPath* widget_path = gtk_widget_path_new (); - gint pos = gtk_widget_path_append_type (widget_path, GTK_TYPE_WINDOW); - gtk_widget_path_iter_set_name (widget_path, pos, "UnityPanelWidget"); + GtkWidgetPath* widget_path = gtk_widget_path_new(); + gint pos = gtk_widget_path_append_type(widget_path, GTK_TYPE_WINDOW); + gtk_widget_path_iter_set_name(widget_path, pos, "UnityPanelWidget"); - window_header_style_ = gtk_style_context_new (); - gtk_style_context_set_path (window_header_style_, widget_path); - gtk_style_context_add_class (window_header_style_, "gnome-panel-menu-bar"); - gtk_style_context_add_class (window_header_style_, "unity-panel"); + window_header_style_ = gtk_style_context_new(); + gtk_style_context_set_path(window_header_style_, widget_path); + gtk_style_context_add_class(window_header_style_, "gnome-panel-menu-bar"); + gtk_style_context_add_class(window_header_style_, "unity-panel"); // get close button panel::Style& style = panel::Style::Instance(); - std::vector files = style.GetWindowButtonFileNames (panel::WindowButtonType::CLOSE, - panel::WindowState::NORMAL); + std::vector files = style.GetWindowButtonFileNames(panel::WindowButtonType::CLOSE, + panel::WindowState::NORMAL); - CompString pName ("unityshell"); + CompString pName("unityshell"); foreach (std::string file, files) { - CompString fileName (file.c_str ()); - CompSize size (CLOSE_ICON_SIZE, CLOSE_ICON_SIZE); - close_icon_ = GLTexture::readImageToTexture (fileName, - pName, - size); - if (close_icon_.size () != 0) + CompString fileName(file.c_str ()); + CompSize size(CLOSE_ICON_SIZE, CLOSE_ICON_SIZE); + close_icon_ = GLTexture::readImageToTexture(fileName, + pName, + size); + if (close_icon_.size() != 0) break; } - if (close_icon_.size () == 0) + if (close_icon_.size() == 0) { - CompString fileName (PKGDATADIR"/close_dash.png"); - CompSize size (CLOSE_ICON_SIZE, CLOSE_ICON_SIZE); - close_icon_ = GLTexture::readImageToTexture (fileName, - pName, - size); + CompString fileName(PKGDATADIR"/close_dash.png"); + CompSize size(CLOSE_ICON_SIZE, CLOSE_ICON_SIZE); + close_icon_ = GLTexture::readImageToTexture(fileName, + pName, + size); } } // Make the windows header opaque to override the original - GLWindowPaintAttrib sAttrib (attrib); + GLWindowPaintAttrib sAttrib(attrib); sAttrib.opacity = OPAQUE; - ScalePosition pos = sWindow->getCurrentPosition (); + ScalePosition pos = sWindow->getCurrentPosition(); int maxHeight, maxWidth; // Use "2" as margin to make sure to cover all originial decoration - const float width = (window->width () + 4) * pos.scale; - const float x = pos.x () + window->x () - (2 * pos.scale); - const float y = pos.y () + window->y () - SCALE_WINDOW_TITLE_SIZE; + const float width = (window->width() + 4) * pos.scale; + const float x = pos.x() + window->x() - (2 * pos.scale); + const float y = pos.y() + window->y() - SCALE_WINDOW_TITLE_SIZE; const float iconX = x + CLOSE_ICON_SPACE; const float iconY = y + ((SCALE_WINDOW_TITLE_SIZE - CLOSE_ICON_SIZE) / 2.0); maxHeight = maxWidth = 0; - DrawWindowTitle (sAttrib, - transform, - mask, - x, y, - x + width, y + SCALE_WINDOW_TITLE_SIZE); + DrawWindowTitle(sAttrib, + transform, + mask, + x, y, + x + width, y + SCALE_WINDOW_TITLE_SIZE); mask |= PAINT_WINDOW_BLEND_MASK; foreach(GLTexture *icon, close_icon_) { - DrawTexture (icon, sAttrib, transform, mask, - iconX, iconY, - maxWidth , maxHeight); + DrawTexture(icon, sAttrib, transform, mask, + iconX, iconY, + maxWidth , maxHeight); } - close_button_area_ = CompRect (iconX, iconY, maxWidth, maxHeight); + close_button_area_ = CompRect(iconX, iconY, maxWidth, maxHeight); } -void UnityWindow::scaleSelectWindow () +void +UnityWindow::scaleSelectWindow () { UnityScreen* us = UnityScreen::get(screen); if (us->highlighted_window_ != window->id ()) { - CompositeWindow *cWindow = CompositeWindow::get (window); + CompositeWindow *cWindow = CompositeWindow::get(window); if (cWindow) - cWindow->addDamage (); + cWindow->addDamage(); cWindow = 0; - CompWindow *old_window = screen->findWindow (us->highlighted_window_); + CompWindow *old_window = screen->findWindow(us->highlighted_window_); if (old_window) - cWindow = CompositeWindow::get (old_window); + cWindow = CompositeWindow::get(old_window); if (cWindow) - cWindow->addDamage (); + cWindow->addDamage(); - us->highlighted_window_ = window->id (); + us->highlighted_window_ = window->id(); } - ScaleWindow *sWindow = ScaleWindow::get (window); + ScaleWindow *sWindow = ScaleWindow::get(window); if (sWindow) - sWindow->scaleSelectWindow (); + sWindow->scaleSelectWindow(); } UnityWindow::~UnityWindow() diff --git a/plugins/unityshell/src/unityshell.h b/plugins/unityshell/src/unityshell.h index b9afe93d2..6877273ae 100644 --- a/plugins/unityshell/src/unityshell.h +++ b/plugins/unityshell/src/unityshell.h @@ -419,7 +419,7 @@ public: void handleEvent (XEvent *event); - CompRect closeButtonArea (); + CompRect CloseButtonArea(); typedef compiz::CompizMinimizedWindowHandler UnityMinimizedHandler; @@ -430,11 +430,11 @@ public: //! Emited when CompWindowNotifyBeforeDestroy is received sigc::signal being_destroyed; - void scaleSelectWindow (); - void scalePaintDecoration (const GLWindowPaintAttrib &, - const GLMatrix &, - const CompRegion &, - unsigned int); + void scaleSelectWindow(); + void scalePaintDecoration(const GLWindowPaintAttrib &, + const GLMatrix &, + const CompRegion &, + unsigned int); private: void DoEnableFocus (); @@ -467,20 +467,20 @@ private: compiz::WindowInputRemoverLock::Ptr GetInputRemover (); - void DrawWindowTitle (const GLWindowPaintAttrib& attrib, + void DrawWindowTitle(const GLWindowPaintAttrib& attrib, const GLMatrix& transform, unsigned int mask, float x, float y, float x2, float y2); - void DrawTexture (GLTexture *icon, - const GLWindowPaintAttrib& attrib, - const GLMatrix& transform, - unsigned int mask, - float x, float y, - int &maxWidth, int &maxHeight); - void RenderText (WindowCairoContext *context, + void DrawTexture(GLTexture *icon, + const GLWindowPaintAttrib& attrib, + const GLMatrix& transform, + unsigned int mask, float x, float y, - float maxWidth, float maxHeight); - WindowCairoContext* CreateCairoContext (float width, float height); + int &maxWidth, int &maxHeight); + void RenderText(WindowCairoContext *context, + float x, float y, + float maxWidth, float maxHeight); + WindowCairoContext* CreateCairoContext(float width, float height); compiz::WindowInputRemoverLock::Weak input_remover_; glib::Source::UniquePtr focus_desktop_timeout_; -- cgit v1.2.3 From 3cbf1f538a9de45f4526edea095b7392fa7f9f6d Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Fri, 31 Aug 2012 17:18:36 -0300 Subject: Used glib::Object auto pointer instead of "c" pointer. (bzr r2650.1.3) --- plugins/unityshell/src/unityshell.cpp | 5 +---- plugins/unityshell/src/unityshell.h | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) (limited to 'plugins/unityshell/src') diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index 42272fc0c..7e5af8563 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -3718,7 +3718,7 @@ UnityWindow::scalePaintDecoration(const GLWindowPaintAttrib& attrib, gint pos = gtk_widget_path_append_type(widget_path, GTK_TYPE_WINDOW); gtk_widget_path_iter_set_name(widget_path, pos, "UnityPanelWidget"); - window_header_style_ = gtk_style_context_new(); + window_header_style_ = glib::Object(gtk_style_context_new()); gtk_style_context_set_path(window_header_style_, widget_path); gtk_style_context_add_class(window_header_style_, "gnome-panel-menu-bar"); gtk_style_context_add_class(window_header_style_, "unity-panel"); @@ -3828,9 +3828,6 @@ UnityWindow::~UnityWindow() window->minimize (); } - if (window_header_style_) - g_object_unref (window_header_style_); - ShowdesktopHandler::animating_windows.remove (static_cast (this)); if (mShowdesktopHandler) diff --git a/plugins/unityshell/src/unityshell.h b/plugins/unityshell/src/unityshell.h index 6877273ae..6d9ac77af 100644 --- a/plugins/unityshell/src/unityshell.h +++ b/plugins/unityshell/src/unityshell.h @@ -487,7 +487,7 @@ private: GLTexture::List close_icon_; CompRect close_button_area_; - GtkStyleContext* window_header_style_; + glib::Object window_header_style_; }; -- cgit v1.2.3 From cbfce60ada1bd754258145f2d62239121fb341a2 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Fri, 31 Aug 2012 17:57:43 -0300 Subject: Used smart pointers. (bzr r2650.1.4) --- plugins/unityshell/src/unityshell.cpp | 60 +++++++++++++++++------------------ plugins/unityshell/src/unityshell.h | 2 +- 2 files changed, 30 insertions(+), 32 deletions(-) (limited to 'plugins/unityshell/src') diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index 7e5af8563..d7d90aae5 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -3557,44 +3557,43 @@ UnityWindow::DrawTexture(GLTexture* icon, } } -WindowCairoContext* +std::shared_ptr UnityWindow::CreateCairoContext(float width, float height) { XRenderPictFormat *format; Screen *xScreen; - WindowCairoContext *context = new WindowCairoContext(); + std::shared_ptr cContext(new WindowCairoContext()); xScreen = ScreenOfDisplay(screen->dpy(), screen->screenNum()); format = XRenderFindStandardFormat(screen->dpy(), PictStandardARGB32); - context->pixmap_ = XCreatePixmap(screen->dpy(), + cContext->pixmap_ = XCreatePixmap(screen->dpy(), screen->root(), width, height, 32); - context->texture_ = GLTexture::bindPixmapToTexture(context->pixmap_, - width, height, - 32); - if (context->texture_.empty()) + cContext->texture_ = GLTexture::bindPixmapToTexture(cContext->pixmap_, + width, height, + 32); + if (cContext->texture_.empty()) { - delete context; return 0; } - context->surface_ = cairo_xlib_surface_create_with_xrender_format(screen->dpy(), - context->pixmap_, - xScreen, - format, - width, - height); - context->cr_ = cairo_create(context->surface_); + cContext->surface_ = cairo_xlib_surface_create_with_xrender_format(screen->dpy(), + cContext->pixmap_, + xScreen, + format, + width, + height); + cContext->cr_ = cairo_create(cContext->surface_); // clear - cairo_save(context->cr_); - cairo_set_operator(context->cr_, CAIRO_OPERATOR_CLEAR); - cairo_paint(context->cr_); - cairo_restore(context->cr_); + cairo_save(cContext->cr_); + cairo_set_operator(cContext->cr_, CAIRO_OPERATOR_CLEAR); + cairo_paint(cContext->cr_); + cairo_restore(cContext->cr_); - return context; + return cContext; } void @@ -3602,14 +3601,15 @@ UnityWindow::RenderText(WindowCairoContext *context, float x, float y, float maxWidth, float maxHeight) { - PangoFontDescription* font = pango_font_description_new(); - pango_font_description_set_family(font, "sans"); - pango_font_description_set_absolute_size(font, 12 * PANGO_SCALE); - pango_font_description_set_style(font, PANGO_STYLE_NORMAL); - pango_font_description_set_weight(font, PANGO_WEIGHT_BOLD); + std::shared_ptr font(pango_font_description_new(), + pango_font_description_free); + pango_font_description_set_family(font.get(), "sans"); + pango_font_description_set_absolute_size(font.get(), 12 * PANGO_SCALE); + pango_font_description_set_style(font.get(), PANGO_STYLE_NORMAL); + pango_font_description_set_weight(font.get(), PANGO_WEIGHT_BOLD); - PangoLayout* layout = pango_cairo_create_layout(context->cr_); - pango_layout_set_font_description(layout, font); + glib::Object layout(pango_cairo_create_layout(context->cr_)); + pango_layout_set_font_description(layout, font.get()); pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); pango_layout_set_height(layout, maxHeight); @@ -3648,7 +3648,7 @@ UnityWindow::DrawWindowTitle(const GLWindowPaintAttrib& attrib, const float width = x2 - x; // Paint a fake window decoration - WindowCairoContext *context = CreateCairoContext(width, SCALE_WINDOW_TITLE_SIZE); + std::shared_ptr context(CreateCairoContext(width, SCALE_WINDOW_TITLE_SIZE)); cairo_save(context->cr_); cairo_push_group(context->cr_); @@ -3680,7 +3680,7 @@ UnityWindow::DrawWindowTitle(const GLWindowPaintAttrib& attrib, cairo_restore(context->cr_); // Draw windows title - RenderText(context, + RenderText(context.get(), CLOSE_ICON_SPACE * 2 + CLOSE_ICON_SIZE, 0.0, width, SCALE_WINDOW_TITLE_SIZE); @@ -3693,8 +3693,6 @@ UnityWindow::DrawWindowTitle(const GLWindowPaintAttrib& attrib, x, y, maxWidth , maxHeight); } - - delete context; } void diff --git a/plugins/unityshell/src/unityshell.h b/plugins/unityshell/src/unityshell.h index 6d9ac77af..59b5546d6 100644 --- a/plugins/unityshell/src/unityshell.h +++ b/plugins/unityshell/src/unityshell.h @@ -480,7 +480,7 @@ private: void RenderText(WindowCairoContext *context, float x, float y, float maxWidth, float maxHeight); - WindowCairoContext* CreateCairoContext(float width, float height); + std::shared_ptr CreateCairoContext(float width, float height); compiz::WindowInputRemoverLock::Weak input_remover_; glib::Source::UniquePtr focus_desktop_timeout_; -- cgit v1.2.3 From 58c536439f4395df75f282f2cb4eb0f250af1d67 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Fri, 31 Aug 2012 18:18:54 -0300 Subject: Created "WindowCairoContext::Ptr" typedef to make the code more readable. (bzr r2650.1.5) --- plugins/unityshell/src/unityshell.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'plugins/unityshell/src') diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index d7d90aae5..9d61c5519 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -110,6 +110,8 @@ const std::string RELAYOUT_TIMEOUT = "relayout-timeout"; class WindowCairoContext { public: + typedef std::shared_ptr Ptr; + Pixmap pixmap_; cairo_surface_t* surface_; GLTexture::List texture_; @@ -3562,7 +3564,7 @@ UnityWindow::CreateCairoContext(float width, float height) { XRenderPictFormat *format; Screen *xScreen; - std::shared_ptr cContext(new WindowCairoContext()); + auto cContext = std::make_shared(); xScreen = ScreenOfDisplay(screen->dpy(), screen->screenNum()); @@ -3648,7 +3650,7 @@ UnityWindow::DrawWindowTitle(const GLWindowPaintAttrib& attrib, const float width = x2 - x; // Paint a fake window decoration - std::shared_ptr context(CreateCairoContext(width, SCALE_WINDOW_TITLE_SIZE)); + WindowCairoContext::Ptr context(CreateCairoContext(width, SCALE_WINDOW_TITLE_SIZE)); cairo_save(context->cr_); cairo_push_group(context->cr_); -- cgit v1.2.3 From e53f021f53865366fbeced248a21b304f3e6fa2f Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Mon, 3 Sep 2012 10:06:45 -0300 Subject: Used panel style font on windows title decoration; Implemented fade effect on windows title decoration; (bzr r2650.1.7) --- plugins/unityshell/src/unityshell.cpp | 59 ++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 15 deletions(-) (limited to 'plugins/unityshell/src') diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index 9d61c5519..0829e1233 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -3603,29 +3603,33 @@ UnityWindow::RenderText(WindowCairoContext *context, float x, float y, float maxWidth, float maxHeight) { - std::shared_ptr font(pango_font_description_new(), - pango_font_description_free); - pango_font_description_set_family(font.get(), "sans"); - pango_font_description_set_absolute_size(font.get(), 12 * PANGO_SCALE); - pango_font_description_set_style(font.get(), PANGO_STYLE_NORMAL); - pango_font_description_set_weight(font.get(), PANGO_WEIGHT_BOLD); + panel::Style& style = panel::Style::Instance(); + std::string fontDescription(style.GetFontDescription(panel::PanelItem::TITLE)); glib::Object layout(pango_cairo_create_layout(context->cr_)); + std::shared_ptr font(pango_font_description_from_string(fontDescription.c_str()), + pango_font_description_free); + pango_layout_set_font_description(layout, font.get()); - pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END); - pango_layout_set_height(layout, maxHeight); + GdkScreen* gdkScreen = gdk_screen_get_default(); + PangoContext* pCxt = pango_layout_get_context(layout); + int dpi = style.GetTextDPI(); + + pango_cairo_context_set_font_options(pCxt, gdk_screen_get_font_options(gdkScreen)); + pango_cairo_context_set_resolution(pCxt, dpi / static_cast(PANGO_SCALE)); + pango_layout_context_changed(layout); + + pango_layout_set_height(layout, maxHeight); + pango_layout_set_width(layout, -1); //avoid wrap lines pango_layout_set_auto_dir(layout, false); pango_layout_set_text(layout, WindowManager::Default()->GetWindowName(window->id()).c_str(), -1); /* update the size of the pango layout */ - pango_layout_set_width(layout, maxWidth * PANGO_SCALE); pango_cairo_update_layout(context->cr_, layout); - cairo_set_operator(context->cr_, CAIRO_OPERATOR_OVER); - cairo_set_source_rgba(context->cr_, 1.0, 1.0, @@ -3633,12 +3637,37 @@ UnityWindow::RenderText(WindowCairoContext *context, 1.0); // alignment - int lWidth, lHeight; - pango_layout_get_pixel_size(layout, &lWidth, &lHeight); + PangoRectangle lRect; + int textWidth, textHeight; - y = ((maxHeight - lHeight) / 2.0) + y; + pango_layout_get_extents(layout, NULL, &lRect); + textWidth = lRect.width / PANGO_SCALE; + textHeight = lRect.height / PANGO_SCALE; + + y = ((maxHeight - textHeight) / 2.0) + y; cairo_translate(context->cr_, x, y); - pango_cairo_show_layout(context->cr_, layout); + + if (textWidth > (maxWidth - y)) + { + // apply a fade effect in the right corner + int outPixels = textWidth - (maxWidth - y); + const int fadingPixels = 35; + int fadingWidth = outPixels < fadingPixels ? outPixels : fadingPixels; + + cairo_push_group(context->cr_); + pango_cairo_show_layout(context->cr_, layout); + cairo_pop_group_to_source(context->cr_); + + std::shared_ptr linpat(cairo_pattern_create_linear(fadingWidth, y, maxWidth, y), + cairo_pattern_destroy); + cairo_pattern_add_color_stop_rgba(linpat.get(), 0, 0, 0, 0, 1); + cairo_pattern_add_color_stop_rgba(linpat.get(), 1, 0, 0, 0, 0); + cairo_mask(context->cr_, linpat.get()); + } + else + { + pango_cairo_show_layout(context->cr_, layout); + } } void -- cgit v1.2.3 From 79f5afb7abe2e59f51f52e3b873186d4911e3219 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Mon, 3 Sep 2012 21:57:40 -0300 Subject: Fixed fade effect on title bar; Fixed window title alignment; (bzr r2650.1.8) --- plugins/unityshell/src/unityshell.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'plugins/unityshell/src') diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index 0829e1233..bfe31470d 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -3647,18 +3647,19 @@ UnityWindow::RenderText(WindowCairoContext *context, y = ((maxHeight - textHeight) / 2.0) + y; cairo_translate(context->cr_, x, y); - if (textWidth > (maxWidth - y)) + if (textWidth > maxWidth) { // apply a fade effect in the right corner - int outPixels = textWidth - (maxWidth - y); + const int outPixels = textWidth - maxWidth; const int fadingPixels = 35; - int fadingWidth = outPixels < fadingPixels ? outPixels : fadingPixels; + const int fadingWidth = outPixels < fadingPixels ? outPixels : fadingPixels; cairo_push_group(context->cr_); pango_cairo_show_layout(context->cr_, layout); cairo_pop_group_to_source(context->cr_); - std::shared_ptr linpat(cairo_pattern_create_linear(fadingWidth, y, maxWidth, y), + std::shared_ptr linpat(cairo_pattern_create_linear(maxWidth - fadingWidth, + y, maxWidth, y), cairo_pattern_destroy); cairo_pattern_add_color_stop_rgba(linpat.get(), 0, 0, 0, 0, 1); cairo_pattern_add_color_stop_rgba(linpat.get(), 1, 0, 0, 0, 0); @@ -3711,10 +3712,10 @@ UnityWindow::DrawWindowTitle(const GLWindowPaintAttrib& attrib, cairo_restore(context->cr_); // Draw windows title + const float xText = CLOSE_ICON_SPACE * 2 + CLOSE_ICON_SIZE; RenderText(context.get(), - CLOSE_ICON_SPACE * 2 + CLOSE_ICON_SIZE, - 0.0, - width, SCALE_WINDOW_TITLE_SIZE); + xText, 0.0, + width - xText, SCALE_WINDOW_TITLE_SIZE); mask |= PAINT_WINDOW_BLEND_MASK; int maxWidth, maxHeight; @@ -3786,9 +3787,9 @@ UnityWindow::scalePaintDecoration(const GLWindowPaintAttrib& attrib, ScalePosition pos = sWindow->getCurrentPosition(); int maxHeight, maxWidth; - // Use "2" as margin to make sure to cover all originial decoration - const float width = (window->width() + 4) * pos.scale; - const float x = pos.x() + window->x() - (2 * pos.scale); + // Use "1" as margin to make sure to cover all originial decoration + const float width = (window->width() * pos.scale) + 2; + const float x = pos.x() + window->x() - 1; const float y = pos.y() + window->y() - SCALE_WINDOW_TITLE_SIZE; const float iconX = x + CLOSE_ICON_SPACE; const float iconY = y + ((SCALE_WINDOW_TITLE_SIZE - CLOSE_ICON_SIZE) / 2.0); -- cgit v1.2.3 From 91b9ab1b239a1e6d58dbfd52f8a12d08bcabe3fa Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Mon, 3 Sep 2012 22:31:20 -0300 Subject: Renamed DrawTitle function. (bzr r2650.1.9) --- plugins/unityshell/src/unityshell.cpp | 19 ++++++++----------- plugins/unityshell/src/unityshell.h | 8 ++++---- 2 files changed, 12 insertions(+), 15 deletions(-) (limited to 'plugins/unityshell/src') diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index bfe31470d..7c23f00c3 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -3672,10 +3672,10 @@ UnityWindow::RenderText(WindowCairoContext *context, } void -UnityWindow::DrawWindowTitle(const GLWindowPaintAttrib& attrib, - const GLMatrix& transform, - unsigned int mask, - float x, float y, float x2, float y2) +UnityWindow::DrawWindowDecoration(const GLWindowPaintAttrib& attrib, + const GLMatrix& transform, + unsigned int mask, + float x, float y, float x2, float y2) { const float width = x2 - x; @@ -3794,15 +3794,12 @@ UnityWindow::scalePaintDecoration(const GLWindowPaintAttrib& attrib, const float iconX = x + CLOSE_ICON_SPACE; const float iconY = y + ((SCALE_WINDOW_TITLE_SIZE - CLOSE_ICON_SIZE) / 2.0); - maxHeight = maxWidth = 0; - - DrawWindowTitle(sAttrib, - transform, - mask, - x, y, - x + width, y + SCALE_WINDOW_TITLE_SIZE); + DrawWindowDecoration(sAttrib, transform, mask, + x, y, + x + width, y + SCALE_WINDOW_TITLE_SIZE); mask |= PAINT_WINDOW_BLEND_MASK; + maxHeight = maxWidth = 0; foreach(GLTexture *icon, close_icon_) { DrawTexture(icon, sAttrib, transform, mask, diff --git a/plugins/unityshell/src/unityshell.h b/plugins/unityshell/src/unityshell.h index 59b5546d6..2caf745dd 100644 --- a/plugins/unityshell/src/unityshell.h +++ b/plugins/unityshell/src/unityshell.h @@ -467,10 +467,10 @@ private: compiz::WindowInputRemoverLock::Ptr GetInputRemover (); - void DrawWindowTitle(const GLWindowPaintAttrib& attrib, - const GLMatrix& transform, - unsigned int mask, - float x, float y, float x2, float y2); + void DrawWindowDecoration(const GLWindowPaintAttrib& attrib, + const GLMatrix& transform, + unsigned int mask, + float x, float y, float x2, float y2); void DrawTexture(GLTexture *icon, const GLWindowPaintAttrib& attrib, const GLMatrix& transform, -- cgit v1.2.3 From 908d88658deb4190aae5c5f3e9fef25c9f7b7825 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Tue, 4 Sep 2012 09:51:22 -0300 Subject: Fixed windows decoration for maximized windows. (bzr r2650.1.10) --- plugins/unityshell/src/unityshell.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'plugins/unityshell/src') diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index 7c23f00c3..3d40eb65c 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -3790,7 +3790,14 @@ UnityWindow::scalePaintDecoration(const GLWindowPaintAttrib& attrib, // Use "1" as margin to make sure to cover all originial decoration const float width = (window->width() * pos.scale) + 2; const float x = pos.x() + window->x() - 1; - const float y = pos.y() + window->y() - SCALE_WINDOW_TITLE_SIZE; + float y = pos.y() + window->y(); + + // If window is decorated draw the decoration over the original + // otherwise draw inside the window + WindowManager *wm = WindowManager::Default(); + if (wm->IsWindowDecorated(window->id()) && !wm->IsWindowMaximized(window->id())) + y -= SCALE_WINDOW_TITLE_SIZE; + const float iconX = x + CLOSE_ICON_SPACE; const float iconY = y + ((SCALE_WINDOW_TITLE_SIZE - CLOSE_ICON_SIZE) / 2.0); -- cgit v1.2.3 From 5182a9065ab28d7c7921d34f7f25c9c5e3b29524 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Tue, 4 Sep 2012 12:26:06 -0300 Subject: Removed all originial decoration when window is in scale mode; Draw window decoration inside of window following the designer docs; (bzr r2650.1.11) --- plugins/unityshell/src/unityshell.cpp | 140 ++++++++++++++++++++++++---------- plugins/unityshell/src/unityshell.h | 11 ++- 2 files changed, 109 insertions(+), 42 deletions(-) (limited to 'plugins/unityshell/src') diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index 3d40eb65c..0e79a44a4 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -423,7 +423,10 @@ UnityScreen::UnityScreen(CompScreen* screen) } panel::Style::Instance().changed.connect(sigc::mem_fun(this, &UnityScreen::OnPanelStyleChanged)); - + + WindowManager::Default()->initiate_spread.connect(sigc::mem_fun(this, &UnityScreen::OnInitiateSpreed)); + WindowManager::Default()->terminate_spread.connect(sigc::mem_fun(this, &UnityScreen::OnTerminateSpreed)); + minimize_speed_controller->DurationChanged.connect( sigc::mem_fun(this, &UnityScreen::OnMinimizeDurationChanged) ); @@ -440,6 +443,25 @@ UnityScreen::~UnityScreen() reset_glib_logging(); } +void UnityScreen::OnInitiateSpreed() +{ + for (CompWindow *w : screen->windows()) + { + UnityWindow *uw = UnityWindow::get(w); + uw->InitiateSpreed(); + } +} + +void UnityScreen::OnTerminateSpreed() +{ + for (CompWindow *w : screen->windows()) + { + UnityWindow *uw = UnityWindow::get(w); + uw->TerminateSpreed(); + } +} + + void UnityScreen::initAltTabNextWindow() { KeyboardUtil key_util(screen->dpy()); @@ -3675,18 +3697,19 @@ void UnityWindow::DrawWindowDecoration(const GLWindowPaintAttrib& attrib, const GLMatrix& transform, unsigned int mask, + bool highlighted, float x, float y, float x2, float y2) { const float width = x2 - x; + const float height = y2 - y; // Paint a fake window decoration - WindowCairoContext::Ptr context(CreateCairoContext(width, SCALE_WINDOW_TITLE_SIZE)); + WindowCairoContext::Ptr context(CreateCairoContext(width, height)); cairo_save(context->cr_); cairo_push_group(context->cr_); // Round window decoration top border - const double height = SCALE_WINDOW_TITLE_SIZE; const double aspect = 1.0; const double corner_radius = height / 10.0; const double radius = corner_radius / aspect; @@ -3703,19 +3726,22 @@ UnityWindow::DrawWindowDecoration(const GLWindowPaintAttrib& attrib, cairo_clip(context->cr_); // Draw window decoration abased on gtk style - gtk_render_background(window_header_style_, context->cr_, 0, 0, width, SCALE_WINDOW_TITLE_SIZE); - gtk_render_frame(window_header_style_, context->cr_, 0, 0, width, SCALE_WINDOW_TITLE_SIZE); + gtk_render_background(window_header_style_, context->cr_, 0, 0, width, height); + gtk_render_frame(window_header_style_, context->cr_, 0, 0, width, height); cairo_pop_group_to_source(context->cr_); cairo_paint_with_alpha(context->cr_, 1.0); cairo_restore(context->cr_); - // Draw windows title - const float xText = CLOSE_ICON_SPACE * 2 + CLOSE_ICON_SIZE; - RenderText(context.get(), - xText, 0.0, - width - xText, SCALE_WINDOW_TITLE_SIZE); + if (highlighted) + { + // Draw windows title + const float xText = CLOSE_ICON_SPACE * 2 + CLOSE_ICON_SIZE; + RenderText(context.get(), + xText, 0.0, + width - xText, height); + } mask |= PAINT_WINDOW_BLEND_MASK; int maxWidth, maxHeight; @@ -3728,20 +3754,8 @@ UnityWindow::DrawWindowDecoration(const GLWindowPaintAttrib& attrib, } void -UnityWindow::scalePaintDecoration(const GLWindowPaintAttrib& attrib, - const GLMatrix& transform, - const CompRegion& region, - unsigned int mask) +UnityWindow::PrepareHeaderStyle() { - ScaleWindow *sWindow = ScaleWindow::get(window); - if (!sWindow) - return; - - sWindow->scalePaintDecoration(attrib, transform, region, mask); - - if (!sWindow->hasSlot()) // animation not finished - return; - if (!window_header_style_) { GtkWidgetPath* widget_path = gtk_widget_path_new(); @@ -3780,41 +3794,68 @@ UnityWindow::scalePaintDecoration(const GLWindowPaintAttrib& attrib, size); } } +} + +void +UnityWindow::scalePaintDecoration(const GLWindowPaintAttrib& attrib, + const GLMatrix& transform, + const CompRegion& region, + unsigned int mask) +{ + ScaleWindow *sWindow = ScaleWindow::get(window); + if (!sWindow) + return; + + sWindow->scalePaintDecoration(attrib, transform, region, mask); - // Make the windows header opaque to override the original + if (!sWindow->hasSlot()) // animation not finished + return; + + UnityScreen* us = UnityScreen::get(screen); + const guint32 xid = window->id(); + const bool highlighted = (us->highlighted_window_ == xid); GLWindowPaintAttrib sAttrib(attrib); sAttrib.opacity = OPAQUE; + PrepareHeaderStyle(); + ScalePosition pos = sWindow->getCurrentPosition(); int maxHeight, maxWidth; // Use "1" as margin to make sure to cover all originial decoration const float width = (window->width() * pos.scale) + 2; const float x = pos.x() + window->x() - 1; float y = pos.y() + window->y(); + float decorationHeight = SCALE_WINDOW_TITLE_SIZE; // If window is decorated draw the decoration over the original - // otherwise draw inside the window - WindowManager *wm = WindowManager::Default(); - if (wm->IsWindowDecorated(window->id()) && !wm->IsWindowMaximized(window->id())) - y -= SCALE_WINDOW_TITLE_SIZE; - - const float iconX = x + CLOSE_ICON_SPACE; - const float iconY = y + ((SCALE_WINDOW_TITLE_SIZE - CLOSE_ICON_SIZE) / 2.0); + // otherwise draw a small bar over the window + if (!highlighted) + decorationHeight = SCALE_WINDOW_TITLE_SIZE * 0.30; - DrawWindowDecoration(sAttrib, transform, mask, + DrawWindowDecoration(sAttrib, transform, mask, highlighted, x, y, - x + width, y + SCALE_WINDOW_TITLE_SIZE); + x + width, y + decorationHeight); - mask |= PAINT_WINDOW_BLEND_MASK; - maxHeight = maxWidth = 0; - foreach(GLTexture *icon, close_icon_) + if (highlighted) { - DrawTexture(icon, sAttrib, transform, mask, - iconX, iconY, - maxWidth , maxHeight); - } + const float iconX = x + CLOSE_ICON_SPACE; + const float iconY = y + ((SCALE_WINDOW_TITLE_SIZE - CLOSE_ICON_SIZE) / 2.0); + maxHeight = maxWidth = 0; + mask |= PAINT_WINDOW_BLEND_MASK; + + foreach(GLTexture *icon, close_icon_) + { + DrawTexture(icon, sAttrib, transform, mask, + iconX, iconY, + maxWidth , maxHeight); + } - close_button_area_ = CompRect(iconX, iconY, maxWidth, maxHeight); + close_button_area_ = CompRect(iconX, iconY, maxWidth, maxHeight); + } + else + { + close_button_area_ = CompRect(); + } } void @@ -3844,6 +3885,23 @@ UnityWindow::scaleSelectWindow () sWindow->scaleSelectWindow(); } +void UnityWindow::InitiateSpreed() +{ + WindowManager *wm = WindowManager::Default(); + const guint32 xid = window->id(); + has_original_decoration_ = wm->IsWindowDecorated(xid) && + !wm->IsWindowMaximized(xid); + wm->Undecorate(xid); +} + +void UnityWindow::TerminateSpreed() +{ + if (has_original_decoration_) + WindowManager::Default()->Decorate(window->id()); + else + WindowManager::Default()->Undecorate(window->id()); +} + UnityWindow::~UnityWindow() { UnityScreen* us = UnityScreen::get(screen); diff --git a/plugins/unityshell/src/unityshell.h b/plugins/unityshell/src/unityshell.h index 2caf745dd..7ad71ac03 100644 --- a/plugins/unityshell/src/unityshell.h +++ b/plugins/unityshell/src/unityshell.h @@ -249,7 +249,10 @@ private: void OnPanelStyleChanged(); void InitGesturesSupport(); - + + void OnInitiateSpreed(); + void OnTerminateSpreed(); + nux::animation::TickSource tick_source_; nux::animation::AnimationController animation_controller_; @@ -436,6 +439,9 @@ public: const CompRegion &, unsigned int); + void InitiateSpreed(); + void TerminateSpreed(); + private: void DoEnableFocus (); void DoDisableFocus (); @@ -470,6 +476,7 @@ private: void DrawWindowDecoration(const GLWindowPaintAttrib& attrib, const GLMatrix& transform, unsigned int mask, + bool highlighted, float x, float y, float x2, float y2); void DrawTexture(GLTexture *icon, const GLWindowPaintAttrib& attrib, @@ -480,6 +487,7 @@ private: void RenderText(WindowCairoContext *context, float x, float y, float maxWidth, float maxHeight); + void PrepareHeaderStyle(); std::shared_ptr CreateCairoContext(float width, float height); compiz::WindowInputRemoverLock::Weak input_remover_; @@ -488,6 +496,7 @@ private: GLTexture::List close_icon_; CompRect close_button_area_; glib::Object window_header_style_; + bool has_original_decoration_; }; -- cgit v1.2.3 From ad529eec1b446a63ece2f794a622bffec5e789e0 Mon Sep 17 00:00:00 2001 From: Renato Araujo Oliveira Filho Date: Tue, 4 Sep 2012 14:14:38 -0300 Subject: Code optimizations. (bzr r2650.1.12) --- plugins/unityshell/src/unityshell.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'plugins/unityshell/src') diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index 0e79a44a4..e0e36b40a 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -3827,7 +3827,7 @@ UnityWindow::scalePaintDecoration(const GLWindowPaintAttrib& attrib, float y = pos.y() + window->y(); float decorationHeight = SCALE_WINDOW_TITLE_SIZE; - // If window is decorated draw the decoration over the original + // If window is decorated draw the decoration // otherwise draw a small bar over the window if (!highlighted) decorationHeight = SCALE_WINDOW_TITLE_SIZE * 0.30; @@ -3839,7 +3839,7 @@ UnityWindow::scalePaintDecoration(const GLWindowPaintAttrib& attrib, if (highlighted) { const float iconX = x + CLOSE_ICON_SPACE; - const float iconY = y + ((SCALE_WINDOW_TITLE_SIZE - CLOSE_ICON_SIZE) / 2.0); + const float iconY = y + ((decorationHeight - CLOSE_ICON_SIZE) / 2.0); maxHeight = maxWidth = 0; mask |= PAINT_WINDOW_BLEND_MASK; @@ -3891,15 +3891,14 @@ void UnityWindow::InitiateSpreed() const guint32 xid = window->id(); has_original_decoration_ = wm->IsWindowDecorated(xid) && !wm->IsWindowMaximized(xid); - wm->Undecorate(xid); + if (has_original_decoration_) + wm->Undecorate(xid); } void UnityWindow::TerminateSpreed() { if (has_original_decoration_) WindowManager::Default()->Decorate(window->id()); - else - WindowManager::Default()->Undecorate(window->id()); } UnityWindow::~UnityWindow() -- cgit v1.2.3 From 7faef9921cc40e922489e301612ab6ce8775e6bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 5 Sep 2012 02:07:53 +0200 Subject: unityshell: on spread decorate all windows, draw the new decoration above them (bzr r2655.5.2) --- plugins/unityshell/src/unityshell.cpp | 54 ++++++++++++++++------------------- 1 file changed, 24 insertions(+), 30 deletions(-) (limited to 'plugins/unityshell/src') diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index e0e36b40a..3f009f42b 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -85,7 +85,6 @@ UnityScreen* uScreen = 0; static unsigned int CLOSE_ICON_SIZE = 19; static unsigned int CLOSE_ICON_SPACE = 5; -static unsigned int SCALE_WINDOW_TITLE_SIZE = 28; void reset_glib_logging(); void configure_logging(); @@ -3811,48 +3810,43 @@ UnityWindow::scalePaintDecoration(const GLWindowPaintAttrib& attrib, if (!sWindow->hasSlot()) // animation not finished return; + PrepareHeaderStyle(); UnityScreen* us = UnityScreen::get(screen); const guint32 xid = window->id(); const bool highlighted = (us->highlighted_window_ == xid); GLWindowPaintAttrib sAttrib(attrib); sAttrib.opacity = OPAQUE; - PrepareHeaderStyle(); + ScalePosition const& pos = sWindow->getCurrentPosition(); + auto const& border_rect = window->borderRect(); + auto const& deco_ext = window->border(); - ScalePosition pos = sWindow->getCurrentPosition(); - int maxHeight, maxWidth; - // Use "1" as margin to make sure to cover all originial decoration - const float width = (window->width() * pos.scale) + 2; - const float x = pos.x() + window->x() - 1; - float y = pos.y() + window->y(); - float decorationHeight = SCALE_WINDOW_TITLE_SIZE; + const unsigned decoration_height = deco_ext.top; + unsigned width = (border_rect.width() + deco_ext.left + deco_ext.right) * pos.scale; + unsigned height = decoration_height * pos.scale; + int x = pos.x() + border_rect.x(); + int y = pos.y() + border_rect.y() + decoration_height - height - 1; - // If window is decorated draw the decoration - // otherwise draw a small bar over the window - if (!highlighted) - decorationHeight = SCALE_WINDOW_TITLE_SIZE * 0.30; + // If window is highlighted, we draw the decoration at full size + if (highlighted) + height = decoration_height; - DrawWindowDecoration(sAttrib, transform, mask, highlighted, - x, y, - x + width, y + decorationHeight); + DrawWindowDecoration(sAttrib, transform, mask, highlighted, x, y, width, height); if (highlighted) { - const float iconX = x + CLOSE_ICON_SPACE; - const float iconY = y + ((decorationHeight - CLOSE_ICON_SIZE) / 2.0); - maxHeight = maxWidth = 0; + x += CLOSE_ICON_SPACE; + y += (decoration_height - CLOSE_ICON_SIZE) / 2.0f; + int max_height = 0; + int max_width = 0; mask |= PAINT_WINDOW_BLEND_MASK; - foreach(GLTexture *icon, close_icon_) - { - DrawTexture(icon, sAttrib, transform, mask, - iconX, iconY, - maxWidth , maxHeight); - } + for (GLTexture *icon : close_icon_) + DrawTexture(icon, sAttrib, transform, mask, x, y, max_width , max_height); - close_button_area_ = CompRect(iconX, iconY, maxWidth, maxHeight); + close_button_area_ = CompRect(x, y, max_height, max_width); } - else + else if (!close_button_area_.isEmpty()) { close_button_area_ = CompRect(); } @@ -3890,15 +3884,15 @@ void UnityWindow::InitiateSpreed() WindowManager *wm = WindowManager::Default(); const guint32 xid = window->id(); has_original_decoration_ = wm->IsWindowDecorated(xid) && - !wm->IsWindowMaximized(xid); + wm->IsWindowMaximized(xid); if (has_original_decoration_) - wm->Undecorate(xid); + wm->Decorate(xid); } void UnityWindow::TerminateSpreed() { if (has_original_decoration_) - WindowManager::Default()->Decorate(window->id()); + WindowManager::Default()->Undecorate(window->id()); } UnityWindow::~UnityWindow() -- cgit v1.2.3 From 130b11bbdab7782fa09def65b05f184068271d29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 5 Sep 2012 02:14:27 +0200 Subject: UnityWindow: use smart pointers, use static close_icon and panelStyle context This should save a lot of computation per each scale window. (bzr r2655.5.3) --- plugins/unityshell/src/unityshell.cpp | 171 +++++++++++++--------------------- plugins/unityshell/src/unityshell.h | 30 +++--- 2 files changed, 77 insertions(+), 124 deletions(-) (limited to 'plugins/unityshell/src') diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index 3f009f42b..c834a3b30 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -83,8 +83,8 @@ nux::logging::Logger logger("unity.shell"); UnityScreen* uScreen = 0; -static unsigned int CLOSE_ICON_SIZE = 19; -static unsigned int CLOSE_ICON_SPACE = 5; +const unsigned int SCALE_CLOSE_ICON_SIZE = 19; +const unsigned int SCALE_CLOSE_ICON_SPACE = 5; void reset_glib_logging(); void configure_logging(); @@ -423,9 +423,6 @@ UnityScreen::UnityScreen(CompScreen* screen) panel::Style::Instance().changed.connect(sigc::mem_fun(this, &UnityScreen::OnPanelStyleChanged)); - WindowManager::Default()->initiate_spread.connect(sigc::mem_fun(this, &UnityScreen::OnInitiateSpreed)); - WindowManager::Default()->terminate_spread.connect(sigc::mem_fun(this, &UnityScreen::OnTerminateSpreed)); - minimize_speed_controller->DurationChanged.connect( sigc::mem_fun(this, &UnityScreen::OnMinimizeDurationChanged) ); @@ -442,25 +439,6 @@ UnityScreen::~UnityScreen() reset_glib_logging(); } -void UnityScreen::OnInitiateSpreed() -{ - for (CompWindow *w : screen->windows()) - { - UnityWindow *uw = UnityWindow::get(w); - uw->InitiateSpreed(); - } -} - -void UnityScreen::OnTerminateSpreed() -{ - for (CompWindow *w : screen->windows()) - { - UnityWindow *uw = UnityWindow::get(w); - uw->TerminateSpreed(); - } -} - - void UnityScreen::initAltTabNextWindow() { KeyboardUtil key_util(screen->dpy()); @@ -1117,8 +1095,8 @@ void UnityScreen::leaveShowDesktopMode (CompWindow *w) void UnityWindow::enterShowDesktop () { if (!mShowdesktopHandler) - mShowdesktopHandler = new ShowdesktopHandler (static_cast (this), - static_cast (this)); + mShowdesktopHandler.reset(new ShowdesktopHandler(static_cast (this), + static_cast (this))); window->setShowDesktopMode (true); mShowdesktopHandler->FadeOut (); @@ -1246,8 +1224,7 @@ void UnityWindow::DoAddDamage () void UnityWindow::DoDeleteHandler () { - delete mShowdesktopHandler; - mShowdesktopHandler = NULL; + mShowdesktopHandler.reset(); window->updateFrameRegion (); } @@ -1283,7 +1260,7 @@ void UnityWindow::handleEvent (XEvent *event) CompRect UnityWindow::CloseButtonArea() { - return close_button_area_; + return close_button_area_; } bool UnityScreen::shellCouldBeHidden(CompOutput const& output) @@ -3485,14 +3462,13 @@ void UnityScreen::InitGesturesSupport() } /* Window init */ +GLTexture::List UnityWindow::close_icon_; + UnityWindow::UnityWindow(CompWindow* window) : BaseSwitchWindow (dynamic_cast (UnityScreen::get (screen)), window) , PluginClassHandler(window) , window(window) , gWindow(GLWindow::get(window)) - , mMinimizeHandler() - , mShowdesktopHandler(nullptr) - , window_header_style_(0) { WindowInterface::setHandler(window); GLWindowInterface::setHandler(gWindow); @@ -3539,6 +3515,9 @@ UnityWindow::UnityWindow(CompWindow* window) } } } + + WindowManager::Default()->initiate_spread.connect(sigc::mem_fun(this, &UnityWindow::OnInitiateSpreed)); + WindowManager::Default()->terminate_spread.connect(sigc::mem_fun(this, &UnityWindow::OnTerminateSpreed)); } void @@ -3590,17 +3569,13 @@ UnityWindow::CreateCairoContext(float width, float height) xScreen = ScreenOfDisplay(screen->dpy(), screen->screenNum()); format = XRenderFindStandardFormat(screen->dpy(), PictStandardARGB32); - cContext->pixmap_ = XCreatePixmap(screen->dpy(), - screen->root(), - width, height, 32); + cContext->pixmap_ = XCreatePixmap(screen->dpy(), screen->root(), + width, height, 32); cContext->texture_ = GLTexture::bindPixmapToTexture(cContext->pixmap_, - width, height, - 32); + width, height, 32); if (cContext->texture_.empty()) - { - return 0; - } + return nullptr; cContext->surface_ = cairo_xlib_surface_create_with_xrender_format(screen->dpy(), cContext->pixmap_, @@ -3620,7 +3595,7 @@ UnityWindow::CreateCairoContext(float width, float height) } void -UnityWindow::RenderText(WindowCairoContext *context, +UnityWindow::RenderText(WindowCairoContext::Ptr const& context, float x, float y, float maxWidth, float maxHeight) { @@ -3693,15 +3668,12 @@ UnityWindow::RenderText(WindowCairoContext *context, } void -UnityWindow::DrawWindowDecoration(const GLWindowPaintAttrib& attrib, - const GLMatrix& transform, +UnityWindow::DrawWindowDecoration(GLWindowPaintAttrib const& attrib, + GLMatrix const& transform, unsigned int mask, bool highlighted, - float x, float y, float x2, float y2) + int x, int y, unsigned width, unsigned height) { - const float width = x2 - x; - const float height = y2 - y; - // Paint a fake window decoration WindowCairoContext::Ptr context(CreateCairoContext(width, height)); @@ -3724,9 +3696,10 @@ UnityWindow::DrawWindowDecoration(const GLWindowPaintAttrib& attrib, cairo_close_path(context->cr_); cairo_clip(context->cr_); - // Draw window decoration abased on gtk style - gtk_render_background(window_header_style_, context->cr_, 0, 0, width, height); - gtk_render_frame(window_header_style_, context->cr_, 0, 0, width, height); + // Draw window decoration based on gtk style + auto& style = panel::Style::Instance(); + gtk_render_background(style.GetStyleContext(), context->cr_, 0, 0, width, height); + gtk_render_frame(style.GetStyleContext(), context->cr_, 0, 0, width, height); cairo_pop_group_to_source(context->cr_); @@ -3736,70 +3709,48 @@ UnityWindow::DrawWindowDecoration(const GLWindowPaintAttrib& attrib, if (highlighted) { // Draw windows title - const float xText = CLOSE_ICON_SPACE * 2 + CLOSE_ICON_SIZE; - RenderText(context.get(), - xText, 0.0, - width - xText, height); + const float xText = SCALE_CLOSE_ICON_SPACE * 2 + SCALE_CLOSE_ICON_SIZE; + RenderText(context, xText, 0.0, width - xText, height); } mask |= PAINT_WINDOW_BLEND_MASK; int maxWidth, maxHeight; foreach(GLTexture *icon, context->texture_) { - DrawTexture(icon, attrib, transform, mask, - x, y, - maxWidth , maxHeight); + DrawTexture(icon, attrib, transform, mask, x, y, maxWidth , maxHeight); } } -void -UnityWindow::PrepareHeaderStyle() +void UnityWindow::SetupScaleHeaderStyle() { - if (!window_header_style_) + if (close_icon_.empty()) { - GtkWidgetPath* widget_path = gtk_widget_path_new(); - gint pos = gtk_widget_path_append_type(widget_path, GTK_TYPE_WINDOW); - gtk_widget_path_iter_set_name(widget_path, pos, "UnityPanelWidget"); - - window_header_style_ = glib::Object(gtk_style_context_new()); - gtk_style_context_set_path(window_header_style_, widget_path); - gtk_style_context_add_class(window_header_style_, "gnome-panel-menu-bar"); - gtk_style_context_add_class(window_header_style_, "unity-panel"); - - // get close button - panel::Style& style = panel::Style::Instance(); - - std::vector files = style.GetWindowButtonFileNames(panel::WindowButtonType::CLOSE, - panel::WindowState::NORMAL); + auto& style = panel::Style::Instance(); + auto const& files = style.GetWindowButtonFileNames(panel::WindowButtonType::CLOSE, panel::WindowState::NORMAL); CompString pName("unityshell"); - foreach (std::string file, files) + for (std::string const& file : files) { - CompString fileName(file.c_str ()); - CompSize size(CLOSE_ICON_SIZE, CLOSE_ICON_SIZE); - close_icon_ = GLTexture::readImageToTexture(fileName, - pName, - size); - if (close_icon_.size() != 0) + CompString fileName(file.c_str()); + CompSize size(SCALE_CLOSE_ICON_SIZE, SCALE_CLOSE_ICON_SIZE); + close_icon_ = GLTexture::readImageToTexture(fileName, pName, size); + if (!close_icon_.empty()) break; } - if (close_icon_.size() == 0) + if (close_icon_.empty()) { CompString fileName(PKGDATADIR"/close_dash.png"); - CompSize size(CLOSE_ICON_SIZE, CLOSE_ICON_SIZE); - close_icon_ = GLTexture::readImageToTexture(fileName, - pName, - size); + CompSize size(SCALE_CLOSE_ICON_SIZE, SCALE_CLOSE_ICON_SIZE); + close_icon_ = GLTexture::readImageToTexture(fileName, pName, size); } } } -void -UnityWindow::scalePaintDecoration(const GLWindowPaintAttrib& attrib, - const GLMatrix& transform, - const CompRegion& region, - unsigned int mask) +void UnityWindow::scalePaintDecoration(GLWindowPaintAttrib const& attrib, + GLMatrix const& transform, + CompRegion const& region, + unsigned int mask) { ScaleWindow *sWindow = ScaleWindow::get(window); if (!sWindow) @@ -3810,7 +3761,6 @@ UnityWindow::scalePaintDecoration(const GLWindowPaintAttrib& attrib, if (!sWindow->hasSlot()) // animation not finished return; - PrepareHeaderStyle(); UnityScreen* us = UnityScreen::get(screen); const guint32 xid = window->id(); const bool highlighted = (us->highlighted_window_ == xid); @@ -3835,8 +3785,8 @@ UnityWindow::scalePaintDecoration(const GLWindowPaintAttrib& attrib, if (highlighted) { - x += CLOSE_ICON_SPACE; - y += (decoration_height - CLOSE_ICON_SIZE) / 2.0f; + x += SCALE_CLOSE_ICON_SPACE; + y += (decoration_height - SCALE_CLOSE_ICON_SIZE) / 2.0f; int max_height = 0; int max_width = 0; mask |= PAINT_WINDOW_BLEND_MASK; @@ -3879,20 +3829,32 @@ UnityWindow::scaleSelectWindow () sWindow->scaleSelectWindow(); } -void UnityWindow::InitiateSpreed() +void UnityWindow::OnInitiateSpreed() { + auto const windows = screen->windows(); + if (std::find(windows.begin(), windows.end(), window) == windows.end()) + return; + + SetupScaleHeaderStyle(); + WindowManager *wm = WindowManager::Default(); - const guint32 xid = window->id(); - has_original_decoration_ = wm->IsWindowDecorated(xid) && - wm->IsWindowMaximized(xid); - if (has_original_decoration_) + Window xid = window->id(); + + if (wm->IsWindowDecorated(xid)) wm->Decorate(xid); } -void UnityWindow::TerminateSpreed() +void UnityWindow::OnTerminateSpreed() { - if (has_original_decoration_) - WindowManager::Default()->Undecorate(window->id()); + auto const windows = screen->windows(); + if (std::find(windows.begin(), windows.end(), window) == windows.end()) + return; + + WindowManager *wm = WindowManager::Default(); + Window xid = window->id(); + + if (wm->IsWindowDecorated(xid) && wm->IsWindowMaximized(xid)) + wm->Undecorate(xid); } UnityWindow::~UnityWindow() @@ -3915,13 +3877,10 @@ UnityWindow::~UnityWindow() ShowdesktopHandler::animating_windows.remove (static_cast (this)); - if (mShowdesktopHandler) - delete mShowdesktopHandler; - if (window->state () & CompWindowStateFullscreenMask) UnityScreen::get (screen)->fullscreen_windows_.remove(window); - PluginAdapter::Default ()->OnWindowClosed (window); + PluginAdapter::Default ()->OnWindowClosed(window); } /* vtable init */ diff --git a/plugins/unityshell/src/unityshell.h b/plugins/unityshell/src/unityshell.h index 7ad71ac03..58e259c32 100644 --- a/plugins/unityshell/src/unityshell.h +++ b/plugins/unityshell/src/unityshell.h @@ -250,9 +250,6 @@ private: void InitGesturesSupport(); - void OnInitiateSpreed(); - void OnTerminateSpreed(); - nux::animation::TickSource tick_source_; nux::animation::AnimationController animation_controller_; @@ -427,8 +424,7 @@ public: typedef compiz::CompizMinimizedWindowHandler UnityMinimizedHandler; std::unique_ptr mMinimizeHandler; - - ShowdesktopHandler *mShowdesktopHandler; + std::unique_ptr mShowdesktopHandler; //! Emited when CompWindowNotifyBeforeDestroy is received sigc::signal being_destroyed; @@ -439,9 +435,6 @@ public: const CompRegion &, unsigned int); - void InitiateSpreed(); - void TerminateSpreed(); - private: void DoEnableFocus (); void DoDisableFocus (); @@ -462,6 +455,9 @@ private: void DoShow (); void DoNotifyShown (); + void OnInitiateSpreed(); + void OnTerminateSpreed(); + void DoAddDamage (); ShowdesktopHandlerWindowInterface::PostPaintAction DoHandleAnimations (unsigned int ms); @@ -473,30 +469,28 @@ private: compiz::WindowInputRemoverLock::Ptr GetInputRemover (); - void DrawWindowDecoration(const GLWindowPaintAttrib& attrib, - const GLMatrix& transform, + void DrawWindowDecoration(GLWindowPaintAttrib const& attrib, + GLMatrix const& transform, unsigned int mask, bool highlighted, - float x, float y, float x2, float y2); + int x, int y, unsigned width, unsigned height); void DrawTexture(GLTexture *icon, const GLWindowPaintAttrib& attrib, const GLMatrix& transform, unsigned int mask, float x, float y, int &maxWidth, int &maxHeight); - void RenderText(WindowCairoContext *context, + void RenderText(std::shared_ptr const& context, float x, float y, float maxWidth, float maxHeight); - void PrepareHeaderStyle(); + + void SetupScaleHeaderStyle(); std::shared_ptr CreateCairoContext(float width, float height); + static GLTexture::List close_icon_; compiz::WindowInputRemoverLock::Weak input_remover_; - glib::Source::UniquePtr focus_desktop_timeout_; - - GLTexture::List close_icon_; CompRect close_button_area_; - glib::Object window_header_style_; - bool has_original_decoration_; + glib::Source::UniquePtr focus_desktop_timeout_; }; -- cgit v1.2.3 From cab29f3568b3168e1a797a08c981317a9dd56e98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 5 Sep 2012 02:38:57 +0200 Subject: UnityWindow: WindowCairoContext moved to struct UnityWindow::CairoContext Using it as stack allocated. (bzr r2655.5.4) --- plugins/unityshell/src/unityshell.cpp | 166 +++++++++++++++------------------- plugins/unityshell/src/unityshell.h | 7 +- 2 files changed, 77 insertions(+), 96 deletions(-) (limited to 'plugins/unityshell/src') diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index c834a3b30..7f2662f67 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -106,36 +106,6 @@ const std::string RELAYOUT_TIMEOUT = "relayout-timeout"; } // namespace local } // anon namespace -class WindowCairoContext -{ - public: - typedef std::shared_ptr Ptr; - - Pixmap pixmap_; - cairo_surface_t* surface_; - GLTexture::List texture_; - cairo_t *cr_; - - WindowCairoContext () - : pixmap_ (0), surface_ (0), cr_ (0) - { - } - - ~WindowCairoContext () - { - if (cr_) - cairo_destroy (cr_); - - if (surface_) - cairo_surface_destroy (surface_); - - texture_.clear (); - - if (pixmap_) - XFreePixmap (screen->dpy (), pixmap_); - } -}; - UnityScreen::UnityScreen(CompScreen* screen) : BaseSwitchScreen (screen) , PluginClassHandler (screen) @@ -3464,6 +3434,52 @@ void UnityScreen::InitGesturesSupport() /* Window init */ GLTexture::List UnityWindow::close_icon_; +struct UnityWindow::CairoContext +{ + CairoContext(int width, int height) + : pixmap_(XCreatePixmap(screen->dpy(), screen->root(), width, height, 32)) + , texture_(GLTexture::bindPixmapToTexture(pixmap_, width, height, 32)) + , surface_(nullptr) + , cr_(nullptr) + { + Screen *xscreen = ScreenOfDisplay(screen->dpy(), screen->screenNum()); + XRenderPictFormat* format = XRenderFindStandardFormat(screen->dpy(), PictStandardARGB32); + + if (texture_.empty()) + return; + + surface_ = cairo_xlib_surface_create_with_xrender_format(screen->dpy(), pixmap_, + xscreen, format, + width, height); + cr_ = cairo_create(surface_); + + // clear + cairo_save(cr_); + cairo_set_operator(cr_, CAIRO_OPERATOR_CLEAR); + cairo_paint(cr_); + cairo_restore(cr_); + } + + ~CairoContext () + { + if (cr_) + cairo_destroy(cr_); + + if (surface_) + cairo_surface_destroy(surface_); + + texture_.clear(); + + if (pixmap_) + XFreePixmap(screen->dpy (), pixmap_); + } + + Pixmap pixmap_; + GLTexture::List texture_; + cairo_surface_t* surface_; + cairo_t *cr_; +}; + UnityWindow::UnityWindow(CompWindow* window) : BaseSwitchWindow (dynamic_cast (UnityScreen::get (screen)), window) , PluginClassHandler(window) @@ -3559,50 +3575,15 @@ UnityWindow::DrawTexture(GLTexture* icon, } } -std::shared_ptr -UnityWindow::CreateCairoContext(float width, float height) -{ - XRenderPictFormat *format; - Screen *xScreen; - auto cContext = std::make_shared(); - - xScreen = ScreenOfDisplay(screen->dpy(), screen->screenNum()); - - format = XRenderFindStandardFormat(screen->dpy(), PictStandardARGB32); - cContext->pixmap_ = XCreatePixmap(screen->dpy(), screen->root(), - width, height, 32); - - cContext->texture_ = GLTexture::bindPixmapToTexture(cContext->pixmap_, - width, height, 32); - if (cContext->texture_.empty()) - return nullptr; - - cContext->surface_ = cairo_xlib_surface_create_with_xrender_format(screen->dpy(), - cContext->pixmap_, - xScreen, - format, - width, - height); - cContext->cr_ = cairo_create(cContext->surface_); - - // clear - cairo_save(cContext->cr_); - cairo_set_operator(cContext->cr_, CAIRO_OPERATOR_CLEAR); - cairo_paint(cContext->cr_); - cairo_restore(cContext->cr_); - - return cContext; -} - void -UnityWindow::RenderText(WindowCairoContext::Ptr const& context, +UnityWindow::RenderText(UnityWindow::CairoContext const& context, float x, float y, float maxWidth, float maxHeight) { panel::Style& style = panel::Style::Instance(); std::string fontDescription(style.GetFontDescription(panel::PanelItem::TITLE)); - glib::Object layout(pango_cairo_create_layout(context->cr_)); + glib::Object layout(pango_cairo_create_layout(context.cr_)); std::shared_ptr font(pango_font_description_from_string(fontDescription.c_str()), pango_font_description_free); @@ -3624,9 +3605,9 @@ UnityWindow::RenderText(WindowCairoContext::Ptr const& context, -1); /* update the size of the pango layout */ - pango_cairo_update_layout(context->cr_, layout); - cairo_set_operator(context->cr_, CAIRO_OPERATOR_OVER); - cairo_set_source_rgba(context->cr_, + pango_cairo_update_layout(context.cr_, layout); + cairo_set_operator(context.cr_, CAIRO_OPERATOR_OVER); + cairo_set_source_rgba(context.cr_, 1.0, 1.0, 1.0, @@ -3641,7 +3622,7 @@ UnityWindow::RenderText(WindowCairoContext::Ptr const& context, textHeight = lRect.height / PANGO_SCALE; y = ((maxHeight - textHeight) / 2.0) + y; - cairo_translate(context->cr_, x, y); + cairo_translate(context.cr_, x, y); if (textWidth > maxWidth) { @@ -3650,20 +3631,20 @@ UnityWindow::RenderText(WindowCairoContext::Ptr const& context, const int fadingPixels = 35; const int fadingWidth = outPixels < fadingPixels ? outPixels : fadingPixels; - cairo_push_group(context->cr_); - pango_cairo_show_layout(context->cr_, layout); - cairo_pop_group_to_source(context->cr_); + cairo_push_group(context.cr_); + pango_cairo_show_layout(context.cr_, layout); + cairo_pop_group_to_source(context.cr_); std::shared_ptr linpat(cairo_pattern_create_linear(maxWidth - fadingWidth, y, maxWidth, y), cairo_pattern_destroy); cairo_pattern_add_color_stop_rgba(linpat.get(), 0, 0, 0, 0, 1); cairo_pattern_add_color_stop_rgba(linpat.get(), 1, 0, 0, 0, 0); - cairo_mask(context->cr_, linpat.get()); + cairo_mask(context.cr_, linpat.get()); } else { - pango_cairo_show_layout(context->cr_, layout); + pango_cairo_show_layout(context.cr_, layout); } } @@ -3675,10 +3656,10 @@ UnityWindow::DrawWindowDecoration(GLWindowPaintAttrib const& attrib, int x, int y, unsigned width, unsigned height) { // Paint a fake window decoration - WindowCairoContext::Ptr context(CreateCairoContext(width, height)); + CairoContext context(width, height); - cairo_save(context->cr_); - cairo_push_group(context->cr_); + cairo_save(context.cr_); + cairo_push_group(context.cr_); // Round window decoration top border const double aspect = 1.0; @@ -3686,25 +3667,25 @@ UnityWindow::DrawWindowDecoration(GLWindowPaintAttrib const& attrib, const double radius = corner_radius / aspect; const double degrees = M_PI / 180.0; - cairo_new_sub_path(context->cr_); + cairo_new_sub_path(context.cr_); - cairo_arc(context->cr_, radius, radius, radius, 180 * degrees, 270 * degrees); - cairo_arc(context->cr_, width - radius, radius, radius, -90 * degrees, 0 * degrees); - cairo_line_to(context->cr_, width, height); - cairo_line_to(context->cr_, 0, height); + cairo_arc(context.cr_, radius, radius, radius, 180 * degrees, 270 * degrees); + cairo_arc(context.cr_, width - radius, radius, radius, -90 * degrees, 0 * degrees); + cairo_line_to(context.cr_, width, height); + cairo_line_to(context.cr_, 0, height); - cairo_close_path(context->cr_); - cairo_clip(context->cr_); + cairo_close_path(context.cr_); + cairo_clip(context.cr_); // Draw window decoration based on gtk style auto& style = panel::Style::Instance(); - gtk_render_background(style.GetStyleContext(), context->cr_, 0, 0, width, height); - gtk_render_frame(style.GetStyleContext(), context->cr_, 0, 0, width, height); + gtk_render_background(style.GetStyleContext(), context.cr_, 0, 0, width, height); + gtk_render_frame(style.GetStyleContext(), context.cr_, 0, 0, width, height); - cairo_pop_group_to_source(context->cr_); + cairo_pop_group_to_source(context.cr_); - cairo_paint_with_alpha(context->cr_, 1.0); - cairo_restore(context->cr_); + cairo_paint_with_alpha(context.cr_, 1.0); + cairo_restore(context.cr_); if (highlighted) { @@ -3715,7 +3696,8 @@ UnityWindow::DrawWindowDecoration(GLWindowPaintAttrib const& attrib, mask |= PAINT_WINDOW_BLEND_MASK; int maxWidth, maxHeight; - foreach(GLTexture *icon, context->texture_) + + foreach(GLTexture *icon, context.texture_) { DrawTexture(icon, attrib, transform, mask, x, y, maxWidth , maxHeight); } diff --git a/plugins/unityshell/src/unityshell.h b/plugins/unityshell/src/unityshell.h index 58e259c32..e1809096f 100644 --- a/plugins/unityshell/src/unityshell.h +++ b/plugins/unityshell/src/unityshell.h @@ -71,8 +71,6 @@ namespace unity { -class WindowCairoContext; - /* base screen class */ class UnityScreen : public unity::debug::Introspectable, @@ -436,6 +434,8 @@ public: unsigned int); private: + struct CairoContext; + void DoEnableFocus (); void DoDisableFocus (); @@ -480,12 +480,11 @@ private: unsigned int mask, float x, float y, int &maxWidth, int &maxHeight); - void RenderText(std::shared_ptr const& context, + void RenderText(CairoContext const& context, float x, float y, float maxWidth, float maxHeight); void SetupScaleHeaderStyle(); - std::shared_ptr CreateCairoContext(float width, float height); static GLTexture::List close_icon_; compiz::WindowInputRemoverLock::Weak input_remover_; -- cgit v1.2.3 From fbc4d06b4b06ec9745664a7fba0bac385f0235f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 5 Sep 2012 03:40:39 +0200 Subject: UnityWindow: make the spread close button to react to mouse in/out and button press events Also close on button release. (bzr r2655.5.5) --- plugins/unityshell/src/unityshell.cpp | 158 ++++++++++++++++++++++++---------- plugins/unityshell/src/unityshell.h | 10 ++- 2 files changed, 119 insertions(+), 49 deletions(-) (limited to 'plugins/unityshell/src') diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index 7f2662f67..9fddcbf9f 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -1216,21 +1216,60 @@ UnityWindow::GetNoCoreInstanceMask () return PAINT_WINDOW_NO_CORE_INSTANCE_MASK; } -void UnityWindow::handleEvent (XEvent *event) +bool UnityWindow::handleEvent(XEvent *event) { - if (screen->XShape () && + bool handled = false; + + if (event->type == MotionNotify) + { + if (close_button_area_.contains(CompPoint(event->xbutton.x_root, event->xbutton.y_root))) + { + close_icon_state_ = panel::WindowState::PRELIGHT; + } + else + { + close_icon_state_ = panel::WindowState::NORMAL; + } + + if (CompositeWindow *cWindow = CompositeWindow::get(window)) + cWindow->addDamage(); + } + else if (event->type == ButtonPress) + { + if (close_button_area_.contains(CompPoint(event->xbutton.x_root, event->xbutton.y_root))) + { + close_icon_state_ = panel::WindowState::PRESSED; + handled = true; + + if (CompositeWindow *cWindow = CompositeWindow::get(window)) + cWindow->addDamage(); + } + } + else if (event->type == ButtonRelease) + { + close_icon_state_ = panel::WindowState::NORMAL; + + if (CompositeWindow *cWindow = CompositeWindow::get(window)) + cWindow->addDamage(); + + if (close_button_area_.contains(CompPoint(pointerX, pointerY))) + { + window->close(0); + handled = true; + } + } + else if (screen->XShape () && event->type == screen->shapeEvent () + ShapeNotify && !event->xany.send_event) { if (mShowdesktopHandler) - mShowdesktopHandler->HandleShapeEvent (); + { + mShowdesktopHandler->HandleShapeEvent(); + handled = true; + } } -} -CompRect -UnityWindow::CloseButtonArea() -{ - return close_button_area_; + return handled; } bool UnityScreen::shellCouldBeHidden(CompOutput const& output) @@ -1594,28 +1633,23 @@ void UnityScreen::handleEvent(XEvent* event) } _key_nav_mode_requested = false; break; + case MotionNotify: + if (highlighted_window_ && PluginAdapter::Default()->IsScaleActive()) + { + if (CompWindow *w = screen->findWindow(highlighted_window_)) + skip_other_plugins = UnityWindow::get(w)->handleEvent(event); + } + break; case ButtonPress: if (super_keypressed_) { launcher_controller_->KeyNavTerminate(false); EnableCancelAction(CancelActionTarget::LAUNCHER_SWITCHER, false); } - if (PluginAdapter::Default()->IsScaleActive() && - event->xbutton.button == Button1 && - highlighted_window_ != 0) + if (highlighted_window_ && PluginAdapter::Default()->IsScaleActive()) { - CompWindow *w = screen->findWindow(highlighted_window_); - if (w) - { - UnityWindow *uw = UnityWindow::get(w); - CompPoint pointer(pointerX, pointerY); - if (uw->CloseButtonArea().contains(pointer)) - { - w->close(0); - skip_other_plugins = true; - } - } - + if (CompWindow *w = screen->findWindow(highlighted_window_)) + skip_other_plugins = UnityWindow::get(w)->handleEvent(event); } break; @@ -1637,6 +1671,11 @@ void UnityScreen::handleEvent(XEvent* event) } } } + else if (highlighted_window_ && PluginAdapter::Default()->IsScaleActive()) + { + if (CompWindow *w = screen->findWindow(highlighted_window_)) + UnityWindow::get(w)->handleEvent(event); + } break; case KeyPress: { @@ -3432,7 +3471,9 @@ void UnityScreen::InitGesturesSupport() } /* Window init */ -GLTexture::List UnityWindow::close_icon_; +GLTexture::List UnityWindow::close_normal_tex_; +GLTexture::List UnityWindow::close_prelight_tex_; +GLTexture::List UnityWindow::close_pressed_tex_; struct UnityWindow::CairoContext { @@ -3703,32 +3744,45 @@ UnityWindow::DrawWindowDecoration(GLWindowPaintAttrib const& attrib, } } -void UnityWindow::SetupScaleHeaderStyle() +void UnityWindow::LoadCloseIcon(panel::WindowState state, GLTexture::List& texture) { - if (close_icon_.empty()) + if (!texture.empty()) + return; + + auto& style = panel::Style::Instance(); + auto const& files = style.GetWindowButtonFileNames(panel::WindowButtonType::CLOSE, state); + + CompString pName("unityshell"); + for (std::string const& file : files) { - auto& style = panel::Style::Instance(); - auto const& files = style.GetWindowButtonFileNames(panel::WindowButtonType::CLOSE, panel::WindowState::NORMAL); + CompString fileName(file.c_str()); + CompSize size(SCALE_CLOSE_ICON_SIZE, SCALE_CLOSE_ICON_SIZE); + texture = GLTexture::readImageToTexture(fileName, pName, size); + if (!texture.empty()) + break; + } - CompString pName("unityshell"); - for (std::string const& file : files) - { - CompString fileName(file.c_str()); - CompSize size(SCALE_CLOSE_ICON_SIZE, SCALE_CLOSE_ICON_SIZE); - close_icon_ = GLTexture::readImageToTexture(fileName, pName, size); - if (!close_icon_.empty()) - break; - } + if (texture.empty()) + { + std::string suffix; + if (state == panel::WindowState::PRELIGHT) + suffix = "_prelight"; + else if (state == panel::WindowState::PRESSED) + suffix = "_pressed"; - if (close_icon_.empty()) - { - CompString fileName(PKGDATADIR"/close_dash.png"); - CompSize size(SCALE_CLOSE_ICON_SIZE, SCALE_CLOSE_ICON_SIZE); - close_icon_ = GLTexture::readImageToTexture(fileName, pName, size); - } + CompString fileName((PKGDATADIR"/close_dash" + suffix + ".png").c_str()); + CompSize size(SCALE_CLOSE_ICON_SIZE, SCALE_CLOSE_ICON_SIZE); + texture = GLTexture::readImageToTexture(fileName, pName, size); } } +void UnityWindow::SetupScaleHeaderStyle() +{ + LoadCloseIcon(panel::WindowState::NORMAL, close_normal_tex_); + LoadCloseIcon(panel::WindowState::PRELIGHT, close_prelight_tex_); + LoadCloseIcon(panel::WindowState::PRESSED, close_pressed_tex_); +} + void UnityWindow::scalePaintDecoration(GLWindowPaintAttrib const& attrib, GLMatrix const& transform, CompRegion const& region, @@ -3773,8 +3827,21 @@ void UnityWindow::scalePaintDecoration(GLWindowPaintAttrib const& attrib, int max_width = 0; mask |= PAINT_WINDOW_BLEND_MASK; - for (GLTexture *icon : close_icon_) - DrawTexture(icon, sAttrib, transform, mask, x, y, max_width , max_height); + if (close_icon_state_ == panel::WindowState::NORMAL) + { + for (GLTexture *icon : close_normal_tex_) + DrawTexture(icon, sAttrib, transform, mask, x, y, max_width , max_height); + } + else if (close_icon_state_ == panel::WindowState::PRELIGHT) + { + for (GLTexture *icon : close_prelight_tex_) + DrawTexture(icon, sAttrib, transform, mask, x, y, max_width , max_height); + } + else if (close_icon_state_ == panel::WindowState::PRESSED) + { + for (GLTexture *icon : close_pressed_tex_) + DrawTexture(icon, sAttrib, transform, mask, x, y, max_width , max_height); + } close_button_area_ = CompRect(x, y, max_height, max_width); } @@ -3817,6 +3884,7 @@ void UnityWindow::OnInitiateSpreed() if (std::find(windows.begin(), windows.end(), window) == windows.end()) return; + close_icon_state_ = panel::WindowState::NORMAL; SetupScaleHeaderStyle(); WindowManager *wm = WindowManager::Default(); diff --git a/plugins/unityshell/src/unityshell.h b/plugins/unityshell/src/unityshell.h index e1809096f..d5fe86f2c 100644 --- a/plugins/unityshell/src/unityshell.h +++ b/plugins/unityshell/src/unityshell.h @@ -415,9 +415,7 @@ public: void leaveShowDesktop (); bool HandleAnimations (unsigned int ms); - void handleEvent (XEvent *event); - - CompRect CloseButtonArea(); + bool handleEvent(XEvent *event); typedef compiz::CompizMinimizedWindowHandler UnityMinimizedHandler; @@ -485,8 +483,12 @@ private: float maxWidth, float maxHeight); void SetupScaleHeaderStyle(); + void LoadCloseIcon(panel::WindowState state, GLTexture::List& texture); - static GLTexture::List close_icon_; + static GLTexture::List close_normal_tex_; + static GLTexture::List close_prelight_tex_; + static GLTexture::List close_pressed_tex_; + panel::WindowState close_icon_state_; compiz::WindowInputRemoverLock::Weak input_remover_; CompRect close_button_area_; glib::Source::UniquePtr focus_desktop_timeout_; -- cgit v1.2.3 From ccc93cf2e9262be482d53824be336958de8ba4e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 5 Sep 2012 03:47:41 +0200 Subject: UnityWindow: avoid unneeded damages on motion event, and keep pressed also on mouse-out (bzr r2655.5.6) --- plugins/unityshell/src/unityshell.cpp | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'plugins/unityshell/src') diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index 9fddcbf9f..bc79ed870 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -1222,17 +1222,25 @@ bool UnityWindow::handleEvent(XEvent *event) if (event->type == MotionNotify) { - if (close_button_area_.contains(CompPoint(event->xbutton.x_root, event->xbutton.y_root))) - { - close_icon_state_ = panel::WindowState::PRELIGHT; - } - else + if (close_icon_state_ != panel::WindowState::PRESSED) { - close_icon_state_ = panel::WindowState::NORMAL; - } + panel::WindowState old_state = close_icon_state_; - if (CompositeWindow *cWindow = CompositeWindow::get(window)) - cWindow->addDamage(); + if (close_button_area_.contains(CompPoint(event->xbutton.x_root, event->xbutton.y_root))) + { + close_icon_state_ = panel::WindowState::PRELIGHT; + } + else + { + close_icon_state_ = panel::WindowState::NORMAL; + } + + if (old_state != close_icon_state_) + { + if (CompositeWindow *cWindow = CompositeWindow::get(window)) + cWindow->addDamage(); + } + } } else if (event->type == ButtonPress) { @@ -1247,10 +1255,13 @@ bool UnityWindow::handleEvent(XEvent *event) } else if (event->type == ButtonRelease) { - close_icon_state_ = panel::WindowState::NORMAL; + if (close_icon_state_ != panel::WindowState::NORMAL) + { + close_icon_state_ = panel::WindowState::NORMAL; - if (CompositeWindow *cWindow = CompositeWindow::get(window)) - cWindow->addDamage(); + if (CompositeWindow *cWindow = CompositeWindow::get(window)) + cWindow->addDamage(); + } if (close_button_area_.contains(CompPoint(pointerX, pointerY))) { -- cgit v1.2.3 From 717640e4095c2dd9dfe2ad667847b2c8d92b93df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 5 Sep 2012 03:54:27 +0200 Subject: UnityWindow: Indentation fix (bzr r2655.5.7) --- plugins/unityshell/src/unityshell.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/unityshell/src') diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index bc79ed870..e1d032e8c 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -1260,7 +1260,7 @@ bool UnityWindow::handleEvent(XEvent *event) close_icon_state_ = panel::WindowState::NORMAL; if (CompositeWindow *cWindow = CompositeWindow::get(window)) - cWindow->addDamage(); + cWindow->addDamage(); } if (close_button_area_.contains(CompPoint(pointerX, pointerY))) -- cgit v1.2.3 From 6e37bc2f96496def8c33840b2c09806381f820db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 5 Sep 2012 04:11:27 +0200 Subject: UnityWindow: use height as scale decoration height (bzr r2655.5.8) --- plugins/unityshell/src/unityshell.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'plugins/unityshell/src') diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index e1d032e8c..4189ea27d 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -3833,7 +3833,7 @@ void UnityWindow::scalePaintDecoration(GLWindowPaintAttrib const& attrib, if (highlighted) { x += SCALE_CLOSE_ICON_SPACE; - y += (decoration_height - SCALE_CLOSE_ICON_SIZE) / 2.0f; + y += (height - SCALE_CLOSE_ICON_SIZE) / 2.0f; int max_height = 0; int max_width = 0; mask |= PAINT_WINDOW_BLEND_MASK; -- cgit v1.2.3 From 49d116da51e3a75415b5a2884281b094cb35e18f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 5 Sep 2012 04:37:24 +0200 Subject: UnityWindow: don't allow to close a scaled window by any mouse button (bzr r2655.5.9) --- plugins/unityshell/src/unityshell.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'plugins/unityshell/src') diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index 4189ea27d..c14325d7a 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -1244,7 +1244,8 @@ bool UnityWindow::handleEvent(XEvent *event) } else if (event->type == ButtonPress) { - if (close_button_area_.contains(CompPoint(event->xbutton.x_root, event->xbutton.y_root))) + if (event->xbutton.button == Button1 && + close_button_area_.contains(CompPoint(event->xbutton.x_root, event->xbutton.y_root))) { close_icon_state_ = panel::WindowState::PRESSED; handled = true; @@ -1255,6 +1256,8 @@ bool UnityWindow::handleEvent(XEvent *event) } else if (event->type == ButtonRelease) { + bool was_pressed = (close_icon_state_ == panel::WindowState::PRESSED); + if (close_icon_state_ != panel::WindowState::NORMAL) { close_icon_state_ = panel::WindowState::NORMAL; @@ -1263,7 +1266,7 @@ bool UnityWindow::handleEvent(XEvent *event) cWindow->addDamage(); } - if (close_button_area_.contains(CompPoint(pointerX, pointerY))) + if (was_pressed && close_button_area_.contains(CompPoint(pointerX, pointerY))) { window->close(0); handled = true; -- cgit v1.2.3 From b1f63bcbd90587bd4e42e84ba1f452738b05a503 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 5 Sep 2012 04:45:35 +0200 Subject: UnityWindow: handle any release event, if it was previously pressed (bzr r2655.5.10) --- plugins/unityshell/src/unityshell.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'plugins/unityshell/src') diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index c14325d7a..797f800ae 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -1266,9 +1266,11 @@ bool UnityWindow::handleEvent(XEvent *event) cWindow->addDamage(); } - if (was_pressed && close_button_area_.contains(CompPoint(pointerX, pointerY))) + if (was_pressed) { - window->close(0); + if (close_button_area_.contains(CompPoint(event->xbutton.x_root, event->xbutton.y_root))) + window->close(0); + handled = true; } } -- cgit v1.2.3 From f0b6aa14db1099ec6dd103f494228d7be55a9939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Wed, 5 Sep 2012 13:14:15 +0200 Subject: UnityWindow: use some padding also at the end of the decoration Not to make long titles to fade to the end of the decoration (bzr r2655.5.11) --- plugins/unityshell/src/unityshell.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'plugins/unityshell/src') diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index 797f800ae..73a0c3f8e 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -84,7 +84,7 @@ nux::logging::Logger logger("unity.shell"); UnityScreen* uScreen = 0; const unsigned int SCALE_CLOSE_ICON_SIZE = 19; -const unsigned int SCALE_CLOSE_ICON_SPACE = 5; +const unsigned int SCALE_ITEMS_PADDING = 5; void reset_glib_logging(); void configure_logging(); @@ -3747,8 +3747,8 @@ UnityWindow::DrawWindowDecoration(GLWindowPaintAttrib const& attrib, if (highlighted) { // Draw windows title - const float xText = SCALE_CLOSE_ICON_SPACE * 2 + SCALE_CLOSE_ICON_SIZE; - RenderText(context, xText, 0.0, width - xText, height); + const float xText = SCALE_ITEMS_PADDING * 2 + SCALE_CLOSE_ICON_SIZE; + RenderText(context, xText, 0.0, width - xText - SCALE_ITEMS_PADDING, height); } mask |= PAINT_WINDOW_BLEND_MASK; @@ -3837,7 +3837,7 @@ void UnityWindow::scalePaintDecoration(GLWindowPaintAttrib const& attrib, if (highlighted) { - x += SCALE_CLOSE_ICON_SPACE; + x += SCALE_ITEMS_PADDING; y += (height - SCALE_CLOSE_ICON_SIZE) / 2.0f; int max_height = 0; int max_width = 0; -- cgit v1.2.3 From 30421d692e7fe0ff4f92552fa24b12ea2f64c20e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 6 Sep 2012 12:42:09 +0200 Subject: UnityWindow: even more code optimizations (bzr r2655.5.12) --- plugins/unityshell/src/unityshell.cpp | 208 +++++++++++++++------------------- plugins/unityshell/src/unityshell.h | 6 +- 2 files changed, 97 insertions(+), 117 deletions(-) (limited to 'plugins/unityshell/src') diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index 73a0c3f8e..9830a6fac 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -134,7 +134,7 @@ UnityScreen::UnityScreen(CompScreen* screen) , panel_texture_has_changed_(true) , paint_panel_(false) , scale_just_activated_(false) - , highlighted_window_(0) + , scale_highlighted_window_(0) , minimize_speed_controller(new WindowMinimizeSpeedController()) { Timer timer; @@ -392,6 +392,7 @@ UnityScreen::UnityScreen(CompScreen* screen) } panel::Style::Instance().changed.connect(sigc::mem_fun(this, &UnityScreen::OnPanelStyleChanged)); + WindowManager::Default()->terminate_spread.connect([this] { scale_highlighted_window_ = 0; }); minimize_speed_controller->DurationChanged.connect( sigc::mem_fun(this, &UnityScreen::OnMinimizeDurationChanged) @@ -1187,9 +1188,9 @@ ShowdesktopHandlerWindowInterface::PostPaintAction UnityWindow::DoHandleAnimatio return action; } -void UnityWindow::DoAddDamage () +void UnityWindow::DoAddDamage() { - cWindow->addDamage (); + cWindow->addDamage(); } void UnityWindow::DoDeleteHandler () @@ -1220,69 +1221,67 @@ bool UnityWindow::handleEvent(XEvent *event) { bool handled = false; - if (event->type == MotionNotify) + switch(event->type) { - if (close_icon_state_ != panel::WindowState::PRESSED) - { - panel::WindowState old_state = close_icon_state_; - - if (close_button_area_.contains(CompPoint(event->xbutton.x_root, event->xbutton.y_root))) - { - close_icon_state_ = panel::WindowState::PRELIGHT; - } - else + case MotionNotify: + if (close_icon_state_ != panel::WindowState::PRESSED) { - close_icon_state_ = panel::WindowState::NORMAL; + panel::WindowState old_state = close_icon_state_; + + if (close_button_geo_.IsPointInside(event->xmotion.x_root, event->xmotion.y_root)) + { + close_icon_state_ = panel::WindowState::PRELIGHT; + } + else + { + close_icon_state_ = panel::WindowState::NORMAL; + } + + if (old_state != close_icon_state_) + DoAddDamage(); } + break; - if (old_state != close_icon_state_) + case ButtonPress: + if (event->xbutton.button == Button1 && + close_button_geo_.IsPointInside(event->xbutton.x_root, event->xbutton.y_root)) { - if (CompositeWindow *cWindow = CompositeWindow::get(window)) - cWindow->addDamage(); + close_icon_state_ = panel::WindowState::PRESSED; + DoAddDamage(); + handled = true; } - } - } - else if (event->type == ButtonPress) - { - if (event->xbutton.button == Button1 && - close_button_area_.contains(CompPoint(event->xbutton.x_root, event->xbutton.y_root))) - { - close_icon_state_ = panel::WindowState::PRESSED; - handled = true; + break; - if (CompositeWindow *cWindow = CompositeWindow::get(window)) - cWindow->addDamage(); - } - } - else if (event->type == ButtonRelease) - { - bool was_pressed = (close_icon_state_ == panel::WindowState::PRESSED); + case ButtonRelease: + { + bool was_pressed = (close_icon_state_ == panel::WindowState::PRESSED); - if (close_icon_state_ != panel::WindowState::NORMAL) - { - close_icon_state_ = panel::WindowState::NORMAL; + if (close_icon_state_ != panel::WindowState::NORMAL) + { + close_icon_state_ = panel::WindowState::NORMAL; + DoAddDamage(); + } - if (CompositeWindow *cWindow = CompositeWindow::get(window)) - cWindow->addDamage(); - } + if (was_pressed) + { + if (close_button_geo_.IsPointInside(event->xbutton.x_root, event->xbutton.y_root)) + window->close(0); - if (was_pressed) - { - if (close_button_area_.contains(CompPoint(event->xbutton.x_root, event->xbutton.y_root))) - window->close(0); + handled = true; + } + } + break; - handled = true; - } - } - else if (screen->XShape () && - event->type == screen->shapeEvent () + ShapeNotify && - !event->xany.send_event) - { - if (mShowdesktopHandler) - { - mShowdesktopHandler->HandleShapeEvent(); - handled = true; - } + default: + if (!event->xany.send_event && screen->XShape() && + event->type == screen->shapeEvent() + ShapeNotify) + { + if (mShowdesktopHandler) + { + mShowdesktopHandler->HandleShapeEvent(); + handled = true; + } + } } return handled; @@ -1650,9 +1649,9 @@ void UnityScreen::handleEvent(XEvent* event) _key_nav_mode_requested = false; break; case MotionNotify: - if (highlighted_window_ && PluginAdapter::Default()->IsScaleActive()) + if (scale_highlighted_window_ && PluginAdapter::Default()->IsScaleActive()) { - if (CompWindow *w = screen->findWindow(highlighted_window_)) + if (CompWindow *w = screen->findWindow(scale_highlighted_window_)) skip_other_plugins = UnityWindow::get(w)->handleEvent(event); } break; @@ -1662,9 +1661,9 @@ void UnityScreen::handleEvent(XEvent* event) launcher_controller_->KeyNavTerminate(false); EnableCancelAction(CancelActionTarget::LAUNCHER_SWITCHER, false); } - if (highlighted_window_ && PluginAdapter::Default()->IsScaleActive()) + if (scale_highlighted_window_ && PluginAdapter::Default()->IsScaleActive()) { - if (CompWindow *w = screen->findWindow(highlighted_window_)) + if (CompWindow *w = screen->findWindow(scale_highlighted_window_)) skip_other_plugins = UnityWindow::get(w)->handleEvent(event); } @@ -1687,9 +1686,9 @@ void UnityScreen::handleEvent(XEvent* event) } } } - else if (highlighted_window_ && PluginAdapter::Default()->IsScaleActive()) + else if (scale_highlighted_window_ && PluginAdapter::Default()->IsScaleActive()) { - if (CompWindow *w = screen->findWindow(highlighted_window_)) + if (CompWindow *w = screen->findWindow(scale_highlighted_window_)) UnityWindow::get(w)->handleEvent(event); } break; @@ -1819,8 +1818,8 @@ void UnityScreen::handleCompizEvent(const char* plugin, ubus_manager_.SendMessage(UBUS_PLACE_VIEW_CLOSE_REQUEST); } - if (PluginAdapter::Default()->IsScaleActive() && - g_strcmp0(plugin, "scale") == 0 && super_keypressed_) + if (PluginAdapter::Default()->IsScaleActive() && g_strcmp0(plugin, "scale") == 0 && + super_keypressed_) { scale_just_activated_ = true; } @@ -3754,10 +3753,8 @@ UnityWindow::DrawWindowDecoration(GLWindowPaintAttrib const& attrib, mask |= PAINT_WINDOW_BLEND_MASK; int maxWidth, maxHeight; - foreach(GLTexture *icon, context.texture_) - { + for (GLTexture *icon : context.texture_) DrawTexture(icon, attrib, transform, mask, x, y, maxWidth , maxHeight); - } } void UnityWindow::LoadCloseIcon(panel::WindowState state, GLTexture::List& texture) @@ -3804,22 +3801,19 @@ void UnityWindow::scalePaintDecoration(GLWindowPaintAttrib const& attrib, CompRegion const& region, unsigned int mask) { - ScaleWindow *sWindow = ScaleWindow::get(window); - if (!sWindow) + ScaleWindow *scale_win = ScaleWindow::get(window); + if (!scale_win) return; - sWindow->scalePaintDecoration(attrib, transform, region, mask); + scale_win->scalePaintDecoration(attrib, transform, region, mask); - if (!sWindow->hasSlot()) // animation not finished + if (!scale_win->hasSlot()) // animation not finished return; UnityScreen* us = UnityScreen::get(screen); - const guint32 xid = window->id(); - const bool highlighted = (us->highlighted_window_ == xid); - GLWindowPaintAttrib sAttrib(attrib); - sAttrib.opacity = OPAQUE; + const bool highlighted = (us->scale_highlighted_window_ == window->id()); - ScalePosition const& pos = sWindow->getCurrentPosition(); + ScalePosition const& pos = scale_win->getCurrentPosition(); auto const& border_rect = window->borderRect(); auto const& deco_ext = window->border(); @@ -3833,7 +3827,7 @@ void UnityWindow::scalePaintDecoration(GLWindowPaintAttrib const& attrib, if (highlighted) height = decoration_height; - DrawWindowDecoration(sAttrib, transform, mask, highlighted, x, y, width, height); + DrawWindowDecoration(attrib, transform, mask, highlighted, x, y, width, height); if (highlighted) { @@ -3843,55 +3837,41 @@ void UnityWindow::scalePaintDecoration(GLWindowPaintAttrib const& attrib, int max_width = 0; mask |= PAINT_WINDOW_BLEND_MASK; - if (close_icon_state_ == panel::WindowState::NORMAL) - { - for (GLTexture *icon : close_normal_tex_) - DrawTexture(icon, sAttrib, transform, mask, x, y, max_width , max_height); - } - else if (close_icon_state_ == panel::WindowState::PRELIGHT) + switch(close_icon_state_) { - for (GLTexture *icon : close_prelight_tex_) - DrawTexture(icon, sAttrib, transform, mask, x, y, max_width , max_height); - } - else if (close_icon_state_ == panel::WindowState::PRESSED) - { - for (GLTexture *icon : close_pressed_tex_) - DrawTexture(icon, sAttrib, transform, mask, x, y, max_width , max_height); + case panel::WindowState::NORMAL: + default: + for (GLTexture *icon : close_normal_tex_) + DrawTexture(icon, attrib, transform, mask, x, y, max_width , max_height); + break; + + case panel::WindowState::PRELIGHT: + for (GLTexture *icon : close_prelight_tex_) + DrawTexture(icon, attrib, transform, mask, x, y, max_width , max_height); + break; + + case panel::WindowState::PRESSED: + for (GLTexture *icon : close_pressed_tex_) + DrawTexture(icon, attrib, transform, mask, x, y, max_width , max_height); + break; } - close_button_area_ = CompRect(x, y, max_height, max_width); + close_button_geo_.Set(x, y, max_height, max_width); } - else if (!close_button_area_.isEmpty()) + else if (!close_button_geo_.IsNull()) { - close_button_area_ = CompRect(); + close_button_geo_.Set(0, 0, 0, 0); } } -void -UnityWindow::scaleSelectWindow () +void UnityWindow::scaleSelectWindow() { - UnityScreen* us = UnityScreen::get(screen); - - if (us->highlighted_window_ != window->id ()) - { - CompositeWindow *cWindow = CompositeWindow::get(window); - if (cWindow) - cWindow->addDamage(); - - cWindow = 0; - CompWindow *old_window = screen->findWindow(us->highlighted_window_); - if (old_window) - cWindow = CompositeWindow::get(old_window); + ScaleWindow::get(window)->scaleSelectWindow(); - if (cWindow) - cWindow->addDamage(); - - us->highlighted_window_ = window->id(); - } + UnityScreen* us = UnityScreen::get(screen); - ScaleWindow *sWindow = ScaleWindow::get(window); - if (sWindow) - sWindow->scaleSelectWindow(); + if (us->scale_highlighted_window_ != window->id()) + us->scale_highlighted_window_ = window->id(); } void UnityWindow::OnInitiateSpreed() diff --git a/plugins/unityshell/src/unityshell.h b/plugins/unityshell/src/unityshell.h index d5fe86f2c..21498f0cf 100644 --- a/plugins/unityshell/src/unityshell.h +++ b/plugins/unityshell/src/unityshell.h @@ -345,7 +345,7 @@ private: glib::SourceManager sources_; unity::ThumbnailGenerator thumb_generator; - Window highlighted_window_; + Window scale_highlighted_window_; WindowMinimizeSpeedController* minimize_speed_controller; friend class UnityWindow; @@ -488,9 +488,9 @@ private: static GLTexture::List close_normal_tex_; static GLTexture::List close_prelight_tex_; static GLTexture::List close_pressed_tex_; - panel::WindowState close_icon_state_; compiz::WindowInputRemoverLock::Weak input_remover_; - CompRect close_button_area_; + panel::WindowState close_icon_state_; + nux::Geometry close_button_geo_; glib::Source::UniquePtr focus_desktop_timeout_; }; -- cgit v1.2.3 From 08bf53a184ef5363cd452e158fec37b6e6a6987f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 7 Sep 2012 02:05:14 +0200 Subject: UnityShell: put back the string optimizations, fix indentation (bzr r2655.5.14) --- plugins/unityshell/src/unityshell.cpp | 170 ++++++++++++++++++++++------------ 1 file changed, 109 insertions(+), 61 deletions(-) (limited to 'plugins/unityshell/src') diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index 9830a6fac..33e8e4e64 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -3243,78 +3243,124 @@ void UnityScreen::InitHints() { // TODO move category text into a vector... + // Compiz' plug-in names + static const std::string COMPIZ_CORE_PLUGIN_NAME = "core"; + static const std::string COMPIZ_EXPO_PLUGIN_NAME = "expo"; + static const std::string COMPIZ_GRID_PLUGIN_NAME = "grid"; + static const std::string COMPIZ_MOVE_PLUGIN_NAME = "move"; + static const std::string COMPIZ_RESIZE_PLUGIN_NAME = "resize"; + static const std::string COMPIZ_SCALE_PLUGIN_NAME = "scale"; + static const std::string COMPIZ_UNITYSHELL_PLUGIN_NAME = "unityshell"; + static const std::string COMPIZ_WALL_PLUGIN_NAME = "wall"; + + // Compiz Core Options + static const std::string COMPIZ_CORE_OPTION_SHOW_DESKTOP_KEY = "show_desktop_key"; + static const std::string COMPIZ_CORE_OPTION_MAXIMIZE_WINDOW_KEY = "maximize_window_key"; + static const std::string COMPIZ_CORE_OPTION_UNMAXIMIZE_WINDOW_KEY = "unmaximize_window_key"; + static const std::string COMPIZ_CORE_OPTION_CLOSE_WINDOW_KEY = "close_window_key"; + static const std::string COMPIZ_CORE_OPTION_WINDOW_MENU_KEY = "window_menu_key"; + + // Compiz Expo Options + static const std::string COMPIZ_EXPO_OPTION_EXPO_KEY = "expo_key"; + + // Compiz Grid Options + static const std::string COMPIZ_GRID_OPTION_PUT_LEFT_KEY = "put_left_key"; + + // Compiz Move Options + static const std::string COMPIZ_MOVE_OPTION_INITIATE_BUTTON = "initiate_button"; + + // Compiz Resize Options + static const std::string COMPIZ_RESIZE_OPTION_INITIATE_BUTTON = "initiate_button"; + + // Compiz Scale Options + static const std::string COMPIZ_SCALE_OPTION_INITIATE_ALL_KEY = "initiate_all_key"; + + // Compiz Unityshell Options + static const std::string COMPIZ_UNITYSHELL_OPTION_SHOW_LAUNCHER = "show_launcher"; + static const std::string COMPIZ_UNITYSHELL_OPTION_KEYBOARD_FOCUS = "keyboard_focus"; + static const std::string COMPIZ_UNITYSHELL_OPTION_LAUNCHER_SWITCHER_FORWARD = "launcher_switcher_forward"; + static const std::string COMPIZ_UNITYSHELL_OPTION_SHOW_HUD = "show_hud"; + static const std::string COMPIZ_UNITYSHELL_OPTION_PANEL_FIRST_MENU = "panel_first_menu"; + static const std::string COMPIZ_UNITYSHELL_OPTION_ALT_TAB_FORWARD = "alt_tab_forward"; + static const std::string COMPIZ_UNITYSHELL_OPTION_ALT_TAB_NEXT_WINDOW = "alt_tab_next_window"; + + // Compiz Wall Options + static const std::string COMPIZ_WALL_OPTION_LEFT_KEY = "left_key"; + static const std::string COMPIZ_WALL_OPTION_LEFT_WINDOW_KEY = "left_window_key"; + + // Launcher... - std::string const launcher(_("Launcher")); + static const std::string launcher(_("Launcher")); hints_.push_back(std::make_shared(launcher, "", _(" (Hold)"), _("Opens the Launcher, displays shortcuts."), shortcut::COMPIZ_KEY_OPTION, - "unityshell", - "show_launcher" )); + COMPIZ_UNITYSHELL_PLUGIN_NAME, + COMPIZ_UNITYSHELL_OPTION_SHOW_LAUNCHER)); hints_.push_back(std::make_shared(launcher, "", "", _("Opens Launcher keyboard navigation mode."), shortcut::COMPIZ_KEY_OPTION, - "unityshell", - "keyboard_focus")); + COMPIZ_UNITYSHELL_PLUGIN_NAME, + COMPIZ_UNITYSHELL_OPTION_KEYBOARD_FOCUS)); hints_.push_back(std::make_shared(launcher, "", "", _("Switches applications via the Launcher."), shortcut::COMPIZ_KEY_OPTION, - "unityshell", - "launcher_switcher_forward")); + COMPIZ_UNITYSHELL_PLUGIN_NAME, + COMPIZ_UNITYSHELL_OPTION_LAUNCHER_SWITCHER_FORWARD)); hints_.push_back(std::make_shared(launcher, "", _(" + 1 to 9"), _("Same as clicking on a Launcher icon."), shortcut::COMPIZ_KEY_OPTION, - "unityshell", - "show_launcher")); + COMPIZ_UNITYSHELL_PLUGIN_NAME, + COMPIZ_UNITYSHELL_OPTION_SHOW_LAUNCHER)); hints_.push_back(std::make_shared(launcher, "", _(" + Shift + 1 to 9"), _("Opens a new window in the app."), shortcut::COMPIZ_KEY_OPTION, - "unityshell", - "show_launcher")); + COMPIZ_UNITYSHELL_PLUGIN_NAME, + COMPIZ_UNITYSHELL_OPTION_SHOW_LAUNCHER)); hints_.push_back(std::make_shared(launcher, "", " + T", _("Opens the Trash."), shortcut::COMPIZ_KEY_OPTION, - "unityshell", - "show_launcher")); + COMPIZ_UNITYSHELL_PLUGIN_NAME, + COMPIZ_UNITYSHELL_OPTION_SHOW_LAUNCHER)); // Dash... - std::string const dash( _("Dash")); + static const std::string dash( _("Dash")); hints_.push_back(std::make_shared(dash, "", _(" (Tap)"), _("Opens the Dash Home."), shortcut::COMPIZ_KEY_OPTION, - "unityshell", - "show_launcher")); + COMPIZ_UNITYSHELL_PLUGIN_NAME, + COMPIZ_UNITYSHELL_OPTION_SHOW_LAUNCHER)); hints_.push_back(std::make_shared(dash, "", " + A", _("Opens the Dash App Lens."), shortcut::COMPIZ_KEY_OPTION, - "unityshell", - "show_launcher")); + COMPIZ_UNITYSHELL_PLUGIN_NAME, + COMPIZ_UNITYSHELL_OPTION_SHOW_LAUNCHER)); hints_.push_back(std::make_shared(dash, "", " + F", _("Opens the Dash Files Lens."), shortcut::COMPIZ_KEY_OPTION, - "unityshell", - "show_launcher")); + COMPIZ_UNITYSHELL_PLUGIN_NAME, + COMPIZ_UNITYSHELL_OPTION_SHOW_LAUNCHER)); hints_.push_back(std::make_shared(dash, "", " + M", _("Opens the Dash Music Lens."), shortcut::COMPIZ_KEY_OPTION, - "unityshell", - "show_launcher")); + COMPIZ_UNITYSHELL_PLUGIN_NAME, + COMPIZ_UNITYSHELL_OPTION_SHOW_LAUNCHER)); hints_.push_back(std::make_shared(dash, "", " + V", _("Opens the Dash Video Lens."), shortcut::COMPIZ_KEY_OPTION, - "unityshell", - "show_launcher")); + COMPIZ_UNITYSHELL_PLUGIN_NAME, + COMPIZ_UNITYSHELL_OPTION_SHOW_LAUNCHER)); hints_.push_back(std::make_shared(dash, "", "", _("Switches between Lenses."), @@ -3332,15 +3378,15 @@ void UnityScreen::InitHints() _("Enter"))); // Menu Bar - std::string const menubar(_("HUD & Menu Bar")); + static const std::string menubar(_("HUD & Menu Bar")); hints_.push_back(std::make_shared(menubar, "", _(" (Tap)"), _("Opens the HUD."), shortcut::COMPIZ_KEY_OPTION, - "unityshell", - "show_hud")); + COMPIZ_UNITYSHELL_PLUGIN_NAME, + COMPIZ_UNITYSHELL_OPTION_SHOW_HUD)); - hints_.push_back(std::make_shared(menubar, "", " (Hold)", + hints_.push_back(std::make_shared(menubar, "", _(" (Hold)"), _("Reveals the application menu."), shortcut::HARDCODED_OPTION, "Alt")); @@ -3348,8 +3394,8 @@ void UnityScreen::InitHints() hints_.push_back(std::make_shared(menubar, "", "", _("Opens the indicator menu."), shortcut::COMPIZ_KEY_OPTION, - "unityshell", - "panel_first_menu")); + COMPIZ_UNITYSHELL_PLUGIN_NAME, + COMPIZ_UNITYSHELL_OPTION_PANEL_FIRST_MENU)); hints_.push_back(std::make_shared(menubar, "", "", _("Moves focus between indicators."), @@ -3357,19 +3403,19 @@ void UnityScreen::InitHints() _("Cursor Left or Right"))); // Switching - std::string const switching(_("Switching")); + static const std::string switching(_("Switching")); hints_.push_back(std::make_shared(switching, "", "", _("Switches between applications."), shortcut::COMPIZ_KEY_OPTION, - "unityshell", - "alt_tab_forward")); + COMPIZ_UNITYSHELL_PLUGIN_NAME, + COMPIZ_UNITYSHELL_OPTION_ALT_TAB_FORWARD)); hints_.push_back(std::make_shared(switching, "", "", _("Switches windows of current applications."), shortcut::COMPIZ_KEY_OPTION, - "unityshell", - "alt_tab_next_window")); + COMPIZ_UNITYSHELL_PLUGIN_NAME, + COMPIZ_UNITYSHELL_OPTION_ALT_TAB_NEXT_WINDOW)); hints_.push_back(std::make_shared(switching, "", "", _("Moves the focus."), @@ -3377,69 +3423,71 @@ void UnityScreen::InitHints() _("Cursor Left or Right"))); // Workspaces - std::string const workspaces(_("Workspaces")); + static const std::string workspaces(_("Workspaces")); hints_.push_back(std::make_shared(workspaces, "", "", _("Switches between workspaces."), shortcut::COMPIZ_KEY_OPTION, - "expo", - "expo_key")); + COMPIZ_EXPO_PLUGIN_NAME, + COMPIZ_EXPO_OPTION_EXPO_KEY)); hints_.push_back(std::make_shared(workspaces, "", _(" + Arrow Keys"), _("Switches workspaces."), shortcut::COMPIZ_METAKEY_OPTION, - "wall", - "left_key")); + COMPIZ_WALL_PLUGIN_NAME, + COMPIZ_WALL_OPTION_LEFT_KEY)); hints_.push_back(std::make_shared(workspaces, "", _(" + Arrow Keys"), _("Moves focused window to another workspace."), shortcut::COMPIZ_METAKEY_OPTION, - "wall", - "left_window_key")); + COMPIZ_WALL_PLUGIN_NAME, + COMPIZ_WALL_OPTION_LEFT_WINDOW_KEY)); // Windows - std::string const windows(_("Windows")); + static const std::string windows(_("Windows")); + hints_.push_back(std::make_shared(windows, "", "", _("Spreads all windows in the current workspace."), shortcut::COMPIZ_KEY_OPTION, - "scale", - "initiate_all_key")); + COMPIZ_SCALE_PLUGIN_NAME, + COMPIZ_SCALE_OPTION_INITIATE_ALL_KEY)); hints_.push_back(std::make_shared(windows, "", "", _("Minimises all windows."), shortcut::COMPIZ_KEY_OPTION, - "core", - "show_desktop_key")); + COMPIZ_CORE_PLUGIN_NAME, + COMPIZ_CORE_OPTION_SHOW_DESKTOP_KEY)); hints_.push_back(std::make_shared(windows, "", "", _("Maximises the current window."), shortcut::COMPIZ_KEY_OPTION, - "core", - "maximize_window_key")); + COMPIZ_CORE_PLUGIN_NAME, + COMPIZ_CORE_OPTION_MAXIMIZE_WINDOW_KEY)); hints_.push_back(std::make_shared(windows, "", "", _("Restores or minimises the current window."), shortcut::COMPIZ_KEY_OPTION, - "core", - "unmaximize_window_key")); + COMPIZ_CORE_PLUGIN_NAME, + COMPIZ_CORE_OPTION_UNMAXIMIZE_WINDOW_KEY)); hints_.push_back(std::make_shared(windows, "", _(" or Right"), _("Semi-maximise the current window."), shortcut::COMPIZ_KEY_OPTION, - "grid", - "put_left_key")); + COMPIZ_GRID_PLUGIN_NAME, + COMPIZ_GRID_OPTION_PUT_LEFT_KEY)); hints_.push_back(std::make_shared(windows, "", "", _("Closes the current window."), shortcut::COMPIZ_KEY_OPTION, - "core", - "close_window_key")); + COMPIZ_CORE_PLUGIN_NAME, + COMPIZ_CORE_OPTION_CLOSE_WINDOW_KEY)); hints_.push_back(std::make_shared(windows, "", "", _("Opens the window accessibility menu."), - shortcut::HARDCODED_OPTION, - _("Alt + Space"))); + shortcut::COMPIZ_KEY_OPTION, + COMPIZ_CORE_PLUGIN_NAME, + COMPIZ_CORE_OPTION_WINDOW_MENU_KEY)); hints_.push_back(std::make_shared(windows, "", "", _("Places the window in corresponding position."), @@ -3449,14 +3497,14 @@ void UnityScreen::InitHints() hints_.push_back(std::make_shared(windows, "", _(" Drag"), _("Moves the window."), shortcut::COMPIZ_MOUSE_OPTION, - "move", - "initiate_button")); + COMPIZ_MOVE_PLUGIN_NAME, + COMPIZ_MOVE_OPTION_INITIATE_BUTTON)); hints_.push_back(std::make_shared(windows, "", _(" Drag"), _("Resizes the window."), shortcut::COMPIZ_MOUSE_OPTION, - "resize", - "initiate_button")); + COMPIZ_RESIZE_PLUGIN_NAME, + COMPIZ_RESIZE_OPTION_INITIATE_BUTTON)); } void UnityScreen::InitGesturesSupport() -- cgit v1.2.3