x11_display.hpp 5.91 KB
Newer Older
1 2 3
/*****************************************************************************
 * x11_display.hpp
 *****************************************************************************
4
 * Copyright (C) 2003 the VideoLAN team
5
 * $Id$
6 7
 *
 * Authors: Cyril Deguet     <asmax@via.ecp.fr>
8
 *          Olivier Teulière <ipkiss@via.ecp.fr>
9 10 11 12 13 14 15 16 17 18 19
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
20 21 22
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 24 25 26 27 28
 *****************************************************************************/

#ifndef X11_DISPLAY_HPP
#define X11_DISPLAY_HPP

#include <X11/Xlib.h>
29
#include <X11/Xatom.h>
30 31 32 33 34 35 36 37
#include "../src/skin_common.hpp"

// Helper macros
#define XDISPLAY m_rDisplay.getDisplay()
#define XVISUAL m_rDisplay.getVisual()
#define XPIXELSIZE m_rDisplay.getPixelSize()
#define XGC m_rDisplay.getGC()

38
#define NET_WM_SUPPORTED          m_rDisplay.m_net_wm_supported
39 40
#define NET_WM_WINDOW_TYPE        m_rDisplay.m_net_wm_window_type
#define NET_WM_WINDOW_TYPE_NORMAL m_rDisplay.m_net_wm_window_type_normal
41 42 43 44 45 46 47
#define NET_WM_STATE              m_rDisplay.m_net_wm_state
#define NET_WM_STATE_FULLSCREEN   m_rDisplay.m_net_wm_state_fullscreen
#define NET_WM_STATE_ABOVE        m_rDisplay.m_net_wm_state_above

#define NET_WM_STAYS_ON_TOP       m_rDisplay.m_net_wm_stays_on_top
#define NET_WM_WINDOW_OPACITY     m_rDisplay.m_net_wm_window_opacity

48
#define NET_WM_PID                m_rDisplay.m_net_wm_pid
49 50 51 52

/// Class for encapsulation of a X11 Display
class X11Display: public SkinObject
{
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
public:
    X11Display( intf_thread_t *pIntf );
    virtual ~X11Display();

    /// Get the display
    Display *getDisplay() const { return m_pDisplay; }

    /// Get the visual
    Visual *getVisual() const { return m_pVisual; }

    /// Get the pixel size
    int getPixelSize() const { return m_pixelSize; }

    /// Get the graphics context
    GC getGC() const { return m_gc; }

    /// Get the colormap
    Colormap getColormap() const { return m_colormap; }

    /// Type of function to put RGBA values into a pixel
    typedef void (X11Display::*MakePixelFunc_t)( uint8_t *pPixel,
        uint8_t r, uint8_t g, uint8_t b, uint8_t a ) const;

    /// Get a pointer on the right blendPixel implementation
    MakePixelFunc_t getBlendPixel() const { return blendPixelImpl; }

    /// Get a pointer on the right putPixel implementation
    MakePixelFunc_t getPutPixel() const { return putPixelImpl; }

    /// Get the pixel value corresponding to the given colors
    unsigned long getPixelValue( uint8_t r, uint8_t g, uint8_t b ) const;

    /// Get the main window ID
    Window getMainWindow() const { return m_mainWindow; }

88 89
    /// EWMH spec
    Atom m_net_wm_supported;
90 91 92 93

    Atom m_net_wm_window_type;
    Atom m_net_wm_window_type_normal;

94 95 96 97 98 99 100
    Atom m_net_wm_state;
    Atom m_net_wm_state_above;
    Atom m_net_wm_state_fullscreen;

    Atom m_net_wm_stays_on_top;
    Atom m_net_wm_window_opacity;

101 102
    Atom m_net_wm_pid;

103 104
    /// test EWMH capabilities
    void testEWMH();
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122

private:
    /// Dummy parent window for the task bar
    Window m_mainWindow;
    /// Display parameters
    Display *m_pDisplay;
    Visual *m_pVisual;
    int m_pixelSize;
    GC m_gc;
    Colormap m_colormap;
    int m_redLeftShift, m_redRightShift;
    int m_greenLeftShift, m_greenRightShift;
    int m_blueLeftShift, m_blueRightShift;
    /// Pointer on the right implementation of blendPixel
    MakePixelFunc_t blendPixelImpl;
    /// Pointer on the right implementation of putPixel
    MakePixelFunc_t putPixelImpl;

123 124 125 126
    template<class type> type putPixel(type r, type g, type b) const;
    template<class type>
    type blendPixel(type v,type r, type g, type b,type a) const;

127
    /// Calculate shifts from a color mask
128
    static void getShifts( uint32_t mask, int &rLeftShift, int &rRightShift );
129 130 131 132 133 134 135

    /// 8 bpp version of blendPixel
    void blendPixel8( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
                      uint8_t a ) const;

    /// 16 bpp MSB first version of blendPixel
    void blendPixel16MSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
136 137
                          uint8_t a ) const;

138 139 140
    /// 16 bpp LSB first version of blendPixel
    void blendPixel16LSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
                          uint8_t a ) const;
141

142 143 144
    /// 24/32 bpp MSB first version of blendPixel
    void blendPixel32MSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
                          uint8_t a ) const;
145

146 147 148
    /// 24/32 bpp LSB first version of blendPixel
    void blendPixel32LSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
                          uint8_t a ) const;
149

150 151 152
    /// 8 bpp version of putPixel
    void putPixel8( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
                    uint8_t a ) const;
153

154 155
    /// 16 bpp MSB first version of putPixel
    void putPixel16MSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
156
                        uint8_t a ) const;
157

158 159 160
    /// 16 bpp LSB first version of putPixel
    void putPixel16LSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
                        uint8_t a ) const;
161

162 163 164
    /// 24/32 bpp MSB first version of putPixel
    void putPixel32MSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
                        uint8_t a ) const;
165

166 167 168
    /// 24/32 bpp LSB first version of putPixel
    void putPixel32LSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
                        uint8_t a ) const;
169

170 171 172
};

#endif