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