/ minilibx-linux / man / man3 / mlx_loop.3
mlx_loop.3
  1  .TH MiniLibX 3 "September 19, 2002"
  2  .SH NAME
  3  MiniLibX - Handle events
  4  .SH SYNOPSYS
  5  
  6  .nf
  7  .I int
  8  .fi
  9  .B mlx_loop
 10  (
 11  .I void *mlx_ptr
 12  );
 13  
 14  .nf
 15  .I int
 16  .fi
 17  .B mlx_key_hook
 18  (
 19  .I void *win_ptr, int (*funct_ptr)(), void *param
 20  );
 21  
 22  .nf
 23  .I int
 24  .fi
 25  .B mlx_mouse_hook
 26  (
 27  .I void *win_ptr, int (*funct_ptr)(), void *param
 28  );
 29  
 30  .nf
 31  .I int
 32  .fi
 33  .B mlx_expose_hook
 34  (
 35  .I void *win_ptr, int (*funct_ptr)(), void *param
 36  );
 37  
 38  .nf
 39  .I int
 40  .fi
 41  .B mlx_loop_hook
 42  (
 43  .I void *mlx_ptr, int (*funct_ptr)(), void *param
 44  );
 45  
 46  .SH X-WINDOW EVENTS
 47  
 48  The X-Window system is bi-directionnal. On one hand, the program sends orders to
 49  the screen to display pixels, images, and so on. On the other hand,
 50  it can get information from the keyboard and mouse associated to
 51  the screen. To do so, the program receives "events" from the keyboard or the
 52  mouse.
 53  
 54  .SH DESCRIPTION
 55  
 56  To receive events, you must use
 57  .B mlx_loop
 58  (). This function never returns. It is an infinite loop that waits for
 59  an event, and then calls a user-defined function associated with this event.
 60  A single parameter is needed, the connection identifier
 61  .I mlx_ptr
 62  (see the
 63  .B mlx manual).
 64  
 65  You can assign different functions to the three following events:
 66  .br
 67  - A key is pressed
 68  .br
 69  - The mouse button is pressed
 70  .br
 71  - A part of the window should be re-drawn
 72  (this is called an "expose" event, and it is your program's job to handle it).
 73  .br
 74  
 75  Each window can define a different function for the same event.
 76  
 77  The three functions
 78  .B mlx_key_hook
 79  (),
 80  .B mlx_mouse_hook
 81  () and
 82  .B mlx_expose_hook
 83  () work exactly the same way.
 84  .I funct_ptr
 85  is a pointer to the function you want to be called
 86  when an event occurs. This assignment is specific to the window defined by the
 87  .I win_ptr
 88  identifier. The
 89  .I param
 90  adress will be passed to the function everytime it is called, and should be
 91  used to store the parameters it might need.
 92  
 93  The syntax for the
 94  .B mlx_loop_hook
 95  () function is identical to the previous ones, but the given function will be
 96  called when no event occurs.
 97  
 98  When it catches an event, the MiniLibX calls the corresponding function
 99  with fixed parameters:
100  .nf
101  
102    expose_hook(void *param);
103    key_hook(int keycode,void *param);
104    mouse_hook(int button,int x,int y,void *param);
105    loop_hook(void *param);
106  
107  .fi
108  These function names are arbitrary. They here are used to distinguish
109  parameters according to the event. These functions are NOT part of the
110  MiniLibX.
111  
112  .I param
113  is the address specified in the mlx_*_hook calls. This address is never
114  used nor modified by the MiniLibX. On key and mouse events, additional
115  information is passed:
116  .I keycode
117  tells you which key is pressed (look for the X11 include file "keysymdef.h"),
118  (
119  .I x
120  ,
121  .I y
122  ) are the coordinates of the mouse click in the window, and
123  .I button
124  tells you which mouse button was pressed.
125  
126  .SH GOING FURTHER WITH EVENTS
127  The MiniLibX provides a much generic access to all X-Window events. The
128  .I mlx.h
129  include define
130  .B mlx_hook()
131  in the same manner mlx_*_hook functions work. The event and mask values
132  will be taken from the X11 include file "X.h".
133  
134  See source code of mlx_int_param_event.c to find out how the MiniLibX will
135  call your own function for a specific event.
136  
137  .SH SEE ALSO
138  mlx(3), mlx_new_window(3), mlx_pixel_put(3), mlx_new_image(3)
139  
140  .SH AUTHOR
141  Copyright ol@ - 2002-2014 - Olivier Crouzet