From efd216005e524592d2dd22484c0a789256aa13d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 23 Nov 2012 04:39:24 +0100 Subject: IconRenderer: add TexturePool static class used to cache all the icons textures using smart pointers No need to delete textures manually anymore (bzr r2919.5.1) --- plugins/unityshell/src/unityshell.cpp | 1 - unity-shared/IconRenderer.cpp | 421 +++++++++++++++------------------- unity-shared/IconRenderer.h | 5 +- 3 files changed, 190 insertions(+), 237 deletions(-) diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index f572f4e4f..786b5e3fc 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -415,7 +415,6 @@ UnityScreen::~UnityScreen() notify_uninit(); unity_a11y_finalize(); - ::unity::ui::IconRenderer::DestroyTextures(); QuicklistManager::Destroy(); reset_glib_logging(); diff --git a/unity-shared/IconRenderer.cpp b/unity-shared/IconRenderer.cpp index 7bc2fd142..7622d50f8 100644 --- a/unity-shared/IconRenderer.cpp +++ b/unity-shared/IconRenderer.cpp @@ -25,7 +25,9 @@ #include #include +#include #include +#include "unity-shared/CairoTexture.h" #include "GraphicsUtils.h" #include @@ -39,6 +41,8 @@ namespace unity { namespace ui { +namespace +{ #ifdef USE_GLES #define VertexShaderHeader "#version 100\n" @@ -171,6 +175,7 @@ LRP temp, factor.x, color, desat; \n\ MUL result.color.rgb, temp, colorify_color; \n\ MOV result.color.a, color; \n\ END"); +} // anonymous namespace // The local namespace is purely for namespacing the file local variables below. namespace local @@ -181,43 +186,65 @@ enum IconSize { SMALL = 0, BIG, - LAST, + SIZE, }; +} // anonymous namespace +} // local namespace -bool textures_created = false; -nux::BaseTexture* progress_bar_trough = 0; -nux::BaseTexture* progress_bar_fill = 0; -nux::BaseTexture* pip_ltr = 0; -nux::BaseTexture* pip_rtl = 0; -nux::BaseTexture* arrow_ltr = 0; -nux::BaseTexture* arrow_rtl = 0; -nux::BaseTexture* arrow_empty_ltr = 0; -nux::BaseTexture* arrow_empty_rtl = 0; - -// nux::BaseTexture* squircle_base = 0; -// nux::BaseTexture* squircle_base_selected = 0; -// nux::BaseTexture* squircle_edge = 0; -// nux::BaseTexture* squircle_glow = 0; -// nux::BaseTexture* squircle_shadow = 0; -// nux::BaseTexture* squircle_shine = 0; - -std::vector icon_background; -std::vector icon_selected_background; -std::vector icon_edge; -std::vector icon_glow; -std::vector icon_shadow; -std::vector icon_shine; -nux::ObjectPtr offscreen_progress_texture; -nux::ObjectPtr shader_program_uv_persp_correction; +std::unique_ptr IconRenderer::textures_; + +struct IconRenderer::TexturesPool +{ + TexturesPool(); + + nux::ObjectPtr RenderLabelTexture(char label, int icon_size, nux::Color const& bg_color); + + BaseTexturePtr progress_bar_trough; + BaseTexturePtr progress_bar_fill; + BaseTexturePtr pip_ltr; + // BaseTexturePtr pip_rtl; + BaseTexturePtr arrow_ltr; + BaseTexturePtr arrow_rtl; + BaseTexturePtr arrow_empty_ltr; + // BaseTexturePtr arrow_empty_rtl; + + // BaseTexturePtr squircle_base; + // BaseTexturePtr squircle_base_selected; + // BaseTexturePtr squircle_edge; + // BaseTexturePtr squircle_glow; + // BaseTexturePtr squircle_shadow; + // BaseTexturePtr squircle_shine; + + BaseTexturePtr icon_background[local::IconSize::SIZE]; + BaseTexturePtr icon_selected_background[local::IconSize::SIZE]; + BaseTexturePtr icon_edge[local::IconSize::SIZE]; + BaseTexturePtr icon_glow[local::IconSize::SIZE]; + BaseTexturePtr icon_shadow[local::IconSize::SIZE]; + BaseTexturePtr icon_shine[local::IconSize::SIZE]; + + nux::ObjectPtr offscreen_progress_texture; + nux::ObjectPtr shader_program_uv_persp_correction; #ifndef USE_GLES -nux::ObjectPtr asm_shader; + nux::ObjectPtr asm_shader; #endif -std::map label_map; -void generate_textures(); -void destroy_textures(); -} -} + std::map labels; + +private: + inline void LoadTexture(BaseTexturePtr &texture_ptr, std::string const& filename) + { + texture_ptr.Adopt(nux::CreateTexture2DFromFile(filename.c_str(), -1, true)); + } + + inline void GenerateTextures(BaseTexturePtr (&texture)[local::IconSize::SIZE], + std::string const& big_file, std::string const& small_file) + { + LoadTexture(texture[local::IconSize::SMALL], small_file); + LoadTexture(texture[local::IconSize::BIG], big_file); + } + + void SetupShaders(); +}; IconRenderer::IconRenderer() : icon_size(0) @@ -226,13 +253,12 @@ IconRenderer::IconRenderer() { pip_style = OUTSIDE_TILE; - if (!local::textures_created) - local::generate_textures(); + if (!textures_) + textures_.reset(new IconRenderer::TexturesPool()); } IconRenderer::~IconRenderer() -{ -} +{} void IconRenderer::SetTargetSize(int tile_size, int image_size_, int spacing_) { @@ -412,11 +438,11 @@ void IconRenderer::RenderIcon(nux::GraphicsEngine& GfxContext, RenderArg const& float glow_intensity = arg.glow_intensity; float shadow_intensity = 0.6f; - nux::BaseTexture* background = local::icon_background[size]; - nux::BaseTexture* edge = local::icon_edge[size]; - nux::BaseTexture* glow = local::icon_glow[size]; - nux::BaseTexture* shine = local::icon_shine[size]; - nux::BaseTexture* shadow = local::icon_shadow[size]; + BaseTexturePtr background = textures_->icon_background[size]; + BaseTexturePtr const& edge = textures_->icon_edge[size]; + BaseTexturePtr const& glow = textures_->icon_glow[size]; + BaseTexturePtr const& shine = textures_->icon_shine[size]; + BaseTexturePtr const& shadow = textures_->icon_shadow[size]; nux::Color shortcut_color = arg.colorify; @@ -445,7 +471,7 @@ void IconRenderer::RenderIcon(nux::GraphicsEngine& GfxContext, RenderArg const& glow_intensity = 1.0f; shadow_intensity = 0.0f; - background = local::icon_selected_background[size]; + background = textures_->icon_selected_background[size]; } else { @@ -477,8 +503,6 @@ void IconRenderer::RenderIcon(nux::GraphicsEngine& GfxContext, RenderArg const& { nux::Color shadow_color = background_tile_colorify * 0.3f; - // FIXME it is using the same transformation of the glow, - // should have its own transformation. RenderElement(GfxContext, arg, shadow->GetDeviceTexture(), @@ -575,7 +599,7 @@ void IconRenderer::RenderIcon(nux::GraphicsEngine& GfxContext, RenderArg const& RenderElement(GfxContext, arg, - local::icon_glow[size]->GetDeviceTexture(), + textures_->icon_glow[size]->GetDeviceTexture(), arg.icon->GlowColor(), nux::color::White, fade_out * arg.alpha, @@ -588,17 +612,17 @@ void IconRenderer::RenderIcon(nux::GraphicsEngine& GfxContext, RenderArg const& // draw progress bar if (arg.progress_bias > -1.0f && arg.progress_bias < 1.0f) { - if (local::offscreen_progress_texture->GetWidth() != icon_size || - local::offscreen_progress_texture->GetHeight() != icon_size) + if (textures_->offscreen_progress_texture->GetWidth() != icon_size || + textures_->offscreen_progress_texture->GetHeight() != icon_size) { - local::offscreen_progress_texture = nux::GetGraphicsDisplay()->GetGpuDevice() + textures_->offscreen_progress_texture = nux::GetGraphicsDisplay()->GetGpuDevice() ->CreateSystemCapableDeviceTexture(icon_size, icon_size, 1, nux::BITFMT_R8G8B8A8); } - RenderProgressToTexture(GfxContext, local::offscreen_progress_texture, arg.progress, arg.progress_bias); + RenderProgressToTexture(GfxContext, textures_->offscreen_progress_texture, arg.progress, arg.progress_bias); RenderElement(GfxContext, arg, - local::offscreen_progress_texture, + textures_->offscreen_progress_texture, nux::color::White, nux::color::White, arg.alpha, @@ -631,12 +655,22 @@ void IconRenderer::RenderIcon(nux::GraphicsEngine& GfxContext, RenderArg const& { char shortcut = (char) arg.shortcut_label; - if (local::label_map.find(shortcut) == local::label_map.end()) - local::label_map[shortcut] = RenderCharToTexture(shortcut, icon_size, icon_size, shortcut_color); + BaseTexturePtr label; + auto label_it = textures_->labels.find(shortcut); + + if (label_it != textures_->labels.end()) + { + label = label_it->second; + } + else + { + label = textures_->RenderLabelTexture(shortcut, icon_size, shortcut_color); + textures_->labels[shortcut] = label; + } RenderElement(GfxContext, arg, - local::label_map[shortcut]->GetDeviceTexture(), + label->GetDeviceTexture(), nux::Color(0xFFFFFFFF), nux::color::White, arg.alpha, @@ -645,43 +679,39 @@ void IconRenderer::RenderIcon(nux::GraphicsEngine& GfxContext, RenderArg const& } } -nux::BaseTexture* IconRenderer::RenderCharToTexture(char label, int width, int height, nux::Color const& bg_color) +nux::ObjectPtr IconRenderer::TexturesPool::RenderLabelTexture(char label, int icon_size, nux::Color const& bg_color) { - nux::BaseTexture* texture = NULL; - nux::CairoGraphics* cg = new nux::CairoGraphics(CAIRO_FORMAT_ARGB32, - width, - height); - cairo_t* cr = cg->GetContext(); - PangoLayout* layout = NULL; - PangoFontDescription* desc = NULL; - GtkSettings* settings = gtk_settings_get_default(); // not ref'ed - gchar* fontName = NULL; - - double label_ratio = 0.44f; - double label_size = icon_size * label_ratio; - double label_x = (icon_size - label_size) / 2; - double label_y = (icon_size - label_size) / 2; - double label_w = label_size; - double label_h = label_size; - double label_radius = 3.0f; + nux::CairoGraphics cg(CAIRO_FORMAT_ARGB32, icon_size, icon_size); + std::shared_ptr cairo_context(cg.GetContext(), cairo_destroy); + cairo_t* cr = cairo_context.get(); + glib::String font_name; + + const double label_ratio = 0.44f; + const double label_size = icon_size * label_ratio; + const double label_x = (icon_size - label_size) / 2; + const double label_y = (icon_size - label_size) / 2; + const double label_w = label_size; + const double label_h = label_size; + const double label_radius = 3.0f; cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); cairo_paint(cr); cairo_scale(cr, 1.0f, 1.0f); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); - cg->DrawRoundedRectangle(cr, 1.0f, label_x, label_y, label_radius, label_w, label_h); + cg.DrawRoundedRectangle(cr, 1.0f, label_x, label_y, label_radius, label_w, label_h); cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.75f); cairo_fill_preserve(cr); cairo_set_source_rgba(cr, bg_color.red, bg_color.green, bg_color.blue, 0.20f); cairo_fill(cr); - double text_ratio = 0.75; - double text_size = label_size * text_ratio; - layout = pango_cairo_create_layout(cr); - g_object_get(settings, "gtk-font-name", &fontName, NULL); - desc = pango_font_description_from_string(fontName); - pango_font_description_set_absolute_size(desc, text_size * PANGO_SCALE); - pango_layout_set_font_description(layout, desc); + const double text_ratio = 0.75; + double text_size = label_size * text_ratio; + glib::Object layout(pango_cairo_create_layout(cr)); + g_object_get(gtk_settings_get_default(), "gtk-font-name", &font_name, NULL); + std::shared_ptr desc(pango_font_description_from_string(font_name), + pango_font_description_free); + pango_font_description_set_absolute_size(desc.get(), text_size * PANGO_SCALE); + pango_layout_set_font_description(layout, desc.get()); pango_layout_set_text(layout, &label, 1); PangoRectangle logRect; @@ -695,16 +725,7 @@ nux::BaseTexture* IconRenderer::RenderCharToTexture(char label, int width, int h cairo_move_to(cr, x, y); pango_cairo_show_layout(cr, layout); - nux::NBitmapData* bitmap = cg->GetBitmap(); - texture = nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableTexture(); - texture->Update(bitmap); - delete bitmap; - delete cg; - g_object_unref(layout); - pango_font_description_free(desc); - g_free(fontName); - - return texture; + return texture_ptr_from_cairo_graphics(cg); } void IconRenderer::RenderElement(nux::GraphicsEngine& GfxContext, @@ -786,28 +807,28 @@ void IconRenderer::RenderElement(nux::GraphicsEngine& GfxContext, if (nux::GetWindowThread()->GetGraphicsEngine().UsingGLSLCodePath()) { - local::shader_program_uv_persp_correction->Begin(); + textures_->shader_program_uv_persp_correction->Begin(); - int TextureObjectLocation = local::shader_program_uv_persp_correction->GetUniformLocationARB("TextureObject0"); - VertexLocation = local::shader_program_uv_persp_correction->GetAttributeLocation("iVertex"); - TextureCoord0Location = local::shader_program_uv_persp_correction->GetAttributeLocation("iTexCoord0"); - FragmentColor = local::shader_program_uv_persp_correction->GetUniformLocationARB("color0"); - ColorifyColor = local::shader_program_uv_persp_correction->GetUniformLocationARB("colorify_color"); - DesatFactor = local::shader_program_uv_persp_correction->GetUniformLocationARB("desat_factor"); + int TextureObjectLocation = textures_->shader_program_uv_persp_correction->GetUniformLocationARB("TextureObject0"); + VertexLocation = textures_->shader_program_uv_persp_correction->GetAttributeLocation("iVertex"); + TextureCoord0Location = textures_->shader_program_uv_persp_correction->GetAttributeLocation("iTexCoord0"); + FragmentColor = textures_->shader_program_uv_persp_correction->GetUniformLocationARB("color0"); + ColorifyColor = textures_->shader_program_uv_persp_correction->GetUniformLocationARB("colorify_color"); + DesatFactor = textures_->shader_program_uv_persp_correction->GetUniformLocationARB("desat_factor"); if (TextureObjectLocation != -1) CHECKGL(glUniform1iARB(TextureObjectLocation, 0)); - int VPMatrixLocation = local::shader_program_uv_persp_correction->GetUniformLocationARB("ViewProjectionMatrix"); + int VPMatrixLocation = textures_->shader_program_uv_persp_correction->GetUniformLocationARB("ViewProjectionMatrix"); if (VPMatrixLocation != -1) { - local::shader_program_uv_persp_correction->SetUniformLocMatrix4fv((GLint)VPMatrixLocation, 1, false, (GLfloat*) & (_stored_projection_matrix.m)); + textures_->shader_program_uv_persp_correction->SetUniformLocMatrix4fv((GLint)VPMatrixLocation, 1, false, (GLfloat*) & (_stored_projection_matrix.m)); } } #ifndef USE_GLES else { - local::asm_shader->Begin(); + textures_->asm_shader->Begin(); VertexLocation = nux::VTXATTRIB_POSITION; TextureCoord0Location = nux::VTXATTRIB_TEXCOORD0; @@ -869,12 +890,12 @@ void IconRenderer::RenderElement(nux::GraphicsEngine& GfxContext, if (nux::GetWindowThread()->GetGraphicsEngine().UsingGLSLCodePath()) { - local::shader_program_uv_persp_correction->End(); + textures_->shader_program_uv_persp_correction->End(); } else { #ifndef USE_GLES - local::asm_shader->End(); + textures_->asm_shader->End(); #endif } } @@ -917,7 +938,7 @@ void IconRenderer::RenderIndicators(nux::GraphicsEngine& GfxContext, color = color * alpha; - nux::BaseTexture* texture; + BaseTexturePtr texture; // markers are well outside screen bounds to start int markers [3] = {-100, -100, -100}; @@ -925,25 +946,25 @@ void IconRenderer::RenderIndicators(nux::GraphicsEngine& GfxContext, if (!arg.running_on_viewport) { markers[0] = markerCenter; - texture = local::arrow_empty_ltr; + texture = textures_->arrow_empty_ltr; } else if (running == 1) { markers[0] = markerCenter; - texture = local::arrow_ltr; + texture = textures_->arrow_ltr; } else if (running == 2) { markers[0] = markerCenter - 2 * scale; markers[1] = markerCenter + 2 * scale; - texture = local::pip_ltr; + texture = textures_->pip_ltr; } else { markers[0] = markerCenter - 4 * scale; markers[1] = markerCenter; markers[2] = markerCenter + 4 * scale; - texture = local::pip_ltr; + texture = textures_->pip_ltr; } @@ -952,7 +973,7 @@ void IconRenderer::RenderIndicators(nux::GraphicsEngine& GfxContext, int center = markers[i]; if (center == -100) break; - + GfxContext.QRP_1Tex(markerX, center - ((texture->GetHeight() * scale) / 2) - 1, (float) texture->GetWidth() * scale, @@ -968,11 +989,11 @@ void IconRenderer::RenderIndicators(nux::GraphicsEngine& GfxContext, nux::TexCoordXForm texxform; nux::Color color = nux::color::LightGrey * alpha; - GfxContext.QRP_1Tex((geo.x + geo.width) - local::arrow_rtl->GetWidth(), - markerCenter - (local::arrow_rtl->GetHeight() / 2) - 1, - (float) local::arrow_rtl->GetWidth(), - (float) local::arrow_rtl->GetHeight(), - local::arrow_rtl->GetDeviceTexture(), + GfxContext.QRP_1Tex((geo.x + geo.width) - textures_->arrow_rtl->GetWidth(), + markerCenter - (textures_->arrow_rtl->GetHeight() / 2) - 1, + (float) textures_->arrow_rtl->GetWidth(), + (float) textures_->arrow_rtl->GetHeight(), + textures_->arrow_rtl->GetDeviceTexture(), texxform, color); } @@ -987,10 +1008,10 @@ void IconRenderer::RenderProgressToTexture(nux::GraphicsEngine& GfxContext, int height = texture->GetHeight(); int progress_width = icon_size; - int progress_height = local::progress_bar_trough->GetHeight(); + int progress_height = textures_->progress_bar_trough->GetHeight(); int fill_width = image_size - (icon_size - image_size); - int fill_height = local::progress_bar_fill->GetHeight(); + int fill_height = textures_->progress_bar_fill->GetHeight(); int fill_offset = (progress_width - fill_width) / 2; @@ -1025,10 +1046,10 @@ void IconRenderer::RenderProgressToTexture(nux::GraphicsEngine& GfxContext, // left door GfxContext.PushClippingRectangle(nux::Geometry(left_edge, 0, half_size, height)); GfxContext.QRP_1Tex(left_edge, progress_y, progress_width, progress_height, - local::progress_bar_trough->GetDeviceTexture(), texxform, + textures_->progress_bar_trough->GetDeviceTexture(), texxform, nux::color::White); GfxContext.QRP_1Tex(left_edge + fill_offset, fill_y, fill_width, fill_height, - local::progress_bar_fill->GetDeviceTexture(), texxform, + textures_->progress_bar_fill->GetDeviceTexture(), texxform, nux::color::White); GfxContext.PopClippingRectangle(); @@ -1036,11 +1057,11 @@ void IconRenderer::RenderProgressToTexture(nux::GraphicsEngine& GfxContext, GfxContext.PushClippingRectangle(nux::Geometry(left_edge + half_size, 0, half_size, height)); GfxContext.QRP_1Tex(right_edge - progress_width, progress_y, progress_width, progress_height, - local::progress_bar_trough->GetDeviceTexture(), texxform, + textures_->progress_bar_trough->GetDeviceTexture(), texxform, nux::color::White); GfxContext.QRP_1Tex(right_edge - progress_width + fill_offset, fill_y, fill_width, fill_height, - local::progress_bar_fill->GetDeviceTexture(), texxform, + textures_->progress_bar_fill->GetDeviceTexture(), texxform, nux::color::White); GfxContext.PopClippingRectangle(); @@ -1048,16 +1069,9 @@ void IconRenderer::RenderProgressToTexture(nux::GraphicsEngine& GfxContext, unity::graphics::PopOffscreenRenderTarget(); } -void IconRenderer::DestroyTextures() -{ - local::destroy_textures(); -} - void IconRenderer::DestroyShortcutTextures() { - for (auto texture : local::label_map) - texture.second->UnReference(); - local::label_map.clear(); + textures_->labels.clear(); } void IconRenderer::GetInverseScreenPerspectiveMatrix(nux::Matrix4& ViewMatrix, nux::Matrix4& PerspectiveMatrix, @@ -1145,12 +1159,55 @@ void IconRenderer::GetInverseScreenPerspectiveMatrix(nux::Matrix4& ViewMatrix, n PerspectiveMatrix.Perspective(Fovy, AspectRatio, NearClipPlane, FarClipPlane); } -// The local namespace is purely for namespacing the file local variables below. -namespace local +IconRenderer::TexturesPool::TexturesPool() + : offscreen_progress_texture(nux::GetGraphicsDisplay()->GetGpuDevice()->CreateSystemCapableDeviceTexture(2, 2, 1, nux::BITFMT_R8G8B8A8)) { -namespace -{ -void setup_shaders() + LoadTexture(progress_bar_trough, PKGDATADIR"/progress_bar_trough.png"); + LoadTexture(progress_bar_fill, PKGDATADIR"/progress_bar_fill.png"); + LoadTexture(pip_ltr, PKGDATADIR"/launcher_pip_ltr.png"); + // LoadTexture(pip_rtl, PKGDATADIR"/launcher_pip_rtl.png"); + LoadTexture(arrow_ltr, PKGDATADIR"/launcher_arrow_ltr.png"); + LoadTexture(arrow_rtl, PKGDATADIR"/launcher_arrow_rtl.png"); + LoadTexture(arrow_empty_ltr, PKGDATADIR"/launcher_arrow_outline_ltr.png"); + // LoadTexture(arrow_empty_rtl, PKGDATADIR"/launcher_arrow_outline_rtl.png"); + + // LoadTexture(squircle_base, PKGDATADIR"/squircle_base_54.png"); + // LoadTexture(squircle_base_selected, PKGDATADIR"/squircle_base_selected_54.png"); + // LoadTexture(squircle_edge, PKGDATADIR"/squircle_edge_54.png"); + // LoadTexture(squircle_glow, PKGDATADIR"/squircle_glow_62.png"); + // LoadTexture(squircle_shadow, PKGDATADIR"/squircle_shadow_62.png"); + // LoadTexture(squircle_shine, PKGDATADIR"/squircle_shine_54.png"); + + // BaseTexturePtr icon_background[local::IconSize::SIZE]; + // BaseTexturePtr icon_selected_background[local::IconSize::SIZE]; + // BaseTexturePtr icon_edge[local::IconSize::SIZE]; + // BaseTexturePtr icon_glow[local::IconSize::SIZE]; + // BaseTexturePtr icon_shadow[local::IconSize::SIZE]; + // BaseTexturePtr icon_shine[local::IconSize::SIZE]; + + GenerateTextures(icon_background, + PKGDATADIR"/launcher_icon_back_150.png", + PKGDATADIR"/launcher_icon_back_54.png"); + GenerateTextures(icon_selected_background, + PKGDATADIR"/launcher_icon_selected_back_150.png", + PKGDATADIR"/launcher_icon_back_54.png"); + GenerateTextures(icon_edge, + PKGDATADIR"/launcher_icon_edge_150.png", + PKGDATADIR"/launcher_icon_edge_54.png"); + GenerateTextures(icon_glow, + PKGDATADIR"/launcher_icon_glow_200.png", + PKGDATADIR"/launcher_icon_glow_62.png"); + GenerateTextures(icon_shadow, + PKGDATADIR"/launcher_icon_shadow_200.png", + PKGDATADIR"/launcher_icon_shadow_62.png"); + GenerateTextures(icon_shine, + PKGDATADIR"/launcher_icon_shine_150.png", + PKGDATADIR"/launcher_icon_shine_54.png"); + + SetupShaders(); +} + +void IconRenderer::TexturesPool::SetupShaders() { if (nux::GetWindowThread()->GetGraphicsEngine().UsingGLSLCodePath()) { @@ -1181,107 +1238,5 @@ void setup_shaders() } } - -inline nux::BaseTexture* load_texture(const char* filename) -{ - return nux::CreateTexture2DFromFile(filename, -1, true); -} - -void generate_textures(std::vector& icons, const char* big_file, const char* small_file) -{ - icons.resize(IconSize::LAST); - icons[IconSize::BIG] = load_texture(big_file); - icons[IconSize::SMALL] = load_texture(small_file); -} - -void generate_textures() -{ - progress_bar_trough = load_texture(PKGDATADIR"/progress_bar_trough.png"); - progress_bar_fill = load_texture(PKGDATADIR"/progress_bar_fill.png"); - - generate_textures(icon_background, - PKGDATADIR"/launcher_icon_back_150.png", - PKGDATADIR"/launcher_icon_back_54.png"); - generate_textures(icon_selected_background, - PKGDATADIR"/launcher_icon_selected_back_150.png", - PKGDATADIR"/launcher_icon_back_54.png"); - generate_textures(icon_edge, - PKGDATADIR"/launcher_icon_edge_150.png", - PKGDATADIR"/launcher_icon_edge_54.png"); - generate_textures(icon_glow, - PKGDATADIR"/launcher_icon_glow_200.png", - PKGDATADIR"/launcher_icon_glow_62.png"); - generate_textures(icon_shadow, - PKGDATADIR"/launcher_icon_shadow_200.png", - PKGDATADIR"/launcher_icon_shadow_62.png"); - generate_textures(icon_shine, - PKGDATADIR"/launcher_icon_shine_150.png", - PKGDATADIR"/launcher_icon_shine_54.png"); - - // squircle_base = load_texture(PKGDATADIR"/squircle_base_54.png"); - // squircle_base_selected = load_texture(PKGDATADIR"/squircle_base_selected_54.png"); - // squircle_edge = load_texture(PKGDATADIR"/squircle_edge_54.png"); - // squircle_glow = load_texture(PKGDATADIR"/squircle_glow_62.png"); - // squircle_shadow = load_texture(PKGDATADIR"/squircle_shadow_62.png"); - // squircle_shine = load_texture(PKGDATADIR"/squircle_shine_54.png"); - - pip_ltr = load_texture(PKGDATADIR"/launcher_pip_ltr.png"); - arrow_ltr = load_texture(PKGDATADIR"/launcher_arrow_ltr.png"); - arrow_empty_ltr = load_texture(PKGDATADIR"/launcher_arrow_outline_ltr.png"); - - pip_rtl = load_texture(PKGDATADIR"/launcher_pip_rtl.png"); - arrow_rtl = load_texture(PKGDATADIR"/launcher_arrow_rtl.png"); - arrow_empty_rtl = load_texture(PKGDATADIR"/launcher_arrow_outline_rtl.png"); - - offscreen_progress_texture = nux::GetGraphicsDisplay()->GetGpuDevice() - ->CreateSystemCapableDeviceTexture(2, 2, 1, nux::BITFMT_R8G8B8A8); - - setup_shaders(); - textures_created = true; -} - -void destroy_textures(std::vector& icons) -{ - icons[SMALL]->UnReference(); - icons[BIG]->UnReference(); - icons.clear(); -} - -void destroy_textures() -{ - if (!textures_created) - return; - - progress_bar_trough->UnReference(); - progress_bar_fill->UnReference(); - pip_ltr->UnReference(); - pip_rtl->UnReference(); - arrow_ltr->UnReference(); - arrow_rtl->UnReference(); - arrow_empty_ltr->UnReference(); - arrow_empty_rtl->UnReference(); - - destroy_textures(icon_background); - destroy_textures(icon_selected_background); - destroy_textures(icon_edge); - destroy_textures(icon_glow); - destroy_textures(icon_shadow); - destroy_textures(icon_shine); - - // squircle_base->UnReference(); - // squircle_base_selected->UnReference(); - // squircle_edge->UnReference(); - // squircle_glow->UnReference(); - // squircle_shadow->UnReference(); - // squircle_shine->UnReference(); - - IconRenderer::DestroyShortcutTextures(); - - textures_created = false; -} - -} // anon namespace -} // namespace local - } // namespace ui } // namespace unity diff --git a/unity-shared/IconRenderer.h b/unity-shared/IconRenderer.h index e3e458bb5..9f6762d40 100644 --- a/unity-shared/IconRenderer.h +++ b/unity-shared/IconRenderer.h @@ -45,12 +45,9 @@ public: void SetTargetSize(int tile_size, int image_size, int spacing); - static void DestroyTextures(); static void DestroyShortcutTextures(); protected: - nux::BaseTexture* RenderCharToTexture(char label, int width, int height, nux::Color const& bg_color); - void RenderElement(nux::GraphicsEngine& GfxContext, RenderArg const& arg, nux::ObjectPtr const& icon, @@ -90,6 +87,8 @@ private: int image_size; int spacing; + struct TexturesPool; + static std::unique_ptr textures_; nux::Matrix4 _stored_projection_matrix; }; -- cgit v1.2.3 From 4f193ca6afbebdc437982ac363ab2999950b4079 Mon Sep 17 00:00:00 2001 From: "Stephen M. Webb" Date: Wed, 13 Mar 2013 11:02:59 -0400 Subject: Internationalized preview message (lp: #1106849). Fixes LP: #1106849 (bzr r3211.2.1) --- unity-shared/CoverArt.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/unity-shared/CoverArt.cpp b/unity-shared/CoverArt.cpp index 97375a6c2..c610aeeb0 100644 --- a/unity-shared/CoverArt.cpp +++ b/unity-shared/CoverArt.cpp @@ -20,6 +20,7 @@ * Nick Dedekind * */ +#include "config.h" #include "CoverArt.h" #include "unity-shared/IntrospectableWrappers.h" @@ -29,6 +30,7 @@ #include "DashStyle.h" #include "IconLoader.h" #include "PreviewStyle.h" +#include namespace unity { @@ -446,7 +448,7 @@ void CoverArt::SetupViews() overlay_text_->SetTextAlignment(StaticCairoText::NUX_ALIGN_CENTRE); overlay_text_->SetFont("Ubuntu 14"); overlay_text_->SetLines(-3); - overlay_text_->SetText("No Image Available"); + overlay_text_->SetText(_("No Image Available")); dash::Style& style = dash::Style::Instance(); spin_ = style.GetSearchSpinIcon(); -- cgit v1.2.3 From 2a3dbcd131c5eeb21e5c49925d8d25897dfbc180 Mon Sep 17 00:00:00 2001 From: "Stephen M. Webb" Date: Thu, 14 Mar 2013 09:58:33 -0400 Subject: Added AP test to verify no regressions with i18n (bzr r3211.2.2) --- tests/autopilot/unity/tests/test_dash.py | 6 ++++++ unity-shared/CoverArt.cpp | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/autopilot/unity/tests/test_dash.py b/tests/autopilot/unity/tests/test_dash.py index 26e092402..64d61d8b6 100644 --- a/tests/autopilot/unity/tests/test_dash.py +++ b/tests/autopilot/unity/tests/test_dash.py @@ -972,6 +972,12 @@ class PreviewNavigateTests(DashTestCase): self.assertThat(self.unity.dash.preview_displaying, Eventually(Equals(False))) + def test_overlay_text(self): + """Fallback overlay text is internationalized, should always be valid.""" + cover_art = self.get_current_preview().cover_art[0] + self.assertThat(cover_art.overlay_text, + Eventually(Equals("No Image Available"))) + class PreviewClickCancelTests(DashTestCase): """Tests that the preview closes when left, middle, and right clicking in the preview""" diff --git a/unity-shared/CoverArt.cpp b/unity-shared/CoverArt.cpp index c610aeeb0..23ef8ce44 100644 --- a/unity-shared/CoverArt.cpp +++ b/unity-shared/CoverArt.cpp @@ -85,7 +85,8 @@ void CoverArt::AddProperties(GVariantBuilder* builder) variant::BuilderWrapper(builder) .add(GetAbsoluteGeometry()) .add("image-hint", image_hint_) - .add("waiting", waiting_); + .add("waiting", waiting_) + .add("overlay-text", overlay_text_->GetText()); } void CoverArt::SetImage(std::string const& image_hint) -- cgit v1.2.3 From 4bb11154e5a64c1ad7e143e70431ba2009b6874f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 14 Mar 2013 17:42:39 +0100 Subject: ApplicationLauncherIcon: On quicklist activate pass the timestamp to the lambda by value Also, use the correct signature on quicklist activate callback (bzr r3212.2.3) --- launcher/ApplicationLauncherIcon.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/launcher/ApplicationLauncherIcon.cpp b/launcher/ApplicationLauncherIcon.cpp index cf1697613..add83c94d 100644 --- a/launcher/ApplicationLauncherIcon.cpp +++ b/launcher/ApplicationLauncherIcon.cpp @@ -729,8 +729,8 @@ void ApplicationLauncherIcon::EnsureMenuItemsWindowsReady() dbusmenu_menuitem_property_set_int(menu_item, QuicklistMenuItem::MAXIMUM_LABEL_WIDTH_PROPERTY, MAXIMUM_QUICKLIST_WIDTH); Window xid = w->window_id(); - _gsignals.Add(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - [xid] (DbusmenuMenuitem*, int) { + _gsignals.Add(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + [xid] (DbusmenuMenuitem*, unsigned) { WindowManager& wm = WindowManager::Default(); wm.Activate(xid); wm.Raise(xid); @@ -821,8 +821,8 @@ void ApplicationLauncherIcon::EnsureMenuItemsReady() dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true); dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true); - _gsignals.Add(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - [&] (DbusmenuMenuitem*, int) { + _gsignals.Add(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + [&] (DbusmenuMenuitem*, unsigned) { ToggleSticky(); }); @@ -945,9 +945,9 @@ AbstractLauncherIcon::MenuItemsVector ApplicationLauncherIcon::GetMenus() dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); dbusmenu_menuitem_property_set_bool(item, QuicklistMenuItem::MARKUP_ENABLED_PROPERTY, TRUE); - _gsignals.Add(item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - [&] (DbusmenuMenuitem*, int timestamp) { - _source_manager.AddIdle([&] { + _gsignals.Add(item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + [&] (DbusmenuMenuitem*, unsigned timestamp) { + _source_manager.AddIdle([this, timestamp] { ActivateLauncherIcon(ActionArg(ActionArg::Source::LAUNCHER, 0, timestamp)); return false; }); -- cgit v1.2.3 From c1e66e976edb6c64cc6e3ae3518c22167f8666f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 14 Mar 2013 17:44:00 +0100 Subject: TestApplicationLauncherIcon: use mock icons (bzr r3212.2.4) --- tests/test_application_launcher_icon.cpp | 34 +++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/tests/test_application_launcher_icon.cpp b/tests/test_application_launcher_icon.cpp index ed8ff310e..56dfaab57 100644 --- a/tests/test_application_launcher_icon.cpp +++ b/tests/test_application_launcher_icon.cpp @@ -30,9 +30,11 @@ #include "StandaloneWindowManager.h" #include "mock-application.h" #include "StandaloneWindowManager.h" +#include "test_utils.h" -using namespace unity; +using namespace testing; using namespace testmocks; +using namespace unity; using namespace unity::launcher; namespace @@ -41,22 +43,30 @@ const std::string DEFAULT_EMPTY_ICON = "application-default-icon"; const std::string USC_DESKTOP = BUILDDIR"/tests/data/applications/ubuntu-software-center.desktop"; const std::string NO_ICON_DESKTOP = BUILDDIR"/tests/data/applications/no-icon.desktop"; -class TestApplicationLauncherIcon : public testing::Test +struct MockApplicationLauncherIcon : ApplicationLauncherIcon +{ + MockApplicationLauncherIcon(ApplicationPtr const& app) + : ApplicationLauncherIcon(app) + {} + + MOCK_METHOD1(ActivateLauncherIcon, void(ActionArg)); +}; + +struct TestApplicationLauncherIcon : Test { -public: virtual void SetUp() { WM = dynamic_cast(&WindowManager::Default()); - usc_app.reset(new MockApplication(USC_DESKTOP, "softwarecenter")); - usc_icon = new launcher::ApplicationLauncherIcon(usc_app); + usc_app = std::make_shared(USC_DESKTOP, "softwarecenter"); + usc_icon = new NiceMock(usc_app); ASSERT_EQ(usc_icon->DesktopFile(), USC_DESKTOP); - empty_app.reset(new MockApplication(NO_ICON_DESKTOP)); - empty_icon = new launcher::ApplicationLauncherIcon(empty_app); + empty_app = std::make_shared(NO_ICON_DESKTOP); + empty_icon = new NiceMock(empty_app); ASSERT_EQ(empty_icon->DesktopFile(), NO_ICON_DESKTOP); - mock_app.reset(new MockApplication("")); - mock_icon = new launcher::ApplicationLauncherIcon(mock_app); + mock_app = std::make_shared(""); + mock_icon = new NiceMock(mock_app); ASSERT_TRUE(mock_icon->DesktopFile().empty()); } @@ -76,9 +86,9 @@ public: std::shared_ptr usc_app; std::shared_ptr empty_app; std::shared_ptr mock_app; - nux::ObjectPtr usc_icon; - nux::ObjectPtr empty_icon; - nux::ObjectPtr mock_icon; + nux::ObjectPtr usc_icon; + nux::ObjectPtr empty_icon; + nux::ObjectPtr mock_icon; }; TEST_F(TestApplicationLauncherIcon, Position) -- cgit v1.2.3 From bab0d4ea25970bca738c110b093775acedcce197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 14 Mar 2013 17:44:51 +0100 Subject: TestApplicationLauncherIcon: add test to check the app quicklist menuitem behavior (bzr r3212.2.5) --- tests/test_application_launcher_icon.cpp | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/test_application_launcher_icon.cpp b/tests/test_application_launcher_icon.cpp index 56dfaab57..d1fc452b1 100644 --- a/tests/test_application_launcher_icon.cpp +++ b/tests/test_application_launcher_icon.cpp @@ -52,6 +52,15 @@ struct MockApplicationLauncherIcon : ApplicationLauncherIcon MOCK_METHOD1(ActivateLauncherIcon, void(ActionArg)); }; +MATCHER_P(AreArgsEqual, a, "") +{ + return arg.source == a.source && + arg.button == a.button && + arg.timestamp == a.timestamp && + arg.target == a.target; + arg.monitor = a.monitor; +} + struct TestApplicationLauncherIcon : Test { virtual void SetUp() @@ -453,4 +462,29 @@ TEST_F(TestApplicationLauncherIcon, WindowListMenusWithEmptyTitles) ASSERT_EQ(menu1_it, menus.end()); } +TEST_F(TestApplicationLauncherIcon, QuicklistMenuItemForAppName) +{ + mock_app->title_ = "MockApplicationTitle"; + + auto const& menus = mock_icon->Menus(); + auto app_it = std::find_if(menus.begin(), menus.end(), [this] (glib::Object it) { + auto* label = dbusmenu_menuitem_property_get(it, DBUSMENU_MENUITEM_PROP_LABEL); + return (label && std::string(label) == (""+mock_app->title_+"")); + }); + + ASSERT_NE(app_it, menus.end()); + + bool method_called = false; + ON_CALL(*mock_icon, ActivateLauncherIcon(_)).WillByDefault(Invoke([&method_called] (ActionArg arg) { + method_called = true; + })); + + unsigned time = g_random_int(); + EXPECT_CALL(*mock_icon, ActivateLauncherIcon(AreArgsEqual(ActionArg(ActionArg::Source::LAUNCHER, 0, time)))); + dbusmenu_menuitem_handle_event(*app_it, DBUSMENU_MENUITEM_EVENT_ACTIVATED, nullptr, time); + + Utils::WaitUntilMSec(method_called); + EXPECT_TRUE(method_called); +} + } -- cgit v1.2.3 From 2722d4e113d4d2e7f41be6a01e948170beb40f77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 14 Mar 2013 17:45:19 +0100 Subject: ApplicationStarterImp: timestamp can't be negative (bzr r3212.2.6) --- dash/ApplicationStarterImp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dash/ApplicationStarterImp.cpp b/dash/ApplicationStarterImp.cpp index bdc75aab4..021649109 100644 --- a/dash/ApplicationStarterImp.cpp +++ b/dash/ApplicationStarterImp.cpp @@ -37,7 +37,7 @@ bool ApplicationStarterImp::Launch(std::string const& application_name, Time tim GdkDisplay* display = gdk_display_get_default(); glib::Object app_launch_context(gdk_display_get_app_launch_context(display)); - if (timestamp >= 0) + if (timestamp > 0) gdk_app_launch_context_set_timestamp(app_launch_context, timestamp); while (true) -- cgit v1.2.3 From 98c56ab724750d9e8e42a321b0d0ca4bc6d73f6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 14 Mar 2013 18:33:04 +0100 Subject: ApplicationLauncherIcon: lambda functions syntax cleanup Use [this] instead of [&] and remove unneeded indentation (bzr r3212.2.7) --- launcher/ApplicationLauncherIcon.cpp | 188 +++++++++++++++++------------------ 1 file changed, 93 insertions(+), 95 deletions(-) diff --git a/launcher/ApplicationLauncherIcon.cpp b/launcher/ApplicationLauncherIcon.cpp index add83c94d..dff816e67 100644 --- a/launcher/ApplicationLauncherIcon.cpp +++ b/launcher/ApplicationLauncherIcon.cpp @@ -90,68 +90,68 @@ ApplicationLauncherIcon::ApplicationLauncherIcon(ApplicationPtr const& app) // Lambda functions should be fine here because when the application the icon // is only ever removed when the application is closed. app->window_opened.connect([this](ApplicationWindow const&) { - EnsureWindowState(); - UpdateMenus(); - UpdateIconGeometries(GetCenters()); - }); - app->window_closed.connect([this]() { EnsureWindowState(); }); - app->window_moved.connect([this](ApplicationWindow const&) { EnsureWindowState(); }); + EnsureWindowState(); + UpdateMenus(); + UpdateIconGeometries(GetCenters()); + }); + app->window_closed.connect(sigc::mem_fun(this, &ApplicationLauncherIcon::EnsureWindowState)); + app->window_moved.connect(sigc::hide(sigc::mem_fun(this, &ApplicationLauncherIcon::EnsureWindowState))); app->urgent.changed.connect([this](bool const& urgent) { - LOG_DEBUG(logger) << tooltip_text() << " urgent now " << (urgent ? "true" : "false"); - SetQuirk(Quirk::URGENT, urgent); - }); + LOG_DEBUG(logger) << tooltip_text() << " urgent now " << (urgent ? "true" : "false"); + SetQuirk(Quirk::URGENT, urgent); + }); app->active.changed.connect([this](bool const& active) { - LOG_DEBUG(logger) << tooltip_text() << " active now " << (active ? "true" : "false"); - SetQuirk(Quirk::ACTIVE, active); - }); + LOG_DEBUG(logger) << tooltip_text() << " active now " << (active ? "true" : "false"); + SetQuirk(Quirk::ACTIVE, active); + }); app->running.changed.connect([this](bool const& running) { - LOG_DEBUG(logger) << tooltip_text() << " running now " << (running ? "true" : "false"); - SetQuirk(Quirk::RUNNING, running); - - if (running) - { - _source_manager.Remove(ICON_REMOVE_TIMEOUT); - - /* It can happen that these values are not set - * during initialization if the view is closed - * very early, so we need to make sure that they - * are updated as soon as the view is re-opened. */ - if (tooltip_text().empty()) - tooltip_text = app_->title(); - - if (icon_name == DEFAULT_ICON) - { - std::string icon = app_->icon(); - icon_name = (icon.empty() ? DEFAULT_ICON : icon); - } - - EnsureWindowState(); - UpdateIconGeometries(GetCenters()); - } - }); + LOG_DEBUG(logger) << tooltip_text() << " running now " << (running ? "true" : "false"); + SetQuirk(Quirk::RUNNING, running); + + if (running) + { + _source_manager.Remove(ICON_REMOVE_TIMEOUT); + + /* It can happen that these values are not set + * during initialization if the view is closed + * very early, so we need to make sure that they + * are updated as soon as the view is re-opened. */ + if (tooltip_text().empty()) + tooltip_text = app_->title(); + + if (icon_name == DEFAULT_ICON) + { + std::string icon = app_->icon(); + icon_name = (icon.empty() ? DEFAULT_ICON : icon); + } + + EnsureWindowState(); + UpdateIconGeometries(GetCenters()); + } + }); app->visible.changed.connect([this](bool const& visible) { - if (!IsSticky()) - SetQuirk(Quirk::VISIBLE, visible); - }); + if (!IsSticky()) + SetQuirk(Quirk::VISIBLE, visible); + }); app->closed.connect([this]() { - if (!IsSticky()) - { - SetQuirk(Quirk::VISIBLE, false); - - /* Use a timeout to remove the icon, this avoids - * that we remove an application that is going - * to be reopened soon. So applications that - * have a splash screen won't be removed from - * the launcher while the splash is closed and - * a new window is opened. */ - _source_manager.AddTimeoutSeconds(1, [&] { - Remove(); - return false; - }, ICON_REMOVE_TIMEOUT); - } - }); + if (!IsSticky()) + { + SetQuirk(Quirk::VISIBLE, false); + + /* Use a timeout to remove the icon, this avoids + * that we remove an application that is going + * to be reopened soon. So applications that + * have a splash screen won't be removed from + * the launcher while the splash is closed and + * a new window is opened. */ + _source_manager.AddTimeoutSeconds(1, [this] { + Remove(); + return false; + }, ICON_REMOVE_TIMEOUT); + } + }); WindowManager& wm = WindowManager::Default(); wm.window_minimized.connect(sigc::mem_fun(this, &ApplicationLauncherIcon::OnWindowMinimized)); @@ -443,7 +443,7 @@ void ApplicationLauncherIcon::OnWindowMoved(guint32 moved_win) if (!app_->OwnsWindow(moved_win)) return; - _source_manager.AddTimeout(250, [&] { + _source_manager.AddTimeout(250, [this] { EnsureWindowState(); UpdateIconGeometries(GetCenters()); @@ -468,31 +468,32 @@ void ApplicationLauncherIcon::UpdateDesktopFile() glib::Object desktop_file(g_file_new_for_path(_desktop_file.c_str())); _desktop_file_monitor = g_file_monitor_file(desktop_file, G_FILE_MONITOR_NONE, nullptr, nullptr); - g_file_monitor_set_rate_limit(_desktop_file_monitor, 1000); - - auto sig = new glib::Signal(_desktop_file_monitor, "changed", - [&] (GFileMonitor*, GFile* f, GFile*, GFileMonitorEvent event_type) { - switch (event_type) - { - case G_FILE_MONITOR_EVENT_DELETED: - { - glib::Object file(f, glib::AddRef()); - _source_manager.AddTimeoutSeconds(1, [this, file] { - if (!g_file_query_exists (file, nullptr)) - UnStick(); - return false; - }); - break; - } - case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT: - UpdateDesktopQuickList(); - UpdateBackgroundColor(); - break; - default: - break; - } - }); - _gsignals.Add(sig); + g_file_monitor_set_rate_limit(_desktop_file_monitor, 2000); + + _gsignals.Add(_desktop_file_monitor, "changed", + [this] (GFileMonitor*, GFile* f, GFile*, GFileMonitorEvent event_type) { + switch (event_type) + { + case G_FILE_MONITOR_EVENT_DELETED: + { + glib::Object file(f, glib::AddRef()); + _source_manager.AddTimeoutSeconds(1, [this, file] { + if (!g_file_query_exists (file, nullptr)) + UnStick(); + return false; + }); + break; + } + case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT: + { + UpdateDesktopQuickList(); + UpdateBackgroundColor(); + break; + } + default: + break; + } + }); } } @@ -645,7 +646,7 @@ void ApplicationLauncherIcon::UpdateDesktopQuickList() { for (GList *l = dbusmenu_menuitem_get_children(_menu_desktop_shortcuts); l; l = l->next) { - _gsignals.Disconnect(l->data, "item-activated"); + _gsignals.Disconnect(l->data, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED); } } @@ -672,15 +673,12 @@ void ApplicationLauncherIcon::UpdateDesktopQuickList() dbusmenu_menuitem_property_set(item, DBUSMENU_MENUITEM_PROP_LABEL, name); dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_ENABLED, TRUE); dbusmenu_menuitem_property_set_bool(item, DBUSMENU_MENUITEM_PROP_VISIBLE, TRUE); - dbusmenu_menuitem_property_set(item, "shortcut-nick", nicks[index]); + std::string nick(nicks[index]); - auto sig = new glib::Signal(item, "item-activated", - [&] (DbusmenuMenuitem* item, gint) { - const gchar *nick; - nick = dbusmenu_menuitem_property_get(item, "shortcut-nick"); - indicator_desktop_shortcuts_nick_exec(_desktop_shortcuts, nick); - }); - _gsignals.Add(sig); + _gsignals.Add(item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + [this, nick] (DbusmenuMenuitem* item, unsigned) { + indicator_desktop_shortcuts_nick_exec(_desktop_shortcuts, nick.c_str()); + }); dbusmenu_menuitem_child_append(_menu_desktop_shortcuts, item); index++; @@ -822,7 +820,7 @@ void ApplicationLauncherIcon::EnsureMenuItemsReady() dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true); _gsignals.Add(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - [&] (DbusmenuMenuitem*, unsigned) { + [this] (DbusmenuMenuitem*, unsigned) { ToggleSticky(); }); @@ -842,8 +840,8 @@ void ApplicationLauncherIcon::EnsureMenuItemsReady() dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_ENABLED, true); dbusmenu_menuitem_property_set_bool(menu_item, DBUSMENU_MENUITEM_PROP_VISIBLE, true); - _gsignals.Add(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - [&] (DbusmenuMenuitem*, int) { + _gsignals.Add(menu_item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + [this] (DbusmenuMenuitem*, unsigned) { Quit(); }); @@ -946,7 +944,7 @@ AbstractLauncherIcon::MenuItemsVector ApplicationLauncherIcon::GetMenus() dbusmenu_menuitem_property_set_bool(item, QuicklistMenuItem::MARKUP_ENABLED_PROPERTY, TRUE); _gsignals.Add(item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, - [&] (DbusmenuMenuitem*, unsigned timestamp) { + [this] (DbusmenuMenuitem*, unsigned timestamp) { _source_manager.AddIdle([this, timestamp] { ActivateLauncherIcon(ActionArg(ActionArg::Source::LAUNCHER, 0, timestamp)); return false; @@ -1102,7 +1100,7 @@ void ApplicationLauncherIcon::OnDndHovered() void ApplicationLauncherIcon::OnDndEnter() { /* Disabled, since the DND code is currently disabled as well. - _source_manager.AddTimeout(1000, [&] { + _source_manager.AddTimeout(1000, [this] { OnDndHovered(); return false; }, ICON_DND_OVER_TIMEOUT); -- cgit v1.2.3 From 75be5d30b56cc1330e41ef2271945227ab1e091f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 14 Mar 2013 19:55:36 +0100 Subject: AbstractLauncherIcon: use struct and enum class for ActionArg, avoid negative Time Adapt code, and clean it up (bzr r3212.2.8) --- dash/DashView.cpp | 2 +- dash/DashView.h | 2 +- dash/ResultViewGrid.cpp | 4 ++-- hud/HudController.cpp | 4 ++-- launcher/AbstractLauncherIcon.h | 18 ++++++++---------- launcher/ApplicationLauncherIcon.cpp | 12 ++++++------ launcher/Launcher.cpp | 2 +- launcher/LauncherController.cpp | 12 ++++++------ launcher/LauncherIcon.cpp | 4 ++-- launcher/SwitcherController.cpp | 4 ++-- .../unityshell/src/unity-launcher-icon-accessible.cpp | 2 +- 11 files changed, 32 insertions(+), 34 deletions(-) diff --git a/dash/DashView.cpp b/dash/DashView.cpp index 17af8d43e..f265d5864 100644 --- a/dash/DashView.cpp +++ b/dash/DashView.cpp @@ -200,7 +200,7 @@ void DashView::OnUriActivated(ResultView::ActivateType type, std::string const& int row_height = 0; int results_to_the_left = 0; int results_to_the_right = 0; - g_variant_get(data, "(iiiiiii)", &last_activated_timestamp_, &column_x, &row_y, &column_width, &row_height, &results_to_the_left, &results_to_the_right); + g_variant_get(data, "(tiiiiii)", &last_activated_timestamp_, &column_x, &row_y, &column_width, &row_height, &results_to_the_left, &results_to_the_right); preview_state_machine_.SetSplitPosition(SplitPosition::CONTENT_AREA, row_y); preview_state_machine_.left_results = results_to_the_left; diff --git a/dash/DashView.h b/dash/DashView.h index 37c06bfed..eb929f706 100644 --- a/dash/DashView.h +++ b/dash/DashView.h @@ -162,7 +162,7 @@ private: OverlayRenderer renderer_; std::string last_activated_uri_; - Time last_activated_timestamp_; + guint64 last_activated_timestamp_; bool search_in_progress_; bool activate_on_finish_; diff --git a/dash/ResultViewGrid.cpp b/dash/ResultViewGrid.cpp index 4f52952d5..fa8924811 100644 --- a/dash/ResultViewGrid.cpp +++ b/dash/ResultViewGrid.cpp @@ -208,8 +208,8 @@ void ResultViewGrid::Activate(std::string const& uri, int index, ResultView::Act } active_index_ = index; - auto timestamp = nux::GetWindowThread()->GetGraphicsDisplay().GetCurrentEvent().x11_timestamp; - glib::Variant data(g_variant_new("(iiiiiii)", timestamp, column_x, row_y, column_width, row_height, left_results, right_results)); + unsigned long timestamp = nux::GetGraphicsDisplay()->GetCurrentEvent().x11_timestamp; + glib::Variant data(g_variant_new("(tiiiiii)", timestamp, column_x, row_y, column_width, row_height, left_results, right_results)); UriActivated.emit(uri, type, data); } diff --git a/hud/HudController.cpp b/hud/HudController.cpp index f8687a367..c6f5d5ddc 100644 --- a/hud/HudController.cpp +++ b/hud/HudController.cpp @@ -484,7 +484,7 @@ void Controller::OnSearchChanged(std::string search_string) void Controller::OnSearchActivated(std::string search_string) { - unsigned int timestamp = nux::GetWindowThread()->GetGraphicsDisplay().GetCurrentEvent().x11_timestamp; + unsigned int timestamp = nux::GetGraphicsDisplay()->GetCurrentEvent().x11_timestamp; hud_service_.ExecuteQueryBySearch(search_string, timestamp); ubus.SendMessage(UBUS_HUD_CLOSE_REQUEST); } @@ -492,7 +492,7 @@ void Controller::OnSearchActivated(std::string search_string) void Controller::OnQueryActivated(Query::Ptr query) { LOG_DEBUG(logger) << "Activating query, " << query->formatted_text; - unsigned int timestamp = nux::GetWindowThread()->GetGraphicsDisplay().GetCurrentEvent().x11_timestamp; + unsigned int timestamp = nux::GetGraphicsDisplay()->GetCurrentEvent().x11_timestamp; hud_service_.ExecuteQuery(query, timestamp); ubus.SendMessage(UBUS_HUD_CLOSE_REQUEST); } diff --git a/launcher/AbstractLauncherIcon.h b/launcher/AbstractLauncherIcon.h index 7bf6e1ee5..859ab56ba 100644 --- a/launcher/AbstractLauncherIcon.h +++ b/launcher/AbstractLauncherIcon.h @@ -41,10 +41,9 @@ namespace unity namespace launcher { -class ActionArg +struct ActionArg { -public: - enum Source + enum class Source { LAUNCHER, SWITCHER, @@ -52,25 +51,24 @@ public: }; ActionArg() - : source(OTHER) + : source(Source::OTHER) , button(0) + , timestamp(0) , target(0) , monitor(-1) - { - } + {} - ActionArg(Source source, int button, Time timestamp = -1, Window target = 0, int monitor = -1) + ActionArg(Source source, int button, unsigned long timestamp = 0, Window target = 0, int monitor = -1) : source(source) , button(button) , timestamp(timestamp) , target(target) , monitor(monitor) - { - } + {} Source source; int button; - Time timestamp; + unsigned long timestamp; Window target; int monitor; }; diff --git a/launcher/ApplicationLauncherIcon.cpp b/launcher/ApplicationLauncherIcon.cpp index dff816e67..2e0e70691 100644 --- a/launcher/ApplicationLauncherIcon.cpp +++ b/launcher/ApplicationLauncherIcon.cpp @@ -262,7 +262,7 @@ void ApplicationLauncherIcon::ActivateLauncherIcon(ActionArg arg) * an unmapped (!= minimized) window around and * if so force "Focus" behaviour */ - if (arg.source != ActionArg::SWITCHER) + if (arg.source != ActionArg::Source::SWITCHER) { user_visible = app_->visible(); @@ -339,7 +339,7 @@ void ApplicationLauncherIcon::ActivateLauncherIcon(ActionArg arg) } else // #2 above { - if (arg.source != ActionArg::SWITCHER) + if (arg.source != ActionArg::Source::SWITCHER) { Spread(true, 0, false); } @@ -350,7 +350,7 @@ void ApplicationLauncherIcon::ActivateLauncherIcon(ActionArg arg) if (scaleWasActive) // #4 above { Focus(arg); - if (arg.source != ActionArg::SWITCHER) + if (arg.source != ActionArg::Source::SWITCHER) Spread(true, 0, false); } else // #3 above @@ -592,7 +592,7 @@ void ApplicationLauncherIcon::Focus(ActionArg arg) return; } - bool show_only_visible = arg.source == ActionArg::SWITCHER; + bool show_only_visible = arg.source == ActionArg::Source::SWITCHER; app_->Focus(show_only_visible, arg.monitor); } @@ -1150,7 +1150,7 @@ nux::DndAction ApplicationLauncherIcon::OnQueryAcceptDrop(DndData const& dnd_dat void ApplicationLauncherIcon::OnAcceptDrop(DndData const& dnd_data) { - auto timestamp = nux::GetWindowThread()->GetGraphicsDisplay().GetCurrentEvent().x11_timestamp; + auto timestamp = nux::GetGraphicsDisplay()->GetCurrentEvent().x11_timestamp; OpenInstanceWithUris(ValidateUrisForLaunch(dnd_data), timestamp); } @@ -1167,7 +1167,7 @@ bool ApplicationLauncherIcon::ShowInSwitcher(bool current) } else { - for (int i = 0; i < max_num_monitors; i++) + for (int i = 0; i < max_num_monitors; ++i) { if (WindowVisibleOnMonitor(i)) { diff --git a/launcher/Launcher.cpp b/launcher/Launcher.cpp index d55d91275..8698f78a1 100644 --- a/launcher/Launcher.cpp +++ b/launcher/Launcher.cpp @@ -2249,7 +2249,7 @@ void Launcher::RecvMouseWheel(int /*x*/, int /*y*/, int wheel_delta, unsigned lo } else if (_icon_under_mouse) { - auto timestamp = nux::GetWindowThread()->GetGraphicsDisplay().GetCurrentEvent().x11_timestamp; + auto timestamp = nux::GetGraphicsDisplay()->GetCurrentEvent().x11_timestamp; auto scroll_direction = (wheel_delta < 0) ? AbstractLauncherIcon::ScrollDirection::DOWN : AbstractLauncherIcon::ScrollDirection::UP; _icon_under_mouse->PerformScroll(scroll_direction, timestamp); } diff --git a/launcher/LauncherController.cpp b/launcher/LauncherController.cpp index 25da39a3a..eef602458 100644 --- a/launcher/LauncherController.cpp +++ b/launcher/LauncherController.cpp @@ -1262,9 +1262,9 @@ bool Controller::HandleLauncherKeyEvent(Display *display, unsigned int key_sym, if (TimeUtil::TimeDelta(¤t, &last_action_time) > local::ignore_repeat_shortcut_duration) { if (g_ascii_isdigit((gchar)(*it)->GetShortcut()) && (key_state & ShiftMask)) - (*it)->OpenInstance(ActionArg(ActionArg::LAUNCHER, 0, timestamp)); + (*it)->OpenInstance(ActionArg(ActionArg::Source::LAUNCHER, 0, timestamp)); else - (*it)->Activate(ActionArg(ActionArg::LAUNCHER, 0, timestamp)); + (*it)->Activate(ActionArg(ActionArg::Source::LAUNCHER, 0, timestamp)); } // disable the "tap on super" check @@ -1384,10 +1384,10 @@ void Controller::KeyNavTerminate(bool activate) if (activate) { - auto timestamp = nux::GetWindowThread()->GetGraphicsDisplay().GetCurrentEvent().x11_timestamp; + auto timestamp = nux::GetGraphicsDisplay()->GetCurrentEvent().x11_timestamp; pimpl->sources_.AddIdle([this, timestamp] { - pimpl->model_->Selection()->Activate(ActionArg(ActionArg::LAUNCHER, 0, timestamp)); + pimpl->model_->Selection()->Activate(ActionArg(ActionArg::Source::LAUNCHER, 0, timestamp)); return false; }); } @@ -1488,8 +1488,8 @@ void Controller::Impl::ReceiveLauncherKeyPress(unsigned long eventType, // (open a new instance) case NUX_VK_SPACE: { - auto timestamp = nux::GetWindowThread()->GetGraphicsDisplay().GetCurrentEvent().x11_timestamp; - model_->Selection()->OpenInstance(ActionArg(ActionArg::LAUNCHER, 0, timestamp)); + auto timestamp = nux::GetGraphicsDisplay()->GetCurrentEvent().x11_timestamp; + model_->Selection()->OpenInstance(ActionArg(ActionArg::Source::LAUNCHER, 0, timestamp)); parent_->KeyNavTerminate(false); break; } diff --git a/launcher/LauncherIcon.cpp b/launcher/LauncherIcon.cpp index 927df2763..28d2a668a 100644 --- a/launcher/LauncherIcon.cpp +++ b/launcher/LauncherIcon.cpp @@ -651,9 +651,9 @@ void LauncherIcon::RecvMouseUp(int button, int monitor, unsigned long key_flags) void LauncherIcon::RecvMouseClick(int button, int monitor, unsigned long key_flags) { - auto timestamp = nux::GetWindowThread()->GetGraphicsDisplay().GetCurrentEvent().x11_timestamp; + auto timestamp = nux::GetGraphicsDisplay()->GetCurrentEvent().x11_timestamp; - ActionArg arg(ActionArg::LAUNCHER, button, timestamp); + ActionArg arg(ActionArg::Source::LAUNCHER, button, timestamp); arg.monitor = monitor; bool shift_pressed = nux::GetKeyModifierState(key_flags, nux::NUX_STATE_SHIFT); diff --git a/launcher/SwitcherController.cpp b/launcher/SwitcherController.cpp index 89922e006..bd48fb74f 100644 --- a/launcher/SwitcherController.cpp +++ b/launcher/SwitcherController.cpp @@ -426,8 +426,8 @@ void Controller::Impl::Hide(bool accept_state) Selection selection = GetCurrentSelection(); if (selection.application_) { - Time timestamp = -1; - selection.application_->Activate(ActionArg(ActionArg::SWITCHER, 0, + Time timestamp = 0; + selection.application_->Activate(ActionArg(ActionArg::Source::SWITCHER, 0, timestamp, selection.window_)); } } diff --git a/plugins/unityshell/src/unity-launcher-icon-accessible.cpp b/plugins/unityshell/src/unity-launcher-icon-accessible.cpp index b0331eb00..66643eadf 100644 --- a/plugins/unityshell/src/unity-launcher-icon-accessible.cpp +++ b/plugins/unityshell/src/unity-launcher-icon-accessible.cpp @@ -465,7 +465,7 @@ unity_launcher_icon_accessible_do_action(AtkAction *action, icon = dynamic_cast(nux_object); - icon->Activate(ActionArg(ActionArg::LAUNCHER, 0)); + icon->Activate(ActionArg(ActionArg::Source::LAUNCHER, 0)); return TRUE; } -- cgit v1.2.3 From c77169f2ff6542cb5206f306ef5a37afe13654ab Mon Sep 17 00:00:00 2001 From: Andrea Azzarone Date: Thu, 14 Mar 2013 20:50:16 +0100 Subject: Fix lp bu 1125346. (bzr r3215.1.1) --- dash/DashView.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dash/DashView.cpp b/dash/DashView.cpp index 17af8d43e..609b2eb30 100644 --- a/dash/DashView.cpp +++ b/dash/DashView.cpp @@ -703,7 +703,10 @@ void DashView::DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw renderer_.DrawInner(graphics_engine, content_geo_, renderer_geo_abs, renderer_geo); nux::Geometry const& geo_layout(layout_->GetGeometry()); - graphics_engine.PushClippingRectangle(geo_layout); + + nux::Geometry clip_geo = geo_layout; + clip_geo.x += 1; + graphics_engine.PushClippingRectangle(clip_geo); if (IsFullRedraw()) { -- cgit v1.2.3 From 8b175e4be21be949ecafd7504353fd5391259959 Mon Sep 17 00:00:00 2001 From: Andrea Azzarone Date: Thu, 14 Mar 2013 21:19:06 +0100 Subject: Add comment. (bzr r3215.1.2) --- dash/DashView.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/dash/DashView.cpp b/dash/DashView.cpp index 609b2eb30..07c7c2510 100644 --- a/dash/DashView.cpp +++ b/dash/DashView.cpp @@ -704,6 +704,7 @@ void DashView::DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw nux::Geometry const& geo_layout(layout_->GetGeometry()); + // See lp bug: 1125346 (The sharp white line between dash and launcher is missing) nux::Geometry clip_geo = geo_layout; clip_geo.x += 1; graphics_engine.PushClippingRectangle(clip_geo); -- cgit v1.2.3 From 05c171e3e40258e280b6caf266e9d3ec1b4b58fc Mon Sep 17 00:00:00 2001 From: Brandon Schaefer Date: Thu, 14 Mar 2013 17:47:00 -0700 Subject: * Mouse will not accept input unless a mouse is moving in the HudView now. Fixes LP: #1066442 (bzr r3215.2.2) --- hud/HudView.cpp | 21 +++++++++++++-------- tests/autopilot/unity/tests/test_hud.py | 11 +++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/hud/HudView.cpp b/hud/HudView.cpp index a79a0dc40..1fd883b19 100644 --- a/hud/HudView.cpp +++ b/hud/HudView.cpp @@ -114,6 +114,11 @@ View::View() } }); + mouse_move.connect([this] (int x, int y, int dx, int dy, unsigned long mouse_button, unsigned long special_key) { + for (auto button : buttons_) + button->SetInputEventSensitivity(true); + }); + mouse_down.connect(sigc::mem_fun(this, &View::OnMouseButtonDown)); Relayout(); @@ -181,7 +186,6 @@ void View::ProcessGrowShrink() button->SetSkipDraw((button->GetAbsoluteY() + button->GetBaseHeight()) > (GetAbsoluteY() + current_height_)); } - void View::ResetToDefault() { SetQueries(Hud::Queries()); @@ -240,7 +244,7 @@ void View::SetQueries(Hud::Queries queries) query_activated.emit(dynamic_cast(view)->GetQuery()); }); - button->mouse_move.connect([&](int x, int y, int dx, int dy, unsigned long mouse_button, unsigned long special_key) { + button->mouse_move.connect([this](int x, int y, int dx, int dy, unsigned long mouse_button, unsigned long special_key) { if (keyboard_stole_focus_) { MouseStealsHudButtonFocus(); @@ -248,19 +252,19 @@ void View::SetQueries(Hud::Queries queries) } }); - button->mouse_enter.connect([&](int x, int y, unsigned long mouse_button, unsigned long special_key) { + button->mouse_enter.connect([this](int x, int y, unsigned long mouse_button, unsigned long special_key) { MouseStealsHudButtonFocus(); }); - button->mouse_leave.connect([&](int x, int y, unsigned long mouse_button, unsigned long special_key) { + button->mouse_leave.connect([this](int x, int y, unsigned long mouse_button, unsigned long special_key) { SelectLastFocusedButton(); }); - button->key_nav_focus_activate.connect([&](nux::Area* area) { + button->key_nav_focus_activate.connect([this](nux::Area* area) { query_activated.emit(dynamic_cast(area)->GetQuery()); }); - button->key_nav_focus_change.connect([&](nux::Area* area, bool recieving, nux::KeyNavDirection direction){ + button->key_nav_focus_change.connect([this](nux::Area* area, bool recieving, nux::KeyNavDirection direction){ if (recieving) query_selected.emit(dynamic_cast(area)->GetQuery()); }); @@ -416,9 +420,7 @@ void View::OnSearchChanged(std::string const& search_string) search_changed.emit(search_string); for(auto button : buttons_) - { button->fake_focused = false; - } if (!buttons_.empty()) buttons_.back()->fake_focused = true; @@ -592,6 +594,9 @@ bool View::InspectKeyEvent(unsigned int eventType, void View::SearchFinished() { + for (auto button : buttons_) + button->SetInputEventSensitivity(false); + search_bar_->SearchFinished(); } diff --git a/tests/autopilot/unity/tests/test_hud.py b/tests/autopilot/unity/tests/test_hud.py index 97938b9d9..bc040a1ed 100644 --- a/tests/autopilot/unity/tests/test_hud.py +++ b/tests/autopilot/unity/tests/test_hud.py @@ -459,6 +459,17 @@ class HudBehaviorTests(HudTestsBase): self.assertProperty(char_win, is_active=True) + def test_mouse_does_not_steal_button_focus(self): + """When typing in the hud the mouse must not steal button focus.""" + + self.unity.hud.ensure_visible() + + (x,y,w,h) = self.unity.hud.view.geometry + self.mouse.move(w/4, h/4) + + self.keyboard.type("a") + self.assertThat(self.unity.hud.view.selected_button, Eventually(Equals(1))) + class HudLauncherInteractionsTests(HudTestsBase): -- cgit v1.2.3 From 353e2373dde05519b31151a49a91be615ec0dac4 Mon Sep 17 00:00:00 2001 From: Andrea Azzarone Date: Fri, 15 Mar 2013 13:34:14 +0100 Subject: Style fix in TooltipManager.* (bzr r3215.1.3) --- launcher/TooltipManager.cpp | 16 ++++++++-------- launcher/TooltipManager.h | 10 +++++----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/launcher/TooltipManager.cpp b/launcher/TooltipManager.cpp index c34783233..6d100b389 100644 --- a/launcher/TooltipManager.cpp +++ b/launcher/TooltipManager.cpp @@ -35,9 +35,9 @@ TooltipManager::TooltipManager() , timer_locked_(false) {} -void TooltipManager::SetIcon(AbstractLauncherIcon::Ptr const& newIcon) +void TooltipManager::SetIcon(AbstractLauncherIcon::Ptr const& new_icon) { - if (icon_ == newIcon) + if (icon_ == new_icon) return; // Unlock hover timer, in case the previous icon had no valid tooltip @@ -48,20 +48,20 @@ void TooltipManager::SetIcon(AbstractLauncherIcon::Ptr const& newIcon) // Show new tooltip, get rid of the old olne if (icon_) icon_->HideTooltip(); - if (newIcon) - newIcon->ShowTooltip(); + if (new_icon) + new_icon->ShowTooltip(); } - else if (!newIcon) + else if (!new_icon) { // Stop the hover timer for null launcher space StopTimer(); } else { - AbstractLauncherIcon::IconType type = newIcon->GetIconType(); + AbstractLauncherIcon::IconType type = new_icon->GetIconType(); if ((type == AbstractLauncherIcon::IconType::HOME || type == AbstractLauncherIcon::IconType::HUD) && - newIcon->GetQuirk(AbstractLauncherIcon::Quirk::ACTIVE)) + new_icon->GetQuirk(AbstractLauncherIcon::Quirk::ACTIVE)) { // Lock the hover timer for no valid tooltip cases timer_locked_ = true; @@ -69,7 +69,7 @@ void TooltipManager::SetIcon(AbstractLauncherIcon::Ptr const& newIcon) } } - icon_ = newIcon; + icon_ = new_icon; } void TooltipManager::SetHover(bool on_launcher) diff --git a/launcher/TooltipManager.h b/launcher/TooltipManager.h index f61fc199f..1e969d1c4 100644 --- a/launcher/TooltipManager.h +++ b/launcher/TooltipManager.h @@ -36,7 +36,7 @@ public: TooltipManager(); void SetHover(bool on_launcher); - void SetIcon(AbstractLauncherIcon::Ptr const& newIcon); + void SetIcon(AbstractLauncherIcon::Ptr const& new_icon); void MouseMoved(); void IconClicked(); @@ -44,11 +44,11 @@ private: void ResetTimer(); void StopTimer(); - bool show_tooltips_; - bool hovered_; + bool show_tooltips_; + bool hovered_; AbstractLauncherIcon::Ptr icon_; - glib::Source::UniquePtr hover_timer_; - bool timer_locked_; + glib::Source::UniquePtr hover_timer_; + bool timer_locked_; }; } // namespace launcher -- cgit v1.2.3 From 8ebc1b12b213de0e3f09f22194f732abd0720da1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 15 Mar 2013 14:44:17 +0100 Subject: SearchBar: correctly set the number of lines of the Filter text (bzr r3212.2.9) --- unity-shared/SearchBar.cpp | 2 +- unity-shared/SearchBar.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/unity-shared/SearchBar.cpp b/unity-shared/SearchBar.cpp index bb6b8c15f..80e850457 100644 --- a/unity-shared/SearchBar.cpp +++ b/unity-shared/SearchBar.cpp @@ -187,7 +187,7 @@ void SearchBar::Init() show_filters_->SetFont(SHOW_FILTERS_LABEL_DEFAULT_FONT.c_str()); show_filters_->SetTextColor(nux::color::White); show_filters_->SetTextAlignment(StaticCairoText::NUX_ALIGN_RIGHT); - show_filters_->SetLines(1); + show_filters_->SetLines(-1); nux::BaseTexture* arrow; arrow = style.GetGroupExpandIcon(); diff --git a/unity-shared/SearchBar.h b/unity-shared/SearchBar.h index 8095f8348..5b502ffb7 100644 --- a/unity-shared/SearchBar.h +++ b/unity-shared/SearchBar.h @@ -68,7 +68,6 @@ public: sigc::signal live_search_reached; private: - void Init(); void OnFontChanged(GtkSettings* settings, GParamSpec* pspec=NULL); -- cgit v1.2.3 From 8057a5a4dc9d8cd597e62de5735c06ee060e0c45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 15 Mar 2013 14:44:36 +0100 Subject: StaticCairoText: recompute the extents if they exceed the maximum size Keep the texture the most little that we can, then adjust its position when drawing. (bzr r3212.2.10) --- unity-shared/StaticCairoText.cpp | 102 +++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 52 deletions(-) diff --git a/unity-shared/StaticCairoText.cpp b/unity-shared/StaticCairoText.cpp index 7def057c8..a35c37315 100644 --- a/unity-shared/StaticCairoText.cpp +++ b/unity-shared/StaticCairoText.cpp @@ -67,6 +67,8 @@ struct StaticCairoText::Impl std::shared_ptr cr; }; + + void UpdateBaseSize(); Size GetTextExtents() const; void SetAttributes(PangoLayout* layout); @@ -92,7 +94,7 @@ struct StaticCairoText::Impl EllipsizeState ellipsize_; AlignState align_; AlignState valign_; - UnderlineState underline_; + UnderlineState underline_; std::string font_; @@ -173,7 +175,6 @@ StaticCairoText::StaticCairoText(std::string const& text, : View(NUX_FILE_LINE_PARAM) , pimpl(new Impl(this, text)) { - SetMinimumSize(1, 1); SetAcceptKeyNavFocusOnMouseDown(false); } @@ -182,7 +183,6 @@ StaticCairoText::StaticCairoText(std::string const& text, bool escape_text, : View(NUX_FILE_LINE_PARAM) , pimpl(new Impl(this, escape_text ? GetEscapedText(text) : text)) { - SetMinimumSize(1, 1); SetAcceptKeyNavFocusOnMouseDown(false); } @@ -226,17 +226,14 @@ void StaticCairoText::SetLineSpacing(float line_spacing) void StaticCairoText::PreLayoutManagement() { - Geometry geo = GetGeometry(); + Geometry const& geo = GetGeometry(); pimpl->pre_layout_size_.width = geo.width; pimpl->pre_layout_size_.height = geo.height; + pimpl->UpdateBaseSize(); - SetBaseSize(pimpl->cached_extent_.width, - pimpl->cached_extent_.height); if (pimpl->textures2D_.empty()) - { pimpl->UpdateTexture(); - } View::PreLayoutManagement(); } @@ -293,23 +290,27 @@ void StaticCairoText::Draw(GraphicsEngine& gfxContext, bool forceDraw) gfxContext.GetRenderStates().GetBlend(alpha, src, dest); gfxContext.GetRenderStates().SetBlend(true, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - Color col = color::Black; - col.alpha = 0; - gfxContext.QRP_Color(base.x, - base.y, - base.width, - base.height, - col); + gfxContext.QRP_Color(base.x, base.y, base.width, base.height, color::Transparent); + int current_x = base.x; int current_y = base.y + ((base.height - pimpl->cached_extent_.height) / 2); + if (pimpl->align_ == NUX_ALIGN_CENTRE) + { + current_x += std::round((base.width - pimpl->cached_extent_.width) / 2.0f); + } + else if (pimpl->align_ == NUX_ALIGN_RIGHT) + { + current_x += base.width - pimpl->cached_extent_.width; + } + for (BaseTexturePtr tex : pimpl->textures2D_) { nux::ObjectPtr text_tex = tex->GetDeviceTexture(); if (!text_tex) break; - gfxContext.QRP_1Tex(base.x, + gfxContext.QRP_1Tex(current_x, current_y, text_tex->GetWidth(), text_tex->GetHeight(), @@ -406,7 +407,7 @@ void StaticCairoText::SetTextColor(Color const& textColor) void StaticCairoText::SetFont(std::string const& font) { if (pimpl->font_ != font) - { + { pimpl->font_ = font; pimpl->need_new_extent_cache_ = true; Size s = GetTextExtents(); @@ -524,8 +525,6 @@ Size StaticCairoText::Impl::GetTextExtents() const PangoLayout* layout = NULL; PangoFontDescription* desc = NULL; PangoContext* pangoCtx = NULL; - PangoRectangle inkRect = {0, 0, 0, 0}; - PangoRectangle logRect = {0, 0, 0, 0}; int dpi = 0; GdkScreen* screen = gdk_screen_get_default(); // is not ref'ed GtkSettings* settings = gtk_settings_get_default(); // is not ref'ed @@ -537,10 +536,9 @@ Size StaticCairoText::Impl::GetTextExtents() const Size result; std::string font = GetEffectiveFont(); + nux::Size layout_size(-1, lines_ < 0 ? lines_ : std::numeric_limits::min()); - int maxwidth = parent_->GetMaximumWidth(); - - surface = cairo_image_surface_create(CAIRO_FORMAT_A1, 1, 1); + surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1); cr = cairo_create(surface); cairo_set_font_options(cr, gdk_screen_get_font_options(screen)); @@ -550,8 +548,8 @@ Size StaticCairoText::Impl::GetTextExtents() const pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); pango_layout_set_ellipsize(layout, GetPangoEllipsizeMode()); pango_layout_set_alignment(layout, GetPangoAlignment()); - pango_layout_set_height(layout, lines_); - pango_layout_set_width(layout, maxwidth * PANGO_SCALE); + pango_layout_set_width(layout, layout_size.width); + pango_layout_set_height(layout, layout_size.height); pango_layout_set_markup(layout, text_.c_str(), -1); pango_layout_set_spacing(layout, line_spacing_ * PANGO_SCALE); @@ -570,15 +568,15 @@ Size StaticCairoText::Impl::GetTextExtents() const (float) dpi / (float) PANGO_SCALE); } pango_layout_context_changed(layout); - pango_layout_get_extents(layout, &inkRect, &logRect); + pango_layout_get_pixel_size(layout, &result.width, &result.height); - // logRect has some issues using italic style - if (inkRect.x + inkRect.width > logRect.x + logRect.width) - result.width = std::ceil(static_cast(inkRect.x + inkRect.width - logRect.x) / PANGO_SCALE); - else - result.width = std::ceil(static_cast(logRect.width) / PANGO_SCALE); + if (result.width > parent_->GetMaximumWidth()) + { + pango_layout_set_width(layout, parent_->GetMaximumWidth() * PANGO_SCALE); + pango_layout_context_changed(layout); + pango_layout_get_pixel_size(layout, &result.width, &result.height); + } - result.height = std::ceil(static_cast(logRect.height) / PANGO_SCALE); cached_extent_ = result; baseline_ = pango_layout_get_baseline(layout) / PANGO_SCALE; need_new_extent_cache_ = false; @@ -671,20 +669,8 @@ void StaticCairoText::Impl::DrawText(CacheTexture::Ptr const& texture) if (!texture) return; - nux::Size tex_size(parent_->GetMaximumWidth(), parent_->GetMaximumHeight()); - nux::Size layout_size(tex_size.width * PANGO_SCALE, tex_size.height * PANGO_SCALE); - - if (tex_size.width == nux::AREA_MAX_WIDTH) - { - tex_size.width = parent_->GetWidth(); - layout_size.width = -1; - } - - if (tex_size.height == nux::AREA_MAX_HEIGHT) - { - tex_size.height = parent_->GetHeight(); - layout_size.height = -1; - } + nux::Size tex_size(parent_->GetWidth(), parent_->GetHeight()); + nux::Size layout_size(-1, lines_ < 0 ? lines_ : std::numeric_limits::min()); texture->cr.reset(new CairoGraphics(CAIRO_FORMAT_ARGB32, tex_size.width, tex_size.height)); cairo_t* cr = texture->cr->GetInternalContext(); @@ -702,8 +688,9 @@ void StaticCairoText::Impl::DrawText(CacheTexture::Ptr const& texture) cairo_set_font_options(cr, gdk_screen_get_font_options(screen)); layout = pango_cairo_create_layout(cr); - desc = pango_font_description_from_string(font.c_str()); + + desc = pango_font_description_from_string(font.c_str()); pango_layout_set_font_description(layout, desc); pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); pango_layout_set_ellipsize(layout, GetPangoEllipsizeMode()); @@ -713,8 +700,6 @@ void StaticCairoText::Impl::DrawText(CacheTexture::Ptr const& texture) pango_layout_set_height(layout, layout_size.height); pango_layout_set_spacing(layout, line_spacing_ * PANGO_SCALE); - pango_layout_set_height(layout, lines_); - SetAttributes(layout); pangoCtx = pango_layout_get_context(layout); // is not ref'ed @@ -732,14 +717,22 @@ void StaticCairoText::Impl::DrawText(CacheTexture::Ptr const& texture) (float) dpi / (float) PANGO_SCALE); } + Size result; + pango_layout_context_changed(layout); + pango_layout_get_pixel_size(layout, &result.width, &result.height); + + if (result.width > parent_->GetMaximumWidth()) + { + pango_layout_set_width(layout, parent_->GetMaximumWidth() * PANGO_SCALE); + pango_layout_context_changed(layout); + } + cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); cairo_paint(cr); cairo_set_operator(cr, CAIRO_OPERATOR_OVER); cairo_set_source_rgba(cr, text_color_.red, text_color_.green, text_color_.blue, text_color_.alpha); - pango_layout_context_changed(layout); - cairo_move_to(cr, 0.0f, 0.0f); pango_cairo_show_layout(cr, layout); @@ -750,10 +743,15 @@ void StaticCairoText::Impl::DrawText(CacheTexture::Ptr const& texture) g_object_unref(layout); } +void StaticCairoText::Impl::UpdateBaseSize() +{ + parent_->SetBaseSize(cached_extent_.width, cached_extent_.height); +} + void StaticCairoText::Impl::UpdateTexture() { - auto const& size = GetTextExtents(); - parent_->SetBaseSize(size.width, size.height); + GetTextExtents(); + UpdateBaseSize(); textures2D_.clear(); for (auto const& texture : cache_textures_) -- cgit v1.2.3 From 884355e55d7805c7008daa8fe6d0646d63291167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 15 Mar 2013 15:34:51 +0100 Subject: StaticCairoText: fix vertical alignment, keep the texture size as small as we can (bzr r3212.2.11) --- unity-shared/StaticCairoText.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/unity-shared/StaticCairoText.cpp b/unity-shared/StaticCairoText.cpp index a35c37315..3086f5d86 100644 --- a/unity-shared/StaticCairoText.cpp +++ b/unity-shared/StaticCairoText.cpp @@ -116,7 +116,7 @@ StaticCairoText::Impl::Impl(StaticCairoText* parent, std::string const& text) , text_color_(color::White) , ellipsize_(NUX_ELLIPSIZE_END) , align_(NUX_ALIGN_LEFT) - , valign_(NUX_ALIGN_TOP) + , valign_(NUX_ALIGN_CENTRE) , underline_(NUX_UNDERLINE_NONE) , lines_(-2) // should find out why -2... // the desired height of the layout in Pango units if positive, or desired @@ -293,7 +293,7 @@ void StaticCairoText::Draw(GraphicsEngine& gfxContext, bool forceDraw) gfxContext.QRP_Color(base.x, base.y, base.width, base.height, color::Transparent); int current_x = base.x; - int current_y = base.y + ((base.height - pimpl->cached_extent_.height) / 2); + int current_y = base.y; if (pimpl->align_ == NUX_ALIGN_CENTRE) { @@ -304,6 +304,15 @@ void StaticCairoText::Draw(GraphicsEngine& gfxContext, bool forceDraw) current_x += base.width - pimpl->cached_extent_.width; } + if (pimpl->valign_ == NUX_ALIGN_CENTRE) + { + current_y += std::round((base.height - pimpl->cached_extent_.height) / 2.0f); + } + else if (pimpl->valign_ == NUX_ALIGN_BOTTOM) + { + current_y += base.height - pimpl->cached_extent_.height; + } + for (BaseTexturePtr tex : pimpl->textures2D_) { nux::ObjectPtr text_tex = tex->GetDeviceTexture(); @@ -502,7 +511,8 @@ std::string StaticCairoText::GetName() const void StaticCairoText::AddProperties(GVariantBuilder* builder) { unity::variant::BuilderWrapper(builder) - .add(GetGeometry()); + .add(GetGeometry()) + .add("text", pimpl->text_); } std::string StaticCairoText::Impl::GetEffectiveFont() const @@ -669,10 +679,8 @@ void StaticCairoText::Impl::DrawText(CacheTexture::Ptr const& texture) if (!texture) return; - nux::Size tex_size(parent_->GetWidth(), parent_->GetHeight()); nux::Size layout_size(-1, lines_ < 0 ? lines_ : std::numeric_limits::min()); - - texture->cr.reset(new CairoGraphics(CAIRO_FORMAT_ARGB32, tex_size.width, tex_size.height)); + texture->cr.reset(new CairoGraphics(CAIRO_FORMAT_ARGB32, cached_extent_.width, cached_extent_.height)); cairo_t* cr = texture->cr->GetInternalContext(); PangoLayout* layout = NULL; -- cgit v1.2.3 From 03c6e62d049fac7201db0f79cf6a56ef4931d9fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Fri, 15 Mar 2013 16:05:28 +0100 Subject: StaticCairoText: compute the layout size using an A1 surface (bzr r3212.2.12) --- unity-shared/StaticCairoText.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unity-shared/StaticCairoText.cpp b/unity-shared/StaticCairoText.cpp index 3086f5d86..e1e0de781 100644 --- a/unity-shared/StaticCairoText.cpp +++ b/unity-shared/StaticCairoText.cpp @@ -548,7 +548,7 @@ Size StaticCairoText::Impl::GetTextExtents() const std::string font = GetEffectiveFont(); nux::Size layout_size(-1, lines_ < 0 ? lines_ : std::numeric_limits::min()); - surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1); + surface = cairo_image_surface_create(CAIRO_FORMAT_A1, 1, 1); cr = cairo_create(surface); cairo_set_font_options(cr, gdk_screen_get_font_options(screen)); -- cgit v1.2.3 From 884ef70b78957c5d4d4c405bcdfc669754f2204c Mon Sep 17 00:00:00 2001 From: Andrea Azzarone Date: Fri, 15 Mar 2013 16:25:29 +0100 Subject: Add more unit test for TooltipManager. Don't reset time on every mouse move. (bzr r3215.1.4) --- launcher/Launcher.cpp | 3 +- launcher/TooltipManager.cpp | 104 ++++++++++++++--------------------------- launcher/TooltipManager.h | 21 ++++----- tests/test_tooltip_manager.cpp | 79 +++++++++++++++++++++++-------- 4 files changed, 105 insertions(+), 102 deletions(-) diff --git a/launcher/Launcher.cpp b/launcher/Launcher.cpp index ee73cb274..dda22403f 100644 --- a/launcher/Launcher.cpp +++ b/launcher/Launcher.cpp @@ -303,7 +303,6 @@ void Launcher::SetIconUnderMouse(AbstractLauncherIcon::Ptr const& icon) icon->mouse_enter.emit(monitor); _icon_under_mouse = icon; - tooltip_manager_.SetIcon(icon); } bool Launcher::MouseBeyondDragThreshold() const @@ -2224,7 +2223,7 @@ void Launcher::RecvMouseLeave(int x, int y, unsigned long button_flags, unsigned void Launcher::RecvMouseMove(int x, int y, int dx, int dy, unsigned long button_flags, unsigned long key_flags) { SetMousePosition(x, y); - tooltip_manager_.MouseMoved(); + tooltip_manager_.MouseMoved(_icon_under_mouse); if (!_hidden) UpdateChangeInMousePosition(dx, dy); diff --git a/launcher/TooltipManager.cpp b/launcher/TooltipManager.cpp index 6d100b389..dee8a5103 100644 --- a/launcher/TooltipManager.cpp +++ b/launcher/TooltipManager.cpp @@ -15,6 +15,7 @@ * along with this program. If not, see . * * Authored by: Jacob Edwards + * Andrea Azzarone */ #include "TooltipManager.h" @@ -23,104 +24,69 @@ namespace unity { namespace launcher { - namespace { -const unsigned int TOOLTIPS_SHOW_TIMEOUT_LENGTH = 1000; +const unsigned int TOOLTIPS_SHOW_TIMEOUT_LENGTH = 500; } TooltipManager::TooltipManager() - : show_tooltips_(false) - , hovered_(false) - , timer_locked_(false) + : skip_timeout_(false) {} -void TooltipManager::SetIcon(AbstractLauncherIcon::Ptr const& new_icon) -{ - if (icon_ == new_icon) +void TooltipManager::MouseMoved(AbstractLauncherIcon::Ptr const& icon_under_mouse) +{ + if (icon_ == icon_under_mouse) return; - // Unlock hover timer, in case the previous icon had no valid tooltip - timer_locked_ = false; - - if (show_tooltips_) - { - // Show new tooltip, get rid of the old olne - if (icon_) - icon_->HideTooltip(); - if (new_icon) - new_icon->ShowTooltip(); - } - else if (!new_icon) - { - // Stop the hover timer for null launcher space - StopTimer(); - } - else - { - AbstractLauncherIcon::IconType type = new_icon->GetIconType(); - if ((type == AbstractLauncherIcon::IconType::HOME || - type == AbstractLauncherIcon::IconType::HUD) && - new_icon->GetQuirk(AbstractLauncherIcon::Quirk::ACTIVE)) - { - // Lock the hover timer for no valid tooltip cases - timer_locked_ = true; - StopTimer(); - } - } + StopTimer(); + if (icon_) + icon_->HideTooltip(); + + icon_ = icon_under_mouse; - icon_ = new_icon; + if (icon_ && !skip_timeout_) + ResetTimer(icon_); + else if (icon_ && skip_timeout_) + icon_->ShowTooltip(); } -void TooltipManager::SetHover(bool on_launcher) -{ - if (hovered_ == on_launcher) - return; - hovered_ = on_launcher; - - if (show_tooltips_ && !hovered_) - { - show_tooltips_ = false; - if (icon_) - icon_->HideTooltip(); - } +void TooltipManager::IconClicked() +{ + if (icon_) + icon_->HideTooltip(); } -void TooltipManager::MouseMoved() +void TooltipManager::SetHover(bool hovered) { - if (!icon_ || show_tooltips_) - return; - - ResetTimer(); + if (!hovered) + Reset(); } -void TooltipManager::IconClicked() +void TooltipManager::Reset() { StopTimer(); - if (show_tooltips_ && icon_) + + if (icon_) icon_->HideTooltip(); - show_tooltips_ = false; - timer_locked_ = true; + icon_ = AbstractLauncherIcon::Ptr(); + skip_timeout_ = false; } -void TooltipManager::ResetTimer() +void TooltipManager::ResetTimer(AbstractLauncherIcon::Ptr const& icon_under_mouse) { - if (timer_locked_) - return; - hover_timer_.reset(new glib::Timeout(TOOLTIPS_SHOW_TIMEOUT_LENGTH)); hover_timer_->Run([&] () { - show_tooltips_ = true; - icon_->ShowTooltip(); + skip_timeout_ = true; + icon_under_mouse->ShowTooltip(); return false; }); -} - + } + void TooltipManager::StopTimer() { - hover_timer_.reset(); + hover_timer_.reset(); } -} // namespace launcher -} // namespace unity +} +} diff --git a/launcher/TooltipManager.h b/launcher/TooltipManager.h index 1e969d1c4..817239d26 100644 --- a/launcher/TooltipManager.h +++ b/launcher/TooltipManager.h @@ -15,10 +15,11 @@ * along with this program. If not, see . * * Authored by: Jacob Edwards + * Andrea Azzarone */ -#ifndef TOOLTIPMANAGER -#define TOOLTIPMANAGER +#ifndef LAUNCHER_TOOLTIP_MANAGER_H +#define LAUNCHER_TOOLTIP_MANAGER_H #include #include @@ -35,23 +36,21 @@ class TooltipManager : public boost::noncopyable public: TooltipManager(); - void SetHover(bool on_launcher); - void SetIcon(AbstractLauncherIcon::Ptr const& new_icon); - void MouseMoved(); + void SetHover(bool hovered); + void MouseMoved(AbstractLauncherIcon::Ptr const& icon_under_mouse); void IconClicked(); private: - void ResetTimer(); + void Reset(); + void ResetTimer(AbstractLauncherIcon::Ptr const& icon_under_mouse); void StopTimer(); - bool show_tooltips_; - bool hovered_; + bool skip_timeout_; AbstractLauncherIcon::Ptr icon_; glib::Source::UniquePtr hover_timer_; - bool timer_locked_; }; -} // namespace launcher -} // namespace unity +} +} #endif diff --git a/tests/test_tooltip_manager.cpp b/tests/test_tooltip_manager.cpp index c7f2583ed..5badb4edf 100644 --- a/tests/test_tooltip_manager.cpp +++ b/tests/test_tooltip_manager.cpp @@ -15,40 +15,79 @@ * along with this program. If not, see . * * Authored by: Jacob Edwards + * Andrea Azzarone */ -#include +#include using namespace testing; #include "launcher/TooltipManager.h" #include "launcher/MockLauncherIcon.h" +using unity::launcher::MockLauncherIcon; +using unity::launcher::TooltipManager; + #include "test_utils.h" -namespace unity -{ -namespace launcher +namespace { -namespace +bool CheckIsTooltipVisible(nux::ObjectPtr const& icon, bool value) { + return icon->IsTooltipVisible() == value; +} + +struct TestTooltipManager : public Test { + TooltipManager tooltip_manager; +}; + +TEST_F(TestTooltipManager, MouseMoved) { + nux::ObjectPtr icon1(new MockLauncherIcon()); + nux::ObjectPtr icon2(new MockLauncherIcon()); + + tooltip_manager.MouseMoved(icon1); + ASSERT_FALSE(icon1->IsTooltipVisible()); // don't skip the timeout! + Utils::WaitUntil(std::bind(CheckIsTooltipVisible, icon1, true)); + Utils::WaitUntil(std::bind(CheckIsTooltipVisible, icon2, false)); + + tooltip_manager.MouseMoved(icon2); + ASSERT_FALSE(icon1->IsTooltipVisible()); + ASSERT_TRUE(icon2->IsTooltipVisible()); + + tooltip_manager.MouseMoved(nux::ObjectPtr()); + ASSERT_FALSE(icon1->IsTooltipVisible()); + ASSERT_FALSE(icon2->IsTooltipVisible()); -TEST(TestTooltipManager, TestHideAndShowTooltip) + tooltip_manager.MouseMoved(icon1); + ASSERT_TRUE(icon1->IsTooltipVisible()); + ASSERT_FALSE(icon2->IsTooltipVisible()); +} + +TEST_F(TestTooltipManager, IconClicked) { - // Makes sure that TooltipManager calls icon->ShowTooltip() when the mouse - // hovers it, and icon->HideTooltip() after the mouse dehovers it. - TooltipManager tm; - MockLauncherIcon* icon = new MockLauncherIcon(); - - tm.SetIcon(AbstractLauncherIcon::Ptr(icon)); - tm.MouseMoved(); - Utils::WaitForTimeoutMSec(1050); - - EXPECT_TRUE(icon->IsTooltipVisible()); - tm.SetIcon(AbstractLauncherIcon::Ptr()); - EXPECT_FALSE(icon->IsTooltipVisible()); + nux::ObjectPtr icon(new MockLauncherIcon()); + + tooltip_manager.MouseMoved(icon); + ASSERT_FALSE(icon->IsTooltipVisible()); // don't skip the timeout! + Utils::WaitUntil(std::bind(CheckIsTooltipVisible, icon, true)); + + tooltip_manager.IconClicked(); + ASSERT_FALSE(icon->IsTooltipVisible()); } +TEST_F(TestTooltipManager, SetHover) +{ + nux::ObjectPtr icon(new MockLauncherIcon()); + + tooltip_manager.MouseMoved(icon); + ASSERT_FALSE(icon->IsTooltipVisible()); // don't skip the timeout! + Utils::WaitUntil(std::bind(CheckIsTooltipVisible, icon, true)); + + tooltip_manager.SetHover(false); + ASSERT_FALSE(icon->IsTooltipVisible()); + + tooltip_manager.MouseMoved(icon); + ASSERT_FALSE(icon->IsTooltipVisible()); // don't skip the timeout! + Utils::WaitUntil(std::bind(CheckIsTooltipVisible, icon, true)); } -} // launcher -} // unity +} -- cgit v1.2.3 From 8abe4ed1d3c50e2d4caf9efe06278b409eba2c42 Mon Sep 17 00:00:00 2001 From: Andrea Azzarone Date: Mon, 18 Mar 2013 13:57:00 +0100 Subject: Add fade animation for tooltip too. (bzr r3221.3.1) --- launcher/LauncherIcon.cpp | 30 +++++++++++++++++++++++++++++- launcher/LauncherIcon.h | 7 +++---- launcher/MockLauncherIcon.h | 1 - unity-shared/Timer.h | 1 - 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/launcher/LauncherIcon.cpp b/launcher/LauncherIcon.cpp index 28d2a668a..e0eac42db 100644 --- a/launcher/LauncherIcon.cpp +++ b/launcher/LauncherIcon.cpp @@ -62,6 +62,8 @@ const std::string UNITY_THEME_NAME = "unity-icon-theme"; const std::string CENTER_STABILIZE_TIMEOUT = "center-stabilize-timeout"; const std::string PRESENT_TIMEOUT = "present-timeout"; const std::string QUIRK_DELAY_TIMEOUT = "quirk-delay-timeout"; + +const unsigned TOOLTIP_FADE_DURATION = 80; } NUX_IMPLEMENT_OBJECT_TYPE(LauncherIcon); @@ -86,6 +88,7 @@ LauncherIcon::LauncherIcon(IconType type) , _parent_geo(max_num_monitors) , _saved_center(max_num_monitors) , _allow_quicklist_to_show(true) + , _tooltip_fade_animator(TOOLTIP_FADE_DURATION) { for (unsigned i = 0; i < unsigned(Quirk::LAST); ++i) { @@ -115,6 +118,19 @@ LauncherIcon::LauncherIcon(IconType type) mouse_down.connect(sigc::mem_fun(this, &LauncherIcon::RecvMouseDown)); mouse_up.connect(sigc::mem_fun(this, &LauncherIcon::RecvMouseUp)); mouse_click.connect(sigc::mem_fun(this, &LauncherIcon::RecvMouseClick)); + + _tooltip_fade_animator.updated.connect([this] (double opacity) { + if (_tooltip) + { + _tooltip->SetOpacity(opacity); + + if (opacity == 0.0f && _tooltip_fade_animator.GetStartValue() >= _tooltip_fade_animator.GetFinishValue()) + { + _tooltip->ShowWindow(false); + _tooltip->SetOpacity(0.0f); + } + } + }); } LauncherIcon::~LauncherIcon() @@ -143,6 +159,7 @@ LauncherIcon::~LauncherIcon() void LauncherIcon::LoadTooltip() { _tooltip = new Tooltip(); + _tooltip->SetOpacity(0.0f); AddChild(_tooltip.GetPointer()); _tooltip->text = tooltip_text(); @@ -522,6 +539,11 @@ LauncherIcon::ShowTooltip() _tooltip->ShowTooltipWithTipAt(tip_x, tip_y); _tooltip->ShowWindow(!tooltip_text().empty()); tooltip_visible.emit(_tooltip); + + if (_tooltip_fade_animator.CurrentState() == nux::animation::Animation::State::Running) + _tooltip_fade_animator.Reverse(); + else + _tooltip_fade_animator.SetStartValue(0.0f).SetFinishValue(1.0f).Start(); } void @@ -669,7 +691,13 @@ void LauncherIcon::RecvMouseClick(int button, int monitor, unsigned long key_fla void LauncherIcon::HideTooltip() { if (_tooltip) - _tooltip->ShowWindow(false); + { + if (_tooltip_fade_animator.CurrentState() == nux::animation::Animation::State::Running) + _tooltip_fade_animator.Reverse(); + else + _tooltip_fade_animator.SetStartValue(1.0f).SetFinishValue(0.0f).Start(); + } + tooltip_visible.emit(nux::ObjectPtr(nullptr)); } diff --git a/launcher/LauncherIcon.h b/launcher/LauncherIcon.h index 26f8b04e4..68a783b60 100644 --- a/launcher/LauncherIcon.h +++ b/launcher/LauncherIcon.h @@ -21,12 +21,9 @@ #ifndef LAUNCHERICON_H #define LAUNCHERICON_H -#include -#include - #include #include -#include +#include #include #include @@ -338,6 +335,8 @@ private: std::list _entry_list; + nux::animation::AnimateValue _tooltip_fade_animator; + protected: glib::SourceManager _source_manager; }; diff --git a/launcher/MockLauncherIcon.h b/launcher/MockLauncherIcon.h index 06e0edb33..e1057515c 100644 --- a/launcher/MockLauncherIcon.h +++ b/launcher/MockLauncherIcon.h @@ -22,7 +22,6 @@ #define MOCKLAUNCHERICON_H #include -#include #include #include diff --git a/unity-shared/Timer.h b/unity-shared/Timer.h index 8669164b5..a646dec62 100644 --- a/unity-shared/Timer.h +++ b/unity-shared/Timer.h @@ -20,7 +20,6 @@ #ifndef UNITY_TIMER_H #define UNITY_TIMER_H -#include #include #include -- cgit v1.2.3 From a3e97996310585e89e5300c4cc12e796a420857f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Mon, 18 Mar 2013 13:59:31 +0100 Subject: ResultViewGrid: use guint64 also on assigment (bzr r3221.1.1) --- dash/ResultViewGrid.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dash/ResultViewGrid.cpp b/dash/ResultViewGrid.cpp index fa8924811..d81341474 100644 --- a/dash/ResultViewGrid.cpp +++ b/dash/ResultViewGrid.cpp @@ -208,7 +208,7 @@ void ResultViewGrid::Activate(std::string const& uri, int index, ResultView::Act } active_index_ = index; - unsigned long timestamp = nux::GetGraphicsDisplay()->GetCurrentEvent().x11_timestamp; + guint64 timestamp = nux::GetGraphicsDisplay()->GetCurrentEvent().x11_timestamp; glib::Variant data(g_variant_new("(tiiiiii)", timestamp, column_x, row_y, column_width, row_height, left_results, right_results)); UriActivated.emit(uri, type, data); } -- cgit v1.2.3 -- cgit v1.2.3 From 89a7c358c4ec8422289f1eb70bbe61d1d155db24 Mon Sep 17 00:00:00 2001 From: Andrea Azzarone Date: Mon, 18 Mar 2013 14:16:03 +0100 Subject: Minor change. (bzr r3221.3.3) --- launcher/LauncherIcon.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/LauncherIcon.cpp b/launcher/LauncherIcon.cpp index e0eac42db..7efe4b458 100644 --- a/launcher/LauncherIcon.cpp +++ b/launcher/LauncherIcon.cpp @@ -124,7 +124,7 @@ LauncherIcon::LauncherIcon(IconType type) { _tooltip->SetOpacity(opacity); - if (opacity == 0.0f && _tooltip_fade_animator.GetStartValue() >= _tooltip_fade_animator.GetFinishValue()) + if (opacity == 0.0f && _tooltip_fade_animator.GetStartValue() > _tooltip_fade_animator.GetFinishValue()) { _tooltip->ShowWindow(false); _tooltip->SetOpacity(0.0f); -- cgit v1.2.3 From a7c6a0728a8ba84d788860a2e7c552bcd7ff99cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Mon, 18 Mar 2013 17:53:49 +0100 Subject: resources: updated the icon Edge textures, removed unused files (bzr r3221.2.1) --- resources/launcher_icon_back_170.png | Bin 6990 -> 0 bytes resources/launcher_icon_edge_150.png | Bin 1152 -> 4983 bytes resources/launcher_icon_edge_170.png | Bin 4909 -> 0 bytes resources/launcher_icon_edge_54.png | Bin 437 -> 2709 bytes resources/launcher_icon_selected_back_170.png | Bin 3788 -> 0 bytes resources/launcher_icon_selected_edge_170.png | Bin 4642 -> 0 bytes resources/launcher_icon_shine_170.png | Bin 11408 -> 0 bytes 7 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 resources/launcher_icon_back_170.png delete mode 100644 resources/launcher_icon_edge_170.png delete mode 100644 resources/launcher_icon_selected_back_170.png delete mode 100644 resources/launcher_icon_selected_edge_170.png delete mode 100644 resources/launcher_icon_shine_170.png diff --git a/resources/launcher_icon_back_170.png b/resources/launcher_icon_back_170.png deleted file mode 100644 index efc6794a4..000000000 Binary files a/resources/launcher_icon_back_170.png and /dev/null differ diff --git a/resources/launcher_icon_edge_150.png b/resources/launcher_icon_edge_150.png index df07bd264..9a982fefb 100644 Binary files a/resources/launcher_icon_edge_150.png and b/resources/launcher_icon_edge_150.png differ diff --git a/resources/launcher_icon_edge_170.png b/resources/launcher_icon_edge_170.png deleted file mode 100644 index 5ed464976..000000000 Binary files a/resources/launcher_icon_edge_170.png and /dev/null differ diff --git a/resources/launcher_icon_edge_54.png b/resources/launcher_icon_edge_54.png index e0f85f305..e97bfdb7f 100644 Binary files a/resources/launcher_icon_edge_54.png and b/resources/launcher_icon_edge_54.png differ diff --git a/resources/launcher_icon_selected_back_170.png b/resources/launcher_icon_selected_back_170.png deleted file mode 100644 index 303532ee2..000000000 Binary files a/resources/launcher_icon_selected_back_170.png and /dev/null differ diff --git a/resources/launcher_icon_selected_edge_170.png b/resources/launcher_icon_selected_edge_170.png deleted file mode 100644 index 4ec6455fe..000000000 Binary files a/resources/launcher_icon_selected_edge_170.png and /dev/null differ diff --git a/resources/launcher_icon_shine_170.png b/resources/launcher_icon_shine_170.png deleted file mode 100644 index 41aba4632..000000000 Binary files a/resources/launcher_icon_shine_170.png and /dev/null differ -- cgit v1.2.3 From 97ad99dc7b6c597a56fd16aadc65ca1eb6c8a0c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Mon, 18 Mar 2013 17:58:58 +0100 Subject: IconRenderer: use white color to colorize the icon edges Fixes LP: #1156698 (bzr r3221.2.2) --- unity-shared/IconRenderer.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/unity-shared/IconRenderer.cpp b/unity-shared/IconRenderer.cpp index 39153795b..74e09b03f 100644 --- a/unity-shared/IconRenderer.cpp +++ b/unity-shared/IconRenderer.cpp @@ -404,9 +404,10 @@ void IconRenderer::RenderIcon(nux::GraphicsEngine& GfxContext, RenderArg const& nux::Color background_tile_color = arg.icon->BackgroundColor(); nux::Color glow_color = arg.icon->GlowColor(); - nux::Color edge_color(0x55555555); + nux::Color edge_color = nux::color::White; nux::Color colorify = arg.colorify; nux::Color background_tile_colorify = arg.colorify; + nux::Color edge_tile_colorify = nux::color::White; bool colorify_background = arg.colorify_background; float backlight_intensity = arg.backlight_intensity; float glow_intensity = arg.glow_intensity; @@ -502,10 +503,10 @@ void IconRenderer::RenderIcon(nux::GraphicsEngine& GfxContext, RenderArg const& backlight_intensity * arg.alpha, force_filter, tile_transform); - } - edge_color = edge_color + ((background_tile_color - edge_color) * backlight_intensity); - nux::Color edge_tile_colorify = background_tile_colorify; + edge_tile_colorify = background_tile_colorify * backlight_intensity; + edge_color = edge_color + ((background_tile_color - edge_color) * backlight_intensity); + } if (colorify_background && !arg.keyboard_nav_hl) { -- cgit v1.2.3 From a46001e15c2762ac20963a39a5b35d70fa3fdc5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Mon, 18 Mar 2013 19:12:36 +0100 Subject: resources: added larger launcher pips (bzr r3221.4.1) --- resources/launcher_pip_large_ltr.png | Bin 0 -> 266 bytes resources/launcher_pip_large_rtl.png | Bin 0 -> 266 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 resources/launcher_pip_large_ltr.png create mode 100644 resources/launcher_pip_large_rtl.png diff --git a/resources/launcher_pip_large_ltr.png b/resources/launcher_pip_large_ltr.png new file mode 100644 index 000000000..33f0a6d45 Binary files /dev/null and b/resources/launcher_pip_large_ltr.png differ diff --git a/resources/launcher_pip_large_rtl.png b/resources/launcher_pip_large_rtl.png new file mode 100644 index 000000000..9c036c921 Binary files /dev/null and b/resources/launcher_pip_large_rtl.png differ -- cgit v1.2.3 From 978b933addca86604d814652af7935cce914e4b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Mon, 18 Mar 2013 19:18:10 +0100 Subject: IconRenderer: use bigger assets to draw pips inside tile (in Switcher) Fixes LP: #863331 (bzr r3221.4.2) --- unity-shared/IconRenderer.cpp | 46 +++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/unity-shared/IconRenderer.cpp b/unity-shared/IconRenderer.cpp index 39153795b..6170134ec 100644 --- a/unity-shared/IconRenderer.cpp +++ b/unity-shared/IconRenderer.cpp @@ -189,6 +189,8 @@ nux::BaseTexture* progress_bar_trough = 0; nux::BaseTexture* progress_bar_fill = 0; nux::BaseTexture* pip_ltr = 0; nux::BaseTexture* pip_rtl = 0; +nux::BaseTexture* large_pip_ltr = 0; +nux::BaseTexture* large_pip_rtl = 0; nux::BaseTexture* arrow_ltr = 0; nux::BaseTexture* arrow_rtl = 0; nux::BaseTexture* arrow_empty_ltr = 0; @@ -890,8 +892,8 @@ void IconRenderer::RenderIndicators(nux::GraphicsEngine& GfxContext, if (running > 0) { int scale = 1; - int markerX; + if (pip_style == OUTSIDE_TILE) { markerX = geo.x; @@ -899,8 +901,7 @@ void IconRenderer::RenderIndicators(nux::GraphicsEngine& GfxContext, else { auto bounds = arg.icon->GetTransform(ui::IconTextureSource::TRANSFORM_TILE, monitor); - markerX = bounds[0].x + 2; - scale = 2; + markerX = bounds[0].x + 1; } nux::TexCoordXForm texxform; @@ -921,26 +922,47 @@ void IconRenderer::RenderIndicators(nux::GraphicsEngine& GfxContext, if (!arg.running_on_viewport) { + scale = (pip_style == OUTSIDE_TILE) ? 1 : 2; markers[0] = markerCenter; texture = local::arrow_empty_ltr; } else if (running == 1) { + scale = (pip_style == OUTSIDE_TILE) ? 1 : 2; markers[0] = markerCenter; texture = local::arrow_ltr; } else if (running == 2) { - markers[0] = markerCenter - 2 * scale; - markers[1] = markerCenter + 2 * scale; - texture = local::pip_ltr; + if (pip_style == OUTSIDE_TILE) + { + texture = local::pip_ltr; + markers[0] = markerCenter - 2; + markers[1] = markerCenter + 2; + } + else + { + texture = local::large_pip_ltr; + markers[0] = markerCenter - 4; + markers[1] = markerCenter + 4; + } } else { - markers[0] = markerCenter - 4 * scale; - markers[1] = markerCenter; - markers[2] = markerCenter + 4 * scale; - texture = local::pip_ltr; + if (pip_style == OUTSIDE_TILE) + { + texture = local::pip_ltr; + markers[0] = markerCenter - 4; + markers[1] = markerCenter; + markers[2] = markerCenter + 4; + } + else + { + texture = local::large_pip_ltr; + markers[0] = markerCenter - 8; + markers[1] = markerCenter; + markers[2] = markerCenter + 8; + } } @@ -1223,10 +1245,12 @@ void generate_textures() // squircle_shine = load_texture(PKGDATADIR"/squircle_shine_54.png"); pip_ltr = load_texture(PKGDATADIR"/launcher_pip_ltr.png"); + large_pip_ltr = load_texture(PKGDATADIR"/launcher_pip_large_ltr.png"); arrow_ltr = load_texture(PKGDATADIR"/launcher_arrow_ltr.png"); arrow_empty_ltr = load_texture(PKGDATADIR"/launcher_arrow_outline_ltr.png"); pip_rtl = load_texture(PKGDATADIR"/launcher_pip_rtl.png"); + large_pip_rtl = load_texture(PKGDATADIR"/launcher_pip_large_rt.png"); arrow_rtl = load_texture(PKGDATADIR"/launcher_arrow_rtl.png"); arrow_empty_rtl = load_texture(PKGDATADIR"/launcher_arrow_outline_rtl.png"); @@ -1253,6 +1277,8 @@ void destroy_textures() progress_bar_fill->UnReference(); pip_ltr->UnReference(); pip_rtl->UnReference(); + large_pip_ltr->UnReference(); + large_pip_rtl->UnReference(); arrow_ltr->UnReference(); arrow_rtl->UnReference(); arrow_empty_ltr->UnReference(); -- cgit v1.2.3 From f1f72fcdcccbf7ba18d8892b26b71ccafaedbfd4 Mon Sep 17 00:00:00 2001 From: Brandon Schaefer Date: Mon, 18 Mar 2013 12:46:13 -0700 Subject: * SetInputEventSensitivity to false when setting queries vs when search changes. (bzr r3215.2.3) --- hud/HudView.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/hud/HudView.cpp b/hud/HudView.cpp index 1fd883b19..4465eb729 100644 --- a/hud/HudView.cpp +++ b/hud/HudView.cpp @@ -234,6 +234,7 @@ void View::SetQueries(Hud::Queries queries) HudButton::Ptr button(new HudButton()); buttons_.push_front(button); + button->SetInputEventSensitivity(false); button->SetMinimumWidth(content_width); button->SetMaximumWidth(content_width); button->SetQuery(query); @@ -594,9 +595,6 @@ bool View::InspectKeyEvent(unsigned int eventType, void View::SearchFinished() { - for (auto button : buttons_) - button->SetInputEventSensitivity(false); - search_bar_->SearchFinished(); } -- cgit v1.2.3 From ba470c0641bb1b7bf05afb43f9fba35f8941e5fe Mon Sep 17 00:00:00 2001 From: Mathieu Trudel-Lapierre Date: Mon, 18 Mar 2013 15:58:05 -0400 Subject: Rename gnome calculator desktop file again; 3.7.92 has the desktop file renamed again. Fixes LP: #1156810 (bzr r3222.1.1) --- tests/autopilot/unity/emulators/launcher.py | 2 +- tests/autopilot/unity/tests/launcher/test_icon_behavior.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/autopilot/unity/emulators/launcher.py b/tests/autopilot/unity/emulators/launcher.py index ac7842192..0f74d9bff 100644 --- a/tests/autopilot/unity/emulators/launcher.py +++ b/tests/autopilot/unity/emulators/launcher.py @@ -494,7 +494,7 @@ class LauncherModel(UnityIntrospectionObject): looking for an icon. For example, to find an icon with a particular desktop_id, one might do this from within a test: - >>> self.launcher.model.get_icon(desktop_id="gnome-calculator.desktop") + >>> self.launcher.model.get_icon(desktop_id="gcalctool.desktop") This method returns only one icon. It is the callers responsibility to ensure that the filter matches only one icon. diff --git a/tests/autopilot/unity/tests/launcher/test_icon_behavior.py b/tests/autopilot/unity/tests/launcher/test_icon_behavior.py index c7c0847b1..da6e38cae 100644 --- a/tests/autopilot/unity/tests/launcher/test_icon_behavior.py +++ b/tests/autopilot/unity/tests/launcher/test_icon_behavior.py @@ -315,7 +315,7 @@ class LauncherDragIconsBehavior(LauncherTestCase): # not exist, and we don't want to wait for 10 seconds, so we do this # the old fashioned way. get_icon_fn = lambda: self.unity.launcher.model.get_children_by_type( - ApplicationLauncherIcon, desktop_id="gnome-calculator.desktop") + ApplicationLauncherIcon, desktop_id="gcalctool.desktop") calc_icon = get_icon_fn() if calc_icon: self.launcher_instance.unlock_from_launcher(calc_icon[0]) -- cgit v1.2.3 From fe662485f38f16c8dc9eb0fd501bd966a4c01c2b Mon Sep 17 00:00:00 2001 From: Brandon Schaefer Date: Mon, 18 Mar 2013 12:59:43 -0700 Subject: * Revert rev 3216 as this is done in a different branch (bzr r3215.2.4) --- hud/HudView.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/hud/HudView.cpp b/hud/HudView.cpp index 4465eb729..09a6ad413 100644 --- a/hud/HudView.cpp +++ b/hud/HudView.cpp @@ -138,7 +138,6 @@ void View::ProcessGrowShrink() { float diff = g_get_monotonic_time() - start_time_; int target_height = content_layout_->GetGeometry().height; - // only animate if we are after our defined pause time if (diff > pause_before_grow_length) { @@ -156,12 +155,18 @@ void View::ProcessGrowShrink() //shrink new_height = last_height - ((last_height - target_height) * progress); } + LOG_DEBUG(logger) << "resizing to " << target_height << " (" << new_height << ")" << "View height: " << GetGeometry().height; current_height_ = new_height; } + for (auto button : buttons_) + { + button->SetSkipDraw((button->GetAbsoluteY() + button->GetBaseHeight()) > (GetAbsoluteY() + current_height_)); + } + if (diff > grow_anim_length + pause_before_grow_length) { // ensure we are at our final location and update last known height @@ -180,10 +185,6 @@ void View::ProcessGrowShrink() return false; })); } - - // Do this after we check if we are finished, it will skip drawing buttons otherwise - for (auto button : buttons_) - button->SetSkipDraw((button->GetAbsoluteY() + button->GetBaseHeight()) > (GetAbsoluteY() + current_height_)); } void View::ResetToDefault() @@ -197,6 +198,13 @@ void View::ResetToDefault() void View::Relayout() { + nux::Geometry const& geo = GetGeometry(); + content_geo_ = GetBestFitGeometry(geo); + LOG_DEBUG(logger) << "content_geo: " << content_geo_.width << "x" << content_geo_.height; + + layout_->SetMinimumWidth(content_geo_.width); + layout_->SetMaximumSize(content_geo_.width, content_geo_.height); + QueueDraw(); } @@ -353,7 +361,6 @@ void View::AboutToHide() visible_ = false; overlay_window_buttons_->Hide(); renderer_.AboutToHide(); - ResetToDefault(); } void View::SetupViews() @@ -402,11 +409,6 @@ void View::SetupViews() } }); - nux::Geometry const& geo = GetGeometry(); - content_geo_ = GetBestFitGeometry(geo); - - layout_->SetMinimumWidth(content_geo_.width); - layout_->SetMaximumSize(content_geo_.width, content_geo_.height); layout_->AddLayout(content_layout_.GetPointer(), 1, nux::MINOR_POSITION_START); } -- cgit v1.2.3 From 184f6571382cce8e1ffc0fdd9911bef46588e660 Mon Sep 17 00:00:00 2001 From: Brandon Schaefer Date: Mon, 18 Mar 2013 15:48:08 -0700 Subject: * Make a new test suite, test-gtest-slow for tests that run slow. * Moved over 2 im_text_entry tests which took ~30 seconds to run. * Moved over tooltip_manager as each tests took over half a second. (bzr r3225.2.1) --- tests/CMakeLists.txt | 27 ++++++++++++++-- tests/test_im_text_entry.cpp | 65 ++------------------------------------ tests/test_im_text_entry.h | 47 +++++++++++++++++++++++++++ tests/test_im_text_entry_class.cpp | 41 ++++++++++++++++++++++++ tests/test_im_text_entry_slow.cpp | 46 +++++++++++++++++++++++++++ 5 files changed, 161 insertions(+), 65 deletions(-) create mode 100644 tests/test_im_text_entry.h create mode 100644 tests/test_im_text_entry_class.cpp create mode 100644 tests/test_im_text_entry_slow.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8fdb8444f..d07dd17e2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -99,6 +99,27 @@ if (GTEST_SRC_DIR AND test_service_panel.cpp) target_link_libraries(test-gtest-service unity-shared ${LIBS}) +# gtest-slow, start moving things over that are slow running tests + set (GTEST_SLOW_SOURCES + test_main.cpp + logger_helper.cpp + test_im_text_entry_slow.cpp + test_im_text_entry_class.cpp + test_tooltip_manager.cpp + ) + + set (GTEST_SLOW_LIBS + gtest + gmock + launcher-lib + unity-shared + ) + + add_executable(test-gtest-slow ${GTEST_SLOW_SOURCES}) + + target_link_libraries(test-gtest-slow ${GTEST_SLOW_LIBS}) + + add_test(UnityGTestSlow test-gtest-slow) # The actual test executable (xless) - do not put anything that requires X in here set (GTEST_XLESS_SOURCES @@ -218,6 +239,7 @@ if (ENABLE_X_SUPPORT) test_hud_view.cpp test_icon_loader.cpp test_im_text_entry.cpp + test_im_text_entry_class.cpp test_launcher.cpp test_launcher_controller.cpp test_launcher_drag_window.cpp @@ -263,7 +285,6 @@ if (ENABLE_X_SUPPORT) test_texture_cache.cpp test_text_input.cpp test_thumbnail_generator.cpp - test_tooltip_manager.cpp test_trash_launcher_icon.cpp test_unity_settings.cpp test_unity_window_style.cpp @@ -322,6 +343,7 @@ if (ENABLE_X_SUPPORT) set (GTEST_TEST_COMMAND_GESTURES ./test-gestures/test-gestures) endif (ENABLE_X_SUPPORT) set (GTEST_TEST_COMMAND_XLESS ./test-gtest-xless) +set (GTEST_TEST_COMMAND_SLOW ./test-gtest-slow) set (GTEST_TEST_COMMAND_DBUS dbus-test-runner --task ./test-gtest-service --task ./test-gtest-dbus) set (TEST_COMMAND @@ -330,6 +352,7 @@ set (TEST_COMMAND && ${GTEST_TEST_COMMAND_XLESS} --gtest_output=xml:./ && ${GTEST_TEST_COMMAND_GESTURES} --gtest_output=xml:./ && ${GTEST_TEST_COMMAND_DBUS} --gtest_output=xml:./ + && ${GTEST_TEST_COMMAND_SLOW} --gtest_output=xml:./ ) set (TEST_COMMAND_HEADLESS @@ -340,7 +363,7 @@ set (TEST_COMMAND_HEADLESS if (GTEST_SRC_DIR) if (ENABLE_X_SUPPORT) - add_custom_target (check COMMAND ${TEST_COMMAND} DEPENDS test-unit test-gtest test-gtest-xless test-gtest-dbus test-gestures) + add_custom_target (check COMMAND ${TEST_COMMAND} DEPENDS test-unit test-gtest test-gtest-slow test-gtest-xless test-gtest-dbus test-gestures) add_custom_target (check-headless COMMAND ${TEST_COMMAND_HEADLESS} DEPENDS test-gtest-xless test-gtest-dbus test-gestures) add_custom_target (gcheck COMMAND ${DBUS_TEST_COMMAND} DEPENDS test-gtest test-gtest-xless) else () diff --git a/tests/test_im_text_entry.cpp b/tests/test_im_text_entry.cpp index 2c5457119..334b6ab9d 100644 --- a/tests/test_im_text_entry.cpp +++ b/tests/test_im_text_entry.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2012 Canonical Ltd. + * Copyright 2012-2013 Canonical Ltd. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3, as @@ -19,49 +19,12 @@ * */ -#include -#include "unity-shared/IMTextEntry.h" +#include "test_im_text_entry.h" using namespace testing; using namespace unity; using namespace nux; -namespace -{ - -class TestEvent : public nux::Event -{ -public: - TestEvent(nux::KeyModifier keymod, unsigned long keysym) - { - type = NUX_KEYDOWN; - key_modifiers = keymod; - x11_keysym = keysym; - } - - TestEvent(unsigned long keysym) - { - type = NUX_KEYDOWN; - x11_keysym = keysym; - } -}; - -class MockTextEntry : public IMTextEntry -{ -public: - MOCK_METHOD0(CutClipboard, void()); - MOCK_METHOD0(CopyClipboard, void()); - MOCK_METHOD0(PasteClipboard, void()); - MOCK_METHOD0(PastePrimaryClipboard, void()); - - bool InspectKeyEvent(nux::Event const& event) - { - key_down.emit(event.type, event.GetKeySym(), event.GetKeyState(), nullptr, 0); - return IMTextEntry::InspectKeyEvent(event); - } -}; - - TEST(TestIMTextEntry, CopyCtrlC) { MockTextEntry text_entry; @@ -173,27 +136,3 @@ TEST(TestIMTextEntry, CtrlKeybindings) EXPECT_TRUE(text_entry.InspectKeyEvent(event)); } } - -TEST(TestIMTextEntry, AltKeybindings) -{ - MockTextEntry text_entry; - - for (unsigned long keysym = 0; keysym < XK_VoidSymbol; ++keysym) - { - TestEvent event(KEY_MODIFIER_ALT, keysym); - EXPECT_FALSE(text_entry.InspectKeyEvent(event)); - } -} - -TEST(TestIMTextEntry, SuperKeybindings) -{ - MockTextEntry text_entry; - - for (unsigned long keysym = 0; keysym < XK_VoidSymbol; ++keysym) - { - TestEvent event(KEY_MODIFIER_SUPER, keysym); - EXPECT_FALSE(text_entry.InspectKeyEvent(event)); - } -} - -} diff --git a/tests/test_im_text_entry.h b/tests/test_im_text_entry.h new file mode 100644 index 000000000..1fa0e8f10 --- /dev/null +++ b/tests/test_im_text_entry.h @@ -0,0 +1,47 @@ +/* + * Copyright 2012-2013 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 3, as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the applicable version of the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of both the GNU Lesser General Public + * License version 3 along with this program. If not, see + * + * + * Authored by: Marco Trevisan (Treviño) <3v1n0@ubuntu.com> + * + */ + +#ifndef TEST_IM_TEXT_ENTRY_H +#define TEST_IM_TEXT_ENTRY_H + +#include +#include "unity-shared/IMTextEntry.h" + +class TestEvent : public nux::Event +{ +public: + TestEvent(nux::KeyModifier keymod, unsigned long keysym); + + TestEvent(unsigned long keysym); +}; + +class MockTextEntry : public unity::IMTextEntry +{ +public: + MOCK_METHOD0(CutClipboard, void()); + MOCK_METHOD0(CopyClipboard, void()); + MOCK_METHOD0(PasteClipboard, void()); + MOCK_METHOD0(PastePrimaryClipboard, void()); + + bool InspectKeyEvent(nux::Event const& event); +}; + +#endif // TEST_IM_TEXT_ENTRY_H diff --git a/tests/test_im_text_entry_class.cpp b/tests/test_im_text_entry_class.cpp new file mode 100644 index 000000000..52083994f --- /dev/null +++ b/tests/test_im_text_entry_class.cpp @@ -0,0 +1,41 @@ +/* + * Copyright 2012-2013 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 3, as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the applicable version of the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of both the GNU Lesser General Public + * License version 3 along with this program. If not, see + * + * + * Authored by: Marco Trevisan (Treviño) <3v1n0@ubuntu.com> + * + */ + +#include "test_im_text_entry.h" + +TestEvent::TestEvent(nux::KeyModifier keymod, unsigned long keysym) +{ + type = nux::NUX_KEYDOWN; + key_modifiers = keymod; + x11_keysym = keysym; +} + +TestEvent::TestEvent(unsigned long keysym) +{ + type = nux::NUX_KEYDOWN; + x11_keysym = keysym; +} + +bool MockTextEntry::InspectKeyEvent(nux::Event const& event) +{ + key_down.emit(event.type, event.GetKeySym(), event.GetKeyState(), nullptr, 0); + return IMTextEntry::InspectKeyEvent(event); +} diff --git a/tests/test_im_text_entry_slow.cpp b/tests/test_im_text_entry_slow.cpp new file mode 100644 index 000000000..caa3493b8 --- /dev/null +++ b/tests/test_im_text_entry_slow.cpp @@ -0,0 +1,46 @@ +/* + * Copyright 2012-2013 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 3, as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the applicable version of the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of both the GNU Lesser General Public + * License version 3 along with this program. If not, see + * + * + * Authored by: Marco Trevisan (Treviño) <3v1n0@ubuntu.com> + * + */ + +#include "test_im_text_entry.h" + +using namespace nux; + +TEST(TestIMTextEntry, AltKeybindings) +{ + MockTextEntry text_entry; + + for (unsigned long keysym = 0; keysym < XK_VoidSymbol; ++keysym) + { + TestEvent event(KEY_MODIFIER_ALT, keysym); + EXPECT_FALSE(text_entry.InspectKeyEvent(event)); + } +} + +TEST(TestIMTextEntry, SuperKeybindings) +{ + MockTextEntry text_entry; + + for (unsigned long keysym = 0; keysym < XK_VoidSymbol; ++keysym) + { + TestEvent event(KEY_MODIFIER_SUPER, keysym); + EXPECT_FALSE(text_entry.InspectKeyEvent(event)); + } +} -- cgit v1.2.3 From b6f2a0b98ebb1865e10efb083960967dbf174885 Mon Sep 17 00:00:00 2001 From: Brandon Schaefer Date: Mon, 18 Mar 2013 17:28:28 -0700 Subject: * Fixes a FTBFS from launcher/TrashLauncherIcon.cpp:91 using unicode, and xget fails to parse it. (bzr r3225.1.1) --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1839bde69..70b66c195 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -153,7 +153,7 @@ find_package (Gettext REQUIRED) set (COMPIZ_I18N_DIR ${CMAKE_SOURCE_DIR}/po) add_custom_command (OUTPUT ${CMAKE_SOURCE_DIR}/po/unity.pot - COMMAND xgettext -c --files-from ${CMAKE_SOURCE_DIR}/po/POTFILES.in --keyword=_ -o ${CMAKE_SOURCE_DIR}/po/unity.pot --copyright-holder="Canonical Ltd" --msgid-bugs-address="ayatana-dev@lists.launchpad.net" --no-wrap --no-location + COMMAND xgettext -c --from-code=UTF-8 --files-from ${CMAKE_SOURCE_DIR}/po/POTFILES.in --keyword=_ -o ${CMAKE_SOURCE_DIR}/po/unity.pot --copyright-holder="Canonical Ltd" --msgid-bugs-address="ayatana-dev@lists.launchpad.net" --no-wrap --no-location WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} ) -- cgit v1.2.3 From 2b952f6bc5285d831b70eaa0efecd1dc17758231 Mon Sep 17 00:00:00 2001 From: Andrea Azzarone Date: Tue, 19 Mar 2013 12:56:42 +0100 Subject: Add virtual dtor. (bzr r3226.1.1) --- dash/ApplicationStarter.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dash/ApplicationStarter.h b/dash/ApplicationStarter.h index 817a5466d..d74f302fe 100644 --- a/dash/ApplicationStarter.h +++ b/dash/ApplicationStarter.h @@ -32,6 +32,8 @@ class ApplicationStarter : boost::noncopyable public: typedef std::shared_ptr Ptr; + virtual ~ApplicationStarter() {} + virtual bool Launch(std::string const& application_name, Time timestamp) = 0; }; -- cgit v1.2.3 From aedf2c0acedb08a07f3d2ec1a42f0d98a0907709 Mon Sep 17 00:00:00 2001 From: Andrea Azzarone Date: Tue, 19 Mar 2013 13:41:22 +0100 Subject: Fix standalone launcher. (bzr r3226.2.1) --- launcher/StandaloneLauncher.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/launcher/StandaloneLauncher.cpp b/launcher/StandaloneLauncher.cpp index 777951f6f..cec0cd82d 100644 --- a/launcher/StandaloneLauncher.cpp +++ b/launcher/StandaloneLauncher.cpp @@ -18,7 +18,9 @@ * */ -#include "Nux/Nux.h" +#include +#include +#include #include #include "unity-shared/BackgroundEffectHelper.h" @@ -43,6 +45,7 @@ struct LauncherWindow { LauncherWindow() : wt(nux::CreateGUIThread("Unity Launcher", win_size.width, win_size.height, 0, &LauncherWindow::ThreadWidgetInit, this)) + , animation_controller(tick_source) {} void Show() @@ -85,6 +88,8 @@ private: unity::Settings settings; panel::Style panel_style; std::shared_ptr wt; + nux::NuxTimerTickSource tick_source; + nux::animation::AnimationController animation_controller; launcher::Controller::Ptr controller; }; -- cgit v1.2.3 From 5759fd2ad3960837b842978d0c71efb6cf76d056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 19 Mar 2013 14:16:04 +0100 Subject: IconRenderer::TexturesPool: add a static getter, and use ref_counted instance (bzr r2919.5.4) --- unity-shared/IconRenderer.cpp | 16 +++++++++------- unity-shared/IconRenderer.h | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/unity-shared/IconRenderer.cpp b/unity-shared/IconRenderer.cpp index 743b237df..687d8aea6 100644 --- a/unity-shared/IconRenderer.cpp +++ b/unity-shared/IconRenderer.cpp @@ -191,11 +191,13 @@ enum IconSize } // anonymous namespace } // local namespace -std::unique_ptr IconRenderer::textures_; - struct IconRenderer::TexturesPool { - TexturesPool(); + static std::shared_ptr Get() + { + static std::shared_ptr instance(new TexturesPool()); + return instance; + } nux::ObjectPtr RenderLabelTexture(char label, int icon_size, nux::Color const& bg_color); @@ -233,6 +235,8 @@ struct IconRenderer::TexturesPool std::map labels; private: + TexturesPool(); + inline void LoadTexture(BaseTexturePtr &texture_ptr, std::string const& filename) { texture_ptr.Adopt(nux::CreateTexture2DFromFile(filename.c_str(), -1, true)); @@ -252,11 +256,9 @@ IconRenderer::IconRenderer() : icon_size(0) , image_size(0) , spacing(0) + , textures_(TexturesPool::Get()) { pip_style = OUTSIDE_TILE; - - if (!textures_) - textures_.reset(new IconRenderer::TexturesPool()); } IconRenderer::~IconRenderer() @@ -1091,7 +1093,7 @@ void IconRenderer::RenderProgressToTexture(nux::GraphicsEngine& GfxContext, void IconRenderer::DestroyShortcutTextures() { - textures_->labels.clear(); + TexturesPool::Get()->labels.clear(); } void IconRenderer::GetInverseScreenPerspectiveMatrix(nux::Matrix4& ViewMatrix, nux::Matrix4& PerspectiveMatrix, diff --git a/unity-shared/IconRenderer.h b/unity-shared/IconRenderer.h index 9f6762d40..c087cb5f7 100644 --- a/unity-shared/IconRenderer.h +++ b/unity-shared/IconRenderer.h @@ -88,7 +88,7 @@ private: int spacing; struct TexturesPool; - static std::unique_ptr textures_; + std::shared_ptr textures_; nux::Matrix4 _stored_projection_matrix; }; -- cgit v1.2.3 From 3a88f36da45dd9d5a04e0ba067b8ad3046209742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 19 Mar 2013 14:24:45 +0100 Subject: IconRenderer: adjust variable name to style rules (bzr r2919.5.5) --- unity-shared/IconRenderer.cpp | 4 ++-- unity-shared/IconRenderer.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/unity-shared/IconRenderer.cpp b/unity-shared/IconRenderer.cpp index 687d8aea6..bc82dbf02 100644 --- a/unity-shared/IconRenderer.cpp +++ b/unity-shared/IconRenderer.cpp @@ -278,7 +278,7 @@ void IconRenderer::PreprocessIcons(std::list& args, nux::Geometry con nux::Matrix4 ProjectionMatrix; nux::Matrix4 ViewProjectionMatrix; - _stored_projection_matrix = nux::GetWindowThread()->GetGraphicsEngine().GetOpenGLModelViewProjectionMatrix(); + stored_projection_matrix_ = nux::GetWindowThread()->GetGraphicsEngine().GetOpenGLModelViewProjectionMatrix(); GetInverseScreenPerspectiveMatrix(ViewMatrix, ProjectionMatrix, geo.width, geo.height, 0.1f, 1000.0f, DEGTORAD(90)); @@ -825,7 +825,7 @@ void IconRenderer::RenderElement(nux::GraphicsEngine& GfxContext, int VPMatrixLocation = textures_->shader_program_uv_persp_correction->GetUniformLocationARB("ViewProjectionMatrix"); if (VPMatrixLocation != -1) { - textures_->shader_program_uv_persp_correction->SetUniformLocMatrix4fv((GLint)VPMatrixLocation, 1, false, (GLfloat*) & (_stored_projection_matrix.m)); + textures_->shader_program_uv_persp_correction->SetUniformLocMatrix4fv((GLint)VPMatrixLocation, 1, false, (GLfloat*) & (stored_projection_matrix_.m)); } } #ifndef USE_GLES diff --git a/unity-shared/IconRenderer.h b/unity-shared/IconRenderer.h index c087cb5f7..00b5985d8 100644 --- a/unity-shared/IconRenderer.h +++ b/unity-shared/IconRenderer.h @@ -89,7 +89,7 @@ private: struct TexturesPool; std::shared_ptr textures_; - nux::Matrix4 _stored_projection_matrix; + nux::Matrix4 stored_projection_matrix_; }; } -- cgit v1.2.3 From 6df245a3f928e2b34df6cb101a9fc0aed7b3c45a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 19 Mar 2013 14:52:55 +0100 Subject: SessionView: rename the Logout and Shutdown buttons as requested Fixed bugs: - LP: #1156641 - LP: #1156638 (bzr r3227.1.1) --- shutdown/SessionView.cpp | 6 +++--- tests/test_session_view.cpp | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/shutdown/SessionView.cpp b/shutdown/SessionView.cpp index 93e77c996..2977965fb 100644 --- a/shutdown/SessionView.cpp +++ b/shutdown/SessionView.cpp @@ -177,7 +177,7 @@ void View::Populate() button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::LockScreen)); AddButton(button); - button = new Button(_("Logout"), "logout", NUX_TRACKER_LOCATION); + button = new Button(_("Log Out"), "logout", NUX_TRACKER_LOCATION); button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Logout)); AddButton(button); } @@ -206,7 +206,7 @@ void View::Populate() if (manager_->CanShutdown()) { - auto* button = new Button(_("Shutdown"), "shutdown", NUX_TRACKER_LOCATION); + auto* button = new Button(_("Shut Down"), "shutdown", NUX_TRACKER_LOCATION); button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Shutdown)); AddButton(button); @@ -216,7 +216,7 @@ void View::Populate() } else if (mode() == Mode::FULL) { - auto* button = new Button(_("Logout"), "logout", NUX_TRACKER_LOCATION); + auto* button = new Button(_("Log Out"), "logout", NUX_TRACKER_LOCATION); button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Logout)); AddButton(button); } diff --git a/tests/test_session_view.cpp b/tests/test_session_view.cpp index 5b65178e6..d8966b216 100644 --- a/tests/test_session_view.cpp +++ b/tests/test_session_view.cpp @@ -129,18 +129,18 @@ TEST_F(TestSessionView, FullModeButtons) ON_CALL(*manager, CanHibernate()).WillByDefault(testing::Return(true)); view.mode.changed.emit(View::Mode::FULL); - EXPECT_EQ(view.GetButtonByLabel("Logout"), nullptr); + EXPECT_EQ(view.GetButtonByLabel("Log Out"), nullptr); EXPECT_NE(view.GetButtonByLabel("Lock"), nullptr); EXPECT_NE(view.GetButtonByLabel("Suspend"), nullptr); EXPECT_NE(view.GetButtonByLabel("Hibernate"), nullptr); - EXPECT_NE(view.GetButtonByLabel("Shutdown"), nullptr); + EXPECT_NE(view.GetButtonByLabel("Shut Down"), nullptr); EXPECT_NE(view.GetButtonByLabel("Restart"), nullptr); ON_CALL(*manager, CanShutdown()).WillByDefault(testing::Return(false)); view.mode.changed.emit(View::Mode::FULL); - EXPECT_NE(view.GetButtonByLabel("Logout"), nullptr); - EXPECT_EQ(view.GetButtonByLabel("Shutdown"), nullptr); + EXPECT_NE(view.GetButtonByLabel("Log Out"), nullptr); + EXPECT_EQ(view.GetButtonByLabel("Shut Down"), nullptr); EXPECT_EQ(view.GetButtonByLabel("Restart"), nullptr); ON_CALL(*manager, CanSuspend()).WillByDefault(testing::Return(false)); @@ -160,7 +160,7 @@ TEST_F(TestSessionView, ShutdownModeButtons) view.mode = View::Mode::SHUTDOWN; EXPECT_EQ(view.GetButtons().size(), 2); - EXPECT_NE(view.GetButtonByLabel("Shutdown"), nullptr); + EXPECT_NE(view.GetButtonByLabel("Shut Down"), nullptr); EXPECT_NE(view.GetButtonByLabel("Restart"), nullptr); } @@ -169,7 +169,7 @@ TEST_F(TestSessionView, LogoutModeButtons) view.mode = View::Mode::LOGOUT; EXPECT_EQ(view.GetButtons().size(), 2); - EXPECT_NE(view.GetButtonByLabel("Logout"), nullptr); + EXPECT_NE(view.GetButtonByLabel("Log Out"), nullptr); EXPECT_NE(view.GetButtonByLabel("Lock"), nullptr); } @@ -227,7 +227,7 @@ TEST_F(TestSessionView, LogoutButtonActivateLogouts) { view.mode = View::Mode::LOGOUT; EXPECT_CALL(*manager, Logout()); - auto button = view.GetButtonByLabel("Logout"); + auto button = view.GetButtonByLabel("Log Out"); ASSERT_NE(button, nullptr); button->activated.emit(); } @@ -260,7 +260,7 @@ TEST_F(TestSessionView, ShutdownButtonActivateShutsdown) view.mode = View::Mode::SHUTDOWN; EXPECT_CALL(*manager, Shutdown()); - auto button = view.GetButtonByLabel("Shutdown"); + auto button = view.GetButtonByLabel("Shut Down"); ASSERT_NE(button, nullptr); button->activated.emit(); } -- cgit v1.2.3 From 2bce9159712773b5f793c14c14c460e4e80cbfc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 19 Mar 2013 15:14:10 +0100 Subject: SessionButton: generate labels and texture internally by Action (bzr r3227.1.2) --- po/POTFILES.in | 1 + shutdown/SessionButton.cpp | 36 +++++++++++++++++++++++++++++++++--- shutdown/SessionButton.h | 12 +++++++++++- shutdown/SessionView.cpp | 16 ++++++++-------- tests/test_session_button.cpp | 4 ++-- 5 files changed, 55 insertions(+), 14 deletions(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index 5db06e85e..dd5b73a1f 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -33,6 +33,7 @@ shortcuts/ShortcutHintPrivate.cpp shortcuts/ShortcutView.cpp shortcuts/CompizShortcutModeller.cpp shutdown/SessionView.cpp +shutdown/SessionButton.cpp services/panel-service.c unity-shared/DashStyle.cpp unity-shared/SearchBar.cpp diff --git a/shutdown/SessionButton.cpp b/shutdown/SessionButton.cpp index ef45506c1..153360b8a 100644 --- a/shutdown/SessionButton.cpp +++ b/shutdown/SessionButton.cpp @@ -22,7 +22,7 @@ #include #include - +#include namespace unity { @@ -38,7 +38,7 @@ namespace style NUX_IMPLEMENT_OBJECT_TYPE(Button); -Button::Button(std::string const& label, std::string const& texture_name, NUX_FILE_LINE_DECL) +Button::Button(Action action, NUX_FILE_LINE_DECL) : nux::View(NUX_FILE_LINE_PARAM) , highlighted(false) , label([this] { return label_view_->GetText(); }) @@ -46,7 +46,37 @@ Button::Button(std::string const& label, std::string const& texture_name, NUX_FI SetAcceptKeyNavFocusOnMouseDown(false); SetAcceptKeyNavFocusOnMouseEnter(true); - std::string texture_prefix = PKGDATADIR"/" + texture_name; + std::string texture_prefix = PKGDATADIR"/"; + std::string label; + + switch (action) + { + case Action::LOCK: + texture_prefix += "lockscreen"; + label = _("Lock"); + break; + case Action::LOGOUT: + texture_prefix += "logout"; + label = _("Log Out"); + break; + case Action::SUSPEND: + texture_prefix += "suspend"; + label = _("Suspend"); + break; + case Action::HIBERNATE: + texture_prefix += "hibernate"; + label = _("Hibernate"); + break; + case Action::SHUTDOWN: + texture_prefix += "shutdown"; + label = _("Shut Down"); + break; + case Action::REBOOT: + texture_prefix += "restart"; + label = _("Restart"); + break; + } + normal_tex_.Adopt(nux::CreateTexture2DFromFile((texture_prefix + ".png").c_str(), -1, true)); highlight_tex_.Adopt(nux::CreateTexture2DFromFile((texture_prefix + "_highlight.png").c_str(), -1, true)); diff --git a/shutdown/SessionButton.h b/shutdown/SessionButton.h index f9b0ae362..d9da04222 100644 --- a/shutdown/SessionButton.h +++ b/shutdown/SessionButton.h @@ -37,7 +37,17 @@ class Button : public nux::View, public debug::Introspectable { NUX_DECLARE_OBJECT_TYPE(Button, nux::View); public: - Button(std::string const& label, std::string const& texture_name, NUX_FILE_LINE_PROTO); + enum class Action + { + LOCK, + LOGOUT, + SUSPEND, + HIBERNATE, + SHUTDOWN, + REBOOT + }; + + Button(Action, NUX_FILE_LINE_PROTO); nux::Property highlighted; nux::ROProperty label; diff --git a/shutdown/SessionView.cpp b/shutdown/SessionView.cpp index 2977965fb..df5ae0b85 100644 --- a/shutdown/SessionView.cpp +++ b/shutdown/SessionView.cpp @@ -173,11 +173,11 @@ void View::Populate() if (mode() == Mode::LOGOUT) { - auto* button = new Button(_("Lock"), "lockscreen", NUX_TRACKER_LOCATION); + auto* button = new Button(Button::Action::LOCK, NUX_TRACKER_LOCATION); button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::LockScreen)); AddButton(button); - button = new Button(_("Log Out"), "logout", NUX_TRACKER_LOCATION); + button = new Button(Button::Action::LOGOUT, NUX_TRACKER_LOCATION); button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Logout)); AddButton(button); } @@ -185,20 +185,20 @@ void View::Populate() { if (mode() == Mode::FULL) { - auto* button = new Button(_("Lock"), "lockscreen", NUX_TRACKER_LOCATION); + auto* button = new Button(Button::Action::LOCK, NUX_TRACKER_LOCATION); button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::LockScreen)); AddButton(button); if (manager_->CanSuspend()) { - button = new Button(_("Suspend"), "suspend", NUX_TRACKER_LOCATION); + button = new Button(Button::Action::SUSPEND, NUX_TRACKER_LOCATION); button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Suspend)); AddButton(button); } if (manager_->CanHibernate()) { - button = new Button(_("Hibernate"), "hibernate", NUX_TRACKER_LOCATION); + button = new Button(Button::Action::HIBERNATE, NUX_TRACKER_LOCATION); button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Hibernate)); AddButton(button); } @@ -206,17 +206,17 @@ void View::Populate() if (manager_->CanShutdown()) { - auto* button = new Button(_("Shut Down"), "shutdown", NUX_TRACKER_LOCATION); + auto* button = new Button(Button::Action::SHUTDOWN, NUX_TRACKER_LOCATION); button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Shutdown)); AddButton(button); - button = new Button(_("Restart"), "restart", NUX_TRACKER_LOCATION); + button = new Button(Button::Action::REBOOT, NUX_TRACKER_LOCATION); button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Reboot)); AddButton(button); } else if (mode() == Mode::FULL) { - auto* button = new Button(_("Log Out"), "logout", NUX_TRACKER_LOCATION); + auto* button = new Button(Button::Action::LOGOUT, NUX_TRACKER_LOCATION); button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Logout)); AddButton(button); } diff --git a/tests/test_session_button.cpp b/tests/test_session_button.cpp index a108a7373..50b08820b 100644 --- a/tests/test_session_button.cpp +++ b/tests/test_session_button.cpp @@ -31,7 +31,7 @@ struct TestSessionButton : testing::Test { struct ButtonWrap : Button { - ButtonWrap() : Button("ButtonLabel", "hibernate") {} + ButtonWrap() : Button(Action::LOCK) {} using Button::AcceptKeyNavFocusOnMouseEnter; using Button::AcceptKeyNavFocusOnMouseDown; @@ -47,7 +47,7 @@ struct TestSessionButton : testing::Test TEST_F(TestSessionButton, Construct) { EXPECT_FALSE(button.highlighted()); - EXPECT_EQ(button.label(), "ButtonLabel"); + EXPECT_EQ(button.label(), "Lock"); EXPECT_TRUE(button.AcceptKeyNavFocusOnMouseEnter()); EXPECT_FALSE(button.AcceptKeyNavFocusOnMouseDown()); } -- cgit v1.2.3 From 85d18a917c0d381c35ae7d68545335bdd4f57d61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 19 Mar 2013 15:28:11 +0100 Subject: TestSessionButtonLabel: added lalbel tests (bzr r3227.1.3) --- tests/test_session_button.cpp | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/tests/test_session_button.cpp b/tests/test_session_button.cpp index 50b08820b..fb4c8d92c 100644 --- a/tests/test_session_button.cpp +++ b/tests/test_session_button.cpp @@ -47,7 +47,6 @@ struct TestSessionButton : testing::Test TEST_F(TestSessionButton, Construct) { EXPECT_FALSE(button.highlighted()); - EXPECT_EQ(button.label(), "Lock"); EXPECT_TRUE(button.AcceptKeyNavFocusOnMouseEnter()); EXPECT_FALSE(button.AcceptKeyNavFocusOnMouseDown()); } @@ -120,5 +119,43 @@ TEST_F(TestSessionButton, KeyFocusActivatesIt) EXPECT_TRUE(activated); } +// Other tests + +TEST(TestSessionButtonLabel, Lock) +{ + Button button(Button::Action::LOCK); + EXPECT_EQ(button.label(), "Lock"); +} + +TEST(TestSessionButtonLabel, Logout) +{ + Button button(Button::Action::LOGOUT); + EXPECT_EQ(button.label(), "Log Out"); +} + +TEST(TestSessionButtonLabel, Suspend) +{ + Button button(Button::Action::SUSPEND); + EXPECT_EQ(button.label(), "Suspend"); +} + +TEST(TestSessionButtonLabel, Hibernate) +{ + Button button(Button::Action::HIBERNATE); + EXPECT_EQ(button.label(), "Hibernate"); +} + +TEST(TestSessionButtonLabel, Reboot) +{ + Button button(Button::Action::REBOOT); + EXPECT_EQ(button.label(), "Restart"); +} + +TEST(TestSessionButtonLabel, Shutdown) +{ + Button button(Button::Action::SHUTDOWN); + EXPECT_EQ(button.label(), "Shut Down"); +} + } // session } // unity \ No newline at end of file -- cgit v1.2.3 From 82ce2e43120fe0da758fa05d19ade7d2d6d3707e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 19 Mar 2013 15:53:22 +0100 Subject: SessionButton: save button action in a ROProperty (bzr r3227.1.4) --- shutdown/SessionButton.cpp | 2 ++ shutdown/SessionButton.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/shutdown/SessionButton.cpp b/shutdown/SessionButton.cpp index 153360b8a..77a77043c 100644 --- a/shutdown/SessionButton.cpp +++ b/shutdown/SessionButton.cpp @@ -41,7 +41,9 @@ NUX_IMPLEMENT_OBJECT_TYPE(Button); Button::Button(Action action, NUX_FILE_LINE_DECL) : nux::View(NUX_FILE_LINE_PARAM) , highlighted(false) + , action([this] { return action_; }) , label([this] { return label_view_->GetText(); }) + , action_(action) { SetAcceptKeyNavFocusOnMouseDown(false); SetAcceptKeyNavFocusOnMouseEnter(true); diff --git a/shutdown/SessionButton.h b/shutdown/SessionButton.h index d9da04222..055360048 100644 --- a/shutdown/SessionButton.h +++ b/shutdown/SessionButton.h @@ -50,6 +50,7 @@ public: Button(Action, NUX_FILE_LINE_PROTO); nux::Property highlighted; + nux::ROProperty action; nux::ROProperty label; sigc::signal activated; @@ -64,6 +65,7 @@ protected: private: friend class TestSessionButton; + Action action_; IconTexture* image_view_; StaticCairoText* label_view_; nux::ObjectPtr normal_tex_; -- cgit v1.2.3 From 664d2f594cb4551cd036aabf84a92dafae32f3cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 19 Mar 2013 15:54:43 +0100 Subject: TestSessionButtonTypes: added typed tests for action buttons (bzr r3227.1.5) --- shutdown/SessionButton.cpp | 2 +- tests/test_session_button.cpp | 64 ++++++++++++++++++++++++------------------- 2 files changed, 37 insertions(+), 29 deletions(-) diff --git a/shutdown/SessionButton.cpp b/shutdown/SessionButton.cpp index 77a77043c..8af0b6ee7 100644 --- a/shutdown/SessionButton.cpp +++ b/shutdown/SessionButton.cpp @@ -51,7 +51,7 @@ Button::Button(Action action, NUX_FILE_LINE_DECL) std::string texture_prefix = PKGDATADIR"/"; std::string label; - switch (action) + switch (action_) { case Action::LOCK: texture_prefix += "lockscreen"; diff --git a/tests/test_session_button.cpp b/tests/test_session_button.cpp index fb4c8d92c..67e28d496 100644 --- a/tests/test_session_button.cpp +++ b/tests/test_session_button.cpp @@ -46,6 +46,7 @@ struct TestSessionButton : testing::Test TEST_F(TestSessionButton, Construct) { + EXPECT_EQ(button.action(), Button::Action::LOCK); EXPECT_FALSE(button.highlighted()); EXPECT_TRUE(button.AcceptKeyNavFocusOnMouseEnter()); EXPECT_FALSE(button.AcceptKeyNavFocusOnMouseDown()); @@ -119,42 +120,49 @@ TEST_F(TestSessionButton, KeyFocusActivatesIt) EXPECT_TRUE(activated); } -// Other tests +// Action typed buttons tests -TEST(TestSessionButtonLabel, Lock) -{ - Button button(Button::Action::LOCK); - EXPECT_EQ(button.label(), "Lock"); -} - -TEST(TestSessionButtonLabel, Logout) -{ - Button button(Button::Action::LOGOUT); - EXPECT_EQ(button.label(), "Log Out"); -} +struct ActionButton : public testing::TestWithParam { + ActionButton() + : button(GetParam()) + {} -TEST(TestSessionButtonLabel, Suspend) -{ - Button button(Button::Action::SUSPEND); - EXPECT_EQ(button.label(), "Suspend"); -} + std::string GetExpectedLabel() + { + switch (GetParam()) + { + case Button::Action::LOCK: + return "Lock"; + case Button::Action::LOGOUT: + return "Log Out"; + case Button::Action::SUSPEND: + return "Suspend"; + case Button::Action::HIBERNATE: + return "Hibernate"; + case Button::Action::SHUTDOWN: + return "Shut Down"; + case Button::Action::REBOOT: + return "Restart"; + } + + return ""; + } + + Button button; +}; -TEST(TestSessionButtonLabel, Hibernate) -{ - Button button(Button::Action::HIBERNATE); - EXPECT_EQ(button.label(), "Hibernate"); -} +INSTANTIATE_TEST_CASE_P(TestSessionButtonTypes, ActionButton, + testing::Values(Button::Action::LOCK, Button::Action::LOGOUT, Button::Action::SUSPEND, + Button::Action::HIBERNATE, Button::Action::SHUTDOWN, Button::Action::REBOOT)); -TEST(TestSessionButtonLabel, Reboot) +TEST_P(/*TestSessionButtonTypes*/ActionButton, Label) { - Button button(Button::Action::REBOOT); - EXPECT_EQ(button.label(), "Restart"); + EXPECT_EQ(button.label(), GetExpectedLabel()); } -TEST(TestSessionButtonLabel, Shutdown) +TEST_P(/*TestSessionButtonTypes*/ActionButton, Action) { - Button button(Button::Action::SHUTDOWN); - EXPECT_EQ(button.label(), "Shut Down"); + EXPECT_EQ(button.action(), GetParam()); } } // session -- cgit v1.2.3 From 6acc472c125ac3d1beea7c846d2f95c8b3a4087e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 19 Mar 2013 15:57:54 +0100 Subject: TestSessionView: add GetButtonByAction (instead of by label) and use it (bzr r3227.1.6) --- tests/test_session_view.cpp | 50 ++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/tests/test_session_view.cpp b/tests/test_session_view.cpp index d8966b216..019214a39 100644 --- a/tests/test_session_view.cpp +++ b/tests/test_session_view.cpp @@ -60,11 +60,11 @@ struct TestSessionView : testing::Test return buttons; } - Button* GetButtonByLabel(std::string const& label) const + Button* GetButtonByAction(Button::Action action) const { for (auto const& button : GetButtons()) { - if (button->label() == label) + if (button->action() == action) return button; } @@ -129,29 +129,29 @@ TEST_F(TestSessionView, FullModeButtons) ON_CALL(*manager, CanHibernate()).WillByDefault(testing::Return(true)); view.mode.changed.emit(View::Mode::FULL); - EXPECT_EQ(view.GetButtonByLabel("Log Out"), nullptr); - EXPECT_NE(view.GetButtonByLabel("Lock"), nullptr); - EXPECT_NE(view.GetButtonByLabel("Suspend"), nullptr); - EXPECT_NE(view.GetButtonByLabel("Hibernate"), nullptr); - EXPECT_NE(view.GetButtonByLabel("Shut Down"), nullptr); - EXPECT_NE(view.GetButtonByLabel("Restart"), nullptr); + EXPECT_EQ(view.GetButtonByAction(Button::Action::LOGOUT), nullptr); + EXPECT_NE(view.GetButtonByAction(Button::Action::LOCK), nullptr); + EXPECT_NE(view.GetButtonByAction(Button::Action::SUSPEND), nullptr); + EXPECT_NE(view.GetButtonByAction(Button::Action::HIBERNATE), nullptr); + EXPECT_NE(view.GetButtonByAction(Button::Action::SHUTDOWN), nullptr); + EXPECT_NE(view.GetButtonByAction(Button::Action::REBOOT), nullptr); ON_CALL(*manager, CanShutdown()).WillByDefault(testing::Return(false)); view.mode.changed.emit(View::Mode::FULL); - EXPECT_NE(view.GetButtonByLabel("Log Out"), nullptr); - EXPECT_EQ(view.GetButtonByLabel("Shut Down"), nullptr); - EXPECT_EQ(view.GetButtonByLabel("Restart"), nullptr); + EXPECT_NE(view.GetButtonByAction(Button::Action::LOGOUT), nullptr); + EXPECT_EQ(view.GetButtonByAction(Button::Action::SHUTDOWN), nullptr); + EXPECT_EQ(view.GetButtonByAction(Button::Action::REBOOT), nullptr); ON_CALL(*manager, CanSuspend()).WillByDefault(testing::Return(false)); view.mode.changed.emit(View::Mode::FULL); - EXPECT_EQ(view.GetButtonByLabel("Suspend"), nullptr); + EXPECT_EQ(view.GetButtonByAction(Button::Action::SUSPEND), nullptr); ON_CALL(*manager, CanHibernate()).WillByDefault(testing::Return(false)); view.mode.changed.emit(View::Mode::FULL); - EXPECT_EQ(view.GetButtonByLabel("Hibernate"), nullptr); + EXPECT_EQ(view.GetButtonByAction(Button::Action::HIBERNATE), nullptr); } TEST_F(TestSessionView, ShutdownModeButtons) @@ -160,8 +160,8 @@ TEST_F(TestSessionView, ShutdownModeButtons) view.mode = View::Mode::SHUTDOWN; EXPECT_EQ(view.GetButtons().size(), 2); - EXPECT_NE(view.GetButtonByLabel("Shut Down"), nullptr); - EXPECT_NE(view.GetButtonByLabel("Restart"), nullptr); + EXPECT_NE(view.GetButtonByAction(Button::Action::SHUTDOWN), nullptr); + EXPECT_NE(view.GetButtonByAction(Button::Action::REBOOT), nullptr); } TEST_F(TestSessionView, LogoutModeButtons) @@ -169,8 +169,8 @@ TEST_F(TestSessionView, LogoutModeButtons) view.mode = View::Mode::LOGOUT; EXPECT_EQ(view.GetButtons().size(), 2); - EXPECT_NE(view.GetButtonByLabel("Log Out"), nullptr); - EXPECT_NE(view.GetButtonByLabel("Lock"), nullptr); + EXPECT_NE(view.GetButtonByAction(Button::Action::LOGOUT), nullptr); + EXPECT_NE(view.GetButtonByAction(Button::Action::LOCK), nullptr); } TEST_F(TestSessionView, FullModeTitle) @@ -198,7 +198,7 @@ TEST_F(TestSessionView, ButtonsActivateRequestsHide) bool request_hide = false; view.request_hide.connect([&request_hide] { request_hide = true; }); - auto button = view.GetButtonByLabel("Lock"); + auto button = view.GetButtonByAction(Button::Action::LOCK); ASSERT_NE(button, nullptr); button->activated.emit(); @@ -207,7 +207,7 @@ TEST_F(TestSessionView, ButtonsActivateRequestsHide) TEST_F(TestSessionView, ButtonsActivateDeselectButton) { - auto button = view.GetButtonByLabel("Lock"); + auto button = view.GetButtonByAction(Button::Action::LOCK); ASSERT_NE(button, nullptr); button->highlighted = true; button->activated.emit(); @@ -218,7 +218,7 @@ TEST_F(TestSessionView, ButtonsActivateDeselectButton) TEST_F(TestSessionView, LockButtonActivateLocks) { EXPECT_CALL(*manager, LockScreen()); - auto button = view.GetButtonByLabel("Lock"); + auto button = view.GetButtonByAction(Button::Action::LOCK); ASSERT_NE(button, nullptr); button->activated.emit(); } @@ -227,7 +227,7 @@ TEST_F(TestSessionView, LogoutButtonActivateLogouts) { view.mode = View::Mode::LOGOUT; EXPECT_CALL(*manager, Logout()); - auto button = view.GetButtonByLabel("Log Out"); + auto button = view.GetButtonByAction(Button::Action::LOGOUT); ASSERT_NE(button, nullptr); button->activated.emit(); } @@ -238,7 +238,7 @@ TEST_F(TestSessionView, SuspendButtonActivateSuspends) view.mode.changed.emit(View::Mode::FULL); EXPECT_CALL(*manager, Suspend()); - auto button = view.GetButtonByLabel("Suspend"); + auto button = view.GetButtonByAction(Button::Action::SUSPEND); ASSERT_NE(button, nullptr); button->activated.emit(); } @@ -249,7 +249,7 @@ TEST_F(TestSessionView, HibernateButtonActivateHibernates) view.mode.changed.emit(View::Mode::FULL); EXPECT_CALL(*manager, Hibernate()); - auto button = view.GetButtonByLabel("Hibernate"); + auto button = view.GetButtonByAction(Button::Action::HIBERNATE); ASSERT_NE(button, nullptr); button->activated.emit(); } @@ -260,7 +260,7 @@ TEST_F(TestSessionView, ShutdownButtonActivateShutsdown) view.mode = View::Mode::SHUTDOWN; EXPECT_CALL(*manager, Shutdown()); - auto button = view.GetButtonByLabel("Shut Down"); + auto button = view.GetButtonByAction(Button::Action::SHUTDOWN); ASSERT_NE(button, nullptr); button->activated.emit(); } @@ -271,7 +271,7 @@ TEST_F(TestSessionView, RebootButtonActivateReboots) view.mode = View::Mode::SHUTDOWN; EXPECT_CALL(*manager, Reboot()); - auto button = view.GetButtonByLabel("Restart"); + auto button = view.GetButtonByAction(Button::Action::REBOOT); ASSERT_NE(button, nullptr); button->activated.emit(); } -- cgit v1.2.3 From 93b68fdc1d06832dba67f97e01f914137cb5d411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 19 Mar 2013 16:20:49 +0100 Subject: SessionView: invert the position of reboot/shutdown buttons Fixes LP: #1154578 (bzr r3227.1.7) --- shutdown/SessionView.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/shutdown/SessionView.cpp b/shutdown/SessionView.cpp index df5ae0b85..2fa8cf0cd 100644 --- a/shutdown/SessionView.cpp +++ b/shutdown/SessionView.cpp @@ -206,12 +206,12 @@ void View::Populate() if (manager_->CanShutdown()) { - auto* button = new Button(Button::Action::SHUTDOWN, NUX_TRACKER_LOCATION); - button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Shutdown)); + auto *button = new Button(Button::Action::REBOOT, NUX_TRACKER_LOCATION); + button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Reboot)); AddButton(button); - button = new Button(Button::Action::REBOOT, NUX_TRACKER_LOCATION); - button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Reboot)); + button = new Button(Button::Action::SHUTDOWN, NUX_TRACKER_LOCATION); + button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Shutdown)); AddButton(button); } else if (mode() == Mode::FULL) -- cgit v1.2.3 From 9f9f3d7374816bebea3261b8e5968c924d4d5a49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 19 Mar 2013 16:21:30 +0100 Subject: TestSessionView: add method to check button positions, and check it (bzr r3227.1.8) --- tests/test_session_view.cpp | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/tests/test_session_view.cpp b/tests/test_session_view.cpp index 019214a39..4cdebefad 100644 --- a/tests/test_session_view.cpp +++ b/tests/test_session_view.cpp @@ -70,6 +70,20 @@ struct TestSessionView : testing::Test return nullptr; } + + int GetButtonPosition(Button::Action action) const + { + int pos = 0; + for (auto const& button : GetButtons()) + { + if (button->action() == action) + return pos; + + ++pos; + } + + return -1; + } }; void TearDown() @@ -130,11 +144,11 @@ TEST_F(TestSessionView, FullModeButtons) view.mode.changed.emit(View::Mode::FULL); EXPECT_EQ(view.GetButtonByAction(Button::Action::LOGOUT), nullptr); - EXPECT_NE(view.GetButtonByAction(Button::Action::LOCK), nullptr); - EXPECT_NE(view.GetButtonByAction(Button::Action::SUSPEND), nullptr); - EXPECT_NE(view.GetButtonByAction(Button::Action::HIBERNATE), nullptr); - EXPECT_NE(view.GetButtonByAction(Button::Action::SHUTDOWN), nullptr); - EXPECT_NE(view.GetButtonByAction(Button::Action::REBOOT), nullptr); + EXPECT_EQ(view.GetButtonPosition(Button::Action::LOCK), 0); + EXPECT_EQ(view.GetButtonPosition(Button::Action::SUSPEND), 1); + EXPECT_EQ(view.GetButtonPosition(Button::Action::HIBERNATE), 2); + EXPECT_EQ(view.GetButtonPosition(Button::Action::REBOOT), 3); + EXPECT_EQ(view.GetButtonPosition(Button::Action::SHUTDOWN), 4); ON_CALL(*manager, CanShutdown()).WillByDefault(testing::Return(false)); view.mode.changed.emit(View::Mode::FULL); @@ -160,8 +174,8 @@ TEST_F(TestSessionView, ShutdownModeButtons) view.mode = View::Mode::SHUTDOWN; EXPECT_EQ(view.GetButtons().size(), 2); - EXPECT_NE(view.GetButtonByAction(Button::Action::SHUTDOWN), nullptr); - EXPECT_NE(view.GetButtonByAction(Button::Action::REBOOT), nullptr); + EXPECT_EQ(view.GetButtonPosition(Button::Action::REBOOT), 0); + EXPECT_EQ(view.GetButtonPosition(Button::Action::SHUTDOWN), 1); } TEST_F(TestSessionView, LogoutModeButtons) @@ -169,8 +183,8 @@ TEST_F(TestSessionView, LogoutModeButtons) view.mode = View::Mode::LOGOUT; EXPECT_EQ(view.GetButtons().size(), 2); - EXPECT_NE(view.GetButtonByAction(Button::Action::LOGOUT), nullptr); - EXPECT_NE(view.GetButtonByAction(Button::Action::LOCK), nullptr); + EXPECT_EQ(view.GetButtonPosition(Button::Action::LOCK), 0); + EXPECT_EQ(view.GetButtonPosition(Button::Action::LOGOUT), 1); } TEST_F(TestSessionView, FullModeTitle) -- cgit v1.2.3 From 8ecefa2f77a4890e4e459b1ca3047698e1f66ffa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 19 Mar 2013 18:06:25 +0100 Subject: IconRenderer: always colorize the edge_tile, despite the backlight_intensity Fixes LP: #1157303 (bzr r3227.2.1) --- unity-shared/IconRenderer.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/unity-shared/IconRenderer.cpp b/unity-shared/IconRenderer.cpp index fca8df0a0..8143f3859 100644 --- a/unity-shared/IconRenderer.cpp +++ b/unity-shared/IconRenderer.cpp @@ -506,7 +506,6 @@ void IconRenderer::RenderIcon(nux::GraphicsEngine& GfxContext, RenderArg const& force_filter, tile_transform); - edge_tile_colorify = background_tile_colorify * backlight_intensity; edge_color = edge_color + ((background_tile_color - edge_color) * backlight_intensity); } -- cgit v1.2.3