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 
38 {
39 public:
40  enum WMAtom {
41  // atoms for types
43 
44  // atoms for extended WM hints
80 
81  // atoms for Gnome WM hints
93 
94  // atoms for general WM hints
104 
105  // special atoms
114  NetAtomMax
115  };
116 
117  /*
118  * flags for frame decoration
119  */
120  static const int decoration_Title = 0x00000001;
121  static const int decoration_Border = 0x00000002;
122  static const int decoration_Resize = 0x00000004;
123  static const int decoration_MinimizeBtn = 0x00000008;
124  static const int decoration_MaximizeBtn = 0x00000010;
125  static const int decoration_CloseBtn = 0x00000020;
126  static const int decoration_All = 0x10000000;
127 
128 protected:
129  SalDisplay* const m_pSalDisplay; // Display to use
130  Display* m_pDisplay; // X Display of SalDisplay
131  OUString m_aWMName;
132  Atom m_aWMAtoms[ NetAtomMax];
135  ::std::vector< tools::Rectangle >
143 
144  WMAdaptor( SalDisplay * )
145 ;
146  void initAtoms();
147  bool getNetWmName();
148 
149  /*
150  * returns whether this instance is useful
151  * only useful for createWMAdaptor
152  */
153  virtual bool isValid() const;
154 
155  bool getWMshouldSwitchWorkspace() const;
156 public:
157  virtual ~WMAdaptor();
158 
159  /*
160  * creates a valid WMAdaptor instance for the SalDisplay
161  */
162  static std::unique_ptr<WMAdaptor> createWMAdaptor( SalDisplay* );
163 
164  /*
165  * may return an empty string if the window manager could
166  * not be identified.
167  */
168  const OUString& getWindowManagerName() const
169  { return m_aWMName; }
170 
171  /*
172  * gets the current work area/desktop number: [0,m_nDesktops[ or -1 if unknown
173  */
174  int getCurrentWorkArea() const;
175  /*
176  * gets the workarea the specified window is on (or -1)
177  */
178  int getWindowWorkArea( ::Window aWindow ) const;
179  /*
180  * gets the specified workarea
181  */
182  const tools::Rectangle& getWorkArea( int n ) const
183  { return m_aWMWorkAreas[n]; }
184 
185  /*
186  * attempt to switch the desktop to a certain workarea (ie. virtual desktops)
187  */
188  void switchToWorkArea( int nWorkArea ) const;
189 
190  /*
191  * sets window title
192  */
193  virtual void setWMName( X11SalFrame* pFrame, const OUString& rWMName ) const;
194 
195  /*
196  * set NET_WM_PID
197  */
198  void setPID( X11SalFrame const * pFrame ) const;
199 
200  /*
201  * set WM_CLIENT_MACHINE
202  */
203  void setClientMachine( X11SalFrame const * pFrame ) const;
204 
205  void answerPing( X11SalFrame const *, XClientMessageEvent const * ) const;
206 
207  /*
208  * maximizes frame
209  * maximization can be toggled in either direction
210  * to get the original position and size
211  * use maximizeFrame( pFrame, false, false )
212  */
213  virtual void maximizeFrame( X11SalFrame* pFrame, bool bHorizontal = true, bool bVertical = true ) const;
214  /*
215  * start/stop fullscreen mode on a frame
216  */
217  virtual void showFullScreen( X11SalFrame* pFrame, bool bFullScreen ) const;
218  /*
219  * tell whether legacy partial full screen handling is necessary
220  * see #i107249#: NET_WM_STATE_FULLSCREEN is not well defined, but de facto
221  * modern WM's interpret it the "right" way, namely they make "full screen"
222  * taking twin view or Xinerama into account and honor the positioning hints
223  * to see which screen actually was meant to use for fullscreen.
224  */
226  { return m_bLegacyPartialFullscreen; }
227  /*
228  * set _NET_WM_USER_TIME property, if NetWM
229  */
230  virtual void setUserTime( X11SalFrame* i_pFrame, long i_nUserTime ) const;
231 
232  /*
233  * tells whether fullscreen mode is supported by WM
234  */
235  bool supportsFullScreen() const { return m_aWMAtoms[ NET_WM_STATE_FULLSCREEN ] != 0; }
236 
237  /*
238  * shade/unshade frame
239  */
240  virtual void shade( X11SalFrame* pFrame, bool bToShaded ) const;
241 
242  /*
243  * set hints what decoration is needed;
244  * must be called before showing the frame
245  */
246  virtual void setFrameTypeAndDecoration( X11SalFrame* pFrame, WMWindowType eType, int nDecorationFlags, X11SalFrame* pTransientFrame ) const;
247 
248  /*
249  * tells whether there is WM support for splash screens
250  */
251  bool supportsSplash() const { return m_aWMAtoms[ NET_WM_WINDOW_TYPE_SPLASH ] != 0; }
252 
253  /*
254  * enables always on top or equivalent if possible
255  */
256  virtual void enableAlwaysOnTop( X11SalFrame* pFrame, bool bEnable ) const;
257 
258  /*
259  * tells whether enableAlwaysOnTop actually works with this WM
260  */
261  bool isAlwaysOnTopOK() const { return m_bEnableAlwaysOnTopWorks; }
262 
263  /*
264  * handle WM messages (especially WM state changes)
265  */
266  virtual int handlePropertyNotify( X11SalFrame* pFrame, XPropertyEvent* pEvent ) const;
267 
268  /*
269  * called by SalFrame::Show: time to update state properties
270  */
271  virtual void frameIsMapping( X11SalFrame* ) const;
272 
273  /*
274  * gets a WM atom
275  */
276  Atom getAtom( WMAtom eAtom ) const
277  { return m_aWMAtoms[ eAtom ]; }
278 
280  { return m_nWinGravity; }
281  int getInitWinGravity() const
282  { return m_nInitWinGravity; }
283 
284  /*
285  * changes the transient hint of a window to reference frame
286  * if reference frame is NULL the root window is used instead
287  */
288  void changeReferenceFrame( X11SalFrame* pFrame, X11SalFrame const * pReferenceFrame ) const;
289 
290  /*
291  * Requests the change of active window by sending
292  * _NET_ACTIVE_WINDOW message to the frame. The frame
293  * has to be mapped
294  */
295  void activateWindow( X11SalFrame const *pFrame, Time nTimestamp );
296 };
297 
298 } // namespace
299 
300 #endif
301 
302 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool supportsFullScreen() const
Definition: wmadaptor.hxx:235
Atom getAtom(WMAtom eAtom) const
Definition: wmadaptor.hxx:276
int getInitWinGravity() const
Definition: wmadaptor.hxx:281
SalDisplay *const m_pSalDisplay
Definition: wmadaptor.hxx:129
bool isAlwaysOnTopOK() const
Definition: wmadaptor.hxx:261
Display * m_pDisplay
Definition: wmadaptor.hxx:130
bool m_bLegacyPartialFullscreen
Definition: wmadaptor.hxx:138
const tools::Rectangle & getWorkArea(int n) const
Definition: wmadaptor.hxx:182
#define VCLPLUG_GEN_PUBLIC
Definition: vclpluginapi.h:29
WMWindowType
Definition: unx/salframe.h:51
bool m_bWMshouldSwitchWorkspaceInit
Definition: wmadaptor.hxx:142
Display
bool isLegacyPartialFullscreen() const
Definition: wmadaptor.hxx:225
::std::vector< tools::Rectangle > m_aWMWorkAreas
Definition: wmadaptor.hxx:136
const OUString & getWindowManagerName() const
Definition: wmadaptor.hxx:168
bool m_bEnableAlwaysOnTopWorks
Definition: wmadaptor.hxx:137
int getPositionWinGravity() const
Definition: wmadaptor.hxx:279
bool supportsSplash() const
Definition: wmadaptor.hxx:251
bool m_bWMshouldSwitchWorkspace
Definition: wmadaptor.hxx:141