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