Skip to content

Commit

Permalink
Merge branch 'Alexays:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveSaah authored Nov 20, 2024
2 parents ce97dc7 + 8645115 commit 61cc37f
Show file tree
Hide file tree
Showing 94 changed files with 1,526 additions and 202 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 .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
jobs:
build-and-push:
runs-on: ubuntu-latest
if: github.repository == 'Alexays/Waybar'
strategy:
fail-fast: false # don't fail the other jobs if one of the images fails to build
matrix:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/nix-update-flake-lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
jobs:
lockfile:
runs-on: ubuntu-latest
if: github.event_name != 'schedule' || github.repository == 'Alexays/Waybar'
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand Down
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
4 changes: 2 additions & 2 deletions 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 All @@ -54,7 +54,7 @@ class BarIpcClient;
}
#endif // HAVE_SWAY

class Bar {
class Bar : public sigc::trackable {
public:
using bar_mode_map = std::map<std::string, struct bar_mode>;
static const bar_mode_map PRESET_MODES;
Expand Down
3 changes: 3 additions & 0 deletions include/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class Config {
static std::optional<std::string> findConfigPath(
const std::vector<std::string> &names, const std::vector<std::string> &dirs = CONFIG_DIRS);

static std::optional<std::string> tryExpandPath(const std::string &base,
const std::string &filename);

Config() = default;

void load(const std::string &config);
Expand Down
2 changes: 1 addition & 1 deletion include/group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace waybar {
class Group : public AModule {
public:
Group(const std::string &, const std::string &, const Json::Value &, bool);
virtual ~Group() = default;
~Group() override = default;
auto update() -> void override;
operator Gtk::Widget &() override;

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
1 change: 1 addition & 0 deletions include/modules/temperature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Temperature : public ALabel {
private:
float getTemperature();
bool isCritical(uint16_t);
bool isWarning(uint16_t);

std::string file_path_;
util::SleeperThread thread_;
Expand Down
7 changes: 7 additions & 0 deletions include/modules/wlr/taskbar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@

namespace waybar::modules::wlr {

struct widget_geometry {
int x, y, w, h;
};

class Taskbar;

class Task {
Expand All @@ -42,6 +46,7 @@ class Task {
};
// made public so TaskBar can reorder based on configuration.
Gtk::Button button;
struct widget_geometry minimize_hint;

private:
static uint32_t global_id;
Expand Down Expand Up @@ -82,6 +87,8 @@ class Task {
private:
std::string repr() const;
std::string state_string(bool = false) const;
void set_minimize_hint();
void on_button_size_allocated(Gtk::Allocation &alloc);
void set_app_info_from_app_id_list(const std::string &app_id_list);
bool image_load_icon(Gtk::Image &image, const Glib::RefPtr<Gtk::IconTheme> &icon_theme,
Glib::RefPtr<Gio::DesktopAppInfo> app_info, int size);
Expand Down
2 changes: 2 additions & 0 deletions include/util/audio_backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class AudioBackend {
std::string desc_;
std::string monitor_;
std::string current_sink_name_;
std::string default_sink_name;
bool default_sink_running_;
bool current_sink_running_;
// SOURCE
uint32_t source_idx_{0};
Expand Down
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
7 changes: 6 additions & 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 Expand Up @@ -81,6 +81,11 @@ The *backlight* module displays the current backlight level.
default: 1.0 ++
The speed at which to change the brightness when scrolling.

*min-brightness*: ++
typeof: double ++
default: 0.0 ++
The minimum brightness of the backlight.

*menu*: ++
typeof: string ++
Action that popups the menu.
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
Loading

0 comments on commit 61cc37f

Please sign in to comment.