Commit 794e57b9 authored by Robert Knight's avatar Robert Knight

Make use of window transparency setting in the color scheme when compositing support is available.

svn path=/trunk/KDE/kdebase/apps/konsole/; revision=663884
parent 53d5b769
......@@ -40,8 +40,9 @@
using namespace Konsole;
Application::Application()
: _sessionList(0)
Application::Application(Display* display , Qt::HANDLE visual, Qt::HANDLE colormap)
: KUniqueApplication(display,visual,colormap)
, _sessionList(0)
, _backgroundInstance(0)
{
// create session manager
......
......@@ -51,7 +51,7 @@ Q_OBJECT
public:
/** Constructs a new Konsole application. */
Application();
Application(Display* display , Qt::HANDLE visual, Qt::HANDLE colormap);
virtual ~Application();
......
......@@ -434,7 +434,6 @@ TerminalDisplay::TerminalDisplay(QWidget *parent)
//repainting.
//the widget may then need to repaint over some of the area in a different colour
//but because of the double buffering there won't be any flicker
setAutoFillBackground(true);
_gridLayout = new QGridLayout(this);
_gridLayout->setMargin(0);
......@@ -683,6 +682,29 @@ QColor TerminalDisplay::keyboardCursorColor() const
return _cursorColor;
}
void TerminalDisplay::setOpacity(qreal opacity)
{
QColor color(_blendColor);
color.setAlphaF(opacity);
_blendColor = color.rgba();
}
void TerminalDisplay::drawBackground(QPainter& painter, const QRect& rect, const QColor& backgroundColor)
{
if ( HAVE_TRANSPARENCY && qAlpha(_blendColor) < 0xff )
{
QColor color(backgroundColor);
color.setAlpha(qAlpha(_blendColor));
painter.save();
painter.setCompositionMode(QPainter::CompositionMode_Source);
painter.fillRect(rect, color);
painter.restore();
}
else
painter.fillRect(rect, backgroundColor);
}
/*!
attributed string draw primitive
*/
......@@ -718,26 +740,9 @@ void TerminalDisplay::drawAttrStr(QPainter &paint, const QRect& rect,
{
if (pm || clear || (_blinking && (attr->rendition & RE_BLINK)) ||
attr->backgroundColor == CharacterColor(COLOR_SPACE_DEFAULT, _colorsInverted ? DEFAULT_FORE_COLOR : DEFAULT_BACK_COLOR) )
// draw background colors with 75% opacity
if ( HAVE_TRANSPARENCY && qAlpha(_blendColor) < 0xff ) {
QRgb col = bColor.rgb();
quint8 salpha = 192;
quint8 dalpha = 255 - salpha;
int a, r, g, b;
a = qMin( (qAlpha (col) * salpha) / 255 + (qAlpha (_blendColor) * dalpha) / 255, 255 );
r = qMin( (qRed (col) * salpha) / 255 + (qRed (_blendColor) * dalpha) / 255, 255 );
g = qMin( (qGreen (col) * salpha) / 255 + (qGreen (_blendColor) * dalpha) / 255, 255 );
b = qMin( (qBlue (col) * salpha) / 255 + (qBlue (_blendColor) * dalpha) / 255, 255 );
col = a << 24 | r << 16 | g << 8 | b;
//int pixel = a << 24 | (r * a / 255) << 16 | (g * a / 255) << 8 | (b * a / 255);
paint.fillRect(rect, QColor(col));
} else
paint.fillRect(rect, bColor);
{
drawBackground(paint,rect,bColor);
}
}
QString tmpStr = str.simplified();
......
......@@ -84,6 +84,8 @@ public:
const ColorEntry* colorTable() const;
/** Sets the terminal color palette used by the display. */
void setColorTable(const ColorEntry table[]);
/** Sets the opacity of the terminal display. */
void setOpacity(qreal opacity);
/**
* This enum describes the location where the scroll bar is positioned in the display widget.
......@@ -461,7 +463,9 @@ protected:
void drawAttrStr(QPainter &paint, const QRect& rect,
QString& str, const Character *attr, bool pm, bool clear);
void drawBackground(QPainter& painter, const QRect& rect, const QColor& color);
void paintEvent( QPaintEvent * );
void paintContents(QPainter &paint, const QRect &rect);
......
......@@ -553,6 +553,7 @@ void ViewManager::applyProfile(TerminalDisplay* view , const QString& profileKey
// load colour scheme
view->setColorTable(colorScheme->colorTable());
view->setOpacity(colorScheme->opacity());
// load font
view->setVTFont(info->font());
......
......@@ -17,12 +17,17 @@
02110-1301 USA.
*/
// Own
#include "Application.h"
// X11
#include <X11/extensions/Xrender.h>
// KDE
#include <KAboutData>
#include <KCmdLineArgs>
#include <KLocale>
#include "Application.h"
// bump the version to 2.0 before the KDE 4 release
#define KONSOLE_VERSION "1.9"
......@@ -32,6 +37,7 @@ using namespace Konsole;
// fills the KAboutData structure with information about contributors to
// Konsole
void fillAboutData(KAboutData& aboutData);
void getDisplayInformation(Display*& display , Visual*& visual , Colormap& colormap);
static KCmdLineOptions options[] =
{
......@@ -68,7 +74,12 @@ extern "C" int KDE_EXPORT kdemain(int argc,char** argv)
exit(0);
}
Application app;
Display* display = 0;
Visual* visual = 0;
Colormap colormap = 0;
getDisplayInformation(display,visual,colormap);
Application app(display,Qt::HANDLE(visual),Qt::HANDLE(colormap));
return app.exec();
}
......@@ -136,3 +147,38 @@ void fillAboutData(KAboutData& aboutData)
aboutData.addCredit("",I18N_NOOP("Thanks to many others.\n"));
}
void getDisplayInformation(Display*& display , Visual*& visual , Colormap& colormap)
{
display = XOpenDisplay(0); // open default display
if (!display) {
qWarning("Cannot connect to the X server");
exit(1);
}
int screen = DefaultScreen(display);
int eventBase, errorBase;
if (XRenderQueryExtension(display, &eventBase, &errorBase)) {
int nvi;
XVisualInfo templ;
templ.screen = screen;
templ.depth = 32;
templ.c_class = TrueColor;
XVisualInfo *xvi = XGetVisualInfo(display, VisualScreenMask |
VisualDepthMask |
VisualClassMask, &templ, &nvi);
for (int i = 0; i < nvi; ++i) {
XRenderPictFormat* format = XRenderFindVisualFormat(display,
xvi[i].visual);
if (format->type == PictTypeDirect && format->direct.alphaMask) {
visual = xvi[i].visual;
colormap = XCreateColormap(display, RootWindow(display, screen),
visual, AllocNone);
// found ARGB visual
break;
}
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment