YggdrasilWM  0.1.1
A tiny window manager coded in C++
Bars.hpp
Go to the documentation of this file.
1 
26 #ifndef BARS_HPP
27 #define BARS_HPP
28 #include <vector>
29 #include <memory>
30 #include <unordered_map>
31 #include <string>
32 #include <thread>
33 #include <set>
34 
35 extern "C" {
36 #include <X11/Xlib.h>
37 }
38 
39 class Bar;
40 class ConfigDataBars;
41 class TSBarsData;
42 class Widget;
43 
55 class Bars
56 {
57 public:
58  Bars(const Bars&) = delete;
59  Bars& operator=(const Bars&) = delete;
65  static void createInstance();
72  static Bars& getInstance();
78  static void destroy();
79  ~Bars();
89  void init(std::shared_ptr<ConfigDataBars> configData,
90  std::shared_ptr<TSBarsData> tsData,
91  Display *display,
92  Window root);
98  void run();
99  void start_thread();
105  [[nodiscard]] unsigned int getSpaceN() const;
111  [[nodiscard]] unsigned int getSpaceS() const;
117  [[nodiscard]] unsigned int getSpaceE() const;
123  [[nodiscard]] unsigned int getSpaceW() const;
124  const std::unordered_map<std::string, std::string> &getData() const;
132  bool isBarWindow(Window window);
137  void stop_thread();
143  void redraw();
144  void addPluginLocation(const std::string& location);
145  [[nodiscard]] const std::set<std::string>& getPluginsLocations() const;
146  [[nodiscard]] void * getWidgetTypeHandle(const std::string& widgetType);
147  void setWidgetTypeHandle(const std::string& widgetType, void * handle);
148  void subscribeWidget(Widget *w);
149 private:
150  static Bars* instance;
151  std::vector<std::unique_ptr<Bar>> bars;
152  std::vector<Window> windows;
153  std::shared_ptr<ConfigDataBars> configData;
154  std::shared_ptr<TSBarsData> tsData;
155  std::unordered_map<std::string, std::string> data;
156  Display* display;
157  Window root;
158  unsigned int spaceN;
159  unsigned int spaceS;
160  unsigned int spaceE;
161  unsigned int spaceW;
162  std::thread barThread;
163  std::set<std::string>pluginsLocations;
164  std::unordered_map<std::string, void *> widgetTypeHandle;
165  std::unordered_map<std::string,std::vector<Widget *>> subscriptions;
166  Bars();
167 };
168 #endif // BARS_HPP
Definition: Bar.hpp:41
Class to manage the bars This class is a singleton and is responsible for managing the bars instancia...
Definition: Bars.hpp:56
static Bars * instance
Definition: Bars.hpp:150
std::shared_ptr< TSBarsData > tsData
Definition: Bars.hpp:154
std::shared_ptr< ConfigDataBars > configData
Definition: Bars.hpp:153
void setWidgetTypeHandle(const std::string &widgetType, void *handle)
Definition: Bars.cpp:153
std::vector< Window > windows
Definition: Bars.hpp:152
void run()
Run the Bars class in a separate thread.
Definition: Bars.cpp:93
std::unordered_map< std::string, void * > widgetTypeHandle
Definition: Bars.hpp:164
Bars & operator=(const Bars &)=delete
Display * display
Definition: Bars.hpp:156
const std::set< std::string > & getPluginsLocations() const
Definition: Bars.cpp:139
unsigned int getSpaceE() const
Get the spaceE value used to calculate the space left for the Layout Manager.
Definition: Bars.cpp:188
Bars(const Bars &)=delete
Bars()
Definition: Bars.cpp:124
void stop_thread()
Stop the thread (join)
Definition: Bars.cpp:195
void redraw()
Redraw the bars by calling the draw method of each bar.
Definition: Bars.cpp:119
unsigned int getSpaceS() const
Get the spaceS value used to calculate the space left for the Layout Manager.
Definition: Bars.cpp:187
std::vector< std::unique_ptr< Bar > > bars
Definition: Bars.hpp:151
void start_thread()
Definition: Bars.cpp:90
unsigned int spaceE
Definition: Bars.hpp:160
unsigned int getSpaceN() const
Get the spaceN value used to calculate the space left for the Layout Manager.
Definition: Bars.cpp:186
unsigned int spaceS
Definition: Bars.hpp:159
void * getWidgetTypeHandle(const std::string &widgetType)
Definition: Bars.cpp:143
void init(std::shared_ptr< ConfigDataBars > configData, std::shared_ptr< TSBarsData > tsData, Display *display, Window root)
Initialize the Bars class.
Definition: Bars.cpp:40
unsigned int getSpaceW() const
Get the spaceW value used to calculate the space left for the Layout Manager.
Definition: Bars.cpp:189
const std::unordered_map< std::string, std::string > & getData() const
Definition: Bars.cpp:190
void addPluginLocation(const std::string &location)
Definition: Bars.cpp:135
std::set< std::string > pluginsLocations
Definition: Bars.hpp:163
unsigned int spaceW
Definition: Bars.hpp:161
~Bars()
Definition: Bars.cpp:156
bool isBarWindow(Window window)
Check if the window is a bar window used to filter events in EventHandler.
Definition: Bars.cpp:191
static void createInstance()
Create the singleton instance if the instance is already created, it will do nothing.
Definition: Bars.cpp:173
static Bars & getInstance()
Get the singleton instance if the instance is not created, it will create it.
Definition: Bars.cpp:177
unsigned int spaceN
Definition: Bars.hpp:158
static void destroy()
Destroy the singleton instance if the instance is not created, it will do nothing.
Definition: Bars.cpp:182
Window root
Definition: Bars.hpp:157
void subscribeWidget(Widget *w)
Definition: Bars.cpp:199
std::thread barThread
Definition: Bars.hpp:162
std::unordered_map< std::string, std::vector< Widget * > > subscriptions
Definition: Bars.hpp:165
std::unordered_map< std::string, std::string > data
Definition: Bars.hpp:155
ConfigDataBars class.
Definition: ConfigDataBars.hpp:42
Definition: TSBarsData.hpp:32
Definition: Widget.hpp:33