~azzar1/unity/fix-1059562-6.0

« back to all changes in this revision

Viewing changes to plugins/unityshell/src/unityshell.cpp

UnityShell: enable closing on middle-click, fix scaled decoration sizes, fix theming issues, added scale autopilot tests. Fixes: https://bugs.launchpad.net/bugs/1052821, https://bugs.launchpad.net/bugs/1053225, https://bugs.launchpad.net/bugs/1055605, https://bugs.launchpad.net/bugs/1055609, https://bugs.launchpad.net/bugs/1055610. Approved by Brandon Schaefer.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include <Nux/WindowCompositor.h>
27
27
#include <Nux/NuxTimerTickSource.h>
28
28
 
 
29
#include <UnityCore/Variant.h>
 
30
 
29
31
#include "BaseWindowRaiserImp.h"
30
32
#include "IconRenderer.h"
31
33
#include "Launcher.h"
125
127
  , allowWindowPaint(false)
126
128
  , _key_nav_mode_requested(false)
127
129
  , _last_output(nullptr)
128
 
  , _bghash(NULL)
129
130
  , grab_index_ (0)
130
131
  , painting_tray_ (false)
131
132
  , last_scroll_event_(0)
133
134
  , panel_texture_has_changed_(true)
134
135
  , paint_panel_(false)
135
136
  , scale_just_activated_(false)
136
 
  , minimize_speed_controller(new WindowMinimizeSpeedController())
 
137
  , screen_introspection_(screen)
137
138
{
138
139
  Timer timer;
139
140
#ifndef USE_GLES
244
245
    // _bghash is a pointer. We don't want it to be created before Nux system has had a chance
245
246
    // to start. BGHash relies on animations. Nux animation system starts after the WindowThread
246
247
    // has been created.
247
 
    _bghash = new BGHash();
 
248
    _bghash.reset(new BGHash());
248
249
 
249
250
     unity_a11y_init(wt.get());
250
251
 
375
376
    Display* display = gdk_x11_display_get_xdisplay(gdk_display_get_default());;
376
377
    XSelectInput(display, GDK_ROOT_WINDOW(), PropertyChangeMask);
377
378
    LOG_INFO(logger) << "UnityScreen constructed: " << timer.ElapsedSeconds() << "s";
 
379
 
 
380
    panel::Style::Instance().changed.connect(sigc::mem_fun(this, &UnityScreen::OnPanelStyleChanged));
 
381
 
 
382
    minimize_speed_controller_.DurationChanged.connect(
 
383
        sigc::mem_fun(this, &UnityScreen::OnMinimizeDurationChanged)
 
384
    );
 
385
 
 
386
    AddChild(&screen_introspection_);
378
387
  }
379
 
 
380
 
  panel::Style::Instance().changed.connect(sigc::mem_fun(this, &UnityScreen::OnPanelStyleChanged));
381
 
 
382
 
  minimize_speed_controller->DurationChanged.connect(
383
 
      sigc::mem_fun(this, &UnityScreen::OnMinimizeDurationChanged)
384
 
  );
385
388
}
386
389
 
387
390
UnityScreen::~UnityScreen()
391
394
  unity_a11y_finalize();
392
395
  ::unity::ui::IconRenderer::DestroyTextures();
393
396
  QuicklistManager::Destroy();
394
 
  delete _bghash;
395
397
 
396
398
  reset_glib_logging();
397
399
}
659
661
  wy = y + (last_bound.height - height) / 2;
660
662
}
661
663
 
662
 
void
663
 
UnityScreen::OnPanelStyleChanged()
 
664
void UnityScreen::OnPanelStyleChanged()
664
665
{
665
666
  panel_texture_has_changed_ = true;
 
667
 
 
668
  // Reload the windows themed textures
 
669
  UnityWindow::CleanupSharedTextures();
 
670
 
 
671
  if (WindowManager::Default()->IsScaleActive())
 
672
    UnityWindow::SetupSharedTextures();
666
673
}
667
674
 
668
675
void UnityScreen::paintDisplay()
1136
1143
        DoAddDamage();
1137
1144
        handled = true;
1138
1145
      }
 
1146
      else if (event->xbutton.button == Button2 &&
 
1147
               GetScaledGeometry().IsPointInside(event->xbutton.x_root, event->xbutton.y_root))
 
1148
      {
 
1149
        middle_clicked_ = true;
 
1150
        handled = true;
 
1151
      }
1139
1152
      break;
1140
1153
 
1141
1154
    case ButtonRelease:
1155
1168
 
1156
1169
          handled = true;
1157
1170
        }
 
1171
 
 
1172
        if (middle_clicked_)
 
1173
        {
 
1174
          if (event->xbutton.button == Button2 &&
 
1175
              GetScaledGeometry().IsPointInside(event->xbutton.x_root, event->xbutton.y_root))
 
1176
          {
 
1177
            window->close(0);
 
1178
          }
 
1179
 
 
1180
          middle_clicked_ = false;
 
1181
          handled = true;
 
1182
        }
1158
1183
      }
1159
1184
      break;
1160
1185
 
2277
2302
}
2278
2303
 
2279
2304
void UnityScreen::AddProperties(GVariantBuilder* builder)
2280
 
{
2281
 
}
 
2305
{}
2282
2306
 
2283
2307
std::string UnityScreen::GetName() const
2284
2308
{
2469
2493
        CompOption::Value& value = o.value();
2470
2494
        CompOption::Value::Vector& list = value.list();
2471
2495
        CompOption::Value::Vector::iterator i = list.begin();
2472
 
        if (i != list.end()) {
2473
 
          i->set(minimize_speed_controller->getDuration());
2474
 
        }
2475
 
        value.set(list);                
 
2496
        if (i != list.end())
 
2497
          i->set(minimize_speed_controller_.getDuration());
 
2498
 
 
2499
        value.set(list);
2476
2500
        screen->setOptionForPlugin(p->vTable->name().c_str(),
2477
2501
                                   o.name().c_str(), value);
2478
2502
        break;
2603
2627
      case CompWindowNotifyMinimize:
2604
2628
        /* Updating the count in dconf will trigger a "changed" signal to which
2605
2629
         * the method setting the new animation speed is attached */
2606
 
        UnityScreen::get(screen)->minimize_speed_controller->UpdateCount();
 
2630
        UnityScreen::get(screen)->minimize_speed_controller_.UpdateCount();
2607
2631
        break;
2608
2632
      default:
2609
2633
        break;
3458
3482
  WindowManager::Default()->terminate_spread.connect(sigc::mem_fun(this, &UnityWindow::OnTerminateSpreed));
3459
3483
}
3460
3484
 
3461
 
void
3462
 
UnityWindow::DrawTexture(GLTexture* icon,
3463
 
                         const GLWindowPaintAttrib& attrib,
3464
 
                         const GLMatrix& transform,
3465
 
                         unsigned int mask,
3466
 
                         float x, float y,
3467
 
                         int &maxWidth, int &maxHeight)
3468
 
{
3469
 
  if (icon)
 
3485
void UnityWindow::AddProperties(GVariantBuilder* builder)
 
3486
{
 
3487
  Window xid = window->id();
 
3488
  auto const& swins = ScaleScreen::get(screen)->getWindows();
 
3489
  bool scaled = std::find(swins.begin(), swins.end(), ScaleWindow::get(window)) != swins.end();
 
3490
  auto wm = WindowManager::Default();
 
3491
 
 
3492
  variant::BuilderWrapper(builder)
 
3493
    .add(scaled ? GetScaledGeometry() : wm->GetWindowGeometry(xid))
 
3494
    .add("xid", xid)
 
3495
    .add("title", wm->GetWindowName(xid))
 
3496
    .add("scaled", scaled)
 
3497
    .add("scaled_close_x", close_button_geo_.x)
 
3498
    .add("scaled_close_y", close_button_geo_.y)
 
3499
    .add("scaled_close_width", close_button_geo_.width)
 
3500
    .add("scaled_close_height", close_button_geo_.height);
 
3501
}
 
3502
 
 
3503
std::string UnityWindow::GetName() const
 
3504
{
 
3505
  return "Window";
 
3506
}
 
3507
 
 
3508
void UnityWindow::DrawTexture(GLTexture::List const& textures, GLWindowPaintAttrib const& attrib,
 
3509
                              GLMatrix const& transform, unsigned int mask, int x, int y)
 
3510
{
 
3511
  for (auto const& texture : textures)
3470
3512
  {
3471
 
    int width, height;
3472
 
    width  = icon->width();
3473
 
    height = icon->height();
3474
 
 
3475
 
    if (height > maxHeight)
3476
 
      maxHeight = height;
3477
 
 
3478
 
    if (width > maxWidth)
3479
 
      maxWidth = width;
3480
 
 
3481
 
    CompRegion  iconReg(0, 0, width, height);
3482
 
    GLTexture::MatrixList ml(1);
3483
 
 
3484
 
    ml[0] = icon->matrix();
 
3513
    if (!texture)
 
3514
      continue;
 
3515
 
3485
3516
    gWindow->vertexBuffer()->begin();
3486
 
    if (width && height)
3487
 
      gWindow->glAddGeometry(ml, iconReg, iconReg);
 
3517
 
 
3518
    if (texture->width() && texture->height())
 
3519
    {
 
3520
      GLTexture::MatrixList ml(1);
 
3521
      ml[0] = texture->matrix();
 
3522
      CompRegion texture_region(0, 0, texture->width(), texture->height());
 
3523
      gWindow->glAddGeometry(ml, texture_region, texture_region);
 
3524
    }
3488
3525
 
3489
3526
    if (gWindow->vertexBuffer()->end())
3490
3527
    {
3491
3528
      GLMatrix wTransform(transform);
3492
 
 
3493
3529
      wTransform.translate(x, y, 0.0f);
3494
3530
 
3495
 
      gWindow->glDrawTexture(icon, wTransform, attrib, mask);
 
3531
      gWindow->glDrawTexture(texture, wTransform, attrib, mask);
3496
3532
    }
3497
3533
  }
3498
3534
}
3499
3535
 
3500
 
void
3501
 
UnityWindow::RenderText(UnityWindow::CairoContext const& context,
3502
 
                        float x, float y,
3503
 
                        float maxWidth, float maxHeight)
 
3536
void UnityWindow::RenderText(CairoContext const& context, int x, int y, int width, int height)
3504
3537
{
3505
3538
  panel::Style& style = panel::Style::Instance();
3506
 
  std::string fontDescription(style.GetFontDescription(panel::PanelItem::TITLE));
 
3539
  std::string const& font_desc = style.GetFontDescription(panel::PanelItem::TITLE);
3507
3540
 
3508
3541
  glib::Object<PangoLayout> layout(pango_cairo_create_layout(context.cr_));
3509
 
  std::shared_ptr<PangoFontDescription> font(pango_font_description_from_string(fontDescription.c_str()),
 
3542
  std::shared_ptr<PangoFontDescription> font(pango_font_description_from_string(font_desc.c_str()),
3510
3543
                                             pango_font_description_free);
3511
3544
 
3512
3545
  pango_layout_set_font_description(layout, font.get());
3513
3546
 
3514
 
  GdkScreen* gdkScreen = gdk_screen_get_default();
3515
 
  PangoContext* pCxt = pango_layout_get_context(layout);
 
3547
  GdkScreen* gdk_screen = gdk_screen_get_default();
 
3548
  PangoContext* pango_ctx = pango_layout_get_context(layout);
3516
3549
  int dpi = style.GetTextDPI();
3517
3550
 
3518
 
  pango_cairo_context_set_font_options(pCxt, gdk_screen_get_font_options(gdkScreen));
3519
 
  pango_cairo_context_set_resolution(pCxt, dpi / static_cast<float>(PANGO_SCALE));
 
3551
  pango_cairo_context_set_font_options(pango_ctx, gdk_screen_get_font_options(gdk_screen));
 
3552
  pango_cairo_context_set_resolution(pango_ctx, dpi / static_cast<float>(PANGO_SCALE));
3520
3553
  pango_layout_context_changed(layout);
3521
3554
 
3522
 
  pango_layout_set_height(layout, maxHeight);
 
3555
  std::string const& win_title = WindowManager::Default()->GetWindowName(window->id());
 
3556
  pango_layout_set_height(layout, height);
3523
3557
  pango_layout_set_width(layout, -1); //avoid wrap lines
3524
3558
  pango_layout_set_auto_dir(layout, false);
3525
 
  pango_layout_set_text(layout,
3526
 
                        WindowManager::Default()->GetWindowName(window->id()).c_str(),
3527
 
                        -1);
 
3559
  pango_layout_set_text(layout, win_title.c_str(), -1);
3528
3560
 
3529
3561
  /* update the size of the pango layout */
3530
3562
  pango_cairo_update_layout(context.cr_, layout);
3531
 
  cairo_set_operator(context.cr_, CAIRO_OPERATOR_OVER);
3532
 
  cairo_set_source_rgba(context.cr_,
3533
 
                        1.0,
3534
 
                        1.0,
3535
 
                        1.0,
3536
 
                        1.0);
 
3563
 
 
3564
  GtkStyleContext* style_context = style.GetStyleContext();
 
3565
  gtk_style_context_save(style_context);
 
3566
 
 
3567
  std::shared_ptr<GtkWidgetPath> widget_path(gtk_widget_path_new(), gtk_widget_path_free);
 
3568
  gtk_widget_path_append_type(widget_path.get(), GTK_TYPE_MENU_BAR);
 
3569
  gtk_widget_path_append_type(widget_path.get(), GTK_TYPE_MENU_ITEM);
 
3570
  gtk_widget_path_iter_set_name(widget_path.get(), -1 , "UnityPanelWidget");
 
3571
 
 
3572
  gtk_style_context_set_path(style_context, widget_path.get());
 
3573
  gtk_style_context_add_class(style_context, GTK_STYLE_CLASS_MENUBAR);
 
3574
  gtk_style_context_add_class(style_context, GTK_STYLE_CLASS_MENUITEM);
3537
3575
 
3538
3576
  // alignment
3539
3577
  PangoRectangle lRect;
3540
 
  int textWidth, textHeight;
3541
 
 
3542
 
  pango_layout_get_extents(layout, NULL, &lRect);
3543
 
  textWidth = lRect.width / PANGO_SCALE;
3544
 
  textHeight = lRect.height / PANGO_SCALE;
3545
 
 
3546
 
  y = ((maxHeight - textHeight) / 2.0) + y;
3547
 
  cairo_translate(context.cr_, x, y);
3548
 
 
3549
 
  if (textWidth > maxWidth)
 
3578
  pango_layout_get_extents(layout, nullptr, &lRect);
 
3579
  int text_width = lRect.width / PANGO_SCALE;
 
3580
  int text_height = lRect.height / PANGO_SCALE;
 
3581
  y += (height - text_height) / 2.0f;
 
3582
  int text_space = width - x;
 
3583
 
 
3584
  if (text_width > text_space)
3550
3585
  {
3551
 
    // apply a fade effect in the right corner
3552
 
    const int outPixels = textWidth - maxWidth;
3553
 
    const int fadingPixels = 35;
3554
 
    const int fadingWidth = outPixels < fadingPixels ? outPixels : fadingPixels;
 
3586
    // Cut the text with fade
 
3587
    int out_pixels = text_width - text_space;
 
3588
    const int fading_pixels = 35;
 
3589
    int fading_width = (out_pixels < fading_pixels) ? out_pixels : fading_pixels;
3555
3590
 
3556
3591
    cairo_push_group(context.cr_);
3557
 
    pango_cairo_show_layout(context.cr_, layout);
 
3592
    gtk_render_layout(style_context, context.cr_, x, y, layout);
3558
3593
    cairo_pop_group_to_source(context.cr_);
3559
3594
 
3560
 
    std::shared_ptr<cairo_pattern_t> linpat(cairo_pattern_create_linear(maxWidth - fadingWidth,
3561
 
                                                                        y, maxWidth, y),
 
3595
    std::shared_ptr<cairo_pattern_t> linpat(cairo_pattern_create_linear(width - fading_width, y, width, y),
3562
3596
                                            cairo_pattern_destroy);
3563
3597
    cairo_pattern_add_color_stop_rgba(linpat.get(), 0, 0, 0, 0, 1);
3564
3598
    cairo_pattern_add_color_stop_rgba(linpat.get(), 1, 0, 0, 0, 0);
3566
3600
  }
3567
3601
  else
3568
3602
  {
3569
 
    pango_cairo_show_layout(context.cr_, layout);
 
3603
    gtk_render_layout(style_context, context.cr_, x, y, layout);
3570
3604
  }
 
3605
 
 
3606
  gtk_style_context_restore(style_context);
3571
3607
}
3572
3608
 
3573
 
void
3574
 
UnityWindow::DrawWindowDecoration(GLWindowPaintAttrib const& attrib,
3575
 
                                  GLMatrix const& transform,
3576
 
                                  unsigned int mask,
3577
 
                                  bool highlighted,
3578
 
                                  int x, int y, unsigned width, unsigned height)
 
3609
void UnityWindow::DrawWindowDecoration(GLWindowPaintAttrib const& attrib,
 
3610
                                       GLMatrix const& transform,
 
3611
                                       unsigned int mask,
 
3612
                                       bool highlighted,
 
3613
                                       int x, int y, unsigned width, unsigned height)
3579
3614
{
3580
3615
  // Paint a fake window decoration
3581
3616
  CairoContext context(width, height);
3582
3617
 
3583
3618
  cairo_save(context.cr_);
 
3619
 
 
3620
  // Draw window decoration based on gtk style
3584
3621
  cairo_push_group(context.cr_);
 
3622
  auto& style = panel::Style::Instance();
 
3623
  gtk_render_background(style.GetStyleContext(), context.cr_, 0, 0, width, height);
 
3624
  gtk_render_frame(style.GetStyleContext(), context.cr_, 0, 0, width, height);
 
3625
  cairo_pop_group_to_source(context.cr_);
3585
3626
 
3586
3627
  // Round window decoration top border
3587
 
  const double aspect = 1.0;
3588
 
  const double corner_radius = height / 10.0;
3589
 
  const double radius = corner_radius / aspect;
3590
 
  const double degrees = M_PI / 180.0;
 
3628
  const double aspect = ScaleWindow::get(window)->getCurrentPosition().scale;
 
3629
  const double radius = 8.0 * aspect;
3591
3630
 
3592
3631
  cairo_new_sub_path(context.cr_);
3593
 
 
3594
 
  cairo_arc(context.cr_, radius, radius, radius, 180 * degrees, 270 * degrees);
3595
 
  cairo_arc(context.cr_, width - radius, radius, radius, -90 * degrees, 0 * degrees);
 
3632
  cairo_line_to(context.cr_, 0, height);
 
3633
  cairo_arc(context.cr_, radius, radius, radius, M_PI, -M_PI * 0.5f);
 
3634
  cairo_line_to(context.cr_, width - radius, 0);
 
3635
  cairo_arc(context.cr_, width - radius, radius, radius, M_PI * 0.5f, 0);
3596
3636
  cairo_line_to(context.cr_, width, height);
3597
 
  cairo_line_to(context.cr_, 0, height);
3598
 
 
3599
3637
  cairo_close_path(context.cr_);
3600
 
  cairo_clip(context.cr_);
3601
 
 
3602
 
  // Draw window decoration based on gtk style
3603
 
  auto& style = panel::Style::Instance();
3604
 
  gtk_render_background(style.GetStyleContext(), context.cr_, 0, 0, width, height);
3605
 
  gtk_render_frame(style.GetStyleContext(), context.cr_, 0, 0, width, height);
3606
 
 
3607
 
  cairo_pop_group_to_source(context.cr_);
3608
 
 
3609
 
  cairo_paint_with_alpha(context.cr_, 1.0);
 
3638
 
 
3639
  cairo_fill(context.cr_);
 
3640
 
3610
3641
  cairo_restore(context.cr_);
3611
3642
 
3612
3643
  if (highlighted)
3613
3644
  {
3614
3645
    // Draw windows title
3615
3646
    const float xText = SCALE_ITEMS_PADDING * 2 + SCALE_CLOSE_ICON_SIZE;
3616
 
    RenderText(context, xText, 0.0, width - xText - SCALE_ITEMS_PADDING, height);
 
3647
    RenderText(context, xText, 0.0, width - SCALE_ITEMS_PADDING, height);
3617
3648
  }
3618
3649
 
3619
3650
  mask |= PAINT_WINDOW_BLEND_MASK;
3620
 
  int maxWidth, maxHeight;
3621
 
 
3622
 
  for (GLTexture *icon : context.texture_)
3623
 
    DrawTexture(icon, attrib, transform, mask, x, y, maxWidth , maxHeight);
 
3651
  DrawTexture(context.texture_, attrib, transform, mask, x, y);
3624
3652
}
3625
3653
 
3626
3654
void UnityWindow::LoadCloseIcon(panel::WindowState state, GLTexture::List& texture)
3631
3659
  auto& style = panel::Style::Instance();
3632
3660
  auto const& files = style.GetWindowButtonFileNames(panel::WindowButtonType::CLOSE, state);
3633
3661
 
3634
 
  CompString pName("unityshell");
 
3662
  CompString plugin("unityshell");
3635
3663
  for (std::string const& file : files)
3636
3664
  {
3637
 
    CompString fileName(file.c_str());
 
3665
    CompString file_name = file;
3638
3666
    CompSize size(SCALE_CLOSE_ICON_SIZE, SCALE_CLOSE_ICON_SIZE);
3639
 
    texture = GLTexture::readImageToTexture(fileName, pName, size);
 
3667
    texture = GLTexture::readImageToTexture(file_name, plugin, size);
3640
3668
    if (!texture.empty())
3641
3669
      break;
3642
3670
  }
3649
3677
    else if (state == panel::WindowState::PRESSED)
3650
3678
      suffix = "_pressed";
3651
3679
 
3652
 
    CompString fileName((PKGDATADIR"/close_dash" + suffix + ".png").c_str());
 
3680
    CompString file_name(PKGDATADIR"/close_dash" + suffix + ".png");
3653
3681
    CompSize size(SCALE_CLOSE_ICON_SIZE, SCALE_CLOSE_ICON_SIZE);
3654
 
    texture = GLTexture::readImageToTexture(fileName, pName, size);
 
3682
    texture = GLTexture::readImageToTexture(file_name, plugin, size);
3655
3683
  }
3656
3684
}
3657
3685
 
3658
 
void UnityWindow::SetupScaleHeaderStyle()
 
3686
void UnityWindow::SetupSharedTextures()
3659
3687
{
3660
3688
  LoadCloseIcon(panel::WindowState::NORMAL, close_normal_tex_);
3661
3689
  LoadCloseIcon(panel::WindowState::PRELIGHT, close_prelight_tex_);
3662
3690
  LoadCloseIcon(panel::WindowState::PRESSED, close_pressed_tex_);
3663
3691
}
3664
3692
 
 
3693
void UnityWindow::CleanupSharedTextures()
 
3694
{
 
3695
  close_normal_tex_.clear();
 
3696
  close_prelight_tex_.clear();
 
3697
  close_pressed_tex_.clear();
 
3698
}
 
3699
 
3665
3700
void UnityWindow::scalePaintDecoration(GLWindowPaintAttrib const& attrib,
3666
3701
                                       GLMatrix const& transform,
3667
3702
                                       CompRegion const& region,
3668
3703
                                       unsigned int mask)
3669
3704
{
3670
3705
  ScaleWindow *scale_win = ScaleWindow::get(window);
3671
 
  if (!scale_win)
3672
 
    return;
3673
 
 
3674
3706
  scale_win->scalePaintDecoration(attrib, transform, region, mask);
3675
3707
 
3676
3708
  if (!scale_win->hasSlot()) // animation not finished
3677
3709
    return;
3678
3710
 
3679
3711
  ScaleScreen* ss = ScaleScreen::get(screen);
 
3712
  auto state = ss->getState();
 
3713
 
 
3714
  if (state != ScaleScreen::Wait && state != ScaleScreen::Out)
 
3715
    return;
 
3716
 
 
3717
  auto const& scaled_geo = GetScaledGeometry();
 
3718
  auto const& decoration_extents = window->border();
 
3719
  auto const& pos = scale_win->getCurrentPosition();
 
3720
 
3680
3721
  const bool highlighted = (ss->getSelectedWindow() == window->id());
3681
 
 
3682
 
  ScalePosition const& pos = scale_win->getCurrentPosition();
3683
 
  auto const& border_rect = window->borderRect();
3684
 
  auto const& deco_ext = window->border();
3685
 
 
3686
 
  const unsigned decoration_height = deco_ext.top;
3687
 
  unsigned width = (border_rect.width() + deco_ext.left + deco_ext.right)  * pos.scale;
3688
 
  unsigned height = decoration_height * pos.scale;
3689
 
  int x = pos.x() + border_rect.x();
3690
 
  int y = pos.y() + border_rect.y() + decoration_height - height - 1;
3691
 
 
3692
 
  // If window is highlighted, we draw the decoration at full size
3693
 
  if (highlighted)
3694
 
    height = decoration_height;
 
3722
  int width = scaled_geo.width;
 
3723
  int height = decoration_extents.top;
 
3724
  int x = scaled_geo.x;
 
3725
  int y = scaled_geo.y;
 
3726
 
 
3727
 
 
3728
  // If window is not highlighted, we draw the decoration at scaled size
 
3729
  if (!highlighted)
 
3730
    height *= pos.scale;
3695
3731
 
3696
3732
  DrawWindowDecoration(attrib, transform, mask, highlighted, x, y, width, height);
3697
3733
 
3699
3735
  {
3700
3736
    x += SCALE_ITEMS_PADDING;
3701
3737
    y += (height - SCALE_CLOSE_ICON_SIZE) / 2.0f;
3702
 
    int max_height = 0;
3703
 
    int max_width = 0;
3704
3738
    mask |= PAINT_WINDOW_BLEND_MASK;
3705
3739
 
3706
 
    switch(close_icon_state_)
 
3740
    switch (close_icon_state_)
3707
3741
    {
3708
3742
      case panel::WindowState::NORMAL:
3709
3743
      default:
3710
 
        for (GLTexture *icon : close_normal_tex_)
3711
 
          DrawTexture(icon, attrib, transform, mask, x, y, max_width , max_height);
 
3744
        DrawTexture(close_normal_tex_, attrib, transform, mask, x, y);
3712
3745
        break;
3713
3746
 
3714
3747
      case panel::WindowState::PRELIGHT:
3715
 
        for (GLTexture *icon : close_prelight_tex_)
3716
 
          DrawTexture(icon, attrib, transform, mask, x, y, max_width , max_height);
 
3748
        DrawTexture(close_prelight_tex_, attrib, transform, mask, x, y);
3717
3749
        break;
3718
3750
 
3719
3751
      case panel::WindowState::PRESSED:
3720
 
        for (GLTexture *icon : close_pressed_tex_)
3721
 
          DrawTexture(icon, attrib, transform, mask, x, y, max_width , max_height);
 
3752
        DrawTexture(close_pressed_tex_, attrib, transform, mask, x, y);
3722
3753
        break;
3723
3754
    }
3724
3755
 
3725
 
    close_button_geo_.Set(x, y, max_height, max_width);
 
3756
    close_button_geo_.Set(x, y, SCALE_CLOSE_ICON_SIZE, SCALE_CLOSE_ICON_SIZE);
3726
3757
  }
3727
3758
  else if (!close_button_geo_.IsNull())
3728
3759
  {
3730
3761
  }
3731
3762
}
3732
3763
 
 
3764
nux::Geometry UnityWindow::GetScaledGeometry()
 
3765
{
 
3766
  ScaleWindow *scale_win = ScaleWindow::get(window);
 
3767
 
 
3768
  ScalePosition const& pos = scale_win->getCurrentPosition();
 
3769
  auto const& border_rect = window->borderRect();
 
3770
  auto const& deco_ext = window->border();
 
3771
 
 
3772
  const unsigned width = std::floor(border_rect.width() * pos.scale);
 
3773
  const unsigned height = std::floor(border_rect.height() * pos.scale);
 
3774
  const int x = pos.x() + window->x() - std::floor(deco_ext.left * pos.scale);
 
3775
  const int y = pos.y() + window->y() - std::floor(deco_ext.top * pos.scale);
 
3776
 
 
3777
  return nux::Geometry(x, y, width, height);
 
3778
}
 
3779
 
3733
3780
void UnityWindow::OnInitiateSpreed()
3734
3781
{
3735
 
  auto const& windows = screen->windows();
3736
 
  if (std::find(windows.begin(), windows.end(), window) == windows.end())
3737
 
    return;
3738
 
 
3739
3782
  close_icon_state_ = panel::WindowState::NORMAL;
3740
 
  SetupScaleHeaderStyle();
 
3783
  middle_clicked_ = false;
 
3784
  SetupSharedTextures();
3741
3785
 
3742
3786
  WindowManager *wm = WindowManager::Default();
3743
3787
  Window xid = window->id();
3748
3792
 
3749
3793
void UnityWindow::OnTerminateSpreed()
3750
3794
{
3751
 
  auto const& windows = screen->windows();
3752
 
  if (std::find(windows.begin(), windows.end(), window) == windows.end())
3753
 
    return;
3754
 
 
3755
3795
  WindowManager *wm = WindowManager::Default();
3756
3796
  Window xid = window->id();
3757
3797
 
3813
3853
  return true;
3814
3854
}
3815
3855
 
 
3856
namespace debug
 
3857
{
 
3858
 
 
3859
ScreenIntrospection::ScreenIntrospection(CompScreen* screen)
 
3860
  : screen_(screen)
 
3861
{}
 
3862
 
 
3863
std::string ScreenIntrospection::GetName() const
 
3864
{
 
3865
  return "Screen";
 
3866
}
 
3867
 
 
3868
void ScreenIntrospection::AddProperties(GVariantBuilder* builder)
 
3869
{}
 
3870
 
 
3871
Introspectable::IntrospectableList ScreenIntrospection::GetIntrospectableChildren()
 
3872
{
 
3873
  IntrospectableList children;
 
3874
 
 
3875
  for (auto const& win : screen_->windows())
 
3876
    children.push_back(UnityWindow::get(win));
 
3877
 
 
3878
  return children;
 
3879
}
 
3880
 
 
3881
} // debug namespace
 
3882
 
3816
3883
namespace
3817
3884
{
3818
3885