Skip to content

Commit

Permalink
panel: add css classes to widgets (#239)
Browse files Browse the repository at this point in the history
* panel: add css classes to widgets

* panel: fix css collision on menu widget
  • Loading branch information
trigg authored Apr 21, 2024
1 parent f857efb commit 9a30c24
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/panel/panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class WayfirePanel::impl
{
window = std::make_unique<WayfireAutohidingWindow>(output, "panel");
window->set_size_request(1, minimal_panel_height);
window->get_style_context()->add_class("wf-panel");
panel_layer.set_callback(set_panel_layer);
set_panel_layer(); // initial setting

Expand Down Expand Up @@ -147,6 +148,9 @@ class WayfirePanel::impl

void init_layout()
{
left_box.get_style_context()->add_class("left");
center_box.get_style_context()->add_class("center");
right_box.get_style_context()->add_class("right");
content_box.pack_start(left_box, false, false);
content_box.pack_end(right_box, false, false);
if (!center_box.get_children().empty())
Expand Down
1 change: 1 addition & 0 deletions src/panel/widgets/battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ void WayfireBatteryInfo::init(Gtk::HBox *container)
}

button_box.add(icon);
button.get_style_context()->add_class("battery");
button.get_style_context()->add_class("flat");

status_opt.set_callback([=] () { update_details(); });
Expand Down
2 changes: 2 additions & 0 deletions src/panel/widgets/clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
void WayfireClock::init(Gtk::HBox *container)
{
button = std::make_unique<WayfireMenuButton>("panel");
button->get_style_context()->add_class("clock");
button->add(label);
button->show();
label.show();

update_label();

calendar.show();
button->get_popover()->get_style_context()->add_class("clock-popover");
button->get_popover()->add(calendar);
button->get_popover()->signal_show().connect_notify(
sigc::mem_fun(this, &WayfireClock::on_calendar_shown));
Expand Down
3 changes: 3 additions & 0 deletions src/panel/widgets/command-output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ WfCommandOutputButtons::CommandOutput::CommandOutput(const std::string & name,
set_image_icon(icon, icon_name, icon_size, {});
}

get_style_context()->add_class("command-output");

main_label.set_ellipsize(Pango::ELLIPSIZE_END);
main_label.set_max_width_chars(max_chars_opt);
max_chars_opt.set_callback([=]
Expand Down Expand Up @@ -138,6 +140,7 @@ WfCommandOutputButtons::CommandOutput::CommandOutput(const std::string & name,

void WfCommandOutputButtons::init(Gtk::HBox *container)
{
box.get_style_context()->add_class("command-output-box");
container->pack_start(box, false, false);
update_buttons();
commands_list_opt.set_callback([=] { update_buttons(); });
Expand Down
7 changes: 6 additions & 1 deletion src/panel/widgets/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "wf-autohide-window.hpp"

#define MAX_LAUNCHER_NAME_LENGTH 11
const std::string default_icon = ICONDIR "/wayfire.png";
const std::string default_icon = "wayfire";

WfMenuCategory::WfMenuCategory(std::string _name, std::string _icon_name) :
name(_name), icon_name(_icon_name)
Expand Down Expand Up @@ -832,6 +832,8 @@ void WayfireMenu::init(Gtk::HBox *container)
category_list["Hidden"] = std::make_unique<WfMenuCategory>("Other Desktops",
"user-desktop");

main_image.get_style_context()->add_class("menu-icon");

output->toggle_menu_signal().connect(sigc::mem_fun(this, &WayfireMenu::toggle_menu));

menu_icon.set_callback([=] () { update_icon(); });
Expand All @@ -842,6 +844,9 @@ void WayfireMenu::init(Gtk::HBox *container)

button = std::make_unique<WayfireMenuButton>("panel");
button->add(main_image);
auto style = button->get_style_context();
style->add_class("menu-button");
style->add_class("flat");
button->get_popover()->set_constrain_to(Gtk::POPOVER_CONSTRAINT_NONE);
button->get_popover()->signal_show().connect_notify(
sigc::mem_fun(this, &WayfireMenu::on_popover_shown));
Expand Down
4 changes: 4 additions & 0 deletions src/panel/widgets/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,10 @@ void WayfireNetworkInfo::init(Gtk::HBox *container)
return;
}

auto style = button.get_style_context();
style->add_class("flat");
style->add_class("network");

container->add(button);
button.add(button_content);
button.get_style_context()->add_class("flat");
Expand Down
1 change: 1 addition & 0 deletions src/panel/widgets/notifications/notification-center.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
void WayfireNotificationCenter::init(Gtk::HBox *container)
{
button = std::make_unique<WayfireMenuButton>("panel");
button->get_style_context()->add_class("notification-center");

updateIcon();
button->add(icon);
Expand Down
1 change: 1 addition & 0 deletions src/panel/widgets/spacing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ WayfireSpacing::WayfireSpacing(int pixels)

void WayfireSpacing::init(Gtk::HBox *container)
{
box.get_style_context()->add_class("spacing");
container->pack_start(box);
box.show_all();
}
3 changes: 3 additions & 0 deletions src/panel/widgets/tray/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ void StatusNotifierItem::init_widget()
icon_size.set_callback([this] { update_icon(); });
setup_tooltip();
init_menu();
auto style = get_style_context();
style->add_class("tray-box");
style->add_class("flat");

signal_button_press_event().connect([this] (GdkEventButton *ev) -> bool
{
Expand Down
1 change: 1 addition & 0 deletions src/panel/widgets/tray/tray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

void WayfireStatusNotifier::init(Gtk::HBox *container)
{
icons_hbox.get_style_context()->add_class("tray");
icons_hbox.set_spacing(5);
container->add(icons_hbox);
}
Expand Down
5 changes: 2 additions & 3 deletions src/panel/widgets/volume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,8 @@ void WayfireVolume::init(Gtk::HBox *container)
/* Setup button */
button = std::make_unique<WayfireMenuButton>("panel");
auto style = button->get_style_context();
style->context_save();
style->set_state(Gtk::STATE_FLAG_NORMAL & ~Gtk::STATE_FLAG_PRELIGHT);
button->reset_style();
style->add_class("volume");
style->add_class("flat");
button->set_events(Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK | Gdk::BUTTON_PRESS_MASK);
button->signal_scroll_event().connect_notify(
sigc::mem_fun(this, &WayfireVolume::on_volume_scroll));
Expand Down
1 change: 1 addition & 0 deletions src/panel/widgets/window-list/toplevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class WayfireToplevel::impl
zwlr_foreign_toplevel_handle_v1_add_listener(handle,
&toplevel_handle_v1_impl, this);

button.get_style_context()->add_class("window-button");
button_contents.add(image);
button_contents.add(label);
button_contents.set_halign(Gtk::ALIGN_START);
Expand Down
2 changes: 2 additions & 0 deletions src/panel/widgets/window-list/window-list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ void WayfireWindowList::init(Gtk::HBox *container)
return;
}

scrolled_window.get_style_context()->add_class("window-list");

wl_registry_destroy(registry);
zwlr_foreign_toplevel_manager_v1_add_listener(manager,
&toplevel_manager_v1_impl, this);
Expand Down

0 comments on commit 9a30c24

Please sign in to comment.