YggdrasilWM  0.1.1
A tiny window manager coded in C++
WindowManager Class Reference

WindowManager class This class is responsible for managing the windows.in an X11 session. It is the main class of the project. It should be instantiated only via the static create function. You must use the init function to initialize the WindowManager. The Run function is the main loop of the WindowManager. More...

#include <WindowManager.hpp>

Collaboration diagram for WindowManager:
Collaboration graph

Public Member Functions

 WindowManager (const WindowManager &)=delete
 
WindowManageroperator= (const WindowManager &)=delete
 
 ~WindowManager ()
 Destroy the WindowManager object i have yet to find a clean way to close the window manager. More...
 
void init ()
 Initialize the WindowManager set the event select mask on the root window creates clients for the existing top level windows and launch the bar window. More...
 
void Run ()
 Run the window manager. More...
 
Display * getDisplay () const
 Get the Display object. More...
 
Window getRoot () const
 Get the Root Window pointer. More...
 
std::unordered_map< Window, std::shared_ptr< Client > > & getClients ()
 Get the Clients map. More...
 
std::shared_ptr< ClientgetClient (Window window)
 Get the Client by window ptr or frame ptr. More...
 
std::shared_ptr< ClientgetClientRef (Window window)
 Get a ref to the Client by window ptr does not look for frames and throws if not found. More...
 
unsigned long getClientCount ()
 Get the number of clients. More...
 
void setFocus (Client *client)
 Set the focus to a client. More...
 
void insertClient (Window window)
 Insert a client in the clients map. More...
 
void Stop ()
 Stop the window manager. More...
 
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 groups the groups are the workspaces of the window manager the active group is the one that is currently displayed the groups are created from the config file the active group is set to the first group in the vector the active group can be changed by the user. More...
 
std::shared_ptr< GroupgetActiveGroup () const
 get the current Active Group More...
 
bool getRunning () const
 Get the Running status. More...
 
void setActiveGroup (std::shared_ptr< Group > activeGroup)
 
void setActiveGroup (Group *activeGroup)
 set the current active group More...
 
void testRun ()
 test function this function is used for testing purposes it is not used in the normal operation of the window manager More...
 
unsigned int getGeometryX () const
 Get the Geometry X this function returns the width of the screen. More...
 
unsigned int getGeometryY () const
 Get the Geometry Y. More...
 
Window getActiveWindow () const
 Get the Active Window. More...
 
void setActiveWindow (Window activeWindow)
 set the Active Window More...
 
const std::shared_ptr< BaseX11Wrapper > & getX11Wrapper () const
 get the X11 Wrapper object More...
 

Static Public Member Functions

static void create (std::shared_ptr< BaseX11Wrapper > wrapper, const std::string &displayStr=std::string())
 create a WindowManager object More...
 
static WindowManagergetInstance ()
 Get the WindowManager instance this is a singleton class this function returns the instance of the WindowManager if it does not exist, it creates it. More...
 
static void Destroy ()
 Destroy the WindowManager instance this function destroys the WindowManager instance and sets the instance_ pointer to nullptr this is a singleton class this function should be called when the WindowManager is no longer needed. More...
 

Private Member Functions

 WindowManager (Display *display, const std::shared_ptr< BaseX11Wrapper > &wrapper)
 
void selectEventOnRoot () const
 set the event mask on the root window and register as the window manager for the X session More...
 
void getTopLevelWindows ()
 look for existing top level windows and create clients for them More...
 
void addGroupsFromConfig ()
 add groups configured in the ConfigDataGroups to the groups vector More...
 
void createBars ()
 create the bars Bars are created from the config file and handled in a separate thread More...
 

Static Private Member Functions

static int OnXError (Display *display, XErrorEvent *e)
 X11 Error handler. More...
 
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 running this function is called when a BadAccess error is detected it sets the wmDetected flag to true and stops the window manager only one window manager can run at a time. More...
 

Private Attributes

Display * display_
 
const Window root_
 
std::vector< std::shared_ptr< Group > > groups_
 
std::weak_ptr< Groupactive_group_ {}
 
const Atom WM_PROTOCOLS
 
const Atom WM_DELETE_WINDOW
 
unsigned int geometryX {}
 
unsigned int geometryY {}
 
bool running
 
std::unordered_map< Window, std::shared_ptr< Client > > clients_
 
std::shared_ptr< TSBarsDatatsData
 
Window activeWindow
 
std::shared_ptr< BaseX11Wrapperx11Wrapper
 

Static Private Attributes

static bool wmDetected
 
static WindowManagerinstance_ = nullptr
 

Detailed Description

WindowManager class This class is responsible for managing the windows.in an X11 session. It is the main class of the project. It should be instantiated only via the static create function. You must use the init function to initialize the WindowManager. The Run function is the main loop of the WindowManager.

Constructor & Destructor Documentation

◆ WindowManager() [1/2]

WindowManager::WindowManager ( const WindowManager )
delete

Referenced by create().

Here is the caller graph for this function:

◆ ~WindowManager()

WindowManager::~WindowManager ( )

Destroy the WindowManager object i have yet to find a clean way to close the window manager.

71  {
72  clients_.clear();
73  groups_.clear();
74  Logger::GetInstance()->Log("WindowManager destroyed", L_INFO);
75 }
@ L_INFO
Definition: Logger.hpp:49
virtual void Log(const std::string &message, LogLevel level) const
Log a message This method logs a message to the log file or stream. The message is only logged if the...
Definition: Logger.cpp:73
static Logger * GetInstance()
Get the Logger object.
Definition: Logger.cpp:41
std::unordered_map< Window, std::shared_ptr< Client > > clients_
Definition: WindowManager.hpp:233
std::vector< std::shared_ptr< Group > > groups_
Definition: WindowManager.hpp:226

References clients_, Logger::GetInstance(), groups_, L_INFO, and Logger::Log().

Here is the call graph for this function:

◆ WindowManager() [2/2]

WindowManager::WindowManager ( Display *  display,
const std::shared_ptr< BaseX11Wrapper > &  wrapper 
)
private
61  : display_(display),
62  root_(DefaultRootWindow(display)),
63  WM_PROTOCOLS( wrapper->internAtom(display_, "WM_PROTOCOLS", false)),
64  WM_DELETE_WINDOW(wrapper->internAtom(display_, "WM_DELETE_WINDOW", false)),
65  running(true),
66  tsData(nullptr),
67  geometryX(0),
68  geometryY(0),
69  activeWindow(0),
70  x11Wrapper(wrapper){}
const Atom WM_DELETE_WINDOW
Definition: WindowManager.hpp:229
Window activeWindow
Definition: WindowManager.hpp:236
const Window root_
Definition: WindowManager.hpp:225
unsigned int geometryY
Definition: WindowManager.hpp:231
const Atom WM_PROTOCOLS
Definition: WindowManager.hpp:228
std::shared_ptr< TSBarsData > tsData
Definition: WindowManager.hpp:235
unsigned int geometryX
Definition: WindowManager.hpp:230
bool running
Definition: WindowManager.hpp:232
std::shared_ptr< BaseX11Wrapper > x11Wrapper
Definition: WindowManager.hpp:237
Display * display_
Definition: WindowManager.hpp:223

Member Function Documentation

◆ addGroupsFromConfig()

void WindowManager::addGroupsFromConfig ( )
private

add groups configured in the ConfigDataGroups to the groups vector

153  {
155  std::string groupsNames = "";
156  for (auto group: configGroups) {
157  std::shared_ptr<Group> g = std::make_shared<Group>(group, x11Wrapper,display_,root_);
158  groupsNames += g->getName() + ",";
159  groups_.push_back(g);
160  }
161  if (groupsNames.back() == ',') {
162  groupsNames.pop_back();
163  }
164  tsData->addData("Groups", groupsNames);
165  groups_[0]->setActive(true);
166  tsData->addData("ActiveGroup", groups_[0]->getName());
167  active_group_ = groups_[0];
168  Logger::GetInstance()->Log("Active Group is [" + getActiveGroup()->getName() + "]", L_INFO);
169 }
ConfigDataGroups class. stores an array of ConfigDataGroup created from the config file.
Definition: ConfigDataGroups.hpp:41
static ConfigHandler & GetInstance()
Get the ConfigHandler object Throws an exception if the object is not created.
Definition: ConfigHandler.cpp:46
std::shared_ptr< T > getConfigData()
Get the ConfigData object of type T.
Definition: ConfigHandler.hpp:66
std::shared_ptr< Group > getActiveGroup() const
get the current Active Group
Definition: WindowManager.cpp:272
std::weak_ptr< Group > active_group_
Definition: WindowManager.hpp:227
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

References active_group_, display_, getActiveGroup(), ConfigHandler::getConfigData(), getGroups(), ConfigHandler::GetInstance(), Logger::GetInstance(), groups_, L_INFO, Logger::Log(), root_, tsData, and x11Wrapper.

Referenced by getTopLevelWindows().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ create()

void WindowManager::create ( std::shared_ptr< BaseX11Wrapper wrapper,
const std::string &  displayStr = std::string() 
)
static

create a WindowManager object

Parameters
displayStrOptional X Display string if not set, the DISPLAY environment variable will be used
45  {
46  Logger::GetInstance()->Log("================ Yggdrasil Initialisation ================\n\n", L_INFO);
47  if (WindowManager::instance_ != nullptr) {
48  throw std::runtime_error("WindowManager instance already created");
49  }
50  const char *displayCStr =
51  displayStr.empty() ? nullptr : displayStr.c_str();
52  Display *display = XOpenDisplay(displayCStr);
53  if (display == nullptr) {
54  Logger::GetInstance()->Log("Failed to open X display " + std::string(XDisplayName(displayCStr)), L_ERROR);
55  throw std::runtime_error("Failed to open X display");
56  }
57  Logger::GetInstance()->Log("Opened X Display:\t" + std::string(XDisplayName(displayCStr)), L_INFO);
58  WindowManager::instance_ = new WindowManager(display,wrapper);
59 }
@ L_ERROR
Definition: Logger.hpp:51
static WindowManager * instance_
Definition: WindowManager.hpp:234
WindowManager(const WindowManager &)=delete

References Logger::GetInstance(), instance_, L_ERROR, L_INFO, Logger::Log(), and WindowManager().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createBars()

void WindowManager::createBars ( )
private

create the bars Bars are created from the config file and handled in a separate thread

Note
communication between main thread and Bars thread is handled in Thread Safe way by the TSBarsData class
140  {
142  Bars::getInstance().init(ConfigHandler::GetInstance().getConfigData<ConfigDataBars>(), tsData, display_, root_);
144  auto g = getActiveGroup();
145  unsigned int sizeX = geometryX- Bars::getInstance().getSpaceE() - Bars::getInstance().getSpaceW() - g->getBorderSize() * 2;
146  unsigned int sizeY = geometryY - Bars::getInstance().getSpaceN() - Bars::getInstance().getSpaceS() - g->getBorderSize() * 2;
147  unsigned int posX = Bars::getInstance().getSpaceW();
148  unsigned int posY = Bars::getInstance().getSpaceN();
149  for (auto &g:groups_) {
150  g->resize(sizeX,sizeY,posX,posY);
151  }
152 }
unsigned int getSpaceE() const
Get the spaceE value used to calculate the space left for the Layout Manager.
Definition: Bars.cpp:188
unsigned int getSpaceS() const
Get the spaceS value used to calculate the space left for the Layout Manager.
Definition: Bars.cpp:187
void start_thread()
Definition: Bars.cpp:90
unsigned int getSpaceN() const
Get the spaceN value used to calculate the space left for the Layout Manager.
Definition: Bars.cpp:186
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
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

References Bars::createInstance(), display_, geometryX, geometryY, getActiveGroup(), Bars::getInstance(), ConfigHandler::GetInstance(), Bars::getSpaceE(), Bars::getSpaceN(), Bars::getSpaceS(), Bars::getSpaceW(), groups_, Bars::init(), root_, Bars::start_thread(), and tsData.

Referenced by init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Destroy()

static void WindowManager::Destroy ( )
static

Destroy the WindowManager instance this function destroys the WindowManager instance and sets the instance_ pointer to nullptr this is a singleton class this function should be called when the WindowManager is no longer needed.

213  {
214  if (WindowManager::instance_ != nullptr) {
216  WindowManager::instance_ = nullptr;
217  }
218 }

References instance_.

Referenced by main().

Here is the caller graph for this function:

◆ getActiveGroup()

Group * WindowManager::getActiveGroup ( ) const

get the current Active Group

Returns
272  {
273  auto g = active_group_.lock();
274  if (g)
275  return g;
276  else
277  throw YggdrasilException("invalid active group");
278 }
Definition: YggdrasilExceptions.hpp:32

References active_group_.

Referenced by addGroupsFromConfig(), createBars(), FocusGroup::execute(), Grow::execute(), getTopLevelWindows(), EventHandler::handleDestroyNotify(), and insertClient().

Here is the caller graph for this function:

◆ getActiveWindow()

void WindowManager::getActiveWindow ( ) const

Get the Active Window.

283 { return activeWindow; }

References activeWindow.

◆ getClient()

Client * WindowManager::getClient ( Window  window)

Get the Client by window ptr or frame ptr.

Parameters
window
Returns
nullptr if not found
251  {
252  auto clientIter = clients_.find(window);
253  if (clientIter != clients_.end()) {
254  return clientIter->second;
255  }
256  for (const auto &client: clients_) {
257  if (client.second->getFrame() == window) {
258  return client.second;
259  }
260  }
261  return nullptr;
262 }

References clients_.

Referenced by Grow::execute(), EventHandler::handleButtonPress(), EventHandler::handleFocusIn(), EventHandler::handleFocusOut(), EventHandler::handleMapNotify(), Group::moveClientToGroup(), and Group::removeClient().

Here is the caller graph for this function:

◆ getClientCount()

unsigned long WindowManager::getClientCount ( )

Get the number of clients.

267 { return clients_.size(); }

References clients_.

◆ getClientRef()

Client & WindowManager::getClientRef ( Window  window)

Get a ref to the Client by window ptr does not look for frames and throws if not found.

265 { return clients_.at(window); }

References clients_.

Referenced by EventHandler::handleDestroyNotify(), EventHandler::handleMapRequest(), EventHandler::handleMotionNotify(), and EventHandler::handleUnmapNotify().

Here is the caller graph for this function:

◆ getClients()

std::unordered_map< Window, Client * > & WindowManager::getClients ( )

Get the Clients map.

264 { return clients_; }

References clients_.

Referenced by EventHandler::handleDestroyNotify(), and EventHandler::handleUnmapNotify().

Here is the caller graph for this function:

◆ getDisplay()

Display * WindowManager::getDisplay ( ) const

Get the Display object.

263 { return display_; }

References display_.

Referenced by EventHandler::handleClientMessage(), EventHandler::handleUnmapNotify(), and Bar::init().

Here is the caller graph for this function:

◆ getGeometryX()

void WindowManager::getGeometryX ( ) const

Get the Geometry X this function returns the width of the screen.

281 { return geometryX; }

References geometryX.

Referenced by ewmh::updateDesktopGeometry().

Here is the caller graph for this function:

◆ getGeometryY()

void WindowManager::getGeometryY ( ) const

Get the Geometry Y.

282 { return geometryY; }

References geometryY.

Referenced by ewmh::updateDesktopGeometry().

Here is the caller graph for this function:

◆ getGroups()

const std::vector< Group * > & WindowManager::getGroups ( ) const

Get the Groups vector this function returns the groups vector the groups vector contains all the groups the groups are the workspaces of the window manager the active group is the one that is currently displayed the groups are created from the config file the active group is set to the first group in the vector the active group can be changed by the user.

Returns
279 { return groups_; }

References groups_.

Referenced by addGroupsFromConfig(), FocusGroup::execute(), and ewmh::updateNumberOfDesktops().

Here is the caller graph for this function:

◆ getInstance()

◆ getRoot()

Window WindowManager::getRoot ( ) const

◆ getRunning()

bool WindowManager::getRunning ( ) const

Get the Running status.

280 { return running; }

References running.

◆ getTopLevelWindows()

void WindowManager::getTopLevelWindows ( )
private

look for existing top level windows and create clients for them

105  {
106  Window returnedRoot, returnedParent;
107  Window *topLevelWindows;
108  unsigned int numTopLevelWindows;
109  x11Wrapper->queryTree(
110  display_,
111  root_,
112  &returnedRoot,
113  &returnedParent,
114  &topLevelWindows,
115  &numTopLevelWindows);
116  if (returnedRoot != root_) {
117  throw std::runtime_error("Root window is not the same as the one returned by XQueryTree");
118  }
120  Logger::GetInstance()->Log("Found " + std::to_string(numTopLevelWindows) + " top level windows.\troot:" + std::to_string(root_), L_INFO);
121  for (unsigned int i = 0; i < numTopLevelWindows; ++i) {
122  std::shared_ptr<Client> newClient = nullptr;
123  try {
124  auto g = getActiveGroup();
125  newClient = std::make_shared<Client>(display_, root_, topLevelWindows[i], g,
126  g->getInactiveColor(), g->getBorderSize(), x11Wrapper);
127  newClient->frame();
128  g->addClient(newClient->getWindow(),newClient);
129  setFocus(newClient.get());
130  } catch (const YggdrasilException &e) {
131  Logger::GetInstance()->Log(e.what(), L_ERROR);
132  continue;
133  }
134  if (newClient != nullptr) {
135  clients_[newClient->getWindow()] = newClient;
136  }
137  }
138  x11Wrapper->freeX(topLevelWindows);
139 }
void setFocus(Client *client)
Set the focus to a client.
Definition: WindowManager.cpp:208
void addGroupsFromConfig()
add groups configured in the ConfigDataGroups to the groups vector
Definition: WindowManager.cpp:153

References addGroupsFromConfig(), clients_, display_, getActiveGroup(), Logger::GetInstance(), L_ERROR, L_INFO, Logger::Log(), root_, setFocus(), and x11Wrapper.

Referenced by init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getX11Wrapper()

std::shared_ptr< BaseX11Wrapper > WindowManager::getX11Wrapper ( ) const

get the X11 Wrapper object

284 { return x11Wrapper; }

References x11Wrapper.

Referenced by EventHandler::EventHandler(), and OnXError().

Here is the caller graph for this function:

◆ init()

void WindowManager::init ( )

Initialize the WindowManager set the event select mask on the root window creates clients for the existing top level windows and launch the bar window.

76  {
79  if (wmDetected) {
80  throw std::runtime_error("Another window manager is already running.");
81  }
83  geometryX = x11Wrapper->displayWidth(display_, x11Wrapper->defaultScreen(display_));
84  geometryY = x11Wrapper->displayHeight(display_, x11Wrapper->defaultScreen(display_));
85  x11Wrapper->grabServer(display_);
87  tsData = std::make_shared<TSBarsData>();
89  createBars();
90  x11Wrapper->ungrabServer(display_);
92  x11Wrapper->flush(display_);
93  tsData->addData("EvCount", "0");
94  signal(SIGINT, handleSIGHUP);
95 }
void handleSIGHUP(int signal)
Definition: WindowManager.cpp:219
ConfigDataBindings class. This class is used to handle the bindings configuration it instanciates the...
Definition: ConfigDataBindings.hpp:45
void createBars()
create the bars Bars are created from the config file and handled in a separate thread
Definition: WindowManager.cpp:140
static bool wmDetected
Definition: WindowManager.hpp:224
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 getTopLevelWindows()
look for existing top level windows and create clients for them
Definition: WindowManager.cpp:105
void updateWmProperties(Display *display, Window root)
Definition: Ewmh.cpp:124
void initEwmh(Display *display, Window root)
register the supported EWMH atoms.
Definition: Ewmh.cpp:34

References createBars(), display_, geometryX, geometryY, ConfigHandler::getConfigData(), ConfigHandler::GetInstance(), getTopLevelWindows(), handleSIGHUP(), ewmh::initEwmh(), root_, selectEventOnRoot(), tsData, ewmh::updateWmProperties(), wmDetected, and x11Wrapper.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ insertClient()

void WindowManager::insertClient ( Window  window)

Insert a client in the clients map.

Parameters
window
195  {
196  try {
197  int borderSize = getActiveGroup()->getBorderSize();
198  unsigned long inactiveColor = getActiveGroup()->getInactiveColor();
199  std::shared_ptr<Client> client = std::make_shared<Client>(display_, root_, window, getActiveGroup(), inactiveColor,
200  borderSize, x11Wrapper);
202  "Inserting client in map: " + client->getTitle() + "\t[" + std::to_string(window) + "]", L_INFO);
203  clients_.insert({window, client});
204  } catch (const YggdrasilException &e) {
205  Logger::GetInstance()->Log(e.what(), L_ERROR);
206  }
207 }

References clients_, display_, getActiveGroup(), Logger::GetInstance(), L_ERROR, L_INFO, Logger::Log(), root_, and x11Wrapper.

Referenced by EventHandler::handleMapRequest().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onWmDetected()

static int WindowManager::onWmDetected ( [[maybe_unused] ] Display *  display,
XErrorEvent *  e 
)
staticprivate

When selecting events on the root window, we may get a BadAccess error if another window manager is running this function is called when a BadAccess error is detected it sets the wmDetected flag to true and stops the window manager only one window manager can run at a time.

300  {
301  if (static_cast<int>(e->error_code) == BadAccess)
302  wmDetected = true;
303  return 0;
304 }

References wmDetected.

Referenced by selectEventOnRoot().

Here is the caller graph for this function:

◆ OnXError()

static int WindowManager::OnXError ( Display *  display,
XErrorEvent *  e 
)
staticprivate

X11 Error handler.

286  {
287  const int MAX_ERROR_TEXT_LENGTH = 1024;
288  char errorText[MAX_ERROR_TEXT_LENGTH];
289  WindowManager::getInstance()->getX11Wrapper()->getErrorText(display, e->error_code, errorText, sizeof(errorText));
290  std::stringstream errorStream;
291  errorStream << "Received X error:\n"
292  << " Request: " << int(e->request_code)
293  << " Error code: " << int(e->error_code)
294  << " - " << errorText << "\n"
295  << " Resource ID: " << e->resourceid;
296  Logger::GetInstance()->Log(errorStream.str(), L_ERROR);
297  // The return value is ignored.
298  return 0;
299 }
static WindowManager * getInstance()
Get the WindowManager instance this is a singleton class this function returns the instance of the Wi...
Definition: WindowManager.cpp:244
const std::shared_ptr< BaseX11Wrapper > & getX11Wrapper() const
get the X11 Wrapper object
Definition: WindowManager.cpp:284

References Logger::GetInstance(), getInstance(), getX11Wrapper(), L_ERROR, and Logger::Log().

Referenced by selectEventOnRoot().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

WindowManager& WindowManager::operator= ( const WindowManager )
delete

◆ Run()

void WindowManager::Run ( )

Run the window manager.

170  {
171  Logger::GetInstance()->Log("================ Yggdrasil WM Running ================\n\n", L_INFO);
173  XEvent e;
174 // int evcount = 0;
175  while (running && !x11Wrapper->nextEvent(display_, &e)) {
177  x11Wrapper->sync(display_, false);
178 // tsData->modifyData("EvCount", std::to_string(evcount++));
179  }
180  Logger::GetInstance()->Log("WindowManager stopped", L_INFO);
181 // XCloseDisplay(display_);
182 }
static EventHandler * getInstance()
Get the Event handler:: Event handler object.
Definition: EventHandler.cpp:87
static void create()
create the Event handler:: Event handler object
Definition: EventHandler.cpp:81
void dispatchEvent(const XEvent &event)
Dispatches the event to the appropriate handler function. the eventHandlerArray is an array of pointe...
Definition: EventHandler.cpp:119

References EventHandler::create(), EventHandler::dispatchEvent(), display_, EventHandler::getInstance(), Logger::GetInstance(), L_INFO, Logger::Log(), running, and x11Wrapper.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ selectEventOnRoot()

void WindowManager::selectEventOnRoot ( ) const
private

set the event mask on the root window and register as the window manager for the X session

96  {
97  x11Wrapper->setErrorHandler(&WindowManager::onWmDetected);
98  x11Wrapper->selectInput(
99  display_,
100  root_,
101  SubstructureRedirectMask | SubstructureNotifyMask | FocusChangeMask | ClientMessage);
102  x11Wrapper->setErrorHandler(&WindowManager::OnXError);
103  x11Wrapper->sync(display_, false);
104 }
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
static int OnXError(Display *display, XErrorEvent *e)
X11 Error handler.
Definition: WindowManager.cpp:286

References display_, onWmDetected(), OnXError(), root_, and x11Wrapper.

Referenced by init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setActiveGroup() [1/2]

void WindowManager::setActiveGroup ( Group activeGroup)

set the current active group

Parameters
activeGroup
306  {
307  WindowManager::active_group_ = std::shared_ptr<Group>(activeGroup);
308 }

References active_group_.

◆ setActiveGroup() [2/2]

void WindowManager::setActiveGroup ( std::shared_ptr< Group activeGroup)
268  {
269  tsData->modifyData("ActiveGroup", activeGroup->getName());
270  active_group_ = std::weak_ptr<Group> (activeGroup);
271 }

References active_group_, and tsData.

Referenced by Group::switchTo().

Here is the caller graph for this function:

◆ setActiveWindow()

void WindowManager::setActiveWindow ( Window  activeWindow)

set the Active Window

Parameters
activeWindow
285 { WindowManager::activeWindow = aWindow; }

References activeWindow.

Referenced by EventHandler::handleFocusIn(), and EventHandler::handleFocusOut().

Here is the caller graph for this function:

◆ setFocus()

void WindowManager::setFocus ( Client client)

Set the focus to a client.

208  {
209  if (client != nullptr) {
210  x11Wrapper->setInputFocus(display_, client->getWindow(), RevertToParent, CurrentTime);
211  }
212 }
Window getWindow() const
Client::getWindow return the window attribute of the client.
Definition: Client.cpp:175

References display_, Client::getWindow(), and x11Wrapper.

Referenced by getTopLevelWindows(), EventHandler::handleDestroyNotify(), and EventHandler::handleMapRequest().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Stop()

void WindowManager::Stop ( )

Stop the window manager.

Todo:
: implement a clean way to stop the window manager
225  {
226  this->running = false;
227  XClientMessageEvent ev;
228  memset(&ev, 0, sizeof(ev));
229  ev.type = ClientMessage;
230  ev.window = root_;
231  ev.message_type = XInternAtom(display_, "WM_PROTOCOLS", False);
232  ev.format = 32;
233  ev.data.l[0] = static_cast<long>(XInternAtom(display_, "WM_DELETE_WINDOW", False));
234  try {
235  x11Wrapper->sendEvent(display_, root_, False, NoEventMask, (XEvent *) &ev);
236  x11Wrapper->flush(display_); // Ensure the event is sent immediately
237  } catch (const YggdrasilException &e) {
238  std::cerr << e.what();
239  }
241  Bars::destroy();
242  std::cout << "Stopping WindowManager" << std::endl;
243 }
void stop_thread()
Stop the thread (join)
Definition: Bars.cpp:195
static void destroy()
Destroy the singleton instance if the instance is not created, it will do nothing.
Definition: Bars.cpp:182

References Bars::destroy(), display_, Bars::getInstance(), root_, running, Bars::stop_thread(), and x11Wrapper.

Referenced by Quit::execute(), and handleSIGHUP().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ testRun()

void WindowManager::testRun ( )

test function this function is used for testing purposes it is not used in the normal operation of the window manager

183  {
184  try {
186  } catch (const std::exception &e) {
188  }
189  XSync(display_, false);
190  XEvent ev;
191  x11Wrapper->nextEvent(display_, &ev);
193  x11Wrapper->sync(display_, false);
194 }

References EventHandler::create(), EventHandler::dispatchEvent(), display_, EventHandler::getInstance(), and x11Wrapper.

Here is the call graph for this function:

Member Data Documentation

◆ active_group_

std::weak_ptr<Group> WindowManager::active_group_ {}
private

◆ activeWindow

Window WindowManager::activeWindow
private

Referenced by getActiveWindow(), and setActiveWindow().

◆ clients_

std::unordered_map<Window, std::shared_ptr<Client> > WindowManager::clients_
private

◆ display_

◆ geometryX

unsigned int WindowManager::geometryX {}
private

Referenced by createBars(), getGeometryX(), and init().

◆ geometryY

unsigned int WindowManager::geometryY {}
private

Referenced by createBars(), getGeometryY(), and init().

◆ groups_

std::vector<std::shared_ptr<Group> > WindowManager::groups_
private

◆ instance_

WindowManager * WindowManager::instance_ = nullptr
staticprivate

Referenced by create(), Destroy(), and getInstance().

◆ root_

const Window WindowManager::root_
private

◆ running

bool WindowManager::running
private

Referenced by getRunning(), Run(), and Stop().

◆ tsData

std::shared_ptr<TSBarsData> WindowManager::tsData
private

◆ WM_DELETE_WINDOW

const Atom WindowManager::WM_DELETE_WINDOW
private

◆ WM_PROTOCOLS

const Atom WindowManager::WM_PROTOCOLS
private

◆ wmDetected

bool WindowManager::wmDetected
staticprivate

Referenced by init(), and onWmDetected().

◆ x11Wrapper


The documentation for this class was generated from the following files: