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

The Client class is responsible for managing the client windows. It creates a frame around the client window, Map the frame, Add the window to the save set, Reparent it, grab the buttons It also unframe the client window by removing the frame and reparenting the window to the root window It also move, resize, restack the client window. More...

#include <Client.hpp>

Collaboration diagram for Client:
Collaboration graph

Public Member Functions

 Client (Display *display, Window root, Window window, std::shared_ptr< Group > group, unsigned long inActiveColor, int borderSize, std::shared_ptr< BaseX11Wrapper > wrapper)
 Client constructor.get window class and title. More...
 
 ~Client ()
 Client destructor Destroy the Client object & the Frame Window it needed. More...
 
void frame ()
 Client::frame create a frame around the client window, Map the frame, Add the window to the save set Reparent it, grab the buttons. More...
 
void unframe ()
 Client::unframe unframe the client window by removing the frame and reparenting the window to the root window. More...
 
Window getWindow () const
 Client::getWindow return the window attribute of the client. More...
 
std::shared_ptr< GroupgetGroup () const
 return the group of the client More...
 
void move (int x, int y)
 : Client::move move the client window to the given position More...
 
void resize (unsigned int width, unsigned int height)
 Client::resize resize the client window to the given size. More...
 
bool isFramed () const
 Client::isFramed() check if the client is framed. More...
 
void setMapped (bool mapped)
 Client::setMapped() set the mapped status of the client. More...
 
bool isMapped () const
 Client::isMapped() check if the client is mapped. More...
 
const std::string & getTitle () const
 Client::getTitle() return the title of the client, the title is get during the construction of the client. More...
 
const std::string & getClass () const
 Client::getClass() return the class of the client, the class is get during the construction of the client. More...
 
Window getFrame () const
 Client::getFrame() return the frame Window of the client. More...
 
void restack ()
 Client::restack() restack the client window to avoid the frame to get in front of the client. More...
 
void setGroup (std::shared_ptr< Group > g)
 

Private Attributes

Display * display_
 
Window root_
 
Window window_
 
Window frame_
 
unsigned int border_width
 
unsigned long border_color
 
bool framed
 
bool mapped {}
 
std::string title_
 
std::string class_
 
std::weak_ptr< Groupgroup_
 
std::shared_ptr< BaseX11Wrapperwrapper
 

Detailed Description

The Client class is responsible for managing the client windows. It creates a frame around the client window, Map the frame, Add the window to the save set, Reparent it, grab the buttons It also unframe the client window by removing the frame and reparenting the window to the root window It also move, resize, restack the client window.

Constructor & Destructor Documentation

◆ Client()

Client::Client ( Display *  display,
Window  root,
Window  window,
std::shared_ptr< Group group,
unsigned long  inActiveColor,
int  borderSize,
std::shared_ptr< BaseX11Wrapper wrapper 
)

Client constructor.get window class and title.

Parameters
displayX11 display
rootroot window
windowwindow to manage
layout_managerReference to the layout manager
inActiveColorcolor of the border
borderSizesize of the border
wrapperX11 wrapper
46  : display_(display),
47  root_(root),
48  group_(std::weak_ptr<Group>(g)),
49  window_(window),
50  frame_(0),
51  border_width(borderSize),
52  border_color(inActiveColor),
53  framed(false),
54  mapped(false),
55  wrapper(x11Wrapper)
56 {
57  Atom wmClassAtom = wrapper->internAtom(display, "WM_CLASS", False);
58  Atom actualType = 0;
59  int actualFormat = 0;
60  unsigned long nItems = 0, bytesAfter = 0;
61  unsigned char* propData = 0;
62  wrapper->getWindowProperty(display,
63  window,
64  wmClassAtom,
65  0,
66  1024,
67  False,
68  AnyPropertyType,
69  &actualType,
70  &actualFormat,
71  &nItems,
72  &bytesAfter,
73  &propData);
74  if (actualType == XA_STRING && actualFormat == 8 && nItems > 1) {
75  char* instanceName = reinterpret_cast<char*>(propData);
76  char* className = instanceName + strlen(instanceName) + 1;
77  this->class_ = className;
78  this->title_ = instanceName;
79  } else {
80  Logger::GetInstance()->Log("Failed to get WM_CLASS property", L_ERROR);
81  this->class_ = "Unknown";
82  this->title_ = "Unknown";
83  }
84  wrapper->freeX(propData);
85 }
@ L_ERROR
Definition: Logger.hpp:51
Window root_
Definition: Client.hpp:153
std::shared_ptr< BaseX11Wrapper > wrapper
Definition: Client.hpp:163
bool mapped
Definition: Client.hpp:159
bool framed
Definition: Client.hpp:158
Window frame_
Definition: Client.hpp:155
std::string class_
Definition: Client.hpp:161
Display * display_
Definition: Client.hpp:152
unsigned int border_width
Definition: Client.hpp:156
std::string title_
Definition: Client.hpp:160
unsigned long border_color
Definition: Client.hpp:157
Window window_
Definition: Client.hpp:154
std::weak_ptr< Group > group_
Definition: Client.hpp:162
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 class_, Logger::GetInstance(), L_ERROR, Logger::Log(), title_, and wrapper.

Here is the call graph for this function:

◆ ~Client()

Client::~Client ( )

Client destructor Destroy the Client object & the Frame Window it needed.

86  {
87  try {
88  if (this->framed) {
89  wrapper->destroyWindow(display_, frame_);
90  }
91  } catch (const X11Exception &e) {
92  Logger::GetInstance()->Log(e.what(), L_ERROR);
93  }
94  Logger::GetInstance()->Log("Client destroyed :" + title_, L_INFO);
95 }
@ L_INFO
Definition: Logger.hpp:49
Definition: YggdrasilExceptions.hpp:36

References display_, frame_, framed, Logger::GetInstance(), L_ERROR, L_INFO, Logger::Log(), title_, and wrapper.

Here is the call graph for this function:

Member Function Documentation

◆ frame()

void Client::frame ( )

Client::frame create a frame around the client window, Map the frame, Add the window to the save set Reparent it, grab the buttons.

96  {
97  const unsigned long BG_COLOR = 0x000000;
98  auto g = group_.lock();
99  if (g) {
100  border_width = g->getBorderSize();
101  border_color = g->getInactiveColor();
102  } else {
103  throw YggdrasilException("Group no longer exists");
104  }
105  if (this->framed)
106  throw YggdrasilException("Client is already framed");
107  XWindowAttributes x_window_attrs;
108  wrapper->getWindowAttributes(display_, window_, &x_window_attrs);
109  if (x_window_attrs.override_redirect)
110  throw YggdrasilException("ignoring window with override redirect attribute.");
111  this->frame_ = wrapper->createSimpleWindow(
112  display_,
113  root_,
114  x_window_attrs.x,
115  x_window_attrs.y,
116  x_window_attrs.width,
117  x_window_attrs.height,
118  border_width,
119  border_color,
120  BG_COLOR
121  );
122  wrapper->selectInput(
123  display_,
124  this->frame_,
125  SubstructureRedirectMask | SubstructureNotifyMask | FocusChangeMask | ClientMessage);
126  wrapper->addToSaveSet(display_,window_);
127  wrapper->reparentWindow(
128  display_,
129  window_,
130  frame_,
131  0,0
132  );
133  wrapper->mapWindow(display_,frame_);
134  // a. Move windows with alt + left button.
135  wrapper->grabButton(
136  display_,
137  Button1,
138  Mod1Mask,
139  window_,
140  false,
141  ButtonPressMask | ButtonReleaseMask | ButtonMotionMask,
142  GrabModeAsync,
143  GrabModeAsync,
144  None,
145  None);
146  try {
148  } catch (const std::exception &e) {
149  Logger::GetInstance()->Log(e.what(), L_ERROR);
150  }
151  this->framed = true;
152 // this->group_->addClient(window_, this);
153 }
ConfigDataBindings class. This class is used to handle the bindings configuration it instanciates the...
Definition: ConfigDataBindings.hpp:45
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
Definition: YggdrasilExceptions.hpp:32

References border_color, border_width, display_, frame_, framed, ConfigHandler::getConfigData(), ConfigHandler::GetInstance(), Logger::GetInstance(), group_, L_ERROR, Logger::Log(), root_, window_, and wrapper.

Here is the call graph for this function:

◆ getClass()

const std::string & Client::getClass ( ) const

Client::getClass() return the class of the client, the class is get during the construction of the client.

Returns
204 { return class_; }

References class_.

◆ getFrame()

Window Client::getFrame ( ) const

Client::getFrame() return the frame Window of the client.

Returns
Window (frame)
199 {return frame_; }

References frame_.

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

Here is the caller graph for this function:

◆ getGroup()

Group * Client::getGroup ( ) const

return the group of the client

Returns
205 { return group_.lock(); }

References group_.

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

Here is the caller graph for this function:

◆ getTitle()

const std::string & Client::getTitle ( ) const

Client::getTitle() return the title of the client, the title is get during the construction of the client.

Returns
std::string
203 { return title_; }

References title_.

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

Here is the caller graph for this function:

◆ getWindow()

Window Client::getWindow ( ) const

Client::getWindow return the window attribute of the client.

Returns
Window
175  {
176  return this->window_;
177 }

References window_.

Referenced by Group::removeClient(), and WindowManager::setFocus().

Here is the caller graph for this function:

◆ isFramed()

bool Client::isFramed ( ) const

Client::isFramed() check if the client is framed.

Returns
200 { return framed; }

References framed.

◆ isMapped()

bool Client::isMapped ( ) const

Client::isMapped() check if the client is mapped.

Returns
bool
201 { return mapped; }

References mapped.

◆ move()

void Client::move ( int  x,
int  y 
)

: Client::move move the client window to the given position

Parameters
x
y
178  {
179  try {
180  if (this->framed) {
181  wrapper->moveWindow(display_, frame_, x, y);
182  } else {
183  wrapper->moveWindow(display_, window_, x + (int) border_width / 2, y + (int) border_width / 2);
184  }
185  } catch (const X11Exception &e) {
186  Logger::GetInstance()->Log(e.what(), L_ERROR);
187  }
188 }

References border_width, display_, frame_, framed, Logger::GetInstance(), L_ERROR, Logger::Log(), window_, and wrapper.

Here is the call graph for this function:

◆ resize()

void Client::resize ( unsigned int  width,
unsigned int  height 
)

Client::resize resize the client window to the given size.

Parameters
width
height
189  {
190  try {
191  if (this->framed) {
192  wrapper->resizeWindow(display_, frame_, width, height);
193  }
194  wrapper->resizeWindow(display_, window_, width - border_width, height - border_width);
195  } catch (const X11Exception &e) {
196  Logger::GetInstance()->Log(e.what(), L_ERROR);
197  }
198 }

References border_width, display_, frame_, framed, Logger::GetInstance(), L_ERROR, Logger::Log(), window_, and wrapper.

Here is the call graph for this function:

◆ restack()

void Client::restack ( )

Client::restack() restack the client window to avoid the frame to get in front of the client.

154  {
155  try {
156  if (this->framed) {
157  wrapper->raiseWindow(display_, frame_);
158  }
159  wrapper->raiseWindow(display_, window_);
160  } catch (const X11Exception &e) {
161  Logger::GetInstance()->Log(e.what(), L_ERROR);
162  }
163 }

References display_, frame_, framed, Logger::GetInstance(), L_ERROR, Logger::Log(), window_, and wrapper.

Referenced by EventHandler::handleMapNotify().

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

◆ setGroup()

void Client::setGroup ( std::shared_ptr< Group g)
206 { this->group_ = std::weak_ptr<Group>(g);}

References group_.

◆ setMapped()

void Client::setMapped ( bool  mapped)

Client::setMapped() set the mapped status of the client.

Parameters
mapped
202 { Client::mapped = m; }

References mapped.

Referenced by EventHandler::handleMapNotify().

Here is the caller graph for this function:

◆ unframe()

void Client::unframe ( )

Client::unframe unframe the client window by removing the frame and reparenting the window to the root window.

164  {
165  if (!this->framed)
166  throw YggdrasilException("Client is not framed");
167  try {
168  wrapper->destroyWindow(display_,frame_);
169  } catch (const std::exception &e) {
170  Logger::GetInstance()->Log(e.what(), L_ERROR);
171  }
172  this->framed = false;
173  this->frame_ = 0;
174 }

References display_, frame_, framed, Logger::GetInstance(), L_ERROR, Logger::Log(), and wrapper.

Here is the call graph for this function:

Member Data Documentation

◆ border_color

unsigned long Client::border_color
private

Referenced by frame().

◆ border_width

unsigned int Client::border_width
private

Referenced by frame(), move(), and resize().

◆ class_

std::string Client::class_
private

Referenced by Client(), and getClass().

◆ display_

Display* Client::display_
private

◆ frame_

Window Client::frame_
private

◆ framed

bool Client::framed
private

◆ group_

std::weak_ptr<Group> Client::group_
private

Referenced by frame(), getGroup(), and setGroup().

◆ mapped

bool Client::mapped {}
private

Referenced by isMapped(), and setMapped().

◆ root_

Window Client::root_
private

Referenced by frame().

◆ title_

std::string Client::title_
private

Referenced by Client(), getTitle(), and ~Client().

◆ window_

Window Client::window_
private

Referenced by frame(), getWindow(), move(), resize(), and restack().

◆ wrapper

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

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