Skip to content

Visible separator #233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Apr 21, 2024
Merged
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
1 change: 1 addition & 0 deletions src/panel/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ widget_sources = ['widgets/battery.cpp',
'widgets/launchers.cpp',
'widgets/network.cpp',
'widgets/spacing.cpp',
'widgets/separator.cpp',
'widgets/window-list/window-list.cpp',
'widgets/window-list/toplevel.cpp',
'widgets/notifications/daemon.cpp',
Expand Down
35 changes: 24 additions & 11 deletions src/panel/panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "widgets/launchers.hpp"
#include "widgets/network.hpp"
#include "widgets/spacing.hpp"
#include "widgets/separator.hpp"
#ifdef HAVE_PULSE
#include "widgets/volume.hpp"
#endif
Expand Down Expand Up @@ -158,6 +159,23 @@ class WayfirePanel::impl
window->show_all();
}

std::optional<int> widget_with_value(std::string value, std::string prefix)
{
if (value.find(prefix) == 0)
{
auto output_str = value.substr(prefix.size());
int output = std::atoi(output_str.c_str());
if (output > 0)
{
return output;
}

std::cerr << "Invalid widget value: " << value << std::endl;
}

return {};
}

Widget widget_from_name(std::string name)
{
if (name == "menu")
Expand Down Expand Up @@ -216,19 +234,14 @@ class WayfirePanel::impl
return Widget(new WfCommandOutputButtons());
}

std::string spacing = "spacing";
if (name.find(spacing) == 0)
if (auto pixel = widget_with_value(name, "spacing"))
{
auto pixel_str = name.substr(spacing.size());
int pixel = std::atoi(pixel_str.c_str());

if (pixel <= 0)
{
std::cerr << "Invalid spacing, " << pixel << std::endl;
return nullptr;
}
return Widget(new WayfireSpacing(*pixel));
}

return Widget(new WayfireSpacing(pixel));
if (auto pixel = widget_with_value(name, "separator"))
{
return Widget(new WayfireSeparator(*pixel));
}

if (name != "none")
Expand Down
14 changes: 14 additions & 0 deletions src/panel/widgets/separator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "separator.hpp"

WayfireSeparator::WayfireSeparator(int pixels)
{
int half = pixels / 2;
separator.set_margin_start(half);
separator.set_margin_end(half);
}

void WayfireSeparator::init(Gtk::HBox *container)
{
container->pack_start(separator);
separator.show_all();
}
20 changes: 20 additions & 0 deletions src/panel/widgets/separator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef WIDGET_SEPARATOR_HPP
#define WIDGET_SEPARATOR_HPP

#include "../widget.hpp"
#include <gtkmm/separator.h>

class WayfireSeparator : public WayfireWidget
{
Gtk::Separator separator;

public:
WayfireSeparator(int pixels);

virtual void init(Gtk::HBox *container);
virtual ~WayfireSeparator()
{}
};


#endif /* end of include guard: WIDGET_SEPARATOR_HPP */
6 changes: 3 additions & 3 deletions wf-shell.ini.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ randomize = 0
# widgets_* is a space-separated list of widgets to be displayed
# at the corresponding part of the panel
# Supported widgets are: launchers clock network battery window-list volume menu notifications tray command-output
# A special widgets is spacing widgets, it can be used to add padding everywhere on the panel
# To use it, just append the amount of pixels you want as a padding
# to the word "spacing" and use it as a plugin
# Special widgets are "spacing" and "separator" widgets, they can be used to add padding everywhere on the panel
# To use them, just append the amount of pixels you want as a padding
# to the word "spacing" or "separator" and use it as a plugin
widgets_left = menu spacing4 launchers window-list
widgets_center = none
widgets_right = command-output tray notifications volume network battery clock
Expand Down