mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Merge pull request #956 from AndreasBackx/feature/output-identifier
Added waybar_output.identifier support. #602
This commit is contained in:
commit
bd208fcec6
@ -17,6 +17,7 @@ class Factory;
|
|||||||
struct waybar_output {
|
struct waybar_output {
|
||||||
Glib::RefPtr<Gdk::Monitor> monitor;
|
Glib::RefPtr<Gdk::Monitor> monitor;
|
||||||
std::string name;
|
std::string name;
|
||||||
|
std::string identifier;
|
||||||
|
|
||||||
std::unique_ptr<struct zxdg_output_v1, decltype(&zxdg_output_v1_destroy)> xdg_output = {
|
std::unique_ptr<struct zxdg_output_v1, decltype(&zxdg_output_v1_destroy)> xdg_output = {
|
||||||
nullptr, &zxdg_output_v1_destroy};
|
nullptr, &zxdg_output_v1_destroy};
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <wayland-client.h>
|
#include <wayland-client.h>
|
||||||
#include <wordexp.h>
|
#include <wordexp.h>
|
||||||
|
|
||||||
#include "bar.hpp"
|
#include "bar.hpp"
|
||||||
|
|
||||||
struct zwlr_layer_shell_v1;
|
struct zwlr_layer_shell_v1;
|
||||||
@ -44,7 +45,9 @@ class Client {
|
|||||||
static void handleGlobal(void *data, struct wl_registry *registry, uint32_t name,
|
static void handleGlobal(void *data, struct wl_registry *registry, uint32_t name,
|
||||||
const char *interface, uint32_t version);
|
const char *interface, uint32_t version);
|
||||||
static void handleGlobalRemove(void *data, struct wl_registry *registry, uint32_t name);
|
static void handleGlobalRemove(void *data, struct wl_registry *registry, uint32_t name);
|
||||||
|
static void handleOutputDone(void *, struct zxdg_output_v1 *);
|
||||||
static void handleOutputName(void *, struct zxdg_output_v1 *, const char *);
|
static void handleOutputName(void *, struct zxdg_output_v1 *, const char *);
|
||||||
|
static void handleOutputDescription(void *, struct zxdg_output_v1 *, const char *);
|
||||||
void handleMonitorAdded(Glib::RefPtr<Gdk::Monitor> monitor);
|
void handleMonitorAdded(Glib::RefPtr<Gdk::Monitor> monitor);
|
||||||
void handleMonitorRemoved(Glib::RefPtr<Gdk::Monitor> monitor);
|
void handleMonitorRemoved(Glib::RefPtr<Gdk::Monitor> monitor);
|
||||||
|
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
#include "client.hpp"
|
#include "client.hpp"
|
||||||
|
|
||||||
#include <fmt/ostream.h>
|
#include <fmt/ostream.h>
|
||||||
#include <spdlog/spdlog.h>
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "util/clara.hpp"
|
|
||||||
#include "util/json.hpp"
|
|
||||||
|
|
||||||
#include "idle-inhibit-unstable-v1-client-protocol.h"
|
#include "idle-inhibit-unstable-v1-client-protocol.h"
|
||||||
|
#include "util/clara.hpp"
|
||||||
|
#include "util/json.hpp"
|
||||||
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
|
#include "wlr-layer-shell-unstable-v1-client-protocol.h"
|
||||||
|
|
||||||
waybar::Client *waybar::Client::inst() {
|
waybar::Client *waybar::Client::inst() {
|
||||||
@ -58,9 +60,9 @@ void waybar::Client::handleOutput(struct waybar_output &output) {
|
|||||||
static const struct zxdg_output_v1_listener xdgOutputListener = {
|
static const struct zxdg_output_v1_listener xdgOutputListener = {
|
||||||
.logical_position = [](void *, struct zxdg_output_v1 *, int32_t, int32_t) {},
|
.logical_position = [](void *, struct zxdg_output_v1 *, int32_t, int32_t) {},
|
||||||
.logical_size = [](void *, struct zxdg_output_v1 *, int32_t, int32_t) {},
|
.logical_size = [](void *, struct zxdg_output_v1 *, int32_t, int32_t) {},
|
||||||
.done = [](void *, struct zxdg_output_v1 *) {},
|
.done = &handleOutputDone,
|
||||||
.name = &handleOutputName,
|
.name = &handleOutputName,
|
||||||
.description = [](void *, struct zxdg_output_v1 *, const char *) {},
|
.description = &handleOutputDescription,
|
||||||
};
|
};
|
||||||
// owned by output->monitor; no need to destroy
|
// owned by output->monitor; no need to destroy
|
||||||
auto wl_output = gdk_wayland_monitor_get_wl_output(output.monitor->gobj());
|
auto wl_output = gdk_wayland_monitor_get_wl_output(output.monitor->gobj());
|
||||||
@ -71,18 +73,20 @@ void waybar::Client::handleOutput(struct waybar_output &output) {
|
|||||||
bool waybar::Client::isValidOutput(const Json::Value &config, struct waybar_output &output) {
|
bool waybar::Client::isValidOutput(const Json::Value &config, struct waybar_output &output) {
|
||||||
if (config["output"].isArray()) {
|
if (config["output"].isArray()) {
|
||||||
for (auto const &output_conf : config["output"]) {
|
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 || output_conf.asString() == output.identifier)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} else if (config["output"].isString()) {
|
} else if (config["output"].isString()) {
|
||||||
auto config_output_name = config["output"].asString();
|
auto config_output = config["output"].asString();
|
||||||
if (!config_output_name.empty()) {
|
if (!config_output.empty()) {
|
||||||
if (config_output_name.substr(0, 1) == "!") {
|
if (config_output.substr(0, 1) == "!") {
|
||||||
return config_output_name.substr(1) != output.name;
|
return config_output.substr(1) != output.name &&
|
||||||
|
config_output.substr(1) != output.identifier;
|
||||||
}
|
}
|
||||||
return config_output_name == output.name;
|
return config_output == output.name || config_output == output.identifier;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,16 +116,12 @@ std::vector<Json::Value> waybar::Client::getOutputConfigs(struct waybar_output &
|
|||||||
return configs;
|
return configs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void waybar::Client::handleOutputName(void * data, struct zxdg_output_v1 * /*xdg_output*/,
|
void waybar::Client::handleOutputDone(void *data, struct zxdg_output_v1 * /*xdg_output*/) {
|
||||||
const char *name) {
|
|
||||||
auto client = waybar::Client::inst();
|
auto client = waybar::Client::inst();
|
||||||
try {
|
try {
|
||||||
auto &output = client->getOutput(data);
|
auto &output = client->getOutput(data);
|
||||||
output.name = name;
|
spdlog::debug("Output detection done: {} ({})", output.name, output.identifier);
|
||||||
spdlog::debug("Output detected: {} ({} {})",
|
|
||||||
name,
|
|
||||||
output.monitor->get_manufacturer(),
|
|
||||||
output.monitor->get_model());
|
|
||||||
auto configs = client->getOutputConfigs(output);
|
auto configs = client->getOutputConfigs(output);
|
||||||
if (configs.empty()) {
|
if (configs.empty()) {
|
||||||
output.xdg_output.reset();
|
output.xdg_output.reset();
|
||||||
@ -139,6 +139,32 @@ void waybar::Client::handleOutputName(void * data, struct zxdg_output_v1 *
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void waybar::Client::handleOutputName(void * data, struct zxdg_output_v1 * /*xdg_output*/,
|
||||||
|
const char *name) {
|
||||||
|
auto client = waybar::Client::inst();
|
||||||
|
try {
|
||||||
|
auto &output = client->getOutput(data);
|
||||||
|
output.name = name;
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void waybar::Client::handleOutputDescription(void *data, struct zxdg_output_v1 * /*xdg_output*/,
|
||||||
|
const char *description) {
|
||||||
|
auto client = waybar::Client::inst();
|
||||||
|
try {
|
||||||
|
auto & output = client->getOutput(data);
|
||||||
|
const char *open_paren = strrchr(description, '(');
|
||||||
|
|
||||||
|
// Description format: "identifier (name)"
|
||||||
|
size_t identifier_length = open_paren - description;
|
||||||
|
output.identifier = std::string(description, identifier_length - 1);
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void waybar::Client::handleMonitorAdded(Glib::RefPtr<Gdk::Monitor> monitor) {
|
void waybar::Client::handleMonitorAdded(Glib::RefPtr<Gdk::Monitor> monitor) {
|
||||||
auto &output = outputs_.emplace_back();
|
auto &output = outputs_.emplace_back();
|
||||||
output.monitor = monitor;
|
output.monitor = monitor;
|
||||||
@ -260,7 +286,8 @@ int waybar::Client::main(int argc, char *argv[]) {
|
|||||||
if (!log_level.empty()) {
|
if (!log_level.empty()) {
|
||||||
spdlog::set_level(spdlog::level::from_str(log_level));
|
spdlog::set_level(spdlog::level::from_str(log_level));
|
||||||
}
|
}
|
||||||
gtk_app = Gtk::Application::create(argc, argv, "fr.arouillard.waybar", Gio::APPLICATION_HANDLES_COMMAND_LINE);
|
gtk_app = Gtk::Application::create(
|
||||||
|
argc, argv, "fr.arouillard.waybar", Gio::APPLICATION_HANDLES_COMMAND_LINE);
|
||||||
gdk_display = Gdk::Display::get_default();
|
gdk_display = Gdk::Display::get_default();
|
||||||
if (!gdk_display) {
|
if (!gdk_display) {
|
||||||
throw std::runtime_error("Can't find display");
|
throw std::runtime_error("Can't find display");
|
||||||
|
Loading…
Reference in New Issue
Block a user