1 // Copyright 2016 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "ui/base/x/x11_cursor.h" 6 7 #include "ui/base/x/x11_cursor_loader.h" 8 #include "ui/gfx/x/connection.h" 9 #include "ui/gfx/x/xproto.h" 10 11 namespace ui { 12 13 X11Cursor::X11Cursor() = default; 14 X11Cursor(x11::Cursor cursor)15X11Cursor::X11Cursor(x11::Cursor cursor) : loaded_(true), xcursor_(cursor) {} 16 OnCursorLoaded(Callback callback)17void X11Cursor::OnCursorLoaded(Callback callback) { 18 if (loaded_) 19 std::move(callback).Run(xcursor_); 20 else 21 callbacks_.push_back(std::move(callback)); 22 } 23 SetCursor(x11::Cursor cursor)24void X11Cursor::SetCursor(x11::Cursor cursor) { 25 DCHECK(!loaded_); 26 loaded_ = true; 27 xcursor_ = cursor; 28 for (auto& callback : callbacks_) 29 std::move(callback).Run(cursor); 30 callbacks_.clear(); 31 } 32 ReleaseCursor()33x11::Cursor X11Cursor::ReleaseCursor() { 34 return std::exchange(xcursor_, x11::Cursor::None); 35 } 36 ~X11Cursor()37X11Cursor::~X11Cursor() { 38 if (xcursor_ != x11::Cursor::None) 39 x11::Connection::Get()->FreeCursor({xcursor_}); 40 } 41 42 } // namespace ui 43