summaryrefslogtreecommitdiff
path: root/kde/window-decorator-kde4/main.cpp
blob: 91c96ee9c045921624e24ff3165c53b10a931868 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
 * Copyright © 2008 Dennis Kasprzyk <onestone@opencompositing.org>
 * Copyright © 2006 Novell, Inc.
 * Copyright © 2006 Volker Krause <vkrause@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.
 *
 * Author: David Reveman <davidr@novell.com>
 */

#include <X11/Xlib.h>
#include <X11/extensions/Xdamage.h>

#include <fixx11h.h>
#include <KDE/KApplication>
#include <KDE/KCmdLineArgs>
#include <KDE/KDebug>
#include <KDE/KLocale>

#include "decorator.h"
#include "utils.h"

#include <QX11Info>
#include <QtDBus/QtDBus>



int
main (int argc, char **argv)
{
    KWD::Decorator  *app;
    KCmdLineArgs    *args;
    KCmdLineOptions options;
    int		    status;
    int		    event, error;
    Time	    timestamp;
    QString         appname;

#ifndef QT_45
    Colormap        colormap = 0;
    Visual          *visual = 0;
    int             event_base, error_base;
    Display         *dpy;
    int             screen;
#endif

    options.add ("replace", ki18n ("Replace existing window decorator"));
    options.add ("sm-disable", ki18n ("Disable connection to session manager"));
    options.add ("opacity <value>", ki18n ("Decoration opacity"), "0.75");
    options.add ("no-opacity-shade", ki18n ("No decoration opacity shading"));
    options.add ("active-opacity <value>",
		 ki18n ("Active decoration opacity"), "1.0");
    options.add ("no-active-opacity-shade",
		 ki18n ("No active decoration opacity shading"));
    options.add ("blur <type>", ki18n ("Blur type"), "none");

    KCmdLineArgs::init (argc, argv,
			"kde-window-decorator",
			"kwin",
			ki18n ("KDE Window Decorator"),
			"0.0.1");
    KCmdLineArgs::addCmdLineOptions (options);
    args = KCmdLineArgs::parsedArgs ();

    if (args->isSet ("opacity"))
	decorationOpacity = args->getOption ("opacity").toDouble ();

    if (args->isSet ("-opacity-shade"))
	decorationOpacityShade = true;

    if (args->isSet ("active-opacity"))
	activeDecorationOpacity =
	    args->getOption ("active-opacity").toDouble ();

    if (args->isSet ("-active-opacity-shade"))
	activeDecorationOpacityShade = true;

    if (args->isSet ("blur"))
    {
	QString blur = args->getOption ("blur");

	if (blur == QString ("titlebar"))
	    blurType = BLUR_TYPE_TITLEBAR;
	else if (blur == QString ("all"))
	    blurType = BLUR_TYPE_ALL;
    }

    // Disable window less child widgets
    QApplication::setAttribute (Qt::AA_NativeWindows, true);

#ifdef QT_45
    app = new KWD::Decorator ();
#else
    dpy = XOpenDisplay (0); // open default display
    screen = DefaultScreen (dpy);
    if (!dpy) {
        kError () << "Cannot connect to the X server" << endl;
        return 0;
    }

    if (XRenderQueryExtension (dpy, &event_base, &error_base))
    {
	int nvi;
	XVisualInfo templ;
	templ.screen = screen;
	templ.depth = 32;
	templ.c_class = TrueColor;
        XVisualInfo *xvi = XGetVisualInfo (dpy, VisualScreenMask |
					   VisualDepthMask |
					   VisualClassMask, &templ, &nvi);

	for (int i = 0; i < nvi; i++)
	{
	    XRenderPictFormat *format =
		XRenderFindVisualFormat (dpy, xvi[i].visual);
	    if (format->type == PictTypeDirect && format->direct.alphaMask)
	    {
		visual = xvi[i].visual;
		colormap = XCreateColormap (dpy, RootWindow (dpy, screen),
					    visual, AllocNone);
	        break;
	    }
	}
    }

    app = new KWD::Decorator (dpy, visual ? Qt::HANDLE (visual) : 0,
			      colormap ? Qt::HANDLE (colormap) : 0);
#endif

    if (args->isSet ("sm-disable"))
	app->disableSessionManagement ();

    if (!XDamageQueryExtension (QX11Info::display (), &event, &error))
    {
	fprintf (stderr,
		 "%s: Damage extension is missing on display \"%s\"\n",
		 argv[0], DisplayString (QX11Info::display ()));

	return 1;
    }

    status = decor_acquire_dm_session (QX11Info::display (),
				       QX11Info::appScreen (),
				       "kwd", args->isSet ("replace"),
				       &timestamp);
    if (status != DECOR_ACQUIRE_STATUS_SUCCESS)
    {
	if (status == DECOR_ACQUIRE_STATUS_FAILED)
	{
	    fprintf (stderr,
		     "%s: Could not acquire decoration manager "
		     "selection on screen %d display \"%s\"\n",
		     argv[0], QX11Info::appScreen (),
		     DisplayString (QX11Info::display ()));
	}
	else if (status == DECOR_ACQUIRE_STATUS_OTHER_DM_RUNNING)
	{
	    fprintf (stderr,
		     "%s: Screen %d on display \"%s\" already "
		     "has a decoration manager; try using the "
		     "--replace option to replace the current "
		     "decoration manager.\n",
		     argv[0], QX11Info::appScreen (),
		     DisplayString (QX11Info::display ()));
	}

	return 1;
    }

    decor_set_dm_check_hint (QX11Info::display (), QX11Info::appScreen (),
			     WINDOW_DECORATION_TYPE_PIXMAP |
			     WINDOW_DECORATION_TYPE_WINDOW);

    if (!app->enableDecorations (timestamp, event))
    {
	fprintf (stderr,
		 "%s: Could not enable decorations on display \"%s\"\n",
		 argv[0], DisplayString (QX11Info::display ()));

	return 1;
    }

    if (QX11Info::appScreen () == 0)
        appname = "org.kde.kwin";
    else
        appname.sprintf ("org.kde.kwin-screen-%d", QX11Info::appScreen ());

    QDBusConnection::sessionBus ().interface ()->registerService
	(appname, QDBusConnectionInterface::DontQueueService);

    status = app->exec ();

    delete app;

    return status;
}