mirror of
				https://github.com/rad4day/Waybar.git
				synced 2025-10-30 23:42:42 +01:00 
			
		
		
		
	refactor: format code
This commit is contained in:
		| @@ -1,35 +1,35 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include <iostream> | ||||
| #include <cstring> | ||||
| #include <unistd.h> | ||||
| #include <sys/socket.h> | ||||
| #include <sys/un.h> | ||||
| #include <unistd.h> | ||||
| #include <cstring> | ||||
| #include <iostream> | ||||
| #include "ipc.hpp" | ||||
|  | ||||
| namespace waybar::modules::sway { | ||||
|  | ||||
| class Ipc { | ||||
| public: | ||||
|  public: | ||||
|   Ipc(); | ||||
|   ~Ipc(); | ||||
|  | ||||
|   struct ipc_response { | ||||
|     uint32_t size; | ||||
|     uint32_t type; | ||||
|     uint32_t    size; | ||||
|     uint32_t    type; | ||||
|     std::string payload; | ||||
|   }; | ||||
|  | ||||
|   struct ipc_response sendCmd(uint32_t type, const std::string &payload = "") const; | ||||
|   void subscribe(const std::string &payload) const; | ||||
|   void                subscribe(const std::string &payload) const; | ||||
|   struct ipc_response handleEvent() const; | ||||
|  | ||||
| protected: | ||||
|  protected: | ||||
|   static inline const std::string ipc_magic_ = "i3-ipc"; | ||||
|   static inline const size_t ipc_header_size_ = ipc_magic_.size() + 8; | ||||
|   static inline const size_t      ipc_header_size_ = ipc_magic_.size() + 8; | ||||
|  | ||||
|   const std::string getSocketPath() const; | ||||
|   int open(const std::string &) const; | ||||
|   const std::string   getSocketPath() const; | ||||
|   int                 open(const std::string &) const; | ||||
|   struct ipc_response send(int fd, uint32_t type, const std::string &payload = "") const; | ||||
|   struct ipc_response recv(int fd) const; | ||||
|  | ||||
| @@ -37,4 +37,4 @@ protected: | ||||
|   int fd_event_; | ||||
| }; | ||||
|  | ||||
| } // namespace waybar::modules::sway | ||||
| }  // namespace waybar::modules::sway | ||||
|   | ||||
| @@ -1,28 +1,29 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include <fmt/format.h> | ||||
| #include "ALabel.hpp" | ||||
| #include "bar.hpp" | ||||
| #include "client.hpp" | ||||
| #include "util/sleeper_thread.hpp" | ||||
| #include "util/json.hpp" | ||||
| #include "ALabel.hpp" | ||||
| #include "modules/sway/ipc/client.hpp" | ||||
| #include "util/json.hpp" | ||||
| #include "util/sleeper_thread.hpp" | ||||
|  | ||||
| namespace waybar::modules::sway { | ||||
|  | ||||
| class Mode : public ALabel { | ||||
|   public: | ||||
|     Mode(const std::string&, const waybar::Bar&, const Json::Value&); | ||||
|     ~Mode() = default; | ||||
|     auto update() -> void; | ||||
|   private: | ||||
|     void worker(); | ||||
|      | ||||
|     const Bar& bar_; | ||||
|     waybar::util::SleeperThread thread_; | ||||
|     util::JsonParser parser_; | ||||
|     Ipc ipc_; | ||||
|     std::string mode_; | ||||
|  public: | ||||
|   Mode(const std::string&, const waybar::Bar&, const Json::Value&); | ||||
|   ~Mode() = default; | ||||
|   auto update() -> void; | ||||
|  | ||||
|  private: | ||||
|   void worker(); | ||||
|  | ||||
|   const Bar&                  bar_; | ||||
|   waybar::util::SleeperThread thread_; | ||||
|   util::JsonParser            parser_; | ||||
|   Ipc                         ipc_; | ||||
|   std::string                 mode_; | ||||
| }; | ||||
|  | ||||
| } | ||||
| }  // namespace waybar::modules::sway | ||||
| @@ -2,31 +2,32 @@ | ||||
|  | ||||
| #include <fmt/format.h> | ||||
| #include <tuple> | ||||
| #include "ALabel.hpp" | ||||
| #include "bar.hpp" | ||||
| #include "client.hpp" | ||||
| #include "util/sleeper_thread.hpp" | ||||
| #include "util/json.hpp" | ||||
| #include "ALabel.hpp" | ||||
| #include "modules/sway/ipc/client.hpp" | ||||
| #include "util/json.hpp" | ||||
| #include "util/sleeper_thread.hpp" | ||||
|  | ||||
| namespace waybar::modules::sway { | ||||
|  | ||||
| class Window : public ALabel { | ||||
|   public: | ||||
|     Window(const std::string&, const waybar::Bar&, const Json::Value&); | ||||
|     ~Window() = default; | ||||
|     auto update() -> void; | ||||
|   private: | ||||
|     void worker(); | ||||
|     std::tuple<int, std::string> getFocusedNode(Json::Value nodes); | ||||
|     void getFocusedWindow(); | ||||
|  public: | ||||
|   Window(const std::string&, const waybar::Bar&, const Json::Value&); | ||||
|   ~Window() = default; | ||||
|   auto update() -> void; | ||||
|  | ||||
|     const Bar& bar_; | ||||
|     waybar::util::SleeperThread thread_; | ||||
|     util::JsonParser parser_; | ||||
|     Ipc ipc_; | ||||
|     std::string window_; | ||||
|     int windowId_; | ||||
|  private: | ||||
|   void                         worker(); | ||||
|   std::tuple<int, std::string> getFocusedNode(Json::Value nodes); | ||||
|   void                         getFocusedWindow(); | ||||
|  | ||||
|   const Bar&                  bar_; | ||||
|   waybar::util::SleeperThread thread_; | ||||
|   util::JsonParser            parser_; | ||||
|   Ipc                         ipc_; | ||||
|   std::string                 window_; | ||||
|   int                         windowId_; | ||||
| }; | ||||
|  | ||||
| } | ||||
| }  // namespace waybar::modules::sway | ||||
|   | ||||
| @@ -1,43 +1,44 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include <fmt/format.h> | ||||
| #include "bar.hpp" | ||||
| #include "client.hpp" | ||||
| #include "util/sleeper_thread.hpp" | ||||
| #include "util/json.hpp" | ||||
| #include "IModule.hpp" | ||||
| #include "modules/sway/ipc/client.hpp" | ||||
| #include <gtkmm/button.h> | ||||
| #include <gtkmm/label.h> | ||||
| #include "IModule.hpp" | ||||
| #include "bar.hpp" | ||||
| #include "client.hpp" | ||||
| #include "modules/sway/ipc/client.hpp" | ||||
| #include "util/json.hpp" | ||||
| #include "util/sleeper_thread.hpp" | ||||
|  | ||||
| namespace waybar::modules::sway { | ||||
|  | ||||
| class Workspaces : public IModule { | ||||
|   public: | ||||
|     Workspaces(const std::string&, const waybar::Bar&, const Json::Value&); | ||||
|     ~Workspaces() = default; | ||||
|     auto update() -> void; | ||||
|     operator Gtk::Widget &(); | ||||
|   private: | ||||
|     void worker(); | ||||
|     void addWorkspace(const Json::Value&); | ||||
| 		void onButtonReady(const Json::Value&, Gtk::Button&); | ||||
|     std::string getIcon(const std::string&, const Json::Value&); | ||||
|     bool handleScroll(GdkEventScroll*); | ||||
|     const std::string getCycleWorkspace(uint8_t current, bool prev) const; | ||||
|     uint16_t getWorkspaceIndex(const std::string &name) const; | ||||
|     std::string trimWorkspaceName(std::string); | ||||
|  public: | ||||
|   Workspaces(const std::string&, const waybar::Bar&, const Json::Value&); | ||||
|   ~Workspaces() = default; | ||||
|   auto update() -> void; | ||||
|        operator Gtk::Widget&(); | ||||
|  | ||||
|     const Bar& bar_; | ||||
|     const Json::Value& config_; | ||||
|     Json::Value workspaces_; | ||||
|     waybar::util::SleeperThread thread_; | ||||
|     Gtk::Box box_; | ||||
|     util::JsonParser parser_; | ||||
|     Ipc ipc_; | ||||
|     std::mutex mutex_; | ||||
|     bool scrolling_; | ||||
|     std::unordered_map<std::string, Gtk::Button> buttons_; | ||||
|  private: | ||||
|   void              worker(); | ||||
|   void              addWorkspace(const Json::Value&); | ||||
|   void              onButtonReady(const Json::Value&, Gtk::Button&); | ||||
|   std::string       getIcon(const std::string&, const Json::Value&); | ||||
|   bool              handleScroll(GdkEventScroll*); | ||||
|   const std::string getCycleWorkspace(uint8_t current, bool prev) const; | ||||
|   uint16_t          getWorkspaceIndex(const std::string& name) const; | ||||
|   std::string       trimWorkspaceName(std::string); | ||||
|  | ||||
|   const Bar&                                   bar_; | ||||
|   const Json::Value&                           config_; | ||||
|   Json::Value                                  workspaces_; | ||||
|   waybar::util::SleeperThread                  thread_; | ||||
|   Gtk::Box                                     box_; | ||||
|   util::JsonParser                             parser_; | ||||
|   Ipc                                          ipc_; | ||||
|   std::mutex                                   mutex_; | ||||
|   bool                                         scrolling_; | ||||
|   std::unordered_map<std::string, Gtk::Button> buttons_; | ||||
| }; | ||||
|  | ||||
| } | ||||
| }  // namespace waybar::modules::sway | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Alex
					Alex