Fix null dereference in Workspace::workspaceEvent()

If Xcb::CurrentInput fails for some reason, the "->" operator will return
null.
This commit is contained in:
Vlad Zahorodnii 2024-08-26 13:17:13 +00:00
parent 636cbbe024
commit 276baa7dd5

View file

@ -283,18 +283,20 @@ bool Workspace::workspaceEvent(xcb_generic_event_t *e)
&& (event->detail == XCB_NOTIFY_DETAIL_NONE || event->detail == XCB_NOTIFY_DETAIL_POINTER_ROOT || event->detail == XCB_NOTIFY_DETAIL_INFERIOR)) { && (event->detail == XCB_NOTIFY_DETAIL_NONE || event->detail == XCB_NOTIFY_DETAIL_POINTER_ROOT || event->detail == XCB_NOTIFY_DETAIL_INFERIOR)) {
Xcb::CurrentInput currentInput; Xcb::CurrentInput currentInput;
kwinApp()->updateXTime(); // focusToNull() uses xTime(), which is old now (FocusIn has no timestamp) kwinApp()->updateXTime(); // focusToNull() uses xTime(), which is old now (FocusIn has no timestamp)
// it seems we can "loose" focus reversions when the closing window hold a grab if (!currentInput.isNull()) {
// => catch the typical pattern (though we don't want the focus on the root anyway) #348935 // it seems we can "loose" focus reversions when the closing window hold a grab
const bool lostFocusPointerToRoot = currentInput->focus == kwinApp()->x11RootWindow() && event->detail == XCB_NOTIFY_DETAIL_INFERIOR; // => catch the typical pattern (though we don't want the focus on the root anyway) #348935
if (!currentInput.isNull() && (currentInput->focus == XCB_WINDOW_NONE || currentInput->focus == XCB_INPUT_FOCUS_POINTER_ROOT || lostFocusPointerToRoot)) { const bool lostFocusPointerToRoot = currentInput->focus == kwinApp()->x11RootWindow() && event->detail == XCB_NOTIFY_DETAIL_INFERIOR;
// kWarning( 1212 ) << "X focus set to None/PointerRoot, reseting focus" ; if (currentInput->focus == XCB_WINDOW_NONE || currentInput->focus == XCB_INPUT_FOCUS_POINTER_ROOT || lostFocusPointerToRoot) {
Window *window = mostRecentlyActivatedWindow(); // kWarning( 1212 ) << "X focus set to None/PointerRoot, reseting focus" ;
if (window != nullptr) { Window *window = mostRecentlyActivatedWindow();
requestFocus(window, true); if (window != nullptr) {
} else if (activateNextWindow(nullptr)) { requestFocus(window, true);
; // ok, activated } else if (activateNextWindow(nullptr)) {
} else { ; // ok, activated
focusToNull(); } else {
focusToNull();
}
} }
} }
} }