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

Side by Side Diff: ui/base/x/x11_util.cc

Issue 6386009: Remove app/win/win_util.h,cc etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with NSApp changes in r73581 Created 9 years, 10 months 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 | « ui/base/x/x11_util.h ('k') | views/controls/textfield/native_textfield_win.h » ('j') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // This file defines utility functions for X11 (Linux only). This code has been 5 // This file defines utility functions for X11 (Linux only). This code has been
6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support 6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support
7 // remains woefully incomplete. 7 // remains woefully incomplete.
8 8
9 #include "ui/base/x/x11_util.h" 9 #include "ui/base/x/x11_util.h"
10 10
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 return false; 680 return false;
681 681
682 gdk_error_trap_push(); 682 gdk_error_trap_push();
683 result = GetStringProperty( 683 result = GetStringProperty(
684 static_cast<XID>(wm_window), "_NET_WM_NAME", wm_name); 684 static_cast<XID>(wm_window), "_NET_WM_NAME", wm_name);
685 gdk_flush(); 685 gdk_flush();
686 got_error = gdk_error_trap_pop(); 686 got_error = gdk_error_trap_pop();
687 return !got_error && result; 687 return !got_error && result;
688 } 688 }
689 689
690 static cairo_status_t SnapshotCallback(
691 void *closure, const unsigned char *data, unsigned int length) {
692 std::vector<unsigned char>* png_representation =
693 static_cast<std::vector<unsigned char>*>(closure);
694
695 size_t old_size = png_representation->size();
696 png_representation->resize(old_size + length);
697 memcpy(&(*png_representation)[old_size], data, length);
698 return CAIRO_STATUS_SUCCESS;
699 }
700
701 void GrabWindowSnapshot(GtkWindow* gtk_window,
702 std::vector<unsigned char>* png_representation) {
703 GdkWindow* gdk_window = GTK_WIDGET(gtk_window)->window;
704 Display* display = GDK_WINDOW_XDISPLAY(gdk_window);
705 XID win = GDK_WINDOW_XID(gdk_window);
706 XWindowAttributes attr;
707 if (XGetWindowAttributes(display, win, &attr) == 0) {
708 LOG(ERROR) << "Couldn't get window attributes";
709 return;
710 }
711 XImage* image = XGetImage(
712 display, win, 0, 0, attr.width, attr.height, AllPlanes, ZPixmap);
713 if (!image) {
714 LOG(ERROR) << "Couldn't get image";
715 return;
716 }
717 if (image->depth != 24) {
718 LOG(ERROR)<< "Unsupported image depth " << image->depth;
719 return;
720 }
721 cairo_surface_t* surface =
722 cairo_image_surface_create_for_data(
723 reinterpret_cast<unsigned char*>(image->data),
724 CAIRO_FORMAT_RGB24,
725 image->width,
726 image->height,
727 image->bytes_per_line);
728
729 if (!surface) {
730 LOG(ERROR) << "Unable to create Cairo surface from XImage data";
731 return;
732 }
733 cairo_surface_write_to_png_stream(
734 surface, SnapshotCallback, png_representation);
735 cairo_surface_destroy(surface);
736 }
737
738 bool ChangeWindowDesktop(XID window, XID destination) { 690 bool ChangeWindowDesktop(XID window, XID destination) {
739 int desktop; 691 int desktop;
740 if (!GetWindowDesktop(destination, &desktop)) 692 if (!GetWindowDesktop(destination, &desktop))
741 return false; 693 return false;
742 694
743 // If |window| is sticky, use the current desktop. 695 // If |window| is sticky, use the current desktop.
744 if (desktop == kAllDesktops && 696 if (desktop == kAllDesktops &&
745 !GetCurrentDesktop(&desktop)) 697 !GetCurrentDesktop(&desktop))
746 return false; 698 return false;
747 699
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 "X Error detected: serial %lu, error_code %u (%s), " 862 "X Error detected: serial %lu, error_code %u (%s), "
911 "request_code %u minor_code %u (%s)", 863 "request_code %u minor_code %u (%s)",
912 error_event->serial, error_event->error_code, error_str, 864 error_event->serial, error_event->error_code, error_str,
913 error_event->request_code, error_event->minor_code, request_str); 865 error_event->request_code, error_event->minor_code, request_str);
914 } 866 }
915 // ---------------------------------------------------------------------------- 867 // ----------------------------------------------------------------------------
916 // End of x11_util_internal.h 868 // End of x11_util_internal.h
917 869
918 870
919 } // namespace ui 871 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/x/x11_util.h ('k') | views/controls/textfield/native_textfield_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698