1 /* 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. 3 * Copyright (C) 2006 Michael Emmel mike.emmel (at) gmail.com 4 * Copyright (C) 2008 Christian Dywan <christian (at) imendio.com> 5 * Copyright (C) 2008 Collabora Ltd. 6 * Copyright (C) 2009 Holger Hans Peter Freyther 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 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. 17 * 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. 29 */ 30 31 #include "config.h" 32 #include "PlatformScreen.h" 33 34 #include "HostWindow.h" 35 #include "ScrollView.h" 36 #include "Widget.h" 37 38 #include <gtk/gtk.h> 39 40 #if PLATFORM(X11) 41 #include <gdk/gdkx.h> 42 #include <X11/Xatom.h> 43 #endif 44 45 namespace WebCore { 46 47 static GdkVisual* getVisual(Widget* widget) 48 { 49 if (!widget) 50 return 0; 51 52 GtkWidget* container = GTK_WIDGET(widget->root()->hostWindow()->platformPageClient()); 53 54 if (!container) 55 return 0; 56 57 if (!GTK_WIDGET_REALIZED(container)) { 58 GtkWidget* toplevel = gtk_widget_get_toplevel(container); 59 #if GTK_CHECK_VERSION(2, 18, 0) 60 if (gtk_widget_is_toplevel(toplevel)) 61 #else 62 if (GTK_WIDGET_TOPLEVEL(toplevel)) 63 #endif 64 container = toplevel; 65 else 66 return 0; 67 } 68 69 70 return gdk_drawable_get_visual(GDK_DRAWABLE(container->window)); 71 } 72 73 int screenDepth(Widget* widget) 74 { 75 GdkVisual* visual = getVisual(widget); 76 if (!visual) 77 return 24; 78 return visual->depth; 79 } 80 81 int screenDepthPerComponent(Widget* widget) 82 { 83 GdkVisual* visual = getVisual(widget); 84 if (!visual) 85 return 8; 86 87 return visual->bits_per_rgb; 88 } 89 90 bool screenIsMonochrome(Widget* widget) 91 { 92 return screenDepth(widget) < 2; 93 } 94 95 FloatRect screenRect(Widget* widget) 96 { 97 if (!widget) 98 return FloatRect(); 99 100 GtkWidget* container = gtk_widget_get_toplevel(GTK_WIDGET(widget->root()->hostWindow()->platformPageClient())); 101 #if GTK_CHECK_VERSION(2, 18, 0) 102 if (!gtk_widget_is_toplevel(container)) 103 #else 104 if (!GTK_WIDGET_TOPLEVEL(container)) 105 #endif 106 return FloatRect(); 107 108 GdkScreen* screen = gtk_widget_has_screen(container) ? gtk_widget_get_screen(container) : gdk_screen_get_default(); 109 if (!screen) 110 return FloatRect(); 111 112 gint monitor = gdk_screen_get_monitor_at_window(screen, GTK_WIDGET(container)->window); 113 GdkRectangle geometry; 114 gdk_screen_get_monitor_geometry(screen, monitor, &geometry); 115 116 return FloatRect(geometry.x, geometry.y, geometry.width, geometry.height); 117 } 118 119 FloatRect screenAvailableRect(Widget* widget) 120 { 121 if (!widget) 122 return FloatRect(); 123 124 #if PLATFORM(X11) 125 GtkWidget* container = GTK_WIDGET(widget->root()->hostWindow()->platformPageClient()); 126 if (!container) 127 return FloatRect(); 128 129 if (!GTK_WIDGET_REALIZED(container)) 130 return screenRect(widget); 131 132 GdkDrawable* rootWindow = GDK_DRAWABLE(gtk_widget_get_root_window(container)); 133 GdkDisplay* display = gdk_drawable_get_display(rootWindow); 134 Atom xproperty = gdk_x11_get_xatom_by_name_for_display(display, "_NET_WORKAREA"); 135 136 Atom retType; 137 int retFormat; 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); 143 144 FloatRect rect; 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)); 150 } else 151 rect = screenRect(widget); 152 153 if (workAreaPos) 154 XFree(workAreaPos); 155 156 return rect; 157 #else 158 return screenRect(widget); 159 #endif 160 } 161 162 } // namespace WebCore 163