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

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: Code cleanup Created 9 years, 11 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
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 674 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 return false; 685 return false;
686 686
687 gdk_error_trap_push(); 687 gdk_error_trap_push();
688 result = GetStringProperty( 688 result = GetStringProperty(
689 static_cast<XID>(wm_window), "_NET_WM_NAME", wm_name); 689 static_cast<XID>(wm_window), "_NET_WM_NAME", wm_name);
690 gdk_flush(); 690 gdk_flush();
691 got_error = gdk_error_trap_pop(); 691 got_error = gdk_error_trap_pop();
692 return !got_error && result; 692 return !got_error && result;
693 } 693 }
694 694
695 static cairo_status_t SnapshotCallback(
696 void *closure, const unsigned char *data, unsigned int length) {
697 std::vector<unsigned char>* png_representation =
698 static_cast<std::vector<unsigned char>*>(closure);
699
700 size_t old_size = png_representation->size();
701 png_representation->resize(old_size + length);
702 memcpy(&(*png_representation)[old_size], data, length);
703 return CAIRO_STATUS_SUCCESS;
704 }
705
706 void GrabWindowSnapshot(GtkWindow* gtk_window,
707 std::vector<unsigned char>* png_representation) {
708 GdkWindow* gdk_window = GTK_WIDGET(gtk_window)->window;
709 Display* display = GDK_WINDOW_XDISPLAY(gdk_window);
710 XID win = GDK_WINDOW_XID(gdk_window);
711 XWindowAttributes attr;
712 if (XGetWindowAttributes(display, win, &attr) == 0) {
713 LOG(ERROR) << "Couldn't get window attributes";
714 return;
715 }
716 XImage* image = XGetImage(
717 display, win, 0, 0, attr.width, attr.height, AllPlanes, ZPixmap);
718 if (!image) {
719 LOG(ERROR) << "Couldn't get image";
720 return;
721 }
722 if (image->depth != 24) {
723 LOG(ERROR)<< "Unsupported image depth " << image->depth;
724 return;
725 }
726 cairo_surface_t* surface =
727 cairo_image_surface_create_for_data(
728 reinterpret_cast<unsigned char*>(image->data),
729 CAIRO_FORMAT_RGB24,
730 image->width,
731 image->height,
732 image->bytes_per_line);
733
734 if (!surface) {
735 LOG(ERROR) << "Unable to create Cairo surface from XImage data";
736 return;
737 }
738 cairo_surface_write_to_png_stream(
739 surface, SnapshotCallback, png_representation);
740 cairo_surface_destroy(surface);
741 }
742
743 bool ChangeWindowDesktop(XID window, XID destination) { 695 bool ChangeWindowDesktop(XID window, XID destination) {
744 int desktop; 696 int desktop;
745 if (!GetWindowDesktop(destination, &desktop)) 697 if (!GetWindowDesktop(destination, &desktop))
746 return false; 698 return false;
747 699
748 // If |window| is sticky, use the current desktop. 700 // If |window| is sticky, use the current desktop.
749 if (desktop == kAllDesktops && 701 if (desktop == kAllDesktops &&
750 !GetCurrentDesktop(&desktop)) 702 !GetCurrentDesktop(&desktop))
751 return false; 703 return false;
752 704
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 "X Error detected: serial %lu, error_code %u (%s), " 867 "X Error detected: serial %lu, error_code %u (%s), "
916 "request_code %u minor_code %u (%s)", 868 "request_code %u minor_code %u (%s)",
917 error_event->serial, error_event->error_code, error_str, 869 error_event->serial, error_event->error_code, error_str,
918 error_event->request_code, error_event->minor_code, request_str); 870 error_event->request_code, error_event->minor_code, request_str);
919 } 871 }
920 // ---------------------------------------------------------------------------- 872 // ----------------------------------------------------------------------------
921 // End of x11_util_internal.h 873 // End of x11_util_internal.h
922 874
923 875
924 } // namespace ui 876 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698