]> git.sesse.net Git - vlc/blob - modules/gui/skins2/x11/x11_display.hpp
skins2(X11): add icon to vlc
[vlc] / modules / gui / skins2 / x11 / x11_display.hpp
1 /*****************************************************************************
2  * x11_display.hpp
3  *****************************************************************************
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  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License along
21  * with this program; if not, write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifndef X11_DISPLAY_HPP
26 #define X11_DISPLAY_HPP
27
28 #include <X11/Xlib.h>
29 #include <X11/Xatom.h>
30 #include "../src/skin_common.hpp"
31
32 // Helper macros
33 #define XDISPLAY m_rDisplay.getDisplay()
34 #define XVISUAL m_rDisplay.getVisual()
35 #define XPIXELSIZE m_rDisplay.getPixelSize()
36 #define XGC m_rDisplay.getGC()
37
38 #define NET_WM_SUPPORTED          m_rDisplay.m_net_wm_supported
39 #define NET_WM_STATE              m_rDisplay.m_net_wm_state
40 #define NET_WM_STATE_FULLSCREEN   m_rDisplay.m_net_wm_state_fullscreen
41 #define NET_WM_STATE_ABOVE        m_rDisplay.m_net_wm_state_above
42
43 #define NET_WM_STAYS_ON_TOP       m_rDisplay.m_net_wm_stays_on_top
44 #define NET_WM_WINDOW_OPACITY     m_rDisplay.m_net_wm_window_opacity
45
46 #define NET_WM_PID                m_rDisplay.m_net_wm_pid
47
48 /// Class for encapsulation of a X11 Display
49 class X11Display: public SkinObject
50 {
51 public:
52     X11Display( intf_thread_t *pIntf );
53     virtual ~X11Display();
54
55     /// Get the display
56     Display *getDisplay() const { return m_pDisplay; }
57
58     /// Get the visual
59     Visual *getVisual() const { return m_pVisual; }
60
61     /// Get the pixel size
62     int getPixelSize() const { return m_pixelSize; }
63
64     /// Get the graphics context
65     GC getGC() const { return m_gc; }
66
67     /// Get the colormap
68     Colormap getColormap() const { return m_colormap; }
69
70     /// Type of function to put RGBA values into a pixel
71     typedef void (X11Display::*MakePixelFunc_t)( uint8_t *pPixel,
72         uint8_t r, uint8_t g, uint8_t b, uint8_t a ) const;
73
74     /// Get a pointer on the right blendPixel implementation
75     MakePixelFunc_t getBlendPixel() const { return blendPixelImpl; }
76
77     /// Get a pointer on the right putPixel implementation
78     MakePixelFunc_t getPutPixel() const { return putPixelImpl; }
79
80     /// Get the pixel value corresponding to the given colors
81     unsigned long getPixelValue( uint8_t r, uint8_t g, uint8_t b ) const;
82
83     /// Get the main window ID
84     Window getMainWindow() const { return m_mainWindow; }
85
86     //XXX
87     ///Window m_voutWindow;
88
89     /// EWMH spec
90     Atom m_net_wm_supported;
91     Atom m_net_wm_state;
92     Atom m_net_wm_state_above;
93     Atom m_net_wm_state_fullscreen;
94
95     Atom m_net_wm_stays_on_top;
96     Atom m_net_wm_window_opacity;
97
98     Atom m_net_wm_pid;
99
100     /// test EWMH capabilities
101     void testEWMH();
102
103 private:
104     /// Dummy parent window for the task bar
105     Window m_mainWindow;
106     /// Display parameters
107     Display *m_pDisplay;
108     Visual *m_pVisual;
109     int m_pixelSize;
110     GC m_gc;
111     Colormap m_colormap;
112     int m_redLeftShift, m_redRightShift;
113     int m_greenLeftShift, m_greenRightShift;
114     int m_blueLeftShift, m_blueRightShift;
115     /// Pointer on the right implementation of blendPixel
116     MakePixelFunc_t blendPixelImpl;
117     /// Pointer on the right implementation of putPixel
118     MakePixelFunc_t putPixelImpl;
119
120     template<class type> type putPixel(type r, type g, type b) const;
121     template<class type>
122     type blendPixel(type v,type r, type g, type b,type a) const;
123
124     /// Calculate shifts from a color mask
125     static void getShifts( uint32_t mask, int &rLeftShift, int &rRightShift );
126
127     /// 8 bpp version of blendPixel
128     void blendPixel8( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
129                       uint8_t a ) const;
130
131     /// 16 bpp MSB first version of blendPixel
132     void blendPixel16MSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
133                           uint8_t a ) const;
134
135     /// 16 bpp LSB first version of blendPixel
136     void blendPixel16LSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
137                           uint8_t a ) const;
138
139     /// 24/32 bpp MSB first version of blendPixel
140     void blendPixel32MSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
141                           uint8_t a ) const;
142
143     /// 24/32 bpp LSB first version of blendPixel
144     void blendPixel32LSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
145                           uint8_t a ) const;
146
147     /// 8 bpp version of putPixel
148     void putPixel8( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
149                     uint8_t a ) const;
150
151     /// 16 bpp MSB first version of putPixel
152     void putPixel16MSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
153                         uint8_t a ) const;
154
155     /// 16 bpp LSB first version of putPixel
156     void putPixel16LSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
157                         uint8_t a ) const;
158
159     /// 24/32 bpp MSB first version of putPixel
160     void putPixel32MSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
161                         uint8_t a ) const;
162
163     /// 24/32 bpp LSB first version of putPixel
164     void putPixel32LSB( uint8_t *pPixel, uint8_t r, uint8_t g, uint8_t b,
165                         uint8_t a ) const;
166
167 };
168
169 #endif