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

Binding store a binding to a command object. More...

#include <Binding.hpp>

Collaboration diagram for Binding:
Collaboration graph

Public Member Functions

 Binding ()
 
 ~Binding ()
 
void init (std::string Mod, std::string Key, std::string Command, std::string Args)
 Initialize a binding all the parameters are read from the Json::Value from the configuration file Mod is parsed to store the proper modMask Command is parsed to link the proper command object. More...
 
void init_keycode (Display *display, BaseX11Wrapper *x11Wrapper)
 Initialize the keycode of the binding had to be initialized after the display is opened. More...
 
void execute (const XKeyEvent *)
 Execute the command linked to the binding The arguments passed to the command are the one stored in the binding. More...
 
const std::string & getMod () const
 
const std::string & getKey () const
 
const std::string & getCommandName () const
 
const std::string & getArgs () const
 
unsigned int getModMask () const
 
int getKeyCode () const
 

Private Attributes

std::string mod_
 
unsigned int modMask_
 
std::string key_
 
int keyCode_
 
std::string commandName_
 
std::string args_
 
CommandBasecommand_
 

Detailed Description

Binding store a binding to a command object.

Constructor & Destructor Documentation

◆ Binding()

Binding::Binding ( )
78  :
79  mod_(""),
80  modMask_(0),
81  key_(""),
82  keyCode_(0),
83  commandName_(""),
84  args_(""),
85  command_(nullptr) {}
std::string key_
Definition: Binding.hpp:74
CommandBase * command_
Definition: Binding.hpp:78
std::string args_
Definition: Binding.hpp:77
std::string commandName_
Definition: Binding.hpp:76
std::string mod_
Definition: Binding.hpp:72
unsigned int modMask_
Definition: Binding.hpp:73
int keyCode_
Definition: Binding.hpp:75

◆ ~Binding()

Binding::~Binding ( )
108  {
109  delete command_;
110 }

References command_.

Member Function Documentation

◆ execute()

void Binding::execute ( const XKeyEvent *  event = nullptr)

Execute the command linked to the binding The arguments passed to the command are the one stored in the binding.

65  {
66  if (command_ != nullptr) {
67  if (event == nullptr) {
69  } else {
70  std::stringstream ss;
71  ss << args_ << "," <<event->subwindow << "," << event->window << "," << event->state << "," << event->keycode;
72  command_->execute(ss.str());
73  }
74  }
75  else
76  throw std::runtime_error("Command not initialized.");
77 }
virtual void execute(const std::string &args)=0
Each child class must implement this interface.

References args_, command_, and CommandBase::execute().

Here is the call graph for this function:

◆ getArgs()

const std::string & Binding::getArgs ( ) const
89 { return args_; }

References args_.

◆ getCommandName()

const std::string & Binding::getCommandName ( ) const
88 { return commandName_; }

References commandName_.

◆ getKey()

const std::string & Binding::getKey ( ) const
87 { return key_; }

References key_.

◆ getKeyCode()

int Binding::getKeyCode ( ) const
91 { return keyCode_; }

References keyCode_.

◆ getMod()

const std::string & Binding::getMod ( ) const
86 { return mod_; }

References mod_.

◆ getModMask()

unsigned int Binding::getModMask ( ) const
90 { return modMask_; }

References modMask_.

◆ init()

void Binding::init ( std::string  Mod,
std::string  Key,
std::string  Command,
std::string  Args 
)

Initialize a binding all the parameters are read from the Json::Value from the configuration file Mod is parsed to store the proper modMask Command is parsed to link the proper command object.

Note
you need to call init_keycode after the display is opened
41  {
42  mod_ = Mod;
43  key_ = Key;
44  commandName_ = Command;
45  args_ = Args;
46  if (commandName_ == "FocusGroup") {
47  command_ = new FocusGroup();
48  } else if (commandName_ == "Spawn") {
49  command_ = new Spawn();
50  } else if (commandName_== "Quit") {
51  command_ = new Quit();
52  } else if (commandName_ == "Grow") {
53  command_ = new Grow();
54  } else {
55  throw std::runtime_error("Unknown command: " + commandName_);
56  }
57  if (mod_ == "Mod4") {
58  modMask_ = Mod4Mask;
59  } else if (mod_ == "Mod1") {
60  modMask_ = Mod1Mask;
61  } else {
62  throw std::runtime_error("Unknown mod : " + mod_);
63  }
64 }
FocusGroup implement the mecanism to switch between group.
Definition: FocusGroup.hpp:34
Grow a window.
Definition: Grow.hpp:45
Quit implement the mecanism to quit the window manager.
Definition: Quit.hpp:35
Implement the mecanism to spawn a program.
Definition: Spawn.hpp:34

References args_, command_, commandName_, key_, mod_, and modMask_.

◆ init_keycode()

void Binding::init_keycode ( Display *  display,
BaseX11Wrapper x11Wrapper 
)

Initialize the keycode of the binding had to be initialized after the display is opened.

Parameters
display
93  {
94  keyCode_ = x11Wrapper->keysymToKeycode(display, (int)x11Wrapper->stringToKeysym(key_.c_str()));
95  Logger::GetInstance()->Log("Binding registered : ["
96  + mod_
97  + " + "
98  +key_
99  +"] Command: "
100  + commandName_
101  + " Args: "
102  + args_
103  + " keycode: ["
104  + std::to_string(keyCode_)
105  +"]", L_INFO);
106 }
@ L_INFO
Definition: Logger.hpp:49
virtual int keysymToKeycode(Display *display, int keysym)=0
virtual KeySym stringToKeysym(const char *string)=0
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 args_, commandName_, Logger::GetInstance(), key_, keyCode_, BaseX11Wrapper::keysymToKeycode(), L_INFO, Logger::Log(), mod_, and BaseX11Wrapper::stringToKeysym().

Here is the call graph for this function:

Member Data Documentation

◆ args_

std::string Binding::args_
private

Referenced by execute(), getArgs(), init(), and init_keycode().

◆ command_

CommandBase* Binding::command_
private

Referenced by execute(), init(), and ~Binding().

◆ commandName_

std::string Binding::commandName_
private

Referenced by getCommandName(), init(), and init_keycode().

◆ key_

std::string Binding::key_
private

Referenced by getKey(), init(), and init_keycode().

◆ keyCode_

int Binding::keyCode_
private

Referenced by getKeyCode(), and init_keycode().

◆ mod_

std::string Binding::mod_
private

Referenced by getMod(), init(), and init_keycode().

◆ modMask_

unsigned int Binding::modMask_
private

Referenced by getModMask(), and init().


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