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
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/
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
15
* The Original Code is mozilla.org code.
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.
23
* Christopher A. Aillon <caillon@redhat.com>
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.
37
* ***** END LICENSE BLOCK ***** */
39
#include "nsScreenGtk.h"
43
#include <X11/Xatom.h>
45
static GdkFilterReturn
46
root_window_event_filter(GdkXEvent *aGdkXEvent, GdkEvent *aGdkEvent,
49
XEvent *xevent = static_cast<XEvent*>(aGdkXEvent);
50
nsScreenGtk *ourScreen = static_cast<nsScreenGtk*>(aClosure);
52
// See comments in nsScreenGtk::Init below.
53
switch (xevent->type) {
59
XPropertyEvent *propertyEvent = &xevent->xproperty;
60
if (propertyEvent->atom == ourScreen->NetWorkareaAtom()) {
69
return GDK_FILTER_CONTINUE;
72
nsScreenGtk :: nsScreenGtk ( )
73
: mRootWindow(nsnull),
76
mAvailRect(0, 0, 0, 0)
81
nsScreenGtk :: ~nsScreenGtk()
84
gdk_window_remove_filter(mRootWindow, root_window_event_filter, this);
85
g_object_unref(mRootWindow);
91
// addref, release, QI
92
NS_IMPL_ISUPPORTS1(nsScreenGtk, nsIScreen)
96
nsScreenGtk :: GetRect(PRInt32 *outLeft, PRInt32 *outTop, PRInt32 *outWidth, PRInt32 *outHeight)
100
*outWidth = mRect.width;
101
*outHeight = mRect.height;
109
nsScreenGtk :: GetAvailRect(PRInt32 *outLeft, PRInt32 *outTop, PRInt32 *outWidth, PRInt32 *outHeight)
111
*outLeft = mAvailRect.x;
112
*outTop = mAvailRect.y;
113
*outWidth = mAvailRect.width;
114
*outHeight = mAvailRect.height;
122
nsScreenGtk :: GetPixelDepth(PRInt32 *aPixelDepth)
124
GdkVisual * rgb_visual = gdk_rgb_get_visual();
125
*aPixelDepth = rgb_visual->depth;
133
nsScreenGtk :: GetColorDepth(PRInt32 *aColorDepth)
135
return GetPixelDepth ( aColorDepth );
141
nsScreenGtk :: Init (PRBool aReInit)
143
// We listen for configure events on the root window to pick up
144
// changes to this rect. We could listen for "size_changed" signals
145
// on the default screen to do this, except that doesn't work with
146
// versions of GDK predating the GdkScreen object. See bug 256646.
147
mAvailRect = mRect = nsRect(0, 0, gdk_screen_width(), gdk_screen_height());
149
// We need to account for the taskbar, etc in the available rect.
150
// See http://freedesktop.org/Standards/wm-spec/index.html#id2767771
152
// XXX do we care about _NET_WM_STRUT_PARTIAL? That will
153
// add much more complexity to the code here (our screen
154
// could have a non-rectangular shape), but should
155
// lead to greater accuracy.
158
#if GTK_CHECK_VERSION(2,2,0)
159
mRootWindow = gdk_get_default_root_window();
161
mRootWindow = GDK_ROOT_PARENT();
162
#endif // GTK_CHECK_VERSION(2,2,0)
163
g_object_ref(mRootWindow);
165
// GDK_STRUCTURE_MASK ==> StructureNotifyMask, for ConfigureNotify
166
// GDK_PROPERTY_CHANGE_MASK ==> PropertyChangeMask, for PropertyNotify
167
gdk_window_set_events(mRootWindow,
168
GdkEventMask(gdk_window_get_events(mRootWindow) |
170
GDK_PROPERTY_CHANGE_MASK));
171
gdk_window_add_filter(mRootWindow, root_window_event_filter, this);
173
XInternAtom(GDK_WINDOW_XDISPLAY(mRootWindow), "_NET_WORKAREA", False);
177
GdkAtom type_returned;
181
#if GTK_CHECK_VERSION(2,0,0)
182
GdkAtom cardinal_atom = gdk_x11_xatom_to_atom(XA_CARDINAL);
184
GdkAtom cardinal_atom = (GdkAtom) XA_CARDINAL;
187
gdk_error_trap_push();
189
// gdk_property_get uses (length + 3) / 4, hence G_MAXLONG - 3 here.
190
if (!gdk_property_get(mRootWindow,
191
gdk_atom_intern ("_NET_WORKAREA", FALSE),
193
0, G_MAXLONG - 3, FALSE,
197
(guchar **) &workareas)) {
198
// This window manager doesn't support the freedesktop standard.
199
// Nothing we can do about it, so assume full screen size.
203
// Flush the X queue to catch errors now.
206
if (!gdk_error_trap_pop() &&
207
type_returned == cardinal_atom &&
208
length_returned && (length_returned % 4) == 0 &&
209
format_returned == 32) {
210
int num_items = length_returned / sizeof(long);
212
for (int i = 0; i < num_items; i += 4) {
213
nsRect workarea(workareas[i], workareas[i + 1],
214
workareas[i + 2], workareas[i + 3]);
215
if (!mRect.Contains(workarea)) {
216
// Note that we hit this when processing screen size changes,
217
// since we'll get the configure event before the toolbars have
218
// been moved. We'll end up cleaning this up when we get the
219
// change notification to the _NET_WORKAREA property. However,
220
// we still want to listen to both, so we'll handle changes
221
// properly for desktop environments that don't set the
222
// _NET_WORKAREA property.
223
NS_WARNING("Invalid bounds");
227
mAvailRect.IntersectRect(mAvailRect, workarea);
234
nsScreenGtk :: Init (XineramaScreenInfo *aScreenInfo)
236
nsRect xineRect(aScreenInfo->x_org, aScreenInfo->y_org,
237
aScreenInfo->width, aScreenInfo->height);
239
mScreenNum = aScreenInfo->screen_number;
241
mAvailRect = mRect = xineRect;