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

EventHandler class. This class is responsible for handling the XEvents. It is a part of the WindowManager class The event handlers functions are private and are called by the dispatchEvent function. More...

#include <EventHandler.hpp>

Collaboration diagram for EventHandler:
Collaboration graph

Public Member Functions

 EventHandler (const EventHandler &)=delete
 
EventHandleroperator= (const EventHandler &)=delete
 
 ~EventHandler ()
 Destroy the Event handler:: Event handler object. More...
 
void dispatchEvent (const XEvent &event)
 Dispatches the event to the appropriate handler function. the eventHandlerArray is an array of pointers to member functions of the EventHandler class. The array is initialized with the handleUnknown function. The array is then populated with the appropriate handler functions. More...
 

Static Public Member Functions

static void create ()
 create the Event handler:: Event handler object More...
 
static EventHandlergetInstance ()
 Get the Event handler:: Event handler object. More...
 
static void destroy ()
 

Private Types

using handler = void(EventHandler::*)(const XEvent &)
 

Private Member Functions

 EventHandler ()
 
void handleMapNotify (const XEvent &event)
 Handles the MapNotify event. The MapNotify event is sent to a client when it is mapped. The event handler retrieves the client from the WindowManager object and sets its mapped attribute to true. The event handler then logs the event. the client is restacked. More...
 
void handleUnmapNotify (const XEvent &event)
 Handles the UnmapNotify event. The UnmapNotify event is sent to a client when it is unmapped. The event handler retrieves the client from the WindowManager object and sets its mapped attribute to false. The event handler then logs the event. More...
 
void handleConfigureRequest (const XEvent &event)
 Handles the ConfigureRequest event. The ConfigureRequest event is sent to a client when it requests a change in its size, position, or stacking order. More...
 
void handleConfigureNotify (const XEvent &event)
 Handles the ConfigureNotify event. More...
 
void handleButtonPress (const XEvent &event)
 Handles the ButtonPress event. The ButtonPress event is sent to a client when a mouse button is pressed. More...
 
void handleButtonRelease (const XEvent &event)
 Handles the ButtonRelease event. More...
 
void handleKeyPress (const XEvent &event)
 Handles the KeyPress event. the handling of KeyPress event is delegated to the ConfigDataBindings object to avoid dependencies to the Binding class and the Command class. More...
 
void handleKeyRelease (const XEvent &event)
 Handles the KeyRelease event. More...
 
void handleEnterNotify (const XEvent &event)
 Handles the EnterNotify event. More...
 
void handleLeaveNotify (const XEvent &event)
 Handles the LeaveNotify event. More...
 
void handleExpose (const XEvent &event)
 This where the bar is drawn, other windows are ignored. More...
 
void handleFocusIn (const XEvent &event)
 Handles the FocusIn event. Changes the border color of the client. More...
 
void handleFocusOut (const XEvent &event)
 Handles the FocusOut event. Changes the border color of the client. More...
 
void handlePropertyNotify (const XEvent &event)
 Handles the PropertyNotify event. More...
 
void handleClientMessage (const XEvent &event)
 Handles the ClientMessage event. More...
 
void handleDestroyNotify (const XEvent &event)
 Handles the DestroyNotify event. More...
 
void handleReparentNotify (const XEvent &event)
 Handles the ReparentNotify event. More...
 
void handleMapRequest (const XEvent &event)
 Handles the MapRequest event. The MapRequest event is sent to a client when it is mapped. The event handler retrieves the client from the WindowManager object and sets its mapped attribute to true. The event handler then logs the event. More...
 
void handleMotionNotify (const XEvent &event)
 Handles the MotionNotify event. this was previously used for dragging windows.r. More...
 
void handleUnknown (const XEvent &event)
 Handles the Unknown event. More...
 
void handleCreateNotify (const XEvent &event)
 Handles the CreateNotify event. More...
 

Private Attributes

handler eventHandlerArray [LASTEvent] {}
 
std::shared_ptr< BaseX11Wrapperwrapper
 

Static Private Attributes

static EventHandlerinstance_ = nullptr
 

Detailed Description

EventHandler class. This class is responsible for handling the XEvents. It is a part of the WindowManager class The event handlers functions are private and are called by the dispatchEvent function.

Todo:
see the pertinence of implementing observer pattern here
See also
WindowManager
Client
Logger

Member Typedef Documentation

◆ handler

using EventHandler::handler = void (EventHandler::*)(const XEvent&)
private

Constructor & Destructor Documentation

◆ EventHandler() [1/2]

EventHandler::EventHandler ( const EventHandler )
delete

◆ ~EventHandler()

EventHandler::~EventHandler ( )
default

Destroy the Event handler:: Event handler object.

◆ EventHandler() [2/2]

EventHandler::EventHandler ( )
private
93  {
94  for (auto & i : eventHandlerArray) {
96  }
117 }
handler eventHandlerArray[LASTEvent]
Definition: EventHandler.hpp:84
void handleUnknown(const XEvent &event)
Handles the Unknown event.
Definition: EventHandler.cpp:390
void handleMapNotify(const XEvent &event)
Handles the MapNotify event. The MapNotify event is sent to a client when it is mapped....
Definition: EventHandler.cpp:126
void handleExpose(const XEvent &event)
This where the bar is drawn, other windows are ignored.
Definition: EventHandler.cpp:225
void handleLeaveNotify(const XEvent &event)
Handles the LeaveNotify event.
Definition: EventHandler.cpp:224
void handleButtonPress(const XEvent &event)
Handles the ButtonPress event. The ButtonPress event is sent to a client when a mouse button is press...
Definition: EventHandler.cpp:182
void handleUnmapNotify(const XEvent &event)
Handles the UnmapNotify event. The UnmapNotify event is sent to a client when it is unmapped....
Definition: EventHandler.cpp:141
void handleKeyPress(const XEvent &event)
Handles the KeyPress event. the handling of KeyPress event is delegated to the ConfigDataBindings obj...
Definition: EventHandler.cpp:211
void handleFocusOut(const XEvent &event)
Handles the FocusOut event. Changes the border color of the client.
Definition: EventHandler.cpp:250
void handleDestroyNotify(const XEvent &event)
Handles the DestroyNotify event.
Definition: EventHandler.cpp:280
void handlePropertyNotify(const XEvent &event)
Handles the PropertyNotify event.
Definition: EventHandler.cpp:270
std::shared_ptr< BaseX11Wrapper > wrapper
Definition: EventHandler.hpp:86
void handleConfigureRequest(const XEvent &event)
Handles the ConfigureRequest event. The ConfigureRequest event is sent to a client when it requests a...
Definition: EventHandler.cpp:168
void handleMotionNotify(const XEvent &event)
Handles the MotionNotify event. this was previously used for dragging windows.r.
Definition: EventHandler.cpp:354
void handleConfigureNotify(const XEvent &event)
Handles the ConfigureNotify event.
Definition: EventHandler.cpp:180
void handleKeyRelease(const XEvent &event)
Handles the KeyRelease event.
Definition: EventHandler.cpp:216
void handleMapRequest(const XEvent &event)
Handles the MapRequest event. The MapRequest event is sent to a client when it is mapped....
Definition: EventHandler.cpp:312
void handleEnterNotify(const XEvent &event)
Handles the EnterNotify event.
Definition: EventHandler.cpp:217
void handleReparentNotify(const XEvent &event)
Handles the ReparentNotify event.
Definition: EventHandler.cpp:311
void handleFocusIn(const XEvent &event)
Handles the FocusIn event. Changes the border color of the client.
Definition: EventHandler.cpp:232
void handleClientMessage(const XEvent &event)
Handles the ClientMessage event.
Definition: EventHandler.cpp:274
void handleButtonRelease(const XEvent &event)
Handles the ButtonRelease event.
Definition: EventHandler.cpp:210
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 eventHandlerArray, WindowManager::getInstance(), WindowManager::getX11Wrapper(), handleButtonPress(), handleButtonRelease(), handleClientMessage(), handleConfigureNotify(), handleConfigureRequest(), handleDestroyNotify(), handleEnterNotify(), handleExpose(), handleFocusIn(), handleFocusOut(), handleKeyPress(), handleKeyRelease(), handleLeaveNotify(), handleMapNotify(), handleMapRequest(), handleMotionNotify(), handlePropertyNotify(), handleReparentNotify(), handleUnknown(), handleUnmapNotify(), and wrapper.

Referenced by create().

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

Member Function Documentation

◆ create()

static void EventHandler::create ( )
static

create the Event handler:: Event handler object

81  {
82  if (instance_ != nullptr) {
83  throw std::runtime_error("EventHandler instance already created");
84  }
85  instance_ = new EventHandler();
86 }
EventHandler()
Definition: EventHandler.cpp:93
static EventHandler * instance_
Definition: EventHandler.hpp:85

References EventHandler(), and instance_.

Referenced by WindowManager::Run(), and WindowManager::testRun().

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

◆ destroy()

void EventHandler::destroy ( )
static
392  {
393  if (instance_ != nullptr) {
394  delete instance_;
395  instance_ = nullptr;
396  }
397 }

References instance_.

Referenced by main().

Here is the caller graph for this function:

◆ dispatchEvent()

void EventHandler::dispatchEvent ( const XEvent &  event)

Dispatches the event to the appropriate handler function. the eventHandlerArray is an array of pointers to member functions of the EventHandler class. The array is initialized with the handleUnknown function. The array is then populated with the appropriate handler functions.

Parameters
eventThe XEvent to be dispatched.
119  {
120  std::string name = GetEventTypeName(event.xany.type);
121  if (event.type > 0 && event.type < LASTEvent && eventHandlerArray[event.type] != nullptr)
122  (this->*eventHandlerArray[event.type])(event);
123  else
124  Logger::GetInstance()->Log("Unknown event type: [" + std::to_string(event.type) + "]\t" + name, L_WARNING);
125 }
std::string GetEventTypeName(int eventType)
Definition: EventHandler.cpp:39
@ L_WARNING
Definition: Logger.hpp:50
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 eventHandlerArray, GetEventTypeName(), Logger::GetInstance(), L_WARNING, and Logger::Log().

Referenced by WindowManager::Run(), and WindowManager::testRun().

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

◆ getInstance()

EventHandler * EventHandler::getInstance ( )
static

Get the Event handler:: Event handler object.

87  {
88  if (instance_ == nullptr) {
89  throw std::runtime_error("EventHandler instance not created");
90  }
91  return instance_;
92 }

References instance_.

Referenced by WindowManager::Run(), and WindowManager::testRun().

Here is the caller graph for this function:

◆ handleButtonPress()

void EventHandler::handleButtonPress ( const XEvent &  event)
private

Handles the ButtonPress event. The ButtonPress event is sent to a client when a mouse button is pressed.

Parameters
eventThe ButtonPress event to be handled.
182  {
183  auto e = event.xbutton;
184  if (Bars::getInstance().isBarWindow(e.window)) {
185  Logger::GetInstance()->Log("Ignoring unmap for bar window", L_INFO);
186  return;
187  }
188  const Window frame = WindowManager::getInstance()->getClient(event.xbutton.window)->getFrame();
189  // give focus to the window
190  wrapper->setInputFocus(WindowManager::getInstance()->getDisplay(), frame, RevertToParent, CurrentTime);
191  // 1. Save initial cursor position.
192 // drag_start_pos_ = Position<int>(e.x_root, e.y_root);
193 // // 2. Save initial window info.
194 // Window returned_root;
195 // int x, y;
196 // unsigned width, height, border_width, depth;
197 // XGetGeometry(
198 // wm_.getDisplay(),
199 // frame,
200 // &returned_root,
201 // &x, &y,
202 // &width, &height,
203 // &border_width,
204 // &depth);
205 // drag_start_frame_pos_ = Position<int>(x, y);
206 // drag_start_frame_size_ = Size<int>(width, height);
207  // 3. Raise clicked window to top.
208  wrapper->raiseWindow(WindowManager::getInstance()->getDisplay(),frame);
209 }
@ L_INFO
Definition: Logger.hpp:49
static Bars & getInstance()
Get the singleton instance if the instance is not created, it will create it.
Definition: Bars.cpp:177
std::shared_ptr< Client > getClient(Window window)
Get the Client by window ptr or frame ptr.
Definition: WindowManager.cpp:251

References WindowManager::getClient(), Bars::getInstance(), Logger::GetInstance(), WindowManager::getInstance(), L_INFO, Logger::Log(), and wrapper.

Referenced by EventHandler().

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

◆ handleButtonRelease()

void EventHandler::handleButtonRelease ( const XEvent &  event)
private

Handles the ButtonRelease event.

Parameters
event
210 {}

Referenced by EventHandler().

Here is the caller graph for this function:

◆ handleClientMessage()

void EventHandler::handleClientMessage ( const XEvent &  event)
private

Handles the ClientMessage event.

Parameters
event
274  {
275  XClientMessageEvent e = event.xclient;
276  Display * display = WindowManager::getInstance()->getDisplay();
277  Window root = WindowManager::getInstance()->getRoot();
278  ewmh::handleMessage(&e, display, root);
279 }
Display * getDisplay() const
Get the Display object.
Definition: WindowManager.cpp:263
Window getRoot() const
Get the Root Window pointer.
Definition: WindowManager.cpp:266
void handleMessage(XClientMessageEvent *event, Display *display, Window root)
Definition: Ewmh.cpp:60

References WindowManager::getDisplay(), WindowManager::getInstance(), WindowManager::getRoot(), and ewmh::handleMessage().

Referenced by EventHandler().

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

◆ handleConfigureNotify()

void EventHandler::handleConfigureNotify ( const XEvent &  event)
private

Handles the ConfigureNotify event.

Parameters
event
180  {
181 }

Referenced by EventHandler().

Here is the caller graph for this function:

◆ handleConfigureRequest()

void EventHandler::handleConfigureRequest ( const XEvent &  event)
private

Handles the ConfigureRequest event. The ConfigureRequest event is sent to a client when it requests a change in its size, position, or stacking order.

Parameters
event
168  {
169  auto e = event.xconfigurerequest;
170  XWindowChanges changes;
171  changes.x = e.x;
172  changes.y = e.y;
173  changes.width = e.width;
174  changes.height = e.height;
175  changes.border_width = e.border_width;
176  changes.sibling = e.above;
177  changes.stack_mode = e.detail;
178  wrapper->configureWindow(WindowManager::getInstance()->getDisplay(),e.window,e.value_mask,&changes);
179 }

References WindowManager::getInstance(), and wrapper.

Referenced by EventHandler().

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

◆ handleCreateNotify()

void EventHandler::handleCreateNotify ( const XEvent &  event)
private

Handles the CreateNotify event.

Parameters
event
389 {}

◆ handleDestroyNotify()

void EventHandler::handleDestroyNotify ( const XEvent &  event)
private

Handles the DestroyNotify event.

Parameters
event
280  {
281  auto e = event.xdestroywindow;
282  if (e.window == WindowManager::getInstance()->getRoot()) {
283  Logger::GetInstance()->Log("Ignoring destroy for root window", L_INFO);
284  return;
285  }
286  if (Bars::getInstance().isBarWindow(e.window)) {
287  Logger::GetInstance()->Log("Ignoring unmap for bar window", L_INFO);
288  return;
289  }
290  try {
291  auto client = WindowManager::getInstance()->getClientRef(e.window);
292  Logger::GetInstance()->Log("Destroying window: " + client->getTitle(), L_INFO);
293  client->unframe();
294  WindowManager::getInstance()->getClients().erase(e.window);
295  client->getGroup()->removeClient(client.get());
296  auto clients = WindowManager::getInstance()->getActiveGroup()->getClients();
297  if (!clients.empty()) {
298  Client *dclient = clients.begin()->second.get();
299  if (dclient != nullptr) {
301  return;
302  }
303  }
304  wrapper->setInputFocus(WindowManager::getInstance()->getDisplay(),
305  WindowManager::getInstance()->getRoot(),
306  RevertToParent, CurrentTime);
307  } catch (std::out_of_range &err) {
308  Logger::GetInstance()->Log("Destroying unknown window: " + std::to_string(e.window), L_WARNING);
309  }
310 }
The Client class is responsible for managing the client windows. It creates a frame around the client...
Definition: Client.hpp:47
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
void setFocus(Client *client)
Set the focus to a client.
Definition: WindowManager.cpp:208
std::shared_ptr< Group > getActiveGroup() const
get the current Active Group
Definition: WindowManager.cpp:272

References WindowManager::getActiveGroup(), WindowManager::getClientRef(), WindowManager::getClients(), Bars::getInstance(), Logger::GetInstance(), WindowManager::getInstance(), WindowManager::getRoot(), L_INFO, L_WARNING, Logger::Log(), WindowManager::setFocus(), and wrapper.

Referenced by EventHandler().

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

◆ handleEnterNotify()

void EventHandler::handleEnterNotify ( const XEvent &  event)
private

Handles the EnterNotify event.

Parameters
event
217  {
218  auto e = event.xcrossing;
219  if (Bars::getInstance().isBarWindow(e.window)) {
221  return;
222  }
223 }
void redraw()
Redraw the bars by calling the draw method of each bar.
Definition: Bars.cpp:119

References Bars::getInstance(), and Bars::redraw().

Referenced by EventHandler().

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

◆ handleExpose()

void EventHandler::handleExpose ( const XEvent &  event)
private

This where the bar is drawn, other windows are ignored.

225  {
226  auto e = event.xexpose;
227  if (Bars::getInstance().isBarWindow(e.window)) {
229  return;
230  }
231 }

References Bars::getInstance(), and Bars::redraw().

Referenced by EventHandler().

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

◆ handleFocusIn()

void EventHandler::handleFocusIn ( const XEvent &  event)
private

Handles the FocusIn event. Changes the border color of the client.

Parameters
event
232  {
233  auto e = event.xfocus;
235  ewmh::updateActiveWindow(WindowManager::getInstance()->getDisplay(), WindowManager::getInstance()->getRoot(), e.window);
236  if (e.window == WindowManager::getInstance()->getRoot()) {
237  return;
238  }
239  Client * client = WindowManager::getInstance()->getClient(e.window).get();
240  if (client == nullptr) {
241  return;
242  }
243  else {
244  unsigned long ActiveColor = client->getGroup()->getActiveColor();
245  Logger::GetInstance()->Log("Window focused: " + client->getTitle() , L_INFO);
246  wrapper->setWindowBorder(WindowManager::getInstance()->getDisplay(), client->getFrame(), ActiveColor);
247  wrapper->flush(WindowManager::getInstance()->getDisplay());
248  }
249 }
const std::string & getTitle() const
Client::getTitle() return the title of the client, the title is get during the construction of the cl...
Definition: Client.cpp:203
Window getFrame() const
Client::getFrame() return the frame Window of the client.
Definition: Client.cpp:199
std::shared_ptr< Group > getGroup() const
return the group of the client
Definition: Client.cpp:205
void setActiveWindow(Window activeWindow)
set the Active Window
Definition: WindowManager.cpp:285
void updateActiveWindow(Display *display, Window root, Window activeWindow)
Definition: Ewmh.cpp:113

References WindowManager::getClient(), Client::getFrame(), Client::getGroup(), Logger::GetInstance(), WindowManager::getInstance(), WindowManager::getRoot(), Client::getTitle(), L_INFO, Logger::Log(), WindowManager::setActiveWindow(), ewmh::updateActiveWindow(), and wrapper.

Referenced by EventHandler().

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

◆ handleFocusOut()

void EventHandler::handleFocusOut ( const XEvent &  event)
private

Handles the FocusOut event. Changes the border color of the client.

Parameters
event
250  {
251  auto e = event.xfocus;
252  if (WindowManager::getInstance()->getActiveWindow() == e.window) {
255  }
256  if (e.window == WindowManager::getInstance()->getRoot()) {
257  return;
258  }
259  Client * client = WindowManager::getInstance()->getClient(e.window).get();
260  if (client == nullptr) {
261  return;
262  }
263  else {
264  unsigned long InActiveColor = client->getGroup()->getInactiveColor();
265  Logger::GetInstance()->Log("Window unfocused: " + client->getTitle() , L_INFO);
266  wrapper->setWindowBorder(WindowManager::getInstance()->getDisplay(), client->getFrame(), InActiveColor);
267  wrapper->flush(WindowManager::getInstance()->getDisplay());
268  }
269 }

References WindowManager::getClient(), Client::getFrame(), Client::getGroup(), Logger::GetInstance(), WindowManager::getInstance(), WindowManager::getRoot(), Client::getTitle(), L_INFO, Logger::Log(), WindowManager::setActiveWindow(), ewmh::updateActiveWindow(), and wrapper.

Referenced by EventHandler().

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

◆ handleKeyPress()

void EventHandler::handleKeyPress ( const XEvent &  event)
private

Handles the KeyPress event. the handling of KeyPress event is delegated to the ConfigDataBindings object to avoid dependencies to the Binding class and the Command class.

Parameters
event
211  {
212  auto e = &event.xkey;
213  ConfigHandler::GetInstance().getConfigData<ConfigDataBindings>()->handleKeypressEvent(e);
214  wrapper->sync(WindowManager::getInstance()->getDisplay(),false);
215 }
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

References ConfigHandler::getConfigData(), ConfigHandler::GetInstance(), WindowManager::getInstance(), and wrapper.

Referenced by EventHandler().

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

◆ handleKeyRelease()

void EventHandler::handleKeyRelease ( const XEvent &  event)
private

Handles the KeyRelease event.

Parameters
event
216 {}

Referenced by EventHandler().

Here is the caller graph for this function:

◆ handleLeaveNotify()

void EventHandler::handleLeaveNotify ( const XEvent &  event)
private

Handles the LeaveNotify event.

Parameters
event
224 {}

Referenced by EventHandler().

Here is the caller graph for this function:

◆ handleMapNotify()

void EventHandler::handleMapNotify ( const XEvent &  event)
private

Handles the MapNotify event. The MapNotify event is sent to a client when it is mapped. The event handler retrieves the client from the WindowManager object and sets its mapped attribute to true. The event handler then logs the event. the client is restacked.

Parameters
eventThe MapNotify event to be handled.
126  {
127  auto e = event.xmap;
128  Client * client = WindowManager::getInstance()->getClient(e.window).get();
129  if (client == nullptr) {
130  Logger::GetInstance()->Log("Ignoring map for unknown window: " + std::to_string(e.window), L_INFO);
131  return;
132  }
133  else {
134  Logger::GetInstance()->Log("Window Mapped: " + client->getTitle() , L_INFO);
135  if (client->getFrame() != e.window) {
136  client->restack();
137  client->setMapped(true);
138  }
139  }
140 }
void setMapped(bool mapped)
Client::setMapped() set the mapped status of the client.
Definition: Client.cpp:202
void restack()
Client::restack() restack the client window to avoid the frame to get in front of the client.
Definition: Client.cpp:154

References WindowManager::getClient(), Client::getFrame(), Logger::GetInstance(), WindowManager::getInstance(), Client::getTitle(), L_INFO, Logger::Log(), Client::restack(), and Client::setMapped().

Referenced by EventHandler().

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

◆ handleMapRequest()

void EventHandler::handleMapRequest ( const XEvent &  event)
private

Handles the MapRequest event. The MapRequest event is sent to a client when it is mapped. The event handler retrieves the client from the WindowManager object and sets its mapped attribute to true. The event handler then logs the event.

Parameters
eventThe MapRequest event to be handled.
312  {
313  XMapRequestEvent e = event.xmaprequest;
314  if (e.parent != WindowManager::getInstance()->getRoot()) {
315  Logger::GetInstance()->Log("Ignoring map request for window: " + std::to_string(e.window), L_INFO);
316  return;
317  }
318  try {
319  if (WindowManager::getInstance()->getClientRef(e.window)->isMapped()) {
320  Logger::GetInstance()->Log("Window already mapped: " + std::to_string(e.window), L_INFO);
321  return;
322  }
323  auto client = WindowManager::getInstance()->getClientRef(e.window);
324  if (client->isFramed()) {
325  Logger::GetInstance()->Log("Window already framed: " + std::to_string(e.window), L_INFO);
326  return;
327  }
328  else {
329  Logger::GetInstance()->Log("Framing window: " + client->getTitle(), L_INFO);
330  try {
331  client->frame();
332  client->getGroup()->addClient(client->getWindow(),client);
333  WindowManager::getInstance()->setFocus(client.get());
334  } catch (const std::exception &ex) {
335  Logger::GetInstance()->Log(ex.what(), L_ERROR);
336  }
337  }
338  Logger::GetInstance()->Log("Window already mapped: " + std::to_string(e.window), L_INFO);
339  return;
340  }
341  catch (std::out_of_range &err) {
342  Logger::GetInstance()->Log("Creating new client for window: " + std::to_string(e.window), L_INFO);
344  try {
345  auto c = WindowManager::getInstance()->getClientRef(e.window);
346  c->frame();
347  c->getGroup()->addClient(e.window,c);
348  } catch (const std::exception &ex) {
349  Logger::GetInstance()->Log(ex.what(), L_ERROR);
350  }
351  }
352  wrapper->mapWindow(WindowManager::getInstance()->getDisplay(), e.window);
353 }
@ L_ERROR
Definition: Logger.hpp:51
void insertClient(Window window)
Insert a client in the clients map.
Definition: WindowManager.cpp:195

References WindowManager::getClientRef(), Logger::GetInstance(), WindowManager::getInstance(), WindowManager::getRoot(), WindowManager::insertClient(), L_ERROR, L_INFO, Logger::Log(), WindowManager::setFocus(), and wrapper.

Referenced by EventHandler().

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

◆ handleMotionNotify()

void EventHandler::handleMotionNotify ( const XEvent &  event)
private

Handles the MotionNotify event. this was previously used for dragging windows.r.

Todo:
: rework this function to handle dragging windows.
Parameters
event
354  {
355  auto e = event.xmotion;
356  if (Bars::getInstance().isBarWindow(e.window)) {
357  return;
358  }
359  const Window frame = WindowManager::getInstance()->getClientRef(event.xmotion.window)->getFrame();
360 // const Position<int> drag_pos(e.x_root, e.y_root);
361 // const Vector2D<int> delta = drag_pos - drag_start_pos_;
362 //
363 // if (e.state & Button1Mask) {
364 // // alt + left button: Move window.
365 // const Position<int> dest_frame_pos = drag_start_frame_pos_ + delta;
366 // XMoveWindow(
367 // wm_.getDisplay(),
368 // frame,
369 // dest_frame_pos.x, dest_frame_pos.y);
370 // } else if (e.state & Button3Mask) {
371 // // alt + right button: Resize window.
372 // // Window dimensions cannot be negative.
373 // const Vector2D<int> size_delta(
374 // std::max(delta.x, -drag_start_frame_size_.width),
375 // std::max(delta.y, -drag_start_frame_size_.height));
376 // const Size<int> dest_frame_size = drag_start_frame_size_ + size_delta;
377 // // 1. Resize frame.
378 // XResizeWindow(
379 // wm_.getDisplay(),
380 // frame,
381 // dest_frame_size.width, dest_frame_size.height);
382 // // 2. Resize client window.
383 // XResizeWindow(
384 // wm_.getDisplay(),
385 // e.window,
386 // dest_frame_size.width, dest_frame_size.height);
387 // }
388 }

References WindowManager::getClientRef(), Bars::getInstance(), and WindowManager::getInstance().

Referenced by EventHandler().

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

◆ handlePropertyNotify()

void EventHandler::handlePropertyNotify ( const XEvent &  event)
private

Handles the PropertyNotify event.

Parameters
event
270  {
271  XPropertyEvent e = event.xproperty;
272  Logger::GetInstance()->Log("PropertyNotify: " + std::to_string(e.atom), L_INFO);
273 }

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

Referenced by EventHandler().

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

◆ handleReparentNotify()

void EventHandler::handleReparentNotify ( const XEvent &  event)
private

Handles the ReparentNotify event.

Parameters
event
311 {}

Referenced by EventHandler().

Here is the caller graph for this function:

◆ handleUnknown()

void EventHandler::handleUnknown ( const XEvent &  event)
private

Handles the Unknown event.

Parameters
event
390 {}

Referenced by EventHandler().

Here is the caller graph for this function:

◆ handleUnmapNotify()

void EventHandler::handleUnmapNotify ( const XEvent &  event)
private

Handles the UnmapNotify event. The UnmapNotify event is sent to a client when it is unmapped. The event handler retrieves the client from the WindowManager object and sets its mapped attribute to false. The event handler then logs the event.

Parameters
eventThe UnmapNotify event to be handled.
141  {
142  auto e = event.xunmap;
143  if (Bars::getInstance().isBarWindow(e.window)) {
144  Logger::GetInstance()->Log("Ignoring unmap for bar window", L_INFO);
145  return;
146  }
147  if (e.window == WindowManager::getInstance()->getRoot()) {
149  Logger::GetInstance()->Log("Ignoring unmap for root window", L_INFO);
150  return;
151  }
152  try {
153  auto client = WindowManager::getInstance()->getClientRef(e.window);
154  Logger::GetInstance()->Log("Unmapping window: " + client->getTitle(), L_INFO);
155  if (client->getFrame() != e.window) {
156  client->setMapped(false);
157  }
158  else {
159  client->unframe();
160  client->getGroup()->removeClient(client.get());
161  WindowManager::getInstance()->getClients().erase(e.window);
162  }
163  }
164  catch (std::out_of_range &err) {
165  Logger::GetInstance()->Log("Unmapping unknown window: " + std::to_string(e.window), L_WARNING);
166  }
167 }

References WindowManager::getClientRef(), WindowManager::getClients(), ConfigHandler::getConfigData(), WindowManager::getDisplay(), Bars::getInstance(), ConfigHandler::GetInstance(), Logger::GetInstance(), WindowManager::getInstance(), WindowManager::getRoot(), L_INFO, L_WARNING, and Logger::Log().

Referenced by EventHandler().

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

◆ operator=()

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

Member Data Documentation

◆ eventHandlerArray

handler EventHandler::eventHandlerArray[LASTEvent] {}
private

Referenced by dispatchEvent(), and EventHandler().

◆ instance_

EventHandler * EventHandler::instance_ = nullptr
staticprivate

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

◆ wrapper


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