KWindowSystem

platforms/windows/kwindowsystem.cpp
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 2007 Laurent Montel <[email protected]>
4  SPDX-FileCopyrightText: 2007 Christian Ehrlicher <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.1-or-later
7 */
8 
9 #include "kwindowsystem.h"
10 
11 #include <QApplication>
12 #include <QBitmap>
13 #include <QDebug>
14 #include <QDesktopWidget>
15 #include <QIcon>
16 #include <QLibrary>
17 #include <QMetaMethod>
18 #include <QPixmap>
19 #include <QtWin>
20 
21 #include <windows.h>
22 #include <windowsx.h>
23 
24 #ifdef _WIN64
25 #define GCL_HICON GCLP_HICON
26 #define GCL_HICONSM GCLP_HICONSM
27 #endif
28 
29 // function to register us as taskmanager
30 #define RSH_UNREGISTER 0
31 #define RSH_REGISTER 1
32 #define RSH_TASKMGR 3
33 typedef bool(WINAPI *PtrRegisterShellHook)(HWND hWnd, DWORD method);
34 
35 static PtrRegisterShellHook pRegisterShellHook = 0;
36 static int WM_SHELLHOOK = -1;
37 
38 class KWindowSystemStaticContainer
39 {
40 public:
41  KWindowSystemStaticContainer()
42  : d(0)
43  {
44  }
45  KWindowSystem kwm;
46  KWindowSystemPrivate *d;
47 };
48 
49 Q_GLOBAL_STATIC(KWindowSystemStaticContainer, g_kwmInstanceContainer)
50 
51 struct InternalWindowInfo {
52  InternalWindowInfo()
53  {
54  }
55  QPixmap bigIcon;
56  QPixmap smallIcon;
57  QString windowName;
58 };
59 
60 class KWindowSystemPrivate : public QWidget
61 {
62  friend class KWindowSystem;
63 
64 public:
65  KWindowSystemPrivate(int what);
66  ~KWindowSystemPrivate();
67 
68  static bool CALLBACK EnumWindProc(HWND hwnd, LPARAM lparam);
69  static void readWindowInfo(HWND hwnd, InternalWindowInfo *winfo);
70 
71  void windowAdded(WId wid);
72  void windowRemoved(WId wid);
73  void windowActivated(WId wid);
74  void windowRedraw(WId wid);
75  void windowFlash(WId wid);
76  void windowStateChanged(WId wid);
77  void reloadStackList();
78  void activate();
79 
80 protected:
81  bool nativeEvent(const QByteArray &eventType, void *message, long *result) override;
82 
83 private:
84  bool activated;
85  int what;
86  WId fakeHwnd;
89 };
90 
91 static HBITMAP QPixmapMask2HBitmap(const QPixmap &pix)
92 {
93  QBitmap bm = pix.mask();
94  if (bm.isNull()) {
95  bm = QBitmap(pix.size());
96  bm.fill(Qt::color1);
97  }
99  im.invertPixels(); // funny blank'n'white games on windows
100  int w = im.width();
101  int h = im.height();
102  int bpl = ((w + 15) / 16) * 2; // bpl, 16 bit alignment
103  QByteArray bits(bpl * h, '\0');
104  for (int y = 0; y < h; y++) {
105  memcpy(bits.data() + y * bpl, im.scanLine(y), bpl);
106  }
107  return CreateBitmap(w, h, 1, 1, bits.constData());
108 }
109 
110 KWindowSystemPrivate::KWindowSystemPrivate(int what)
111  : QWidget(0)
112  , activated(false)
113 {
114  // i think there is no difference in windows we always load everything
115  what = KWindowSystem::INFO_WINDOWS;
116  setVisible(false);
117 }
118 
119 void KWindowSystemPrivate::activate()
120 {
121 #if 0
122  //prevent us from doing the same over and over again
123  if (activated) {
124  return;
125  }
126  activated = true;
127 
128  //resolve winapi stuff
129  if (!pRegisterShellHook) {
130  pRegisterShellHook = (PtrRegisterShellHook)QLibrary::resolve("shell32", (LPCSTR)0xb5);
131  }
132 
133  //get the id for the shellhook message
134  if (WM_SHELLHOOK == -1) {
135  WM_SHELLHOOK = RegisterWindowMessage(TEXT("SHELLHOOK"));
136  //qDebug() << "WM_SHELLHOOK:" << WM_SHELLHOOK << winId();
137  }
138 
139  bool shellHookRegistered = false;
140  if (pRegisterShellHook) {
141  shellHookRegistered = pRegisterShellHook(winId(), RSH_TASKMGR);
142  }
143 
144  if (!shellHookRegistered)
145  //use a timer and poll the windows ?
146  {
147  qDebug() << "Could not create shellhook to receive WindowManager Events";
148  }
149 
150  //fetch window infos
151  reloadStackList();
152 #endif
153 }
154 
155 KWindowSystemPrivate::~KWindowSystemPrivate()
156 {
157  if (pRegisterShellHook) {
158  pRegisterShellHook(reinterpret_cast<HWND>(winId()), RSH_UNREGISTER);
159  }
160 }
161 
162 /**
163  *the callback procedure for the invisible ShellHook window
164  */
165 bool KWindowSystemPrivate::nativeEvent(const QByteArray &eventType, void *message_, long *result)
166 {
167  if (eventType != QByteArrayLiteral("windows_generic_MSG")) {
168  return QWidget::nativeEvent(eventType, message_, result);
169  }
170 
171  MSG *message = static_cast<MSG *>(message_);
172 
173  /*
174  check winuser.h for the following codes
175  HSHELL_WINDOWCREATED 1
176  HSHELL_WINDOWDESTROYED 2
177  HSHELL_ACTIVATESHELLWINDOW 3
178  HSHELL_WINDOWACTIVATED 4
179  HSHELL_GETMINRECT 5
180  HSHELL_RUDEAPPACTIVATED 32768 + 4 = 32772
181  HSHELL_REDRAW 6
182  HSHELL_FLASH 32768 + 6 = 32774
183  HSHELL_TASKMAN 7
184  HSHELL_LANGUAGE 8
185  HSHELL_SYSMENU 9
186  HSHELL_ENDTASK 10
187  HSHELL_ACCESSIBILITYSTATE 11
188  HSHELL_APPCOMMAND 12
189  HSHELL_WINDOWREPLACED 13
190  HSHELL_WINDOWREPLACING 14
191  */
192  if (message->message == WM_SHELLHOOK) {
193  // qDebug() << "what has happened?:" << message->wParam << message->message;
194 
195  switch (message->wParam) {
196  case HSHELL_WINDOWCREATED:
197  KWindowSystem::s_d_func()->windowAdded(static_cast<WId>(message->lParam));
198  break;
199  case HSHELL_WINDOWDESTROYED:
200  KWindowSystem::s_d_func()->windowRemoved(static_cast<WId>(message->lParam));
201  break;
202  case HSHELL_WINDOWACTIVATED:
203 #ifndef _WIN32_WCE
204  case HSHELL_RUDEAPPACTIVATED:
205 #endif
206  KWindowSystem::s_d_func()->windowActivated(static_cast<WId>(message->lParam));
207  break;
208 #ifndef _WIN32_WCE
209  case HSHELL_GETMINRECT:
210  KWindowSystem::s_d_func()->windowStateChanged(static_cast<WId>(message->lParam));
211  break;
212  case HSHELL_REDRAW: // the caption has changed
213  KWindowSystem::s_d_func()->windowRedraw(static_cast<WId>(message->lParam));
214  break;
215  case HSHELL_FLASH:
216  KWindowSystem::s_d_func()->windowFlash(static_cast<WId>(message->lParam));
217  break;
218 #endif
219  }
220  }
221  return QWidget::nativeEvent(eventType, message_, result);
222 }
223 
224 bool CALLBACK KWindowSystemPrivate::EnumWindProc(HWND hWnd, LPARAM lparam)
225 {
226  WId win = reinterpret_cast<WId>(hWnd);
227  QByteArray windowText = QByteArray((GetWindowTextLength(hWnd) + 1) * sizeof(wchar_t), 0);
228  GetWindowTextW(hWnd, (LPWSTR)windowText.data(), windowText.size());
229  DWORD ex_style = GetWindowExStyle(hWnd);
230  KWindowSystemPrivate *p = KWindowSystem::s_d_func();
231 
232  QString add;
233  if (!QString::fromWCharArray((wchar_t *)windowText.data()).trimmed().isEmpty() && IsWindowVisible(hWnd) && !(ex_style & WS_EX_TOOLWINDOW)
234  && !GetParent(hWnd) && !GetWindow(hWnd, GW_OWNER) && !p->winInfos.contains(win)) {
235  // qDebug()<<"Adding window to windowList " << add + QString(windowText).trimmed();
236 
237  InternalWindowInfo winfo;
238  KWindowSystemPrivate::readWindowInfo(hWnd, &winfo);
239 
240  p->stackingOrder.append(win);
241  p->winInfos.insert(win, winfo);
242  }
243  return true;
244 }
245 
246 void KWindowSystemPrivate::readWindowInfo(HWND hWnd, InternalWindowInfo *winfo)
247 {
248  QByteArray windowText = QByteArray((GetWindowTextLength(hWnd) + 1) * sizeof(wchar_t), 0);
249  GetWindowTextW(hWnd, (LPWSTR)windowText.data(), windowText.size());
250  // maybe use SendMessageTimout here?
251  QPixmap smallIcon;
252  HICON hSmallIcon = (HICON)SendMessage(hWnd, WM_GETICON, ICON_SMALL, 0);
253  // if(!hSmallIcon) hSmallIcon = (HICON)SendMessage(hWnd, WM_GETICON, ICON_SMALL2, 0);
254  if (!hSmallIcon) {
255  hSmallIcon = (HICON)SendMessage(hWnd, WM_GETICON, ICON_BIG, 0);
256  }
257 #ifndef _WIN32_WCE
258  if (!hSmallIcon) {
259  hSmallIcon = (HICON)GetClassLong(hWnd, GCL_HICONSM);
260  }
261  if (!hSmallIcon) {
262  hSmallIcon = (HICON)GetClassLong(hWnd, GCL_HICON);
263  }
264 #endif
265  if (!hSmallIcon) {
266  hSmallIcon = (HICON)SendMessage(hWnd, WM_QUERYDRAGICON, 0, 0);
267  }
268  if (hSmallIcon) {
269  smallIcon = QtWin::fromHICON(hSmallIcon);
270  }
271 
272  QPixmap bigIcon;
273  HICON hBigIcon = (HICON)SendMessage(hWnd, WM_GETICON, ICON_BIG, 0);
274  // if(!hBigIcon) hBigIcon = (HICON)SendMessage(hWnd, WM_GETICON, ICON_SMALL2, 0);
275  if (!hBigIcon) {
276  hBigIcon = (HICON)SendMessage(hWnd, WM_GETICON, ICON_SMALL, 0);
277  }
278 #ifndef _WIN32_WCE
279  if (!hBigIcon) {
280  hBigIcon = (HICON)GetClassLong(hWnd, GCL_HICON);
281  }
282  if (!hBigIcon) {
283  hBigIcon = (HICON)GetClassLong(hWnd, GCL_HICONSM);
284  }
285 #endif
286  if (!hBigIcon) {
287  hBigIcon = (HICON)SendMessage(hWnd, WM_QUERYDRAGICON, 0, 0);
288  }
289  if (hBigIcon) {
290  bigIcon = QtWin::fromHICON(hBigIcon);
291  }
292 
293  winfo->bigIcon = bigIcon;
294  winfo->smallIcon = smallIcon;
295  winfo->windowName = QString::fromWCharArray((wchar_t *)windowText.data()).trimmed();
296 }
297 
298 void KWindowSystemPrivate::windowAdded(WId wid)
299 {
300  // qDebug() << "window added!";
301  KWindowSystem::s_d_func()->reloadStackList();
305 }
306 
307 void KWindowSystemPrivate::windowRemoved(WId wid)
308 {
309  // qDebug() << "window removed!";
310  KWindowSystem::s_d_func()->reloadStackList();
313 }
314 
315 void KWindowSystemPrivate::windowActivated(WId wid)
316 {
317  // qDebug() << "window activated!";
318  if (!wid) {
319  return;
320  }
321 
322  KWindowSystem::s_d_func()->reloadStackList();
325 }
326 
327 void KWindowSystemPrivate::windowRedraw(WId wid)
328 {
329  KWindowSystem::s_d_func()->reloadStackList();
330 }
331 
332 void KWindowSystemPrivate::windowFlash(WId wid)
333 {
334  // emit KWindowSystem::self()->demandAttention( wid );
335 }
336 
337 void KWindowSystemPrivate::windowStateChanged(WId wid)
338 {
339 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 80)
341 #endif
342 
344 }
345 
346 void KWindowSystemPrivate::reloadStackList()
347 {
348  KWindowSystem::s_d_func()->stackingOrder.clear();
349  KWindowSystem::s_d_func()->winInfos.clear();
350  // EnumWindows((WNDENUMPROC)EnumWindProc, 0 );
351 }
352 
354 {
355  return &(g_kwmInstanceContainer()->kwm);
356 }
357 
358 KWindowSystemPrivate *KWindowSystem::s_d_func()
359 {
360  return g_kwmInstanceContainer()->d;
361 }
362 
363 void KWindowSystem::init(int what)
364 {
365  KWindowSystemPrivate *const s_d = s_d_func();
366 
367  if (what >= INFO_WINDOWS) {
368  what = INFO_WINDOWS;
369  } else {
370  what = INFO_BASIC;
371  }
372 
373  if (!s_d) {
374  g_kwmInstanceContainer()->d = new KWindowSystemPrivate(what); // invalidates s_d
375  g_kwmInstanceContainer()->d->activate();
376  } else if (s_d->what < what) {
377  delete s_d;
378  g_kwmInstanceContainer()->d = new KWindowSystemPrivate(what); // invalidates s_d
379  g_kwmInstanceContainer()->d->activate();
380  }
381 }
382 
384 {
385  return false;
386 }
387 
389 {
390  return 1;
391 }
392 
394 {
395  return 1;
396 }
397 
398 void KWindowSystem::setMainWindow(QWidget *subwindow, WId mainwindow)
399 {
400  SetForegroundWindow(reinterpret_cast<HWND>(subwindow->winId()));
401 }
402 
403 void KWindowSystem::setCurrentDesktop(int desktop)
404 {
405  qDebug() << "KWindowSystem::setCurrentDesktop( int desktop ) isn't yet implemented!";
406  // TODO
407 }
408 
409 void KWindowSystem::setOnAllDesktops(WId win, bool b)
410 {
411  qDebug() << "KWindowSystem::setOnAllDesktops( WId win, bool b ) isn't yet implemented!";
412  // TODO
413 }
414 
415 void KWindowSystem::setOnDesktop(WId win, int desktop)
416 {
417  // TODO
418  qDebug() << "KWindowSystem::setOnDesktop( WId win, int desktop ) isn't yet implemented!";
419 }
420 
422 {
423  return reinterpret_cast<WId>(GetActiveWindow());
424 }
425 
426 void KWindowSystem::activateWindow(WId win, long)
427 {
428  SetActiveWindow(reinterpret_cast<HWND>(win));
429 }
430 
431 void KWindowSystem::forceActiveWindow(WId win, long time)
432 {
433  HWND hwnd = reinterpret_cast<HWND>(win);
434  // FIXME restoring a hidden window doesn't work: the window contents just appear white.
435  // But the mouse cursor still acts as if the widgets were there (e.g. button clicking works),
436  // which indicates the issue is at the window/backingstore level.
437  // This is probably a side effect of bypassing Qt's internal window state handling.
438 #ifndef _WIN32_WCE
439  if (IsIconic(hwnd) /*|| !IsWindowVisible( win ) */) {
440  // Do not activate the window as we restore it,
441  // otherwise the window appears see-through (contents not updated).
442  ShowWindow(hwnd, SW_SHOWNOACTIVATE);
443  }
444 #endif
445  // Puts the window in front and activates it.
446  // to bring a window to the front while the user is active in a different application we
447  // have to attach our self to the current active window
448  HWND hwndActiveWin = GetForegroundWindow();
449  int idActive = GetWindowThreadProcessId(hwndActiveWin, nullptr);
450  if (AttachThreadInput(GetCurrentThreadId(), idActive, TRUE)) {
451  SetForegroundWindow(hwnd);
452  SetFocus(hwnd);
453  AttachThreadInput(GetCurrentThreadId(), idActive, FALSE);
454  }
455 }
456 
457 void KWindowSystem::demandAttention(WId win, bool set)
458 {
459 // One can not flash a windows in wince
460 #ifndef _WIN32_WCE
461  FLASHWINFO fi;
462  fi.cbSize = sizeof(FLASHWINFO);
463  fi.hwnd = reinterpret_cast<HWND>(win);
464  fi.dwFlags = set ? FLASHW_ALL : FLASHW_STOP;
465  fi.uCount = 5;
466  fi.dwTimeout = 0;
467 
468  FlashWindowEx(&fi);
469 #endif
470 }
471 
472 QPixmap KWindowSystem::icon(WId win, int width, int height, bool scale)
473 {
474  KWindowSystem::init(INFO_WINDOWS);
475 
476  QPixmap pm;
477  if (KWindowSystem::s_d_func()->winInfos.contains(win)) {
478  if (width < 24 || height < 24) {
479  pm = KWindowSystem::s_d_func()->winInfos[win].smallIcon;
480  } else {
481  pm = KWindowSystem::s_d_func()->winInfos[win].bigIcon;
482  }
483  } else {
484  qDebug() << "KWindowSystem::icon winid not in winInfos";
485  UINT size = ICON_BIG;
486  if (width < 24 || height < 24) {
487  size = ICON_SMALL;
488  }
489  HICON hIcon = (HICON)SendMessage(reinterpret_cast<HWND>(win), WM_GETICON, size, 0);
490  if (hIcon != nullptr) {
491  pm = QtWin::fromHICON(hIcon);
492  }
493  }
494  if (scale) {
495  pm = pm.scaled(width, height);
496  }
497  return pm;
498 }
499 
500 QPixmap KWindowSystem::icon(WId win, int width, int height, bool scale, int)
501 {
502  return icon(win, width, height, scale);
503 }
504 
505 void KWindowSystem::setIcons(WId win, const QPixmap &icon, const QPixmap &miniIcon)
506 {
507  KWindowSystem::init(INFO_WINDOWS);
508  KWindowSystemPrivate *s_d = s_d_func();
509 
510  if (s_d->winInfos.contains(win)) {
511  // is this safe enough or do i have to refresh() the window infos
512  s_d->winInfos[win].smallIcon = miniIcon;
513  s_d->winInfos[win].bigIcon = icon;
514  }
515 
516  HICON hIconBig = QtWin::toHICON(icon);
517  HICON hIconSmall = QtWin::toHICON(miniIcon);
518 
519  HWND hwnd = reinterpret_cast<HWND>(win);
520  hIconBig = (HICON)SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)hIconBig);
521  hIconSmall = (HICON)SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hIconSmall);
522 }
523 
524 void KWindowSystem::setState(WId win, NET::States state)
525 {
526  HWND hwnd = reinterpret_cast<HWND>(win);
527  bool got = false;
528 #ifndef _WIN32_WCE
529  if (state & NET::SkipTaskbar) {
530  got = true;
531  LONG_PTR lp = GetWindowLongPtr(hwnd, GWL_EXSTYLE);
532  SetWindowLongPtr(hwnd, GWL_EXSTYLE, lp | WS_EX_TOOLWINDOW);
533  }
534 #endif
535  if (state & NET::KeepAbove) {
536  got = true;
537  SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
538  }
539  if (state & NET::KeepBelow) {
540  got = true;
541  SetWindowPos(hwnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
542  }
543  if (state & NET::Max) {
544  got = true;
545  ShowWindow(hwnd, SW_MAXIMIZE);
546  }
547  if (!got) {
548  qDebug() << "KWindowSystem::setState( WId win, unsigned long state ) isn't yet implemented for the state you requested!";
549  }
550 }
551 
552 void KWindowSystem::clearState(WId win, NET::States state)
553 {
554  bool got = false;
555  HWND hwnd = reinterpret_cast<HWND>(win);
556 
557 #ifndef _WIN32_WCE
558  if (state & NET::SkipTaskbar) {
559  got = true;
560  LONG_PTR lp = GetWindowLongPtr(hwnd, GWL_EXSTYLE);
561  SetWindowLongPtr(hwnd, GWL_EXSTYLE, lp & ~WS_EX_TOOLWINDOW);
562  }
563 #endif
564  if (state & NET::KeepAbove) {
565  got = true;
566  // lets hope this remove the topmost
567  SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
568  }
569  if (state & NET::Max) {
570  got = true;
571  ShowWindow(hwnd, SW_RESTORE);
572  }
573  if (!got) {
574  qDebug() << "KWindowSystem::clearState( WId win, unsigned long state ) isn't yet implemented!";
575  }
576 }
577 
578 void KWindowSystem::minimizeWindow(WId win, bool animation)
579 {
580  Q_UNUSED(animation);
581  ShowWindow(reinterpret_cast<HWND>(win), SW_MINIMIZE);
582 }
583 
584 void KWindowSystem::unminimizeWindow(WId win, bool animation)
585 {
586  Q_UNUSED(animation);
587  ShowWindow(reinterpret_cast<HWND>(win), SW_RESTORE);
588 }
589 
590 void KWindowSystem::raiseWindow(WId win)
591 {
592  // to bring a window to the front while the user is active in a different application we
593  // have to attach our self to the current active window
594  HWND hwndActiveWin = GetForegroundWindow();
595  int idActive = GetWindowThreadProcessId(hwndActiveWin, nullptr);
596  if (AttachThreadInput(GetCurrentThreadId(), idActive, TRUE)) {
597  SetForegroundWindow(reinterpret_cast<HWND>(win));
598  AttachThreadInput(GetCurrentThreadId(), idActive, FALSE);
599  }
600 }
601 
602 void KWindowSystem::lowerWindow(WId win)
603 {
604  SetWindowPos(reinterpret_cast<HWND>(win), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE); // mhhh?
605 }
606 
608 {
609  return true;
610 }
611 
612 QRect KWindowSystem::workArea(int desktop)
613 {
614  return qApp->desktop()->availableGeometry(desktop);
615 }
616 
617 QRect KWindowSystem::workArea(const QList<WId> &exclude, int desktop)
618 {
619  // TODO
620  qDebug() << "QRect KWindowSystem::workArea( const QList<WId>& exclude, int desktop ) isn't yet implemented!";
621  return QRect();
622 }
623 
625 {
626  return tr("Desktop %1").arg(desktop);
627 }
628 
629 void KWindowSystem::setDesktopName(int desktop, const QString &name)
630 {
631  qDebug() << "KWindowSystem::setDesktopName( int desktop, const QString& name ) isn't yet implemented!";
632  // TODO
633 }
634 
636 {
637  return false;
638 }
639 
640 void KWindowSystem::setUserTime(WId win, long time)
641 {
642  qDebug() << "KWindowSystem::setUserTime( WId win, long time ) isn't yet implemented!";
643  // TODO
644 }
645 
647 {
648  return false;
649 }
650 
651 // optimalization - create KWindowSystemPrivate only when needed and only for what is needed
652 void KWindowSystem::connectNotify(const QMetaMethod &method)
653 {
654  int what = INFO_BASIC;
656  what = INFO_WINDOWS;
657  } else if (method == QMetaMethod::fromSignal(&KWindowSystem::strutChanged)) {
658  what = INFO_WINDOWS;
659  } else if (method == QMetaMethod::fromSignal(qOverload<WId, NET::Properties, NET::Properties2>(&KWindowSystem::windowChanged))) {
660  what = INFO_WINDOWS;
661  }
662 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 0)
663  else if (method == QMetaMethod::fromSignal(static_cast<void (KWindowSystem::*)(WId, const ulong *)>(&KWindowSystem::windowChanged))) {
664  what = INFO_WINDOWS;
665  } else if (method == QMetaMethod::fromSignal(static_cast<void (KWindowSystem::*)(WId, uint)>(&KWindowSystem::windowChanged))) {
666  what = INFO_WINDOWS;
667  }
668 #endif
669 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 80)
670  else if (method == QMetaMethod::fromSignal(static_cast<void (KWindowSystem::*)(WId)>(&KWindowSystem::windowChanged))) {
671  what = INFO_WINDOWS;
672  }
673 #endif
674 
675  init(what);
676  QObject::connectNotify(method);
677 }
678 
680  int left_width,
681  int left_start,
682  int left_end,
683  int right_width,
684  int right_start,
685  int right_end,
686  int top_width,
687  int top_start,
688  int top_end,
689  int bottom_width,
690  int bottom_start,
691  int bottom_end)
692 {
693  qDebug() << "KWindowSystem::setExtendedStrut isn't yet implemented!";
694  // TODO
695 }
696 void KWindowSystem::setStrut(WId win, int left, int right, int top, int bottom)
697 {
698  qDebug() << "KWindowSystem::setStrut isn't yet implemented!";
699  // TODO
700 }
701 
702 QString KWindowSystem::readNameProperty(WId window, unsigned long atom)
703 {
704  // TODO
705  qDebug() << "QString KWindowSystem::readNameProperty( WId window, unsigned long atom ) isn't yet implemented!";
706  return QString();
707 }
708 
710 {
711  KWindowSystem::init(INFO_WINDOWS);
712  return KWindowSystem::s_d_func()->stackingOrder;
713 }
714 
716 {
717  KWindowSystem::init(INFO_WINDOWS);
718  return KWindowSystem::s_d_func()->stackingOrder;
719 }
720 
721 void KWindowSystem::setType(WId win, NET::WindowType windowType)
722 {
723  // TODO
724  qDebug() << "setType( WId win, NET::WindowType windowType ) isn't yet implemented!";
725 }
726 
727 #if KWINDOWSYSTEM_BUILD_DEPRECATED_SINCE(5, 0)
728 KWindowInfo KWindowSystem::windowInfo(WId win, unsigned long properties, unsigned long properties2)
729 {
730  KWindowSystem::init(INFO_WINDOWS);
731  return KWindowInfo(win, properties, properties2);
732 }
733 #endif
734 
735 bool KWindowSystem::hasWId(WId w)
736 {
737  KWindowSystem::init(INFO_WINDOWS);
738  return KWindowSystem::s_d_func()->winInfos.contains(w);
739 }
740 
742 {
743 #ifndef _WIN32_WCE
744  AllowSetForegroundWindow(pid == -1 ? ASFW_ANY : pid);
745 #endif
746 }
747 
748 void KWindowSystem::setBlockingCompositing(WId window, bool active)
749 {
750  // TODO
751  qDebug() << "setBlockingCompositing( WId window, bool active ) isn't yet implemented!";
752 }
753 
754 #include "moc_kwindowsystem.cpp"
static QString readNameProperty(WId window, unsigned long atom)
Function that reads and returns the contents of the given text property (WM_NAME, WM_ICON_NAME...
uchar * scanLine(int i)
QString fromWCharArray(const wchar_t *string, int size)
KCOREADDONS_EXPORT void message(KMessage::MessageType messageType, const QString &text, const QString &caption=QString())
void windowChanged(WId id, NET::Properties properties, NET::Properties2 properties2)
The window changed.
QImage convertToFormat(QImage::Format format, Qt::ImageConversionFlags flags) const &const
QSize size() const const
indicates that a window should on top of most windows (but below fullscreen windows).
Definition: netwm_def.h:535
static void lowerWindow(WId win)
Lowers the given window.
indicates that a window should not be included on a taskbar.
Definition: netwm_def.h:530
static void setMainWindow(QWindow *subwindow, WId mainwindow)
Sets the parent window of subwindow to be mainwindow.
indicates that a window should be below most windows (but above any desktop windows).
Definition: netwm_def.h:559
void fill(const QColor &color)
static QString desktopName(int desktop)
Returns the name of the specified desktop.
Convenience access to certain properties and features of the window manager.
Definition: kwindowsystem.h:44
static void setOnDesktop(WId win, int desktop)
Moves window win to desktop desktop.
KIOFILEWIDGETS_EXPORT void add(const QString &fileClass, const QString &directory)
This class provides information about a given window in the platform specific windowing system...
Definition: kwindowinfo.h:62
static void setUserTime(WId win, long time)
Sets user timestamp time on window win.
static void raiseWindow(WId win)
Raises the given window.
static void forceActiveWindow(WId win, long time=0)
Sets window win to be the active window.
static void setType(WId win, NET::WindowType windowType)
Sets the type of window win to windowType.
QString tr(const char *sourceText, const char *disambiguation, int n)
static void setExtendedStrut(WId win, int left_width, int left_start, int left_end, int right_width, int right_start, int right_end, int top_width, int top_start, int top_end, int bottom_width, int bottom_start, int bottom_end)
Sets the strut of window win to left_width ranging from left_start to left_end on the left edge...
static void clearState(WId win, NET::States state)
Clears the state of window win from state.
static void activateWindow(WId win, long time=0)
Requests that window win is activated.
static int currentDesktop()
Returns the current virtual desktop.
static KWindowInfo windowInfo(WId win, NET::Properties properties, NET::Properties2 properties2=NET::Properties2())
Returns information about window win.
static WId activeWindow()
Returns the currently active window, or 0 if no window is active.
WindowType
Window type.
Definition: netwm_def.h:357
static bool icccmCompliantMappingState()
int width() const const
static void setBlockingCompositing(WId window, bool active)
Sets whether the client wishes to block compositing (for better performance)
bool isEmpty() const const
void windowAdded(WId id)
A window has been added.
virtual bool nativeEvent(const QByteArray &eventType, void *message, long *result)
static void setStrut(WId win, int left, int right, int top, int bottom)
Convenience function for setExtendedStrut() that automatically makes struts as wide/high as the scree...
QBitmap mask() const const
WId winId() const const
QPixmap scaled(int width, int height, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformMode) const const
static void unminimizeWindow(WId win)
Unminimizes the window with id win.
QMetaMethod fromSignal(PointerToMemberFunction signal)
static void setCurrentDesktop(int desktop)
Convenience function to set the current desktop to desktop.
static void setState(WId win, NET::States state)
Sets the state of window win to state.
virtual void connectNotify(const QMetaMethod &signal)
static QRect workArea(int desktop=-1)
Returns the workarea for the specified desktop, or the current work area if no desktop has been speci...
bool isNull() const const
static void setIcons(WId win, const QPixmap &icon, const QPixmap &miniIcon)
Sets an icon and a miniIcon on window win.
void windowRemoved(WId id)
A window has been removed.
QCA_EXPORT void init()
static KWindowSystem * self()
Access to the singleton instance.
void invertPixels(QImage::InvertMode mode)
static void allowExternalProcessWindowActivation(int pid=-1)
Allows a window from another process to raise and activate itself.
static void minimizeWindow(WId win)
Minimizes the window with id win.
void workAreaChanged()
The workarea has changed.
static QList< WId > windows()
Returns the list of all toplevel windows currently managed by the window manager in the order of crea...
static bool hasWId(WId id)
Test to see if id still managed at present.
static bool showingDesktop()
Returns the state of showing the desktop.
QFunctionPointer resolve(const char *symbol)
void stackingOrderChanged()
Emitted when the stacking order of the window changed.
static void demandAttention(WId win, bool set=true)
When application finishes some operation and wants to notify the user about it, it can call demandAtt...
static void setOnAllDesktops(WId win, bool b)
Sets window win to be present on all virtual desktops if is true.
static int numberOfDesktops()
Returns the number of virtual desktops.
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
static bool allowedActionsSupported()
Returns true if the WM announces which actions it allows for windows.
static bool compositingActive()
Returns true if a compositing manager is running (i.e.
static QPixmap icon(WId win, int width=-1, int height=-1, bool scale=false)
Returns an icon for window win.
char * data()
int height() const const
convenience value.
Definition: netwm_def.h:522
QImage toImage() const const
void strutChanged()
Something changed with the struts, may or may not have changed the work area.
int size() const const
void activeWindowChanged(WId id)
Hint that <Window> is active (= has focus) now.
static QList< WId > stackingOrder()
Returns the list of all toplevel windows currently managed by the window manager in the current stack...
Q_EMITQ_EMIT
static void setDesktopName(int desktop, const QString &name)
Sets the name of the specified desktop.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Oct 15 2021 22:41:50 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.