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
|
/* Copyright (C) 2000-2003 Damir Zucic */
/*=============================================================================
event_loop.c
Purpose:
Take and process events.
Input:
(1) Pointer to the array of MolComplexS structures.
(2) Pointer to the number of macromolecular complexes.
(3) Pointer to the next macromolecular complex identifier.
(4) Pointer to pointer to the array of NearestAtomS structures.
(5) Pointer to the number of pixels in the main window free area.
(6) Pointer to ConfigS structure, with configuration data.
(7) Pointer to GUIS structure, with GUI data and the rest of command
line options.
(8) Events (from event queue).
(9) Molecular coordinates read from one or more files, on request.
Output:
(1) Graphics, text and other useful things.
(2) Array pointed at by MolComplexS structure pointer may be filled
with data.
(3) Number of macromolecular complexes updated, if at least one
complex is loaded at runtime.
(4) Return value.
Return value:
(1) Positive if everything worked fine.
(2) Negative if something failed.
Notes:
(1) When a new macromolecular complex is loaded, *next_mol_complexIDP
should be used as complex identifier. The m. complex index should
not be used, because one of the previously initialized complex
identifiers may have the value equal to current_complexI. This
may happen if one or more objects are discarded from memory.
(2) The refreshI index is updated before refreshing the main window.
The lowest value of refreshI should be one. Never reset to zero!
The value zero is reserved as the initial value for last_refreshI
member of NearestAtomS structure. Pixels which have last_refreshI
value set to zero are free for drawing; there is no need to check
the z coordinate associated with this pixel. Otherwise, if the
last_refreshI is equal to the current refreshI, the z coordinate
of a given atom should be compared with a z value stored in the
NearestAtomS structure associated with a given pixel. It is
assumed that refreshI is updated no more than once in each event
handling function. If this is not the case, the care should be
taken to avoid refreshI overflow.
(3) A single action may result in several Expose events. The server
guarantees that such Expose events are sent contiguously. The
last event has the xexpose.count equal to zero. In this program
only the last Expose event is processed.
(4) Note the unusual indentation of while (1) loop.
(5) The array of NearestAtomS structures may be reallocated, so it is
neccesary to use pointer to pointer. The array is freed later.
========includes:============================================================*/
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/Xatom.h>
#include "defines.h"
#include "commands.h"
#include "typedefs.h"
/*======function prototypes:=================================================*/
int InitRuntime_ (RuntimeS *, ConfigS *);
void InitNearest_ (NearestAtomS *, size_t);
size_t MainRefresh_ (MolComplexS *, int,
RuntimeS *, ConfigS *, GUIS *,
NearestAtomS *, size_t, unsigned int);
int ControlRefresh_ (MolComplexS *, ConfigS *, GUIS *);
int InputRefresh_ (GUIS *, RuntimeS *);
int DockingRefresh_ (RuntimeS *, GUIS *);
int KeyPress_ (MolComplexS *, int *, int *,
RuntimeS *, ConfigS *, GUIS *,
NearestAtomS **, size_t *, unsigned int *,
XKeyEvent *);
int KeyRelease_ (GUIS *, XKeyEvent *);
int MotionNotify_ (MolComplexS *, int,
RuntimeS *, ConfigS *, GUIS *,
NearestAtomS *, size_t, unsigned int,
XMotionEvent *);
int DockingResize_ (RuntimeS *, GUIS *, XConfigureEvent *);
int MainResize_ (NearestAtomS **, size_t *,
MolComplexS *, int,
ConfigS *, GUIS *,
XConfigureEvent *);
int FreeRuntime_ (RuntimeS *);
int ButtonPress_ (MolComplexS *, int,
RuntimeS *, ConfigS *, GUIS *,
NearestAtomS *, size_t, unsigned int *,
XButtonEvent *);
/*======do the remaining initializations; take and process events:===========*/
int EventLoop_ (MolComplexS *mol_complexSP, int *mol_complexesNP,
int *next_mol_complexIDP,
NearestAtomS **nearest_atomSPP, size_t *pixelsNP,
ConfigS *configSP, GUIS *guiSP)
{
static XEvent eventS;
static unsigned int refreshI = 1;
static XClientMessageEvent *client_eventSP;
static RuntimeS runtimeS;
static int command_code;
/* Initialize memory for some runtime data and do some initializations: */
if (InitRuntime_ (&runtimeS, configSP) < 0) return -1;
/* The event loop: */
while (1)
{
/* Take the next event: */
XNextEvent (guiSP->displaySP, &eventS);
/* Check the current refreshI value; reset it and initialize the */
/* NearestAtomS array if maximal value is reached or exceeded: */
if (refreshI >= MAXREFRESHI)
{
InitNearest_ (*nearest_atomSPP, *pixelsNP);
refreshI = 1;
}
/* Handle the event: */
switch (eventS.type)
{
/*---------------------------------------------------------------------------*/
case Expose:
/* A single action may result in several Expose */
/* events. Only the last one is taken seriously: */
if (eventS.xexpose.count != 0) continue;
/* Update refresh index before use: */
refreshI++;
/* Refreshing the main window: */
MainRefresh_ (mol_complexSP, *mol_complexesNP,
&runtimeS, configSP, guiSP,
*nearest_atomSPP, *pixelsNP, refreshI);
/* Refresh the control window: */
ControlRefresh_ (mol_complexSP + runtimeS.default_complexI,
configSP, guiSP);
/* Refresh the input window: */
InputRefresh_ (guiSP, &runtimeS);
/* Refresh docking window, if docking is switched on: */
if (guiSP->dockingF) DockingRefresh_ (&runtimeS, guiSP);
/* Flush the output buffer: */
XFlush (guiSP->displaySP);
/* Reset modifier flags: */
guiSP->shift_pressedF = 0;
guiSP->control_pressedF = 0;
guiSP->alt_pressedF = 0;
/* End of case Expose: */
break;
/*---------------------------------------------------------------------------*/
case KeyPress:
/* Handle KeyPress_ event: */
command_code = KeyPress_ (mol_complexSP, mol_complexesNP,
next_mol_complexIDP,
&runtimeS,
configSP, guiSP,
nearest_atomSPP, pixelsNP,
&refreshI,
&eventS.xkey);
/* Flush the output buffer: */
XFlush (guiSP->displaySP);
/* Break from event loop if quit command issued: */
if (command_code == COMMAND_QUIT)
{
/** Free memory used for runtime data: **/
FreeRuntime_ (&runtimeS);
/** Return to caller: **/
return 1;
}
/* End of case KeyPress: */
break;
/*---------------------------------------------------------------------------*/
case KeyRelease:
KeyRelease_ (guiSP, &eventS.xkey);
/* End of case KeyRelease: */
break;
/*---------------------------------------------------------------------------*/
case MotionNotify:
MotionNotify_ (mol_complexSP, *mol_complexesNP,
&runtimeS, configSP, guiSP,
*nearest_atomSPP, *pixelsNP, refreshI,
&eventS.xmotion);
/* End of case MotionNotify: */
break;
/*---------------------------------------------------------------------------*/
case ButtonPress:
ButtonPress_ (mol_complexSP, *mol_complexesNP,
&runtimeS, configSP, guiSP,
*nearest_atomSPP, *pixelsNP, &refreshI,
&eventS.xbutton);
/* End of case ButtonPress: */
break;
/*---------------------------------------------------------------------------*/
case ButtonRelease:
break;
/*---------------------------------------------------------------------------*/
case ConfigureNotify:
/* If event belongs to docking window: */
if (eventS.xconfigure.window == guiSP->docking_winS.ID)
{
DockingResize_ (&runtimeS, guiSP, &eventS.xconfigure);
}
/* If event belongs to the main window: */
else
{
MainResize_ (nearest_atomSPP, pixelsNP,
mol_complexSP, *mol_complexesNP,
configSP, guiSP,
&eventS.xconfigure);
}
break;
/*---------------------------------------------------------------------------*/
case ClientMessage:
client_eventSP = (XClientMessageEvent *) &eventS;
if ((client_eventSP->message_type == guiSP->protocols_atom) &&
(client_eventSP->data.l[0] ==
(long) guiSP->delete_window_atom))
{
return 1;
}
break;
/*---------------------------------------------------------------------------*/
default:
/* Do nothing */
;
/*---------------------------------------------------------------------------*/
} /* End of switch (eventS.type) */
} /* End of while (1) loop */
/* Return positive value on success: */
return 1;
}
/*===========================================================================*/
|