From 6b9513987ac0e6a56e0c9a799cf459100997b2da Mon Sep 17 00:00:00 2001 From: Paul Breugnot Date: Sun, 15 Dec 2024 14:45:02 +0100 Subject: [PATCH] :art: No reparent + logs --- CMakeLists.txt | 2 ++ src/configure.c | 34 +++++++++++++++++++------ src/create.c | 4 --- src/map.c | 68 ------------------------------------------------- src/unmap.c | 23 ----------------- 5 files changed, 28 insertions(+), 103 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 18a6bbf..c110d25 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,8 @@ project(aswm) find_package(X11 REQUIRED) +set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fsanitize=address") + add_executable(aswm src/main.c src/create.c diff --git a/src/configure.c b/src/configure.c index ec158e9..b4e7c49 100644 --- a/src/configure.c +++ b/src/configure.c @@ -1,21 +1,39 @@ -#ifndef ASWM_CONFIGURE -#define ASWM_CONFIGURE - #include "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. - changes.x = e->x; - changes.y = e->y; - changes.width = e->width; - changes.height = e->height; + changes.x = 0; + changes.y = 0; + changes.width = full_width; + changes.height = full_height; changes.border_width = e->border_width; changes.sibling = e->above; changes.stack_mode = e->detail; // Grant request by calling XConfigureWindow(). XConfigureWindow(e->display, e->window, e->value_mask, &changes); } -#endif diff --git a/src/create.c b/src/create.c index 3b6fed9..95c3052 100644 --- a/src/create.c +++ b/src/create.c @@ -1,10 +1,6 @@ -#ifndef ASWM_CREATE -#define ASWM_CREATE - #include "create.h" #include void OnCreateNotify(const XCreateWindowEvent* e) { printf("XCreateWindowEvent %lu\n", e->window); } -#endif diff --git a/src/map.c b/src/map.c index 643b470..c9a590c 100644 --- a/src/map.c +++ b/src/map.c @@ -1,75 +1,7 @@ -#ifndef ASWM_MAP -#define ASWM_MAP - #include "map.h" #include -void map_fullscreen_window(Window root, Display* display, Window w); - void OnMapRequest(Window root, const XMapRequestEvent* e) { printf("XMapRequestEvent %lu\n", e->window); - map_fullscreen_window(root, e->display, e->window); XMapWindow(e->display, e->window); } - -void map_fullscreen_window(Window root, Display* display, Window w) { - // Visual properties of the frame to create. - const unsigned int BORDER_WIDTH = 0; - const unsigned long BORDER_COLOR = 0xff0000; - const unsigned long BG_COLOR = 0x0000ff; - - // 1. Retrieve attributes of window to frame. - XWindowAttributes x_window_attrs; - XGetWindowAttributes(display, w, &x_window_attrs); - - // 2. TODO - see Framing Existing Top-Level Windows section below. - - printf("\tXCreateSimpleWindow:\n"); - printf("\t\tx: %i\n", x_window_attrs.x); - printf("\t\ty: %i\n", x_window_attrs.y); - printf("\t\tw: %i\n", x_window_attrs.width); - printf("\t\th: %i\n", x_window_attrs.height); - - // 3. Create frame. - const Window frame = XCreateSimpleWindow( - display, - root, - x_window_attrs.x, - x_window_attrs.y, - x_window_attrs.width, - x_window_attrs.height, - BORDER_WIDTH, - BORDER_COLOR, - BG_COLOR); - // 3. Select events on frame. - XSelectInput( - display, - frame, - SubstructureRedirectMask | SubstructureNotifyMask); - // 4. Add client to save set, so that it will be restored and kept alive if we - // crash. - XAddToSaveSet(display, w); - // 5. Reparent client window. - XReparentWindow( - display, - w, - frame, - 0, 0); // Offset of client window within frame. - // 6. Map frame. - XMapWindow(display, frame); - // 7. Save frame handle. - /* clients_[w] = frame; */ - // 8. Grab events for window management actions on client window. - // a. Move windows with alt + left button. - /* XGrabButton(...); */ - // b. Resize windows with alt + right button. - /* XGrabButton(...); */ - // c. Kill windows with alt + f4. - /* XGrabKey(...); */ - // d. Switch windows with alt + tab. - /* XGrabKey(...); */ - - printf("\tFramed window %lu [%lu]\n", w, frame); -} - -#endif diff --git a/src/unmap.c b/src/unmap.c index f55ccac..6f3ae67 100644 --- a/src/unmap.c +++ b/src/unmap.c @@ -4,26 +4,3 @@ void OnUnmapRequest(Window root, const XMapRequestEvent* e) { printf("XUnmapWindow %lu", e->window); } - -/* - * void unframe(Window root, Display* display, Window w) { - * // We reverse the steps taken in Frame(). - * const Window frame = clients_[w]; - * // 1. Unmap frame. - * XUnmapWindow(display, frame); - * // 2. Reparent client window back to root window. - * XReparentWindow( - * display, - * w, - * root, - * 0, 0); // Offset of client window within root. - * // 3. Remove client window from save set, as it is now unrelated to us. - * XRemoveFromSaveSet(display, w); - * // 4. Destroy frame. - * XDestroyWindow(display, frame); - * // 5. Drop reference to frame handle. - * clients_.erase(w); - * - * LOG(INFO) << "Unframed window " << w << " [" << frame << "]"; - * } - */