diff --git a/src/panel/widgets/window-list/toplevel.cpp b/src/panel/widgets/window-list/toplevel.cpp index 59ffcfb6..2c0d7ef1 100644 --- a/src/panel/widgets/window-list/toplevel.cpp +++ b/src/panel/widgets/window-list/toplevel.cpp @@ -53,12 +53,16 @@ class WayfireToplevel::impl zwlr_foreign_toplevel_handle_v1_add_listener(handle, &toplevel_handle_v1_impl, this); + static constexpr auto SIZE_LIMIT_COEF = 0.01; + Gdk::Rectangle monitor_rect; + window_list->output->monitor->get_geometry(monitor_rect); + label.set_max_width_chars(monitor_rect.get_width() * SIZE_LIMIT_COEF); + label.set_ellipsize(Pango::EllipsizeMode::ELLIPSIZE_END); button_contents.add(image); button_contents.add(label); button_contents.set_halign(Gtk::ALIGN_START); button_contents.set_spacing(5); button.add(button_contents); - button.set_tooltip_text("none"); button.signal_clicked().connect_notify( sigc::mem_fun(this, &WayfireToplevel::impl::on_clicked)); @@ -265,7 +269,7 @@ class WayfireToplevel::impl void on_allocation_changed(Gtk::Allocation& alloc) { send_rectangle_hint(); - window_list->scrolled_window.queue_allocate(); + window_list->box.queue_allocate(); } void on_scale_update() @@ -304,60 +308,10 @@ class WayfireToplevel::impl panel->get_wl_surface(), x, y, width, height); } - int32_t max_width = 0; void set_title(std::string title) { - this->title = title; button.set_tooltip_text(title); - - set_max_width(max_width); - } - - Glib::ustring shorten_title(int show_chars) - { - if (show_chars == 0) - return ""; - - int title_len = title.length(); - Glib::ustring short_title = title.substr(0, show_chars); - if (title_len - show_chars >= 2) { - short_title += ".."; - } else if (title_len != show_chars) { - short_title += "."; - } - - return short_title; - } - - int get_button_preferred_width() - { - int min_width, preferred_width; - button.get_preferred_width(min_width, preferred_width); - - return preferred_width; - } - - void set_max_width(int width) - { - this->max_width = width; - if (max_width == 0) - { - this->button.set_size_request(-1, -1); - this->label.set_label(title); - return; - } - - this->button.set_size_request(width, -1); - - int show_chars = 0; - for (show_chars = title.length(); show_chars > 0; show_chars--) - { - this->label.set_text(shorten_title(show_chars)); - if (get_button_preferred_width() <= max_width) - break; - } - - label.set_text(shorten_title(show_chars)); + label.set_text(title); } uint32_t get_state() @@ -450,7 +404,6 @@ WayfireToplevel::WayfireToplevel(WayfireWindowList *window_list, zwlr_foreign_toplevel_handle_v1 *handle) :pimpl(new WayfireToplevel::impl(window_list, handle)) { } -void WayfireToplevel::set_width(int pixels) { return pimpl->set_max_width(pixels); } std::vector& WayfireToplevel::get_children() { return pimpl->get_children(); } zwlr_foreign_toplevel_handle_v1 * WayfireToplevel::get_parent() { return pimpl->get_parent(); } void WayfireToplevel::set_parent(zwlr_foreign_toplevel_handle_v1 *parent) { return pimpl->set_parent(parent); } diff --git a/src/panel/widgets/window-list/toplevel.hpp b/src/panel/widgets/window-list/toplevel.hpp index d923512d..2969a455 100644 --- a/src/panel/widgets/window-list/toplevel.hpp +++ b/src/panel/widgets/window-list/toplevel.hpp @@ -27,7 +27,6 @@ class WayfireToplevel WayfireToplevel(WayfireWindowList *window_list, zwlr_foreign_toplevel_handle_v1 *handle); uint32_t get_state(); - void set_width(int pixels); zwlr_foreign_toplevel_handle_v1 * get_parent(); void set_parent(zwlr_foreign_toplevel_handle_v1 *); std::vector& get_children(); diff --git a/src/panel/widgets/window-list/window-list.cpp b/src/panel/widgets/window-list/window-list.cpp index 7d1d8532..61eed83d 100644 --- a/src/panel/widgets/window-list/window-list.cpp +++ b/src/panel/widgets/window-list/window-list.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -6,9 +7,7 @@ #include "window-list.hpp" #include "panel.hpp" -WayfireWindowListBox::WayfireWindowListBox() : Gtk::HBox() -{ -} +WayfireWindowListBox::WayfireWindowListBox() = default; void WayfireWindowListBox::set_top_widget(Gtk::Widget *top) { @@ -116,8 +115,6 @@ Gtk::Widget* WayfireWindowListBox::get_widget_at(int x) return nullptr; } -#define DEFAULT_SIZE_PC 0.1 - static void handle_manager_toplevel(void *data, zwlr_foreign_toplevel_manager_v1 *manager, zwlr_foreign_toplevel_handle_v1 *toplevel) { @@ -178,64 +175,9 @@ void WayfireWindowList::init(Gtk::HBox *container) zwlr_foreign_toplevel_manager_v1_add_listener(manager, &toplevel_manager_v1_impl, this); - scrolled_window.signal_draw().connect_notify( - sigc::mem_fun(this, &WayfireWindowList::on_draw)); - box.set_homogeneous(true); - scrolled_window.add(box); - scrolled_window.set_propagate_natural_width(true); - container->pack_start(scrolled_window, true, true); - scrolled_window.show_all(); -} - -void WayfireWindowList::set_button_width(int width) -{ - std::cout << "set width " << width << std::endl; - for (auto& toplevel : toplevels) - { - if (toplevel.second) - toplevel.second->set_width(width); - } -} - -int WayfireWindowList::get_default_button_width() -{ - return DEFAULT_SIZE_PC * - WayfirePanelApp::get().panel_for_wl_output(output->wo)->get_window() - .get_allocated_width(); -} - -int WayfireWindowList::get_target_button_width() -{ - int num_children = box.get_children().size(); - int target_width = get_default_button_width(); - - if (num_children > 0) - { - target_width = std::min(target_width, - scrolled_window.get_allocated_width() / num_children); - std::cout << "target button " << scrolled_window.get_allocated_width() << std::endl; - } - - return target_width; -} - -void WayfireWindowList::on_draw(const Cairo::RefPtr& ctx) -{ - int allocated_width = scrolled_window.get_allocated_width(); - - int minimal_width, preferred_width; - scrolled_window.get_preferred_width(minimal_width, preferred_width); - - /* We have changed the size/number of toplevels. On top of that, our list - * is longer that the max size, so we need to re-layout the buttons */ - if (preferred_width > allocated_width && toplevels.size() > 0) - set_button_width(get_target_button_width()); -} - -void WayfireWindowList::add_output(WayfireOutput *output) -{ - std::unique_ptr(); + box.show_all(); + container->pack_start(box, true, true); } void WayfireWindowList::handle_toplevel_manager(zwlr_foreign_toplevel_manager_v1 *manager) @@ -245,21 +187,12 @@ void WayfireWindowList::handle_toplevel_manager(zwlr_foreign_toplevel_manager_v1 void WayfireWindowList::handle_new_toplevel(zwlr_foreign_toplevel_handle_v1 *handle) { - toplevels[handle] = std::unique_ptr (new WayfireToplevel(this, handle)); - /* The size will be updated in the next on_draw() if needed */ - toplevels[handle]->set_width(get_default_button_width()); + toplevels[handle] = std::make_unique(this, handle); } void WayfireWindowList::handle_toplevel_closed(zwlr_foreign_toplevel_handle_v1 *handle) { toplevels.erase(handle); - - /* No size adjustments necessary in this case */ - if (toplevels.size() == 0) - return; - - /* Recalculate button size */ - set_button_width(get_target_button_width()); } WayfireWindowList::WayfireWindowList(WayfireOutput *output) diff --git a/src/panel/widgets/window-list/window-list.hpp b/src/panel/widgets/window-list/window-list.hpp index 06da8a12..d9250093 100644 --- a/src/panel/widgets/window-list/window-list.hpp +++ b/src/panel/widgets/window-list/window-list.hpp @@ -65,7 +65,6 @@ class WayfireWindowList : public WayfireWidget zwlr_foreign_toplevel_manager_v1 *manager; WayfireOutput *output; WayfireWindowListBox box; - Gtk::ScrolledWindow scrolled_window; WayfireWindowList(WayfireOutput *output); virtual ~WayfireWindowList(); @@ -77,14 +76,6 @@ class WayfireWindowList : public WayfireWidget wayfire_config *get_config(); void init(Gtk::HBox *container) override; - void add_output(WayfireOutput *output); - - private: - void on_draw(const Cairo::RefPtr&); - - void set_button_width(int width); - int get_default_button_width(); - int get_target_button_width(); }; #endif /* end of include guard: WIDGETS_WINDOW_LIST_HPP */