YSTest: XCB.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

XCB.h
浏览该文件的文档.
1 /*
2 © 2014-2015, 2018 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
29 #ifndef YCL_INC_XCB_h_
30 #define YCL_INC_XCB_h_ 1
31
32 #include "YCLib/YModules.h"
33 #include YFM_YCLib_Platform
34 #if YF_Use_XCB
35 // #include <xcb/xcb.h>
36 # include YFM_YCLib_Host // for platform::string, platform::string_view,
37 // platform_ex::Exception;
38 # include YFM_YCLib_Debug // for platform::Deref;
39 # include <ystdex/pointer.hpp> // for ystdex::nptr;
40 # include YFM_YSLib_Core_YGraphics
41 # include YFM_YSLib_Core_YEvent
42 # include <atomic>
43
45
46 struct xcb_connection_t;
47 struct xcb_auth_info_t;
48 struct xcb_setup_t;
50 struct xcb_screen_t;
52
53 namespace platform_ex
54 {
55
57 namespace XCB
58 {
59
61 using platform::string_view;
62
64 class YF_API XCBException : public Exception
65 {
66 private:
68
69 std::uint8_t error_code;
70 std::uint16_t sequence;
71 std::uint32_t resource_id;
72 std::uint16_t minor_code;
73 std::uint8_t major_code;
74 std::uint32_t full_sequence;
76
77 public:
83 YB_NONNULL(2)
84 XCBException(const char*, std::uint8_t, std::uint8_t, std::uint16_t,
85 std::uint32_t, std::uint16_t, std::uint8_t, std::uint32_t,
86 YSLib::RecordLevel = YSLib::Emergent);
87 XCBException(string_view, std::uint8_t, std::uint8_t, std::uint16_t,
88 std::uint32_t, std::uint16_t, std::uint8_t, std::uint32_t,
89 YSLib::RecordLevel = YSLib::Emergent);
91 DefDeCopyCtor(XCBException)
97 ~XCBException() override;
98
100 DefDeCopyAssignment(XCBException)
101
103
104 DefGetter(const ynothrow, std::uint8_t, ErrorCode, error_code)
105 DefGetter(const ynothrow, std::uint8_t, FullSequence, full_sequence)
106 DefGetter(const ynothrow, std::uint8_t, MajorCode, major_code)
107 DefGetter(const ynothrow, std::uint16_t, MinorCode, minor_code)
108 DefGetter(const ynothrow, std::uint8_t, ResponseType,
109 std::uint8_t(code().value()))
110 DefGetter(const ynothrow, std::uint32_t, ResourceID, resource_id)
111 DefGetter(const ynothrow, std::uint16_t, Sequence, sequence)
113 };
114
115
120 class YF_API ConnectionReference : private tidy_ptr<::xcb_connection_t>
121 {
122 public:
123 using NativeHandle = typename tidy_ptr<::xcb_connection_t>::pointer;
124
126 using tidy_ptr<::xcb_connection_t>::tidy_ptr;
127 DefDeCopyMoveCtorAssignment(ConnectionReference)
128
129
130
131 DefPred(const ynothrow, OnError, GetError() != 0)
133
134
138 int
139 GetError() const ynothrow;
141 int
142 GetFileDescriptor() const ynothrow;
149 const ::xcb_setup_t&
150 GetSetup() const;
151
157 void
158 Check() const;
160 std::uint32_t
161 GenerateID() const ynothrow;
163
165 using tidy_ptr<::xcb_connection_t>::get;
166 };
167
168
173 class YF_API Connection final : private ConnectionReference,
174 private YSLib::noncopyable, private YSLib::nonmovable
175 {
176 private:
178 shared_ptr<void> p_shared;
179
180 public:
182
183
188 Connection(const char* = {}, int* = {});
194 Connection(::xcb_auth_info_t*, const char* = {}, int* = {});
199 explicit
200 Connection(ConnectionReference);
202 ~Connection();
204
205 DefBoolNeg(explicit, !IsOnError())
206
207 using ConnectionReference::IsOnError;
208
210 using ConnectionReference::GetError;
211 using ConnectionReference::GetFileDescriptor;
212 using ConnectionReference::GetSetup;
213
215 using ConnectionReference::Check;
216 using ConnectionReference::GenerateID;
217
219 using ConnectionReference::get;
220 };
221
222
224 class YF_API Atom final
225 {
226 public:
228 using NativeType = std::uint32_t;
229
230 private:
231 std::uint32_t atom;
232
233 public:
238 explicit
239 Atom(::xcb_connection_t&, string_view, bool = {}) ynothrowv;
240
241 DefCvt(const ynothrow, NativeType, atom)
242 };
243
244
250 YF_API Atom::NativeType
251 LookupAtom(::xcb_connection_t&, const YSLib::string&);
252
253
258 class YF_API Drawable
259 {
260 public:
265 using ID = std::uint32_t;
266
267 private:
268 ConnectionReference conn_ref;
269 ID id;
270
271 protected:
272 Drawable(::xcb_connection_t& c_ref) ynothrow
273 : conn_ref(make_observer(&c_ref)), id(conn_ref.GenerateID())
274 {}
275 DefDeDtor(Drawable)
276
277 public:
278 DefGetter(const ynothrow, ConnectionReference, ConnectionRef, conn_ref)
279 DefGetter(const ynothrow, ID, ID, id)
280
281 PDefH(::xcb_connection_t&, DerefConn, ) const ynothrow
282 ImplRet(platform::Deref(conn_ref.get()))
283 };
284
285
287 class YF_API WindowData final : public Drawable
288 {
289 public:
300 WindowData(::xcb_connection_t&, const YSLib::Drawing::Rect&);
302 WindowData(::xcb_connection_t&, const YSLib::Drawing::Rect&,
303 const ::xcb_screen_t&);
305 WindowData(::xcb_connection_t&, const YSLib::Drawing::Rect&, ID);
307
311 ~WindowData();
312
314
315 YSLib::Drawing::Rect
316 GetBounds() const;
317 DefGetter(const, YSLib::Drawing::Point, Location, GetBounds().GetPoint())
318 DefGetter(const, YSLib::Drawing::Size, Size, GetBounds().GetSize())
319
320 void
321 SetBounds(const YSLib::Drawing::Rect&);
323
325 void
326 Close();
327
328 void
329 Hide();
330
332
333 PDefH(void, Invalidate, )
334 ImplExpr(Invalidate(GetBounds()))
335 void
336 Invalidate(const YSLib::Drawing::Rect&);
337
339 PDefH(Atom::NativeType, LookupAtom, const YSLib::string& name)
340 ImplRet(XCB::LookupAtom(DerefConn(), name))
341
342 void
343 Move(const YSLib::Drawing::Point&);
344
345 void
346 Resize(const YSLib::Drawing::Size&);
347
348 void
349 Show();
351 };
352
353
358 class YF_API GContext final : public Drawable, private YSLib::noncopyable
359 {
360 public:
361 GContext(::xcb_connection_t& c_ref) ynothrow
362 : Drawable(c_ref)
363 {}
364 ~GContext();
365 };
366
367
369 YF_API void
370 UpdatePixmapBuffer(WindowData&, const YSLib::Drawing::Rect&,
371 const YSLib::Drawing::ConstGraphics&);
372
373 } // namespace XCB;
374
375 } // namespace platform_ex;
376
377 #endif
378
379 #endif
380
DefPred
#define DefPred(_q, _n,...)
Definition: YBaseMacro.h:232
ystdex::tidy_ptr
nptr< observer_ptr< _type > > tidy_ptr
Definition: pointer.hpp:415
YSLib::UI::Hide
YF_API void Hide(IWidget &)
隐藏部件。
Definition: YWidget.cpp:100
platform_ex::Windows::PDefH
YB_ATTR_nodiscard YB_STATELESS yconstfn PDefH(bool, IsDirectory, FileAttributes attr) ynothrow ImplRet(attr &Directory) YB_ATTR_nodiscard YB_STATELESS inline PDefH(bool
判断 FileAttributes 是否指定目录。
ystdex::cpp2017::basic_string
Definition: string.hpp:77
platform_ex
平台扩展命名空间。
Definition: Android.h:46
platform::Descriptions::Emergent
@ Emergent
Definition: YCommon.h:179
ystdex::noncopyable
bases::noncopyable noncopyable
Definition: base.h:215
platform::Descriptions::RecordLevel
RecordLevel
记录等级。
Definition: YCommon.h:178
ystdex::cpp2017::string_view
basic_string_view< char > string_view
Definition: string_view.hpp:437
YSLib::IO::int
YF_API int
Definition: File.h:51
platform_ex::YB_NONNULL
YB_ATTR_nodiscard YB_NONNULL(1) inline PDefH(u16string
构造适合表示路径的 char16_t 字符串。
pointer.hpp
通用指针。
YF_API
#define YF_API
Definition: Platform.h:56
YSLib::UI::Move
@ Move
移动：位置调整。
Definition: YWidgetEvent.h:381
YSLib::UI::Invalidate
YF_API void Invalidate(IWidget &, const Rect &)
无效化：使相对部件的指定区域在直接和间接的窗口缓冲区中无效。
Definition: YWidget.cpp:108
DefBoolNeg
#define DefBoolNeg(_spec,...)
定义表示显式转换 bool 操作符及其否定的 operator! 。
Definition: YBaseMacro.h:228
DefDeDtor
#define DefDeDtor(_t)
Definition: YBaseMacro.h:177
YSLib::UI::Show
YF_API void Show(IWidget &)
显示部件。
Definition: YWidget.cpp:202
DefDeCopyMoveCtorAssignment
#define DefDeCopyMoveCtorAssignment(_t)
Definition: YBaseMacro.h:202
YSLib::Drawing::GGraphics
二维图形接口上下文模板。
Definition: YGraphics.h:63
ystdex::make_observer
observer_ptr< _type > make_observer(_type *p)
Definition: pointer.hpp:405
YSLib::Drawing::Point
GBinaryGroup< SPos > Point
屏幕二维点（直角坐标表示）。
Definition: YGDIBase.h:520
std
Definition: optional.h:982
YSLib::Drawing::GBinaryGroup< SPos >
YSLib::Drawing::GetSize
dst GetSize()
YSLib::UI::Close
void Close(IWidget &wgt)
Definition: YWidget.cpp:92
YSLib::UI::Resize
@ Resize
大小调整。
Definition: YWidgetEvent.h:383
YSLib::Drawing::Rect
屏幕标准矩形：表示屏幕矩形区域。
Definition: YGDIBase.h:788
platform
默认平台命名空间。
Definition: Container.h:56
NPL::A1::Forms::Sequence
YF_API ReductionStatus Sequence(TermNode &, ContextNode &)
序列有序参数规约：移除第一项后顺序规约子项，结果为最后一个子项的规约结果。
Definition: NPLA1Forms.cpp:2605
DefDeCopyAssignment
#define DefDeCopyAssignment(_t)
Definition: YBaseMacro.h:186
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:46
NPL::A1::name
const char * name
Definition: NPLA1.h:1876
platform::Deref
YB_PURE yconstfn auto Deref(_type &&p) -> decltype(*p)
断言并解引用非空指针。
Definition: Debug.h:547
ynothrowv
#define ynothrowv
YSLib 无异常抛出保证验证：有条件地使用无异常抛出规范。
Definition: ydef.h:1219
DefDeCopyCtor
#define DefDeCopyCtor(_t)
Definition: YBaseMacro.h:162
YModules.h
YCLib 库模块配置文件。
DefCvt
#define DefCvt(_q, _t,...)
Definition: YBaseMacro.h:206
ImplExpr
#define ImplExpr(...)
简单通用函数实现。
Definition: YBaseMacro.h:96
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:241
ystdex::nonmovable
bases::nonmovable nonmovable
Definition: base.h:217
platform::ID
std::uintmax_t ID
YF_Platform_* 宏替换值的公共类型。
Definition: YCommon.h:54
const
const Decapsulate const Decapsulate &y ynothrow ContextNode &ctx const
Definition: NPLA1Forms.cpp:1629
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:1199
platform_ex::Windows::ErrorCode
unsigned long ErrorCode
Definition: Win32/include/YCLib/MinGW32.h:58
platform_ex::ImplRet
YB_ATTR_nodiscard const char16_t *s ImplRet(platform::Nonnull(s)) YB_ATTR_nodiscard inline PDefH(const u16string &
NPL::get
PDefH(void, LiftTermRef, TermNode &term, const TermNode &tm) ImplExpr(NPL ref get()
Definition: NPLA.h:1737