Added return for if another wm is running

This commit is contained in:
intexisty 2021-12-15 11:57:32 -06:00
parent 6ee58399a9
commit f23a757277
1 changed files with 14 additions and 3 deletions

View File

@ -11,6 +11,8 @@
#include "xdg.hpp" #include "xdg.hpp"
//int check_x();
//int check_other_wm();
void autostart(Config conf); void autostart(Config conf);
int main() { int main() {
@ -23,17 +25,16 @@ int main() {
Config config(std::filesystem::canonical(path)); Config config(std::filesystem::canonical(path));
#endif #endif
// Check if X is running // TODO: Turn this into `int check_x()`
Display* disp = XOpenDisplay(NULL); Display* disp = XOpenDisplay(NULL);
if (!disp) { if (!disp) {
// Can't really start an X window manager without X. // 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; return 1;
} }
XCloseDisplay(disp); XCloseDisplay(disp);
free(disp); // Not sure if X frees this pointer, going to do it anyways until told otherwise. 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); xcb_connection_t* connection = xcb_connect(NULL, NULL);
// grab first screen // grab first screen
@ -41,6 +42,16 @@ int main() {
xcb_screen_iterator_t iter = xcb_setup_roots_iterator(setup); xcb_screen_iterator_t iter = xcb_setup_roots_iterator(setup);
xcb_screen_t* screen = iter.data; 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 // create basic window
xcb_window_t window = xcb_generate_id(connection); 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); 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);