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

Groups are defined in the config file. Each group use a specific layout manager and manage it's list of clients, a client can be in multiple groups. More...

#include <Group.hpp>

Inheritance diagram for Group:
Inheritance graph
Collaboration diagram for Group:
Collaboration graph

Public Member Functions

 Group (const std::shared_ptr< ConfigDataGroup > &config, std::shared_ptr< BaseX11Wrapper > x11Wrapper, Display *display, Window root)
 Group constructor. More...
 
 ~Group ()
 Group destructor. More...
 
void addClient (Window window, std::shared_ptr< Client > client)
 Add a client to the group. More...
 
void removeClient (Window window)
 Definitely remove a client from the group. More...
 
void removeClient (Client *client)
 Definitely remove a client from the group. More...
 
void moveClientToGroup (Window window, Group *group)
 Move a client to another group. More...
 
void setActive (bool active)
 Set the group as active. More...
 
bool isActive () const
 Check if the group is active. More...
 
void setName (std::string name)
 Set the name of the group. More...
 
std::string getName ()
 Get the name of the group. More...
 
std::shared_ptr< ClientgetClient (Window window)
 Get a client from the group. More...
 
std::unordered_map< Window, std::shared_ptr< Client > > getClients ()
 Get the list of clients of the group. More...
 
std::shared_ptr< LayoutManagergetLayoutManager ()
 Get the layout manager of the group. More...
 
void switchTo ()
 Switch to this group Set this group as active, switch the layout manager and map the clients. More...
 
void switchFrom ()
 Switch from this group Set this group as inactive, switch the layout manager and unmap the clients. More...
 
int getBorderSize () const
 Get the border size of the group. More...
 
int getGap () const
 Get the gap of the group. More...
 
unsigned long getInactiveColor () const
 Get the inactive color of the group. More...
 
unsigned long getActiveColor () const
 Get the active color of the group. More...
 
void resize (unsigned int sizeX, unsigned int sizeY, unsigned int posX, unsigned int posY)
 

Private Attributes

std::string name_
 
std::unordered_map< Window, std::shared_ptr< Client > > clients_
 
std::shared_ptr< LayoutManagerlayoutManager_
 
int borderSize_
 
int gap_
 
unsigned long inactiveColor_
 
unsigned long activeColor_
 
int barHeight_
 
bool active_ {}
 
std::shared_ptr< BaseX11Wrapperwrapper
 

Detailed Description

Groups are defined in the config file. Each group use a specific layout manager and manage it's list of clients, a client can be in multiple groups.

Todo:
Rules on the WM_CLASS of the client can be defined in the config file.

Constructor & Destructor Documentation

◆ Group()

Group::Group ( const std::shared_ptr< ConfigDataGroup > &  config,
std::shared_ptr< BaseX11Wrapper x11Wrapper,
Display *  display,
Window  root 
)
explicit

Group constructor.

Parameters
nameThe name of the group
borderSizeThe size of the border
gapThe gap between the clients
barHeightThe height of the bar
layoutTypeThe layout type
Todo:
add the other layout types
38  {
39  name_ = config->getGroupName();
40  LayoutType layoutType;
41  if (config->getGroupLayout() == "Tree") {
42  layoutType = TREE;
43  } else if (config->getGroupLayout() == "Max") {
44  layoutType = MAX;
45  } else if (config->getGroupLayout() == "MasterVertical") {
46  layoutType = MASTER_VERTICAL;
47  } else if (config->getGroupLayout() == "MasterHorizontal") {
48  layoutType = MASTER_HORIZONTAL;
49  } else {
50  layoutType = TREE;
51  }
52  wrapper = x11Wrapper;
53  borderSize_ = config->getGroupBorderWidth();
54  gap_ = config->getGroupGap();
55  inactiveColor_ = config->getGroupInactiveColor();
56  activeColor_ = config->getGroupActiveColor();
57  barHeight_ = 30;
58  active_ = false;
59  Logger::GetInstance()->Log("Group Created [" + name_ + "]", L_INFO);
60  int size_x = wrapper->displayWidth(display, wrapper->defaultScreen(display));
61  int size_y = wrapper->displayHeight(display, wrapper->defaultScreen(display));
62  switch (layoutType) {
63  case TREE:
64  layoutManager_ = std::make_shared<TreeLayoutManager>(display,
65  root,
66  size_x,
67  size_y,
68  0,
69  0,
71  gap_,
72  barHeight_);
73  break;
74  case MAX:
75  break;
76  case MASTER_VERTICAL:
77  layoutManager_ = std::make_shared<TreeLayoutManager>(display,
78  root,
79  size_x,
80  size_y,
81  0,
82  0,
84  gap_,
85  barHeight_);
86  break;
87  case MASTER_HORIZONTAL:
88  layoutManager_ = std::make_shared<TreeLayoutManager>(display,
89  root,
90  size_x,
91  size_y,
92  0,
93  0,
95  gap_,
96  barHeight_);
97  break;
98  default:
99  layoutManager_ = std::make_shared<TreeLayoutManager>(display,
100  root,
101  size_x,
102  size_y,
103  0,
104  0,
105  borderSize_,
106  gap_,
107  barHeight_);
108  break;
109  }
110 }
LayoutType
LayoutType enum This enum is used to define the different layout managers.
Definition: Group.hpp:46
@ MASTER_HORIZONTAL
Definition: Group.hpp:50
@ MASTER_VERTICAL
Definition: Group.hpp:49
@ TREE
Definition: Group.hpp:47
@ MAX
Definition: Group.hpp:48
@ L_INFO
Definition: Logger.hpp:49
std::string name_
Definition: Group.hpp:186
std::shared_ptr< LayoutManager > layoutManager_
Definition: Group.hpp:188
int gap_
Definition: Group.hpp:190
unsigned long inactiveColor_
Definition: Group.hpp:191
bool active_
Definition: Group.hpp:194
int borderSize_
Definition: Group.hpp:189
unsigned long activeColor_
Definition: Group.hpp:192
int barHeight_
Definition: Group.hpp:193
std::shared_ptr< BaseX11Wrapper > wrapper
Definition: Group.hpp:195
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

References active_, activeColor_, barHeight_, borderSize_, gap_, Logger::GetInstance(), inactiveColor_, L_INFO, layoutManager_, Logger::Log(), MASTER_HORIZONTAL, MASTER_VERTICAL, MAX, name_, TREE, and wrapper.

Here is the call graph for this function:

◆ ~Group()

Group::~Group ( )

Group destructor.

111 { }

Member Function Documentation

◆ addClient()

void Group::addClient ( Window  window,
std::shared_ptr< Client client 
)

Add a client to the group.

Parameters
window
client
112  {
113  clients_[window] = client;
114  layoutManager_->addClient(client);
115 }
std::unordered_map< Window, std::shared_ptr< Client > > clients_
Definition: Group.hpp:187

References clients_, and layoutManager_.

Referenced by moveClientToGroup().

Here is the caller graph for this function:

◆ getActiveColor()

unsigned long Group::getActiveColor ( ) const

Get the active color of the group.

Returns
170 { return activeColor_; }

References activeColor_.

◆ getBorderSize()

int Group::getBorderSize ( ) const

Get the border size of the group.

Returns
167 { return borderSize_; }

References borderSize_.

◆ getClient()

Client * Group::getClient ( Window  window)

Get a client from the group.

Parameters
window
164 { return clients_[window]; }

References clients_.

◆ getClients()

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

Get the list of clients of the group.

165 { return clients_; }

References clients_.

Referenced by switchFrom(), and switchTo().

Here is the caller graph for this function:

◆ getGap()

int Group::getGap ( ) const

Get the gap of the group.

Returns
168 { return gap_; }

References gap_.

◆ getInactiveColor()

unsigned long Group::getInactiveColor ( ) const

Get the inactive color of the group.

Returns
169 { return inactiveColor_; }

References inactiveColor_.

◆ getLayoutManager()

LayoutManager * Group::getLayoutManager ( )

Get the layout manager of the group.

166 { return layoutManager_; }

References layoutManager_.

◆ getName()

std::string Group::getName ( )

Get the name of the group.

Returns
163 { return name_; }

References name_.

◆ isActive()

bool Group::isActive ( ) const

Check if the group is active.

Returns
bool
162 { return active_; }

References active_.

◆ moveClientToGroup()

void Group::moveClientToGroup ( Window  window,
Group group 
)

Move a client to another group.

Parameters
window
group
130  {
131  clients_.erase(window);
132  try {
133  auto c = WindowManager::getInstance()->getClient(window);
134  group->addClient(window, c);
135  } catch (const std::exception &e) {
136  Logger::GetInstance()->Log(e.what(), L_ERROR);
137  }
138 }
@ L_ERROR
Definition: Logger.hpp:51
void addClient(Window window, std::shared_ptr< Client > client)
Add a client to the group.
Definition: Group.cpp:112
std::shared_ptr< Client > getClient(Window window)
Get the Client by window ptr or frame ptr.
Definition: WindowManager.cpp:251
static WindowManager * getInstance()
Get the WindowManager instance this is a singleton class this function returns the instance of the Wi...
Definition: WindowManager.cpp:244

References addClient(), clients_, WindowManager::getClient(), Logger::GetInstance(), WindowManager::getInstance(), L_ERROR, and Logger::Log().

Here is the call graph for this function:

◆ removeClient() [1/2]

void Group::removeClient ( Client client)

Definitely remove a client from the group.

Parameters
client
125  {
126  clients_.erase(client->getWindow());
127  layoutManager_->removeClient(client);
128 }
Window getWindow() const
Client::getWindow return the window attribute of the client.
Definition: Client.cpp:175

References clients_, Client::getWindow(), and layoutManager_.

Here is the call graph for this function:

◆ removeClient() [2/2]

void Group::removeClient ( Window  window)

Definitely remove a client from the group.

Parameters
window
116  {
117  clients_.erase(window);
118  try {
119  auto c = WindowManager::getInstance()->getClient(window);
120  layoutManager_->removeClient(c.get());
121  } catch (const std::exception &e) {
122  Logger::GetInstance()->Log(e.what(), L_ERROR);
123  }
124 }

References clients_, WindowManager::getClient(), Logger::GetInstance(), WindowManager::getInstance(), L_ERROR, layoutManager_, and Logger::Log().

Here is the call graph for this function:

◆ resize()

void Group::resize ( unsigned int  sizeX,
unsigned int  sizeY,
unsigned int  posX,
unsigned int  posY 
)
172  {
173  layoutManager_->updateGeometry(sizeX, sizeY, posX, posY);
174 }

References layoutManager_.

◆ setActive()

void Group::setActive ( bool  active)

Set the group as active.

Parameters
active
129 { active_ = active; }

References active_.

◆ setName()

void Group::setName ( std::string  name)

Set the name of the group.

Parameters
name
159  {
160  name_ = std::move(name);
161 }

References name_.

◆ switchFrom()

void Group::switchFrom ( )

Switch from this group Set this group as inactive, switch the layout manager and unmap the clients.

149  {
150  Logger::GetInstance()->Log("Group switched from [" + name_ + "]", L_INFO);
151  for (auto &client: WindowManager::getInstance()->getClients()) {
152  if (client.second->getGroup().get() == this) {
153 // client.second->unframe();
154  wrapper->unmapWindow(WindowManager::getInstance()->getDisplay(), client.second->getFrame());
155  }
156  }
157  this->active_ = false;
158 }
std::unordered_map< Window, std::shared_ptr< Client > > getClients()
Get the list of clients of the group.
Definition: Group.cpp:165

References active_, getClients(), Logger::GetInstance(), WindowManager::getInstance(), L_INFO, Logger::Log(), name_, and wrapper.

Here is the call graph for this function:

◆ switchTo()

void Group::switchTo ( )

Switch to this group Set this group as active, switch the layout manager and map the clients.

139  {
140  Logger::GetInstance()->Log("Group switched to [" + name_ + "]", L_INFO);
141  for (auto &client: WindowManager::getInstance()->getClients()) {
142  if (client.second->getGroup().get() == this) {
143  wrapper->mapWindow(WindowManager::getInstance()->getDisplay(), client.second->getFrame());
144  }
145  }
146  this->active_= true;
147  WindowManager::getInstance()->setActiveGroup(shared_from_this());
148 }
void setActiveGroup(std::shared_ptr< Group > activeGroup)
Definition: WindowManager.cpp:268

References active_, getClients(), Logger::GetInstance(), WindowManager::getInstance(), L_INFO, Logger::Log(), name_, WindowManager::setActiveGroup(), and wrapper.

Here is the call graph for this function:

Member Data Documentation

◆ active_

bool Group::active_ {}
private

◆ activeColor_

unsigned long Group::activeColor_
private

Referenced by getActiveColor(), and Group().

◆ barHeight_

int Group::barHeight_
private

Referenced by Group().

◆ borderSize_

int Group::borderSize_
private

Referenced by getBorderSize(), and Group().

◆ clients_

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

◆ gap_

int Group::gap_
private

Referenced by getGap(), and Group().

◆ inactiveColor_

unsigned long Group::inactiveColor_
private

Referenced by getInactiveColor(), and Group().

◆ layoutManager_

std::shared_ptr<LayoutManager> Group::layoutManager_
private

◆ name_

std::string Group::name_
private

◆ wrapper

std::shared_ptr<BaseX11Wrapper> Group::wrapper
private

Referenced by Group(), switchFrom(), and switchTo().


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