Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. /*
  2.  
  3. MIT License
  4.  
  5. Copyright © 2019 Samuel Venable
  6.  
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13.  
  14. The above copyright notice and this permission notice shall be included in all
  15. copies or substantial portions of the Software.
  16.  
  17. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. SOFTWARE.
  24.  
  25. */
  26.  
  27. #include <X11/Xlib.h>
  28. #include <climits>
  29.  
  30. typedef struct {
  31. unsigned long flags;
  32. unsigned long functions;
  33. unsigned long decorations;
  34. long inputMode;
  35. unsigned long status;
  36. } Hints;
  37.  
  38. bool window_get_showborder(void *hwnd) {
  39. Atom type;
  40. int format;
  41. unsigned long bytes;
  42. unsigned long items;
  43. unsigned char *data = NULL;
  44. bool ret = true;
  45. Display *d = XOpenDisplay(NULL);
  46. Window w = (Window)hwnd;
  47. Atom property = XInternAtom(d, "_MOTIF_WM_HINTS", False);
  48. if (XGetWindowProperty(d, w, property, 0, LONG_MAX, False, AnyPropertyType, &type, &format, &items, &bytes, &data) == Success && data != NULL) {
  49. Hints *hints = (Hints *)data;
  50. ret = hints->decorations;
  51. XFree(data);
  52. }
  53. XCloseDisplay(d);
  54. return ret;
  55. }
  56.  
  57. void window_set_showborder(void *hwnd, bool show, int clientx, int clienty) {
  58. Display *d = XOpenDisplay(NULL);
  59. Window w = (Window)hwnd;
  60. Atom aKWinRunning = XInternAtom(d, "KWIN_RUNNING", True);
  61. bool bKWinRunning = (aKWinRunning != None);
  62. XWindowAttributes wa;
  63. Window root, parent, *child; uint children;
  64. XWindowAttributes pwa;
  65. for (;;) {
  66. XGetWindowAttributes(d, w, &wa);
  67. XQueryTree(d, w, &root, &parent, &child, &children);
  68. XGetWindowAttributes(d, parent, &pwa);
  69. if ((bKWinRunning ? pwa.x : wa.x) || (bKWinRunning ? pwa.y : wa.y) || !window_get_showborder(hwnd))
  70. break;
  71. }
  72. static const int xoffset = bKWinRunning ? pwa.x : wa.x;
  73. static const int yoffset = bKWinRunning ? pwa.y : wa.y;
  74. Hints hints;
  75. Atom property = XInternAtom(d, "_MOTIF_WM_HINTS", False);
  76. hints.flags = 2;
  77. hints.decorations = show;
  78. XChangeProperty(d, w, property, property, 32, PropModeReplace, (unsigned char *)&hints, 5);
  79. int xpos = show ? clientx - xoffset : clientx;
  80. int ypos = show ? clienty - yoffset : clienty;
  81. XMoveResizeWindow(d, w, xpos, ypos, bKWinRunning ? wa.width : wa.width + xoffset, bKWinRunning ? wa.height : wa.height + yoffset);
  82. XCloseDisplay(d);
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement