LCOV - code coverage report
Current view: top level - vcl/unx/generic/window - FWS.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 72 0.0 %
Date: 2014-04-14 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

          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 <stdio.h>
      21             : #include <stdlib.h>
      22             : #include <string.h>
      23             : #include <unistd.h>
      24             : 
      25             : #include <X11/Xlib.h>
      26             : #include <X11/Xutil.h>
      27             : #include <X11/Xatom.h>
      28             : #include "FWS.hxx"
      29             : 
      30             : static Atom fwsIconAtom;
      31             : 
      32             : static Atom FWS_CLIENT;
      33             : static Atom FWS_COMM_WINDOW;
      34             : static Atom FWS_PROTOCOLS;
      35             : static Atom FWS_STACK_UNDER;
      36             : static Atom FWS_PARK_ICONS;
      37             : static Atom FWS_PASS_ALL_INPUT;
      38             : static Atom FWS_PASSES_INPUT;
      39             : static Atom FWS_HANDLES_FOCUS;
      40             : 
      41             : static Atom FWS_REGISTER_WINDOW;
      42             : static Atom FWS_STATE_CHANGE;
      43             : static Atom FWS_UNSEEN_STATE;
      44             : static Atom FWS_NORMAL_STATE;
      45             : static Atom WM_PROTOCOLS;
      46             : static Atom WM_CHANGE_STATE;
      47             : 
      48             : static Bool fwsStackUnder;
      49             : static Bool fwsParkIcons;
      50             : static Bool fwsPassesInput;
      51             : static Bool fwsHandlesFocus;
      52             : 
      53             : static Window fwsCommWindow;
      54             : 
      55             : /*************************************<->***********************************
      56             :  *
      57             :  * WMSupportsFWS() -
      58             :  *
      59             :  * Initialize our atoms and determine if the current window manager is
      60             :  * providing FWS extension support.
      61             :  *
      62             :  *************************************<->***********************************/
      63             : 
      64             : Bool
      65           0 : WMSupportsFWS (Display *display, int screen)
      66             : {
      67             :     unsigned int    i;
      68             :     Atom            protocol;
      69             :     Atom            propType;
      70             :     int             propFormat;
      71             :     unsigned long   propItems;
      72             :     unsigned long   propBytesAfter;
      73             :     unsigned char   *propData;
      74             :     char            propName[64];
      75             : 
      76           0 :     FWS_CLIENT         = XInternAtom(display, "_SUN_FWS_CLIENT",         False);
      77           0 :     FWS_COMM_WINDOW    = XInternAtom(display, "_SUN_FWS_COMM_WINDOW",    False);
      78           0 :     FWS_PROTOCOLS      = XInternAtom(display, "_SUN_FWS_PROTOCOLS",      False);
      79           0 :     FWS_STACK_UNDER    = XInternAtom(display, "_SUN_FWS_STACK_UNDER",    False);
      80           0 :     FWS_PARK_ICONS     = XInternAtom(display, "_SUN_FWS_PARK_ICONS",     False);
      81           0 :     FWS_PASS_ALL_INPUT = XInternAtom(display, "_SUN_FWS_PASS_ALL_INPUT", False);
      82           0 :     FWS_PASSES_INPUT   = XInternAtom(display, "_SUN_FWS_PASSES_INPUT",   False);
      83           0 :     FWS_HANDLES_FOCUS  = XInternAtom(display, "_SUN_FWS_HANDLES_FOCUS",  False);
      84           0 :     FWS_REGISTER_WINDOW= XInternAtom(display, "_SUN_FWS_REGISTER_WINDOW",False);
      85           0 :     FWS_STATE_CHANGE   = XInternAtom(display, "_SUN_FWS_STATE_CHANGE",   False);
      86           0 :     FWS_UNSEEN_STATE   = XInternAtom(display, "_SUN_FWS_UNSEEN_STATE",   False);
      87           0 :     FWS_NORMAL_STATE   = XInternAtom(display, "_SUN_FWS_NORMAL_STATE",   False);
      88           0 :     WM_PROTOCOLS       = XInternAtom(display, "WM_PROTOCOLS",            False);
      89           0 :     WM_CHANGE_STATE    = XInternAtom(display, "WM_CHANGE_STATE",         False);
      90             : 
      91           0 :     snprintf (propName, sizeof(propName), "_SUN_FWS_NEXT_ICON_%d", screen);
      92           0 :     fwsIconAtom        = XInternAtom(display, propName, False);
      93             : 
      94           0 :     if (XGetWindowProperty (display, DefaultRootWindow (display),
      95             :                 FWS_COMM_WINDOW, 0, 1,
      96             :                 False, AnyPropertyType, &propType,
      97             :                 &propFormat, &propItems,
      98           0 :                 &propBytesAfter, &propData) != Success)
      99           0 :         return False;
     100             : 
     101           0 :     if (propFormat != 32 ||
     102           0 :         propItems != 1 ||
     103           0 :         propBytesAfter != 0)
     104             :     {
     105             :         #if OSL_DEBUG_LEVEL > 1
     106             :         fprintf (stderr, "Bad FWS_COMM_WINDOW property on root window.\n");
     107             :         #endif
     108           0 :         XFree (propData);
     109           0 :         return False;
     110             :     }
     111             : 
     112           0 :     fwsCommWindow = *(Window *) propData;
     113             :     #if OSL_DEBUG_LEVEL > 1
     114             :     fprintf (stderr, "Using fwsCommWindow = 0x%lx.\n", fwsCommWindow);
     115             :     #endif
     116           0 :     XFree (propData);
     117             : 
     118           0 :     if (XGetWindowProperty (display, DefaultRootWindow (display),
     119             :             FWS_PROTOCOLS, 0, 10,
     120             :             False, AnyPropertyType, &propType,
     121             :             &propFormat, &propItems,
     122           0 :             &propBytesAfter, &propData) != Success)
     123             :     {
     124           0 :         return False;
     125             :     }
     126             : 
     127           0 :     if (propFormat     != 32 ||
     128           0 :         propBytesAfter != 0)
     129             :     {
     130             :         #if OSL_DEBUG_LEVEL > 1
     131             :         fprintf (stderr, "Bad FWS_PROTOCOLS property on root window.\n");
     132             :         #endif
     133           0 :         XFree (propData);
     134           0 :         return False;
     135             :     }
     136             : 
     137           0 :     for (i = 0; i < propItems; ++i)
     138             :     {
     139           0 :         protocol = ((Atom *) propData)[i];
     140           0 :         if (protocol == FWS_STACK_UNDER)
     141             :         {
     142           0 :             fwsStackUnder = True;
     143             :             #if OSL_DEBUG_LEVEL > 1
     144             :             fprintf (stderr, "Using fwsStackUnder.\n");
     145             :             #endif
     146             :         }
     147             :         else
     148           0 :         if (protocol == FWS_PARK_ICONS)
     149             :         {
     150           0 :             fwsParkIcons = True;
     151             :             #if OSL_DEBUG_LEVEL > 1
     152             :             fprintf (stderr, "Using fwsParkIcons.\n");
     153             :             #endif
     154             :         }
     155             :         else
     156           0 :         if (protocol == FWS_PASSES_INPUT)
     157             :         {
     158           0 :             fwsPassesInput = True;
     159             :             #if OSL_DEBUG_LEVEL > 1
     160             :             fprintf (stderr, "Using fwsPassesInput.\n");
     161             :             #endif
     162             :         }
     163             :         else
     164           0 :         if (protocol == FWS_HANDLES_FOCUS)
     165             :         {
     166           0 :             fwsHandlesFocus = True;
     167             :             #if OSL_DEBUG_LEVEL > 1
     168             :             fprintf (stderr, "Using fwsHandlesFocus.\n");
     169             :             #endif
     170             :         }
     171             :     }
     172             : 
     173           0 :     XFree (propData);
     174           0 :     return True;
     175             : }
     176             : 
     177             : /*************************************<->***********************************
     178             :  *
     179             :  * newHandler() -
     180             :  *
     181             :  * Handle X errors (temporarily) to record the occurrence of BadWindow
     182             :  * errors without crashing.  Used to detect the FWS_COMM_WINDOW root window
     183             :  * property containing an old or obsolete window id.
     184             :  *
     185             :  *************************************<->***********************************/
     186             : 
     187             : extern "C" {
     188             : 
     189             : static Bool badWindowFound;
     190             : static int (* oldHandler) (Display *, XErrorEvent *);
     191             : 
     192             : static int
     193           0 : newHandler (Display *display, XErrorEvent *xerror)
     194             : {
     195           0 :     if (xerror->error_code != BadWindow)
     196           0 :         (*oldHandler)(display, xerror);
     197             :     else
     198           0 :         badWindowFound = True;
     199             : 
     200           0 :     return 0;
     201             : }
     202             : 
     203             : }
     204             : 
     205             : /*************************************<->***********************************
     206             :  *
     207             :  * RegisterFwsWindow() -
     208             :  *
     209             :  * Send a client message to the FWS_COMM_WINDOW indicating the existance
     210             :  * of a new FWS client window.  Be careful to avoid BadWindow errors on
     211             :  * the XSendEvent in case the FWS_COMM_WINDOW root window property had
     212             :  * old/obsolete junk in it.
     213             :  *
     214             :  *************************************<->***********************************/
     215             : 
     216             : Bool
     217           0 : RegisterFwsWindow (Display *display, Window window)
     218             : {
     219             :     XClientMessageEvent  msg;
     220             : 
     221           0 :     msg.type         = ClientMessage;
     222           0 :     msg.window       = fwsCommWindow;
     223           0 :     msg.message_type = FWS_REGISTER_WINDOW;
     224           0 :     msg.format       = 32;
     225           0 :     msg.data.l[0]    = window;
     226             : 
     227           0 :     XSync (display, False);
     228           0 :     badWindowFound = False;
     229           0 :     oldHandler = XSetErrorHandler (newHandler);
     230             : 
     231             :     XSendEvent (display, fwsCommWindow, False, NoEventMask,
     232           0 :             (XEvent *) &msg);
     233           0 :     XSync (display, False);
     234             : 
     235           0 :     XSetErrorHandler (oldHandler);
     236             :     #if OSL_DEBUG_LEVEL > 1
     237             :     if (badWindowFound)
     238             :         fprintf (stderr, "No FWS client window to register with.\n");
     239             :     #endif
     240             : 
     241           0 :     return !badWindowFound;
     242             : }
     243             : 
     244             : /*************************************<->***********************************
     245             :  *
     246             :  * AddFwsProtocols -
     247             :  *
     248             :  * Add the FWS protocol atoms to the WMProtocols property for the window.
     249             :  *
     250             :  *************************************<->***********************************/
     251             : 
     252             : void
     253           0 : AddFwsProtocols (Display *display, Window window)
     254             : {
     255             :     #define MAX_FWS_PROTOS 10
     256             : 
     257             :     Atom fwsProtocols[ MAX_FWS_PROTOS ];
     258           0 :     int  nProtos = 0;
     259             : 
     260           0 :     fwsProtocols[ nProtos++ ] = FWS_CLIENT;
     261           0 :     fwsProtocols[ nProtos++ ] = FWS_STACK_UNDER;
     262           0 :     fwsProtocols[ nProtos++ ] = FWS_STATE_CHANGE;
     263           0 :     fwsProtocols[ nProtos++ ] = FWS_PASS_ALL_INPUT;
     264             :     XChangeProperty (display, window, WM_PROTOCOLS,
     265             :             XA_ATOM, 32, PropModeAppend,
     266           0 :             (unsigned char *) fwsProtocols, nProtos);
     267           0 : }
     268             : 
     269             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10