3 * Copyright (C) 2009 Jürg Billeter
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Jürg Billeter <j@bitron.ch>
23 [CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "X11/Xlib.h,X11/Xatom.h,X11/Xutil.h,X11/Xregion.h")]
25 // Note: must be called before opening a display or calling any other Xlib function,
26 // see http://tronche.com/gui/x/xlib/display/XInitThreads.html
27 [CCode (cname = "XInitThreads")]
28 public Status init_threads ();
31 [CCode (cname = "Display", ref_function = "", unref_function = "")]
32 public class Display {
33 [CCode (cname = "XOpenDisplay")]
34 public Display (string? name = null);
36 [CCode (cname = "XAllPlanes")]
37 public static ulong get_all_planes ();
39 [CCode (cname = "XActivateScreenSaver")]
40 public void activate_screensaver ();
42 [CCode (cname = "XAddToSaveSet")]
43 public int add_to_save_set (Window w);
45 [CCode (cname = "XAllowEvents")]
46 public int allow_events (int event_mode, int time);
48 [CCode (cname = "XBitmapBitOrder")]
49 public int bitmap_bit_order ();
51 [CCode (cname = "XBitmapUnit")]
52 public int bitmap_scanline_unit ();
54 [CCode (cname = "XBitmapPad")]
55 public int bitmap_scanline_padding ();
57 [CCode (cname = "XChangeProperty")]
58 public int change_property (Window w, Atom property, Atom type, int format, int mode, [CCode (array_length = false)] uchar[] data, int nelements);
60 [CCode (cname = "XChangeWindowAttributes")]
61 public int change_window_attributes (Window w, ulong valuemask, SetWindowAttributes attributes);
63 [CCode (cname = "XConfigureWindow")]
64 public int configure_window (Window w, uint value_mask, WindowChanges values);
66 [CCode (cname = "ConnectionNumber")]
67 public int connection_number ();
69 [CCode (cname = "DefaultRootWindow")]
70 public Window default_root_window ();
72 [CCode (cname = "XDefaultScreenOfDisplay")]
73 public unowned Screen default_screen ();
75 [CCode (cname = "XScreenOfDisplay")]
76 public unowned Screen screen_by_id (int screen_number);
78 [CCode (cname = "DisplayString")]
79 public string display_string ();
81 [CCode (cname = "XQLength")]
82 public int event_queue_length ();
84 [CCode (cname = "XFlush")]
87 [CCode (cname = "XForceScreenSaver")]
88 public void force_screensaver (int mode);
90 [CCode (cname = "XGetKeyboardMapping", array_length = false)]
91 public unowned uint[] get_keyboard_mapping (uint first_keycode, int keycode_count, ref int keysyms_per_keycode_return);
93 [CCode (cname = "XGetModifierMapping")]
94 public ModifierKeymap get_modifier_mapping ();
96 [CCode (cname = "XGetScreenSaver")]
97 public void get_screensaver (out int timeout, out int interval, out int prefer_blanking, out int allow_exposures);
99 [CCode (cname = "XGetSelectionOwner")]
100 public Window get_selection_owner (Atom selection);
102 [CCode (cname = "XGetWindowAttributes")]
103 public void get_window_attributes (Window w, out WindowAttributes window_attributes_return);
105 [CCode (cname = "XGetWindowProperty")]
106 public int get_window_property (Window w, Atom property, long long_offset, long long_length, bool delete, Atom req_type, out Atom actual_type_return, out int actual_format_return, out ulong nitems_return, out ulong bytes_after_return, [CCode (type = "unsigned char **")] out void* prop_return);
108 [CCode (cname = "XGrabButton")]
109 public int grab_button (uint button, uint modifiers, Window grab_window, bool owner_events, uint event_mask, int pointer_mode, int keyboard_mode, Window confine_to, uint cursor);
111 [CCode (cname = "XGrabKey")]
112 public int grab_key (int keycode, uint modifiers, Window grab_window, bool owner_events, int pointer_mode, int keyboard_mode);
114 [CCode (cname = "XGrabPointer")]
115 public int grab_pointer (Window grab_window, bool owner_events, uint event_mask, int pointer_mode, int keyboard_mode, Window confine_to, uint cursor, int time);
117 [CCode (cname = "XGrabServer")]
118 public int grab_server ();
120 [CCode (cname = "XImageByteOrder")]
121 public int image_byte_order ();
123 [CCode (cname = "XInternAtom")]
124 public Atom intern_atom (string atom_name, bool only_if_exists);
126 [CCode (cname = "XInternAtoms")]
127 public void intern_atoms (string[] names, bool only_if_exists, [CCode (array_length = false)] Atom[] atoms_return);
129 [CCode (cname = "XInternalConnectionNumbers")]
130 public Status internal_connection_numbers (ref int[] fd_return);
132 [CCode (cname = "XDisplayKeycodes")]
133 public int keycodes (ref int min_keycodes_return, ref int max_keycodes_return);
135 [CCode (cname = "XKeysymToKeycode")]
136 public int keysym_to_keycode (uint keysym);
138 [CCode (cname = "XLastKnownRequestProcessed")]
139 public ulong last_known_request_processed ();
141 [CCode (cname = "XLockDisplay")]
142 public void lock_display ();
144 [CCode (cname = "XMapWindow")]
145 public int map_window (Window w);
147 [CCode (cname = "XMaxRequestSize")]
148 public long max_request_size ();
150 [CCode (cname = "XExtendedMaxRequestSize")]
151 public long max_extended_request_size ();
153 [CCode (cname = "XEventsQueued")]
154 public int events_queued (int mode);
156 [CCode (cname = "XNextEvent")]
157 public int next_event (ref Event event_return);
159 [CCode (cname = "XNextRequest")]
160 public ulong next_request ();
162 [CCode (cname = "XNoOp")]
163 public void no_operation ();
165 [CCode (cname = "XScreenCount")]
166 public int number_of_screens ();
168 [CCode (cname = "XPending")]
169 public int pending ();
171 [CCode (cname = "XProcessInternalConnection")]
172 public void process_internal_connection (int fd);
174 [CCode (cname = "XProtocolVersion")]
175 public int protocol_version ();
177 [CCode (cname = "XProtocolRevision")]
178 public int protocol_revision ();
180 [CCode (cname = "XRaiseWindow")]
181 public int raise_window (Window w);
183 [CCode (cname = "XReparentWindow")]
184 public int reparent_window (Window w, Window parent, int x, int y);
186 [CCode (cname = "XResetScreenSaver")]
187 public void reset_screensaver ();
189 [CCode (cname = "XResizeWindow")]
190 public int resize_window (Window w, uint width, uint height);
192 [CCode (cname = "XRootWindow")]
193 public Window root_window (int screen_number);
195 [CCode (cname = "ScreenCount")]
196 public int screen_count ();
198 [CCode (cname = "XScreenOfDisplay")]
199 public unowned Screen screen_of_display (int screen_number);
201 [CCode (cname = "XSelectInput")]
202 public int select_input (Window w, long event_mask);
204 [CCode (cname = "XSendEvent")]
205 public void send_event (Window w, bool prpagate, long event_mask, ref Event event_send);
207 [CCode (cname = "XSetCloseDownMode")]
208 public void set_close_down_mode (int close_mode);
210 [CCode (cname = "XSetScreenSaver")]
211 public void set_screensaver (int timeout, int interval, int prefer_blanking, int allow_exposures);
213 [CCode (cname = "XSetSelectionOwner")]
214 public Window set_selection_owner (Atom selection, Window owner, int time);
216 [CCode (cname = "XSetInputFocus")]
217 public int set_input_focus (Window focus, int revert_to, int time);
219 [CCode (cname = "XUngrabButton")]
220 public int ungrab_button (uint button, uint modifiers, Window grab_window);
222 [CCode (cname = "XUngrabKey")]
223 public int ungrab_key (int keycode, uint modifiers, Window grab_window);
225 [CCode (cname = "XUngrabPointer")]
226 public int ungrab_pointer (int time);
228 [CCode (cname = "XUngrabServer")]
229 public int ungrab_server ();
231 [CCode (cname = "XUnlockDisplay")]
232 public void unlock_display ();
234 [CCode (cname = "XUnmapWindow")]
235 public int unmap_window (Window w);
237 [CCode (cname = "XQueryTree")]
238 public void query_tree (Window w, out Window root_return, out Window parent_return, out Window[] children_return);
240 [CCode (cname = "XWindowEvent")]
241 public int window_event (Window w, EventMask event_mask, out Event event_return);
243 [CCode (cname = "XServerVendor")]
244 public string xserver_vendor_name ();
246 [CCode (cname = "XVendorRelease")]
247 public string xserver_vendor_release ();
249 [CCode (cname = "XMoveWindow")]
250 public void move_window (Window window, int x, int y);
254 [CCode (cname = "XModifierKeymap", free_function = "XFreeModifiermap")]
255 public class ModifierKeymap {
256 // The server's max # of keys per modifier
257 public int max_keypermod;
258 // An 8 by max_keypermod array of modifiers
259 public uchar[] modifiermap;
263 [IntegerType (rank = 9)]
264 [CCode (cname = "Atom")]
269 [IntegerType (rank = 9)]
270 [CCode (cname = "Colormap")]
271 public struct Colormap {
275 [CCode (cname = "GC")]
280 [IntegerType (rank = 9)]
281 [CCode (cname = "Status")]
282 public struct Status {
286 [IntegerType (rank = 9)]
287 [CCode (cname = "XID", type_id = "G_TYPE_INT",
288 marshaller_type_name = "INT",
289 get_value_function = "g_value_get_int",
290 set_value_function = "g_value_set_int", default_value = "0",
291 type_signature = "i")]
296 [IntegerType (rank = 9)]
297 [CCode (cname = "Drawable", type_id = "G_TYPE_INT",
298 marshaller_type_name = "INT",
299 get_value_function = "g_value_get_int",
300 set_value_function = "g_value_set_int", default_value = "0",
301 type_signature = "i")]
302 public struct Drawable : ID
307 [IntegerType (rank = 9)]
308 [CCode (cname = "Window", type_id = "G_TYPE_INT",
309 marshaller_type_name = "INT",
310 get_value_function = "g_value_get_int",
311 set_value_function = "g_value_set_int", default_value = "0",
312 type_signature = "i")]
313 public struct Window : Drawable {
318 [IntegerType (rank = 9)]
319 [CCode (cname = "Pixmap", type_id = "G_TYPE_INT",
320 marshaller_type_name = "INT",
321 get_value_function = "g_value_get_int",
322 set_value_function = "g_value_set_int", default_value = "0",
323 type_signature = "i")]
324 public struct Pixmap : Drawable {
327 public struct Visual {
330 public struct WindowChanges {
335 public int border_width;
336 public Window sibling;
337 public int stack_mode;
339 public struct SizeHints {
347 [CCode (cname = "XCreateWindow")]
348 public Window create_window (Display display, Window parent, int x, int y, uint width, uint height, uint border_width, int depth, uint @class, Visual? visual, X.CW valuemask, ref SetWindowAttributes attributes);
350 [CCode (cname = "XSetWindowAttributes")]
351 public struct SetWindowAttributes {
352 // public Pixmap background_pixmap; /* background or None or ParentRelative */
353 public ulong background_pixel; /* background pixel */
354 // public Pixmap border_pixmap; /* border of the window */
355 public ulong border_pixel; /* border pixel value */
356 public int bit_gravity; /* one of bit gravity values */
357 public int win_gravity; /* one of the window gravity values */
358 public int backing_store; /* NotUseful, WhenMapped, Always */
359 public ulong backing_planes;/* planes to be preseved if possible */
360 public ulong backing_pixel;/* value to use in restoring planes */
361 public bool save_under; /* should bits under be saved? (popups) */
362 public long event_mask; /* set of events that should be saved */
363 public long do_not_propagate_mask; /* set of events that should not propagate */
364 public bool override_redirect; /* boolean value for override-redirect */
365 // public Colormap colormap; /* color map to be associated with window */
366 // public Cursor cursor; /* cursor to be displayed (or None) */
369 [CCode(cname = "XWindowAttributes",
370 cheader_filename = "X11/Xlib.h,X11/Xatom.h,X11/Xutil.h")]
371 public struct WindowAttributes {
373 public int y; /* location of window */
375 public int height; /* width and height of window */
376 public int border_width; /* border width of window */
377 public int depth; /* depth of window */
378 public Visual visual; /* the associated visual structure */
379 public Window root; /* root of screen containing window */
380 public int @class; /* InputOutput, InputOnly*/
381 public int bit_gravity; /* one of bit gravity values */
382 public int win_gravity; /* one of the window gravity values */
383 public int backing_store; /* NotUseful, WhenMapped, Always */
384 public ulong backing_planes;/* planes to be preserved if possible */
385 public ulong backing_pixel;/* value to be used when restoring planes */
386 public bool save_under; /* boolean, should bits under be saved? */
387 // public Colormap colormap; /* color map to be associated with window */
388 public bool map_installed; /* boolean, is color map currently installed*/
389 public int map_state; /* IsUnmapped, IsUnviewable, IsViewable */
390 public long all_event_masks; /* set of events all people have interest in*/
391 public long your_event_mask; /* my event mask */
392 public long do_not_propagate_mask; /* set of events that should not propagate */
393 public bool override_redirect; /* boolean value for override-redirect */
394 // public Screen screen; /* back pointer to correct screen */
397 [CCode (cname = "CopyFromParent")]
398 public const int COPY_FROM_PARENT;
400 [CCode (cname = "CurrentTime")]
401 public const ulong CURRENT_TIME;
403 [CCode (cname = "Success")]
406 [CCode (cname = "XFree")]
407 public int free (void* data);
409 [CCode (cprefix = "CW", cname = "int")]
435 [CCode (cprefix = "GrabMode")]
436 public enum GrabMode {
441 [CCode (cprefix = "")]
442 public enum EventMask {
451 PointerMotionHintMask,
460 VisibilityChangeMask,
463 SubstructureNotifyMask,
464 SubstructureRedirectMask,
471 [CCode (cprefix = "")]
472 public enum KeyMask {
483 [CCode (cprefix = "")]
484 public enum EventType {
521 [CCode (cname = "XEvent")]
522 public struct Event {
524 public AnyEvent xany;
525 public KeyEvent xkey;
526 public ButtonEvent xbutton;
527 public MotionEvent xmotion;
528 public CrossingEvent xcrossing;
529 public CreateWindowEvent xcreatewindow;
530 public DestroyWindowEvent xdestroywindow;
531 public UnmapEvent xunmap;
532 public MapEvent xmap;
533 public MapRequestEvent xmaprequest;
534 public ReparentEvent xreparent;
535 public ConfigureEvent xconfigure;
536 public GravityEvent xgravity;
537 public ConfigureRequestEvent xconfigurerequest;
538 public CirculateEvent xcirculate;
539 public CirculateRequestEvent xcirculaterequest;
540 public PropertyEvent xproperty;
541 public SelectionEvent xselection;
542 public ClientMessageEvent xclient;
545 [CCode (cname = "XAnyEvent")]
546 public struct AnyEvent {
549 public bool send_event;
550 public unowned Display display;
551 public Window window;
554 [CCode (cname = "XKeyEvent")]
555 public struct KeyEvent {
558 public bool send_event;
559 public unowned Display display;
560 public Window window;
562 public Window subwindow;
570 public bool same_screen;
573 [CCode (cname = "XButtonEvent")]
574 public struct ButtonEvent {
577 public bool send_event;
578 public unowned Display display;
579 public Window window;
580 public Window subwindow;
588 public bool same_screen;
591 [CCode (cname = "XMotionEvent")]
592 public struct MotionEvent {
595 public bool send_event;
596 public unowned Display display;
597 public Window window;
598 public Window subwindow;
606 public bool same_screen;
609 [CCode (cname = "XCrossingEvent")]
610 public struct CrossingEvent {
613 public bool send_event;
614 public unowned Display display;
615 public Window window;
617 public Window subwindow;
625 public bool same_screen;
630 [CCode (cname = "XCreateWindowEvent")]
631 public struct CreateWindowEvent {
634 public bool send_event;
635 public unowned Display display;
636 public Window parent;
637 public Window window;
642 public int border_width;
643 public bool override_redirect;
646 [CCode (cname = "XDestroyWindowEvent")]
647 public struct DestroyWindowEvent {
650 public bool send_event;
651 public unowned Display display;
653 public Window window;
656 [CCode (cname = "XUnmapEvent")]
657 public struct UnmapEvent {
660 public bool send_event;
661 public unowned Display display;
663 public Window window;
664 public bool from_configure;
667 [CCode (cname = "XMapEvent")]
668 public struct MapEvent {
671 public bool send_event;
672 public unowned Display display;
674 public Window window;
675 public bool override_redirect;
678 [CCode (cname = "XMapRequestEvent")]
679 public struct MapRequestEvent {
682 public bool send_event;
683 public unowned Display display;
684 public Window parent;
685 public Window window;
688 [CCode (cname = "XReparentEvent")]
689 public struct ReparentEvent {
692 public bool send_event;
693 public unowned Display display;
695 public Window window;
696 public Window parent;
699 public bool override_redirect;
702 [CCode (cname = "XConfigureEvent")]
703 public struct ConfigureEvent {
706 public bool send_event;
707 public unowned Display display;
709 public Window window;
714 public int border_width;
716 public bool override_redirect;
719 [CCode (cname = "XGravityEvent")]
720 public struct GravityEvent {
723 public bool send_event;
724 public unowned Display display;
726 public Window window;
731 [CCode (cname = "XConfigureRequestEvent")]
732 public struct ConfigureRequestEvent {
735 public bool send_event;
736 public unowned Display display;
737 public Window parent;
738 public Window window;
743 public int border_width;
746 public ulong value_mask;
749 [CCode (cname = "XCirculateEvent")]
750 public struct CirculateEvent {
753 public bool send_event;
754 public unowned Display display;
756 public Window window;
760 [CCode (cname = "XCirculateRequestEvent")]
761 public struct CirculateRequestEvent {
764 public bool send_event;
765 public unowned Display display;
766 public Window parent;
767 public Window window;
771 [CCode (cname = "XPropertyEvent")]
772 public struct PropertyEvent {
775 public bool send_event;
776 public unowned Display display;
777 public Window window;
783 [CCode (cname = "XSelectionEvent")]
784 public struct SelectionEvent {
787 public bool send_event;
788 public unowned Display display;
789 public Window requestor;
790 public Atom selection;
792 public Atom property;
796 [CCode (cname = "XClientMessageEvent")]
797 public struct ClientMessageEvent {
799 public ulong serial; /* # of last request processed by server */
800 public bool send_event; /* true if this came from a SendEvent request */
801 public unowned Display display; /* Display the event was read from */
802 public Window window;
803 public Atom message_type;
805 public ClientMessageEventData data;
808 [CCode (cname = "RECTANGLE", has_type_id = false)]
809 public struct Rectangle {
817 public struct ClientMessageEventData {
818 public unowned char[] b;
819 public unowned short[] s;
820 public unowned long[] l;
823 [CCode (cprefix = "Queued")]
824 public enum QueuedMode {
830 [CCode (cprefix = "PropMode")]
831 public enum PropMode {
837 [CCode (cprefix = "")]
838 public enum AllowEventsMode {
849 [CCode (cprefix = "")]
850 public enum MapState {
856 [CCode (cprefix = "RevertTo")]
857 public enum RevertTo {
864 [CCode (cname = "Screen")]
865 public class Screen {
866 public Display display;
871 [CCode (cname = "XScreenOfDisplay")]
872 public static unowned Screen get_screen (Display disp, int screen_number);
874 [CCode (cname = "XBlackPixelOfScreen")]
875 public ulong black_pixel_of_screen ();
877 [CCode (cname = "XCellsOfScreen")]
878 public int cells_of_screen ();
880 [CCode (cname = "XDefaultColormapOfScreen")]
881 public Colormap default_colormap_of_screen ();
883 [CCode (cname = "XDefaultDepthOfScreen")]
884 public int default_depth_of_screen ();
886 [CCode (cname = "XDefaultGCOfScreen")]
887 public GC default_gc_of_screen ();
889 [CCode (cname = "XDefaultVisualOfScreen")]
890 public Visual default_visual_of_screen ();
892 [CCode (cname = "XDisplayOfScreen")]
893 public unowned Display display_of_screen ();
895 [CCode (cname = "XDoesBackingStore")]
896 public int does_backing_store ();
898 [CCode (cname = "XDoesSaveUnders")]
899 public bool does_save_unders ();
901 [CCode (cname = "XEventMaskOfScreen")]
902 public long event_mask_of_Screen ();
904 [CCode (cname = "XHeightMMOfScreen")]
905 public int height_in_mm_of_screen ();
907 [CCode (cname = "XHeightOfScreen")]
908 public int height_of_screen ();
910 [CCode (cname = "XMaxCmapsOfScreen")]
911 public int max_colormaps_of_screen ();
913 [CCode (cname = "XMinCmapsOfScreen")]
914 public int min_colormaps_of_screen ();
916 [CCode (cname = "XPlanesOfScreen")]
917 public int planes_of_screen ();
919 [CCode (cname = "XRootWindowOfScreen")]
920 public Window root_window_of_screen ();
922 [CCode (cname = "XScreenNumberOfScreen")]
923 public int screen_number_of_screen ();
925 [CCode (cname = "XWhitePixelOfScreen")]
926 public ulong white_pixel_of_screen ();
928 [CCode (cname = "XWidthMMOfScreen")]
929 public int width_in_mm_of_screen ();
931 [CCode (cname = "XWidthOfScreen")]
932 public int width_of_screen ();
935 public const X.ID None;
937 public const X.Atom XA_ATOM;
938 public const X.Atom XA_CARDINAL;
939 public const X.Atom XA_WINDOW;
940 public const X.Atom XA_WM_CLASS;
941 public const X.Atom XA_WM_HINTS;
942 public const X.Atom XA_WM_ICON_NAME;
943 public const X.Atom XA_WM_NAME;
944 public const X.Atom XA_WM_NORMAL_HINTS;
945 public const X.Atom XA_WM_TRANSIENT_FOR;
947 public const uint XK_Num_Lock;
948 public const uint XK_Scroll_Lock;
949 public const uint XK_Super_L;
950 public const uint XK_Super_R;