better window killing method

This commit is contained in:
vaxerski 2021-11-30 16:43:28 +01:00
parent 565bcd3e5f
commit e9313fe3aa
6 changed files with 45 additions and 2 deletions

View file

@ -89,7 +89,27 @@ xcb_keycode_t KeybindManager::getKeycodeFromKeysym(xcb_keysym_t keysym) {
void KeybindManager::killactive(std::string args) {
// args unused
xcb_destroy_window(g_pWindowManager->DisplayConnection, g_pWindowManager->LastWindow);
const auto PLASTWINDOW = g_pWindowManager->getWindowFromDrawable(g_pWindowManager->LastWindow);
if (!PLASTWINDOW)
return;
if (PLASTWINDOW->getCanKill()) {
// Send a kill message
xcb_client_message_event_t event;
bzero(&event, sizeof(event));
event.response_type = XCB_CLIENT_MESSAGE;
event.window = PLASTWINDOW->getDrawable();
event.type = HYPRATOMS["WM_PROTOCOLS"];
event.format = 32;
event.data.data32[0] = HYPRATOMS["WM_DELETE_WINDOW"];
event.data.data32[1] = 0;
xcb_send_event(g_pWindowManager->DisplayConnection, 0, PLASTWINDOW->getDrawable(), XCB_EVENT_MASK_NO_EVENT, (const char*)&event);
} else
xcb_kill_client(g_pWindowManager->DisplayConnection, g_pWindowManager->LastWindow);
g_pWindowManager->closeWindowAllChecks(g_pWindowManager->LastWindow);
}
void KeybindManager::call(std::string args) {
@ -160,12 +180,14 @@ void KeybindManager::toggleActiveWindowFloating(std::string unusedArg) {
const auto RESTOREACSIZE = PWINDOW->getDefaultSize();
const auto RESTOREACPOS = PWINDOW->getDefaultPosition();
const auto RESTOREWINID = PWINDOW->getDrawable();
const auto RESTORECANKILL = PWINDOW->getCanKill();
g_pWindowManager->removeWindowFromVectorSafe(PWINDOW->getDrawable());
const auto PNEWWINDOW = Events::remapWindow(RESTOREWINID, true);
PNEWWINDOW->setDefaultPosition(RESTOREACPOS);
PNEWWINDOW->setDefaultSize(RESTOREACSIZE);
PNEWWINDOW->setCanKill(RESTORECANKILL);
}
}

View file

@ -308,6 +308,9 @@ void Events::eventMapWindow(xcb_generic_event_t* event) {
// Do post-creation checks.
g_pWindowManager->doPostCreationChecks(pNewWindow);
// Do ICCCM
g_pWindowManager->getICCCMWMProtocols(pNewWindow);
}
void Events::eventButtonPress(xcb_generic_event_t* event) {

View file

@ -1,7 +1,7 @@
#include "window.hpp"
#include "windowManager.hpp"
CWindow::CWindow() { this->setImmovable(false); this->setNoInterventions(false); this->setDirty(true); this->setFullscreen(false); this->setIsFloating(false); this->setParentNodeID(0); this->setChildNodeAID(0); this->setChildNodeBID(0); this->setName(""); }
CWindow::CWindow() { this->setCanKill(false); this->setImmovable(false); this->setNoInterventions(false); this->setDirty(true); this->setFullscreen(false); this->setIsFloating(false); this->setParentNodeID(0); this->setChildNodeAID(0); this->setChildNodeBID(0); this->setName(""); }
CWindow::~CWindow() { }
void CWindow::generateNodeID() {

View file

@ -65,6 +65,9 @@ public:
// Docks etc
EXPOSED_MEMBER(Immovable, bool, b);
EXPOSED_MEMBER(NoInterventions, bool, b);
// ICCCM
EXPOSED_MEMBER(CanKill, bool, b);
private:

View file

@ -1348,4 +1348,18 @@ void CWindowManager::doPostCreationChecks(CWindow* pWindow) {
Debug::log(LOG, "Post creation checks ended");
//
}
void CWindowManager::getICCCMWMProtocols(CWindow* pWindow) {
xcb_icccm_get_wm_protocols_reply_t WMProtocolsReply;
if (!xcb_icccm_get_wm_protocols_reply(DisplayConnection,
xcb_icccm_get_wm_protocols(DisplayConnection, pWindow->getDrawable(), HYPRATOMS["WM_PROTOCOLS"]), &WMProtocolsReply, NULL))
return;
for (auto i = 0; i < (int)WMProtocolsReply.atoms_len; i++) {
if (WMProtocolsReply.atoms[i] == HYPRATOMS["WM_DELETE_WINDOW"])
pWindow->setCanKill(true);
}
xcb_icccm_get_wm_protocols_reply_wipe(&WMProtocolsReply);
}

View file

@ -95,6 +95,7 @@ public:
bool shouldBeFloatedOnInit(int64_t);
void doPostCreationChecks(CWindow*);
void getICCCMWMProtocols(CWindow*);
void setupRandrMonitors();
void createAndOpenAllPipes();