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")]
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 = "XGetAtomName")]
37 public string get_atom_name(Atom a);
39 [CCode (cname = "XAllPlanes")]
40 public static ulong get_all_planes ();
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 = "XGetKeyboardMapping", array_length = false)]
88 public weak uint[] get_keyboard_mapping (uint first_keycode, int keycode_count, ref int keysyms_per_keycode_return);
90 [CCode (cname = "XGetModifierMapping")]
91 public ModifierKeymap get_modifier_mapping ();
93 [CCode (cname = "XGetSelectionOwner")]
94 public Window get_selection_owner (Atom selection);
96 [CCode (cname = "XGetWindowAttributes")]
97 public void get_window_attributes (Window w, out WindowAttributes window_attributes_return);
99 [CCode (cname = "XGetWindowProperty")]
100 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, out void* prop_return);
102 [CCode (cname = "XGrabButton")]
103 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);
105 [CCode (cname = "XGrabKey")]
106 public int grab_key (int keycode, uint modifiers, Window grab_window, bool owner_events, int pointer_mode, int keyboard_mode);
108 [CCode (cname = "XGrabPointer")]
109 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);
111 [CCode (cname = "XGrabServer")]
112 public int grab_server ();
114 [CCode (cname = "XImageByteOrder")]
115 public int image_byte_order ();
117 [CCode (cname = "XInternAtom")]
118 public Atom intern_atom (string atom_name, bool only_if_exists);
120 [CCode (cname = "XInternAtoms")]
121 public void intern_atoms (string[] names, bool only_if_exists, [CCode (array_length = false)] Atom[] atoms_return);
123 [CCode (cname = "XInternalConnectionNumbers")]
124 public Status internal_connection_numbers (ref int[] fd_return);
126 [CCode (cname = "XDisplayKeycodes")]
127 public int keycodes (ref int min_keycodes_return, ref int max_keycodes_return);
129 [CCode (cname = "XKeysymToKeycode")]
130 public int keysym_to_keycode (uint keysym);
132 [CCode (cname = "XLastKnownRequestProcessed")]
133 public ulong last_known_request_processed ();
135 [CCode (cname = "XLockDisplay")]
136 public void lock_display ();
138 [CCode (cname = "XMapWindow")]
139 public int map_window (Window w);
141 [CCode (cname = "XMaxRequestSize")]
142 public long max_request_size ();
144 [CCode (cname = "XExtendedMaxRequestSize")]
145 public long max_extended_request_size ();
147 [CCode (cname = "XNextEvent")]
148 public int next_event (ref Event event_return);
150 [CCode (cname = "XNextRequest")]
151 public ulong next_request ();
153 [CCode (cname = "XNoOp")]
154 public void no_operation ();
156 [CCode (cname = "XScreenCount")]
157 public int number_of_screens ();
159 [CCode (cname = "XPending")]
160 public int pending ();
162 [CCode (cname = "XProcessInternalConnection")]
163 public void process_internal_connection (int fd);
165 [CCode (cname = "XProtocolVersion")]
166 public int protocol_version ();
168 [CCode (cname = "XProtocolRevision")]
169 public int protocol_revision ();
171 [CCode (cname = "XRaiseWindow")]
172 public int raise_window (Window w);
174 [CCode (cname = "XReparentWindow")]
175 public int reparent_window (Window w, Window parent, int x, int y);
177 [CCode (cname = "XResizeWindow")]
178 public int resize_window (Window w, uint width, uint height);
180 [CCode (cname = "XRootWindow")]
181 public Window root_window (int screen_number);
183 [CCode (cname = "ScreenCount")]
184 public int screen_count ();
186 [CCode (cname = "XScreenOfDisplay")]
187 public weak Screen screen_of_display (int screen_number);
189 [CCode (cname = "XSelectInput")]
190 public int select_input (Window w, long event_mask);
192 [CCode (cname = "XSendEvent")]
193 public void send_event (Window w, bool prpagate, long event_mask, ref Event event_send);
195 [CCode (cname = "XSetCloseDownMode")]
196 public void set_close_down_mode (int close_mode);
198 [CCode (cname = "XSetSelectionOwner")]
199 public Window set_selection_owner (Atom selection, Window owner, int time);
201 [CCode (cname = "XSetInputFocus")]
202 public int set_input_focus (Window focus, int revert_to, int time);
204 [CCode (cname = "XUngrabButton")]
205 public int ungrab_button (uint button, uint modifiers, Window grab_window);
207 [CCode (cname = "XUngrabPointer")]
208 public int ungrab_pointer (int time);
210 [CCode (cname = "XUngrabServer")]
211 public int ungrab_server ();
213 [CCode (cname = "XUnlockDisplay")]
214 public void unlock_display ();
216 [CCode (cname = "XUnmapWindow")]
217 public int unmap_window (Window w);
219 [CCode (cname = "XQueryTree")]
220 public void query_tree (Window w, out Window root_return, out Window parent_return, out Window[] children_return);
222 [CCode (cname = "XWindowEvent")]
223 public int window_event (Window w, EventMask event_mask, out Event event_return);
225 [CCode (cname = "XServerVendor")]
226 public string xserver_vendor_name ();
228 [CCode (cname = "XVendorRelease")]
229 public string xserver_vendor_release ();
231 [CCode (cname = "XMoveWindow")]
232 public void move_window (Window window, int x, int y);
236 [CCode (cname = "XModifierKeymap", free_function = "XFreeModifiermap")]
237 public class ModifierKeymap {
238 // The server's max # of keys per modifier
239 public int max_keypermod;
240 // An 8 by max_keypermod array of modifiers
241 public uchar[] modifiermap;
245 [IntegerType (rank = 9)]
246 [CCode (cname = "Atom")]
251 [IntegerType (rank = 9)]
252 [CCode (cname = "Colormap")]
253 public struct Colormap {
257 [CCode (cname = "GC")]
262 [IntegerType (rank = 9)]
263 [CCode (cname = "Status")]
264 public struct Status {
268 [IntegerType (rank = 9)]
269 [CCode (cname = "Window", type_id = "G_TYPE_INT",
270 marshaller_type_name = "INT",
271 get_value_function = "g_value_get_int",
272 set_value_function = "g_value_set_int", default_value = "0",
273 type_signature = "i")]
274 public struct Window {
277 public struct Visual {
280 public struct WindowChanges {
285 public int border_width;
286 public Window sibling;
287 public int stack_mode;
289 public struct SizeHints {
297 [CCode (cname = "XCreateWindow")]
298 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);
300 [CCode (cname = "XSetWindowAttributes")]
301 public struct SetWindowAttributes {
302 // public Pixmap background_pixmap; /* background or None or ParentRelative */
303 public ulong background_pixel; /* background pixel */
304 // public Pixmap border_pixmap; /* border of the window */
305 public ulong border_pixel; /* border pixel value */
306 public int bit_gravity; /* one of bit gravity values */
307 public int win_gravity; /* one of the window gravity values */
308 public int backing_store; /* NotUseful, WhenMapped, Always */
309 public ulong backing_planes;/* planes to be preseved if possible */
310 public ulong backing_pixel;/* value to use in restoring planes */
311 public bool save_under; /* should bits under be saved? (popups) */
312 public long event_mask; /* set of events that should be saved */
313 public long do_not_propagate_mask; /* set of events that should not propagate */
314 public bool override_redirect; /* boolean value for override-redirect */
315 // public Colormap colormap; /* color map to be associated with window */
316 // public Cursor cursor; /* cursor to be displayed (or None) */
319 [CCode(cname = "XWindowAttributes",
320 cheader_filename = "X11/Xlib.h,X11/Xatom.h,X11/Xutil.h")]
321 public struct WindowAttributes {
323 public int y; /* location of window */
325 public int height; /* width and height of window */
326 public int border_width; /* border width of window */
327 public int depth; /* depth of window */
328 public Visual visual; /* the associated visual structure */
329 public Window root; /* root of screen containing window */
330 public int @class; /* InputOutput, InputOnly*/
331 public int bit_gravity; /* one of bit gravity values */
332 public int win_gravity; /* one of the window gravity values */
333 public int backing_store; /* NotUseful, WhenMapped, Always */
334 public ulong backing_planes;/* planes to be preserved if possible */
335 public ulong backing_pixel;/* value to be used when restoring planes */
336 public bool save_under; /* boolean, should bits under be saved? */
337 // public Colormap colormap; /* color map to be associated with window */
338 public bool map_installed; /* boolean, is color map currently installed*/
339 public int map_state; /* IsUnmapped, IsUnviewable, IsViewable */
340 public long all_event_masks; /* set of events all people have interest in*/
341 public long your_event_mask; /* my event mask */
342 public long do_not_propagate_mask; /* set of events that should not propagate */
343 public bool override_redirect; /* boolean value for override-redirect */
344 // public Screen screen; /* back pointer to correct screen */
347 [CCode (cname = "CopyFromParent")]
348 public const int COPY_FROM_PARENT;
350 [CCode (cname = "CurrentTime")]
351 public const ulong CURRENT_TIME;
353 [CCode (cname = "Success")]
356 [CCode (cname = "XFree")]
357 public int free (void* data);
359 [CCode (cprefix = "CW", cname = "int")]
385 [CCode (cprefix = "GrabMode")]
386 public enum GrabMode {
391 [CCode (cprefix = "")]
392 public enum EventMask {
401 PointerMotionHintMask,
410 VisibilityChangeMask,
413 SubstructureNotifyMask,
414 SubstructureRedirectMask,
421 [CCode (cprefix = "")]
422 public enum KeyMask {
433 [CCode (cprefix = "")]
434 public enum EventType {
471 [CCode (cname = "XEvent")]
472 public struct Event {
474 public AnyEvent xany;
475 public KeyEvent xkey;
476 public ButtonEvent xbutton;
477 public MotionEvent xmotion;
478 public CrossingEvent xcrossing;
479 public CreateWindowEvent xcreatewindow;
480 public DestroyWindowEvent xdestroywindow;
481 public UnmapEvent xunmap;
482 public MapEvent xmap;
483 public MapRequestEvent xmaprequest;
484 public ReparentEvent xreparent;
485 public ConfigureEvent xconfigure;
486 public GravityEvent xgravity;
487 public ConfigureRequestEvent xconfigurerequest;
488 public CirculateEvent xcirculate;
489 public CirculateRequestEvent xcirculaterequest;
490 public PropertyEvent xproperty;
491 public SelectionEvent xselection;
492 public ClientMessageEvent xclient;
495 [CCode (cname = "XAnyEvent")]
496 public struct AnyEvent {
499 public bool send_event;
500 public unowned Display display;
501 public Window window;
504 [CCode (cname = "XKeyEvent")]
505 public struct KeyEvent {
508 public bool send_event;
509 public unowned Display display;
510 public Window window;
512 public Window subwindow;
520 public bool same_screen;
523 [CCode (cname = "XButtonEvent")]
524 public struct ButtonEvent {
527 public bool send_event;
528 public unowned Display display;
529 public Window window;
530 public Window subwindow;
538 public bool same_screen;
541 [CCode (cname = "XMotionEvent")]
542 public struct MotionEvent {
545 public bool send_event;
546 public unowned Display display;
547 public Window window;
548 public Window subwindow;
556 public bool same_screen;
559 [CCode (cname = "XCrossingEvent")]
560 public struct CrossingEvent {
563 public bool send_event;
564 public unowned Display display;
565 public Window window;
567 public Window subwindow;
575 public bool same_screen;
580 [CCode (cname = "XCreateWindowEvent")]
581 public struct CreateWindowEvent {
584 public bool send_event;
585 public unowned Display display;
586 public Window parent;
587 public Window window;
592 public int border_width;
593 public bool override_redirect;
596 [CCode (cname = "XDestroyWindowEvent")]
597 public struct DestroyWindowEvent {
600 public bool send_event;
601 public unowned Display display;
603 public Window window;
606 [CCode (cname = "XUnmapEvent")]
607 public struct UnmapEvent {
610 public bool send_event;
611 public unowned Display display;
613 public Window window;
614 public bool from_configure;
617 [CCode (cname = "XMapEvent")]
618 public struct MapEvent {
621 public bool send_event;
622 public unowned Display display;
624 public Window window;
625 public bool override_redirect;
628 [CCode (cname = "XMapRequestEvent")]
629 public struct MapRequestEvent {
632 public bool send_event;
633 public unowned Display display;
634 public Window parent;
635 public Window window;
638 [CCode (cname = "XReparentEvent")]
639 public struct ReparentEvent {
642 public bool send_event;
643 public unowned Display display;
645 public Window window;
646 public Window parent;
649 public bool override_redirect;
652 [CCode (cname = "XConfigureEvent")]
653 public struct ConfigureEvent {
656 public bool send_event;
657 public unowned Display display;
659 public Window window;
664 public int border_width;
666 public bool override_redirect;
669 [CCode (cname = "XGravityEvent")]
670 public struct GravityEvent {
673 public bool send_event;
674 public unowned Display display;
676 public Window window;
681 [CCode (cname = "XConfigureRequestEvent")]
682 public struct ConfigureRequestEvent {
685 public bool send_event;
686 public unowned Display display;
687 public Window parent;
688 public Window window;
693 public int border_width;
696 public ulong value_mask;
699 [CCode (cname = "XCirculateEvent")]
700 public struct CirculateEvent {
703 public bool send_event;
704 public unowned Display display;
706 public Window window;
710 [CCode (cname = "XCirculateRequestEvent")]
711 public struct CirculateRequestEvent {
714 public bool send_event;
715 public unowned Display display;
716 public Window parent;
717 public Window window;
721 [CCode (cname = "XPropertyEvent")]
722 public struct PropertyEvent {
725 public bool send_event;
726 public unowned Display display;
727 public Window window;
733 [CCode (cname = "XSelectionEvent")]
734 public struct SelectionEvent {
737 public bool send_event;
738 public unowned Display display;
739 public Window requestor;
740 public Atom selection;
742 public Atom property;
746 [CCode (cname = "XClientMessageEvent")]
747 public struct ClientMessageEvent {
749 public ulong serial; /* # of last request processed by server */
750 public bool send_event; /* true if this came from a SendEvent request */
751 public unowned Display display; /* Display the event was read from */
752 public Window window;
753 public Atom message_type;
755 public ClientMessageEventData data;
759 public struct ClientMessageEventData {
760 public unowned char[] b;
761 public unowned short[] s;
762 public unowned long[] l;
765 [CCode (cprefix = "PropMode")]
766 public enum PropMode {
772 [CCode (cprefix = "")]
773 public enum AllowEventsMode {
784 [CCode (cprefix = "")]
785 public enum MapState {
791 [CCode (cprefix = "RevertTo")]
792 public enum RevertTo {
799 [CCode (cname = "Screen")]
800 public class Screen {
801 public Display display;
806 [CCode (cname = "XScreenOfDisplay")]
807 public static unowned Screen get_screen (Display disp, int screen_number);
809 [CCode (cname = "XBlackPixelOfScreen")]
810 public ulong black_pixel_of_screen ();
812 [CCode (cname = "XCellsOfScreen")]
813 public int cells_of_screen ();
815 [CCode (cname = "XDefaultColormapOfScreen")]
816 public Colormap default_colormap_of_screen ();
818 [CCode (cname = "XDefaultDepthOfScreen")]
819 public int default_depth_of_screen ();
821 [CCode (cname = "XDefaultGCOfScreen")]
822 public GC default_gc_of_screen ();
824 [CCode (cname = "XDefaultVisualOfScreen")]
825 public Visual default_visual_of_screen ();
827 [CCode (cname = "XDisplayOfScreen")]
828 public unowned Display display_of_screen ();
830 [CCode (cname = "XDoesBackingStore")]
831 public int does_backing_store ();
833 [CCode (cname = "XDoesSaveUnders")]
834 public bool does_save_unders ();
836 [CCode (cname = "XEventMaskOfScreen")]
837 public long event_mask_of_Screen ();
839 [CCode (cname = "XHeightMMOfScreen")]
840 public int height_in_mm_of_screen ();
842 [CCode (cname = "XHeightOfScreen")]
843 public int height_of_screen ();
845 [CCode (cname = "XMaxCmapsOfScreen")]
846 public int max_colormaps_of_screen ();
848 [CCode (cname = "XMinCmapsOfScreen")]
849 public int min_colormaps_of_screen ();
851 [CCode (cname = "XPlanesOfScreen")]
852 public int planes_of_screen ();
854 [CCode (cname = "XRootWindowOfScreen")]
855 public Window root_window_of_screen ();
857 [CCode (cname = "XScreenNumberOfScreen")]
858 public int screen_number_of_screen ();
860 [CCode (cname = "XWhitePixelOfScreen")]
861 public ulong white_pixel_of_screen ();
863 [CCode (cname = "XWidthMMOfScreen")]
864 public int width_in_mm_of_screen ();
866 [CCode (cname = "XWidthOfScreen")]
867 public int width_of_screen ();
870 public const X.Atom XA_ATOM;
871 public const X.Atom XA_CARDINAL;
872 public const X.Atom XA_WINDOW;
873 public const X.Atom XA_WM_CLASS;
874 public const X.Atom XA_WM_HINTS;
875 public const X.Atom XA_WM_ICON_NAME;
876 public const X.Atom XA_WM_NAME;
877 public const X.Atom XA_WM_NORMAL_HINTS;
878 public const X.Atom XA_WM_TRANSIENT_FOR;
880 public const uint XK_Num_Lock;
881 public const uint XK_Scroll_Lock;