diff --git a/CMakeLists.txt b/CMakeLists.txt index c110d25..e08a56f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,11 +7,11 @@ find_package(X11 REQUIRED) set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fsanitize=address") add_executable(aswm - src/main.c - src/create.c - src/configure.c - src/reparent.c - src/destroy.c - src/map.c) + src/aswm/main.c + src/aswm/event_handlers/create.c + src/aswm/event_handlers/configure.c + src/aswm/event_handlers/reparent.c + src/aswm/event_handlers/destroy.c + src/aswm/event_handlers/map.c) target_include_directories(aswm PUBLIC ${X11_INCLUDE_DIR} include) target_link_libraries(aswm ${X11_LIBRARIES}) diff --git a/include/configure.h b/include/aswm/event_handlers/configure.h similarity index 100% rename from include/configure.h rename to include/aswm/event_handlers/configure.h diff --git a/include/create.h b/include/aswm/event_handlers/create.h similarity index 100% rename from include/create.h rename to include/aswm/event_handlers/create.h diff --git a/include/destroy.h b/include/aswm/event_handlers/destroy.h similarity index 100% rename from include/destroy.h rename to include/aswm/event_handlers/destroy.h diff --git a/include/map.h b/include/aswm/event_handlers/map.h similarity index 100% rename from include/map.h rename to include/aswm/event_handlers/map.h diff --git a/include/reparent.h b/include/aswm/event_handlers/reparent.h similarity index 100% rename from include/reparent.h rename to include/aswm/event_handlers/reparent.h diff --git a/include/unmap.h b/include/aswm/event_handlers/unmap.h similarity index 100% rename from include/unmap.h rename to include/aswm/event_handlers/unmap.h diff --git a/src/configure.c b/src/aswm/event_handlers/configure.c similarity index 70% rename from src/configure.c rename to src/aswm/event_handlers/configure.c index b4e7c49..8cb90fe 100644 --- a/src/configure.c +++ b/src/aswm/event_handlers/configure.c @@ -1,32 +1,19 @@ -#include "configure.h" +#include "aswm/event_handlers/configure.h" #include -#include void OnConfigureRequest(const XConfigureRequestEvent* e) { - XWindowChanges changes; printf("XConfigureRequestEvent %lu\n", e->window); printf("\tx = %i\n", e->x); printf("\ty = %i\n", e->y); printf("\tw = %i\n", e->width); printf("\th = %i\n", e->height); - - { - XTextProperty text_property; - XGetWMName(e->display, e->window, &text_property); - printf("\tname: %s\n", text_property.value); - } - { - XClassHint class; - XGetClassHint(e->display, e->window, &class); - printf("\tclass: %s, %s\n", class.res_class, class.res_name); - } - int screen_number = XDefaultScreen(e->display); int full_width = XDisplayWidth(e->display, screen_number); int full_height = XDisplayWidth(e->display, screen_number); // Copy fields from e to changes. + XWindowChanges changes; changes.x = 0; changes.y = 0; changes.width = full_width; diff --git a/src/create.c b/src/aswm/event_handlers/create.c similarity index 75% rename from src/create.c rename to src/aswm/event_handlers/create.c index 95c3052..2254671 100644 --- a/src/create.c +++ b/src/aswm/event_handlers/create.c @@ -1,4 +1,4 @@ -#include "create.h" +#include "aswm/event_handlers/create.h" #include void OnCreateNotify(const XCreateWindowEvent* e) { diff --git a/src/destroy.c b/src/aswm/event_handlers/destroy.c similarity index 78% rename from src/destroy.c rename to src/aswm/event_handlers/destroy.c index 635c844..f1c0197 100644 --- a/src/destroy.c +++ b/src/aswm/event_handlers/destroy.c @@ -1,4 +1,4 @@ -#include "destroy.h" +#include "aswm/event_handlers/destroy.h" #include void OnDestroyNotify(const XDestroyWindowEvent* e) { diff --git a/src/aswm/event_handlers/map.c b/src/aswm/event_handlers/map.c new file mode 100644 index 0000000..7d22a65 --- /dev/null +++ b/src/aswm/event_handlers/map.c @@ -0,0 +1,38 @@ +#include "aswm/event_handlers/map.h" +#include +#include + +void OnMapRequest(Window root, const XMapRequestEvent* e) { + printf("XMapRequestEvent %lu\n", e->window); + + { + XTextProperty text_property; + XGetWMName(e->display, e->window, &text_property); + printf("\tname: %s\n", text_property.value); + } + { + XClassHint class; + XGetClassHint(e->display, e->window, &class); + printf("\tclass: %s, %s\n", class.res_class, class.res_name); + } + + int screen_number = XDefaultScreen(e->display); + int full_width = XDisplayWidth(e->display, screen_number); + int full_height = XDisplayWidth(e->display, screen_number); + + // Automatically reconfigure position and size of the window + XWindowChanges changes; + changes.x = 0; + changes.y = 0; + changes.width = full_width; + changes.height = full_height; + + printf("\tx = %i\n", changes.x); + printf("\ty = %i\n", changes.y); + printf("\tw = %i\n", changes.width); + printf("\th = %i\n", changes.height); + + XConfigureWindow(e->display, e->window, CWX | CWY | CWWidth | CWHeight, &changes); + + XMapWindow(e->display, e->window); +} diff --git a/src/reparent.c b/src/aswm/event_handlers/reparent.c similarity index 73% rename from src/reparent.c rename to src/aswm/event_handlers/reparent.c index f2f3842..9c6d14a 100644 --- a/src/reparent.c +++ b/src/aswm/event_handlers/reparent.c @@ -1,4 +1,4 @@ -#include "reparent.h" +#include "aswm/event_handlers/reparent.h" #include void OnReparentNotify(const XReparentEvent* e) { diff --git a/src/unmap.c b/src/aswm/event_handlers/unmap.c similarity index 76% rename from src/unmap.c rename to src/aswm/event_handlers/unmap.c index 6f3ae67..26ecb2e 100644 --- a/src/unmap.c +++ b/src/aswm/event_handlers/unmap.c @@ -1,4 +1,4 @@ -#include "unmap.h" +#include "aswm/event_handlers/unmap.h" #include void OnUnmapRequest(Window root, const XMapRequestEvent* e) { diff --git a/src/main.c b/src/aswm/main.c similarity index 79% rename from src/main.c rename to src/aswm/main.c index 766493e..277c6e1 100644 --- a/src/main.c +++ b/src/aswm/main.c @@ -1,9 +1,9 @@ #include -#include "create.h" -#include "configure.h" -#include "map.h" -#include "reparent.h" -#include "destroy.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" Display *display; Window root; diff --git a/src/map.c b/src/map.c deleted file mode 100644 index c9a590c..0000000 --- a/src/map.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "map.h" -#include - -void OnMapRequest(Window root, const XMapRequestEvent* e) { - printf("XMapRequestEvent %lu\n", e->window); - XMapWindow(e->display, e->window); -}