kwin/events.cpp

1537 lines
61 KiB
C++
Raw Normal View History

/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
/*
This file contains things relevant to handling incoming events.
*/
#include "client.h"
#include "cursor.h"
#include "focuschain.h"
#include "netinfo.h"
#include "workspace.h"
#include "atoms.h"
#ifdef KWIN_BUILD_TABBOX
#include "tabbox.h"
#endif
#include "group.h"
#include "overlaywindow.h"
#include "rules.h"
#include "unmanaged.h"
#include "useractions.h"
#include "effects.h"
#include "screenedge.h"
#include "screens.h"
#include "xcbutils.h"
#include <KDecoration2/Decoration>
#include <QApplication>
#include <QDebug>
2014-12-02 12:50:26 +00:00
#include <QHoverEvent>
#include <QKeyEvent>
#include <QMouseEvent>
#include <QStyleHints>
#include <QWhatsThis>
2014-12-02 12:50:26 +00:00
#include <QWheelEvent>
#include <kkeyserver.h>
#include <xcb/sync.h>
#ifdef XCB_ICCCM_FOUND
#include <xcb/xcb_icccm.h>
#endif
#include "composite.h"
#include "killwindow.h"
#include "x11eventfilter.h"
#include "wayland_server.h"
#include <KWayland/Server/surface_interface.h>
#ifndef XCB_GE_GENERIC
#define XCB_GE_GENERIC 35
typedef struct xcb_ge_generic_event_t {
uint8_t response_type; /**< */
uint8_t extension; /**< */
uint16_t sequence; /**< */
uint32_t length; /**< */
uint16_t event_type; /**< */
uint8_t pad0[22]; /**< */
uint32_t full_sequence; /**< */
} xcb_ge_generic_event_t;
#endif
namespace KWin
{
extern int currentRefreshRate();
2011-01-30 14:34:42 +00:00
// ****************************************
// Workspace
// ****************************************
static xcb_window_t findEventWindow(xcb_generic_event_t *event)
{
const uint8_t eventType = event->response_type & ~0x80;
switch(eventType) {
case XCB_KEY_PRESS:
case XCB_KEY_RELEASE:
return reinterpret_cast<xcb_key_press_event_t*>(event)->event;
case XCB_BUTTON_PRESS:
case XCB_BUTTON_RELEASE:
return reinterpret_cast<xcb_button_press_event_t*>(event)->event;
case XCB_MOTION_NOTIFY:
return reinterpret_cast<xcb_motion_notify_event_t*>(event)->event;
case XCB_ENTER_NOTIFY:
case XCB_LEAVE_NOTIFY:
return reinterpret_cast<xcb_enter_notify_event_t*>(event)->event;
case XCB_FOCUS_IN:
case XCB_FOCUS_OUT:
return reinterpret_cast<xcb_focus_in_event_t*>(event)->event;
case XCB_EXPOSE:
return reinterpret_cast<xcb_expose_event_t*>(event)->window;
case XCB_GRAPHICS_EXPOSURE:
return reinterpret_cast<xcb_graphics_exposure_event_t*>(event)->drawable;
case XCB_NO_EXPOSURE:
return reinterpret_cast<xcb_no_exposure_event_t*>(event)->drawable;
case XCB_VISIBILITY_NOTIFY:
return reinterpret_cast<xcb_visibility_notify_event_t*>(event)->window;
case XCB_CREATE_NOTIFY:
return reinterpret_cast<xcb_create_notify_event_t*>(event)->window;
case XCB_DESTROY_NOTIFY:
return reinterpret_cast<xcb_destroy_notify_event_t*>(event)->window;
case XCB_UNMAP_NOTIFY:
return reinterpret_cast<xcb_unmap_notify_event_t*>(event)->window;
case XCB_MAP_NOTIFY:
return reinterpret_cast<xcb_map_notify_event_t*>(event)->window;
case XCB_MAP_REQUEST:
return reinterpret_cast<xcb_map_request_event_t*>(event)->window;
case XCB_REPARENT_NOTIFY:
return reinterpret_cast<xcb_reparent_notify_event_t*>(event)->window;
case XCB_CONFIGURE_NOTIFY:
return reinterpret_cast<xcb_configure_notify_event_t*>(event)->window;
case XCB_CONFIGURE_REQUEST:
return reinterpret_cast<xcb_configure_request_event_t*>(event)->window;
case XCB_GRAVITY_NOTIFY:
return reinterpret_cast<xcb_gravity_notify_event_t*>(event)->window;
case XCB_RESIZE_REQUEST:
return reinterpret_cast<xcb_resize_request_event_t*>(event)->window;
case XCB_CIRCULATE_NOTIFY:
case XCB_CIRCULATE_REQUEST:
return reinterpret_cast<xcb_circulate_notify_event_t*>(event)->window;
case XCB_PROPERTY_NOTIFY:
return reinterpret_cast<xcb_property_notify_event_t*>(event)->window;
case XCB_COLORMAP_NOTIFY:
return reinterpret_cast<xcb_colormap_notify_event_t*>(event)->window;
case XCB_CLIENT_MESSAGE:
return reinterpret_cast<xcb_client_message_event_t*>(event)->window;
default:
// extension handling
if (eventType == Xcb::Extensions::self()->shapeNotifyEvent()) {
return reinterpret_cast<xcb_shape_notify_event_t*>(event)->affected_window;
}
if (eventType == Xcb::Extensions::self()->damageNotifyEvent()) {
return reinterpret_cast<xcb_damage_notify_event_t*>(event)->drawable;
}
return XCB_WINDOW_NONE;
}
}
QVector<QByteArray> s_xcbEerrors({
QByteArrayLiteral("Success"),
QByteArrayLiteral("BadRequest"),
QByteArrayLiteral("BadValue"),
QByteArrayLiteral("BadWindow"),
QByteArrayLiteral("BadPixmap"),
QByteArrayLiteral("BadAtom"),
QByteArrayLiteral("BadCursor"),
QByteArrayLiteral("BadFont"),
QByteArrayLiteral("BadMatch"),
QByteArrayLiteral("BadDrawable"),
QByteArrayLiteral("BadAccess"),
QByteArrayLiteral("BadAlloc"),
QByteArrayLiteral("BadColor"),
QByteArrayLiteral("BadGC"),
QByteArrayLiteral("BadIDChoice"),
QByteArrayLiteral("BadName"),
QByteArrayLiteral("BadLength"),
QByteArrayLiteral("BadImplementation"),
QByteArrayLiteral("Unknown")});
void Workspace::registerEventFilter(X11EventFilter *filter)
{
if (filter->eventType() == XCB_GE_GENERIC)
m_genericEventFilters.append(filter);
else
m_eventFilters.append(filter);
}
void Workspace::unregisterEventFilter(X11EventFilter *filter)
{
if (filter->eventType() == XCB_GE_GENERIC)
m_genericEventFilters.removeOne(filter);
else
m_eventFilters.removeOne(filter);
}
/*!
Handles workspace specific XCB event
*/
bool Workspace::workspaceEvent(xcb_generic_event_t *e)
2011-01-30 14:34:42 +00:00
{
const uint8_t eventType = e->response_type & ~0x80;
if (!eventType) {
// let's check whether it's an error from one of the extensions KWin uses
xcb_generic_error_t *error = reinterpret_cast<xcb_generic_error_t*>(e);
const QVector<Xcb::ExtensionData> extensions = Xcb::Extensions::self()->extensions();
for (const auto &extension : extensions) {
if (error->major_code == extension.majorOpcode) {
QByteArray errorName;
if (error->error_code < s_xcbEerrors.size()) {
errorName = s_xcbEerrors.at(error->error_code);
} else if (error->error_code >= extension.errorBase) {
const int index = error->error_code - extension.errorBase;
if (index >= 0 && index < extension.errorCodes.size()) {
errorName = extension.errorCodes.at(index);
}
}
if (errorName.isEmpty()) {
errorName = QByteArrayLiteral("Unknown");
}
qCWarning(KWIN_CORE, "XCB error: %d (%s), sequence: %d, resource id: %d, major code: %d (%s), minor code: %d (%s)",
int(error->error_code), errorName.constData(),
int(error->sequence), int(error->resource_id),
int(error->major_code), extension.name.constData(),
int(error->minor_code),
extension.opCodes.size() > error->minor_code ? extension.opCodes.at(error->minor_code).constData() : "Unknown");
return true;
}
}
return false;
}
if (eventType == XCB_GE_GENERIC) {
xcb_ge_generic_event_t *ge = reinterpret_cast<xcb_ge_generic_event_t *>(e);
foreach (X11EventFilter *filter, m_genericEventFilters) {
if (filter->extension() == ge->extension && filter->genericEventTypes().contains(ge->event_type) && filter->event(e)) {
return true;
}
}
} else {
foreach (X11EventFilter *filter, m_eventFilters) {
if (filter->eventType() == eventType && filter->event(e)) {
return true;
}
}
}
2011-01-30 14:34:42 +00:00
if (effects && static_cast< EffectsHandlerImpl* >(effects)->hasKeyboardGrab()
&& (eventType == XCB_KEY_PRESS || eventType == XCB_KEY_RELEASE))
return false; // let Qt process it, it'll be intercepted again in eventFilter()
if (!m_windowKiller.isNull() && m_windowKiller->isActive() && m_windowKiller->isResponsibleForEvent(eventType)) {
m_windowKiller->processEvent(e);
// filter out the event
return true;
}
if (eventType == XCB_PROPERTY_NOTIFY || eventType == XCB_CLIENT_MESSAGE) {
NET::Properties dirtyProtocols;
NET::Properties2 dirtyProtocols2;
rootInfo()->event(e, &dirtyProtocols, &dirtyProtocols2);
if (dirtyProtocols & NET::DesktopNames)
VirtualDesktopManager::self()->save();
if (dirtyProtocols2 & NET::WM2DesktopLayout)
VirtualDesktopManager::self()->updateLayout();
2011-01-30 14:34:42 +00:00
}
// events that should be handled before Clients can get them
switch (eventType) {
case XCB_BUTTON_PRESS:
case XCB_BUTTON_RELEASE: {
2011-01-30 14:34:42 +00:00
was_user_interaction = true;
auto *mouseEvent = reinterpret_cast<xcb_button_press_event_t*>(e);
#ifdef KWIN_BUILD_TABBOX
if (TabBox::TabBox::self()->isGrabbed()) {
return TabBox::TabBox::self()->handleMouseEvent(mouseEvent);
}
#endif
if (effects && static_cast<EffectsHandlerImpl*>(effects)->checkInputWindowEvent(mouseEvent)) {
return true;
}
break;
}
case XCB_MOTION_NOTIFY: {
auto *mouseEvent = reinterpret_cast<xcb_motion_notify_event_t*>(e);
const QPoint rootPos(mouseEvent->root_x, mouseEvent->root_y);
#ifdef KWIN_BUILD_TABBOX
if (TabBox::TabBox::self()->isGrabbed()) {
ScreenEdges::self()->check(rootPos, QDateTime::fromMSecsSinceEpoch(xTime()), true);
return TabBox::TabBox::self()->handleMouseEvent(mouseEvent);
}
#endif
if (effects && static_cast<EffectsHandlerImpl*>(effects)->checkInputWindowEvent(mouseEvent)) {
2011-01-30 14:34:42 +00:00
return true;
}
if (QWidget::mouseGrabber()) {
ScreenEdges::self()->check(rootPos, QDateTime::fromMSecsSinceEpoch(xTime()), true);
} else {
ScreenEdges::self()->check(rootPos, QDateTime::fromMSecsSinceEpoch(mouseEvent->time));
}
2011-01-30 14:34:42 +00:00
break;
}
case XCB_KEY_PRESS: {
2011-01-30 14:34:42 +00:00
was_user_interaction = true;
int keyQt;
xcb_key_press_event_t *event = reinterpret_cast<xcb_key_press_event_t*>(e);
KKeyServer::xcbKeyPressEventToQt(event, &keyQt);
2013-11-01 11:29:05 +00:00
// qDebug() << "Workspace::keyPress( " << keyQt << " )";
if (Client *c = dynamic_cast<Client*>(movingClient)) {
c->keyPressEvent(keyQt, event->time);
return true;
}
#ifdef KWIN_BUILD_TABBOX
if (TabBox::TabBox::self()->isGrabbed()) {
TabBox::TabBox::self()->keyPress(keyQt);
return true;
}
#endif
2011-01-30 14:34:42 +00:00
break;
}
case XCB_KEY_RELEASE:
2011-01-30 14:34:42 +00:00
was_user_interaction = true;
#ifdef KWIN_BUILD_TABBOX
if (TabBox::TabBox::self()->isGrabbed()) {
TabBox::TabBox::self()->keyRelease(reinterpret_cast<xcb_key_release_event_t*>(e));
return true;
}
#endif
2011-01-30 14:34:42 +00:00
break;
2013-07-26 08:10:49 +00:00
case XCB_CONFIGURE_NOTIFY:
if (reinterpret_cast<xcb_configure_notify_event_t*>(e)->event == rootWindow())
2011-01-30 14:34:42 +00:00
x_stacking_dirty = true;
break;
};
const xcb_window_t eventWindow = findEventWindow(e);
if (eventWindow != XCB_WINDOW_NONE) {
if (Client* c = findClient(Predicate::WindowMatch, eventWindow)) {
if (c->windowEvent(e))
return true;
} else if (Client* c = findClient(Predicate::WrapperIdMatch, eventWindow)) {
if (c->windowEvent(e))
return true;
} else if (Client* c = findClient(Predicate::FrameIdMatch, eventWindow)) {
if (c->windowEvent(e))
return true;
} else if (Client *c = findClient(Predicate::InputIdMatch, eventWindow)) {
if (c->windowEvent(e))
return true;
} else if (Unmanaged* c = findUnmanaged(eventWindow)) {
if (c->windowEvent(e))
return true;
} else {
// We want to pass root window property events to effects
if (eventType == XCB_PROPERTY_NOTIFY) {
auto *event = reinterpret_cast<xcb_property_notify_event_t*>(e);
if (event->window == rootWindow()) {
emit propertyNotify(event->atom);
}
}
}
2011-01-30 14:34:42 +00:00
}
if (Client *c = dynamic_cast<Client*>(movingClient)) {
if (eventType == XCB_BUTTON_PRESS || eventType == XCB_BUTTON_RELEASE || eventType == XCB_MOTION_NOTIFY) {
if (c->moveResizeGrabWindow() == reinterpret_cast<xcb_button_press_event_t*>(e)->event && c->windowEvent(e)) {
return true;
}
}
2011-01-30 14:34:42 +00:00
}
switch (eventType) {
case XCB_CREATE_NOTIFY: {
const auto *event = reinterpret_cast<xcb_create_notify_event_t*>(e);
if (event->parent == rootWindow() &&
!QWidget::find(event->window) &&
!event->override_redirect) {
2011-01-30 14:34:42 +00:00
// see comments for allowClientActivation()
updateXTime();
const xcb_timestamp_t t = xTime();
xcb_change_property(connection(), XCB_PROP_MODE_REPLACE, event->window, atoms->kde_net_wm_user_creation_time, XCB_ATOM_CARDINAL, 32, 1, &t);
2011-01-30 14:34:42 +00:00
}
break;
}
case XCB_UNMAP_NOTIFY: {
const auto *event = reinterpret_cast<xcb_unmap_notify_event_t*>(e);
return (event->event != event->window); // hide wm typical event from Qt
2011-01-30 14:34:42 +00:00
}
case XCB_REPARENT_NOTIFY: {
//do not confuse Qt with these events. After all, _we_ are the
//window manager who does the reparenting.
2011-01-30 14:34:42 +00:00
return true;
}
case XCB_DESTROY_NOTIFY: {
2011-01-30 14:34:42 +00:00
return false;
}
case XCB_MAP_REQUEST: {
2011-01-30 14:34:42 +00:00
updateXTime();
const auto *event = reinterpret_cast<xcb_map_request_event_t*>(e);
if (Client* c = findClient(Predicate::WindowMatch, event->window)) {
// e->xmaprequest.window is different from e->xany.window
// TODO this shouldn't be necessary now
2011-01-30 14:34:42 +00:00
c->windowEvent(e);
FocusChain::self()->update(c, FocusChain::Update);
} else if ( true /*|| e->xmaprequest.parent != root */ ) {
// NOTICE don't check for the parent being the root window, this breaks when some app unmaps
// a window, changes something and immediately maps it back, without giving KWin
// a chance to reparent it back to root
// since KWin can get MapRequest only for root window children and
// children of WindowWrapper (=clients), the check is AFAIK useless anyway
// NOTICE: The save-set support in Client::mapRequestEvent() actually requires that
// this code doesn't check the parent to be root.
if (!createClient(event->window, false)) {
xcb_map_window(connection(), event->window);
const uint32_t values[] = { XCB_STACK_MODE_ABOVE };
xcb_configure_window(connection(), event->window, XCB_CONFIG_WINDOW_STACK_MODE, values);
}
2011-01-30 14:34:42 +00:00
}
return true;
2011-01-30 14:34:42 +00:00
}
case XCB_MAP_NOTIFY: {
const auto *event = reinterpret_cast<xcb_map_notify_event_t*>(e);
if (event->override_redirect) {
Unmanaged* c = findUnmanaged(event->window);
2011-01-30 14:34:42 +00:00
if (c == NULL)
c = createUnmanaged(event->window);
2011-01-30 14:34:42 +00:00
if (c)
return c->windowEvent(e);
}
return (event->event != event->window); // hide wm typical event from Qt
2011-01-30 14:34:42 +00:00
}
case XCB_ENTER_NOTIFY: {
2011-01-30 14:34:42 +00:00
if (QWhatsThis::inWhatsThisMode()) {
QWidget* w = QWidget::find(reinterpret_cast<xcb_enter_notify_event_t*>(e)->event);
2011-01-30 14:34:42 +00:00
if (w)
QWhatsThis::leaveWhatsThisMode();
2011-01-30 14:34:42 +00:00
}
if (ScreenEdges::self()->isEntered(reinterpret_cast<xcb_enter_notify_event_t*>(e)))
2011-01-30 14:34:42 +00:00
return true;
break;
}
case XCB_LEAVE_NOTIFY: {
2011-01-30 14:34:42 +00:00
if (!QWhatsThis::inWhatsThisMode())
break;
2011-01-30 14:34:42 +00:00
// TODO is this cliente ever found, given that client events are searched above?
const auto *event = reinterpret_cast<xcb_leave_notify_event_t*>(e);
Client* c = findClient(Predicate::FrameIdMatch, event->event);
if (c && event->detail != XCB_NOTIFY_DETAIL_INFERIOR)
2011-01-30 14:34:42 +00:00
QWhatsThis::leaveWhatsThisMode();
break;
}
case XCB_CONFIGURE_REQUEST: {
const auto *event = reinterpret_cast<xcb_configure_request_event_t*>(e);
if (event->parent == rootWindow()) {
uint32_t values[5] = { 0, 0, 0, 0, 0};
const uint32_t value_mask = event->value_mask
& (XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT | XCB_CONFIG_WINDOW_BORDER_WIDTH);
int i = 0;
if (value_mask & XCB_CONFIG_WINDOW_X) {
values[i++] = event->x;
}
if (value_mask & XCB_CONFIG_WINDOW_Y) {
values[i++] = event->y;
}
if (value_mask & XCB_CONFIG_WINDOW_WIDTH) {
values[i++] = event->width;
}
if (value_mask & XCB_CONFIG_WINDOW_HEIGHT) {
values[i++] = event->height;
}
if (value_mask & XCB_CONFIG_WINDOW_BORDER_WIDTH) {
values[i++] = event->border_width;
}
xcb_configure_window(connection(), event->window, value_mask, values);
2011-01-30 14:34:42 +00:00
return true;
}
break;
}
case XCB_FOCUS_IN: {
const auto *event = reinterpret_cast<xcb_focus_in_event_t*>(e);
if (event->event == rootWindow()
&& (event->detail == XCB_NOTIFY_DETAIL_NONE || event->detail == XCB_NOTIFY_DETAIL_POINTER_ROOT || event->detail == XCB_NOTIFY_DETAIL_INFERIOR)) {
Xcb::CurrentInput currentInput;
2011-01-30 14:34:42 +00:00
updateXTime(); // focusToNull() uses xTime(), which is old now (FocusIn has no timestamp)
// it seems we can "loose" focus reversions when the closing client hold a grab
// => catch the typical pattern (though we don't want the focus on the root anyway) #348935
const bool lostFocusPointerToRoot = currentInput->focus == rootWindow() && event->detail == XCB_NOTIFY_DETAIL_INFERIOR;
if (!currentInput.isNull() && (currentInput->focus == XCB_WINDOW_NONE || currentInput->focus == XCB_INPUT_FOCUS_POINTER_ROOT || lostFocusPointerToRoot)) {
2011-01-30 14:34:42 +00:00
//kWarning( 1212 ) << "X focus set to None/PointerRoot, reseting focus" ;
AbstractClient *c = mostRecentlyActivatedClient();
2011-01-30 14:34:42 +00:00
if (c != NULL)
requestFocus(c, true);
else if (activateNextClient(NULL))
; // ok, activated
else
focusToNull();
}
2011-01-30 14:34:42 +00:00
}
}
2011-01-30 14:34:42 +00:00
// fall through
case XCB_FOCUS_OUT:
2011-01-30 14:34:42 +00:00
return true; // always eat these, they would tell Qt that KWin is the active app
2013-07-26 09:41:44 +00:00
case XCB_CLIENT_MESSAGE:
if (ScreenEdges::self()->isEntered(reinterpret_cast<xcb_client_message_event_t*>(e)))
2011-01-30 14:34:42 +00:00
return true;
break;
2013-07-26 09:44:00 +00:00
case XCB_EXPOSE: {
const auto *event = reinterpret_cast<xcb_expose_event_t*>(e);
2011-01-30 14:34:42 +00:00
if (compositing()
2013-07-26 09:44:00 +00:00
&& (event->window == rootWindow() // root window needs repainting
|| (m_compositor->overlayWindow() != XCB_WINDOW_NONE && event->window == m_compositor->overlayWindow()))) { // overlay needs repainting
m_compositor->addRepaint(event->x, event->y, event->width, event->height);
2011-01-30 14:34:42 +00:00
}
break;
2013-07-26 09:44:00 +00:00
}
case XCB_VISIBILITY_NOTIFY: {
const auto *event = reinterpret_cast<xcb_visibility_notify_event_t*>(e);
if (compositing() && m_compositor->overlayWindow() != XCB_WINDOW_NONE && event->window == m_compositor->overlayWindow()) {
bool was_visible = m_compositor->isOverlayWindowVisible();
m_compositor->setOverlayWindowVisibility((event->state != XCB_VISIBILITY_FULLY_OBSCURED));
if (!was_visible && m_compositor->isOverlayWindowVisible()) {
2011-01-30 14:34:42 +00:00
// hack for #154825
m_compositor->addRepaintFull();
QTimer::singleShot(2000, m_compositor, SLOT(addRepaintFull()));
}
m_compositor->scheduleRepaint();
2011-01-30 14:34:42 +00:00
}
break;
}
2011-01-30 14:34:42 +00:00
default:
if (eventType == Xcb::Extensions::self()->randrNotifyEvent() && Xcb::Extensions::self()->isRandrAvailable()) {
auto *event = reinterpret_cast<xcb_randr_screen_change_notify_event_t*>(e);
xcb_screen_t *screen = defaultScreen();
if (event->rotation & (XCB_RANDR_ROTATION_ROTATE_90 | XCB_RANDR_ROTATION_ROTATE_270)) {
screen->width_in_pixels = event->height;
screen->height_in_pixels = event->width;
screen->width_in_millimeters = event->mheight;
screen->height_in_millimeters = event->mwidth;
} else {
screen->width_in_pixels = event->width;
screen->height_in_pixels = event->height;
screen->width_in_millimeters = event->mwidth;
screen->height_in_millimeters = event->mheight;
}
if (compositing()) {
2011-01-30 14:34:42 +00:00
// desktopResized() should take care of when the size or
// shape of the desktop has changed, but we also want to
// catch refresh rate changes
if (m_compositor->xrrRefreshRate() != currentRefreshRate())
m_compositor->setCompositeResetTimer(0);
2011-01-30 14:34:42 +00:00
}
} else if (eventType == Xcb::Extensions::self()->syncAlarmNotifyEvent() && Xcb::Extensions::self()->isSyncAvailable()) {
for (Client *c : clients)
c->syncEvent(reinterpret_cast< xcb_sync_alarm_notify_event_t* >(e));
for (Client *c : desktops)
c->syncEvent(reinterpret_cast< xcb_sync_alarm_notify_event_t* >(e));
} else if (eventType == Xcb::Extensions::self()->fixesCursorNotifyEvent() && Xcb::Extensions::self()->isFixesAvailable()) {
Cursor::self()->notifyCursorChanged(reinterpret_cast<xcb_xfixes_cursor_notify_event_t*>(e)->cursor_serial);
}
2011-01-30 14:34:42 +00:00
break;
}
2011-01-30 14:34:42 +00:00
return false;
}
// Used only to filter events that need to be processed by Qt first
// (e.g. keyboard input to be composed), otherwise events are
// handle by the XEvent filter above
2011-01-30 14:34:42 +00:00
bool Workspace::workspaceEvent(QEvent* e)
{
if ((e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease || e->type() == QEvent::ShortcutOverride)
&& effects && static_cast< EffectsHandlerImpl* >(effects)->hasKeyboardGrab()) {
static_cast< EffectsHandlerImpl* >(effects)->grabbedKeyboardEvent(static_cast< QKeyEvent* >(e));
return true;
}
2011-01-30 14:34:42 +00:00
return false;
}
// ****************************************
// Client
// ****************************************
/*!
General handler for XEvents concerning the client window
*/
bool Client::windowEvent(xcb_generic_event_t *e)
2011-01-30 14:34:42 +00:00
{
if (findEventWindow(e) == window()) { // avoid doing stuff on frame or wrapper
NET::Properties dirtyProperties;
NET::Properties2 dirtyProperties2;
double old_opacity = opacity();
info->event(e, &dirtyProperties, &dirtyProperties2); // pass through the NET stuff
if ((dirtyProperties & NET::WMName) != 0)
fetchName();
if ((dirtyProperties & NET::WMIconName) != 0)
fetchIconicName();
if ((dirtyProperties & NET::WMStrut) != 0
|| (dirtyProperties2 & NET::WM2ExtendedStrut) != 0) {
workspace()->updateClientArea();
2011-01-30 14:34:42 +00:00
}
if ((dirtyProperties & NET::WMIcon) != 0)
getIcons();
// Note there's a difference between userTime() and info->userTime()
// info->userTime() is the value of the property, userTime() also includes
// updates of the time done by KWin (ButtonPress on windowrapper etc.).
if ((dirtyProperties2 & NET::WM2UserTime) != 0) {
workspace()->setWasUserInteraction();
2011-01-30 14:34:42 +00:00
updateUserTime(info->userTime());
}
if ((dirtyProperties2 & NET::WM2StartupId) != 0)
startupIdChanged();
if (dirtyProperties2 & NET::WM2Opacity) {
2011-01-30 14:34:42 +00:00
if (compositing()) {
addRepaintFull();
2011-03-06 09:30:23 +00:00
emit opacityChanged(this, old_opacity);
2011-01-30 14:34:42 +00:00
} else {
// forward to the frame if there's possibly another compositing manager running
NETWinInfo i(connection(), frameId(), rootWindow(), 0, 0);
2011-01-30 14:34:42 +00:00
i.setOpacity(info->opacity());
}
2011-01-30 14:34:42 +00:00
}
if (dirtyProperties2 & NET::WM2FrameOverlap) {
// ### Inform the decoration
}
if (dirtyProperties2.testFlag(NET::WM2WindowRole)) {
emit windowRoleChanged();
}
if (dirtyProperties2.testFlag(NET::WM2WindowClass)) {
getResourceClass();
}
if (dirtyProperties2.testFlag(NET::WM2BlockCompositing)) {
setBlockingCompositing(info->isBlockingCompositing());
}
if (dirtyProperties2.testFlag(NET::WM2GroupLeader)) {
checkGroup();
updateAllowedActions(); // Group affects isMinimizable()
}
if (dirtyProperties2.testFlag(NET::WM2Urgency)) {
updateUrgency();
}
if (dirtyProperties2 & NET::WM2OpaqueRegion) {
getWmOpaqueRegion();
}
2011-01-30 14:34:42 +00:00
}
const uint8_t eventType = e->response_type & ~0x80;
switch(eventType) {
case XCB_UNMAP_NOTIFY:
unmapNotifyEvent(reinterpret_cast<xcb_unmap_notify_event_t*>(e));
2011-01-30 14:34:42 +00:00
break;
case XCB_DESTROY_NOTIFY:
destroyNotifyEvent(reinterpret_cast<xcb_destroy_notify_event_t*>(e));
2011-01-30 14:34:42 +00:00
break;
case XCB_MAP_REQUEST:
2011-01-30 14:34:42 +00:00
// this one may pass the event to workspace
return mapRequestEvent(reinterpret_cast<xcb_map_request_event_t*>(e));
case XCB_CONFIGURE_REQUEST:
configureRequestEvent(reinterpret_cast<xcb_configure_request_event_t*>(e));
2011-01-30 14:34:42 +00:00
break;
case XCB_PROPERTY_NOTIFY:
propertyNotifyEvent(reinterpret_cast<xcb_property_notify_event_t*>(e));
2011-01-30 14:34:42 +00:00
break;
case XCB_KEY_PRESS:
updateUserTime(reinterpret_cast<xcb_key_press_event_t*>(e)->time);
2011-01-30 14:34:42 +00:00
workspace()->setWasUserInteraction();
break;
case XCB_BUTTON_PRESS: {
const auto *event = reinterpret_cast<xcb_button_press_event_t*>(e);
updateUserTime(event->time);
2011-01-30 14:34:42 +00:00
workspace()->setWasUserInteraction();
buttonPressEvent(event->event, event->detail, event->state,
event->event_x, event->event_y, event->root_x, event->root_y, event->time);
2011-01-30 14:34:42 +00:00
break;
}
case XCB_KEY_RELEASE:
2011-01-30 14:34:42 +00:00
// don't update user time on releases
// e.g. if the user presses Alt+F2, the Alt release
// would appear as user input to the currently active window
break;
case XCB_BUTTON_RELEASE: {
const auto *event = reinterpret_cast<xcb_button_release_event_t*>(e);
2011-01-30 14:34:42 +00:00
// don't update user time on releases
// e.g. if the user presses Alt+F2, the Alt release
// would appear as user input to the currently active window
buttonReleaseEvent(event->event, event->detail, event->state,
event->event_x, event->event_y, event->root_x, event->root_y);
2011-01-30 14:34:42 +00:00
break;
}
case XCB_MOTION_NOTIFY: {
const auto *event = reinterpret_cast<xcb_motion_notify_event_t*>(e);
motionNotifyEvent(event->event, event->state,
event->event_x, event->event_y, event->root_x, event->root_y);
workspace()->updateFocusMousePosition(QPoint(event->root_x, event->root_y));
2011-01-30 14:34:42 +00:00
break;
}
case XCB_ENTER_NOTIFY: {
auto *event = reinterpret_cast<xcb_enter_notify_event_t*>(e);
enterNotifyEvent(event);
2011-01-30 14:34:42 +00:00
// MotionNotify is guaranteed to be generated only if the mouse
// move start and ends in the window; for cases when it only
// starts or only ends there, Enter/LeaveNotify are generated.
// Fake a MotionEvent in such cases to make handle of mouse
// events simpler (Qt does that too).
motionNotifyEvent(event->event, event->state,
event->event_x, event->event_y, event->root_x, event->root_y);
workspace()->updateFocusMousePosition(QPoint(event->root_x, event->root_y));
2011-01-30 14:34:42 +00:00
break;
}
case XCB_LEAVE_NOTIFY: {
auto *event = reinterpret_cast<xcb_leave_notify_event_t*>(e);
motionNotifyEvent(event->event, event->state,
event->event_x, event->event_y, event->root_x, event->root_y);
leaveNotifyEvent(event);
2011-01-30 14:34:42 +00:00
// not here, it'd break following enter notify handling
// workspace()->updateFocusMousePosition( QPoint( e->xcrossing.x_root, e->xcrossing.y_root ));
break;
}
case XCB_FOCUS_IN:
focusInEvent(reinterpret_cast<xcb_focus_in_event_t*>(e));
2011-01-30 14:34:42 +00:00
break;
case XCB_FOCUS_OUT:
focusOutEvent(reinterpret_cast<xcb_focus_out_event_t*>(e));
2011-01-30 14:34:42 +00:00
break;
case XCB_REPARENT_NOTIFY:
2011-01-30 14:34:42 +00:00
break;
case XCB_CLIENT_MESSAGE:
clientMessageEvent(reinterpret_cast<xcb_client_message_event_t*>(e));
2011-01-30 14:34:42 +00:00
break;
case XCB_EXPOSE: {
xcb_expose_event_t *event = reinterpret_cast<xcb_expose_event_t*>(e);
if (event->window == frameId() && !Compositor::self()->isActive()) {
// TODO: only repaint required areas
triggerDecorationRepaint();
}
break;
}
2011-01-30 14:34:42 +00:00
default:
if (eventType == Xcb::Extensions::self()->shapeNotifyEvent() && reinterpret_cast<xcb_shape_notify_event_t*>(e)->affected_window == window()) {
detectShape(window()); // workaround for #19644
updateShape();
}
if (eventType == Xcb::Extensions::self()->damageNotifyEvent() && reinterpret_cast<xcb_damage_notify_event_t*>(e)->drawable == frameId())
damageNotifyEvent();
2011-01-30 14:34:42 +00:00
break;
}
2011-01-30 14:34:42 +00:00
return true; // eat all events
}
/*!
Handles map requests of the client window
*/
bool Client::mapRequestEvent(xcb_map_request_event_t *e)
2011-01-30 14:34:42 +00:00
{
if (e->window != window()) {
// Special support for the save-set feature, which is a bit broken.
// If there's a window from one client embedded in another one,
// e.g. using XEMBED, and the embedder suddenly loses its X connection,
// save-set will reparent the embedded window to its closest ancestor
// that will remains. Unfortunately, with reparenting window managers,
// this is not the root window, but the frame (or in KWin's case,
// it's the wrapper for the client window). In this case,
// the wrapper will get ReparentNotify for a window it won't know,
// which will be ignored, and then it gets MapRequest, as save-set
// always maps. Returning true here means that Workspace::workspaceEvent()
// will handle this MapRequest and manage this window (i.e. act as if
// it was reparented to root window).
2011-01-30 14:34:42 +00:00
if (e->parent == wrapperId())
return false;
return true; // no messing with frame etc.
2011-01-30 14:34:42 +00:00
}
// also copied in clientMessage()
2011-01-30 14:34:42 +00:00
if (isMinimized())
unminimize();
2011-01-30 14:34:42 +00:00
if (isShade())
setShade(ShadeNone);
if (!isOnCurrentDesktop()) {
if (workspace()->allowClientActivation(this))
workspace()->activateClient(this);
else
demandAttention();
}
2011-01-30 14:34:42 +00:00
return true;
}
/*!
Handles unmap notify events of the client window
*/
void Client::unmapNotifyEvent(xcb_unmap_notify_event_t *e)
2011-01-30 14:34:42 +00:00
{
if (e->window != window())
return;
2011-01-30 14:34:42 +00:00
if (e->event != wrapperId()) {
// most probably event from root window when initially reparenting
bool ignore = true;
if (e->event == rootWindow() && (e->response_type & 0x80))
ignore = false; // XWithdrawWindow()
2011-01-30 14:34:42 +00:00
if (ignore)
return;
}
// check whether this is result of an XReparentWindow - client then won't be parented by wrapper
// in this case do not release the client (causes reparent to root, removal from saveSet and what not)
// but just destroy the client
Xcb::Tree tree(m_client);
xcb_window_t daddy = tree.parent();
if (daddy == m_wrapper) {
releaseWindow(); // unmapped from a regular client state
} else {
destroyClient(); // the client was moved to some other parent
}
2011-01-30 14:34:42 +00:00
}
void Client::destroyNotifyEvent(xcb_destroy_notify_event_t *e)
2011-01-30 14:34:42 +00:00
{
if (e->window != window())
return;
destroyClient();
2011-01-30 14:34:42 +00:00
}
/*!
Handles client messages for the client window
*/
void Client::clientMessageEvent(xcb_client_message_event_t *e)
2011-01-30 14:34:42 +00:00
{
Toplevel::clientMessageEvent(e);
2011-01-30 14:34:42 +00:00
if (e->window != window())
return; // ignore frame/wrapper
// WM_STATE
if (e->type == atoms->wm_change_state) {
if (e->data.data32[0] == XCB_ICCCM_WM_STATE_ICONIC)
minimize();
return;
}
2011-01-30 14:34:42 +00:00
}
/*!
Handles configure requests of the client window
*/
void Client::configureRequestEvent(xcb_configure_request_event_t *e)
2011-01-30 14:34:42 +00:00
{
if (e->window != window())
return; // ignore frame/wrapper
2011-01-30 14:34:42 +00:00
if (isResize() || isMove())
return; // we have better things to do right now
2011-01-30 14:34:42 +00:00
if (fullscreen_mode == FullScreenNormal) { // refuse resizing of fullscreen windows
// but allow resizing fullscreen hacks in order to let them cancel fullscreen mode
sendSyntheticConfigureNotify();
return;
2011-01-30 14:34:42 +00:00
}
if (isSplash()) { // no manipulations with splashscreens either
sendSyntheticConfigureNotify();
return;
2011-01-30 14:34:42 +00:00
}
if (e->value_mask & XCB_CONFIG_WINDOW_BORDER_WIDTH) {
// first, get rid of a window border
m_client.setBorderWidth(0);
2011-01-30 14:34:42 +00:00
}
if (e->value_mask & (XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_HEIGHT | XCB_CONFIG_WINDOW_WIDTH))
2011-01-30 14:34:42 +00:00
configureRequest(e->value_mask, e->x, e->y, e->width, e->height, 0, false);
if (e->value_mask & XCB_CONFIG_WINDOW_STACK_MODE)
restackWindow(e->sibling, e->stack_mode, NET::FromApplication, userTime(), false);
// Sending a synthetic configure notify always is fine, even in cases where
// the ICCCM doesn't require this - it can be though of as 'the WM decided to move
// the window later'. The client should not cause that many configure request,
// so this should not have any significant impact. With user moving/resizing
// the it should be optimized though (see also Client::setGeometry()/plainResize()/move()).
sendSyntheticConfigureNotify();
// SELI TODO accept configure requests for isDesktop windows (because kdesktop
// may get XRANDR resize event before kwin), but check it's still at the bottom?
2011-01-30 14:34:42 +00:00
}
/*!
Handles property changes of the client window
*/
void Client::propertyNotifyEvent(xcb_property_notify_event_t *e)
2011-01-30 14:34:42 +00:00
{
Toplevel::propertyNotifyEvent(e);
if (e->window != window())
return; // ignore frame/wrapper
2011-01-30 14:34:42 +00:00
switch(e->atom) {
case XCB_ATOM_WM_NORMAL_HINTS:
2011-01-30 14:34:42 +00:00
getWmNormalHints();
break;
case XCB_ATOM_WM_NAME:
2011-01-30 14:34:42 +00:00
fetchName();
break;
case XCB_ATOM_WM_ICON_NAME:
2011-01-30 14:34:42 +00:00
fetchIconicName();
break;
case XCB_ATOM_WM_TRANSIENT_FOR:
2011-01-30 14:34:42 +00:00
readTransient();
break;
case XCB_ATOM_WM_HINTS:
2011-01-30 14:34:42 +00:00
getIcons(); // because KWin::icon() uses WMHints as fallback
break;
default:
if (e->atom == atoms->motif_wm_hints) {
2011-01-30 14:34:42 +00:00
getMotifHints();
} else if (e->atom == atoms->net_wm_sync_request_counter)
2011-01-30 14:34:42 +00:00
getSyncCounter();
else if (e->atom == atoms->activities)
checkActivities();
else if (e->atom == atoms->kde_first_in_window_list)
updateFirstInTabBox();
else if (e->atom == atoms->kde_color_sheme)
updateColorScheme();
Screenedge show support for Clients This provides a new protocol intended to be used by auto-hiding panels to make use of the centralized screen edges. To use it a Client can set an X11 property of type _KDE_NET_WM_SCREEN_EDGE_SHOW to KWin. As value it takes: * 0: top edge * 1: right edge * 2: bottom edge * 3: left edge KWin will hide the Client (hide because unmap or minimize would break it) and create an Edge. If that Edge gets triggered the Client is shown again and the property gets deleted. If the Client doesn't border the specified screen edge the Client gets shown immediately so that we never end in a situation that we cannot unhide the auto-hidden panel again. The exact process is described in the documentation of ScreenEdges. The Client can request to be shown again by deleting the property. If KWin gets restarted the state is read from the property and it is tried to create the edge as described. As this is a KWin specific extension we need to discuss what it means for Clients using this feature with other WMs: it does nothing. As the Client gets hidden by KWin and not by the Client, it just doesn't get hidden if the WM doesn't provide the feature. In case of an auto-hiding panel this seems like a good solution given that we don't want to hide it if we cannot unhide it. Of course there's the option for the Client to provide that feature itself and if that's wanted we would need to announce the feature in the _NET_SUPPORTED atom. At the moment that doesn't sound like being needed as Plasma doesn't want to provide an own implementation. The implementation comes with a small test application showing how the feature is intended to be used. REVIEW: 115910
2014-02-20 11:39:23 +00:00
else if (e->atom == atoms->kde_screen_edge_show)
updateShowOnScreenEdge();
Add a script to enforce window decorations for GTK windows This is going to be a controversal change. It enforces KWin decorations on all client side decorated windows from GTK+. Unfortunately we are caught between a rock and a hard place. Keeping the status quo means having broken windows and a more or less broken window manager due to GTK+ including the shadow in the windows. This is no solution. Enforcing server side decorations visually breaks the windows. This is also no solution. So why do it? It's our task to provide the best possible user experience and KWin is a window manager which has always done great efforts to fix misbehaving windows. One can think of the focus stealing prevention, the window rules and lately the scripts. The best possible window management experience is our aim. This means we cannot leave the users with the broken windows from GTK. The issues we noticed were reported to GTK+ about 2 months ago and we are working on improving the situation. Unfortunately several issues are not yet addressed and others will only be addressed in the next GTK+ release. We are working on improving the NETWM spec (see [1]) to ensure that the client side decorated windows are not in a broken state. This means the enforcment is a temporary solution and will be re-evaluated with the next GTK release. I would prefer to not have to do such a change, if some of the bugs were fixed or GTK+ would not use client-side-decos on wms not yet supporting those all of this would be a no issue. For a complete list of the problems caused by GTK's decos see bug [2] and the linked bug reports from there. The change is done in a least inversive way in KWin. We just check for the property _GTK_FRAME_EXTENTS and create a Q_PROPERTY in Client for it. If we add support for the frame extents in future we would also need this. So it's not a change just for enforcing the decoration. The actual enforcing is done through a KWin script so users can still disable it. REVIEW: 119062 [1] https://mail.gnome.org/archives/wm-spec-list/2014-June/msg00002.html [2] https://bugzilla.gnome.org/show_bug.cgi?id=729721
2014-07-01 13:44:02 +00:00
else if (e->atom == atoms->gtk_frame_extents)
detectGtkFrameExtents();
2011-01-30 14:34:42 +00:00
break;
}
2011-01-30 14:34:42 +00:00
}
void Client::enterNotifyEvent(xcb_enter_notify_event_t *e)
2011-01-30 14:34:42 +00:00
{
if (e->event != frameId())
return; // care only about entering the whole frame
#define MOUSE_DRIVEN_FOCUS (!options->focusPolicyIsReasonable() || \
(options->focusPolicy() == Options::FocusFollowsMouse && options->isNextFocusPrefersMouse()))
if (e->mode == XCB_NOTIFY_MODE_NORMAL || (e->mode == XCB_NOTIFY_MODE_UNGRAB && MOUSE_DRIVEN_FOCUS)) {
if (options->isShadeHover()) {
cancelShadeHoverTimer();
2011-01-30 14:34:42 +00:00
if (isShade()) {
shadeHoverTimer = new QTimer(this);
connect(shadeHoverTimer, SIGNAL(timeout()), this, SLOT(shadeHover()));
shadeHoverTimer->setSingleShot(true);
shadeHoverTimer->start(options->shadeHoverInterval());
}
2011-01-30 14:34:42 +00:00
}
#undef MOUSE_DRIVEN_FOCUS
enterEvent(QPoint(e->root_x, e->root_y));
2011-01-30 14:34:42 +00:00
return;
}
2011-01-30 14:34:42 +00:00
}
void Client::leaveNotifyEvent(xcb_leave_notify_event_t *e)
2011-01-30 14:34:42 +00:00
{
if (e->event != frameId())
return; // care only about leaving the whole frame
if (e->mode == XCB_NOTIFY_MODE_NORMAL) {
if (!isMoveResizePointerButtonDown()) {
setMoveResizePointerMode(PositionCenter);
updateCursor();
2011-01-30 14:34:42 +00:00
}
bool lostMouse = !rect().contains(QPoint(e->event_x, e->event_y));
// 'lostMouse' wouldn't work with e.g. B2 or Keramik, which have non-rectangular decorations
// (i.e. the LeaveNotify event comes before leaving the rect and no LeaveNotify event
// comes after leaving the rect) - so lets check if the pointer is really outside the window
// TODO this still sucks if a window appears above this one - it should lose the mouse
// if this window is another client, but not if it's a popup ... maybe after KDE3.1 :(
// (repeat after me 'AARGHL!')
if (!lostMouse && e->detail != XCB_NOTIFY_DETAIL_INFERIOR) {
Xcb::Pointer pointer(frameId());
if (!pointer || !pointer->same_screen || pointer->child == XCB_WINDOW_NONE) {
// really lost the mouse
lostMouse = true;
}
2011-01-30 14:34:42 +00:00
}
if (lostMouse) {
leaveEvent();
cancelShadeHoverTimer();
if (shade_mode == ShadeHover && !isMoveResize() && !isMoveResizePointerButtonDown()) {
2011-01-30 14:34:42 +00:00
shadeHoverTimer = new QTimer(this);
connect(shadeHoverTimer, SIGNAL(timeout()), this, SLOT(shadeUnhover()));
shadeHoverTimer->setSingleShot(true);
shadeHoverTimer->start(options->shadeHoverInterval());
}
if (isDecorated()) {
// sending a move instead of a leave. With leave we need to send proper coords, with move it's handled internally
QHoverEvent leaveEvent(QEvent::HoverMove, QPointF(-1, -1), QPointF(-1, -1), Qt::NoModifier);
QCoreApplication::sendEvent(decoration(), &leaveEvent);
}
}
if (options->focusPolicy() == Options::FocusStrictlyUnderMouse && isActive() && lostMouse) {
workspace()->requestDelayFocus(0);
}
2011-01-30 14:34:42 +00:00
return;
}
2011-01-30 14:34:42 +00:00
}
#define XCapL KKeyServer::modXLock()
#define XNumL KKeyServer::modXNumLock()
#define XScrL KKeyServer::modXScrollLock()
2011-01-30 14:34:42 +00:00
void Client::grabButton(int modifier)
{
unsigned int mods[ 8 ] = {
0, XCapL, XNumL, XNumL | XCapL,
XScrL, XScrL | XCapL,
XScrL | XNumL, XScrL | XNumL | XCapL
2011-01-30 14:34:42 +00:00
};
for (int i = 0;
i < 8;
++i)
m_wrapper.grabButton(XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC, modifier | mods[ i ]);
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
void Client::ungrabButton(int modifier)
{
unsigned int mods[ 8 ] = {
0, XCapL, XNumL, XNumL | XCapL,
XScrL, XScrL | XCapL,
XScrL | XNumL, XScrL | XNumL | XCapL
2011-01-30 14:34:42 +00:00
};
for (int i = 0;
i < 8;
++i)
m_wrapper.ungrabButton(modifier | mods[ i ]);
2011-01-30 14:34:42 +00:00
}
#undef XCapL
#undef XNumL
#undef XScrL
/*
Releases the passive grab for some modifier combinations when a
window becomes active. This helps broken X programs that
missinterpret LeaveNotify events in grab mode to work properly
(Motif, AWT, Tk, ...)
*/
void Client::updateMouseGrab()
2011-01-30 14:34:42 +00:00
{
if (workspace()->globalShortcutsDisabled()) {
m_wrapper.ungrabButton();
// keep grab for the simple click without modifiers if needed (see below)
bool not_obscured = workspace()->topClientOnDesktop(VirtualDesktopManager::self()->current(), -1, true, false) == this;
if (!(!options->isClickRaise() || not_obscured))
grabButton(XCB_NONE);
return;
2011-01-30 14:34:42 +00:00
}
if (isActive() && !TabBox::TabBox::self()->forcedGlobalMouseGrab()) { // see TabBox::establishTabBoxGrab()
// first grab all modifier combinations
m_wrapper.grabButton(XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC);
// remove the grab for no modifiers only if the window
// is unobscured or if the user doesn't want click raise
// (it is unobscured if it the topmost in the unconstrained stacking order, i.e. it is
// the most recently raised window)
bool not_obscured = workspace()->topClientOnDesktop(VirtualDesktopManager::self()->current(), -1, true, false) == this;
if (!options->isClickRaise() || not_obscured)
ungrabButton(XCB_NONE);
else
grabButton(XCB_NONE);
ungrabButton(XCB_MOD_MASK_SHIFT);
ungrabButton(XCB_MOD_MASK_CONTROL);
ungrabButton(XCB_MOD_MASK_CONTROL | XCB_MOD_MASK_SHIFT);
2011-01-30 14:34:42 +00:00
} else {
m_wrapper.ungrabButton();
// simply grab all modifier combinations
m_wrapper.grabButton(XCB_GRAB_MODE_SYNC, XCB_GRAB_MODE_ASYNC);
}
2011-01-30 14:34:42 +00:00
}
static bool modKeyDown(int state) {
const uint keyModX = (options->keyCmdAllModKey() == Qt::Key_Meta) ?
KKeyServer::modXMeta() : KKeyServer::modXAlt();
return keyModX && (state & KKeyServer::accelModMaskX()) == keyModX;
}
// return value matters only when filtering events before decoration gets them
bool Client::buttonPressEvent(xcb_window_t w, int button, int state, int x, int y, int x_root, int y_root, xcb_timestamp_t time)
2011-01-30 14:34:42 +00:00
{
if (isMoveResizePointerButtonDown()) {
2011-01-30 14:34:42 +00:00
if (w == wrapperId())
xcb_allow_events(connection(), XCB_ALLOW_SYNC_POINTER, XCB_TIME_CURRENT_TIME); //xTime());
return true;
2011-01-30 14:34:42 +00:00
}
if (w == wrapperId() || w == frameId() || w == inputId()) {
2011-01-30 14:34:42 +00:00
// FRAME neco s tohohle by se melo zpracovat, nez to dostane dekorace
updateUserTime(time);
workspace()->setWasUserInteraction();
const bool bModKeyHeld = modKeyDown(state);
2011-01-30 14:34:42 +00:00
if (isSplash()
&& button == XCB_BUTTON_INDEX_1 && !bModKeyHeld) {
2011-01-30 14:34:42 +00:00
// hide splashwindow if the user clicks on it
hideClient(true);
if (w == wrapperId())
xcb_allow_events(connection(), XCB_ALLOW_SYNC_POINTER, XCB_TIME_CURRENT_TIME); //xTime());
return true;
2011-01-30 14:34:42 +00:00
}
Options::MouseCommand com = Options::MouseNothing;
bool was_action = false;
2011-01-30 14:34:42 +00:00
if (bModKeyHeld) {
was_action = true;
2011-01-30 14:34:42 +00:00
switch(button) {
case XCB_BUTTON_INDEX_1:
2011-01-30 14:34:42 +00:00
com = options->commandAll1();
break;
case XCB_BUTTON_INDEX_2:
2011-01-30 14:34:42 +00:00
com = options->commandAll2();
break;
case XCB_BUTTON_INDEX_3:
2011-01-30 14:34:42 +00:00
com = options->commandAll3();
break;
case XCB_BUTTON_INDEX_4:
case XCB_BUTTON_INDEX_5:
com = options->operationWindowMouseWheel(button == XCB_BUTTON_INDEX_4 ? 120 : -120);
2011-01-30 14:34:42 +00:00
break;
}
} else {
if (w == wrapperId()) {
if (button < 4) {
com = getMouseCommand(x11ToQtMouseButton(button), &was_action);
} else if (button < 6) {
com = getWheelCommand(Qt::Vertical, &was_action);
}
}
2011-01-30 14:34:42 +00:00
}
if (was_action) {
bool replay = performMouseCommand(com, QPoint(x_root, y_root));
2011-01-30 14:34:42 +00:00
if (isSpecialWindow())
replay = true;
2011-01-30 14:34:42 +00:00
if (w == wrapperId()) // these can come only from a grab
xcb_allow_events(connection(), replay ? XCB_ALLOW_REPLAY_POINTER : XCB_ALLOW_SYNC_POINTER, XCB_TIME_CURRENT_TIME); //xTime());
return true;
}
2011-01-30 14:34:42 +00:00
}
2011-01-30 14:34:42 +00:00
if (w == wrapperId()) { // these can come only from a grab
xcb_allow_events(connection(), XCB_ALLOW_REPLAY_POINTER, XCB_TIME_CURRENT_TIME); //xTime());
return true;
2011-01-30 14:34:42 +00:00
}
if (w == inputId()) {
x = x_root - geometry().x();
y = y_root - geometry().y();
// New API processes core events FIRST and only passes unused ones to the decoration
QMouseEvent ev(QMouseEvent::MouseButtonPress, QPoint(x, y), QPoint(x_root, y_root),
x11ToQtMouseButton(button), x11ToQtMouseButtons(state), Qt::KeyboardModifiers());
return processDecorationButtonPress(&ev, true);
}
if (w == frameId() && isDecorated()) {
if (button >= 4 && button <= 7) {
const Qt::KeyboardModifiers modifiers = x11ToQtKeyboardModifiers(state);
// Logic borrowed from qapplication_x11.cpp
const int delta = 120 * ((button == 4 || button == 6) ? 1 : -1);
const bool hor = (((button == 4 || button == 5) && (modifiers & Qt::AltModifier))
|| (button == 6 || button == 7));
const QPoint angle = hor ? QPoint(delta, 0) : QPoint(0, delta);
QWheelEvent event(QPointF(x, y),
QPointF(x_root, y_root),
QPoint(),
angle,
delta,
hor ? Qt::Horizontal : Qt::Vertical,
x11ToQtMouseButtons(state),
modifiers);
event.setAccepted(false);
QCoreApplication::sendEvent(decoration(), &event);
if (!event.isAccepted() && !hor) {
if (titlebarPositionUnderMouse()) {
performMouseCommand(options->operationTitlebarMouseWheel(delta), QPoint(x_root, y_root));
}
}
} else {
QMouseEvent event(QEvent::MouseButtonPress, QPointF(x, y), QPointF(x_root, y_root),
x11ToQtMouseButton(button), x11ToQtMouseButtons(state), x11ToQtKeyboardModifiers(state));
event.setAccepted(false);
QCoreApplication::sendEvent(decoration(), &event);
if (!event.isAccepted()) {
processDecorationButtonPress(&event);
}
}
return true;
}
2011-01-30 14:34:42 +00:00
return true;
}
// return value matters only when filtering events before decoration gets them
bool Client::buttonReleaseEvent(xcb_window_t w, int button, int state, int x, int y, int x_root, int y_root)
2011-01-30 14:34:42 +00:00
{
if (w == frameId() && isDecorated()) {
// wheel handled on buttonPress
if (button < 4 || button > 7) {
QMouseEvent event(QEvent::MouseButtonRelease,
QPointF(x, y),
QPointF(x_root, y_root),
x11ToQtMouseButton(button),
x11ToQtMouseButtons(state) & ~x11ToQtMouseButton(button),
x11ToQtKeyboardModifiers(state));
event.setAccepted(false);
QCoreApplication::sendEvent(decoration(), &event);
if (event.isAccepted() || !titlebarPositionUnderMouse()) {
invalidateDecorationDoubleClickTimer(); // click was for the deco and shall not init a doubleclick
}
}
}
2011-01-30 14:34:42 +00:00
if (w == wrapperId()) {
xcb_allow_events(connection(), XCB_ALLOW_SYNC_POINTER, XCB_TIME_CURRENT_TIME); //xTime());
return true;
2011-01-30 14:34:42 +00:00
}
if (w != frameId() && w != inputId() && w != moveResizeGrabWindow())
return true;
if (w == frameId() && workspace()->userActionsMenu() && workspace()->userActionsMenu()->isShown()) {
const_cast<UserActionsMenu*>(workspace()->userActionsMenu())->grabInput();
}
x = this->x(); // translate from grab window to local coords
y = this->y();
// Check whether other buttons are still left pressed
int buttonMask = XCB_BUTTON_MASK_1 | XCB_BUTTON_MASK_2 | XCB_BUTTON_MASK_3;
if (button == XCB_BUTTON_INDEX_1)
buttonMask &= ~XCB_BUTTON_MASK_1;
else if (button == XCB_BUTTON_INDEX_2)
buttonMask &= ~XCB_BUTTON_MASK_2;
else if (button == XCB_BUTTON_INDEX_3)
buttonMask &= ~XCB_BUTTON_MASK_3;
if ((state & buttonMask) == 0) {
endMoveResize();
}
2011-01-30 14:34:42 +00:00
return true;
}
// return value matters only when filtering events before decoration gets them
bool Client::motionNotifyEvent(xcb_window_t w, int state, int x, int y, int x_root, int y_root)
2011-01-30 14:34:42 +00:00
{
if (w == frameId() && isDecorated() && !isMinimized()) {
// TODO Mouse move event dependent on state
QHoverEvent event(QEvent::HoverMove, QPointF(x, y), QPointF(x, y));
QCoreApplication::instance()->sendEvent(decoration(), &event);
}
if (w != frameId() && w != inputId() && w != moveResizeGrabWindow())
return true; // care only about the whole frame
if (!isMoveResizePointerButtonDown()) {
if (w == inputId()) {
int x = x_root - geometry().x();// + padding_left;
int y = y_root - geometry().y();// + padding_top;
if (isDecorated()) {
QHoverEvent event(QEvent::HoverMove, QPointF(x, y), QPointF(x, y));
QCoreApplication::instance()->sendEvent(decoration(), &event);
}
}
Position newmode = modKeyDown(state) ? PositionCenter : mousePosition();
if (newmode != moveResizePointerMode()) {
setMoveResizePointerMode(newmode);
updateCursor();
2011-01-30 14:34:42 +00:00
}
return false;
2011-01-30 14:34:42 +00:00
}
if (w == moveResizeGrabWindow()) {
x = this->x(); // translate from grab window to local coords
y = this->y();
}
handleMoveResize(QPoint(x, y), QPoint(x_root, y_root));
2011-01-30 14:34:42 +00:00
return true;
}
void Client::focusInEvent(xcb_focus_in_event_t *e)
2011-01-30 14:34:42 +00:00
{
if (e->event != window())
return; // only window gets focus
if (e->mode == XCB_NOTIFY_MODE_UNGRAB)
return; // we don't care
if (e->detail == XCB_NOTIFY_DETAIL_POINTER)
return; // we don't care
2011-01-30 14:34:42 +00:00
if (!isShown(false) || !isOnCurrentDesktop()) // we unmapped it, but it got focus meanwhile ->
return; // activateNextClient() already transferred focus elsewhere
workspace()->forEachClient([](Client *client) {
client->cancelFocusOutTimer();
});
// check if this client is in should_get_focus list or if activation is allowed
2011-01-30 14:34:42 +00:00
bool activate = workspace()->allowClientActivation(this, -1U, true);
workspace()->gotFocusIn(this); // remove from should_get_focus list
if (activate)
setActive(true);
else {
workspace()->restoreFocus();
demandAttention();
}
2011-01-30 14:34:42 +00:00
}
void Client::focusOutEvent(xcb_focus_out_event_t *e)
2011-01-30 14:34:42 +00:00
{
if (e->event != window())
return; // only window gets focus
if (e->mode == XCB_NOTIFY_MODE_GRAB)
return; // we don't care
2011-01-30 14:34:42 +00:00
if (isShade())
return; // here neither
if (e->detail != XCB_NOTIFY_DETAIL_NONLINEAR
&& e->detail != XCB_NOTIFY_DETAIL_NONLINEAR_VIRTUAL)
// SELI check all this
return; // hack for motif apps like netscape
2011-01-30 14:34:42 +00:00
if (QApplication::activePopupWidget())
return;
// When a client loses focus, FocusOut events are usually immediatelly
// followed by FocusIn events for another client that gains the focus
// (unless the focus goes to another screen, or to the nofocus widget).
// Without this check, the former focused client would have to be
// deactivated, and after that, the new one would be activated, with
// a short time when there would be no active client. This can cause
// flicker sometimes, e.g. when a fullscreen is shown, and focus is transferred
// from it to its transient, the fullscreen would be kept in the Active layer
// at the beginning and at the end, but not in the middle, when the active
// client would be temporarily none (see Client::belongToLayer() ).
// Therefore the setActive(false) call is moved to the end of the current
// event queue. If there is a matching FocusIn event in the current queue
// this will be processed before the setActive(false) call and the activation
// of the Client which gained FocusIn will automatically deactivate the
// previously active client.
if (!m_focusOutTimer) {
m_focusOutTimer = new QTimer(this);
m_focusOutTimer->setSingleShot(true);
m_focusOutTimer->setInterval(0);
connect(m_focusOutTimer, &QTimer::timeout, [this]() {
setActive(false);
});
}
m_focusOutTimer->start();
2011-01-30 14:34:42 +00:00
}
// performs _NET_WM_MOVERESIZE
2011-01-30 14:34:42 +00:00
void Client::NETMoveResize(int x_root, int y_root, NET::Direction direction)
{
if (direction == NET::Move) {
// move cursor to the provided position to prevent the window jumping there on first movement
// the expectation is that the cursor is already at the provided position,
// thus it's more a safety measurement
Cursor::setPos(QPoint(x_root, y_root));
2011-01-30 14:34:42 +00:00
performMouseCommand(Options::MouseMove, QPoint(x_root, y_root));
} else if (isMoveResize() && direction == NET::MoveResizeCancel) {
2011-01-30 14:34:42 +00:00
finishMoveResize(true);
setMoveResizePointerButtonDown(false);
updateCursor();
2011-01-30 14:34:42 +00:00
} else if (direction >= NET::TopLeft && direction <= NET::Left) {
static const Position convert[] = {
PositionTopLeft,
PositionTop,
PositionTopRight,
PositionRight,
PositionBottomRight,
PositionBottom,
PositionBottomLeft,
PositionLeft
2011-01-30 14:34:42 +00:00
};
if (!isResizable() || isShade())
return;
if (isMoveResize())
2011-01-30 14:34:42 +00:00
finishMoveResize(false);
setMoveResizePointerButtonDown(true);
setMoveOffset(QPoint(x_root - x(), y_root - y())); // map from global
setInvertedMoveOffset(rect().bottomRight() - moveOffset());
setUnrestrictedMoveResize(false);
setMoveResizePointerMode(convert[ direction ]);
2011-01-30 14:34:42 +00:00
if (!startMoveResize())
setMoveResizePointerButtonDown(false);
updateCursor();
2011-01-30 14:34:42 +00:00
} else if (direction == NET::KeyboardMove) {
// ignore mouse coordinates given in the message, mouse position is used by the moving algorithm
Cursor::setPos(geometry().center());
2011-01-30 14:34:42 +00:00
performMouseCommand(Options::MouseUnrestrictedMove, geometry().center());
} else if (direction == NET::KeyboardSize) {
// ignore mouse coordinates given in the message, mouse position is used by the resizing algorithm
Cursor::setPos(geometry().bottomRight());
2011-01-30 14:34:42 +00:00
performMouseCommand(Options::MouseUnrestrictedResize, geometry().bottomRight());
}
2011-01-30 14:34:42 +00:00
}
void Client::keyPressEvent(uint key_code, xcb_timestamp_t time)
2011-01-30 14:34:42 +00:00
{
updateUserTime(time);
AbstractClient::keyPressEvent(key_code);
2011-01-30 14:34:42 +00:00
}
void Client::syncEvent(xcb_sync_alarm_notify_event_t* e)
2011-01-30 14:34:42 +00:00
{
2013-07-31 08:11:39 +00:00
if (e->alarm == syncRequest.alarm && e->counter_value.hi == syncRequest.value.hi && e->counter_value.lo == syncRequest.value.lo) {
setReadyForPainting();
setupWindowManagementInterface();
syncRequest.isPending = false;
if (syncRequest.failsafeTimeout)
syncRequest.failsafeTimeout->stop();
2011-01-30 14:34:42 +00:00
if (isResize()) {
if (syncRequest.timeout)
syncRequest.timeout->stop();
performMoveResize();
} else // setReadyForPainting does as well, but there's a small chance for resize syncs after the resize ended
addRepaintFull();
}
2011-01-30 14:34:42 +00:00
}
// ****************************************
// Unmanaged
// ****************************************
bool Unmanaged::windowEvent(xcb_generic_event_t *e)
2011-01-30 14:34:42 +00:00
{
double old_opacity = opacity();
NET::Properties dirtyProperties;
NET::Properties2 dirtyProperties2;
info->event(e, &dirtyProperties, &dirtyProperties2); // pass through the NET stuff
if (dirtyProperties2 & NET::WM2Opacity) {
2011-01-30 14:34:42 +00:00
if (compositing()) {
addRepaintFull();
2011-03-06 09:30:23 +00:00
emit opacityChanged(this, old_opacity);
2011-01-30 14:34:42 +00:00
}
}
if (dirtyProperties2 & NET::WM2OpaqueRegion) {
getWmOpaqueRegion();
}
if (dirtyProperties2.testFlag(NET::WM2WindowRole)) {
emit windowRoleChanged();
}
if (dirtyProperties2.testFlag(NET::WM2WindowClass)) {
getResourceClass();
}
const uint8_t eventType = e->response_type & ~0x80;
switch (eventType) {
case XCB_DESTROY_NOTIFY:
release(ReleaseReason::Destroyed);
break;
case XCB_UNMAP_NOTIFY:{
workspace()->updateFocusMousePosition(Cursor::pos()); // may cause leave event
// unmap notify might have been emitted due to a destroy notify
// but unmap notify gets emitted before the destroy notify, nevertheless at this
// point the window is already destroyed. This means any XCB request with the window
// will cause an error.
// To not run into these errors we try to wait for the destroy notify. For this we
// generate a round trip to the X server and wait a very short time span before
// handling the release.
updateXTime();
// using 1 msec to not just move it at the end of the event loop but add an very short
// timespan to cover cases like unmap() followed by destroy(). The only other way to
// ensure that the window is not destroyed when we do the release handling is to grab
// the XServer which we do not want to do for an Unmanaged. The timespan of 1 msec is
// short enough to not cause problems in the close window animations.
// It's of course still possible that we miss the destroy in which case non-fatal
// X errors are reported to the event loop and logged by Qt.
QTimer::singleShot(1, this, SLOT(release()));
2011-01-30 14:34:42 +00:00
break;
}
case XCB_CONFIGURE_NOTIFY:
configureNotifyEvent(reinterpret_cast<xcb_configure_notify_event_t*>(e));
2011-01-30 14:34:42 +00:00
break;
case XCB_PROPERTY_NOTIFY:
propertyNotifyEvent(reinterpret_cast<xcb_property_notify_event_t*>(e));
2011-01-30 14:34:42 +00:00
break;
case XCB_CLIENT_MESSAGE:
clientMessageEvent(reinterpret_cast<xcb_client_message_event_t*>(e));
break;
2011-01-30 14:34:42 +00:00
default: {
if (eventType == Xcb::Extensions::self()->shapeNotifyEvent()) {
2011-01-30 14:34:42 +00:00
detectShape(window());
addRepaintFull();
addWorkspaceRepaint(geometry()); // in case shape change removes part of this window
emit geometryShapeChanged(this, geometry());
}
if (eventType == Xcb::Extensions::self()->damageNotifyEvent())
damageNotifyEvent();
2011-01-30 14:34:42 +00:00
break;
}
}
2011-01-30 14:34:42 +00:00
return false; // don't eat events, even our own unmanaged widgets are tracked
}
void Unmanaged::configureNotifyEvent(xcb_configure_notify_event_t *e)
2011-01-30 14:34:42 +00:00
{
if (effects)
static_cast<EffectsHandlerImpl*>(effects)->checkInputWindowStacking(); // keep them on top
2011-01-30 14:34:42 +00:00
QRect newgeom(e->x, e->y, e->width, e->height);
if (newgeom != geom) {
addWorkspaceRepaint(visibleRect()); // damage old area
QRect old = geom;
geom = newgeom;
emit geometryChanged(); // update shadow region
addRepaintFull();
2011-01-30 14:34:42 +00:00
if (old.size() != geom.size())
discardWindowPixmap();
emit geometryShapeChanged(this, old);
}
2011-01-30 14:34:42 +00:00
}
// ****************************************
// Toplevel
// ****************************************
void Toplevel::propertyNotifyEvent(xcb_property_notify_event_t *e)
2011-01-30 14:34:42 +00:00
{
if (e->window != window())
return; // ignore frame/wrapper
2011-01-30 14:34:42 +00:00
switch(e->atom) {
default:
if (e->atom == atoms->wm_client_leader)
getWmClientLeader();
else if (e->atom == atoms->kde_net_wm_shadow)
getShadow();
else if (e->atom == atoms->kde_skip_close_animation)
getSkipCloseAnimation();
2011-01-30 14:34:42 +00:00
break;
}
2011-03-12 18:18:19 +00:00
emit propertyNotify(this, e->atom);
2011-01-30 14:34:42 +00:00
}
void Toplevel::clientMessageEvent(xcb_client_message_event_t *e)
{
if (e->type == atoms->wl_surface_id) {
m_surfaceId = e->data.data32[0];
if (auto w = waylandServer()) {
if (auto s = KWayland::Server::SurfaceInterface::get(m_surfaceId, w->xWaylandConnection())) {
setSurface(s);
}
}
emit surfaceIdChanged(m_surfaceId);
}
}
} // namespace