1 /************************************************************************* 2 * Copyright (C) 2014 by Hugo Pereira Da Costa <hugo.pereira@free.fr> * 3 * Copyright (C) 2014-2018 Martin Bříza <m@rtinbriza.cz> * 4 * Copyright (C) 2019-2021 Jan Grulich <jgrulich@redhat.com> * 5 * * 6 * This program is free software; you can redistribute it and/or modify * 7 * it under the terms of the GNU General Public License as published by * 8 * the Free Software Foundation; either version 2 of the License, or * 9 * (at your option) any later version. * 10 * * 11 * This program is distributed in the hope that it will be useful, * 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 14 * GNU General Public License for more details. * 15 * * 16 * You should have received a copy of the GNU General Public License * 17 * along with this program; if not, write to the * 18 * Free Software Foundation, Inc., * 19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * 20 *************************************************************************/ 21 22 #ifndef ADWAITA_HELPER_H 23 #define ADWAITA_HELPER_H 24 25 #include "adwaita.h" 26 #include "config-adwaita.h" 27 28 #include <QPainterPath> 29 #include <QStyle> 30 #include <QWidget> 31 32 #include <QWindow> 33 34 #if ADWAITA_HAVE_X11 35 #include <QX11Info> 36 #include <xcb/xcb.h> 37 #endif 38 39 namespace Adwaita 40 { 41 /* 42 * Adwaita style helper class. 43 * contains utility functions used at multiple places in both adwaita style and adwaita window decoration 44 */ 45 class Helper 46 { 47 public: 48 explicit Helper(); 49 50 virtual ~Helper() = default; 51 52 static bool isWindowActive(const QWidget *widget); 53 54 // true if style was compiled for and is running on X11 55 static bool isX11(); 56 57 // true if running on platform Wayland 58 static bool isWayland(); 59 60 // returns true if compositing is active 61 bool compositingActive() const; 62 63 // returns true if a given widget supports alpha channel 64 bool hasAlphaChannel(const QWidget *widget ) const; 65 66 // return dpi-aware pixmap of given size highDpiPixmap(const QSize & size)67 virtual QPixmap highDpiPixmap(const QSize &size) const 68 { 69 return highDpiPixmap(size.width(), size.height()); 70 } 71 72 // return dpi-aware pixmap of given size highDpiPixmap(int width)73 virtual QPixmap highDpiPixmap(int width) const 74 { 75 return highDpiPixmap(width, width); 76 } 77 78 // return dpi-aware pixmap of given size 79 virtual QPixmap highDpiPixmap(int width, int height) const; 80 81 // return device pixel ratio for a given pixmap 82 virtual qreal devicePixelRatio(const QPixmap &pixmap) const; 83 84 #if ADWAITA_HAVE_X11 85 // get xcb connection 86 static xcb_connection_t *connection(); 87 88 // create xcb atom 89 xcb_atom_t createAtom(const QString &name) const; 90 91 #endif 92 93 void setVariant(QWidget *widget, const QByteArray &variant); 94 95 protected: 96 // initialize 97 void init(void); 98 99 private: 100 #if ADWAITA_HAVE_X11 101 // atom used for compositing manager 102 xcb_atom_t _compositingManagerAtom; 103 #endif 104 }; 105 106 } 107 108 #endif 109