xref: /trunk/main/vcl/inc/unx/wmadaptor.hxx (revision d11ac732c2ba6981498374757fddc29abbf2b738)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #ifndef _VCL_WMADAPTOR_HXX_
23 #define _VCL_WMADAPTOR_HXX_
24 
25 #ifndef _TL_STRING_HXX
26 #include <tools/string.hxx>
27 #endif
28 #include <tools/gen.hxx>
29 #ifndef _PREX_H
30 #include <tools/prex.h>
31 #include <X11/Xlib.h>
32 #include <tools/postx.h>
33 #endif
34 #include <vclpluginapi.h>
35 #include <vector>
36 
37 class SalDisplay;
38 class X11SalFrame;
39 
40 namespace vcl_sal {
41 
42 class VCLPLUG_GEN_PUBLIC WMAdaptor
43 {
44 public:
45     enum WMAtom {
46         // atoms for types
47         UTF8_STRING,
48 
49         // atoms for extended WM hints
50         NET_SUPPORTED,
51         NET_SUPPORTING_WM_CHECK,
52         NET_WM_NAME,
53         NET_WM_DESKTOP,
54         NET_WM_ICON_NAME,
55         NET_WM_PID,
56         NET_WM_PING,
57         NET_WM_STATE,
58         NET_WM_STATE_MAXIMIZED_HORZ,
59         NET_WM_STATE_MAXIMIZED_VERT,
60         NET_WM_STATE_MODAL,
61         NET_WM_STATE_SHADED,
62         NET_WM_STATE_SKIP_PAGER,
63         NET_WM_STATE_SKIP_TASKBAR,
64         NET_WM_STATE_STAYS_ON_TOP,
65         NET_WM_STATE_STICKY,
66         NET_WM_STATE_FULLSCREEN,
67         NET_WM_FULLSCREEN_MONITORS,
68         NET_WM_STRUT,
69         NET_WM_STRUT_PARTIAL,
70         NET_WM_USER_TIME,
71         NET_WM_WINDOW_TYPE,
72         NET_WM_WINDOW_TYPE_DESKTOP,
73         NET_WM_WINDOW_TYPE_DIALOG,
74         NET_WM_WINDOW_TYPE_DOCK,
75         NET_WM_WINDOW_TYPE_MENU,
76         NET_WM_WINDOW_TYPE_NORMAL,
77         NET_WM_WINDOW_TYPE_TOOLBAR,
78         KDE_NET_WM_WINDOW_TYPE_OVERRIDE,
79         NET_WM_WINDOW_TYPE_SPLASH,
80         NET_WM_WINDOW_TYPE_UTILITY,
81         NET_NUMBER_OF_DESKTOPS,
82         NET_CURRENT_DESKTOP,
83         NET_WORKAREA,
84 
85         // atoms for Gnome WM hints
86         WIN_SUPPORTING_WM_CHECK,
87         WIN_PROTOCOLS,
88         WIN_WORKSPACE_COUNT,
89         WIN_WORKSPACE,
90         WIN_LAYER,
91         WIN_STATE,
92         WIN_HINTS,
93         WIN_APP_STATE,
94         WIN_EXPANDED_SIZE,
95         WIN_ICONS,
96         WIN_WORKSPACE_NAMES,
97         WIN_CLIENT_LIST,
98 
99         // atoms for general WM hints
100         WM_STATE,
101         MOTIF_WM_HINTS,
102         WM_PROTOCOLS,
103         WM_DELETE_WINDOW,
104         WM_TAKE_FOCUS,
105         WM_SAVE_YOURSELF,
106         WM_CLIENT_LEADER,
107         WM_COMMAND,
108         WM_LOCALE_NAME,
109         WM_TRANSIENT_FOR,
110 
111         // special atoms
112         SAL_QUITEVENT,
113         SAL_USEREVENT,
114         SAL_EXTTEXTEVENT,
115         SAL_GETTIMEEVENT,
116         DTWM_IS_RUNNING,
117         VCL_SYSTEM_SETTINGS,
118         XSETTINGS,
119         XEMBED,
120         XEMBED_INFO,
121         NetAtomMax
122     };
123 
124     /*
125      * flags for frame decoration
126      */
127     static const int decoration_Title           = 0x00000001;
128     static const int decoration_Border      = 0x00000002;
129     static const int decoration_Resize      = 0x00000004;
130     static const int decoration_MinimizeBtn = 0x00000008;
131     static const int decoration_MaximizeBtn = 0x00000010;
132     static const int decoration_CloseBtn        = 0x00000020;
133     static const int decoration_All         = 0x10000000;
134 
135     /*
136      * window type
137      */
138     enum WMWindowType
139     {
140         windowType_Normal,
141         windowType_ModalDialogue,
142         windowType_ModelessDialogue,
143         windowType_Utility,
144         windowType_Splash,
145         windowType_Toolbar,
146         windowType_Dock
147     };
148 
149 protected:
150     SalDisplay*             m_pSalDisplay;      // Display to use
151     Display*                m_pDisplay;         // X Display of SalDisplay
152     String                  m_aWMName;
153     Atom                    m_aWMAtoms[ NetAtomMax];
154     int                     m_nDesktops;
155     bool                    m_bEqualWorkAreas;
156     ::std::vector< Rectangle >
157                             m_aWMWorkAreas;
158     bool                    m_bTransientBehaviour;
159     bool                    m_bEnableAlwaysOnTopWorks;
160     bool                    m_bLegacyPartialFullscreen;
161     int                     m_nWinGravity;
162     int                     m_nInitWinGravity;
163     bool                    m_bWMshouldSwitchWorkspace;
164     bool                    m_bWMshouldSwitchWorkspaceInit;
165 
166     WMAdaptor( SalDisplay * )
167 ;
168     void initAtoms();
169     bool getNetWmName();
170 
171     /*
172      * returns whether this instance is useful
173      * only useful for createWMAdaptor
174      */
175     virtual bool isValid() const;
176 
177     bool getWMshouldSwitchWorkspace() const;
178 public:
179     virtual ~WMAdaptor();
180 
181     /*
182      * creates a valid WMAdaptor instance for the SalDisplay
183      */
184     static WMAdaptor* createWMAdaptor( SalDisplay* );
185 
186     /*
187      * may return an empty string if the window manager could
188      * not be identified.
189      */
getWindowManagerName() const190     const String& getWindowManagerName() const
191     { return m_aWMName; }
192 
193     /*
194      * gets the number of workareas
195      */
getWorkAreaCount() const196     int getWorkAreaCount() const
197     { return m_aWMWorkAreas.size(); }
198 
199     /*
200      * gets the current work area/desktop number: [0,m_nDesktops[ or -1 if unknown
201      */
202     int getCurrentWorkArea() const;
203     /*
204      * gets the workarea the specified window is on (or -1)
205      */
206     int getWindowWorkArea( XLIB_Window aWindow ) const;
207     /*
208      * gets the specified workarea
209      */
getWorkArea(int n) const210     const Rectangle& getWorkArea( int n ) const
211     { return m_aWMWorkAreas[n]; }
212 
213     /*
214      * attempt to switch the desktop to a certain workarea
215      * if bConsiderWM is true, then on some WMs the call will not result in any action
216      */
217     void switchToWorkArea( int nWorkArea, bool bConsiderWM = true ) const;
218 
219     /*
220      * sets window title
221      */
222     virtual void setWMName( X11SalFrame* pFrame, const String& rWMName ) const;
223 
224     /*
225      * set NET_WM_PID
226      */
227     virtual void setPID( X11SalFrame* pFrame ) const;
228 
229     /*
230      * set WM_CLIENT_MACHINE
231      */
232     virtual void setClientMachine( X11SalFrame* pFrame ) const;
233 
234     virtual void answerPing( X11SalFrame*, XClientMessageEvent* ) const;
235 
236     /*
237      * maximizes frame
238      * maximization can be toggled in either direction
239      * to get the original position and size
240      * use maximizeFrame( pFrame, false, false )
241      */
242     virtual void maximizeFrame( X11SalFrame* pFrame, bool bHorizontal = true, bool bVertical = true ) const;
243     /*
244      * start/stop fullscreen mode on a frame
245      */
246     virtual void showFullScreen( X11SalFrame* pFrame, bool bFullScreen ) const;
247     /*
248      * tell whether legacy partial full screen handling is necessary
249      * see #i107249#: NET_WM_STATE_FULLSCREEN is not well defined, but de facto
250      * modern WM's interpret it the "right" way, namely they make "full screen"
251      * taking twin view or Xinerama into account and honor the positioning hints
252      * to see which screen actually was meant to use for fullscreen.
253      */
isLegacyPartialFullscreen() const254     bool isLegacyPartialFullscreen() const
255     { return m_bLegacyPartialFullscreen; }
256     /*
257      * set window struts
258      */
259     virtual void setFrameStruts( X11SalFrame*pFrame,
260                                  int left, int right, int top, int bottom,
261                                  int left_start_y, int left_end_y,
262                                  int right_start_y, int right_end_y,
263                                  int top_start_x, int top_end_x,
264                                  int bottom_start_x, int bottom_end_x ) const;
265     /*
266      * set _NET_WM_USER_TIME property, if NetWM
267      */
268     virtual void setUserTime( X11SalFrame* i_pFrame, long i_nUserTime ) const;
269 
270     /*
271      * tells whether fullscreen mode is supported by WM
272      */
supportsFullScreen() const273     bool supportsFullScreen() const { return m_aWMAtoms[ NET_WM_STATE_FULLSCREEN ] != 0; }
274 
275     /*
276      * shade/unshade frame
277      */
278     virtual void shade( X11SalFrame* pFrame, bool bToShaded ) const;
279 
280     /*
281      * set hints what decoration is needed;
282      * must be called before showing the frame
283      */
284     virtual void setFrameTypeAndDecoration( X11SalFrame* pFrame, WMWindowType eType, int nDecorationFlags, X11SalFrame* pTransientFrame = NULL ) const;
285 
286     /*
287      * tells whether there is WM support for splash screens
288      */
supportsSplash() const289     bool supportsSplash() const { return m_aWMAtoms[ NET_WM_WINDOW_TYPE_SPLASH ] != 0; }
290 
291     /*
292      * tells whether there is WM support for NET_WM_WINDOW_TYPE_TOOLBAR
293      */
supportsToolbar() const294     bool supportsToolbar() const { return m_aWMAtoms[ NET_WM_WINDOW_TYPE_TOOLBAR ] != 0; }
295 
296     /*
297      * enables always on top or equivalent if possible
298      */
299     virtual void enableAlwaysOnTop( X11SalFrame* pFrame, bool bEnable ) const;
300 
301     /*
302      * tells whether enableAlwaysOnTop actually works with this WM
303      */
isAlwaysOnTopOK() const304     bool isAlwaysOnTopOK() const { return m_bEnableAlwaysOnTopWorks; }
305 
306     /*
307      * handle WM messages (especially WM state changes)
308      */
309     virtual int handlePropertyNotify( X11SalFrame* pFrame, XPropertyEvent* pEvent ) const;
310 
311     /*
312      * called by SalFrame::Show: time to update state properties
313      */
314     virtual void frameIsMapping( X11SalFrame* ) const;
315 
316     /*
317      * gets a WM atom
318      */
getAtom(WMAtom eAtom) const319     Atom getAtom( WMAtom eAtom ) const
320     { return m_aWMAtoms[ eAtom ]; }
321 
322     /*
323      * supports correct positioning
324      */
325 
326     virtual bool supportsICCCMPos () const;
327 
getPositionWinGravity() const328     int getPositionWinGravity () const
329     { return m_nWinGravity; }
getInitWinGravity() const330     int getInitWinGravity() const
331     { return m_nInitWinGravity; }
332 
333     /*
334      * expected behavior is that the WM will not allow transient
335      * windows to get stacked behind the windows they are transient for
336      */
isTransientBehaviourAsExpected() const337     bool isTransientBehaviourAsExpected() const
338     { return m_bTransientBehaviour; }
339 
340     /*
341      * changes the transient hint of a window to reference frame
342      * if reference frame is NULL the root window is used instead
343      */
344     void changeReferenceFrame( X11SalFrame* pFrame, X11SalFrame* pReferenceFrame ) const;
345 
346     /* set fullscreen monitor range; takes X11 window as input since it is also used by gtk plugin
347      */
348     virtual void setFullScreenMonitors( XLIB_Window i_aWindow, sal_Int32 i_nScreen );
349 };
350 
351 } // namespace
352 
353 #endif
354 
355 /* vim: set noet sw=4 ts=4: */
356