Changeset View
Changeset View
Standalone View
Standalone View
xcbutils.h
Show First 20 Lines • Show All 170 Lines • ▼ Show 20 Line(s) | |||||
171 | * @see XCB_WRAPPER | 171 | * @see XCB_WRAPPER | ||
172 | * @see Wrapper | 172 | * @see Wrapper | ||
173 | * @see WindowAttributes | 173 | * @see WindowAttributes | ||
174 | * @see OverlayWindow | 174 | * @see OverlayWindow | ||
175 | * @see WindowGeometry | 175 | * @see WindowGeometry | ||
176 | * @see Tree | 176 | * @see Tree | ||
177 | * @see CurrentInput | 177 | * @see CurrentInput | ||
178 | * @see TransientFor | 178 | * @see TransientFor | ||
179 | */ | 179 | **/ | ||
180 | template <typename Reply, | 180 | template <typename Reply, | ||
181 | typename Cookie, | 181 | typename Cookie, | ||
182 | typename... Args> | 182 | typename... Args> | ||
183 | struct WrapperData | 183 | struct WrapperData | ||
184 | { | 184 | { | ||
185 | /** | 185 | /** | ||
186 | * @brief The type returned by the xcb reply function. | 186 | * @brief The type returned by the xcb reply function. | ||
187 | */ | 187 | **/ | ||
188 | typedef Reply reply_type; | 188 | typedef Reply reply_type; | ||
189 | /** | 189 | /** | ||
190 | * @brief The type returned by the xcb request function. | 190 | * @brief The type returned by the xcb request function. | ||
191 | */ | 191 | **/ | ||
192 | typedef Cookie cookie_type; | 192 | typedef Cookie cookie_type; | ||
193 | /** | 193 | /** | ||
194 | * @brief Variadic arguments combined as a std::tuple. | 194 | * @brief Variadic arguments combined as a std::tuple. | ||
195 | * @internal Used for verifying the arguments. | 195 | * @internal Used for verifying the arguments. | ||
196 | */ | 196 | **/ | ||
197 | typedef std::tuple<Args...> argument_types; | 197 | typedef std::tuple<Args...> argument_types; | ||
198 | /** | 198 | /** | ||
199 | * @brief The function pointer definition for the xcb request function. | 199 | * @brief The function pointer definition for the xcb request function. | ||
200 | */ | 200 | **/ | ||
201 | typedef Cookie (*request_func)(xcb_connection_t*, Args...); | 201 | typedef Cookie (*request_func)(xcb_connection_t*, Args...); | ||
202 | /** | 202 | /** | ||
203 | * @brief The function pointer definition for the xcb reply function. | 203 | * @brief The function pointer definition for the xcb reply function. | ||
204 | */ | 204 | **/ | ||
205 | typedef Reply *(*reply_func)(xcb_connection_t*, Cookie, xcb_generic_error_t**); | 205 | typedef Reply *(*reply_func)(xcb_connection_t*, Cookie, xcb_generic_error_t**); | ||
206 | /** | 206 | /** | ||
207 | * @brief Number of variadic arguments. | 207 | * @brief Number of variadic arguments. | ||
208 | * @internal Used for verifying the arguments. | 208 | * @internal Used for verifying the arguments. | ||
209 | */ | 209 | **/ | ||
210 | static constexpr std::size_t argumentCount = sizeof...(Args); | 210 | static constexpr std::size_t argumentCount = sizeof...(Args); | ||
211 | }; | 211 | }; | ||
212 | 212 | | |||
213 | /** | 213 | /** | ||
214 | * @brief Partial template specialization for WrapperData with no further arguments. | 214 | * @brief Partial template specialization for WrapperData with no further arguments. | ||
215 | * | 215 | * | ||
216 | * This will be used for xcb requests just taking the xcb_connection_t* argument. | 216 | * This will be used for xcb requests just taking the xcb_connection_t* argument. | ||
217 | **/ | 217 | **/ | ||
Show All 9 Lines | 221 | { | |||
227 | static constexpr std::size_t argumentCount = 0; | 227 | static constexpr std::size_t argumentCount = 0; | ||
228 | }; | 228 | }; | ||
229 | 229 | | |||
230 | /** | 230 | /** | ||
231 | * @brief Abstract base class for the wrapper. | 231 | * @brief Abstract base class for the wrapper. | ||
232 | * | 232 | * | ||
233 | * This class contains the complete functionality of the Wrapper. It's only an abstract | 233 | * This class contains the complete functionality of the Wrapper. It's only an abstract | ||
234 | * base class to provide partial template specialization for more specific constructors. | 234 | * base class to provide partial template specialization for more specific constructors. | ||
235 | */ | 235 | **/ | ||
236 | template<typename Data> | 236 | template<typename Data> | ||
237 | class AbstractWrapper | 237 | class AbstractWrapper | ||
238 | { | 238 | { | ||
239 | public: | 239 | public: | ||
240 | typedef typename Data::cookie_type Cookie; | 240 | typedef typename Data::cookie_type Cookie; | ||
241 | typedef typename Data::reply_type Reply; | 241 | typedef typename Data::reply_type Reply; | ||
242 | virtual ~AbstractWrapper() { | 242 | virtual ~AbstractWrapper() { | ||
243 | cleanup(); | 243 | cleanup(); | ||
▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Line(s) | 338 | private: | |||
357 | WindowId m_window; | 357 | WindowId m_window; | ||
358 | Reply *m_reply; | 358 | Reply *m_reply; | ||
359 | }; | 359 | }; | ||
360 | 360 | | |||
361 | /** | 361 | /** | ||
362 | * @brief Template to compare the arguments of two std::tuple. | 362 | * @brief Template to compare the arguments of two std::tuple. | ||
363 | * | 363 | * | ||
364 | * @internal Used by static_assert in Wrapper | 364 | * @internal Used by static_assert in Wrapper | ||
365 | */ | 365 | **/ | ||
366 | template <typename T1, typename T2, std::size_t I> | 366 | template <typename T1, typename T2, std::size_t I> | ||
367 | struct tupleCompare | 367 | struct tupleCompare | ||
368 | { | 368 | { | ||
369 | typedef typename std::tuple_element<I, T1>::type tuple1Type; | 369 | typedef typename std::tuple_element<I, T1>::type tuple1Type; | ||
370 | typedef typename std::tuple_element<I, T2>::type tuple2Type; | 370 | typedef typename std::tuple_element<I, T2>::type tuple2Type; | ||
371 | /** | 371 | /** | ||
372 | * @c true if both tuple have the same arguments, @c false otherwise. | 372 | * @c true if both tuple have the same arguments, @c false otherwise. | ||
373 | * | 373 | **/ | ||
374 | */ | | |||
375 | static constexpr bool value = std::is_same< tuple1Type, tuple2Type >::value && tupleCompare<T1, T2, I-1>::value; | 374 | static constexpr bool value = std::is_same< tuple1Type, tuple2Type >::value && tupleCompare<T1, T2, I-1>::value; | ||
376 | }; | 375 | }; | ||
377 | 376 | | |||
378 | /** | 377 | /** | ||
379 | * @brief Recursive template case for first tuple element. | 378 | * @brief Recursive template case for first tuple element. | ||
380 | */ | 379 | **/ | ||
381 | template <typename T1, typename T2> | 380 | template <typename T1, typename T2> | ||
382 | struct tupleCompare<T1, T2, 0> | 381 | struct tupleCompare<T1, T2, 0> | ||
383 | { | 382 | { | ||
384 | typedef typename std::tuple_element<0, T1>::type tuple1Type; | 383 | typedef typename std::tuple_element<0, T1>::type tuple1Type; | ||
385 | typedef typename std::tuple_element<0, T2>::type tuple2Type; | 384 | typedef typename std::tuple_element<0, T2>::type tuple2Type; | ||
386 | static constexpr bool value = std::is_same< tuple1Type, tuple2Type >::value; | 385 | static constexpr bool value = std::is_same< tuple1Type, tuple2Type >::value; | ||
387 | }; | 386 | }; | ||
388 | 387 | | |||
389 | /** | 388 | /** | ||
390 | * @brief Wrapper taking a WrapperData as first template argument and xcb request args as variadic args. | 389 | * @brief Wrapper taking a WrapperData as first template argument and xcb request args as variadic args. | ||
391 | */ | 390 | **/ | ||
392 | template<typename Data, typename... Args> | 391 | template<typename Data, typename... Args> | ||
393 | class Wrapper : public AbstractWrapper<Data> | 392 | class Wrapper : public AbstractWrapper<Data> | ||
394 | { | 393 | { | ||
395 | public: | 394 | public: | ||
396 | static_assert(!std::is_same<Data, Xcb::WrapperData<typename Data::reply_type, typename Data::cookie_type, Args...> >::value, | 395 | static_assert(!std::is_same<Data, Xcb::WrapperData<typename Data::reply_type, typename Data::cookie_type, Args...> >::value, | ||
397 | "Data template argument must be derived from WrapperData"); | 396 | "Data template argument must be derived from WrapperData"); | ||
398 | static_assert(std::is_base_of<Xcb::WrapperData<typename Data::reply_type, typename Data::cookie_type, Args...>, Data>::value, | 397 | static_assert(std::is_base_of<Xcb::WrapperData<typename Data::reply_type, typename Data::cookie_type, Args...>, Data>::value, | ||
399 | "Data template argument must be derived from WrapperData"); | 398 | "Data template argument must be derived from WrapperData"); | ||
▲ Show 20 Lines • Show All 276 Lines • ▼ Show 20 Line(s) | 650 | public: | |||
676 | * Uses the type which got passed into the ctor and derives the format from the sizeof(T). | 675 | * Uses the type which got passed into the ctor and derives the format from the sizeof(T). | ||
677 | * Note: for the automatic format detection the size of the type T may not vary between | 676 | * Note: for the automatic format detection the size of the type T may not vary between | ||
678 | * architectures. Thus one needs to use e.g. uint32_t instead of long. In general all xcb | 677 | * architectures. Thus one needs to use e.g. uint32_t instead of long. In general all xcb | ||
679 | * data types can be used, all Xlib data types can not be used. | 678 | * data types can be used, all Xlib data types can not be used. | ||
680 | * | 679 | * | ||
681 | * @param defaultValue The default value to return in case of error | 680 | * @param defaultValue The default value to return in case of error | ||
682 | * @param ok Set to @c false in case of error, @c true in case of success | 681 | * @param ok Set to @c false in case of error, @c true in case of success | ||
683 | * @return The read value or @p defaultValue in error case | 682 | * @return The read value or @p defaultValue in error case | ||
684 | */ | 683 | **/ | ||
685 | template <typename T> | 684 | template <typename T> | ||
686 | inline typename std::enable_if<!std::is_pointer<T>::value, T>::type value(T defaultValue = T(), bool *ok = nullptr) { | 685 | inline typename std::enable_if<!std::is_pointer<T>::value, T>::type value(T defaultValue = T(), bool *ok = nullptr) { | ||
687 | return value<T>(sizeof(T) * 8, m_type, defaultValue, ok); | 686 | return value<T>(sizeof(T) * 8, m_type, defaultValue, ok); | ||
688 | } | 687 | } | ||
689 | /** | 688 | /** | ||
690 | * @brief Reads the property as a POD type. | 689 | * @brief Reads the property as a POD type. | ||
691 | * | 690 | * | ||
692 | * Returns the first value of the property data. In case of @p format or @p type mismatch | 691 | * Returns the first value of the property data. In case of @p format or @p type mismatch | ||
Show All 21 Lines | |||||
714 | * Uses the type which got passed into the ctor and derives the format from the sizeof(T). | 713 | * Uses the type which got passed into the ctor and derives the format from the sizeof(T). | ||
715 | * Note: for the automatic format detection the size of the type T may not vary between | 714 | * Note: for the automatic format detection the size of the type T may not vary between | ||
716 | * architectures. Thus one needs to use e.g. uint32_t instead of long. In general all xcb | 715 | * architectures. Thus one needs to use e.g. uint32_t instead of long. In general all xcb | ||
717 | * data types can be used, all Xlib data types can not be used. | 716 | * data types can be used, all Xlib data types can not be used. | ||
718 | * | 717 | * | ||
719 | * @param defaultValue The default value to return in case of error | 718 | * @param defaultValue The default value to return in case of error | ||
720 | * @param ok Set to @c false in case of error, @c true in case of success | 719 | * @param ok Set to @c false in case of error, @c true in case of success | ||
721 | * @return The read value or @p defaultValue in error case | 720 | * @return The read value or @p defaultValue in error case | ||
722 | */ | 721 | **/ | ||
723 | template <typename T> | 722 | template <typename T> | ||
724 | inline typename std::enable_if<std::is_pointer<T>::value, T>::type value(T defaultValue = nullptr, bool *ok = nullptr) { | 723 | inline typename std::enable_if<std::is_pointer<T>::value, T>::type value(T defaultValue = nullptr, bool *ok = nullptr) { | ||
725 | return value<T>(sizeof(typename std::remove_pointer<T>::type) * 8, m_type, defaultValue, ok); | 724 | return value<T>(sizeof(typename std::remove_pointer<T>::type) * 8, m_type, defaultValue, ok); | ||
726 | } | 725 | } | ||
727 | /** | 726 | /** | ||
728 | * @brief Reads the property as an array of T. | 727 | * @brief Reads the property as an array of T. | ||
729 | * | 728 | * | ||
730 | * This method is an overload for the case that T is a pointer type. | 729 | * This method is an overload for the case that T is a pointer type. | ||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | |||||
802 | * between error case and a read @c false value. Use the optional argument @p ok to | 801 | * between error case and a read @c false value. Use the optional argument @p ok to | ||
803 | * distinguish the error case. | 802 | * distinguish the error case. | ||
804 | * | 803 | * | ||
805 | * @param format Expected format. Defaults to 32. | 804 | * @param format Expected format. Defaults to 32. | ||
806 | * @param type Expected type Defaults to XCB_ATOM_CARDINAL. | 805 | * @param type Expected type Defaults to XCB_ATOM_CARDINAL. | ||
807 | * @param ok Set to @c false in case of error, @c true in case of success | 806 | * @param ok Set to @c false in case of error, @c true in case of success | ||
808 | * @return bool The first element interpreted as a boolean value or @c false in error case | 807 | * @return bool The first element interpreted as a boolean value or @c false in error case | ||
809 | * @see value | 808 | * @see value | ||
810 | */ | 809 | **/ | ||
811 | inline bool toBool(uint8_t format = 32, xcb_atom_t type = XCB_ATOM_CARDINAL, bool *ok = nullptr) { | 810 | inline bool toBool(uint8_t format = 32, xcb_atom_t type = XCB_ATOM_CARDINAL, bool *ok = nullptr) { | ||
812 | bool *reply = value<bool*>(format, type, nullptr, ok); | 811 | bool *reply = value<bool*>(format, type, nullptr, ok); | ||
813 | if (!reply) { | 812 | if (!reply) { | ||
814 | return false; | 813 | return false; | ||
815 | } | 814 | } | ||
816 | if (data()->value_len != 1) { | 815 | if (data()->value_len != 1) { | ||
817 | if (ok) { | 816 | if (ok) { | ||
818 | *ok = false; | 817 | *ok = false; | ||
▲ Show 20 Lines • Show All 1006 Lines • ▼ Show 20 Line(s) | |||||
1825 | 1824 | | |||
1826 | void selectInput(xcb_window_t window, uint32_t events) | 1825 | void selectInput(xcb_window_t window, uint32_t events) | ||
1827 | { | 1826 | { | ||
1828 | xcb_change_window_attributes(connection(), window, XCB_CW_EVENT_MASK, &events); | 1827 | xcb_change_window_attributes(connection(), window, XCB_CW_EVENT_MASK, &events); | ||
1829 | } | 1828 | } | ||
1830 | 1829 | | |||
1831 | /** | 1830 | /** | ||
1832 | * @brief Small helper class to encapsulate SHM related functionality. | 1831 | * @brief Small helper class to encapsulate SHM related functionality. | ||
1833 | * | 1832 | **/ | ||
1834 | */ | | |||
1835 | class Shm | 1833 | class Shm | ||
1836 | { | 1834 | { | ||
1837 | public: | 1835 | public: | ||
1838 | Shm(); | 1836 | Shm(); | ||
1839 | ~Shm(); | 1837 | ~Shm(); | ||
1840 | int shmId() const; | 1838 | int shmId() const; | ||
1841 | void *buffer() const; | 1839 | void *buffer() const; | ||
1842 | xcb_shm_seg_t segment() const; | 1840 | xcb_shm_seg_t segment() const; | ||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |