mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Compare commits
19 Commits
Author | SHA1 | Date | |
---|---|---|---|
e9b6380c18 | |||
43beefb00d | |||
12f869ccba | |||
7e9207d75c | |||
7a2dee7377 | |||
21a89ac46d | |||
bb99e6cf5b | |||
0834551161 | |||
ccd1586c65 | |||
617b370104 | |||
d607a4e33f | |||
a6c0bc5a52 | |||
67ad0e69ce | |||
ae88d6bc3c | |||
4f3c38c542 | |||
a6980fca7f | |||
bd5146fdcf | |||
22ddbde394 | |||
c916fe258e |
@ -10,7 +10,7 @@ namespace waybar {
|
|||||||
class ALabel : public AModule {
|
class ALabel : public AModule {
|
||||||
public:
|
public:
|
||||||
ALabel(const Json::Value &, const std::string &, const std::string &, const std::string &format,
|
ALabel(const Json::Value &, const std::string &, const std::string &, const std::string &format,
|
||||||
uint16_t interval = 0);
|
uint16_t interval = 0, bool ellipsize = false);
|
||||||
virtual ~ALabel() = default;
|
virtual ~ALabel() = default;
|
||||||
virtual auto update() -> void;
|
virtual auto update() -> void;
|
||||||
virtual std::string getIcon(uint16_t, const std::string &alt = "", uint16_t max = 0);
|
virtual std::string getIcon(uint16_t, const std::string &alt = "", uint16_t max = 0);
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <glibmm/refptr.h>
|
#include <glibmm/refptr.h>
|
||||||
|
#include <gtkmm/box.h>
|
||||||
#include <gtkmm/cssprovider.h>
|
#include <gtkmm/cssprovider.h>
|
||||||
#include <gtkmm/main.h>
|
#include <gtkmm/main.h>
|
||||||
#include <gtkmm/window.h>
|
#include <gtkmm/window.h>
|
||||||
#include <gtkmm/box.h>
|
|
||||||
#include <json/json.h>
|
#include <json/json.h>
|
||||||
#include "AModule.hpp"
|
#include "AModule.hpp"
|
||||||
#include "idle-inhibit-unstable-v1-client-protocol.h"
|
#include "idle-inhibit-unstable-v1-client-protocol.h"
|
||||||
@ -15,10 +15,10 @@ namespace waybar {
|
|||||||
|
|
||||||
class Factory;
|
class Factory;
|
||||||
struct waybar_output {
|
struct waybar_output {
|
||||||
struct wl_output * output;
|
struct wl_output * output = nullptr;
|
||||||
std::string name;
|
std::string name;
|
||||||
uint32_t wl_name;
|
uint32_t wl_name;
|
||||||
struct zxdg_output_v1 *xdg_output;
|
struct zxdg_output_v1 *xdg_output = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Bar {
|
class Bar {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
project(
|
project(
|
||||||
'waybar', 'cpp', 'c',
|
'waybar', 'cpp', 'c',
|
||||||
version: '0.7.0',
|
version: '0.7.2',
|
||||||
license: 'MIT',
|
license: 'MIT',
|
||||||
default_options : [
|
default_options : [
|
||||||
'cpp_std=c++17',
|
'cpp_std=c++17',
|
||||||
|
@ -140,5 +140,6 @@
|
|||||||
},
|
},
|
||||||
"escape": true,
|
"escape": true,
|
||||||
"exec": "$HOME/.config/waybar/mediaplayer.py 2> /dev/null" // Script in resources folder
|
"exec": "$HOME/.config/waybar/mediaplayer.py 2> /dev/null" // Script in resources folder
|
||||||
|
// "exec": "$HOME/.config/waybar/mediaplayer.py --player spotify 2> /dev/null" // Filter player based on name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ def on_metadata(player, metadata, manager):
|
|||||||
|
|
||||||
|
|
||||||
def on_player_appeared(manager, player, selected_player=None):
|
def on_player_appeared(manager, player, selected_player=None):
|
||||||
if player is not None and player.name == selected_player:
|
if player is not None and (selected_player is None or player.name == selected_player):
|
||||||
init_player(manager, player)
|
init_player(manager, player)
|
||||||
else:
|
else:
|
||||||
logger.debug("New player appeared, but it's not the selected player, skipping")
|
logger.debug("New player appeared, but it's not the selected player, skipping")
|
||||||
|
@ -36,7 +36,6 @@ window#waybar.chromium {
|
|||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* https://github.com/Alexays/Waybar/wiki/FAQ#the-workspace-buttons-have-a-strange-hover-effect */
|
|
||||||
#workspaces button {
|
#workspaces button {
|
||||||
padding: 0 5px;
|
padding: 0 5px;
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
@ -44,6 +43,13 @@ window#waybar.chromium {
|
|||||||
border-bottom: 3px solid transparent;
|
border-bottom: 3px solid transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* https://github.com/Alexays/Waybar/wiki/FAQ#the-workspace-buttons-have-a-strange-hover-effect */
|
||||||
|
#workspaces button:hover {
|
||||||
|
background: rgba(0, 0, 0, 0.2);
|
||||||
|
box-shadow: inherit;
|
||||||
|
border-bottom: 3px solid #ffffff;
|
||||||
|
}
|
||||||
|
|
||||||
#workspaces button.focused {
|
#workspaces button.focused {
|
||||||
background-color: #64727D;
|
background-color: #64727D;
|
||||||
border-bottom: 3px solid #ffffff;
|
border-bottom: 3px solid #ffffff;
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
namespace waybar {
|
namespace waybar {
|
||||||
|
|
||||||
ALabel::ALabel(const Json::Value& config, const std::string& name, const std::string& id,
|
ALabel::ALabel(const Json::Value& config, const std::string& name, const std::string& id,
|
||||||
const std::string& format, uint16_t interval)
|
const std::string& format, uint16_t interval, bool ellipsize)
|
||||||
: AModule(config, name, id, config["format-alt"].isString()),
|
: AModule(config, name, id, config["format-alt"].isString()),
|
||||||
format_(config_["format"].isString() ? config_["format"].asString() : format),
|
format_(config_["format"].isString() ? config_["format"].asString() : format),
|
||||||
interval_(config_["interval"] == "once"
|
interval_(config_["interval"] == "once"
|
||||||
@ -21,6 +21,8 @@ ALabel::ALabel(const Json::Value& config, const std::string& name, const std::st
|
|||||||
if (config_["max-length"].isUInt()) {
|
if (config_["max-length"].isUInt()) {
|
||||||
label_.set_max_width_chars(config_["max-length"].asUInt());
|
label_.set_max_width_chars(config_["max-length"].asUInt());
|
||||||
label_.set_ellipsize(Pango::EllipsizeMode::ELLIPSIZE_END);
|
label_.set_ellipsize(Pango::EllipsizeMode::ELLIPSIZE_END);
|
||||||
|
} else if (ellipsize && label_.get_max_width_chars() == -1) {
|
||||||
|
label_.set_ellipsize(Pango::EllipsizeMode::ELLIPSIZE_END);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config_["rotate"].isUInt()) {
|
if (config_["rotate"].isUInt()) {
|
||||||
|
12
src/bar.cpp
12
src/bar.cpp
@ -18,6 +18,8 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
|
|||||||
window.set_name("waybar");
|
window.set_name("waybar");
|
||||||
window.set_decorated(false);
|
window.set_decorated(false);
|
||||||
window.get_style_context()->add_class(output->name);
|
window.get_style_context()->add_class(output->name);
|
||||||
|
window.get_style_context()->add_class(config["name"].asString());
|
||||||
|
window.get_style_context()->add_class(config["position"].asString());
|
||||||
|
|
||||||
if (config["position"] == "right" || config["position"] == "left") {
|
if (config["position"] == "right" || config["position"] == "left") {
|
||||||
height_ = 0;
|
height_ = 0;
|
||||||
@ -302,9 +304,9 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos) {
|
|||||||
|
|
||||||
auto waybar::Bar::setupWidgets() -> void {
|
auto waybar::Bar::setupWidgets() -> void {
|
||||||
window.add(box_);
|
window.add(box_);
|
||||||
box_.pack_start(left_, true, true);
|
box_.pack_start(left_, false, false);
|
||||||
box_.set_center_widget(center_);
|
box_.set_center_widget(center_);
|
||||||
box_.pack_end(right_, true, true);
|
box_.pack_end(right_, false, false);
|
||||||
|
|
||||||
// Convert to button code for every module that is used.
|
// Convert to button code for every module that is used.
|
||||||
setupAltFormatKeyForModuleList("modules-left");
|
setupAltFormatKeyForModuleList("modules-left");
|
||||||
@ -316,13 +318,13 @@ auto waybar::Bar::setupWidgets() -> void {
|
|||||||
getModules(factory, "modules-center");
|
getModules(factory, "modules-center");
|
||||||
getModules(factory, "modules-right");
|
getModules(factory, "modules-right");
|
||||||
for (auto const& module : modules_left_) {
|
for (auto const& module : modules_left_) {
|
||||||
left_.pack_start(*module, false, true, 0);
|
left_.pack_start(*module, false, false);
|
||||||
}
|
}
|
||||||
for (auto const& module : modules_center_) {
|
for (auto const& module : modules_center_) {
|
||||||
center_.pack_start(*module, true, true, 0);
|
center_.pack_start(*module, false, false);
|
||||||
}
|
}
|
||||||
std::reverse(modules_right_.begin(), modules_right_.end());
|
std::reverse(modules_right_.begin(), modules_right_.end());
|
||||||
for (auto const& module : modules_right_) {
|
for (auto const& module : modules_right_) {
|
||||||
right_.pack_end(*module, false, false, 0);
|
right_.pack_end(*module, false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,8 +65,14 @@ void waybar::Client::handleGlobalRemove(void * data, struct wl_registry * /*re
|
|||||||
client->outputs_.end(),
|
client->outputs_.end(),
|
||||||
[&name](const auto &output) { return output->wl_name == name; });
|
[&name](const auto &output) { return output->wl_name == name; });
|
||||||
if (it != client->outputs_.end()) {
|
if (it != client->outputs_.end()) {
|
||||||
|
if ((*it)->xdg_output != nullptr) {
|
||||||
zxdg_output_v1_destroy((*it)->xdg_output);
|
zxdg_output_v1_destroy((*it)->xdg_output);
|
||||||
|
(*it)->xdg_output = nullptr;
|
||||||
|
}
|
||||||
|
if ((*it)->output != nullptr) {
|
||||||
wl_output_destroy((*it)->output);
|
wl_output_destroy((*it)->output);
|
||||||
|
(*it)->output = nullptr;
|
||||||
|
}
|
||||||
client->outputs_.erase(it);
|
client->outputs_.erase(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -151,8 +157,14 @@ void waybar::Client::handleName(void * data, struct zxdg_output_v1 * /*xdg_
|
|||||||
output->name = name;
|
output->name = name;
|
||||||
auto configs = client->getOutputConfigs(output);
|
auto configs = client->getOutputConfigs(output);
|
||||||
if (configs.empty()) {
|
if (configs.empty()) {
|
||||||
|
if (output->output != nullptr) {
|
||||||
wl_output_destroy(output->output);
|
wl_output_destroy(output->output);
|
||||||
|
output->output = nullptr;
|
||||||
|
}
|
||||||
|
if (output->xdg_output != nullptr) {
|
||||||
zxdg_output_v1_destroy(output->xdg_output);
|
zxdg_output_v1_destroy(output->xdg_output);
|
||||||
|
output->xdg_output = nullptr;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
wl_display_roundtrip(client->wl_display);
|
wl_display_roundtrip(client->wl_display);
|
||||||
for (const auto &config : configs) {
|
for (const auto &config : configs) {
|
||||||
|
@ -546,8 +546,7 @@ int waybar::modules::Network::getPreferredIface(int skip_idx) const {
|
|||||||
ifa = ifaddr;
|
ifa = ifaddr;
|
||||||
ifid = -1;
|
ifid = -1;
|
||||||
while (ifa != nullptr) {
|
while (ifa != nullptr) {
|
||||||
if (ifa->ifa_addr->sa_family == family_ &&
|
if (wildcardMatch(config_["interface"].asString(), ifa->ifa_name)) {
|
||||||
wildcardMatch(config_["interface"].asString(), ifa->ifa_name)) {
|
|
||||||
ifid = if_nametoindex(ifa->ifa_name);
|
ifid = if_nametoindex(ifa->ifa_name);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,8 @@ waybar::modules::Pulseaudio::Pulseaudio(const std::string &id, const Json::Value
|
|||||||
throw std::runtime_error("pa_mainloop_run() failed.");
|
throw std::runtime_error("pa_mainloop_run() failed.");
|
||||||
}
|
}
|
||||||
pa_threaded_mainloop_unlock(mainloop_);
|
pa_threaded_mainloop_unlock(mainloop_);
|
||||||
|
event_box_.add_events(Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK);
|
||||||
|
event_box_.signal_scroll_event().connect(sigc::mem_fun(*this, &Pulseaudio::handleScroll));
|
||||||
}
|
}
|
||||||
|
|
||||||
waybar::modules::Pulseaudio::~Pulseaudio() {
|
waybar::modules::Pulseaudio::~Pulseaudio() {
|
||||||
|
@ -10,7 +10,7 @@ Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config)
|
|||||||
host_(nb_hosts_, config, std::bind(&Tray::onAdd, this, std::placeholders::_1),
|
host_(nb_hosts_, config, std::bind(&Tray::onAdd, this, std::placeholders::_1),
|
||||||
std::bind(&Tray::onRemove, this, std::placeholders::_1)) {
|
std::bind(&Tray::onRemove, this, std::placeholders::_1)) {
|
||||||
spdlog::warn(
|
spdlog::warn(
|
||||||
"For a functionnal tray you must have libappindicator-* installed and export "
|
"For a functional tray you must have libappindicator-* installed and export "
|
||||||
"XDG_CURRENT_DESKTOP=Unity");
|
"XDG_CURRENT_DESKTOP=Unity");
|
||||||
box_.set_name("tray");
|
box_.set_name("tray");
|
||||||
event_box_.add(box_);
|
event_box_.add(box_);
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
|
|
||||||
namespace waybar::modules::sway {
|
namespace waybar::modules::sway {
|
||||||
|
|
||||||
Mode::Mode(const std::string& id, const Json::Value& config) : ALabel(config, "mode", id, "{}") {
|
Mode::Mode(const std::string& id, const Json::Value& config)
|
||||||
|
: ALabel(config, "mode", id, "{}", 0, true) {
|
||||||
ipc_.subscribe(R"(["mode"])");
|
ipc_.subscribe(R"(["mode"])");
|
||||||
ipc_.signal_event.connect(sigc::mem_fun(*this, &Mode::onEvent));
|
ipc_.signal_event.connect(sigc::mem_fun(*this, &Mode::onEvent));
|
||||||
// Launch worker
|
// Launch worker
|
||||||
|
@ -4,10 +4,7 @@
|
|||||||
namespace waybar::modules::sway {
|
namespace waybar::modules::sway {
|
||||||
|
|
||||||
Window::Window(const std::string& id, const Bar& bar, const Json::Value& config)
|
Window::Window(const std::string& id, const Bar& bar, const Json::Value& config)
|
||||||
: ALabel(config, "window", id, "{}"), bar_(bar), windowId_(-1) {
|
: ALabel(config, "window", id, "{}", 0, true), bar_(bar), windowId_(-1) {
|
||||||
if (label_.get_max_width_chars() == -1) {
|
|
||||||
label_.set_ellipsize(Pango::EllipsizeMode::ELLIPSIZE_END);
|
|
||||||
}
|
|
||||||
ipc_.subscribe(R"(["window","workspace"])");
|
ipc_.subscribe(R"(["window","workspace"])");
|
||||||
ipc_.signal_event.connect(sigc::mem_fun(*this, &Window::onEvent));
|
ipc_.signal_event.connect(sigc::mem_fun(*this, &Window::onEvent));
|
||||||
ipc_.signal_cmd.connect(sigc::mem_fun(*this, &Window::onCmd));
|
ipc_.signal_cmd.connect(sigc::mem_fun(*this, &Window::onCmd));
|
||||||
|
@ -218,6 +218,8 @@ bool Workspaces::handleScroll(GdkEventScroll *e) {
|
|||||||
if (dir == SCROLL_DIR::NONE) {
|
if (dir == SCROLL_DIR::NONE) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
std::string name;
|
||||||
|
{
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
auto it = std::find_if(workspaces_.begin(), workspaces_.end(), [](const auto &workspace) {
|
auto it = std::find_if(workspaces_.begin(), workspaces_.end(), [](const auto &workspace) {
|
||||||
return workspace["focused"].asBool();
|
return workspace["focused"].asBool();
|
||||||
@ -225,7 +227,6 @@ bool Workspaces::handleScroll(GdkEventScroll *e) {
|
|||||||
if (it == workspaces_.end()) {
|
if (it == workspaces_.end()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
std::string name;
|
|
||||||
if (dir == SCROLL_DIR::DOWN || dir == SCROLL_DIR::RIGHT) {
|
if (dir == SCROLL_DIR::DOWN || dir == SCROLL_DIR::RIGHT) {
|
||||||
name = getCycleWorkspace(it, false);
|
name = getCycleWorkspace(it, false);
|
||||||
} else if (dir == SCROLL_DIR::UP || dir == SCROLL_DIR::LEFT) {
|
} else if (dir == SCROLL_DIR::UP || dir == SCROLL_DIR::LEFT) {
|
||||||
@ -236,6 +237,7 @@ bool Workspaces::handleScroll(GdkEventScroll *e) {
|
|||||||
if (name == (*it)["name"].asString()) {
|
if (name == (*it)["name"].asString()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
ipc_.sendCmd(IPC_COMMAND, fmt::format("workspace \"{}\"", name));
|
ipc_.sendCmd(IPC_COMMAND, fmt::format("workspace \"{}\"", name));
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
|
Reference in New Issue
Block a user