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