• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kde-workspace API Reference
  • KDE Home
  • Contact Us
 

KWin

  • kde-4.x
  • kde-workspace
  • kwin
xcbutils.h
Go to the documentation of this file.
1 /********************************************************************
2  KWin - the KDE window manager
3  This file is part of the KDE project.
4 
5 Copyright (C) 2012, 2013 Martin Gräßlin <[email protected]>
6 
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11 
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *********************************************************************/
20 #ifndef KWIN_XCB_UTILS_H
21 #define KWIN_XCB_UTILS_H
22 
23 #include <kwinglobals.h>
24 #include "utils.h"
25 
26 #include <QRect>
27 #include <QRegion>
28 #include <QVector>
29 
30 #include <xcb/xcb.h>
31 #include <xcb/composite.h>
32 #include <xcb/randr.h>
33 
34 #include <xcb/shm.h>
35 
36 namespace KWin {
37 
38 namespace Xcb {
39 
40 typedef xcb_window_t WindowId;
41 
42 // forward declaration of methods
43 static void defineCursor(xcb_window_t window, xcb_cursor_t cursor);
44 static void setInputFocus(xcb_window_t window, uint8_t revertTo = XCB_INPUT_FOCUS_POINTER_ROOT, xcb_timestamp_t time = xTime());
45 static void moveWindow(xcb_window_t window, const QPoint &pos);
46 static void moveWindow(xcb_window_t window, uint32_t x, uint32_t y);
47 static void lowerWindow(xcb_window_t window);
48 static void selectInput(xcb_window_t window, uint32_t events);
49 
50 template <typename Reply,
51  typename Cookie,
52  Reply *(*replyFunc)(xcb_connection_t*, Cookie, xcb_generic_error_t**),
53  Cookie (*requestFunc)(xcb_connection_t*, xcb_window_t)>
54 class Wrapper
55 {
56 public:
57  Wrapper()
58  : m_retrieved(false)
59  , m_window(XCB_WINDOW_NONE)
60  , m_reply(NULL)
61  {
62  m_cookie.sequence = 0;
63  }
64  explicit Wrapper(WindowId window)
65  : m_retrieved(false)
66  , m_cookie(requestFunc(connection(), window))
67  , m_window(window)
68  , m_reply(NULL)
69  {
70  }
71  explicit Wrapper(const Wrapper &other)
72  : m_retrieved(other.m_retrieved)
73  , m_cookie(other.m_cookie)
74  , m_window(other.m_window)
75  , m_reply(NULL)
76  {
77  takeFromOther(const_cast<Wrapper&>(other));
78  }
79  virtual ~Wrapper() {
80  cleanup();
81  }
82  inline Wrapper &operator=(const Wrapper &other) {
83  if (this != &other) {
84  // if we had managed a reply, free it
85  cleanup();
86  // copy members
87  m_retrieved = other.m_retrieved;
88  m_cookie = other.m_cookie;
89  m_window = other.m_window;
90  m_reply = other.m_reply;
91  // take over the responsibility for the reply pointer
92  takeFromOther(const_cast<Wrapper&>(other));
93  }
94  return *this;
95  }
96 
97  inline const Reply *operator->() {
98  getReply();
99  return m_reply;
100  }
101  inline bool isNull() {
102  getReply();
103  return m_reply == NULL;
104  }
105  inline operator bool() {
106  return !isNull();
107  }
108  inline const Reply *data() {
109  getReply();
110  return m_reply;
111  }
112  inline WindowId window() const {
113  return m_window;
114  }
115  inline bool isRetrieved() const {
116  return m_retrieved;
117  }
125  inline Reply *take() {
126  getReply();
127  Reply *ret = m_reply;
128  m_reply = NULL;
129  m_window = XCB_WINDOW_NONE;
130  return ret;
131  }
132 
133 protected:
134  void getReply() {
135  if (m_retrieved || !m_cookie.sequence) {
136  return;
137  }
138  m_reply = replyFunc(connection(), m_cookie, NULL);
139  m_retrieved = true;
140  }
141 
142 private:
143  inline void cleanup() {
144  if (!m_retrieved && m_cookie.sequence) {
145  xcb_discard_reply(connection(), m_cookie.sequence);
146  } else if (m_reply) {
147  free(m_reply);
148  }
149  }
150  inline void takeFromOther(Wrapper &other) {
151  if (m_retrieved) {
152  m_reply = other.take();
153  } else {
154  //ensure that other object doesn't try to get the reply or discards it in the dtor
155  other.m_retrieved = true;
156  other.m_window = XCB_WINDOW_NONE;
157  }
158  }
159  bool m_retrieved;
160  Cookie m_cookie;
161  WindowId m_window;
162  Reply *m_reply;
163 };
164 
165 class Atom
166 {
167 public:
168  explicit Atom(const QByteArray &name, bool onlyIfExists = false)
169  : m_retrieved(false)
170  , m_cookie(xcb_intern_atom_unchecked(connection(), onlyIfExists, name.length(), name.constData()))
171  , m_atom(XCB_ATOM_NONE)
172  , m_name(name)
173  {
174  }
175  Atom() = delete;
176  Atom(const Atom &) = delete;
177 
178  ~Atom() {
179  if (!m_retrieved && m_cookie.sequence) {
180  xcb_discard_reply(connection(), m_cookie.sequence);
181  }
182  }
183 
184  operator xcb_atom_t() const {
185  (const_cast<Atom*>(this))->getReply();
186  return m_atom;
187  }
188 
189  inline const QByteArray &name() const {
190  return m_name;
191  }
192 
193 private:
194  void getReply() {
195  if (m_retrieved || !m_cookie.sequence) {
196  return;
197  }
198  ScopedCPointer<xcb_intern_atom_reply_t> reply(xcb_intern_atom_reply(connection(), m_cookie, nullptr));
199  if (!reply.isNull()) {
200  m_atom = reply->atom;
201  }
202  m_retrieved = true;
203  }
204  bool m_retrieved;
205  xcb_intern_atom_cookie_t m_cookie;
206  xcb_atom_t m_atom;
207  QByteArray m_name;
208 };
209 
210 typedef Wrapper<xcb_get_window_attributes_reply_t, xcb_get_window_attributes_cookie_t, &xcb_get_window_attributes_reply, &xcb_get_window_attributes_unchecked> WindowAttributes;
211 typedef Wrapper<xcb_composite_get_overlay_window_reply_t, xcb_composite_get_overlay_window_cookie_t, &xcb_composite_get_overlay_window_reply, &xcb_composite_get_overlay_window_unchecked> OverlayWindow;
212 
213 
214 class WindowGeometry : public Wrapper<xcb_get_geometry_reply_t, xcb_get_geometry_cookie_t, &xcb_get_geometry_reply, &xcb_get_geometry_unchecked>
215 {
216 public:
217  WindowGeometry() : Wrapper<xcb_get_geometry_reply_t, xcb_get_geometry_cookie_t, &xcb_get_geometry_reply, &xcb_get_geometry_unchecked>() {}
218  explicit WindowGeometry(xcb_window_t window) : Wrapper<xcb_get_geometry_reply_t, xcb_get_geometry_cookie_t, &xcb_get_geometry_reply, &xcb_get_geometry_unchecked>(window) {}
219 
220  inline QRect rect() {
221  const xcb_get_geometry_reply_t *geometry = data();
222  if (!geometry) {
223  return QRect();
224  }
225  return QRect(geometry->x, geometry->y, geometry->width, geometry->height);
226  }
227 };
228 
229 class Tree : public Wrapper<xcb_query_tree_reply_t, xcb_query_tree_cookie_t, &xcb_query_tree_reply, &xcb_query_tree_unchecked>
230 {
231 public:
232  explicit Tree(WindowId window) : Wrapper<xcb_query_tree_reply_t, xcb_query_tree_cookie_t, &xcb_query_tree_reply, &xcb_query_tree_unchecked>(window) {}
233 
234  inline WindowId *children() {
235  return xcb_query_tree_children(data());
236  }
237  inline xcb_window_t parent() {
238  if (isNull())
239  return XCB_WINDOW_NONE;
240  return (*this)->parent;
241  }
242 };
243 
244 inline xcb_get_input_focus_cookie_t get_input_focus(xcb_connection_t *c, xcb_window_t) {
245  return xcb_get_input_focus(c);
246 }
247 class CurrentInput : public Wrapper<xcb_get_input_focus_reply_t, xcb_get_input_focus_cookie_t, &xcb_get_input_focus_reply, &get_input_focus>
248 {
249 public:
250  CurrentInput() : Wrapper<xcb_get_input_focus_reply_t, xcb_get_input_focus_cookie_t, &xcb_get_input_focus_reply, &get_input_focus>(XCB_WINDOW_NONE) {}
251 
252  inline xcb_window_t window() {
253  if (isNull())
254  return XCB_WINDOW_NONE;
255  return (*this)->focus;
256  }
257 };
258 
259 inline xcb_get_property_cookie_t get_transient_for(xcb_connection_t *c, xcb_window_t window)
260 {
261  return xcb_get_property_unchecked(c, 0, window, XCB_ATOM_WM_TRANSIENT_FOR, XCB_ATOM_WINDOW, 0, 1);
262 }
263 
264 class TransientFor : public Wrapper<xcb_get_property_reply_t, xcb_get_property_cookie_t, &xcb_get_property_reply, &get_transient_for>
265 {
266 public:
267  explicit TransientFor(WindowId window) : Wrapper<xcb_get_property_reply_t, xcb_get_property_cookie_t, &xcb_get_property_reply, &get_transient_for>(window) {}
268 
274  inline bool getTransientFor(WindowId *prop) {
275  if (isNull()) {
276  return false;
277  }
278 
279  const xcb_get_property_reply_t *reply = data();
280  if (!reply || reply->type != XCB_ATOM_WINDOW || reply->format != 32 || reply->length == 0)
281  return false;
282 
283  *prop = *reinterpret_cast<WindowId *>(xcb_get_property_value(reply));
284  return true;
285  }
286 };
287 
288 namespace RandR
289 {
290 typedef Wrapper<xcb_randr_get_screen_info_reply_t, xcb_randr_get_screen_info_cookie_t, &xcb_randr_get_screen_info_reply, &xcb_randr_get_screen_info_unchecked> ScreenInfo;
291 
292 class ScreenResources : public Wrapper<xcb_randr_get_screen_resources_reply_t, xcb_randr_get_screen_resources_cookie_t, &xcb_randr_get_screen_resources_reply, &xcb_randr_get_screen_resources_unchecked>
293 {
294 public:
295  explicit ScreenResources(WindowId window) : Wrapper<xcb_randr_get_screen_resources_reply_t, xcb_randr_get_screen_resources_cookie_t, &xcb_randr_get_screen_resources_reply, &xcb_randr_get_screen_resources_unchecked>(window) {}
296 
297  inline xcb_randr_crtc_t *crtcs() {
298  if (isNull()) {
299  return nullptr;
300  }
301  return xcb_randr_get_screen_resources_crtcs(data());
302  }
303 };
304 
305 class CrtcGamma : public Wrapper<xcb_randr_get_crtc_gamma_reply_t, xcb_randr_get_crtc_gamma_cookie_t, &xcb_randr_get_crtc_gamma_reply, &xcb_randr_get_crtc_gamma_unchecked>
306 {
307 public:
308  explicit CrtcGamma(xcb_randr_crtc_t c) : Wrapper<xcb_randr_get_crtc_gamma_reply_t, xcb_randr_get_crtc_gamma_cookie_t, &xcb_randr_get_crtc_gamma_reply, &xcb_randr_get_crtc_gamma_unchecked>(c) {}
309 
310  inline uint16_t *red() {
311  return xcb_randr_get_crtc_gamma_red(data());
312  }
313  inline uint16_t *green() {
314  return xcb_randr_get_crtc_gamma_green(data());
315  }
316  inline uint16_t *blue() {
317  return xcb_randr_get_crtc_gamma_blue(data());
318  }
319 };
320 
321 }
322 
323 class ExtensionData
324 {
325 public:
326  ExtensionData();
327  int version;
328  int eventBase;
329  int errorBase;
330  int majorOpcode;
331  bool present;
332  QByteArray name;
333 };
334 
335 class Extensions
336 {
337 public:
338  bool isShapeAvailable() const {
339  return m_shape.version > 0;
340  }
341  bool isShapeInputAvailable() const;
342  int shapeNotifyEvent() const;
343  bool hasShape(xcb_window_t w) const;
344  bool isRandrAvailable() const {
345  return m_randr.present;
346  }
347  int randrNotifyEvent() const;
348  bool isDamageAvailable() const {
349  return m_damage.present;
350  }
351  int damageNotifyEvent() const;
352  bool isCompositeAvailable() const {
353  return m_composite.version > 0;
354  }
355  bool isCompositeOverlayAvailable() const;
356  bool isRenderAvailable() const {
357  return m_render.version > 0;
358  }
359  bool isFixesAvailable() const {
360  return m_fixes.version > 0;
361  }
362  int fixesCursorNotifyEvent() const;
363  bool isFixesRegionAvailable() const;
364  bool isSyncAvailable() const {
365  return m_sync.present;
366  }
367  int syncAlarmNotifyEvent() const;
368  QVector<ExtensionData> extensions() const;
369 
370  static Extensions *self();
371  static void destroy();
372 private:
373  Extensions();
374  ~Extensions();
375  void init();
376  template <typename reply, typename T, typename F>
377  void initVersion(T cookie, F f, ExtensionData *dataToFill);
378  void extensionQueryReply(const xcb_query_extension_reply_t *extension, ExtensionData *dataToFill);
379 
380  ExtensionData m_shape;
381  ExtensionData m_randr;
382  ExtensionData m_damage;
383  ExtensionData m_composite;
384  ExtensionData m_render;
385  ExtensionData m_fixes;
386  ExtensionData m_sync;
387 
388  static Extensions *s_self;
389 };
390 
400 class Window
401 {
402 public:
415  Window(xcb_window_t window = XCB_WINDOW_NONE, bool destroy = true);
424  Window(const QRect &geometry, uint32_t mask = 0, const uint32_t *values = NULL, xcb_window_t parent = rootWindow());
434  Window(const QRect &geometry, uint16_t windowClass, uint32_t mask = 0, const uint32_t *values = NULL, xcb_window_t parent = rootWindow());
435  Window(const Window &other) = delete;
436  ~Window();
437 
448  void create(const QRect &geometry, uint32_t mask = 0, const uint32_t *values = NULL, xcb_window_t parent = rootWindow());
460  void create(const QRect &geometry, uint16_t windowClass, uint32_t mask = 0, const uint32_t *values = NULL, xcb_window_t parent = rootWindow());
467  void reset(xcb_window_t window = XCB_WINDOW_NONE, bool destroy = true);
471  bool isValid() const;
476  void setGeometry(const QRect &geometry);
477  void setGeometry(uint32_t x, uint32_t y, uint32_t width, uint32_t height);
478  void move(const QPoint &pos);
479  void move(uint32_t x, uint32_t y);
480  void resize(const QSize &size);
481  void resize(uint32_t width, uint32_t height);
482  void raise();
483  void lower();
484  void map();
485  void unmap();
486  void reparent(xcb_window_t parent, int x = 0, int y = 0);
487  void changeProperty(xcb_atom_t property, xcb_atom_t type, uint8_t format, uint32_t lenght,
488  const void *data, uint8_t mode = XCB_PROP_MODE_REPLACE);
489  void deleteProperty(xcb_atom_t property);
490  void setBorderWidth(uint32_t width);
491  void grabButton(uint8_t pointerMode, uint8_t keyboardmode,
492  uint16_t modifiers = XCB_MOD_MASK_ANY,
493  uint8_t button = XCB_BUTTON_INDEX_ANY,
494  uint16_t eventMask = XCB_EVENT_MASK_BUTTON_PRESS,
495  xcb_window_t confineTo = XCB_WINDOW_NONE,
496  xcb_cursor_t cursor = XCB_CURSOR_NONE,
497  bool ownerEvents = false);
498  void ungrabButton(uint16_t modifiers = XCB_MOD_MASK_ANY, uint8_t button = XCB_BUTTON_INDEX_ANY);
502  void clear();
503  void setBackgroundPixmap(xcb_pixmap_t pixmap);
504  void defineCursor(xcb_cursor_t cursor);
505  void focus(uint8_t revertTo = XCB_INPUT_FOCUS_POINTER_ROOT, xcb_timestamp_t time = xTime());
506  void selectInput(uint32_t events);
507  void kill();
508  operator xcb_window_t() const;
509 private:
510  xcb_window_t doCreate(const QRect &geometry, uint16_t windowClass, uint32_t mask = 0, const uint32_t *values = NULL, xcb_window_t parent = rootWindow());
511  void destroy();
512  xcb_window_t m_window;
513  bool m_destroy;
514 };
515 
516 inline
517 Window::Window(xcb_window_t window, bool destroy)
518  : m_window(window)
519  , m_destroy(destroy)
520 {
521 }
522 
523 inline
524 Window::Window(const QRect &geometry, uint32_t mask, const uint32_t *values, xcb_window_t parent)
525  : m_window(doCreate(geometry, XCB_COPY_FROM_PARENT, mask, values, parent))
526  , m_destroy(true)
527 {
528 }
529 
530 inline
531 Window::Window(const QRect &geometry, uint16_t windowClass, uint32_t mask, const uint32_t *values, xcb_window_t parent)
532  : m_window(doCreate(geometry, windowClass, mask, values, parent))
533  , m_destroy(true)
534 {
535 }
536 
537 inline
538 Window::~Window()
539 {
540  destroy();
541 }
542 
543 inline
544 void Window::destroy()
545 {
546  if (!isValid() || !m_destroy) {
547  return;
548  }
549  xcb_destroy_window(connection(), m_window);
550  m_window = XCB_WINDOW_NONE;
551 }
552 
553 inline
554 bool Window::isValid() const
555 {
556  return m_window != XCB_WINDOW_NONE;
557 }
558 
559 inline
560 Window::operator xcb_window_t() const
561 {
562  return m_window;
563 }
564 
565 inline
566 void Window::create(const QRect &geometry, uint16_t windowClass, uint32_t mask, const uint32_t *values, xcb_window_t parent)
567 {
568  destroy();
569  m_window = doCreate(geometry, windowClass, mask, values, parent);
570 }
571 
572 inline
573 void Window::create(const QRect &geometry, uint32_t mask, const uint32_t *values, xcb_window_t parent)
574 {
575  create(geometry, XCB_COPY_FROM_PARENT, mask, values, parent);
576 }
577 
578 inline
579 xcb_window_t Window::doCreate(const QRect &geometry, uint16_t windowClass, uint32_t mask, const uint32_t *values, xcb_window_t parent)
580 {
581  xcb_window_t w = xcb_generate_id(connection());
582  xcb_create_window(connection(), XCB_COPY_FROM_PARENT, w, parent,
583  geometry.x(), geometry.y(), geometry.width(), geometry.height(),
584  0, windowClass, XCB_COPY_FROM_PARENT, mask, values);
585  return w;
586 }
587 
588 inline
589 void Window::reset(xcb_window_t window, bool shouldDestroy)
590 {
591  destroy();
592  m_window = window;
593  m_destroy = shouldDestroy;
594 }
595 
596 inline
597 void Window::setGeometry(const QRect &geometry)
598 {
599  setGeometry(geometry.x(), geometry.y(), geometry.width(), geometry.height());
600 }
601 
602 inline
603 void Window::setGeometry(uint32_t x, uint32_t y, uint32_t width, uint32_t height)
604 {
605  if (!isValid()) {
606  return;
607  }
608  const uint16_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
609  const uint32_t values[] = { x, y, width, height };
610  xcb_configure_window(connection(), m_window, mask, values);
611 }
612 
613 inline
614 void Window::move(const QPoint &pos)
615 {
616  move(pos.x(), pos.y());
617 }
618 
619 inline
620 void Window::move(uint32_t x, uint32_t y)
621 {
622  if (!isValid()) {
623  return;
624  }
625  moveWindow(m_window, x, y);
626 }
627 
628 inline
629 void Window::resize(const QSize &size)
630 {
631  resize(size.width(), size.height());
632 }
633 
634 inline
635 void Window::resize(uint32_t width, uint32_t height)
636 {
637  if (!isValid()) {
638  return;
639  }
640  const uint16_t mask = XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
641  const uint32_t values[] = { width, height };
642  xcb_configure_window(connection(), m_window, mask, values);
643 }
644 
645 inline
646 void Window::raise()
647 {
648  const uint32_t values[] = { XCB_STACK_MODE_ABOVE };
649  xcb_configure_window(connection(), m_window, XCB_CONFIG_WINDOW_STACK_MODE, values);
650 }
651 
652 inline
653 void Window::lower()
654 {
655  lowerWindow(m_window);
656 }
657 
658 inline
659 void Window::map()
660 {
661  if (!isValid()) {
662  return;
663  }
664  xcb_map_window(connection(), m_window);
665 }
666 
667 inline
668 void Window::unmap()
669 {
670  if (!isValid()) {
671  return;
672  }
673  xcb_unmap_window(connection(), m_window);
674 }
675 
676 inline
677 void Window::reparent(xcb_window_t parent, int x, int y)
678 {
679  if (!isValid()) {
680  return;
681  }
682  xcb_reparent_window(connection(), m_window, parent, x, y);
683 }
684 
685 inline
686 void Window::changeProperty(xcb_atom_t property, xcb_atom_t type, uint8_t format, uint32_t lenght, const void *data, uint8_t mode)
687 {
688  if (!isValid()) {
689  return;
690  }
691  xcb_change_property(connection(), mode, m_window, property, type, format, lenght, data);
692 }
693 
694 inline
695 void Window::deleteProperty(xcb_atom_t property)
696 {
697  if (!isValid()) {
698  return;
699  }
700  xcb_delete_property(connection(), m_window, property);
701 }
702 
703 inline
704 void Window::setBorderWidth(uint32_t width)
705 {
706  if (!isValid()) {
707  return;
708  }
709  xcb_configure_window(connection(), m_window, XCB_CONFIG_WINDOW_BORDER_WIDTH, &width);
710 }
711 
712 inline
713 void Window::grabButton(uint8_t pointerMode, uint8_t keyboardmode, uint16_t modifiers,
714  uint8_t button, uint16_t eventMask, xcb_window_t confineTo,
715  xcb_cursor_t cursor, bool ownerEvents)
716 {
717  if (!isValid()) {
718  return;
719  }
720  xcb_grab_button(connection(), ownerEvents, m_window, eventMask,
721  pointerMode, keyboardmode, confineTo, cursor, button, modifiers);
722 }
723 
724 inline
725 void Window::ungrabButton(uint16_t modifiers, uint8_t button)
726 {
727  if (!isValid()) {
728  return;
729  }
730  xcb_ungrab_button(connection(), button, m_window, modifiers);
731 }
732 
733 inline
734 void Window::clear()
735 {
736  if (!isValid()) {
737  return;
738  }
739  xcb_clear_area(connection(), false, m_window, 0, 0, 0, 0);
740 }
741 
742 inline
743 void Window::setBackgroundPixmap(xcb_pixmap_t pixmap)
744 {
745  if (!isValid()) {
746  return;
747  }
748  const uint32_t values[] = {pixmap};
749  xcb_change_window_attributes(connection(), m_window, XCB_CW_BACK_PIXMAP, values);
750 }
751 
752 inline
753 void Window::defineCursor(xcb_cursor_t cursor)
754 {
755  Xcb::defineCursor(m_window, cursor);
756 }
757 
758 inline
759 void Window::focus(uint8_t revertTo, xcb_timestamp_t time)
760 {
761  setInputFocus(m_window, revertTo, time);
762 }
763 
764 inline
765 void Window::selectInput(uint32_t events)
766 {
767  Xcb::selectInput(m_window, events);
768 }
769 
770 inline
771 void Window::kill()
772 {
773  xcb_kill_client(connection(), m_window);
774 }
775 
776 // helper functions
777 static inline void moveResizeWindow(WindowId window, const QRect &geometry)
778 {
779  const uint16_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
780  const uint32_t values[] = {
781  static_cast<uint32_t>(geometry.x()),
782  static_cast<uint32_t>(geometry.y()),
783  static_cast<uint32_t>(geometry.width()),
784  static_cast<uint32_t>(geometry.height())
785  };
786  xcb_configure_window(connection(), window, mask, values);
787 }
788 
789 static inline void moveWindow(xcb_window_t window, const QPoint& pos)
790 {
791  moveWindow(window, pos.x(), pos.y());
792 }
793 
794 static inline void moveWindow(xcb_window_t window, uint32_t x, uint32_t y)
795 {
796  const uint16_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y;
797  const uint32_t values[] = { x, y };
798  xcb_configure_window(connection(), window, mask, values);
799 }
800 
801 static inline void lowerWindow(xcb_window_t window)
802 {
803  const uint32_t values[] = { XCB_STACK_MODE_BELOW };
804  xcb_configure_window(connection(), window, XCB_CONFIG_WINDOW_STACK_MODE, values);
805 }
806 
807 static inline WindowId createInputWindow(const QRect &geometry, uint32_t mask, const uint32_t *values)
808 {
809  WindowId window = xcb_generate_id(connection());
810  xcb_create_window(connection(), 0, window, rootWindow(),
811  geometry.x(), geometry.y(), geometry.width(), geometry.height(),
812  0, XCB_WINDOW_CLASS_INPUT_ONLY,
813  XCB_COPY_FROM_PARENT, mask, values);
814  return window;
815 }
816 
817 static inline void restackWindows(const QVector<xcb_window_t> &windows)
818 {
819  if (windows.count() < 2) {
820  // only one window, nothing to do
821  return;
822  }
823  for (int i=1; i<windows.count(); ++i) {
824  const uint16_t mask = XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE;
825  const uint32_t stackingValues[] = {
826  windows.at(i-1),
827  XCB_STACK_MODE_BELOW
828  };
829  xcb_configure_window(connection(), windows.at(i), mask, stackingValues);
830  }
831 }
832 
833 static inline void restackWindowsWithRaise(const QVector<xcb_window_t> &windows)
834 {
835  if (windows.isEmpty()) {
836  return;
837  }
838  const uint32_t values[] = { XCB_STACK_MODE_ABOVE };
839  xcb_configure_window(connection(), windows.first(), XCB_CONFIG_WINDOW_STACK_MODE, values);
840  restackWindows(windows);
841 }
842 
843 static inline int defaultDepth()
844 {
845  static int depth = 0;
846  if (depth != 0) {
847  return depth;
848  }
849  int screen = QX11Info::appScreen();
850  for (xcb_screen_iterator_t it = xcb_setup_roots_iterator(xcb_get_setup(connection()));
851  it.rem;
852  --screen, xcb_screen_next(&it)) {
853  if (screen == 0) {
854  depth = it.data->root_depth;
855  break;
856  }
857  }
858  return depth;
859 }
860 
861 static inline xcb_rectangle_t fromQt(const QRect &rect)
862 {
863  xcb_rectangle_t rectangle;
864  rectangle.x = rect.x();
865  rectangle.y = rect.y();
866  rectangle.width = rect.width();
867  rectangle.height = rect.height();
868  return rectangle;
869 }
870 
871 static inline QVector<xcb_rectangle_t> regionToRects(const QRegion &region)
872 {
873  const QVector<QRect> regionRects = region.rects();
874  QVector<xcb_rectangle_t> rects(regionRects.count());
875  for (int i=0; i<regionRects.count(); ++i) {
876  rects[i] = Xcb::fromQt(regionRects.at(i));
877  }
878  return rects;
879 }
880 
881 static inline void defineCursor(xcb_window_t window, xcb_cursor_t cursor)
882 {
883  xcb_change_window_attributes(connection(), window, XCB_CW_CURSOR, &cursor);
884 }
885 
886 static inline void setInputFocus(xcb_window_t window, uint8_t revertTo, xcb_timestamp_t time)
887 {
888  xcb_set_input_focus(connection(), revertTo, window, time);
889 }
890 
891 static inline void setTransientFor(xcb_window_t window, xcb_window_t transient_for_window)
892 {
893  xcb_change_property(connection(), XCB_PROP_MODE_REPLACE, window, XCB_ATOM_WM_TRANSIENT_FOR,
894  XCB_ATOM_WINDOW, 32, 1, &transient_for_window);
895 }
896 
897 static inline void sync()
898 {
899  auto *c = connection();
900  const auto cookie = xcb_get_input_focus(c);
901  xcb_generic_error_t *error = nullptr;
902  ScopedCPointer<xcb_get_input_focus_reply_t> sync(xcb_get_input_focus_reply(c, cookie, &error));
903  if (error) {
904  free(error);
905  }
906 }
907 
908 void selectInput(xcb_window_t window, uint32_t events)
909 {
910  xcb_change_window_attributes(connection(), window, XCB_CW_EVENT_MASK, &events);
911 }
912 
917 class Shm
918 {
919 public:
920  Shm();
921  ~Shm();
922  int shmId() const;
923  void *buffer() const;
924  xcb_shm_seg_t segment() const;
925  bool isValid() const;
926  uint8_t pixmapFormat() const;
927 private:
928  bool init();
929  int m_shmId;
930  void *m_buffer;
931  xcb_shm_seg_t m_segment;
932  bool m_valid;
933  uint8_t m_pixmapFormat;
934 };
935 
936 inline
937 void *Shm::buffer() const
938 {
939  return m_buffer;
940 }
941 
942 inline
943 bool Shm::isValid() const
944 {
945  return m_valid;
946 }
947 
948 inline
949 xcb_shm_seg_t Shm::segment() const
950 {
951  return m_segment;
952 }
953 
954 inline
955 int Shm::shmId() const
956 {
957  return m_shmId;
958 }
959 
960 inline
961 uint8_t Shm::pixmapFormat() const
962 {
963  return m_pixmapFormat;
964 }
965 
966 } // namespace X11
967 
968 } // namespace KWin
969 #endif // KWIN_X11_UTILS_H
KWin::Xcb::Extensions::isRenderAvailable
bool isRenderAvailable() const
Definition: xcbutils.h:356
KWin::Xcb::Window::map
void map()
Definition: xcbutils.h:659
KWin::Xcb::Shm::~Shm
~Shm()
Definition: xcbutils.cpp:273
KWin::Xcb::Wrapper::operator->
const Reply * operator->()
Definition: xcbutils.h:97
KWin::Xcb::Wrapper::data
const Reply * data()
Definition: xcbutils.h:108
KWin::Xcb::Extensions::isSyncAvailable
bool isSyncAvailable() const
Definition: xcbutils.h:364
KWin::Xcb::Atom
Definition: xcbutils.h:165
KWin::Xcb::Tree::parent
xcb_window_t parent()
Definition: xcbutils.h:237
KWin::Xcb::Wrapper::getReply
void getReply()
Definition: xcbutils.h:134
KWin::Xcb::Extensions::isDamageAvailable
bool isDamageAvailable() const
Definition: xcbutils.h:348
KWin::Xcb::Window::deleteProperty
void deleteProperty(xcb_atom_t property)
Definition: xcbutils.h:695
KWin::Xcb::ExtensionData::present
bool present
Definition: xcbutils.h:331
QSize::width
int width() const
KWin::Xcb::RandR::CrtcGamma::green
uint16_t * green()
Definition: xcbutils.h:313
KWin::Xcb::Extensions::isFixesAvailable
bool isFixesAvailable() const
Definition: xcbutils.h:359
KWin::Xcb::Window::isValid
bool isValid() const
Definition: xcbutils.h:554
KWin::Xcb::RandR::ScreenInfo
Wrapper< xcb_randr_get_screen_info_reply_t, xcb_randr_get_screen_info_cookie_t,&xcb_randr_get_screen_info_reply,&xcb_randr_get_screen_info_unchecked > ScreenInfo
Definition: xcbutils.h:290
xcb_query_tree_cookie_t
KWin::Xcb::Window::focus
void focus(uint8_t revertTo=XCB_INPUT_FOCUS_POINTER_ROOT, xcb_timestamp_t time=xTime())
Definition: xcbutils.h:759
KWin::Xcb::Window::changeProperty
void changeProperty(xcb_atom_t property, xcb_atom_t type, uint8_t format, uint32_t lenght, const void *data, uint8_t mode=XCB_PROP_MODE_REPLACE)
Definition: xcbutils.h:686
QByteArray
KWin::Xcb::Atom::~Atom
~Atom()
Definition: xcbutils.h:178
KWin::Xcb::ExtensionData
Definition: xcbutils.h:323
KWin::Xcb::RandR::CrtcGamma::blue
uint16_t * blue()
Definition: xcbutils.h:316
KWin::Xcb::Extensions::isRandrAvailable
bool isRandrAvailable() const
Definition: xcbutils.h:344
KWin::Xcb::Wrapper::Wrapper
Wrapper()
Definition: xcbutils.h:57
QRect::height
int height() const
KWin::Xcb::Atom::Atom
Atom(const QByteArray &name, bool onlyIfExists=false)
Definition: xcbutils.h:168
KWin::Xcb::Wrapper::operator=
Wrapper & operator=(const Wrapper &other)
Definition: xcbutils.h:82
QRect::x
int x() const
QRect::y
int y() const
KWin::Xcb::Window::reparent
void reparent(xcb_window_t parent, int x=0, int y=0)
Definition: xcbutils.h:677
QPoint
QVector::first
T & first()
KWin::Xcb::get_transient_for
xcb_get_property_cookie_t get_transient_for(xcb_connection_t *c, xcb_window_t window)
Definition: xcbutils.h:259
KWin::Xcb::Window::ungrabButton
void ungrabButton(uint16_t modifiers=XCB_MOD_MASK_ANY, uint8_t button=XCB_BUTTON_INDEX_ANY)
Definition: xcbutils.h:725
KWin::Xcb::Extensions::isCompositeAvailable
bool isCompositeAvailable() const
Definition: xcbutils.h:352
KWin::Xcb::Shm::segment
xcb_shm_seg_t segment() const
Definition: xcbutils.h:949
QPoint::x
int x() const
QPoint::y
int y() const
KWin::Xcb::regionToRects
static QVector< xcb_rectangle_t > regionToRects(const QRegion &region)
Definition: xcbutils.h:871
KWin::Xcb::RandR::ScreenResources
Definition: xcbutils.h:292
KWin::Xcb::Tree
Definition: xcbutils.h:229
KWin::Xcb::createInputWindow
static WindowId createInputWindow(const QRect &geometry, uint32_t mask, const uint32_t *values)
Definition: xcbutils.h:807
KWin::Xcb::Shm::shmId
int shmId() const
Definition: xcbutils.h:955
KWin::Xcb::setTransientFor
static void setTransientFor(xcb_window_t window, xcb_window_t transient_for_window)
Definition: xcbutils.h:891
utils.h
QRect
KWin::Xcb::CurrentInput::CurrentInput
CurrentInput()
Definition: xcbutils.h:250
KWin::Xcb::Window::defineCursor
void defineCursor(xcb_cursor_t cursor)
Definition: xcbutils.h:753
KWin::Xcb::Wrapper::Wrapper
Wrapper(WindowId window)
Definition: xcbutils.h:64
KWin::Xcb::RandR::ScreenResources::ScreenResources
ScreenResources(WindowId window)
Definition: xcbutils.h:295
KWin::Xcb::get_input_focus
xcb_get_input_focus_cookie_t get_input_focus(xcb_connection_t *c, xcb_window_t)
Definition: xcbutils.h:244
xcb_get_property_cookie_t
KWin::Xcb::moveResizeWindow
static void moveResizeWindow(WindowId window, const QRect &geometry)
Definition: xcbutils.h:777
QX11Info::appScreen
int appScreen()
QScopedPointer
KWin::Xcb::Wrapper::~Wrapper
virtual ~Wrapper()
Definition: xcbutils.h:79
KWin::Xcb::ExtensionData::name
QByteArray name
Definition: xcbutils.h:332
KWin::Xcb::RandR::ScreenResources::crtcs
xcb_randr_crtc_t * crtcs()
Definition: xcbutils.h:297
KWin::Xcb::TransientFor::getTransientFor
bool getTransientFor(WindowId *prop)
Fill given window pointer with the WM_TRANSIENT_FOR property of a window.
Definition: xcbutils.h:274
KWin::Xcb::Shm::isValid
bool isValid() const
Definition: xcbutils.h:943
KWin::Xcb::Wrapper::take
Reply * take()
Returns the value of the reply pointer referenced by this object.
Definition: xcbutils.h:125
KWin::Xcb::Extensions::isShapeAvailable
bool isShapeAvailable() const
Definition: xcbutils.h:338
KWin::Xcb::TransientFor
Definition: xcbutils.h:264
KWin::Xcb::Window::unmap
void unmap()
Definition: xcbutils.h:668
KWin::Xcb::Wrapper::Wrapper
Wrapper(const Wrapper &other)
Definition: xcbutils.h:71
KWin::Xcb::WindowId
xcb_window_t WindowId
Definition: xcbutils.h:40
KWin::Xcb::Window::setGeometry
void setGeometry(const QRect &geometry)
Configures the window with a new geometry.
Definition: xcbutils.h:597
KWin::Xcb::Window::setBorderWidth
void setBorderWidth(uint32_t width)
Definition: xcbutils.h:704
KWin::Xcb::Window
This class is an RAII wrapper for an xcb_window_t.
Definition: xcbutils.h:400
KWin::Xcb::Shm
Small helper class to encapsulate SHM related functionality.
Definition: xcbutils.h:917
KWin::Xcb::ExtensionData::errorBase
int errorBase
Definition: xcbutils.h:329
xcb_randr_get_crtc_gamma_cookie_t
KWin::Xcb::setInputFocus
static void setInputFocus(xcb_window_t window, uint8_t revertTo=XCB_INPUT_FOCUS_POINTER_ROOT, xcb_timestamp_t time=xTime())
Definition: xcbutils.h:886
KWin::Xcb::lowerWindow
static void lowerWindow(xcb_window_t window)
Definition: xcbutils.h:801
KWin::Xcb::Window::resize
void resize(const QSize &size)
Definition: xcbutils.h:629
xcb_get_input_focus_cookie_t
KWin::Xcb::Shm::pixmapFormat
uint8_t pixmapFormat() const
Definition: xcbutils.h:961
KWin::Xcb::restackWindowsWithRaise
static void restackWindowsWithRaise(const QVector< xcb_window_t > &windows)
Definition: xcbutils.h:833
QSize
KWin::Xcb::sync
static void sync()
Definition: xcbutils.h:897
KWin::Xcb::Window::grabButton
void grabButton(uint8_t pointerMode, uint8_t keyboardmode, uint16_t modifiers=XCB_MOD_MASK_ANY, uint8_t button=XCB_BUTTON_INDEX_ANY, uint16_t eventMask=XCB_EVENT_MASK_BUTTON_PRESS, xcb_window_t confineTo=XCB_WINDOW_NONE, xcb_cursor_t cursor=XCB_CURSOR_NONE, bool ownerEvents=false)
Definition: xcbutils.h:713
KWin::Xcb::Wrapper::isRetrieved
bool isRetrieved() const
Definition: xcbutils.h:115
KWin::Xcb::OverlayWindow
Wrapper< xcb_composite_get_overlay_window_reply_t, xcb_composite_get_overlay_window_cookie_t,&xcb_composite_get_overlay_window_reply,&xcb_composite_get_overlay_window_unchecked > OverlayWindow
Definition: xcbutils.h:211
xcb_randr_get_screen_resources_cookie_t
KWin::Xcb::Wrapper
Definition: xcbutils.h:54
KWin::Xcb::defaultDepth
static int defaultDepth()
Definition: xcbutils.h:843
KWin::Xcb::Window::clear
void clear()
Clears the window area.
Definition: xcbutils.h:734
KWin::Xcb::RandR::CrtcGamma::red
uint16_t * red()
Definition: xcbutils.h:310
QVector::at
const T & at(int i) const
KWin::Xcb::restackWindows
static void restackWindows(const QVector< xcb_window_t > &windows)
Definition: xcbutils.h:817
KWin::Xcb::CurrentInput::window
xcb_window_t window()
Definition: xcbutils.h:252
KWin::Xcb::ExtensionData::eventBase
int eventBase
Definition: xcbutils.h:328
KWin::Xcb::Window::selectInput
void selectInput(uint32_t events)
Definition: xcbutils.h:765
KWin::Xcb::WindowGeometry
Definition: xcbutils.h:214
QRect::width
int width() const
QVector
KWin::Xcb::fromQt
static xcb_rectangle_t fromQt(const QRect &rect)
Definition: xcbutils.h:861
KWin::Xcb::Shm::Shm
Shm()
Definition: xcbutils.cpp:263
KWin::Xcb::Window::raise
void raise()
Definition: xcbutils.h:646
KWin::Xcb::selectInput
static void selectInput(xcb_window_t window, uint32_t events)
Definition: xcbutils.h:908
KWin::Xcb::ExtensionData::majorOpcode
int majorOpcode
Definition: xcbutils.h:330
QVector::isEmpty
bool isEmpty() const
KWin::Xcb::ExtensionData::version
int version
Definition: xcbutils.h:327
KWin::Xcb::Window::kill
void kill()
Definition: xcbutils.h:771
KWin::Xcb::Window::create
void create(const QRect &geometry, uint32_t mask=0, const uint32_t *values=NULL, xcb_window_t parent=rootWindow())
Creates a new window for which the responsibility is taken over.
Definition: xcbutils.h:573
QRegion::rects
QVector< QRect > rects() const
QSize::height
int height() const
QVector::count
int count(const T &value) const
KWin::Xcb::Window::~Window
~Window()
Definition: xcbutils.h:538
KWin::Xcb::RandR::CrtcGamma
Definition: xcbutils.h:305
xcb_window_t
KWin::Xcb::Window::reset
void reset(xcb_window_t window=XCB_WINDOW_NONE, bool destroy=true)
Frees the existing window and starts to manage the new window.
Definition: xcbutils.h:589
KWin::Xcb::moveWindow
static void moveWindow(xcb_window_t window, const QPoint &pos)
Definition: xcbutils.h:789
bool
KWin::Xcb::Shm::buffer
void * buffer() const
Definition: xcbutils.h:937
KWin::Xcb::Wrapper::window
WindowId window() const
Definition: xcbutils.h:112
KWin::Xcb::Tree::Tree
Tree(WindowId window)
Definition: xcbutils.h:232
KWin::Xcb::RandR::CrtcGamma::CrtcGamma
CrtcGamma(xcb_randr_crtc_t c)
Definition: xcbutils.h:308
KWin::Xcb::WindowAttributes
Wrapper< xcb_get_window_attributes_reply_t, xcb_get_window_attributes_cookie_t,&xcb_get_window_attributes_reply,&xcb_get_window_attributes_unchecked > WindowAttributes
Definition: xcbutils.h:210
KWin::Xcb::Extensions
Definition: xcbutils.h:335
KWin::Xcb::Window::lower
void lower()
Definition: xcbutils.h:653
KWin::Xcb::TransientFor::TransientFor
TransientFor(WindowId window)
Definition: xcbutils.h:267
KWin::Xcb::defineCursor
static void defineCursor(xcb_window_t window, xcb_cursor_t cursor)
Definition: xcbutils.h:881
KWin::Xcb::WindowGeometry::rect
QRect rect()
Definition: xcbutils.h:220
KWin::Xcb::WindowGeometry::WindowGeometry
WindowGeometry()
Definition: xcbutils.h:217
KWin::Xcb::Atom::name
const QByteArray & name() const
Definition: xcbutils.h:189
KWin::Xcb::Window::move
void move(const QPoint &pos)
Definition: xcbutils.h:614
QRegion
KWin::Xcb::Wrapper::isNull
bool isNull()
Definition: xcbutils.h:101
KWin::Xcb::WindowGeometry::WindowGeometry
WindowGeometry(xcb_window_t window)
Definition: xcbutils.h:218
KWin::Xcb::CurrentInput
Definition: xcbutils.h:247
KWin::Xcb::Window::setBackgroundPixmap
void setBackgroundPixmap(xcb_pixmap_t pixmap)
Definition: xcbutils.h:743
KWin::Xcb::Window::Window
Window(xcb_window_t window=XCB_WINDOW_NONE, bool destroy=true)
Takes over responsibility of window.
Definition: xcbutils.h:517
KWin::Xcb::Tree::children
WindowId * children()
Definition: xcbutils.h:234
xcb_get_geometry_cookie_t
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Wed Dec 11 2019 06:44:07 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KWin

Skip menu "KWin"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kde-workspace API Reference

Skip menu "kde-workspace API Reference"
  • KWin
  •   KWin Decoration Library
  •   KWin Effects Library
  • Plasma
  • Plasma
  •   Applets
  •   Engines
  •   libkworkspace
  •   libtaskmanager
  • System Settings
  •   SystemSettingsView

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal