michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsScreenGtk.h" michael@0: michael@0: #include michael@0: #ifdef MOZ_X11 michael@0: #include michael@0: #include michael@0: #endif michael@0: #include michael@0: michael@0: nsScreenGtk :: nsScreenGtk ( ) michael@0: : mScreenNum(0), michael@0: mRect(0, 0, 0, 0), michael@0: mAvailRect(0, 0, 0, 0) michael@0: { michael@0: } michael@0: michael@0: michael@0: nsScreenGtk :: ~nsScreenGtk() michael@0: { michael@0: } michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: nsScreenGtk :: GetRect(int32_t *outLeft, int32_t *outTop, int32_t *outWidth, int32_t *outHeight) michael@0: { michael@0: *outLeft = mRect.x; michael@0: *outTop = mRect.y; michael@0: *outWidth = mRect.width; michael@0: *outHeight = mRect.height; michael@0: michael@0: return NS_OK; michael@0: michael@0: } // GetRect michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: nsScreenGtk :: GetAvailRect(int32_t *outLeft, int32_t *outTop, int32_t *outWidth, int32_t *outHeight) michael@0: { michael@0: *outLeft = mAvailRect.x; michael@0: *outTop = mAvailRect.y; michael@0: *outWidth = mAvailRect.width; michael@0: *outHeight = mAvailRect.height; michael@0: michael@0: return NS_OK; michael@0: michael@0: } // GetAvailRect michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: nsScreenGtk :: GetPixelDepth(int32_t *aPixelDepth) michael@0: { michael@0: GdkVisual * visual = gdk_screen_get_system_visual(gdk_screen_get_default()); michael@0: *aPixelDepth = gdk_visual_get_depth(visual); michael@0: michael@0: return NS_OK; michael@0: michael@0: } // GetPixelDepth michael@0: michael@0: michael@0: NS_IMETHODIMP michael@0: nsScreenGtk :: GetColorDepth(int32_t *aColorDepth) michael@0: { michael@0: return GetPixelDepth ( aColorDepth ); michael@0: michael@0: } // GetColorDepth michael@0: michael@0: michael@0: void michael@0: nsScreenGtk :: Init (GdkWindow *aRootWindow) michael@0: { michael@0: // We listen for configure events on the root window to pick up michael@0: // changes to this rect. We could listen for "size_changed" signals michael@0: // on the default screen to do this, except that doesn't work with michael@0: // versions of GDK predating the GdkScreen object. See bug 256646. michael@0: mAvailRect = mRect = nsIntRect(0, 0, gdk_screen_width(), gdk_screen_height()); michael@0: michael@0: #ifdef MOZ_X11 michael@0: // We need to account for the taskbar, etc in the available rect. michael@0: // See http://freedesktop.org/Standards/wm-spec/index.html#id2767771 michael@0: michael@0: // XXX do we care about _NET_WM_STRUT_PARTIAL? That will michael@0: // add much more complexity to the code here (our screen michael@0: // could have a non-rectangular shape), but should michael@0: // lead to greater accuracy. michael@0: michael@0: long *workareas; michael@0: GdkAtom type_returned; michael@0: int format_returned; michael@0: int length_returned; michael@0: michael@0: GdkAtom cardinal_atom = gdk_x11_xatom_to_atom(XA_CARDINAL); michael@0: michael@0: gdk_error_trap_push(); michael@0: michael@0: // gdk_property_get uses (length + 3) / 4, hence G_MAXLONG - 3 here. michael@0: if (!gdk_property_get(aRootWindow, michael@0: gdk_atom_intern ("_NET_WORKAREA", FALSE), michael@0: cardinal_atom, michael@0: 0, G_MAXLONG - 3, FALSE, michael@0: &type_returned, michael@0: &format_returned, michael@0: &length_returned, michael@0: (guchar **) &workareas)) { michael@0: // This window manager doesn't support the freedesktop standard. michael@0: // Nothing we can do about it, so assume full screen size. michael@0: return; michael@0: } michael@0: michael@0: // Flush the X queue to catch errors now. michael@0: gdk_flush(); michael@0: michael@0: if (!gdk_error_trap_pop() && michael@0: type_returned == cardinal_atom && michael@0: length_returned && (length_returned % 4) == 0 && michael@0: format_returned == 32) { michael@0: int num_items = length_returned / sizeof(long); michael@0: michael@0: for (int i = 0; i < num_items; i += 4) { michael@0: nsIntRect workarea(workareas[i], workareas[i + 1], michael@0: workareas[i + 2], workareas[i + 3]); michael@0: if (!mRect.Contains(workarea)) { michael@0: // Note that we hit this when processing screen size changes, michael@0: // since we'll get the configure event before the toolbars have michael@0: // been moved. We'll end up cleaning this up when we get the michael@0: // change notification to the _NET_WORKAREA property. However, michael@0: // we still want to listen to both, so we'll handle changes michael@0: // properly for desktop environments that don't set the michael@0: // _NET_WORKAREA property. michael@0: NS_WARNING("Invalid bounds"); michael@0: continue; michael@0: } michael@0: michael@0: mAvailRect.IntersectRect(mAvailRect, workarea); michael@0: } michael@0: } michael@0: g_free (workareas); michael@0: #endif michael@0: } michael@0: michael@0: #ifdef MOZ_X11 michael@0: void michael@0: nsScreenGtk :: Init (XineramaScreenInfo *aScreenInfo) michael@0: { michael@0: nsIntRect xineRect(aScreenInfo->x_org, aScreenInfo->y_org, michael@0: aScreenInfo->width, aScreenInfo->height); michael@0: michael@0: mScreenNum = aScreenInfo->screen_number; michael@0: michael@0: mAvailRect = mRect = xineRect; michael@0: } michael@0: #endif