Skip to content

Commit

Permalink
SpreadWidgets: add container for spread filter and new spread decorat…
Browse files Browse the repository at this point in the history
…ions

Now when windows are spread, launcher and panel aren't "naked" anymore (LP: #1283314)
  • Loading branch information
3v1n0 authored and Bileto Bot committed Aug 17, 2016
2 parents 68e1f58 + fee9bf0 commit 42caeae
Show file tree
Hide file tree
Showing 6 changed files with 272 additions and 15 deletions.
3 changes: 3 additions & 0 deletions panel/PanelView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,9 @@ void PanelView::SetMonitor(int monitor)
menu_view_->SetMonitor(monitor);
indicators_->SetMonitor(monitor);
Resize();

if (WindowManager::Default().IsScaleActive())
EnableOverlayMode(true);
}

void PanelView::Resize()
Expand Down
36 changes: 23 additions & 13 deletions plugins/unityshell/src/unityshell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,16 +570,16 @@ void UnityScreen::InitAltTabNextWindow()
void UnityScreen::OnInitiateSpread()
{
scale_just_activated_ = super_keypressed_;
spread_filter_ = std::make_shared<spread::Filter>();
spread_filter_->text.changed.connect([this] (std::string const& filter) {
spread_widgets_ = std::make_shared<spread::Widgets>();
spread_widgets_->GetFilter()->text.changed.connect([this] (std::string const& filter) {
if (filter.empty())
{
sScreen->relayoutSlots(CompMatch::emptyMatch);
}
else
{
CompMatch windows_match;
auto const& filtered_windows = spread_filter_->FilteredWindows();
auto const& filtered_windows = spread_widgets_->GetFilter()->FilteredWindows();

for (auto const& swin : sScreen->getWindows())
{
Expand Down Expand Up @@ -610,7 +610,7 @@ void UnityScreen::OnInitiateSpread()

void UnityScreen::OnTerminateSpread()
{
spread_filter_.reset();
spread_widgets_.reset();

for (auto const& swin : sScreen->getWindows())
UnityWindow::get(swin->window)->OnTerminateSpread();
Expand Down Expand Up @@ -1745,7 +1745,7 @@ void UnityScreen::compizDamageNux(CompRegion const& damage)
auto const& geo = NuxGeometryFromCompRect(r);
wt->PresentWindowsIntersectingGeometryOnThisFrame(geo);
}

auto const& launchers = launcher_controller_->launchers();

for (auto const& launcher : launchers)
Expand Down Expand Up @@ -1857,8 +1857,13 @@ void UnityScreen::handleEvent(XEvent* event)
}
if (wm.IsScaleActive())
{
if (spread_filter_ && spread_filter_->Visible())
skip_other_plugins = spread_filter_->GetAbsoluteGeometry().IsPointInside(event->xbutton.x_root, event->xbutton.y_root);
if (spread_widgets_)
{
auto const& spread_filter = spread_widgets_->GetFilter();

if (spread_filter && spread_filter->Visible())
skip_other_plugins = spread_filter->GetAbsoluteGeometry().IsPointInside(event->xbutton.x_root, event->xbutton.y_root);
}

if (!skip_other_plugins)
{
Expand Down Expand Up @@ -1941,8 +1946,13 @@ void UnityScreen::handleEvent(XEvent* event)
}
else if (wm.IsScaleActive())
{
if (spread_filter_ && spread_filter_->Visible())
skip_other_plugins = spread_filter_->GetAbsoluteGeometry().IsPointInside(event->xbutton.x_root, event->xbutton.y_root);
if (spread_widgets_)
{
auto const& spread_filter = spread_widgets_->GetFilter();

if (spread_filter && spread_filter->Visible())
skip_other_plugins = spread_filter->GetAbsoluteGeometry().IsPointInside(event->xbutton.x_root, event->xbutton.y_root);
}

if (!skip_other_plugins)
{
Expand Down Expand Up @@ -2018,12 +2028,12 @@ void UnityScreen::handleEvent(XEvent* event)
}
}

if (spread_filter_ && spread_filter_->Visible())
if (spread_widgets_ && spread_widgets_->GetFilter()->Visible())
{
if (key_sym == XK_Escape)
{
skip_other_plugins = true;
spread_filter_->text = "";
spread_widgets_->GetFilter()->text = "";
}
}

Expand Down Expand Up @@ -2072,7 +2082,7 @@ void UnityScreen::handleEvent(XEvent* event)
skip_other_plugins = true;
}

if (spread_filter_ && spread_filter_->Visible())
if (spread_widgets_ && spread_widgets_->GetFilter() && spread_widgets_->GetFilter()->Visible())
skip_other_plugins = false;

if (!skip_other_plugins &&
Expand Down Expand Up @@ -4777,7 +4787,7 @@ void ScreenIntrospection::AddProperties(debug::IntrospectionData& introspection)

Introspectable::IntrospectableList ScreenIntrospection::GetIntrospectableChildren()
{
IntrospectableList children({uScreen->spread_filter_.get()});
IntrospectableList children({uScreen->spread_widgets_ ? uScreen->spread_widgets_->GetFilter().get() : nullptr});

for (auto const& win : screen_->windows())
children.push_back(UnityWindow::get(win));
Expand Down
4 changes: 2 additions & 2 deletions plugins/unityshell/src/unityshell.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
#include "SwitcherController.h"
#include "SessionController.h"
#include "SessionDBusManager.h"
#include "SpreadFilter.h"
#include "SpreadWidgets.h"
#include "UBusWrapper.h"
#include "UnityshellPrivate.h"
#include "UnityShowdesktopHandler.h"
Expand Down Expand Up @@ -340,7 +340,7 @@ class UnityScreen :
ui::EdgeBarrierController::Ptr edge_barriers_;
debug::DebugDBusInterface debugger_;
std::unique_ptr<BGHash> bghash_;
spread::Filter::Ptr spread_filter_;
spread::Widgets::Ptr spread_widgets_;

/* Subscription for gestures that manipulate Unity launcher */
std::unique_ptr<nux::GesturesSubscription> gestures_sub_launcher_;
Expand Down
1 change: 1 addition & 0 deletions unity-shared/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ set (UNITY_SHARED_SOURCES
SearchBar.cpp
SearchBarSpinner.cpp
SpreadFilter.cpp
SpreadWidgets.cpp
StaticCairoText.cpp
TextureCache.cpp
TextInput.cpp
Expand Down
195 changes: 195 additions & 0 deletions unity-shared/SpreadWidgets.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright (C) 2016 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Marco Trevisan <marco@ubuntu.com>
*/

#include "SpreadWidgets.h"

#include "DashStyle.h"
#include "PanelStyle.h"
#include "RawPixel.h"
#include "SearchBar.h"
#include "UnitySettings.h"
#include "UScreen.h"

namespace unity
{
namespace spread
{
namespace
{
const RawPixel LEFT_CORNER_OFFSET = 10_em;
}

class Decorations : public nux::BaseWindow
{
public:
nux::Property<int> monitor;

Decorations(int monitor_)
: monitor(monitor_)
{
monitor.changed.connect(sigc::mem_fun(this, &Decorations::Update));
SetBackgroundColor(nux::color::Transparent);

Update(monitor);
PushToFront();
ShowWindow(true);
}

~Decorations()
{
ShowWindow(false);
object_destroyed.emit(this);
}

void Update(int monitor)
{
auto& settings = Settings::Instance();
auto abs_geo = UScreen::GetDefault()->GetMonitorGeometry(monitor);
int panel_height = panel::Style::Instance().PanelHeight(monitor);
int launcher_size = settings.LauncherSize(monitor);
scale_ = settings.em(monitor)->DPIScale();

if (settings.launcher_position() == LauncherPosition::LEFT)
{
abs_geo.x += launcher_size;
abs_geo.width -= launcher_size;
}
else
{
abs_geo.height -= launcher_size;
}

abs_geo.y += panel_height;
abs_geo.height -= panel_height;
SetGeometry(abs_geo);

auto& dash_style = dash::Style::Instance();
corner_tex_ = dash_style.GetDashTopLeftTile(scale_);
left_edge_tex_ = dash_style.GetDashLeftTile(scale_);
horizontal_tex_ = dash_style.GetDashTopTile(scale_);
}

void DrawContent(nux::GraphicsEngine& gfx_context, bool force_draw) override
{
auto const& geo = GetGeometry();
auto launcher_position = Settings::Instance().launcher_position();
int x_offset = 0;

nux::TexCoordXForm texxform;

if (launcher_position == LauncherPosition::LEFT)
{
// Corner
texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
texxform.SetWrap(nux::TEXWRAP_CLAMP_TO_BORDER, nux::TEXWRAP_CLAMP_TO_BORDER);

gfx_context.QRP_1Tex(0,
0,
corner_tex_->GetWidth(),
corner_tex_->GetHeight(),
corner_tex_->GetDeviceTexture(),
texxform,
nux::color::White);

x_offset = corner_tex_->GetWidth();
}

// Top Edge
texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);

gfx_context.QRP_1Tex(x_offset,
-LEFT_CORNER_OFFSET.CP(scale_),
geo.width - x_offset,
horizontal_tex_->GetHeight(),
horizontal_tex_->GetDeviceTexture(),
texxform,
nux::color::White);

if (launcher_position == LauncherPosition::LEFT)
{
// Left edge
texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);

gfx_context.QRP_1Tex(-LEFT_CORNER_OFFSET.CP(scale_),
corner_tex_->GetHeight(),
left_edge_tex_->GetWidth(),
geo.height,
left_edge_tex_->GetDeviceTexture(),
texxform,
nux::color::White);
}
else if (launcher_position == LauncherPosition::BOTTOM)
{
texxform.flip_v_coord = true;

// Bottom Edge
texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);

gfx_context.QRP_1Tex(0,
geo.height - horizontal_tex_->GetHeight() + LEFT_CORNER_OFFSET.CP(scale_),
geo.width,
horizontal_tex_->GetHeight(),
horizontal_tex_->GetDeviceTexture(),
texxform,
nux::color::White);
}
}

double scale_;
dash::BaseTexturePtr corner_tex_;
dash::BaseTexturePtr left_edge_tex_;
dash::BaseTexturePtr horizontal_tex_;
};


Widgets::Widgets()
: filter_(std::make_shared<Filter>())
{
auto const& uscreen = UScreen::GetDefault();
auto num_monitors = uscreen->GetPluggedMonitorsNumber();

for (auto i = 0; i < num_monitors; ++i)
decos_.push_back(std::make_shared<Decorations>(i));

uscreen->changed.connect(sigc::track_obj([this] (int, std::vector<nux::Geometry> const& monitors) {
auto num_monitors = monitors.size();
decos_.reserve(num_monitors);

while (decos_.size() < num_monitors)
decos_.emplace_back(std::make_shared<Decorations>(decos_.size()-1));

decos_.resize(num_monitors);
for (auto i = 0u; i < num_monitors; ++i)
{
decos_[i]->monitor = i;
decos_[i]->monitor.changed.emit(i);
}
}, *this));
}

Filter::Ptr Widgets::GetFilter() const
{
return filter_;
}

} // namespace spread
} // namespace unity
48 changes: 48 additions & 0 deletions unity-shared/SpreadWidgets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
/*
* Copyright (C) 2016 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Marco Trevisan <marco@ubuntu.com>
*/

#ifndef UNITYSHELL_SPREAD_WIDGETS_H
#define UNITYSHELL_SPREAD_WIDGETS_H

#include "SpreadFilter.h"

namespace unity
{
namespace spread
{
class Decorations;

class Widgets : public sigc::trackable
{
public:
typedef std::shared_ptr<Widgets> Ptr;

Widgets();

Filter::Ptr GetFilter() const;

private:
Filter::Ptr filter_;
std::vector<std::shared_ptr<Decorations>> decos_;
};

} // namespace spread
} // namespace unity

#endif

0 comments on commit 42caeae

Please sign in to comment.