summaryrefslogtreecommitdiff
path: root/src/window.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/window.cpp')
-rw-r--r--src/window.cpp3217
1 files changed, 1731 insertions, 1486 deletions
diff --git a/src/window.cpp b/src/window.cpp
index d3b9658..18bc1fe 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -1,29 +1,28 @@
/*
- * Aquamarine the KDE window decorator
- *
- * Copyright (c) 2006 Dennis Kasprzyk <onestone@beryl-project.org>
- * Copyright (c) 2006 Volker Krause <vkrause@kde.org>
- *
- * Uses code of:
- * Emerald window decorator (www.beryl-project.org)
- * gtk-window-decorator (www.freedesktop.org/wiki/Software/Compiz)
- * KWin window manager (www.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, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
+* Aquamarine the KDE window decorator
+*
+* Copyright (c) 2006 Dennis Kasprzyk <onestone@beryl-project.org>
+* Copyright (c) 2006 Volker Krause <vkrause@kde.org>
+* Copyright (c) 2006 David Reveman <davidr@novell.com>
+*
+* Uses code of:
+* KWin window manager (www.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, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+*/
#include "window.h"
#include "decorator.h"
@@ -32,19 +31,14 @@
#include "settings.h"
#include <X11/Xlib.h>
-#include <X11/Xatom.h>
-#include <X11/extensions/Xcomposite.h>
#include <X11/extensions/shape.h>
-#include <X11/extensions/Xrender.h>
-
-#include <math.h>
+#include <X11/extensions/Xcomposite.h>
#include <fixx11h.h>
#include <kdebug.h>
#include <kglobal.h>
#include <kglobalsettings.h>
-#include <klocale.h>
#include <kiconloader.h>
#include <kdecoration.h>
#include <kwin.h>
@@ -52,8 +46,6 @@
#include <kprocess.h>
#include <kstandarddirs.h>
-#include <netwm.h>
-
#include <qapplication.h>
#include <qlayout.h>
#include <qevent.h>
@@ -65,707 +57,642 @@
#include <qcursor.h>
#include <qpopupmenu.h>
-#define BERYL_ADVANCED_DECORATION_VERSION 10121980
-
-#define GRAVITY_WEST (1 << 0)
-#define GRAVITY_EAST (1 << 1)
-#define GRAVITY_NORTH (1 << 2)
-#define GRAVITY_SOUTH (1 << 3)
-
-#define XX_MASK (1 << 12)
-#define XY_MASK (1 << 13)
-#define YX_MASK (1 << 14)
-#define YY_MASK (1 << 15)
-
-#define CLAMP_HORZ (1 << 0)
-#define CLAMP_VERT (1 << 1)
-
-#define WM_MOVERESIZE_SIZE_TOPLEFT 0
-#define WM_MOVERESIZE_SIZE_TOP 1
-#define WM_MOVERESIZE_SIZE_TOPRIGHT 2
-#define WM_MOVERESIZE_SIZE_RIGHT 3
-#define WM_MOVERESIZE_SIZE_BOTTOMRIGHT 4
-#define WM_MOVERESIZE_SIZE_BOTTOM 5
-#define WM_MOVERESIZE_SIZE_BOTTOMLEFT 6
-#define WM_MOVERESIZE_SIZE_LEFT 7
-#define WM_MOVERESIZE_MOVE 8
-#define WM_MOVERESIZE_SIZE_KEYBOARD 9
-#define WM_MOVERESIZE_MOVE_KEYBOARD 10
-
-extern Atom net_window_decor;
-extern Atom net_wm_moveresize;
-
-extern Atom wm_protocols;
-extern Atom wm_delete_window;
-extern Atom wm_take_focus;
-extern Atom net_wm_context_help;
-extern Atom net_wm_ping;
-extern Atom net_wm_take_activity;
-
-extern struct _cursor cursors[3][3];
-
-Aquamarine::Window::Window (WId wid, WId frame):
-QWidget(0,0,Qt::WX11BypassWM),
-m_wid (wid),
-m_active (false),
-m_deco (0),
-m_fakeMaximized (false),
-m_shapeSet (false),
-m_popup (0),
-m_advanced_popup (0),
-m_viewport_menu (0),
-m_appearance_menu (0),
-m_brightness_menu (0), m_saturation_menu (0), m_opacity_menu (0),
-mProcessKiller (0)
-{
- KWin::WindowInfo wInf = KWin::windowInfo (m_wid, NET::WMState, 0);
- m_state = wInf.state ();
-
- m_name = KWin::readNameProperty (m_wid, XA_WM_NAME);
-
- m_icons = QIconSet (KWin::icon (m_wid, 16, 16, TRUE),
- KWin::icon (m_wid, 32, 32, TRUE));
-
- m_opacity = readWindowPropertyDefault (m_wid, Atoms::opacity, 0xffff);
- m_brightness =
- readWindowPropertyDefault (m_wid, Atoms::brightness, 0xffff);
- m_saturation =
- readWindowPropertyDefault (m_wid, Atoms::saturation, 0xffff);
-
- setBackgroundColor(QColor(0,0));
-
- double op = Settings::shadowOpacity() / 100.0;
- op *= 0xffff;
-
- m_sradius = Settings::shadowRadius();
- QColor color = Settings::shadowColor();
- m_scolor[0] = short((color.red() / 256.0) * 0xffff);
- m_scolor[1] = short((color.green() / 256.0) * 0xffff);
- m_scolor[2] = short((color.blue() / 256.0) * 0xffff);
- m_scolor[3] = short(op);
-
- int offX = Settings::shadowOffsetX();
- int offY = Settings::shadowOffsetY();
- offX = KMAX(-m_sradius,KMIN(m_sradius,offX));
- offY = KMAX(-m_sradius,KMIN(m_sradius,offY));
-
- if (Settings::drawShadows())
- m_soffset.setCoords(-m_sradius + offX,-m_sradius + offY,
- m_sradius + offX,m_sradius + offY);
- else
- m_soffset.setCoords(0,0,0,0);
+Aquamarine::Window::Window (QWidget *parent, WId clientId, WId frame, Type type,
+ int x, int y, int w, int h): QWidget (parent, 0),
+ mType (type),
+ mFrame (0),
+ mClientId (clientId),
+ mSelectedId (0),
+ mDecor (0),
+ mPixmap (0),
+ mDamageId (0),
+ mShadow (0),
+ mPicture (0),
+ mTexturePicture (0),
+ mDecorationPicture (0),
+ mUpdateProperty (false),
+ mShapeSet (false),
+ mUniqueHorzShape (false),
+ mUniqueVertShape (false),
+ mPopup (0),
+ mAdvancedMenu (0),
+ mDesktopMenu (0),
+ mViewportMenu (0),
+ mAppearanceMenu (0),
+ mBrightnessMenu (0),
+ mSaturationMenu (0),
+ mOpacityMenu (0),
+ mMapped (false),
+ mPendingMap (0),
+ mPendingConfigure (0),
+ mProcessKiller (0)
+{
+ if (mType == Normal || mType == Switcher)
+ {
+ KWin::WindowInfo wInfo = KWin::windowInfo (mClientId, NET::WMState, 0);
- m_currentPixmap = None;
- m_updatePixmap = true;
- m_mapped = true;
+ mState = wInfo.state ();
- setWState (Qt::WState_Visible);
- updateFrame (frame);
+ if (mType == Normal)
+ {
+ mName = KWin::readNameProperty (mClientId, XA_WM_NAME);
+ mIcons = QIconSet (KWin::icon (mClientId, 16, 16, TRUE),
+ KWin::icon (mClientId, 32, 32, TRUE));
+ mOpacity = readPropertyShort (mClientId, Atoms::netWmWindowOpacity,
+ 0xffff);
+ }
+ else
+ {
+ mIcons = QIconSet ();
+ mName = QString ("");
+ }
- int x, y;
- unsigned int width, height, border, depth;
- installEventFilter(this);
+ updateFrame (frame);
- ::Window root;
- XGetGeometry (qt_xdisplay (), m_wid, &root, &x, &y, &width, &height,
- &border, &depth);
- m_geometry = QRect (x, y, width, height);
+ mGeometry = QRect (x, y, w, h);
getWindowProtocols ();
+ }
+ else
+ {
+ mIcons = QIconSet ();
+ mName = QString ("");
+ mGeometry = QRect (50, 50, 30, 1);
+ }
+
+ setGeometry (QRect (mGeometry.x () + ROOT_OFF_X,
+ mGeometry.y () + ROOT_OFF_Y,
+ mGeometry.width (), mGeometry.height ()));
+
createDecoration ();
+
+ mActiveChild = NULL;
}
-Aquamarine::Window::~Window ()
+Aquamarine::Window::~Window (void)
{
- delete m_deco;
- delete m_popup;
+ if (mShadow)
+ decor_shadow_destroy (qt_xdisplay (), mShadow);
- Atom my_atom = Atoms::net_window_decor;
+ if (mPicture)
+ XRenderFreePicture (qt_xdisplay (), mPicture);
- Aquamarine::trapXError ();
- XWindowAttributes
- attr;
- if (XGetWindowAttributes (qt_xdisplay (), m_wid, &attr)
- && !Aquamarine::popXError ())
- {
- XDeleteProperty (qt_xdisplay (), m_wid, my_atom);
- }
+ if (mTexturePicture)
+ XRenderFreePicture (qt_xdisplay (), mTexturePicture);
- if (m_currentPixmap != None)
- XFreePixmap (qt_xdisplay(), m_currentPixmap);
+ if (mDecorationPicture)
+ XRenderFreePicture (qt_xdisplay (), mDecorationPicture);
+ if (mDecor)
+ delete mDecor;
- Aquamarine::popXError ();
-}
-
+ if (mPopup)
+ delete mPopup;
+ if (mProcessKiller)
+ delete mProcessKiller;
+}
bool
-Aquamarine::Window::isActive () const
+Aquamarine::Window::isActive (void) const
{
- return m_active;
+ if (mType == DefaultActive)
+ return true;
+
+ return Decorator::activeId () == mClientId;
}
bool
-Aquamarine::Window::isCloseable () const
+Aquamarine::Window::isCloseable (void) const
{
- return true;
+ if (mType != Normal)
+ return false;
+
+ return true;
}
bool
-Aquamarine::Window::isMaximizable () const
+Aquamarine::Window::isMaximizable (void) const
{
- return true;
+ if (mType != Normal)
+ return false;
+
+ return true;
}
-KDecoration::MaximizeMode Aquamarine::Window::maximizeMode () const
+KDecoration::MaximizeMode
+Aquamarine::Window::maximizeMode (void) const
{
- if (m_fakeMaximized)
- return MaximizeVertical | MaximizeHorizontal;
+ MaximizeMode mode = MaximizeRestore;
- MaximizeMode cur = ((m_state & NET::MaxVert)
- ? MaximizeVertical : MaximizeRestore) |
- ((m_state & NET::MaxHoriz) ? MaximizeHorizontal : MaximizeRestore);
- return cur;
+ if (mType != Normal)
+ return mode;
+
+ mode =
+ ((mState & NET::MaxVert) ? MaximizeVertical : MaximizeRestore) |
+ ((mState & NET::MaxHoriz) ? MaximizeHorizontal : MaximizeRestore);
+
+ return mode;
}
bool
-Aquamarine::Window::isMinimizable () const
+Aquamarine::Window::isMinimizable (void) const
{
- return true;
+ if (mType != Normal)
+ return false;
+
+ return true;
}
bool
-Aquamarine::Window::providesContextHelp () const
+Aquamarine::Window::providesContextHelp (void) const
{
- return m_supportContextHelp;
+ if (mType != Normal)
+ return false;
+
+ return mSupportContextHelp;
}
int
-Aquamarine::Window::desktop () const
+Aquamarine::Window::desktop (void) const
{
- return (m_state & NET::Sticky) ? NET::OnAllDesktops : 1;
+ KWin::WindowInfo wInfo = KWin::windowInfo (mClientId, NET::WMDesktop, 0);
+
+ return wInfo.desktop ();
}
bool
-Aquamarine::Window::isModal () const
+Aquamarine::Window::isModal (void) const
{
- return m_state & NET::Modal;
+ return mState & NET::Modal;
}
bool
-Aquamarine::Window::isShadeable () const
+Aquamarine::Window::isShadeable (void) const
{
- return true;
+ KWin::WindowInfo wInfo = KWin::windowInfo (mClientId, NET::WMPid,
+ NET::WM2AllowedActions);
+
+ return wInfo.actionSupported (NET::ActionShade);
}
bool
-Aquamarine::Window::isShade () const
+Aquamarine::Window::isShade (void) const
{
- return (m_state & NET::Shaded);
+ if (mType != Normal)
+ return false;
+
+ return (mState & NET::Shaded);
}
bool
-Aquamarine::Window::isSetShade () const
+Aquamarine::Window::isSetShade (void) const
{
- return isShade ();
+ return isShade ();
}
bool
-Aquamarine::Window::keepAbove () const
+Aquamarine::Window::keepAbove (void) const
{
- return (m_state & NET::KeepAbove);
+ if (mType != Normal)
+ return false;
+
+ return (mState & NET::KeepAbove);
}
bool
-Aquamarine::Window::keepBelow () const
+Aquamarine::Window::keepBelow (void) const
{
- return (m_state & NET::KeepBelow);
+ if (mType != Normal)
+ return false;
+
+ return (mState & NET::KeepBelow);
}
bool
-Aquamarine::Window::isMovable () const
+Aquamarine::Window::isMovable (void) const
{
- return true;
+ KWin::WindowInfo wInfo = KWin::windowInfo (mClientId, NET::WMPid,
+ NET::WM2AllowedActions);
+
+ return wInfo.actionSupported (NET::ActionMove);
}
-NET::WindowType Aquamarine::Window::windowType (unsigned long) const
+NET::WindowType
+Aquamarine::Window::windowType (unsigned long mask) const
{
- return NET::Normal;
+ KWin::WindowInfo wInfo = KWin::windowInfo (mClientId, NET::WMWindowType, 0);
+
+ return wInfo.windowType (mask);
}
bool
-Aquamarine::Window::isResizable () const
+Aquamarine::Window::isResizable (void) const
{
- return true;
+ KWin::WindowInfo wInfo = KWin::windowInfo (mClientId, NET::WMPid,
+ NET::WM2AllowedActions);
+
+ return wInfo.actionSupported (NET::ActionResize);
}
QIconSet
-Aquamarine::Window::icon () const
+Aquamarine::Window::icon (void) const
{
- return m_icons;
+ return mIcons;
}
QString
-Aquamarine::Window::caption () const
+Aquamarine::Window::caption (void) const
{
- return m_name;
+ return mName;
}
+/* TODO: We should use libtaskmanager, which is part of kdebase to create
+the window menu instead but the headers for that library are currently
+not installed. If kdebase could install those headers, we wouldn't have
+to have our own window menu implementaion here. */
void
Aquamarine::Window::showWindowMenu (QPoint pos)
{
- kdDebug () << k_funcinfo << pos << endl;
-
- // create menu if we don't have it already
- if (!m_popup)
- {
- m_popup = new QPopupMenu (this);
- m_popup->setCheckable (true);
- m_popup->setFont (KGlobalSettings::menuFont ());
-
- m_advanced_popup = new QPopupMenu (m_popup);
- m_advanced_popup->setCheckable (true);
- m_advanced_popup->setFont (KGlobalSettings::menuFont ());
- connect (m_advanced_popup, SIGNAL (activated (int)),
- SLOT (slotPopupActivated (int)));
-
- m_advanced_popup->insertItem (SmallIconSet ("up"),
- i18n ("Keep &Above Others"),
- Options::KeepAboveOp);
- m_advanced_popup->insertItem (SmallIconSet ("down"),
- i18n ("Keep &Below Others"),
- Options::KeepBelowOp);
- m_advanced_popup->insertItem (SmallIconSet ("window_fullscreen"),
- i18n ("&Fullscreen"),
- Options::FullScreenOp);
-
- m_popup->insertItem (i18n ("Ad&vanced"), m_advanced_popup);
-
- m_viewport_menu = new QPopupMenu (m_popup);
- m_viewport_menu->setCheckable (true);
- m_viewport_menu->setFont (KGlobalSettings::menuFont ());
- connect (m_viewport_menu, SIGNAL (activated (int)),
- SLOT (slotChangeViewport (int)));
-
- m_viewport_menu->insertItem (i18n ("On all Viewports"), 0);
- m_viewport_menu->insertSeparator ();
- for (int i = 1;
- i <=
- Decorator::viewports ().height () *
- Decorator::viewports ().width (); ++i)
- m_viewport_menu->insertItem (i18n ("Move to Viewport %1").arg (i),
- i);
-
- m_popup->insertItem (i18n ("To Viewport"), m_viewport_menu);
-
- m_popup->insertItem (SmallIconSet ("move"), i18n ("&Move"),
- Options::MoveOp);
- m_popup->insertItem (i18n ("Re&size"), Options::ResizeOp);
-
- m_popup->insertItem (i18n ("Mi&nimize"), Options::MinimizeOp);
- m_popup->insertItem (i18n ("Ma&ximize"), Options::MaximizeOp);
- m_popup->insertItem (i18n ("Sh&ade"), Options::ShadeOp);
-
-
- m_appearance_menu = new QPopupMenu (m_popup);
- m_appearance_menu->setFont (KGlobalSettings::menuFont ());
-
- m_opacity_menu = new QPopupMenu (m_appearance_menu);
- m_opacity_menu->setFont (KGlobalSettings::menuFont ());
- m_opacity_menu->insertItem ("25%", ChangeOpacity25);
- m_opacity_menu->insertItem ("50%", ChangeOpacity50);
- m_opacity_menu->insertItem ("75%", ChangeOpacity75);
- m_opacity_menu->insertItem ("100%", ChangeOpacity100);
-
- m_brightness_menu = new QPopupMenu (m_appearance_menu);
- m_brightness_menu->setFont (KGlobalSettings::menuFont ());
- m_brightness_menu->insertItem ("25%", ChangeBrightness25);
- m_brightness_menu->insertItem ("50%", ChangeBrightness50);
- m_brightness_menu->insertItem ("75%", ChangeBrightness75);
- m_brightness_menu->insertItem ("100%", ChangeBrightness100);
-
- m_saturation_menu = new QPopupMenu (m_appearance_menu);
- m_saturation_menu->setFont (KGlobalSettings::menuFont ());
- m_saturation_menu->insertItem ("25%", ChangeSaturation25);
- m_saturation_menu->insertItem ("50%", ChangeSaturation50);
- m_saturation_menu->insertItem ("75%", ChangeSaturation75);
- m_saturation_menu->insertItem ("100%", ChangeSaturation100);
-
- m_appearance_menu->insertItem (i18n ("Opacity"), m_opacity_menu);
- m_appearance_menu->insertItem (i18n ("Brightness"),
- m_brightness_menu);
- m_appearance_menu->insertItem (i18n ("Saturation"),
- m_saturation_menu);
- m_appearance_menu->insertSeparator ();
- m_appearance_menu->insertItem (i18n ("Reset settings"), ResetValues);
-
- m_popup->insertItem (i18n ("Appearance"), m_appearance_menu);
-
- connect (m_appearance_menu, SIGNAL (activated (int)),
- SLOT (slotAppearanceChange (int)));
- connect (m_opacity_menu, SIGNAL (activated (int)),
- SLOT (slotAppearanceChange (int)));
- connect (m_brightness_menu, SIGNAL (activated (int)),
- SLOT (slotAppearanceChange (int)));
- connect (m_saturation_menu, SIGNAL (activated (int)),
- SLOT (slotAppearanceChange (int)));
-
-
- m_popup->insertSeparator ();
- m_popup->insertItem (SmallIconSet ("fileclose"), i18n ("&Close"),
- Options::CloseOp);
- m_popup->insertSeparator ();
-
- connect (m_popup, SIGNAL (aboutToShow ()),
- SLOT (slotPopupAboutToShow ()));
- connect (m_popup, SIGNAL (activated (int)),
- SLOT (slotPopupActivated (int)));
- }
- m_popup->exec (pos);
+ if (!mPopup)
+ {
+ mPopup = new QPopupMenu ();
+ mPopup->setCheckable (true);
+ mPopup->setFont (KGlobalSettings::menuFont ());
+
+ mAdvancedMenu = new QPopupMenu (mPopup);
+ mAdvancedMenu->setCheckable (true);
+ mAdvancedMenu->setFont (KGlobalSettings::menuFont ());
+
+ connect (mAdvancedMenu, SIGNAL (activated (int)),
+ SLOT (handlePopupActivated (int)));
+
+ mAdvancedMenu->insertItem (SmallIconSet ("up"),
+ i18n ("Keep &Above Others"),
+ Options::KeepAboveOp);
+ mAdvancedMenu->insertItem (SmallIconSet ("down"),
+ i18n ("Keep &Below Others"),
+ Options::KeepBelowOp);
+ mAdvancedMenu->insertItem (SmallIconSet ("window_fullscreen"),
+ i18n ("&Fullscreen"),
+ Options::FullScreenOp);
+
+ mPopup->insertItem (i18n ("Ad&vanced"), mAdvancedMenu);
+
+ mDesktopMenu = new QPopupMenu (mPopup);
+ mDesktopMenu->setCheckable (true);
+ mDesktopMenu->setFont (KGlobalSettings::menuFont ());
+
+ connect (mDesktopMenu, SIGNAL (activated (int)),
+ SLOT (handleDesktopPopupActivated (int)));
+
+ mPopup->insertItem (i18n ("To &Desktop"), mDesktopMenu, Options::NoOp);
+
+ mViewportMenu = new QPopupMenu (mPopup);
+ mViewportMenu->setCheckable (true);
+ mViewportMenu->setFont (KGlobalSettings::menuFont ());
+ connect (mViewportMenu, SIGNAL (activated (int)),
+ SLOT (handleChangeViewport (int)));
+
+ mViewportMenu->insertItem (i18n ("On all Viewports"), 0);
+ mViewportMenu->insertSeparator ();
+ for (int i = 1; i <=
+ Decorator::viewports ().height () *
+ Decorator::viewports ().width (); ++i)
+ mViewportMenu->insertItem (i18n ("Move to Viewport %1").arg (i),
+ i);
+
+ mPopup->insertItem (i18n ("To Viewport"), mViewportMenu);
+
+ mAppearanceMenu = new QPopupMenu (mPopup);
+ mAppearanceMenu->setFont (KGlobalSettings::menuFont ());
+
+ mOpacityMenu = new QPopupMenu (mAppearanceMenu);
+ mOpacityMenu->setFont (KGlobalSettings::menuFont ());
+ mOpacityMenu->insertItem ("25%", ChangeOpacity25);
+ mOpacityMenu->insertItem ("50%", ChangeOpacity50);
+ mOpacityMenu->insertItem ("75%", ChangeOpacity75);
+ mOpacityMenu->insertItem ("100%", ChangeOpacity100);
+
+ mBrightnessMenu = new QPopupMenu (mAppearanceMenu);
+ mBrightnessMenu->setFont (KGlobalSettings::menuFont ());
+ mBrightnessMenu->insertItem ("25%", ChangeBrightness25);
+ mBrightnessMenu->insertItem ("50%", ChangeBrightness50);
+ mBrightnessMenu->insertItem ("75%", ChangeBrightness75);
+ mBrightnessMenu->insertItem ("100%", ChangeBrightness100);
+
+ mSaturationMenu = new QPopupMenu (mAppearanceMenu);
+ mSaturationMenu->setFont (KGlobalSettings::menuFont ());
+ mSaturationMenu->insertItem ("25%", ChangeSaturation25);
+ mSaturationMenu->insertItem ("50%", ChangeSaturation50);
+ mSaturationMenu->insertItem ("75%", ChangeSaturation75);
+ mSaturationMenu->insertItem ("100%", ChangeSaturation100);
+
+ mAppearanceMenu->insertItem (i18n ("Opacity"), mOpacityMenu);
+ mAppearanceMenu->insertItem (i18n ("Brightness"),
+ mBrightnessMenu);
+ mAppearanceMenu->insertItem (i18n ("Saturation"),
+ mSaturationMenu);
+ mAppearanceMenu->insertSeparator ();
+ mAppearanceMenu->insertItem (i18n ("Reset settings"), ResetValues);
+
+ mPopup->insertItem (i18n ("Appearance"), mAppearanceMenu);
+
+ connect (mAppearanceMenu, SIGNAL (activated (int)),
+ SLOT (handleAppearanceChange (int)));
+ connect (mOpacityMenu, SIGNAL (activated (int)),
+ SLOT (handleAppearanceChange (int)));
+ connect (mBrightnessMenu, SIGNAL (activated (int)),
+ SLOT (handleAppearanceChange (int)));
+ connect (mSaturationMenu, SIGNAL (activated (int)),
+ SLOT (handleAppearanceChange (int)));
+
+
+ mPopup->insertItem (SmallIconSet ("move"), i18n ("&Move"),
+ Options::MoveOp);
+ mPopup->insertItem (i18n ("Re&size"), Options::ResizeOp);
+
+ mPopup->insertItem (i18n ("Mi&nimize"), Options::MinimizeOp);
+ mPopup->insertItem (i18n ("Ma&ximize"), Options::MaximizeOp);
+ mPopup->insertItem (i18n ("Sh&ade"), Options::ShadeOp);
+
+ mPopup->insertSeparator ();
+
+ mPopup->insertItem (SmallIconSet ("fileclose"), i18n ("&Close"),
+ Options::CloseOp);
+
+ connect (mPopup, SIGNAL (aboutToShow ()),
+ SLOT (handlePopupAboutToShow ()));
+ connect (mPopup, SIGNAL (activated (int)),
+ SLOT (handlePopupActivated (int)));
+ }
+
+ mPopup->exec (pos);
}
void
-Aquamarine::Window::showWindowMenu (const QRect & pos)
+Aquamarine::Window::showWindowMenu (const QRect &pos)
{
- showWindowMenu (pos.bottomLeft ());
+ showWindowMenu (pos.bottomLeft ());
}
void
-Aquamarine::Window::processMousePressEvent (QMouseEvent * qme)
-{
- Options::MouseCommand com = Options::MouseNothing;
- bool active = isActive();
- if ( !m_supportTakeFocus )
- active = TRUE;
-
- switch (qme->button ())
- {
- case Qt::LeftButton:
- com = active ? Decorator::options()->commandActiveTitlebar1() : Decorator::options()->commandInactiveTitlebar1();
- break;
- case Qt::MidButton:
- com = active ? Decorator::options()->commandActiveTitlebar2() : Decorator::options()->commandInactiveTitlebar2();
- break;
- case Qt::RightButton:
- com = active ? Decorator::options()->commandActiveTitlebar3() : Decorator::options()->commandInactiveTitlebar3();
- break;
- default:
- break;
- }
- if( qme->button () == Qt::LeftButton
- && com != Options::MouseOperationsMenu // actions where it's not possible to get the matching
- && com != Options::MouseMinimize ) // mouse release event
- {
- moveWindow (qme);
- }
-
-
- performMouseCommand( com, qme);
+Aquamarine::Window::processMousePressEvent (QMouseEvent *qme)
+{
+ Options::MouseCommand com = Options::MouseNothing;
+ bool active = isActive ();
+
+ if (!mSupportTakeFocus)
+ active = TRUE;
+
+ switch (qme->button ()) {
+ case Qt::LeftButton:
+ com = active ? Decorator::options ()->commandActiveTitlebar1 () :
+ Decorator::options()->commandInactiveTitlebar1 ();
+ break;
+ case Qt::MidButton:
+ com = active ? Decorator::options ()->commandActiveTitlebar2 () :
+ Decorator::options()->commandInactiveTitlebar2 ();
+ break;
+ case Qt::RightButton:
+ com = active ? Decorator::options ()->commandActiveTitlebar3 () :
+ Decorator::options()->commandInactiveTitlebar3 ();
+ default:
+ break;
+ }
+
+ if (qme->button () == Qt::LeftButton)
+ {
+ // actions where it's not possible to get the matching release event
+ if (com != Options::MouseOperationsMenu &&
+ com != Options::MouseMinimize)
+ {
+ moveWindow (qme);
+ return;
+ }
+ }
+
+ performMouseCommand (com, qme);
}
void
Aquamarine::Window::performWindowOperation (WindowOperation wo)
{
- kdDebug () << k_funcinfo << wo << endl;
- switch (wo)
- {
- case KDecoration::MaximizeOp:
- maximize (maximizeMode () == KDecoration::MaximizeFull
- ? KDecoration::MaximizeRestore : KDecoration::MaximizeFull);
- break;
- case KDecoration::HMaximizeOp:
- maximize (maximizeMode () ^ KDecoration::MaximizeHorizontal);
- break;
- case KDecoration::VMaximizeOp:
- maximize (maximizeMode () ^ KDecoration::MaximizeVertical);
- break;
- case KDecoration::MinimizeOp:
- minimize ();
- break;
- case KDecoration::ShadeOp:
- setShade (!isShade ());
- break;
- case KDecoration::CloseOp:
- closeWindow ();
- break;
- case KDecoration::KeepAboveOp:
- setKeepAbove (!keepAbove ());
- break;
- case KDecoration::KeepBelowOp:
- setKeepBelow (!keepBelow ());
- break;
- case KDecoration::FullScreenOp:
- if (m_state & NET::FullScreen)
- {
- KWin::clearState (m_wid, NET::FullScreen);
- }
- else
- KWin::setState (m_wid, NET::FullScreen);
- break;
- case KDecoration::MoveOp:
- {
- XEvent ev;
- ev.xclient.type = ClientMessage;
- ev.xclient.display = qt_xdisplay ();
-
- ev.xclient.serial = 0;
- ev.xclient.send_event = TRUE;
-
- ev.xclient.window = m_wid;
- ev.xclient.message_type = Atoms::net_wm_moveresize;
- ev.xclient.format = 32;
-
- ev.xclient.data.l[0] = m_geometry.x () + (m_geometry.width () / 2);
- ev.xclient.data.l[1] = m_geometry.y () + (m_geometry.height () / 2);
- ev.xclient.data.l[2] = WM_MOVERESIZE_MOVE_KEYBOARD;
- ev.xclient.data.l[3] = 1;
- ev.xclient.data.l[4] = 1;
-
- XUngrabPointer (qt_xdisplay (), CurrentTime);
- XUngrabKeyboard (qt_xdisplay (), CurrentTime);
-
- XSendEvent (qt_xdisplay (), qt_xrootwin (), FALSE,
- SubstructureRedirectMask | SubstructureNotifyMask, &ev);
-
- XSync (qt_xdisplay (), FALSE);
- }
- break;
- case KDecoration::ResizeOp:
- {
- XEvent
- ev;
- ev.xclient.type = ClientMessage;
- ev.xclient.display = qt_xdisplay ();
-
- ev.xclient.serial = 0;
- ev.xclient.send_event = TRUE;
-
- ev.xclient.window = m_wid;
- ev.xclient.message_type = Atoms::net_wm_moveresize;
- ev.xclient.format = 32;
-
- ev.xclient.data.l[0] = m_geometry.x () + (m_geometry.width () / 2);
- ev.xclient.data.l[1] = m_geometry.y () + (m_geometry.height () / 2);
- ev.xclient.data.l[2] = WM_MOVERESIZE_SIZE_KEYBOARD;
- ev.xclient.data.l[3] = 1;
- ev.xclient.data.l[4] = 1;
-
- XUngrabPointer (qt_xdisplay (), CurrentTime);
- XUngrabKeyboard (qt_xdisplay (), CurrentTime);
-
- XSendEvent (qt_xdisplay (), qt_xrootwin (), FALSE,
- SubstructureRedirectMask | SubstructureNotifyMask, &ev);
-
- XSync (qt_xdisplay (), FALSE);
- }
- break;
- default:
- break;
- }
+ switch (wo) {
+ case KDecoration::MaximizeOp:
+ maximize (maximizeMode () == KDecoration::MaximizeFull ?
+ KDecoration::MaximizeRestore : KDecoration::MaximizeFull);
+ break;
+ case KDecoration::HMaximizeOp:
+ maximize (maximizeMode () ^ KDecoration::MaximizeHorizontal);
+ break;
+ case KDecoration::VMaximizeOp:
+ maximize (maximizeMode () ^ KDecoration::MaximizeVertical);
+ break;
+ case KDecoration::MinimizeOp:
+ minimize ();
+ break;
+ case KDecoration::ShadeOp:
+ setShade (!isShade ());
+ break;
+ case KDecoration::CloseOp:
+ closeWindow ();
+ break;
+ case KDecoration::KeepAboveOp:
+ setKeepAbove (!keepAbove ());
+ break;
+ case KDecoration::KeepBelowOp:
+ setKeepBelow (!keepBelow ());
+ break;
+ case KDecoration::FullScreenOp:
+ if (mState & NET::FullScreen)
+ KWin::clearState (mClientId, NET::FullScreen);
+ else
+ KWin::setState (mClientId, NET::FullScreen);
+ break;
+ case KDecoration::MoveOp:
+ Decorator::rootInfo ()->moveResizeRequest (mClientId,
+ mGeometry.x () +
+ mGeometry.width () / 2,
+ mGeometry.y () +
+ mGeometry.height () / 2,
+ NET::KeyboardMove);
+ break;
+ case KDecoration::ResizeOp:
+ Decorator::rootInfo ()->moveResizeRequest (mClientId,
+ mGeometry.x () +
+ mGeometry.width () / 2,
+ mGeometry.y () +
+ mGeometry.height () / 2,
+ NET::KeyboardSize);
+ default:
+ break;
+ }
}
-void
-Aquamarine::Window::setMask (const QRegion & reg, int)
+bool
+Aquamarine::Window::isPreview (void) const
{
- kdDebug () << k_funcinfo << endl;
-
- int top, bottom, left, right;
- m_deco->borders (left, right, top, bottom);
-
- if (m_shapeSet)
- m_shapeChange += m_shape.eor(reg);
- else
- m_shapeChange = reg;
-
- m_shape = QRegion (reg);
- m_shapeSet = true;
-
- if (m_deco)
- m_deco->widget()->setMask(reg);
-
- QRegion moved = QRegion (reg);
- moved.translate(-m_soffset.left(),-m_soffset.top());
-
- XShapeCombineRegion (qt_xdisplay (), handle(), ShapeInput, 0, 0,
- moved.handle (), ShapeSet);
-
- //renderShadow();
+ return false;
}
-bool
-Aquamarine::Window::isPreview () const
+QRect
+Aquamarine::Window::geometry (void) const
{
- return false;
+ QRect rect = QWidget::geometry ();
+
+ return QRect (rect.x () - ROOT_OFF_X,
+ rect.y () - ROOT_OFF_Y,
+ rect.width (),
+ rect.height ());
}
QRect
-Aquamarine::Window::geometry () const
+Aquamarine::Window::iconGeometry (void) const
{
- if (m_deco)
- {
- int top, bottom, left, right;
- m_deco->borders (left, right, top, bottom);
- return QRect (0, 0, m_geometry.width () + left + right,
- m_geometry.height () + top + bottom);
- }
- return m_geometry;
+ return QRect ();
}
QRect
-Aquamarine::Window::iconGeometry () const
+Aquamarine::Window::clientGeometry (void)
{
- return QRect ();
+ QRect frame = geometry ();
+
+ return QRect (frame.x () + mBorder.left,
+ frame.y () + mBorder.top,
+ frame.width () - mBorder.left - mBorder.right,
+ frame.height () - mBorder.top - mBorder.bottom);
}
QRegion
Aquamarine::Window::unobscuredRegion (const QRegion & r) const
{
- return r;
+ return r;
}
QWidget *
-Aquamarine::Window::workspaceWidget () const
+Aquamarine::Window::workspaceWidget (void) const
{
- return 0;
+ return const_cast <Window *> (this);
}
WId
-Aquamarine::Window::windowId () const
+Aquamarine::Window::windowId (void) const
{
- return m_wid;
+ return mClientId;
}
void
-Aquamarine::Window::closeWindow ()
-{
- kdDebug () << k_funcinfo << endl;
- if (!isCloseable ())
- return;
- if (m_supportDeleteWindow)
- {
- Aquamarine::Decorator::sendClientMessage (m_wid, Atoms::wm_protocols,
- Atoms::wm_delete_window);
- }
- else
- {
- XKillClient (qt_xdisplay (), m_wid);
- }
+Aquamarine::Window::closeWindow (void)
+{
+ Decorator::rootInfo ()->closeWindowRequest (mClientId);
}
void
Aquamarine::Window::maximize (MaximizeMode mode)
{
- kdDebug () << k_funcinfo << endl;
-
- KWin::setState (m_wid,
- ((mode & MaximizeVertical) ? NET::
- MaxVert : 0) | ((mode & MaximizeHorizontal) ? NET::
- MaxHoriz : 0));
- KWin::clearState (m_wid,
- ((mode & MaximizeVertical) ? 0 : NET::
- MaxVert) | ((mode & MaximizeHorizontal) ? 0 : NET::
- MaxHoriz));
+ KWin::setState (mClientId,
+ ((mode & MaximizeVertical) ? NET::MaxVert : 0) |
+ ((mode & MaximizeHorizontal) ? NET::MaxHoriz : 0));
+ KWin::clearState (mClientId,
+ ((mode & MaximizeVertical) ? 0 : NET::MaxVert) |
+ ((mode & MaximizeHorizontal) ? 0 : NET::MaxHoriz));
}
void
-Aquamarine::Window::minimize ()
+Aquamarine::Window::minimize (void)
{
- kdDebug () << k_funcinfo << endl;
- KWin::iconifyWindow (m_wid, false);
+ KWin::iconifyWindow (mClientId, false);
}
void
-Aquamarine::Window::showContextHelp ()
+Aquamarine::Window::showContextHelp (void)
{
- kdDebug () << k_funcinfo << endl;
- if (m_supportContextHelp)
- {
- Aquamarine::Decorator::sendClientMessage (m_wid, Atoms::wm_protocols,
- Atoms::net_wm_context_help);
- }
+ if (mSupportContextHelp)
+ Aquamarine::Decorator::sendClientMessage (mClientId, mClientId,
+ Atoms::wmProtocols,
+ Atoms::netWmContextHelp);
}
void
-Aquamarine::Window::titlebarDblClickOperation ()
+Aquamarine::Window::titlebarDblClickOperation (void)
{
- kdDebug () << k_funcinfo << endl;
- performWindowOperation (Aquamarine::Decorator::options ()->
- operationTitlebarDblClick ());
+ WindowOperation op;
+
+ op = Aquamarine::Decorator::options ()->operationTitlebarDblClick ();
+ performWindowOperation (op);
}
void
Aquamarine::Window::setDesktop (int desktop)
{
- kdDebug () << k_funcinfo << endl;
- if (desktop == NET::OnAllDesktops)
- {
- KWin::setState (m_wid, NET::Sticky);
- }
- else
- {
- KWin::clearState (m_wid, NET::Sticky);
- }
+ KWin::setOnDesktop (mClientId, desktop);
}
void
Aquamarine::Window::setKeepBelow (bool set)
{
- if (set)
- {
- KWin::clearState (m_wid, NET::KeepAbove);
- KWin::setState (m_wid, NET::KeepBelow);
- }
- else
- KWin::clearState (m_wid, NET::KeepBelow);
+ if (set)
+ {
+ KWin::clearState (mClientId, NET::KeepAbove);
+ KWin::setState (mClientId, NET::KeepBelow);
+ }
+ else
+ {
+ KWin::clearState (mClientId, NET::KeepBelow);
+ }
}
void
Aquamarine::Window::setKeepAbove (bool set)
{
- if (set)
- {
- KWin::clearState (m_wid, NET::KeepBelow);
- KWin::setState (m_wid, NET::KeepAbove);
- }
- else
- KWin::clearState (m_wid, NET::KeepAbove);
+ if (set)
+ {
+ KWin::clearState (mClientId, NET::KeepBelow);
+ KWin::setState (mClientId, NET::KeepAbove);
+ }
+ else
+ {
+ KWin::clearState (mClientId, NET::KeepAbove);
+ }
}
void
Aquamarine::Window::setShade (bool set)
{
- kdDebug () << k_funcinfo << endl;
- if (set)
- KWin::setState (m_wid, NET::Shaded);
- else
- KWin::clearState (m_wid, NET::Shaded);
- m_deco->shadeChange ();
+ if (set)
+ KWin::setState (mClientId, NET::Shaded);
+ else
+ KWin::clearState (mClientId, NET::Shaded);
+
+ mDecor->shadeChange ();
}
void
Aquamarine::Window::titlebarMouseWheelOperation (int delta)
{
- kdDebug () << k_funcinfo << endl;
- performMouseCommand( Decorator::options()->operationTitlebarMouseWheel( delta ), 0);
-}
+ Options::MouseCommand com;
+ com = Decorator::options()->operationTitlebarMouseWheel (delta);
+ performMouseCommand (com, 0);
+}
int
-Aquamarine::Window::currentDesktop () const
+Aquamarine::Window::currentDesktop (void) const
{
- return 1;
+ return KWin::currentDesktop ();
}
QWidget *
-Aquamarine::Window::initialParentWidget () const
+Aquamarine::Window::initialParentWidget (void) const
{
- return const_cast < Window * >(this);
+ return const_cast <Window *> (this);
}
-Qt::WFlags Aquamarine::Window::initialWFlags () const
+Qt::WFlags
+Aquamarine::Window::initialWFlags (void) const
{
- return 0;
+ return 0;
}
void
@@ -779,1111 +706,1429 @@ Aquamarine::Window::grabXServer (bool)
}
void
-Aquamarine::Window::createDecoration ()
+Aquamarine::Window::createDecoration (void)
{
- if (m_deco)
- return;
- KDecoration *
- deco = Decorator::pluginManager ()->createDecoration (this);
- deco->init ();
- deco->widget()->move(-m_soffset.left(),-m_soffset.top());
- m_deco = deco;
- m_deco->widget()->installEventFilter(this);
- resizeDecoration ();
+ KDecoration *decor;
- updateFrame(m_frame);
+ if (mDecor)
+ return;
+
+ decor = Decorator::pluginManager ()->createDecoration (this);
+ decor->init ();
+
+ mDecor = decor;
+
+ if (mType == Normal && mFrame)
+ {
+ Aquamarine::trapXError ();
+ XSelectInput (qt_xdisplay (), mFrame,
+ StructureNotifyMask | PropertyChangeMask |
+ ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
+ EnterWindowMask | LeaveWindowMask);
+ if (Aquamarine::popXError ())
+ return;
+ }
+
+ resizeDecoration (true);
}
-void
-Aquamarine::Window::resizeDecoration ()
-{
- int top, bottom, left, right;
- m_deco->borders (left, right, top, bottom);
+static void
+fillQRegion (Display *xdisplay,
+ Picture picture,
+ int clipX1,
+ int clipY1,
+ int clipX2,
+ int clipY2,
+ int xOff,
+ int yOff,
+ QRegion *region)
+{
+ static XRenderColor white = { 0xffff, 0xffff, 0xffff, 0xffff };
+ QMemArray <QRect> rects = region->rects ();
+ QMemArray <QRect>::ConstIterator it;
+ int x1, y1, x2, y2;
+
+ for (it = rects.begin (); it != rects.end (); it++)
+ {
+ x1 = it->x ();
+ y1 = it->y ();
+ x2 = x1 + it->width ();
+ y2 = y1 + it->height ();
+
+ if (x1 < clipX1)
+ x1 = clipX1;
+ if (y1 < clipY1)
+ y1 = clipY1;
+ if (x2 > clipX2)
+ x2 = clipX2;
+ if (y2 > clipY2)
+ y2 = clipY2;
+
+ if (x1 < x2 && y1 < y2)
+ XRenderFillRectangle (xdisplay, PictOpSrc, picture, &white,
+ xOff + x1,
+ yOff + y1,
+ x2 - x1,
+ y2 - y1);
+ }
+}
+
+static void
+drawBorderShape (Display *xdisplay,
+ Pixmap pixmap,
+ Picture picture,
+ int width,
+ int height,
+ decor_context_t *c,
+ void *closure)
+{
+ static XRenderColor clear = { 0x0000, 0x0000, 0x0000, 0x0000 };
+ static XRenderColor white = { 0xffff, 0xffff, 0xffff, 0xffff };
+ Aquamarine::Window *w = (Aquamarine::Window *) closure;
+ QRegion *shape;
+ bool uniqueHorzShade;
+ bool uniqueVertShade;
+ int xOffLeft, yOffTop, xOffRight, yOffBottom;
+ QRect rect = w->geometry ();
+ int x1, y1, x2, y2;
+
+ (void) pixmap;
- kdDebug () << k_funcinfo << endl;
+ XRenderFillRectangle (xdisplay, PictOpSrc, picture, &clear,
+ 0, 0, width, height);
- m_updatePixmap = true;
+ shape = w->getShape ();
+ w->getShapeInfo (&uniqueHorzShade, &uniqueVertShade);
- move (m_geometry.x() - left + m_soffset.left(),
- m_geometry.y() - top + m_soffset.top());
+ xOffLeft = c->left_space - c->extents.left;
+ yOffTop = c->top_space - c->extents.top;
- if (m_geometry.width () + left + right + m_soffset.width() != width() ||
- m_geometry.height () + top + bottom + m_soffset.height() != height())
+ xOffRight = c->left_space - c->extents.left;
+ yOffBottom = c->top_space - c->extents.top;
+
+ x1 = c->left_space;
+ y1 = c->top_space;
+ x2 = width - c->right_space;
+ y2 = height - c->bottom_space;
+
+ if (shape)
+ {
+ if (uniqueHorzShade && uniqueVertShade)
+ {
+ fillQRegion (xdisplay, picture,
+ 0, 0,
+ rect.width (), rect.height (),
+ xOffLeft, yOffTop, shape);
+ }
+ else
{
- m_shapeSet = false;
- resize (m_geometry.width () + left + right + m_soffset.width(),
- m_geometry.height () + top + bottom + m_soffset.height());
+ if (!uniqueHorzShade)
+ xOffRight = x2 - (rect.width () - c->extents.right);
- m_deco->resize (QSize(m_geometry.width () + left + right,
- m_geometry.height () + top + bottom));
+ if (!uniqueVertShade)
+ yOffBottom = y2 - (rect.height () - c->extents.bottom);
+
+ if (uniqueHorzShade)
+ {
+ fillQRegion (xdisplay, picture,
+ 0, 0,
+ rect.width (), c->extents.top,
+ xOffLeft, yOffTop, shape);
+ fillQRegion (xdisplay, picture,
+ 0, rect.height () - c->extents.bottom,
+ rect.width (), rect.height (),
+ xOffLeft, yOffBottom, shape);
+ }
+ else
+ {
+ fillQRegion (xdisplay, picture,
+ 0, 0,
+ c->extents.left, c->extents.top,
+ xOffLeft, yOffTop, shape);
+ fillQRegion (xdisplay, picture,
+ rect.width () - c->extents.right, 0,
+ rect.width (), c->extents.top,
+ xOffRight, yOffTop, shape);
+ fillQRegion (xdisplay, picture,
+ 0, rect.height () - c->extents.bottom,
+ c->extents.left, rect.height (),
+ xOffLeft, yOffBottom, shape);
+ fillQRegion (xdisplay, picture,
+ rect.width () - c->extents.right,
+ rect.height () - c->extents.bottom,
+ rect.width (), rect.height (),
+ xOffRight, yOffBottom, shape);
+
+ y1 -= c->extents.top;
+ y2 += c->extents.bottom;
+ }
+
+ if (uniqueVertShade)
+ {
+ fillQRegion (xdisplay, picture,
+ 0, c->extents.top,
+ c->extents.left,
+ rect.height () - c->extents.bottom,
+ xOffLeft, yOffTop, shape);
+ fillQRegion (xdisplay, picture,
+ rect.width () - c->extents.right, c->extents.top,
+ rect.width (),
+ rect.height () - c->extents.bottom,
+ xOffRight, yOffTop, shape);
+ }
+ else
+ {
+ x1 -= c->extents.left;
+ x2 += c->extents.right;
+ }
+ }
+ }
+ else
+ {
+ x1 -= c->extents.left;
+ x2 += c->extents.right;
+ y1 -= c->extents.top;
+ y2 += c->extents.bottom;
}
- m_deco->widget ()->setShown (true);
-}
-void
-Aquamarine::Window::updateWindowProperties ()
-{
-
- Pixmap pix = XCompositeNameWindowPixmap(qt_xdisplay(),handle());
-
- int top, bottom, left, right;
- int mtop, mbottom, mleft, mright;
-
- m_fakeMaximized = true;
- m_deco->borders (mleft, mright, mtop, mbottom);
- m_fakeMaximized = false;
- m_deco->borders (left, right, top, bottom);
-
- int w_w = m_geometry.width ();
- int w_h = m_geometry.height ();
-
- int otop = top - m_soffset.top();
- int obottom = bottom + m_soffset.bottom();
- int oleft = left - m_soffset.left();
- int oright = right + m_soffset.right();
-
- long mdata[256];
-
- long *data = mdata;
-
- *data++ = BERYL_ADVANCED_DECORATION_VERSION;
-
- memcpy (data++, &pix, sizeof (pix));
-
- *data++ = left;
- *data++ = right;
- *data++ = top;
- *data++ = bottom;
-
- *data++ = mleft;
- *data++ = mright;
- *data++ = mtop;
- *data++ = mbottom;
-
- *data++ = 0;
- *data++ = 0;
-
- *data++ = 0;
- *data++ = (unsigned short)((Settings::activeOpacity() / 100.0) * 0xffff);
- *data++ = (unsigned short)((Settings::inactiveOpacity() / 100.0) * 0xffff);
-
- // TOP LEFT
- *data++ =
- ((GRAVITY_NORTH | GRAVITY_WEST) << 0) |
- ((GRAVITY_NORTH | GRAVITY_WEST) << 4) |
- (0 << 8) | (0 << 10) | (XX_MASK) | (YY_MASK);
-
- *data++ = -oleft;
- *data++ = -otop;
- *data++ = 0;
- *data++ = 0;
- *data++ = oleft;
- *data++ = otop;
- *data++ = 0;
- *data++ = 0;
-
- // TOP RIGHT
- *data++ =
- ((GRAVITY_NORTH | GRAVITY_EAST) << 0) |
- ((GRAVITY_NORTH | GRAVITY_EAST) << 4) |
- (0 << 8) | (0 << 10) | (XX_MASK) | (YY_MASK);
-
- *data++ = 0;
- *data++ = -otop;
- *data++ = oright;
- *data++ = 0;
- *data++ = oright;
- *data++ = otop;
- *data++ = oleft + w_w;
- *data++ = 0;
-
- // BOTTOM LEFT
- *data++ =
- ((GRAVITY_SOUTH | GRAVITY_WEST) << 0) |
- ((GRAVITY_SOUTH | GRAVITY_WEST) << 4) |
- (0 << 8) | (0 << 10) | (XX_MASK) | (YY_MASK);
-
- *data++ = -oleft;
- *data++ = 0;
- *data++ = 0;
- *data++ = obottom;
- *data++ = oleft;
- *data++ = obottom;
- *data++ = 0;
- *data++ = w_h + otop;
-
- // BOTTOM RIGHT
- *data++ =
- ((GRAVITY_SOUTH | GRAVITY_EAST) << 0) |
- ((GRAVITY_SOUTH | GRAVITY_EAST) << 4) |
- (0 << 8) | (0 << 10) | (XX_MASK) | (YY_MASK);
-
- *data++ = 0;
- *data++ = 0;
- *data++ = oright;
- *data++ = obottom;
- *data++ = oright;
- *data++ = obottom;
- *data++ = oleft + w_w;
- *data++ = w_h + otop;
-
- // TOP CENTER
- *data++ =
- ((GRAVITY_NORTH | GRAVITY_WEST) << 0) |
- ((GRAVITY_NORTH | GRAVITY_EAST) << 4) |
- (0 << 8) | (0 << 10) | (XX_MASK) | (YY_MASK);
-
- *data++ = 0;
- *data++ = -otop;
- *data++ = 0;
- *data++ = 0;
- *data++ = w_w;
- *data++ = otop;
- *data++ = oleft;
- *data++ = 0;
-
- *data++ =
- ((GRAVITY_NORTH | GRAVITY_WEST) << 0) |
- ((GRAVITY_NORTH | GRAVITY_EAST) << 4) |
- (0 << 8) | (CLAMP_HORZ << 10) | (YY_MASK);
-
- *data++ = w_w;
- *data++ = -otop;
- *data++ = 0;
- *data++ = 0;
- *data++ = SHRT_MAX;
- *data++ = otop;
- *data++ = oleft + w_w;
- *data++ = 0;
-
- // BOTTOM CENTER
- *data++ =
- ((GRAVITY_SOUTH | GRAVITY_WEST) << 0) |
- ((GRAVITY_SOUTH | GRAVITY_EAST) << 4) |
- (0 << 8) | (0 << 10) | (XX_MASK) | (YY_MASK);
-
- *data++ = 0;
- *data++ = 0;
- *data++ = 0;
- *data++ = obottom;
- *data++ = w_w;
- *data++ = obottom;
- *data++ = oleft;
- *data++ = w_h + otop;
-
- *data++ =
- ((GRAVITY_SOUTH | GRAVITY_WEST) << 0) |
- ((GRAVITY_SOUTH | GRAVITY_EAST) << 4) |
- (0 << 8) | (CLAMP_HORZ << 10) | (YY_MASK);
-
- *data++ = w_w;
- *data++ = 0;
- *data++ = 0;
- *data++ = obottom;
- *data++ = SHRT_MAX;
- *data++ = obottom;
- *data++ = oleft + w_w;
- *data++ = w_h + otop;
-
- //LEFT
- *data++ =
- ((GRAVITY_NORTH | GRAVITY_WEST) << 0) |
- ((GRAVITY_SOUTH | GRAVITY_WEST) << 4) |
- (0 << 8) | (0 << 10) | (XX_MASK) | (YY_MASK);
-
- *data++ = -oleft;
- *data++ = 0;
- *data++ = 0;
- *data++ = 0;
- *data++ = oleft;
- *data++ = w_h;
- *data++ = 0;
- *data++ = otop;
-
- *data++ =
- ((GRAVITY_NORTH | GRAVITY_WEST) << 0) |
- ((GRAVITY_SOUTH | GRAVITY_WEST) << 4) |
- (0 << 8) | (CLAMP_VERT << 10) | (XX_MASK);
-
- *data++ = -oleft;
- *data++ = w_h;
- *data++ = 0;
- *data++ = 0;
- *data++ = oleft;
- *data++ = SHRT_MAX;
- *data++ = 0;
- *data++ = otop + w_h;
-
- //RIGHT
- *data++ =
- ((GRAVITY_NORTH | GRAVITY_EAST) << 0) |
- ((GRAVITY_SOUTH | GRAVITY_EAST) << 4) |
- (0 << 8) | (0 << 10) | (XX_MASK) | (YY_MASK);
-
- *data++ = 0;
- *data++ = 0;
- *data++ = oright;
- *data++ = 0;
- *data++ = oright;
- *data++ = w_h;
- *data++ = w_w + oleft;
- *data++ = otop;
-
- *data++ =
- ((GRAVITY_NORTH | GRAVITY_EAST) << 0) |
- ((GRAVITY_SOUTH | GRAVITY_EAST) << 4) |
- (0 << 8) | (CLAMP_VERT << 10) | (XX_MASK);
-
- *data++ = 0;
- *data++ = w_h;
- *data++ = oright;
- *data++ = 0;
- *data++ = oright;
- *data++ = SHRT_MAX;
- *data++ = w_w + oleft;
- *data++ = otop + w_h;
-
- Aquamarine::trapXError ();
- XChangeProperty (qt_xdisplay (), m_wid,
- Atoms::net_window_decor,
- XA_INTEGER,
- 32, PropModeReplace, (unsigned char *)mdata,
- 15 + (12 * 9));
- Aquamarine::popXError ();
- XSync (qt_xdisplay (), FALSE);
- if (m_currentPixmap != None)
- XFreePixmap(qt_xdisplay(),m_currentPixmap);
- m_currentPixmap = pix;
+ XRenderFillRectangle (xdisplay, PictOpSrc, picture, &white,
+ x1,
+ y1,
+ x2 - x1,
+ y2 - y1);
}
-void
-Aquamarine::Window::setActive (bool active)
-{
- m_active = active;
- m_deco->activeChange ();
- resizeDecoration ();
+static void
+cornersFromQRegion (QRegion *region,
+ int width,
+ int height,
+ int left,
+ int right,
+ int top,
+ int bottom,
+ int *leftCorner,
+ int *rightCorner,
+ int *topCorner,
+ int *bottomCorner)
+{
+ QRegion l, r, t, b;
+
+ l = QRegion (0, top, left, height - top - bottom) - *region;
+ r = QRegion (width - right, top, right, height - top - bottom) - *region;
+ t = QRegion (0, 0, width, top) - *region;
+ b = QRegion (0, height - bottom, width, bottom) - *region;
+
+ if (l.isEmpty ())
+ *leftCorner = left;
+ else
+ *leftCorner = left -
+ (l.boundingRect ().x () + l.boundingRect ().width ());
+
+ if (r.isEmpty ())
+ *rightCorner = right;
+ else
+ *rightCorner = r.boundingRect ().x () - width + right;
+
+ if (t.isEmpty ())
+ *topCorner = top;
+ else
+ *topCorner = top -
+ (t.boundingRect ().y () + t.boundingRect ().height ());
+
+ if (b.isEmpty ())
+ *bottomCorner = bottom;
+ else
+ *bottomCorner = b.boundingRect ().y () - height + bottom;
}
void
-Aquamarine::Window::updateFrame (WId frame)
+Aquamarine::Window::updateShadow (void)
{
- m_frame = frame;
- if (m_deco && frame != handle())
+ Display *xdisplay = qt_xdisplay ();
+ Screen *xscreen = ScreenOfDisplay (xdisplay, qt_xscreen ());
+ XRenderPictFormat *xformat;
+ int leftCorner, rightCorner, topCorner, bottomCorner;
+
+ if (mShadow)
+ {
+ decor_shadow_destroy (qt_xdisplay (), mShadow);
+ mShadow = NULL;
+ }
+
+ if (mShapeSet)
+ {
+ cornersFromQRegion (&mShape,
+ mGeometry.width () + mBorder.left + mBorder.right,
+ mGeometry.height () + mBorder.top + mBorder.bottom,
+ mBorder.left,
+ mBorder.right,
+ mBorder.top,
+ mBorder.bottom,
+ &leftCorner,
+ &rightCorner,
+ &topCorner,
+ &bottomCorner);
+ }
+ else
+ {
+ leftCorner = mBorder.left;
+ rightCorner = mBorder.right;
+ topCorner = mBorder.top;
+ bottomCorner = mBorder.bottom;
+ }
+
+ /* use default shadow if such exist */
+ if (!mUniqueHorzShape && !mUniqueVertShape)
+ {
+ mShadow = Decorator::defaultWindowShadow (&mContext);
+ if (mShadow)
+ decor_shadow_reference (mShadow);
+ }
+
+ if (!mShadow)
{
- XEvent ev;
-
- memset (&ev, 0, sizeof (ev));
- ev.xclient.type = ClientMessage;
- ev.xclient.window = m_wid;
- ev.xclient.message_type = Atoms::change_frame_window;
- ev.xclient.format = 32;
- ev.xclient.data.l[0] = handle();
- ev.xclient.data.l[1] = TRUE;
- ev.xclient.data.l[2] = 0;
- ev.xclient.data.l[3] = 0;
- ev.xclient.data.l[4] = 0;
-
- XSendEvent (qt_xdisplay (), qt_xrootwin(), False,
- SubstructureRedirectMask | SubstructureNotifyMask, &ev);
+ mShadow = decor_shadow_create (xdisplay,
+ xscreen,
+ mUniqueHorzShape ?
+ mGeometry.width () : 1,
+ mUniqueVertShape ?
+ mGeometry.height () : 1,
+ mBorder.left,
+ mBorder.right,
+ mBorder.top,
+ mBorder.bottom,
+ leftCorner,
+ rightCorner,
+ topCorner,
+ bottomCorner,
+ Aquamarine::Decorator::shadowOptions (),
+ &mContext,
+ drawBorderShape,
+ (void *) this);
+
+ if (mType == Default)
+ Aquamarine::Decorator::updateDefaultShadow (this);
}
- if (m_deco && frame == handle())
+
+ /* create new layout */
+ if (mType == Normal || mType == Switcher)
+ decor_get_best_layout (&mContext,
+ mGeometry.width (),
+ mGeometry.height (),
+ &mLayout);
+ else
+ decor_get_default_layout (&mContext,
+ mGeometry.width (),
+ mGeometry.height (),
+ &mLayout);
+
+ if (mDecorationPicture)
+ XRenderFreePicture (qt_xdisplay (), mDecorationPicture);
+
+ if (mTexturePicture)
+ XRenderFreePicture (qt_xdisplay (), mTexturePicture);
+
+ if (!mTexturePixmapBuffer.isNull ())
+ mTexturePixmapBuffer.resize (0, 0);
+
+ if (!mTexturePixmap.isNull ())
+ mTexturePixmap.resize (0, 0);
+
+ mTexturePixmap = QPixmap (mLayout.width, mLayout.height, 32);
+ mTexturePixmapBuffer = QPixmap (mLayout.width, mLayout.height, 32);
+
+ xformat = XRenderFindStandardFormat (qt_xdisplay (),
+ PictStandardARGB32);
+
+ mDecorationPicture =
+ XRenderCreatePicture (qt_xdisplay (),
+ mTexturePixmap.handle (),
+ xformat, 0, NULL);
+ mTexturePicture =
+ XRenderCreatePicture (qt_xdisplay (),
+ mTexturePixmapBuffer.handle (),
+ xformat, 0, NULL);
+
+ decor_fill_picture_extents_with_shadow (qt_xdisplay (),
+ mShadow,
+ &mContext,
+ mTexturePicture,
+ &mLayout);
+
+ if (mPixmap)
{
- //updateWindowProperties ();
- XSelectInput (qt_xdisplay (), m_frame,
- defaultMask | ButtonPressMask | ButtonReleaseMask |
- PointerMotionMask | EnterWindowMask | LeaveWindowMask);
+ /* hm, update or repaint doesn't seem to do it */
+ mDecor->widget ()->hide ();
+ mDecor->widget ()->show ();
}
+
+ mUpdateProperty = true;
}
void
-Aquamarine::Window::updateWindowGeometry ()
+Aquamarine::Window::setMask (const QRegion &reg, int)
{
- int x, y;
- unsigned int width, height, border, depth;
- ::Window root;
- XGetGeometry (qt_xdisplay (), m_wid, &root, &x, &y, &width, &height,
- &border, &depth);
- m_geometry = QRect (x, y, width, height);
- resizeDecoration ();
+ QRegion top, bottom, left, right;
+ bool uniqueHorzShape, uniqueVertShape;
+
+ if (mShapeSet && reg == mShape)
+ return;
+
+ mShape = reg;
+ mShapeSet = true;
+
+ if (mFrame)
+ {
+ QRegion r;
+
+ r = reg - QRegion (mBorder.left, mBorder.top,
+ mGeometry.width (), mGeometry.height ());
+
+ Aquamarine::trapXError ();
+ XShapeCombineRegion (qt_xdisplay (),
+ mFrame,
+ ShapeInput,
+ 0,
+ 0,
+ r.handle (),
+ ShapeSet);
+ Aquamarine::popXError ();
+ }
+
+ top = QRegion (mBorder.left, 0,
+ mGeometry.width (), mBorder.top) - reg;
+ bottom = QRegion (mBorder.left, mGeometry.height () + mBorder.top,
+ mGeometry.width (), mBorder.bottom) - reg;
+ left = QRegion (0, mBorder.top, mBorder.left,
+ mGeometry.height ()) - reg;
+ right = QRegion (mBorder.left + mGeometry.width (), mBorder.top,
+ mBorder.right, mGeometry.height ()) - reg;
+
+ uniqueHorzShape = !top.isEmpty () || !bottom.isEmpty ();
+ uniqueVertShape = !left.isEmpty () || !right.isEmpty ();
+
+ if (uniqueHorzShape || mUniqueHorzShape ||
+ uniqueVertShape || mUniqueVertShape)
+ {
+ mUniqueHorzShape = uniqueHorzShape;
+ mUniqueVertShape = uniqueVertShape;
+
+ if (mPixmap)
+ updateShadow ();
+ }
}
-void
-Aquamarine::Window::updateConfig ()
+bool
+Aquamarine::Window::resizeDecoration (bool force)
{
- if (!m_deco) return;
+ int w, h;
- double op = Settings::shadowOpacity() / 100.0;
- op *= 0xffff;
+ mDecor->borders (mBorder.left, mBorder.right, mBorder.top, mBorder.bottom);
- m_sradius = Settings::shadowRadius();
- QColor color = Settings::shadowColor();
- m_scolor[0] = short((color.red() / 256.0) * 0xffff);
- m_scolor[1] = short((color.green() / 256.0) * 0xffff);
- m_scolor[2] = short((color.blue() / 256.0) * 0xffff);
- m_scolor[3] = short(op);
+ w = mGeometry.width () + mBorder.left + mBorder.right;
+ h = mGeometry.height () + mBorder.top + mBorder.bottom;
- int offX = Settings::shadowOffsetX();
- int offY = Settings::shadowOffsetY();
- offX = KMAX(-m_sradius,KMIN(m_sradius,offX));
- offY = KMAX(-m_sradius,KMIN(m_sradius,offY));
+ if (!force)
+ {
+ if (w == width () && h == height ())
+ return FALSE;
+ }
+
+ /* reset shape */
+ mShapeSet = false;
+ mUniqueHorzShape = false;
+ mUniqueVertShape = false;
+
+ if (mType != Normal && mType != Switcher)
+ {
+ Display *xdisplay = qt_xdisplay ();
+ Screen *xscreen = ScreenOfDisplay (xdisplay, qt_xscreen ());
+ decor_shadow_t *tmpShadow;
+ decor_context_t c;
+
+ /* XXX: we have to create a temporary shadow to get the client
+ geometry. libdecoration should be fixed so it's able to just
+ fill out a context struct and not necessarily generate a
+ shadow for this purpose. */
+ tmpShadow = decor_shadow_create (xdisplay,
+ xscreen,
+ 1, 1,
+ mBorder.left,
+ mBorder.right,
+ mBorder.top,
+ mBorder.bottom,
+ mBorder.left,
+ mBorder.right,
+ mBorder.top,
+ mBorder.bottom,
+ Aquamarine::Decorator::shadowOptions (),
+ &c,
+ decor_draw_simple,
+ (void *) 0);
+
+ decor_shadow_destroy (xdisplay, tmpShadow);
+
+ w = c.left_corner_space + 1 + c.right_corner_space;
+
+ /* most styles render something useful at least 30 px width */
+ if (w < 30)
+ w = 30;
+
+ mGeometry = QRect (50, 50, w,
+ c.top_corner_space + 1 + c.bottom_corner_space);
+ }
- m_deco->widget()->move(m_soffset.left(),m_soffset.top());
+ w = mGeometry.width () + mBorder.left + mBorder.right;
+ h = mGeometry.height () + mBorder.top + mBorder.bottom;
- if (Settings::drawShadows())
- m_soffset.setCoords(-m_sradius + offX,-m_sradius + offY,
- m_sradius + offX,m_sradius + offY);
+ if (mPixmap)
+ {
+ XFreePixmap (qt_xdisplay (), mPixmap);
+ mPixmap = None;
+ }
+
+ if (mPicture)
+ {
+ XRenderFreePicture (qt_xdisplay (), mPicture);
+ mPicture = 0;
+ }
+
+ setGeometry (QRect (mGeometry.x () + ROOT_OFF_X - mBorder.left,
+ mGeometry.y () + ROOT_OFF_Y - mBorder.top,
+ w, h));
+
+ if (mMapped)
+ {
+ mPendingConfigure++;
+ }
else
- m_soffset.setCoords(0,0,0,0);
+ {
+ mPendingMap = 1;
+
+ show ();
- m_deco->widget()->move(-m_soffset.left(),-m_soffset.top());
+ mMapped = true;
- resizeDecoration();
- updateWindowProperties();
+ /* XXX: is there a more appropriate way to achieve this?
+ add WType_TopLevel flag so that visualRect isn't clipped
+ to parent. */
+ setWFlags (getWFlags () | WType_TopLevel);
- if (m_shapeSet)
+ if (mDamageId != winId ())
{
- m_shapeChange = m_shape;
- renderShadow();
+ mDamageId = winId ();
+ XDamageCreate (qt_xdisplay (), mDamageId,
+ XDamageReportRawRectangles);
}
+ }
+
+ mDecor->resize (QSize (w, h));
+ mDecor->widget ()->show ();
+
+ return TRUE;
}
void
-Aquamarine::Window::reloadDecoration ()
+Aquamarine::Window::rebindPixmap (void)
{
- delete m_deco;
- m_deco = 0;
+ XRenderPictFormat *xformat;
+ QPaintEvent *e;
+
+ if (mPicture)
+ XRenderFreePicture (qt_xdisplay (), mPicture);
+
+ if (mPixmap)
+ XFreePixmap (qt_xdisplay (), mPixmap);
+
+ mPixmap = XCompositeNameWindowPixmap (qt_xdisplay (), winId ());
- createDecoration ();
+ xformat = XRenderFindVisualFormat (qt_xdisplay (),
+ (Visual *) x11Visual ());
+
+ mPicture = XRenderCreatePicture (qt_xdisplay (), mPixmap,
+ xformat, 0, NULL);
+
+ updateShadow ();
+
+ e = new QPaintEvent (mDecor->widget ()->rect (), false);
+ QApplication::postEvent (mDecor->widget (), e);
}
-void
-Aquamarine::Window::updateCursor (QPoint pos)
+bool
+Aquamarine::Window::handleMap (void)
{
- switch (m_deco->mousePosition (pos))
- {
- case PositionCenter:
- XDefineCursor (qt_xdisplay (), m_frame, cursors[1][1].cursor);
- break;
- case PositionLeft:
- XDefineCursor (qt_xdisplay (), m_frame, cursors[1][0].cursor);
- break;
- case PositionRight:
- XDefineCursor (qt_xdisplay (), m_frame, cursors[1][2].cursor);
- break;
- case PositionTop:
- XDefineCursor (qt_xdisplay (), m_frame, cursors[0][1].cursor);
- break;
- case PositionBottom:
- XDefineCursor (qt_xdisplay (), m_frame, cursors[2][1].cursor);
- break;
- case PositionTopLeft:
- XDefineCursor (qt_xdisplay (), m_frame, cursors[0][0].cursor);
- break;
- case PositionTopRight:
- XDefineCursor (qt_xdisplay (), m_frame, cursors[0][2].cursor);
- break;
- case PositionBottomLeft:
- XDefineCursor (qt_xdisplay (), m_frame, cursors[2][0].cursor);
- break;
- case PositionBottomRight:
- XDefineCursor (qt_xdisplay (), m_frame, cursors[2][2].cursor);
- break;
- default:
- XDefineCursor (qt_xdisplay (), m_frame, cursors[1][1].cursor);
- break;
- }
+ if (!mPendingMap)
+ return FALSE;
+
+ mPendingMap = 0;
+ if (mPendingConfigure)
+ return FALSE;
+
+ rebindPixmap ();
+
+ return TRUE;
}
-void
-Aquamarine::Window::getWindowProtocols ()
-{
- Atom *p;
- int i, n;
-
- m_supportDeleteWindow = false;
- m_supportTakeFocus = false;
- m_supportTakeActivity = false;
- m_supportContextHelp = false;
- m_supportPing = false;
-
- if (XGetWMProtocols (qt_xdisplay (), m_wid, &p, &n))
- {
- for (i = 0; i < n; i++)
- if (p[i] == Atoms::wm_delete_window)
- m_supportDeleteWindow = true;
- else if (p[i] == Atoms::wm_take_focus)
- m_supportTakeFocus = true;
- else if (p[i] == Atoms::net_wm_take_activity)
- m_supportTakeActivity = true;
- else if (p[i] == Atoms::net_wm_context_help)
- m_supportContextHelp = true;
- else if (p[i] == Atoms::net_wm_ping)
- m_supportPing = true;
- if (n > 0)
- XFree (p);
- }
+bool
+Aquamarine::Window::handleConfigure (void)
+{
+ if (!mPendingConfigure)
+ return FALSE;
+
+ mPendingConfigure--;
+ if (mPendingConfigure || mPendingMap)
+ return FALSE;
+
+ rebindPixmap ();
+
+ return TRUE;
}
void
-Aquamarine::Window::slotPopupActivated (int id)
-{
- WindowOperation
- op = static_cast < WindowOperation > (id);
- performWindowOperation (op);
+Aquamarine::Window::updateProperty (void)
+{
+ Atom atom = Atoms::netWindowDecor;
+ decor_extents_t maxExtents;
+ long data[256];
+ decor_quad_t quads[N_QUADS_MAX];
+ int nQuad;
+ int lh, rh;
+ int w;
+ int minWidth;
+ unsigned int saveState;
+
+ if (mType == Default)
+ atom = Atoms::netWindowDecorNormal;
+ else if (mType == DefaultActive)
+ atom = Atoms::netWindowDecorActive;
+
+ saveState = mState;
+ mState = NET::MaxVert | NET::MaxHoriz;
+ mDecor->borders (maxExtents.left, maxExtents.right,
+ maxExtents.top, maxExtents.bottom);
+ mState = saveState;
+
+ if (mLayout.rotation)
+ lh = mLayout.left.x2 - mLayout.left.x1;
+ else
+ lh = mLayout.left.y2 - mLayout.left.y1;
+
+ if (mLayout.rotation)
+ rh = mLayout.right.x2 - mLayout.right.x1;
+ else
+ rh = mLayout.right.y2 - mLayout.right.y1;
+
+ w = mLayout.top.x2 - mLayout.top.x1 - mContext.left_space -
+ mContext.right_space;
+
+ if (mType == Normal || mType == Switcher)
+ {
+ int topXOffset = w / 2;
+
+ if (mDecor)
+ {
+ const QObjectList *children = mDecor->widget ()->children ();
+ QWidget *child;
+ int x;
+
+ x = w - mContext.left_space - mContext.left_corner_space;
+ if (x > topXOffset)
+ topXOffset = x;
+
+ for (QObjectListIt it(*children); it.current (); ++it)
+ {
+ if (!it.current ()->isWidgetType ())
+ continue;
+
+ child = static_cast <QWidget *> (it.current ());
+
+ x = child->x () - mBorder.left - 2;
+ if (x > w / 2 && x < topXOffset)
+ topXOffset = x;
+ }
+ }
+
+ nQuad = decor_set_lXrXtXbX_window_quads (quads,
+ &mContext,
+ &mLayout,
+ lh / 2,
+ rh / 2,
+ topXOffset,
+ w / 2);
+
+ minWidth = mContext.left_corner_space + 1 + mContext.right_corner_space;
+ }
+ else
+ {
+ nQuad = decor_set_lSrStSbS_window_quads (quads, &mContext, &mLayout);
+
+ minWidth = 1;
+ }
+
+ decor_quads_to_property (data, mTexturePixmap.handle (),
+ &mBorder, &maxExtents,
+ minWidth, 0,
+ quads, nQuad);
+
+ Aquamarine::trapXError ();
+ XChangeProperty (qt_xdisplay (), mClientId, atom,
+ XA_INTEGER,
+ 32, PropModeReplace, (unsigned char *) data,
+ BASE_PROP_SIZE + QUAD_PROP_SIZE * nQuad);
+ Aquamarine::popXError ();
+
+ mUpdateProperty = false;
}
void
-Aquamarine::Window::slotPopupAboutToShow ()
-{
- m_popup->setItemEnabled (Options::ResizeOp, isResizable ());
- m_popup->setItemEnabled (Options::MoveOp, isMovable ());
-
- m_popup->setItemEnabled (Options::MaximizeOp, isMaximizable ());
- m_popup->setItemChecked (Options::MaximizeOp,
- maximizeMode () == MaximizeFull);
-
- m_popup->setItemChecked (Options::ShadeOp, isShade ());
- m_popup->setItemEnabled (Options::ShadeOp, isShadeable ());
-
- m_advanced_popup->setItemChecked (Options::KeepAboveOp, keepAbove ());
- m_advanced_popup->setItemChecked (Options::KeepBelowOp, keepBelow ());
- m_advanced_popup->setItemChecked (Options::FullScreenOp, m_state & NET::FullScreen);
-
- m_popup->setItemEnabled (Options::MinimizeOp, isMinimizable ());
- m_popup->setItemEnabled (Options::CloseOp, isCloseable ());
-
-
- m_opacity_menu->setItemEnabled (ChangeOpacity25, m_opacity != 0x3fff);
- m_opacity_menu->setItemEnabled (ChangeOpacity50, m_opacity != 0x7fff);
- m_opacity_menu->setItemEnabled (ChangeOpacity75, m_opacity != 0xbfff);
- m_opacity_menu->setItemEnabled (ChangeOpacity100, m_opacity != 0xffff);
-
- m_brightness_menu->setItemEnabled (ChangeBrightness25,
- m_brightness != 0x3fff);
- m_brightness_menu->setItemEnabled (ChangeBrightness50,
- m_brightness != 0x7fff);
- m_brightness_menu->setItemEnabled (ChangeBrightness75,
- m_brightness != 0xbfff);
- m_brightness_menu->setItemEnabled (ChangeBrightness100,
- m_brightness != 0xffff);
-
- m_saturation_menu->setItemEnabled (ChangeSaturation25,
- m_saturation != 0x3fff);
- m_saturation_menu->setItemEnabled (ChangeSaturation50,
- m_saturation != 0x7fff);
- m_saturation_menu->setItemEnabled (ChangeSaturation75,
- m_saturation != 0xbfff);
- m_saturation_menu->setItemEnabled (ChangeSaturation100,
- m_saturation != 0xffff);
-
- m_appearance_menu->setItemEnabled (ResetValues, m_opacity != 0xffff
- || m_brightness != 0xffff
- || m_saturation != 0xffff);
-
- m_viewport_menu->setItemChecked (0, desktop () == NET::OnAllDesktops);
- for (int i = 1;
- i <=
- Decorator::viewports ().width () * Decorator::viewports ().height ();
- ++i)
- {
- if (Decorator::
- onViewport (QPoint (m_geometry.x (), m_geometry.y ())) == i)
- {
- m_viewport_menu->setItemEnabled (i, false);
- }
- else
- {
- m_viewport_menu->setItemEnabled (i, true);
- }
- }
+Aquamarine::Window::handleActiveChange (void)
+{
+ mDecor->activeChange ();
+ resizeDecoration ();
}
void
-Aquamarine::Window::updateState ()
-{
- KWin::WindowInfo wInf = KWin::windowInfo (m_wid, NET::WMState, 0);
- unsigned long
- newState = wInf.state ();
- unsigned long
- stateChange = m_state ^ newState;
- m_state = newState;
-
- if (stateChange & NET::Max)
- {
- m_deco->maximizeChange ();
- resizeDecoration ();
- }
- if (stateChange & NET::KeepAbove && !(m_state & NET::KeepAbove))
- m_deco->emitKeepAboveChanged (m_state & NET::KeepAbove);
- if (stateChange & NET::KeepBelow && !(m_state & NET::KeepBelow))
- m_deco->emitKeepBelowChanged (m_state & NET::KeepBelow);
- if (stateChange & NET::KeepAbove && m_state & NET::KeepAbove)
- m_deco->emitKeepAboveChanged (m_state & NET::KeepAbove);
- if (stateChange & NET::KeepBelow && m_state & NET::KeepBelow)
- m_deco->emitKeepBelowChanged (m_state & NET::KeepBelow);
- if (stateChange & NET::Shaded)
- m_deco->shadeChange ();
- if (stateChange & NET::Sticky)
- m_deco->desktopChange ();
+Aquamarine::Window::updateFrame (WId frame)
+{
+ mFrame = frame;
+
+ Aquamarine::trapXError ();
+ XSelectInput (qt_xdisplay (), mFrame,
+ StructureNotifyMask | PropertyChangeMask |
+ ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
+ EnterWindowMask | LeaveWindowMask);
+ Aquamarine::popXError ();
}
void
-Aquamarine::Window::updateName ()
+Aquamarine::Window::updateSelected (WId selectedId)
{
- m_name = KWin::readNameProperty (m_wid, XA_WM_NAME);
- m_deco->captionChange ();
+ mSelectedId = selectedId;
+
+ updateName ();
}
void
-Aquamarine::Window::updateIcons ()
+Aquamarine::Window::updateWindowGeometry (void)
{
- kdDebug () << k_funcinfo << endl;
- m_icons =
- QIconSet (KWin::icon (m_wid, 16, 16, TRUE),
- KWin::icon (m_wid, 32, 32, TRUE));
- m_deco->iconChange ();
+ unsigned int w, h, bw, d;
+ int x, y;
+ XID root;
+
+ Aquamarine::trapXError ();
+ XGetGeometry (qt_xdisplay (), mClientId, &root, &x, &y, &w, &h, &bw, &d);
+ if (Aquamarine::popXError ())
+ return;
+
+ w += bw * 2;
+ h += bw * 2;
+
+ mGeometry = QRect (x, y, w, h);
+ if (resizeDecoration ())
+ return;
+
+ move (x + ROOT_OFF_X - mBorder.left,
+ y + ROOT_OFF_Y - mBorder.top);
}
void
-Aquamarine::Window::slotChangeViewport (int id)
+Aquamarine::Window::reloadDecoration (void)
{
- if (id == 0)
- setDesktop ((desktop () ==
- NET::OnAllDesktops) ? 1 : NET::OnAllDesktops);
- else
- Decorator::moveToViewport (m_wid, id);
+ delete mDecor;
+ mDecor = 0;
+
+ setWFlags (getWFlags () & ~WType_TopLevel);
+ hide ();
+
+ mMapped = false;
+ mShapeSet = false;
+
+ if (mShadow)
+ {
+ decor_shadow_destroy (qt_xdisplay (), mShadow);
+ mShadow = NULL;
+ }
+
+ createDecoration ();
+}
+
+Cursor
+Aquamarine::Window::positionToCursor (QPoint pos)
+{
+ switch (mDecor->mousePosition (pos)) {
+ case PositionCenter:
+ return cursors[1][1].cursor;
+ case PositionLeft:
+ return cursors[1][0].cursor;
+ case PositionRight:
+ return cursors[1][2].cursor;
+ case PositionTop:
+ return cursors[0][1].cursor;
+ case PositionBottom:
+ return cursors[2][1].cursor;
+ case PositionTopLeft:
+ return cursors[0][0].cursor;
+ case PositionTopRight:
+ return cursors[0][2].cursor;
+ case PositionBottomLeft:
+ return cursors[2][0].cursor;
+ case PositionBottomRight:
+ return cursors[2][2].cursor;
+ default:
+ break;
+ }
+
+ return cursors[1][1].cursor;
}
void
-Aquamarine::Window::slotAppearanceChange (int id)
-{
- switch (id)
- {
- case ResetValues:
- setWindowProperty (m_wid, Atoms::opacity, 0xffff);
- setWindowProperty (m_wid, Atoms::brightness, 0xffff);
- setWindowProperty (m_wid, Atoms::saturation, 0xffff);
- break;
- case ChangeOpacity25:
- setWindowProperty (m_wid, Atoms::opacity, 0x3fff);
- break;
- case ChangeOpacity50:
- setWindowProperty (m_wid, Atoms::opacity, 0x7fff);
- break;
- case ChangeOpacity75:
- setWindowProperty (m_wid, Atoms::opacity, 0xbfff);
- break;
- case ChangeOpacity100:
- setWindowProperty (m_wid, Atoms::opacity, 0xffff);
- break;
- case ChangeBrightness25:
- setWindowProperty (m_wid, Atoms::brightness, 0x3fff);
- break;
- case ChangeBrightness50:
- setWindowProperty (m_wid, Atoms::brightness, 0x7fff);
- break;
- case ChangeBrightness75:
- setWindowProperty (m_wid, Atoms::brightness, 0xbfff);
- break;
- case ChangeBrightness100:
- setWindowProperty (m_wid, Atoms::brightness, 0xffff);
- break;
- case ChangeSaturation25:
- setWindowProperty (m_wid, Atoms::saturation, 0x3fff);
- break;
- case ChangeSaturation50:
- setWindowProperty (m_wid, Atoms::saturation, 0x7fff);
- break;
- case ChangeSaturation75:
- setWindowProperty (m_wid, Atoms::saturation, 0xbfff);
- break;
- case ChangeSaturation100:
- setWindowProperty (m_wid, Atoms::saturation, 0xffff);
- break;
- default:
- break;
- }
+Aquamarine::Window::updateCursor (QPoint pos)
+{
+ Aquamarine::trapXError ();
+ XDefineCursor (qt_xdisplay (), mFrame, positionToCursor (pos));
+ Aquamarine::popXError ();
}
void
-Aquamarine::Window::moveWindow (QMouseEvent * qme)
-{
- if (!qme)
- return;
- int
- direction = WM_MOVERESIZE_MOVE;
- switch (m_deco->mousePosition (qme->pos ()))
- {
-
- case PositionCenter:
- direction = WM_MOVERESIZE_MOVE;
- break;
- case PositionLeft:
- direction = WM_MOVERESIZE_SIZE_LEFT;
- break;
- case PositionRight:
- direction = WM_MOVERESIZE_SIZE_RIGHT;
- break;
- case PositionTop:
- direction = WM_MOVERESIZE_SIZE_TOP;
- break;
- case PositionBottom:
- direction = WM_MOVERESIZE_SIZE_BOTTOM;
- break;
- case PositionTopLeft:
- direction = WM_MOVERESIZE_SIZE_TOPLEFT;
- break;
- case PositionTopRight:
- direction = WM_MOVERESIZE_SIZE_TOPRIGHT;
- break;
- case PositionBottomLeft:
- direction = WM_MOVERESIZE_SIZE_BOTTOMLEFT;
- break;
- case PositionBottomRight:
- direction = WM_MOVERESIZE_SIZE_BOTTOMRIGHT;
- break;
- default:
- direction = WM_MOVERESIZE_MOVE;
- break;
- }
-
- XEvent
- ev;
- ev.xclient.type = ClientMessage;
- ev.xclient.display = qt_xdisplay ();
-
- ev.xclient.serial = 0;
- ev.xclient.send_event = TRUE;
-
- ev.xclient.window = m_wid;
- ev.xclient.message_type = Atoms::net_wm_moveresize;
- ev.xclient.format = 32;
-
- ev.xclient.data.l[0] = qme->globalX ();
- ev.xclient.data.l[1] = qme->globalY ();
- ev.xclient.data.l[2] = direction;
- ev.xclient.data.l[3] = qme->button ();
- ev.xclient.data.l[4] = 1;
-
- XUngrabPointer (qt_xdisplay (), CurrentTime);
- XUngrabKeyboard (qt_xdisplay (), CurrentTime);
-
- XSendEvent (qt_xdisplay (), RootWindow (qt_xdisplay (), qt_xscreen ()),
- FALSE, SubstructureRedirectMask | SubstructureNotifyMask,
- &ev);
-
- XSync (qt_xdisplay (), FALSE);
-}
-
-void Aquamarine::Window::slotDesktopGeometryChanged()
+Aquamarine::Window::getWindowProtocols (void)
{
- // force menu regeneration
- delete m_popup;
- m_popup = 0;
-}
-
-
-void Aquamarine::Window::performMouseCommand(Options::MouseCommand command, QMouseEvent *qme)
-{
- switch (command)
- {
- case Options::MouseRaise:
- case Options::MouseActivateAndRaise:
- KWin::raiseWindow (m_wid);
- break;
- case Options::MouseLower:
- KWin::lowerWindow (m_wid);
- break;
- case Options::MouseShade :
- setShade (!isShade ());
- break;
- case Options::MouseSetShade:
- setShade (true);
- break;
- case Options::MouseUnsetShade:
- setShade (false);
- break;
- case Options::MouseOperationsMenu:
- {
- QPoint mp(0,0);
- if (qme)
- mp = QPoint(qme->globalX (), qme->globalY ());
- showWindowMenu (mp);
- break;
- }
- case Options::MouseMaximize:
- maximize( KDecoration::MaximizeFull );
- break;
- case Options::MouseRestore:
- maximize( KDecoration::MaximizeRestore );
- break;
- case Options::MouseMinimize:
- minimize();
- break;
- case Options::MouseAbove:
- {
- if( keepBelow())
- setKeepBelow( false );
- else
- setKeepAbove( true );
- break;
- }
- case Options::MouseBelow:
- {
- if( keepAbove())
- setKeepAbove( false );
- else
- setKeepBelow( true );
- break;
- }
- case Options::MousePreviousDesktop:
- {
- int vp = Decorator::onViewport (m_geometry.topLeft ());
- Decorator::moveToViewport (m_wid, vp-1);
- break;
- }
- case Options::MouseNextDesktop:
- {
- int vp = Decorator::onViewport (m_geometry.topLeft ());
- Decorator::moveToViewport (m_wid, vp+1);
- break;
- }
- case Options::MouseOpacityMore:
- if (m_opacity < 0xFFFF)
- {
- if (m_opacity < 0xF333)
- setWindowProperty (m_wid, Atoms::opacity, m_opacity + 0xCCC);
- else
- setWindowProperty (m_wid, Atoms::opacity, 0xFFFF);
- }
- break;
- case Options::MouseOpacityLess:
- if (m_opacity > 0)
- setWindowProperty (m_wid, Atoms::opacity, (m_opacity > 0xCCC)? m_opacity - 0xCCC : 0);
- break;
- case Options::MouseActivateRaiseAndMove:
- case Options::MouseActivateRaiseAndUnrestrictedMove:
- case Options::MouseMove:
- case Options::MouseUnrestrictedMove:
- case Options::MouseResize:
- case Options::MouseUnrestrictedResize:
- moveWindow (qme);
- break;
- case Options::MouseNothing:
- default:
- break;
- }
-}
-
-void Aquamarine::Window::setMapping (bool map)
-{
- m_mapped = map;
- if (!m_mapped)
- m_shapeSet = false;
-}
-
-void Aquamarine::Window::updateWindow ()
-{
- if (!m_mapped) return;
-
- if (m_updatePixmap)
+ Atom *p;
+ int n;
+ int status;
+
+ mSupportTakeFocus = false;
+ mSupportContextHelp = false;
+
+ Aquamarine::trapXError ();
+ status = XGetWMProtocols (qt_xdisplay (), mClientId, &p, &n);
+ if (Aquamarine::popXError ())
+ return;
+
+ if (status)
+ {
+ int i;
+
+ for (i = 0; i < n; i++)
{
- updateWindowProperties();
- m_updatePixmap = false;
+ if (p[i] == Atoms::wmTakeFocus)
+ mSupportTakeFocus = true;
+ else if (p[i] == Atoms::netWmContextHelp)
+ mSupportContextHelp = true;
+ }
+
+ if (n > 0)
+ XFree (p);
}
- renderShadow();
}
-#if INT_MAX != LONG_MAX
-/* XRenderSetPictureFilter used to be broken on LP64. This
- * works with either the broken or fixed version.
- */
-static void
-XRenderSetPictureFilter_wrapper (Display *dpy,
- Picture picture,
- char *filter,
- XFixed *params,
- int nparams)
+void
+Aquamarine::Window::handlePopupActivated (int id)
{
- Aquamarine::trapXError ();
- XRenderSetPictureFilter (dpy, picture, filter, params, nparams);
- XSync (dpy, False);
- if (Aquamarine::popXError ())
- {
- long *long_params = new long[nparams];
- int i;
+ WindowOperation op = static_cast <WindowOperation> (id);
- for (i = 0; i < nparams; i++)
- long_params[i] = params[i];
+ performWindowOperation (op);
+}
- XRenderSetPictureFilter (dpy, picture, filter,
- (XFixed *) long_params, nparams);
- delete long_params;
- }
+void
+Aquamarine::Window::handleDesktopPopupActivated (int id)
+{
+ if (id)
+ setDesktop (id);
+ else
+ KWin::setOnAllDesktops (mClientId, true);
}
+void
+Aquamarine::Window::handlePopupAboutToShow (void)
+{
+ int numberOfDesktops;
-#define XRenderSetPictureFilter XRenderSetPictureFilter_wrapper
-#endif
+ numberOfDesktops = KWin::numberOfDesktops ();
+ if (numberOfDesktops > 1)
+ {
+ NETRootInfo *rootInfo = Decorator::rootInfo ();
+ QString name;
+ int id, i;
+ int winDesktop = desktop ();
-#define SIGMA(r) ((r) / 2.0)
-#define ALPHA(r) (r)
+ mDesktopMenu->clear ();
-void Aquamarine::Window::renderShadow ()
-{
- if (m_shapeChange.isEmpty() || !Settings::drawShadows()) return;
- kdDebug () << k_funcinfo << endl;
+ id = mDesktopMenu->insertItem (i18n ("&All Desktops"), 0);
- int top, bottom, left, right;
- m_deco->borders (left, right, top, bottom);
+ mDesktopMenu->setItemChecked (id, (winDesktop == NET::OnAllDesktops));
+ mDesktopMenu->insertSeparator ();
- renderShadow(m_shapeChange.intersect(QRegion(0,0,m_deco->width(),top)));
- renderShadow(m_shapeChange.intersect(QRegion(0,m_deco->height() - bottom,m_deco->width(),bottom)));
- renderShadow(m_shapeChange.intersect(QRegion(0,top,left,m_geometry.height())));
- renderShadow(m_shapeChange.intersect(QRegion(m_deco->width() - right,top,right,m_geometry.height())));
+ for (i = 1; i <= numberOfDesktops; i++)
+ {
+ QString name;
- m_shapeChange = QRegion();
-}
+ name =
+ QString ("&%1 ").arg (i) +
+ QString (rootInfo->desktopName (i)).replace ('&', "&&");
-void Aquamarine::Window::renderShadow (QRegion reg)
-{
+ id = mDesktopMenu->insertItem (name, i);
+ mDesktopMenu->setItemChecked (id, (winDesktop == i));
+ }
- if (reg.isEmpty())
- return;
+ mPopup->setItemVisible (Options::NoOp, true);
+ }
+ else
+ {
+ mPopup->setItemVisible (Options::NoOp, false);
+ }
+
+ mViewportMenu->setItemChecked (0, desktop () == NET::OnAllDesktops);
+ for (int i = 1;i <=
+ Decorator::viewports ().width () * Decorator::viewports ().height ();
+ ++i)
+ {
+ if (Decorator:: onViewport (QPoint (mGeometry.x (), mGeometry.y ())) == i)
+ {
+ mViewportMenu->setItemEnabled (i, false);
+ }
+ else
+ {
+ mViewportMenu->setItemEnabled (i, true);
+ }
+ }
- int s2 = m_sradius * 2;
+ mPopup->setItemEnabled (Options::ResizeOp, isResizable ());
+ mPopup->setItemEnabled (Options::MoveOp, isMovable ());
- QRect rect = reg.boundingRect();
+ mPopup->setItemEnabled (Options::MaximizeOp, isMaximizable ());
+ mPopup->setItemChecked (Options::MaximizeOp,
+ maximizeMode () == MaximizeFull);
- rect.setLeft(rect.left() - s2);
- rect.setTop(rect.top() - s2);
- rect.setRight(rect.right() + s2);
- rect.setBottom(rect.bottom() + s2);
+ mPopup->setItemChecked (Options::ShadeOp, isShade ());
+ mPopup->setItemEnabled (Options::ShadeOp, isShadeable ());
- QRegion bound(rect);
- bound = m_shape.intersect(bound);
+ mAdvancedMenu->setItemChecked (Options::KeepAboveOp, keepAbove ());
+ mAdvancedMenu->setItemChecked (Options::KeepBelowOp, keepBelow ());
+ mAdvancedMenu->setItemChecked (Options::FullScreenOp,
+ mState & NET::FullScreen);
- bound.translate(-rect.left(),-rect.top());
+ mPopup->setItemEnabled (Options::MinimizeOp, isMinimizable ());
+ mPopup->setItemEnabled (Options::CloseOp, isCloseable ());
- QPixmap qRegPix(rect.width(), rect.height(), 32);
- QPixmap qTmpPix(rect.width() + s2, rect.height(), 32);
- qRegPix.fill( QColor(0,0));
+ mOpacityMenu->setItemEnabled (ChangeOpacity25, mOpacity != 0x3fff);
+ mOpacityMenu->setItemEnabled (ChangeOpacity50, mOpacity != 0x7fff);
+ mOpacityMenu->setItemEnabled (ChangeOpacity75, mOpacity != 0xbfff);
+ mOpacityMenu->setItemEnabled (ChangeOpacity100, mOpacity != 0xffff);
- QPainter p(&qRegPix);
- QBrush b(QColor(0, ((m_scolor[3] >> 8) << 24) + 0xffffff));
- p.setClipRegion(bound);
- p.fillRect(0, 0, rect.width(), rect.height(), b);
+ mBrightnessMenu->setItemEnabled (ChangeBrightness25,
+ mBrightness != 0x3fff);
+ mBrightnessMenu->setItemEnabled (ChangeBrightness50,
+ mBrightness != 0x7fff);
+ mBrightnessMenu->setItemEnabled (ChangeBrightness75,
+ mBrightness != 0xbfff);
+ mBrightnessMenu->setItemEnabled (ChangeBrightness100,
+ mBrightness != 0xffff);
- XFixed *params;
- int n_params = 0;
- int size;
+ mSaturationMenu->setItemEnabled (ChangeSaturation25,
+ mSaturation != 0x3fff);
+ mSaturationMenu->setItemEnabled (ChangeSaturation50,
+ mSaturation != 0x7fff);
+ mSaturationMenu->setItemEnabled (ChangeSaturation75,
+ mSaturation != 0xbfff);
+ mSaturationMenu->setItemEnabled (ChangeSaturation100,
+ mSaturation != 0xffff);
- params = createGaussianKernel (&size);
+ mAppearanceMenu->setItemEnabled (ResetValues, mOpacity != 0xffff
+ || mBrightness != 0xffff || mSaturation != 0xffff);
- n_params = size + 2;
- size = size / 2;
+}
- params[0] = (n_params - 2) << 16;
- params[1] = 1 << 16;
+void
+Aquamarine::Window::updateState (void)
+{
+ KWin::WindowInfo wInfo = KWin::windowInfo (mClientId, NET::WMState, 0);
+ unsigned long newState = wInfo.state ();
+ unsigned long stateChange = mState ^ newState;
- XRenderPictFormat *format;
- format = XRenderFindStandardFormat (qt_xdisplay(), PictStandardARGB32);
+ mState = newState;
- char *filter = NULL;
- XFilters* filters = XRenderQueryFilters (qt_xdisplay(), qRegPix.handle());
- if (filters)
+ if (stateChange & NET::Max)
{
- int i;
+ mDecor->maximizeChange ();
+ resizeDecoration (false);
+ }
- for (i = 0; i < filters->nfilter; i++)
- {
- if (strcmp (filters->filter[i], FilterConvolution) == 0)
- {
- filter = (char *) FilterConvolution;
- break;
- }
- }
+ if (stateChange & NET::KeepAbove && !(mState & NET::KeepAbove))
+ mDecor->emitKeepAboveChanged (mState & NET::KeepAbove);
+ if (stateChange & NET::KeepBelow && !(mState & NET::KeepBelow))
+ mDecor->emitKeepBelowChanged (mState & NET::KeepBelow);
+ if (stateChange & NET::KeepAbove && mState & NET::KeepAbove)
+ mDecor->emitKeepAboveChanged (mState & NET::KeepAbove);
+ if (stateChange & NET::KeepBelow && mState & NET::KeepBelow)
+ mDecor->emitKeepBelowChanged (mState & NET::KeepBelow);
+ if (stateChange & NET::Shaded)
+ mDecor->shadeChange ();
+ if (stateChange & NET::Sticky)
+ mDecor->desktopChange ();
+}
- XFree (filters);
- }
- if (!filter)
+void
+Aquamarine::Window::updateName (void)
+{
+ if (mType == Switcher)
+ {
+ if (!mSelectedId)
return;
- static XRenderColor white = { 0xffff, 0xffff, 0xffff, 0xffff };
+ mName = KWin::readNameProperty (mSelectedId, XA_WM_NAME);
+ }
+ else
+ {
+ mName = KWin::readNameProperty (mClientId, XA_WM_NAME);
+ }
- Picture fill = XRenderCreateSolidFill (qt_xdisplay(), &white);
- Picture src = XRenderCreatePicture(qt_xdisplay(), qRegPix.handle(), format, 0, NULL);
- Picture tmp = XRenderCreatePicture(qt_xdisplay(), qTmpPix.handle(), format, 0, NULL);
- Picture dst = XRenderCreatePicture(qt_xdisplay(), handle(), format, 0, NULL);
+ mDecor->captionChange ();
+}
- setPictureTransform(src,size,0);
- XRenderSetPictureFilter (qt_xdisplay(), src, filter, params, n_params);
- XRenderComposite (qt_xdisplay(), PictOpSrc, fill, src, tmp, 0, 0, 0, 0, 0, 0, rect.width() + s2, rect.height());
+void
+Aquamarine::Window::updateIcons (void)
+{
+ mIcons = QIconSet (KWin::icon (mClientId, 16, 16, TRUE),
+ KWin::icon (mClientId, 32, 32, TRUE));
+ mDecor->iconChange ();
+}
+
+NET::Direction
+Aquamarine::Window::positionToDirection (int pos)
+{
+ switch (pos) {
+ case PositionLeft:
+ return NET::Left;
+ case PositionRight:
+ return NET::Right;
+ case PositionTop:
+ return NET::Top;
+ case PositionBottom:
+ return NET::Bottom;
+ case PositionTopLeft:
+ return NET::TopLeft;
+ case PositionTopRight:
+ return NET::TopRight;
+ case PositionBottomLeft:
+ return NET::BottomLeft;
+ case PositionBottomRight:
+ return NET::BottomRight;
+ default:
+ break;
+ }
- XRenderFreePicture (qt_xdisplay(), fill);
+ return NET::Move;
+}
- params[0] = 1 << 16;
- params[1] = (n_params - 2) << 16;
+void
+Aquamarine::Window::moveWindow (QMouseEvent *qme)
+{
+ NET::Direction direction;
- XRenderFreePicture (qt_xdisplay(), src);
- XRenderColor color = { m_scolor[0], m_scolor[1], m_scolor[2], 0xffff };
+ direction = positionToDirection (mDecor->mousePosition (qme->pos ()));
- src = XRenderCreateSolidFill (qt_xdisplay(), &color);
+ XUngrabPointer (qt_xdisplay (), CurrentTime);
+ XUngrabKeyboard (qt_xdisplay (), CurrentTime);
- setPictureTransform(tmp,0,size);
- XRenderSetPictureFilter (qt_xdisplay(), tmp, filter, params, n_params);
+ Decorator::rootInfo ()->moveResizeRequest (mClientId,
+ qme->globalX (),
+ qme->globalY (),
+ direction);
+}
- XRenderComposite (qt_xdisplay(), PictOpSrc, src, tmp, dst, s2, s2, s2, s2, rect.left() + s2, rect.top() + s2, rect.width() - s2, rect.height() - s2);
+#define OPACITY_STEP (0xffff / 10)
- XRenderFreePicture (qt_xdisplay(), src);
- XRenderFreePicture (qt_xdisplay(), tmp);
- XRenderFreePicture (qt_xdisplay(), dst);
+void
+Aquamarine::Window::performMouseCommand (Options::MouseCommand command,
+ QMouseEvent *qme)
+{
+ switch (command) {
+ case Options::MouseRaise:
+ KWin::raiseWindow (mClientId);
+ break;
+ case Options::MouseLower:
+ KWin::lowerWindow (mClientId);
+ break;
+ case Options::MouseShade :
+ setShade (!isShade ());
+ break;
+ case Options::MouseSetShade:
+ setShade (true);
+ break;
+ case Options::MouseUnsetShade:
+ setShade (false);
+ break;
+ case Options::MouseOperationsMenu:
+ {
+ QPoint mp (0, 0);
+
+ if (qme)
+ mp = QPoint (qme->globalX (), qme->globalY ());
+
+ showWindowMenu (mp);
+ } break;
+ case Options::MouseMaximize:
+ maximize (KDecoration::MaximizeFull);
+ break;
+ case Options::MouseRestore:
+ maximize (KDecoration::MaximizeRestore);
+ break;
+ case Options::MouseMinimize:
+ minimize ();
+ break;
+ case Options::MouseAbove:
+ if (keepBelow ())
+ setKeepBelow (false);
+ else
+ setKeepAbove (true);
+ break;
+ case Options::MouseBelow:
+ if (keepAbove ())
+ setKeepAbove (false);
+ else
+ setKeepBelow (true);
+ break;
+ case Options::MousePreviousDesktop:
+ break;
+ case Options::MouseNextDesktop:
+ break;
+ case Options::MouseOpacityMore:
+ {
+ int opacity = mOpacity;
+
+ if (opacity < 0xffff)
+ {
+ opacity += OPACITY_STEP;
+ if (opacity > 0xffff)
+ opacity = 0xffff;
+
+ Decorator::sendClientMessage (qt_xrootwin (),
+ mClientId,
+ Atoms::netWmWindowOpacity,
+ (opacity << 16) | opacity);
+ }
+ } break;
+ case Options::MouseOpacityLess:
+ {
+ int opacity = mOpacity;
- delete params;
+ if (opacity > OPACITY_STEP)
+ {
+ opacity -= OPACITY_STEP;
+ if (opacity < OPACITY_STEP)
+ opacity = OPACITY_STEP;
+
+ Decorator::sendClientMessage (qt_xrootwin (),
+ mClientId,
+ Atoms::netWmWindowOpacity,
+ (opacity << 16) | opacity);
+ }
+ } break;
+ case Options::MouseActivateRaiseAndMove:
+ case Options::MouseActivateRaiseAndUnrestrictedMove:
+ case Options::MouseMove:
+ case Options::MouseUnrestrictedMove:
+ case Options::MouseResize:
+ case Options::MouseUnrestrictedResize:
+ if (qme)
+ moveWindow (qme);
+ case Options::MouseNothing:
+ default:
+ break;
+ }
}
-XFixed *Aquamarine::Window::createGaussianKernel (int *r_size)
+void
+Aquamarine::Window::processDamage (void)
{
- double sigma = m_sradius / 2.0;
- double alpha = m_sradius;
- double radius = m_sradius;
+ QRegion r1, r2;
+ int xOff, yOff, w;
+ double alpha;
+ int shade_alpha;
- XFixed *params;
- double *amp, scale, x_scale, fx, sum;
- int size, half_size, x, i, n;
+ if (isActive ())
+ {
+ alpha = Settings::activeOpacity() / 100.0;
+ shade_alpha = 0;
+ }
+ else
+ {
+ alpha = Settings::inactiveOpacity() / 100.0;
+ shade_alpha = 0;
+ }
- scale = 1.0f / (2.0f * M_PI * sigma * sigma);
- half_size = int(alpha + 0.5f);
+ if (!mPixmap)
+ return;
- if (half_size == 0)
- half_size = 1;
+ if (mDamage.isEmpty ())
+ return;
- size = half_size * 2 + 1;
- x_scale = 2.0f * radius / size;
+ if (mShapeSet)
+ mDamage = mShape.intersect (mDamage);
- if (size < 3)
- return NULL;
+ w = mGeometry.width () + mContext.extents.left + mContext.extents.right;
- n = size;
+ if (mType == Switcher)
+ shade_alpha = 0;
- amp = new double[n];
- if (!amp)
- return NULL;
+ xOff = 0;
+ yOff = 0;
- n += 2;
+ r1 = QRegion (xOff, yOff, w, mContext.extents.top);
+ r2 = r1.intersect (mDamage);
- params = new XFixed[n];
- if (!params)
- return NULL;
+ if (!r2.isEmpty ())
+ {
+ r2.translate (-xOff, -yOff);
+
+ decor_blend_top_border_picture (qt_xdisplay (),
+ &mContext,
+ mPicture,
+ xOff, xOff,
+ mTexturePicture,
+ &mLayout,
+ r2.handle (),
+ (unsigned short) (alpha * 0xffff),
+ shade_alpha);
+ }
- i = 0;
- sum = 0.0f;
+ xOff = 0;
+ yOff = mContext.extents.top + mGeometry.height ();
- for (x = 0; x < size; x++)
- {
- fx = x_scale * (x - half_size);
+ r1 = QRegion (xOff, yOff, w, mContext.extents.bottom);
+ r2 = r1.intersect (mDamage);
- amp[i] = scale * exp ((-1.0f * (fx * fx)) / (2.0f * sigma * sigma));
+ if (!r2.isEmpty ())
+ {
+ r2.translate (-xOff, -yOff);
+
+ decor_blend_bottom_border_picture (qt_xdisplay (),
+ &mContext,
+ mPicture,
+ xOff, yOff,
+ mTexturePicture,
+ &mLayout,
+ r2.handle (),
+ (unsigned short) (alpha * 0xffff),
+ shade_alpha);
+ }
- sum += amp[i];
+ xOff = 0;
+ yOff = mContext.extents.top;
- i++;
- }
+ r1 = QRegion (xOff, yOff, mContext.extents.left, mGeometry.height ());
+ r2 = r1.intersect (mDamage);
- /* normalize */
- if (sum != 0.0)
- sum = 1.0 / sum;
+ if (!r2.isEmpty ())
+ {
+ r2.translate (-xOff, -yOff);
+
+ decor_blend_left_border_picture (qt_xdisplay (),
+ &mContext,
+ mPicture,
+ xOff, yOff,
+ mTexturePicture,
+ &mLayout,
+ r2.handle (),
+ (unsigned short) (alpha * 0xffff),
+ shade_alpha);
+ }
- params[0] = params[1] = 0;
+ xOff = mContext.extents.left + mGeometry.width ();
+ yOff = mContext.extents.top;
- for (i = 2; i < n; i++)
- params[i] = XDoubleToFixed (amp[i - 2] * sum);
+ r1 = QRegion (xOff, yOff, mContext.extents.right, mGeometry.height ());
+ r2 = r1.intersect (mDamage);
- delete amp;
+ if (!r2.isEmpty ())
+ {
+ r2.translate (-xOff, -yOff);
+
+ decor_blend_right_border_picture (qt_xdisplay (),
+ &mContext,
+ mPicture,
+ xOff, yOff,
+ mTexturePicture,
+ &mLayout,
+ r2.handle (),
+ (unsigned short) (alpha * 0xffff),
+ shade_alpha);
+ }
- *r_size = size;
+ mDamage = QRegion ();
- return params;
-}
+ XRenderComposite (qt_xdisplay (),
+ PictOpSrc,
+ mTexturePicture,
+ None,
+ mDecorationPicture,
+ 0, 0,
+ 0, 0,
+ 0, 0,
+ mTexturePixmap.width (),
+ mTexturePixmap.height ());
-void Aquamarine::Window::setPictureTransform (Picture p, int dx, int dy)
-{
- XTransform transform = {
+ if (mUpdateProperty)
+ {
+ if (mType == Switcher)
{
- { 1 << 16, 0, -dx << 16 },
- { 0, 1 << 16, -dy << 16 },
- { 0, 0, 1 << 16 },
+ QPainter p (this);
+ unsigned long pixel;
+ QColor bg = p.backgroundColor ();
+
+ pixel = (((int) (alpha * 0xff) << 24) |
+ ((int) (alpha * bg.red ()) << 16) |
+ ((int) (alpha * bg.green ()) << 8) |
+ ((int) (alpha * bg.blue ()) << 0));
+
+ Aquamarine::trapXError ();
+ XSetWindowBackground (qt_xdisplay (), mClientId, pixel);
+ XClearWindow (qt_xdisplay (), mClientId);
+ Aquamarine::popXError ();
}
- };
-
- XRenderSetPictureTransform (qt_xdisplay(), p, &transform);
-}
-
-bool
-Aquamarine::Window::eventFilter (QObject * watched, QEvent * event)
-{
- bool rv = QWidget::eventFilter (watched, event);
- if (event->type () == QEvent::Paint)
- {
- QTimer::singleShot (0, this, SLOT(updateWindow()));
- }
-
- return rv;
+ updateProperty ();
+ }
}
-void Aquamarine::Window::handleProcessKillerExited (void)
+void
+Aquamarine::Window::handleProcessKillerExited (void)
{
- if (mProcessKiller)
- {
- delete mProcessKiller;
- mProcessKiller = NULL;
- }
+ if (mProcessKiller)
+ {
+ delete mProcessKiller;
+ mProcessKiller = NULL;
+ }
}
-void Aquamarine::Window::showKillProcessDialog (Time timestamp)
+void
+Aquamarine::Window::showKillProcessDialog (Time timestamp)
{
- KWin::WindowInfo kWinInfo =
- KWin::windowInfo (m_wid, 0, NET::WM2WindowClass | NET::WM2ClientMachine);
- NETWinInfo wInfo = NETWinInfo (qt_xdisplay(), m_wid,
- qt_xrootwin (), NET::WMPid);
- QCString clientMachine, resourceClass;
- pid_t pid;
- char buf[257];
+ KWin::WindowInfo kWinInfo =
+ KWin::windowInfo (mClientId, 0,
+ NET::WM2WindowClass | NET::WM2ClientMachine);
+ NETWinInfo wInfo = NETWinInfo (qt_xdisplay(), mClientId,
+ qt_xrootwin (), NET::WMPid);
+ QCString clientMachine, resourceClass;
+ pid_t pid;
+ char buf[257];
- if (mProcessKiller)
- return;
+ if (mProcessKiller)
+ return;
- clientMachine = kWinInfo.clientMachine ();
- resourceClass = kWinInfo.windowClassClass ();
- pid = wInfo.pid ();
+ clientMachine = kWinInfo.clientMachine ();
+ resourceClass = kWinInfo.windowClassClass ();
+ pid = wInfo.pid ();
- if (gethostname (buf, sizeof (buf) - 1) == 0)
- {
- if (strcmp (buf, clientMachine) == 0)
- clientMachine = "localhost";
- }
+ if (gethostname (buf, sizeof (buf) - 1) == 0)
+ {
+ if (strcmp (buf, clientMachine) == 0)
+ clientMachine = "localhost";
+ }
- mProcessKiller = new KProcess (this);
+ mProcessKiller = new KProcess (this);
- *mProcessKiller << KStandardDirs::findExe ("kwin_killer_helper") <<
+ *mProcessKiller << KStandardDirs::findExe ("kwin_killer_helper") <<
"--pid" << QCString ().setNum (pid) <<
"--hostname" << clientMachine <<
- "--windowname" << m_name.utf8 () <<
+ "--windowname" << mName.utf8 () <<
"--applicationname" << resourceClass <<
- "--wid" << QCString ().setNum (m_wid) <<
+ "--wid" << QCString ().setNum (mClientId) <<
"--timestamp" << QCString ().setNum (timestamp);
- connect (mProcessKiller, SIGNAL (processExited (KProcess *)),
- SLOT (handleProcessKillerExited ()));
+ connect (mProcessKiller, SIGNAL (processExited (KProcess *)),
+ SLOT (handleProcessKillerExited ()));
- if (!mProcessKiller->start (KProcess::NotifyOnExit))
- {
- delete mProcessKiller;
- mProcessKiller = NULL;
- }
+ if (!mProcessKiller->start (KProcess::NotifyOnExit))
+ {
+ delete mProcessKiller;
+ mProcessKiller = NULL;
+ }
+}
+
+void
+Aquamarine::Window::hideKillProcessDialog (void)
+{
+ handleProcessKillerExited ();
}
-void Aquamarine::Window::hideKillProcessDialog (void)
+void Aquamarine::Window::handleChangeViewport (int id)
{
- handleProcessKillerExited ();
+ if (id == 0)
+ setDesktop ((desktop () == NET::OnAllDesktops) ? 1 : NET::OnAllDesktops);
+ else
+ Decorator::moveToViewport (mClientId, id);
+}
+
+void Aquamarine::Window::handleDesktopGeometryChanged()
+{
+ // force menu regeneration
+ delete mPopup;
+ mPopup = 0;
+}
+
+void Aquamarine::Window::handleAppearanceChange (int id)
+{
+ int opacity = mOpacity;
+ int brightness = mBrightness;
+ int saturation = mSaturation;
+
+ switch (id)
+ {
+ case ResetValues:
+ opacity = brightness = saturation = 0xffff;
+ break;
+ case ChangeOpacity25:
+ opacity = 0x3fff;
+ break;
+ case ChangeOpacity50:
+ opacity = 0x7fff;
+ break;
+ case ChangeOpacity75:
+ opacity = 0xbfff;
+ break;
+ case ChangeOpacity100:
+ opacity = 0xffff;
+ break;
+ case ChangeBrightness25:
+ brightness = 0x3fff;
+ break;
+ case ChangeBrightness50:
+ brightness = 0x7fff;
+ break;
+ case ChangeBrightness75:
+ brightness = 0xbfff;
+ break;
+ case ChangeBrightness100:
+ brightness = 0xffff;
+ break;
+ case ChangeSaturation25:
+ saturation = 0x3fff;
+ break;
+ case ChangeSaturation50:
+ saturation = 0x7fff;
+ break;
+ case ChangeSaturation75:
+ saturation = 0xbfff;
+ break;
+ case ChangeSaturation100:
+ saturation = 0xffff;
+ break;
+ default:
+ break;
+ }
+ if (opacity != mOpacity)
+ Decorator::sendClientMessage (qt_xrootwin (),
+ mClientId,
+ Atoms::netWmWindowOpacity,
+ (opacity << 16) | opacity);
+ if (brightness != mBrightness)
+ Decorator::sendClientMessage (qt_xrootwin (),
+ mClientId,
+ Atoms::netWmWindowBrightness,
+ (brightness << 16) | brightness);
+ if (saturation != mSaturation)
+ Decorator::sendClientMessage (qt_xrootwin (),
+ mClientId,
+ Atoms::netWmWindowSaturation,
+ (saturation << 16) | saturation);
}