Merge pull request #1 from Alexays/master

Integrate changes from Alexays/Waybar
This commit is contained in:
Marc Radau 2020-01-19 16:08:46 +01:00 committed by GitHub
commit bd67c9e620
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 255 additions and 149 deletions

View File

@ -30,12 +30,12 @@ class Client {
const std::string &style) const;
void bindInterfaces();
const std::string getValidPath(const std::vector<std::string> &paths) const;
void handleOutput(std::unique_ptr<struct waybar_output> &output);
bool isValidOutput(const Json::Value &config, std::unique_ptr<struct waybar_output> &output);
void handleOutput(struct waybar_output &output);
bool isValidOutput(const Json::Value &config, struct waybar_output &output);
auto setupConfig(const std::string &config_file) -> void;
auto setupCss(const std::string &css_file) -> void;
std::unique_ptr<struct waybar_output> &getOutput(void *);
std::vector<Json::Value> getOutputConfigs(std::unique_ptr<struct waybar_output> &output);
struct waybar_output &getOutput(void *);
std::vector<Json::Value> getOutputConfigs(struct waybar_output &output);
static void handleGlobal(void *data, struct wl_registry *registry, uint32_t name,
const char *interface, uint32_t version);
@ -47,7 +47,7 @@ class Client {
Json::Value config_;
Glib::RefPtr<Gtk::StyleContext> style_context_;
Glib::RefPtr<Gtk::CssProvider> css_provider_;
std::vector<std::unique_ptr<struct waybar_output>> outputs_;
std::list<struct waybar_output> outputs_;
};
} // namespace waybar

View File

@ -36,6 +36,7 @@ class MPD : public ALabel {
bool stopped();
bool playing();
bool paused();
const std::string module_name_;

View File

@ -34,6 +34,7 @@ class Pulseaudio : public ALabel {
pa_cvolume pa_volume_;
bool muted_;
std::string port_name_;
std::string form_factor_;
std::string desc_;
std::string monitor_;
// SOURCE

View File

@ -36,6 +36,10 @@ The *backlight* module displays the current backlight level.
typeof: string ++
Command to execute when the module is clicked.
*on-click-middle*: ++
typeof: string ++
Command to execute when middle-clicked on the module using mousewheel.
*on-click-right* ++
typeof: string ++
Command to execute when the module is right clicked.

View File

@ -37,32 +37,36 @@ The *battery* module displays the current capacity and state (eg. charging) of y
default: {H} h {M} min ++
The format, how the time should be displayed.
*format-icons*
typeof: array/object
*format-icons*: ++
typeof: array/object ++
Based on the current capacity, the corresponding icon gets selected. ++
The order is *low* to *high*. Or by the state if it is an object.
*max-length* ++
*max-length*: ++
typeof: integer++
The maximum length in character the module should display.
*rotate* ++
*rotate*: ++
typeof: integer++
Positive value to rotate the text label.
*on-click* ++
*on-click*: ++
typeof: string ++
Command to execute when clicked on the module.
*on-click-middle*: ++
typeof: string ++
Command to execute when middle-clicked on the module using mousewheel.
*on-click-right* ++
typeof: string ++
Command to execute when you right clicked on the module.
*on-scroll-up* ++
*on-scroll-up*: ++
typeof: string ++
Command to execute when scrolling up on the module.
*on-scroll-down* ++
*on-scroll-down*: ++
typeof: string ++
Command to execute when scrolling down on the module.

View File

@ -32,6 +32,10 @@ The *clock* module displays the current date and time.
typeof: string ++
Command to execute when clicked on the module.
*on-click-middle*: ++
typeof: string ++
Command to execute when middle-clicked on the module using mousewheel.
*on-click-right*: ++
typeof: string ++
Command to execute when you right clicked on the module.

View File

@ -36,6 +36,10 @@ The *cpu* module displays the current cpu utilization.
typeof: string ++
Command to execute when clicked on the module.
*on-click-middle*: ++
typeof: string ++
Command to execute when middle-clicked on the module using mousewheel.
*on-click-right*: ++
typeof: string ++
Command to execute when you right clicked on the module.

View File

@ -59,6 +59,10 @@ Addressed by *custom/<name>*
typeof: string ++
Command to execute when clicked on the module.
*on-click-middle*: ++
typeof: string ++
Command to execute when middle-clicked on the module using mousewheel.
*on-click-right*: ++
typeof: string ++
Command to execute when you right clicked on the module.

View File

@ -39,6 +39,10 @@ Addressed by *disk*
typeof: string ++
Command to execute when clicked on the module.
*on-click-middle*: ++
typeof: string ++
Command to execute when middle-clicked on the module using mousewheel.
*on-click-right*: ++
typeof: string ++
Command to execute when you right clicked on the module.

View File

@ -31,6 +31,10 @@ screensaving, also known as "presentation mode".
typeof: string ++
Command to execute when clicked on the module. A click also toggles the state
*on-click-middle*: ++
typeof: string ++
Command to execute when middle-clicked on the module using mousewheel.
*on-click-right*: ++
typeof: string ++
Command to execute when you right clicked on the module.

View File

@ -38,6 +38,10 @@ Addressed by *memory*
typeof: string ++
Command to execute when clicked on the module.
*on-click-middle*: ++
typeof: string ++
Command to execute when middle-clicked on the module using mousewheel.
*on-click-right*: ++
typeof: string ++
Command to execute when you right clicked on the module.

View File

@ -38,13 +38,17 @@ Addressed by *mpd*
*format*: ++
typeof: string ++
default: "{album} - {artist} - {title}" ++
Information displayed when a song is playing or paused
Information displayed when a song is playing.
*format-stopped*: ++
typeof: string ++
default: "stopped" ++
Information displayed when the player is stopped.
*format-paused*: ++
typeof: string ++
This format is used when a song is paused.
*format-disconnected*: ++
typeof: string ++
default: "disconnected" ++
@ -77,6 +81,10 @@ Addressed by *mpd*
typeof: string ++
Command to execute when clicked on the module.
*on-click-middle*: ++
typeof: string ++
Command to execute when middle-clicked on the module using mousewheel.
*on-click-right*: ++
typeof: string ++
Command to execute when you right clicked on the module.

View File

@ -21,6 +21,11 @@ Addressed by *network*
default: 60 ++
The interval in which the network information gets polled (e.g. signal strength).
*family*: ++
typeof: string ++
default: *ipv4* ++
The address family that is used for the format replacement {ipaddr} and to determine if a network connection is present.
*format*: ++
typeof: string ++
default: *{ifname}* ++
@ -42,6 +47,11 @@ Addressed by *network*
typeof: string ++
This format is used when the displayed interface is disconnected.
*format-icons*: ++
typeof: array/object ++
Based on the current signal strength, the corresponding icon gets selected. ++
The order is *low* to *high*. Or by the state if it is an object.
*rotate*: ++
typeof: integer ++
Positive value to rotate the text label.
@ -54,6 +64,10 @@ Addressed by *network*
typeof: string ++
Command to execute when clicked on the module.
*on-click-middle*: ++
typeof: string ++
Command to execute when middle-clicked on the module using mousewheel.
*on-click-right*: ++
typeof: string ++
Command to execute when you right clicked on the module.
@ -117,6 +131,8 @@ Addressed by *network*
*{bandwidthDownOctets}*: Instant down speed in octets/seconds.
*{icon}*: Icon, as defined in *format-icons*.
# EXAMPLES
```

View File

@ -59,6 +59,10 @@ Additionally you can control the volume by scrolling *up* or *down* while the cu
typeof: string ++
Command to execute when clicked on the module.
*on-click-middle*: ++
typeof: string ++
Command to execute when middle-clicked on the module using mousewheel.
*on-click-right*: ++
typeof: string ++
Command to execute when you right clicked on the module.

View File

@ -29,6 +29,10 @@ Addressed by *sway/mode*
typeof: string ++
Command to execute when clicked on the module.
*on-click-middle*: ++
typeof: string ++
Command to execute when middle-clicked on the module using mousewheel.
*on-click-right*: ++
typeof: string ++
Command to execute when you right clicked on the module.

View File

@ -29,6 +29,10 @@ Addressed by *sway/window*
typeof: string ++
Command to execute when clicked on the module.
*on-click-middle*: ++
typeof: string ++
Command to execute when middle-clicked on the module using mousewheel.
*on-click-right*: ++
typeof: string ++
Command to execute when you right clicked on the module.

View File

@ -54,6 +54,10 @@ Addressed by *temperature*
typeof: string ++
Command to execute when you clicked on the module.
*on-click-middle*: ++
typeof: string ++
Command to execute when middle-clicked on the module using mousewheel.
*on-click-right*: ++
typeof: string ++
Command to execute when you right clicked on the module.

View File

@ -23,7 +23,8 @@ Also a minimal example configuration can be found on the at the bottom of this m
*layer* ++
typeof: string ++
default: bottom ++
Decide if the bar is displayed in front of the windows or behind them.
Decide if the bar is displayed in front (*top*) of the windows or behind (*bottom*)
them.
*output* ++
typeof: string|array ++
@ -66,6 +67,12 @@ Also a minimal example configuration can be found on the at the bottom of this m
typeof: string ++
Optional name added as a CSS class, for styling multiple waybars.
*gtk-layer-shell* ++
typeof: bool ++
default: true ++
Option to disable the use of gtk-layer-shell for popups.
Only functional if compiled with gtk-layer-shell support.
# MODULE FORMAT
You can use PangoMarkupFormat (See https://developer.gnome.org/pango/stable/PangoMarkupFormat.html#PangoMarkupFormat).

View File

@ -31,7 +31,9 @@
<property name='Id' type='s' access='read'/>
<property name='Title' type='s' access='read'/>
<property name='Status' type='s' access='read'/>
<!-- See discussion on pull #536
<property name='WindowId' type='u' access='read'/>
-->
<property name='IconThemePath' type='s' access='read'/>
<property name='IconName' type='s' access='read'/>
<property name='IconPixmap' type='a(iiay)' access='read'/>

View File

@ -49,7 +49,7 @@ void waybar::Client::handleGlobalRemove(void * data, struct wl_registry * /*re
// Nothing here
}
void waybar::Client::handleOutput(std::unique_ptr<struct waybar_output> &output) {
void waybar::Client::handleOutput(struct waybar_output &output) {
static const struct zxdg_output_v1_listener xdgOutputListener = {
.logical_position = [](void *, struct zxdg_output_v1 *, int32_t, int32_t) {},
.logical_size = [](void *, struct zxdg_output_v1 *, int32_t, int32_t) {},
@ -58,42 +58,39 @@ void waybar::Client::handleOutput(std::unique_ptr<struct waybar_output> &output)
.description = [](void *, struct zxdg_output_v1 *, const char *) {},
};
// owned by output->monitor; no need to destroy
auto wl_output = gdk_wayland_monitor_get_wl_output(output->monitor->gobj());
output->xdg_output.reset(zxdg_output_manager_v1_get_xdg_output(xdg_output_manager, wl_output));
zxdg_output_v1_add_listener(output->xdg_output.get(), &xdgOutputListener, output.get());
auto wl_output = gdk_wayland_monitor_get_wl_output(output.monitor->gobj());
output.xdg_output.reset(zxdg_output_manager_v1_get_xdg_output(xdg_output_manager, wl_output));
zxdg_output_v1_add_listener(output.xdg_output.get(), &xdgOutputListener, &output);
}
bool waybar::Client::isValidOutput(const Json::Value & config,
std::unique_ptr<struct waybar_output> &output) {
bool waybar::Client::isValidOutput(const Json::Value &config, struct waybar_output &output) {
bool found = true;
if (config["output"].isArray()) {
bool in_array = false;
for (auto const &output_conf : config["output"]) {
if (output_conf.isString() && output_conf.asString() == output->name) {
if (output_conf.isString() && output_conf.asString() == output.name) {
in_array = true;
break;
}
}
found = in_array;
}
if (config["output"].isString() && config["output"].asString() != output->name) {
if (config["output"].isString() && config["output"].asString() != output.name) {
found = false;
}
return found;
}
std::unique_ptr<struct waybar::waybar_output> &waybar::Client::getOutput(void *addr) {
auto it = std::find_if(outputs_.begin(), outputs_.end(), [&addr](const auto &output) {
return output.get() == addr;
});
struct waybar::waybar_output &waybar::Client::getOutput(void *addr) {
auto it = std::find_if(
outputs_.begin(), outputs_.end(), [&addr](const auto &output) { return &output == addr; });
if (it == outputs_.end()) {
throw std::runtime_error("Unable to find valid output");
}
return *it;
}
std::vector<Json::Value> waybar::Client::getOutputConfigs(
std::unique_ptr<struct waybar_output> &output) {
std::vector<Json::Value> waybar::Client::getOutputConfigs(struct waybar_output &output) {
std::vector<Json::Value> configs;
if (config_.isArray()) {
for (auto const &config : config_) {
@ -112,18 +109,18 @@ void waybar::Client::handleOutputName(void * data, struct zxdg_output_v1 *
auto client = waybar::Client::inst();
try {
auto &output = client->getOutput(data);
output->name = name;
output.name = name;
spdlog::debug("Output detected: {} ({} {})",
name,
output->monitor->get_manufacturer(),
output->monitor->get_model());
output.monitor->get_manufacturer(),
output.monitor->get_model());
auto configs = client->getOutputConfigs(output);
if (configs.empty()) {
output->xdg_output.reset();
output.xdg_output.reset();
} else {
wl_display_roundtrip(client->wl_display);
for (const auto &config : configs) {
client->bars.emplace_back(std::make_unique<Bar>(output.get(), config));
client->bars.emplace_back(std::make_unique<Bar>(&output, config));
Glib::RefPtr<Gdk::Screen> screen = client->bars.back()->window.get_screen();
client->style_context_->add_provider_for_screen(
screen, client->css_provider_, GTK_STYLE_PROVIDER_PRIORITY_USER);
@ -135,7 +132,8 @@ void waybar::Client::handleOutputName(void * data, struct zxdg_output_v1 *
}
void waybar::Client::handleMonitorAdded(Glib::RefPtr<Gdk::Monitor> monitor) {
auto &output = outputs_.emplace_back(new struct waybar_output({monitor}));
auto &output = outputs_.emplace_back();
output.monitor = monitor;
handleOutput(output);
}
@ -151,9 +149,7 @@ void waybar::Client::handleMonitorRemoved(Glib::RefPtr<Gdk::Monitor> monitor) {
++it;
}
}
std::remove_if(outputs_.begin(), outputs_.end(), [&monitor](const auto &output) {
return output->monitor == monitor;
});
outputs_.remove_if([&monitor](const auto &output) { return output.monitor == monitor; });
}
std::tuple<const std::string, const std::string> waybar::Client::getConfigs(

View File

@ -140,7 +140,9 @@ void waybar::modules::MPD::setLabel() {
if (playing()) {
label_.get_style_context()->add_class("playing");
label_.get_style_context()->remove_class("paused");
} else {
} else if (paused()) {
format =
config_["format-paused"].isString() ? config_["format-paused"].asString() : config_["format"].asString();
label_.get_style_context()->add_class("paused");
label_.get_style_context()->remove_class("playing");
}
@ -346,3 +348,5 @@ bool waybar::modules::MPD::stopped() {
}
bool waybar::modules::MPD::playing() { return connection_ != nullptr && state_ == MPD_STATE_PLAY; }
bool waybar::modules::MPD::paused() { return connection_ != nullptr && state_ == MPD_STATE_PAUSE; }

View File

@ -2,6 +2,7 @@
#include <spdlog/spdlog.h>
#include <sys/eventfd.h>
#include <fstream>
#include <cassert>
#include "util/format.hpp"
@ -439,7 +440,6 @@ out:
}
void waybar::modules::Network::getInterfaceAddress() {
unsigned int cidrRaw;
struct ifaddrs *ifaddr, *ifa;
cidr_ = 0;
int success = getifaddrs(&ifaddr);
@ -451,19 +451,35 @@ void waybar::modules::Network::getInterfaceAddress() {
if (ifa->ifa_addr != nullptr && ifa->ifa_addr->sa_family == family_ &&
ifa->ifa_name == ifname_) {
char ipaddr[INET6_ADDRSTRLEN];
ipaddr_ = inet_ntop(family_,
char netmask[INET6_ADDRSTRLEN];
unsigned int cidr = 0;
if (family_ == AF_INET) {
ipaddr_ = inet_ntop(AF_INET,
&reinterpret_cast<struct sockaddr_in *>(ifa->ifa_addr)->sin_addr,
ipaddr,
INET6_ADDRSTRLEN);
char netmask[INET6_ADDRSTRLEN];
INET_ADDRSTRLEN);
auto net_addr = reinterpret_cast<struct sockaddr_in *>(ifa->ifa_netmask);
netmask_ = inet_ntop(family_, &net_addr->sin_addr, netmask, INET6_ADDRSTRLEN);
cidrRaw = net_addr->sin_addr.s_addr;
unsigned int cidr = 0;
netmask_ = inet_ntop(AF_INET, &net_addr->sin_addr, netmask, INET_ADDRSTRLEN);
unsigned int cidrRaw = net_addr->sin_addr.s_addr;
while (cidrRaw) {
cidr += cidrRaw & 1;
cidrRaw >>= 1;
}
} else {
ipaddr_ = inet_ntop(AF_INET6,
&reinterpret_cast<struct sockaddr_in6 *>(ifa->ifa_addr)->sin6_addr,
ipaddr,
INET6_ADDRSTRLEN);
auto net_addr = reinterpret_cast<struct sockaddr_in6 *>(ifa->ifa_netmask);
netmask_ = inet_ntop(AF_INET6, &net_addr->sin6_addr, netmask, INET6_ADDRSTRLEN);
for (size_t i = 0; i < sizeof(net_addr->sin6_addr.s6_addr); ++i) {
unsigned char cidrRaw = net_addr->sin6_addr.s6_addr[i];
while (cidrRaw) {
cidr += cidrRaw & 1;
cidrRaw >>= 1;
}
}
}
cidr_ = cidr;
break;
}

View File

@ -158,6 +158,9 @@ void waybar::modules::Pulseaudio::sinkInfoCb(pa_context * /*context*/, const pa_
pa->desc_ = i->description;
pa->monitor_ = i->monitor_source_name;
pa->port_name_ = i->active_port != nullptr ? i->active_port->name : "Unknown";
if (auto ff = pa_proplist_gets(i->proplist, PA_PROP_DEVICE_FORM_FACTOR)) {
pa->form_factor_ = ff;
}
pa->dp.emit();
}
}
@ -185,7 +188,7 @@ static const std::array<std::string, 9> ports = {
};
const std::string waybar::modules::Pulseaudio::getPortIcon() const {
std::string nameLC = port_name_;
std::string nameLC = port_name_ + form_factor_;
std::transform(nameLC.begin(), nameLC.end(), nameLC.begin(), ::tolower);
for (auto const &port : ports) {
if (nameLC.find(port) != std::string::npos) {

View File

@ -265,7 +265,11 @@ void Item::updateImage() {
if (pixbuf->gobj() != nullptr) {
// An icon specified by path and filename may be the wrong size for
// the tray
pixbuf = pixbuf->scale_simple(icon_size, icon_size, Gdk::InterpType::INTERP_BILINEAR);
// Keep the aspect ratio and scale to make the height equal to icon_size
// If people have non square icons, assume they want it to grow in width not height
int width = icon_size * pixbuf->get_width() / pixbuf->get_height();
pixbuf = pixbuf->scale_simple(width, icon_size, Gdk::InterpType::INTERP_BILINEAR);
image.set(pixbuf);
}
} else {

View File

@ -5,6 +5,6 @@ source_url = https://github.com/fmtlib/fmt/archive/5.3.0.tar.gz
source_filename = fmt-5.3.0.tar.gz
source_hash = defa24a9af4c622a7134076602070b45721a43c51598c8456ec6f2c4dbb51c89
patch_url = https://wrapdb.mesonbuild.com/v1/projects/fmt/5.3.0/1/get_zip
patch_url = https://github.com/mesonbuild/fmt/releases/download/5.3.0-1/fmt.zip
patch_filename = fmt-5.3.0-1-wrap.zip
patch_hash = 18f21a3b8833949c35d4ac88a7059577d5fa24b98786e4b1b2d3d81bb811440f

View File

@ -5,6 +5,6 @@ source_url = https://github.com/gabime/spdlog/archive/v1.3.1.tar.gz
source_filename = v1.3.1.tar.gz
source_hash = 160845266e94db1d4922ef755637f6901266731c4cb3b30b45bf41efa0e6ab70
patch_url = https://wrapdb.mesonbuild.com/v1/projects/spdlog/1.3.1/1/get_zip
patch_url = https://github.com/mesonbuild/spdlog/releases/download/1.3.1-1/spdlog.zip
patch_filename = spdlog-1.3.1-1-wrap.zip
patch_hash = 715a0229781019b853d409cc0bf891ee4b9d3a17bec0cf87f4ad30b28bbecc87