diff --git a/src/aswm/event_handlers/map.c b/src/aswm/event_handlers/map.c index a4f43e5..b3063d4 100644 --- a/src/aswm/event_handlers/map.c +++ b/src/aswm/event_handlers/map.c @@ -26,6 +26,8 @@ void OnMapRequest(Aswm* aswm, const XMapRequestEvent* e) { if(!stacked) aswm_tile_window(e->display, aswm->current_desktop.tile_root, e->window); + XSetInputFocus(e->display, e->window, RevertToParent, CurrentTime); + aswm_info("Map tree:\n"); aswm_log_tree(aswm_info, aswm, DefaultRootWindow(aswm->display), 1); } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c7a8b9d..f7d9db2 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -14,6 +14,7 @@ add_executable(test_aswm aswm/create_windows/multiple_resizeable.c aswm/create_windows/single_fixed_size.c aswm/property/fix_size.c + aswm/input_focus/init.c ) target_include_directories(test_aswm PUBLIC ${unity_SOURCE_DIR}/src) target_link_libraries(test_aswm libaswm unity) diff --git a/test/aswm/aswm.c b/test/aswm/aswm.c index 30a0791..d7282a0 100644 --- a/test/aswm/aswm.c +++ b/test/aswm/aswm.c @@ -4,6 +4,7 @@ #include "../test_set_up.h" #include "create_windows.h" #include "property.h" +#include "input_focus.h" void run_aswm(void) { int stat_loc; @@ -22,6 +23,7 @@ int main(void) { RUN_TEST(create_multiple_resizeable_top_level_window); RUN_TEST(create_single_fixed_size_top_level_window); RUN_TEST(fix_size_of_an_existing_single_top_level_window); + RUN_TEST(init_input_focus); } tear_down_test_logger(); return UNITY_END(); diff --git a/test/aswm/input_focus.h b/test/aswm/input_focus.h new file mode 100644 index 0000000..373a804 --- /dev/null +++ b/test/aswm/input_focus.h @@ -0,0 +1,6 @@ +#ifndef TEST_ASWM_INPUT_FOCUS +#define TEST_ASWM_INPUT_FOCUS + +void init_input_focus(void); + +#endif diff --git a/test/aswm/input_focus/init.c b/test/aswm/input_focus/init.c new file mode 100644 index 0000000..5f2debe --- /dev/null +++ b/test/aswm/input_focus/init.c @@ -0,0 +1,29 @@ +#include "../../test_set_up.h" +#include "../../utils.h" + +void init_input_focus() { + const int N = 3; + Window windows[N]; + Window children[N]; + + for(auto i = 0; i < N; i++) { + windows[i] = XCreateSimpleWindow(test_display, test_root, + 10 /*x*/, 10 /*y*/, 128 /*w*/, 128 /*h*/, + 0 /*TODO: border width*/, CopyFromParent /*depth*/, blue(((float) i+1)/N).pixel /* background */); + // The top level windows might have children. Those must **not** be + // altered by the Window Manager + children[i] = XCreateSimpleWindow(test_display, windows[i], + 0, 0, 25, 30, + 0, CopyFromParent, red(1).pixel); + XMapWindow(test_display, children[i]); + XMapWindow(test_display, windows[i]); + + Window input_focus; + int revert_to; + wait_visibility(test_display, windows[i]); + + XGetInputFocus(test_display, &input_focus, &revert_to); + + TEST_ASSERT_EQUAL(input_focus, windows[i]); + } +}