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

#include <Bar.hpp>

Collaboration diagram for Bar:
Collaboration graph

Public Member Functions

 Bar ()
 
 ~Bar ()
 
void init (std::shared_ptr< ConfigDataBar > configData, std::shared_ptr< TSBarsData > tsData)
 
void draw ()
 
Window getWindow () const
 
unsigned int getSizeX () const
 
unsigned int getSizeY () const
 
void addWidget (void *handle, std::shared_ptr< ConfigDataWidget >)
 
const std::unordered_map< Window, Widget * > & getWidgets () const
 

Private Attributes

std::shared_ptr< ConfigDataBarconfigData
 
std::unordered_map< Window, Widget * > widgets
 
std::shared_ptr< TSBarsDatatsData
 
Display * display
 
Window window
 
Window root
 
unsigned int sizeX
 
unsigned int sizeY
 
int pos
 
unsigned long BGColor
 
unsigned long FGColor
 
unsigned long borderColor
 
unsigned int borderSize
 
std::string font
 

Constructor & Destructor Documentation

◆ Bar()

Bar::Bar ( )

Yb dP 8 w 8 Yb dP 8b d8 YbdP .d88 .d88 .d88 8d8b .d88 d88b w 8 Yb db dP 8YbmdP8 YP 8 8 8 8 8 8 8P 8 8 Yb. 8 8 YbdPYbdP 8 " 8 88Y88 Y88Y88 8 `Y88 Y88P 8 8 YP YP 8 8 wwdP wwdP Yggdrasil Window Manager https://github.com/corecaps/YggdrasilWM Copyright (C) 2024 jgarcia jgarc.nosp@m.ia@s.nosp@m.tuden.nosp@m.t.42.nosp@m..fr corec.nosp@m.aps@.nosp@m.gmail.nosp@m..com

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

32  : window(0),
33  sizeX(0),
34  sizeY(0),
35  display(nullptr),
36  root(0) {}
Window window
Definition: Bar.hpp:58
Window root
Definition: Bar.hpp:59
unsigned int sizeY
Definition: Bar.hpp:61
unsigned int sizeX
Definition: Bar.hpp:60
Display * display
Definition: Bar.hpp:57

◆ ~Bar()

Bar::~Bar ( )
38  {
39 // typedef void destroy_t(Widget*);
40 // destroy_t *destroyPlugin = (destroy_t*)dlsym(handle, "destroyPlugin");
41 // if (!destroyPlugin) {
42 // std::cerr << "Cannot load symbol destroyPlugin: " << dlerror() << '\n';
43 // dlclose(handle);
44 // return;
45 // }
46 // destroyPlugin(widget);
47 }

Member Function Documentation

◆ addWidget()

void Bar::addWidget ( void *  handle,
std::shared_ptr< ConfigDataWidget widgetConfig 
)
116  {
117  typedef Widget* create_t();
118  create_t* createPlugin = (create_t*)dlsym(handle, "createPlugin");
119  if (!createPlugin) {
120  std::cerr << "Cannot load symbol createPlugin: " << dlerror() << '\n';
121  return;
122  }
123  Widget * newWidget = createPlugin();
124  if (!newWidget) {
125  Logger::GetInstance()->Log("Cannot create plugin: " + std::string(dlerror()), L_ERROR);
126  return;
127  }
128  // TODO : change position/size for left/right bar
129  Window newWidgetWindow = newWidget->initialize(display,
130  window,
131  widgetConfig->getPosition(),0,
132  widgetConfig->getSize(),(int)sizeY,
133  widgetConfig->getFontName(),
134  widgetConfig->getBgColor(),
135  widgetConfig->getFgColor(),
136  widgetConfig->getFontSize());
137  Logger::GetInstance()->Log("New Widget added ["
138  + widgetConfig->getType()
139  + "] widgetWindow: ["
140  + std::to_string(newWidgetWindow)
141  + "] Bar ["
142  + std::to_string(window)
143  + "]", L_INFO);
144  widgets[newWidgetWindow] = newWidget;
145 }
@ L_ERROR
Definition: Logger.hpp:51
@ L_INFO
Definition: Logger.hpp:49
std::unordered_map< Window, Widget * > widgets
Definition: Bar.hpp:55
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
Definition: Widget.hpp:33
virtual Window initialize(Display *display, Window parentWindow, int x, int y, int width, int height, std::string font_, unsigned long bgColor_, unsigned long fgColor_, int fontSize)=0

References display, Logger::GetInstance(), Widget::initialize(), L_ERROR, L_INFO, Logger::Log(), sizeY, widgets, and window.

Here is the call graph for this function:

◆ draw()

void Bar::draw ( )
94  {
95  if (widgets.empty()) {
96  return;
97  }
98  for (auto &w : widgets) {
99  w.second->draw();
100  }
101  XFlush(display);
102 }

References display, and widgets.

Referenced by init().

Here is the caller graph for this function:

◆ getSizeX()

unsigned int Bar::getSizeX ( ) const
108  {
109  return sizeX;
110 }

References sizeX.

◆ getSizeY()

unsigned int Bar::getSizeY ( ) const
112  {
113  return sizeY;
114 }

References sizeY.

◆ getWidgets()

const std::unordered_map< Window, Widget * > & Bar::getWidgets ( ) const
147  {
148  return widgets;
149 }

References widgets.

◆ getWindow()

Window Bar::getWindow ( ) const
104  {
105  return window;
106 }

References window.

◆ init()

void Bar::init ( std::shared_ptr< ConfigDataBar configData,
std::shared_ptr< TSBarsData tsData 
)
49  {
51  tsData = tsData;
53  int screen = DefaultScreen(display);
54  root = RootWindow(display, screen);
55  int posX = 0;
56  int posY = 0;
57  if (configData->getBarPosition() == "top") {
58  sizeY = configData->getBarSize();
59  sizeX = DisplayWidth(display, screen);
60  posX = 0;
61  posY = 0;
62  } else if (configData->getBarPosition() == "bottom") {
63  sizeY = configData->getBarSize();
64  sizeX = DisplayWidth(display, screen);
65  posX = 0;
66  posY = DisplayHeight(display, screen) - sizeY;
67  } else if (configData->getBarPosition() == "left") {
68  sizeY = DisplayHeight(display, screen);
69  sizeX = configData->getBarSize();
70  posX = 0;
71  posY = 0;
72  } else if (configData->getBarPosition() == "right") {
73  sizeY = DisplayHeight(display, screen);
74  sizeX = configData->getBarSize();
75  posX = DisplayWidth(display, screen) - sizeX;
76  posY = 0;
77  }
78  unsigned int bg = configData->getBarBackgroundColor();
79  unsigned int fg = configData->getBarFontColor();
80  unsigned int border = configData->getBarBorderColor();
81  unsigned int borderSize = configData->getBarBorderSize();
82  window = XCreateSimpleWindow(display, root, posX, posY,sizeX, sizeY, borderSize, 0, bg);
83  XSelectInput(display, window,SubstructureRedirectMask
84  | SubstructureNotifyMask
85  | FocusChangeMask
86  | KeyPressMask
87  | ExposureMask
88  | ButtonPressMask
89  | PointerMotionMask);
90  XMapWindow(display, window);
91  this->draw();
92 }
std::shared_ptr< ConfigDataBar > configData
Definition: Bar.hpp:54
std::shared_ptr< TSBarsData > tsData
Definition: Bar.hpp:56
void draw()
Definition: Bar.cpp:94
unsigned int borderSize
Definition: Bar.hpp:66
Display * getDisplay() const
Get the Display object.
Definition: WindowManager.cpp:263
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 borderSize, configData, display, draw(), WindowManager::getDisplay(), WindowManager::getInstance(), root, sizeX, sizeY, tsData, and window.

Here is the call graph for this function:

Member Data Documentation

◆ BGColor

unsigned long Bar::BGColor
private

◆ borderColor

unsigned long Bar::borderColor
private

◆ borderSize

unsigned int Bar::borderSize
private

Referenced by init().

◆ configData

std::shared_ptr<ConfigDataBar> Bar::configData
private

Referenced by init().

◆ display

Display* Bar::display
private

Referenced by addWidget(), draw(), and init().

◆ FGColor

unsigned long Bar::FGColor
private

◆ font

std::string Bar::font
private

◆ pos

int Bar::pos
private

◆ root

Window Bar::root
private

Referenced by init().

◆ sizeX

unsigned int Bar::sizeX
private

Referenced by getSizeX(), and init().

◆ sizeY

unsigned int Bar::sizeY
private

Referenced by addWidget(), getSizeY(), and init().

◆ tsData

std::shared_ptr<TSBarsData> Bar::tsData
private

Referenced by init().

◆ widgets

std::unordered_map<Window, Widget *> Bar::widgets
private

Referenced by addWidget(), draw(), and getWidgets().

◆ window

Window Bar::window
private

Referenced by addWidget(), getWindow(), and init().


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