BsLinuxWindow.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsLinuxWindow.h"
  4. #include "BsLinuxPlatform.h"
  5. #include "BsLinuxDropTarget.h"
  6. #include <X11/Xatom.h>
  7. #include <X11/extensions/Xrandr.h>
  8. #include <X11/Xutil.h>
  9. #include <X11/Xlib.h>
  10. #define _NET_WM_STATE_REMOVE 0
  11. #define _NET_WM_STATE_ADD 1
  12. #define _NET_WM_STATE_TOGGLE 2
  13. #define _NET_WM_MOVERESIZE_MOVE 8
  14. #define _NET_WM_MOVERESIZE_CANCEL 11
  15. #define WM_NormalState 1
  16. #define WM_IconicState 3
  17. namespace bs
  18. {
  19. enum class WindowState
  20. {
  21. Minimized,
  22. Maximized,
  23. Normal
  24. };
  25. struct LinuxWindow::Pimpl
  26. {
  27. ::Window xWindow = 0;
  28. INT32 x, y;
  29. UINT32 width, height;
  30. bool hasTitleBar = true;
  31. bool dragInProgress = false;
  32. bool resizeDisabled = false;
  33. WindowState state = WindowState::Normal;
  34. Vector<Rect2I> dragZones;
  35. void* userData = nullptr;
  36. };
  37. LinuxWindow::LinuxWindow(const WINDOW_DESC &desc)
  38. {
  39. m = bs_new<Pimpl>();
  40. ::Display* display = LinuxPlatform::getXDisplay();
  41. // Find the screen of the chosen monitor, as well as its current dimensions
  42. INT32 screen = XDefaultScreen(display);
  43. UINT32 outputIdx = 0;
  44. RROutput primaryOutput = XRRGetOutputPrimary(display, RootWindow(display, screen));
  45. INT32 monitorX = 0;
  46. INT32 monitorY = 0;
  47. UINT32 monitorWidth = 0;
  48. UINT32 monitorHeight = 0;
  49. INT32 screenCount = XScreenCount(display);
  50. for(INT32 i = 0; i < screenCount; i++)
  51. {
  52. XRRScreenResources* screenRes = XRRGetScreenResources(display, RootWindow(display, i));
  53. bool foundMonitor = false;
  54. for (INT32 j = 0; j < screenRes->noutput; j++)
  55. {
  56. XRROutputInfo* outputInfo = XRRGetOutputInfo(display, screenRes, screenRes->outputs[j]);
  57. if (outputInfo == nullptr || outputInfo->crtc == 0 || outputInfo->connection == RR_Disconnected)
  58. {
  59. XRRFreeOutputInfo(outputInfo);
  60. continue;
  61. }
  62. XRRCrtcInfo* crtcInfo = XRRGetCrtcInfo(display, screenRes, outputInfo->crtc);
  63. if (crtcInfo == nullptr)
  64. {
  65. XRRFreeCrtcInfo(crtcInfo);
  66. XRRFreeOutputInfo(outputInfo);
  67. continue;
  68. }
  69. if(desc.screen == (UINT32)-1)
  70. {
  71. if(screenRes->outputs[j] == primaryOutput)
  72. foundMonitor = true;
  73. }
  74. else
  75. foundMonitor = outputIdx == desc.screen;
  76. if(foundMonitor)
  77. {
  78. screen = i;
  79. monitorX = crtcInfo->x;
  80. monitorY = crtcInfo->y;
  81. monitorWidth = crtcInfo->width;
  82. monitorHeight = crtcInfo->height;
  83. foundMonitor = true;
  84. break;
  85. }
  86. }
  87. if(foundMonitor)
  88. break;
  89. }
  90. XSetWindowAttributes attributes;
  91. attributes.background_pixel = XWhitePixel(display, screen);
  92. attributes.border_pixel = XBlackPixel(display, screen);
  93. attributes.background_pixmap = 0;
  94. attributes.colormap = XCreateColormap(display,
  95. XRootWindow(display, screen),
  96. desc.visualInfo.visual,
  97. AllocNone);
  98. // If no position specified, center on the requested monitor
  99. if (desc.x == -1)
  100. m->x = monitorX + (monitorWidth - desc.width) / 2;
  101. else if (desc.screen != (UINT32)-1)
  102. m->x = monitorX + desc.x;
  103. else
  104. m->x = desc.x;
  105. if (desc.y == -1)
  106. m->y = monitorY + (monitorHeight - desc.height) / 2;
  107. else if (desc.screen != (UINT32)-1)
  108. m->y = monitorY + desc.y;
  109. else
  110. m->y = desc.y;
  111. m->width = desc.width;
  112. m->height = desc.height;
  113. m->xWindow = XCreateWindow(display,
  114. XRootWindow(display, screen),
  115. m->x, m->y,
  116. m->width, m->height,
  117. 0, desc.visualInfo.depth,
  118. InputOutput, desc.visualInfo.visual,
  119. CWBackPixel | CWBorderPixel | CWColormap | CWBackPixmap, &attributes);
  120. XStoreName(display, m->xWindow, desc.title.c_str());
  121. // Position/size might have (and usually will) get overridden by the WM, so re-apply them
  122. XSizeHints hints;
  123. hints.flags = PPosition | PSize;
  124. hints.x = m->x;
  125. hints.y = m->y;
  126. hints.width = m->width;
  127. hints.height = m->height;
  128. if(!desc.allowResize)
  129. {
  130. hints.flags |= PMinSize | PMaxSize;
  131. hints.min_height = desc.height;
  132. hints.max_height = desc.height;
  133. hints.min_width = desc.width;
  134. hints.max_width = desc.width;
  135. }
  136. XSetNormalHints(display, m->xWindow, &hints);
  137. setShowDecorations(desc.showDecorations);
  138. setIsModal(desc.modal);
  139. XClassHint* classHint = XAllocClassHint();
  140. classHint->res_class = (char*)"banshee3d";
  141. classHint->res_name = (char*)desc.title.c_str();
  142. XSetClassHint(display, m->xWindow, classHint);
  143. XFree(classHint);
  144. // Ensures the child window is always on top of the parent window
  145. if(desc.parent)
  146. XSetTransientForHint(display, m->xWindow, desc.parent);
  147. XSelectInput(display, m->xWindow,
  148. ExposureMask | FocusChangeMask |
  149. KeyPressMask | KeyReleaseMask |
  150. ButtonPressMask | ButtonReleaseMask |
  151. EnterWindowMask | LeaveWindowMask |
  152. PointerMotionMask | ButtonMotionMask |
  153. StructureNotifyMask | PropertyChangeMask
  154. );
  155. // Make sure we get the window delete message from WM, so we can clean up ourselves
  156. Atom atomDeleteWindow = XInternAtom(display, "WM_DELETE_WINDOW", False);
  157. XSetWMProtocols(display, m->xWindow, &atomDeleteWindow, 1);
  158. // Enable drag and drop
  159. LinuxDragAndDrop::makeDNDAware(m->xWindow);
  160. // Set background image if assigned
  161. if(desc.background)
  162. {
  163. Pixmap pixmap = LinuxPlatform::createPixmap(*desc.background, (UINT32)desc.visualInfo.depth);
  164. XSetWindowBackgroundPixmap(display, m->xWindow, pixmap);
  165. XFreePixmap(display, pixmap);
  166. XSync(display, 0);
  167. }
  168. // Show the window (needs to happen after setting the background pixmap)
  169. if(!desc.hidden)
  170. XMapWindow(display, m->xWindow);
  171. if(!desc.showOnTaskBar)
  172. showOnTaskbar(false);
  173. m->hasTitleBar = desc.showDecorations;
  174. m->resizeDisabled = !desc.allowResize;
  175. LinuxPlatform::_registerWindow(m->xWindow, this);
  176. }
  177. LinuxWindow::~LinuxWindow()
  178. {
  179. if(m->xWindow != 0)
  180. _destroy();
  181. bs_delete(m);
  182. }
  183. void LinuxWindow::move(INT32 x, INT32 y)
  184. {
  185. m->x = x;
  186. m->y = y;
  187. XMoveWindow(LinuxPlatform::getXDisplay(), m->xWindow, x, y);
  188. }
  189. void LinuxWindow::resize(UINT32 width, UINT32 height)
  190. {
  191. // If resize is disabled on WM level, we need to force it
  192. if(m->resizeDisabled)
  193. {
  194. XSizeHints hints;
  195. hints.flags = PMinSize | PMaxSize;
  196. hints.min_height = height;
  197. hints.max_height = height;
  198. hints.min_width = width;
  199. hints.max_width = width;
  200. XSetNormalHints(LinuxPlatform::getXDisplay(), m->xWindow, &hints);
  201. }
  202. m->width = width;
  203. m->height = height;
  204. XResizeWindow(LinuxPlatform::getXDisplay(), m->xWindow, width, height);
  205. }
  206. void LinuxWindow::hide()
  207. {
  208. XUnmapWindow(LinuxPlatform::getXDisplay(), m->xWindow);
  209. }
  210. void LinuxWindow::show()
  211. {
  212. XMapWindow(LinuxPlatform::getXDisplay(), m->xWindow);
  213. XMoveResizeWindow(LinuxPlatform::getXDisplay(), m->xWindow, m->x, m->y, m->width, m->height);
  214. }
  215. void LinuxWindow::maximize()
  216. {
  217. maximize(true);
  218. }
  219. void LinuxWindow::minimize()
  220. {
  221. minimize(true);
  222. }
  223. void LinuxWindow::restore()
  224. {
  225. if(isMaximized())
  226. maximize(false);
  227. else if(isMinimized())
  228. minimize(false);
  229. }
  230. INT32 LinuxWindow::getLeft() const
  231. {
  232. INT32 x, y;
  233. ::Window child;
  234. XTranslateCoordinates(LinuxPlatform::getXDisplay(), m->xWindow, DefaultRootWindow(LinuxPlatform::getXDisplay()),
  235. 0, 0, &x, &y, &child);
  236. return x;
  237. }
  238. INT32 LinuxWindow::getTop() const
  239. {
  240. INT32 x, y;
  241. ::Window child;
  242. XTranslateCoordinates(LinuxPlatform::getXDisplay(), m->xWindow, DefaultRootWindow(LinuxPlatform::getXDisplay()),
  243. 0, 0, &x, &y, &child);
  244. return y;
  245. }
  246. UINT32 LinuxWindow::getWidth() const
  247. {
  248. XWindowAttributes xwa;
  249. XGetWindowAttributes(LinuxPlatform::getXDisplay(), m->xWindow, &xwa);
  250. return (UINT32)xwa.width;
  251. }
  252. UINT32 LinuxWindow::getHeight() const
  253. {
  254. XWindowAttributes xwa;
  255. XGetWindowAttributes(LinuxPlatform::getXDisplay(), m->xWindow, &xwa);
  256. return (UINT32)xwa.height;
  257. }
  258. Vector2I LinuxWindow::windowToScreenPos(const Vector2I& windowPos) const
  259. {
  260. Vector2I screenPos;
  261. ::Window child;
  262. XTranslateCoordinates(LinuxPlatform::getXDisplay(), m->xWindow, DefaultRootWindow(LinuxPlatform::getXDisplay()),
  263. windowPos.x, windowPos.y, &screenPos.x, &screenPos.y, &child);
  264. return screenPos;
  265. }
  266. Vector2I LinuxWindow::screenToWindowPos(const Vector2I& screenPos) const
  267. {
  268. Vector2I windowPos;
  269. ::Window child;
  270. XTranslateCoordinates(LinuxPlatform::getXDisplay(), DefaultRootWindow(LinuxPlatform::getXDisplay()), m->xWindow,
  271. screenPos.x, screenPos.y, &windowPos.x, &windowPos.y, &child);
  272. return windowPos;
  273. }
  274. void LinuxWindow::setIcon(const PixelData& data)
  275. {
  276. ::Display* display = LinuxPlatform::getXDisplay();
  277. Pixmap iconPixmap = LinuxPlatform::createPixmap(data, (UINT32)XDefaultDepth(display, XDefaultScreen(display)));
  278. XWMHints* hints = XAllocWMHints();
  279. hints->flags = IconPixmapHint;
  280. hints->icon_pixmap = iconPixmap;
  281. XSetWMHints(display, m->xWindow, hints);
  282. XFlush(display);
  283. XFree(hints);
  284. XFreePixmap(display, iconPixmap);
  285. }
  286. void LinuxWindow::_destroy()
  287. {
  288. XUnmapWindow(LinuxPlatform::getXDisplay(), m->xWindow);
  289. XSync(LinuxPlatform::getXDisplay(), 0);
  290. XDestroyWindow(LinuxPlatform::getXDisplay(), m->xWindow);
  291. XSync(LinuxPlatform::getXDisplay(), 0);
  292. LinuxPlatform::_unregisterWindow(m->xWindow);
  293. m->xWindow = 0;
  294. }
  295. void LinuxWindow::_setDragZones(const Vector<Rect2I>& rects)
  296. {
  297. m->dragZones = rects;
  298. }
  299. void LinuxWindow::_dragStart(const XButtonEvent& event)
  300. {
  301. // Make sure to reset the flag since WM could have (and probably has) handled the drag end event, so we never
  302. // received _dragEnd() call.
  303. m->dragInProgress = false;
  304. // If window has a titlebar, custom drag zones aren't used
  305. if(m->hasTitleBar)
  306. return;
  307. for(auto& entry : m->dragZones)
  308. {
  309. if (entry.width == 0 || entry.height == 0)
  310. continue;
  311. if(entry.contains(Vector2I(event.x, event.y)))
  312. {
  313. XUngrabPointer(LinuxPlatform::getXDisplay(), 0L);
  314. XFlush(LinuxPlatform::getXDisplay());
  315. Atom wmMoveResize = XInternAtom(LinuxPlatform::getXDisplay(), "_NET_WM_MOVERESIZE", False);
  316. XEvent xev;
  317. memset(&xev, 0, sizeof(xev));
  318. xev.type = ClientMessage;
  319. xev.xclient.window = m->xWindow;
  320. xev.xclient.message_type = wmMoveResize;
  321. xev.xclient.format = 32;
  322. xev.xclient.data.l[0] = event.x_root;
  323. xev.xclient.data.l[1] = event.y_root;
  324. xev.xclient.data.l[2] = _NET_WM_MOVERESIZE_MOVE;
  325. xev.xclient.data.l[3] = Button1;
  326. xev.xclient.data.l[4] = 0;
  327. XSendEvent(LinuxPlatform::getXDisplay(), DefaultRootWindow(LinuxPlatform::getXDisplay()), False,
  328. SubstructureRedirectMask | SubstructureNotifyMask, &xev);
  329. XSync(LinuxPlatform::getXDisplay(), 0);
  330. m->dragInProgress = true;
  331. return;
  332. }
  333. }
  334. return;
  335. }
  336. void LinuxWindow::_dragEnd()
  337. {
  338. // WM failed to end the drag, send the cancel drag event
  339. if(m->dragInProgress)
  340. {
  341. Atom wmMoveResize = XInternAtom(LinuxPlatform::getXDisplay(), "_NET_WM_MOVERESIZE", False);
  342. XEvent xev;
  343. memset(&xev, 0, sizeof(xev));
  344. xev.type = ClientMessage;
  345. xev.xclient.window = m->xWindow;
  346. xev.xclient.message_type = wmMoveResize;
  347. xev.xclient.format = 32;
  348. xev.xclient.data.l[0] = 0;
  349. xev.xclient.data.l[1] = 0;
  350. xev.xclient.data.l[2] = _NET_WM_MOVERESIZE_CANCEL;
  351. xev.xclient.data.l[3] = Button1;
  352. xev.xclient.data.l[4] = 0;
  353. XSendEvent(LinuxPlatform::getXDisplay(), DefaultRootWindow(LinuxPlatform::getXDisplay()), False,
  354. SubstructureRedirectMask | SubstructureNotifyMask, &xev);
  355. m->dragInProgress = false;
  356. }
  357. }
  358. ::Window LinuxWindow::_getXWindow() const
  359. {
  360. return m->xWindow;
  361. }
  362. void LinuxWindow::_setUserData(void* data)
  363. {
  364. m->userData = data;
  365. }
  366. void* LinuxWindow::_getUserData() const
  367. {
  368. return m->userData;
  369. }
  370. bool LinuxWindow::isMaximized() const
  371. {
  372. Atom wmState = XInternAtom(LinuxPlatform::getXDisplay(), "_NET_WM_STATE", False);
  373. Atom type;
  374. INT32 format;
  375. uint64_t length;
  376. uint64_t remaining;
  377. uint8_t* data = nullptr;
  378. INT32 result = XGetWindowProperty(LinuxPlatform::getXDisplay(), m->xWindow, wmState,
  379. 0, 1024, False, XA_ATOM, &type, &format,
  380. &length, &remaining, &data);
  381. if (result == Success)
  382. {
  383. Atom* atoms = (Atom*)data;
  384. Atom wmMaxHorz = XInternAtom(LinuxPlatform::getXDisplay(), "_NET_WM_STATE_MAXIMIZED_HORZ", False);
  385. Atom wmMaxVert = XInternAtom(LinuxPlatform::getXDisplay(), "_NET_WM_STATE_MAXIMIZED_VERT", False);
  386. bool foundHorz = false;
  387. bool foundVert = false;
  388. for (UINT32 i = 0; i < length; i++)
  389. {
  390. if (atoms[i] == wmMaxHorz)
  391. foundHorz = true;
  392. if (atoms[i] == wmMaxVert)
  393. foundVert = true;
  394. if (foundVert && foundHorz)
  395. return true;
  396. }
  397. XFree(atoms);
  398. }
  399. return false;
  400. }
  401. bool LinuxWindow::isMinimized()
  402. {
  403. Atom wmState = XInternAtom(LinuxPlatform::getXDisplay(), "WM_STATE", True);
  404. Atom type;
  405. INT32 format;
  406. uint64_t length;
  407. uint64_t remaining;
  408. uint8_t* data = nullptr;
  409. INT32 result = XGetWindowProperty(LinuxPlatform::getXDisplay(), m->xWindow, wmState,
  410. 0, 1024, False, AnyPropertyType, &type, &format,
  411. &length, &remaining, &data);
  412. if(result == Success)
  413. {
  414. long* state = (long*) data;
  415. if(state[0] == WM_IconicState)
  416. return true;
  417. }
  418. return false;
  419. }
  420. void LinuxWindow::maximize(bool enable)
  421. {
  422. Atom wmState = XInternAtom(LinuxPlatform::getXDisplay(), "_NET_WM_STATE", False);
  423. Atom wmMaxHorz = XInternAtom(LinuxPlatform::getXDisplay(), "_NET_WM_STATE_MAXIMIZED_HORZ", False);
  424. Atom wmMaxVert = XInternAtom(LinuxPlatform::getXDisplay(), "_NET_WM_STATE_MAXIMIZED_VERT", False);
  425. XEvent xev;
  426. memset(&xev, 0, sizeof(xev));
  427. xev.type = ClientMessage;
  428. xev.xclient.window = m->xWindow;
  429. xev.xclient.message_type = wmState;
  430. xev.xclient.format = 32;
  431. xev.xclient.data.l[0] = enable ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
  432. xev.xclient.data.l[1] = wmMaxHorz;
  433. xev.xclient.data.l[2] = wmMaxVert;
  434. XSendEvent(LinuxPlatform::getXDisplay(), DefaultRootWindow(LinuxPlatform::getXDisplay()), False,
  435. SubstructureRedirectMask | SubstructureNotifyMask, &xev);
  436. }
  437. void LinuxWindow::minimize(bool enable)
  438. {
  439. XEvent xev;
  440. Atom wmChange = XInternAtom(LinuxPlatform::getXDisplay(), "WM_CHANGE_STATE", False);
  441. memset(&xev, 0, sizeof(xev));
  442. xev.type = ClientMessage;
  443. xev.xclient.window = m->xWindow;
  444. xev.xclient.message_type = wmChange;
  445. xev.xclient.format = 32;
  446. xev.xclient.data.l[0] = enable ? WM_IconicState : WM_NormalState;
  447. XSendEvent(LinuxPlatform::getXDisplay(), DefaultRootWindow(LinuxPlatform::getXDisplay()), False,
  448. SubstructureRedirectMask | SubstructureNotifyMask, &xev);
  449. }
  450. void LinuxWindow::showOnTaskbar(bool enable)
  451. {
  452. Atom wmState = XInternAtom(LinuxPlatform::getXDisplay(), "_NET_WM_STATE", False);
  453. Atom wmSkipTaskbar = XInternAtom(LinuxPlatform::getXDisplay(), "_NET_WM_STATE_SKIP_TASKBAR", False);
  454. Atom wmSkipPager = XInternAtom(LinuxPlatform::getXDisplay(), "_NET_WM_STATE_SKIP_PAGER", False);
  455. XEvent xev;
  456. memset(&xev, 0, sizeof(xev));
  457. xev.type = ClientMessage;
  458. xev.xclient.window = m->xWindow;
  459. xev.xclient.message_type = wmState;
  460. xev.xclient.format = 32;
  461. xev.xclient.data.l[0] = enable ? _NET_WM_STATE_REMOVE : _NET_WM_STATE_ADD;
  462. xev.xclient.data.l[1] = wmSkipTaskbar;
  463. XSendEvent(LinuxPlatform::getXDisplay(), DefaultRootWindow(LinuxPlatform::getXDisplay()), False,
  464. SubstructureRedirectMask | SubstructureNotifyMask, &xev);
  465. xev.xclient.data.l[1] = wmSkipPager;
  466. XSendEvent(LinuxPlatform::getXDisplay(), DefaultRootWindow(LinuxPlatform::getXDisplay()), False,
  467. SubstructureRedirectMask | SubstructureNotifyMask, &xev);
  468. XSync(LinuxPlatform::getXDisplay(), 0);
  469. }
  470. void LinuxWindow::_setFullscreen(bool fullscreen)
  471. {
  472. // Attempt to bypass compositor if switching to fullscreen
  473. if(fullscreen)
  474. {
  475. Atom wmBypassCompositor = XInternAtom(LinuxPlatform::getXDisplay(), "_NET_WM_BYPASS_COMPOSITOR", False);
  476. if (wmBypassCompositor)
  477. {
  478. static constexpr UINT32 enabled = 1;
  479. XChangeProperty(LinuxPlatform::getXDisplay(), m->xWindow, wmBypassCompositor,
  480. XA_CARDINAL, 32, PropModeReplace, (unsigned char*) &enabled, 1);
  481. }
  482. }
  483. // Make the switch to fullscreen
  484. XEvent xev;
  485. Atom wmState = XInternAtom(LinuxPlatform::getXDisplay(), "_NET_WM_STATE", False);
  486. Atom wmFullscreen = XInternAtom(LinuxPlatform::getXDisplay(), "_NET_WM_STATE_FULLSCREEN", False);
  487. memset(&xev, 0, sizeof(xev));
  488. xev.type = ClientMessage;
  489. xev.xclient.window = m->xWindow;
  490. xev.xclient.message_type = wmState;
  491. xev.xclient.format = 32;
  492. xev.xclient.data.l[0] = fullscreen ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
  493. xev.xclient.data.l[1] = wmFullscreen;
  494. xev.xclient.data.l[2] = 0;
  495. XSendEvent(LinuxPlatform::getXDisplay(), DefaultRootWindow(LinuxPlatform::getXDisplay()), False,
  496. SubstructureRedirectMask | SubstructureNotifyMask, &xev);
  497. }
  498. void LinuxWindow::setShowDecorations(bool show)
  499. {
  500. static constexpr UINT32 MWM_HINTS_DECORATIONS = (1 << 1);
  501. struct MotifHints
  502. {
  503. UINT32 flags;
  504. UINT32 functions;
  505. UINT32 decorations;
  506. INT32 inputMode;
  507. UINT32 status;
  508. };
  509. if(show)
  510. return;
  511. MotifHints motifHints;
  512. motifHints.flags = MWM_HINTS_DECORATIONS;
  513. motifHints.decorations = 0;
  514. motifHints.functions = 0;
  515. motifHints.inputMode = 0;
  516. motifHints.status = 0;
  517. Atom wmHintsAtom = XInternAtom(LinuxPlatform::getXDisplay(), "_MOTIF_WM_HINTS", False);
  518. XChangeProperty(LinuxPlatform::getXDisplay(), m->xWindow,
  519. wmHintsAtom, wmHintsAtom,
  520. 32,
  521. PropModeReplace,
  522. (unsigned char *)&motifHints,
  523. 5);
  524. }
  525. void LinuxWindow::setIsModal(bool modal)
  526. {
  527. if(modal)
  528. {
  529. Atom wmState = XInternAtom(LinuxPlatform::getXDisplay(), "_NET_WM_STATE", False);
  530. Atom wmValue = XInternAtom(LinuxPlatform::getXDisplay(), "_NET_WM_STATE_MODAL", False);
  531. XEvent xev;
  532. memset(&xev, 0, sizeof(xev));
  533. xev.type = ClientMessage;
  534. xev.xclient.window = m->xWindow;
  535. xev.xclient.message_type = wmState;
  536. xev.xclient.format = 32;
  537. xev.xclient.data.l[0] = _NET_WM_STATE_ADD;
  538. xev.xclient.data.l[1] = wmValue;
  539. xev.xclient.data.l[2] = 0;
  540. xev.xclient.data.l[3] = 1;
  541. XSendEvent(LinuxPlatform::getXDisplay(), DefaultRootWindow(LinuxPlatform::getXDisplay()), False,
  542. SubstructureRedirectMask | SubstructureNotifyMask, &xev);
  543. }
  544. }
  545. }