not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / kwin / notifications.cpp
bloba45e85d9c75f9c84eb6583c6b15f3775f2a073c1
1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
6 Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *********************************************************************/
22 #include "notifications.h"
23 #include <knotification.h>
25 #include "client.h"
27 namespace KWin
30 static bool forgetIt = false;
31 QList< Notify::EventData > Notify::pending_events;
33 bool Notify::raise( Event e, const QString& message, Client* c )
35 if ( forgetIt )
36 return false; // no connection was possible, don't try each time
38 QString event;
39 KNotification::NotificationFlags flags = KNotification::CloseOnTimeout;
40 switch ( e )
42 case Activate:
43 event = "activate";
44 break;
45 case Close:
46 event = "close";
47 break;
48 case Minimize:
49 event = "minimize";
50 break;
51 case UnMinimize:
52 event = "unminimize";
53 break;
54 case Maximize:
55 event = "maximize";
56 break;
57 case UnMaximize:
58 event = "unmaximize";
59 break;
60 case OnAllDesktops:
61 event = "on_all_desktops";
62 break;
63 case NotOnAllDesktops:
64 event = "not_on_all_desktops";
65 break;
66 case New:
67 event = "new";
68 break;
69 case Delete:
70 event = "delete";
71 break;
72 case TransNew:
73 event = "transnew";
74 break;
75 case TransDelete:
76 event = "transdelete";
77 break;
78 case ShadeUp:
79 event = "shadeup";
80 break;
81 case ShadeDown:
82 event = "shadedown";
83 break;
84 case MoveStart:
85 event = "movestart";
86 break;
87 case MoveEnd:
88 event = "moveend";
89 break;
90 case ResizeStart:
91 event = "resizestart";
92 break;
93 case ResizeEnd:
94 event = "resizeend";
95 break;
96 case DemandAttentionCurrent:
97 event = "demandsattentioncurrent";
98 break;
99 case DemandAttentionOther:
100 event = "demandsattentionother";
101 break;
102 case CompositingSlow:
103 event = "compositingslow";
104 flags = KNotification::Persistent;
105 break;
106 default:
107 if ((e > DesktopChange) && (e <= DesktopChange+20))
109 event = QString("desktop%1").arg(e-DesktopChange);
111 break;
113 if ( event.isNull() )
114 return false;
116 // There may be a deadlock if KNotify event is sent while KWin has X grabbed.
117 // If KNotify is not running, KLauncher may do X requests (startup notification, whatever)
118 // that will block it. And KNotifyClient waits for the launch to succeed, which means
119 // KLauncher waits for X and KWin waits for KLauncher. So postpone events in such case.
120 if( grabbedXServer())
122 EventData data;
123 data.event = event;
124 data.message = message;
125 data.window = c ? c->window() : 0;
126 data.flags = flags;
127 pending_events.append( data );
128 return true;
132 return KNotification::event( event, message, QPixmap(), NULL /* TODO c ? c->window() : 0*/, flags );
135 void Notify::sendPendingEvents()
137 while( !pending_events.isEmpty())
139 EventData data = pending_events.first();
140 pending_events.pop_front();
141 if( !forgetIt )
142 KNotification::event( data.event, data.message, QPixmap(), NULL /* TODO data.window*/, data.flags );
146 } // namespace