Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions data/css/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
padding-left: 5px;
}

.wf-panel .window-button label {
padding-right: 5px;
}

.wf-panel .window-button.activated {
background-color: #8883;
}
Expand Down
8 changes: 5 additions & 3 deletions src/panel/panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,9 @@ class WayfirePanel::impl
(panel_position.value() == PANEL_POSITION_LEFT) ||
(panel_position.value() == PANEL_POSITION_RIGHT);

box.set_hexpand(!vertical);
box.set_vexpand(vertical);
const bool in_center = (&box == &center_box);
box.set_hexpand(!vertical && !in_center);
box.set_vexpand(vertical && !in_center);
}

auto widget = widget_from_name(widget_name);
Expand Down Expand Up @@ -398,7 +399,8 @@ class WayfirePanel::impl

left_box.set_hexpand(has_window_list(left_widgets_opt.value()));
right_box.set_hexpand(has_window_list(right_widgets_opt.value()));
center_box.set_hexpand(has_window_list(center_widgets_opt.value()));
center_box.set_hexpand(false);
center_box.set_vexpand(false);
}

WfOption<std::string> left_widgets_opt{"panel/widgets_left"};
Expand Down
146 changes: 86 additions & 60 deletions src/panel/widgets/window-list/layout.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
#include "toplevel.hpp"
#include "window-list.hpp"

#include <algorithm>
#include <cstdint>
#include <vector>

namespace
{
struct button_width_t
{
int minimum;
int natural;
};

button_width_t measure_button(const Gtk::Widget& child, int height, int maximum_width)
{
int minimum, natural, minimum_baseline, natural_baseline;
child.measure(Gtk::Orientation::HORIZONTAL, height,
minimum, natural, minimum_baseline, natural_baseline);

// Keep the existing square minimum and respect the button's CSS minimum.
minimum = std::max(minimum, std::max(height, 1));
natural = std::max(minimum, std::min(natural, maximum_width));
return {minimum, natural};
}
}

WayfireWindowListLayout::WayfireWindowListLayout(WayfireWindowList *window_list)
{
this->window_list = window_list;
Expand All @@ -10,74 +35,78 @@ void WayfireWindowListLayout::allocate_vfunc(const Gtk::Widget& widget,
int width, int height, int baseline)
{
Gtk::Widget& widget_not_const = const_cast<Gtk::Widget&>(widget);
int child_count = widget.get_children().size();
if (child_count <= 0)
auto children = widget_not_const.get_children();
if (children.empty())
{
return;
}

const bool vertical = window_list->is_vertical();
std::vector<button_width_t> widths;
int minimum_total = 0;
int natural_total = 0;

int per_child;

if (vertical)
{
// Keep window buttons square on a vertical panel.
per_child = width;
} else
if (!vertical)
{
per_child = width / child_count;

// user preference is ignored if too small
int preference = std::max(height, user_size.value());

// At minimum use ratio of 1:1, at max use user preference
per_child = std::max(per_child, height);
per_child = std::min(per_child, preference);
for (auto child : children)
{
auto measured = measure_button(*child, height, user_size.value());
widths.push_back(measured);
minimum_total += measured.minimum;
natural_total += measured.natural;
}
}

int index = 0;
auto alloc = Gtk::Allocation();
const int extra_total = natural_total - minimum_total;
const int available_extra = std::max(0,
std::min(width - minimum_total, extra_total));
int cumulative_extra = 0;
int allocated_extra = 0;
int offset = 0;
size_t index = 0;

if (vertical)
for (auto child : children)
{
alloc.set_width(width);
alloc.set_height(per_child);
alloc.set_x(0);
} else
{
alloc.set_height(height);
alloc.set_width(per_child);
alloc.set_y(0);
}
int size = width;
if (!vertical)
{
const auto& measured = widths[index];
cumulative_extra += measured.natural - measured.minimum;
// Share limited space in proportion to each button's content.
// Cumulative rounding ensures no pixels are lost between buttons.
int next_extra = extra_total > 0 ?
static_cast<int>(static_cast<int64_t>(available_extra) *
cumulative_extra / extra_total) : 0;
size = measured.minimum + next_extra - allocated_extra;
allocated_extra = next_extra;
}

for (auto child : widget_not_const.get_children())
{
int position = offset;
if (child == top_widget)
{
if (vertical)
{
alloc.set_y(top_position);
} else
{
alloc.set_x(top_position);
}

child->size_allocate(alloc, -1);
index++;
continue;
const int extent = vertical ? height : width;
position = std::max(0, std::min(top_position, extent - size));
}

auto alloc = Gtk::Allocation();
if (vertical)
{
alloc.set_y(per_child * index);
alloc.set_width(width);
alloc.set_height(size);
alloc.set_x(0);
alloc.set_y(position);
} else
{
alloc.set_x(per_child * index);
alloc.set_width(size);
alloc.set_height(height);
alloc.set_x(position);
alloc.set_y(0);
}

child->size_allocate(alloc, -1);
index++;
// Reserve the dragged button's own width in its logical position.
offset += size;
++index;
}

for (auto& t : window_list->toplevels)
Expand All @@ -93,35 +122,32 @@ void WayfireWindowListLayout::measure_vfunc(const Gtk::Widget& widget,
Gtk::Orientation orientation, int for_size, int& minimum, int& natural,
int& minimum_baseline, int& natural_baseline) const
{
int child_count = widget.get_children().size();

if (window_list->is_vertical())
{
if (orientation == Gtk::Orientation::VERTICAL)
{
int per_child = std::max(for_size, 1);

minimum = child_count * per_child;
minimum = widget.get_children().size() * per_child;
natural = minimum;
} else
{
minimum = 1;
natural = 1;
}
} else
} else if (orientation == Gtk::Orientation::HORIZONTAL)
{
if (orientation == Gtk::Orientation::HORIZONTAL)
minimum = 0;
natural = 0;
for (auto child : widget.get_children())
{
// Use max of user preference and ratio 1:1
int per_child = std::max(for_size, user_size.value());

minimum = child_count * for_size;
natural = per_child * child_count;
} else
{
minimum = 1;
natural = 1;
auto measured = measure_button(*child, for_size, user_size.value());
minimum += measured.minimum;
natural += measured.natural;
}
} else
{
minimum = 1;
natural = 1;
}

minimum_baseline = -1;
Expand Down
2 changes: 1 addition & 1 deletion src/panel/widgets/window-list/window-list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ WayfireWindowList::WayfireWindowList(WayfireOutput *output)
set_layout_manager(layout);
user_size.set_callback([=]
{
this->queue_allocate();
this->queue_resize();
});
}

Expand Down
Loading