YggdrasilWM
0.1.1
A tiny window manager coded in C++
|
WindowManager class This class is responsible for managing the windows.in an X11 session. It is the main class of the project. It should be instantiated only via the static create function. You must use the init function to initialize the WindowManager. The Run function is the main loop of the WindowManager. More...
#include <WindowManager.hpp>
Public Member Functions | |
WindowManager (const WindowManager &)=delete | |
WindowManager & | operator= (const WindowManager &)=delete |
~WindowManager () | |
Destroy the WindowManager object i have yet to find a clean way to close the window manager. More... | |
void | init () |
Initialize the WindowManager set the event select mask on the root window creates clients for the existing top level windows and launch the bar window. More... | |
void | Run () |
Run the window manager. More... | |
Display * | getDisplay () const |
Get the Display object. More... | |
Window | getRoot () const |
Get the Root Window pointer. More... | |
std::unordered_map< Window, std::shared_ptr< Client > > & | getClients () |
Get the Clients map. More... | |
std::shared_ptr< Client > | getClient (Window window) |
Get the Client by window ptr or frame ptr. More... | |
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. More... | |
unsigned long | getClientCount () |
Get the number of clients. More... | |
void | setFocus (Client *client) |
Set the focus to a client. More... | |
void | insertClient (Window window) |
Insert a client in the clients map. More... | |
void | Stop () |
Stop the window manager. More... | |
const std::vector< std::shared_ptr< Group > > & | getGroups () const |
Get the Groups vector this function returns the groups vector the groups vector contains all the groups the groups are the workspaces of the window manager the active group is the one that is currently displayed the groups are created from the config file the active group is set to the first group in the vector the active group can be changed by the user. More... | |
std::shared_ptr< Group > | getActiveGroup () const |
get the current Active Group More... | |
bool | getRunning () const |
Get the Running status. More... | |
void | setActiveGroup (std::shared_ptr< Group > activeGroup) |
void | setActiveGroup (Group *activeGroup) |
set the current active group More... | |
void | testRun () |
test function this function is used for testing purposes it is not used in the normal operation of the window manager More... | |
unsigned int | getGeometryX () const |
Get the Geometry X this function returns the width of the screen. More... | |
unsigned int | getGeometryY () const |
Get the Geometry Y. More... | |
Window | getActiveWindow () const |
Get the Active Window. More... | |
void | setActiveWindow (Window activeWindow) |
set the Active Window More... | |
const std::shared_ptr< BaseX11Wrapper > & | getX11Wrapper () const |
get the X11 Wrapper object More... | |
Static Public Member Functions | |
static void | create (std::shared_ptr< BaseX11Wrapper > wrapper, const std::string &displayStr=std::string()) |
create a WindowManager object More... | |
static WindowManager * | getInstance () |
Get the WindowManager instance this is a singleton class this function returns the instance of the WindowManager if it does not exist, it creates it. More... | |
static void | Destroy () |
Destroy the WindowManager instance this function destroys the WindowManager instance and sets the instance_ pointer to nullptr this is a singleton class this function should be called when the WindowManager is no longer needed. More... | |
Private Member Functions | |
WindowManager (Display *display, const std::shared_ptr< BaseX11Wrapper > &wrapper) | |
void | selectEventOnRoot () const |
set the event mask on the root window and register as the window manager for the X session More... | |
void | getTopLevelWindows () |
look for existing top level windows and create clients for them More... | |
void | addGroupsFromConfig () |
add groups configured in the ConfigDataGroups to the groups vector More... | |
void | createBars () |
create the bars Bars are created from the config file and handled in a separate thread More... | |
Static Private Member Functions | |
static int | OnXError (Display *display, XErrorEvent *e) |
X11 Error handler. More... | |
static int | onWmDetected ([[maybe_unused]] Display *display, XErrorEvent *e) |
When selecting events on the root window, we may get a BadAccess error if another window manager is running this function is called when a BadAccess error is detected it sets the wmDetected flag to true and stops the window manager only one window manager can run at a time. More... | |
Private Attributes | |
Display * | display_ |
const Window | root_ |
std::vector< std::shared_ptr< Group > > | groups_ |
std::weak_ptr< Group > | active_group_ {} |
const Atom | WM_PROTOCOLS |
const Atom | WM_DELETE_WINDOW |
unsigned int | geometryX {} |
unsigned int | geometryY {} |
bool | running |
std::unordered_map< Window, std::shared_ptr< Client > > | clients_ |
std::shared_ptr< TSBarsData > | tsData |
Window | activeWindow |
std::shared_ptr< BaseX11Wrapper > | x11Wrapper |
Static Private Attributes | |
static bool | wmDetected |
static WindowManager * | instance_ = nullptr |
WindowManager class This class is responsible for managing the windows.in an X11 session. It is the main class of the project. It should be instantiated only via the static create function. You must use the init function to initialize the WindowManager. The Run function is the main loop of the WindowManager.
|
delete |
WindowManager::~WindowManager | ( | ) |
Destroy the WindowManager object i have yet to find a clean way to close the window manager.
References clients_, Logger::GetInstance(), groups_, L_INFO, and Logger::Log().
|
private |
|
private |
add groups configured in the ConfigDataGroups to the groups vector
References active_group_, display_, getActiveGroup(), ConfigHandler::getConfigData(), getGroups(), ConfigHandler::GetInstance(), Logger::GetInstance(), groups_, L_INFO, Logger::Log(), root_, tsData, and x11Wrapper.
Referenced by getTopLevelWindows().
|
static |
create a WindowManager object
displayStr | Optional X Display string if not set, the DISPLAY environment variable will be used |
References Logger::GetInstance(), instance_, L_ERROR, L_INFO, Logger::Log(), and WindowManager().
Referenced by main().
|
private |
create the bars Bars are created from the config file and handled in a separate thread
References Bars::createInstance(), display_, geometryX, geometryY, getActiveGroup(), Bars::getInstance(), ConfigHandler::GetInstance(), Bars::getSpaceE(), Bars::getSpaceN(), Bars::getSpaceS(), Bars::getSpaceW(), groups_, Bars::init(), root_, Bars::start_thread(), and tsData.
Referenced by init().
|
static |
Destroy the WindowManager instance this function destroys the WindowManager instance and sets the instance_ pointer to nullptr this is a singleton class this function should be called when the WindowManager is no longer needed.
References instance_.
Referenced by main().
Group * WindowManager::getActiveGroup | ( | ) | const |
get the current Active Group
References active_group_.
Referenced by addGroupsFromConfig(), createBars(), FocusGroup::execute(), Grow::execute(), getTopLevelWindows(), EventHandler::handleDestroyNotify(), and insertClient().
void WindowManager::getActiveWindow | ( | ) | const |
Client * WindowManager::getClient | ( | Window | window | ) |
Get the Client by window ptr or frame ptr.
window |
References clients_.
Referenced by Grow::execute(), EventHandler::handleButtonPress(), EventHandler::handleFocusIn(), EventHandler::handleFocusOut(), EventHandler::handleMapNotify(), Group::moveClientToGroup(), and Group::removeClient().
unsigned long WindowManager::getClientCount | ( | ) |
Client & WindowManager::getClientRef | ( | Window | window | ) |
Get a ref to the Client by window ptr does not look for frames and throws if not found.
References clients_.
Referenced by EventHandler::handleDestroyNotify(), EventHandler::handleMapRequest(), EventHandler::handleMotionNotify(), and EventHandler::handleUnmapNotify().
std::unordered_map< Window, Client * > & WindowManager::getClients | ( | ) |
Get the Clients map.
References clients_.
Referenced by EventHandler::handleDestroyNotify(), and EventHandler::handleUnmapNotify().
Display * WindowManager::getDisplay | ( | ) | const |
Get the Display object.
References display_.
Referenced by EventHandler::handleClientMessage(), EventHandler::handleUnmapNotify(), and Bar::init().
void WindowManager::getGeometryX | ( | ) | const |
Get the Geometry X this function returns the width of the screen.
References geometryX.
Referenced by ewmh::updateDesktopGeometry().
void WindowManager::getGeometryY | ( | ) | const |
Get the Geometry Y.
References geometryY.
Referenced by ewmh::updateDesktopGeometry().
const std::vector< Group * > & WindowManager::getGroups | ( | ) | const |
Get the Groups vector this function returns the groups vector the groups vector contains all the groups the groups are the workspaces of the window manager the active group is the one that is currently displayed the groups are created from the config file the active group is set to the first group in the vector the active group can be changed by the user.
References groups_.
Referenced by addGroupsFromConfig(), FocusGroup::execute(), and ewmh::updateNumberOfDesktops().
|
static |
Get the WindowManager instance this is a singleton class this function returns the instance of the WindowManager if it does not exist, it creates it.
References instance_.
Referenced by EventHandler::EventHandler(), FocusGroup::execute(), Grow::execute(), Quit::execute(), EventHandler::handleButtonPress(), EventHandler::handleClientMessage(), EventHandler::handleConfigureRequest(), EventHandler::handleDestroyNotify(), EventHandler::handleFocusIn(), EventHandler::handleFocusOut(), EventHandler::handleKeyPress(), EventHandler::handleMapNotify(), EventHandler::handleMapRequest(), EventHandler::handleMotionNotify(), handleSIGHUP(), EventHandler::handleUnmapNotify(), Bar::init(), main(), Group::moveClientToGroup(), OnXError(), Group::removeClient(), Bars::run(), Group::switchFrom(), Group::switchTo(), ewmh::updateDesktopGeometry(), and ewmh::updateNumberOfDesktops().
Window WindowManager::getRoot | ( | ) | const |
Get the Root Window pointer.
References root_.
Referenced by EventHandler::handleClientMessage(), EventHandler::handleDestroyNotify(), EventHandler::handleFocusIn(), EventHandler::handleFocusOut(), EventHandler::handleMapRequest(), and EventHandler::handleUnmapNotify().
bool WindowManager::getRunning | ( | ) | const |
|
private |
look for existing top level windows and create clients for them
References addGroupsFromConfig(), clients_, display_, getActiveGroup(), Logger::GetInstance(), L_ERROR, L_INFO, Logger::Log(), root_, setFocus(), and x11Wrapper.
Referenced by init().
std::shared_ptr< BaseX11Wrapper > WindowManager::getX11Wrapper | ( | ) | const |
get the X11 Wrapper object
References x11Wrapper.
Referenced by EventHandler::EventHandler(), and OnXError().
void WindowManager::init | ( | ) |
Initialize the WindowManager set the event select mask on the root window creates clients for the existing top level windows and launch the bar window.
References createBars(), display_, geometryX, geometryY, ConfigHandler::getConfigData(), ConfigHandler::GetInstance(), getTopLevelWindows(), handleSIGHUP(), ewmh::initEwmh(), root_, selectEventOnRoot(), tsData, ewmh::updateWmProperties(), wmDetected, and x11Wrapper.
Referenced by main().
void WindowManager::insertClient | ( | Window | window | ) |
Insert a client in the clients map.
window |
References clients_, display_, getActiveGroup(), Logger::GetInstance(), L_ERROR, L_INFO, Logger::Log(), root_, and x11Wrapper.
Referenced by EventHandler::handleMapRequest().
|
staticprivate |
When selecting events on the root window, we may get a BadAccess error if another window manager is running this function is called when a BadAccess error is detected it sets the wmDetected flag to true and stops the window manager only one window manager can run at a time.
References wmDetected.
Referenced by selectEventOnRoot().
|
staticprivate |
X11 Error handler.
References Logger::GetInstance(), getInstance(), getX11Wrapper(), L_ERROR, and Logger::Log().
Referenced by selectEventOnRoot().
|
delete |
void WindowManager::Run | ( | ) |
Run the window manager.
References EventHandler::create(), EventHandler::dispatchEvent(), display_, EventHandler::getInstance(), Logger::GetInstance(), L_INFO, Logger::Log(), running, and x11Wrapper.
Referenced by main().
|
private |
set the event mask on the root window and register as the window manager for the X session
References display_, onWmDetected(), OnXError(), root_, and x11Wrapper.
Referenced by init().
void WindowManager::setActiveGroup | ( | Group * | activeGroup | ) |
void WindowManager::setActiveGroup | ( | std::shared_ptr< Group > | activeGroup | ) |
References active_group_, and tsData.
Referenced by Group::switchTo().
void WindowManager::setActiveWindow | ( | Window | activeWindow | ) |
set the Active Window
activeWindow |
References activeWindow.
Referenced by EventHandler::handleFocusIn(), and EventHandler::handleFocusOut().
void WindowManager::setFocus | ( | Client * | client | ) |
Set the focus to a client.
References display_, Client::getWindow(), and x11Wrapper.
Referenced by getTopLevelWindows(), EventHandler::handleDestroyNotify(), and EventHandler::handleMapRequest().
void WindowManager::Stop | ( | ) |
Stop the window manager.
References Bars::destroy(), display_, Bars::getInstance(), root_, running, Bars::stop_thread(), and x11Wrapper.
Referenced by Quit::execute(), and handleSIGHUP().
void WindowManager::testRun | ( | ) |
test function this function is used for testing purposes it is not used in the normal operation of the window manager
References EventHandler::create(), EventHandler::dispatchEvent(), display_, EventHandler::getInstance(), and x11Wrapper.
|
private |
Referenced by addGroupsFromConfig(), getActiveGroup(), and setActiveGroup().
|
private |
Referenced by getActiveWindow(), and setActiveWindow().
|
private |
Referenced by getClient(), getClientCount(), getClientRef(), getClients(), getTopLevelWindows(), insertClient(), and ~WindowManager().
|
private |
Referenced by addGroupsFromConfig(), createBars(), getDisplay(), getTopLevelWindows(), init(), insertClient(), Run(), selectEventOnRoot(), setFocus(), Stop(), and testRun().
|
private |
Referenced by createBars(), getGeometryX(), and init().
|
private |
Referenced by createBars(), getGeometryY(), and init().
|
private |
Referenced by addGroupsFromConfig(), createBars(), getGroups(), and ~WindowManager().
|
staticprivate |
Referenced by create(), Destroy(), and getInstance().
|
private |
Referenced by addGroupsFromConfig(), createBars(), getRoot(), getTopLevelWindows(), init(), insertClient(), selectEventOnRoot(), and Stop().
|
private |
Referenced by getRunning(), Run(), and Stop().
|
private |
Referenced by addGroupsFromConfig(), createBars(), init(), and setActiveGroup().
|
private |
|
private |
|
staticprivate |
Referenced by init(), and onWmDetected().
|
private |
Referenced by addGroupsFromConfig(), getTopLevelWindows(), getX11Wrapper(), init(), insertClient(), Run(), selectEventOnRoot(), setFocus(), Stop(), and testRun().