24 #include <QtGui/QDesktopWidget>
25 #include <QtGui/QIcon>
26 #include <QtGui/QBitmap>
27 #include <QtGui/QPixmap>
28 #include <QtCore/QLibrary>
38 #define GCL_HICON GCLP_HICON
39 #define GCL_HICONSM GCLP_HICONSM
43 #define RSH_UNREGISTER 0
44 #define RSH_REGISTER 1
51 class KWindowSystemStaticContainer {
53 KWindowSystemStaticContainer() : d(0) {}
55 KWindowSystemPrivate* d;
60 K_GLOBAL_STATIC(QDesktopWidget, s_deskWidget)
63 struct InternalWindowInfo
65 InternalWindowInfo(){}
71 class KWindowSystemPrivate :
public QWidget
78 static bool CALLBACK EnumWindProc (WId hwnd, LPARAM lparam);
79 static void readWindowInfo (WId wid , InternalWindowInfo *winfo);
83 void windowActivated (WId wid);
84 void windowRedraw (WId wid);
85 void windowFlash (WId wid);
86 void windowStateChanged (WId wid);
87 void reloadStackList ( );
92 bool winEvent ( MSG * message,
long * result );
104 QBitmap bm = pix.mask();
106 bm = QBitmap( pix.size() );
107 bm.fill( Qt::color1 );
109 QImage im = bm.toImage().convertToFormat( QImage::Format_Mono );
113 int bpl = (( w + 15 ) / 16 ) * 2;
114 QByteArray bits( bpl * h,
'\0' );
115 for (
int y=0; y < h; y++)
116 memcpy( bits.data() + y * bpl, im.scanLine( y ), bpl );
117 return CreateBitmap( w, h, 1, 1, bits );
120 KWindowSystemPrivate::KWindowSystemPrivate(
int what) :
QWidget(0),activated(false)
123 what = KWindowSystem::INFO_WINDOWS;
127 void KWindowSystemPrivate::activate ( )
139 WM_SHELLHOOK = RegisterWindowMessage(TEXT(
"SHELLHOOK"));
143 bool shellHookRegistered =
false;
147 if(!shellHookRegistered)
149 kDebug() <<
"Could not create shellhook to receive WindowManager Events";
155 KWindowSystemPrivate::~KWindowSystemPrivate()
164 bool KWindowSystemPrivate::winEvent ( MSG * message,
long * result )
188 switch(message->wParam) {
189 case HSHELL_WINDOWCREATED:
190 KWindowSystem::s_d_func()->windowAdded(reinterpret_cast<WId>(message->lParam));
192 case HSHELL_WINDOWDESTROYED:
193 KWindowSystem::s_d_func()->windowRemoved(reinterpret_cast<WId>(message->lParam));
195 case HSHELL_WINDOWACTIVATED:
197 case HSHELL_RUDEAPPACTIVATED:
199 KWindowSystem::s_d_func()->windowActivated(reinterpret_cast<WId>(message->lParam));
202 case HSHELL_GETMINRECT:
203 KWindowSystem::s_d_func()->windowStateChanged(reinterpret_cast<WId>(message->lParam));
206 KWindowSystem::s_d_func()->windowRedraw(reinterpret_cast<WId>(message->lParam));
209 KWindowSystem::s_d_func()->windowFlash(reinterpret_cast<WId>(message->lParam));
214 return QWidget::winEvent(message,result);
217 bool CALLBACK KWindowSystemPrivate::EnumWindProc(WId hWnd, LPARAM lparam)
219 QByteArray windowText = QByteArray ( (GetWindowTextLength(hWnd)+1) *
sizeof(
wchar_t), 0 ) ;
220 GetWindowTextW(hWnd, (LPWSTR)windowText.data(), windowText.size());
221 DWORD ex_style = GetWindowExStyle(hWnd);
225 if( !QString::fromWCharArray((
wchar_t*)windowText.data()).trimmed().isEmpty() && IsWindowVisible( hWnd ) && !(ex_style&WS_EX_TOOLWINDOW)
226 && !GetParent(hWnd) && !GetWindow(hWnd,GW_OWNER) && !p->winInfos.contains(hWnd) ) {
230 InternalWindowInfo winfo;
231 KWindowSystemPrivate::readWindowInfo(hWnd,&winfo);
233 p->stackingOrder.append(hWnd);
234 p->winInfos.insert(hWnd,winfo);
239 void KWindowSystemPrivate::readWindowInfo ( WId hWnd , InternalWindowInfo *winfo)
241 QByteArray windowText = QByteArray ( (GetWindowTextLength(hWnd)+1) *
sizeof(
wchar_t), 0 ) ;
242 GetWindowTextW(hWnd, (LPWSTR)windowText.data(), windowText.size());
245 HICON hSmallIcon = (HICON)SendMessage(hWnd, WM_GETICON, ICON_SMALL, 0);
247 if(!hSmallIcon) hSmallIcon = (HICON)SendMessage(hWnd, WM_GETICON, ICON_BIG, 0);
249 if(!hSmallIcon) hSmallIcon = (HICON)GetClassLong(hWnd, GCL_HICONSM);
250 if(!hSmallIcon) hSmallIcon = (HICON)GetClassLong(hWnd, GCL_HICON);
252 if(!hSmallIcon) hSmallIcon = (HICON)SendMessage(hWnd, WM_QUERYDRAGICON, 0, 0);
253 if(hSmallIcon) smallIcon = QPixmap::fromWinHICON(hSmallIcon);
256 HICON hBigIcon = (HICON)SendMessage(hWnd, WM_GETICON, ICON_BIG, 0);
258 if(!hBigIcon) hBigIcon = (HICON)SendMessage(hWnd, WM_GETICON, ICON_SMALL, 0);
260 if(!hBigIcon) hBigIcon = (HICON)GetClassLong(hWnd, GCL_HICON);
261 if(!hBigIcon) hBigIcon = (HICON)GetClassLong(hWnd, GCL_HICONSM);
263 if(!hBigIcon) hBigIcon = (HICON)SendMessage(hWnd, WM_QUERYDRAGICON, 0, 0);
264 if(hBigIcon) bigIcon = QPixmap::fromWinHICON(hBigIcon);
266 winfo->bigIcon = bigIcon;
267 winfo->smallIcon = smallIcon;
268 winfo->windowName = QString::fromWCharArray((
wchar_t*)windowText.data()).trimmed();
272 void KWindowSystemPrivate::windowAdded (WId wid)
275 KWindowSystem::s_d_func()->reloadStackList();
281 void KWindowSystemPrivate::windowRemoved (WId wid)
284 KWindowSystem::s_d_func()->reloadStackList();
289 void KWindowSystemPrivate::windowActivated (WId wid)
296 KWindowSystem::s_d_func()->reloadStackList();
301 void KWindowSystemPrivate::windowRedraw (WId wid)
303 KWindowSystem::s_d_func()->reloadStackList();
306 void KWindowSystemPrivate::windowFlash (WId wid)
311 void KWindowSystemPrivate::windowStateChanged (WId wid)
316 void KWindowSystemPrivate::reloadStackList ()
318 KWindowSystem::s_d_func()->stackingOrder.clear();
319 KWindowSystem::s_d_func()->winInfos.clear();
320 EnumWindows((WNDENUMPROC)EnumWindProc, 0 );
327 return &(g_kwmInstanceContainer->kwm);
332 return g_kwmInstanceContainer->d;
335 void KWindowSystem::init(
int what)
339 if (what >= INFO_WINDOWS)
347 g_kwmInstanceContainer->d->activate();
349 else if (s_d->what < what)
353 g_kwmInstanceContainer->d->activate();
375 SetForegroundWindow(subwindow->winId());
380 kDebug() <<
"KWindowSystem::setCurrentDesktop( int desktop ) isn't yet implemented!";
386 kDebug() <<
"KWindowSystem::setOnAllDesktops( WId win, bool b ) isn't yet implemented!";
393 kDebug() <<
"KWindowSystem::setOnDesktop( WId win, int desktop ) isn't yet implemented!";
398 return GetActiveWindow();
403 SetActiveWindow( win );
413 if ( IsIconic( win ) ) {
416 ShowWindow( win, SW_SHOWNOACTIVATE );
422 HWND hwndActiveWin = GetForegroundWindow();
423 int idActive = GetWindowThreadProcessId(hwndActiveWin, NULL);
424 if ( AttachThreadInput(GetCurrentThreadId(), idActive, TRUE) )
426 SetForegroundWindow( win );
428 AttachThreadInput(GetCurrentThreadId(), idActive, FALSE);
438 fi.cbSize =
sizeof( FLASHWINFO );
440 fi.dwFlags =
set ? FLASHW_ALL : FLASHW_STOP;
444 FlashWindowEx( &fi );
451 KWindowSystem::init(INFO_WINDOWS);
454 if(KWindowSystem::s_d_func()->winInfos.contains(win)){
455 if( width < 24 || height < 24 )
456 pm = KWindowSystem::s_d_func()->winInfos[win].smallIcon;
458 pm = KWindowSystem::s_d_func()->winInfos[win].bigIcon;
461 kDebug()<<
"KWindowSystem::icon winid not in winInfos";
462 UINT size = ICON_BIG;
463 if( width < 24 || height < 24 )
465 HICON hIcon = (HICON)SendMessage( win, WM_GETICON, size, 0);
467 pm = QPixmap::fromWinHICON( hIcon );
470 pm = pm.scaled( width, height );
476 return icon( win, width, height, scale );
481 KWindowSystem::init(INFO_WINDOWS);
484 if(s_d->winInfos.contains(win)){
486 s_d->winInfos[win].smallIcon = miniIcon;
487 s_d->winInfos[win].bigIcon =
icon;
490 HICON hIconBig = icon.toWinHICON();
491 HICON hIconSmall = miniIcon.toWinHICON();
493 hIconBig = (HICON)SendMessage( win, WM_SETICON, ICON_BIG, (LPARAM)hIconBig );
494 hIconSmall = (HICON)SendMessage( win, WM_SETICON, ICON_SMALL, (LPARAM)hIconSmall );
504 LONG_PTR lp = GetWindowLongPtr(win, GWL_EXSTYLE);
505 SetWindowLongPtr(win, GWL_EXSTYLE, lp | WS_EX_TOOLWINDOW);
510 SetWindowPos(win, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
514 SetWindowPos(win, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
518 ShowWindow( win, SW_MAXIMIZE );
521 kDebug() <<
"KWindowSystem::setState( WId win, unsigned long state ) isn't yet implemented for the state you requested!";
529 if (state & NET::SkipTaskbar) {
531 LONG_PTR lp = GetWindowLongPtr(win, GWL_EXSTYLE);
532 SetWindowLongPtr(win, GWL_EXSTYLE, lp & ~WS_EX_TOOLWINDOW);
535 if (state & NET::KeepAbove) {
538 SetWindowPos(win, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
540 if(state & NET::Max){
542 ShowWindow( win, SW_RESTORE );
545 kDebug() <<
"KWindowSystem::clearState( WId win, unsigned long state ) isn't yet implemented!";
550 Q_UNUSED( animation );
551 ShowWindow( win, SW_MINIMIZE );
556 Q_UNUSED( animation );
557 ShowWindow( win, SW_RESTORE );
565 HWND hwndActiveWin = GetForegroundWindow();
566 int idActive = GetWindowThreadProcessId(hwndActiveWin, NULL);
567 if ( AttachThreadInput(GetCurrentThreadId(), idActive, TRUE) )
569 SetForegroundWindow( win );
570 AttachThreadInput(GetCurrentThreadId(), idActive, FALSE);
576 SetWindowPos( win, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE );
586 return s_deskWidget->availableGeometry( desktop );
592 kDebug() <<
"QRect KWindowSystem::workArea( const QList<WId>& exclude, int desktop ) isn't yet implemented!";
598 return i18n(
"Desktop %1", desktop );
603 kDebug() <<
"KWindowSystem::setDesktopName( int desktop, const QString& name ) isn't yet implemented!";
614 kDebug() <<
"KWindowSystem::setUserTime( WId win, long time ) isn't yet implemented!";
626 int what = INFO_BASIC;
629 else if( QLatin1String( signal ) == SIGNAL(
strutChanged()))
631 else if( QLatin1String( signal ) == QMetaObject::normalizedSignature(SIGNAL(
windowChanged(WId,
const ulong*))).constData())
633 else if( QLatin1String( signal ) == QMetaObject::normalizedSignature(SIGNAL(
windowChanged(WId,uint))).constData())
635 else if( QLatin1String( signal ) == QMetaObject::normalizedSignature(SIGNAL(
windowChanged(WId))).constData())
639 QObject::connectNotify( signal );
643 int right_width,
int right_start,
int right_end,
int top_width,
int top_start,
int top_end,
644 int bottom_width,
int bottom_start,
int bottom_end )
646 kDebug() <<
"KWindowSystem::setExtendedStrut isn't yet implemented!";
651 kDebug() <<
"KWindowSystem::setStrut isn't yet implemented!";
658 kDebug() <<
"QString KWindowSystem::readNameProperty( WId window, unsigned long atom ) isn't yet implemented!";
665 kDebug() <<
"KWindowSystem::doNotManage( const QString& title ) isn't yet implemented!";
670 KWindowSystem::init(INFO_WINDOWS);
671 return KWindowSystem::s_d_func()->stackingOrder;
676 KWindowSystem::init(INFO_WINDOWS);
677 return KWindowSystem::s_d_func()->stackingOrder;
683 kDebug() <<
"setType( WId win, NET::WindowType windowType ) isn't yet implemented!";
688 KWindowSystem::init(INFO_WINDOWS);
689 return KWindowInfo( win, properties, properties2 );
694 KWindowSystem::init(INFO_WINDOWS);
695 return KWindowSystem::s_d_func()->winInfos.contains(w);
701 AllowSetForegroundWindow( pid == -1 ? ASFW_ANY : pid );
708 kDebug() <<
"setBlockingCompositing( WId window, bool active ) isn't yet implemented!";
711 #include "kwindowsystem.moc"