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

ConfigDataBindings class. This class is used to handle the bindings configuration it instanciates the bindings in a vector it handle grabbing keys and handle keypress events. More...

#include <ConfigDataBindings.hpp>

Inheritance diagram for ConfigDataBindings:
Inheritance graph
Collaboration diagram for ConfigDataBindings:
Collaboration graph

Public Member Functions

 ConfigDataBindings ()
 
 ~ConfigDataBindings () override
 
void configInit (const Json::Value &root_) override
 Parse the Json::Value object to initialize the bindings Instanciate the bindings in a vector. More...
 
void initKeycodes (Display *display, BaseX11Wrapper *x11Wrapper)
 Initialize the keycodes This method is called by the WindowManager to initialize the keycodes after the display and the x11Wrapper are initialized. More...
 
Json::Value configSave () override
 Build a Json::Value object with the configuration. More...
 
void grabKeys (Display *display, Window window)
 Grab the keys from the bindings GrabKeys is called on the root window on initialisation of the WindowManager and then on each new window creation that is managed by the WindowManager. More...
 
void handleKeypressEvent (const XKeyEvent *event)
 Handle the keypress event This method is called by the EventManager to avoid handling bindings and their interface in the EventHandle class. More...
 
const std::vector< Binding * > & getBindings () const
 

Private Attributes

std::vector< Binding * > bindings_
 

Detailed Description

ConfigDataBindings class. This class is used to handle the bindings configuration it instanciates the bindings in a vector it handle grabbing keys and handle keypress events.

Constructor & Destructor Documentation

◆ ConfigDataBindings()

ConfigDataBindings::ConfigDataBindings ( )
31 : bindings_(){}
std::vector< Binding * > bindings_
Definition: ConfigDataBindings.hpp:86

◆ ~ConfigDataBindings()

ConfigDataBindings::~ConfigDataBindings ( )
override
50  {
51  for (auto &binding : bindings_) {
52  delete binding;
53  }
54 }

References bindings_.

Member Function Documentation

◆ configInit()

void ConfigDataBindings::configInit ( const Json::Value &  root_)
overridevirtual

Parse the Json::Value object to initialize the bindings Instanciate the bindings in a vector.

Parameters
root_the Json::Value object containing the bindings

Implements ConfigDataBase.

32  {
33  std::vector<std::string> modKeys = root.getMemberNames();
34  for (auto &modKey : modKeys) {
35  Json::Value bindings = root[modKey];
36  for (auto &binding : bindings) {
37  std::string key = binding["Key"].asString();
38  std::string command = binding["Action"].asString();
39  std::string arg = binding["Argument"].asString();
40  auto b = new Binding();
41  b->init(modKey, key, command, arg);
42  bindings_.push_back(b);
43  }
44  }
45  Logger::GetInstance()->Log("Successfully added " + std::to_string(bindings_.size()) + " bindings", L_INFO);
46 }
@ L_INFO
Definition: Logger.hpp:49
Binding store a binding to a command object.
Definition: Binding.hpp:39
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 bindings_, Logger::GetInstance(), L_INFO, and Logger::Log().

Here is the call graph for this function:

◆ configSave()

Json::Value ConfigDataBindings::configSave ( )
overridevirtual

Build a Json::Value object with the configuration.

Returns
Json::Value Object with the current runtime configuration

Implements ConfigDataBase.

47  {
48  return Json::Value();
49 }

◆ getBindings()

const std::vector< Binding * > & ConfigDataBindings::getBindings ( ) const
93  {
94  return bindings_;
95 }

References bindings_.

◆ grabKeys()

void ConfigDataBindings::grabKeys ( Display *  display,
Window  window 
)

Grab the keys from the bindings GrabKeys is called on the root window on initialisation of the WindowManager and then on each new window creation that is managed by the WindowManager.

Parameters
display
window
56  {
57  for (auto &binding : bindings_) {
58  XGrabKey(display, binding->getKeyCode(), binding->getModMask(), window, true, GrabModeAsync, GrabModeAsync);
59  }
60  XFlush(display);
61 }

References bindings_.

◆ handleKeypressEvent()

void ConfigDataBindings::handleKeypressEvent ( const XKeyEvent *  event)

Handle the keypress event This method is called by the EventManager to avoid handling bindings and their interface in the EventHandle class.

Parameters
eventmust be converted to const XKeyEvent *event
63  {
64  unsigned int keyCode = event->keycode;
65  bool modOk = false;
66  for (auto &binding : bindings_) {
67  modOk = event->state & binding->getModMask();
68  if (binding->getKeyCode() == keyCode && modOk) {
69  if (binding->getCommandName() == "Grow") {
70  binding->execute(event);
71  } else {
72  binding->execute(nullptr);
73  }
74  Logger::GetInstance()->Log("[" +
75  binding->getMod()
76  + "+"
77  + binding->getKey()
78  +"] ->\t"
79  + binding->getCommandName()
80  + " ["
81  + binding->getArgs()
82  + "]",L_INFO);
83  }
84  }
85 }

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

Here is the call graph for this function:

◆ initKeycodes()

void ConfigDataBindings::initKeycodes ( Display *  display,
BaseX11Wrapper x11Wrapper 
)

Initialize the keycodes This method is called by the WindowManager to initialize the keycodes after the display and the x11Wrapper are initialized.

Parameters
display
x11Wrapper
87  {
88  for (auto &binding : bindings_) {
89  binding->init_keycode(display,x11Wrapper);
90  }
91 }

References bindings_.

Member Data Documentation

◆ bindings_

std::vector<Binding *> ConfigDataBindings::bindings_
private

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