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