3458
3482
WindowManager::Default()->terminate_spread.connect(sigc::mem_fun(this, &UnityWindow::OnTerminateSpreed));
3462
UnityWindow::DrawTexture(GLTexture* icon,
3463
const GLWindowPaintAttrib& attrib,
3464
const GLMatrix& transform,
3467
int &maxWidth, int &maxHeight)
3485
void UnityWindow::AddProperties(GVariantBuilder* builder)
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();
3492
variant::BuilderWrapper(builder)
3493
.add(scaled ? GetScaledGeometry() : wm->GetWindowGeometry(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);
3503
std::string UnityWindow::GetName() const
3508
void UnityWindow::DrawTexture(GLTexture::List const& textures, GLWindowPaintAttrib const& attrib,
3509
GLMatrix const& transform, unsigned int mask, int x, int y)
3511
for (auto const& texture : textures)
3472
width = icon->width();
3473
height = icon->height();
3475
if (height > maxHeight)
3478
if (width > maxWidth)
3481
CompRegion iconReg(0, 0, width, height);
3482
GLTexture::MatrixList ml(1);
3484
ml[0] = icon->matrix();
3485
3516
gWindow->vertexBuffer()->begin();
3486
if (width && height)
3487
gWindow->glAddGeometry(ml, iconReg, iconReg);
3518
if (texture->width() && texture->height())
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);
3489
3526
if (gWindow->vertexBuffer()->end())
3491
3528
GLMatrix wTransform(transform);
3493
3529
wTransform.translate(x, y, 0.0f);
3495
gWindow->glDrawTexture(icon, wTransform, attrib, mask);
3531
gWindow->glDrawTexture(texture, wTransform, attrib, mask);
3501
UnityWindow::RenderText(UnityWindow::CairoContext const& context,
3503
float maxWidth, float maxHeight)
3536
void UnityWindow::RenderText(CairoContext const& context, int x, int y, int width, int height)
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);
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);
3512
3545
pango_layout_set_font_description(layout, font.get());
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();
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);
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(),
3559
pango_layout_set_text(layout, win_title.c_str(), -1);
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_,
3564
GtkStyleContext* style_context = style.GetStyleContext();
3565
gtk_style_context_save(style_context);
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");
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);
3539
3577
PangoRectangle lRect;
3540
int textWidth, textHeight;
3542
pango_layout_get_extents(layout, NULL, &lRect);
3543
textWidth = lRect.width / PANGO_SCALE;
3544
textHeight = lRect.height / PANGO_SCALE;
3546
y = ((maxHeight - textHeight) / 2.0) + y;
3547
cairo_translate(context.cr_, x, y);
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;
3584
if (text_width > text_space)
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;
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_);
3560
std::shared_ptr<cairo_pattern_t> linpat(cairo_pattern_create_linear(maxWidth - fadingWidth,
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);
3569
pango_cairo_show_layout(context.cr_, layout);
3603
gtk_render_layout(style_context, context.cr_, x, y, layout);
3606
gtk_style_context_restore(style_context);
3574
UnityWindow::DrawWindowDecoration(GLWindowPaintAttrib const& attrib,
3575
GLMatrix const& transform,
3578
int x, int y, unsigned width, unsigned height)
3609
void UnityWindow::DrawWindowDecoration(GLWindowPaintAttrib const& attrib,
3610
GLMatrix const& transform,
3613
int x, int y, unsigned width, unsigned height)
3580
3615
// Paint a fake window decoration
3581
3616
CairoContext context(width, height);
3583
3618
cairo_save(context.cr_);
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_);
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;
3592
3631
cairo_new_sub_path(context.cr_);
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);
3599
3637
cairo_close_path(context.cr_);
3600
cairo_clip(context.cr_);
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);
3607
cairo_pop_group_to_source(context.cr_);
3609
cairo_paint_with_alpha(context.cr_, 1.0);
3639
cairo_fill(context.cr_);
3610
3641
cairo_restore(context.cr_);
3612
3643
if (highlighted)
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);
3619
3650
mask |= PAINT_WINDOW_BLEND_MASK;
3620
int maxWidth, maxHeight;
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);
3626
3654
void UnityWindow::LoadCloseIcon(panel::WindowState state, GLTexture::List& texture)
3649
3677
else if (state == panel::WindowState::PRESSED)
3650
3678
suffix = "_pressed";
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);
3658
void UnityWindow::SetupScaleHeaderStyle()
3686
void UnityWindow::SetupSharedTextures()
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_);
3693
void UnityWindow::CleanupSharedTextures()
3695
close_normal_tex_.clear();
3696
close_prelight_tex_.clear();
3697
close_pressed_tex_.clear();
3665
3700
void UnityWindow::scalePaintDecoration(GLWindowPaintAttrib const& attrib,
3666
3701
GLMatrix const& transform,
3667
3702
CompRegion const& region,
3668
3703
unsigned int mask)
3670
3705
ScaleWindow *scale_win = ScaleWindow::get(window);
3674
3706
scale_win->scalePaintDecoration(attrib, transform, region, mask);
3676
3708
if (!scale_win->hasSlot()) // animation not finished
3679
3711
ScaleScreen* ss = ScaleScreen::get(screen);
3712
auto state = ss->getState();
3714
if (state != ScaleScreen::Wait && state != ScaleScreen::Out)
3717
auto const& scaled_geo = GetScaledGeometry();
3718
auto const& decoration_extents = window->border();
3719
auto const& pos = scale_win->getCurrentPosition();
3680
3721
const bool highlighted = (ss->getSelectedWindow() == window->id());
3682
ScalePosition const& pos = scale_win->getCurrentPosition();
3683
auto const& border_rect = window->borderRect();
3684
auto const& deco_ext = window->border();
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;
3692
// If window is highlighted, we draw the decoration at full size
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;
3728
// If window is not highlighted, we draw the decoration at scaled size
3730
height *= pos.scale;
3696
3732
DrawWindowDecoration(attrib, transform, mask, highlighted, x, y, width, height);
3700
3736
x += SCALE_ITEMS_PADDING;
3701
3737
y += (height - SCALE_CLOSE_ICON_SIZE) / 2.0f;
3704
3738
mask |= PAINT_WINDOW_BLEND_MASK;
3706
switch(close_icon_state_)
3740
switch (close_icon_state_)
3708
3742
case panel::WindowState::NORMAL:
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);
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);
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);
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);
3727
3758
else if (!close_button_geo_.IsNull())