LCOV - code coverage report
Current view: directory - widget/gtk2 - nsScreenGtk.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 46 0 0.0 %
Date: 2012-06-02 Functions: 9 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Netscape Communications Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2000
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Christopher A. Aillon <caillon@redhat.com>
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      27                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : #include "nsScreenGtk.h"
      40                 : 
      41                 : #include <gdk/gdk.h>
      42                 : #ifdef MOZ_X11
      43                 : #include <gdk/gdkx.h>
      44                 : #include <X11/Xatom.h>
      45                 : #endif
      46                 : #include <gtk/gtk.h>
      47                 : 
      48               0 : nsScreenGtk :: nsScreenGtk (  )
      49                 :   : mScreenNum(0),
      50                 :     mRect(0, 0, 0, 0),
      51               0 :     mAvailRect(0, 0, 0, 0)
      52                 : {
      53               0 : }
      54                 : 
      55                 : 
      56               0 : nsScreenGtk :: ~nsScreenGtk()
      57                 : {
      58               0 : }
      59                 : 
      60                 : 
      61                 : NS_IMETHODIMP
      62               0 : nsScreenGtk :: GetRect(PRInt32 *outLeft, PRInt32 *outTop, PRInt32 *outWidth, PRInt32 *outHeight)
      63                 : {
      64               0 :   *outLeft = mRect.x;
      65               0 :   *outTop = mRect.y;
      66               0 :   *outWidth = mRect.width;
      67               0 :   *outHeight = mRect.height;
      68                 : 
      69               0 :   return NS_OK;
      70                 :   
      71                 : } // GetRect
      72                 : 
      73                 : 
      74                 : NS_IMETHODIMP
      75               0 : nsScreenGtk :: GetAvailRect(PRInt32 *outLeft, PRInt32 *outTop, PRInt32 *outWidth, PRInt32 *outHeight)
      76                 : {
      77               0 :   *outLeft = mAvailRect.x;
      78               0 :   *outTop = mAvailRect.y;
      79               0 :   *outWidth = mAvailRect.width;
      80               0 :   *outHeight = mAvailRect.height;
      81                 : 
      82               0 :   return NS_OK;
      83                 :   
      84                 : } // GetAvailRect
      85                 : 
      86                 : 
      87                 : NS_IMETHODIMP 
      88               0 : nsScreenGtk :: GetPixelDepth(PRInt32 *aPixelDepth)
      89                 : {
      90               0 :   GdkVisual * rgb_visual = gdk_rgb_get_visual();
      91               0 :   *aPixelDepth = rgb_visual->depth;
      92                 : 
      93               0 :   return NS_OK;
      94                 : 
      95                 : } // GetPixelDepth
      96                 : 
      97                 : 
      98                 : NS_IMETHODIMP 
      99               0 : nsScreenGtk :: GetColorDepth(PRInt32 *aColorDepth)
     100                 : {
     101               0 :   return GetPixelDepth ( aColorDepth );
     102                 : 
     103                 : } // GetColorDepth
     104                 : 
     105                 : 
     106                 : void
     107               0 : nsScreenGtk :: Init (GdkWindow *aRootWindow)
     108                 : {
     109                 :   // We listen for configure events on the root window to pick up
     110                 :   // changes to this rect.  We could listen for "size_changed" signals
     111                 :   // on the default screen to do this, except that doesn't work with
     112                 :   // versions of GDK predating the GdkScreen object.  See bug 256646.
     113               0 :   mAvailRect = mRect = nsIntRect(0, 0, gdk_screen_width(), gdk_screen_height());
     114                 : 
     115                 : #ifdef MOZ_X11
     116                 :   // We need to account for the taskbar, etc in the available rect.
     117                 :   // See http://freedesktop.org/Standards/wm-spec/index.html#id2767771
     118                 : 
     119                 :   // XXX do we care about _NET_WM_STRUT_PARTIAL?  That will
     120                 :   // add much more complexity to the code here (our screen
     121                 :   // could have a non-rectangular shape), but should
     122                 :   // lead to greater accuracy.
     123                 : 
     124                 :   long *workareas;
     125                 :   GdkAtom type_returned;
     126                 :   int format_returned;
     127                 :   int length_returned;
     128                 : 
     129                 : #if GTK_CHECK_VERSION(2,0,0)
     130               0 :   GdkAtom cardinal_atom = gdk_x11_xatom_to_atom(XA_CARDINAL);
     131                 : #else
     132                 :   GdkAtom cardinal_atom = (GdkAtom) XA_CARDINAL;
     133                 : #endif
     134                 : 
     135               0 :   gdk_error_trap_push();
     136                 : 
     137                 :   // gdk_property_get uses (length + 3) / 4, hence G_MAXLONG - 3 here.
     138               0 :   if (!gdk_property_get(aRootWindow,
     139                 :                         gdk_atom_intern ("_NET_WORKAREA", FALSE),
     140                 :                         cardinal_atom,
     141                 :                         0, G_MAXLONG - 3, FALSE,
     142                 :                         &type_returned,
     143                 :                         &format_returned,
     144                 :                         &length_returned,
     145               0 :                         (guchar **) &workareas)) {
     146                 :     // This window manager doesn't support the freedesktop standard.
     147                 :     // Nothing we can do about it, so assume full screen size.
     148               0 :     return;
     149                 :   }
     150                 : 
     151                 :   // Flush the X queue to catch errors now.
     152               0 :   gdk_flush();
     153                 : 
     154               0 :   if (!gdk_error_trap_pop() &&
     155                 :       type_returned == cardinal_atom &&
     156                 :       length_returned && (length_returned % 4) == 0 &&
     157                 :       format_returned == 32) {
     158               0 :     int num_items = length_returned / sizeof(long);
     159                 : 
     160               0 :     for (int i = 0; i < num_items; i += 4) {
     161               0 :       nsIntRect workarea(workareas[i],     workareas[i + 1],
     162               0 :                          workareas[i + 2], workareas[i + 3]);
     163               0 :       if (!mRect.Contains(workarea)) {
     164                 :         // Note that we hit this when processing screen size changes,
     165                 :         // since we'll get the configure event before the toolbars have
     166                 :         // been moved.  We'll end up cleaning this up when we get the
     167                 :         // change notification to the _NET_WORKAREA property.  However,
     168                 :         // we still want to listen to both, so we'll handle changes
     169                 :         // properly for desktop environments that don't set the
     170                 :         // _NET_WORKAREA property.
     171               0 :         NS_WARNING("Invalid bounds");
     172               0 :         continue;
     173                 :       }
     174                 : 
     175               0 :       mAvailRect.IntersectRect(mAvailRect, workarea);
     176                 :     }
     177                 :   }
     178               0 :   g_free (workareas);
     179                 : #endif
     180                 : }
     181                 : 
     182                 : #ifdef MOZ_X11
     183                 : void
     184               0 : nsScreenGtk :: Init (XineramaScreenInfo *aScreenInfo)
     185                 : {
     186                 :   nsIntRect xineRect(aScreenInfo->x_org, aScreenInfo->y_org,
     187               0 :                      aScreenInfo->width, aScreenInfo->height);
     188                 : 
     189               0 :   mScreenNum = aScreenInfo->screen_number;
     190                 : 
     191               0 :   mAvailRect = mRect = xineRect;
     192               0 : }
     193                 : #endif

Generated by: LCOV version 1.7