mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Merge branch 'master' into add-river-layout
This commit is contained in:
@ -15,6 +15,7 @@ class AModule : public IModule {
|
||||
bool enable_scroll = false);
|
||||
virtual ~AModule();
|
||||
virtual auto update() -> void;
|
||||
virtual auto refresh(int) -> void{};
|
||||
virtual operator Gtk::Widget &();
|
||||
|
||||
Glib::Dispatcher dp;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <json/json.h>
|
||||
#ifdef HAVE_LIBDATE
|
||||
#if defined(HAVE_CHRONO_TIMEZONES) || defined(HAVE_LIBDATE)
|
||||
#include "modules/clock.hpp"
|
||||
#else
|
||||
#include "modules/simpleclock.hpp"
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "ALabel.hpp"
|
||||
#include "giomm/dbusproxy.h"
|
||||
#include "util/json.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
|
||||
@ -50,6 +51,8 @@ class Backlight : public ALabel {
|
||||
template <class ForwardIt, class Inserter>
|
||||
static void enumerate_devices(ForwardIt first, ForwardIt last, Inserter inserter, udev *udev);
|
||||
|
||||
bool handleScroll(GdkEventScroll *e);
|
||||
|
||||
const std::string preferred_device_;
|
||||
static constexpr int EPOLL_MAX_EVENTS = 16;
|
||||
|
||||
@ -60,5 +63,7 @@ class Backlight : public ALabel {
|
||||
std::vector<BacklightDev> devices_;
|
||||
// thread must destruct before shared data
|
||||
util::SleeperThread udev_thread_;
|
||||
|
||||
Glib::RefPtr<Gio::DBus::Proxy> login_proxy_;
|
||||
};
|
||||
} // namespace waybar::modules
|
||||
|
@ -1,19 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <date/tz.h>
|
||||
|
||||
#include "ALabel.hpp"
|
||||
#include "util/date.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
|
||||
namespace waybar {
|
||||
|
||||
struct waybar_time;
|
||||
|
||||
namespace modules {
|
||||
namespace waybar::modules {
|
||||
|
||||
const std::string kCalendarPlaceholder = "calendar";
|
||||
const std::string KTimezonedTimeListPlaceholder = "timezoned_time_list";
|
||||
|
||||
enum class WeeksSide {
|
||||
LEFT,
|
||||
RIGHT,
|
||||
HIDDEN,
|
||||
};
|
||||
|
||||
enum class CldMode { MONTH, YEAR };
|
||||
|
||||
class Clock : public ALabel {
|
||||
public:
|
||||
Clock(const std::string&, const Json::Value&);
|
||||
@ -22,26 +25,37 @@ class Clock : public ALabel {
|
||||
|
||||
private:
|
||||
util::SleeperThread thread_;
|
||||
std::map<std::pair<uint, GdkEventType>, void (waybar::modules::Clock::*)()> eventMap_;
|
||||
std::locale locale_;
|
||||
std::vector<const date::time_zone*> time_zones_;
|
||||
int current_time_zone_idx_;
|
||||
date::year_month_day calendar_cached_ymd_{date::January / 1 / 0};
|
||||
date::months calendar_shift_{0}, calendar_shift_init_{0};
|
||||
std::string calendar_cached_text_;
|
||||
bool is_calendar_in_tooltip_;
|
||||
bool is_timezoned_list_in_tooltip_;
|
||||
|
||||
bool handleScroll(GdkEventScroll* e);
|
||||
bool handleToggle(GdkEventButton* const& e);
|
||||
|
||||
std::string fmt_str_weeks_;
|
||||
std::string fmt_str_calendar_;
|
||||
int fmt_weeks_left_pad_{0};
|
||||
auto calendar_text(const waybar_time& wtime) -> std::string;
|
||||
auto weekdays_header(const date::weekday& first_dow, std::ostream& os) -> void;
|
||||
auto first_day_of_week() -> date::weekday;
|
||||
const date::time_zone* current_timezone();
|
||||
bool is_timezone_fixed();
|
||||
auto timezones_text(std::chrono::system_clock::time_point* now) -> std::string;
|
||||
|
||||
/*Calendar properties*/
|
||||
WeeksSide cldWPos_{WeeksSide::HIDDEN};
|
||||
std::map<int, std::string const> fmtMap_;
|
||||
CldMode cldMode_{CldMode::MONTH};
|
||||
uint cldMonCols_{3}; // Count of the month in the row
|
||||
int cldMonColLen_{20}; // Length of the month column
|
||||
int cldWnLen_{3}; // Length of the week number
|
||||
date::year_month_day cldYearShift_;
|
||||
date::year_month cldMonShift_;
|
||||
date::months cldCurrShift_{0};
|
||||
date::months cldShift_{0};
|
||||
std::string cldYearCached_{};
|
||||
std::string cldMonCached_{};
|
||||
/*Calendar functions*/
|
||||
auto get_calendar(const date::zoned_seconds& now, const date::zoned_seconds& wtime)
|
||||
-> std::string;
|
||||
void cldModeSwitch();
|
||||
};
|
||||
} // namespace modules
|
||||
} // namespace waybar
|
||||
} // namespace waybar::modules
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "ALabel.hpp"
|
||||
#include "gtkmm/box.h"
|
||||
#include "util/command.hpp"
|
||||
#include "util/json.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
@ -15,7 +16,7 @@ namespace waybar::modules {
|
||||
|
||||
class Image : public AModule {
|
||||
public:
|
||||
Image(const std::string&, const std::string&, const Json::Value&);
|
||||
Image(const std::string&, const Json::Value&);
|
||||
auto update() -> void;
|
||||
void refresh(int /*signal*/);
|
||||
|
||||
@ -23,6 +24,7 @@ class Image : public AModule {
|
||||
void delayWorker();
|
||||
void handleEvent();
|
||||
|
||||
Gtk::Box box_;
|
||||
Gtk::Image image_;
|
||||
std::string path_;
|
||||
int size_;
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
#include "ipc.hpp"
|
||||
#include "util/sleeper_thread.hpp"
|
||||
|
@ -19,10 +19,11 @@ class Window : public AIconLabel, public sigc::trackable {
|
||||
auto update() -> void;
|
||||
|
||||
private:
|
||||
void setClass(std::string classname, bool enable);
|
||||
void onEvent(const struct Ipc::ipc_response&);
|
||||
void onCmd(const struct Ipc::ipc_response&);
|
||||
std::tuple<std::size_t, int, std::string, std::string, std::string, std::string> getFocusedNode(
|
||||
const Json::Value& nodes, std::string& output);
|
||||
std::tuple<std::size_t, int, int, std::string, std::string, std::string, std::string, std::string>
|
||||
getFocusedNode(const Json::Value& nodes, std::string& output);
|
||||
void getTree();
|
||||
void updateAppIconName();
|
||||
void updateAppIcon();
|
||||
@ -32,12 +33,14 @@ class Window : public AIconLabel, public sigc::trackable {
|
||||
int windowId_;
|
||||
std::string app_id_;
|
||||
std::string app_class_;
|
||||
std::string layout_;
|
||||
std::string old_app_id_;
|
||||
std::size_t app_nb_;
|
||||
std::string shell_;
|
||||
unsigned app_icon_size_{24};
|
||||
bool update_app_icon_{true};
|
||||
std::string app_icon_name_;
|
||||
int floating_count_;
|
||||
util::JsonParser parser_;
|
||||
std::mutex mutex_;
|
||||
Ipc ipc_;
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <gtkmm/button.h>
|
||||
#include <gtkmm/label.h>
|
||||
|
||||
#include <string_view>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "AModule.hpp"
|
||||
@ -21,7 +22,9 @@ class Workspaces : public AModule, public sigc::trackable {
|
||||
auto update() -> void;
|
||||
|
||||
private:
|
||||
static inline const std::string workspace_switch_cmd_ = "workspace {} \"{}\"";
|
||||
static constexpr std::string_view workspace_switch_cmd_ = "workspace {} \"{}\"";
|
||||
static constexpr std::string_view persistent_workspace_switch_cmd_ =
|
||||
R"(workspace {} "{}"; move workspace to output "{}"; workspace {} "{}")";
|
||||
|
||||
static int convertWorkspaceNameToNum(std::string name);
|
||||
|
||||
|
@ -20,15 +20,19 @@ class Wireplumber : public ALabel {
|
||||
void loadRequiredApiModules();
|
||||
void prepare();
|
||||
void activatePlugins();
|
||||
static void updateVolume(waybar::modules::Wireplumber* self);
|
||||
static void updateNodeName(waybar::modules::Wireplumber* self);
|
||||
static uint32_t getDefaultNodeId(waybar::modules::Wireplumber* self);
|
||||
static void updateVolume(waybar::modules::Wireplumber* self, uint32_t id);
|
||||
static void updateNodeName(waybar::modules::Wireplumber* self, uint32_t id);
|
||||
static void onPluginActivated(WpObject* p, GAsyncResult* res, waybar::modules::Wireplumber* self);
|
||||
static void onObjectManagerInstalled(waybar::modules::Wireplumber* self);
|
||||
static void onMixerChanged(waybar::modules::Wireplumber* self, uint32_t id);
|
||||
static void onDefaultNodesApiChanged(waybar::modules::Wireplumber* self);
|
||||
|
||||
WpCore* wp_core_;
|
||||
GPtrArray* apis_;
|
||||
WpObjectManager* om_;
|
||||
WpPlugin* mixer_api_;
|
||||
WpPlugin* def_nodes_api_;
|
||||
gchar* default_node_name_;
|
||||
uint32_t pending_plugins_;
|
||||
bool muted_;
|
||||
double volume_;
|
||||
|
60
include/util/date.hpp
Normal file
60
include/util/date.hpp
Normal file
@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#if HAVE_CHRONO_TIMEZONES
|
||||
#include <chrono>
|
||||
#include <format>
|
||||
|
||||
/* Compatibility layer for <date/tz.h> on top of C++20 <chrono> */
|
||||
namespace date {
|
||||
|
||||
using namespace std::chrono;
|
||||
|
||||
namespace literals {
|
||||
using std::chrono::last;
|
||||
}
|
||||
|
||||
inline auto format(const std::string& spec, const auto& ztime) {
|
||||
return spec.empty() ? "" : std::vformat("{:L" + spec + "}", std::make_format_args(ztime));
|
||||
}
|
||||
|
||||
inline auto format(const std::locale& loc, const std::string& spec, const auto& ztime) {
|
||||
return spec.empty() ? "" : std::vformat(loc, "{:L" + spec + "}", std::make_format_args(ztime));
|
||||
}
|
||||
|
||||
} // namespace date
|
||||
|
||||
#else
|
||||
#include <date/tz.h>
|
||||
#endif
|
||||
|
||||
template <typename Duration, typename TimeZonePtr>
|
||||
struct fmt::formatter<date::zoned_time<Duration, TimeZonePtr>> {
|
||||
std::string_view specs;
|
||||
|
||||
template <typename ParseContext>
|
||||
constexpr auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
|
||||
auto it = ctx.begin();
|
||||
if (it != ctx.end() && *it == ':') {
|
||||
++it;
|
||||
}
|
||||
auto end = it;
|
||||
while (end != ctx.end() && *end != '}') {
|
||||
++end;
|
||||
}
|
||||
if (end != it) {
|
||||
specs = {it, std::string_view::size_type(end - it)};
|
||||
}
|
||||
return end;
|
||||
}
|
||||
|
||||
template <typename FormatContext>
|
||||
auto format(const date::zoned_time<Duration, TimeZonePtr>& ztime, FormatContext& ctx) {
|
||||
if (ctx.locale()) {
|
||||
const auto loc = ctx.locale().template get<std::locale>();
|
||||
return fmt::format_to(ctx.out(), "{}", date::format(loc, fmt::to_string(specs), ztime));
|
||||
}
|
||||
return fmt::format_to(ctx.out(), "{}", date::format(fmt::to_string(specs), ztime));
|
||||
}
|
||||
};
|
@ -66,9 +66,9 @@ struct formatter<pow_format> {
|
||||
std::string string;
|
||||
switch (spec) {
|
||||
case '>':
|
||||
return format_to(ctx.out(), "{:>{}}", fmt::format("{}", s), max_width);
|
||||
return fmt::format_to(ctx.out(), "{:>{}}", fmt::format("{}", s), max_width);
|
||||
case '<':
|
||||
return format_to(ctx.out(), "{:<{}}", fmt::format("{}", s), max_width);
|
||||
return fmt::format_to(ctx.out(), "{:<{}}", fmt::format("{}", s), max_width);
|
||||
case '=':
|
||||
format = "{coefficient:<{number_width}.1f}{padding}{prefix}{unit}";
|
||||
break;
|
||||
@ -77,8 +77,8 @@ struct formatter<pow_format> {
|
||||
format = "{coefficient:.1f}{prefix}{unit}";
|
||||
break;
|
||||
}
|
||||
return format_to(
|
||||
ctx.out(), format, fmt::arg("coefficient", fraction),
|
||||
return fmt::format_to(
|
||||
ctx.out(), fmt::runtime(format), fmt::arg("coefficient", fraction),
|
||||
fmt::arg("number_width", number_width),
|
||||
fmt::arg("prefix", std::string() + units[pow] + ((s.binary_ && pow) ? "i" : "")),
|
||||
fmt::arg("unit", s.unit_),
|
||||
|
@ -1,39 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <date/tz.h>
|
||||
#include <fmt/format.h>
|
||||
|
||||
namespace waybar {
|
||||
|
||||
struct waybar_time {
|
||||
std::locale locale;
|
||||
date::zoned_seconds ztime;
|
||||
};
|
||||
|
||||
} // namespace waybar
|
||||
|
||||
template <>
|
||||
struct fmt::formatter<waybar::waybar_time> {
|
||||
std::string_view specs;
|
||||
|
||||
template <typename ParseContext>
|
||||
constexpr auto parse(ParseContext& ctx) -> decltype(ctx.begin()) {
|
||||
auto it = ctx.begin();
|
||||
if (it != ctx.end() && *it == ':') {
|
||||
++it;
|
||||
}
|
||||
auto end = it;
|
||||
while (end != ctx.end() && *end != '}') {
|
||||
++end;
|
||||
}
|
||||
if (end != it) {
|
||||
specs = {it, std::string_view::size_type(end - it)};
|
||||
}
|
||||
return end;
|
||||
}
|
||||
|
||||
template <typename FormatContext>
|
||||
auto format(const waybar::waybar_time& t, FormatContext& ctx) {
|
||||
return format_to(ctx.out(), "{}", date::format(t.locale, fmt::to_string(specs), t.ztime));
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user