2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
3 * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com
4 * Copyright (C) 2008 Christian Dywan <christian@imendio.com>
5 * Copyright (C) 2008 Collabora Ltd.
6 * Copyright (C) 2009 Holger Hans Peter Freyther
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "PlatformScreen.h"
34 #include "GtkVersioning.h"
35 #include "HostWindow.h"
36 #include "ScrollView.h"
43 #include <X11/Xatom.h>
48 static GtkWidget* getToplevel(GtkWidget* widget)
50 GtkWidget* toplevel = gtk_widget_get_toplevel(widget);
51 return gtk_widget_is_toplevel(toplevel) ? toplevel : 0;
54 static GdkVisual* getVisual(Widget* widget)
59 GtkWidget* container = GTK_WIDGET(widget->root()->hostWindow()->platformPageClient());
61 GdkScreen* screen = gdk_screen_get_default();
62 return screen ? gdk_screen_get_system_visual(screen) : 0;
65 if (!gtk_widget_get_realized(container))
66 container = getToplevel(container);
67 return container ? gdk_window_get_visual(gtk_widget_get_window(container)) : 0;
70 int screenDepth(Widget* widget)
72 GdkVisual* visual = getVisual(widget);
75 return gdk_visual_get_depth(visual);
78 int screenDepthPerComponent(Widget* widget)
80 GdkVisual* visual = getVisual(widget);
84 return gdk_visual_get_bits_per_rgb(visual);
87 bool screenIsMonochrome(Widget* widget)
89 return screenDepth(widget) < 2;
93 static GdkScreen* getScreen(GtkWidget* widget)
95 return gtk_widget_has_screen(widget) ? gtk_widget_get_screen(widget) : gdk_screen_get_default();
98 FloatRect screenRect(Widget* widget)
103 GtkWidget* container = GTK_WIDGET(widget->root()->hostWindow()->platformPageClient());
105 container = getToplevel(container);
107 GdkScreen* screen = container ? getScreen(container) : gdk_screen_get_default();
111 gint monitor = container ? gdk_screen_get_monitor_at_window(screen, gtk_widget_get_window(container)) : 0;
113 GdkRectangle geometry;
114 gdk_screen_get_monitor_geometry(screen, monitor, &geometry);
116 return FloatRect(geometry.x, geometry.y, geometry.width, geometry.height);
119 FloatRect screenAvailableRect(Widget* widget)
125 GtkWidget* container = GTK_WIDGET(widget->root()->hostWindow()->platformPageClient());
129 if (!gtk_widget_get_realized(container))
130 return screenRect(widget);
132 GdkWindow* rootWindow = gtk_widget_get_root_window(container);
133 GdkDisplay* display = gdk_window_get_display(rootWindow);
134 Atom xproperty = gdk_x11_get_xatom_by_name_for_display(display, "_NET_WORKAREA");
138 long *workAreaPos = NULL;
139 unsigned long retNItems;
140 unsigned long retAfter;
141 int xRes = XGetWindowProperty(GDK_DISPLAY_XDISPLAY(display), GDK_WINDOW_XWINDOW(rootWindow), xproperty,
142 0, 4, FALSE, XA_CARDINAL, &retType, &retFormat, &retNItems, &retAfter, (guchar**)&workAreaPos);
145 if (xRes == Success && workAreaPos != NULL && retType == XA_CARDINAL && retNItems == 4 && retFormat == 32) {
146 rect = FloatRect(workAreaPos[0], workAreaPos[1], workAreaPos[2], workAreaPos[3]);
147 // rect contains the available space in the whole screen not just in the monitor
148 // containing the widget, so we intersect it with the monitor rectangle.
149 rect.intersect(screenRect(widget));
151 rect = screenRect(widget);
158 return screenRect(widget);
162 } // namespace WebCore