Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: views/screen_gtk.cc

Issue 460134: Uses X mechanisms to get the screen size. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "views/screen.h" 5 #include "views/screen.h"
6 6
7 #include <gdk/gdkx.h>
7 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
8 9
9 #include "base/logging.h" 10 #include "base/logging.h"
10 11
11 namespace views { 12 namespace views {
12 13
13 // static 14 // static
14 gfx::Point Screen::GetCursorScreenPoint() { 15 gfx::Point Screen::GetCursorScreenPoint() {
15 gint x, y; 16 gint x, y;
16 gdk_display_get_pointer(gdk_display_get_default(), NULL, &x, &y, NULL); 17 gdk_display_get_pointer(gdk_display_get_default(), NULL, &x, &y, NULL);
17 return gfx::Point(x, y); 18 return gfx::Point(x, y);
18 } 19 }
19 20
20 gfx::Rect static GetPrimaryMonitorBounds() { 21 gfx::Rect static GetPrimaryMonitorBounds() {
21 guchar* raw_data = NULL; 22 guchar* raw_data = NULL;
22 gint data_len = 0; 23 gint data_len = 0;
23 gboolean success = gdk_property_get(gdk_get_default_root_window(), 24 gboolean success = gdk_property_get(gdk_get_default_root_window(),
24 gdk_atom_intern("_NET_WORKAREA", FALSE), 25 gdk_atom_intern("_NET_WORKAREA", FALSE),
25 gdk_atom_intern("CARDINAL", FALSE), 26 gdk_atom_intern("CARDINAL", FALSE),
26 0, 0xFF, false, NULL, NULL, &data_len, 27 0, 0xFF, false, NULL, NULL, &data_len,
27 &raw_data); 28 &raw_data);
29 int top_left_x = 0;
30 int top_left_y = 0;
31 int width = 0;
32 int height = 0;
33
34 if (success) {
35 glong* data = reinterpret_cast<glong*>(raw_data);
36 top_left_x = data[0];
37 top_left_y = data[1];
38 width = data[2];
39 height = data[3];
40 } else {
41 #if defined(OS_LINUX)
sky 2009/12/09 16:34:34 This file is only compiled on linux, so no need fo
Chris Masone 2009/12/09 17:09:50 fixed and committed
42 // If there's no window manager, we can ask X for Monitor info directly.
43 XWindowAttributes attributes;
44 Status status = XGetWindowAttributes(gdk_x11_get_default_xdisplay(),
45 gdk_x11_get_default_root_xwindow(),
46 &attributes);
47 if (status) {
48 top_left_x = attributes.x;
49 top_left_y = attributes.y;
50 width = attributes.width;
51 height = attributes.height;
52 success = true;
53 }
54 #endif
55 }
28 DCHECK(success); 56 DCHECK(success);
29 glong* data = reinterpret_cast<glong*>(raw_data); 57 return gfx::Rect(top_left_x, top_left_y, width, height);
30 return gfx::Rect(data[0], data[1], data[0] + data[2], data[1] + data[3]);
31 } 58 }
32 59
33 // static 60 // static
34 gfx::Rect Screen::GetMonitorWorkAreaNearestWindow(gfx::NativeView view) { 61 gfx::Rect Screen::GetMonitorWorkAreaNearestWindow(gfx::NativeView view) {
35 // TODO(beng): use |view|. 62 // TODO(beng): use |view|.
36 return GetPrimaryMonitorBounds(); 63 return GetPrimaryMonitorBounds();
37 } 64 }
38 65
39 // static 66 // static
40 gfx::Rect Screen::GetMonitorAreaNearestWindow(gfx::NativeView view) { 67 gfx::Rect Screen::GetMonitorAreaNearestWindow(gfx::NativeView view) {
(...skipping 26 matching lines...) Expand all
67 gdk_window_get_user_data(window, &data); 94 gdk_window_get_user_data(window, &data);
68 GtkWidget* widget = reinterpret_cast<GtkWidget*>(data); 95 GtkWidget* widget = reinterpret_cast<GtkWidget*>(data);
69 if (!widget) 96 if (!widget)
70 return NULL; 97 return NULL;
71 widget = gtk_widget_get_toplevel(widget); 98 widget = gtk_widget_get_toplevel(widget);
72 return GTK_IS_WINDOW(widget) ? GTK_WINDOW(widget) : NULL; 99 return GTK_IS_WINDOW(widget) ? GTK_WINDOW(widget) : NULL;
73 } 100 }
74 101
75 } // namespace 102 } // namespace
76 103
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698