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 ulong[] get_keyboard_mapping (uchar 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 uchar keysym_to_keycode (ulong keysym);
138 [CCode (cname = "XKeycodeToKeysym")]
139 public ulong keycode_to_keysym (uchar keycode, int index);
141 [CCode (cname = "XLastKnownRequestProcessed")]
142 public ulong last_known_request_processed ();
144 [CCode (cname = "XLockDisplay")]
145 public void lock_display ();
147 [CCode (cname = "XMapWindow")]
148 public int map_window (Window w);
150 [CCode (cname = "XMaxRequestSize")]
151 public long max_request_size ();
153 [CCode (cname = "XExtendedMaxRequestSize")]
154 public long max_extended_request_size ();
156 [CCode (cname = "XEventsQueued")]
157 public int events_queued (int mode);
159 [CCode (cname = "XNextEvent")]
160 public int next_event (ref Event event_return);
162 [CCode (cname = "XNextRequest")]
163 public ulong next_request ();
165 [CCode (cname = "XNoOp")]
166 public void no_operation ();
168 [CCode (cname = "XScreenCount")]
169 public int number_of_screens ();
171 [CCode (cname = "XPending")]
172 public int pending ();
174 [CCode (cname = "XProcessInternalConnection")]
175 public void process_internal_connection (int fd);
177 [CCode (cname = "XProtocolVersion")]
178 public int protocol_version ();
180 [CCode (cname = "XProtocolRevision")]
181 public int protocol_revision ();
183 [CCode (cname = "XRaiseWindow")]
184 public int raise_window (Window w);
186 [CCode (cname = "XReparentWindow")]
187 public int reparent_window (Window w, Window parent, int x, int y);
189 [CCode (cname = "XResetScreenSaver")]
190 public void reset_screensaver ();
192 [CCode (cname = "XResizeWindow")]
193 public int resize_window (Window w, uint width, uint height);
195 [CCode (cname = "XRootWindow")]
196 public Window root_window (int screen_number);
198 [CCode (cname = "ScreenCount")]
199 public int screen_count ();
201 [CCode (cname = "XScreenOfDisplay")]
202 public unowned Screen screen_of_display (int screen_number);
204 [CCode (cname = "XSelectInput")]
205 public int select_input (Window w, long event_mask);
207 [CCode (cname = "XSendEvent")]
208 public void send_event (Window w, bool propagate, long event_mask, ref Event event_send);
210 [CCode (cname = "XSetCloseDownMode")]
211 public void set_close_down_mode (int close_mode);
213 [CCode (cname = "XSetScreenSaver")]
214 public void set_screensaver (int timeout, int interval, int prefer_blanking, int allow_exposures);
216 [CCode (cname = "XSetSelectionOwner")]
217 public Window set_selection_owner (Atom selection, Window owner, int time);
219 [CCode (cname = "XSetInputFocus")]
220 public int set_input_focus (Window focus, int revert_to, int time);
222 [CCode (cname = "XUngrabButton")]
223 public int ungrab_button (uint button, uint modifiers, Window grab_window);
225 [CCode (cname = "XUngrabKey")]
226 public int ungrab_key (int keycode, uint modifiers, Window grab_window);
228 [CCode (cname = "XUngrabPointer")]
229 public int ungrab_pointer (int time);
231 [CCode (cname = "XUngrabServer")]
232 public int ungrab_server ();
234 [CCode (cname = "XUnlockDisplay")]
235 public void unlock_display ();
237 [CCode (cname = "XUnmapWindow")]
238 public int unmap_window (Window w);
240 [CCode (cname = "XQueryTree")]
241 public void query_tree (Window w, out Window root_return, out Window parent_return, out Window[] children_return);
243 [CCode (cname = "XWindowEvent")]
244 public int window_event (Window w, EventMask event_mask, out Event event_return);
246 [CCode (cname = "XServerVendor")]
247 public string xserver_vendor_name ();
249 [CCode (cname = "XVendorRelease")]
250 public string xserver_vendor_release ();
252 [CCode (cname = "XMoveWindow")]
253 public void move_window (Window window, int x, int y);
257 [CCode (cname = "XModifierKeymap", free_function = "XFreeModifiermap")]
258 public class ModifierKeymap {
259 // The server's max # of keys per modifier
260 public int max_keypermod;
261 // An 8 by max_keypermod array of modifiers
262 public uchar[] modifiermap;
266 [IntegerType (rank = 9)]
267 [CCode (cname = "Atom")]
272 [IntegerType (rank = 9)]
273 [CCode (cname = "Colormap")]
274 public struct Colormap {
278 [CCode (cname = "GC")]
283 [IntegerType (rank = 9)]
284 [CCode (cname = "Status")]
285 public struct Status {
289 [IntegerType (rank = 9)]
290 [CCode (cname = "XID", type_id = "G_TYPE_INT",
291 marshaller_type_name = "INT",
292 get_value_function = "g_value_get_int",
293 set_value_function = "g_value_set_int", default_value = "0",
294 type_signature = "i")]
299 [IntegerType (rank = 9)]
300 [CCode (cname = "Drawable", type_id = "G_TYPE_INT",
301 marshaller_type_name = "INT",
302 get_value_function = "g_value_get_int",
303 set_value_function = "g_value_set_int", default_value = "0",
304 type_signature = "i")]
305 public struct Drawable : ID
310 [IntegerType (rank = 9)]
311 [CCode (cname = "Window", type_id = "G_TYPE_INT",
312 marshaller_type_name = "INT",
313 get_value_function = "g_value_get_int",
314 set_value_function = "g_value_set_int", default_value = "0",
315 type_signature = "i")]
316 public struct Window : Drawable {
321 [IntegerType (rank = 9)]
322 [CCode (cname = "Pixmap", type_id = "G_TYPE_INT",
323 marshaller_type_name = "INT",
324 get_value_function = "g_value_get_int",
325 set_value_function = "g_value_set_int", default_value = "0",
326 type_signature = "i")]
327 public struct Pixmap : Drawable {
330 public struct Visual {
333 public struct WindowChanges {
338 public int border_width;
339 public Window sibling;
340 public int stack_mode;
342 public struct SizeHints {
350 [CCode (cname = "XCreateWindow")]
351 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);
353 [CCode (cname = "XSetWindowAttributes")]
354 public struct SetWindowAttributes {
355 // public Pixmap background_pixmap; /* background or None or ParentRelative */
356 public ulong background_pixel; /* background pixel */
357 // public Pixmap border_pixmap; /* border of the window */
358 public ulong border_pixel; /* border pixel value */
359 public int bit_gravity; /* one of bit gravity values */
360 public int win_gravity; /* one of the window gravity values */
361 public int backing_store; /* NotUseful, WhenMapped, Always */
362 public ulong backing_planes;/* planes to be preseved if possible */
363 public ulong backing_pixel;/* value to use in restoring planes */
364 public bool save_under; /* should bits under be saved? (popups) */
365 public long event_mask; /* set of events that should be saved */
366 public long do_not_propagate_mask; /* set of events that should not propagate */
367 public bool override_redirect; /* boolean value for override-redirect */
368 // public Colormap colormap; /* color map to be associated with window */
369 // public Cursor cursor; /* cursor to be displayed (or None) */
372 [CCode(cname = "XWindowAttributes",
373 cheader_filename = "X11/Xlib.h,X11/Xatom.h,X11/Xutil.h")]
374 public struct WindowAttributes {
376 public int y; /* location of window */
378 public int height; /* width and height of window */
379 public int border_width; /* border width of window */
380 public int depth; /* depth of window */
381 public Visual visual; /* the associated visual structure */
382 public Window root; /* root of screen containing window */
383 public int @class; /* InputOutput, InputOnly*/
384 public int bit_gravity; /* one of bit gravity values */
385 public int win_gravity; /* one of the window gravity values */
386 public int backing_store; /* NotUseful, WhenMapped, Always */
387 public ulong backing_planes;/* planes to be preserved if possible */
388 public ulong backing_pixel;/* value to be used when restoring planes */
389 public bool save_under; /* boolean, should bits under be saved? */
390 // public Colormap colormap; /* color map to be associated with window */
391 public bool map_installed; /* boolean, is color map currently installed*/
392 public int map_state; /* IsUnmapped, IsUnviewable, IsViewable */
393 public long all_event_masks; /* set of events all people have interest in*/
394 public long your_event_mask; /* my event mask */
395 public long do_not_propagate_mask; /* set of events that should not propagate */
396 public bool override_redirect; /* boolean value for override-redirect */
397 // public Screen screen; /* back pointer to correct screen */
400 [CCode (cname = "CopyFromParent")]
401 public const int COPY_FROM_PARENT;
403 [CCode (cname = "CurrentTime")]
404 public const ulong CURRENT_TIME;
406 [CCode (cname = "Success")]
409 [CCode (cname = "XFree")]
410 public int free (void* data);
412 [CCode (cprefix = "CW", cname = "int")]
438 [CCode (cprefix = "GrabMode")]
439 public enum GrabMode {
444 [CCode (cprefix = "")]
445 public enum EventMask {
454 PointerMotionHintMask,
463 VisibilityChangeMask,
466 SubstructureNotifyMask,
467 SubstructureRedirectMask,
474 [CCode (cprefix = "")]
475 public enum KeyMask {
486 [CCode (cprefix = "")]
487 public enum EventType {
524 [CCode (cname = "XEvent")]
525 public struct Event {
527 public AnyEvent xany;
528 public KeyEvent xkey;
529 public ButtonEvent xbutton;
530 public MotionEvent xmotion;
531 public CrossingEvent xcrossing;
532 public CreateWindowEvent xcreatewindow;
533 public DestroyWindowEvent xdestroywindow;
534 public UnmapEvent xunmap;
535 public MapEvent xmap;
536 public MapRequestEvent xmaprequest;
537 public ReparentEvent xreparent;
538 public ConfigureEvent xconfigure;
539 public GravityEvent xgravity;
540 public ConfigureRequestEvent xconfigurerequest;
541 public CirculateEvent xcirculate;
542 public CirculateRequestEvent xcirculaterequest;
543 public PropertyEvent xproperty;
544 public SelectionEvent xselection;
545 public ClientMessageEvent xclient;
548 [CCode (cname = "XAnyEvent")]
549 public struct AnyEvent {
552 public bool send_event;
553 public unowned Display display;
554 public Window window;
557 [CCode (cname = "XKeyEvent")]
558 public struct KeyEvent {
561 public bool send_event;
562 public unowned Display display;
563 public Window window;
565 public Window subwindow;
573 public bool same_screen;
576 [CCode (cname = "XButtonEvent")]
577 public struct ButtonEvent {
580 public bool send_event;
581 public unowned Display display;
582 public Window window;
583 public Window subwindow;
591 public bool same_screen;
594 [CCode (cname = "XMotionEvent")]
595 public struct MotionEvent {
598 public bool send_event;
599 public unowned Display display;
600 public Window window;
601 public Window subwindow;
609 public bool same_screen;
612 [CCode (cname = "XCrossingEvent")]
613 public struct CrossingEvent {
616 public bool send_event;
617 public unowned Display display;
618 public Window window;
620 public Window subwindow;
628 public bool same_screen;
633 [CCode (cname = "XCreateWindowEvent")]
634 public struct CreateWindowEvent {
637 public bool send_event;
638 public unowned Display display;
639 public Window parent;
640 public Window window;
645 public int border_width;
646 public bool override_redirect;
649 [CCode (cname = "XDestroyWindowEvent")]
650 public struct DestroyWindowEvent {
653 public bool send_event;
654 public unowned Display display;
656 public Window window;
659 [CCode (cname = "XUnmapEvent")]
660 public struct UnmapEvent {
663 public bool send_event;
664 public unowned Display display;
666 public Window window;
667 public bool from_configure;
670 [CCode (cname = "XMapEvent")]
671 public struct MapEvent {
674 public bool send_event;
675 public unowned Display display;
677 public Window window;
678 public bool override_redirect;
681 [CCode (cname = "XMapRequestEvent")]
682 public struct MapRequestEvent {
685 public bool send_event;
686 public unowned Display display;
687 public Window parent;
688 public Window window;
691 [CCode (cname = "XReparentEvent")]
692 public struct ReparentEvent {
695 public bool send_event;
696 public unowned Display display;
698 public Window window;
699 public Window parent;
702 public bool override_redirect;
705 [CCode (cname = "XConfigureEvent")]
706 public struct ConfigureEvent {
709 public bool send_event;
710 public unowned Display display;
712 public Window window;
717 public int border_width;
719 public bool override_redirect;
722 [CCode (cname = "XGravityEvent")]
723 public struct GravityEvent {
726 public bool send_event;
727 public unowned Display display;
729 public Window window;
734 [CCode (cname = "XConfigureRequestEvent")]
735 public struct ConfigureRequestEvent {
738 public bool send_event;
739 public unowned Display display;
740 public Window parent;
741 public Window window;
746 public int border_width;
749 public ulong value_mask;
752 [CCode (cname = "XCirculateEvent")]
753 public struct CirculateEvent {
756 public bool send_event;
757 public unowned Display display;
759 public Window window;
763 [CCode (cname = "XCirculateRequestEvent")]
764 public struct CirculateRequestEvent {
767 public bool send_event;
768 public unowned Display display;
769 public Window parent;
770 public Window window;
774 [CCode (cname = "XPropertyEvent")]
775 public struct PropertyEvent {
778 public bool send_event;
779 public unowned Display display;
780 public Window window;
786 [CCode (cname = "XSelectionEvent")]
787 public struct SelectionEvent {
790 public bool send_event;
791 public unowned Display display;
792 public Window requestor;
793 public Atom selection;
795 public Atom property;
799 [CCode (cname = "XClientMessageEvent")]
800 public struct ClientMessageEvent {
802 public ulong serial; /* # of last request processed by server */
803 public bool send_event; /* true if this came from a SendEvent request */
804 public unowned Display display; /* Display the event was read from */
805 public Window window;
806 public Atom message_type;
808 public ClientMessageEventData data;
811 [CCode (cname = "RECTANGLE", has_type_id = false)]
812 public struct Rectangle {
820 public struct ClientMessageEventData {
821 public unowned char[] b;
822 public unowned short[] s;
823 public unowned long[] l;
826 [CCode (cprefix = "Queued")]
827 public enum QueuedMode {
833 [CCode (cprefix = "PropMode")]
834 public enum PropMode {
840 [CCode (cprefix = "")]
841 public enum AllowEventsMode {
852 [CCode (cprefix = "")]
853 public enum MapState {
859 [CCode (cprefix = "RevertTo")]
860 public enum RevertTo {
867 [CCode (cname = "Screen")]
868 public class Screen {
869 public Display display;
874 [CCode (cname = "XScreenOfDisplay")]
875 public static unowned Screen get_screen (Display disp, int screen_number);
877 [CCode (cname = "XBlackPixelOfScreen")]
878 public ulong black_pixel_of_screen ();
880 [CCode (cname = "XCellsOfScreen")]
881 public int cells_of_screen ();
883 [CCode (cname = "XDefaultColormapOfScreen")]
884 public Colormap default_colormap_of_screen ();
886 [CCode (cname = "XDefaultDepthOfScreen")]
887 public int default_depth_of_screen ();
889 [CCode (cname = "XDefaultGCOfScreen")]
890 public GC default_gc_of_screen ();
892 [CCode (cname = "XDefaultVisualOfScreen")]
893 public Visual default_visual_of_screen ();
895 [CCode (cname = "XDisplayOfScreen")]
896 public unowned Display display_of_screen ();
898 [CCode (cname = "XDoesBackingStore")]
899 public int does_backing_store ();
901 [CCode (cname = "XDoesSaveUnders")]
902 public bool does_save_unders ();
904 [CCode (cname = "XEventMaskOfScreen")]
905 public long event_mask_of_Screen ();
907 [CCode (cname = "XHeightMMOfScreen")]
908 public int height_in_mm_of_screen ();
910 [CCode (cname = "XHeightOfScreen")]
911 public int height_of_screen ();
913 [CCode (cname = "XMaxCmapsOfScreen")]
914 public int max_colormaps_of_screen ();
916 [CCode (cname = "XMinCmapsOfScreen")]
917 public int min_colormaps_of_screen ();
919 [CCode (cname = "XPlanesOfScreen")]
920 public int planes_of_screen ();
922 [CCode (cname = "XRootWindowOfScreen")]
923 public Window root_window_of_screen ();
925 [CCode (cname = "XScreenNumberOfScreen")]
926 public int screen_number_of_screen ();
928 [CCode (cname = "XWhitePixelOfScreen")]
929 public ulong white_pixel_of_screen ();
931 [CCode (cname = "XWidthMMOfScreen")]
932 public int width_in_mm_of_screen ();
934 [CCode (cname = "XWidthOfScreen")]
935 public int width_of_screen ();
938 public const X.ID None;
940 public const X.Atom XA_ATOM;
941 public const X.Atom XA_CARDINAL;
942 public const X.Atom XA_WINDOW;
943 public const X.Atom XA_WM_CLASS;
944 public const X.Atom XA_WM_HINTS;
945 public const X.Atom XA_WM_ICON_NAME;
946 public const X.Atom XA_WM_NAME;
947 public const X.Atom XA_WM_NORMAL_HINTS;
948 public const X.Atom XA_WM_TRANSIENT_FOR;
950 public const uint XK_Num_Lock;
951 public const uint XK_Scroll_Lock;
952 public const uint XK_Super_L;
953 public const uint XK_Super_R;
955 [CCode (cname = "XStringToKeysym")]
956 public ulong string_to_keysym (string key);
958 [CCode (cname = "XKeysymToString")]
959 public unowned string keysym_to_string (ulong keysym);
961 [CCode (cname = "XConvertCase")]
962 public void convert_case (ulong keysym, out ulong lower_return, out ulong upper_return);