- Timestamp:
- 08/15/08 13:25:16 (5 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/BAL/WKAL/Concretizations/Widgets/Gtk/BCPlatformScreenGtk.cpp
r243 r437 2 2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. 3 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. 4 6 * All rights reserved. 5 7 * … … 34 36 #include <gtk/gtk.h> 35 37 38 #if defined(GDK_WINDOWING_X11) 39 #include <gdk/gdkx.h> 40 #include <X11/Xatom.h> 41 #endif 42 36 43 namespace WKAL { 37 44 38 45 int screenDepth(Widget* widget) 39 46 { 40 ASSERT(widget->containingWindow() && GTK_WIDGET(widget->containingWindow())->window); 47 GtkWidget* container = GTK_WIDGET(widget->containingWindow()); 48 if (!container) 49 return 24; 41 50 42 gint depth; 43 gdk_window_get_geometry(GTK_WIDGET(widget->containingWindow())->window, 0, 0, 0, 0, &depth); 44 return depth; 51 GdkVisual* visual = gdk_drawable_get_visual(GDK_DRAWABLE(GTK_WIDGET(widget->containingWindow())->window)); 52 return visual->depth; 45 53 } 46 54 47 int screenDepthPerComponent(Widget* )55 int screenDepthPerComponent(Widget* widget) 48 56 { 49 notImplemented(); 50 return 8; 57 GtkWidget* container = GTK_WIDGET(widget->containingWindow()); 58 if (!container) 59 return 8; 60 61 GdkVisual* visual = gdk_drawable_get_visual(GDK_DRAWABLE(GTK_WIDGET(widget->containingWindow())->window)); 62 return visual->bits_per_rgb; 51 63 } 52 64 53 65 bool screenIsMonochrome(Widget* widget) 54 66 { 67 GtkWidget* container = GTK_WIDGET(widget->containingWindow()); 68 if (!container) 69 return false; 70 55 71 return screenDepth(widget) < 2; 56 72 } … … 58 74 FloatRect screenRect(Widget* widget) 59 75 { 60 ASSERT(widget->containingWindow() && GTK_WIDGET(widget->containingWindow())->window); 76 GtkWidget* container = GTK_WIDGET(widget->containingWindow()); 77 if (!container) 78 return FloatRect(); 61 79 62 GdkScreen* screen = gtk_widget_get_screen(GTK_WIDGET(widget->containingWindow())); 63 gint monitor = gdk_screen_get_monitor_at_window(screen, GTK_WIDGET(widget->containingWindow())->window); 80 GdkScreen* screen = gtk_widget_has_screen(container) ? gtk_widget_get_screen(container) : gdk_screen_get_default(); 81 if (!screen) 82 return FloatRect(); 83 84 gint monitor = gdk_screen_get_monitor_at_window(screen, GTK_WIDGET(container)->window); 64 85 GdkRectangle geometry; 65 66 86 gdk_screen_get_monitor_geometry(screen, monitor, &geometry); 67 87 … … 69 89 } 70 90 71 FloatRect screenAvailableRect(Widget* )91 FloatRect screenAvailableRect(Widget* widget) 72 92 { 73 notImplemented(); 74 return FloatRect(); 93 #if defined(GDK_WINDOWING_X11) 94 GtkWidget* container = GTK_WIDGET(widget->containingWindow()); 95 if (!container) 96 return FloatRect(); 97 98 if (!GTK_WIDGET_REALIZED(container)) 99 return screenRect(widget); 100 101 GdkDrawable* rootWindow = GDK_DRAWABLE(gtk_widget_get_root_window(container)); 102 GdkDisplay* display = gdk_drawable_get_display(rootWindow); 103 Atom xproperty = gdk_x11_get_xatom_by_name_for_display(display, "_NET_WORKAREA"); 104 105 Atom retType; 106 int retFormat; 107 long *workAreaPos = NULL; 108 unsigned long retNItems; 109 unsigned long retAfter; 110 int xRes = XGetWindowProperty(GDK_DISPLAY_XDISPLAY(display), GDK_WINDOW_XWINDOW(rootWindow), xproperty, 111 0, 4, FALSE, XA_CARDINAL, &retType, &retFormat, &retNItems, &retAfter, (guchar**)&workAreaPos); 112 113 FloatRect rect; 114 if (xRes == Success && workAreaPos != NULL && retType == XA_CARDINAL && retNItems == 4 && retFormat == 32) { 115 rect = FloatRect(workAreaPos[0], workAreaPos[1], workAreaPos[2], workAreaPos[3]); 116 // rect contains the available space in the whole screen not just in the monitor 117 // containing the widget, so we intersect it with the monitor rectangle. 118 rect.intersect(screenRect(widget)); 119 } else 120 rect = screenRect(widget); 121 122 if (workAreaPos) 123 XFree(workAreaPos); 124 125 return rect; 126 #else 127 return screenRect(widget); 128 #endif 75 129 } 76 130
