summaryrefslogtreecommitdiff
path: root/icccm/xcb_icccm.h
blob: 938fecb4baa43062f20941401c7c249a10fb6e8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
#ifndef __XCB_ICCCM_H__
#define __XCB_ICCCM_H__

/*
 * Copyright (C) 2008 Arnaud Fontaine <arnau@debian.org>
 * Copyright (C) 2007-2008 Vincent Torri <vtorri@univ-evry.fr>
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * Except as contained in this notice, the names of the authors or
 * their institutions shall not be used in advertising or otherwise to
 * promote the sale, use or other dealings in this Software without
 * prior written authorization from the authors.
 */

/**
 * @defgroup xcb__icccm_t XCB ICCCM Functions
 *
 * These functions allow easy handling of the protocol described in the
 * Inter-Client Communication Conventions Manual.
 *
 * @{
 */

#include <xcb/xcb.h>
#include "xcb_property.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @brief TextProperty reply structure.
 */
typedef struct {
  /** Store reply to avoid memory allocation, should normally not be
      used directly */
  xcb_get_property_reply_t *_reply;
  /** Encoding used */
  xcb_atom_t encoding;
  /** Length of the name field above */
  uint32_t name_len;
  /** Property value */
  char *name;
  /** Format, may be 8, 16 or 32 */
  uint8_t format;
} xcb_get_text_property_reply_t;

/**
 * @brief Deliver a GetProperty request to the X server.
 * @param c The connection to the X server.
 * @param window Window X identifier.
 * @param property Property atom to get.
 * @return The request cookie.
 *
 * Allow to get a window property, in most case you might want to use
 * above functions to get an ICCCM property for a given window.
 */
xcb_get_property_cookie_t xcb_get_text_property(xcb_connection_t *c,
                                                xcb_window_t window,
                                                xcb_atom_t property);

/**
 * @see xcb_get_text_property()
 */
xcb_get_property_cookie_t xcb_get_text_property_unchecked(xcb_connection_t *c,
                                                          xcb_window_t window,
                                                          xcb_atom_t property);

/**
 * @brief Fill given structure with the property value of a window.
 * @param c The connection to the X server.
 * @param cookie TextProperty request cookie.
 * @param prop TextProperty reply which is to be filled.
 * @param e Error if any.
 * @return Return 1 on success, 0 otherwise.
 *
 * If the function return 0 (failure), the content of prop is unmodified and
 * therefore the structure must not be wiped.
 *
 * The parameter e supplied to this function must be NULL if
 * xcb_get_text_property_unchecked() is used.  Otherwise, it stores
 * the error if any.  prop structure members should be freed by
 * xcb_get_text_property_reply_wipe().
 */
uint8_t xcb_get_text_property_reply(xcb_connection_t *c,
                                    xcb_get_property_cookie_t cookie,
                                    xcb_get_text_property_reply_t *prop,
                                    xcb_generic_error_t **e);

/**
 * @brief Wipe prop structure members previously allocated by
 *        xcb_get_text_property_reply().
 * @param prop prop structure whose members is going to be freed.
 */
void xcb_get_text_property_reply_wipe(xcb_get_text_property_reply_t *prop);

/* WM_NAME */

/**
 * @brief Deliver a SetProperty request to set WM_NAME property value.
 * @param c The connection to the X server.
 * @param window Window X identifier.
 * @param encoding Encoding used for the data passed in the name parameter, the set property will also have this encoding as its type.
 * @param name_len Length of name value to set.
 * @param name Name value to set.
 */
void xcb_set_wm_name_checked(xcb_connection_t *c,
                             xcb_window_t window,
                             xcb_atom_t encoding,
                             uint32_t name_len,
                             const char *name);

/**
 * @see xcb_set_wm_name_checked()
 */
void xcb_set_wm_name(xcb_connection_t *c, xcb_window_t window,
                     xcb_atom_t encoding, uint32_t name_len,
                     const char *name);

/**
 * @brief Deliver a GetProperty request to the X server for WM_NAME.
 * @param c The connection to the X server.
 * @param window Window X identifier.
 * @return The request cookie.
 */
xcb_get_property_cookie_t xcb_get_wm_name(xcb_connection_t *c,
                                          xcb_window_t window);

/**
 * @see xcb_get_wm_name()
 */
xcb_get_property_cookie_t xcb_get_wm_name_unchecked(xcb_connection_t *c,
                                                    xcb_window_t window);

/**
 * @brief Fill given structure with the WM_NAME property of a window.
 * @param c The connection to the X server.
 * @param cookie Request cookie.
 * @param prop WM_NAME property value.
 * @param e Error if any.
 * @see xcb_get_text_property_reply()
 * @return Return 1 on success, 0 otherwise.
 */
uint8_t xcb_get_wm_name_reply(xcb_connection_t *c,
                              xcb_get_property_cookie_t cookie,
                              xcb_get_text_property_reply_t *prop,
                              xcb_generic_error_t **e);

/**
 * @brief Set a callback on WM_NAME property changes.
 * @param prophs Property handlers.
 * @param long_len Length of data.
 * @param handler The callback.
 * @param data data given to the callback.
 */
void xcb_watch_wm_name(xcb_property_handlers_t *prophs, uint32_t long_len,
                       xcb_generic_property_handler_t handler, void *data);

/* WM_ICON_NAME */

/**
 * @brief Deliver a SetProperty request to set WM_ICON_NAME property value.
 * @param c The connection to the X server.
 * @param window Window X identifier.
 * @param encoding Encoding used for the data passed in the name parameter, the set property will also have this encoding as its type.
 * @param name_len Length of name value to set.
 * @param name Name value to set.
 */
void xcb_set_wm_icon_name_checked(xcb_connection_t *c, xcb_window_t window,
                                  xcb_atom_t encoding, uint32_t name_len,
                                  const char *name);

/**
 * @see xcb_set_wm_icon_name_checked()
 */
void xcb_set_wm_icon_name(xcb_connection_t *c, xcb_window_t window,
                          xcb_atom_t encoding, uint32_t name_len,
                          const char *name);

/**
 * @brief Send request to get WM_ICON_NAME property of a window.
 * @param c The connection to the X server.
 * @param window Window X identifier.
 * @return The request cookie.
 */
xcb_get_property_cookie_t xcb_get_wm_icon_name(xcb_connection_t *c,
                                               xcb_window_t window);

/**
  * @see xcb_get_wm_icon_name()
  */
xcb_get_property_cookie_t xcb_get_wm_icon_name_unchecked(xcb_connection_t *c,
                                                         xcb_window_t window);

/**
 * @brief Fill given structure with the WM_ICON_NAME property of a window.
 * @param c The connection to the X server.
 * @param cookie Request cookie.
 * @param prop WM_ICON_NAME property value.
 * @param e Error if any.
 * @see xcb_get_text_property_reply()
 * @return Return 1 on success, 0 otherwise.
 */
uint8_t xcb_get_wm_icon_name_reply(xcb_connection_t *c,
                                   xcb_get_property_cookie_t cookie,
                                   xcb_get_text_property_reply_t *prop,
                                   xcb_generic_error_t **e);

/**
 * @brief Set a callback on WM_ICON_NAME property changes.
 * @param prophs Property handlers.
 * @param long_len Length of data.
 * @param handler The callback.
 * @param data data given to the callback.
 */
void xcb_watch_wm_icon_name(xcb_property_handlers_t *prophs, uint32_t long_len,
                            xcb_generic_property_handler_t handler,
                            void *data);

/* WM_CLIENT_MACHINE */

/**
 * @brief Deliver a SetProperty request to set WM_CLIENT_MACHINE property value.
 * @param c The connection to the X server.
 * @param window Window X identifier.
 * @param encoding Encoding used for the data passed in the name parameter, the set property will also have this encoding as its type.
 * @param name_len Length of name value to set.
 * @param name Name value to set.
 */
void xcb_set_wm_client_machine_checked(xcb_connection_t *c, xcb_window_t window,
                                       xcb_atom_t encoding, uint32_t name_len,
                                       const char *name);

/**
 * @see xcb_set_wm_client_machine_checked()
 */
void xcb_set_wm_client_machine(xcb_connection_t *c, xcb_window_t window,
                               xcb_atom_t encoding, uint32_t name_len,
                               const char *name);

/**
 * @brief Send request to get WM_CLIENT_MACHINE property of a window.
 * @param c The connection to the X server.
 * @param window Window X identifier.
 * @return The request cookie.
 */
xcb_get_property_cookie_t xcb_get_wm_client_machine(xcb_connection_t *c,
                                                    xcb_window_t window);

/**
 * @see xcb_get_wm_client_machine()
 */
xcb_get_property_cookie_t xcb_get_wm_client_machine_unchecked(xcb_connection_t *c,
                                                              xcb_window_t window);

/**
 * @brief Fill given structure with the WM_CLIENT_MACHINE property of a window.
 * @param c The connection to the X server.
 * @param cookie Request cookie.
 * @param prop WM_CLIENT_MACHINE property value.
 * @param e Error if any.
 * @see xcb_get_text_property_reply()
 * @return Return 1 on success, 0 otherwise.
 */
uint8_t xcb_get_wm_client_machine_reply(xcb_connection_t *c,
                                        xcb_get_property_cookie_t cookie,
                                        xcb_get_text_property_reply_t *prop,
                                        xcb_generic_error_t **e);

/**
 * @brief Set a callback on WM_CLIENT_MACHINE property changes.
 * @param prophs Property handlers.
 * @param long_len Length of data.
 * @param handler The callback.
 * @param data data given to the callback.
 */
void xcb_watch_wm_client_machine(xcb_property_handlers_t *prophs,
                                 uint32_t long_len,
                                 xcb_generic_property_handler_t handler,
                                 void *data);

/* WM_CLASS */

/**
 * @brief WM_CLASS hint structure
 */
typedef struct {
  /** Instance name */
  char *instance_name;
  /** Class of application */
  char *class_name;
  /** Store reply to avoid memory allocation, should normally not be
      used directly */
  xcb_get_property_reply_t *_reply;
} xcb_get_wm_class_reply_t;

/**
 * @brief Deliver a GetProperty request to the X server for WM_CLASS.
 * @param c The connection to the X server.
 * @param window Window X identifier.
 * @return The request cookie.
 */
xcb_get_property_cookie_t xcb_get_wm_class(xcb_connection_t *c,
                                           xcb_window_t window);

/**
 * @see xcb_get_wm_class()
 */
xcb_get_property_cookie_t xcb_get_wm_class_unchecked(xcb_connection_t *c,
                                                     xcb_window_t window);


/**
 * @brief Fill give structure with the WM_CLASS property of a window.
 * @param prop The property structur to fill.
 * @param reply The property request reply.
 * @return Return 1 on success, 0 otherwise.
 */
uint8_t
xcb_get_wm_class_from_reply(xcb_get_wm_class_reply_t *prop,
                            xcb_get_property_reply_t *reply);

/**
 * @brief Fill given structure with the WM_CLASS property of a window.
 * @param c The connection to the X server.
 * @param cookie Request cookie.
 * @param prop WM_CLASS property value.
 * @param e Error if any.
 * @return Return 1 on success, 0 otherwise.
 *
 * The parameter e supplied to this function must be NULL if
 * xcb_get_wm_class_unchecked() is used.  Otherwise, it stores the
 * error if any. prop structure members should be freed by
 * xcb_get_wm_class_reply_wipe().
 */
uint8_t xcb_get_wm_class_reply(xcb_connection_t *c,
                               xcb_get_property_cookie_t cookie,
                               xcb_get_wm_class_reply_t *prop,
                               xcb_generic_error_t **e);

/**
 * @brief Wipe prop structure members previously allocated by
 *        xcb_get_wm_class_reply().
 * @param prop prop structure whose members is going to be freed.
 */
void xcb_get_wm_class_reply_wipe(xcb_get_wm_class_reply_t *prop);

/* WM_TRANSIENT_FOR */

/**
 * @brief Send request to get WM_TRANSIENT_FOR property of a window.
 * @param c The connection to the X server
 * @param window Window X identifier.
 * @return The request cookie.
 */
xcb_get_property_cookie_t xcb_get_wm_transient_for(xcb_connection_t *c,
                                                   xcb_window_t window);

/**
 * @see xcb_get_wm_transient_for_unchecked()
 */
xcb_get_property_cookie_t xcb_get_wm_transient_for_unchecked(xcb_connection_t *c,
                                                             xcb_window_t window);

/**
 * @brief Fill given window pointer with the WM_TRANSIENT_FOR property of a window.
 * @param prop WM_TRANSIENT_FOR property value.
 * @param reply The get property request reply.
 * @return Return 1 on success, 0 otherwise.
 */
uint8_t
xcb_get_wm_transient_for_from_reply(xcb_window_t *prop,
                                    xcb_get_property_reply_t *reply);
/**
 * @brief Fill given structure with the WM_TRANSIENT_FOR property of a window.
 * @param c The connection to the X server.
 * @param cookie Request cookie.
 * @param prop WM_TRANSIENT_FOR property value.
 * @param e Error if any.
 * @return Return 1 on success, 0 otherwise.
 *
 * The parameter e supplied to this function must be NULL if
 * xcb_get_wm_transient_for_unchecked() is used.  Otherwise, it stores
 * the error if any.
 */
uint8_t xcb_get_wm_transient_for_reply(xcb_connection_t *c,
                                       xcb_get_property_cookie_t cookie,
                                       xcb_window_t *prop,
                                       xcb_generic_error_t **e);

/* WM_SIZE_HINTS */

typedef enum {
  XCB_SIZE_HINT_US_POSITION = 1 << 0,
  XCB_SIZE_HINT_US_SIZE = 1 << 1,
  XCB_SIZE_HINT_P_POSITION = 1 << 2,
  XCB_SIZE_HINT_P_SIZE = 1 << 3,
  XCB_SIZE_HINT_P_MIN_SIZE = 1 << 4,
  XCB_SIZE_HINT_P_MAX_SIZE = 1 << 5,
  XCB_SIZE_HINT_P_RESIZE_INC = 1 << 6,
  XCB_SIZE_HINT_P_ASPECT = 1 << 7,
  XCB_SIZE_HINT_BASE_SIZE = 1 << 8,
  XCB_SIZE_HINT_P_WIN_GRAVITY = 1 << 9
} xcb_size_hints_flags_t;

/**
 * @brief Size hints structure.
 */
typedef struct {
  /** User specified flags */
  uint32_t flags;
  /** User-specified position */
  int32_t x, y;
  /** User-specified size */
  int32_t width, height;
  /** Program-specified minimum size */
  int32_t min_width, min_height;
  /** Program-specified maximum size */
  int32_t max_width, max_height;
  /** Program-specified resize increments */
  int32_t width_inc, height_inc;
  /** Program-specified minimum aspect ratios */
  int32_t min_aspect_num, min_aspect_den;
  /** Program-specified maximum aspect ratios */
  int32_t max_aspect_num, max_aspect_den;
  /** Program-specified base size */
  int32_t base_width, base_height;
  /** Program-specified window gravity */
  uint32_t win_gravity;
} xcb_size_hints_t;

/**
 * @brief Set size hints to a given position.
 * @param hints SIZE_HINTS structure.
 * @param user_specified Is the size user-specified?
 * @param x The X position.
 * @param y The Y position.
 */
void xcb_size_hints_set_position(xcb_size_hints_t *hints, int user_specified,
                                 int32_t x, int32_t y);

/**
 * @brief Set size hints to a given size.
 * @param hints SIZE_HINTS structure.
 * @param user_specified is the size user-specified?
 * @param width The width.
 * @param height The height.
 */
void xcb_size_hints_set_size(xcb_size_hints_t *hints, int user_specified,
                             int32_t width, int32_t height);

/**
 * @brief Set size hints to a given minimum size.
 * @param hints SIZE_HINTS structure.
 * @param width The minimum width.
 * @param height The minimum height.
 */
void xcb_size_hints_set_min_size(xcb_size_hints_t *hints, int32_t min_width,
                                 int32_t min_height);

/**
 * @brief Set size hints to a given maximum size.
 * @param hints SIZE_HINTS structure.
 * @param width The maximum width.
 * @param height The maximum height.
 */
void xcb_size_hints_set_max_size(xcb_size_hints_t *hints, int32_t max_width,
                                 int32_t max_height);

/**
 * @brief Set size hints to a given resize increments.
 * @param hints SIZE_HINTS structure.
 * @param width The resize increments width.
 * @param height The resize increments height.
 */
void xcb_size_hints_set_resize_inc(xcb_size_hints_t *hints, int32_t width_inc,
                                   int32_t height_inc);

/**
 * @brief Set size hints to a given aspect ratios.
 * @param hints SIZE_HINTS structure.
 * @param min_aspect_num The minimum aspect ratios for the width.
 * @param min_aspect_den The minimum aspect ratios for the height.
 * @param max_aspect_num The maximum aspect ratios for the width.
 * @param max_aspect_den The maximum aspect ratios for the height.
 */
void xcb_size_hints_set_aspect(xcb_size_hints_t *hints, int32_t min_aspect_num,
                               int32_t min_aspect_den, int32_t max_aspect_num,
                               int32_t max_aspect_den);

/**
 * @brief Set size hints to a given base size.
 * @param hints SIZE_HINTS structure.
 * @param base_width Base width.
 * @param base_height Base height.
 */
void xcb_size_hints_set_base_size(xcb_size_hints_t *hints, int32_t base_width,
                                  int32_t base_height);

/**
 * @brief Set size hints to a given window gravity.
 * @param hints SIZE_HINTS structure.
 * @param win_gravity Window gravity value.
 */
void xcb_size_hints_set_win_gravity(xcb_size_hints_t *hints,
                                    uint32_t win_gravity);

/**
 * @brief Deliver a ChangeProperty request to set a value to a given property.
 * @param c The connection to the X server.
 * @param window Window X identifier.
 * @param property Property to set value for.
 * @param hints Hints value to set.
 */
void xcb_set_wm_size_hints_checked(xcb_connection_t *c, xcb_window_t window,
                                   xcb_atom_t property, xcb_size_hints_t *hints);

/**
 * @see xcb_set_wm_size_hints_checked()
 */
void xcb_set_wm_size_hints(xcb_connection_t *c, xcb_window_t window,
                           xcb_atom_t property, xcb_size_hints_t *hints);

/**
 * @brief Send request to get size hints structure for the named property.
 * @param c The connection to the X server.
 * @param window Window X identifier.
 * @param property Specify the property name.
 * @return The request cookie.
 */
xcb_get_property_cookie_t xcb_get_wm_size_hints(xcb_connection_t *c,
                                                xcb_window_t window,
                                                xcb_atom_t property);

/**
 * @see xcb_get_wm_size_hints()
 */
xcb_get_property_cookie_t xcb_get_wm_size_hints_unchecked(xcb_connection_t *c,
                                                          xcb_window_t window,
                                                          xcb_atom_t property);

/**
 * @brief Fill given structure with the size hints of the named property.
 * @param c The connection to the X server.
 * @param cookie Request cookie.
 * @param hints Size hints structure.
 * @param e Error if any.
 * @return Return 1 on success, 0 otherwise.
 *
 * The parameter e supplied to this function must be NULL if
 * xcb_get_wm_size_hints_unchecked() is used.  Otherwise, it stores
 * the error if any. The returned pointer should be freed.
 */
uint8_t xcb_get_wm_size_hints_reply(xcb_connection_t *c,
                                    xcb_get_property_cookie_t cookie,
                                    xcb_size_hints_t *hints,
                                    xcb_generic_error_t **e);

/* WM_NORMAL_HINTS */

/**
 * @brief Deliver a ChangeProperty request to set WM_NORMAL_HINTS property value.
 * @param c The connection to the X server.
 * @param window Window X identifier.
 * @param hints Hints value to set.
 */
void xcb_set_wm_normal_hints_checked(xcb_connection_t *c, xcb_window_t window,
                                     xcb_size_hints_t *hints);

/**
 * @see xcb_set_wm_normal_hints_checked()
 */
void xcb_set_wm_normal_hints(xcb_connection_t *c, xcb_window_t window,
                             xcb_size_hints_t *hints);

/**
 * @brief Send request to get WM_NORMAL_HINTS property of a window.
 * @param c The connection to the X server.
 * @param window Window X identifier.
 * @return The request cookie.
 */
xcb_get_property_cookie_t xcb_get_wm_normal_hints(xcb_connection_t *c,
                                                  xcb_window_t window);

/**
 * @see xcb_get_wm_normal_hints()
 */
xcb_get_property_cookie_t xcb_get_wm_normal_hints_unchecked(xcb_connection_t *c,
                                                            xcb_window_t window);

/**
 * @brief Fill given structure with the WM_NORMAL_HINTS property of a window.
 * @param hints WM_NORMAL_HINTS property value.
 * @param reply The get property request reply.
 * @return Return 1 on success, 0 otherwise.
 */
uint8_t
xcb_get_wm_size_hints_from_reply(xcb_size_hints_t *hints,
                                 xcb_get_property_reply_t *reply);

/**
 * @brief Fill given structure with the WM_NORMAL_HINTS property of a window.
 * @param c The connection to the X server.
 * @param cookie Request cookie.
 * @param hints WM_NORMAL_HINTS property value.
 * @param e Error if any.
 * @return Return 1 on success, 0 otherwise.
 *
 * The parameter e supplied to this function must be NULL if
 * xcb_get_wm_normal_hints_unchecked() is used.  Otherwise, it stores
 * the error if any. The returned pointer should be freed.
 */
uint8_t xcb_get_wm_normal_hints_reply(xcb_connection_t *c,
                                      xcb_get_property_cookie_t cookie,
                                      xcb_size_hints_t *hints,
                                      xcb_generic_error_t **e);

/* WM_HINTS */

/**
 * @brief WM hints structure (may be extended in the future).
 */
typedef struct {
  /** Marks which fields in this structure are defined */
  int32_t flags;
  /** Does this application rely on the window manager to get keyboard
      input? */
  uint32_t input;
  /** See below */
  int32_t initial_state;
  /** Pixmap to be used as icon */
  xcb_pixmap_t icon_pixmap;
  /** Window to be used as icon */
  xcb_window_t icon_window;
  /** Initial position of icon */
  int32_t icon_x, icon_y;
  /** Icon mask bitmap */
  xcb_pixmap_t icon_mask;
  /* Identifier of related window group */
  xcb_window_t window_group;
} xcb_wm_hints_t;

/** Number of elements in this structure */
#define XCB_NUM_WM_HINTS_ELEMENTS 9

/**
 * @brief WM_HINTS window states.
 */
typedef enum {
  XCB_WM_STATE_WITHDRAWN = 0,
  XCB_WM_STATE_NORMAL = 1,
  XCB_WM_STATE_ICONIC = 3
} xcb_wm_state_t;

typedef enum {
  XCB_WM_HINT_INPUT = (1L << 0),
  XCB_WM_HINT_STATE = (1L << 1),
  XCB_WM_HINT_ICON_PIXMAP = (1L << 2),
  XCB_WM_HINT_ICON_WINDOW = (1L << 3),
  XCB_WM_HINT_ICON_POSITION = (1L << 4),
  XCB_WM_HINT_ICON_MASK = (1L << 5),
  XCB_WM_HINT_WINDOW_GROUP = (1L << 6),
  XCB_WM_HINT_X_URGENCY = (1L << 8)
} xcb_wm_t;

#define XCB_WM_ALL_HINTS (XCB_WM_HINT_INPUT | XCB_WM_HINT_STATE |\
                          XCB_WM_HINT_ICON_PIXMAP | XCB_WM_HINT_ICON_WINDOW |\
                          XCB_WM_HINT_ICON_POSITION | XCB_WM_HINT_ICON_MASK |\
                          XCB_WM_HINT_WINDOW_GROUP)

/**
 * @brief Get urgency hint.
 * @param hints WM_HINTS structure.
 * @return Urgency hint value.
 */
uint32_t xcb_wm_hints_get_urgency(xcb_wm_hints_t *hints);

/**
 * @brief Set input focus.
 * @param hints WM_HINTS structure.
 * @param input Input focus.
 */
void xcb_wm_hints_set_input(xcb_wm_hints_t *hints, uint8_t input);

/**
 * @brief Set hints state to 'iconic'.
 * @param hints WM_HINTS structure.
 */
void xcb_wm_hints_set_iconic(xcb_wm_hints_t *hints);

/**
 * @brief Set hints state to 'normal'.
 * @param hints WM_HINTS structure.
 */
void xcb_wm_hints_set_normal(xcb_wm_hints_t *hints);

/**
 * @brief Set hints state to 'withdrawn'.
 * @param hints WM_HINTS structure.
 */
void xcb_wm_hints_set_withdrawn(xcb_wm_hints_t *hints);

/**
 * @brief Set hints state to none.
 * @param hints WM_HINTS structure.
 */
void xcb_wm_hints_set_none(xcb_wm_hints_t *hints);

/**
 * @brief Set pixmap to be used as icon.
 * @param hints WM_HINTS structure.
 * @param icon_pixmap Pixmap.
 */
void xcb_wm_hints_set_icon_pixmap(xcb_wm_hints_t *hints,
                                  xcb_pixmap_t icon_pixmap);

/**
 * @brief Set icon mask bitmap.
 * @param hints WM_HINTS structure.
 * @param icon_mask Pixmap.
 */
void xcb_wm_hints_set_icon_mask(xcb_wm_hints_t *hints, xcb_pixmap_t icon_mask);

/**
 * @brief Set window identifier to be used as icon.
 * @param hints WM_HINTS structure.
 * @param icon_window Window X identifier.
 */
void xcb_wm_hints_set_icon_window(xcb_wm_hints_t *hints,
                                  xcb_window_t icon_window);

/**
 * @brief Set identifier of related window group.
 * @param hints WM_HINTS structure.
 * @param window_group Window X identifier.
 */
void xcb_wm_hints_set_window_group(xcb_wm_hints_t *hints,
                                   xcb_window_t window_group);

/**
 * @brief Set urgency hints flag.
 * @param hints WM_HINTS structure.
 */
void xcb_wm_hints_set_urgency(xcb_wm_hints_t *hints);

/**
 * @brief Deliver a SetProperty request to set WM_HINTS property value.
 * @param c The connection to the X server.
 * @param window Window X identifier.
 * @param hints Hints value to set.
 */
void xcb_set_wm_hints_checked(xcb_connection_t *c, xcb_window_t window,
                              xcb_wm_hints_t *hints);

/**
 * @see xcb_set_wm_hints_checked()
 */
void xcb_set_wm_hints(xcb_connection_t *c, xcb_window_t window,
                      xcb_wm_hints_t *hints);

/**
 * @brief Send request to get WM_HINTS property of a window.
 * @param c The connection to the X server.
 * @param window Window X identifier.
 * @return The request cookie.
 */
xcb_get_property_cookie_t xcb_get_wm_hints(xcb_connection_t *c,
                                           xcb_window_t window);

/**
 * @see xcb_get_wm_hints()
 */
xcb_get_property_cookie_t xcb_get_wm_hints_unchecked(xcb_connection_t *c,
                                                     xcb_window_t window);

/**
 * @brief Fill given structure with the WM_HINTS property of a window.
 * @param hints WM_HINTS property value.
 * @param reply The get property request reply.
 * @return Return 1 on success, 0 otherwise.
 */
uint8_t
xcb_get_wm_hints_from_reply(xcb_wm_hints_t *hints,
                            xcb_get_property_reply_t *reply);

/**
 * @brief Fill given structure with the WM_HINTS property of a window.
 * @param c The connection to the X server.
 * @param cookie Request cookie.
 * @param hints WM_HINTS property value.
 * @param e Error if any.
 * @return Return 1 on success, 0 otherwise.
 *
 * The parameter e supplied to this function must be NULL if
 * xcb_get_wm_hints_unchecked() is used.  Otherwise, it stores the
 * error if any. The returned pointer should be freed.
 */
uint8_t xcb_get_wm_hints_reply(xcb_connection_t *c,
                               xcb_get_property_cookie_t cookie,
                               xcb_wm_hints_t *hints,
                               xcb_generic_error_t **e);

/* WM_PROTOCOLS */

/**
 * @brief Deliver a SetProperty request to set WM_PROTOCOLS property value.
 * @param c The connection to the X server.
 * @param wm_protocols The WM_PROTOCOLS atom.
 * @param window Window X identifier.
 * @param list_len Atom list len.
 * @param list Atom list.
 */
void xcb_set_wm_protocols_checked(xcb_connection_t *c, xcb_atom_t wm_protocols,
                                  xcb_window_t window, uint32_t list_len,
                                  xcb_atom_t *list);

/**
 * @see xcb_set_wm_protocols_checked()
 */
void xcb_set_wm_protocols(xcb_connection_t *c, xcb_atom_t wm_protocols,
                          xcb_window_t window, uint32_t list_len,
                          xcb_atom_t *list);

/**
 * @brief WM_PROTOCOLS structure.
 */
typedef struct {
  /** Length of the atoms list */
  uint32_t atoms_len;
  /** Atoms list */
  xcb_atom_t *atoms;
  /** Store reply to avoid memory allocation, should normally not be
      used directly */
  xcb_get_property_reply_t *_reply;
} xcb_get_wm_protocols_reply_t;

/**
 * @brief Send request to get WM_PROTOCOLS property of a given window.
 * @param c The connection to the X server.
 * @param window Window X identifier.
 * @return The request cookie.
 */
xcb_get_property_cookie_t xcb_get_wm_protocols(xcb_connection_t *c,
                                               xcb_window_t window,
                                               xcb_atom_t wm_protocol_atom);

/**
 * @see xcb_get_wm_protocols()
 */
xcb_get_property_cookie_t xcb_get_wm_protocols_unchecked(xcb_connection_t *c,
                                                         xcb_window_t window,
                                                         xcb_atom_t wm_protocol_atom);

/**
 * @brief Fill the given structure with the WM_PROTOCOLS property of a window.
 * @param reply The reply of the GetProperty request.
 * @param protocols WM_PROTOCOLS property value.
 * @return Return 1 on success, 0 otherwise.
 *
 * protocols structure members should be freed by
 * xcb_get_wm_protocols_reply_wipe().
 */
uint8_t xcb_get_wm_protocols_from_reply(xcb_get_property_reply_t *reply,
                                        xcb_get_wm_protocols_reply_t *protocols);
/**
 * @brief Fill the given structure with the WM_PROTOCOLS property of a window.
 * @param c The connection to the X server.
 * @param cookie Request cookie.
 * @param protocols WM_PROTOCOLS property value.
 * @param e Error if any.
 * @return Return 1 on success, 0 otherwise.
 *
 * The parameter e supplied to this function must be NULL if
 * xcb_get_wm_protocols_unchecked() is used.  Otherwise, it stores the
 * error if any. protocols structure members should be freed by
 * xcb_get_wm_protocols_reply_wipe().
 */
uint8_t xcb_get_wm_protocols_reply(xcb_connection_t *c,
                                   xcb_get_property_cookie_t cookie,
                                   xcb_get_wm_protocols_reply_t *protocols,
                                   xcb_generic_error_t **e);

/**
 * @brief Wipe protocols structure members previously allocated by
 *        xcb_get_wm_protocols_reply().
 * @param protocols protocols structure whose members is going to be freed.
 */
void xcb_get_wm_protocols_reply_wipe(xcb_get_wm_protocols_reply_t *protocols);

#ifdef __cplusplus
}
#endif

/**
 * @}
 */

#endif /* __XCB_ICCCM_H__ */