From 7856d4a224c267271566e2686513086d6aa6b721 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 24 Nov 2021 21:23:14 +0100 Subject: [PATCH] EWMH #1, now shows in neofetch --- src/ewmh/ewmh.cpp | 33 +++++++++++++++++++++++++++++++++ src/ewmh/ewmh.hpp | 9 +++++++++ src/windowManager.cpp | 37 +------------------------------------ src/windowManager.hpp | 1 + 4 files changed, 44 insertions(+), 36 deletions(-) create mode 100644 src/ewmh/ewmh.cpp create mode 100644 src/ewmh/ewmh.hpp diff --git a/src/ewmh/ewmh.cpp b/src/ewmh/ewmh.cpp new file mode 100644 index 0000000..241b30e --- /dev/null +++ b/src/ewmh/ewmh.cpp @@ -0,0 +1,33 @@ +#include "ewmh.hpp" +#include "../windowManager.hpp" + +void EWMH::setupInitEWMH() { + Debug::log(LOG, "EWMH init!"); + + EWMHwindow = xcb_generate_id(g_pWindowManager->DisplayConnection); + + Debug::log(LOG, "Allocated ID " + std::to_string(EWMHwindow) + " for the EWMH window."); + + uint32_t values[1] = {1}; + xcb_create_window(g_pWindowManager->DisplayConnection, XCB_COPY_FROM_PARENT, EWMHwindow, g_pWindowManager->Screen->root, + -1, -1, 1, 1, 0, XCB_WINDOW_CLASS_INPUT_ONLY, XCB_COPY_FROM_PARENT, 0, values); + + xcb_change_property(g_pWindowManager->DisplayConnection, XCB_PROP_MODE_REPLACE, EWMHwindow, HYPRATOMS["_NET_SUPPORTING_WM_CHECK"], XCB_ATOM_WINDOW, 32, 1, &EWMHwindow); + xcb_change_property(g_pWindowManager->DisplayConnection, XCB_PROP_MODE_REPLACE, EWMHwindow, HYPRATOMS["_NET_WM_NAME"], HYPRATOMS["UTF8_STRING"], 8, strlen("Hypr"), "Hypr"); + + xcb_change_property(g_pWindowManager->DisplayConnection, XCB_PROP_MODE_REPLACE, g_pWindowManager->Screen->root, HYPRATOMS["_NET_WM_NAME"], HYPRATOMS["UTF8_STRING"], 8, strlen("Hypr"), "Hypr"); + xcb_change_property(g_pWindowManager->DisplayConnection, XCB_PROP_MODE_REPLACE, g_pWindowManager->Screen->root, HYPRATOMS["_NET_SUPPORTING_WM_CHECK"], XCB_ATOM_WINDOW, 32, 1, &EWMHwindow); + + // Atoms EWMH + + xcb_atom_t supportedAtoms[HYPRATOMS.size()]; + int i = 0; + for (auto& a : HYPRATOMS) { + supportedAtoms[i] = a.second; + i++; + } + + xcb_change_property(g_pWindowManager->DisplayConnection, XCB_PROP_MODE_REPLACE, g_pWindowManager->Screen->root, HYPRATOMS["_NET_SUPPORTED"], XCB_ATOM_ATOM, 32, sizeof(supportedAtoms) / sizeof(xcb_atom_t), supportedAtoms); + + Debug::log(LOG, "EWMH init done."); +} \ No newline at end of file diff --git a/src/ewmh/ewmh.hpp b/src/ewmh/ewmh.hpp new file mode 100644 index 0000000..96d9ad7 --- /dev/null +++ b/src/ewmh/ewmh.hpp @@ -0,0 +1,9 @@ +#pragma once + +#include "../defines.hpp" + +namespace EWMH { + void setupInitEWMH(); + + inline xcb_window_t EWMHwindow = 0; +}; \ No newline at end of file diff --git a/src/windowManager.cpp b/src/windowManager.cpp index 4d0e922..d2420d0 100644 --- a/src/windowManager.cpp +++ b/src/windowManager.cpp @@ -80,42 +80,6 @@ void CWindowManager::setupRandrMonitors() { free(MONITORS); - /* - - const auto MONITORNUM = xcb_randr_get_screen_resources_current_outputs_length(ScreenResReply); - auto OUTPUTS = xcb_randr_get_screen_resources_current_outputs(ScreenResReply); - - xcb_randr_get_output_info_reply_t* outputReply; - xcb_randr_get_crtc_info_reply_t* crtcReply; - - Debug::log(LOG, "Monitors found: " + std::to_string(MONITORNUM)); - - for (int i = 0; i < MONITORNUM; i++) { - outputReply = xcb_randr_get_output_info_reply(DisplayConnection, xcb_randr_get_output_info(DisplayConnection, OUTPUTS[i], XCB_CURRENT_TIME), NULL); - if (!outputReply || outputReply->crtc == XCB_NONE) - continue; - crtcReply = xcb_randr_get_crtc_info_reply(DisplayConnection, xcb_randr_get_crtc_info(DisplayConnection, outputReply->crtc, XCB_CURRENT_TIME), NULL); - if (!crtcReply) - continue; - - monitors.push_back(SMonitor()); - - monitors[monitors.size() - 1].vecPosition = Vector2D(crtcReply->x, crtcReply->y); - monitors[monitors.size() - 1].vecSize = Vector2D(crtcReply->width == 0 ? 1920 : crtcReply->width, crtcReply->height); - - monitors[monitors.size() - 1].ID = monitors.size() - 1; - - char* name = (char*)xcb_randr_get_output_info_name(outputReply); - int nameLen = xcb_randr_get_output_info_name_length(outputReply); - - for (int j = 0; j < nameLen; ++j) { - monitors[monitors.size() - 1].szName += name[j]; - } - - Debug::log(NONE, "Monitor " + monitors[monitors.size() - 1].szName + ": " + std::to_string(monitors[i].vecSize.x) + "x" + std::to_string(monitors[monitors.size() - 1].vecSize.y) + - ", at " + std::to_string(monitors[monitors.size() - 1].vecPosition.x) + "," + std::to_string(monitors[monitors.size() - 1].vecPosition.y) + ", ID: " + std::to_string(monitors[monitors.size() - 1].ID)); - } */ - const auto EXTENSIONREPLY = xcb_get_extension_data(DisplayConnection, &xcb_randr_id); if (!EXTENSIONREPLY->present) Debug::log(ERR, "RandR extension missing"); @@ -128,6 +92,7 @@ void CWindowManager::setupRandrMonitors() { } void CWindowManager::setupManager() { + EWMH::setupInitEWMH(); setupRandrMonitors(); if (monitors.size() == 0) { diff --git a/src/windowManager.hpp b/src/windowManager.hpp index e656036..016dead 100644 --- a/src/windowManager.hpp +++ b/src/windowManager.hpp @@ -15,6 +15,7 @@ #include "utilities/Util.hpp" #include "utilities/AnimationUtil.hpp" #include "utilities/XCBProps.hpp" +#include "ewmh/ewmh.hpp" class CWindowManager { public: