2007-11-27 22:40:25 +03:00
|
|
|
/********************************************************************
|
2007-04-29 21:35:43 +04:00
|
|
|
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>
|
|
|
|
|
2007-11-27 22:40:25 +03:00
|
|
|
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/>.
|
|
|
|
*********************************************************************/
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
This file is for (very) small utility functions/classes.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "utils.h"
|
|
|
|
|
2013-07-23 13:57:35 +04:00
|
|
|
#include <QWidget>
|
2013-09-30 12:56:56 +04:00
|
|
|
#include <kkeyserver.h>
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
#ifndef KCMRULES
|
|
|
|
#include <assert.h>
|
2013-09-10 15:18:55 +04:00
|
|
|
#include <QApplication>
|
2013-09-02 15:14:39 +04:00
|
|
|
#include <QDebug>
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
#include <X11/Xlib.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "atoms.h"
|
2017-08-24 17:53:40 +03:00
|
|
|
#include "platform.h"
|
2007-04-29 21:35:43 +04:00
|
|
|
#include "workspace.h"
|
|
|
|
|
2015-12-15 12:22:03 +03:00
|
|
|
#include <signal.h>
|
|
|
|
|
2007-04-29 21:35:43 +04:00
|
|
|
#endif
|
|
|
|
|
2015-07-31 14:29:58 +03:00
|
|
|
Q_LOGGING_CATEGORY(KWIN_CORE, "kwin_core", QtCriticalMsg)
|
2007-04-29 21:35:43 +04:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
#ifndef KCMRULES
|
|
|
|
|
2009-02-17 18:50:00 +03:00
|
|
|
//************************************
|
|
|
|
// StrutRect
|
|
|
|
//************************************
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
StrutRect::StrutRect(QRect rect, StrutArea area)
|
|
|
|
: QRect(rect)
|
|
|
|
, m_area(area)
|
|
|
|
{
|
|
|
|
}
|
2009-02-17 18:50:00 +03:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
StrutRect::StrutRect(const StrutRect& other)
|
|
|
|
: QRect(other)
|
|
|
|
, m_area(other.area())
|
|
|
|
{
|
|
|
|
}
|
2009-02-17 18:50:00 +03:00
|
|
|
|
2013-01-07 11:07:27 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef KCMRULES
|
2007-04-29 21:35:43 +04:00
|
|
|
void updateXTime()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
2017-08-24 17:53:40 +03:00
|
|
|
kwinApp()->platform()->updateXTime();
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
static int server_grab_count = 0;
|
|
|
|
|
|
|
|
void grabXServer()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (++server_grab_count == 1)
|
2013-05-02 11:20:13 +04:00
|
|
|
xcb_grab_server(connection());
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
void ungrabXServer()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
assert(server_grab_count > 0);
|
|
|
|
if (--server_grab_count == 0) {
|
2013-05-02 11:20:13 +04:00
|
|
|
xcb_ungrab_server(connection());
|
|
|
|
xcb_flush(connection());
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
static bool keyboard_grabbed = false;
|
|
|
|
|
2013-05-02 11:13:25 +04:00
|
|
|
bool grabXKeyboard(xcb_window_t w)
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (QWidget::keyboardGrabber() != NULL)
|
2007-04-29 21:35:43 +04:00
|
|
|
return false;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (keyboard_grabbed)
|
2007-04-29 21:35:43 +04:00
|
|
|
return false;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (qApp->activePopupWidget() != NULL)
|
2007-04-29 21:35:43 +04:00
|
|
|
return false;
|
2013-05-02 11:13:25 +04:00
|
|
|
if (w == XCB_WINDOW_NONE)
|
2007-04-29 21:35:43 +04:00
|
|
|
w = rootWindow();
|
2013-05-02 11:13:25 +04:00
|
|
|
const xcb_grab_keyboard_cookie_t c = xcb_grab_keyboard_unchecked(connection(), false, w, xTime(),
|
|
|
|
XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC);
|
|
|
|
ScopedCPointer<xcb_grab_keyboard_reply_t> grab(xcb_grab_keyboard_reply(connection(), c, NULL));
|
|
|
|
if (grab.isNull()) {
|
2007-04-29 21:35:43 +04:00
|
|
|
return false;
|
2013-05-02 11:13:25 +04:00
|
|
|
}
|
|
|
|
if (grab->status != XCB_GRAB_STATUS_SUCCESS) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
keyboard_grabbed = true;
|
|
|
|
return true;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
void ungrabXKeyboard()
|
2011-01-30 17:34:42 +03:00
|
|
|
{
|
|
|
|
if (!keyboard_grabbed) {
|
|
|
|
// grabXKeyboard() may fail sometimes, so don't fail, but at least warn anyway
|
2014-12-05 13:42:15 +03:00
|
|
|
qCDebug(KWIN_CORE) << "ungrabXKeyboard() called but keyboard not grabbed!";
|
2007-04-29 21:35:43 +04:00
|
|
|
}
|
2011-01-30 17:34:42 +03:00
|
|
|
keyboard_grabbed = false;
|
2013-05-02 11:13:25 +04:00
|
|
|
xcb_ungrab_keyboard(connection(), XCB_TIME_CURRENT_TIME);
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2015-12-15 12:22:03 +03:00
|
|
|
Process::Process(QObject *parent)
|
|
|
|
: QProcess(parent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Process::~Process() = default;
|
|
|
|
|
|
|
|
void Process::setupChildProcess()
|
|
|
|
{
|
|
|
|
sigset_t userSiganls;
|
|
|
|
sigemptyset(&userSiganls);
|
|
|
|
sigaddset(&userSiganls, SIGUSR1);
|
|
|
|
sigaddset(&userSiganls, SIGUSR2);
|
|
|
|
pthread_sigmask(SIG_UNBLOCK, &userSiganls, nullptr);
|
|
|
|
}
|
|
|
|
|
2013-09-30 12:56:56 +04:00
|
|
|
#endif
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
// converting between X11 mouse/keyboard state mask and Qt button/keyboard states
|
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
Qt::MouseButton x11ToQtMouseButton(int button)
|
|
|
|
{
|
2013-05-02 11:42:39 +04:00
|
|
|
if (button == XCB_BUTTON_INDEX_1)
|
2007-04-29 21:35:43 +04:00
|
|
|
return Qt::LeftButton;
|
2013-05-02 11:42:39 +04:00
|
|
|
if (button == XCB_BUTTON_INDEX_2)
|
2007-04-29 21:35:43 +04:00
|
|
|
return Qt::MidButton;
|
2013-05-02 11:42:39 +04:00
|
|
|
if (button == XCB_BUTTON_INDEX_3)
|
2007-04-29 21:35:43 +04:00
|
|
|
return Qt::RightButton;
|
2013-05-02 11:42:39 +04:00
|
|
|
if (button == XCB_BUTTON_INDEX_4)
|
2009-02-06 12:45:34 +03:00
|
|
|
return Qt::XButton1;
|
2013-05-02 11:42:39 +04:00
|
|
|
if (button == XCB_BUTTON_INDEX_5)
|
2009-02-06 12:45:34 +03:00
|
|
|
return Qt::XButton2;
|
2007-04-29 21:35:43 +04:00
|
|
|
return Qt::NoButton;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
Qt::MouseButtons x11ToQtMouseButtons(int state)
|
|
|
|
{
|
2007-04-29 21:35:43 +04:00
|
|
|
Qt::MouseButtons ret = 0;
|
2013-05-02 11:42:39 +04:00
|
|
|
if (state & XCB_KEY_BUT_MASK_BUTTON_1)
|
2007-04-29 21:35:43 +04:00
|
|
|
ret |= Qt::LeftButton;
|
2013-05-02 11:42:39 +04:00
|
|
|
if (state & XCB_KEY_BUT_MASK_BUTTON_2)
|
2007-04-29 21:35:43 +04:00
|
|
|
ret |= Qt::MidButton;
|
2013-05-02 11:42:39 +04:00
|
|
|
if (state & XCB_KEY_BUT_MASK_BUTTON_3)
|
2007-04-29 21:35:43 +04:00
|
|
|
ret |= Qt::RightButton;
|
2013-05-02 11:42:39 +04:00
|
|
|
if (state & XCB_KEY_BUT_MASK_BUTTON_4)
|
2009-02-06 12:45:34 +03:00
|
|
|
ret |= Qt::XButton1;
|
2013-05-02 11:42:39 +04:00
|
|
|
if (state & XCB_KEY_BUT_MASK_BUTTON_5)
|
2009-02-06 12:45:34 +03:00
|
|
|
ret |= Qt::XButton2;
|
2007-04-29 21:35:43 +04:00
|
|
|
return ret;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
2011-01-30 17:34:42 +03:00
|
|
|
Qt::KeyboardModifiers x11ToQtKeyboardModifiers(int state)
|
|
|
|
{
|
2007-04-29 21:35:43 +04:00
|
|
|
Qt::KeyboardModifiers ret = 0;
|
2013-05-02 11:42:39 +04:00
|
|
|
if (state & XCB_KEY_BUT_MASK_SHIFT)
|
2007-04-29 21:35:43 +04:00
|
|
|
ret |= Qt::ShiftModifier;
|
2013-05-02 11:42:39 +04:00
|
|
|
if (state & XCB_KEY_BUT_MASK_CONTROL)
|
2007-04-29 21:35:43 +04:00
|
|
|
ret |= Qt::ControlModifier;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (state & KKeyServer::modXAlt())
|
2007-04-29 21:35:43 +04:00
|
|
|
ret |= Qt::AltModifier;
|
2011-01-30 17:34:42 +03:00
|
|
|
if (state & KKeyServer::modXMeta())
|
2007-04-29 21:35:43 +04:00
|
|
|
ret |= Qt::MetaModifier;
|
|
|
|
return ret;
|
2011-01-30 17:34:42 +03:00
|
|
|
}
|
2007-04-29 21:35:43 +04:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#ifndef KCMRULES
|
|
|
|
#endif
|