diff --git a/CMakeLists.txt b/CMakeLists.txt index e08a56f..e30d5fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,7 @@ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fsanitize=address") add_executable(aswm src/aswm/main.c + src/aswm/aswm.c src/aswm/event_handlers/create.c src/aswm/event_handlers/configure.c src/aswm/event_handlers/reparent.c diff --git a/include/aswm/aswm.h b/include/aswm/aswm.h new file mode 100644 index 0000000..46800a2 --- /dev/null +++ b/include/aswm/aswm.h @@ -0,0 +1,11 @@ +#include + +typedef struct { + Display *display; + Window root; +} aswm; + +void AswmOpen(); +void AswmEventLoop(); +void AswmClose(); + diff --git a/src/aswm/aswm.c b/src/aswm/aswm.c new file mode 100644 index 0000000..5a3f5b6 --- /dev/null +++ b/src/aswm/aswm.c @@ -0,0 +1,48 @@ +#include "aswm/aswm.h" +#include "aswm/event_handlers/create.h" +#include "aswm/event_handlers/configure.h" +#include "aswm/event_handlers/map.h" +#include "aswm/event_handlers/reparent.h" +#include "aswm/event_handlers/destroy.h" + +aswm _aswm; + +void AswmOpen() { + _aswm.display = XOpenDisplay(NULL); + _aswm.root = DefaultRootWindow(_aswm.display); + + XSelectInput(_aswm.display, _aswm.root, SubstructureRedirectMask | SubstructureNotifyMask); + XSync(_aswm.display, 0); +} + +void AswmEventLoop() { + for (;;) { + XEvent e; + XNextEvent(_aswm.display, &e); + + switch(e.type) { + case CreateNotify: + OnCreateNotify(&e.xcreatewindow); + break; + case ConfigureRequest: + OnConfigureRequest(&e.xconfigurerequest); + break; + case MapRequest: + OnMapRequest(_aswm.root, &e.xmaprequest); + break; + case DestroyNotify: + OnDestroyNotify(&e.xdestroywindow); + break; + case ReparentNotify: + OnReparentNotify(&e.xreparent); + break; + default: + break; + /* LOG(WARNING) << "Ignored event"; */ + } + } +} + +void AswmClose() { + XCloseDisplay(_aswm.display); +} diff --git a/src/aswm/main.c b/src/aswm/main.c index 277c6e1..46f5d3e 100644 --- a/src/aswm/main.c +++ b/src/aswm/main.c @@ -1,46 +1,7 @@ -#include -#include "aswm/event_handlers/create.h" -#include "aswm/event_handlers/configure.h" -#include "aswm/event_handlers/map.h" -#include "aswm/event_handlers/reparent.h" -#include "aswm/event_handlers/destroy.h" - -Display *display; -Window root; +#include "aswm/aswm.h" int main(int argc, char** argv) { - display = XOpenDisplay(NULL); - - root = DefaultRootWindow(display); - - XSelectInput(display, root, SubstructureRedirectMask | SubstructureNotifyMask); - XSync(display, 0); - - for (;;) { - XEvent e; - XNextEvent(display, &e); - - switch(e.type) { - case CreateNotify: - OnCreateNotify(&e.xcreatewindow); - break; - case ConfigureRequest: - OnConfigureRequest(&e.xconfigurerequest); - break; - case MapRequest: - OnMapRequest(root, &e.xmaprequest); - break; - case DestroyNotify: - OnDestroyNotify(&e.xdestroywindow); - break; - case ReparentNotify: - OnReparentNotify(&e.xreparent); - break; - default: - break; - /* LOG(WARNING) << "Ignored event"; */ - } - } - - XCloseDisplay(display); + AswmOpen(); + AswmEventLoop(); + AswmClose(); }