LibreOffice Module vcl (master)  1
wmadaptor.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_VCL_INC_UNX_WMADAPTOR_HXX
21 #define INCLUDED_VCL_INC_UNX_WMADAPTOR_HXX
22 
23 #include <rtl/ustring.hxx>
24 #include <tools/gen.hxx>
25 
26 #include <X11/Xlib.h>
27 
28 #include <vclpluginapi.h>
29 #include "salframe.h"
30 #include <vector>
31 
32 class SalDisplay;
33 class X11SalFrame;
34 
35 namespace vcl_sal {
36 
37 class WMAdaptor
38 {
39 public:
40  enum WMAtom {
41  // atoms for types
43 
44  // atoms for extended WM hints
79 
80  // atoms for Gnome WM hints
92 
93  // atoms for general WM hints
103 
104  // special atoms
114  };
115 
116  /*
117  * flags for frame decoration
118  */
119  static const int decoration_Title = 0x00000001;
120  static const int decoration_Border = 0x00000002;
121  static const int decoration_Resize = 0x00000004;
122  static const int decoration_MinimizeBtn = 0x00000008;
123  static const int decoration_MaximizeBtn = 0x00000010;
124  static const int decoration_CloseBtn = 0x00000020;
125  static const int decoration_All = 0x10000000;
126 
127 protected:
128  SalDisplay* m_pSalDisplay; // Display to use
129  Display* m_pDisplay; // X Display of SalDisplay
130  OUString m_aWMName;
134  ::std::vector< tools::Rectangle >
142 
143  WMAdaptor( SalDisplay * )
144 ;
145  void initAtoms();
146  bool getNetWmName();
147 
148  /*
149  * returns whether this instance is useful
150  * only useful for createWMAdaptor
151  */
152  virtual bool isValid() const;
153 
154  bool getWMshouldSwitchWorkspace() const;
155 public:
156  virtual ~WMAdaptor();
157 
158  /*
159  * creates a valid WMAdaptor instance for the SalDisplay
160  */
161  static std::unique_ptr<WMAdaptor> createWMAdaptor( SalDisplay* );
162 
163  /*
164  * may return an empty string if the window manager could
165  * not be identified.
166  */
167  const OUString& getWindowManagerName() const
168  { return m_aWMName; }
169 
170  /*
171  * gets the current work area/desktop number: [0,m_nDesktops[ or -1 if unknown
172  */
173  int getCurrentWorkArea() const;
174  /*
175  * gets the workarea the specified window is on (or -1)
176  */
177  int getWindowWorkArea( ::Window aWindow ) const;
178  /*
179  * gets the specified workarea
180  */
181  const tools::Rectangle& getWorkArea( int n ) const
182  { return m_aWMWorkAreas[n]; }
183 
184  /*
185  * attempt to switch the desktop to a certain workarea (ie. virtual desktops)
186  */
187  void switchToWorkArea( int nWorkArea ) const;
188 
189  /*
190  * sets window title
191  */
192  virtual void setWMName( X11SalFrame* pFrame, const OUString& rWMName ) const;
193 
194  /*
195  * set NET_WM_PID
196  */
197  void setPID( X11SalFrame const * pFrame ) const;
198 
199  /*
200  * set WM_CLIENT_MACHINE
201  */
202  void setClientMachine( X11SalFrame const * pFrame ) const;
203 
204  void answerPing( X11SalFrame const *, XClientMessageEvent const * ) const;
205 
206  /*
207  * maximizes frame
208  * maximization can be toggled in either direction
209  * to get the original position and size
210  * use maximizeFrame( pFrame, false, false )
211  */
212  virtual void maximizeFrame( X11SalFrame* pFrame, bool bHorizontal = true, bool bVertical = true ) const;
213  /*
214  * start/stop fullscreen mode on a frame
215  */
216  virtual void showFullScreen( X11SalFrame* pFrame, bool bFullScreen ) const;
217  /*
218  * tell whether legacy partial full screen handling is necessary
219  * see #i107249#: NET_WM_STATE_FULLSCREEN is not well defined, but de facto
220  * modern WM's interpret it the "right" way, namely they make "full screen"
221  * taking twin view or Xinerama into account and honor the positioning hints
222  * to see which screen actually was meant to use for fullscreen.
223  */
225  { return m_bLegacyPartialFullscreen; }
226  /*
227  * set _NET_WM_USER_TIME property, if NetWM
228  */
229  virtual void setUserTime( X11SalFrame* i_pFrame, tools::Long i_nUserTime ) const;
230 
231  /*
232  * tells whether fullscreen mode is supported by WM
233  */
234  bool supportsFullScreen() const { return m_aWMAtoms[ NET_WM_STATE_FULLSCREEN ] != 0; }
235 
236  /*
237  * set hints what decoration is needed;
238  * must be called before showing the frame
239  */
240  virtual void setFrameTypeAndDecoration( X11SalFrame* pFrame, WMWindowType eType, int nDecorationFlags, X11SalFrame* pTransientFrame ) const;
241 
242  /*
243  * tells whether there is WM support for splash screens
244  */
245  bool supportsSplash() const { return m_aWMAtoms[ NET_WM_WINDOW_TYPE_SPLASH ] != 0; }
246 
247  /*
248  * enables always on top or equivalent if possible
249  */
250  virtual void enableAlwaysOnTop( X11SalFrame* pFrame, bool bEnable ) const;
251 
252  /*
253  * tells whether enableAlwaysOnTop actually works with this WM
254  */
256 
257  /*
258  * handle WM messages (especially WM state changes)
259  */
260  virtual int handlePropertyNotify( X11SalFrame* pFrame, XPropertyEvent* pEvent ) const;
261 
262  /*
263  * called by SalFrame::Show: time to update state properties
264  */
265  virtual void frameIsMapping( X11SalFrame* ) const;
266 
267  /*
268  * gets a WM atom
269  */
270  Atom getAtom( WMAtom eAtom ) const
271  { return m_aWMAtoms[ eAtom ]; }
272 
274  { return m_nWinGravity; }
275  int getInitWinGravity() const
276  { return m_nInitWinGravity; }
277 
278  /*
279  * changes the transient hint of a window to reference frame
280  * if reference frame is NULL the root window is used instead
281  */
282  void changeReferenceFrame( X11SalFrame* pFrame, X11SalFrame const * pReferenceFrame ) const;
283 
284  /*
285  * Requests the change of active window by sending
286  * _NET_ACTIVE_WINDOW message to the frame. The frame
287  * has to be mapped
288  */
289  void activateWindow( X11SalFrame const *pFrame, Time nTimestamp );
290 };
291 
292 } // namespace
293 
294 #endif
295 
296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Atom m_aWMAtoms[NetAtomMax]
Definition: wmadaptor.hxx:131
void switchToWorkArea(int nWorkArea) const
virtual void maximizeFrame(X11SalFrame *pFrame, bool bHorizontal=true, bool bVertical=true) const
static const int decoration_Border
Definition: wmadaptor.hxx:120
virtual bool isValid() const
void setPID(X11SalFrame const *pFrame) const
int getCurrentWorkArea() const
long Long
virtual int handlePropertyNotify(X11SalFrame *pFrame, XPropertyEvent *pEvent) const
bool supportsFullScreen() const
Definition: wmadaptor.hxx:234
Atom getAtom(WMAtom eAtom) const
Definition: wmadaptor.hxx:270
int getInitWinGravity() const
Definition: wmadaptor.hxx:275
int getWindowWorkArea(::Window aWindow) const
bool isAlwaysOnTopOK() const
Definition: wmadaptor.hxx:255
Display * m_pDisplay
Definition: wmadaptor.hxx:129
bool m_bLegacyPartialFullscreen
Definition: wmadaptor.hxx:137
virtual ~WMAdaptor()
const tools::Rectangle & getWorkArea(int n) const
Definition: wmadaptor.hxx:181
static const int decoration_All
Definition: wmadaptor.hxx:125
static std::unique_ptr< WMAdaptor > createWMAdaptor(SalDisplay *)
static const int decoration_MinimizeBtn
Definition: wmadaptor.hxx:122
WMWindowType
Definition: unx/salframe.h:50
bool m_bWMshouldSwitchWorkspaceInit
Definition: wmadaptor.hxx:141
static const int decoration_Resize
Definition: wmadaptor.hxx:121
virtual void enableAlwaysOnTop(X11SalFrame *pFrame, bool bEnable) const
SalDisplay * m_pSalDisplay
Definition: wmadaptor.hxx:128
void setClientMachine(X11SalFrame const *pFrame) const
virtual void setFrameTypeAndDecoration(X11SalFrame *pFrame, WMWindowType eType, int nDecorationFlags, X11SalFrame *pTransientFrame) const
Display
static const int decoration_MaximizeBtn
Definition: wmadaptor.hxx:123
virtual void showFullScreen(X11SalFrame *pFrame, bool bFullScreen) const
static const int decoration_CloseBtn
Definition: wmadaptor.hxx:124
void changeReferenceFrame(X11SalFrame *pFrame, X11SalFrame const *pReferenceFrame) const
bool isLegacyPartialFullscreen() const
Definition: wmadaptor.hxx:224
::std::vector< tools::Rectangle > m_aWMWorkAreas
Definition: wmadaptor.hxx:135
virtual void frameIsMapping(X11SalFrame *) const
bool getWMshouldSwitchWorkspace() const
const OUString & getWindowManagerName() const
Definition: wmadaptor.hxx:167
static const int decoration_Title
Definition: wmadaptor.hxx:119
WMAdaptor(SalDisplay *)
bool m_bEnableAlwaysOnTopWorks
Definition: wmadaptor.hxx:136
int getPositionWinGravity() const
Definition: wmadaptor.hxx:273
virtual void setUserTime(X11SalFrame *i_pFrame, tools::Long i_nUserTime) const
bool supportsSplash() const
Definition: wmadaptor.hxx:245
virtual void setWMName(X11SalFrame *pFrame, const OUString &rWMName) const
void answerPing(X11SalFrame const *, XClientMessageEvent const *) const
void activateWindow(X11SalFrame const *pFrame, Time nTimestamp)
bool m_bWMshouldSwitchWorkspace
Definition: wmadaptor.hxx:140