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 ( )
140 WM_SHELLHOOK = RegisterWindowMessage(TEXT(
"SHELLHOOK"));
144 bool shellHookRegistered =
false;
148 if(!shellHookRegistered)
150 kDebug() <<
"Could not create shellhook to receive WindowManager Events";
157 KWindowSystemPrivate::~KWindowSystemPrivate()
166 bool KWindowSystemPrivate::winEvent ( MSG * message,
long * result )
190 switch(message->wParam) {
191 case HSHELL_WINDOWCREATED:
192 KWindowSystem::s_d_func()->windowAdded(reinterpret_cast<WId>(message->lParam));
194 case HSHELL_WINDOWDESTROYED:
195 KWindowSystem::s_d_func()->windowRemoved(reinterpret_cast<WId>(message->lParam));
197 case HSHELL_WINDOWACTIVATED:
199 case HSHELL_RUDEAPPACTIVATED:
201 KWindowSystem::s_d_func()->windowActivated(reinterpret_cast<WId>(message->lParam));
204 case HSHELL_GETMINRECT:
205 KWindowSystem::s_d_func()->windowStateChanged(reinterpret_cast<WId>(message->lParam));
208 KWindowSystem::s_d_func()->windowRedraw(reinterpret_cast<WId>(message->lParam));
211 KWindowSystem::s_d_func()->windowFlash(reinterpret_cast<WId>(message->lParam));
216 return QWidget::winEvent(message,result);
219 bool CALLBACK KWindowSystemPrivate::EnumWindProc(WId hWnd, LPARAM lparam)
221 QByteArray windowText = QByteArray ( (GetWindowTextLength(hWnd)+1) *
sizeof(
wchar_t), 0 ) ;
222 GetWindowTextW(hWnd, (LPWSTR)windowText.data(), windowText.size());
223 DWORD ex_style = GetWindowExStyle(hWnd);
227 if( !QString::fromWCharArray((
wchar_t*)windowText.data()).trimmed().isEmpty() && IsWindowVisible( hWnd ) && !(ex_style&WS_EX_TOOLWINDOW)
228 && !GetParent(hWnd) && !GetWindow(hWnd,GW_OWNER) && !p->winInfos.contains(hWnd) ) {
232 InternalWindowInfo winfo;
233 KWindowSystemPrivate::readWindowInfo(hWnd,&winfo);
235 p->stackingOrder.append(hWnd);
236 p->winInfos.insert(hWnd,winfo);
241 void KWindowSystemPrivate::readWindowInfo ( WId hWnd , InternalWindowInfo *winfo)
243 QByteArray windowText = QByteArray ( (GetWindowTextLength(hWnd)+1) *
sizeof(
wchar_t), 0 ) ;
244 GetWindowTextW(hWnd, (LPWSTR)windowText.data(), windowText.size());
247 HICON hSmallIcon = (HICON)SendMessage(hWnd, WM_GETICON, ICON_SMALL, 0);
249 if(!hSmallIcon) hSmallIcon = (HICON)SendMessage(hWnd, WM_GETICON, ICON_BIG, 0);
251 if(!hSmallIcon) hSmallIcon = (HICON)GetClassLong(hWnd, GCL_HICONSM);
252 if(!hSmallIcon) hSmallIcon = (HICON)GetClassLong(hWnd, GCL_HICON);
254 if(!hSmallIcon) hSmallIcon = (HICON)SendMessage(hWnd, WM_QUERYDRAGICON, 0, 0);
255 if(hSmallIcon) smallIcon = QPixmap::fromWinHICON(hSmallIcon);
258 HICON hBigIcon = (HICON)SendMessage(hWnd, WM_GETICON, ICON_BIG, 0);
260 if(!hBigIcon) hBigIcon = (HICON)SendMessage(hWnd, WM_GETICON, ICON_SMALL, 0);
262 if(!hBigIcon) hBigIcon = (HICON)GetClassLong(hWnd, GCL_HICON);
263 if(!hBigIcon) hBigIcon = (HICON)GetClassLong(hWnd, GCL_HICONSM);
265 if(!hBigIcon) hBigIcon = (HICON)SendMessage(hWnd, WM_QUERYDRAGICON, 0, 0);
266 if(hBigIcon) bigIcon = QPixmap::fromWinHICON(hBigIcon);
268 winfo->bigIcon = bigIcon;
269 winfo->smallIcon = smallIcon;
270 winfo->windowName = QString::fromWCharArray((
wchar_t*)windowText.data()).trimmed();
274 void KWindowSystemPrivate::windowAdded (WId wid)
277 KWindowSystem::s_d_func()->reloadStackList();
283 void KWindowSystemPrivate::windowRemoved (WId wid)
286 KWindowSystem::s_d_func()->reloadStackList();
291 void KWindowSystemPrivate::windowActivated (WId wid)
298 KWindowSystem::s_d_func()->reloadStackList();
303 void KWindowSystemPrivate::windowRedraw (WId wid)
305 KWindowSystem::s_d_func()->reloadStackList();
308 void KWindowSystemPrivate::windowFlash (WId wid)
313 void KWindowSystemPrivate::windowStateChanged (WId wid)
318 void KWindowSystemPrivate::reloadStackList ()
320 KWindowSystem::s_d_func()->stackingOrder.clear();
321 KWindowSystem::s_d_func()->winInfos.clear();
329 return &(g_kwmInstanceContainer->kwm);
334 return g_kwmInstanceContainer->d;
337 void KWindowSystem::init(
int what)
341 if (what >= INFO_WINDOWS)
349 g_kwmInstanceContainer->d->activate();
351 else if (s_d->what < what)
355 g_kwmInstanceContainer->d->activate();
377 SetForegroundWindow(subwindow->winId());
382 kDebug() <<
"KWindowSystem::setCurrentDesktop( int desktop ) isn't yet implemented!";
388 kDebug() <<
"KWindowSystem::setOnAllDesktops( WId win, bool b ) isn't yet implemented!";
395 kDebug() <<
"KWindowSystem::setOnDesktop( WId win, int desktop ) isn't yet implemented!";
400 return GetActiveWindow();
405 SetActiveWindow( win );
415 if ( IsIconic( win ) ) {
418 ShowWindow( win, SW_SHOWNOACTIVATE );
424 HWND hwndActiveWin = GetForegroundWindow();
425 int idActive = GetWindowThreadProcessId(hwndActiveWin, NULL);
426 if ( AttachThreadInput(GetCurrentThreadId(), idActive, TRUE) )
428 SetForegroundWindow( win );
430 AttachThreadInput(GetCurrentThreadId(), idActive, FALSE);
440 fi.cbSize =
sizeof( FLASHWINFO );
442 fi.dwFlags =
set ? FLASHW_ALL : FLASHW_STOP;
446 FlashWindowEx( &fi );
453 KWindowSystem::init(INFO_WINDOWS);
456 if(KWindowSystem::s_d_func()->winInfos.contains(win)){
457 if( width < 24 || height < 24 )
458 pm = KWindowSystem::s_d_func()->winInfos[win].smallIcon;
460 pm = KWindowSystem::s_d_func()->winInfos[win].bigIcon;
463 kDebug()<<
"KWindowSystem::icon winid not in winInfos";
464 UINT size = ICON_BIG;
465 if( width < 24 || height < 24 )
467 HICON hIcon = (HICON)SendMessage( win, WM_GETICON, size, 0);
469 pm = QPixmap::fromWinHICON( hIcon );
472 pm = pm.scaled( width, height );
478 return icon( win, width, height, scale );
483 KWindowSystem::init(INFO_WINDOWS);
486 if(s_d->winInfos.contains(win)){
488 s_d->winInfos[win].smallIcon = miniIcon;
489 s_d->winInfos[win].bigIcon =
icon;
492 HICON hIconBig = icon.toWinHICON();
493 HICON hIconSmall = miniIcon.toWinHICON();
495 hIconBig = (HICON)SendMessage( win, WM_SETICON, ICON_BIG, (LPARAM)hIconBig );
496 hIconSmall = (HICON)SendMessage( win, WM_SETICON, ICON_SMALL, (LPARAM)hIconSmall );
506 LONG_PTR lp = GetWindowLongPtr(win, GWL_EXSTYLE);
507 SetWindowLongPtr(win, GWL_EXSTYLE, lp | WS_EX_TOOLWINDOW);
512 SetWindowPos(win, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
516 SetWindowPos(win, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
520 ShowWindow( win, SW_MAXIMIZE );
523 kDebug() <<
"KWindowSystem::setState( WId win, unsigned long state ) isn't yet implemented for the state you requested!";
531 if (state & NET::SkipTaskbar) {
533 LONG_PTR lp = GetWindowLongPtr(win, GWL_EXSTYLE);
534 SetWindowLongPtr(win, GWL_EXSTYLE, lp & ~WS_EX_TOOLWINDOW);
537 if (state & NET::KeepAbove) {
540 SetWindowPos(win, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
542 if(state & NET::Max){
544 ShowWindow( win, SW_RESTORE );
547 kDebug() <<
"KWindowSystem::clearState( WId win, unsigned long state ) isn't yet implemented!";
552 Q_UNUSED( animation );
553 ShowWindow( win, SW_MINIMIZE );
558 Q_UNUSED( animation );
559 ShowWindow( win, SW_RESTORE );
567 HWND hwndActiveWin = GetForegroundWindow();
568 int idActive = GetWindowThreadProcessId(hwndActiveWin, NULL);
569 if ( AttachThreadInput(GetCurrentThreadId(), idActive, TRUE) )
571 SetForegroundWindow( win );
572 AttachThreadInput(GetCurrentThreadId(), idActive, FALSE);
578 SetWindowPos( win, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE );
588 return s_deskWidget->availableGeometry( desktop );
594 kDebug() <<
"QRect KWindowSystem::workArea( const QList<WId>& exclude, int desktop ) isn't yet implemented!";
600 return i18n(
"Desktop %1", desktop );
605 kDebug() <<
"KWindowSystem::setDesktopName( int desktop, const QString& name ) isn't yet implemented!";
616 kDebug() <<
"KWindowSystem::setUserTime( WId win, long time ) isn't yet implemented!";
628 int what = INFO_BASIC;
631 else if( QLatin1String( signal ) == SIGNAL(
strutChanged()))
633 else if( QLatin1String( signal ) == QMetaObject::normalizedSignature(SIGNAL(
windowChanged(WId,
const ulong*))).constData())
635 else if( QLatin1String( signal ) == QMetaObject::normalizedSignature(SIGNAL(
windowChanged(WId,uint))).constData())
637 else if( QLatin1String( signal ) == QMetaObject::normalizedSignature(SIGNAL(
windowChanged(WId))).constData())
641 QObject::connectNotify( signal );
645 int right_width,
int right_start,
int right_end,
int top_width,
int top_start,
int top_end,
646 int bottom_width,
int bottom_start,
int bottom_end )
648 kDebug() <<
"KWindowSystem::setExtendedStrut isn't yet implemented!";
653 kDebug() <<
"KWindowSystem::setStrut isn't yet implemented!";
660 kDebug() <<
"QString KWindowSystem::readNameProperty( WId window, unsigned long atom ) isn't yet implemented!";
667 kDebug() <<
"KWindowSystem::doNotManage( const QString& title ) isn't yet implemented!";
672 KWindowSystem::init(INFO_WINDOWS);
673 return KWindowSystem::s_d_func()->stackingOrder;
678 KWindowSystem::init(INFO_WINDOWS);
679 return KWindowSystem::s_d_func()->stackingOrder;
685 kDebug() <<
"setType( WId win, NET::WindowType windowType ) isn't yet implemented!";
690 KWindowSystem::init(INFO_WINDOWS);
691 return KWindowInfo( win, properties, properties2 );
696 KWindowSystem::init(INFO_WINDOWS);
697 return KWindowSystem::s_d_func()->winInfos.contains(w);
703 AllowSetForegroundWindow( pid == -1 ? ASFW_ANY : pid );
710 kDebug() <<
"setBlockingCompositing( WId window, bool active ) isn't yet implemented!";
713 #include "kwindowsystem.moc"