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) 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
|
|
|
|
|
|
|
#include "bridge.h"
|
|
|
|
|
|
|
|
#include "client.h"
|
|
|
|
#include "options.h"
|
|
|
|
|
2008-11-25 09:10:52 +00:00
|
|
|
#include <kconfiggroup.h>
|
2011-08-21 19:50:23 +00:00
|
|
|
#include "composite.h"
|
2013-04-26 09:52:15 +00:00
|
|
|
#include "workspace.h"
|
2008-11-25 09:10:52 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
Bridge::Bridge(Client* cl)
|
|
|
|
: c(cl)
|
|
|
|
{
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#define BRIDGE_HELPER( rettype, prototype, args1, args2, cst ) \
|
2011-01-30 14:34:42 +00:00
|
|
|
rettype Bridge::prototype ( args1 ) cst \
|
2007-04-29 17:35:43 +00:00
|
|
|
{ \
|
2011-01-30 14:34:42 +00:00
|
|
|
return c->prototype( args2 ); \
|
|
|
|
}
|
|
|
|
|
|
|
|
BRIDGE_HELPER(bool, isCloseable, , , const)
|
|
|
|
BRIDGE_HELPER(bool, isMaximizable, , , const)
|
|
|
|
BRIDGE_HELPER(Bridge::MaximizeMode, maximizeMode, , , const)
|
2013-02-17 00:56:01 +00:00
|
|
|
BRIDGE_HELPER(Bridge::QuickTileMode, quickTileMode, , , const)
|
2011-01-30 14:34:42 +00:00
|
|
|
BRIDGE_HELPER(bool, isMinimizable, , , const)
|
|
|
|
BRIDGE_HELPER(bool, providesContextHelp, , , const)
|
|
|
|
BRIDGE_HELPER(int, desktop, , , const)
|
|
|
|
BRIDGE_HELPER(bool, isModal, , , const)
|
|
|
|
BRIDGE_HELPER(bool, isShadeable, , , const)
|
|
|
|
BRIDGE_HELPER(bool, isShade, , , const)
|
|
|
|
BRIDGE_HELPER(bool, keepAbove, , , const)
|
|
|
|
BRIDGE_HELPER(bool, keepBelow, , , const)
|
|
|
|
BRIDGE_HELPER(bool, isMovable, , , const)
|
|
|
|
BRIDGE_HELPER(bool, isResizable, , , const)
|
|
|
|
BRIDGE_HELPER(void, processMousePressEvent, QMouseEvent* e, e,)
|
|
|
|
BRIDGE_HELPER(QRect, geometry, , , const)
|
|
|
|
BRIDGE_HELPER(void, closeWindow, , ,)
|
|
|
|
BRIDGE_HELPER(void, maximize, MaximizeMode m, m,)
|
|
|
|
BRIDGE_HELPER(void, minimize, , ,)
|
|
|
|
BRIDGE_HELPER(void, showContextHelp, , ,)
|
|
|
|
BRIDGE_HELPER(void, setDesktop, int desktop, desktop,)
|
|
|
|
|
2012-01-12 06:42:55 +00:00
|
|
|
bool Bridge::isActive() const
|
|
|
|
{
|
|
|
|
return c->isActive() || (c->tabGroup() && c->tabGroup()->isActive());
|
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Bridge::setKeepAbove(bool set)
|
|
|
|
{
|
|
|
|
if (c->keepAbove() != set)
|
|
|
|
c->workspace()->performWindowOperation(c, KeepAboveOp);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Bridge::setKeepBelow(bool set)
|
|
|
|
{
|
|
|
|
if (c->keepBelow() != set)
|
|
|
|
c->workspace()->performWindowOperation(c, KeepBelowOp);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
NET::WindowType Bridge::windowType(unsigned long supported_types) const
|
|
|
|
{
|
|
|
|
return c->windowType(false, supported_types);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
QIcon Bridge::icon() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
QIcon ret(c->icon());
|
|
|
|
ret.addPixmap(c->miniIcon());
|
2007-11-01 17:03:05 +00:00
|
|
|
return ret;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
bool Bridge::isSetShade() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return c->shadeMode() != ShadeNone;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Bridge::showWindowMenu(const QPoint &p)
|
|
|
|
{
|
2012-01-12 06:42:55 +00:00
|
|
|
c->workspace()->showWindowMenu(QRect(p,p), c);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Bridge::showWindowMenu(const QPoint &p, long id)
|
|
|
|
{
|
|
|
|
Client *cc = clientForId(id);
|
|
|
|
if (!cc)
|
|
|
|
cc = c;
|
|
|
|
cc->workspace()->showWindowMenu(QRect(p,p), cc);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Bridge::showWindowMenu(const QRect &p)
|
|
|
|
{
|
|
|
|
c->workspace()->showWindowMenu(p, c);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2012-11-09 12:44:50 +00:00
|
|
|
void Bridge::showApplicationMenu(const QPoint &p)
|
|
|
|
{
|
|
|
|
#ifdef KWIN_BUILD_KAPPMENU
|
|
|
|
c->showApplicationMenu(p);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Bridge::menuAvailable() const
|
|
|
|
{
|
|
|
|
#ifdef KWIN_BUILD_KAPPMENU
|
|
|
|
return c->menuAvailable();
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Bridge::performWindowOperation(WindowOperation op)
|
|
|
|
{
|
|
|
|
c->workspace()->performWindowOperation(c, op);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Bridge::setMask(const QRegion& r, int mode)
|
|
|
|
{
|
|
|
|
c->setMask(r, mode);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
bool Bridge::isPreview() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
QRect Bridge::iconGeometry() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
NETRect r = c->info->iconGeometry();
|
2011-01-30 14:34:42 +00:00
|
|
|
return QRect(r.pos.x, r.pos.y, r.size.width, r.size.height);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
WId Bridge::windowId() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return c->window();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void Bridge::titlebarDblClickOperation()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
c->workspace()->performWindowOperation(c, options->operationTitlebarDblClick());
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Bridge::titlebarMouseWheelOperation(int delta)
|
|
|
|
{
|
|
|
|
c->performMouseCommand(options->operationTitlebarMouseWheel(delta), cursorPos());
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Bridge::setShade(bool set)
|
|
|
|
{
|
|
|
|
c->setShade(set ? ShadeNormal : ShadeNone);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
int Bridge::currentDesktop() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-11-16 07:23:47 +00:00
|
|
|
return VirtualDesktopManager::self()->current();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
QWidget* Bridge::initialParentWidget() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return NULL;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
Qt::WFlags Bridge::initialWFlags() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return 0;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
QRegion Bridge::unobscuredRegion(const QRegion& r) const
|
|
|
|
{
|
|
|
|
QRegion reg(r);
|
2012-04-08 08:07:35 +00:00
|
|
|
const ToplevelList stacking_order = c->workspace()->stackingOrder();
|
2011-01-30 14:34:42 +00:00
|
|
|
int pos = stacking_order.indexOf(c);
|
2007-04-29 17:35:43 +00:00
|
|
|
++pos;
|
2011-01-30 14:34:42 +00:00
|
|
|
for (; pos < stacking_order.count(); ++pos) {
|
2012-04-08 08:07:35 +00:00
|
|
|
Client *client = qobject_cast<Client*>(stacking_order[pos]);
|
|
|
|
if (!client) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!client->isShown(true))
|
2007-04-29 17:35:43 +00:00
|
|
|
continue; // these don't obscure the window
|
2011-01-30 14:34:42 +00:00
|
|
|
if (c->isOnAllDesktops()) {
|
2012-04-08 08:07:35 +00:00
|
|
|
if (!client->isOnCurrentDesktop())
|
2007-04-29 17:35:43 +00:00
|
|
|
continue;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2012-04-08 08:07:35 +00:00
|
|
|
if (!client->isOnDesktop(c->desktop()))
|
2007-04-29 17:35:43 +00:00
|
|
|
continue;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
/* the clients all have their mask-regions in local coords
|
2008-09-24 10:28:49 +00:00
|
|
|
so we have to translate them to a shared coord system
|
|
|
|
we choose ours */
|
2012-04-08 08:07:35 +00:00
|
|
|
int dx = client->x() - c->x();
|
|
|
|
int dy = client->y() - c->y();
|
|
|
|
QRegion creg = client->mask();
|
2008-09-24 10:28:49 +00:00
|
|
|
creg.translate(dx, dy);
|
|
|
|
reg -= creg;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (reg.isEmpty()) {
|
2008-09-24 10:28:49 +00:00
|
|
|
// early out, we are completely obscured
|
|
|
|
break;
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
return reg;
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void Bridge::grabXServer(bool grab)
|
|
|
|
{
|
|
|
|
if (grab)
|
2007-04-29 17:35:43 +00:00
|
|
|
KWin::grabXServer();
|
|
|
|
else
|
|
|
|
KWin::ungrabXServer();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2008-10-17 10:30:43 +00:00
|
|
|
bool Bridge::compositingActive() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-08-28 17:31:17 +00:00
|
|
|
return Compositor::compositing();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2008-10-17 10:30:43 +00:00
|
|
|
|
2009-11-25 23:32:35 +00:00
|
|
|
QRect Bridge::transparentRect() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2009-11-25 23:32:35 +00:00
|
|
|
return c->transparentRect().translated(-c->decorationRect().topLeft());
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-11-25 23:32:35 +00:00
|
|
|
|
2012-01-12 06:42:55 +00:00
|
|
|
//BEGIN TABBING
|
|
|
|
|
|
|
|
Client *Bridge::clientForId(long id) const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-01-12 06:42:55 +00:00
|
|
|
Client* client = reinterpret_cast<Client*>(id);
|
|
|
|
if (!c->workspace()->hasClient(client)) {
|
|
|
|
kWarning(1212) << "****** ARBITRARY CODE EXECUTION ATTEMPT DETECTED ******" << id;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return client;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2012-01-12 06:42:55 +00:00
|
|
|
int Bridge::tabCount() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-01-12 06:42:55 +00:00
|
|
|
if (c->tabGroup())
|
|
|
|
return c->tabGroup()->count();
|
|
|
|
return 1;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2012-01-12 06:42:55 +00:00
|
|
|
long Bridge::tabId(int idx) const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-01-12 06:42:55 +00:00
|
|
|
if (c->tabGroup())
|
|
|
|
return tabIdOf(c->tabGroup()->clients().at(idx));
|
|
|
|
return tabIdOf(c);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2012-01-12 06:42:55 +00:00
|
|
|
QIcon Bridge::icon(int idx) const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-01-12 06:42:55 +00:00
|
|
|
if (c->tabGroup()) {
|
|
|
|
Client *tabC = c->tabGroup()->clients().at(idx);
|
|
|
|
QIcon icon(tabC->icon());
|
|
|
|
icon.addPixmap(tabC->miniIcon());
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
return icon();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2012-10-16 20:42:19 +00:00
|
|
|
QString Bridge::caption() const
|
|
|
|
{
|
|
|
|
return c->caption(true, true);
|
|
|
|
}
|
|
|
|
|
2012-01-12 06:42:55 +00:00
|
|
|
QString Bridge::caption(int idx) const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-01-12 06:42:55 +00:00
|
|
|
if (c->tabGroup())
|
2012-10-16 20:42:19 +00:00
|
|
|
return c->tabGroup()->clients().at(idx)->caption(true, true);
|
|
|
|
return c->caption(true, true);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2012-01-12 06:42:55 +00:00
|
|
|
long Bridge::currentTabId() const
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-01-12 06:42:55 +00:00
|
|
|
if (c->tabGroup())
|
|
|
|
return tabIdOf(c->tabGroup()->current());
|
|
|
|
return 0;
|
2012-01-12 06:42:55 +00:00
|
|
|
}
|
|
|
|
|
2012-01-12 06:42:55 +00:00
|
|
|
void Bridge::setCurrentTab(long id)
|
2012-01-12 06:42:55 +00:00
|
|
|
{
|
2012-01-12 06:42:55 +00:00
|
|
|
if (c->tabGroup())
|
|
|
|
c->tabGroup()->setCurrent(clientForId(id));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Bridge::tab_A_before_B(long A, long B)
|
|
|
|
{
|
|
|
|
if (!B) {
|
|
|
|
if (c->tabGroup()) {
|
|
|
|
if (Client *a = clientForId(A))
|
|
|
|
a->untab();
|
|
|
|
}
|
2009-12-19 09:39:01 +00:00
|
|
|
return;
|
2009-11-15 03:24:04 +00:00
|
|
|
}
|
2012-01-12 06:42:55 +00:00
|
|
|
|
|
|
|
if (Client *a = clientForId(A))
|
|
|
|
if (Client *b = clientForId(B))
|
2013-04-30 18:37:29 +00:00
|
|
|
if (a != b)
|
2012-01-12 06:42:55 +00:00
|
|
|
a->tabBefore(b, true);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2012-01-12 06:42:55 +00:00
|
|
|
void Bridge::tab_A_behind_B(long A, long B)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-01-12 06:42:55 +00:00
|
|
|
if (!B) {
|
|
|
|
if (c->tabGroup()) {
|
|
|
|
if (Client *a = clientForId(A))
|
|
|
|
a->untab();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Client *a = clientForId(A))
|
|
|
|
if (Client *b = clientForId(B))
|
2013-04-30 18:37:29 +00:00
|
|
|
if (a != b)
|
2012-01-12 06:42:55 +00:00
|
|
|
a->tabBehind(b, true);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2012-01-12 06:42:55 +00:00
|
|
|
|
|
|
|
void Bridge::untab(long id, const QRect& newGeom)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-01-12 06:42:55 +00:00
|
|
|
if (c->tabGroup())
|
|
|
|
if (Client* client = clientForId(id))
|
|
|
|
if (client->untab(newGeom)) {
|
|
|
|
if (options->focusPolicyIsReasonable())
|
|
|
|
c->workspace()->takeActivity(client, ActivityFocus | ActivityRaise, true);
|
|
|
|
c->workspace()->raiseClient(client);
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2012-01-12 06:42:55 +00:00
|
|
|
void Bridge::closeTab(long id)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-01-12 06:42:55 +00:00
|
|
|
if (Client* client = clientForId(id))
|
|
|
|
client->closeWindow();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2012-01-12 06:42:55 +00:00
|
|
|
void Bridge::closeTabGroup()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2012-01-12 06:42:55 +00:00
|
|
|
if (c->tabGroup())
|
|
|
|
c->tabGroup()->closeAll();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2009-11-15 03:24:04 +00:00
|
|
|
|
2012-01-12 06:42:55 +00:00
|
|
|
//END TABBING
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
KDecoration::WindowOperation Bridge::buttonToWindowOperation(Qt::MouseButtons button)
|
|
|
|
{
|
|
|
|
return c->mouseButtonToWindowOperation(button);
|
|
|
|
}
|
2009-11-17 07:17:49 +00:00
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
} // namespace
|