From 000b7832794785534fbc9cdd65f2828278fcd9fe Mon Sep 17 00:00:00 2001 From: Paul Breugnot Date: Sat, 28 Dec 2024 11:11:16 +0100 Subject: [PATCH] :construction: Basic ES-DE window detection and event logging --- CMakeLists.txt | 3 ++- src/aswm/aswm.c | 33 ++++++++++++++++++++++++++++++++- src/aswm/aswm.h | 1 + src/aswm/event_handlers/map.c | 5 +++++ src/aswm/event_handlers/unmap.c | 7 +++++-- src/aswm/event_handlers/unmap.h | 4 +++- src/aswm/mapper/mapper.h | 1 + 7 files changed, 49 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5fa353b..6558b84 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,7 @@ add_executable(aswm src/aswm/event_handlers/configure.c src/aswm/event_handlers/reparent.c src/aswm/event_handlers/destroy.c - src/aswm/event_handlers/map.c) + src/aswm/event_handlers/map.c + src/aswm/event_handlers/unmap.c) target_include_directories(aswm PUBLIC ${X11_INCLUDE_DIR} src) target_link_libraries(aswm ${X11_LIBRARIES}) diff --git a/src/aswm/aswm.c b/src/aswm/aswm.c index e787c62..acf2eb1 100644 --- a/src/aswm/aswm.c +++ b/src/aswm/aswm.c @@ -1,8 +1,10 @@ #include +#include #include "aswm.h" #include "event_handlers/create.h" #include "event_handlers/configure.h" #include "event_handlers/map.h" +#include "event_handlers/unmap.h" #include "event_handlers/reparent.h" #include "event_handlers/destroy.h" @@ -15,7 +17,11 @@ void aswm_open() { _aswm.root_tile = aswm_alloc_root_tile(_aswm.display, _aswm.root_window); - XSelectInput(_aswm.display, _aswm.root_window, SubstructureRedirectMask | SubstructureNotifyMask); + printf("PointerRoot %lu\n", PointerRoot); + printf("None %lu\n", None); + printf("Root window %lu\n", _aswm.root_window); + + XSelectInput(_aswm.display, _aswm.root_window, SubstructureRedirectMask | SubstructureNotifyMask | FocusChangeMask | EnterWindowMask | LeaveWindowMask | ButtonPressMask | ButtonReleaseMask); XSync(_aswm.display, 0); atexit(aswm_close); @@ -36,12 +42,37 @@ void aswm_event_loop() { case MapRequest: OnMapRequest(&_aswm, &e.xmaprequest); break; + case UnmapNotify: + OnUnmapNotify(&_aswm, &e.xunmap); + break; case DestroyNotify: OnDestroyNotify(&e.xdestroywindow); break; case ReparentNotify: OnReparentNotify(&e.xreparent); break; + case FocusIn: + printf("FocusIn %lu\n", (&e.xfocus)->window); + break; + case FocusOut: + printf("FocusOut %lu\n", e.xfocus.window); + break; + case EnterNotify: + int revert_to; + Window window; + XGetInputFocus(e.xcrossing.display, &window, &revert_to); + printf("Enter %lu\n", e.xcrossing.window); + printf("Input focus %lu\n", window); + break; + case LeaveNotify: + printf("Leave %lu\n", e.xcrossing.window); + break; + case ButtonPress: + printf("Press %lu\n", e.xbutton.window); + break; + case ButtonRelease: + printf("Release %lu\n", e.xbutton.window); + break; default: break; /* LOG(WARNING) << "Ignored event"; */ diff --git a/src/aswm/aswm.h b/src/aswm/aswm.h index 0358410..c0944c5 100644 --- a/src/aswm/aswm.h +++ b/src/aswm/aswm.h @@ -7,6 +7,7 @@ typedef struct { Display *display; Window root_window; AswmTile* root_tile; + Window es_de_window; } Aswm; void aswm_open(); diff --git a/src/aswm/event_handlers/map.c b/src/aswm/event_handlers/map.c index 896cb5f..6e96a9a 100644 --- a/src/aswm/event_handlers/map.c +++ b/src/aswm/event_handlers/map.c @@ -1,5 +1,6 @@ #include "map.h" #include +#include #include void OnMapRequest(Aswm* aswm, const XMapRequestEvent* e) { @@ -9,6 +10,8 @@ void OnMapRequest(Aswm* aswm, const XMapRequestEvent* e) { XTextProperty text_property; XGetWMName(e->display, e->window, &text_property); printf("\tname: %s\n", text_property.value); + if(text_property.value != nullptr && strcmp(text_property.value, "ES-DE") == 0) + aswm->es_de_window = e->window; } { XClassHint class; @@ -21,5 +24,7 @@ void OnMapRequest(Aswm* aswm, const XMapRequestEvent* e) { int full_height = XDisplayWidth(e->display, screen_number); aswm_map_new_window(e->display, e->window, aswm->root_tile); + + /* XSelectInput(e->display, e->window, FocusChangeMask | EnterWindowMask | LeaveWindowMask | ButtonPressMask | ButtonReleaseMask); */ XMapWindow(e->display, e->window); } diff --git a/src/aswm/event_handlers/unmap.c b/src/aswm/event_handlers/unmap.c index 6f3ae67..c4431f6 100644 --- a/src/aswm/event_handlers/unmap.c +++ b/src/aswm/event_handlers/unmap.c @@ -1,6 +1,9 @@ #include "unmap.h" #include -void OnUnmapRequest(Window root, const XMapRequestEvent* e) { - printf("XUnmapWindow %lu", e->window); +void OnUnmapNotify(Aswm* aswm, const XUnmapEvent* e) { + printf("XUnmapWindow %lu\n", e->window); + printf("ES-DE window %lu\n", aswm->es_de_window); + if(aswm->es_de_window != None) + XSetInputFocus(e->display, aswm->es_de_window, RevertToPointerRoot, CurrentTime); } diff --git a/src/aswm/event_handlers/unmap.h b/src/aswm/event_handlers/unmap.h index f82fe1c..5f0aec4 100644 --- a/src/aswm/event_handlers/unmap.h +++ b/src/aswm/event_handlers/unmap.h @@ -1,3 +1,5 @@ #include -void OnUnmapRequest(Window root, const XMapRequestEvent* e); +#include "aswm/aswm.h" + +void OnUnmapNotify(Aswm* aswm, const XUnmapEvent* e); diff --git a/src/aswm/mapper/mapper.h b/src/aswm/mapper/mapper.h index 3e7a757..dce378d 100644 --- a/src/aswm/mapper/mapper.h +++ b/src/aswm/mapper/mapper.h @@ -20,5 +20,6 @@ AswmTile* aswm_alloc_root_tile(Display* display, Window window); void aswm_free_tile(AswmTile* tile); AswmTile* aswm_map_new_window(Display* display, Window window, AswmTile* tile); +AswmTile* aswm_unmap_window(Display* display, Window window, AswmTile* tile); #endif