Skip to content

Commit

Permalink
Merge branch 'master' into update_flake_lock_action
Browse files Browse the repository at this point in the history
  • Loading branch information
LukashonakV authored Sep 28, 2024
2 parents 2fa5a99 + 486b99c commit 00b2996
Show file tree
Hide file tree
Showing 73 changed files with 1,335 additions and 166 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ jobs:
with:
source: "."
extensions: "hpp,h,cpp,c"
clangFormatVersion: 16
style: "file:.clang-format"
clangFormatVersion: 18
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Sway (Workspaces, Binding mode, Focused window name)
- River (Mapping mode, Tags, Focused window name)
- Hyprland (Window Icons, Workspaces, Focused window name)
- Niri (Workspaces, Focused window name, Language)
- DWL (Tags, Focused window name) [requires dwl ipc patch](https://github.com/djpohly/dwl/wiki/ipc)
- Tray [#21](https://github.com/Alexays/Waybar/issues/21)
- Local time
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion include/AModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AModule : public IModule {

~AModule() override;
auto update() -> void override;
virtual auto refresh(int shouldRefresh) -> void{};
virtual auto refresh(int shouldRefresh) -> void {};
operator Gtk::Widget &() override;
auto doAction(const std::string &name) -> void override;

Expand Down
2 changes: 1 addition & 1 deletion include/bar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct bar_margins {
};

struct bar_mode {
std::optional<bar_layer> layer;
bar_layer layer;
bool exclusive;
bool passthrough;
bool visible;
Expand Down
1 change: 1 addition & 0 deletions include/modules/cava.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Cava final : public ALabel {
std::chrono::seconds suspend_silence_delay_{0};
bool silence_{false};
bool hide_on_silence_{false};
std::string format_silent_{""};
int sleep_counter_{0};
// Cava method
void pause_resume();
Expand Down
4 changes: 2 additions & 2 deletions include/modules/clock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class Clock final : public ALabel {
day cldBaseDay_{0}; // calendar Cached day. Is used when today is changing(midnight)
std::string cldText_{""}; // calendar text to print
CldMode cldMode_{CldMode::MONTH};
auto get_calendar(const year_month_day& today, const year_month_day& ymd, const time_zone* tz)
-> const std::string;
auto get_calendar(const year_month_day& today, const year_month_day& ymd,
const time_zone* tz) -> const std::string;

// get local time zone
auto local_zone() -> const time_zone*;
Expand Down
4 changes: 2 additions & 2 deletions include/modules/hyprland/workspaces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class Workspaces : public AModule, public EventHandler {
// Config
void parseConfig(const Json::Value& config);
auto populateIconsMap(const Json::Value& formatIcons) -> void;
static auto populateBoolConfig(const Json::Value& config, const std::string& key, bool& member)
-> void;
static auto populateBoolConfig(const Json::Value& config, const std::string& key,
bool& member) -> void;
auto populateSortByConfig(const Json::Value& config) -> void;
auto populateIgnoreWorkspacesConfig(const Json::Value& config) -> void;
auto populateFormatWindowSeparatorConfig(const Json::Value& config) -> void;
Expand Down
52 changes: 52 additions & 0 deletions include/modules/niri/backend.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#pragma once

#include <list>
#include <mutex>
#include <string>
#include <utility>

#include "util/json.hpp"

namespace waybar::modules::niri {

class EventHandler {
public:
virtual void onEvent(const Json::Value& ev) = 0;
virtual ~EventHandler() = default;
};

class IPC {
public:
IPC() { startIPC(); }

void registerForIPC(const std::string& ev, EventHandler* ev_handler);
void unregisterForIPC(EventHandler* handler);

static Json::Value send(const Json::Value& request);

// The data members are only safe to access while dataMutex_ is locked.
std::lock_guard<std::mutex> lockData() { return std::lock_guard(dataMutex_); }
const std::vector<Json::Value>& workspaces() const { return workspaces_; }
const std::vector<Json::Value>& windows() const { return windows_; }
const std::vector<std::string>& keyboardLayoutNames() const { return keyboardLayoutNames_; }
unsigned keyboardLayoutCurrent() const { return keyboardLayoutCurrent_; }

private:
void startIPC();
static int connectToSocket();
void parseIPC(const std::string&);

std::mutex dataMutex_;
std::vector<Json::Value> workspaces_;
std::vector<Json::Value> windows_;
std::vector<std::string> keyboardLayoutNames_;
unsigned keyboardLayoutCurrent_;

util::JsonParser parser_;
std::mutex callbackMutex_;
std::list<std::pair<std::string, EventHandler*>> callbacks_;
};

inline std::unique_ptr<IPC> gIPC;

}; // namespace waybar::modules::niri
38 changes: 38 additions & 0 deletions include/modules/niri/language.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once

#include <string>

#include "ALabel.hpp"
#include "bar.hpp"
#include "modules/niri/backend.hpp"

namespace waybar::modules::niri {

class Language : public ALabel, public EventHandler {
public:
Language(const std::string &, const Bar &, const Json::Value &);
~Language() override;
void update() override;

private:
void updateFromIPC();
void onEvent(const Json::Value &ev) override;
void doUpdate();

struct Layout {
std::string full_name;
std::string short_name;
std::string variant;
std::string short_description;
};

static Layout getLayout(const std::string &fullName);

std::mutex mutex_;
const Bar &bar_;

std::vector<Layout> layouts_;
unsigned current_idx_;
};

} // namespace waybar::modules::niri
28 changes: 28 additions & 0 deletions include/modules/niri/window.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <gtkmm/button.h>
#include <json/value.h>

#include "AAppIconLabel.hpp"
#include "bar.hpp"
#include "modules/niri/backend.hpp"

namespace waybar::modules::niri {

class Window : public AAppIconLabel, public EventHandler {
public:
Window(const std::string &, const Bar &, const Json::Value &);
~Window() override;
void update() override;

private:
void onEvent(const Json::Value &ev) override;
void doUpdate();
void setClass(const std::string &className, bool enable);

const Bar &bar_;

std::string oldAppId_;
};

} // namespace waybar::modules::niri
30 changes: 30 additions & 0 deletions include/modules/niri/workspaces.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include <gtkmm/button.h>
#include <json/value.h>

#include "AModule.hpp"
#include "bar.hpp"
#include "modules/niri/backend.hpp"

namespace waybar::modules::niri {

class Workspaces : public AModule, public EventHandler {
public:
Workspaces(const std::string &, const Bar &, const Json::Value &);
~Workspaces() override;
void update() override;

private:
void onEvent(const Json::Value &ev) override;
void doUpdate();
Gtk::Button &addButton(const Json::Value &ws);
std::string getIcon(const std::string &value, const Json::Value &ws);

const Bar &bar_;
Gtk::Box box_;
// Map from niri workspace id to button.
std::unordered_map<uint64_t, Gtk::Button> buttons_;
};

} // namespace waybar::modules::niri
12 changes: 6 additions & 6 deletions include/util/clara.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,8 @@ inline auto convertInto(std::string const &source, bool &target) -> ParserResult
}
#ifdef CLARA_CONFIG_OPTIONAL_TYPE
template <typename T>
inline auto convertInto(std::string const &source, CLARA_CONFIG_OPTIONAL_TYPE<T> &target)
-> ParserResult {
inline auto convertInto(std::string const &source,
CLARA_CONFIG_OPTIONAL_TYPE<T> &target) -> ParserResult {
T temp;
auto result = convertInto(source, temp);
if (result) target = std::move(temp);
Expand Down Expand Up @@ -751,8 +751,8 @@ class ParserBase {
public:
virtual ~ParserBase() = default;
virtual auto validate() const -> Result { return Result::ok(); }
virtual auto parse(std::string const &exeName, TokenStream const &tokens) const
-> InternalParseResult = 0;
virtual auto parse(std::string const &exeName,
TokenStream const &tokens) const -> InternalParseResult = 0;
virtual auto cardinality() const -> size_t { return 1; }

auto parse(Args const &args) const -> InternalParseResult {
Expand Down Expand Up @@ -1098,8 +1098,8 @@ struct Parser : ParserBase {

using ParserBase::parse;

auto parse(std::string const &exeName, TokenStream const &tokens) const
-> InternalParseResult override {
auto parse(std::string const &exeName,
TokenStream const &tokens) const -> InternalParseResult override {
struct ParserInfo {
ParserBase const *parser = nullptr;
size_t count = 0;
Expand Down
2 changes: 1 addition & 1 deletion include/util/format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class pow_format {
public:
pow_format(long long val, std::string&& unit, bool binary = false)
: val_(val), unit_(unit), binary_(binary){};
: val_(val), unit_(unit), binary_(binary) {};

long long val_;
std::string unit_;
Expand Down
2 changes: 1 addition & 1 deletion man/waybar-backlight.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The *backlight* module displays the current backlight level.

*rotate*: ++
typeof: integer ++
Positive value to rotate the text label.
Positive value to rotate the text label (in 90 degree increments).

*states*: ++
typeof: object ++
Expand Down
2 changes: 1 addition & 1 deletion man/waybar-battery.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ The *battery* module displays the current capacity and state (eg. charging) of y

*rotate*: ++
typeof: integer++
Positive value to rotate the text label.
Positive value to rotate the text label (in 90 degree increments).

*on-click*: ++
typeof: string ++
Expand Down
2 changes: 1 addition & 1 deletion man/waybar-bluetooth.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Addressed by *bluetooth*

*rotate*: ++
typeof: integer ++
Positive value to rotate the text label.
Positive value to rotate the text label (in 90 degree increments).

*max-length*: ++
typeof: integer ++
Expand Down
9 changes: 9 additions & 0 deletions man/waybar-cava.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ libcava lives in:
:[ bool
:[ false
:[ Hides the widget if no input (after sleep_timer elapsed)
|[ *format_silent*
:[ string
:[
:[ Widget's text after sleep_timer elapsed (hide_on_silence has to be false)
|[ *method*
:[ string
:[ pulse
Expand Down Expand Up @@ -196,3 +200,8 @@ In case when cava releases new version and you're wanna get it, it should be rai
}
},
```
# STYLE

- *#cava*
- *#cava.silent* Applied after no sound has been detected for sleep_timer seconds
- *#cava.updated* Applied when a new frame is shown
2 changes: 1 addition & 1 deletion man/waybar-clock.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ $XDG_CONFIG_HOME/waybar/config ++
|[ *rotate*
:[ integer
:[
:[ Positive value to rotate the text label
:[ Positive value to rotate the text label (in 90 degree increments)
|[ *on-click*
:[ string
:[
Expand Down
2 changes: 1 addition & 1 deletion man/waybar-cpu.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The *cpu* module displays the current CPU utilization.

*rotate*: ++
typeof: integer ++
Positive value to rotate the text label.
Positive value to rotate the text label (in 90 degree increments).

*states*: ++
typeof: object ++
Expand Down
Loading

0 comments on commit 00b2996

Please sign in to comment.