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