From f23a7572773d99399acac4d0172b751eaf8ea3f0 Mon Sep 17 00:00:00 2001 From: intexisty <30681593+intexisty@users.noreply.github.com> Date: Wed, 15 Dec 2021 11:57:32 -0600 Subject: [PATCH] Added return for if another wm is running --- src/main.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 844e3fc..b963304 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,6 +11,8 @@ #include "xdg.hpp" +//int check_x(); +//int check_other_wm(); void autostart(Config conf); int main() { @@ -23,17 +25,16 @@ int main() { Config config(std::filesystem::canonical(path)); #endif - // Check if X is running + // TODO: Turn this into `int check_x()` Display* disp = XOpenDisplay(NULL); if (!disp) { // Can't really start an X window manager without X. - std::cerr << "X is not running, please start X first!"; + std::cerr << "X is not running, please start X first!" << std::endl; return 1; } XCloseDisplay(disp); free(disp); // Not sure if X frees this pointer, going to do it anyways until told otherwise. - // opens connection to display server (xorg) xcb_connection_t* connection = xcb_connect(NULL, NULL); // grab first screen @@ -41,6 +42,16 @@ int main() { xcb_screen_iterator_t iter = xcb_setup_roots_iterator(setup); xcb_screen_t* screen = iter.data; + // TODO: Turn this into `int check_other_wm()` + xcb_generic_error_t* error; + unsigned int mask[1] = {XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT}; + error = xcb_request_check(connection, xcb_change_window_attributes_checked(connection, screen->root, XCB_CW_EVENT_MASK, mask)); + xcb_flush(connection); + if (error) { + std::cerr << "Another WM is running, please close out of it first!" << std::endl; + return 1; + } + // create basic window xcb_window_t window = xcb_generate_id(connection); xcb_create_window(connection, XCB_COPY_FROM_PARENT, window, screen->root, 0, 0, 150, 150, 10, XCB_WINDOW_CLASS_INPUT_OUTPUT, screen->root_visual, 0, NULL);