🎨 No reparent + logs

This commit is contained in:
Paul Breugnot 2024-12-15 14:45:02 +01:00
parent cb31369947
commit 6b9513987a
5 changed files with 28 additions and 103 deletions

View File

@ -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

View File

@ -1,21 +1,39 @@
#ifndef ASWM_CONFIGURE
#define ASWM_CONFIGURE
#include "configure.h"
#include <stdio.h>
#include <X11/Xutil.h>
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

View File

@ -1,10 +1,6 @@
#ifndef ASWM_CREATE
#define ASWM_CREATE
#include "create.h"
#include <stdio.h>
void OnCreateNotify(const XCreateWindowEvent* e) {
printf("XCreateWindowEvent %lu\n", e->window);
}
#endif

View File

@ -1,75 +1,7 @@
#ifndef ASWM_MAP
#define ASWM_MAP
#include "map.h"
#include <stdio.h>
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

View File

@ -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 << "]";
* }
*/