Line data Source code
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 : #include <string.h>
21 : #include <stdio.h>
22 : #include <stdlib.h>
23 :
24 : #include "sal/alloca.h"
25 : #include "rtl/locale.h"
26 :
27 : #include "osl/thread.h"
28 : #include "osl/process.h"
29 : #include <sal/macros.h>
30 : #include "vcl/configsettings.hxx"
31 :
32 : #include "unx/wmadaptor.hxx"
33 : #include "unx/saldisp.hxx"
34 : #include "unx/saldata.hxx"
35 : #include "unx/salframe.h"
36 :
37 : #include "salgdi.hxx"
38 :
39 : #include <prex.h>
40 : #include <X11/X.h>
41 : #include <X11/Xatom.h>
42 : #include <X11/Xresource.h>
43 : #include <postx.h>
44 :
45 : namespace vcl_sal {
46 :
47 : class NetWMAdaptor : public WMAdaptor
48 : {
49 : void setNetWMState( X11SalFrame* pFrame ) const;
50 : void initAtoms();
51 : virtual bool isValid() const SAL_OVERRIDE;
52 : public:
53 : explicit NetWMAdaptor( SalDisplay* );
54 : virtual ~NetWMAdaptor();
55 :
56 : virtual void setWMName( X11SalFrame* pFrame, const OUString& rWMName ) const SAL_OVERRIDE;
57 : virtual void maximizeFrame( X11SalFrame* pFrame, bool bHorizontal = true, bool bVertical = true ) const SAL_OVERRIDE;
58 : virtual void shade( X11SalFrame* pFrame, bool bToShaded ) const SAL_OVERRIDE;
59 : virtual void setFrameTypeAndDecoration( X11SalFrame* pFrame, WMWindowType eType, int nDecorationFlags, X11SalFrame* pTransientFrame = NULL ) const SAL_OVERRIDE;
60 : virtual void enableAlwaysOnTop( X11SalFrame* pFrame, bool bEnable ) const SAL_OVERRIDE;
61 : virtual int handlePropertyNotify( X11SalFrame* pFrame, XPropertyEvent* pEvent ) const SAL_OVERRIDE;
62 : virtual void showFullScreen( X11SalFrame* pFrame, bool bFullScreen ) const SAL_OVERRIDE;
63 : virtual void frameIsMapping( X11SalFrame* pFrame ) const SAL_OVERRIDE;
64 : virtual void setFrameStruts( X11SalFrame* pFrame,
65 : int left, int right, int top, int bottom,
66 : int left_start_y, int left_end_y,
67 : int right_start_y, int right_end_y,
68 : int top_start_x, int top_end_x,
69 : int bottom_start_x, int bottom_end_x ) const SAL_OVERRIDE;
70 : virtual void setUserTime( X11SalFrame* i_pFrame, long i_nUserTime ) const SAL_OVERRIDE;
71 : };
72 :
73 : class GnomeWMAdaptor : public WMAdaptor
74 : {
75 : bool m_bValid;
76 :
77 : void setGnomeWMState( X11SalFrame* pFrame ) const;
78 : void initAtoms();
79 : virtual bool isValid() const SAL_OVERRIDE;
80 : public:
81 : explicit GnomeWMAdaptor( SalDisplay * );
82 : virtual ~GnomeWMAdaptor();
83 :
84 : virtual void maximizeFrame( X11SalFrame* pFrame, bool bHorizontal = true, bool bVertical = true ) const SAL_OVERRIDE;
85 : virtual void shade( X11SalFrame* pFrame, bool bToShaded ) const SAL_OVERRIDE;
86 : virtual void enableAlwaysOnTop( X11SalFrame* pFrame, bool bEnable ) const SAL_OVERRIDE;
87 : virtual int handlePropertyNotify( X11SalFrame* pFrame, XPropertyEvent* pEvent ) const SAL_OVERRIDE;
88 : };
89 :
90 : }
91 :
92 : using namespace vcl_sal;
93 :
94 : struct WMAdaptorProtocol
95 : {
96 : const char* pProtocol;
97 : int nProtocol;
98 : };
99 :
100 : /*
101 : * table must be sorted ascending in strings
102 : * since it is use with bsearch
103 : */
104 : static const WMAdaptorProtocol aProtocolTab[] =
105 : {
106 : { "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE", WMAdaptor::KDE_NET_WM_WINDOW_TYPE_OVERRIDE },
107 : { "_NET_CURRENT_DESKTOP", WMAdaptor::NET_CURRENT_DESKTOP },
108 : { "_NET_NUMBER_OF_DESKTOPS", WMAdaptor::NET_NUMBER_OF_DESKTOPS },
109 : { "_NET_WM_DESKTOP", WMAdaptor::NET_WM_DESKTOP },
110 : { "_NET_WM_ICON", WMAdaptor::NET_WM_ICON },
111 : { "_NET_WM_ICON_NAME", WMAdaptor::NET_WM_ICON_NAME },
112 : { "_NET_WM_PING", WMAdaptor::NET_WM_PING },
113 : { "_NET_WM_STATE", WMAdaptor::NET_WM_STATE },
114 : { "_NET_WM_STATE_ABOVE", WMAdaptor::NET_WM_STATE_STAYS_ON_TOP },
115 : { "_NET_WM_STATE_FULLSCREEN", WMAdaptor::NET_WM_STATE_FULLSCREEN },
116 : { "_NET_WM_STATE_MAXIMIZED_HORIZ", WMAdaptor::NET_WM_STATE_MAXIMIZED_HORZ }, // common bug in e.g. older kwin and sawfish implementations
117 : { "_NET_WM_STATE_MAXIMIZED_HORZ", WMAdaptor::NET_WM_STATE_MAXIMIZED_HORZ },
118 : { "_NET_WM_STATE_MAXIMIZED_VERT", WMAdaptor::NET_WM_STATE_MAXIMIZED_VERT },
119 : { "_NET_WM_STATE_MODAL", WMAdaptor::NET_WM_STATE_MODAL },
120 : { "_NET_WM_STATE_SHADED", WMAdaptor::NET_WM_STATE_SHADED },
121 : { "_NET_WM_STATE_SKIP_PAGER", WMAdaptor::NET_WM_STATE_SKIP_PAGER },
122 : { "_NET_WM_STATE_SKIP_TASKBAR", WMAdaptor::NET_WM_STATE_SKIP_TASKBAR },
123 : { "_NET_WM_STATE_STAYS_ON_TOP", WMAdaptor::NET_WM_STATE_STAYS_ON_TOP },
124 : { "_NET_WM_STATE_STICKY", WMAdaptor::NET_WM_STATE_STICKY },
125 : { "_NET_WM_STRUT", WMAdaptor::NET_WM_STRUT },
126 : { "_NET_WM_STRUT_PARTIAL", WMAdaptor::NET_WM_STRUT_PARTIAL },
127 : { "_NET_WM_WINDOW_TYPE", WMAdaptor::NET_WM_WINDOW_TYPE },
128 : { "_NET_WM_WINDOW_TYPE_DESKTOP", WMAdaptor::NET_WM_WINDOW_TYPE_DESKTOP },
129 : { "_NET_WM_WINDOW_TYPE_DIALOG", WMAdaptor::NET_WM_WINDOW_TYPE_DIALOG },
130 : { "_NET_WM_WINDOW_TYPE_DOCK", WMAdaptor::NET_WM_WINDOW_TYPE_DOCK },
131 : { "_NET_WM_WINDOW_TYPE_MENU", WMAdaptor::NET_WM_WINDOW_TYPE_MENU },
132 : { "_NET_WM_WINDOW_TYPE_NORMAL", WMAdaptor::NET_WM_WINDOW_TYPE_NORMAL },
133 : { "_NET_WM_WINDOW_TYPE_SPLASH", WMAdaptor::NET_WM_WINDOW_TYPE_SPLASH },
134 : { "_NET_WM_WINDOW_TYPE_SPLASHSCREEN", WMAdaptor::NET_WM_WINDOW_TYPE_SPLASH }, // bug in Metacity 2.4.1
135 : { "_NET_WM_WINDOW_TYPE_TOOLBAR", WMAdaptor::NET_WM_WINDOW_TYPE_TOOLBAR },
136 : { "_NET_WM_WINDOW_TYPE_UTILITY", WMAdaptor::NET_WM_WINDOW_TYPE_UTILITY },
137 : { "_NET_WORKAREA", WMAdaptor::NET_WORKAREA },
138 : { "_WIN_APP_STATE", WMAdaptor::WIN_APP_STATE },
139 : { "_WIN_CLIENT_LIST", WMAdaptor::WIN_CLIENT_LIST },
140 : { "_WIN_EXPANDED_SIZE", WMAdaptor::WIN_EXPANDED_SIZE },
141 : { "_WIN_HINTS", WMAdaptor::WIN_HINTS },
142 : { "_WIN_ICONS", WMAdaptor::WIN_ICONS },
143 : { "_WIN_LAYER", WMAdaptor::WIN_LAYER },
144 : { "_WIN_STATE", WMAdaptor::WIN_STATE },
145 : { "_WIN_WORKSPACE", WMAdaptor::WIN_WORKSPACE },
146 : { "_WIN_WORKSPACE_COUNT", WMAdaptor::WIN_WORKSPACE_COUNT }
147 : };
148 :
149 : /*
150 : * table containing atoms to get anyway
151 : */
152 :
153 : static const WMAdaptorProtocol aAtomTab[] =
154 : {
155 : { "WM_STATE", WMAdaptor::WM_STATE },
156 : { "_MOTIF_WM_HINTS", WMAdaptor::MOTIF_WM_HINTS },
157 : { "WM_PROTOCOLS", WMAdaptor::WM_PROTOCOLS },
158 : { "WM_DELETE_WINDOW", WMAdaptor::WM_DELETE_WINDOW },
159 : { "WM_TAKE_FOCUS", WMAdaptor::WM_TAKE_FOCUS },
160 : { "WM_COMMAND", WMAdaptor::WM_COMMAND },
161 : { "WM_CLIENT_LEADER", WMAdaptor::WM_CLIENT_LEADER },
162 : { "WM_LOCALE_NAME", WMAdaptor::WM_LOCALE_NAME },
163 : { "WM_TRANSIENT_FOR", WMAdaptor::WM_TRANSIENT_FOR },
164 : { "SAL_QUITEVENT", WMAdaptor::SAL_QUITEVENT },
165 : { "SAL_USEREVENT", WMAdaptor::SAL_USEREVENT },
166 : { "SAL_EXTTEXTEVENT", WMAdaptor::SAL_EXTTEXTEVENT },
167 : { "SAL_GETTIMEEVENT", WMAdaptor::SAL_GETTIMEEVENT },
168 : { "VCL_SYSTEM_SETTINGS", WMAdaptor::VCL_SYSTEM_SETTINGS },
169 : { "_XSETTINGS_SETTINGS", WMAdaptor::XSETTINGS },
170 : { "_XEMBED", WMAdaptor::XEMBED },
171 : { "_XEMBED_INFO", WMAdaptor::XEMBED_INFO },
172 : { "_NET_WM_USER_TIME", WMAdaptor::NET_WM_USER_TIME },
173 : { "_NET_WM_PID", WMAdaptor::NET_WM_PID }
174 : };
175 :
176 : extern "C" {
177 819 : static int compareProtocol( const void* pLeft, const void* pRight )
178 : {
179 819 : return strcmp( static_cast<const WMAdaptorProtocol*>(pLeft)->pProtocol, static_cast<const WMAdaptorProtocol*>(pRight)->pProtocol );
180 : }
181 : }
182 :
183 3 : WMAdaptor* WMAdaptor::createWMAdaptor( SalDisplay* pSalDisplay )
184 : {
185 3 : WMAdaptor* pAdaptor = NULL;
186 :
187 : // try a NetWM
188 3 : pAdaptor = new NetWMAdaptor( pSalDisplay );
189 3 : if( ! pAdaptor->isValid() )
190 0 : delete pAdaptor, pAdaptor = NULL;
191 : #if OSL_DEBUG_LEVEL > 1
192 : else
193 : fprintf( stderr, "WM supports extended WM hints\n" );
194 : #endif
195 :
196 : // try a GnomeWM
197 3 : if( ! pAdaptor )
198 : {
199 0 : pAdaptor = new GnomeWMAdaptor( pSalDisplay );
200 0 : if( ! pAdaptor->isValid() )
201 0 : delete pAdaptor, pAdaptor = NULL;
202 : #if OSL_DEBUG_LEVEL > 1
203 : else
204 : fprintf( stderr, "WM supports GNOME WM hints\n" );
205 : #endif
206 : }
207 :
208 3 : if( ! pAdaptor )
209 0 : pAdaptor = new WMAdaptor( pSalDisplay );
210 :
211 : #if OSL_DEBUG_LEVEL > 1
212 : fprintf(stderr, "Window Manager's name is \"%s\"\n",
213 : OUStringToOString(pAdaptor->getWindowManagerName(),
214 : RTL_TEXTENCODING_UTF8).getStr());
215 : #endif
216 3 : return pAdaptor;
217 : }
218 :
219 : /*
220 : * WMAdaptor constructor
221 : */
222 :
223 3 : WMAdaptor::WMAdaptor( SalDisplay* pDisplay ) :
224 : m_pSalDisplay( pDisplay ),
225 : m_bTransientBehaviour( true ),
226 : m_bEnableAlwaysOnTopWorks( false ),
227 : m_bLegacyPartialFullscreen( false ),
228 : m_nWinGravity( StaticGravity ),
229 : m_nInitWinGravity( StaticGravity ),
230 : m_bWMshouldSwitchWorkspace( true ),
231 3 : m_bWMshouldSwitchWorkspaceInit( false )
232 : {
233 3 : Atom aRealType = None;
234 3 : int nFormat = 8;
235 3 : unsigned long nItems = 0;
236 3 : unsigned long nBytesLeft = 0;
237 3 : unsigned char* pProperty = NULL;
238 :
239 : // default desktops
240 3 : m_nDesktops = 1;
241 9 : m_aWMWorkAreas = ::std::vector< Rectangle >
242 6 : ( 1, Rectangle( Point(), m_pSalDisplay->GetScreenSize( m_pSalDisplay->GetDefaultXScreen() ) ) );
243 3 : m_bEqualWorkAreas = true;
244 :
245 3 : memset( m_aWMAtoms, 0, sizeof( m_aWMAtoms ) );
246 3 : m_pDisplay = m_pSalDisplay->GetDisplay();
247 :
248 3 : initAtoms();
249 3 : getNetWmName(); // try to discover e.g. Sawfish
250 :
251 3 : if( m_aWMName.isEmpty() )
252 : {
253 : // check for ReflectionX wm (as it needs a workaround in Windows mode
254 0 : Atom aRwmRunning = XInternAtom( m_pDisplay, "RWM_RUNNING", True );
255 0 : if( aRwmRunning != None &&
256 : XGetWindowProperty( m_pDisplay,
257 : m_pSalDisplay->GetRootWindow( m_pSalDisplay->GetDefaultXScreen() ),
258 : aRwmRunning,
259 : 0, 32,
260 : False,
261 : aRwmRunning,
262 : &aRealType,
263 : &nFormat,
264 : &nItems,
265 : &nBytesLeft,
266 0 : &pProperty ) == 0 )
267 : {
268 0 : if( aRealType == aRwmRunning )
269 0 : m_aWMName = "ReflectionX";
270 0 : XFree( pProperty );
271 : }
272 0 : else if( (aRwmRunning = XInternAtom( m_pDisplay, "_WRQ_WM_RUNNING", True )) != None &&
273 : XGetWindowProperty( m_pDisplay,
274 : m_pSalDisplay->GetRootWindow( m_pSalDisplay->GetDefaultXScreen() ),
275 : aRwmRunning,
276 : 0, 32,
277 : False,
278 : XA_STRING,
279 : &aRealType,
280 : &nFormat,
281 : &nItems,
282 : &nBytesLeft,
283 0 : &pProperty ) == 0 )
284 : {
285 0 : if( aRealType == XA_STRING )
286 0 : m_aWMName = "ReflectionX Windows";
287 0 : XFree( pProperty );
288 : }
289 : }
290 3 : if( m_aWMName.isEmpty() )
291 : {
292 0 : Atom aTTAPlatform = XInternAtom( m_pDisplay, "TTA_CLIENT_PLATFORM", True );
293 0 : if( aTTAPlatform != None &&
294 : XGetWindowProperty( m_pDisplay,
295 : m_pSalDisplay->GetRootWindow( m_pSalDisplay->GetDefaultXScreen() ),
296 : aTTAPlatform,
297 : 0, 32,
298 : False,
299 : XA_STRING,
300 : &aRealType,
301 : &nFormat,
302 : &nItems,
303 : &nBytesLeft,
304 0 : &pProperty ) == 0 )
305 : {
306 0 : if( aRealType == XA_STRING )
307 : {
308 0 : m_aWMName = "Tarantella";
309 : // #i62319# pretend that AlwaysOnTop works since
310 : // the alwaysontop workaround in salframe.cxx results
311 : // in a raise/lower loop on a Windows tarantella client
312 : // FIXME: this property contains an identification string that
313 : // in theory should be good enough to recognize running on a
314 : // Windows client; however this string does not seem to be
315 : // documented as well as the property itself.
316 0 : m_bEnableAlwaysOnTopWorks = true;
317 : }
318 0 : XFree( pProperty );
319 : }
320 : }
321 3 : }
322 :
323 : /*
324 : * WMAdaptor destructor
325 : */
326 :
327 0 : WMAdaptor::~WMAdaptor()
328 : {
329 0 : }
330 :
331 : /*
332 : * NetWMAdaptor constructor
333 : */
334 :
335 3 : NetWMAdaptor::NetWMAdaptor( SalDisplay* pSalDisplay ) :
336 3 : WMAdaptor( pSalDisplay )
337 : {
338 : // currently all _NET WMs do transient like expected
339 3 : m_bTransientBehaviour = true;
340 :
341 3 : Atom aRealType = None;
342 3 : int nFormat = 8;
343 3 : unsigned long nItems = 0;
344 3 : unsigned long nBytesLeft = 0;
345 3 : unsigned char* pProperty = NULL;
346 :
347 3 : initAtoms();
348 :
349 : // check for NetWM
350 3 : bool bNetWM = getNetWmName();
351 3 : if( bNetWM
352 3 : && XGetWindowProperty( m_pDisplay,
353 : m_pSalDisplay->GetRootWindow( m_pSalDisplay->GetDefaultXScreen() ),
354 : m_aWMAtoms[ NET_SUPPORTED ],
355 : 0, 0,
356 : False,
357 : XA_ATOM,
358 : &aRealType,
359 : &nFormat,
360 : &nItems,
361 : &nBytesLeft,
362 3 : &pProperty ) == 0
363 3 : && aRealType == XA_ATOM
364 6 : && nFormat == 32
365 : )
366 : {
367 3 : if( pProperty )
368 : {
369 3 : XFree( pProperty );
370 3 : pProperty = NULL;
371 : }
372 : // collect supported protocols
373 3 : if( XGetWindowProperty( m_pDisplay,
374 : m_pSalDisplay->GetRootWindow( m_pSalDisplay->GetDefaultXScreen() ),
375 : m_aWMAtoms[ NET_SUPPORTED ],
376 3 : 0, nBytesLeft/4,
377 : False,
378 : XA_ATOM,
379 : &aRealType,
380 : &nFormat,
381 : &nItems,
382 : &nBytesLeft,
383 3 : &pProperty ) == 0
384 3 : && nItems
385 : )
386 : {
387 3 : Atom* pAtoms = reinterpret_cast<Atom*>(pProperty);
388 3 : char** pAtomNames = static_cast<char**>(alloca( sizeof(char*)*nItems ));
389 3 : if( XGetAtomNames( m_pDisplay, pAtoms, nItems, pAtomNames ) )
390 : {
391 : #if OSL_DEBUG_LEVEL > 1
392 : fprintf( stderr, "supported protocols:\n" );
393 : #endif
394 159 : for( unsigned long i = 0; i < nItems; i++ )
395 : {
396 : // #i80971# protect against invalid atoms
397 156 : if( pAtomNames[i] == NULL )
398 0 : continue;
399 :
400 : WMAdaptorProtocol aSearch;
401 156 : aSearch.pProtocol = pAtomNames[i];
402 : WMAdaptorProtocol* pMatch = static_cast<WMAdaptorProtocol*>(
403 : bsearch( &aSearch,
404 : aProtocolTab,
405 : SAL_N_ELEMENTS( aProtocolTab ),
406 : sizeof( struct WMAdaptorProtocol ),
407 156 : compareProtocol ));
408 156 : if( pMatch )
409 : {
410 72 : m_aWMAtoms[ pMatch->nProtocol ] = pAtoms[ i ];
411 72 : if( pMatch->nProtocol == NET_WM_STATE_STAYS_ON_TOP )
412 3 : m_bEnableAlwaysOnTopWorks = true;
413 : }
414 : #if OSL_DEBUG_LEVEL > 1
415 : fprintf( stderr, " %s%s\n", pAtomNames[i], ((pMatch)&&(pMatch->nProtocol != -1)) ? "" : " (unsupported)" );
416 : #endif
417 156 : XFree( pAtomNames[i] );
418 : }
419 : }
420 3 : XFree( pProperty );
421 3 : pProperty = NULL;
422 : }
423 0 : else if( pProperty )
424 : {
425 0 : XFree( pProperty );
426 0 : pProperty = NULL;
427 : }
428 :
429 : // get number of desktops
430 6 : if( m_aWMAtoms[ NET_NUMBER_OF_DESKTOPS ]
431 3 : && XGetWindowProperty( m_pDisplay,
432 : m_pSalDisplay->GetRootWindow( m_pSalDisplay->GetDefaultXScreen() ),
433 : m_aWMAtoms[ NET_NUMBER_OF_DESKTOPS ],
434 : 0, 1,
435 : False,
436 : XA_CARDINAL,
437 : &aRealType,
438 : &nFormat,
439 : &nItems,
440 : &nBytesLeft,
441 3 : &pProperty ) == 0
442 6 : && pProperty
443 : )
444 : {
445 3 : m_nDesktops = *reinterpret_cast<long*>(pProperty);
446 3 : XFree( pProperty );
447 3 : pProperty = NULL;
448 : // get work areas
449 6 : if( m_aWMAtoms[ NET_WORKAREA ]
450 3 : && XGetWindowProperty( m_pDisplay,
451 : m_pSalDisplay->GetRootWindow( m_pSalDisplay->GetDefaultXScreen() ),
452 : m_aWMAtoms[ NET_WORKAREA ],
453 3 : 0, 4*m_nDesktops,
454 : False,
455 : XA_CARDINAL,
456 : &aRealType,
457 : &nFormat,
458 : &nItems,
459 : &nBytesLeft,
460 : &pProperty
461 3 : ) == 0
462 6 : && nItems == 4*(unsigned)m_nDesktops
463 : )
464 : {
465 3 : m_aWMWorkAreas = ::std::vector< Rectangle > ( m_nDesktops );
466 3 : long* pValues = reinterpret_cast<long*>(pProperty);
467 15 : for( int i = 0; i < m_nDesktops; i++ )
468 : {
469 12 : Point aPoint( pValues[4*i],
470 24 : pValues[4*i+1] );
471 12 : Size aSize( pValues[4*i+2],
472 24 : pValues[4*i+3] );
473 12 : Rectangle aWorkArea( aPoint, aSize );
474 12 : m_aWMWorkAreas[i] = aWorkArea;
475 12 : if( aWorkArea != m_aWMWorkAreas[0] )
476 0 : m_bEqualWorkAreas = false;
477 : #if OSL_DEBUG_LEVEL > 1
478 : fprintf( stderr, "workarea %d: %ldx%ld+%ld+%ld\n",
479 : i,
480 : m_aWMWorkAreas[i].GetWidth(),
481 : m_aWMWorkAreas[i].GetHeight(),
482 : m_aWMWorkAreas[i].Left(),
483 : m_aWMWorkAreas[i].Top() );
484 : #endif
485 : }
486 3 : XFree( pProperty );
487 : }
488 : else
489 : {
490 : #if OSL_DEBUG_LEVEL > 1
491 : fprintf( stderr, "%ld workareas for %d desktops !\n", nItems/4, m_nDesktops );
492 : #endif
493 0 : if( pProperty )
494 : {
495 0 : XFree(pProperty);
496 0 : pProperty = NULL;
497 : }
498 : }
499 : }
500 0 : else if( pProperty )
501 : {
502 0 : XFree( pProperty );
503 0 : pProperty = NULL;
504 : }
505 : }
506 0 : else if( pProperty )
507 : {
508 0 : XFree( pProperty );
509 0 : pProperty = NULL;
510 : }
511 3 : }
512 :
513 : /*
514 : * NetWMAdaptor destructor
515 : */
516 0 : NetWMAdaptor::~NetWMAdaptor()
517 : {
518 0 : }
519 :
520 : /*
521 : * GnomeWMAdaptor constructor
522 : */
523 :
524 0 : GnomeWMAdaptor::GnomeWMAdaptor( SalDisplay* pSalDisplay ) :
525 : WMAdaptor( pSalDisplay ),
526 0 : m_bValid( false )
527 : {
528 : // currently all Gnome WMs do transient like expected
529 0 : m_bTransientBehaviour = true;
530 :
531 0 : Atom aRealType = None;
532 0 : int nFormat = 8;
533 0 : unsigned long nItems = 0;
534 0 : unsigned long nBytesLeft = 0;
535 0 : unsigned char* pProperty = NULL;
536 :
537 0 : initAtoms();
538 :
539 : // check for GnomeWM
540 0 : if( m_aWMAtoms[ WIN_SUPPORTING_WM_CHECK ] && m_aWMAtoms[ WIN_PROTOCOLS ] )
541 : {
542 0 : ::Window aWMChild = None;
543 0 : if( XGetWindowProperty( m_pDisplay,
544 : m_pSalDisplay->GetRootWindow( m_pSalDisplay->GetDefaultXScreen() ),
545 : m_aWMAtoms[ WIN_SUPPORTING_WM_CHECK ],
546 : 0, 1,
547 : False,
548 : XA_CARDINAL,
549 : &aRealType,
550 : &nFormat,
551 : &nItems,
552 : &nBytesLeft,
553 0 : &pProperty ) == 0
554 0 : && aRealType == XA_CARDINAL
555 0 : && nFormat == 32
556 0 : && nItems != 0
557 : )
558 : {
559 0 : aWMChild = *reinterpret_cast< ::Window* >(pProperty);
560 0 : XFree( pProperty );
561 0 : pProperty = NULL;
562 0 : ::Window aCheckWindow = None;
563 0 : GetGenericData()->ErrorTrapPush();
564 0 : if( XGetWindowProperty( m_pDisplay,
565 : aWMChild,
566 : m_aWMAtoms[ WIN_SUPPORTING_WM_CHECK ],
567 : 0, 1,
568 : False,
569 : XA_CARDINAL,
570 : &aRealType,
571 : &nFormat,
572 : &nItems,
573 : &nBytesLeft,
574 0 : &pProperty ) == 0
575 0 : && aRealType == XA_CARDINAL
576 0 : && nFormat == 32
577 0 : && nItems != 0 )
578 : {
579 0 : if (! GetGenericData()->ErrorTrapPop( false ) )
580 : {
581 0 : GetGenericData()->ErrorTrapPush();
582 :
583 0 : aCheckWindow = *reinterpret_cast< ::Window* >(pProperty);
584 0 : XFree( pProperty );
585 0 : pProperty = NULL;
586 0 : if( aCheckWindow == aWMChild )
587 : {
588 0 : m_bValid = true;
589 : /*
590 : * get name of WM
591 : * this is NOT part of the GNOME WM hints, but e.g. Sawfish
592 : * already supports this part of the extended WM hints
593 : */
594 0 : m_aWMAtoms[ UTF8_STRING ] = XInternAtom( m_pDisplay, "UTF8_STRING", False );
595 0 : getNetWmName();
596 : }
597 : }
598 : else
599 0 : GetGenericData()->ErrorTrapPush();
600 : }
601 0 : GetGenericData()->ErrorTrapPop();
602 : }
603 0 : else if( pProperty )
604 : {
605 0 : XFree( pProperty );
606 0 : pProperty = NULL;
607 : }
608 : }
609 0 : if( m_bValid
610 0 : && XGetWindowProperty( m_pDisplay,
611 : m_pSalDisplay->GetRootWindow( m_pSalDisplay->GetDefaultXScreen() ),
612 : m_aWMAtoms[ WIN_PROTOCOLS ],
613 : 0, 0,
614 : False,
615 : XA_ATOM,
616 : &aRealType,
617 : &nFormat,
618 : &nItems,
619 : &nBytesLeft,
620 0 : &pProperty ) == 0
621 0 : && aRealType == XA_ATOM
622 0 : && nFormat == 32
623 : )
624 : {
625 0 : if( pProperty )
626 : {
627 0 : XFree( pProperty );
628 0 : pProperty = NULL;
629 : }
630 : // collect supported protocols
631 0 : if( XGetWindowProperty( m_pDisplay,
632 : m_pSalDisplay->GetRootWindow( m_pSalDisplay->GetDefaultXScreen() ),
633 : m_aWMAtoms[ WIN_PROTOCOLS ],
634 0 : 0, nBytesLeft/4,
635 : False,
636 : XA_ATOM,
637 : &aRealType,
638 : &nFormat,
639 : &nItems,
640 : &nBytesLeft,
641 0 : &pProperty ) == 0
642 0 : && pProperty
643 : )
644 : {
645 0 : Atom* pAtoms = reinterpret_cast<Atom*>(pProperty);
646 0 : char** pAtomNames = static_cast<char**>(alloca( sizeof(char*)*nItems ));
647 0 : if( XGetAtomNames( m_pDisplay, pAtoms, nItems, pAtomNames ) )
648 : {
649 : #if OSL_DEBUG_LEVEL > 1
650 : fprintf( stderr, "supported protocols:\n" );
651 : #endif
652 0 : for( unsigned long i = 0; i < nItems; i++ )
653 : {
654 : // #i80971# protect against invalid atoms
655 0 : if( pAtomNames[i] == NULL )
656 0 : continue;
657 :
658 : WMAdaptorProtocol aSearch;
659 0 : aSearch.pProtocol = pAtomNames[i];
660 : WMAdaptorProtocol* pMatch = static_cast<WMAdaptorProtocol*>(
661 : bsearch( &aSearch,
662 : aProtocolTab,
663 : SAL_N_ELEMENTS( aProtocolTab ),
664 : sizeof( struct WMAdaptorProtocol ),
665 0 : compareProtocol ));
666 0 : if( pMatch )
667 : {
668 0 : m_aWMAtoms[ pMatch->nProtocol ] = pAtoms[ i ];
669 0 : if( pMatch->nProtocol == WIN_LAYER )
670 0 : m_bEnableAlwaysOnTopWorks = true;
671 : }
672 0 : if( strncmp( "_ICEWM_TRAY", pAtomNames[i], 11 ) == 0 )
673 : {
674 0 : m_aWMName = "IceWM";
675 0 : m_nWinGravity = NorthWestGravity;
676 0 : m_nInitWinGravity = NorthWestGravity;
677 : }
678 : #if OSL_DEBUG_LEVEL > 1
679 : fprintf( stderr, " %s%s\n", pAtomNames[i], ((pMatch) && (pMatch->nProtocol != -1)) ? "" : " (unsupported)" );
680 : #endif
681 0 : XFree( pAtomNames[i] );
682 : }
683 : }
684 0 : XFree( pProperty );
685 0 : pProperty = NULL;
686 : }
687 0 : else if( pProperty )
688 : {
689 0 : XFree( pProperty );
690 0 : pProperty = NULL;
691 : }
692 :
693 : // get number of desktops
694 0 : if( m_aWMAtoms[ WIN_WORKSPACE_COUNT ]
695 0 : && XGetWindowProperty( m_pDisplay,
696 : m_pSalDisplay->GetRootWindow( m_pSalDisplay->GetDefaultXScreen() ),
697 : m_aWMAtoms[ WIN_WORKSPACE_COUNT ],
698 : 0, 1,
699 : False,
700 : XA_CARDINAL,
701 : &aRealType,
702 : &nFormat,
703 : &nItems,
704 : &nBytesLeft,
705 0 : &pProperty ) == 0
706 0 : && pProperty
707 : )
708 : {
709 0 : m_nDesktops = *reinterpret_cast<long*>(pProperty);
710 0 : XFree( pProperty );
711 0 : pProperty = NULL;
712 : }
713 0 : else if( pProperty )
714 : {
715 0 : XFree( pProperty );
716 0 : pProperty = NULL;
717 : }
718 : }
719 0 : else if( pProperty )
720 : {
721 0 : XFree( pProperty );
722 0 : pProperty = NULL;
723 : }
724 0 : }
725 :
726 : /*
727 : * GnomeWMAdaptor destructor
728 : */
729 0 : GnomeWMAdaptor::~GnomeWMAdaptor()
730 : {
731 0 : }
732 :
733 : /*
734 : * getNetWmName()
735 : */
736 6 : bool WMAdaptor::getNetWmName()
737 : {
738 6 : Atom aRealType = None;
739 6 : int nFormat = 8;
740 6 : unsigned long nItems = 0;
741 6 : unsigned long nBytesLeft = 0;
742 6 : unsigned char* pProperty = NULL;
743 6 : bool bNetWM = false;
744 :
745 6 : if( m_aWMAtoms[ NET_SUPPORTING_WM_CHECK ] && m_aWMAtoms[ NET_WM_NAME ] )
746 : {
747 6 : ::Window aWMChild = None;
748 6 : if( XGetWindowProperty( m_pDisplay,
749 : m_pSalDisplay->GetRootWindow( m_pSalDisplay->GetDefaultXScreen() ),
750 : m_aWMAtoms[ NET_SUPPORTING_WM_CHECK ],
751 : 0, 1,
752 : False,
753 : XA_WINDOW,
754 : &aRealType,
755 : &nFormat,
756 : &nItems,
757 : &nBytesLeft,
758 6 : &pProperty ) == 0
759 6 : && aRealType == XA_WINDOW
760 6 : && nFormat == 32
761 12 : && nItems != 0
762 : )
763 : {
764 6 : aWMChild = *reinterpret_cast< ::Window* >(pProperty);
765 6 : XFree( pProperty );
766 6 : pProperty = NULL;
767 6 : ::Window aCheckWindow = None;
768 6 : GetGenericData()->ErrorTrapPush();
769 6 : if( XGetWindowProperty( m_pDisplay,
770 : aWMChild,
771 : m_aWMAtoms[ NET_SUPPORTING_WM_CHECK ],
772 : 0, 1,
773 : False,
774 : XA_WINDOW,
775 : &aRealType,
776 : &nFormat,
777 : &nItems,
778 : &nBytesLeft,
779 6 : &pProperty ) == 0
780 6 : && aRealType == XA_WINDOW
781 6 : && nFormat == 32
782 12 : && nItems != 0 )
783 : {
784 6 : if ( ! GetGenericData()->ErrorTrapPop( false ) )
785 : {
786 6 : GetGenericData()->ErrorTrapPush();
787 6 : aCheckWindow = *reinterpret_cast< ::Window* >(pProperty);
788 6 : XFree( pProperty );
789 6 : pProperty = NULL;
790 6 : if( aCheckWindow == aWMChild )
791 : {
792 6 : bNetWM = true;
793 : // get name of WM
794 6 : m_aWMAtoms[ UTF8_STRING ] = XInternAtom( m_pDisplay, "UTF8_STRING", False );
795 6 : if( XGetWindowProperty( m_pDisplay,
796 : aWMChild,
797 : m_aWMAtoms[ NET_WM_NAME ],
798 : 0, 256,
799 : False,
800 : AnyPropertyType, /* m_aWMAtoms[ UTF8_STRING ],*/
801 : &aRealType,
802 : &nFormat,
803 : &nItems,
804 : &nBytesLeft,
805 6 : &pProperty ) == 0
806 6 : && nItems != 0
807 : )
808 : {
809 6 : if (aRealType == m_aWMAtoms[ UTF8_STRING ])
810 6 : m_aWMName = OUString( reinterpret_cast<char*>(pProperty), nItems, RTL_TEXTENCODING_UTF8 );
811 0 : else if (aRealType == XA_STRING)
812 0 : m_aWMName = OUString( reinterpret_cast<char*>(pProperty), nItems, RTL_TEXTENCODING_ISO_8859_1 );
813 :
814 6 : XFree( pProperty );
815 6 : pProperty = NULL;
816 : }
817 0 : else if( pProperty )
818 : {
819 0 : XFree( pProperty );
820 0 : pProperty = NULL;
821 : }
822 :
823 : // if this is metacity, check for version to enable a legacy workaround
824 6 : if( m_aWMName == "Metacity" )
825 : {
826 0 : int nVersionMajor = 0, nVersionMinor = 0;
827 0 : Atom nVersionAtom = XInternAtom( m_pDisplay, "_METACITY_VERSION", True );
828 0 : if( nVersionAtom )
829 : {
830 0 : if( XGetWindowProperty( m_pDisplay,
831 : aWMChild,
832 : nVersionAtom,
833 : 0, 256,
834 : False,
835 : m_aWMAtoms[ UTF8_STRING ],
836 : &aRealType,
837 : &nFormat,
838 : &nItems,
839 : &nBytesLeft,
840 0 : &pProperty ) == 0
841 0 : && nItems != 0
842 : )
843 : {
844 0 : OUString aMetaVersion( reinterpret_cast<char*>(pProperty), nItems, RTL_TEXTENCODING_UTF8 );
845 0 : nVersionMajor = aMetaVersion.getToken(0, '.').toInt32();
846 0 : nVersionMinor = aMetaVersion.getToken(1, '.').toInt32();
847 : }
848 0 : if( pProperty )
849 : {
850 0 : XFree( pProperty );
851 0 : pProperty = NULL;
852 : }
853 : }
854 0 : if( nVersionMajor < 2 || (nVersionMajor == 2 && nVersionMinor < 12) )
855 0 : m_bLegacyPartialFullscreen = true;
856 : }
857 : }
858 : }
859 : else
860 : {
861 0 : if( pProperty )
862 : {
863 0 : XFree( pProperty );
864 0 : pProperty = NULL;
865 : }
866 0 : GetGenericData()->ErrorTrapPush();
867 : }
868 : }
869 :
870 6 : GetGenericData()->ErrorTrapPop();
871 : }
872 0 : else if( pProperty )
873 : {
874 0 : XFree( pProperty );
875 0 : pProperty = NULL;
876 : }
877 : }
878 6 : return bNetWM;
879 : }
880 :
881 0 : bool WMAdaptor::getWMshouldSwitchWorkspace() const
882 : {
883 0 : if( ! m_bWMshouldSwitchWorkspaceInit )
884 : {
885 0 : WMAdaptor * pWMA = const_cast<WMAdaptor*>(this);
886 :
887 0 : pWMA->m_bWMshouldSwitchWorkspace = true;
888 0 : vcl::SettingsConfigItem* pItem = vcl::SettingsConfigItem::get();
889 : OUString aSetting( pItem->getValue( OUString( "WM" ),
890 0 : OUString( "ShouldSwitchWorkspace" ) ) );
891 0 : if( aSetting.isEmpty() )
892 : {
893 0 : if( m_aWMName == "awesome" )
894 : {
895 0 : pWMA->m_bWMshouldSwitchWorkspace = false;
896 : }
897 : }
898 : else
899 0 : pWMA->m_bWMshouldSwitchWorkspace = aSetting.toBoolean();
900 0 : pWMA->m_bWMshouldSwitchWorkspaceInit = true;
901 : }
902 0 : return m_bWMshouldSwitchWorkspace;
903 : }
904 :
905 : /*
906 : * WMAdaptor::isValid()
907 : */
908 0 : bool WMAdaptor::isValid() const
909 : {
910 0 : return true;
911 : }
912 :
913 : /*
914 : * NetWMAdaptor::isValid()
915 : */
916 3 : bool NetWMAdaptor::isValid() const
917 : {
918 : // some necessary sanity checks; there are WMs out there
919 : // which implement some of the WM hints spec without
920 : // real functionality
921 : return
922 3 : m_aWMAtoms[ NET_SUPPORTED ]
923 3 : && m_aWMAtoms[ NET_SUPPORTING_WM_CHECK ]
924 3 : && m_aWMAtoms[ NET_WM_NAME ]
925 3 : && m_aWMAtoms[ NET_WM_WINDOW_TYPE_NORMAL ]
926 6 : && m_aWMAtoms[ NET_WM_WINDOW_TYPE_DIALOG ]
927 : ;
928 : }
929 :
930 : /*
931 : * GnomeWMAdaptor::isValid()
932 : */
933 0 : bool GnomeWMAdaptor::isValid() const
934 : {
935 0 : return m_bValid;
936 : }
937 :
938 : /*
939 : * WMAdaptor::initAtoms
940 : */
941 :
942 6 : void WMAdaptor::initAtoms()
943 : {
944 : // get basic atoms
945 120 : for( unsigned int i = 0; i < SAL_N_ELEMENTS( aAtomTab ); i++ )
946 114 : m_aWMAtoms[ aAtomTab[i].nProtocol ] = XInternAtom( m_pDisplay, aAtomTab[i].pProtocol, False );
947 6 : m_aWMAtoms[ NET_SUPPORTING_WM_CHECK ] = XInternAtom( m_pDisplay, "_NET_SUPPORTING_WM_CHECK", True );
948 6 : m_aWMAtoms[ NET_WM_NAME ] = XInternAtom( m_pDisplay, "_NET_WM_NAME", True );
949 6 : }
950 :
951 : /*
952 : * NetWMAdaptor::initAtoms
953 : */
954 :
955 3 : void NetWMAdaptor::initAtoms()
956 : {
957 3 : WMAdaptor::initAtoms();
958 :
959 3 : m_aWMAtoms[ NET_SUPPORTED ] = XInternAtom( m_pDisplay, "_NET_SUPPORTED", True );
960 3 : }
961 :
962 : /*
963 : * GnomeWMAdaptor::initAtoms
964 : */
965 :
966 0 : void GnomeWMAdaptor::initAtoms()
967 : {
968 0 : WMAdaptor::initAtoms();
969 :
970 0 : m_aWMAtoms[ WIN_PROTOCOLS ] = XInternAtom( m_pDisplay, "_WIN_PROTOCOLS", True );
971 0 : m_aWMAtoms[ WIN_SUPPORTING_WM_CHECK ] = XInternAtom( m_pDisplay, "_WIN_SUPPORTING_WM_CHECK", True );
972 0 : }
973 :
974 : /*
975 : * WMAdaptor::setWMName
976 : * sets WM_NAME
977 : * WM_ICON_NAME
978 : */
979 :
980 0 : void WMAdaptor::setWMName( X11SalFrame* pFrame, const OUString& rWMName ) const
981 : {
982 : OString aTitle(OUStringToOString(rWMName,
983 0 : osl_getThreadTextEncoding()));
984 :
985 0 : OString aWMLocale;
986 0 : rtl_Locale* pLocale = NULL;
987 0 : osl_getProcessLocale( &pLocale );
988 0 : if( pLocale )
989 : {
990 0 : OUString aLocaleString( LanguageTag( *pLocale).getGlibcLocaleString( OUString()));
991 0 : aWMLocale = OUStringToOString( aLocaleString, RTL_TEXTENCODING_ISO_8859_1 );
992 : }
993 : else
994 : {
995 0 : static const char* pLang = getenv( "LANG" );
996 0 : aWMLocale = pLang ? pLang : "C";
997 : }
998 :
999 : static bool bTrustXmb = true;
1000 :
1001 0 : char* pT = const_cast<char*>(aTitle.getStr());
1002 0 : XTextProperty aProp = { NULL, None, 0, 0 };
1003 0 : if( bTrustXmb )
1004 : {
1005 : XmbTextListToTextProperty( m_pDisplay,
1006 : &pT,
1007 : 1,
1008 : XStdICCTextStyle,
1009 0 : &aProp );
1010 : }
1011 :
1012 0 : unsigned char const * pData = aProp.nitems ? aProp.value : reinterpret_cast<unsigned char const *>(aTitle.getStr());
1013 0 : Atom nType = aProp.nitems ? aProp.encoding : XA_STRING;
1014 0 : int nFormat = aProp.nitems ? aProp.format : 8;
1015 0 : int nBytes = aProp.nitems ? aProp.nitems : aTitle.getLength();
1016 0 : const SystemEnvData* pEnv = pFrame->GetSystemData();
1017 : XChangeProperty( m_pDisplay,
1018 : (::Window)pEnv->aShellWindow,
1019 : XA_WM_NAME,
1020 : nType,
1021 : nFormat,
1022 : PropModeReplace,
1023 : pData,
1024 0 : nBytes );
1025 : XChangeProperty( m_pDisplay,
1026 : (::Window)pEnv->aShellWindow,
1027 : XA_WM_ICON_NAME,
1028 : nType,
1029 : nFormat,
1030 : PropModeReplace,
1031 : pData,
1032 0 : nBytes );
1033 : XChangeProperty( m_pDisplay,
1034 : (::Window)pEnv->aShellWindow,
1035 0 : m_aWMAtoms[ WM_LOCALE_NAME ],
1036 : XA_STRING,
1037 : 8,
1038 : PropModeReplace,
1039 0 : reinterpret_cast<unsigned char const *>(aWMLocale.getStr()),
1040 0 : aWMLocale.getLength() );
1041 0 : if (aProp.value != NULL)
1042 0 : XFree( aProp.value );
1043 0 : }
1044 :
1045 : /*
1046 : * NetWMAdaptor::setWMName
1047 : * sets WM_NAME
1048 : * _NET_WM_NAME
1049 : * WM_ICON_NAME
1050 : * _NET_WM_ICON_NAME
1051 : */
1052 0 : void NetWMAdaptor::setWMName( X11SalFrame* pFrame, const OUString& rWMName ) const
1053 : {
1054 0 : WMAdaptor::setWMName( pFrame, rWMName );
1055 :
1056 0 : OString aTitle(OUStringToOString(rWMName, RTL_TEXTENCODING_UTF8));
1057 0 : const SystemEnvData* pEnv = pFrame->GetSystemData();
1058 0 : if( m_aWMAtoms[ NET_WM_NAME ] )
1059 : XChangeProperty( m_pDisplay,
1060 : (::Window)pEnv->aShellWindow,
1061 0 : m_aWMAtoms[ NET_WM_NAME ],
1062 0 : m_aWMAtoms[ UTF8_STRING ],
1063 : 8,
1064 : PropModeReplace,
1065 0 : reinterpret_cast<unsigned char const *>(aTitle.getStr()),
1066 0 : aTitle.getLength() );
1067 0 : if( m_aWMAtoms[ NET_WM_ICON_NAME ] )
1068 : XChangeProperty( m_pDisplay,
1069 : (::Window)pEnv->aShellWindow,
1070 0 : m_aWMAtoms[ NET_WM_ICON_NAME ],
1071 0 : m_aWMAtoms[ UTF8_STRING ],
1072 : 8,
1073 : PropModeReplace,
1074 0 : reinterpret_cast<unsigned char const *>(aTitle.getStr()),
1075 0 : aTitle.getLength() );
1076 0 : }
1077 :
1078 : /*
1079 : * NetWMAdaptor::setNetWMState
1080 : * sets _NET_WM_STATE
1081 : */
1082 0 : void NetWMAdaptor::setNetWMState( X11SalFrame* pFrame ) const
1083 : {
1084 0 : if( m_aWMAtoms[ NET_WM_STATE ] )
1085 : {
1086 : Atom aStateAtoms[ 10 ];
1087 0 : int nStateAtoms = 0;
1088 :
1089 : // set NET_WM_STATE_MODAL
1090 0 : if( m_aWMAtoms[ NET_WM_STATE_MODAL ]
1091 0 : && pFrame->meWindowType == windowType_ModalDialogue )
1092 : {
1093 0 : aStateAtoms[ nStateAtoms++ ] = m_aWMAtoms[ NET_WM_STATE_MODAL ];
1094 : /*
1095 : * #90998# NET_WM_STATE_SKIP_TASKBAR set on a frame will
1096 : * cause kwin not to give it the focus on map request
1097 : * this seems to be a bug in kwin
1098 : * aStateAtoms[ nStateAtoms++ ] = m_aWMAtoms[ NET_WM_STATE_SKIP_TASKBAR ];
1099 : */
1100 : }
1101 0 : if( pFrame->mbMaximizedVert
1102 0 : && m_aWMAtoms[ NET_WM_STATE_MAXIMIZED_VERT ] )
1103 0 : aStateAtoms[ nStateAtoms++ ] = m_aWMAtoms[ NET_WM_STATE_MAXIMIZED_VERT ];
1104 0 : if( pFrame->mbMaximizedHorz
1105 0 : && m_aWMAtoms[ NET_WM_STATE_MAXIMIZED_HORZ ] )
1106 0 : aStateAtoms[ nStateAtoms++ ] = m_aWMAtoms[ NET_WM_STATE_MAXIMIZED_HORZ ];
1107 0 : if( pFrame->bAlwaysOnTop_ && m_aWMAtoms[ NET_WM_STATE_STAYS_ON_TOP ] )
1108 0 : aStateAtoms[ nStateAtoms++ ] = m_aWMAtoms[ NET_WM_STATE_STAYS_ON_TOP ];
1109 0 : if( pFrame->mbShaded && m_aWMAtoms[ NET_WM_STATE_SHADED ] )
1110 0 : aStateAtoms[ nStateAtoms++ ] = m_aWMAtoms[ NET_WM_STATE_SHADED ];
1111 0 : if( pFrame->mbFullScreen && m_aWMAtoms[ NET_WM_STATE_FULLSCREEN ] )
1112 0 : aStateAtoms[ nStateAtoms++ ] = m_aWMAtoms[ NET_WM_STATE_FULLSCREEN ];
1113 0 : if( pFrame->meWindowType == windowType_Utility && m_aWMAtoms[ NET_WM_STATE_SKIP_TASKBAR ] )
1114 0 : aStateAtoms[ nStateAtoms++ ] = m_aWMAtoms[ NET_WM_STATE_SKIP_TASKBAR ];
1115 :
1116 0 : if( nStateAtoms )
1117 : {
1118 : XChangeProperty( m_pDisplay,
1119 : pFrame->GetShellWindow(),
1120 0 : m_aWMAtoms[ NET_WM_STATE ],
1121 : XA_ATOM,
1122 : 32,
1123 : PropModeReplace,
1124 : reinterpret_cast<unsigned char*>(aStateAtoms),
1125 : nStateAtoms
1126 0 : );
1127 : }
1128 : else
1129 : XDeleteProperty( m_pDisplay,
1130 : pFrame->GetShellWindow(),
1131 0 : m_aWMAtoms[ NET_WM_STATE ] );
1132 0 : if( pFrame->mbMaximizedHorz
1133 0 : && pFrame->mbMaximizedVert
1134 0 : && ! ( pFrame->nStyle_ & SAL_FRAME_STYLE_SIZEABLE ) )
1135 : {
1136 : /*
1137 : * for maximizing use NorthWestGravity (including decoration)
1138 : */
1139 : XSizeHints hints;
1140 : long supplied;
1141 0 : bool bHint = false;
1142 0 : if( XGetWMNormalHints( m_pDisplay,
1143 : pFrame->GetShellWindow(),
1144 : &hints,
1145 0 : &supplied ) )
1146 : {
1147 0 : bHint = true;
1148 0 : hints.flags |= PWinGravity;
1149 0 : hints.win_gravity = NorthWestGravity;
1150 : XSetWMNormalHints( m_pDisplay,
1151 : pFrame->GetShellWindow(),
1152 0 : &hints );
1153 0 : XSync( m_pDisplay, False );
1154 : }
1155 :
1156 : // SetPosSize necessary to set width/height, min/max w/h
1157 0 : sal_Int32 nCurrent = 0;
1158 : /*
1159 : * get current desktop here if work areas have different size
1160 : * (does this happen on any platform ?)
1161 : */
1162 0 : if( ! m_bEqualWorkAreas )
1163 : {
1164 0 : nCurrent = getCurrentWorkArea();
1165 0 : if( nCurrent < 0 )
1166 0 : nCurrent = 0;
1167 : }
1168 0 : Rectangle aPosSize = m_aWMWorkAreas[nCurrent];
1169 0 : const SalFrameGeometry& rGeom( pFrame->GetUnmirroredGeometry() );
1170 0 : aPosSize = Rectangle( Point( aPosSize.Left() + rGeom.nLeftDecoration,
1171 0 : aPosSize.Top() + rGeom.nTopDecoration ),
1172 0 : Size( aPosSize.GetWidth()
1173 0 : - rGeom.nLeftDecoration
1174 0 : - rGeom.nRightDecoration,
1175 0 : aPosSize.GetHeight()
1176 0 : - rGeom.nTopDecoration
1177 0 : - rGeom.nBottomDecoration )
1178 0 : );
1179 0 : pFrame->SetPosSize( aPosSize );
1180 :
1181 : /*
1182 : * reset gravity hint to static gravity
1183 : * (this should not move window according to ICCCM)
1184 : */
1185 0 : if( bHint && pFrame->nShowState_ != SHOWSTATE_UNKNOWN )
1186 : {
1187 0 : hints.win_gravity = StaticGravity;
1188 : XSetWMNormalHints( m_pDisplay,
1189 : pFrame->GetShellWindow(),
1190 0 : &hints );
1191 : }
1192 : }
1193 : }
1194 0 : }
1195 :
1196 : /*
1197 : * GnomeWMAdaptor::setNetWMState
1198 : * sets _WIN_STATE
1199 : */
1200 0 : void GnomeWMAdaptor::setGnomeWMState( X11SalFrame* pFrame ) const
1201 : {
1202 0 : if( m_aWMAtoms[ WIN_STATE ] )
1203 : {
1204 0 : sal_uInt32 nWinWMState = 0;
1205 :
1206 0 : if( pFrame->mbMaximizedVert )
1207 0 : nWinWMState |= 1 << 2;
1208 0 : if( pFrame->mbMaximizedHorz )
1209 0 : nWinWMState |= 1 << 3;
1210 0 : if( pFrame->mbShaded )
1211 0 : nWinWMState |= 1 << 5;
1212 :
1213 : XChangeProperty( m_pDisplay,
1214 : pFrame->GetShellWindow(),
1215 0 : m_aWMAtoms[ WIN_STATE ],
1216 : XA_CARDINAL,
1217 : 32,
1218 : PropModeReplace,
1219 : reinterpret_cast<unsigned char*>(&nWinWMState),
1220 : 1
1221 0 : );
1222 0 : if( pFrame->mbMaximizedHorz
1223 0 : && pFrame->mbMaximizedVert
1224 0 : && ! ( pFrame->nStyle_ & SAL_FRAME_STYLE_SIZEABLE ) )
1225 : {
1226 : /*
1227 : * for maximizing use NorthWestGravity (including decoration)
1228 : */
1229 : XSizeHints hints;
1230 : long supplied;
1231 0 : bool bHint = false;
1232 0 : if( XGetWMNormalHints( m_pDisplay,
1233 : pFrame->GetShellWindow(),
1234 : &hints,
1235 0 : &supplied ) )
1236 : {
1237 0 : bHint = true;
1238 0 : hints.flags |= PWinGravity;
1239 0 : hints.win_gravity = NorthWestGravity;
1240 : XSetWMNormalHints( m_pDisplay,
1241 : pFrame->GetShellWindow(),
1242 0 : &hints );
1243 0 : XSync( m_pDisplay, False );
1244 : }
1245 :
1246 : // SetPosSize necessary to set width/height, min/max w/h
1247 0 : sal_Int32 nCurrent = 0;
1248 : /*
1249 : * get current desktop here if work areas have different size
1250 : * (does this happen on any platform ?)
1251 : */
1252 0 : if( ! m_bEqualWorkAreas )
1253 : {
1254 0 : nCurrent = getCurrentWorkArea();
1255 0 : if( nCurrent < 0 )
1256 0 : nCurrent = 0;
1257 : }
1258 0 : Rectangle aPosSize = m_aWMWorkAreas[nCurrent];
1259 0 : const SalFrameGeometry& rGeom( pFrame->GetUnmirroredGeometry() );
1260 0 : aPosSize = Rectangle( Point( aPosSize.Left() + rGeom.nLeftDecoration,
1261 0 : aPosSize.Top() + rGeom.nTopDecoration ),
1262 0 : Size( aPosSize.GetWidth()
1263 0 : - rGeom.nLeftDecoration
1264 0 : - rGeom.nRightDecoration,
1265 0 : aPosSize.GetHeight()
1266 0 : - rGeom.nTopDecoration
1267 0 : - rGeom.nBottomDecoration )
1268 0 : );
1269 0 : pFrame->SetPosSize( aPosSize );
1270 :
1271 : /*
1272 : * reset gravity hint to static gravity
1273 : * (this should not move window according to ICCCM)
1274 : */
1275 0 : if( bHint && pFrame->nShowState_ != SHOWSTATE_UNKNOWN )
1276 : {
1277 0 : hints.win_gravity = StaticGravity;
1278 : XSetWMNormalHints( m_pDisplay,
1279 : pFrame->GetShellWindow(),
1280 0 : &hints );
1281 : }
1282 : }
1283 : }
1284 0 : }
1285 :
1286 : /*
1287 : * WMAdaptor::setFrameDecoration
1288 : * sets _MOTIF_WM_HINTS
1289 : * WM_TRANSIENT_FOR
1290 : */
1291 :
1292 0 : void WMAdaptor::setFrameTypeAndDecoration( X11SalFrame* pFrame, WMWindowType eType, int nDecorationFlags, X11SalFrame* pReferenceFrame ) const
1293 : {
1294 0 : pFrame->meWindowType = eType;
1295 0 : pFrame->mnDecorationFlags = nDecorationFlags;
1296 :
1297 0 : if( ! pFrame->mbFullScreen )
1298 : {
1299 : // set mwm hints
1300 : struct _mwmhints {
1301 : unsigned long flags, func, deco;
1302 : long input_mode;
1303 : unsigned long status;
1304 : } aHint;
1305 :
1306 0 : aHint.flags = 15; /* flags for functions, decoration, input mode and status */
1307 0 : aHint.deco = 0;
1308 0 : aHint.func = 1L << 2;
1309 0 : aHint.status = 0;
1310 0 : aHint.input_mode = 0;
1311 :
1312 : // evaluate decoration flags
1313 0 : if( nDecorationFlags & decoration_All )
1314 0 : aHint.deco = 1, aHint.func = 1;
1315 : else
1316 : {
1317 0 : if( nDecorationFlags & decoration_Title )
1318 0 : aHint.deco |= 1L << 3;
1319 0 : if( nDecorationFlags & decoration_Border )
1320 0 : aHint.deco |= 1L << 1;
1321 0 : if( nDecorationFlags & decoration_Resize )
1322 0 : aHint.deco |= 1L << 2, aHint.func |= 1L << 1;
1323 0 : if( nDecorationFlags & decoration_MinimizeBtn )
1324 0 : aHint.deco |= 1L << 5, aHint.func |= 1L << 3;
1325 0 : if( nDecorationFlags & decoration_MaximizeBtn )
1326 0 : aHint.deco |= 1L << 6, aHint.func |= 1L << 4;
1327 0 : if( nDecorationFlags & decoration_CloseBtn )
1328 0 : aHint.deco |= 1L << 4, aHint.func |= 1L << 5;
1329 : }
1330 : // evaluate window type
1331 0 : switch( eType )
1332 : {
1333 : case windowType_ModalDialogue:
1334 0 : aHint.input_mode = 1;
1335 0 : break;
1336 : default:
1337 0 : break;
1338 : }
1339 :
1340 : // set the hint
1341 : XChangeProperty( m_pDisplay,
1342 : pFrame->GetShellWindow(),
1343 0 : m_aWMAtoms[ MOTIF_WM_HINTS ],
1344 0 : m_aWMAtoms[ MOTIF_WM_HINTS ],
1345 : 32,
1346 : PropModeReplace,
1347 : reinterpret_cast<unsigned char*>(&aHint),
1348 0 : 5 );
1349 : }
1350 :
1351 : // set transientFor hint
1352 : /* #91030# dtwm will not map a dialogue if the transient
1353 : * window is iconified. This is deemed undesirable because
1354 : * message boxes do not get mapped, so use the root as transient
1355 : * instead.
1356 : */
1357 0 : if( pReferenceFrame )
1358 : {
1359 : XSetTransientForHint( m_pDisplay,
1360 : pFrame->GetShellWindow(),
1361 : pReferenceFrame->bMapped_ ?
1362 : pReferenceFrame->GetShellWindow() :
1363 0 : m_pSalDisplay->GetRootWindow( pFrame->GetScreenNumber() )
1364 0 : );
1365 0 : if( ! pReferenceFrame->bMapped_ )
1366 0 : pFrame->mbTransientForRoot = true;
1367 : }
1368 0 : }
1369 :
1370 : /*
1371 : * NetWMAdaptor::setFrameDecoration
1372 : * sets _MOTIF_WM_HINTS
1373 : * _NET_WM_WINDOW_TYPE
1374 : * _NET_WM_STATE
1375 : * WM_TRANSIENT_FOR
1376 : */
1377 :
1378 0 : void NetWMAdaptor::setFrameTypeAndDecoration( X11SalFrame* pFrame, WMWindowType eType, int nDecorationFlags, X11SalFrame* pReferenceFrame ) const
1379 : {
1380 0 : WMAdaptor::setFrameTypeAndDecoration( pFrame, eType, nDecorationFlags, pReferenceFrame );
1381 :
1382 0 : setNetWMState( pFrame );
1383 :
1384 : // set NET_WM_WINDOW_TYPE
1385 0 : if( m_aWMAtoms[ NET_WM_WINDOW_TYPE ] )
1386 : {
1387 : Atom aWindowTypes[4];
1388 0 : int nWindowTypes = 0;
1389 0 : switch( eType )
1390 : {
1391 : case windowType_Utility:
1392 0 : aWindowTypes[nWindowTypes++] =
1393 0 : m_aWMAtoms[ NET_WM_WINDOW_TYPE_UTILITY ] ?
1394 : m_aWMAtoms[ NET_WM_WINDOW_TYPE_UTILITY ] :
1395 0 : m_aWMAtoms[ NET_WM_WINDOW_TYPE_DIALOG ];
1396 0 : break;
1397 : case windowType_ModelessDialogue:
1398 : case windowType_ModalDialogue:
1399 0 : aWindowTypes[nWindowTypes++] =
1400 0 : m_aWMAtoms[ NET_WM_WINDOW_TYPE_DIALOG ];
1401 0 : break;
1402 : case windowType_Splash:
1403 0 : aWindowTypes[nWindowTypes++] =
1404 0 : m_aWMAtoms[ NET_WM_WINDOW_TYPE_SPLASH ] ?
1405 : m_aWMAtoms[ NET_WM_WINDOW_TYPE_SPLASH ] :
1406 0 : m_aWMAtoms[ NET_WM_WINDOW_TYPE_NORMAL ];
1407 0 : break;
1408 : case windowType_Toolbar:
1409 0 : if( m_aWMAtoms[ KDE_NET_WM_WINDOW_TYPE_OVERRIDE ] )
1410 0 : aWindowTypes[nWindowTypes++] = m_aWMAtoms[ KDE_NET_WM_WINDOW_TYPE_OVERRIDE ];
1411 0 : aWindowTypes[nWindowTypes++] =
1412 0 : m_aWMAtoms[ NET_WM_WINDOW_TYPE_TOOLBAR ] ?
1413 : m_aWMAtoms[ NET_WM_WINDOW_TYPE_TOOLBAR ] :
1414 0 : m_aWMAtoms[ NET_WM_WINDOW_TYPE_NORMAL];
1415 0 : break;
1416 : case windowType_Dock:
1417 0 : aWindowTypes[nWindowTypes++] =
1418 0 : m_aWMAtoms[ NET_WM_WINDOW_TYPE_DOCK ] ?
1419 : m_aWMAtoms[ NET_WM_WINDOW_TYPE_DOCK ] :
1420 0 : m_aWMAtoms[ NET_WM_WINDOW_TYPE_NORMAL];
1421 0 : break;
1422 : default:
1423 0 : aWindowTypes[nWindowTypes++] = m_aWMAtoms[ NET_WM_WINDOW_TYPE_NORMAL ];
1424 0 : break;
1425 : }
1426 : XChangeProperty( m_pDisplay,
1427 : pFrame->GetShellWindow(),
1428 0 : m_aWMAtoms[ NET_WM_WINDOW_TYPE ],
1429 : XA_ATOM,
1430 : 32,
1431 : PropModeReplace,
1432 : reinterpret_cast<unsigned char*>(aWindowTypes),
1433 0 : nWindowTypes );
1434 : }
1435 0 : if( ( eType == windowType_ModalDialogue ||
1436 : eType == windowType_ModelessDialogue )
1437 0 : && ! pReferenceFrame )
1438 : {
1439 : XSetTransientForHint( m_pDisplay,
1440 : pFrame->GetShellWindow(),
1441 0 : m_pSalDisplay->GetRootWindow( pFrame->GetScreenNumber() ) );
1442 0 : pFrame->mbTransientForRoot = true;
1443 : }
1444 0 : }
1445 :
1446 : /*
1447 : * WMAdaptor::maximizeFrame
1448 : */
1449 :
1450 0 : void WMAdaptor::maximizeFrame( X11SalFrame* pFrame, bool bHorizontal, bool bVertical ) const
1451 : {
1452 0 : pFrame->mbMaximizedVert = bVertical;
1453 0 : pFrame->mbMaximizedHorz = bHorizontal;
1454 :
1455 0 : const SalFrameGeometry& rGeom( pFrame->GetUnmirroredGeometry() );
1456 :
1457 : // discard pending configure notifies for this frame
1458 0 : XSync( m_pDisplay, False );
1459 : XEvent aDiscard;
1460 0 : while( XCheckTypedWindowEvent( m_pDisplay,
1461 : pFrame->GetShellWindow(),
1462 : ConfigureNotify,
1463 0 : &aDiscard ) )
1464 : ;
1465 0 : while( XCheckTypedWindowEvent( m_pDisplay,
1466 : pFrame->GetWindow(),
1467 : ConfigureNotify,
1468 0 : &aDiscard ) )
1469 : ;
1470 :
1471 0 : if( bHorizontal || bVertical )
1472 : {
1473 0 : Size aScreenSize( m_pSalDisplay->GetScreenSize( pFrame->GetScreenNumber() ) );
1474 0 : Point aTL( rGeom.nLeftDecoration, rGeom.nTopDecoration );
1475 0 : if( m_pSalDisplay->IsXinerama() )
1476 : {
1477 0 : Point aMed( aTL.X() + rGeom.nWidth/2, aTL.Y() + rGeom.nHeight/2 );
1478 0 : const std::vector< Rectangle >& rScreens = m_pSalDisplay->GetXineramaScreens();
1479 0 : for( size_t i = 0; i < rScreens.size(); i++ )
1480 0 : if( rScreens[i].IsInside( aMed ) )
1481 : {
1482 0 : aTL += rScreens[i].TopLeft();
1483 0 : aScreenSize = rScreens[i].GetSize();
1484 0 : break;
1485 : }
1486 : }
1487 : Rectangle aTarget( aTL,
1488 0 : Size( aScreenSize.Width() - rGeom.nLeftDecoration - rGeom.nTopDecoration,
1489 0 : aScreenSize.Height() - rGeom.nTopDecoration - rGeom.nBottomDecoration )
1490 0 : );
1491 0 : if( ! bHorizontal )
1492 : {
1493 : aTarget.SetSize(
1494 : Size(
1495 0 : pFrame->maRestorePosSize.IsEmpty() ?
1496 0 : rGeom.nWidth : pFrame->maRestorePosSize.GetWidth(),
1497 : aTarget.GetHeight()
1498 : )
1499 0 : );
1500 0 : aTarget.Left() =
1501 0 : pFrame->maRestorePosSize.IsEmpty() ?
1502 0 : rGeom.nX : pFrame->maRestorePosSize.Left();
1503 : }
1504 0 : else if( ! bVertical )
1505 : {
1506 : aTarget.SetSize(
1507 : Size(
1508 : aTarget.GetWidth(),
1509 0 : pFrame->maRestorePosSize.IsEmpty() ?
1510 0 : rGeom.nHeight : pFrame->maRestorePosSize.GetHeight()
1511 : )
1512 0 : );
1513 0 : aTarget.Top() =
1514 0 : pFrame->maRestorePosSize.IsEmpty() ?
1515 0 : rGeom.nY : pFrame->maRestorePosSize.Top();
1516 : }
1517 :
1518 0 : Rectangle aRestore( Point( rGeom.nX, rGeom.nY ), Size( rGeom.nWidth, rGeom.nHeight ) );
1519 0 : if( pFrame->bMapped_ )
1520 : {
1521 : XSetInputFocus( m_pDisplay,
1522 : pFrame->GetShellWindow(),
1523 : RevertToNone,
1524 : CurrentTime
1525 0 : );
1526 : }
1527 :
1528 0 : if( pFrame->maRestorePosSize.IsEmpty() )
1529 0 : pFrame->maRestorePosSize = aRestore;
1530 :
1531 0 : pFrame->SetPosSize( aTarget );
1532 0 : pFrame->nWidth_ = aTarget.GetWidth();
1533 0 : pFrame->nHeight_ = aTarget.GetHeight();
1534 : XRaiseWindow( m_pDisplay,
1535 : pFrame->GetShellWindow()
1536 0 : );
1537 0 : if( pFrame->GetStackingWindow() )
1538 : XRaiseWindow( m_pDisplay,
1539 : pFrame->GetStackingWindow()
1540 0 : );
1541 :
1542 : }
1543 : else
1544 : {
1545 0 : pFrame->SetPosSize( pFrame->maRestorePosSize );
1546 0 : pFrame->maRestorePosSize = Rectangle();
1547 0 : pFrame->nWidth_ = rGeom.nWidth;
1548 0 : pFrame->nHeight_ = rGeom.nHeight;
1549 : }
1550 0 : }
1551 :
1552 : /*
1553 : * NetWMAdaptor::maximizeFrame
1554 : * changes _NET_WM_STATE by sending a client message
1555 : */
1556 :
1557 0 : void NetWMAdaptor::maximizeFrame( X11SalFrame* pFrame, bool bHorizontal, bool bVertical ) const
1558 : {
1559 0 : pFrame->mbMaximizedVert = bVertical;
1560 0 : pFrame->mbMaximizedHorz = bHorizontal;
1561 :
1562 0 : if( m_aWMAtoms[ NET_WM_STATE ]
1563 0 : && m_aWMAtoms[ NET_WM_STATE_MAXIMIZED_VERT ]
1564 0 : && m_aWMAtoms[ NET_WM_STATE_MAXIMIZED_HORZ ]
1565 0 : && ( pFrame->nStyle_ & ~SAL_FRAME_STYLE_DEFAULT )
1566 : )
1567 : {
1568 0 : if( pFrame->bMapped_ )
1569 : {
1570 : // window already mapped, send WM a message
1571 : XEvent aEvent;
1572 0 : aEvent.type = ClientMessage;
1573 0 : aEvent.xclient.display = m_pDisplay;
1574 0 : aEvent.xclient.window = pFrame->GetShellWindow();
1575 0 : aEvent.xclient.message_type = m_aWMAtoms[ NET_WM_STATE ];
1576 0 : aEvent.xclient.format = 32;
1577 0 : aEvent.xclient.data.l[0] = bHorizontal ? 1 : 0;
1578 0 : aEvent.xclient.data.l[1] = m_aWMAtoms[ NET_WM_STATE_MAXIMIZED_HORZ ];
1579 0 : aEvent.xclient.data.l[2] = bHorizontal == bVertical ? m_aWMAtoms[ NET_WM_STATE_MAXIMIZED_VERT ] : 0;
1580 0 : aEvent.xclient.data.l[3] = 0;
1581 0 : aEvent.xclient.data.l[4] = 0;
1582 : XSendEvent( m_pDisplay,
1583 : m_pSalDisplay->GetRootWindow( pFrame->GetScreenNumber() ),
1584 : False,
1585 : SubstructureNotifyMask | SubstructureRedirectMask,
1586 : &aEvent
1587 0 : );
1588 0 : if( bHorizontal != bVertical )
1589 : {
1590 0 : aEvent.xclient.data.l[0]= bVertical ? 1 : 0;
1591 0 : aEvent.xclient.data.l[1]= m_aWMAtoms[ NET_WM_STATE_MAXIMIZED_VERT ];
1592 0 : aEvent.xclient.data.l[2]= 0;
1593 : XSendEvent( m_pDisplay,
1594 : m_pSalDisplay->GetRootWindow( pFrame->GetScreenNumber() ),
1595 : False,
1596 : SubstructureNotifyMask | SubstructureRedirectMask,
1597 : &aEvent
1598 0 : );
1599 : }
1600 : }
1601 : else
1602 : {
1603 : // window not mapped yet, set _NET_WM_STATE directly
1604 0 : setNetWMState( pFrame );
1605 : }
1606 0 : if( !bHorizontal && !bVertical )
1607 0 : pFrame->maRestorePosSize = Rectangle();
1608 0 : else if( pFrame->maRestorePosSize.IsEmpty() )
1609 : {
1610 0 : const SalFrameGeometry& rGeom( pFrame->GetUnmirroredGeometry() );
1611 : pFrame->maRestorePosSize =
1612 0 : Rectangle( Point( rGeom.nX, rGeom.nY ), Size( rGeom.nWidth, rGeom.nHeight ) );
1613 0 : }
1614 : }
1615 : else
1616 0 : WMAdaptor::maximizeFrame( pFrame, bHorizontal, bVertical );
1617 0 : }
1618 :
1619 : /*
1620 : * GnomeWMAdaptor::maximizeFrame
1621 : * changes _WIN_STATE by sending a client message
1622 : */
1623 :
1624 0 : void GnomeWMAdaptor::maximizeFrame( X11SalFrame* pFrame, bool bHorizontal, bool bVertical ) const
1625 : {
1626 0 : pFrame->mbMaximizedVert = bVertical;
1627 0 : pFrame->mbMaximizedHorz = bHorizontal;
1628 :
1629 0 : if( m_aWMAtoms[ WIN_STATE ]
1630 0 : && ( pFrame->nStyle_ & ~SAL_FRAME_STYLE_DEFAULT )
1631 : )
1632 : {
1633 0 : if( pFrame->bMapped_ )
1634 : {
1635 : // window already mapped, send WM a message
1636 : XEvent aEvent;
1637 0 : aEvent.type = ClientMessage;
1638 0 : aEvent.xclient.display = m_pDisplay;
1639 0 : aEvent.xclient.window = pFrame->GetShellWindow();
1640 0 : aEvent.xclient.message_type = m_aWMAtoms[ WIN_STATE ];
1641 0 : aEvent.xclient.format = 32;
1642 0 : aEvent.xclient.data.l[0] = (1<<2)|(1<<3);
1643 : aEvent.xclient.data.l[1] =
1644 : (bVertical ? (1<<2) : 0)
1645 0 : | (bHorizontal ? (1<<3) : 0);
1646 0 : aEvent.xclient.data.l[2] = 0;
1647 0 : aEvent.xclient.data.l[3] = 0;
1648 0 : aEvent.xclient.data.l[4] = 0;
1649 : XSendEvent( m_pDisplay,
1650 : m_pSalDisplay->GetRootWindow( pFrame->GetScreenNumber() ),
1651 : False,
1652 : SubstructureNotifyMask,
1653 : &aEvent
1654 0 : );
1655 : }
1656 : else
1657 : // window not mapped yet, set _WIN_STATE directly
1658 0 : setGnomeWMState( pFrame );
1659 :
1660 0 : if( !bHorizontal && !bVertical )
1661 0 : pFrame->maRestorePosSize = Rectangle();
1662 0 : else if( pFrame->maRestorePosSize.IsEmpty() )
1663 : {
1664 0 : const SalFrameGeometry& rGeom( pFrame->GetUnmirroredGeometry() );
1665 : pFrame->maRestorePosSize =
1666 0 : Rectangle( Point( rGeom.nX, rGeom.nY ), Size( rGeom.nWidth, rGeom.nHeight ) );
1667 0 : }
1668 : }
1669 : else
1670 0 : WMAdaptor::maximizeFrame( pFrame, bHorizontal, bVertical );
1671 0 : }
1672 :
1673 : /*
1674 : * WMAdaptor::enableAlwaysOnTop
1675 : */
1676 0 : void WMAdaptor::enableAlwaysOnTop( X11SalFrame*, bool /*bEnable*/ ) const
1677 : {
1678 0 : }
1679 :
1680 : /*
1681 : * NetWMAdaptor::enableAlwaysOnTop
1682 : */
1683 0 : void NetWMAdaptor::enableAlwaysOnTop( X11SalFrame* pFrame, bool bEnable ) const
1684 : {
1685 0 : pFrame->bAlwaysOnTop_ = bEnable;
1686 0 : if( m_aWMAtoms[ NET_WM_STATE_STAYS_ON_TOP ] )
1687 : {
1688 0 : if( pFrame->bMapped_ )
1689 : {
1690 : // window already mapped, send WM a message
1691 : XEvent aEvent;
1692 0 : aEvent.type = ClientMessage;
1693 0 : aEvent.xclient.display = m_pDisplay;
1694 0 : aEvent.xclient.window = pFrame->GetShellWindow();
1695 0 : aEvent.xclient.message_type = m_aWMAtoms[ NET_WM_STATE ];
1696 0 : aEvent.xclient.format = 32;
1697 0 : aEvent.xclient.data.l[0] = bEnable ? 1 : 0;
1698 0 : aEvent.xclient.data.l[1] = m_aWMAtoms[ NET_WM_STATE_STAYS_ON_TOP ];
1699 0 : aEvent.xclient.data.l[2] = 0;
1700 0 : aEvent.xclient.data.l[3] = 0;
1701 0 : aEvent.xclient.data.l[4] = 0;
1702 : XSendEvent( m_pDisplay,
1703 : m_pSalDisplay->GetRootWindow( pFrame->GetScreenNumber() ),
1704 : False,
1705 : SubstructureNotifyMask | SubstructureRedirectMask,
1706 : &aEvent
1707 0 : );
1708 : }
1709 : else
1710 0 : setNetWMState( pFrame );
1711 : }
1712 0 : }
1713 :
1714 : /*
1715 : * GnomeWMAdaptor::enableAlwaysOnTop
1716 : */
1717 0 : void GnomeWMAdaptor::enableAlwaysOnTop( X11SalFrame* pFrame, bool bEnable ) const
1718 : {
1719 0 : pFrame->bAlwaysOnTop_ = bEnable;
1720 0 : if( m_aWMAtoms[ WIN_LAYER ] )
1721 : {
1722 0 : if( pFrame->bMapped_ )
1723 : {
1724 : // window already mapped, send WM a message
1725 : XEvent aEvent;
1726 0 : aEvent.type = ClientMessage;
1727 0 : aEvent.xclient.display = m_pDisplay;
1728 0 : aEvent.xclient.window = pFrame->GetShellWindow();
1729 0 : aEvent.xclient.message_type = m_aWMAtoms[ WIN_LAYER ];
1730 0 : aEvent.xclient.format = 32;
1731 0 : aEvent.xclient.data.l[0] = bEnable ? 6 : 4;
1732 0 : aEvent.xclient.data.l[1] = 0;
1733 0 : aEvent.xclient.data.l[2] = 0;
1734 0 : aEvent.xclient.data.l[3] = 0;
1735 0 : aEvent.xclient.data.l[4] = 0;
1736 : XSendEvent( m_pDisplay,
1737 : m_pSalDisplay->GetRootWindow( pFrame->GetScreenNumber() ),
1738 : False,
1739 : SubstructureNotifyMask | SubstructureRedirectMask,
1740 : &aEvent
1741 0 : );
1742 : }
1743 : else
1744 : {
1745 0 : sal_uInt32 nNewLayer = bEnable ? 6 : 4;
1746 : XChangeProperty( m_pDisplay,
1747 : pFrame->GetShellWindow(),
1748 0 : m_aWMAtoms[ WIN_LAYER ],
1749 : XA_CARDINAL,
1750 : 32,
1751 : PropModeReplace,
1752 : reinterpret_cast<unsigned char*>(&nNewLayer),
1753 : 1
1754 0 : );
1755 : }
1756 : }
1757 0 : }
1758 :
1759 : /*
1760 : * WMAdaptor::changeReferenceFrame
1761 : */
1762 0 : void WMAdaptor::changeReferenceFrame( X11SalFrame* pFrame, X11SalFrame* pReferenceFrame ) const
1763 : {
1764 0 : if( ! ( pFrame->nStyle_ & SAL_FRAME_STYLE_PLUG )
1765 0 : && ! pFrame->IsOverrideRedirect()
1766 0 : && ! pFrame->IsFloatGrabWindow()
1767 : )
1768 : {
1769 0 : ::Window aTransient = pFrame->pDisplay_->GetRootWindow( pFrame->GetScreenNumber() );
1770 0 : pFrame->mbTransientForRoot = true;
1771 0 : if( pReferenceFrame )
1772 : {
1773 0 : aTransient = pReferenceFrame->GetShellWindow();
1774 0 : pFrame->mbTransientForRoot = false;
1775 : }
1776 : XSetTransientForHint( m_pDisplay,
1777 : pFrame->GetShellWindow(),
1778 0 : aTransient );
1779 : }
1780 0 : }
1781 :
1782 : /*
1783 : * WMAdaptor::handlePropertyNotify
1784 : */
1785 0 : int WMAdaptor::handlePropertyNotify( X11SalFrame*, XPropertyEvent* ) const
1786 : {
1787 0 : return 0;
1788 : }
1789 :
1790 : /*
1791 : * NetWMAdaptor::handlePropertyNotify
1792 : */
1793 0 : int NetWMAdaptor::handlePropertyNotify( X11SalFrame* pFrame, XPropertyEvent* pEvent ) const
1794 : {
1795 0 : int nHandled = 1;
1796 0 : if( pEvent->atom == m_aWMAtoms[ NET_WM_STATE ] )
1797 : {
1798 0 : pFrame->mbMaximizedHorz = pFrame->mbMaximizedVert = false;
1799 0 : pFrame->mbShaded = false;
1800 :
1801 0 : if( pEvent->state == PropertyNewValue )
1802 : {
1803 : Atom nType, *pStates;
1804 : int nFormat;
1805 : unsigned long nItems, nBytesLeft;
1806 0 : unsigned char* pData = NULL;
1807 0 : long nOffset = 0;
1808 0 : do
1809 : {
1810 : XGetWindowProperty( m_pDisplay,
1811 : pEvent->window,
1812 0 : m_aWMAtoms[ NET_WM_STATE ],
1813 : nOffset, 64,
1814 : False,
1815 : XA_ATOM,
1816 : &nType,
1817 : &nFormat,
1818 : &nItems, &nBytesLeft,
1819 0 : &pData );
1820 0 : if( pData )
1821 : {
1822 0 : if( nType == XA_ATOM && nFormat == 32 && nItems > 0 )
1823 : {
1824 0 : pStates = reinterpret_cast<Atom*>(pData);
1825 0 : for( unsigned long i = 0; i < nItems; i++ )
1826 : {
1827 0 : if( pStates[i] == m_aWMAtoms[ NET_WM_STATE_MAXIMIZED_VERT ] && m_aWMAtoms[ NET_WM_STATE_MAXIMIZED_VERT ] )
1828 0 : pFrame->mbMaximizedVert = true;
1829 0 : else if( pStates[i] == m_aWMAtoms[ NET_WM_STATE_MAXIMIZED_HORZ ] && m_aWMAtoms[ NET_WM_STATE_MAXIMIZED_HORZ ] )
1830 0 : pFrame->mbMaximizedHorz = true;
1831 0 : else if( pStates[i] == m_aWMAtoms[ NET_WM_STATE_SHADED ] && m_aWMAtoms[ NET_WM_STATE_SHADED ] )
1832 0 : pFrame->mbShaded = true;
1833 : }
1834 : }
1835 0 : XFree( pData );
1836 0 : pData = NULL;
1837 0 : nOffset += nItems * nFormat / 32;
1838 : }
1839 : else
1840 0 : break;
1841 0 : } while( nBytesLeft > 0 );
1842 : }
1843 :
1844 0 : if( ! (pFrame->mbMaximizedHorz || pFrame->mbMaximizedVert ) )
1845 0 : pFrame->maRestorePosSize = Rectangle();
1846 : else
1847 : {
1848 0 : const SalFrameGeometry& rGeom = pFrame->GetUnmirroredGeometry();
1849 : // the current geometry may already be changed by the corresponding
1850 : // ConfigureNotify, but this cannot be helped
1851 : pFrame->maRestorePosSize =
1852 : Rectangle( Point( rGeom.nX, rGeom.nY ),
1853 0 : Size( rGeom.nWidth, rGeom.nHeight ) );
1854 : }
1855 : }
1856 0 : else if( pEvent->atom == m_aWMAtoms[ NET_WM_DESKTOP ] )
1857 : {
1858 0 : pFrame->m_nWorkArea = getWindowWorkArea( pFrame->GetShellWindow() );
1859 : }
1860 : else
1861 0 : nHandled = 0;
1862 :
1863 0 : return nHandled;
1864 : }
1865 :
1866 : /*
1867 : * GnomeWMAdaptor::handlePropertyNotify
1868 : */
1869 0 : int GnomeWMAdaptor::handlePropertyNotify( X11SalFrame* pFrame, XPropertyEvent* pEvent ) const
1870 : {
1871 0 : int nHandled = 1;
1872 0 : if( pEvent->atom == m_aWMAtoms[ WIN_STATE ] )
1873 : {
1874 0 : pFrame->mbMaximizedHorz = pFrame->mbMaximizedVert = false;
1875 0 : pFrame->mbShaded = false;
1876 :
1877 0 : if( pEvent->state == PropertyNewValue )
1878 : {
1879 : Atom nType;
1880 0 : int nFormat = 0;
1881 0 : unsigned long nItems = 0;
1882 0 : unsigned long nBytesLeft = 0;
1883 0 : unsigned char* pData = 0;
1884 : XGetWindowProperty( m_pDisplay,
1885 : pEvent->window,
1886 0 : m_aWMAtoms[ WIN_STATE ],
1887 : 0, 1,
1888 : False,
1889 : XA_CARDINAL,
1890 : &nType,
1891 : &nFormat,
1892 : &nItems, &nBytesLeft,
1893 0 : &pData );
1894 0 : if( pData )
1895 : {
1896 0 : if( nType == XA_CARDINAL && nFormat == 32 && nItems == 1 )
1897 : {
1898 0 : sal_uInt32 nWinState = *reinterpret_cast<sal_uInt32*>(pData);
1899 0 : if( nWinState & (1<<2) )
1900 0 : pFrame->mbMaximizedVert = true;
1901 0 : if( nWinState & (1<<3) )
1902 0 : pFrame->mbMaximizedHorz = true;
1903 0 : if( nWinState & (1<<5) )
1904 0 : pFrame->mbShaded = true;
1905 : }
1906 0 : XFree( pData );
1907 : }
1908 : }
1909 :
1910 0 : if( ! (pFrame->mbMaximizedHorz || pFrame->mbMaximizedVert ) )
1911 0 : pFrame->maRestorePosSize = Rectangle();
1912 : else
1913 : {
1914 0 : const SalFrameGeometry& rGeom = pFrame->GetUnmirroredGeometry();
1915 : // the current geometry may already be changed by the corresponding
1916 : // ConfigureNotify, but this cannot be helped
1917 : pFrame->maRestorePosSize =
1918 : Rectangle( Point( rGeom.nX, rGeom.nY ),
1919 0 : Size( rGeom.nWidth, rGeom.nHeight ) );
1920 : }
1921 : }
1922 0 : else if( pEvent->atom == m_aWMAtoms[ NET_WM_DESKTOP ] )
1923 : {
1924 0 : pFrame->m_nWorkArea = getWindowWorkArea( pFrame->GetShellWindow() );
1925 : }
1926 : else
1927 0 : nHandled = 0;
1928 :
1929 0 : return nHandled;
1930 : }
1931 :
1932 : /*
1933 : * WMAdaptor::shade
1934 : */
1935 0 : void WMAdaptor::shade( X11SalFrame*, bool /*bToShaded*/ ) const
1936 : {
1937 0 : }
1938 :
1939 : /*
1940 : * NetWMAdaptor::shade
1941 : */
1942 0 : void NetWMAdaptor::shade( X11SalFrame* pFrame, bool bToShaded ) const
1943 : {
1944 0 : if( m_aWMAtoms[ NET_WM_STATE ]
1945 0 : && m_aWMAtoms[ NET_WM_STATE_SHADED ]
1946 0 : && ( pFrame->nStyle_ & ~SAL_FRAME_STYLE_DEFAULT )
1947 : )
1948 : {
1949 0 : pFrame->mbShaded = bToShaded;
1950 0 : if( pFrame->bMapped_ )
1951 : {
1952 : // window already mapped, send WM a message
1953 : XEvent aEvent;
1954 0 : aEvent.type = ClientMessage;
1955 0 : aEvent.xclient.display = m_pDisplay;
1956 0 : aEvent.xclient.window = pFrame->GetShellWindow();
1957 0 : aEvent.xclient.message_type = m_aWMAtoms[ NET_WM_STATE ];
1958 0 : aEvent.xclient.format = 32;
1959 0 : aEvent.xclient.data.l[0] = bToShaded ? 1 : 0;
1960 0 : aEvent.xclient.data.l[1] = m_aWMAtoms[ NET_WM_STATE_SHADED ];
1961 0 : aEvent.xclient.data.l[2] = 0;
1962 0 : aEvent.xclient.data.l[3] = 0;
1963 0 : aEvent.xclient.data.l[4] = 0;
1964 : XSendEvent( m_pDisplay,
1965 : m_pSalDisplay->GetRootWindow( pFrame->GetScreenNumber() ),
1966 : False,
1967 : SubstructureNotifyMask | SubstructureRedirectMask,
1968 : &aEvent
1969 0 : );
1970 : }
1971 : else
1972 : {
1973 : // window not mapped yet, set _NET_WM_STATE directly
1974 0 : setNetWMState( pFrame );
1975 : }
1976 : }
1977 0 : }
1978 :
1979 : /*
1980 : * GnomeWMAdaptor::shade
1981 : */
1982 0 : void GnomeWMAdaptor::shade( X11SalFrame* pFrame, bool bToShaded ) const
1983 : {
1984 0 : if( m_aWMAtoms[ WIN_STATE ] )
1985 : {
1986 0 : pFrame->mbShaded = bToShaded;
1987 0 : if( pFrame->bMapped_ )
1988 : {
1989 : // window already mapped, send WM a message
1990 : XEvent aEvent;
1991 0 : aEvent.type = ClientMessage;
1992 0 : aEvent.xclient.display = m_pDisplay;
1993 0 : aEvent.xclient.window = pFrame->GetShellWindow();
1994 0 : aEvent.xclient.message_type = m_aWMAtoms[ WIN_STATE ];
1995 0 : aEvent.xclient.format = 32;
1996 0 : aEvent.xclient.data.l[0] = (1<<5);
1997 0 : aEvent.xclient.data.l[1] = bToShaded ? (1<<5) : 0;
1998 0 : aEvent.xclient.data.l[2] = 0;
1999 0 : aEvent.xclient.data.l[3] = 0;
2000 0 : aEvent.xclient.data.l[4] = 0;
2001 : XSendEvent( m_pDisplay,
2002 : m_pSalDisplay->GetRootWindow( pFrame->GetScreenNumber() ),
2003 : False,
2004 : SubstructureNotifyMask | SubstructureRedirectMask,
2005 : &aEvent
2006 0 : );
2007 : }
2008 : else
2009 0 : setGnomeWMState( pFrame );
2010 : }
2011 0 : }
2012 :
2013 : /*
2014 : * WMAdaptor::showFullScreen
2015 : */
2016 0 : void WMAdaptor::showFullScreen( X11SalFrame* pFrame, bool bFullScreen ) const
2017 : {
2018 0 : pFrame->mbFullScreen = bFullScreen;
2019 0 : maximizeFrame( pFrame, bFullScreen, bFullScreen );
2020 0 : }
2021 :
2022 : /*
2023 : * NetWMAdaptor::showFullScreen
2024 : */
2025 0 : void NetWMAdaptor::showFullScreen( X11SalFrame* pFrame, bool bFullScreen ) const
2026 : {
2027 0 : if( m_aWMAtoms[ NET_WM_STATE_FULLSCREEN ] )
2028 : {
2029 0 : pFrame->mbFullScreen = bFullScreen;
2030 0 : if( bFullScreen )
2031 : {
2032 0 : if( m_aWMAtoms[ MOTIF_WM_HINTS ] )
2033 : {
2034 : XDeleteProperty( m_pDisplay,
2035 : pFrame->GetShellWindow(),
2036 0 : m_aWMAtoms[ MOTIF_WM_HINTS ] );
2037 : }
2038 : }
2039 0 : if( pFrame->bMapped_ )
2040 : {
2041 : // window already mapped, send WM a message
2042 : XEvent aEvent;
2043 0 : aEvent.type = ClientMessage;
2044 0 : aEvent.xclient.display = m_pDisplay;
2045 0 : aEvent.xclient.window = pFrame->GetShellWindow();
2046 0 : aEvent.xclient.message_type = m_aWMAtoms[ NET_WM_STATE ];
2047 0 : aEvent.xclient.format = 32;
2048 0 : aEvent.xclient.data.l[0] = bFullScreen ? 1 : 0;
2049 0 : aEvent.xclient.data.l[1] = m_aWMAtoms[ NET_WM_STATE_FULLSCREEN ];
2050 0 : aEvent.xclient.data.l[2] = 0;
2051 0 : aEvent.xclient.data.l[3] = 0;
2052 0 : aEvent.xclient.data.l[4] = 0;
2053 : XSendEvent( m_pDisplay,
2054 : m_pSalDisplay->GetRootWindow( pFrame->GetScreenNumber() ),
2055 : False,
2056 : SubstructureNotifyMask | SubstructureRedirectMask,
2057 : &aEvent
2058 0 : );
2059 : }
2060 : else
2061 : {
2062 : // window not mapped yet, set _NET_WM_STATE directly
2063 0 : setNetWMState( pFrame );
2064 : }
2065 : // #i42750# guess size before resize event shows up
2066 0 : if( bFullScreen )
2067 : {
2068 0 : if( m_pSalDisplay->IsXinerama() )
2069 : {
2070 : ::Window aRoot, aChild;
2071 0 : int root_x = 0, root_y = 0, lx, ly;
2072 : unsigned int mask;
2073 : XQueryPointer( m_pDisplay,
2074 : m_pSalDisplay->GetRootWindow( pFrame->GetScreenNumber() ),
2075 : &aRoot, &aChild,
2076 0 : &root_x, &root_y, &lx, &ly, &mask );
2077 0 : const std::vector< Rectangle >& rScreens = m_pSalDisplay->GetXineramaScreens();
2078 0 : Point aMousePoint( root_x, root_y );
2079 0 : for( size_t i = 0; i < rScreens.size(); i++ )
2080 : {
2081 0 : if( rScreens[i].IsInside( aMousePoint ) )
2082 : {
2083 0 : pFrame->maGeometry.nX = rScreens[i].Left();
2084 0 : pFrame->maGeometry.nY = rScreens[i].Top();
2085 0 : pFrame->maGeometry.nWidth = rScreens[i].GetWidth();
2086 0 : pFrame->maGeometry.nHeight = rScreens[i].GetHeight();
2087 0 : break;
2088 : }
2089 : }
2090 : }
2091 : else
2092 : {
2093 0 : Size aSize = m_pSalDisplay->GetScreenSize( pFrame->GetScreenNumber() );
2094 0 : pFrame->maGeometry.nX = 0;
2095 0 : pFrame->maGeometry.nY = 0;
2096 0 : pFrame->maGeometry.nWidth = aSize.Width();
2097 0 : pFrame->maGeometry.nHeight = aSize.Height();
2098 : }
2099 0 : pFrame->CallCallback( SALEVENT_MOVERESIZE, NULL );
2100 : }
2101 : }
2102 0 : else WMAdaptor::showFullScreen( pFrame, bFullScreen );
2103 0 : }
2104 :
2105 : /*
2106 : * WMAdaptor::getCurrentWorkArea
2107 : */
2108 : // FIXME: multiscreen case
2109 16 : int WMAdaptor::getCurrentWorkArea() const
2110 : {
2111 16 : int nCurrent = -1;
2112 16 : if( m_aWMAtoms[ NET_CURRENT_DESKTOP ] )
2113 : {
2114 16 : Atom aRealType = None;
2115 16 : int nFormat = 8;
2116 16 : unsigned long nItems = 0;
2117 16 : unsigned long nBytesLeft = 0;
2118 16 : unsigned char* pProperty = NULL;
2119 16 : if( XGetWindowProperty( m_pDisplay,
2120 : m_pSalDisplay->GetRootWindow( m_pSalDisplay->GetDefaultXScreen() ),
2121 16 : m_aWMAtoms[ NET_CURRENT_DESKTOP ],
2122 : 0, 1,
2123 : False,
2124 : XA_CARDINAL,
2125 : &aRealType,
2126 : &nFormat,
2127 : &nItems,
2128 : &nBytesLeft,
2129 16 : &pProperty ) == 0
2130 16 : && pProperty
2131 : )
2132 : {
2133 16 : nCurrent = int(*reinterpret_cast<sal_Int32*>(pProperty));
2134 16 : XFree( pProperty );
2135 : }
2136 0 : else if( pProperty )
2137 : {
2138 0 : XFree( pProperty );
2139 0 : pProperty = NULL;
2140 : }
2141 : }
2142 16 : return nCurrent;
2143 : }
2144 :
2145 : /*
2146 : * WMAdaptor::getWindowWorkArea
2147 : */
2148 0 : int WMAdaptor::getWindowWorkArea( ::Window aWindow ) const
2149 : {
2150 0 : int nCurrent = -1;
2151 0 : if( m_aWMAtoms[ NET_WM_DESKTOP ] )
2152 : {
2153 0 : Atom aRealType = None;
2154 0 : int nFormat = 8;
2155 0 : unsigned long nItems = 0;
2156 0 : unsigned long nBytesLeft = 0;
2157 0 : unsigned char* pProperty = NULL;
2158 0 : if( XGetWindowProperty( m_pDisplay,
2159 : aWindow,
2160 0 : m_aWMAtoms[ NET_WM_DESKTOP ],
2161 : 0, 1,
2162 : False,
2163 : XA_CARDINAL,
2164 : &aRealType,
2165 : &nFormat,
2166 : &nItems,
2167 : &nBytesLeft,
2168 0 : &pProperty ) == 0
2169 0 : && pProperty
2170 : )
2171 : {
2172 0 : nCurrent = int(*reinterpret_cast<sal_Int32*>(pProperty));
2173 0 : XFree( pProperty );
2174 : }
2175 0 : else if( pProperty )
2176 : {
2177 0 : XFree( pProperty );
2178 0 : pProperty = NULL;
2179 : }
2180 : }
2181 0 : return nCurrent;
2182 : }
2183 :
2184 : /*
2185 : * WMAdaptor::getCurrentWorkArea
2186 : */
2187 : // fixme: multi screen case
2188 0 : void WMAdaptor::switchToWorkArea( int nWorkArea, bool bConsiderWM ) const
2189 : {
2190 0 : if( bConsiderWM && ! getWMshouldSwitchWorkspace() )
2191 0 : return;
2192 :
2193 0 : if( m_aWMAtoms[ NET_CURRENT_DESKTOP ] )
2194 : {
2195 : XEvent aEvent;
2196 0 : aEvent.type = ClientMessage;
2197 0 : aEvent.xclient.display = m_pDisplay;
2198 0 : aEvent.xclient.window = m_pSalDisplay->GetRootWindow( m_pSalDisplay->GetDefaultXScreen() );
2199 0 : aEvent.xclient.message_type = m_aWMAtoms[ NET_CURRENT_DESKTOP ];
2200 0 : aEvent.xclient.format = 32;
2201 0 : aEvent.xclient.data.l[0] = nWorkArea;
2202 0 : aEvent.xclient.data.l[1] = 0;
2203 0 : aEvent.xclient.data.l[2] = 0;
2204 0 : aEvent.xclient.data.l[3] = 0;
2205 0 : aEvent.xclient.data.l[4] = 0;
2206 : XSendEvent( m_pDisplay,
2207 : m_pSalDisplay->GetRootWindow( m_pSalDisplay->GetDefaultXScreen() ),
2208 : False,
2209 : SubstructureNotifyMask | SubstructureRedirectMask,
2210 : &aEvent
2211 0 : );
2212 : }
2213 : }
2214 :
2215 : /*
2216 : * WMAdaptor::frameIsMapping
2217 : */
2218 0 : void WMAdaptor::frameIsMapping( X11SalFrame* ) const
2219 : {
2220 0 : }
2221 :
2222 : /*
2223 : * NetWMAdaptor::frameIsMapping
2224 : */
2225 0 : void NetWMAdaptor::frameIsMapping( X11SalFrame* pFrame ) const
2226 : {
2227 0 : setNetWMState( pFrame );
2228 0 : }
2229 :
2230 : /*
2231 : * WMAdaptor::setFrameStruts
2232 : */
2233 0 : void WMAdaptor::setFrameStruts( X11SalFrame*,
2234 : int, int, int, int,
2235 : int, int, int, int,
2236 : int, int, int, int ) const
2237 : {
2238 0 : }
2239 :
2240 : /*
2241 : * NetWMAdaptor::setFrameStruts
2242 : */
2243 0 : void NetWMAdaptor::setFrameStruts( X11SalFrame* pFrame,
2244 : int left, int right, int top, int bottom,
2245 : int left_start_y, int left_end_y,
2246 : int right_start_y, int right_end_y,
2247 : int top_start_x, int top_end_x,
2248 : int bottom_start_x, int bottom_end_x ) const
2249 : {
2250 : long nData[12];
2251 0 : nData[0] = left;
2252 0 : nData[1] = right;
2253 0 : nData[2] = top;
2254 0 : nData[3] = bottom;
2255 0 : nData[4] = left_start_y;
2256 0 : nData[5] = left_end_y;
2257 0 : nData[6] = right_start_y;
2258 0 : nData[7] = right_end_y;
2259 0 : nData[8] = top_start_x;
2260 0 : nData[9] = top_end_x;
2261 0 : nData[10]= bottom_start_x;
2262 0 : nData[11]= bottom_end_x;
2263 0 : Atom aProperty = None;
2264 0 : int nSetData = 0;
2265 :
2266 0 : if( m_aWMAtoms[NET_WM_STRUT_PARTIAL] )
2267 : {
2268 0 : aProperty = m_aWMAtoms[NET_WM_STRUT_PARTIAL];
2269 0 : nSetData = 12;
2270 : }
2271 0 : else if( m_aWMAtoms[NET_WM_STRUT] )
2272 : {
2273 0 : aProperty = m_aWMAtoms[NET_WM_STRUT];
2274 0 : nSetData = 4;
2275 : }
2276 0 : if( nSetData )
2277 : {
2278 : XChangeProperty( m_pDisplay,
2279 : pFrame->GetShellWindow(),
2280 : aProperty,
2281 : XA_CARDINAL,
2282 : 32,
2283 : PropModeReplace,
2284 : reinterpret_cast<unsigned char*>(&nData),
2285 : nSetData
2286 0 : );
2287 : }
2288 0 : }
2289 :
2290 : /*
2291 : * WMAdaptor::setUserTime
2292 : */
2293 0 : void WMAdaptor::setUserTime( X11SalFrame*, long ) const
2294 : {
2295 0 : }
2296 :
2297 : /*
2298 : * NetWMAdaptor::setUserTime
2299 : */
2300 0 : void NetWMAdaptor::setUserTime( X11SalFrame* i_pFrame, long i_nUserTime ) const
2301 : {
2302 0 : if( m_aWMAtoms[NET_WM_USER_TIME] )
2303 : {
2304 : XChangeProperty( m_pDisplay,
2305 : i_pFrame->GetShellWindow(),
2306 0 : m_aWMAtoms[NET_WM_USER_TIME],
2307 : XA_CARDINAL,
2308 : 32,
2309 : PropModeReplace,
2310 : reinterpret_cast<unsigned char*>(&i_nUserTime),
2311 : 1
2312 0 : );
2313 : }
2314 0 : }
2315 :
2316 : /*
2317 : * WMAdaptor::setPID
2318 : */
2319 0 : void WMAdaptor::setPID( X11SalFrame* i_pFrame ) const
2320 : {
2321 0 : if( m_aWMAtoms[NET_WM_PID] )
2322 : {
2323 0 : long nPID = (long)getpid();
2324 : XChangeProperty( m_pDisplay,
2325 : i_pFrame->GetShellWindow(),
2326 0 : m_aWMAtoms[NET_WM_PID],
2327 : XA_CARDINAL,
2328 : 32,
2329 : PropModeReplace,
2330 : reinterpret_cast<unsigned char*>(&nPID),
2331 : 1
2332 0 : );
2333 : }
2334 0 : }
2335 :
2336 : /*
2337 : * WMAdaptor::setClientMachine
2338 : */
2339 0 : void WMAdaptor::setClientMachine( X11SalFrame* i_pFrame ) const
2340 : {
2341 0 : OString aWmClient( OUStringToOString( GetGenericData()->GetHostname(), RTL_TEXTENCODING_ASCII_US ) );
2342 0 : XTextProperty aClientProp = { reinterpret_cast<unsigned char *>(const_cast<char *>(aWmClient.getStr())), XA_STRING, 8, sal::static_int_cast<unsigned long>( aWmClient.getLength() ) };
2343 0 : XSetWMClientMachine( m_pDisplay, i_pFrame->GetShellWindow(), &aClientProp );
2344 0 : }
2345 :
2346 0 : void WMAdaptor::answerPing( X11SalFrame* i_pFrame, XClientMessageEvent* i_pEvent ) const
2347 : {
2348 0 : if( m_aWMAtoms[NET_WM_PING] &&
2349 0 : i_pEvent->message_type == m_aWMAtoms[ WM_PROTOCOLS ] &&
2350 0 : (Atom)i_pEvent->data.l[0] == m_aWMAtoms[ NET_WM_PING ] )
2351 : {
2352 : XEvent aEvent;
2353 0 : aEvent.xclient = *i_pEvent;
2354 0 : aEvent.xclient.window = m_pSalDisplay->GetRootWindow( i_pFrame->GetScreenNumber() );
2355 : XSendEvent( m_pDisplay,
2356 : m_pSalDisplay->GetRootWindow( i_pFrame->GetScreenNumber() ),
2357 : False,
2358 : SubstructureNotifyMask | SubstructureRedirectMask,
2359 : &aEvent
2360 0 : );
2361 0 : XFlush( m_pDisplay );
2362 : }
2363 9 : }
2364 :
2365 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|