YggdrasilWM  0.1.1
A tiny window manager coded in C++
WindowManager.hpp
Go to the documentation of this file.
1 
28 #ifndef WINDOW_MANAGER_HPP
29 #define WINDOW_MANAGER_HPP
30 extern "C" {
31 #include <X11/Xlib.h>
32 }
33 #include <memory>
34 #include <string>
35 #include <unordered_map>
36 #include <chrono>
37 #include "Logger.hpp"
38 #include "Client.hpp"
40 #include "Config/ConfigHandler.hpp"
41 #include <iostream>
42 #include <algorithm>
43 #include <csignal>
44 #include <mutex>
45 #include <memory>
46 class Group;
47 class TSBarsData;
48 class BaseX11Wrapper;
49 
60 public:
61  WindowManager(const WindowManager&) = delete;
67  static void create(std::shared_ptr<BaseX11Wrapper> wrapper,const std::string &displayStr = std::string());
80  void init();
85  void Run();
86 // Getters
91  Display *getDisplay() const;
96  Window getRoot() const;
101  std::unordered_map<Window, std::shared_ptr<Client>> & getClients();
108  std::shared_ptr<Client> getClient(Window window);
113  std::shared_ptr<Client> getClientRef(Window window);
118  unsigned long getClientCount();
119 // Setters
124  void setFocus(Client *client);
130  void insertClient(Window window);
131 // Running control
137  void Stop();
150  const std::vector<std::shared_ptr<Group>> & getGroups() const;
156  std::shared_ptr<Group> getActiveGroup() const;
157 
162  bool getRunning() const;
171  static WindowManager * getInstance();
177  void setActiveGroup(std::shared_ptr<Group> activeGroup);
178  void setActiveGroup(Group * activeGroup);
187  static void Destroy();
194  void testRun();
200  unsigned int getGeometryX() const;
205  unsigned int getGeometryY() const;
210  Window getActiveWindow() const;
216  void setActiveWindow(Window activeWindow);
221  const std::shared_ptr<BaseX11Wrapper> & getX11Wrapper() const;
222 private:
223  Display *display_;
224  static bool wmDetected;
225  const Window root_;
226  std::vector<std::shared_ptr<Group>> groups_;
227  std::weak_ptr<Group> active_group_{};
228  const Atom WM_PROTOCOLS;
229  const Atom WM_DELETE_WINDOW;
230  unsigned int geometryX{};
231  unsigned int geometryY{};
232  bool running;
233  std::unordered_map<Window, std::shared_ptr<Client>> clients_;
235  std::shared_ptr<TSBarsData> tsData;
236  Window activeWindow;
237  std::shared_ptr<BaseX11Wrapper> x11Wrapper;
238 // Initialisation
243  WindowManager(Display *display, const std::shared_ptr<BaseX11Wrapper>& wrapper);
248  void selectEventOnRoot() const;
253  void getTopLevelWindows();
254 // Error Management
259  static int OnXError(Display *display, XErrorEvent *e);
267  static int onWmDetected([[maybe_unused]] Display *display, XErrorEvent *e);
272  void addGroupsFromConfig();
279  void createBars();
280 };
281 
282 void handleSIGHUP(int signal);
283 #endif //WINDOW_MANAGER_HPP
This class is responsible for managing the client windows.
ConfigHandler class header.
Logger class header.
void handleSIGHUP(int signal)
Definition: WindowManager.cpp:219
Definition: baseX11Wrapper.hpp:37
The Client class is responsible for managing the client windows. It creates a frame around the client...
Definition: Client.hpp:47
Groups are defined in the config file. Each group use a specific layout manager and manage it's list ...
Definition: Group.hpp:60
Definition: TSBarsData.hpp:32
WindowManager class This class is responsible for managing the windows.in an X11 session....
Definition: WindowManager.hpp:59
static void create(std::shared_ptr< BaseX11Wrapper > wrapper, const std::string &displayStr=std::string())
create a WindowManager object
Definition: WindowManager.cpp:45
void init()
Initialize the WindowManager set the event select mask on the root window creates clients for the exi...
Definition: WindowManager.cpp:76
Display * getDisplay() const
Get the Display object.
Definition: WindowManager.cpp:263
unsigned int getGeometryY() const
Get the Geometry Y.
Definition: WindowManager.cpp:282
unsigned long getClientCount()
Get the number of clients.
Definition: WindowManager.cpp:267
~WindowManager()
Destroy the WindowManager object i have yet to find a clean way to close the window manager.
Definition: WindowManager.cpp:71
const Atom WM_DELETE_WINDOW
Definition: WindowManager.hpp:229
static WindowManager * instance_
Definition: WindowManager.hpp:234
WindowManager(const WindowManager &)=delete
void createBars()
create the bars Bars are created from the config file and handled in a separate thread
Definition: WindowManager.cpp:140
Window activeWindow
Definition: WindowManager.hpp:236
void Run()
Run the window manager.
Definition: WindowManager.cpp:170
const Window root_
Definition: WindowManager.hpp:225
static bool wmDetected
Definition: WindowManager.hpp:224
unsigned int geometryY
Definition: WindowManager.hpp:231
std::unordered_map< Window, std::shared_ptr< Client > > & getClients()
Get the Clients map.
Definition: WindowManager.cpp:264
std::shared_ptr< Client > getClientRef(Window window)
Get a ref to the Client by window ptr does not look for frames and throws if not found.
Definition: WindowManager.cpp:265
const Atom WM_PROTOCOLS
Definition: WindowManager.hpp:228
std::shared_ptr< Client > getClient(Window window)
Get the Client by window ptr or frame ptr.
Definition: WindowManager.cpp:251
Window getRoot() const
Get the Root Window pointer.
Definition: WindowManager.cpp:266
void selectEventOnRoot() const
set the event mask on the root window and register as the window manager for the X session
Definition: WindowManager.cpp:96
void setFocus(Client *client)
Set the focus to a client.
Definition: WindowManager.cpp:208
void setActiveWindow(Window activeWindow)
set the Active Window
Definition: WindowManager.cpp:285
std::shared_ptr< Group > getActiveGroup() const
get the current Active Group
Definition: WindowManager.cpp:272
void getTopLevelWindows()
look for existing top level windows and create clients for them
Definition: WindowManager.cpp:105
static WindowManager * getInstance()
Get the WindowManager instance this is a singleton class this function returns the instance of the Wi...
Definition: WindowManager.cpp:244
void setActiveGroup(std::shared_ptr< Group > activeGroup)
Definition: WindowManager.cpp:268
std::shared_ptr< TSBarsData > tsData
Definition: WindowManager.hpp:235
static int onWmDetected([[maybe_unused]] Display *display, XErrorEvent *e)
When selecting events on the root window, we may get a BadAccess error if another window manager is r...
Definition: WindowManager.cpp:300
unsigned int geometryX
Definition: WindowManager.hpp:230
WindowManager & operator=(const WindowManager &)=delete
void testRun()
test function this function is used for testing purposes it is not used in the normal operation of th...
Definition: WindowManager.cpp:183
std::unordered_map< Window, std::shared_ptr< Client > > clients_
Definition: WindowManager.hpp:233
void insertClient(Window window)
Insert a client in the clients map.
Definition: WindowManager.cpp:195
std::weak_ptr< Group > active_group_
Definition: WindowManager.hpp:227
std::vector< std::shared_ptr< Group > > groups_
Definition: WindowManager.hpp:226
const std::shared_ptr< BaseX11Wrapper > & getX11Wrapper() const
get the X11 Wrapper object
Definition: WindowManager.cpp:284
Window getActiveWindow() const
Get the Active Window.
Definition: WindowManager.cpp:283
void Stop()
Stop the window manager.
Definition: WindowManager.cpp:225
bool running
Definition: WindowManager.hpp:232
std::shared_ptr< BaseX11Wrapper > x11Wrapper
Definition: WindowManager.hpp:237
static void Destroy()
Destroy the WindowManager instance this function destroys the WindowManager instance and sets the ins...
Definition: WindowManager.cpp:213
unsigned int getGeometryX() const
Get the Geometry X this function returns the width of the screen.
Definition: WindowManager.cpp:281
static int OnXError(Display *display, XErrorEvent *e)
X11 Error handler.
Definition: WindowManager.cpp:286
Display * display_
Definition: WindowManager.hpp:223
void addGroupsFromConfig()
add groups configured in the ConfigDataGroups to the groups vector
Definition: WindowManager.cpp:153
bool getRunning() const
Get the Running status.
Definition: WindowManager.cpp:280
const std::vector< std::shared_ptr< Group > > & getGroups() const
Get the Groups vector this function returns the groups vector the groups vector contains all the grou...
Definition: WindowManager.cpp:279