keybinds on reload

This commit is contained in:
vaxerski 2021-11-23 16:49:53 +01:00
parent 52a6ede355
commit 1fd1e09dbc
4 changed files with 33 additions and 26 deletions

View file

@ -134,11 +134,9 @@ void CStatusBar::draw() {
const auto WORKSPACE = g_pWindowManager->getWorkspaceByID(g_pWindowManager->activeWorkspaces[m_iMonitorID]);
if (WORKSPACE->getHasFullscreenWindow())
if (WORKSPACE->getHasFullscreenWindow()) // TODO: fix this
return; // Do not draw a bar on a fullscreen window.
// TODO: CRIT! Status bar flashes, workspaces are wonky (wrong IDs?)
xcb_rectangle_t rectangles[] = {{(int)0, (int)0, (int)m_vecSize.x, (int)m_vecSize.y}};
xcb_poly_fill_rectangle(g_pWindowManager->DisplayConnection, m_iPixmap, m_mContexts["BG"].GContext, 1, rectangles);

View file

@ -25,6 +25,7 @@ void ConfigManager::init() {
configValues["col.inactive_border"].intValue = 0x77222222;
loadConfigLoadVars();
applyKeybindsToX();
}
void handleBind(const std::string& command, const std::string& value) {
@ -174,6 +175,31 @@ void emptyEvent() {
xcb_flush(g_pWindowManager->DisplayConnection);
}
void ConfigManager::applyKeybindsToX() {
xcb_ungrab_key(g_pWindowManager->DisplayConnection, XCB_GRAB_ANY, g_pWindowManager->Screen->root, XCB_MOD_MASK_ANY);
for (auto& keybind : KeybindManager::keybinds) {
xcb_grab_key(g_pWindowManager->DisplayConnection, 1, g_pWindowManager->Screen->root,
KeybindManager::modToMask(keybind.getMod()), KeybindManager::getKeycodeFromKeysym(keybind.getKeysym()),
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
}
xcb_flush(g_pWindowManager->DisplayConnection);
// MOD + mouse
xcb_grab_button(g_pWindowManager->DisplayConnection, 0,
g_pWindowManager->Screen->root, XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE,
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, g_pWindowManager->Screen->root, XCB_NONE,
1, KeybindManager::modToMask(MOD_SUPER));
xcb_grab_button(g_pWindowManager->DisplayConnection, 0,
g_pWindowManager->Screen->root, XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE,
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, g_pWindowManager->Screen->root, XCB_NONE,
3, KeybindManager::modToMask(MOD_SUPER));
xcb_flush(g_pWindowManager->DisplayConnection);
}
void ConfigManager::tick() {
const char* const ENVHOME = getenv("HOME");
@ -191,6 +217,9 @@ void ConfigManager::tick() {
ConfigManager::loadConfigLoadVars();
// So that X updates our grabbed keys.
ConfigManager::applyKeybindsToX();
// so that the WM reloads the windows.
emptyEvent();
}

View file

@ -19,6 +19,8 @@ namespace ConfigManager {
void loadConfigLoadVars();
void tick();
void applyKeybindsToX();
int getInt(std::string_view);
float getFloat(std::string_view);
std::string getString(std::string_view);

View file

@ -146,33 +146,11 @@ void CWindowManager::setupManager() {
Debug::log(LOG, "RandR done.");
ConfigManager::init();
Values[0] = XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_PROPERTY_CHANGE;
xcb_change_window_attributes_checked(DisplayConnection, Screen->root,
XCB_CW_EVENT_MASK, Values);
xcb_ungrab_key(DisplayConnection, XCB_GRAB_ANY, Screen->root, XCB_MOD_MASK_ANY);
for (auto& keybind : KeybindManager::keybinds) {
xcb_grab_key(DisplayConnection, 1, Screen->root,
KeybindManager::modToMask(keybind.getMod()), KeybindManager::getKeycodeFromKeysym(keybind.getKeysym()),
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
}
xcb_flush(DisplayConnection);
// MOD + mouse
xcb_grab_button(DisplayConnection, 0,
Screen->root, XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE,
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, Screen->root, XCB_NONE,
1, KeybindManager::modToMask(MOD_SUPER));
xcb_grab_button(DisplayConnection, 0,
Screen->root, XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE,
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, Screen->root, XCB_NONE,
3, KeybindManager::modToMask(MOD_SUPER));
xcb_flush(DisplayConnection);
ConfigManager::init();
Debug::log(LOG, "Keys done.");